1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00
Ghost-Admin/views/post-item-view.js
Robert Jackson 33322e7ec3 Cleanup posts template.
No issue.

* Fix indentation (it was surprisingly hard for me to grok what was happening
  without indentation).
* Utilize `alternateActive` from `core/client/utils/link-view.js` to
  maintain the `active` state. Observing `childViews` is deprecated (and
  may not work properly in future versions of Ember).
* Remove now unused `item-view`.
2014-12-31 21:06:05 -05:00

53 lines
1.6 KiB
JavaScript

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
});
}
},
removeScrollBehaviour: function () {
this.removeObserver('active', this, this.scrollIntoView);
}.on('willDestroyElement'),
addScrollBehaviour: function () {
this.addObserver('active', this, this.scrollIntoView);
}.on('didInsertElement')
});
export default PostItemView;