2015-02-13 07:22:32 +03:00
|
|
|
import Ember from 'ember';
|
2015-06-13 20:53:43 +03:00
|
|
|
import setScrollClassName from 'ghost/utils/set-scroll-classname';
|
2014-06-06 05:18:03 +04:00
|
|
|
|
2015-06-13 17:34:09 +03:00
|
|
|
export default Ember.Component.extend({
|
2014-05-31 22:32:22 +04:00
|
|
|
tagName: 'section',
|
2015-06-13 20:53:43 +03:00
|
|
|
classNames: ['gh-view'],
|
2015-06-13 17:34:09 +03:00
|
|
|
|
2015-06-13 20:53:43 +03:00
|
|
|
scheduleAfterRender: function () {
|
|
|
|
Ember.run.scheduleOnce('afterRender', this, this.afterRenderEvent);
|
2015-06-03 05:56:42 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
didInsertElement: function () {
|
|
|
|
this.scheduleAfterRender();
|
|
|
|
},
|
2015-06-13 20:53:43 +03:00
|
|
|
|
|
|
|
afterRenderEvent: function () {
|
|
|
|
var $previewViewPort = this.$('.js-entry-preview-content');
|
|
|
|
|
|
|
|
// cache these elements for use in other methods
|
|
|
|
this.set('$previewViewPort', $previewViewPort);
|
|
|
|
this.set('$previewContent', this.$('.js-rendered-markdown'));
|
|
|
|
|
|
|
|
$previewViewPort.on('scroll', Ember.run.bind($previewViewPort, setScrollClassName, {
|
|
|
|
target: this.$('.js-entry-preview'),
|
|
|
|
offset: 10
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
2015-06-03 05:56:42 +03:00
|
|
|
willDestroyElement: function () {
|
|
|
|
// removes scroll handlers from the view
|
2015-06-13 20:53:43 +03:00
|
|
|
this.get('$previewViewPort').off('scroll');
|
2015-06-03 05:56:42 +03:00
|
|
|
},
|
2015-06-13 20:53:43 +03:00
|
|
|
|
|
|
|
// updated when gh-ed-editor component scrolls
|
|
|
|
editorScrollInfo: null,
|
|
|
|
// updated when markdown is rendered
|
|
|
|
height: null,
|
|
|
|
|
|
|
|
// HTML Preview listens to scrollPosition and updates its scrollTop value
|
|
|
|
// This property receives scrollInfo from the textEditor, and height from the preview pane, and will update the
|
|
|
|
// scrollPosition value such that when either scrolling or typing-at-the-end of the text editor the preview pane
|
|
|
|
// stays in sync
|
|
|
|
scrollPosition: Ember.computed('editorScrollInfo', 'height', function () {
|
2015-08-19 21:59:59 +03:00
|
|
|
if (!this.get('editorScrollInfo') || !this.get('$previewContent') || !this.get('$previewViewPort')) {
|
2015-06-13 20:53:43 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
var scrollInfo = this.get('editorScrollInfo'),
|
|
|
|
previewHeight = this.get('$previewContent').height() - this.get('$previewViewPort').height(),
|
|
|
|
previewPosition,
|
|
|
|
ratio;
|
|
|
|
|
|
|
|
ratio = previewHeight / scrollInfo.diff;
|
|
|
|
previewPosition = scrollInfo.top * ratio;
|
|
|
|
|
|
|
|
return previewPosition;
|
|
|
|
})
|
2014-06-08 10:02:21 +04:00
|
|
|
});
|