mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-14 18:52:05 +03:00
86e47ee4a9
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
56 lines
1.7 KiB
JavaScript
56 lines
1.7 KiB
JavaScript
import Ember from 'ember';
|
|
var PostItemView = Ember.View.extend({
|
|
classNameBindings: ['active', 'isFeatured:featured', 'isPage:page'],
|
|
|
|
active: null,
|
|
|
|
isFeatured: Ember.computed.alias('controller.model.featured'),
|
|
|
|
isPage: Ember.computed.alias('controller.model.page'),
|
|
|
|
doubleClick: function () {
|
|
this.get('controller').send('openEditor');
|
|
},
|
|
|
|
click: function () {
|
|
this.get('controller').send('showPostContent');
|
|
},
|
|
scrollIntoView: function () {
|
|
if (!this.get('active')) {
|
|
return;
|
|
}
|
|
var element = this.$(),
|
|
offset = element.offset().top,
|
|
elementHeight = element.height(),
|
|
container = Ember.$('.js-content-scrollbox'),
|
|
containerHeight = container.height(),
|
|
currentScroll = container.scrollTop(),
|
|
isBelowTop,
|
|
isAboveBottom,
|
|
isOnScreen;
|
|
|
|
isAboveBottom = offset < containerHeight;
|
|
isBelowTop = offset > elementHeight;
|
|
|
|
isOnScreen = isBelowTop && isAboveBottom;
|
|
|
|
if (!isOnScreen) {
|
|
// Scroll so that element is centered in container
|
|
// 40 is the amount of padding on the container
|
|
container.clearQueue().animate({
|
|
scrollTop: currentScroll + offset - 40 - containerHeight / 2
|
|
});
|
|
}
|
|
},
|
|
willDestroyElement: function () {
|
|
// removes the scrollIntoView observer
|
|
this.removeObserver('active', this, this.scrollIntoView);
|
|
},
|
|
didInsertElement: function () {
|
|
// adds the scrollIntoView observer
|
|
this.addObserver('active', this, this.scrollIntoView);
|
|
}
|
|
});
|
|
|
|
export default PostItemView;
|