summaryrefslogtreecommitdiff
path: root/lib/scripts/hotkeys.js
diff options
context:
space:
mode:
authorMarek Sacha <sachamar@fel.cvut.cz>2010-04-30 17:18:40 +0200
committerAndreas Gohr <andi@splitbrain.org>2010-05-08 11:48:41 +0200
commit4062d3d5c0c566751a1f098495e9aa836e8db9de (patch)
treee993ca819b6fb71fb8300ab6390589428f853386 /lib/scripts/hotkeys.js
parent7ea8e5925d4d2e18975712870d48912761ea1503 (diff)
downloadrpg-4062d3d5c0c566751a1f098495e9aa836e8db9de.tar.gz
rpg-4062d3d5c0c566751a1f098495e9aa836e8db9de.tar.bz2
Reimplementation of Accesskeys in javascript (FS#1809), toolbar accesskyes fix.
Diffstat (limited to 'lib/scripts/hotkeys.js')
-rw-r--r--lib/scripts/hotkeys.js58
1 files changed, 42 insertions, 16 deletions
diff --git a/lib/scripts/hotkeys.js b/lib/scripts/hotkeys.js
index d062118fb..9e2b9cb83 100644
--- a/lib/scripts/hotkeys.js
+++ b/lib/scripts/hotkeys.js
@@ -27,6 +27,9 @@ function Hotkeys() {
* (at anchor elements and input elements [type="submit"]) and registers
* appropriate shortcuts.
*
+ * Secondly, initialization registers listeners on document to catch all
+ * keyboard events.
+ *
* @author Marek Sacha <sachamar@fel.cvut.cz>
*/
this.initialize = function() {
@@ -39,7 +42,7 @@ function Hotkeys() {
t.each(anchors, function(a) {
if (a.accessKey != "") {
t.addShortcut(t.modifier + '+' + a.accessKey, function() {
- window.location.href = a.href;
+ a.click();
});
}
});
@@ -50,12 +53,41 @@ function Hotkeys() {
*/
var inputs = document.getElementsByTagName("input");
t.each(inputs, function(i) {
- if (i.type == "submit") {
+ if (i.type == "submit" && i.accessKey != "") {
t.addShortcut(t.modifier + '+' + i.accessKey, function() {
i.click();
});
}
});
+
+ /**
+ * Lookup all buttons with accesskey and register event -
+ * perform "click" on a button.
+ */
+ var buttons = document.getElementsByTagName("button");
+ t.each(buttons, function(b) {
+ if (b.accessKey != "") {
+ t.addShortcut(t.modifier + '+' + b.accessKey, function() {
+ b.click();
+ });
+ }
+ });
+
+ /**
+ * Register listeners on document to catch keyboard events.
+ */
+
+ addEvent(document,'keyup',function (e) {
+ return t.onkeyup.call(t,e);
+ });
+
+ addEvent(document,'keypress',function (e) {
+ return t.onkeypress.call(t,e);
+ });
+
+ addEvent(document,'keydown',function (e) {
+ return t.onkeydown.call(t,e);
+ });
};
/**
@@ -247,19 +279,13 @@ function Hotkeys() {
};
}
-addInitEvent(function(){
+/**
+ * Init function for hotkeys. Called from js.php, to ensure hotkyes are initialized after toolbar.
+ * Call of addInitEvent(initializeHotkeys) is unnecessary now.
+ *
+ * @author Marek Sacha <sachamar@fel.cvut.cz>
+ */
+function initializeHotkeys() {
var hotkeys = new Hotkeys();
hotkeys.initialize();
-
- addEvent(document,'keyup',function (e) {
- return hotkeys.onkeyup.call(hotkeys,e);
- });
-
- addEvent(document,'keypress',function (e) {
- return hotkeys.onkeypress.call(hotkeys,e);
- });
-
- addEvent(document,'keydown',function (e) {
- return hotkeys.onkeydown.call(hotkeys,e);
- });
-}); \ No newline at end of file
+} \ No newline at end of file