From dc714611a9ad0c151cd1da4d2576f57edd044ca5 Mon Sep 17 00:00:00 2001 From: Ricardo Tomasi Date: Fri, 7 Jun 2013 23:16:28 -0300 Subject: [PATCH] move Ghost.View out of init, refactor --- core/admin/assets/js/init.js | 49 ++++++------------------------ core/admin/assets/js/starter.js | 15 --------- core/admin/assets/js/views/base.js | 45 +++++++++++++++++++++++++++ core/admin/views/default.hbs | 5 ++- 4 files changed, 58 insertions(+), 56 deletions(-) delete mode 100644 core/admin/assets/js/starter.js create mode 100644 core/admin/assets/js/views/base.js diff --git a/core/admin/assets/js/init.js b/core/admin/assets/js/init.js index 8f302daa82..79ea27c7fe 100644 --- a/core/admin/assets/js/init.js +++ b/core/admin/assets/js/init.js @@ -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; -}()); \ No newline at end of file +}()); diff --git a/core/admin/assets/js/starter.js b/core/admin/assets/js/starter.js deleted file mode 100644 index adb6c2112d..0000000000 --- a/core/admin/assets/js/starter.js +++ /dev/null @@ -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'}); - - }); - - -}()); \ No newline at end of file diff --git a/core/admin/assets/js/views/base.js b/core/admin/assets/js/views/base.js new file mode 100644 index 0000000000..3c89bf5e35 --- /dev/null +++ b/core/admin/assets/js/views/base.js @@ -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); + } + + }); + +}()); diff --git a/core/admin/views/default.hbs b/core/admin/views/default.hbs index dce72828b2..377afa46e0 100644 --- a/core/admin/views/default.hbs +++ b/core/admin/views/default.hbs @@ -56,10 +56,13 @@ + - {{{block "bodyScripts"}}} + \ No newline at end of file