2013-06-01 19:45:02 -04:00
|
|
|
/*globals window, _, $, Backbone */
|
2013-05-31 06:58:20 +01:00
|
|
|
(function ($) {
|
|
|
|
"use strict";
|
|
|
|
|
2013-06-01 19:45:02 -04:00
|
|
|
_.extend(Backbone.View.prototype, {
|
|
|
|
|
|
|
|
// Adds a subview to the current view, which will
|
|
|
|
// ensure its removal when this view is removed,
|
|
|
|
// or when view.removeSubviews is called
|
|
|
|
addSubview: function (view) {
|
|
|
|
if (!(view instanceof Backbone.View)) {
|
|
|
|
throw new Error("Subview must be a Backbone.View");
|
|
|
|
}
|
|
|
|
this.subviews = this.subviews || [];
|
|
|
|
this.subviews.push(view);
|
|
|
|
return view;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Removes any subviews associated with this view
|
|
|
|
// by `addSubview`, which will in-turn remove any
|
|
|
|
// children of those views, and so on.
|
|
|
|
removeSubviews: function () {
|
|
|
|
var i, l, children = this.subviews;
|
|
|
|
if (!children) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
for (i = 0, l = children.length; i < l; i += 1) {
|
|
|
|
children[i].remove();
|
|
|
|
}
|
|
|
|
this.subviews = [];
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Extends the view's remove, by calling `removeSubviews`
|
|
|
|
// if any subviews exist.
|
|
|
|
remove: function () {
|
|
|
|
if (this.subviews) {
|
|
|
|
this.removeSubviews();
|
|
|
|
}
|
|
|
|
return Backbone.View.prototype.remove.apply(this, arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-05-31 06:58:20 +01:00
|
|
|
var Ghost = {
|
2013-06-01 19:45:02 -04:00
|
|
|
Layout : {},
|
|
|
|
Views : {},
|
|
|
|
Collections : {},
|
|
|
|
Models : {},
|
2013-05-31 06:58:20 +01:00
|
|
|
|
|
|
|
settings: {
|
2013-06-01 19:45:02 -04:00
|
|
|
apiRoot: '/api/v0.1'
|
2013-05-31 06:58:20 +01:00
|
|
|
},
|
|
|
|
|
2013-06-01 19:45:02 -04:00
|
|
|
// This is a helper object to denote legacy things in the
|
|
|
|
// middle of being transitioned.
|
|
|
|
temporary: {},
|
|
|
|
|
|
|
|
currentView: null,
|
|
|
|
router: null
|
2013-05-31 06:58:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
window.Ghost = Ghost;
|
|
|
|
|
|
|
|
}());
|