mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-27 18:52:14 +03:00
move Ghost.View out of init, refactor
This commit is contained in:
parent
aa659d29b6
commit
dc714611a9
@ -21,46 +21,15 @@
|
||||
router: null
|
||||
};
|
||||
|
||||
Ghost.View = Backbone.View.extend({
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
});
|
||||
Ghost.init = function () {
|
||||
Ghost.router = new Ghost.Router();
|
||||
Backbone.history.start({
|
||||
pushState: true,
|
||||
hashChange: false,
|
||||
root: '/ghost'
|
||||
});
|
||||
};
|
||||
|
||||
window.Ghost = Ghost;
|
||||
|
||||
}());
|
||||
}());
|
||||
|
@ -1,15 +0,0 @@
|
||||
/*global window, document, Ghost, Backbone, $, _ */
|
||||
(function () {
|
||||
|
||||
"use strict";
|
||||
|
||||
Ghost.router = new Ghost.Router();
|
||||
|
||||
$(function () {
|
||||
|
||||
Backbone.history.start({pushState: true, hashChange: false, root: '/ghost'});
|
||||
|
||||
});
|
||||
|
||||
|
||||
}());
|
45
core/admin/assets/js/views/base.js
Normal file
45
core/admin/assets/js/views/base.js
Normal file
@ -0,0 +1,45 @@
|
||||
/*global window, document, Ghost, Backbone, $, _ */
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
Ghost.View = Backbone.View.extend({
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}());
|
@ -56,10 +56,13 @@
|
||||
<!-- // require '/core/admin/assets/js/models/*' -->
|
||||
<script src="/core/admin/assets/js/models/post.js"></script>
|
||||
<!-- // require '/core/admin/assets/js/views/*' -->
|
||||
<script src="/core/admin/assets/js/views/base.js"></script>
|
||||
<script src="/core/admin/assets/js/views/blog.js"></script>
|
||||
<script src="/core/admin/assets/js/views/editor.js"></script>
|
||||
<script src="/core/admin/assets/js/router.js"></script>
|
||||
<script src="/core/admin/assets/js/starter.js"></script>
|
||||
{{{block "bodyScripts"}}}
|
||||
<script>
|
||||
Ghost.init();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user