diff --git a/IPython/html/static/notebook/js/keyboardmanager.js b/IPython/html/static/notebook/js/keyboardmanager.js index 07703b9..b54a660 100644 --- a/IPython/html/static/notebook/js/keyboardmanager.js +++ b/IPython/html/static/notebook/js/keyboardmanager.js @@ -42,12 +42,12 @@ var IPython = (function (IPython) { // These apply to Firefox and Opera var _mozilla_keycodes = { '; :': 59, '= +': 61, '- _': 173, 'meta': 224 - } + }; // This apply to Webkit and IE var _ie_keycodes = { '; :': 186, '= +': 187, '- _': 189, - } + }; var browser = IPython.utils.browser[0]; var platform = IPython.utils.platform; @@ -63,15 +63,15 @@ var IPython = (function (IPython) { for (var name in _keycodes) { var names = name.split(' '); if (names.length === 1) { - var n = names[0] - keycodes[n] = _keycodes[n] - inv_keycodes[_keycodes[n]] = n + var n = names[0]; + keycodes[n] = _keycodes[n]; + inv_keycodes[_keycodes[n]] = n; } else { var primary = names[0]; var secondary = names[1]; - keycodes[primary] = _keycodes[name] - keycodes[secondary] = _keycodes[name] - inv_keycodes[_keycodes[name]] = primary + keycodes[primary] = _keycodes[name]; + keycodes[secondary] = _keycodes[name]; + inv_keycodes[_keycodes[name]] = primary; } } @@ -111,7 +111,7 @@ var IPython = (function (IPython) { return false; } } - } + }; if (platform === 'MacOS') { default_common_shortcuts['cmd+s'] = @@ -165,11 +165,11 @@ var IPython = (function (IPython) { var cell = IPython.notebook.get_selected_cell(); if (cell && cell.at_top()) { event.preventDefault(); - IPython.notebook.command_mode() + IPython.notebook.command_mode(); IPython.notebook.select_prev(); IPython.notebook.edit_mode(); return false; - }; + } } }, 'down' : { @@ -179,11 +179,11 @@ var IPython = (function (IPython) { var cell = IPython.notebook.get_selected_cell(); if (cell && cell.at_bottom()) { event.preventDefault(); - IPython.notebook.command_mode() + IPython.notebook.command_mode(); IPython.notebook.select_next(); IPython.notebook.edit_mode(); return false; - }; + } } }, 'alt+-' : { @@ -210,7 +210,7 @@ var IPython = (function (IPython) { help : 'tooltip', help_index : 'ed', }, - } + }; if (platform === 'MacOS') { default_edit_shortcuts['cmd+/'] = @@ -266,7 +266,7 @@ var IPython = (function (IPython) { IPython.notebook.select_prev(); var cell = IPython.notebook.get_selected_cell(); cell.focus_cell(); - }; + } return false; } }, @@ -279,7 +279,7 @@ var IPython = (function (IPython) { IPython.notebook.select_next(); var cell = IPython.notebook.get_selected_cell(); cell.focus_cell(); - }; + } return false; } }, @@ -292,7 +292,7 @@ var IPython = (function (IPython) { IPython.notebook.select_prev(); var cell = IPython.notebook.get_selected_cell(); cell.focus_cell(); - }; + } return false; } }, @@ -305,7 +305,7 @@ var IPython = (function (IPython) { IPython.notebook.select_next(); var cell = IPython.notebook.get_selected_cell(); cell.focus_cell(); - }; + } return false; } }, @@ -540,23 +540,23 @@ var IPython = (function (IPython) { return false; } }, - } + }; // Shortcut manager class var ShortcutManager = function (delay) { - this._shortcuts = {} - this._counts = {} - this._timers = {} + this._shortcuts = {}; + this._counts = {}; + this._timers = {}; this.delay = delay || 800; // delay in milliseconds - } + }; ShortcutManager.prototype.help = function () { var help = []; for (var shortcut in this._shortcuts) { - var help_string = this._shortcuts[shortcut]['help']; - var help_index = this._shortcuts[shortcut]['help_index']; + var help_string = this._shortcuts[shortcut].help; + var help_index = this._shortcuts[shortcut].help_index; if (help_string) { if (platform === 'MacOS') { shortcut = shortcut.replace('meta', 'cmd'); @@ -576,45 +576,45 @@ var IPython = (function (IPython) { return 0; }); return help; - } + }; ShortcutManager.prototype.normalize_key = function (key) { return inv_keycodes[keycodes[key]]; - } + }; ShortcutManager.prototype.normalize_shortcut = function (shortcut) { // Sort a sequence of + separated modifiers into the order alt+ctrl+meta+shift shortcut = shortcut.replace('cmd', 'meta').toLowerCase(); var values = shortcut.split("+"); if (values.length === 1) { - return this.normalize_key(values[0]) + return this.normalize_key(values[0]); } else { var modifiers = values.slice(0,-1); var key = this.normalize_key(values[values.length-1]); modifiers.sort(); return modifiers.join('+') + '+' + key; } - } + }; ShortcutManager.prototype.event_to_shortcut = function (event) { // Convert a jQuery keyboard event to a strong based keyboard shortcut var shortcut = ''; - var key = inv_keycodes[event.which] + var key = inv_keycodes[event.which]; if (event.altKey && key !== 'alt') {shortcut += 'alt+';} if (event.ctrlKey && key !== 'ctrl') {shortcut += 'ctrl+';} if (event.metaKey && key !== 'meta') {shortcut += 'meta+';} if (event.shiftKey && key !== 'shift') {shortcut += 'shift+';} shortcut += key; - return shortcut - } + return shortcut; + }; ShortcutManager.prototype.clear_shortcuts = function () { this._shortcuts = {}; - } + }; ShortcutManager.prototype.add_shortcut = function (shortcut, data) { if (typeof(data) === 'function') { - data = {help: '', help_index: '', handler: data} + data = {help: '', help_index: '', handler: data}; } data.help_index = data.help_index || ''; data.help = data.help || ''; @@ -625,19 +625,19 @@ var IPython = (function (IPython) { shortcut = this.normalize_shortcut(shortcut); this._counts[shortcut] = 0; this._shortcuts[shortcut] = data; - } + }; ShortcutManager.prototype.add_shortcuts = function (data) { for (var shortcut in data) { this.add_shortcut(shortcut, data[shortcut]); } - } + }; ShortcutManager.prototype.remove_shortcut = function (shortcut) { shortcut = this.normalize_shortcut(shortcut); delete this._counts[shortcut]; delete this._shortcuts[shortcut]; - } + }; ShortcutManager.prototype.count_handler = function (shortcut, event, data) { var that = this; @@ -646,7 +646,7 @@ var IPython = (function (IPython) { var timer = null; if (c[shortcut] === data.count-1) { c[shortcut] = 0; - var timer = t[shortcut]; + timer = t[shortcut]; if (timer) {clearTimeout(timer); delete t[shortcut];} return data.handler(event); } else { @@ -657,13 +657,13 @@ var IPython = (function (IPython) { t[shortcut] = timer; } return false; - } + }; ShortcutManager.prototype.call_handler = function (event) { var shortcut = this.event_to_shortcut(event); var data = this._shortcuts[shortcut]; if (data) { - var handler = data['handler']; + var handler = data.handler; if (handler) { if (data.count === 1) { return handler(event); @@ -673,7 +673,7 @@ var IPython = (function (IPython) { } } return true; - } + }; @@ -701,14 +701,14 @@ var IPython = (function (IPython) { KeyboardManager.prototype.handle_keydown = function (event) { var notebook = IPython.notebook; - if (event.which === keycodes['esc']) { + if (event.which === keycodes.esc) { // Intercept escape at highest level to avoid closing // websocket connection with firefox event.preventDefault(); } if (!this.enabled) { - if (event.which === keycodes['esc']) { + if (event.which === keycodes.esc) { // ESC notebook.command_mode(); return false; @@ -722,25 +722,25 @@ var IPython = (function (IPython) { return this.command_shortcuts.call_handler(event); } return true; - } + }; KeyboardManager.prototype.edit_mode = function () { this.last_mode = this.mode; this.mode = 'edit'; - } + }; KeyboardManager.prototype.command_mode = function () { this.last_mode = this.mode; this.mode = 'command'; - } + }; KeyboardManager.prototype.enable = function () { this.enabled = true; - } + }; KeyboardManager.prototype.disable = function () { this.enabled = false; - } + }; KeyboardManager.prototype.register_events = function (e) { var that = this; @@ -758,7 +758,7 @@ var IPython = (function (IPython) { that.enable(); } }); - } + }; IPython.keycodes = keycodes;