mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
Variable names changed from underscore to CamelCase. Eslint rules updated. #64
This commit is contained in:
parent
f8193797fa
commit
e3c977934b
66 changed files with 3176 additions and 3172 deletions
|
@ -45,9 +45,9 @@ var Manager = function(app) {
|
|||
this.seasonal = new SeasonalWaiter(this.app, this);
|
||||
|
||||
// Object to store dynamic handlers to fire on elements that may not exist yet
|
||||
this.dynamic_handlers = {};
|
||||
this.dynamicHandlers = {};
|
||||
|
||||
this.initialise_event_listeners();
|
||||
this.initialiseEventListeners();
|
||||
};
|
||||
|
||||
|
||||
|
@ -55,8 +55,8 @@ var Manager = function(app) {
|
|||
* Sets up the various components and listeners.
|
||||
*/
|
||||
Manager.prototype.setup = function() {
|
||||
this.recipe.initialise_operation_drag_n_drop();
|
||||
this.controls.auto_bake_change();
|
||||
this.recipe.initialiseOperationDragNDrop();
|
||||
this.controls.autoBakeChange();
|
||||
this.seasonal.load();
|
||||
};
|
||||
|
||||
|
@ -64,87 +64,87 @@ Manager.prototype.setup = function() {
|
|||
/**
|
||||
* Main function to handle the creation of the event listeners.
|
||||
*/
|
||||
Manager.prototype.initialise_event_listeners = function() {
|
||||
Manager.prototype.initialiseEventListeners = function() {
|
||||
// Global
|
||||
window.addEventListener("resize", this.window.window_resize.bind(this.window));
|
||||
window.addEventListener("blur", this.window.window_blur.bind(this.window));
|
||||
window.addEventListener("focus", this.window.window_focus.bind(this.window));
|
||||
window.addEventListener("statechange", this.app.state_change.bind(this.app));
|
||||
window.addEventListener("popstate", this.app.pop_state.bind(this.app));
|
||||
window.addEventListener("resize", this.window.windowResize.bind(this.window));
|
||||
window.addEventListener("blur", this.window.windowBlur.bind(this.window));
|
||||
window.addEventListener("focus", this.window.windowFocus.bind(this.window));
|
||||
window.addEventListener("statechange", this.app.stateChange.bind(this.app));
|
||||
window.addEventListener("popstate", this.app.popState.bind(this.app));
|
||||
|
||||
// Controls
|
||||
document.getElementById("bake").addEventListener("click", this.controls.bake_click.bind(this.controls));
|
||||
document.getElementById("auto-bake").addEventListener("change", this.controls.auto_bake_change.bind(this.controls));
|
||||
document.getElementById("step").addEventListener("click", this.controls.step_click.bind(this.controls));
|
||||
document.getElementById("clr-recipe").addEventListener("click", this.controls.clear_recipe_click.bind(this.controls));
|
||||
document.getElementById("clr-breaks").addEventListener("click", this.controls.clear_breaks_click.bind(this.controls));
|
||||
document.getElementById("save").addEventListener("click", this.controls.save_click.bind(this.controls));
|
||||
document.getElementById("save-button").addEventListener("click", this.controls.save_button_click.bind(this.controls));
|
||||
document.getElementById("save-link-recipe-checkbox").addEventListener("change", this.controls.slr_check_change.bind(this.controls));
|
||||
document.getElementById("save-link-input-checkbox").addEventListener("change", this.controls.sli_check_change.bind(this.controls));
|
||||
document.getElementById("load").addEventListener("click", this.controls.load_click.bind(this.controls));
|
||||
document.getElementById("load-delete-button").addEventListener("click", this.controls.load_delete_click.bind(this.controls));
|
||||
document.getElementById("load-name").addEventListener("change", this.controls.load_name_change.bind(this.controls));
|
||||
document.getElementById("load-button").addEventListener("click", this.controls.load_button_click.bind(this.controls));
|
||||
this.add_multi_event_listener("#save-text", "keyup paste", this.controls.save_text_change, this.controls);
|
||||
document.getElementById("bake").addEventListener("click", this.controls.bakeClick.bind(this.controls));
|
||||
document.getElementById("auto-bake").addEventListener("change", this.controls.autoBakeChange.bind(this.controls));
|
||||
document.getElementById("step").addEventListener("click", this.controls.stepClick.bind(this.controls));
|
||||
document.getElementById("clr-recipe").addEventListener("click", this.controls.clearRecipeClick.bind(this.controls));
|
||||
document.getElementById("clr-breaks").addEventListener("click", this.controls.clearBreaksClick.bind(this.controls));
|
||||
document.getElementById("save").addEventListener("click", this.controls.saveClick.bind(this.controls));
|
||||
document.getElementById("save-button").addEventListener("click", this.controls.saveButtonClick.bind(this.controls));
|
||||
document.getElementById("save-link-recipe-checkbox").addEventListener("change", this.controls.slrCheckChange.bind(this.controls));
|
||||
document.getElementById("save-link-input-checkbox").addEventListener("change", this.controls.sliCheckChange.bind(this.controls));
|
||||
document.getElementById("load").addEventListener("click", this.controls.loadClick.bind(this.controls));
|
||||
document.getElementById("load-delete-button").addEventListener("click", this.controls.loadDeleteClick.bind(this.controls));
|
||||
document.getElementById("load-name").addEventListener("change", this.controls.loadNameChange.bind(this.controls));
|
||||
document.getElementById("load-button").addEventListener("click", this.controls.loadButtonClick.bind(this.controls));
|
||||
this.addMultiEventListener("#save-text", "keyup paste", this.controls.saveTextChange, this.controls);
|
||||
|
||||
// Operations
|
||||
this.add_multi_event_listener("#search", "keyup paste search", this.ops.search_operations, this.ops);
|
||||
this.add_dynamic_listener(".op_list li.operation", "dblclick", this.ops.operation_dblclick, this.ops);
|
||||
document.getElementById("edit-favourites").addEventListener("click", this.ops.edit_favourites_click.bind(this.ops));
|
||||
document.getElementById("save-favourites").addEventListener("click", this.ops.save_favourites_click.bind(this.ops));
|
||||
document.getElementById("reset-favourites").addEventListener("click", this.ops.reset_favourites_click.bind(this.ops));
|
||||
this.add_dynamic_listener(".op_list .op-icon", "mouseover", this.ops.op_icon_mouseover, this.ops);
|
||||
this.add_dynamic_listener(".op_list .op-icon", "mouseleave", this.ops.op_icon_mouseleave, this.ops);
|
||||
this.add_dynamic_listener(".op_list", "oplistcreate", this.ops.op_list_create, this.ops);
|
||||
this.add_dynamic_listener("li.operation", "operationadd", this.recipe.op_add.bind(this.recipe));
|
||||
this.addMultiEventListener("#search", "keyup paste search", this.ops.searchOperations, this.ops);
|
||||
this.addDynamicListener(".op-list li.operation", "dblclick", this.ops.operationDblclick, this.ops);
|
||||
document.getElementById("edit-favourites").addEventListener("click", this.ops.editFavouritesClick.bind(this.ops));
|
||||
document.getElementById("save-favourites").addEventListener("click", this.ops.saveFavouritesClick.bind(this.ops));
|
||||
document.getElementById("reset-favourites").addEventListener("click", this.ops.resetFavouritesClick.bind(this.ops));
|
||||
this.addDynamicListener(".op-list .op-icon", "mouseover", this.ops.opIconMouseover, this.ops);
|
||||
this.addDynamicListener(".op-list .op-icon", "mouseleave", this.ops.opIconMouseleave, this.ops);
|
||||
this.addDynamicListener(".op-list", "oplistcreate", this.ops.opListCreate, this.ops);
|
||||
this.addDynamicListener("li.operation", "operationadd", this.recipe.opAdd.bind(this.recipe));
|
||||
|
||||
// Recipe
|
||||
this.add_dynamic_listener(".arg", "keyup", this.recipe.ing_change, this.recipe);
|
||||
this.add_dynamic_listener(".arg", "change", this.recipe.ing_change, this.recipe);
|
||||
this.add_dynamic_listener(".disable-icon", "click", this.recipe.disable_click, this.recipe);
|
||||
this.add_dynamic_listener(".breakpoint", "click", this.recipe.breakpoint_click, this.recipe);
|
||||
this.add_dynamic_listener("#rec_list li.operation", "dblclick", this.recipe.operation_dblclick, this.recipe);
|
||||
this.add_dynamic_listener("#rec_list li.operation > div", "dblclick", this.recipe.operation_child_dblclick, this.recipe);
|
||||
this.add_dynamic_listener("#rec_list .input-group .dropdown-menu a", "click", this.recipe.dropdown_toggle_click, this.recipe);
|
||||
this.add_dynamic_listener("#rec_list", "operationremove", this.recipe.op_remove.bind(this.recipe));
|
||||
this.addDynamicListener(".arg", "keyup", this.recipe.ingChange, this.recipe);
|
||||
this.addDynamicListener(".arg", "change", this.recipe.ingChange, this.recipe);
|
||||
this.addDynamicListener(".disable-icon", "click", this.recipe.disableClick, this.recipe);
|
||||
this.addDynamicListener(".breakpoint", "click", this.recipe.breakpointClick, this.recipe);
|
||||
this.addDynamicListener("#rec-list li.operation", "dblclick", this.recipe.operationDblclick, this.recipe);
|
||||
this.addDynamicListener("#rec-list li.operation > div", "dblclick", this.recipe.operationChildDblclick, this.recipe);
|
||||
this.addDynamicListener("#rec-list .input-group .dropdown-menu a", "click", this.recipe.dropdownToggleClick, this.recipe);
|
||||
this.addDynamicListener("#rec-list", "operationremove", this.recipe.opRemove.bind(this.recipe));
|
||||
|
||||
// Input
|
||||
this.add_multi_event_listener("#input-text", "keyup paste", this.input.input_change, this.input);
|
||||
document.getElementById("reset-layout").addEventListener("click", this.app.reset_layout.bind(this.app));
|
||||
document.getElementById("clr-io").addEventListener("click", this.input.clear_io_click.bind(this.input));
|
||||
document.getElementById("input-text").addEventListener("dragover", this.input.input_dragover.bind(this.input));
|
||||
document.getElementById("input-text").addEventListener("dragleave", this.input.input_dragleave.bind(this.input));
|
||||
document.getElementById("input-text").addEventListener("drop", this.input.input_drop.bind(this.input));
|
||||
document.getElementById("input-text").addEventListener("scroll", this.highlighter.input_scroll.bind(this.highlighter));
|
||||
document.getElementById("input-text").addEventListener("mouseup", this.highlighter.input_mouseup.bind(this.highlighter));
|
||||
document.getElementById("input-text").addEventListener("mousemove", this.highlighter.input_mousemove.bind(this.highlighter));
|
||||
this.add_multi_event_listener("#input-text", "mousedown dblclick select", this.highlighter.input_mousedown, this.highlighter);
|
||||
this.addMultiEventListener("#input-text", "keyup paste", this.input.inputChange, this.input);
|
||||
document.getElementById("reset-layout").addEventListener("click", this.app.resetLayout.bind(this.app));
|
||||
document.getElementById("clr-io").addEventListener("click", this.input.clearIoClick.bind(this.input));
|
||||
document.getElementById("input-text").addEventListener("dragover", this.input.inputDragover.bind(this.input));
|
||||
document.getElementById("input-text").addEventListener("dragleave", this.input.inputDragleave.bind(this.input));
|
||||
document.getElementById("input-text").addEventListener("drop", this.input.inputDrop.bind(this.input));
|
||||
document.getElementById("input-text").addEventListener("scroll", this.highlighter.inputScroll.bind(this.highlighter));
|
||||
document.getElementById("input-text").addEventListener("mouseup", this.highlighter.inputMouseup.bind(this.highlighter));
|
||||
document.getElementById("input-text").addEventListener("mousemove", this.highlighter.inputMousemove.bind(this.highlighter));
|
||||
this.addMultiEventListener("#input-text", "mousedown dblclick select", this.highlighter.inputMousedown, this.highlighter);
|
||||
|
||||
// Output
|
||||
document.getElementById("save-to-file").addEventListener("click", this.output.save_click.bind(this.output));
|
||||
document.getElementById("switch").addEventListener("click", this.output.switch_click.bind(this.output));
|
||||
document.getElementById("undo-switch").addEventListener("click", this.output.undo_switch_click.bind(this.output));
|
||||
document.getElementById("maximise-output").addEventListener("click", this.output.maximise_output_click.bind(this.output));
|
||||
document.getElementById("output-text").addEventListener("scroll", this.highlighter.output_scroll.bind(this.highlighter));
|
||||
document.getElementById("output-text").addEventListener("mouseup", this.highlighter.output_mouseup.bind(this.highlighter));
|
||||
document.getElementById("output-text").addEventListener("mousemove", this.highlighter.output_mousemove.bind(this.highlighter));
|
||||
document.getElementById("output-html").addEventListener("mouseup", this.highlighter.output_html_mouseup.bind(this.highlighter));
|
||||
document.getElementById("output-html").addEventListener("mousemove", this.highlighter.output_html_mousemove.bind(this.highlighter));
|
||||
this.add_multi_event_listener("#output-text", "mousedown dblclick select", this.highlighter.output_mousedown, this.highlighter);
|
||||
this.add_multi_event_listener("#output-html", "mousedown dblclick select", this.highlighter.output_html_mousedown, this.highlighter);
|
||||
document.getElementById("save-to-file").addEventListener("click", this.output.saveClick.bind(this.output));
|
||||
document.getElementById("switch").addEventListener("click", this.output.switchClick.bind(this.output));
|
||||
document.getElementById("undo-switch").addEventListener("click", this.output.undoSwitchClick.bind(this.output));
|
||||
document.getElementById("maximise-output").addEventListener("click", this.output.maximiseOutputClick.bind(this.output));
|
||||
document.getElementById("output-text").addEventListener("scroll", this.highlighter.outputScroll.bind(this.highlighter));
|
||||
document.getElementById("output-text").addEventListener("mouseup", this.highlighter.outputMouseup.bind(this.highlighter));
|
||||
document.getElementById("output-text").addEventListener("mousemove", this.highlighter.outputMousemove.bind(this.highlighter));
|
||||
document.getElementById("output-html").addEventListener("mouseup", this.highlighter.outputHtmlMouseup.bind(this.highlighter));
|
||||
document.getElementById("output-html").addEventListener("mousemove", this.highlighter.outputHtmlMousemove.bind(this.highlighter));
|
||||
this.addMultiEventListener("#output-text", "mousedown dblclick select", this.highlighter.outputMousedown, this.highlighter);
|
||||
this.addMultiEventListener("#output-html", "mousedown dblclick select", this.highlighter.outputHtmlMousedown, this.highlighter);
|
||||
|
||||
// Options
|
||||
document.getElementById("options").addEventListener("click", this.options.options_click.bind(this.options));
|
||||
document.getElementById("reset-options").addEventListener("click", this.options.reset_options_click.bind(this.options));
|
||||
$(document).on("switchChange.bootstrapSwitch", ".option-item input:checkbox", this.options.switch_change.bind(this.options));
|
||||
$(document).on("switchChange.bootstrapSwitch", ".option-item input:checkbox", this.options.set_word_wrap.bind(this.options));
|
||||
this.add_dynamic_listener(".option-item input[type=number]", "keyup", this.options.number_change, this.options);
|
||||
this.add_dynamic_listener(".option-item input[type=number]", "change", this.options.number_change, this.options);
|
||||
this.add_dynamic_listener(".option-item select", "change", this.options.select_change, this.options);
|
||||
document.getElementById("options").addEventListener("click", this.options.optionsClick.bind(this.options));
|
||||
document.getElementById("reset-options").addEventListener("click", this.options.resetOptionsClick.bind(this.options));
|
||||
$(document).on("switchChange.bootstrapSwitch", ".option-item input:checkbox", this.options.switchChange.bind(this.options));
|
||||
$(document).on("switchChange.bootstrapSwitch", ".option-item input:checkbox", this.options.setWordWrap.bind(this.options));
|
||||
this.addDynamicListener(".option-item input[type=number]", "keyup", this.options.numberChange, this.options);
|
||||
this.addDynamicListener(".option-item input[type=number]", "change", this.options.numberChange, this.options);
|
||||
this.addDynamicListener(".option-item select", "change", this.options.selectChange, this.options);
|
||||
|
||||
// Misc
|
||||
document.getElementById("alert-close").addEventListener("click", this.app.alert_close_click.bind(this.app));
|
||||
document.getElementById("alert-close").addEventListener("click", this.app.alertCloseClick.bind(this.app));
|
||||
};
|
||||
|
||||
|
||||
|
@ -152,19 +152,19 @@ Manager.prototype.initialise_event_listeners = function() {
|
|||
* Adds an event listener to each element in the specified group.
|
||||
*
|
||||
* @param {string} selector - A selector string for the element group to add the event to, see
|
||||
* this.get_all()
|
||||
* @param {string} event_type - The event to listen for
|
||||
* this.getAll()
|
||||
* @param {string} eventType - The event to listen for
|
||||
* @param {function} callback - The function to execute when the event is triggered
|
||||
* @param {Object} [scope=this] - The object to bind to the callback function
|
||||
*
|
||||
* @example
|
||||
* // Calls the clickable function whenever any element with the .clickable class is clicked
|
||||
* this.add_listeners(".clickable", "click", this.clickable, this);
|
||||
* this.addListeners(".clickable", "click", this.clickable, this);
|
||||
*/
|
||||
Manager.prototype.add_listeners = function(selector, event_type, callback, scope) {
|
||||
Manager.prototype.addListeners = function(selector, eventType, callback, scope) {
|
||||
scope = scope || this;
|
||||
[].forEach.call(document.querySelectorAll(selector), function(el) {
|
||||
el.addEventListener(event_type, callback.bind(scope));
|
||||
el.addEventListener(eventType, callback.bind(scope));
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -173,17 +173,17 @@ Manager.prototype.add_listeners = function(selector, event_type, callback, scope
|
|||
* Adds multiple event listeners to the specified element.
|
||||
*
|
||||
* @param {string} selector - A selector string for the element to add the events to
|
||||
* @param {string} event_types - A space-separated string of all the event types to listen for
|
||||
* @param {string} eventTypes - A space-separated string of all the event types to listen for
|
||||
* @param {function} callback - The function to execute when the events are triggered
|
||||
* @param {Object} [scope=this] - The object to bind to the callback function
|
||||
*
|
||||
* @example
|
||||
* // Calls the search function whenever the the keyup, paste or search events are triggered on the
|
||||
* // search element
|
||||
* this.add_multi_event_listener("search", "keyup paste search", this.search, this);
|
||||
* this.addMultiEventListener("search", "keyup paste search", this.search, this);
|
||||
*/
|
||||
Manager.prototype.add_multi_event_listener = function(selector, event_types, callback, scope) {
|
||||
var evs = event_types.split(" ");
|
||||
Manager.prototype.addMultiEventListener = function(selector, eventTypes, callback, scope) {
|
||||
var evs = eventTypes.split(" ");
|
||||
for (var i = 0; i < evs.length; i++) {
|
||||
document.querySelector(selector).addEventListener(evs[i], callback.bind(scope));
|
||||
}
|
||||
|
@ -194,19 +194,19 @@ Manager.prototype.add_multi_event_listener = function(selector, event_types, cal
|
|||
* Adds multiple event listeners to each element in the specified group.
|
||||
*
|
||||
* @param {string} selector - A selector string for the element group to add the events to
|
||||
* @param {string} event_types - A space-separated string of all the event types to listen for
|
||||
* @param {string} eventTypes - A space-separated string of all the event types to listen for
|
||||
* @param {function} callback - The function to execute when the events are triggered
|
||||
* @param {Object} [scope=this] - The object to bind to the callback function
|
||||
*
|
||||
* @example
|
||||
* // Calls the save function whenever the the keyup or paste events are triggered on any element
|
||||
* // with the .saveable class
|
||||
* this.add_multi_event_listener(".saveable", "keyup paste", this.save, this);
|
||||
* this.addMultiEventListener(".saveable", "keyup paste", this.save, this);
|
||||
*/
|
||||
Manager.prototype.add_multi_event_listeners = function(selector, event_types, callback, scope) {
|
||||
var evs = event_types.split(" ");
|
||||
Manager.prototype.addMultiEventListeners = function(selector, eventTypes, callback, scope) {
|
||||
var evs = eventTypes.split(" ");
|
||||
for (var i = 0; i < evs.length; i++) {
|
||||
this.add_listeners(selector, evs[i], callback, scope);
|
||||
this.addListeners(selector, evs[i], callback, scope);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -216,28 +216,28 @@ Manager.prototype.add_multi_event_listeners = function(selector, event_types, ca
|
|||
* may not exist in the DOM yet.
|
||||
*
|
||||
* @param {string} selector - A selector string for the element(s) to add the event to
|
||||
* @param {string} event_type - The event(s) to listen for
|
||||
* @param {string} eventType - The event(s) to listen for
|
||||
* @param {function} callback - The function to execute when the event(s) is/are triggered
|
||||
* @param {Object} [scope=this] - The object to bind to the callback function
|
||||
*
|
||||
* @example
|
||||
* // Pops up an alert whenever any button is clicked, even if it is added to the DOM after this
|
||||
* // listener is created
|
||||
* this.add_dynamic_listener("button", "click", alert, this);
|
||||
* this.addDynamicListener("button", "click", alert, this);
|
||||
*/
|
||||
Manager.prototype.add_dynamic_listener = function(selector, event_type, callback, scope) {
|
||||
var event_config = {
|
||||
Manager.prototype.addDynamicListener = function(selector, eventType, callback, scope) {
|
||||
var eventConfig = {
|
||||
selector: selector,
|
||||
callback: callback.bind(scope || this)
|
||||
};
|
||||
|
||||
if (this.dynamic_handlers.hasOwnProperty(event_type)) {
|
||||
if (this.dynamicHandlers.hasOwnProperty(eventType)) {
|
||||
// Listener already exists, add new handler to the appropriate list
|
||||
this.dynamic_handlers[event_type].push(event_config);
|
||||
this.dynamicHandlers[eventType].push(eventConfig);
|
||||
} else {
|
||||
this.dynamic_handlers[event_type] = [event_config];
|
||||
this.dynamicHandlers[eventType] = [eventConfig];
|
||||
// Set up listener for this new type
|
||||
document.addEventListener(event_type, this.dynamic_listener_handler.bind(this));
|
||||
document.addEventListener(eventType, this.dynamicListenerHandler.bind(this));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -248,8 +248,8 @@ Manager.prototype.add_dynamic_listener = function(selector, event_type, callback
|
|||
*
|
||||
* @param {Event} e - The event to be handled
|
||||
*/
|
||||
Manager.prototype.dynamic_listener_handler = function(e) {
|
||||
var handlers = this.dynamic_handlers[e.type],
|
||||
Manager.prototype.dynamicListenerHandler = function(e) {
|
||||
var handlers = this.dynamicHandlers[e.type],
|
||||
matches = e.target.matches ||
|
||||
e.target.webkitMatchesSelector ||
|
||||
e.target.mozMatchesSelector ||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue