2015-01-01 05:06:05 +03:00
|
|
|
var PostItemView = Ember.View.extend({
|
|
|
|
classNameBindings: ['active', 'isFeatured:featured', 'isPage:page'],
|
2014-03-02 18:30:35 +04:00
|
|
|
|
2015-01-01 05:06:05 +03:00
|
|
|
active: null,
|
2014-06-16 09:44:07 +04:00
|
|
|
|
2014-06-18 00:20:54 +04:00
|
|
|
isFeatured: Ember.computed.alias('controller.model.featured'),
|
2014-06-16 09:44:07 +04:00
|
|
|
|
2014-06-18 00:20:54 +04:00
|
|
|
isPage: Ember.computed.alias('controller.model.page'),
|
2014-09-10 05:22:11 +04:00
|
|
|
|
2014-06-21 18:44:53 +04:00
|
|
|
doubleClick: function () {
|
2014-09-16 08:55:37 +04:00
|
|
|
this.get('controller').send('openEditor');
|
2014-09-10 05:22:11 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
click: function () {
|
|
|
|
this.get('controller').send('showPostContent');
|
2014-10-27 23:29:27 +03: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-10 05:22:11 +04:00
|
|
|
|
2014-10-27 23:29:27 +03: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
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
removeScrollBehaviour: function () {
|
|
|
|
this.removeObserver('active', this, this.scrollIntoView);
|
|
|
|
}.on('willDestroyElement'),
|
|
|
|
addScrollBehaviour: function () {
|
|
|
|
this.addObserver('active', this, this.scrollIntoView);
|
|
|
|
}.on('didInsertElement')
|
2014-03-04 00:18:10 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
export default PostItemView;
|