1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-11-07 19:13:00 +00:00

Introduce text editor toolbar (#2315)

Tada!
This commit is contained in:
Jeremy Ruston
2016-04-22 08:36:29 +01:00
parent 4dd701c2dd
commit 2adf09129d
234 changed files with 3899 additions and 999 deletions

View File

@@ -3,7 +3,7 @@ title: $:/core/modules/utils/dom/keyboard.js
type: application/javascript
module-type: utils
Keyboard utilities
Keyboard utilities; now deprecated. Instead, use $tw.keyboardManager
\*/
(function(){
@@ -12,60 +12,14 @@ Keyboard utilities
/*global $tw: false */
"use strict";
var namedKeys = {
"backspace": 8,
"tab": 9,
"enter": 13,
"escape": 27
};
/*
Parses a key descriptor into the structure:
{
keyCode: numeric keycode
shiftKey: boolean
altKey: boolean
ctrlKey: boolean
}
Key descriptors have the following format:
ctrl+enter
ctrl+shift+alt+A
*/
exports.parseKeyDescriptor = function(keyDescriptor) {
var components = keyDescriptor.split("+"),
info = {
keyCode: 0,
shiftKey: false,
altKey: false,
ctrlKey: false
};
for(var t=0; t<components.length; t++) {
var s = components[t].toLowerCase();
// Look for modifier keys
if(s === "ctrl") {
info.ctrlKey = true;
} else if(s === "shift") {
info.shiftKey = true;
} else if(s === "alt") {
info.altKey = true;
} else if(s === "meta") {
info.metaKey = true;
["parseKeyDescriptor","checkKeyDescriptor"].forEach(function(method) {
exports[method] = function() {
if($tw.keyboardManager) {
return $tw.keyboardManager[method].apply($tw.keyboardManager,Array.prototype.slice.call(arguments,0));
} else {
return null
}
// Replace named keys with their code
if(namedKeys[s]) {
info.keyCode = namedKeys[s];
}
}
return info;
};
exports.checkKeyDescriptor = function(event,keyInfo) {
var metaKeyStatus = !!keyInfo.metaKey; // Using a temporary variable to keep JSHint happy
return event.keyCode === keyInfo.keyCode &&
event.shiftKey === keyInfo.shiftKey &&
event.altKey === keyInfo.altKey &&
event.ctrlKey === keyInfo.ctrlKey &&
event.metaKey === metaKeyStatus;
};
};
});
})();