mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-16 12:16:09 +03:00
eb949aafae
closes #2426, closes #2781, closes #2913 - Concatenate vendor files on change of js in core/shared/ - Add all the markerManager stuff to its own mixin - make markers a shared object for all that mix it in. makes it easier to use helper functions in different modules - add getMarkdown method, returns object with two keys holding the markdown: one with markers, the other without - Clear markers when codemirror is destroyed - make Editor subcomponents communicate through the Editor Controller - Set Codemirror and html preview shared scrolling - Set CodeMirror, html preview css scroll class with util - Create 'scratch' property in Editor controller; prevents a model save wiping image markers due to markdown bindings - Add editor and html preview actions to handle img upload start/finish - disable codemirror when an image is being uploaded, enables on success or failure - Fix editor wordcount when there are 0 words - Add modal dialog when transitioning out of the editor with an unsaved post - Add window.onbeforeunload handling with `.unloadDirtyMessage()` on editor controller - and various other things
59 lines
2.2 KiB
JavaScript
59 lines
2.2 KiB
JavaScript
import setScrollClassName from 'ghost/utils/set-scroll-classname';
|
|
|
|
var EditorViewMixin = Ember.Mixin.create({
|
|
// create a hook for jQuery logic that will run after
|
|
// a view and all child views have been rendered,
|
|
// since didInsertElement runs only when the view's el
|
|
// has rendered, and not necessarily all child views.
|
|
//
|
|
// http://mavilein.github.io/javascript/2013/08/01/Ember-JS-After-Render-Event/
|
|
// http://emberjs.com/api/classes/Ember.run.html#method_next
|
|
scheduleAfterRender: function () {
|
|
Ember.run.scheduleOnce('afterRender', this, this.afterRenderEvent);
|
|
}.on('didInsertElement'),
|
|
|
|
// all child views will have rendered when this fires
|
|
afterRenderEvent: function () {
|
|
var $previewViewPort = this.$('.entry-preview-content');
|
|
|
|
// cache these elements for use in other methods
|
|
this.set('$previewViewPort', $previewViewPort);
|
|
this.set('$previewContent', this.$('.rendered-markdown'));
|
|
|
|
$previewViewPort.scroll(Ember.run.bind($previewViewPort, setScrollClassName, {
|
|
target: this.$('.entry-preview'),
|
|
offset: 10
|
|
}));
|
|
},
|
|
|
|
removeScrollHandlers: function () {
|
|
this.get('$previewViewPort').off('scroll');
|
|
}.on('willDestroyElement'),
|
|
|
|
// updated when gh-codemirror component scrolls
|
|
markdownScrollInfo: null,
|
|
|
|
// percentage of scroll position to set htmlPreview
|
|
scrollPosition: Ember.computed('markdownScrollInfo', function () {
|
|
if (!this.get('markdownScrollInfo')) {
|
|
return 0;
|
|
}
|
|
|
|
var scrollInfo = this.get('markdownScrollInfo'),
|
|
codemirror = scrollInfo.codemirror,
|
|
markdownHeight = scrollInfo.height - scrollInfo.clientHeight,
|
|
previewHeight = this.get('$previewContent').height() - this.get('$previewViewPort').height(),
|
|
ratio = previewHeight / markdownHeight,
|
|
previewPosition = scrollInfo.top * ratio,
|
|
isCursorAtEnd = codemirror.getCursor('end').line > codemirror.lineCount() - 5;
|
|
|
|
if (isCursorAtEnd) {
|
|
previewPosition = previewHeight + 30;
|
|
}
|
|
|
|
return previewPosition;
|
|
})
|
|
});
|
|
|
|
export default EditorViewMixin;
|