mirror of https://github.com/MISP/MISP
Actually remove keyboard shortcuts from MISP.js
parent
77ce2468a5
commit
fd62155986
|
@ -3279,108 +3279,4 @@ $(document).ready(function() {
|
|||
$(".datepicker").datepicker({
|
||||
format: 'yyyy-mm-dd',
|
||||
});
|
||||
}());
|
||||
|
||||
/* ============== KEYBOARD SHORTCUTS ==============*/
|
||||
let keyboardShortcutsManager = {
|
||||
|
||||
shortcutKeys: new Map(),
|
||||
shortcutListToggled: false,
|
||||
escapedTagNames: ["INPUT", "TEXTAREA", "SELECT"],
|
||||
|
||||
/**
|
||||
* Fetches the keyboard shortcut config files and populates this.shortcutJSON.
|
||||
*/
|
||||
init() {
|
||||
let shortcutURIs = [];
|
||||
for(let keyboardShortcutElement of $('.keyboardShortcutsConfig')) {
|
||||
shortcutURIs.push(keyboardShortcutElement.value);
|
||||
this.ajaxGet(window.location.protocol + "//" + window.location.host + keyboardShortcutElement.value).then(response => {
|
||||
this.mapKeyboardShortcuts(JSON.parse(response));
|
||||
});
|
||||
}
|
||||
this.setKeyboardListener();
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggles the view on the list of shortcuts at the bottom of the screen.
|
||||
*/
|
||||
onTriangleClick() {
|
||||
let activated = this.shortcutListToggled;
|
||||
let shortcutListElement = $('#shortcutsListContainer');
|
||||
let triangleElement = $('#triangle');
|
||||
let shortcutListElementHeight = shortcutListElement.height();
|
||||
shortcutListElement.css('top', activated ? '' : '-' + shortcutListElementHeight + 'px');
|
||||
triangleElement.css('bottom', activated ? '' : shortcutListElementHeight + 30 + 'px');
|
||||
this.shortcutListToggled = !activated;
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates the HTML list of shortcuts for the user to read and sets it in the DOM.
|
||||
*/
|
||||
addShortcutListToHTML() {
|
||||
let html = "<ul>";
|
||||
for(let shortcut of this.shortcutKeys.values()) {
|
||||
html += `<li><strong>${shortcut.key.toUpperCase()}</strong>: ${shortcut.description}</li>`
|
||||
}
|
||||
html += "</ul>"
|
||||
$('#shortcuts').html(html);
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the shortcut object list.
|
||||
* @param {} config The shortcut JSON list: [{key: string, description: string, action: string(eval-able JS code)}]
|
||||
*/
|
||||
mapKeyboardShortcuts(config) {
|
||||
for(let shortcut of config.shortcuts) {
|
||||
this.shortcutKeys.set(shortcut.key, shortcut);
|
||||
}
|
||||
this.addShortcutListToHTML();
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the event to listen to and the routine to call on keypress.
|
||||
*/
|
||||
setKeyboardListener() {
|
||||
window.onkeyup = (keyboardEvent) => {
|
||||
if(this.shortcutKeys.has(keyboardEvent.key)) {
|
||||
let activeElement = document.activeElement.tagName;
|
||||
if( !this.escapedTagNames.includes(activeElement)) {
|
||||
eval(this.shortcutKeys.get(keyboardEvent.key).action);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Queries the given URL with a GET request and returns a Promise
|
||||
* that resolves when the response arrives.
|
||||
* @param string url The URL to fetch.
|
||||
*/
|
||||
ajaxGet(url) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
let req = new XMLHttpRequest();
|
||||
req.open("GET", url);
|
||||
req.onload = function() {
|
||||
if (req.status === 200) {
|
||||
resolve(req.response);
|
||||
} else {
|
||||
reject(new Error(req.statusText));
|
||||
}
|
||||
};
|
||||
|
||||
req.onerror = function() {
|
||||
reject(new Error("Network error"));
|
||||
};
|
||||
|
||||
req.send();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Inits the keyboard shortcut manager's main routine.
|
||||
$(document).ready(() => keyboardShortcutsManager.init());
|
||||
|
||||
// Inits the click event on the keyboard shortcut triangle at the bottom of the screen.
|
||||
$('#triangle').click(keyboardShortcutsManager.onTriangleClick);
|
||||
/* ============ END KEYBOARD SHORTCUTS ============*/
|
||||
}());
|
Loading…
Reference in New Issue