Merge pull request #5517 from jaswilli/issue-5383

Focus on editor if transitioning from new post
This commit is contained in:
Hannah Wolfe 2015-07-11 12:39:56 +01:00
commit 62c89404ac
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>