mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 03:14:03 +03:00
removes usage of prototype extensions
No issue - removes more usage of function prototype extensions in favor of Ember functions - replaces some event calls with the direct function name - adds comments to functions replaced with the event name
This commit is contained in:
parent
3448dcc8c5
commit
45f3c513d5
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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')
|
||||
})
|
||||
});
|
||||
|
@ -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.$();
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user