2015-07-28 18:22:11 +00:00
|
|
|
/* global APP, $ */
|
2015-01-22 16:26:05 +00:00
|
|
|
//maps keycode to character, id of popover for given function and function
|
2015-07-02 21:33:06 +00:00
|
|
|
var shortcuts = {};
|
|
|
|
function initShortcutHandlers() {
|
|
|
|
shortcuts = {
|
Improve keyboard shortcut handling
Use KeyboardEvent.key if available,
match both lower and upper case letters to keep previous behaviour
KeyboardEvent is a mess.
KeyboardEvent.which gives you, in theory, a decimal representation of the key pressed.
"r" or "R" gives you 82, which is "R", you can look at KeyboardEvent.shiftKey,
but you don't have access to capslock...
Maybe you want to use numbers, but of course NumPad will not give you the same than
"normal" numbers ...
Now if you use something else than letter, for exemple "?",
on a QWERTY keyboard "/" and "?" gives you 191,
on a AZERTY keyboard "," and "?" gives you 188, so we have to stick to letters.
This was for keydown and keyup events, keypressed event return the real char
(lower "a", "/", "?", ...) but it fails in some cases
The only non broken property is KeyboardEvent.key,
but it's only supported since Chrome 51, Opera 38, and not supported by Safari
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
A good reference & test:
http://unixpapa.com/js/testkey.html
http://unixpapa.com/js/key.html
Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
2016-07-13 12:22:57 +00:00
|
|
|
"ESCAPE": {
|
2016-06-22 18:30:00 +00:00
|
|
|
character: "Esc",
|
|
|
|
function: function() {
|
|
|
|
APP.UI.showKeyboardShortcutsPanel(false);
|
2016-06-10 19:42:17 +00:00
|
|
|
}
|
|
|
|
},
|
Improve keyboard shortcut handling
Use KeyboardEvent.key if available,
match both lower and upper case letters to keep previous behaviour
KeyboardEvent is a mess.
KeyboardEvent.which gives you, in theory, a decimal representation of the key pressed.
"r" or "R" gives you 82, which is "R", you can look at KeyboardEvent.shiftKey,
but you don't have access to capslock...
Maybe you want to use numbers, but of course NumPad will not give you the same than
"normal" numbers ...
Now if you use something else than letter, for exemple "?",
on a QWERTY keyboard "/" and "?" gives you 191,
on a AZERTY keyboard "," and "?" gives you 188, so we have to stick to letters.
This was for keydown and keyup events, keypressed event return the real char
(lower "a", "/", "?", ...) but it fails in some cases
The only non broken property is KeyboardEvent.key,
but it's only supported since Chrome 51, Opera 38, and not supported by Safari
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
A good reference & test:
http://unixpapa.com/js/testkey.html
http://unixpapa.com/js/key.html
Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
2016-07-13 12:22:57 +00:00
|
|
|
"C": {
|
2015-07-02 21:33:06 +00:00
|
|
|
character: "C",
|
|
|
|
id: "toggleChatPopover",
|
2016-02-05 18:53:31 +00:00
|
|
|
function: function() {
|
|
|
|
APP.UI.toggleChat();
|
|
|
|
}
|
2015-07-02 21:33:06 +00:00
|
|
|
},
|
Improve keyboard shortcut handling
Use KeyboardEvent.key if available,
match both lower and upper case letters to keep previous behaviour
KeyboardEvent is a mess.
KeyboardEvent.which gives you, in theory, a decimal representation of the key pressed.
"r" or "R" gives you 82, which is "R", you can look at KeyboardEvent.shiftKey,
but you don't have access to capslock...
Maybe you want to use numbers, but of course NumPad will not give you the same than
"normal" numbers ...
Now if you use something else than letter, for exemple "?",
on a QWERTY keyboard "/" and "?" gives you 191,
on a AZERTY keyboard "," and "?" gives you 188, so we have to stick to letters.
This was for keydown and keyup events, keypressed event return the real char
(lower "a", "/", "?", ...) but it fails in some cases
The only non broken property is KeyboardEvent.key,
but it's only supported since Chrome 51, Opera 38, and not supported by Safari
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
A good reference & test:
http://unixpapa.com/js/testkey.html
http://unixpapa.com/js/key.html
Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
2016-07-13 12:22:57 +00:00
|
|
|
"D": {
|
2015-11-12 22:56:35 +00:00
|
|
|
character: "D",
|
|
|
|
id: "toggleDesktopSharingPopover",
|
2016-02-04 15:25:11 +00:00
|
|
|
function: function () {
|
|
|
|
APP.conference.toggleScreenSharing();
|
2016-02-05 18:53:31 +00:00
|
|
|
}
|
2015-11-12 22:56:35 +00:00
|
|
|
},
|
Improve keyboard shortcut handling
Use KeyboardEvent.key if available,
match both lower and upper case letters to keep previous behaviour
KeyboardEvent is a mess.
KeyboardEvent.which gives you, in theory, a decimal representation of the key pressed.
"r" or "R" gives you 82, which is "R", you can look at KeyboardEvent.shiftKey,
but you don't have access to capslock...
Maybe you want to use numbers, but of course NumPad will not give you the same than
"normal" numbers ...
Now if you use something else than letter, for exemple "?",
on a QWERTY keyboard "/" and "?" gives you 191,
on a AZERTY keyboard "," and "?" gives you 188, so we have to stick to letters.
This was for keydown and keyup events, keypressed event return the real char
(lower "a", "/", "?", ...) but it fails in some cases
The only non broken property is KeyboardEvent.key,
but it's only supported since Chrome 51, Opera 38, and not supported by Safari
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
A good reference & test:
http://unixpapa.com/js/testkey.html
http://unixpapa.com/js/key.html
Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
2016-07-13 12:22:57 +00:00
|
|
|
"F": {
|
2015-07-02 21:33:06 +00:00
|
|
|
character: "F",
|
|
|
|
id: "filmstripPopover",
|
2016-02-05 18:53:31 +00:00
|
|
|
function: function() {
|
|
|
|
APP.UI.toggleFilmStrip();
|
|
|
|
}
|
2015-07-02 21:33:06 +00:00
|
|
|
},
|
Improve keyboard shortcut handling
Use KeyboardEvent.key if available,
match both lower and upper case letters to keep previous behaviour
KeyboardEvent is a mess.
KeyboardEvent.which gives you, in theory, a decimal representation of the key pressed.
"r" or "R" gives you 82, which is "R", you can look at KeyboardEvent.shiftKey,
but you don't have access to capslock...
Maybe you want to use numbers, but of course NumPad will not give you the same than
"normal" numbers ...
Now if you use something else than letter, for exemple "?",
on a QWERTY keyboard "/" and "?" gives you 191,
on a AZERTY keyboard "," and "?" gives you 188, so we have to stick to letters.
This was for keydown and keyup events, keypressed event return the real char
(lower "a", "/", "?", ...) but it fails in some cases
The only non broken property is KeyboardEvent.key,
but it's only supported since Chrome 51, Opera 38, and not supported by Safari
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
A good reference & test:
http://unixpapa.com/js/testkey.html
http://unixpapa.com/js/key.html
Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
2016-07-13 12:22:57 +00:00
|
|
|
"M": {
|
2015-07-02 21:33:06 +00:00
|
|
|
character: "M",
|
|
|
|
id: "mutePopover",
|
2016-02-05 18:53:31 +00:00
|
|
|
function: function() {
|
|
|
|
APP.conference.toggleAudioMuted();
|
|
|
|
}
|
2015-07-02 21:33:06 +00:00
|
|
|
},
|
Improve keyboard shortcut handling
Use KeyboardEvent.key if available,
match both lower and upper case letters to keep previous behaviour
KeyboardEvent is a mess.
KeyboardEvent.which gives you, in theory, a decimal representation of the key pressed.
"r" or "R" gives you 82, which is "R", you can look at KeyboardEvent.shiftKey,
but you don't have access to capslock...
Maybe you want to use numbers, but of course NumPad will not give you the same than
"normal" numbers ...
Now if you use something else than letter, for exemple "?",
on a QWERTY keyboard "/" and "?" gives you 191,
on a AZERTY keyboard "," and "?" gives you 188, so we have to stick to letters.
This was for keydown and keyup events, keypressed event return the real char
(lower "a", "/", "?", ...) but it fails in some cases
The only non broken property is KeyboardEvent.key,
but it's only supported since Chrome 51, Opera 38, and not supported by Safari
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
A good reference & test:
http://unixpapa.com/js/testkey.html
http://unixpapa.com/js/key.html
Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
2016-07-13 12:22:57 +00:00
|
|
|
"R": {
|
2016-06-20 21:13:17 +00:00
|
|
|
character: "R",
|
|
|
|
function: function() {
|
|
|
|
APP.conference.maybeToggleRaisedHand();
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
Improve keyboard shortcut handling
Use KeyboardEvent.key if available,
match both lower and upper case letters to keep previous behaviour
KeyboardEvent is a mess.
KeyboardEvent.which gives you, in theory, a decimal representation of the key pressed.
"r" or "R" gives you 82, which is "R", you can look at KeyboardEvent.shiftKey,
but you don't have access to capslock...
Maybe you want to use numbers, but of course NumPad will not give you the same than
"normal" numbers ...
Now if you use something else than letter, for exemple "?",
on a QWERTY keyboard "/" and "?" gives you 191,
on a AZERTY keyboard "," and "?" gives you 188, so we have to stick to letters.
This was for keydown and keyup events, keypressed event return the real char
(lower "a", "/", "?", ...) but it fails in some cases
The only non broken property is KeyboardEvent.key,
but it's only supported since Chrome 51, Opera 38, and not supported by Safari
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
A good reference & test:
http://unixpapa.com/js/testkey.html
http://unixpapa.com/js/key.html
Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
2016-07-13 12:22:57 +00:00
|
|
|
"T": {
|
2015-07-02 21:33:06 +00:00
|
|
|
character: "T",
|
|
|
|
function: function() {
|
2015-12-03 13:11:01 +00:00
|
|
|
APP.conference.muteAudio(true);
|
2015-01-22 16:26:05 +00:00
|
|
|
}
|
2015-07-02 21:33:06 +00:00
|
|
|
},
|
Improve keyboard shortcut handling
Use KeyboardEvent.key if available,
match both lower and upper case letters to keep previous behaviour
KeyboardEvent is a mess.
KeyboardEvent.which gives you, in theory, a decimal representation of the key pressed.
"r" or "R" gives you 82, which is "R", you can look at KeyboardEvent.shiftKey,
but you don't have access to capslock...
Maybe you want to use numbers, but of course NumPad will not give you the same than
"normal" numbers ...
Now if you use something else than letter, for exemple "?",
on a QWERTY keyboard "/" and "?" gives you 191,
on a AZERTY keyboard "," and "?" gives you 188, so we have to stick to letters.
This was for keydown and keyup events, keypressed event return the real char
(lower "a", "/", "?", ...) but it fails in some cases
The only non broken property is KeyboardEvent.key,
but it's only supported since Chrome 51, Opera 38, and not supported by Safari
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
A good reference & test:
http://unixpapa.com/js/testkey.html
http://unixpapa.com/js/key.html
Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
2016-07-13 12:22:57 +00:00
|
|
|
"V": {
|
2015-07-02 21:33:06 +00:00
|
|
|
character: "V",
|
|
|
|
id: "toggleVideoPopover",
|
2016-02-05 18:53:31 +00:00
|
|
|
function: function() {
|
|
|
|
APP.conference.toggleVideoMuted();
|
|
|
|
}
|
2016-06-22 18:30:00 +00:00
|
|
|
},
|
Improve keyboard shortcut handling
Use KeyboardEvent.key if available,
match both lower and upper case letters to keep previous behaviour
KeyboardEvent is a mess.
KeyboardEvent.which gives you, in theory, a decimal representation of the key pressed.
"r" or "R" gives you 82, which is "R", you can look at KeyboardEvent.shiftKey,
but you don't have access to capslock...
Maybe you want to use numbers, but of course NumPad will not give you the same than
"normal" numbers ...
Now if you use something else than letter, for exemple "?",
on a QWERTY keyboard "/" and "?" gives you 191,
on a AZERTY keyboard "," and "?" gives you 188, so we have to stick to letters.
This was for keydown and keyup events, keypressed event return the real char
(lower "a", "/", "?", ...) but it fails in some cases
The only non broken property is KeyboardEvent.key,
but it's only supported since Chrome 51, Opera 38, and not supported by Safari
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
A good reference & test:
http://unixpapa.com/js/testkey.html
http://unixpapa.com/js/key.html
Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
2016-07-13 12:22:57 +00:00
|
|
|
"?": {
|
|
|
|
character: "?",
|
2016-06-22 18:30:00 +00:00
|
|
|
function: function(e) {
|
Improve keyboard shortcut handling
Use KeyboardEvent.key if available,
match both lower and upper case letters to keep previous behaviour
KeyboardEvent is a mess.
KeyboardEvent.which gives you, in theory, a decimal representation of the key pressed.
"r" or "R" gives you 82, which is "R", you can look at KeyboardEvent.shiftKey,
but you don't have access to capslock...
Maybe you want to use numbers, but of course NumPad will not give you the same than
"normal" numbers ...
Now if you use something else than letter, for exemple "?",
on a QWERTY keyboard "/" and "?" gives you 191,
on a AZERTY keyboard "," and "?" gives you 188, so we have to stick to letters.
This was for keydown and keyup events, keypressed event return the real char
(lower "a", "/", "?", ...) but it fails in some cases
The only non broken property is KeyboardEvent.key,
but it's only supported since Chrome 51, Opera 38, and not supported by Safari
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
A good reference & test:
http://unixpapa.com/js/testkey.html
http://unixpapa.com/js/key.html
Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
2016-07-13 12:22:57 +00:00
|
|
|
APP.UI.toggleKeyboardShortcutsPanel();
|
2016-06-22 18:30:00 +00:00
|
|
|
}
|
2015-01-22 16:26:05 +00:00
|
|
|
}
|
2015-07-02 21:33:06 +00:00
|
|
|
};
|
|
|
|
}
|
2015-01-22 16:26:05 +00:00
|
|
|
|
|
|
|
var KeyboardShortcut = {
|
|
|
|
init: function () {
|
2015-07-02 21:33:06 +00:00
|
|
|
initShortcutHandlers();
|
Improve keyboard shortcut handling
Use KeyboardEvent.key if available,
match both lower and upper case letters to keep previous behaviour
KeyboardEvent is a mess.
KeyboardEvent.which gives you, in theory, a decimal representation of the key pressed.
"r" or "R" gives you 82, which is "R", you can look at KeyboardEvent.shiftKey,
but you don't have access to capslock...
Maybe you want to use numbers, but of course NumPad will not give you the same than
"normal" numbers ...
Now if you use something else than letter, for exemple "?",
on a QWERTY keyboard "/" and "?" gives you 191,
on a AZERTY keyboard "," and "?" gives you 188, so we have to stick to letters.
This was for keydown and keyup events, keypressed event return the real char
(lower "a", "/", "?", ...) but it fails in some cases
The only non broken property is KeyboardEvent.key,
but it's only supported since Chrome 51, Opera 38, and not supported by Safari
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
A good reference & test:
http://unixpapa.com/js/testkey.html
http://unixpapa.com/js/key.html
Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
2016-07-13 12:22:57 +00:00
|
|
|
var self = this;
|
2015-01-22 16:26:05 +00:00
|
|
|
window.onkeyup = function(e) {
|
Improve keyboard shortcut handling
Use KeyboardEvent.key if available,
match both lower and upper case letters to keep previous behaviour
KeyboardEvent is a mess.
KeyboardEvent.which gives you, in theory, a decimal representation of the key pressed.
"r" or "R" gives you 82, which is "R", you can look at KeyboardEvent.shiftKey,
but you don't have access to capslock...
Maybe you want to use numbers, but of course NumPad will not give you the same than
"normal" numbers ...
Now if you use something else than letter, for exemple "?",
on a QWERTY keyboard "/" and "?" gives you 191,
on a AZERTY keyboard "," and "?" gives you 188, so we have to stick to letters.
This was for keydown and keyup events, keypressed event return the real char
(lower "a", "/", "?", ...) but it fails in some cases
The only non broken property is KeyboardEvent.key,
but it's only supported since Chrome 51, Opera 38, and not supported by Safari
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
A good reference & test:
http://unixpapa.com/js/testkey.html
http://unixpapa.com/js/key.html
Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
2016-07-13 12:22:57 +00:00
|
|
|
var key = self.getKeyboardKey(e).toUpperCase();
|
|
|
|
var num = parseInt(key, 10);
|
2015-01-22 16:26:05 +00:00
|
|
|
if(!($(":focus").is("input[type=text]") ||
|
|
|
|
$(":focus").is("input[type=password]") ||
|
|
|
|
$(":focus").is("textarea"))) {
|
Improve keyboard shortcut handling
Use KeyboardEvent.key if available,
match both lower and upper case letters to keep previous behaviour
KeyboardEvent is a mess.
KeyboardEvent.which gives you, in theory, a decimal representation of the key pressed.
"r" or "R" gives you 82, which is "R", you can look at KeyboardEvent.shiftKey,
but you don't have access to capslock...
Maybe you want to use numbers, but of course NumPad will not give you the same than
"normal" numbers ...
Now if you use something else than letter, for exemple "?",
on a QWERTY keyboard "/" and "?" gives you 191,
on a AZERTY keyboard "," and "?" gives you 188, so we have to stick to letters.
This was for keydown and keyup events, keypressed event return the real char
(lower "a", "/", "?", ...) but it fails in some cases
The only non broken property is KeyboardEvent.key,
but it's only supported since Chrome 51, Opera 38, and not supported by Safari
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
A good reference & test:
http://unixpapa.com/js/testkey.html
http://unixpapa.com/js/key.html
Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
2016-07-13 12:22:57 +00:00
|
|
|
if (shortcuts.hasOwnProperty(key)) {
|
|
|
|
shortcuts[key].function(e);
|
2015-01-22 16:26:05 +00:00
|
|
|
}
|
Improve keyboard shortcut handling
Use KeyboardEvent.key if available,
match both lower and upper case letters to keep previous behaviour
KeyboardEvent is a mess.
KeyboardEvent.which gives you, in theory, a decimal representation of the key pressed.
"r" or "R" gives you 82, which is "R", you can look at KeyboardEvent.shiftKey,
but you don't have access to capslock...
Maybe you want to use numbers, but of course NumPad will not give you the same than
"normal" numbers ...
Now if you use something else than letter, for exemple "?",
on a QWERTY keyboard "/" and "?" gives you 191,
on a AZERTY keyboard "," and "?" gives you 188, so we have to stick to letters.
This was for keydown and keyup events, keypressed event return the real char
(lower "a", "/", "?", ...) but it fails in some cases
The only non broken property is KeyboardEvent.key,
but it's only supported since Chrome 51, Opera 38, and not supported by Safari
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
A good reference & test:
http://unixpapa.com/js/testkey.html
http://unixpapa.com/js/key.html
Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
2016-07-13 12:22:57 +00:00
|
|
|
else if (!isNaN(num) && num >= 0 && num <= 9) {
|
|
|
|
APP.UI.clickOnVideo(num + 1);
|
2015-01-22 16:26:05 +00:00
|
|
|
}
|
Improve keyboard shortcut handling
Use KeyboardEvent.key if available,
match both lower and upper case letters to keep previous behaviour
KeyboardEvent is a mess.
KeyboardEvent.which gives you, in theory, a decimal representation of the key pressed.
"r" or "R" gives you 82, which is "R", you can look at KeyboardEvent.shiftKey,
but you don't have access to capslock...
Maybe you want to use numbers, but of course NumPad will not give you the same than
"normal" numbers ...
Now if you use something else than letter, for exemple "?",
on a QWERTY keyboard "/" and "?" gives you 191,
on a AZERTY keyboard "," and "?" gives you 188, so we have to stick to letters.
This was for keydown and keyup events, keypressed event return the real char
(lower "a", "/", "?", ...) but it fails in some cases
The only non broken property is KeyboardEvent.key,
but it's only supported since Chrome 51, Opera 38, and not supported by Safari
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
A good reference & test:
http://unixpapa.com/js/testkey.html
http://unixpapa.com/js/key.html
Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
2016-07-13 12:22:57 +00:00
|
|
|
//esc while the smileys are visible hides them
|
|
|
|
} else if (key === "ESCAPE" &&
|
2015-09-11 02:42:15 +00:00
|
|
|
$('#smileysContainer').is(':visible')) {
|
2015-01-28 14:35:22 +00:00
|
|
|
APP.UI.toggleSmileys();
|
2015-01-22 16:26:05 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
window.onkeydown = function(e) {
|
|
|
|
if(!($(":focus").is("input[type=text]") ||
|
|
|
|
$(":focus").is("input[type=password]") ||
|
|
|
|
$(":focus").is("textarea"))) {
|
Improve keyboard shortcut handling
Use KeyboardEvent.key if available,
match both lower and upper case letters to keep previous behaviour
KeyboardEvent is a mess.
KeyboardEvent.which gives you, in theory, a decimal representation of the key pressed.
"r" or "R" gives you 82, which is "R", you can look at KeyboardEvent.shiftKey,
but you don't have access to capslock...
Maybe you want to use numbers, but of course NumPad will not give you the same than
"normal" numbers ...
Now if you use something else than letter, for exemple "?",
on a QWERTY keyboard "/" and "?" gives you 191,
on a AZERTY keyboard "," and "?" gives you 188, so we have to stick to letters.
This was for keydown and keyup events, keypressed event return the real char
(lower "a", "/", "?", ...) but it fails in some cases
The only non broken property is KeyboardEvent.key,
but it's only supported since Chrome 51, Opera 38, and not supported by Safari
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
A good reference & test:
http://unixpapa.com/js/testkey.html
http://unixpapa.com/js/key.html
Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
2016-07-13 12:22:57 +00:00
|
|
|
var key = self.getKeyboardKey(e).toUpperCase();
|
|
|
|
if(key === "T") {
|
2016-02-09 16:29:50 +00:00
|
|
|
if(APP.conference.isLocalAudioMuted())
|
|
|
|
APP.conference.muteAudio(false);
|
2015-01-22 16:26:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2015-01-24 14:28:02 +00:00
|
|
|
$('body').popover({ selector: '[data-toggle=popover]',
|
|
|
|
trigger: 'click hover',
|
|
|
|
content: function() {
|
|
|
|
return this.getAttribute("content") +
|
|
|
|
self.getShortcut(this.getAttribute("shortcut"));
|
|
|
|
}
|
|
|
|
});
|
2015-01-22 16:26:05 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param id indicates the popover associated with the shortcut
|
|
|
|
* @returns {string} the keyboard shortcut used for the id given
|
|
|
|
*/
|
|
|
|
getShortcut: function (id) {
|
Improve keyboard shortcut handling
Use KeyboardEvent.key if available,
match both lower and upper case letters to keep previous behaviour
KeyboardEvent is a mess.
KeyboardEvent.which gives you, in theory, a decimal representation of the key pressed.
"r" or "R" gives you 82, which is "R", you can look at KeyboardEvent.shiftKey,
but you don't have access to capslock...
Maybe you want to use numbers, but of course NumPad will not give you the same than
"normal" numbers ...
Now if you use something else than letter, for exemple "?",
on a QWERTY keyboard "/" and "?" gives you 191,
on a AZERTY keyboard "," and "?" gives you 188, so we have to stick to letters.
This was for keydown and keyup events, keypressed event return the real char
(lower "a", "/", "?", ...) but it fails in some cases
The only non broken property is KeyboardEvent.key,
but it's only supported since Chrome 51, Opera 38, and not supported by Safari
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
A good reference & test:
http://unixpapa.com/js/testkey.html
http://unixpapa.com/js/key.html
Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
2016-07-13 12:22:57 +00:00
|
|
|
for (var key in shortcuts) {
|
|
|
|
if (shortcuts.hasOwnProperty(key)) {
|
|
|
|
if (shortcuts[key].id === id) {
|
|
|
|
return " (" + shortcuts[key].character + ")";
|
2015-01-22 16:26:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
Improve keyboard shortcut handling
Use KeyboardEvent.key if available,
match both lower and upper case letters to keep previous behaviour
KeyboardEvent is a mess.
KeyboardEvent.which gives you, in theory, a decimal representation of the key pressed.
"r" or "R" gives you 82, which is "R", you can look at KeyboardEvent.shiftKey,
but you don't have access to capslock...
Maybe you want to use numbers, but of course NumPad will not give you the same than
"normal" numbers ...
Now if you use something else than letter, for exemple "?",
on a QWERTY keyboard "/" and "?" gives you 191,
on a AZERTY keyboard "," and "?" gives you 188, so we have to stick to letters.
This was for keydown and keyup events, keypressed event return the real char
(lower "a", "/", "?", ...) but it fails in some cases
The only non broken property is KeyboardEvent.key,
but it's only supported since Chrome 51, Opera 38, and not supported by Safari
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
A good reference & test:
http://unixpapa.com/js/testkey.html
http://unixpapa.com/js/key.html
Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
2016-07-13 12:22:57 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* @param e a KeyboardEvent
|
|
|
|
* @returns {string} e.key or something close if not supported
|
|
|
|
*/
|
|
|
|
getKeyboardKey: function (e) {
|
|
|
|
if (typeof e.key === "string") {
|
|
|
|
return e.key;
|
|
|
|
}
|
|
|
|
if (e.type === "keypress" && (
|
|
|
|
(e.which >= 32 && e.which <= 126) ||
|
|
|
|
(e.which >= 160 && e.which <= 255) )) {
|
|
|
|
return String.fromCharCode(e.which);
|
|
|
|
}
|
|
|
|
// try to fallback (0-9A-Za-z and QWERTY keyboard)
|
|
|
|
switch (e.which) {
|
|
|
|
case 27:
|
|
|
|
return "Escape";
|
|
|
|
case 191:
|
|
|
|
return e.shiftKey ? "?" : "/";
|
|
|
|
}
|
|
|
|
if (e.shiftKey || e.type === "keypress") {
|
|
|
|
return String.fromCharCode(e.which);
|
|
|
|
} else {
|
|
|
|
return String.fromCharCode(e.which).toLowerCase();
|
|
|
|
}
|
2015-01-22 16:26:05 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = KeyboardShortcut;
|