mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-30 11:54:33 +03:00
00bbf070b2
In later versions of Ember, the views and components can be stable and are not guaranteed to be torn down before a new controller is set on them. In this case, the controller is initially set before the element has been rendered to the DOM causing errors when invoking `closest` on undefined.
30 lines
728 B
JavaScript
30 lines
728 B
JavaScript
import Ember from 'ember';
|
|
import setScrollClassName from 'ghost/utils/set-scroll-classname';
|
|
|
|
var PostContentView = Ember.View.extend({
|
|
classNames: ['content-preview-content'],
|
|
|
|
didInsertElement: function () {
|
|
var el = this.$();
|
|
el.on('scroll', Ember.run.bind(el, setScrollClassName, {
|
|
target: el.closest('.content-preview'),
|
|
offset: 10
|
|
}));
|
|
},
|
|
|
|
contentObserver: function () {
|
|
var el = this.$();
|
|
|
|
if (el) {
|
|
el.closest('.content-preview').scrollTop(0);
|
|
}
|
|
}.observes('controller.content'),
|
|
|
|
willDestroyElement: function () {
|
|
var el = this.$();
|
|
el.off('scroll');
|
|
}
|
|
});
|
|
|
|
export default PostContentView;
|