##// END OF EJS Templates
semicolon fixes buttress half of my js commits
Paul Ivanov -
Show More
@@ -44,12 +44,12 b' IPython.keyboard = (function (IPython) {'
44 // These apply to Firefox and Opera
44 // These apply to Firefox and Opera
45 var _mozilla_keycodes = {
45 var _mozilla_keycodes = {
46 '; :': 59, '= +': 61, '- _': 173, 'meta': 224
46 '; :': 59, '= +': 61, '- _': 173, 'meta': 224
47 }
47 };
48
48
49 // This apply to Webkit and IE
49 // This apply to Webkit and IE
50 var _ie_keycodes = {
50 var _ie_keycodes = {
51 '; :': 186, '= +': 187, '- _': 189,
51 '; :': 186, '= +': 187, '- _': 189,
52 }
52 };
53
53
54 var browser = IPython.utils.browser[0];
54 var browser = IPython.utils.browser[0];
55 var platform = IPython.utils.platform;
55 var platform = IPython.utils.platform;
@@ -65,21 +65,21 b' IPython.keyboard = (function (IPython) {'
65 for (var name in _keycodes) {
65 for (var name in _keycodes) {
66 var names = name.split(' ');
66 var names = name.split(' ');
67 if (names.length === 1) {
67 if (names.length === 1) {
68 var n = names[0]
68 var n = names[0];
69 keycodes[n] = _keycodes[n]
69 keycodes[n] = _keycodes[n];
70 inv_keycodes[_keycodes[n]] = n
70 inv_keycodes[_keycodes[n]] = n;
71 } else {
71 } else {
72 var primary = names[0];
72 var primary = names[0];
73 var secondary = names[1];
73 var secondary = names[1];
74 keycodes[primary] = _keycodes[name]
74 keycodes[primary] = _keycodes[name];
75 keycodes[secondary] = _keycodes[name]
75 keycodes[secondary] = _keycodes[name];
76 inv_keycodes[_keycodes[name]] = primary
76 inv_keycodes[_keycodes[name]] = primary;
77 }
77 }
78 }
78 }
79
79
80 var normalize_key = function (key) {
80 var normalize_key = function (key) {
81 return inv_keycodes[keycodes[key]];
81 return inv_keycodes[keycodes[key]];
82 }
82 };
83
83
84 var normalize_shortcut = function (shortcut) {
84 var normalize_shortcut = function (shortcut) {
85 // Put a shortcut into normalized form:
85 // Put a shortcut into normalized form:
@@ -90,14 +90,14 b' IPython.keyboard = (function (IPython) {'
90 shortcut = shortcut.toLowerCase().replace('cmd', 'meta');
90 shortcut = shortcut.toLowerCase().replace('cmd', 'meta');
91 var values = shortcut.split("+");
91 var values = shortcut.split("+");
92 if (values.length === 1) {
92 if (values.length === 1) {
93 return normalize_key(values[0])
93 return normalize_key(values[0]);
94 } else {
94 } else {
95 var modifiers = values.slice(0,-1);
95 var modifiers = values.slice(0,-1);
96 var key = normalize_key(values[values.length-1]);
96 var key = normalize_key(values[values.length-1]);
97 modifiers.sort();
97 modifiers.sort();
98 return modifiers.join('+') + '+' + key;
98 return modifiers.join('+') + '+' + key;
99 }
99 }
100 }
100 };
101
101
102 var shortcut_to_event = function (shortcut, type) {
102 var shortcut_to_event = function (shortcut, type) {
103 // Convert a shortcut (shift+r) to a jQuery Event object
103 // Convert a shortcut (shift+r) to a jQuery Event object
@@ -112,19 +112,19 b' IPython.keyboard = (function (IPython) {'
112 if (modifiers.indexOf('meta') !== -1) {opts.metaKey = true;}
112 if (modifiers.indexOf('meta') !== -1) {opts.metaKey = true;}
113 if (modifiers.indexOf('shift') !== -1) {opts.shiftKey = true;}
113 if (modifiers.indexOf('shift') !== -1) {opts.shiftKey = true;}
114 return $.Event(type, opts);
114 return $.Event(type, opts);
115 }
115 };
116
116
117 var event_to_shortcut = function (event) {
117 var event_to_shortcut = function (event) {
118 // Convert a jQuery Event object to a shortcut (shift+r)
118 // Convert a jQuery Event object to a shortcut (shift+r)
119 var shortcut = '';
119 var shortcut = '';
120 var key = inv_keycodes[event.which]
120 var key = inv_keycodes[event.which];
121 if (event.altKey && key !== 'alt') {shortcut += 'alt+';}
121 if (event.altKey && key !== 'alt') {shortcut += 'alt+';}
122 if (event.ctrlKey && key !== 'ctrl') {shortcut += 'ctrl+';}
122 if (event.ctrlKey && key !== 'ctrl') {shortcut += 'ctrl+';}
123 if (event.metaKey && key !== 'meta') {shortcut += 'meta+';}
123 if (event.metaKey && key !== 'meta') {shortcut += 'meta+';}
124 if (event.shiftKey && key !== 'shift') {shortcut += 'shift+';}
124 if (event.shiftKey && key !== 'shift') {shortcut += 'shift+';}
125 shortcut += key;
125 shortcut += key;
126 return shortcut
126 return shortcut;
127 }
127 };
128
128
129 var trigger_keydown = function (shortcut, element) {
129 var trigger_keydown = function (shortcut, element) {
130 // Trigger shortcut keydown on an element
130 // Trigger shortcut keydown on an element
@@ -132,17 +132,17 b' IPython.keyboard = (function (IPython) {'
132 element = $(element);
132 element = $(element);
133 var event = shortcut_to_event(shortcut, 'keydown');
133 var event = shortcut_to_event(shortcut, 'keydown');
134 element.trigger(event);
134 element.trigger(event);
135 }
135 };
136
136
137
137
138 // Shortcut manager class
138 // Shortcut manager class
139
139
140 var ShortcutManager = function (delay) {
140 var ShortcutManager = function (delay) {
141 this._shortcuts = {}
141 this._shortcuts = {};
142 this._counts = {}
142 this._counts = {};
143 this._timers = {}
143 this._timers = {};
144 this.delay = delay || 800; // delay in milliseconds
144 this.delay = delay || 800; // delay in milliseconds
145 }
145 };
146
146
147 ShortcutManager.prototype.help = function () {
147 ShortcutManager.prototype.help = function () {
148 var help = [];
148 var help = [];
@@ -168,15 +168,15 b' IPython.keyboard = (function (IPython) {'
168 return 0;
168 return 0;
169 });
169 });
170 return help;
170 return help;
171 }
171 };
172
172
173 ShortcutManager.prototype.clear_shortcuts = function () {
173 ShortcutManager.prototype.clear_shortcuts = function () {
174 this._shortcuts = {};
174 this._shortcuts = {};
175 }
175 };
176
176
177 ShortcutManager.prototype.add_shortcut = function (shortcut, data, suppress_help_update) {
177 ShortcutManager.prototype.add_shortcut = function (shortcut, data, suppress_help_update) {
178 if (typeof(data) === 'function') {
178 if (typeof(data) === 'function') {
179 data = {help: '', help_index: '', handler: data}
179 data = {help: '', help_index: '', handler: data};
180 }
180 }
181 data.help_index = data.help_index || '';
181 data.help_index = data.help_index || '';
182 data.help = data.help || '';
182 data.help = data.help || '';
@@ -189,9 +189,9 b' IPython.keyboard = (function (IPython) {'
189 this._shortcuts[shortcut] = data;
189 this._shortcuts[shortcut] = data;
190 if (!suppress_help_update) {
190 if (!suppress_help_update) {
191 // update the keyboard shortcuts notebook help
191 // update the keyboard shortcuts notebook help
192 $([IPython.events]).trigger('rebuild.QuickHelp')
192 $([IPython.events]).trigger('rebuild.QuickHelp');
193 }
193 }
194 }
194 };
195
195
196 ShortcutManager.prototype.add_shortcuts = function (data) {
196 ShortcutManager.prototype.add_shortcuts = function (data) {
197 for (var shortcut in data) {
197 for (var shortcut in data) {
@@ -199,7 +199,7 b' IPython.keyboard = (function (IPython) {'
199 }
199 }
200 // update the keyboard shortcuts notebook help
200 // update the keyboard shortcuts notebook help
201 $([IPython.events]).trigger('rebuild.QuickHelp');
201 $([IPython.events]).trigger('rebuild.QuickHelp');
202 }
202 };
203
203
204 ShortcutManager.prototype.remove_shortcut = function (shortcut, suppress_help_update) {
204 ShortcutManager.prototype.remove_shortcut = function (shortcut, suppress_help_update) {
205 shortcut = normalize_shortcut(shortcut);
205 shortcut = normalize_shortcut(shortcut);
@@ -209,7 +209,7 b' IPython.keyboard = (function (IPython) {'
209 // update the keyboard shortcuts notebook help
209 // update the keyboard shortcuts notebook help
210 $([IPython.events]).trigger('rebuild.QuickHelp');
210 $([IPython.events]).trigger('rebuild.QuickHelp');
211 }
211 }
212 }
212 };
213
213
214 ShortcutManager.prototype.count_handler = function (shortcut, event, data) {
214 ShortcutManager.prototype.count_handler = function (shortcut, event, data) {
215 var that = this;
215 var that = this;
@@ -229,7 +229,7 b' IPython.keyboard = (function (IPython) {'
229 t[shortcut] = timer;
229 t[shortcut] = timer;
230 }
230 }
231 return false;
231 return false;
232 }
232 };
233
233
234 ShortcutManager.prototype.call_handler = function (event) {
234 ShortcutManager.prototype.call_handler = function (event) {
235 var shortcut = event_to_shortcut(event);
235 var shortcut = event_to_shortcut(event);
@@ -245,7 +245,7 b' IPython.keyboard = (function (IPython) {'
245 }
245 }
246 }
246 }
247 return true;
247 return true;
248 }
248 };
249
249
250 return {
250 return {
251 keycodes : keycodes,
251 keycodes : keycodes,
@@ -256,6 +256,6 b' IPython.keyboard = (function (IPython) {'
256 shortcut_to_event : shortcut_to_event,
256 shortcut_to_event : shortcut_to_event,
257 event_to_shortcut : event_to_shortcut,
257 event_to_shortcut : event_to_shortcut,
258 trigger_keydown : trigger_keydown
258 trigger_keydown : trigger_keydown
259 }
259 };
260
260
261 }(IPython));
261 }(IPython));
@@ -42,7 +42,7 b' var IPython = (function (IPython) {'
42 'allows you to type code/text into a cell and is indicated by a green cell '+
42 'allows you to type code/text into a cell and is indicated by a green cell '+
43 'border. <b>Command mode</b> binds the keyboard to notebook level actions '+
43 'border. <b>Command mode</b> binds the keyboard to notebook level actions '+
44 'and is indicated by a grey cell border.'
44 'and is indicated by a grey cell border.'
45 )
45 );
46 element.append(doc);
46 element.append(doc);
47
47
48 // Command mode
48 // Command mode
@@ -68,7 +68,7 b' var IPython = (function (IPython) {'
68 QuickHelp.prototype.build_command_help = function () {
68 QuickHelp.prototype.build_command_help = function () {
69 var command_shortcuts = IPython.keyboard_manager.command_shortcuts.help();
69 var command_shortcuts = IPython.keyboard_manager.command_shortcuts.help();
70 return build_div('<h4>Command Mode (press <code>Esc</code> to enable)</h4>', command_shortcuts);
70 return build_div('<h4>Command Mode (press <code>Esc</code> to enable)</h4>', command_shortcuts);
71 }
71 };
72
72
73 var special_case = { pageup: "PageUp", pagedown: "Page Down" };
73 var special_case = { pageup: "PageUp", pagedown: "Page Down" };
74 var prettify = function (s) {
74 var prettify = function (s) {
@@ -92,16 +92,16 b' var IPython = (function (IPython) {'
92 var edit_shortcuts = IPython.keyboard_manager.edit_shortcuts.help();
92 var edit_shortcuts = IPython.keyboard_manager.edit_shortcuts.help();
93 // Edit mode
93 // Edit mode
94 return build_div('<h4>Edit Mode (press <code>Enter</code> to enable)</h4>', edit_shortcuts);
94 return build_div('<h4>Edit Mode (press <code>Enter</code> to enable)</h4>', edit_shortcuts);
95 }
95 };
96
96
97 var build_one = function (s) {
97 var build_one = function (s) {
98 var help = s['help'];
98 var help = s.help;
99 var shortcut = prettify(s['shortcut']);
99 var shortcut = prettify(s.shortcut);
100 return $('<div>').addClass('quickhelp').
100 return $('<div>').addClass('quickhelp').
101 append($('<span/>').addClass('shortcut_key').append($(shortcut))).
101 append($('<span/>').addClass('shortcut_key').append($(shortcut))).
102 append($('<span/>').addClass('shortcut_descr').text(' : ' + help))
102 append($('<span/>').addClass('shortcut_descr').text(' : ' + help));
103
103
104 }
104 };
105
105
106 var build_div = function (title, shortcuts) {
106 var build_div = function (title, shortcuts) {
107 var i, half, n;
107 var i, half, n;
@@ -111,12 +111,12 b' var IPython = (function (IPython) {'
111 var col2 = $('<div/>').addClass('box-flex0');
111 var col2 = $('<div/>').addClass('box-flex0');
112 n = shortcuts.length;
112 n = shortcuts.length;
113 half = ~~(n/2); // Truncate :)
113 half = ~~(n/2); // Truncate :)
114 for (i=0; i<half; i++) { col1.append( build_one(shortcuts[i]) ); };
114 for (i=0; i<half; i++) { col1.append( build_one(shortcuts[i]) ); }
115 for (i=half; i<n; i++) { col2.append( build_one(shortcuts[i]) ); };
115 for (i=half; i<n; i++) { col2.append( build_one(shortcuts[i]) ); }
116 sub_div.append(col1).append(col2);
116 sub_div.append(col1).append(col2);
117 div.append(sub_div);
117 div.append(sub_div);
118 return div;
118 return div;
119 }
119 };
120
120
121 // Set module variables
121 // Set module variables
122 IPython.QuickHelp = QuickHelp;
122 IPython.QuickHelp = QuickHelp;
General Comments 0
You need to be logged in to leave comments. Login now