From f81c4af02f70d0d11dec1cab6d90c8d33882b506 2014-12-10 19:51:01 From: Bussonnier Matthias <bussonniermatthias@gmail.com> Date: 2014-12-10 19:51:01 Subject: [PATCH] Fix comments move humanize-map out of function call to have only one instance --- diff --git a/IPython/html/static/notebook/js/quickhelp.js b/IPython/html/static/notebook/js/quickhelp.js index 2d8ceb4..777d9bf 100644 --- a/IPython/html/static/notebook/js/quickhelp.js +++ b/IPython/html/static/notebook/js/quickhelp.js @@ -65,59 +65,66 @@ define([ { shortcut: cmd_ctrl + "Shift-z", help:"redo" }, { shortcut: cmd_ctrl + "y", help:"redo" }, ].concat( platform_specific ); + + var mac_humanize_map = { + // all these are unicode, will probably display badly on anything except macs. + // these are the standard symbol that are used in MacOS native menus + 'cmd':'⌘', + 'shift':'⇧', + 'alt':'⌥', + 'up':'↑', + 'down':'↓', + 'left':'←', + 'right':'→', + 'eject':'⏏', + 'tab':'⇥', + 'capslock':'⇧', + 'esc':'⎋', + 'ctrl':'⌃', + 'enter':'↩', + 'pageup':'⇞', + 'pagedown':'⇟', + 'home':'↖', + 'end':'↘', + 'altenter':'⌤', + 'space':'␣', + 'backspace':'⇤', + 'apple':'', + }; + + var default_humanize_map = { + 'shift':'Shift', + 'alt':'Alt', + 'up':'Up', + 'down':'Down', + 'left':'Left', + 'right':'Right', + 'tab':'Tab', + 'capslock':'Caps Lock', + 'esc':'Esc', + 'ctrl':'Ctrl', + 'enter':'Enter', + 'pageup':'Page Up', + 'pagedown':'Page Down', + 'home':'Home', + 'end':'End', + 'space':'Space', + 'backspace,':'Backaspace', + }; + + var humanize_map; + + if (platform === 'MacOS'){ + humanize_map = mac_humanize_map; + } else { + humanize_map = default_humanize_map; + } function humanize_key(key){ - if (platform === 'MacOS'){ if (key.length === 1){ key = key.toUpperCase(); } - var d= { - // all these are unicode, will probably display badly on anything except macs. - // these are the standard symbol that are used in MacOS native menus - 'cmd':'⌘', - 'shift':'⇧', - 'alt':'⌥', - 'up':'↑', - 'down':'↓', - 'left':'←', - 'right':'→', - 'eject':'⏏', - 'tab':'⇥', - 'capslock':'⇧', - 'esc':'⎋', - 'ctrl':'⌃', - 'enter':'↩', - 'pageup':'⇞', - 'pagedown':'⇟', - 'home':'↖', - 'end':'↘', - 'altenter':'⌤', - 'space':'␣', - 'backspace':'⇤', - 'apple':'', - }; - } else { - var d = { - 'shift':'Shift', - 'alt':'Alt', - 'up':'Up', - 'down':'Down', - 'left':'Left', - 'right':'Right', - 'tab':'Tab', - 'capslock':'Caps Lock', - 'esc':'Esc', - 'ctrl':'Ctrl', - 'enter':'Enter', - 'pageup':'Page Up', - 'pagedown':'Page Down', - 'home':'Home', - 'end':'End', - 'space':'Space', - 'backspace,':'Backaspace', - }; - } - return d[key.toLowerCase()]||key; + return humanize_map[key.toLowerCase()]||key; } function humanize_sequence(sequence){ diff --git a/IPython/html/static/notebook/js/toolbar.js b/IPython/html/static/notebook/js/toolbar.js index e32c46a..fd0b1f0 100644 --- a/IPython/html/static/notebook/js/toolbar.js +++ b/IPython/html/static/notebook/js/toolbar.js @@ -3,7 +3,7 @@ define([ 'base/js/namespace', - 'jquery', + 'jquery' ], function(IPython, $) { "use strict"; @@ -92,12 +92,13 @@ define([ // get rid of legacy code that handle things that are not actions. ToolBar.prototype.add_buttons_group = function (list, group_id) { // handle custom call of pseudoaction binding. - if(typeof(list) == 'string' && list.slice(0,1) == '<' && list.slice(-1) == '>'){ + if(typeof(list) === 'string' && list.slice(0,1) === '<' && list.slice(-1) === '>'){ + var _pseudo_action; try{ - var _n = list.slice(1,-1) - var fun = this[_n](); + _pseudo_action = list.slice(1,-1); + this[_pseudo_action](); } catch (e) { - console.warn('ouch, calling ', _n, 'does not seem to work...:') + console.warn('ouch, calling ', _pseudo_action, 'does not seem to work...:'); } return ; } @@ -109,7 +110,7 @@ define([ var el; for(var i=0; i < list.length; i++) { - // IIFE because Fucking javascript don't have loop scope so + // IIFE because javascript don't have loop scope so // action_name would otherwise be the same on all iteration // of the loop // TODO: Indent this thing once reviewed: diff --git a/IPython/html/tests/notebook/execute_code.js b/IPython/html/tests/notebook/execute_code.js index b705520..a9551c9 100644 --- a/IPython/html/tests/notebook/execute_code.js +++ b/IPython/html/tests/notebook/execute_code.js @@ -66,6 +66,7 @@ casper.notebook_test(function () { IPython.notebook.select(0); cell.clear_output(); cell.set_text('a=13; print(a)'); + // 'run button' is the first of the forth group in default config. $('#maintoolbar .btn-group:nth(4) .btn:first').click() });