Focus on editor if transitioning from new post

Closes #5383
This commit is contained in:
Jason Williams 2015-07-04 13:25:55 -05:00
parent e693d5ed2d
commit 7d3c0fb18b
4 changed files with 26 additions and 3 deletions

View File

@ -30,6 +30,9 @@ export default Ember.Mixin.create({
};
},
shouldFocusTitle: Ember.computed.alias('model.isNew'),
shouldFocusEditor: false,
autoSave: Ember.observer('model.scratch', function () {
// Don't save just because we swapped out models
if (this.get('model.isDraft') && !this.get('model.isNew')) {
@ -229,8 +232,6 @@ export default Ember.Mixin.create({
notifications.showError(message.htmlSafe(), {delayed: delay});
},
shouldFocusTitle: Ember.computed.alias('model.isNew'),
actions: {
save: function (options) {
var status,

View File

@ -6,6 +6,12 @@ import isFinite from 'ghost/utils/isFinite';
var EditorEditRoute = AuthenticatedRoute.extend(base, {
titleToken: 'Editor',
beforeModel: function (transition) {
this.set('_transitionedFromNew', transition.data.fromNew);
this._super(...arguments);
},
model: function (params) {
var self = this,
postId,
@ -44,6 +50,12 @@ var EditorEditRoute = AuthenticatedRoute.extend(base, {
});
},
setupController: function (controller/*, model */) {
this._super(...arguments);
controller.set('shouldFocusEditor', this.get('_transitionedFromNew'));
},
actions: {
authorizationFailed: function () {
this.send('openModal', 'signin');

View File

@ -38,5 +38,15 @@ export default AuthenticatedRoute.extend(base, {
psm.send('resetPubDate');
this._super(controller, model);
},
actions: {
willTransition: function (transition) {
// decorate the transition object so the editor.edit route
// knows this was the previous active route
transition.data.fromNew = true;
this._super(...arguments);
}
}
});

View File

@ -27,7 +27,7 @@
<a class="markdown-help" href="" {{action "openModal" "markdown"}}><i class="icon-markdown"></i></a>
</header>
<section id="entry-markdown-content" class="entry-markdown-content">
{{gh-ed-editor classNames="markdown-editor js-markdown-editor" tabindex="1" spellcheck="true" value=model.scratch setEditor="setEditor" updateScrollInfo="updateEditorScrollInfo" openModal="openModal" onFocusIn="autoSaveNew" height=height}}
{{gh-ed-editor classNames="markdown-editor js-markdown-editor" tabindex="1" spellcheck="true" value=model.scratch setEditor="setEditor" updateScrollInfo="updateEditorScrollInfo" openModal="openModal" onFocusIn="autoSaveNew" height=height focus=shouldFocusEditor}}
</section>
</section>