diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-20 17:58:17 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-20 17:58:17 +0200 |
commit | 0db81a2fc187a45e8c23160770a01e3050d26780 (patch) | |
tree | b7daa312879873ae0f3a214c0e7b722522323fe0 /js | |
parent | 5a7b1e0c36c2dd564f44568de766118b07be49ad (diff) |
keyboard shortcuts first pitch
Diffstat (limited to 'js')
-rw-r--r-- | js/Gruntfile.js | 4 | ||||
-rw-r--r-- | js/build/app.js | 9 | ||||
-rw-r--r-- | js/gui/keyboardshortcuts.js | 103 |
3 files changed, 116 insertions, 0 deletions
diff --git a/js/Gruntfile.js b/js/Gruntfile.js index 7a4573c6c..1baf2d7d1 100644 --- a/js/Gruntfile.js +++ b/js/Gruntfile.js @@ -11,6 +11,7 @@ var globals = [ // libs '$', + 'jQuery', 'angular', // app 'app', @@ -70,6 +71,7 @@ module.exports = function (grunt) { 'controller/**/*.js', 'filter/**/*.js', 'service/**/*.js', + 'gui/**/*.js', 'model/**/*.js', 'directive/**/*.js' ], @@ -104,6 +106,7 @@ module.exports = function (grunt) { 'controller/**/*.js', 'directive/**/*.js', 'tests/**/*.js', + 'gui/**/*.js', 'Gruntfile.js', 'karma.conf.js', 'protractor*conf.js' @@ -124,6 +127,7 @@ module.exports = function (grunt) { 'directive/**/*.js', 'filter/**/*.js', 'service/**/*.js', + 'gui/**/*.js', '../templates/**/*.php' ], tasks: ['default'], diff --git a/js/build/app.js b/js/build/app.js index ca4ef9c38..189310712 100644 --- a/js/build/app.js +++ b/js/build/app.js @@ -395,5 +395,14 @@ app.service('Settings', function () { this.settings[key] = value; }; }); +(function (document, $) { + 'use strict'; + $(document).on('keyup', function (event) { + var keyCode = event.keyCode; + console.log(undefined); + console.log(keyCode); + }); + console.log('hi'); +}(document, jQuery)); })(angular, jQuery, OC, oc_requesttoken);
\ No newline at end of file diff --git a/js/gui/keyboardshortcuts.js b/js/gui/keyboardshortcuts.js new file mode 100644 index 000000000..3062e6dac --- /dev/null +++ b/js/gui/keyboardshortcuts.js @@ -0,0 +1,103 @@ +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2014 + */ + +/** + * Code in here acts only as a click shortcut mechanism. That's why its not + * being put into a directive since it has to be tested with protractor + * anyways and theres no benefit from wiring it into the angular app + */ +(function (document, $) { + 'use strict'; + + $(document).keyup(function (event) { + var keyCode, + noInputFocused, + noModifierKey, + scrollArea, + jumpToNextItem, + jumpToPreviousItem, + toggleStar, + toggleUnread, + expandItem, + openLink, + getActiveItem; + + keyCode = event.keyCode; + scrollArea = $('#app-content'); + + noInputFocused = function (element) { + return !( + element.is('input') + && element.is('select') + && element.is('textarea') + && element.is('checkbox') + ); + }; + + noModifierKey = function (event) { + return !( + event.shiftKey + || event.altKey + || event.ctrlKey + || event.metaKey + ); + }; + + if (noInputFocused($(':focus')) && noModifierKey(event)) { + + // j, n, right arrow + if ([74, 78, 34].indexOf(keyCode) >= 0) { + + event.preventDefault(); + jumpToNextItem(scrollArea); + + // k, p, left arrow + } else if ([75, 80, 37].indexOf(keyCode) >= 0) { + + event.preventDefault(); + jumpToPreviousItem(scrollArea); + + // u + } else if ([85].indexOf(keyCode) >= 0) { + + event.preventDefault(); + toggleUnread(scrollArea); + + // e + } else if ([69].indexOf(keyCode) >= 0) { + + event.preventDefault(); + expandItem(scrollArea); + + // s, i, l + } else if ([73, 83, 76].indexOf(keyCode) >= 0) { + + event.preventDefault(); + toggleStar(scrollArea); + + // h + } else if ([72].indexOf(keyCode) >= 0) { + + event.preventDefault(); + toggleStar(scrollArea); + jumpToNextItem(scrollArea); + + // o + } else if ([79].indexOf(keyCode) >= 0) { + + event.preventDefault(); + openLink(scrollArea); + + } + + } + }); + +}(document, jQuery));
\ No newline at end of file |