summaryrefslogtreecommitdiffstats
path: root/js/gui
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-05-20 17:58:17 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-05-20 17:58:17 +0200
commit0db81a2fc187a45e8c23160770a01e3050d26780 (patch)
treeb7daa312879873ae0f3a214c0e7b722522323fe0 /js/gui
parent5a7b1e0c36c2dd564f44568de766118b07be49ad (diff)
keyboard shortcuts first pitch
Diffstat (limited to 'js/gui')
-rw-r--r--js/gui/keyboardshortcuts.js103
1 files changed, 103 insertions, 0 deletions
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