##// END OF EJS Templates
Merge pull request #5146 from jdfreder/modal-fix...
Brian E. Granger -
r15542:edfc0fa3 merge
parent child Browse files
Show More
@@ -1,1 +1,1 b''
1 Subproject commit bf1ac7f0df7207b26775089c5ac788ce11c23be5
1 Subproject commit 2f8958788c7e0416e5c44f532e9630a658df11fd
@@ -48,7 +48,7 b' var IPython = (function (IPython) {'
48 this.cell_id = utils.uuid();
48 this.cell_id = utils.uuid();
49 this._options = options;
49 this._options = options;
50
50
51 // For JS VM engines optimisation, attributes should be all set (even
51 // For JS VM engines optimization, attributes should be all set (even
52 // to null) in the constructor, and if possible, if different subclass
52 // to null) in the constructor, and if possible, if different subclass
53 // have new attributes with same name, they should be created in the
53 // have new attributes with same name, they should be created in the
54 // same order. Easiest is to create and set to null in parent class.
54 // same order. Easiest is to create and set to null in parent class.
@@ -57,7 +57,6 b' var IPython = (function (IPython) {'
57 this.cell_type = this.cell_type || null;
57 this.cell_type = this.cell_type || null;
58 this.code_mirror = null;
58 this.code_mirror = null;
59
59
60
61 this.create_element();
60 this.create_element();
62 if (this.element !== null) {
61 if (this.element !== null) {
63 this.element.data("cell", this);
62 this.element.data("cell", this);
@@ -76,8 +75,7 b' var IPython = (function (IPython) {'
76
75
77 // FIXME: Workaround CM Bug #332 (Safari segfault on drag)
76 // FIXME: Workaround CM Bug #332 (Safari segfault on drag)
78 // by disabling drag/drop altogether on Safari
77 // by disabling drag/drop altogether on Safari
79 // https://github.com/marijnh/CodeMirror/issues/332
78 // https://github.com/marijnh/CodeMirror/issues/332
80
81 if (utils.browser[0] == "Safari") {
79 if (utils.browser[0] == "Safari") {
82 Cell.options_default.cm_config.dragDrop = false;
80 Cell.options_default.cm_config.dragDrop = false;
83 }
81 }
@@ -85,11 +83,8 b' var IPython = (function (IPython) {'
85 Cell.prototype.mergeopt = function(_class, options, overwrite){
83 Cell.prototype.mergeopt = function(_class, options, overwrite){
86 options = options || {};
84 options = options || {};
87 overwrite = overwrite || {};
85 overwrite = overwrite || {};
88 return $.extend(true, {}, _class.options_default, options, overwrite)
86 return $.extend(true, {}, _class.options_default, options, overwrite);
89
87 };
90 }
91
92
93
88
94 /**
89 /**
95 * Empty. Subclasses must implement create_element.
90 * Empty. Subclasses must implement create_element.
@@ -118,8 +113,7 b' var IPython = (function (IPython) {'
118 } else {
113 } else {
119 this.element.addClass('command_mode');
114 this.element.addClass('command_mode');
120 }
115 }
121 }
116 };
122
123
117
124 /**
118 /**
125 * Subclasses can implement override bind_events.
119 * Subclasses can implement override bind_events.
@@ -133,12 +127,12 b' var IPython = (function (IPython) {'
133 that.element.click(function (event) {
127 that.element.click(function (event) {
134 if (!that.selected) {
128 if (!that.selected) {
135 $([IPython.events]).trigger('select.Cell', {'cell':that});
129 $([IPython.events]).trigger('select.Cell', {'cell':that});
136 };
130 }
137 });
131 });
138 that.element.focusin(function (event) {
132 that.element.focusin(function (event) {
139 if (!that.selected) {
133 if (!that.selected) {
140 $([IPython.events]).trigger('select.Cell', {'cell':that});
134 $([IPython.events]).trigger('select.Cell', {'cell':that});
141 };
135 }
142 });
136 });
143 if (this.code_mirror) {
137 if (this.code_mirror) {
144 this.code_mirror.on("change", function(cm, change) {
138 this.code_mirror.on("change", function(cm, change) {
@@ -152,17 +146,9 b' var IPython = (function (IPython) {'
152 }
146 }
153 if (this.code_mirror) {
147 if (this.code_mirror) {
154 this.code_mirror.on('blur', function(cm, change) {
148 this.code_mirror.on('blur', function(cm, change) {
155 if (that.mode === 'edit') {
149 // Check if this unfocus event is legit.
156 setTimeout(function () {
150 if (!that.should_cancel_blur()) {
157 var isf = IPython.utils.is_focused;
151 $([IPython.events]).trigger('command_mode.Cell', {cell: that});
158 var trigger = true;
159 if (isf('div#tooltip') || isf('div.completions')) {
160 trigger = false;
161 }
162 if (trigger) {
163 $([IPython.events]).trigger('command_mode.Cell', {cell: that});
164 }
165 }, 1);
166 }
152 }
167 });
153 });
168 }
154 }
@@ -273,7 +259,18 b' var IPython = (function (IPython) {'
273 } else {
259 } else {
274 return false;
260 return false;
275 }
261 }
276 }
262 };
263
264 /**
265 * Determine whether or not the unfocus event should be aknowledged.
266 *
267 * @method should_cancel_blur
268 *
269 * @return results {bool} Whether or not to ignore the cell's blur event.
270 **/
271 Cell.prototype.should_cancel_blur = function () {
272 return false;
273 };
277
274
278 /**
275 /**
279 * Focus the cell in the DOM sense
276 * Focus the cell in the DOM sense
@@ -281,24 +278,19 b' var IPython = (function (IPython) {'
281 */
278 */
282 Cell.prototype.focus_cell = function () {
279 Cell.prototype.focus_cell = function () {
283 this.element.focus();
280 this.element.focus();
284 }
281 };
285
282
286 /**
283 /**
287 * Focus the editor area so a user can type
284 * Focus the editor area so a user can type
285 *
286 * NOTE: If codemirror is focused via a mouse click event, you don't want to
287 * call this because it will cause a page jump.
288 * @method focus_editor
288 * @method focus_editor
289 */
289 */
290 Cell.prototype.focus_editor = function () {
290 Cell.prototype.focus_editor = function () {
291 var that = this;
292 this.refresh();
291 this.refresh();
293 // Only focus the CM editor if it is not focused already. This prevents jumps
292 this.code_mirror.focus();
294 // related to the previous prompt position.
293 };
295 setTimeout(function () {
296 var isf = IPython.utils.is_focused;
297 if (!isf(that.element.find('div.CodeMirror'))) {
298 that.code_mirror.focus();
299 }
300 }, 1);
301 }
302
294
303 /**
295 /**
304 * Refresh codemirror instance
296 * Refresh codemirror instance
@@ -375,7 +367,7 b' var IPython = (function (IPython) {'
375 var text = this.code_mirror.getRange({line:0, ch:0}, cursor);
367 var text = this.code_mirror.getRange({line:0, ch:0}, cursor);
376 text = text.replace(/^\n+/, '').replace(/\n+$/, '');
368 text = text.replace(/^\n+/, '').replace(/\n+$/, '');
377 return text;
369 return text;
378 }
370 };
379
371
380
372
381 /**
373 /**
@@ -386,7 +378,7 b' var IPython = (function (IPython) {'
386 var cursor = this.code_mirror.getCursor();
378 var cursor = this.code_mirror.getCursor();
387 var last_line_num = this.code_mirror.lineCount()-1;
379 var last_line_num = this.code_mirror.lineCount()-1;
388 var last_line_len = this.code_mirror.getLine(last_line_num).length;
380 var last_line_len = this.code_mirror.getLine(last_line_num).length;
389 var end = {line:last_line_num, ch:last_line_len}
381 var end = {line:last_line_num, ch:last_line_len};
390 var text = this.code_mirror.getRange(cursor, end);
382 var text = this.code_mirror.getRange(cursor, end);
391 text = text.replace(/^\n+/, '').replace(/\n+$/, '');
383 text = text.replace(/^\n+/, '').replace(/\n+$/, '');
392 return text;
384 return text;
@@ -430,9 +422,10 b' var IPython = (function (IPython) {'
430 **/
422 **/
431 Cell.prototype._auto_highlight = function (modes) {
423 Cell.prototype._auto_highlight = function (modes) {
432 //Here we handle manually selected modes
424 //Here we handle manually selected modes
433 if( this.user_highlight != undefined && this.user_highlight != 'auto' )
425 var mode;
426 if( this.user_highlight !== undefined && this.user_highlight != 'auto' )
434 {
427 {
435 var mode = this.user_highlight;
428 mode = this.user_highlight;
436 CodeMirror.autoLoadMode(this.code_mirror, mode);
429 CodeMirror.autoLoadMode(this.code_mirror, mode);
437 this.code_mirror.setOption('mode', mode);
430 this.code_mirror.setOption('mode', mode);
438 return;
431 return;
@@ -440,22 +433,22 b' var IPython = (function (IPython) {'
440 var current_mode = this.code_mirror.getOption('mode', mode);
433 var current_mode = this.code_mirror.getOption('mode', mode);
441 var first_line = this.code_mirror.getLine(0);
434 var first_line = this.code_mirror.getLine(0);
442 // loop on every pairs
435 // loop on every pairs
443 for( var mode in modes) {
436 for(mode in modes) {
444 var regs = modes[mode]['reg'];
437 var regs = modes[mode].reg;
445 // only one key every time but regexp can't be keys...
438 // only one key every time but regexp can't be keys...
446 for(var i=0; i<regs.length; i++) {
439 for(var i=0; i<regs.length; i++) {
447 // here we handle non magic_modes
440 // here we handle non magic_modes
448 if(first_line.match(regs[i]) != null) {
441 if(first_line.match(regs[i]) !== null) {
449 if(current_mode == mode){
442 if(current_mode == mode){
450 return;
443 return;
451 }
444 }
452 if (mode.search('magic_') != 0) {
445 if (mode.search('magic_') !== 0) {
453 this.code_mirror.setOption('mode', mode);
446 this.code_mirror.setOption('mode', mode);
454 CodeMirror.autoLoadMode(this.code_mirror, mode);
447 CodeMirror.autoLoadMode(this.code_mirror, mode);
455 return;
448 return;
456 }
449 }
457 var open = modes[mode]['open']|| "%%";
450 var open = modes[mode].open || "%%";
458 var close = modes[mode]['close']|| "%%end";
451 var close = modes[mode].close || "%%end";
459 var mmode = mode;
452 var mmode = mode;
460 mode = mmode.substr(6);
453 mode = mmode.substr(6);
461 if(current_mode == mode){
454 if(current_mode == mode){
@@ -482,14 +475,14 b' var IPython = (function (IPython) {'
482 }
475 }
483 }
476 }
484 // fallback on default
477 // fallback on default
485 var default_mode
478 var default_mode;
486 try {
479 try {
487 default_mode = this._options.cm_config.mode;
480 default_mode = this._options.cm_config.mode;
488 } catch(e) {
481 } catch(e) {
489 default_mode = 'text/plain';
482 default_mode = 'text/plain';
490 }
483 }
491 if( current_mode === default_mode){
484 if( current_mode === default_mode){
492 return
485 return;
493 }
486 }
494 this.code_mirror.setOption('mode', default_mode);
487 this.code_mirror.setOption('mode', default_mode);
495 };
488 };
@@ -402,13 +402,20 b' var IPython = (function (IPython) {'
402 return false;
402 return false;
403 };
403 };
404
404
405 CodeCell.prototype.edit_mode = function () {
405 /**
406 var cont = IPython.Cell.prototype.edit_mode.apply(this);
406 * Determine whether or not the unfocus event should be aknowledged.
407 if (cont) {
407 *
408 this.focus_editor();
408 * @method should_cancel_blur
409 }
409 *
410 return cont;
410 * @return results {bool} Whether or not to ignore the cell's blur event.
411 }
411 **/
412 CodeCell.prototype.should_cancel_blur = function () {
413 // Cancel this unfocus event if the base wants to cancel or the cell
414 // completer is open or the tooltip is open.
415 return IPython.Cell.prototype.should_cancel_blur.apply(this) ||
416 (this.completer && this.completer.is_visible()) ||
417 (IPython.tooltip && IPython.tooltip.is_visible());
418 };
412
419
413 CodeCell.prototype.select_all = function () {
420 CodeCell.prototype.select_all = function () {
414 var start = {line: 0, ch: 0};
421 var start = {line: 0, ch: 0};
@@ -73,6 +73,7 b' var IPython = (function (IPython) {'
73
73
74
74
75 var Completer = function (cell) {
75 var Completer = function (cell) {
76 this._visible = false;
76 this.cell = cell;
77 this.cell = cell;
77 this.editor = cell.code_mirror;
78 this.editor = cell.code_mirror;
78 var that = this;
79 var that = this;
@@ -84,6 +85,10 b' var IPython = (function (IPython) {'
84 });
85 });
85 };
86 };
86
87
88 Completer.prototype.is_visible = function () {
89 // Return whether or not the completer is visible.
90 return this._visible;
91 };
87
92
88 Completer.prototype.startCompletion = function () {
93 Completer.prototype.startCompletion = function () {
89 // call for a 'first' completion, that will set the editor and do some
94 // call for a 'first' completion, that will set the editor and do some
@@ -225,6 +230,7 b' var IPython = (function (IPython) {'
225 .attr('multiple', 'true')
230 .attr('multiple', 'true')
226 .attr('size', Math.min(10, this.raw_result.length));
231 .attr('size', Math.min(10, this.raw_result.length));
227 this.complete.append(this.sel);
232 this.complete.append(this.sel);
233 this._visible = true;
228 $('body').append(this.complete);
234 $('body').append(this.complete);
229
235
230 // After everything is on the page, compute the postion.
236 // After everything is on the page, compute the postion.
@@ -282,6 +288,7 b' var IPython = (function (IPython) {'
282 };
288 };
283
289
284 Completer.prototype.close = function () {
290 Completer.prototype.close = function () {
291 this._visible = false;
285 if (this.done) return;
292 if (this.done) return;
286 this.done = true;
293 this.done = true;
287 $('.completions').remove();
294 $('.completions').remove();
@@ -42,12 +42,12 b' var IPython = (function (IPython) {'
42 // These apply to Firefox and Opera
42 // These apply to Firefox and Opera
43 var _mozilla_keycodes = {
43 var _mozilla_keycodes = {
44 '; :': 59, '= +': 61, '- _': 173, 'meta': 224
44 '; :': 59, '= +': 61, '- _': 173, 'meta': 224
45 }
45 };
46
46
47 // This apply to Webkit and IE
47 // This apply to Webkit and IE
48 var _ie_keycodes = {
48 var _ie_keycodes = {
49 '; :': 186, '= +': 187, '- _': 189,
49 '; :': 186, '= +': 187, '- _': 189,
50 }
50 };
51
51
52 var browser = IPython.utils.browser[0];
52 var browser = IPython.utils.browser[0];
53 var platform = IPython.utils.platform;
53 var platform = IPython.utils.platform;
@@ -63,15 +63,15 b' var IPython = (function (IPython) {'
63 for (var name in _keycodes) {
63 for (var name in _keycodes) {
64 var names = name.split(' ');
64 var names = name.split(' ');
65 if (names.length === 1) {
65 if (names.length === 1) {
66 var n = names[0]
66 var n = names[0];
67 keycodes[n] = _keycodes[n]
67 keycodes[n] = _keycodes[n];
68 inv_keycodes[_keycodes[n]] = n
68 inv_keycodes[_keycodes[n]] = n;
69 } else {
69 } else {
70 var primary = names[0];
70 var primary = names[0];
71 var secondary = names[1];
71 var secondary = names[1];
72 keycodes[primary] = _keycodes[name]
72 keycodes[primary] = _keycodes[name];
73 keycodes[secondary] = _keycodes[name]
73 keycodes[secondary] = _keycodes[name];
74 inv_keycodes[_keycodes[name]] = primary
74 inv_keycodes[_keycodes[name]] = primary;
75 }
75 }
76 }
76 }
77
77
@@ -111,7 +111,7 b' var IPython = (function (IPython) {'
111 return false;
111 return false;
112 }
112 }
113 }
113 }
114 }
114 };
115
115
116 if (platform === 'MacOS') {
116 if (platform === 'MacOS') {
117 default_common_shortcuts['cmd+s'] =
117 default_common_shortcuts['cmd+s'] =
@@ -165,11 +165,11 b' var IPython = (function (IPython) {'
165 var cell = IPython.notebook.get_selected_cell();
165 var cell = IPython.notebook.get_selected_cell();
166 if (cell && cell.at_top()) {
166 if (cell && cell.at_top()) {
167 event.preventDefault();
167 event.preventDefault();
168 IPython.notebook.command_mode()
168 IPython.notebook.command_mode();
169 IPython.notebook.select_prev();
169 IPython.notebook.select_prev();
170 IPython.notebook.edit_mode();
170 IPython.notebook.edit_mode();
171 return false;
171 return false;
172 };
172 }
173 }
173 }
174 },
174 },
175 'down' : {
175 'down' : {
@@ -179,11 +179,11 b' var IPython = (function (IPython) {'
179 var cell = IPython.notebook.get_selected_cell();
179 var cell = IPython.notebook.get_selected_cell();
180 if (cell && cell.at_bottom()) {
180 if (cell && cell.at_bottom()) {
181 event.preventDefault();
181 event.preventDefault();
182 IPython.notebook.command_mode()
182 IPython.notebook.command_mode();
183 IPython.notebook.select_next();
183 IPython.notebook.select_next();
184 IPython.notebook.edit_mode();
184 IPython.notebook.edit_mode();
185 return false;
185 return false;
186 };
186 }
187 }
187 }
188 },
188 },
189 'alt+-' : {
189 'alt+-' : {
@@ -210,7 +210,7 b' var IPython = (function (IPython) {'
210 help : 'tooltip',
210 help : 'tooltip',
211 help_index : 'ed',
211 help_index : 'ed',
212 },
212 },
213 }
213 };
214
214
215 if (platform === 'MacOS') {
215 if (platform === 'MacOS') {
216 default_edit_shortcuts['cmd+/'] =
216 default_edit_shortcuts['cmd+/'] =
@@ -264,9 +264,8 b' var IPython = (function (IPython) {'
264 var index = IPython.notebook.get_selected_index();
264 var index = IPython.notebook.get_selected_index();
265 if (index !== 0 && index !== null) {
265 if (index !== 0 && index !== null) {
266 IPython.notebook.select_prev();
266 IPython.notebook.select_prev();
267 var cell = IPython.notebook.get_selected_cell();
267 IPython.notebook.focus_cell();
268 cell.focus_cell();
268 }
269 };
270 return false;
269 return false;
271 }
270 }
272 },
271 },
@@ -277,9 +276,8 b' var IPython = (function (IPython) {'
277 var index = IPython.notebook.get_selected_index();
276 var index = IPython.notebook.get_selected_index();
278 if (index !== (IPython.notebook.ncells()-1) && index !== null) {
277 if (index !== (IPython.notebook.ncells()-1) && index !== null) {
279 IPython.notebook.select_next();
278 IPython.notebook.select_next();
280 var cell = IPython.notebook.get_selected_cell();
279 IPython.notebook.focus_cell();
281 cell.focus_cell();
280 }
282 };
283 return false;
281 return false;
284 }
282 }
285 },
283 },
@@ -290,9 +288,8 b' var IPython = (function (IPython) {'
290 var index = IPython.notebook.get_selected_index();
288 var index = IPython.notebook.get_selected_index();
291 if (index !== 0 && index !== null) {
289 if (index !== 0 && index !== null) {
292 IPython.notebook.select_prev();
290 IPython.notebook.select_prev();
293 var cell = IPython.notebook.get_selected_cell();
291 IPython.notebook.focus_cell();
294 cell.focus_cell();
292 }
295 };
296 return false;
293 return false;
297 }
294 }
298 },
295 },
@@ -303,9 +300,8 b' var IPython = (function (IPython) {'
303 var index = IPython.notebook.get_selected_index();
300 var index = IPython.notebook.get_selected_index();
304 if (index !== (IPython.notebook.ncells()-1) && index !== null) {
301 if (index !== (IPython.notebook.ncells()-1) && index !== null) {
305 IPython.notebook.select_next();
302 IPython.notebook.select_next();
306 var cell = IPython.notebook.get_selected_cell();
303 IPython.notebook.focus_cell();
307 cell.focus_cell();
304 }
308 };
309 return false;
305 return false;
310 }
306 }
311 },
307 },
@@ -540,23 +536,23 b' var IPython = (function (IPython) {'
540 return false;
536 return false;
541 }
537 }
542 },
538 },
543 }
539 };
544
540
545
541
546 // Shortcut manager class
542 // Shortcut manager class
547
543
548 var ShortcutManager = function (delay) {
544 var ShortcutManager = function (delay) {
549 this._shortcuts = {}
545 this._shortcuts = {};
550 this._counts = {}
546 this._counts = {};
551 this._timers = {}
547 this._timers = {};
552 this.delay = delay || 800; // delay in milliseconds
548 this.delay = delay || 800; // delay in milliseconds
553 }
549 };
554
550
555 ShortcutManager.prototype.help = function () {
551 ShortcutManager.prototype.help = function () {
556 var help = [];
552 var help = [];
557 for (var shortcut in this._shortcuts) {
553 for (var shortcut in this._shortcuts) {
558 var help_string = this._shortcuts[shortcut]['help'];
554 var help_string = this._shortcuts[shortcut].help;
559 var help_index = this._shortcuts[shortcut]['help_index'];
555 var help_index = this._shortcuts[shortcut].help_index;
560 if (help_string) {
556 if (help_string) {
561 if (platform === 'MacOS') {
557 if (platform === 'MacOS') {
562 shortcut = shortcut.replace('meta', 'cmd');
558 shortcut = shortcut.replace('meta', 'cmd');
@@ -576,45 +572,45 b' var IPython = (function (IPython) {'
576 return 0;
572 return 0;
577 });
573 });
578 return help;
574 return help;
579 }
575 };
580
576
581 ShortcutManager.prototype.normalize_key = function (key) {
577 ShortcutManager.prototype.normalize_key = function (key) {
582 return inv_keycodes[keycodes[key]];
578 return inv_keycodes[keycodes[key]];
583 }
579 };
584
580
585 ShortcutManager.prototype.normalize_shortcut = function (shortcut) {
581 ShortcutManager.prototype.normalize_shortcut = function (shortcut) {
586 // Sort a sequence of + separated modifiers into the order alt+ctrl+meta+shift
582 // Sort a sequence of + separated modifiers into the order alt+ctrl+meta+shift
587 shortcut = shortcut.replace('cmd', 'meta').toLowerCase();
583 shortcut = shortcut.replace('cmd', 'meta').toLowerCase();
588 var values = shortcut.split("+");
584 var values = shortcut.split("+");
589 if (values.length === 1) {
585 if (values.length === 1) {
590 return this.normalize_key(values[0])
586 return this.normalize_key(values[0]);
591 } else {
587 } else {
592 var modifiers = values.slice(0,-1);
588 var modifiers = values.slice(0,-1);
593 var key = this.normalize_key(values[values.length-1]);
589 var key = this.normalize_key(values[values.length-1]);
594 modifiers.sort();
590 modifiers.sort();
595 return modifiers.join('+') + '+' + key;
591 return modifiers.join('+') + '+' + key;
596 }
592 }
597 }
593 };
598
594
599 ShortcutManager.prototype.event_to_shortcut = function (event) {
595 ShortcutManager.prototype.event_to_shortcut = function (event) {
600 // Convert a jQuery keyboard event to a strong based keyboard shortcut
596 // Convert a jQuery keyboard event to a strong based keyboard shortcut
601 var shortcut = '';
597 var shortcut = '';
602 var key = inv_keycodes[event.which]
598 var key = inv_keycodes[event.which];
603 if (event.altKey && key !== 'alt') {shortcut += 'alt+';}
599 if (event.altKey && key !== 'alt') {shortcut += 'alt+';}
604 if (event.ctrlKey && key !== 'ctrl') {shortcut += 'ctrl+';}
600 if (event.ctrlKey && key !== 'ctrl') {shortcut += 'ctrl+';}
605 if (event.metaKey && key !== 'meta') {shortcut += 'meta+';}
601 if (event.metaKey && key !== 'meta') {shortcut += 'meta+';}
606 if (event.shiftKey && key !== 'shift') {shortcut += 'shift+';}
602 if (event.shiftKey && key !== 'shift') {shortcut += 'shift+';}
607 shortcut += key;
603 shortcut += key;
608 return shortcut
604 return shortcut;
609 }
605 };
610
606
611 ShortcutManager.prototype.clear_shortcuts = function () {
607 ShortcutManager.prototype.clear_shortcuts = function () {
612 this._shortcuts = {};
608 this._shortcuts = {};
613 }
609 };
614
610
615 ShortcutManager.prototype.add_shortcut = function (shortcut, data) {
611 ShortcutManager.prototype.add_shortcut = function (shortcut, data) {
616 if (typeof(data) === 'function') {
612 if (typeof(data) === 'function') {
617 data = {help: '', help_index: '', handler: data}
613 data = {help: '', help_index: '', handler: data};
618 }
614 }
619 data.help_index = data.help_index || '';
615 data.help_index = data.help_index || '';
620 data.help = data.help || '';
616 data.help = data.help || '';
@@ -625,19 +621,19 b' var IPython = (function (IPython) {'
625 shortcut = this.normalize_shortcut(shortcut);
621 shortcut = this.normalize_shortcut(shortcut);
626 this._counts[shortcut] = 0;
622 this._counts[shortcut] = 0;
627 this._shortcuts[shortcut] = data;
623 this._shortcuts[shortcut] = data;
628 }
624 };
629
625
630 ShortcutManager.prototype.add_shortcuts = function (data) {
626 ShortcutManager.prototype.add_shortcuts = function (data) {
631 for (var shortcut in data) {
627 for (var shortcut in data) {
632 this.add_shortcut(shortcut, data[shortcut]);
628 this.add_shortcut(shortcut, data[shortcut]);
633 }
629 }
634 }
630 };
635
631
636 ShortcutManager.prototype.remove_shortcut = function (shortcut) {
632 ShortcutManager.prototype.remove_shortcut = function (shortcut) {
637 shortcut = this.normalize_shortcut(shortcut);
633 shortcut = this.normalize_shortcut(shortcut);
638 delete this._counts[shortcut];
634 delete this._counts[shortcut];
639 delete this._shortcuts[shortcut];
635 delete this._shortcuts[shortcut];
640 }
636 };
641
637
642 ShortcutManager.prototype.count_handler = function (shortcut, event, data) {
638 ShortcutManager.prototype.count_handler = function (shortcut, event, data) {
643 var that = this;
639 var that = this;
@@ -646,7 +642,7 b' var IPython = (function (IPython) {'
646 var timer = null;
642 var timer = null;
647 if (c[shortcut] === data.count-1) {
643 if (c[shortcut] === data.count-1) {
648 c[shortcut] = 0;
644 c[shortcut] = 0;
649 var timer = t[shortcut];
645 timer = t[shortcut];
650 if (timer) {clearTimeout(timer); delete t[shortcut];}
646 if (timer) {clearTimeout(timer); delete t[shortcut];}
651 return data.handler(event);
647 return data.handler(event);
652 } else {
648 } else {
@@ -657,13 +653,13 b' var IPython = (function (IPython) {'
657 t[shortcut] = timer;
653 t[shortcut] = timer;
658 }
654 }
659 return false;
655 return false;
660 }
656 };
661
657
662 ShortcutManager.prototype.call_handler = function (event) {
658 ShortcutManager.prototype.call_handler = function (event) {
663 var shortcut = this.event_to_shortcut(event);
659 var shortcut = this.event_to_shortcut(event);
664 var data = this._shortcuts[shortcut];
660 var data = this._shortcuts[shortcut];
665 if (data) {
661 if (data) {
666 var handler = data['handler'];
662 var handler = data.handler;
667 if (handler) {
663 if (handler) {
668 if (data.count === 1) {
664 if (data.count === 1) {
669 return handler(event);
665 return handler(event);
@@ -673,12 +669,11 b' var IPython = (function (IPython) {'
673 }
669 }
674 }
670 }
675 return true;
671 return true;
676 }
672 };
677
678
673
679
674
680 // Main keyboard manager for the notebook
675 // Main keyboard manager for the notebook
681
676
682 var KeyboardManager = function () {
677 var KeyboardManager = function () {
683 this.mode = 'command';
678 this.mode = 'command';
684 this.enabled = true;
679 this.enabled = true;
@@ -701,14 +696,14 b' var IPython = (function (IPython) {'
701 KeyboardManager.prototype.handle_keydown = function (event) {
696 KeyboardManager.prototype.handle_keydown = function (event) {
702 var notebook = IPython.notebook;
697 var notebook = IPython.notebook;
703
698
704 if (event.which === keycodes['esc']) {
699 if (event.which === keycodes.esc) {
705 // Intercept escape at highest level to avoid closing
700 // Intercept escape at highest level to avoid closing
706 // websocket connection with firefox
701 // websocket connection with firefox
707 event.preventDefault();
702 event.preventDefault();
708 }
703 }
709
704
710 if (!this.enabled) {
705 if (!this.enabled) {
711 if (event.which === keycodes['esc']) {
706 if (event.which === keycodes.esc) {
712 // ESC
707 // ESC
713 notebook.command_mode();
708 notebook.command_mode();
714 return false;
709 return false;
@@ -722,43 +717,60 b' var IPython = (function (IPython) {'
722 return this.command_shortcuts.call_handler(event);
717 return this.command_shortcuts.call_handler(event);
723 }
718 }
724 return true;
719 return true;
725 }
720 };
726
721
727 KeyboardManager.prototype.edit_mode = function () {
722 KeyboardManager.prototype.edit_mode = function () {
728 this.last_mode = this.mode;
723 this.last_mode = this.mode;
729 this.mode = 'edit';
724 this.mode = 'edit';
730 }
725 };
731
726
732 KeyboardManager.prototype.command_mode = function () {
727 KeyboardManager.prototype.command_mode = function () {
733 this.last_mode = this.mode;
728 this.last_mode = this.mode;
734 this.mode = 'command';
729 this.mode = 'command';
735 }
730 };
736
731
737 KeyboardManager.prototype.enable = function () {
732 KeyboardManager.prototype.enable = function () {
738 this.enabled = true;
733 this.enabled = true;
739 }
734 };
740
735
741 KeyboardManager.prototype.disable = function () {
736 KeyboardManager.prototype.disable = function () {
742 this.enabled = false;
737 this.enabled = false;
743 }
738 };
744
739
745 KeyboardManager.prototype.register_events = function (e) {
740 KeyboardManager.prototype.register_events = function (e) {
746 var that = this;
741 var that = this;
747 e.on('focusin', function () {
742 var handle_focus = function () {
748 that.disable();
743 that.disable();
749 });
744 };
750 e.on('focusout', function () {
745 var handle_blur = function () {
751 that.enable();
746 that.enable();
752 });
747 };
748 e.on('focusin', handle_focus);
749 e.on('focusout', handle_blur);
750 // TODO: Very strange. The focusout event does not seem fire for the
751 // bootstrap textboxes on FF25&26... This works around that by
752 // registering focus and blur events recursively on all inputs within
753 // registered element.
754 e.find('input').blur(handle_blur);
755 e.on('DOMNodeInserted', function (event) {
756 var target = $(event.target);
757 if (target.is('input')) {
758 target.blur(handle_blur);
759 } else {
760 target.find('input').blur(handle_blur);
761 }
762 });
753 // There are times (raw_input) where we remove the element from the DOM before
763 // There are times (raw_input) where we remove the element from the DOM before
754 // focusout is called. In this case we bind to the remove event of jQueryUI,
764 // focusout is called. In this case we bind to the remove event of jQueryUI,
755 // which gets triggered upon removal, iff it is focused at the time.
765 // which gets triggered upon removal, iff it is focused at the time.
766 // is_focused must be used to check for the case where an element within
767 // the element being removed is focused.
756 e.on('remove', function () {
768 e.on('remove', function () {
757 if (document.activeElement === e[0]) {
769 if (IPython.utils.is_focused(e[0])) {
758 that.enable();
770 that.enable();
759 }
771 }
760 });
772 });
761 }
773 };
762
774
763
775
764 IPython.keycodes = keycodes;
776 IPython.keycodes = keycodes;
@@ -116,9 +116,7 b' var IPython = (function (IPython) {'
116 });
116 });
117
117
118 $([IPython.events]).on('edit_mode.Cell', function (event, data) {
118 $([IPython.events]).on('edit_mode.Cell', function (event, data) {
119 var index = that.find_cell_index(data.cell);
119 that.handle_edit_mode(that.find_cell_index(data.cell));
120 that.select(index);
121 that.edit_mode();
122 });
120 });
123
121
124 $([IPython.events]).on('command_mode.Cell', function (event, data) {
122 $([IPython.events]).on('command_mode.Cell', function (event, data) {
@@ -459,7 +457,6 b' var IPython = (function (IPython) {'
459 if (this.is_valid_cell_index(index)) {
457 if (this.is_valid_cell_index(index)) {
460 var sindex = this.get_selected_index();
458 var sindex = this.get_selected_index();
461 if (sindex !== null && index !== sindex) {
459 if (sindex !== null && index !== sindex) {
462 this.command_mode();
463 this.get_cell(sindex).unselect();
460 this.get_cell(sindex).unselect();
464 }
461 }
465 var cell = this.get_cell(index);
462 var cell = this.get_cell(index);
@@ -504,6 +501,13 b' var IPython = (function (IPython) {'
504
501
505 // Edit/Command mode
502 // Edit/Command mode
506
503
504 /**
505 * Gets the index of the cell that is in edit mode.
506 *
507 * @method get_edit_index
508 *
509 * @return index {int}
510 **/
507 Notebook.prototype.get_edit_index = function () {
511 Notebook.prototype.get_edit_index = function () {
508 var result = null;
512 var result = null;
509 this.get_cell_elements().filter(function (index) {
513 this.get_cell_elements().filter(function (index) {
@@ -514,32 +518,74 b' var IPython = (function (IPython) {'
514 return result;
518 return result;
515 };
519 };
516
520
521 /**
522 * Make the notebook enter command mode.
523 *
524 * @method command_mode
525 **/
517 Notebook.prototype.command_mode = function () {
526 Notebook.prototype.command_mode = function () {
527 // Make sure there isn't an edit mode cell lingering around.
528 var cell = this.get_cell(this.get_edit_index());
529 if (cell) {
530 cell.command_mode();
531 }
532
533 // Notify the keyboard manager if this is a change of mode for the
534 // notebook as a whole.
518 if (this.mode !== 'command') {
535 if (this.mode !== 'command') {
519 $([IPython.events]).trigger('command_mode.Notebook');
520 var index = this.get_edit_index();
521 var cell = this.get_cell(index);
522 if (cell) {
523 cell.command_mode();
524 }
525 this.mode = 'command';
536 this.mode = 'command';
537 $([IPython.events]).trigger('command_mode.Notebook');
526 IPython.keyboard_manager.command_mode();
538 IPython.keyboard_manager.command_mode();
527 }
539 }
528 };
540 };
529
541
530 Notebook.prototype.edit_mode = function () {
542 /**
543 * Handle when a cell fires it's edit_mode event.
544 *
545 * @method handle_edit_mode
546 * @param [index] {int} Cell index to select. If no index is provided,
547 * the current selected cell is used.
548 **/
549 Notebook.prototype.handle_edit_mode = function (index) {
550 // Make sure the cell exists.
551 var cell = this.get_cell(index);
552 if (cell === null) { return; }
553
554 // Set the cell to edit mode and notify the keyboard manager if this
555 // is a change of mode for the notebook as a whole.
531 if (this.mode !== 'edit') {
556 if (this.mode !== 'edit') {
532 $([IPython.events]).trigger('edit_mode.Notebook');
557 cell.edit_mode();
533 var cell = this.get_selected_cell();
534 if (cell === null) {return;} // No cell is selected
535 // We need to set the mode to edit to prevent reentering this method
536 // when cell.edit_mode() is called below.
537 this.mode = 'edit';
558 this.mode = 'edit';
559 $([IPython.events]).trigger('edit_mode.Notebook');
538 IPython.keyboard_manager.edit_mode();
560 IPython.keyboard_manager.edit_mode();
539 cell.edit_mode();
540 }
561 }
541 };
562 };
542
563
564 /**
565 * Make a cell enter edit mode.
566 *
567 * @method edit_mode
568 * @param [index] {int} Cell index to select. If no index is provided,
569 * the current selected cell is used.
570 **/
571 Notebook.prototype.edit_mode = function (index) {
572 if (index===undefined) {
573 index = this.get_selected_index();
574 }
575 // Make sure the cell exists.
576 var cell = this.get_cell(index);
577 if (cell === null) { return; }
578 if (cell.mode != 'edit') {
579 cell.unrender();
580 cell.focus_editor();
581 }
582 };
583
584 /**
585 * Focus the currently selected cell.
586 *
587 * @method focus_cell
588 **/
543 Notebook.prototype.focus_cell = function () {
589 Notebook.prototype.focus_cell = function () {
544 var cell = this.get_selected_cell();
590 var cell = this.get_selected_cell();
545 if (cell === null) {return;} // No cell is selected
591 if (cell === null) {return;} // No cell is selected
@@ -1403,8 +1449,8 b' var IPython = (function (IPython) {'
1403 var cell_index = this.find_cell_index(cell);
1449 var cell_index = this.find_cell_index(cell);
1404
1450
1405 cell.execute();
1451 cell.execute();
1406 this.command_mode();
1407 cell.focus_cell();
1452 cell.focus_cell();
1453 this.command_mode();
1408 this.set_dirty(true);
1454 this.set_dirty(true);
1409 };
1455 };
1410
1456
@@ -1422,16 +1468,14 b' var IPython = (function (IPython) {'
1422 // If we are at the end always insert a new cell and return
1468 // If we are at the end always insert a new cell and return
1423 if (cell_index === (this.ncells()-1)) {
1469 if (cell_index === (this.ncells()-1)) {
1424 this.insert_cell_below('code');
1470 this.insert_cell_below('code');
1425 this.select(cell_index+1);
1471 this.edit_mode(cell_index+1);
1426 this.edit_mode();
1427 this.scroll_to_bottom();
1472 this.scroll_to_bottom();
1428 this.set_dirty(true);
1473 this.set_dirty(true);
1429 return;
1474 return;
1430 }
1475 }
1431
1476
1432 this.insert_cell_below('code');
1477 this.insert_cell_below('code');
1433 this.select(cell_index+1);
1478 this.edit_mode(cell_index+1);
1434 this.edit_mode();
1435 this.set_dirty(true);
1479 this.set_dirty(true);
1436 };
1480 };
1437
1481
@@ -1450,8 +1494,7 b' var IPython = (function (IPython) {'
1450 // If we are at the end always insert a new cell and return
1494 // If we are at the end always insert a new cell and return
1451 if (cell_index === (this.ncells()-1)) {
1495 if (cell_index === (this.ncells()-1)) {
1452 this.insert_cell_below('code');
1496 this.insert_cell_below('code');
1453 this.select(cell_index+1);
1497 this.edit_mode(cell_index+1);
1454 this.edit_mode();
1455 this.scroll_to_bottom();
1498 this.scroll_to_bottom();
1456 this.set_dirty(true);
1499 this.set_dirty(true);
1457 return;
1500 return;
@@ -1459,6 +1502,7 b' var IPython = (function (IPython) {'
1459
1502
1460 this.select(cell_index+1);
1503 this.select(cell_index+1);
1461 this.get_cell(cell_index+1).focus_cell();
1504 this.get_cell(cell_index+1).focus_cell();
1505 this.command_mode();
1462 this.set_dirty(true);
1506 this.set_dirty(true);
1463 };
1507 };
1464
1508
@@ -1925,8 +1969,7 b' var IPython = (function (IPython) {'
1925 this.fromJSON(data);
1969 this.fromJSON(data);
1926 if (this.ncells() === 0) {
1970 if (this.ncells() === 0) {
1927 this.insert_cell_below('code');
1971 this.insert_cell_below('code');
1928 this.select(0);
1972 this.edit_mode(0);
1929 this.edit_mode();
1930 } else {
1973 } else {
1931 this.select(0);
1974 this.select(0);
1932 this.command_mode();
1975 this.command_mode();
@@ -2286,3 +2329,4 b' var IPython = (function (IPython) {'
2286 return IPython;
2329 return IPython;
2287
2330
2288 }(IPython));
2331 }(IPython));
2332
@@ -81,7 +81,7 b' var IPython = (function (IPython) {'
81 this.celltoolbar = new IPython.CellToolbar(this);
81 this.celltoolbar = new IPython.CellToolbar(this);
82 inner_cell.append(this.celltoolbar.element);
82 inner_cell.append(this.celltoolbar.element);
83 var input_area = $('<div/>').addClass('text_cell_input border-box-sizing');
83 var input_area = $('<div/>').addClass('text_cell_input border-box-sizing');
84 this.code_mirror = CodeMirror(input_area.get(0), this.cm_config);
84 this.code_mirror = new CodeMirror(input_area.get(0), this.cm_config);
85 // The tabindex=-1 makes this div focusable.
85 // The tabindex=-1 makes this div focusable.
86 var render_area = $('<div/>').addClass('text_cell_render border-box-sizing').
86 var render_area = $('<div/>').addClass('text_cell_render border-box-sizing').
87 addClass('rendered_html').attr('tabindex','-1');
87 addClass('rendered_html').attr('tabindex','-1');
@@ -104,8 +104,11 b' var IPython = (function (IPython) {'
104 this.element.dblclick(function () {
104 this.element.dblclick(function () {
105 if (that.selected === false) {
105 if (that.selected === false) {
106 $([IPython.events]).trigger('select.Cell', {'cell':that});
106 $([IPython.events]).trigger('select.Cell', {'cell':that});
107 };
107 }
108 $([IPython.events]).trigger('edit_mode.Cell', {cell: that});
108 var cont = that.unrender();
109 if (cont) {
110 that.focus_editor();
111 }
109 });
112 });
110 };
113 };
111
114
@@ -145,7 +148,7 b' var IPython = (function (IPython) {'
145 return false;
148 return false;
146 } else {
149 } else {
147 return true;
150 return true;
148 };
151 }
149 } else if (event.which === key.DOWNARROW && event.type === 'keydown') {
152 } else if (event.which === key.DOWNARROW && event.type === 'keydown') {
150 // If we are not at the bottom, let CM handle the down arrow and
153 // If we are not at the bottom, let CM handle the down arrow and
151 // prevent the global keydown handler from handling it.
154 // prevent the global keydown handler from handling it.
@@ -154,7 +157,7 b' var IPython = (function (IPython) {'
154 return false;
157 return false;
155 } else {
158 } else {
156 return true;
159 return true;
157 };
160 }
158 } else if (event.which === key.ESC && event.type === 'keydown') {
161 } else if (event.which === key.ESC && event.type === 'keydown') {
159 if (that.code_mirror.options.keyMap === "vim-insert") {
162 if (that.code_mirror.options.keyMap === "vim-insert") {
160 // vim keyMap is active and in insert mode. In this case we leave vim
163 // vim keyMap is active and in insert mode. In this case we leave vim
@@ -179,7 +182,7 b' var IPython = (function (IPython) {'
179 if (this.mode === 'edit') {
182 if (this.mode === 'edit') {
180 this.code_mirror.refresh();
183 this.code_mirror.refresh();
181 }
184 }
182 };
185 }
183 return cont;
186 return cont;
184 };
187 };
185
188
@@ -193,10 +196,9 b' var IPython = (function (IPython) {'
193 text_cell.find('div.text_cell_input').show();
196 text_cell.find('div.text_cell_input').show();
194 if (this.get_text() === this.placeholder) {
197 if (this.get_text() === this.placeholder) {
195 this.set_text('');
198 this.set_text('');
196 this.refresh();
197 }
199 }
198
200 this.refresh();
199 };
201 }
200 return cont;
202 return cont;
201 };
203 };
202
204
@@ -204,15 +206,6 b' var IPython = (function (IPython) {'
204 this.render();
206 this.render();
205 };
207 };
206
208
207 TextCell.prototype.edit_mode = function () {
208 var cont = IPython.Cell.prototype.edit_mode.apply(this);
209 if (cont) {
210 this.unrender();
211 this.focus_editor();
212 };
213 return cont;
214 }
215
216 /**
209 /**
217 * setter: {{#crossLink "TextCell/set_text"}}{{/crossLink}}
210 * setter: {{#crossLink "TextCell/set_text"}}{{/crossLink}}
218 * @method get_text
211 * @method get_text
@@ -261,8 +254,8 b' var IPython = (function (IPython) {'
261 return true;
254 return true;
262 } else {
255 } else {
263 return false;
256 return false;
264 };
257 }
265 };
258 }
266 };
259 };
267
260
268 /**
261 /**
@@ -278,8 +271,8 b' var IPython = (function (IPython) {'
278 return true;
271 return true;
279 } else {
272 } else {
280 return false;
273 return false;
281 };
274 }
282 };
275 }
283 };
276 };
284
277
285 /**
278 /**
@@ -332,7 +325,7 b' var IPython = (function (IPython) {'
332 mode: 'gfm'
325 mode: 'gfm'
333 },
326 },
334 placeholder: "Type *Markdown* and LaTeX: $\\alpha^2$"
327 placeholder: "Type *Markdown* and LaTeX: $\\alpha^2$"
335 }
328 };
336
329
337 MarkdownCell.prototype = new TextCell();
330 MarkdownCell.prototype = new TextCell();
338
331
@@ -363,8 +356,8 b' var IPython = (function (IPython) {'
363 }
356 }
364 this.element.find('div.text_cell_input').hide();
357 this.element.find('div.text_cell_input').hide();
365 this.element.find("div.text_cell_render").show();
358 this.element.find("div.text_cell_render").show();
366 this.typeset()
359 this.typeset();
367 };
360 }
368 return cont;
361 return cont;
369 };
362 };
370
363
@@ -378,7 +371,7 b' var IPython = (function (IPython) {'
378 */
371 */
379 var RawCell = function (options) {
372 var RawCell = function (options) {
380
373
381 options = this.mergeopt(RawCell,options)
374 options = this.mergeopt(RawCell,options);
382 TextCell.apply(this, [options]);
375 TextCell.apply(this, [options]);
383 this.cell_type = 'raw';
376 this.cell_type = 'raw';
384 // RawCell should always hide its rendered div
377 // RawCell should always hide its rendered div
@@ -396,7 +389,7 b' var IPython = (function (IPython) {'
396 /** @method bind_events **/
389 /** @method bind_events **/
397 RawCell.prototype.bind_events = function () {
390 RawCell.prototype.bind_events = function () {
398 TextCell.prototype.bind_events.apply(this);
391 TextCell.prototype.bind_events.apply(this);
399 var that = this
392 var that = this;
400 this.element.focusout(function() {
393 this.element.focusout(function() {
401 that.auto_highlight();
394 that.auto_highlight();
402 });
395 });
@@ -452,7 +445,7 b' var IPython = (function (IPython) {'
452
445
453 /** @method fromJSON */
446 /** @method fromJSON */
454 HeadingCell.prototype.fromJSON = function (data) {
447 HeadingCell.prototype.fromJSON = function (data) {
455 if (data.level != undefined){
448 if (data.level !== undefined){
456 this.level = data.level;
449 this.level = data.level;
457 }
450 }
458 TextCell.prototype.fromJSON.apply(this, arguments);
451 TextCell.prototype.fromJSON.apply(this, arguments);
@@ -492,7 +485,7 b' var IPython = (function (IPython) {'
492 if (this.rendered) {
485 if (this.rendered) {
493 this.rendered = false;
486 this.rendered = false;
494 this.render();
487 this.render();
495 };
488 }
496 };
489 };
497
490
498 /** The depth of header cell, based on html (h1 to h6)
491 /** The depth of header cell, based on html (h1 to h6)
@@ -544,7 +537,7 b' var IPython = (function (IPython) {'
544 this.element.find('div.text_cell_input').hide();
537 this.element.find('div.text_cell_input').hide();
545 this.element.find("div.text_cell_render").show();
538 this.element.find("div.text_cell_render").show();
546
539
547 };
540 }
548 return cont;
541 return cont;
549 };
542 };
550
543
@@ -52,7 +52,7 b' var IPython = (function (IPython) {'
52 // expand the tooltip to see more
52 // expand the tooltip to see more
53 var expandlink = $('<a/>').attr('href', "#").addClass("ui-corner-all") //rounded corner
53 var expandlink = $('<a/>').attr('href', "#").addClass("ui-corner-all") //rounded corner
54 .attr('role', "button").attr('id', 'expanbutton').attr('title', 'Grow the tooltip vertically (press tab 2 times)').click(function () {
54 .attr('role', "button").attr('id', 'expanbutton').attr('title', 'Grow the tooltip vertically (press tab 2 times)').click(function () {
55 that.expand()
55 that.expand();
56 }).append(
56 }).append(
57 $('<span/>').text('Expand').addClass('ui-icon').addClass('ui-icon-plus'));
57 $('<span/>').text('Expand').addClass('ui-icon').addClass('ui-icon-plus'));
58
58
@@ -121,9 +121,13 b' var IPython = (function (IPython) {'
121 this._old_cell = (cell) ? cell : null;
121 this._old_cell = (cell) ? cell : null;
122 this._old_request = (text) ? text : null;
122 this._old_request = (text) ? text : null;
123 this._consecutive_counter = 0;
123 this._consecutive_counter = 0;
124 }
124 };
125 };
125 };
126
126
127 Tooltip.prototype.is_visible = function () {
128 return !this._hidden;
129 };
130
127 Tooltip.prototype.showInPager = function (cell) {
131 Tooltip.prototype.showInPager = function (cell) {
128 // reexecute last call in pager by appending ? to show back in pager
132 // reexecute last call in pager by appending ? to show back in pager
129 var that = this;
133 var that = this;
@@ -139,27 +143,27 b' var IPython = (function (IPython) {'
139 'store_history': true
143 'store_history': true
140 });
144 });
141 this.remove_and_cancel_tooltip();
145 this.remove_and_cancel_tooltip();
142 }
146 };
143
147
144 // grow the tooltip verticaly
148 // grow the tooltip verticaly
145 Tooltip.prototype.expand = function () {
149 Tooltip.prototype.expand = function () {
146 this.text.removeClass('smalltooltip');
150 this.text.removeClass('smalltooltip');
147 this.text.addClass('bigtooltip');
151 this.text.addClass('bigtooltip');
148 $('#expanbutton').hide('slow');
152 $('#expanbutton').hide('slow');
149 }
153 };
150
154
151 // deal with all the logic of hiding the tooltip
155 // deal with all the logic of hiding the tooltip
152 // and reset it's status
156 // and reset it's status
153 Tooltip.prototype._hide = function () {
157 Tooltip.prototype._hide = function () {
158 this._hidden = true;
154 this.tooltip.fadeOut('fast');
159 this.tooltip.fadeOut('fast');
155 $('#expanbutton').show('slow');
160 $('#expanbutton').show('slow');
156 this.text.removeClass('bigtooltip');
161 this.text.removeClass('bigtooltip');
157 this.text.addClass('smalltooltip');
162 this.text.addClass('smalltooltip');
158 // keep scroll top to be sure to always see the first line
163 // keep scroll top to be sure to always see the first line
159 this.text.scrollTop(0);
164 this.text.scrollTop(0);
160 this._hidden = true;
161 this.code_mirror = null;
165 this.code_mirror = null;
162 }
166 };
163
167
164 // return true on successfully removing a visible tooltip; otherwise return
168 // return true on successfully removing a visible tooltip; otherwise return
165 // false.
169 // false.
@@ -178,23 +182,23 b' var IPython = (function (IPython) {'
178 } else {
182 } else {
179 return false;
183 return false;
180 }
184 }
181 }
185 };
182
186
183 // cancel autocall done after '(' for example.
187 // cancel autocall done after '(' for example.
184 Tooltip.prototype.cancel_pending = function () {
188 Tooltip.prototype.cancel_pending = function () {
185 if (this._tooltip_timeout != null) {
189 if (this._tooltip_timeout !== null) {
186 clearTimeout(this._tooltip_timeout);
190 clearTimeout(this._tooltip_timeout);
187 this._tooltip_timeout = null;
191 this._tooltip_timeout = null;
188 }
192 }
189 }
193 };
190
194
191 // will trigger tooltip after timeout
195 // will trigger tooltip after timeout
192 Tooltip.prototype.pending = function (cell, hide_if_no_docstring) {
196 Tooltip.prototype.pending = function (cell, hide_if_no_docstring) {
193 var that = this;
197 var that = this;
194 this._tooltip_timeout = setTimeout(function () {
198 this._tooltip_timeout = setTimeout(function () {
195 that.request(cell, hide_if_no_docstring)
199 that.request(cell, hide_if_no_docstring);
196 }, that.time_before_tooltip);
200 }, that.time_before_tooltip);
197 }
201 };
198
202
199 // easy access for julia monkey patching.
203 // easy access for julia monkey patching.
200 Tooltip.last_token_re = /[a-z_][0-9a-z._]*$/gi;
204 Tooltip.last_token_re = /[a-z_][0-9a-z._]*$/gi;
@@ -219,7 +223,7 b' var IPython = (function (IPython) {'
219 line = line.replace(endBracket, "");
223 line = line.replace(endBracket, "");
220 // reset the regex object
224 // reset the regex object
221 Tooltip.last_token_re.lastIndex = 0;
225 Tooltip.last_token_re.lastIndex = 0;
222 return Tooltip.last_token_re.exec(line)
226 return Tooltip.last_token_re.exec(line);
223 };
227 };
224
228
225 Tooltip.prototype._request_tooltip = function (cell, line) {
229 Tooltip.prototype._request_tooltip = function (cell, line) {
@@ -252,7 +256,7 b' var IPython = (function (IPython) {'
252
256
253 // now we treat the different number of keypress
257 // now we treat the different number of keypress
254 // first if same cell, same text, increment counter by 1
258 // first if same cell, same text, increment counter by 1
255 if (this._old_cell == cell && this._old_request == text && this._hidden == false) {
259 if (this._old_cell == cell && this._old_request == text && this._hidden === false) {
256 this._consecutive_counter++;
260 this._consecutive_counter++;
257 } else {
261 } else {
258 // else reset
262 // else reset
@@ -273,7 +277,7 b' var IPython = (function (IPython) {'
273 }
277 }
274
278
275 return;
279 return;
276 }
280 };
277
281
278 // cancel the option of having the tooltip to stick
282 // cancel the option of having the tooltip to stick
279 Tooltip.prototype.cancel_stick = function () {
283 Tooltip.prototype.cancel_stick = function () {
@@ -281,14 +285,14 b' var IPython = (function (IPython) {'
281 this._stick_timeout = null;
285 this._stick_timeout = null;
282 this._clocklink.hide('slow');
286 this._clocklink.hide('slow');
283 this._sticky = false;
287 this._sticky = false;
284 }
288 };
285
289
286 // put the tooltip in a sicky state for 10 seconds
290 // put the tooltip in a sicky state for 10 seconds
287 // it won't be removed by remove_and_cancell() unless you called with
291 // it won't be removed by remove_and_cancell() unless you called with
288 // the first parameter set to true.
292 // the first parameter set to true.
289 // remove_and_cancell_tooltip(true)
293 // remove_and_cancell_tooltip(true)
290 Tooltip.prototype.stick = function (time) {
294 Tooltip.prototype.stick = function (time) {
291 time = (time != undefined) ? time : 10;
295 time = (time !== undefined) ? time : 10;
292 var that = this;
296 var that = this;
293 this._sticky = true;
297 this._sticky = true;
294 this._clocklink.show('slow');
298 this._clocklink.show('slow');
@@ -296,7 +300,7 b' var IPython = (function (IPython) {'
296 that._sticky = false;
300 that._sticky = false;
297 that._clocklink.hide('slow');
301 that._clocklink.hide('slow');
298 }, time * 1000);
302 }, time * 1000);
299 }
303 };
300
304
301 // should be called with the kernel reply to actually show the tooltip
305 // should be called with the kernel reply to actually show the tooltip
302 Tooltip.prototype._show = function (reply) {
306 Tooltip.prototype._show = function (reply) {
@@ -322,7 +326,7 b' var IPython = (function (IPython) {'
322 var xinter = o.left + (xinit - o.left) / w * (w - 450);
326 var xinter = o.left + (xinit - o.left) / w * (w - 450);
323 var posarrowleft = xinit - xinter;
327 var posarrowleft = xinit - xinter;
324
328
325 if (this._hidden == false) {
329 if (this._hidden === false) {
326 this.tooltip.animate({
330 this.tooltip.animate({
327 'left': xinter - 30 + 'px',
331 'left': xinter - 30 + 'px',
328 'top': (head.bottom + 10) + 'px'
332 'top': (head.bottom + 10) + 'px'
@@ -365,8 +369,8 b' var IPython = (function (IPython) {'
365 }
369 }
366 }
370 }
367
371
368 this.tooltip.fadeIn('fast');
369 this._hidden = false;
372 this._hidden = false;
373 this.tooltip.fadeIn('fast');
370 this.text.children().remove();
374 this.text.children().remove();
371
375
372 var pre = $('<pre/>').html(utils.fixConsole(docstring));
376 var pre = $('<pre/>').html(utils.fixConsole(docstring));
@@ -377,8 +381,7 b' var IPython = (function (IPython) {'
377 this.text.append(pre);
381 this.text.append(pre);
378 // keep scroll top to be sure to always see the first line
382 // keep scroll top to be sure to always see the first line
379 this.text.scrollTop(0);
383 this.text.scrollTop(0);
380 }
384 };
381
382
385
383 IPython.Tooltip = Tooltip;
386 IPython.Tooltip = Tooltip;
384
387
General Comments 0
You need to be logged in to leave comments. Login now