diff --git a/core/client/app/components/gh-ed-editor.js b/core/client/app/components/gh-ed-editor.js index 48ac69609c..bead5eac86 100644 --- a/core/client/app/components/gh-ed-editor.js +++ b/core/client/app/components/gh-ed-editor.js @@ -16,18 +16,20 @@ Editor = Ember.TextArea.extend(EditorAPI, EditorShortcuts, EditorScroll, { }, /** - * Check if the textarea should have focus, and set it if necessary + * Sets the focus of the textarea if needed */ setFocus: function () { if (this.get('focus')) { this.$().val(this.$().val()).focus(); } - }.on('didInsertElement'), + }, /** - * Tell the controller about this component + * Sets up properties at render time */ didInsertElement: function () { + this.setFocus(); + this.sendAction('setEditor', this); Ember.run.scheduleOnce('afterRender', this, this.afterRenderEvent); diff --git a/core/client/app/components/gh-ed-preview.js b/core/client/app/components/gh-ed-preview.js index 437806e18e..2200f81f68 100644 --- a/core/client/app/components/gh-ed-preview.js +++ b/core/client/app/components/gh-ed-preview.js @@ -9,12 +9,12 @@ var Preview = Ember.Component.extend({ Ember.run.scheduleOnce('afterRender', this, this.dropzoneHandler); }, - adjustScrollPosition: function () { + adjustScrollPosition: Ember.observer('scrollPosition', function () { var scrollWrapper = this.get('scrollWrapper'), scrollPosition = this.get('scrollPosition'); scrollWrapper.scrollTop(scrollPosition); - }.observes('scrollPosition'), + }), dropzoneHandler: function () { var dropzones = $('.js-drop-zone'); @@ -35,9 +35,9 @@ var Preview = Ember.Component.extend({ // fire off 'enable' API function from uploadManager // might need to make sure markdown has been processed first - reInitDropzones: function () { + reInitDropzones: Ember.observer('markdown', function () { Ember.run.scheduleOnce('afterRender', this, this.dropzoneHandler); - }.observes('markdown') + }) }); export default Preview; diff --git a/core/client/app/components/gh-tab-pane.js b/core/client/app/components/gh-tab-pane.js index c930e62b66..71e923cebb 100644 --- a/core/client/app/components/gh-tab-pane.js +++ b/core/client/app/components/gh-tab-pane.js @@ -16,14 +16,15 @@ var TabPane = Ember.Component.extend({ active: Ember.computed.alias('tab.active'), - // Register with the tabs manager - registerWithTabs: function () { + didInsertElement: function () { + // Register with the tabs manager this.get('tabsManager').registerTabPane(this); - }.on('didInsertElement'), + }, - unregisterWithTabs: function () { + willDestroyElement: function () { + // Deregister with the tabs manager this.get('tabsManager').unregisterTabPane(this); - }.on('willDestroyElement') + } }); export default TabPane; diff --git a/core/client/app/components/gh-tab.js b/core/client/app/components/gh-tab.js index d2d20d5157..936444a489 100644 --- a/core/client/app/components/gh-tab.js +++ b/core/client/app/components/gh-tab.js @@ -18,14 +18,15 @@ var Tab = Ember.Component.extend({ this.get('tabsManager').select(this); }, - // Registration methods - registerWithTabs: function () { + didInsertElement: function () { + // register the tabs with the tab manager this.get('tabsManager').registerTab(this); - }.on('didInsertElement'), + }, - unregisterWithTabs: function () { + willDestroyElement: function () { + // unregister the tabs with the tab manager this.get('tabsManager').unregisterTab(this); - }.on('willDestroyElement') + } }); export default Tab; diff --git a/core/client/app/components/gh-uploader.js b/core/client/app/components/gh-uploader.js index e136a4efdf..792632b880 100644 --- a/core/client/app/components/gh-uploader.js +++ b/core/client/app/components/gh-uploader.js @@ -10,6 +10,9 @@ var PostImageUploader = Ember.Component.extend({ return this.get('image') || ''; }), + /** + * Sets up the uploader on render + */ setup: function () { var $this = this.$(), self = this; @@ -28,14 +31,23 @@ var PostImageUploader = Ember.Component.extend({ $this.on('imagecleared', function () { self.sendAction('canceled'); }); - }.on('didInsertElement'), + }, + // removes event listeners from the uploader removeListeners: function () { var $this = this.$(); $this.off(); $this.find('.js-cancel').off(); - }.on('willDestroyElement') + }, + + didInsertElement: function () { + this.setup(); + }, + + willDestroyElement: function () { + this.removeListeners(); + } }); export default PostImageUploader; diff --git a/core/client/app/controllers/post-settings-menu.js b/core/client/app/controllers/post-settings-menu.js index 9891966e6f..5c050013e1 100644 --- a/core/client/app/controllers/post-settings-menu.js +++ b/core/client/app/controllers/post-settings-menu.js @@ -18,16 +18,16 @@ export default Ember.Controller.extend(SettingsMenuMixin, { ghostPaths: Ember.inject.service('ghost-paths'), notifications: Ember.inject.service(), - initializeSelectedAuthor: function () { + initializeSelectedAuthor: Ember.observer('model', function () { var self = this; return this.get('model.author').then(function (author) { self.set('selectedAuthor', author); return author; }); - }.observes('model'), + }), - changeAuthor: function () { + changeAuthor: Ember.observer('selectedAuthor', function () { var author = this.get('model.author'), selectedAuthor = this.get('selectedAuthor'), model = this.get('model'), @@ -50,7 +50,7 @@ export default Ember.Controller.extend(SettingsMenuMixin, { self.set('selectedAuthor', author); model.rollback(); }); - }.observes('selectedAuthor'), + }), authors: Ember.computed(function () { // Loaded asynchronously, so must use promise proxies. @@ -196,11 +196,11 @@ export default Ember.Controller.extend(SettingsMenuMixin, { // observe titleScratch, keeping the post's slug in sync // with it until saved for the first time. - addTitleObserver: function () { + addTitleObserver: Ember.observer('model', function () { if (this.get('model.isNew') || this.get('model.title') === '(Untitled)') { this.addObserver('model.titleScratch', this, 'titleObserver'); } - }.observes('model'), + }), titleObserver: function () { var debounceId, diff --git a/core/client/app/controllers/post-tags-input.js b/core/client/app/controllers/post-tags-input.js index 66946151df..583db77ce8 100644 --- a/core/client/app/controllers/post-tags-input.js +++ b/core/client/app/controllers/post-tags-input.js @@ -164,7 +164,7 @@ var PostTagsInputController = Ember.Controller.extend({ } }), - updateSuggestionsList: function () { + updateSuggestionsList: Ember.observer('newTagText', function () { var searchTerm = this.get('newTagText'), matchingTags, // Limit the suggestions number @@ -186,7 +186,7 @@ var PostTagsInputController = Ember.Controller.extend({ }, this); this.set('suggestions', suggestions); - }.observes('newTagText'), + }), findMatchingTags: function (searchTerm) { var matchingTags, diff --git a/core/client/app/controllers/settings/app.js b/core/client/app/controllers/settings/app.js index 58b974f7d7..da0b76a3f4 100644 --- a/core/client/app/controllers/settings/app.js +++ b/core/client/app/controllers/settings/app.js @@ -14,11 +14,11 @@ SettingsAppController = Ember.Controller.extend({ appState: appStates.active, buttonText: '', - setAppState: function () { + setAppState: Ember.on('init', function () { this.set('appState', this.get('active') ? appStates.active : appStates.inactive); - }.on('init'), + }), - buttonTextSetter: function () { + buttonTextSetter: Ember.observer('appState', function () { switch (this.get('appState')) { case appStates.active: this.set('buttonText', 'Deactivate'); @@ -30,7 +30,7 @@ SettingsAppController = Ember.Controller.extend({ this.set('buttonText', 'Working'); break; } - }.observes('appState').on('init'), + }), activeClass: Ember.computed('appState', function () { return this.appState === appStates.active ? true : false; diff --git a/core/client/app/mixins/ed-editor-scroll.js b/core/client/app/mixins/ed-editor-scroll.js index 6901b80521..485f6de2d7 100644 --- a/core/client/app/mixins/ed-editor-scroll.js +++ b/core/client/app/mixins/ed-editor-scroll.js @@ -79,16 +79,24 @@ var EditorScroll = Ember.Mixin.create({ target: Ember.$('.js-entry-markdown'), offset: 10 })); - }.on('didInsertElement'), + }, /** - * once the element is in the DOM unbind from the events which control scroll behaviour + * once the element has been removed from the DOM unbind from the events which control scroll behaviour */ detachScrollHandlers: function () { this.$().off('keypress'); this.$().off('scroll'); Ember.run.cancel(this.get('scrollThrottle')); - }.on('willDestroyElement') + }, + + didInsertElement: function () { + this.attachScrollHandlers(); + }, + + willDestroyElement: function () { + this.detachScrollHandlers(); + } }); export default EditorScroll; diff --git a/core/client/app/mixins/editor-base-controller.js b/core/client/app/mixins/editor-base-controller.js index a600262d49..9b825d9b9a 100644 --- a/core/client/app/mixins/editor-base-controller.js +++ b/core/client/app/mixins/editor-base-controller.js @@ -33,7 +33,7 @@ export default Ember.Mixin.create({ }; }, - autoSave: function () { + autoSave: Ember.observer('model.scratch', function () { // Don't save just because we swapped out models if (this.get('model.isDraft') && !this.get('model.isNew')) { var autoSaveId, @@ -51,7 +51,7 @@ export default Ember.Mixin.create({ autoSaveId = Ember.run.debounce(this, 'send', 'save', saveOptions, 3000); this.set('autoSaveId', autoSaveId); } - }.observes('model.scratch'), + }), /** * By default, a post will not change its publish state. diff --git a/core/client/app/mixins/pagination-view-infinite-scroll.js b/core/client/app/mixins/pagination-view-infinite-scroll.js index a4230e2d1d..0cc7755758 100644 --- a/core/client/app/mixins/pagination-view-infinite-scroll.js +++ b/core/client/app/mixins/pagination-view-infinite-scroll.js @@ -31,15 +31,16 @@ var PaginationViewInfiniteScrollMixin = Ember.Mixin.create({ if (this.element.scrollHeight <= this.element.clientHeight) { controller.send('loadNextPage'); } - }.on('didInsertElement'), + }, - /** - * Unbind from the scroll event when the element is no longer in the DOM - */ - detachCheckScroll: function () { - var el = this.$(); - el.off('scroll'); - }.on('willDestroyElement') + didInsertElement: function () { + this.attachCheckScroll(); + }, + + willDestroyElement: function () { + // unbind from the scroll event when the element is no longer in the DOM + this.$().off('scroll'); + } }); export default PaginationViewInfiniteScrollMixin; diff --git a/core/client/app/routes/mobile-index-route.js b/core/client/app/routes/mobile-index-route.js index 3721e1b408..095f70807e 100644 --- a/core/client/app/routes/mobile-index-route.js +++ b/core/client/app/routes/mobile-index-route.js @@ -17,14 +17,14 @@ var MobileIndexRoute = Ember.Route.extend({ mobileQuery.removeListener(this.desktopTransitionMQ); }, - setDesktopTransitionMQ: function () { + setDesktopTransitionMQ: Ember.on('init', function () { var self = this; this.set('desktopTransitionMQ', function desktopTransitionMQ() { if (!mobileQuery.matches) { self.desktopTransition(); } }); - }.on('init') + }) }); export default MobileIndexRoute; diff --git a/core/client/app/views/application.js b/core/client/app/views/application.js index 697e55078f..309a85f61e 100644 --- a/core/client/app/views/application.js +++ b/core/client/app/views/application.js @@ -3,7 +3,7 @@ import Ember from 'ember'; export default Ember.View.extend({ classNames: 'gh-app', - toggleSettingsMenuBodyClass: function () { + toggleSettingsMenuBodyClass: Ember.observer('controller.showSettingsMenu', function () { $('body').toggleClass('settings-menu-expanded', this.get('controller.showSettingsMenu')); - }.observes('controller.showSettingsMenu') + }) }); diff --git a/core/client/app/views/content-preview-content-view.js b/core/client/app/views/content-preview-content-view.js index b11980d941..89376ce066 100644 --- a/core/client/app/views/content-preview-content-view.js +++ b/core/client/app/views/content-preview-content-view.js @@ -12,13 +12,13 @@ var PostContentView = Ember.View.extend({ })); }, - contentObserver: function () { + contentObserver: Ember.observer('controller.content', function () { var el = this.$(); if (el) { el.closest('.content-preview').scrollTop(0); } - }.observes('controller.content'), + }), willDestroyElement: function () { var el = this.$(); diff --git a/core/client/app/views/editor/edit.js b/core/client/app/views/editor/edit.js index 386eb40a7a..10f5d98600 100644 --- a/core/client/app/views/editor/edit.js +++ b/core/client/app/views/editor/edit.js @@ -13,7 +13,11 @@ var EditorViewMixin = Ember.View.extend({ // http://emberjs.com/api/classes/Ember.run.html#method_next scheduleAfterRender: function () { Ember.run.scheduleOnce('afterRender', this, this.afterRenderEvent); - }.on('didInsertElement'), + }, + + didInsertElement: function () { + this.scheduleAfterRender(); + }, // all child views will have rendered when this fires afterRenderEvent: function () { @@ -29,9 +33,10 @@ var EditorViewMixin = Ember.View.extend({ })); }, - removeScrollHandlers: function () { + willDestroyElement: function () { + // removes scroll handlers from the view this.get('$previewViewPort').off('scroll'); - }.on('willDestroyElement'), + }, // updated when gh-ed-editor component scrolls editorScrollInfo: null, diff --git a/core/client/app/views/paginated-scroll-box.js b/core/client/app/views/paginated-scroll-box.js index d898ea1845..66ae875cfa 100644 --- a/core/client/app/views/paginated-scroll-box.js +++ b/core/client/app/views/paginated-scroll-box.js @@ -3,17 +3,25 @@ import setScrollClassName from 'ghost/utils/set-scroll-classname'; import PaginationViewMixin from 'ghost/mixins/pagination-view-infinite-scroll'; var PaginatedScrollBox = Ember.View.extend(PaginationViewMixin, { + /** + * attach the scroll class handler event + */ attachScrollClassHandler: function () { var el = this.$(); el.on('scroll', Ember.run.bind(el, setScrollClassName, { target: el.closest('.content-list'), offset: 10 })); - }.on('didInsertElement'), + }, - detachScrollClassHandler: function () { + didInsertElement: function () { + this.attachScrollClassHandler(); + }, + + willDestroyElement: function () { + // removes scroll class handler event this.$().off('scroll'); - }.on('willDestroyElement') + } }); export default PaginatedScrollBox; diff --git a/core/client/app/views/post-item-view.js b/core/client/app/views/post-item-view.js index dcf9d88a26..43b6c03e2a 100644 --- a/core/client/app/views/post-item-view.js +++ b/core/client/app/views/post-item-view.js @@ -42,12 +42,14 @@ var PostItemView = Ember.View.extend({ }); } }, - removeScrollBehaviour: function () { + willDestroyElement: function () { + // removes the scrollIntoView observer this.removeObserver('active', this, this.scrollIntoView); - }.on('willDestroyElement'), - addScrollBehaviour: function () { + }, + didInsertElement: function () { + // adds the scrollIntoView observer this.addObserver('active', this, this.scrollIntoView); - }.on('didInsertElement') + } }); export default PostItemView;