From 30cd943690de69e6f982a9a1f87e95d007466fda Mon Sep 17 00:00:00 2001 From: Nazar Gargol Date: Tue, 25 Nov 2014 23:34:55 +0100 Subject: [PATCH] Adds ctrl/cmd+s shortcut to whole application with a noop default closes #4516 - shortcut for ctrl/cmd+s on application level - shortens a syntax for any route that is using 'save' method, shortcuts object doesn't have to be defined at all, only the save action. --- ghost/admin/mixins/shortcuts-route.js | 5 ----- ghost/admin/routes/application.js | 21 ++++++++++++------- ghost/admin/routes/settings/code-injection.js | 11 +--------- ghost/admin/routes/settings/general.js | 11 +--------- ghost/admin/routes/settings/users/user.js | 11 +--------- ghost/admin/utils/editor-shortcuts.js | 1 - 6 files changed, 17 insertions(+), 43 deletions(-) diff --git a/ghost/admin/mixins/shortcuts-route.js b/ghost/admin/mixins/shortcuts-route.js index d3916ec82e..1ae52becef 100644 --- a/ghost/admin/mixins/shortcuts-route.js +++ b/ghost/admin/mixins/shortcuts-route.js @@ -74,11 +74,6 @@ var ShortcutsRoute = Ember.Mixin.create({ activate: function () { this._super(); - - if (!this.shortcuts) { - return; - } - this.registerShortcuts(); }, diff --git a/ghost/admin/routes/application.js b/ghost/admin/routes/application.js index b578805bef..efae553d1b 100644 --- a/ghost/admin/routes/application.js +++ b/ghost/admin/routes/application.js @@ -1,7 +1,16 @@ /* global key */ import ShortcutsRoute from 'ghost/mixins/shortcuts-route'; +import ctrlOrCmd from 'ghost/utils/ctrl-or-cmd'; -var ApplicationRoute = Ember.Route.extend(SimpleAuth.ApplicationRouteMixin, ShortcutsRoute, { +var ApplicationRoute, + shortcuts = {}; + +shortcuts.esc = {action: 'closePopups', scope: 'all'}; +shortcuts.enter = {action: 'confirmModal', scope: 'modal'}; +shortcuts[ctrlOrCmd + '+s'] = {action: 'save', scope: 'all'}; + +ApplicationRoute = Ember.Route.extend(SimpleAuth.ApplicationRouteMixin, ShortcutsRoute, { + shortcuts: shortcuts, afterModel: function (model, transition) { if (this.get('session').isAuthenticated) { @@ -9,11 +18,6 @@ var ApplicationRoute = Ember.Route.extend(SimpleAuth.ApplicationRouteMixin, Shor } }, - shortcuts: { - esc: {action: 'closePopups', scope: 'all'}, - enter: {action: 'confirmModal', scope: 'modal'} - }, - title: function (tokens) { return tokens.join(' - ') + ' - ' + this.get('config.blogTitle'); }, @@ -155,7 +159,10 @@ var ApplicationRoute = Ember.Route.extend(SimpleAuth.ApplicationRouteMixin, Shor errorObj.el.addClass('input-error'); } }); - } + }, + + // noop default for unhandled save (used from shortcuts) + save: Ember.K } }); diff --git a/ghost/admin/routes/settings/code-injection.js b/ghost/admin/routes/settings/code-injection.js index 4c7742a70c..2d1f4f3c1d 100644 --- a/ghost/admin/routes/settings/code-injection.js +++ b/ghost/admin/routes/settings/code-injection.js @@ -2,15 +2,8 @@ import AuthenticatedRoute from 'ghost/routes/authenticated'; import loadingIndicator from 'ghost/mixins/loading-indicator'; import CurrentUserSettings from 'ghost/mixins/current-user-settings'; import styleBody from 'ghost/mixins/style-body'; -import ShortcutsRoute from 'ghost/mixins/shortcuts-route'; -import ctrlOrCmd from 'ghost/utils/ctrl-or-cmd'; -var shortcuts = {}, - SettingsCodeInjectionRoute; - -shortcuts[ctrlOrCmd + '+s'] = {action: 'save'}; - -SettingsCodeInjectionRoute = AuthenticatedRoute.extend(styleBody, loadingIndicator, CurrentUserSettings, ShortcutsRoute, { +var SettingsCodeInjectionRoute = AuthenticatedRoute.extend(styleBody, loadingIndicator, CurrentUserSettings, { classNames: ['settings-view-code'], beforeModel: function () { @@ -25,8 +18,6 @@ SettingsCodeInjectionRoute = AuthenticatedRoute.extend(styleBody, loadingIndicat }); }, - shortcuts: shortcuts, - actions: { save: function () { this.get('controller').send('save'); diff --git a/ghost/admin/routes/settings/general.js b/ghost/admin/routes/settings/general.js index 9e0fa1afd9..4d794a277f 100644 --- a/ghost/admin/routes/settings/general.js +++ b/ghost/admin/routes/settings/general.js @@ -2,15 +2,8 @@ import AuthenticatedRoute from 'ghost/routes/authenticated'; import loadingIndicator from 'ghost/mixins/loading-indicator'; import CurrentUserSettings from 'ghost/mixins/current-user-settings'; import styleBody from 'ghost/mixins/style-body'; -import ShortcutsRoute from 'ghost/mixins/shortcuts-route'; -import ctrlOrCmd from 'ghost/utils/ctrl-or-cmd'; -var shortcuts = {}, - SettingsGeneralRoute; - -shortcuts[ctrlOrCmd + '+s'] = {action: 'save'}; - -SettingsGeneralRoute = AuthenticatedRoute.extend(styleBody, loadingIndicator, CurrentUserSettings, ShortcutsRoute, { +var SettingsGeneralRoute = AuthenticatedRoute.extend(styleBody, loadingIndicator, CurrentUserSettings, { titleToken: 'General', classNames: ['settings-view-general'], @@ -27,8 +20,6 @@ SettingsGeneralRoute = AuthenticatedRoute.extend(styleBody, loadingIndicator, Cu }); }, - shortcuts: shortcuts, - actions: { save: function () { this.get('controller').send('save'); diff --git a/ghost/admin/routes/settings/users/user.js b/ghost/admin/routes/settings/users/user.js index b6f1f21db0..418352f095 100644 --- a/ghost/admin/routes/settings/users/user.js +++ b/ghost/admin/routes/settings/users/user.js @@ -1,14 +1,7 @@ import AuthenticatedRoute from 'ghost/routes/authenticated'; import styleBody from 'ghost/mixins/style-body'; -import ShortcutsRoute from 'ghost/mixins/shortcuts-route'; -import ctrlOrCmd from 'ghost/utils/ctrl-or-cmd'; -var shortcuts = {}, - SettingsUserRoute; - -shortcuts[ctrlOrCmd + '+s'] = {action: 'save'}; - -SettingsUserRoute = AuthenticatedRoute.extend(styleBody, ShortcutsRoute, { +var SettingsUserRoute = AuthenticatedRoute.extend(styleBody, { titleToken: 'User', classNames: ['settings-view-user'], @@ -55,8 +48,6 @@ SettingsUserRoute = AuthenticatedRoute.extend(styleBody, ShortcutsRoute, { this._super(); }, - shortcuts: shortcuts, - actions: { save: function () { this.get('controller').send('save'); diff --git a/ghost/admin/utils/editor-shortcuts.js b/ghost/admin/utils/editor-shortcuts.js index f6ee24ac6d..5fd39e4c0d 100644 --- a/ghost/admin/utils/editor-shortcuts.js +++ b/ghost/admin/utils/editor-shortcuts.js @@ -3,7 +3,6 @@ import ctrlOrCmd from 'ghost/utils/ctrl-or-cmd'; var shortcuts = {}; // General editor shortcuts -shortcuts[ctrlOrCmd + '+s'] = 'save'; shortcuts[ctrlOrCmd + '+alt+p'] = 'publish'; shortcuts['alt+shift+z'] = 'toggleZenMode';