##// END OF EJS Templates
Clean up javascript based on js2-mode feedback.
Stefan van der Walt -
Show More
@@ -45,16 +45,16 b' var IPython = (function (IPython) {'
45
45
46 Cell.prototype.bind_events = function () {
46 Cell.prototype.bind_events = function () {
47 var that = this;
47 var that = this;
48 var nb = that.notebook
48 var nb = that.notebook;
49 that.element.click(function (event) {
49 that.element.click(function (event) {
50 if (that.selected === false) {
50 if (that.selected === false) {
51 nb.select(nb.find_cell_index(that));
51 nb.select(nb.find_cell_index(that));
52 };
52 }
53 });
53 });
54 that.element.focusin(function (event) {
54 that.element.focusin(function (event) {
55 if (that.selected === false) {
55 if (that.selected === false) {
56 nb.select(nb.find_cell_index(that));
56 nb.select(nb.find_cell_index(that));
57 };
57 }
58 });
58 });
59 };
59 };
60
60
@@ -44,7 +44,7 b' var IPython = (function (IPython) {'
44 var output = $('<div></div>').addClass('output vbox');
44 var output = $('<div></div>').addClass('output vbox');
45 cell.append(input).append(output);
45 cell.append(input).append(output);
46 this.element = cell;
46 this.element = cell;
47 this.collapse()
47 this.collapse();
48 };
48 };
49
49
50 //TODO, try to diminish the number of parameters.
50 //TODO, try to diminish the number of parameters.
@@ -123,7 +123,7 b' var IPython = (function (IPython) {'
123 return true;
123 return true;
124 } else {
124 } else {
125 return false;
125 return false;
126 };
126 }
127 } else if (event.keyCode === 76 && event.ctrlKey && event.shiftKey
127 } else if (event.keyCode === 76 && event.ctrlKey && event.shiftKey
128 && event.type == 'keydown') {
128 && event.type == 'keydown') {
129 // toggle line numbers with Ctrl-Shift-L
129 // toggle line numbers with Ctrl-Shift-L
@@ -138,10 +138,11 b' var IPython = (function (IPython) {'
138 if (ed_cur.line !== cc_cur.line || ed_cur.ch !== cc_cur.ch) {
138 if (ed_cur.line !== cc_cur.line || ed_cur.ch !== cc_cur.ch) {
139 this.is_completing = false;
139 this.is_completing = false;
140 this.completion_cursor = null;
140 this.completion_cursor = null;
141 };
141 }
142 };
142 }
143 return false;
143 return false;
144 };
144 };
145 return false;
145 };
146 };
146
147
147 CodeCell.prototype.remove_and_cancell_tooltip = function(timeout)
148 CodeCell.prototype.remove_and_cancell_tooltip = function(timeout)
@@ -345,7 +346,7 b' var IPython = (function (IPython) {'
345 } else {
346 } else {
346 this.code_mirror.setOption('lineNumbers', false);
347 this.code_mirror.setOption('lineNumbers', false);
347 }
348 }
348 this.code_mirror.refresh()
349 this.code_mirror.refresh();
349 };
350 };
350
351
351 CodeCell.prototype.select = function () {
352 CodeCell.prototype.select = function () {
@@ -447,7 +448,7 b' var IPython = (function (IPython) {'
447
448
448 CodeCell.prototype.append_display_data = function (json) {
449 CodeCell.prototype.append_display_data = function (json) {
449 var toinsert = this.create_output_area();
450 var toinsert = this.create_output_area();
450 this.append_mime_type(json, toinsert)
451 this.append_mime_type(json, toinsert);
451 this.element.find('div.output').append(toinsert);
452 this.element.find('div.output').append(toinsert);
452 // If we just output latex, typeset it.
453 // If we just output latex, typeset it.
453 if ( (json.latex !== undefined) || (json.html !== undefined) ) {
454 if ( (json.latex !== undefined) || (json.html !== undefined) ) {
@@ -477,7 +478,7 b' var IPython = (function (IPython) {'
477 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_html rendered_html");
478 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_html rendered_html");
478 toinsert.append(html);
479 toinsert.append(html);
479 element.append(toinsert);
480 element.append(toinsert);
480 }
481 };
481
482
482
483
483 CodeCell.prototype.append_text = function (data, element, extra_class) {
484 CodeCell.prototype.append_text = function (data, element, extra_class) {
@@ -517,7 +518,7 b' var IPython = (function (IPython) {'
517 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_latex");
518 var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_latex");
518 toinsert.append(latex);
519 toinsert.append(latex);
519 element.append(toinsert);
520 element.append(toinsert);
520 }
521 };
521
522
522
523
523 CodeCell.prototype.clear_output = function (stdout, stderr, other) {
524 CodeCell.prototype.clear_output = function (stdout, stderr, other) {
@@ -589,7 +590,7 b' var IPython = (function (IPython) {'
589
590
590 CodeCell.prototype.set_input_prompt = function (number) {
591 CodeCell.prototype.set_input_prompt = function (number) {
591 var n = number || '&nbsp;';
592 var n = number || '&nbsp;';
592 this.input_prompt_number = n
593 this.input_prompt_number = n;
593 this.element.find('div.input_prompt').html('In&nbsp;[' + n + ']:');
594 this.element.find('div.input_prompt').html('In&nbsp;[' + n + ']:');
594 };
595 };
595
596
@@ -653,7 +654,7 b' var IPython = (function (IPython) {'
653 data.input = this.get_code();
654 data.input = this.get_code();
654 data.cell_type = 'code';
655 data.cell_type = 'code';
655 if (this.input_prompt_number !== ' ') {
656 if (this.input_prompt_number !== ' ') {
656 data.prompt_number = this.input_prompt_number
657 data.prompt_number = this.input_prompt_number;
657 };
658 };
658 var outputs = [];
659 var outputs = [];
659 var len = this.outputs.length;
660 var len = this.outputs.length;
@@ -23,9 +23,9 b' var IPython = (function (IPython) {'
23 this.session_id = utils.uuid();
23 this.session_id = utils.uuid();
24
24
25 if (typeof(WebSocket) !== 'undefined') {
25 if (typeof(WebSocket) !== 'undefined') {
26 this.WebSocket = WebSocket
26 this.WebSocket = WebSocket;
27 } else if (typeof(MozWebSocket) !== 'undefined') {
27 } else if (typeof(MozWebSocket) !== 'undefined') {
28 this.WebSocket = MozWebSocket
28 this.WebSocket = MozWebSocket;
29 } else {
29 } else {
30 alert('Your browser does not have WebSocket support, please try Chrome, Safari or Firefox β‰₯ 6. Firefox 4 and 5 are also supported by you have to enable WebSockets in about:config.');
30 alert('Your browser does not have WebSocket support, please try Chrome, Safari or Firefox β‰₯ 6. Firefox 4 and 5 are also supported by you have to enable WebSockets in about:config.');
31 };
31 };
@@ -44,13 +44,13 b' var IPython = (function (IPython) {'
44 parent_header : {}
44 parent_header : {}
45 };
45 };
46 return msg;
46 return msg;
47 }
47 };
48
48
49 Kernel.prototype.start = function (notebook_id, callback) {
49 Kernel.prototype.start = function (notebook_id, callback) {
50 var that = this;
50 var that = this;
51 if (!this.running) {
51 if (!this.running) {
52 var qs = $.param({notebook:notebook_id});
52 var qs = $.param({notebook:notebook_id});
53 var url = this.base_url + '?' + qs
53 var url = this.base_url + '?' + qs;
54 $.post(url,
54 $.post(url,
55 function (kernel_id) {
55 function (kernel_id) {
56 that._handle_start_kernel(kernel_id, callback);
56 that._handle_start_kernel(kernel_id, callback);
@@ -95,10 +95,10 b' var IPython = (function (IPython) {'
95 " You will NOT be able to run code.<br/>" +
95 " You will NOT be able to run code.<br/>" +
96 " Your browser may not be compatible with the websocket version in the server," +
96 " Your browser may not be compatible with the websocket version in the server," +
97 " or if the url does not look right, there could be an error in the" +
97 " or if the url does not look right, there could be an error in the" +
98 " server's configuration."
98 " server's configuration.";
99 } else {
99 } else {
100 msg = "Websocket connection closed unexpectedly.<br/>" +
100 msg = "Websocket connection closed unexpectedly.<br/>" +
101 " The kernel will no longer be responsive."
101 " The kernel will no longer be responsive.";
102 }
102 }
103 var dialog = $('<div/>');
103 var dialog = $('<div/>');
104 dialog.html(msg);
104 dialog.html(msg);
@@ -114,7 +114,7 b' var IPython = (function (IPython) {'
114 }
114 }
115 });
115 });
116
116
117 }
117 };
118
118
119 Kernel.prototype.start_channels = function () {
119 Kernel.prototype.start_channels = function () {
120 var that = this;
120 var that = this;
@@ -125,7 +125,7 b' var IPython = (function (IPython) {'
125 this.iopub_channel = new this.WebSocket(ws_url + "/iopub");
125 this.iopub_channel = new this.WebSocket(ws_url + "/iopub");
126 send_cookie = function(){
126 send_cookie = function(){
127 this.send(document.cookie);
127 this.send(document.cookie);
128 }
128 };
129 var already_called_onclose = false; // only alert once
129 var already_called_onclose = false; // only alert once
130 ws_closed_early = function(evt){
130 ws_closed_early = function(evt){
131 if (already_called_onclose){
131 if (already_called_onclose){
@@ -135,7 +135,7 b' var IPython = (function (IPython) {'
135 if ( ! evt.wasClean ){
135 if ( ! evt.wasClean ){
136 that._websocket_closed(ws_url, true);
136 that._websocket_closed(ws_url, true);
137 }
137 }
138 }
138 };
139 ws_closed_late = function(evt){
139 ws_closed_late = function(evt){
140 if (already_called_onclose){
140 if (already_called_onclose){
141 return;
141 return;
@@ -144,7 +144,7 b' var IPython = (function (IPython) {'
144 if ( ! evt.wasClean ){
144 if ( ! evt.wasClean ){
145 that._websocket_closed(ws_url, false);
145 that._websocket_closed(ws_url, false);
146 }
146 }
147 }
147 };
148 this.shell_channel.onopen = send_cookie;
148 this.shell_channel.onopen = send_cookie;
149 this.shell_channel.onclose = ws_closed_early;
149 this.shell_channel.onclose = ws_closed_early;
150 this.iopub_channel.onopen = send_cookie;
150 this.iopub_channel.onopen = send_cookie;
@@ -159,12 +159,12 b' var IPython = (function (IPython) {'
159
159
160 Kernel.prototype.stop_channels = function () {
160 Kernel.prototype.stop_channels = function () {
161 if (this.shell_channel !== null) {
161 if (this.shell_channel !== null) {
162 this.shell_channel.onclose = function (evt) {null};
162 this.shell_channel.onclose = function (evt) {};
163 this.shell_channel.close();
163 this.shell_channel.close();
164 this.shell_channel = null;
164 this.shell_channel = null;
165 };
165 };
166 if (this.iopub_channel !== null) {
166 if (this.iopub_channel !== null) {
167 this.iopub_channel.onclose = function (evt) {null};
167 this.iopub_channel.onclose = function (evt) {};
168 this.iopub_channel.close();
168 this.iopub_channel.close();
169 this.iopub_channel = null;
169 this.iopub_channel = null;
170 };
170 };
@@ -189,12 +189,12 b' var IPython = (function (IPython) {'
189 silent : false,
189 silent : false,
190 user_variables : [],
190 user_variables : [],
191 user_expressions : {},
191 user_expressions : {},
192 allow_stdin : false,
192 allow_stdin : false
193 };
193 };
194 var msg = this.get_msg("execute_request", content);
194 var msg = this.get_msg("execute_request", content);
195 this.shell_channel.send(JSON.stringify(msg));
195 this.shell_channel.send(JSON.stringify(msg));
196 return msg.header.msg_id;
196 return msg.header.msg_id;
197 }
197 };
198
198
199
199
200 Kernel.prototype.complete = function (line, cursor_pos) {
200 Kernel.prototype.complete = function (line, cursor_pos) {
@@ -206,7 +206,7 b' var IPython = (function (IPython) {'
206 var msg = this.get_msg("complete_request", content);
206 var msg = this.get_msg("complete_request", content);
207 this.shell_channel.send(JSON.stringify(msg));
207 this.shell_channel.send(JSON.stringify(msg));
208 return msg.header.msg_id;
208 return msg.header.msg_id;
209 }
209 };
210
210
211
211
212 Kernel.prototype.interrupt = function () {
212 Kernel.prototype.interrupt = function () {
@@ -221,7 +221,7 b' var IPython = (function (IPython) {'
221 this.running = false;
221 this.running = false;
222 var settings = {
222 var settings = {
223 cache : false,
223 cache : false,
224 type : "DELETE",
224 type : "DELETE"
225 };
225 };
226 $.ajax(this.kernel_url, settings);
226 $.ajax(this.kernel_url, settings);
227 };
227 };
@@ -26,7 +26,7 b' var IPython = (function (IPython) {'
26 this.element.addClass('ui-widget');
26 this.element.addClass('ui-widget');
27 this.element.attr('title', "The kernel execution status." +
27 this.element.attr('title', "The kernel execution status." +
28 " If 'Busy', the kernel is currently running code." +
28 " If 'Busy', the kernel is currently running code." +
29 " If 'Idle', it is available for execution.")
29 " If 'Idle', it is available for execution.");
30 };
30 };
31
31
32
32
@@ -54,7 +54,7 b' var IPython = (function (IPython) {'
54 }
54 }
55 };
55 };
56
56
57 IPython.LayoutManager = LayoutManager
57 IPython.LayoutManager = LayoutManager;
58
58
59 return IPython;
59 return IPython;
60
60
@@ -71,7 +71,7 b' var IPython = (function (IPython) {'
71 this.kernel_section = new IPython.KernelSection('div#kernel_section');
71 this.kernel_section = new IPython.KernelSection('div#kernel_section');
72 }
72 }
73 this.help_section = new IPython.HelpSection('div#help_section');
73 this.help_section = new IPython.HelpSection('div#help_section');
74 }
74 };
75
75
76 LeftPanel.prototype.collapse = function () {
76 LeftPanel.prototype.collapse = function () {
77 if (this.expanded === true) {
77 if (this.expanded === true) {
@@ -20,7 +20,7 b' IPython.namespace = function (ns_string) {'
20 for (i=0; i<parts.length; i+=1) {
20 for (i=0; i<parts.length; i+=1) {
21 // Create property if it doesn't exist
21 // Create property if it doesn't exist
22 if (typeof parent[parts[i]] === "undefined") {
22 if (typeof parent[parts[i]] === "undefined") {
23 parent[parts[i]] == {};
23 parent[parts[i]] = {};
24 }
24 }
25 }
25 }
26 return parent;
26 return parent;
@@ -59,7 +59,7 b' var IPython = (function (IPython) {'
59 var that = this;
59 var that = this;
60 $(document).keydown(function (event) {
60 $(document).keydown(function (event) {
61 // console.log(event);
61 // console.log(event);
62 if (that.read_only) return;
62 if (that.read_only) return false;
63 if (event.which === 27) {
63 if (event.which === 27) {
64 // Intercept escape at highest level to avoid closing
64 // Intercept escape at highest level to avoid closing
65 // websocket connection with firefox
65 // websocket connection with firefox
@@ -165,6 +165,7 b' var IPython = (function (IPython) {'
165 that.control_key_active = false;
165 that.control_key_active = false;
166 return true;
166 return true;
167 };
167 };
168 return true;
168 });
169 });
169
170
170 this.element.bind('collapse_pager', function () {
171 this.element.bind('collapse_pager', function () {
@@ -203,6 +204,7 b' var IPython = (function (IPython) {'
203 if (that.dirty && ! that.read_only) {
204 if (that.dirty && ! that.read_only) {
204 return "You have unsaved changes that will be lost if you leave this page.";
205 return "You have unsaved changes that will be lost if you leave this page.";
205 };
206 };
207 return true;
206 });
208 });
207 };
209 };
208
210
@@ -266,12 +268,12 b' var IPython = (function (IPython) {'
266
268
267 Notebook.prototype.cell_elements = function () {
269 Notebook.prototype.cell_elements = function () {
268 return this.element.children("div.cell");
270 return this.element.children("div.cell");
269 }
271 };
270
272
271
273
272 Notebook.prototype.ncells = function (cell) {
274 Notebook.prototype.ncells = function (cell) {
273 return this.cell_elements().length;
275 return this.cell_elements().length;
274 }
276 };
275
277
276
278
277 // TODO: we are often calling cells as cells()[i], which we should optimize
279 // TODO: we are often calling cells as cells()[i], which we should optimize
@@ -280,7 +282,7 b' var IPython = (function (IPython) {'
280 return this.cell_elements().toArray().map(function (e) {
282 return this.cell_elements().toArray().map(function (e) {
281 return $(e).data("cell");
283 return $(e).data("cell");
282 });
284 });
283 }
285 };
284
286
285
287
286 Notebook.prototype.find_cell_index = function (cell) {
288 Notebook.prototype.find_cell_index = function (cell) {
@@ -296,7 +298,7 b' var IPython = (function (IPython) {'
296
298
297 Notebook.prototype.index_or_selected = function (index) {
299 Notebook.prototype.index_or_selected = function (index) {
298 return index || this.selected_index() || 0;
300 return index || this.selected_index() || 0;
299 }
301 };
300
302
301
303
302 Notebook.prototype.select = function (index) {
304 Notebook.prototype.select = function (index) {
@@ -354,7 +356,7 b' var IPython = (function (IPython) {'
354
356
355 Notebook.prototype.selected_cell = function () {
357 Notebook.prototype.selected_cell = function () {
356 return this.cell_elements().eq(this.selected_index()).data("cell");
358 return this.cell_elements().eq(this.selected_index()).data("cell");
357 }
359 };
358
360
359
361
360 // Cell insertion, deletion and moving.
362 // Cell insertion, deletion and moving.
@@ -392,7 +394,7 b' var IPython = (function (IPython) {'
392 this.cell_elements().eq(index).after(cell.element);
394 this.cell_elements().eq(index).after(cell.element);
393 };
395 };
394 this.dirty = true;
396 this.dirty = true;
395 return this
397 return this;
396 };
398 };
397
399
398
400
@@ -423,14 +425,14 b' var IPython = (function (IPython) {'
423 };
425 };
424 this.dirty = true;
426 this.dirty = true;
425 return this;
427 return this;
426 }
428 };
427
429
428
430
429 Notebook.prototype.move_cell_down = function (index) {
431 Notebook.prototype.move_cell_down = function (index) {
430 var i = index || this.selected_index();
432 var i = index || this.selected_index();
431 if (i !== null && i < (this.ncells()-1) && i >= 0) {
433 if (i !== null && i < (this.ncells()-1) && i >= 0) {
432 var pivot = this.cell_elements().eq(i+1)
434 var pivot = this.cell_elements().eq(i+1);
433 var tomove = this.cell_elements().eq(i)
435 var tomove = this.cell_elements().eq(i);
434 if (pivot !== null && tomove !== null) {
436 if (pivot !== null && tomove !== null) {
435 tomove.detach();
437 tomove.detach();
436 pivot.after(tomove);
438 pivot.after(tomove);
@@ -439,7 +441,7 b' var IPython = (function (IPython) {'
439 };
441 };
440 this.dirty = true;
442 this.dirty = true;
441 return this;
443 return this;
442 }
444 };
443
445
444
446
445 Notebook.prototype.sort_cells = function () {
447 Notebook.prototype.sort_cells = function () {
@@ -447,7 +449,7 b' var IPython = (function (IPython) {'
447 var sindex = this.selected_index();
449 var sindex = this.selected_index();
448 var swapped;
450 var swapped;
449 do {
451 do {
450 swapped = false
452 swapped = false;
451 for (var i=1; i<ncells; i++) {
453 for (var i=1; i<ncells; i++) {
452 current = this.cell_elements().eq(i).data("cell");
454 current = this.cell_elements().eq(i).data("cell");
453 previous = this.cell_elements().eq(i-1).data("cell");
455 previous = this.cell_elements().eq(i-1).data("cell");
@@ -470,7 +472,7 b' var IPython = (function (IPython) {'
470 this.insert_cell_above(cell, i);
472 this.insert_cell_above(cell, i);
471 this.select(this.find_cell_index(cell));
473 this.select(this.find_cell_index(cell));
472 return cell;
474 return cell;
473 }
475 };
474
476
475
477
476 Notebook.prototype.insert_code_cell_below = function (index) {
478 Notebook.prototype.insert_code_cell_below = function (index) {
@@ -481,7 +483,7 b' var IPython = (function (IPython) {'
481 this.insert_cell_below(cell, i);
483 this.insert_cell_below(cell, i);
482 this.select(this.find_cell_index(cell));
484 this.select(this.find_cell_index(cell));
483 return cell;
485 return cell;
484 }
486 };
485
487
486
488
487 Notebook.prototype.insert_html_cell_above = function (index) {
489 Notebook.prototype.insert_html_cell_above = function (index) {
@@ -492,7 +494,7 b' var IPython = (function (IPython) {'
492 this.insert_cell_above(cell, i);
494 this.insert_cell_above(cell, i);
493 this.select(this.find_cell_index(cell));
495 this.select(this.find_cell_index(cell));
494 return cell;
496 return cell;
495 }
497 };
496
498
497
499
498 Notebook.prototype.insert_html_cell_below = function (index) {
500 Notebook.prototype.insert_html_cell_below = function (index) {
@@ -503,7 +505,7 b' var IPython = (function (IPython) {'
503 this.insert_cell_below(cell, i);
505 this.insert_cell_below(cell, i);
504 this.select(this.find_cell_index(cell));
506 this.select(this.find_cell_index(cell));
505 return cell;
507 return cell;
506 }
508 };
507
509
508
510
509 Notebook.prototype.insert_markdown_cell_above = function (index) {
511 Notebook.prototype.insert_markdown_cell_above = function (index) {
@@ -514,7 +516,7 b' var IPython = (function (IPython) {'
514 this.insert_cell_above(cell, i);
516 this.insert_cell_above(cell, i);
515 this.select(this.find_cell_index(cell));
517 this.select(this.find_cell_index(cell));
516 return cell;
518 return cell;
517 }
519 };
518
520
519
521
520 Notebook.prototype.insert_markdown_cell_below = function (index) {
522 Notebook.prototype.insert_markdown_cell_below = function (index) {
@@ -525,7 +527,7 b' var IPython = (function (IPython) {'
525 this.insert_cell_below(cell, i);
527 this.insert_cell_below(cell, i);
526 this.select(this.find_cell_index(cell));
528 this.select(this.find_cell_index(cell));
527 return cell;
529 return cell;
528 }
530 };
529
531
530
532
531 Notebook.prototype.to_code = function (index) {
533 Notebook.prototype.to_code = function (index) {
@@ -553,11 +555,11 b' var IPython = (function (IPython) {'
553 var target_cell = null;
555 var target_cell = null;
554 if (source_cell instanceof IPython.CodeCell) {
556 if (source_cell instanceof IPython.CodeCell) {
555 this.insert_markdown_cell_below(i);
557 this.insert_markdown_cell_below(i);
556 var target_cell = this.cells()[i+1];
558 target_cell = this.cells()[i+1];
557 var text = source_cell.get_code();
559 var text = source_cell.get_code();
558 } else if (source_cell instanceof IPython.HTMLCell) {
560 } else if (source_cell instanceof IPython.HTMLCell) {
559 this.insert_markdown_cell_below(i);
561 this.insert_markdown_cell_below(i);
560 var target_cell = this.cells()[i+1];
562 target_cell = this.cells()[i+1];
561 var text = source_cell.get_source();
563 var text = source_cell.get_source();
562 if (text === source_cell.placeholder) {
564 if (text === source_cell.placeholder) {
563 text = target_cell.placeholder;
565 text = target_cell.placeholder;
@@ -581,11 +583,11 b' var IPython = (function (IPython) {'
581 var target_cell = null;
583 var target_cell = null;
582 if (source_cell instanceof IPython.CodeCell) {
584 if (source_cell instanceof IPython.CodeCell) {
583 this.insert_html_cell_below(i);
585 this.insert_html_cell_below(i);
584 var target_cell = this.cells()[i+1];
586 target_cell = this.cells()[i+1];
585 var text = source_cell.get_code();
587 var text = source_cell.get_code();
586 } else if (source_cell instanceof IPython.MarkdownCell) {
588 } else if (source_cell instanceof IPython.MarkdownCell) {
587 this.insert_html_cell_below(i);
589 this.insert_html_cell_below(i);
588 var target_cell = this.cells()[i+1];
590 target_cell = this.cells()[i+1];
589 var text = source_cell.get_source();
591 var text = source_cell.get_source();
590 if (text === source_cell.placeholder) {
592 if (text === source_cell.placeholder) {
591 text = target_cell.placeholder;
593 text = target_cell.placeholder;
@@ -643,7 +645,7 b' var IPython = (function (IPython) {'
643 var cells = this.cells();
645 var cells = this.cells();
644 len = cells.length;
646 len = cells.length;
645 for (var i=0; i<len; i++) {
647 for (var i=0; i<len; i++) {
646 cells[i].set_autoindent(state)
648 cells[i].set_autoindent(state);
647 };
649 };
648 };
650 };
649
651
@@ -662,7 +664,7 b' var IPython = (function (IPython) {'
662 // Other cell functions: line numbers, ...
664 // Other cell functions: line numbers, ...
663
665
664 Notebook.prototype.cell_toggle_line_numbers = function() {
666 Notebook.prototype.cell_toggle_line_numbers = function() {
665 this.selected_cell().toggle_line_numbers()
667 this.selected_cell().toggle_line_numbers();
666 };
668 };
667
669
668 // Kernel related things
670 // Kernel related things
@@ -864,8 +866,8 b' var IPython = (function (IPython) {'
864 Notebook.prototype.execute_selected_cell = function (options) {
866 Notebook.prototype.execute_selected_cell = function (options) {
865 // add_new: should a new cell be added if we are at the end of the nb
867 // add_new: should a new cell be added if we are at the end of the nb
866 // terminal: execute in terminal mode, which stays in the current cell
868 // terminal: execute in terminal mode, which stays in the current cell
867 default_options = {terminal: false, add_new: true}
869 default_options = {terminal: false, add_new: true};
868 $.extend(default_options, options)
870 $.extend(default_options, options);
869 var that = this;
871 var that = this;
870 var cell = that.selected_cell();
872 var cell = that.selected_cell();
871 var cell_index = that.find_cell_index(cell);
873 var cell_index = that.find_cell_index(cell);
@@ -938,7 +940,8 b' var IPython = (function (IPython) {'
938
940
939 Notebook.prototype.fromJSON = function (data) {
941 Notebook.prototype.fromJSON = function (data) {
940 var ncells = this.ncells();
942 var ncells = this.ncells();
941 for (var i=0; i<ncells; i++) {
943 var i;
944 for (i=0; i<ncells; i++) {
942 // Always delete cell 0 as they get renumbered as they are deleted.
945 // Always delete cell 0 as they get renumbered as they are deleted.
943 this.delete_cell(0);
946 this.delete_cell(0);
944 };
947 };
@@ -951,7 +954,7 b' var IPython = (function (IPython) {'
951 ncells = new_cells.length;
954 ncells = new_cells.length;
952 var cell_data = null;
955 var cell_data = null;
953 var new_cell = null;
956 var new_cell = null;
954 for (var i=0; i<ncells; i++) {
957 for (i=0; i<ncells; i++) {
955 cell_data = new_cells[i];
958 cell_data = new_cells[i];
956 if (cell_data.cell_type == 'code') {
959 if (cell_data.cell_type == 'code') {
957 new_cell = this.insert_code_cell_below();
960 new_cell = this.insert_code_cell_below();
@@ -979,8 +982,8 b' var IPython = (function (IPython) {'
979 // Only handle 1 worksheet for now.
982 // Only handle 1 worksheet for now.
980 worksheets : [{cells:cell_array}],
983 worksheets : [{cells:cell_array}],
981 metadata : this.metadata
984 metadata : this.metadata
982 }
985 };
983 return data
986 return data;
984 };
987 };
985
988
986 Notebook.prototype.save_notebook = function () {
989 Notebook.prototype.save_notebook = function () {
@@ -1002,7 +1005,7 b' var IPython = (function (IPython) {'
1002 error : $.proxy(this.notebook_save_failed,this)
1005 error : $.proxy(this.notebook_save_failed,this)
1003 };
1006 };
1004 IPython.save_widget.status_saving();
1007 IPython.save_widget.status_saving();
1005 var url = $('body').data('baseProjectUrl') + 'notebooks/' + notebook_id
1008 var url = $('body').data('baseProjectUrl') + 'notebooks/' + notebook_id;
1006 $.ajax(url, settings);
1009 $.ajax(url, settings);
1007 };
1010 };
1008 };
1011 };
@@ -1012,7 +1015,7 b' var IPython = (function (IPython) {'
1012 this.dirty = false;
1015 this.dirty = false;
1013 IPython.save_widget.notebook_saved();
1016 IPython.save_widget.notebook_saved();
1014 IPython.save_widget.status_save();
1017 IPython.save_widget.status_save();
1015 }
1018 };
1016
1019
1017
1020
1018 Notebook.prototype.notebook_save_failed = function (xhr, status, error_msg) {
1021 Notebook.prototype.notebook_save_failed = function (xhr, status, error_msg) {
@@ -1020,7 +1023,7 b' var IPython = (function (IPython) {'
1020 // TODO: Handle different types of errors (timeout etc.)
1023 // TODO: Handle different types of errors (timeout etc.)
1021 alert('An unexpected error occured while saving the notebook.');
1024 alert('An unexpected error occured while saving the notebook.');
1022 IPython.save_widget.reset_status();
1025 IPython.save_widget.reset_status();
1023 }
1026 };
1024
1027
1025
1028
1026 Notebook.prototype.load_notebook = function (callback) {
1029 Notebook.prototype.load_notebook = function (callback) {
@@ -1040,9 +1043,9 b' var IPython = (function (IPython) {'
1040 }
1043 }
1041 };
1044 };
1042 IPython.save_widget.status_loading();
1045 IPython.save_widget.status_loading();
1043 var url = $('body').data('baseProjectUrl') + 'notebooks/' + notebook_id
1046 var url = $('body').data('baseProjectUrl') + 'notebooks/' + notebook_id;
1044 $.ajax(url, settings);
1047 $.ajax(url, settings);
1045 }
1048 };
1046
1049
1047
1050
1048 Notebook.prototype.notebook_loaded = function (data, status, xhr) {
1051 Notebook.prototype.notebook_loaded = function (data, status, xhr) {
@@ -67,7 +67,7 b' var IPython = (function (IPython) {'
67 dataType : "json",
67 dataType : "json",
68 success : $.proxy(this.list_loaded, this)
68 success : $.proxy(this.list_loaded, this)
69 };
69 };
70 var url = $('body').data('baseProjectUrl') + 'notebooks'
70 var url = $('body').data('baseProjectUrl') + 'notebooks';
71 $.ajax(url, settings);
71 $.ajax(url, settings);
72 };
72 };
73
73
@@ -174,7 +174,7 b' var IPython = (function (IPython) {'
174 parent_item.remove();
174 parent_item.remove();
175 }
175 }
176 };
176 };
177 var url = $('body').data('baseProjectUrl') + 'notebooks/' + notebook_id
177 var url = $('body').data('baseProjectUrl') + 'notebooks/' + notebook_id;
178 $.ajax(url, settings);
178 $.ajax(url, settings);
179 $(this).dialog('close');
179 $(this).dialog('close');
180 },
180 },
@@ -222,7 +222,7 b' var IPython = (function (IPython) {'
222 };
222 };
223
223
224 var qs = $.param({name:nbname, format:nbformat});
224 var qs = $.param({name:nbname, format:nbformat});
225 var url = $('body').data('baseProjectUrl') + 'notebooks?' + qs
225 var url = $('body').data('baseProjectUrl') + 'notebooks?' + qs;
226 $.ajax(url, settings);
226 $.ajax(url, settings);
227 });
227 });
228 var cancel_button = $('<button>Cancel</button>').button().
228 var cancel_button = $('<button>Cancel</button>').button().
@@ -15,7 +15,7 b' $(document).ready(function () {'
15 MathJax.Hub.Config({
15 MathJax.Hub.Config({
16 tex2jax: {
16 tex2jax: {
17 inlineMath: [ ['$','$'], ["\\(","\\)"] ],
17 inlineMath: [ ['$','$'], ["\\(","\\)"] ],
18 displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
18 displayMath: [ ['$$','$$'], ["\\[","\\]"] ]
19 },
19 },
20 displayAlign: 'left', // Change this to 'center' to center equations.
20 displayAlign: 'left', // Change this to 'center' to center equations.
21 "HTML-CSS": {
21 "HTML-CSS": {
@@ -76,7 +76,7 b' $(document).ready(function () {'
76 // and finally unhide the panel contents after collapse
76 // and finally unhide the panel contents after collapse
77 setTimeout(function(){
77 setTimeout(function(){
78 IPython.left_panel.left_panel_element.css('visibility', 'visible');
78 IPython.left_panel.left_panel_element.css('visibility', 'visible');
79 }, 200)
79 }, 200);
80 }
80 }
81 },100);
81 },100);
82 });
82 });
@@ -186,18 +186,18 b' var IPython = (function (IPython) {'
186 this.content.find('#move_cell_down').attr('title', "Move selected cell down one in the Notebook");
186 this.content.find('#move_cell_down').attr('title', "Move selected cell down one in the Notebook");
187
187
188 this.content.find('#cell_type').buttonset();
188 this.content.find('#cell_type').buttonset();
189 this.content.find('#to_markdown').attr('title', 'Change selected cell to markdown (for text)')
189 this.content.find('#to_markdown').attr('title', 'Change selected cell to markdown (for text)');
190 this.content.find('#to_code').attr('title', 'Change selected cell to code (for execution)')
190 this.content.find('#to_code').attr('title', 'Change selected cell to code (for execution)');
191
191
192 this.content.find('#cell_output').buttonset();
192 this.content.find('#cell_output').buttonset();
193 this.content.find('#toggle_output').attr('title', 'Toggle visibility of the output of code cells')
193 this.content.find('#toggle_output').attr('title', 'Toggle visibility of the output of code cells');
194 this.content.find('#clear_all_output').attr('title', 'Clear output of all code cells (actually removes the data, unlike toggle)')
194 this.content.find('#clear_all_output').attr('title', 'Clear output of all code cells (actually removes the data, unlike toggle)');
195
195
196 this.content.find('#run_cells').buttonset();
196 this.content.find('#run_cells').buttonset();
197 this.content.find('#run_selected_cell').attr('title', 'Submit the selected cell for execution')
197 this.content.find('#run_selected_cell').attr('title', 'Submit the selected cell for execution');
198 this.content.find('#run_all_cells').attr('title', 'Run *all* code cells in the notebook in order')
198 this.content.find('#run_all_cells').attr('title', 'Run *all* code cells in the notebook in order');
199 this.content.find('#autoindent').attr('title', 'Autoindent code as-you-type')
199 this.content.find('#autoindent').attr('title', 'Autoindent code as-you-type');
200 this.content.find('#autoindent_label').attr('title', 'Autoindent code as-you-type')
200 this.content.find('#autoindent_label').attr('title', 'Autoindent code as-you-type');
201 };
201 };
202
202
203
203
@@ -304,12 +304,12 b' var IPython = (function (IPython) {'
304 this.content.find('#help_buttons0').buttonset();
304 this.content.find('#help_buttons0').buttonset();
305 this.content.find('#help_buttons1').buttonset();
305 this.content.find('#help_buttons1').buttonset();
306 this.content.find('#help_buttons2').buttonset();
306 this.content.find('#help_buttons2').buttonset();
307 this.content.find('#python_help').attr('title', "Open the online Python documentation in a new tab")
307 this.content.find('#python_help').attr('title', "Open the online Python documentation in a new tab");
308 this.content.find('#ipython_help').attr('title', "Open the online IPython documentation in a new tab")
308 this.content.find('#ipython_help').attr('title', "Open the online IPython documentation in a new tab");
309 this.content.find('#numpy_help').attr('title', "Open the online NumPy documentation in a new tab")
309 this.content.find('#numpy_help').attr('title', "Open the online NumPy documentation in a new tab");
310 this.content.find('#scipy_help').attr('title', "Open the online SciPy documentation in a new tab")
310 this.content.find('#scipy_help').attr('title', "Open the online SciPy documentation in a new tab");
311 this.content.find('#matplotlib_help').attr('title', "Open the online Matplotlib documentation in a new tab")
311 this.content.find('#matplotlib_help').attr('title', "Open the online Matplotlib documentation in a new tab");
312 this.content.find('#sympy_help').attr('title', "Open the online SymPy documentation in a new tab")
312 this.content.find('#sympy_help').attr('title', "Open the online SymPy documentation in a new tab");
313 };
313 };
314
314
315
315
@@ -15,7 +15,7 b' var IPython = (function (IPython) {'
15
15
16 var SaveWidget = function (selector) {
16 var SaveWidget = function (selector) {
17 this.selector = selector;
17 this.selector = selector;
18 this.notebook_name_blacklist_re = /[\/\\]/
18 this.notebook_name_blacklist_re = /[\/\\]/;
19 this.last_saved_name = '';
19 this.last_saved_name = '';
20 if (this.selector !== undefined) {
20 if (this.selector !== undefined) {
21 this.element = $(selector);
21 this.element = $(selector);
@@ -70,14 +70,14 b' var IPython = (function (IPython) {'
70
70
71 SaveWidget.prototype.get_notebook_name = function () {
71 SaveWidget.prototype.get_notebook_name = function () {
72 return this.element.find('input#notebook_name').attr('value');
72 return this.element.find('input#notebook_name').attr('value');
73 }
73 };
74
74
75
75
76 SaveWidget.prototype.set_notebook_name = function (nbname) {
76 SaveWidget.prototype.set_notebook_name = function (nbname) {
77 this.element.find('input#notebook_name').attr('value',nbname);
77 this.element.find('input#notebook_name').attr('value',nbname);
78 this.set_document_title();
78 this.set_document_title();
79 this.last_saved_name = nbname;
79 this.last_saved_name = nbname;
80 }
80 };
81
81
82
82
83 SaveWidget.prototype.set_document_title = function () {
83 SaveWidget.prototype.set_document_title = function () {
@@ -34,7 +34,7 b' var IPython = (function (IPython) {'
34 mode: this.code_mirror_mode,
34 mode: this.code_mirror_mode,
35 theme: 'default',
35 theme: 'default',
36 value: this.placeholder,
36 value: this.placeholder,
37 readOnly: this.read_only,
37 readOnly: this.read_only
38 });
38 });
39 // The tabindex=-1 makes this div focusable.
39 // The tabindex=-1 makes this div focusable.
40 var render_area = $('<div/>').addClass('text_cell_render').
40 var render_area = $('<div/>').addClass('text_cell_render').
@@ -52,8 +52,8 b' var IPython = (function (IPython) {'
52 if (that.rendered) {
52 if (that.rendered) {
53 that.edit();
53 that.edit();
54 event.preventDefault();
54 event.preventDefault();
55 };
55 }
56 };
56 }
57 });
57 });
58 };
58 };
59
59
@@ -77,8 +77,8 b' var IPython = (function (IPython) {'
77 this.rendered = false;
77 this.rendered = false;
78 if (this.get_source() === this.placeholder) {
78 if (this.get_source() === this.placeholder) {
79 this.set_source('');
79 this.set_source('');
80 };
80 }
81 };
81 }
82 };
82 };
83
83
84
84
@@ -145,13 +145,13 b' var IPython = (function (IPython) {'
145 this.set_rendered(data.rendered || '');
145 this.set_rendered(data.rendered || '');
146 this.rendered = false;
146 this.rendered = false;
147 this.render();
147 this.render();
148 };
148 }
149 };
149 }
150 };
150 };
151
151
152
152
153 TextCell.prototype.toJSON = function () {
153 TextCell.prototype.toJSON = function () {
154 var data = {}
154 var data = {};
155 data.cell_type = this.cell_type;
155 data.cell_type = this.cell_type;
156 data.source = this.get_source();
156 data.source = this.get_source();
157 return data;
157 return data;
@@ -173,13 +173,13 b' var IPython = (function (IPython) {'
173 HTMLCell.prototype.render = function () {
173 HTMLCell.prototype.render = function () {
174 if (this.rendered === false) {
174 if (this.rendered === false) {
175 var text = this.get_source();
175 var text = this.get_source();
176 if (text === "") {text = this.placeholder;};
176 if (text === "") { text = this.placeholder; }
177 this.set_rendered(text);
177 this.set_rendered(text);
178 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
178 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
179 this.element.find('div.text_cell_input').hide();
179 this.element.find('div.text_cell_input').hide();
180 this.element.find("div.text_cell_render").show();
180 this.element.find("div.text_cell_render").show();
181 this.rendered = true;
181 this.rendered = true;
182 };
182 }
183 };
183 };
184
184
185
185
@@ -198,7 +198,7 b' var IPython = (function (IPython) {'
198 MarkdownCell.prototype.render = function () {
198 MarkdownCell.prototype.render = function () {
199 if (this.rendered === false) {
199 if (this.rendered === false) {
200 var text = this.get_source();
200 var text = this.get_source();
201 if (text === "") {text = this.placeholder;};
201 if (text === "") { text = this.placeholder; }
202 var html = IPython.markdown_converter.makeHtml(text);
202 var html = IPython.markdown_converter.makeHtml(text);
203 this.set_rendered(html);
203 this.set_rendered(html);
204 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
204 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
@@ -217,7 +217,7 b' var IPython = (function (IPython) {'
217 return '<code class="prettyprint">' + code + '</code>';
217 return '<code class="prettyprint">' + code + '</code>';
218 });
218 });
219 this.rendered = true;
219 this.rendered = true;
220 };
220 }
221 };
221 };
222
222
223
223
@@ -234,9 +234,9 b' var IPython = (function (IPython) {'
234
234
235
235
236 RSTCell.prototype.render = function () {
236 RSTCell.prototype.render = function () {
237 if (this.rendered === false) {
237 if (this.rendered === false) {
238 var text = this.get_source();
238 var text = this.get_source();
239 if (text === "") {text = this.placeholder;};
239 if (text === "") { text = this.placeholder; }
240 var settings = {
240 var settings = {
241 processData : false,
241 processData : false,
242 cache : false,
242 cache : false,
@@ -249,7 +249,7 b' var IPython = (function (IPython) {'
249 this.element.find('div.text_cell_input').hide();
249 this.element.find('div.text_cell_input').hide();
250 this.element.find("div.text_cell_render").show();
250 this.element.find("div.text_cell_render").show();
251 this.set_rendered("Rendering...");
251 this.set_rendered("Rendering...");
252 };
252 }
253 };
253 };
254
254
255
255
@@ -9,7 +9,7 b''
9 // Utilities
9 // Utilities
10 //============================================================================
10 //============================================================================
11
11
12 IPython.namespace('IPython.utils')
12 IPython.namespace('IPython.utils');
13
13
14 IPython.utils = (function (IPython) {
14 IPython.utils = (function (IPython) {
15
15
@@ -35,7 +35,7 b' IPython.utils = (function (IPython) {'
35 .replace(/>/g,'&'+'gt;')
35 .replace(/>/g,'&'+'gt;')
36 .replace(/\'/g,'&'+'apos;')
36 .replace(/\'/g,'&'+'apos;')
37 .replace(/\"/g,'&'+'quot;')
37 .replace(/\"/g,'&'+'quot;')
38 .replace(/`/g,'&'+'#96;')
38 .replace(/`/g,'&'+'#96;');
39 }
39 }
40
40
41
41
@@ -45,32 +45,32 b' IPython.utils = (function (IPython) {'
45 "32":"ansigreen", "33":"ansiyellow",
45 "32":"ansigreen", "33":"ansiyellow",
46 "34":"ansiblue", "35":"ansipurple","36":"ansicyan",
46 "34":"ansiblue", "35":"ansipurple","36":"ansicyan",
47 "37":"ansigrey", "01":"ansibold"
47 "37":"ansigrey", "01":"ansibold"
48 }
48 };
49
49
50 // Transform ANI color escape codes into HTML <span> tags with css
50 // Transform ANI color escape codes into HTML <span> tags with css
51 // classes listed in the above ansi_colormap object. The actual color used
51 // classes listed in the above ansi_colormap object. The actual color used
52 // are set in the css file.
52 // are set in the css file.
53 function fixConsole(txt) {
53 function fixConsole(txt) {
54 txt = xmlencode(txt)
54 txt = xmlencode(txt);
55 var re = /\033\[([\d;]*?)m/
55 var re = /\033\[([\d;]*?)m/;
56 var opened = false
56 var opened = false;
57 var cmds = []
57 var cmds = [];
58 var opener = ""
58 var opener = "";
59 var closer = ""
59 var closer = "";
60
60
61 while (re.test(txt)) {
61 while (re.test(txt)) {
62 var cmds = txt.match(re)[1].split(";")
62 var cmds = txt.match(re)[1].split(";");
63 closer = opened?"</span>":""
63 closer = opened?"</span>":"";
64 opened = cmds.length > 1 || cmds[0] != 0
64 opened = cmds.length > 1 || cmds[0] != 0;
65 var rep = []
65 var rep = [];
66 for (var i in cmds)
66 for (var i in cmds)
67 if (typeof(ansi_colormap[cmds[i]]) != "undefined")
67 if (typeof(ansi_colormap[cmds[i]]) != "undefined")
68 rep.push(ansi_colormap[cmds[i]])
68 rep.push(ansi_colormap[cmds[i]]);
69 opener = rep.length > 0?"<span class=\""+rep.join(" ")+"\">":""
69 opener = rep.length > 0?"<span class=\""+rep.join(" ")+"\">":"";
70 txt = txt.replace(re, closer + opener)
70 txt = txt.replace(re, closer + opener);
71 }
71 }
72 if (opened) txt += "</span>"
72 if (opened) txt += "</span>";
73 return txt
73 return txt;
74 }
74 }
75
75
76
76
@@ -95,7 +95,7 b' IPython.utils = (function (IPython) {'
95 uuid : uuid,
95 uuid : uuid,
96 fixConsole : fixConsole,
96 fixConsole : fixConsole,
97 grow : grow
97 grow : grow
98 }
98 };
99
99
100 }(IPython));
100 }(IPython));
101
101
General Comments 0
You need to be logged in to leave comments. Login now