mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
More autosave improvements
issue #4305, issue #4259, issue #1413 - change new->edit transitionToRoute to be replaceRoute - auto focus in the editor on transition to the edit route - change the one-time autosave to happen on codemirror focusin instead of title focusout - re-add removed tests, and reorder broken test
This commit is contained in:
parent
0f9342bf69
commit
768e335735
6 changed files with 21 additions and 9 deletions
|
@ -38,6 +38,14 @@ var onScrollHandler = function (cm) {
|
||||||
};
|
};
|
||||||
|
|
||||||
var Codemirror = Ember.TextArea.extend(MarkerManager, {
|
var Codemirror = Ember.TextArea.extend(MarkerManager, {
|
||||||
|
focus: true,
|
||||||
|
|
||||||
|
setFocus: function () {
|
||||||
|
if (this.focus) {
|
||||||
|
this.$().val(this.$().val()).focus();
|
||||||
|
}
|
||||||
|
}.on('didInsertElement'),
|
||||||
|
|
||||||
didInsertElement: function () {
|
didInsertElement: function () {
|
||||||
Ember.run.scheduleOnce('afterRender', this, this.afterRenderEvent);
|
Ember.run.scheduleOnce('afterRender', this, this.afterRenderEvent);
|
||||||
},
|
},
|
||||||
|
@ -90,6 +98,10 @@ var Codemirror = Ember.TextArea.extend(MarkerManager, {
|
||||||
offset: 10
|
offset: 10
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
codemirror.on('focus', function () {
|
||||||
|
codemirror.component.sendAction('onFocusIn');
|
||||||
|
});
|
||||||
|
|
||||||
this.set('codemirror', codemirror);
|
this.set('codemirror', codemirror);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,6 @@ var TrimFocusInput = Ember.TextField.extend({
|
||||||
var text = this.$().val();
|
var text = this.$().val();
|
||||||
|
|
||||||
this.$().val(text.trim());
|
this.$().val(text.trim());
|
||||||
|
|
||||||
this.sendAction('onFocusOut');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ var EditorNewController = Ember.ObjectController.extend(EditorControllerMixin, {
|
||||||
var self = this;
|
var self = this;
|
||||||
return this._super(options).then(function (model) {
|
return this._super(options).then(function (model) {
|
||||||
if (model.get('id')) {
|
if (model.get('id')) {
|
||||||
self.transitionToRoute('editor.edit', model);
|
self.replaceRoute('editor.edit', model);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,6 +187,7 @@ var EditorControllerMixin = Ember.Mixin.create(MarkerManager, {
|
||||||
},
|
},
|
||||||
|
|
||||||
shouldFocusTitle: Ember.computed.alias('model.isNew'),
|
shouldFocusTitle: Ember.computed.alias('model.isNew'),
|
||||||
|
shouldFocusEditor: Ember.computed.not('model.isNew'),
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
save: function (options) {
|
save: function (options) {
|
||||||
|
@ -210,6 +211,7 @@ var EditorControllerMixin = Ember.Mixin.create(MarkerManager, {
|
||||||
if (!this.get('titleScratch')) {
|
if (!this.get('titleScratch')) {
|
||||||
this.set('titleScratch', '(Untitled)');
|
this.set('titleScratch', '(Untitled)');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.set('title', this.get('titleScratch'));
|
this.set('title', this.get('titleScratch'));
|
||||||
|
|
||||||
return this.get('model').save(options).then(function (model) {
|
return this.get('model').save(options).then(function (model) {
|
||||||
|
@ -298,7 +300,7 @@ var EditorControllerMixin = Ember.Mixin.create(MarkerManager, {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
autoSaveOnce: function () {
|
autoSaveNew: function () {
|
||||||
if (this.get('isNew')) {
|
if (this.get('isNew')) {
|
||||||
this.send('autoSave');
|
this.send('autoSave');
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
<div class="page-content">
|
<div class="page-content">
|
||||||
<header>
|
<header>
|
||||||
<section class="box entry-title">
|
<section class="box entry-title">
|
||||||
{{gh-trim-focus-input type="text" id="entry-title" placeholder="Your Post Title" value=titleScratch tabindex="1" focus=shouldFocusTitle onFocusOut="autoSaveOnce"}}
|
{{gh-trim-focus-input type="text" id="entry-title" placeholder="Your Post Title" value=titleScratch
|
||||||
|
tabindex="1" focus=shouldFocusTitle}}
|
||||||
</section>
|
</section>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
|
@ -17,9 +18,8 @@
|
||||||
</header>
|
</header>
|
||||||
<section id="entry-markdown-content" class="entry-markdown-content">
|
<section id="entry-markdown-content" class="entry-markdown-content">
|
||||||
{{gh-codemirror value=scratch scrollInfo=view.markdownScrollInfo
|
{{gh-codemirror value=scratch scrollInfo=view.markdownScrollInfo
|
||||||
setCodeMirror="setCodeMirror"
|
setCodeMirror="setCodeMirror" openModal="openModal" typingPause="autoSave"
|
||||||
openModal="openModal"
|
focus=shouldFocusEditor onFocusIn="autoSaveNew"}}
|
||||||
typingPause="autoSave"}}
|
|
||||||
</section>
|
</section>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ var EditorSaveButtonView = Ember.View.extend({
|
||||||
|
|
||||||
'saveText': Ember.computed('controller.willPublish', function () {
|
'saveText': Ember.computed('controller.willPublish', function () {
|
||||||
return this.get('controller.willPublish') ? this.get('publishText') : this.get('draftText');
|
return this.get('controller.willPublish') ? this.get('publishText') : this.get('draftText');
|
||||||
}),
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
export default EditorSaveButtonView;
|
export default EditorSaveButtonView;
|
||||||
|
|
Loading…
Add table
Reference in a new issue