From 6c3f1c0e324bb78fc6b9402604a5a709f69fc63f Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Thu, 2 Mar 2017 13:04:55 +0100 Subject: [PATCH] add mac/win versions of keyboard shortcuts --- .../umbkeyboardshortcutsoverview.directive.js | 88 ++++++++++++++----- .../src/common/services/platform.service.js | 23 +++++ .../common/services/templatehelper.service.js | 10 ++- .../umb-keyboard-shortcuts-overview.html | 2 +- 4 files changed, 96 insertions(+), 27 deletions(-) create mode 100644 src/Umbraco.Web.UI.Client/src/common/services/platform.service.js diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/umbkeyboardshortcutsoverview.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/umbkeyboardshortcutsoverview.directive.js index 703b20daca..1d8f5b0fec 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/umbkeyboardshortcutsoverview.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/umbkeyboardshortcutsoverview.directive.js @@ -107,36 +107,76 @@ When this combination is hit an overview is opened with shortcuts based on the m @param {object} model keyboard shortcut model. See description and example above. **/ -(function() { - 'use strict'; +(function () { + 'use strict'; - function KeyboardShortcutsOverviewDirective() { + function KeyboardShortcutsOverviewDirective(platformService) { - function link(scope, el, attr, ctrl) { + function link(scope, el, attr, ctrl) { - scope.toggleShortcutsOverlay = function() { - scope.showOverlay = !scope.showOverlay; - scope.onToggle(); - }; + var eventBindings = []; + var isMac = platformService.isMac(); + scope.toggleShortcutsOverlay = function () { + scope.showOverlay = !scope.showOverlay; + scope.onToggle(); + }; + function onInit() { + + angular.forEach(scope.model, function (shortcutGroup) { + angular.forEach(shortcutGroup.shortcuts, function (shortcut) { + + shortcut.platformKeys = []; + + // get shortcut keys for mac + if (isMac && shortcut.keys && shortcut.keys.mac) { + shortcut.platformKeys = shortcut.keys.mac; + // get shortcut keys for windows + } else if (!isMac && shortcut.keys && shortcut.keys.win) { + shortcut.platformKeys = shortcut.keys.win; + // get default shortcut keys + } else if (shortcut.keys && shortcut && shortcut.keys.length > 0) { + shortcut.platformKeys = shortcut.keys; + } + + }); + }); + } + + onInit(); + + eventBindings.push(scope.$watch('model', function(newValue, oldValue){ + if (newValue !== oldValue) { + onInit(); + } + })); + + // clean up + scope.$on('$destroy', function () { + // unbind watchers + for (var e in eventBindings) { + eventBindings[e](); + } + }); + + } + + var directive = { + restrict: 'E', + replace: true, + templateUrl: 'views/components/umb-keyboard-shortcuts-overview.html', + link: link, + scope: { + model: "=", + onToggle: "&", + showOverlay: "=" + } + }; + + return directive; } - var directive = { - restrict: 'E', - replace: true, - templateUrl: 'views/components/umb-keyboard-shortcuts-overview.html', - link: link, - scope: { - model: "=", - onToggle: "&", - showOverlay: "=" - } - }; - - return directive; - } - - angular.module('umbraco.directives').directive('umbKeyboardShortcutsOverview', KeyboardShortcutsOverviewDirective); + angular.module('umbraco.directives').directive('umbKeyboardShortcutsOverview', KeyboardShortcutsOverviewDirective); })(); diff --git a/src/Umbraco.Web.UI.Client/src/common/services/platform.service.js b/src/Umbraco.Web.UI.Client/src/common/services/platform.service.js new file mode 100644 index 0000000000..7834c2f781 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/common/services/platform.service.js @@ -0,0 +1,23 @@ +(function() { + 'use strict'; + + function platformService() { + + function isMac() { + return navigator.platform.toUpperCase().indexOf('MAC')>=0; + } + + //////////// + + var service = { + isMac: isMac + }; + + return service; + + } + + angular.module('umbraco.services').factory('platformService', platformService); + + +})(); diff --git a/src/Umbraco.Web.UI.Client/src/common/services/templatehelper.service.js b/src/Umbraco.Web.UI.Client/src/common/services/templatehelper.service.js index 63eed66917..5d00e2d56d 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/templatehelper.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/templatehelper.service.js @@ -70,11 +70,17 @@ }, { "description": localizationService.localize("shortcuts_copyLineUp"), - "keys": [{ "key": "alt" }, { "key": "shift" }, { "key": "up" }] + "keys": { + "win": [{ "key": "alt" }, { "key": "shift" }, { "key": "up" }], + "mac": [{ "key": "cmd" }, { "key": "alt" }, { "key": "up" }] + } }, { "description": localizationService.localize("shortcuts_copyLineDown"), - "keys": [{ "key": "alt" }, { "key": "shift" }, { "key": "down" }] + "keys": { + "win": [{ "key": "alt" }, { "key": "shift" }, { "key": "down" }], + "mac": [{ "key": "cmd" }, { "key": "alt" }, { "key": "down" }] + } }, { "description": localizationService.localize("shortcuts_moveLineUp"), diff --git a/src/Umbraco.Web.UI.Client/src/views/components/umb-keyboard-shortcuts-overview.html b/src/Umbraco.Web.UI.Client/src/views/components/umb-keyboard-shortcuts-overview.html index 33bb4d36be..8b12ee4afd 100644 --- a/src/Umbraco.Web.UI.Client/src/views/components/umb-keyboard-shortcuts-overview.html +++ b/src/Umbraco.Web.UI.Client/src/views/components/umb-keyboard-shortcuts-overview.html @@ -35,7 +35,7 @@
{{ keyboardShortcut.description }}
-
+
{{ key.key }}