2015-02-12 21:22:32 -07:00
|
|
|
import Ember from 'ember';
|
2014-12-31 21:06:05 -05:00
|
|
|
var PostItemView = Ember.View.extend({
|
|
|
|
classNameBindings: ['active', 'isFeatured:featured', 'isPage:page'],
|
2014-03-02 15:30:35 +01:00
|
|
|
|
2014-12-31 21:06:05 -05:00
|
|
|
active: null,
|
2014-06-16 05:44:07 +00:00
|
|
|
|
2014-06-17 14:20:54 -06:00
|
|
|
isFeatured: Ember.computed.alias('controller.model.featured'),
|
2014-06-16 05:44:07 +00:00
|
|
|
|
2014-06-17 14:20:54 -06:00
|
|
|
isPage: Ember.computed.alias('controller.model.page'),
|
2014-09-09 19:22:11 -06:00
|
|
|
|
2014-06-21 08:44:53 -06:00
|
|
|
doubleClick: function () {
|
2014-09-15 22:55:37 -06:00
|
|
|
this.get('controller').send('openEditor');
|
2014-09-09 19:22:11 -06:00
|
|
|
},
|
|
|
|
|
|
|
|
click: function () {
|
|
|
|
this.get('controller').send('showPostContent');
|
2014-10-27 14:29:27 -06:00
|
|
|
},
|
|
|
|
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;
|
2014-09-09 19:22:11 -06:00
|
|
|
|
2014-10-27 14:29:27 -06:00
|
|
|
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
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2015-06-02 20:56:42 -06:00
|
|
|
willDestroyElement: function () {
|
|
|
|
// removes the scrollIntoView observer
|
2014-10-27 14:29:27 -06:00
|
|
|
this.removeObserver('active', this, this.scrollIntoView);
|
2015-06-02 20:56:42 -06:00
|
|
|
},
|
|
|
|
didInsertElement: function () {
|
|
|
|
// adds the scrollIntoView observer
|
2014-10-27 14:29:27 -06:00
|
|
|
this.addObserver('active', this, this.scrollIntoView);
|
2015-06-02 20:56:42 -06:00
|
|
|
}
|
2014-03-03 21:18:10 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
export default PostItemView;
|