Show More
@@ -1,177 +1,177 b'' | |||||
1 | //---------------------------------------------------------------------------- |
|
1 | //---------------------------------------------------------------------------- | |
2 | // Copyright (C) 2008-2011 The IPython Development Team |
|
2 | // Copyright (C) 2008-2011 The IPython Development Team | |
3 | // |
|
3 | // | |
4 | // Distributed under the terms of the BSD License. The full license is in |
|
4 | // Distributed under the terms of the BSD License. The full license is in | |
5 | // the file COPYING, distributed as part of this software. |
|
5 | // the file COPYING, distributed as part of this software. | |
6 | //---------------------------------------------------------------------------- |
|
6 | //---------------------------------------------------------------------------- | |
7 |
|
7 | |||
8 | //============================================================================ |
|
8 | //============================================================================ | |
9 | // MenuBar |
|
9 | // MenuBar | |
10 | //============================================================================ |
|
10 | //============================================================================ | |
11 |
|
11 | |||
12 | var IPython = (function (IPython) { |
|
12 | var IPython = (function (IPython) { | |
13 |
|
13 | |||
14 | var MenuBar = function (selector) { |
|
14 | var MenuBar = function (selector) { | |
15 | this.selector = selector; |
|
15 | this.selector = selector; | |
16 | if (this.selector !== undefined) { |
|
16 | if (this.selector !== undefined) { | |
17 | this.element = $(selector); |
|
17 | this.element = $(selector); | |
18 | this.style(); |
|
18 | this.style(); | |
19 | this.bind_events(); |
|
19 | this.bind_events(); | |
20 | } |
|
20 | } | |
21 | }; |
|
21 | }; | |
22 |
|
22 | |||
23 |
|
23 | |||
24 | MenuBar.prototype.style = function () { |
|
24 | MenuBar.prototype.style = function () { | |
25 | $('ul#menus').menubar({ |
|
25 | $('ul#menus').menubar({ | |
26 | select : function (event, ui) { |
|
26 | select : function (event, ui) { | |
27 | // The selected cell loses focus when the menu is entered, so we |
|
27 | // The selected cell loses focus when the menu is entered, so we | |
28 | // re-select it upon selection. |
|
28 | // re-select it upon selection. | |
29 | var i = IPython.notebook.get_selected_index(); |
|
29 | var i = IPython.notebook.get_selected_index(); | |
30 | IPython.notebook.select(i); |
|
30 | IPython.notebook.select(i); | |
31 | } |
|
31 | } | |
32 | }); |
|
32 | }); | |
33 | }; |
|
33 | }; | |
34 |
|
34 | |||
35 |
|
35 | |||
36 | MenuBar.prototype.bind_events = function () { |
|
36 | MenuBar.prototype.bind_events = function () { | |
37 | // File |
|
37 | // File | |
38 | this.element.find('#new_notebook').click(function () { |
|
38 | this.element.find('#new_notebook').click(function () { | |
39 | window.open($('body').data('baseProjectUrl')+'new'); |
|
39 | window.open($('body').data('baseProjectUrl')+'new'); | |
40 | }); |
|
40 | }); | |
41 | this.element.find('#open_notebook').click(function () { |
|
41 | this.element.find('#open_notebook').click(function () { | |
42 | window.open($('body').data('baseProjectUrl')); |
|
42 | window.open($('body').data('baseProjectUrl')); | |
43 | }); |
|
43 | }); | |
44 | this.element.find('#rename_notebook').click(function () { |
|
44 | this.element.find('#rename_notebook').click(function () { | |
45 | IPython.save_widget.rename_notebook(); |
|
45 | IPython.save_widget.rename_notebook(); | |
46 | }); |
|
46 | }); | |
47 | this.element.find('#copy_notebook').click(function () { |
|
47 | this.element.find('#copy_notebook').click(function () { | |
48 | var notebook_id = IPython.save_widget.get_notebook_id(); |
|
48 | var notebook_id = IPython.save_widget.get_notebook_id(); | |
49 | var url = $('body').data('baseProjectUrl') + notebook_id + '/copy'; |
|
49 | var url = $('body').data('baseProjectUrl') + notebook_id + '/copy'; | |
50 | window.open(url,'_newtab'); |
|
50 | window.open(url,'_newtab'); | |
51 | }); |
|
51 | }); | |
52 | this.element.find('#save_notebook').click(function () { |
|
52 | this.element.find('#save_notebook').click(function () { | |
53 | IPython.save_widget.save_notebook(); |
|
53 | IPython.save_widget.save_notebook(); | |
54 | }); |
|
54 | }); | |
55 | this.element.find('#download_ipynb').click(function () { |
|
55 | this.element.find('#download_ipynb').click(function () { | |
56 | var notebook_id = IPython.save_widget.get_notebook_id(); |
|
56 | var notebook_id = IPython.save_widget.get_notebook_id(); | |
57 | var url = $('body').data('baseProjectUrl') + 'notebooks/' + |
|
57 | var url = $('body').data('baseProjectUrl') + 'notebooks/' + | |
58 | notebook_id + '?format=json'; |
|
58 | notebook_id + '?format=json'; | |
59 | window.open(url,'_newtab'); |
|
59 | window.open(url,'_newtab'); | |
60 | }); |
|
60 | }); | |
61 | this.element.find('#download_py').click(function () { |
|
61 | this.element.find('#download_py').click(function () { | |
62 | var notebook_id = IPython.save_widget.get_notebook_id(); |
|
62 | var notebook_id = IPython.save_widget.get_notebook_id(); | |
63 | var url = $('body').data('baseProjectUrl') + 'notebooks/' + |
|
63 | var url = $('body').data('baseProjectUrl') + 'notebooks/' + | |
64 | notebook_id + '?format=py'; |
|
64 | notebook_id + '?format=py'; | |
65 | window.open(url,'_newtab'); |
|
65 | window.open(url,'_newtab'); | |
66 | }); |
|
66 | }); | |
67 | this.element.find('button#print_notebook').click(function () { |
|
67 | this.element.find('button#print_notebook').click(function () { | |
68 | IPython.print_widget.print_notebook(); |
|
68 | IPython.print_widget.print_notebook(); | |
69 | }); |
|
69 | }); | |
70 | // Edit |
|
70 | // Edit | |
71 | this.element.find('#cut_cell').click(function () { |
|
71 | this.element.find('#cut_cell').click(function () { | |
72 | IPython.notebook.cut_cell(); |
|
72 | IPython.notebook.cut_cell(); | |
73 | }); |
|
73 | }); | |
74 | this.element.find('#copy_cell').click(function () { |
|
74 | this.element.find('#copy_cell').click(function () { | |
75 | IPython.notebook.copy_cell(); |
|
75 | IPython.notebook.copy_cell(); | |
76 | }); |
|
76 | }); | |
77 | this.element.find('#delete_cell').click(function () { |
|
77 | this.element.find('#delete_cell').click(function () { | |
78 | IPython.notebook.delete_cell(); |
|
78 | IPython.notebook.delete_cell(); | |
79 | }); |
|
79 | }); | |
80 | this.element.find('#split_cell').click(function () { |
|
80 | this.element.find('#split_cell').click(function () { | |
81 | IPython.notebook.split_cell(); |
|
81 | IPython.notebook.split_cell(); | |
82 | }); |
|
82 | }); | |
83 | this.element.find('#merge_cell_above').click(function () { |
|
83 | this.element.find('#merge_cell_above').click(function () { | |
84 | IPython.notebook.merge_cell_above(); |
|
84 | IPython.notebook.merge_cell_above(); | |
85 | }); |
|
85 | }); | |
86 | this.element.find('#merge_cell_below').click(function () { |
|
86 | this.element.find('#merge_cell_below').click(function () { | |
87 | IPython.notebook.merge_cell_below(); |
|
87 | IPython.notebook.merge_cell_below(); | |
88 | }); |
|
88 | }); | |
89 | this.element.find('#move_cell_up').click(function () { |
|
89 | this.element.find('#move_cell_up').click(function () { | |
90 | IPython.notebook.move_cell_up(); |
|
90 | IPython.notebook.move_cell_up(); | |
91 | }); |
|
91 | }); | |
92 | this.element.find('#move_cell_down').click(function () { |
|
92 | this.element.find('#move_cell_down').click(function () { | |
93 | IPython.notebook.move_cell_down(); |
|
93 | IPython.notebook.move_cell_down(); | |
94 | }); |
|
94 | }); | |
95 | this.element.find('#select_previous').click(function () { |
|
95 | this.element.find('#select_previous').click(function () { | |
96 | IPython.notebook.select_prev(); |
|
96 | IPython.notebook.select_prev(); | |
97 | }); |
|
97 | }); | |
98 | this.element.find('#select_next').click(function () { |
|
98 | this.element.find('#select_next').click(function () { | |
99 | IPython.notebook.select_next(); |
|
99 | IPython.notebook.select_next(); | |
100 | }); |
|
100 | }); | |
101 | // View |
|
101 | // View | |
102 | this.element.find('#toggle_header').click(function () { |
|
102 | this.element.find('#toggle_header').click(function () { | |
103 | $('div#header').toggle(); |
|
103 | $('div#header').toggle(); | |
104 | IPython.layout_manager.do_resize(); |
|
104 | IPython.layout_manager.do_resize(); | |
105 | }); |
|
105 | }); | |
106 | this.element.find('#toggle_toolbar').click(function () { |
|
106 | this.element.find('#toggle_toolbar').click(function () { | |
107 | IPython.toolbar.toggle(); |
|
107 | IPython.toolbar.toggle(); | |
108 | }); |
|
108 | }); | |
109 | // Insert |
|
109 | // Insert | |
110 | this.element.find('#insert_cell_above').click(function () { |
|
110 | this.element.find('#insert_cell_above').click(function () { | |
111 | IPython.notebook.insert_cell_above('code'); |
|
111 | IPython.notebook.insert_cell_above('code'); | |
112 | }); |
|
112 | }); | |
113 | this.element.find('#insert_cell_below').click(function () { |
|
113 | this.element.find('#insert_cell_below').click(function () { | |
114 | IPython.notebook.insert_cell_below('code'); |
|
114 | IPython.notebook.insert_cell_below('code'); | |
115 | }); |
|
115 | }); | |
116 | // Cell |
|
116 | // Cell | |
117 | this.element.find('#run_cell').click(function () { |
|
117 | this.element.find('#run_cell').click(function () { | |
118 | IPython.notebook.execute_selected_cell(); |
|
118 | IPython.notebook.execute_selected_cell(); | |
119 | }); |
|
119 | }); | |
120 | this.element.find('#run_cell_in_place').click(function () { |
|
120 | this.element.find('#run_cell_in_place').click(function () { | |
121 | IPython.notebook.execute_selected_cell({terminal:true}); |
|
121 | IPython.notebook.execute_selected_cell({terminal:true}); | |
122 | }); |
|
122 | }); | |
123 | this.element.find('#run_all_cells').click(function () { |
|
123 | this.element.find('#run_all_cells').click(function () { | |
124 | IPython.notebook.execute_all_cells(); |
|
124 | IPython.notebook.execute_all_cells(); | |
125 | }); |
|
125 | }); | |
126 | this.element.find('#to_code').click(function () { |
|
126 | this.element.find('#to_code').click(function () { | |
127 | IPython.notebook.to_code(); |
|
127 | IPython.notebook.to_code(); | |
128 | }); |
|
128 | }); | |
129 | this.element.find('#to_markdown').click(function () { |
|
129 | this.element.find('#to_markdown').click(function () { | |
130 | IPython.notebook.to_markdown(); |
|
130 | IPython.notebook.to_markdown(); | |
131 | }); |
|
131 | }); | |
132 |
this.element.find('#to_ |
|
132 | this.element.find('#to_plaintext').click(function () { | |
133 |
IPython.notebook.to_ |
|
133 | IPython.notebook.to_plaintext(); | |
134 | }); |
|
134 | }); | |
135 | this.element.find('#to_heading1').click(function () { |
|
135 | this.element.find('#to_heading1').click(function () { | |
136 | IPython.notebook.to_heading(undefined, 1); |
|
136 | IPython.notebook.to_heading(undefined, 1); | |
137 | }); |
|
137 | }); | |
138 | this.element.find('#to_heading2').click(function () { |
|
138 | this.element.find('#to_heading2').click(function () { | |
139 | IPython.notebook.to_heading(undefined, 2); |
|
139 | IPython.notebook.to_heading(undefined, 2); | |
140 | }); |
|
140 | }); | |
141 | this.element.find('#to_heading3').click(function () { |
|
141 | this.element.find('#to_heading3').click(function () { | |
142 | IPython.notebook.to_heading(undefined, 3); |
|
142 | IPython.notebook.to_heading(undefined, 3); | |
143 | }); |
|
143 | }); | |
144 | this.element.find('#to_heading4').click(function () { |
|
144 | this.element.find('#to_heading4').click(function () { | |
145 | IPython.notebook.to_heading(undefined, 4); |
|
145 | IPython.notebook.to_heading(undefined, 4); | |
146 | }); |
|
146 | }); | |
147 | this.element.find('#to_heading5').click(function () { |
|
147 | this.element.find('#to_heading5').click(function () { | |
148 | IPython.notebook.to_heading(undefined, 5); |
|
148 | IPython.notebook.to_heading(undefined, 5); | |
149 | }); |
|
149 | }); | |
150 | this.element.find('#to_heading6').click(function () { |
|
150 | this.element.find('#to_heading6').click(function () { | |
151 | IPython.notebook.to_heading(undefined, 6); |
|
151 | IPython.notebook.to_heading(undefined, 6); | |
152 | }); |
|
152 | }); | |
153 | this.element.find('#toggle_output').click(function () { |
|
153 | this.element.find('#toggle_output').click(function () { | |
154 | IPython.notebook.toggle_output(); |
|
154 | IPython.notebook.toggle_output(); | |
155 | }); |
|
155 | }); | |
156 | this.element.find('#clear_all_output').click(function () { |
|
156 | this.element.find('#clear_all_output').click(function () { | |
157 | IPython.notebook.clear_all_output(); |
|
157 | IPython.notebook.clear_all_output(); | |
158 | }); |
|
158 | }); | |
159 | // Kernel |
|
159 | // Kernel | |
160 | this.element.find('#int_kernel').click(function () { |
|
160 | this.element.find('#int_kernel').click(function () { | |
161 | IPython.notebook.kernel.interrupt(); |
|
161 | IPython.notebook.kernel.interrupt(); | |
162 | }); |
|
162 | }); | |
163 | this.element.find('#restart_kernel').click(function () { |
|
163 | this.element.find('#restart_kernel').click(function () { | |
164 | IPython.notebook.restart_kernel(); |
|
164 | IPython.notebook.restart_kernel(); | |
165 | }); |
|
165 | }); | |
166 | // Help |
|
166 | // Help | |
167 | this.element.find('#keyboard_shortcuts').click(function () { |
|
167 | this.element.find('#keyboard_shortcuts').click(function () { | |
168 | IPython.quick_help.show_keyboard_shortcuts(); |
|
168 | IPython.quick_help.show_keyboard_shortcuts(); | |
169 | }); |
|
169 | }); | |
170 | }; |
|
170 | }; | |
171 |
|
171 | |||
172 |
|
172 | |||
173 | IPython.MenuBar = MenuBar; |
|
173 | IPython.MenuBar = MenuBar; | |
174 |
|
174 | |||
175 | return IPython; |
|
175 | return IPython; | |
176 |
|
176 | |||
177 | }(IPython)); |
|
177 | }(IPython)); |
@@ -1,1260 +1,1260 b'' | |||||
1 | //---------------------------------------------------------------------------- |
|
1 | //---------------------------------------------------------------------------- | |
2 | // Copyright (C) 2008-2011 The IPython Development Team |
|
2 | // Copyright (C) 2008-2011 The IPython Development Team | |
3 | // |
|
3 | // | |
4 | // Distributed under the terms of the BSD License. The full license is in |
|
4 | // Distributed under the terms of the BSD License. The full license is in | |
5 | // the file COPYING, distributed as part of this software. |
|
5 | // the file COPYING, distributed as part of this software. | |
6 | //---------------------------------------------------------------------------- |
|
6 | //---------------------------------------------------------------------------- | |
7 |
|
7 | |||
8 | //============================================================================ |
|
8 | //============================================================================ | |
9 | // Notebook |
|
9 | // Notebook | |
10 | //============================================================================ |
|
10 | //============================================================================ | |
11 |
|
11 | |||
12 | var IPython = (function (IPython) { |
|
12 | var IPython = (function (IPython) { | |
13 |
|
13 | |||
14 | var utils = IPython.utils; |
|
14 | var utils = IPython.utils; | |
15 |
|
15 | |||
16 | var Notebook = function (selector) { |
|
16 | var Notebook = function (selector) { | |
17 | this.read_only = IPython.read_only; |
|
17 | this.read_only = IPython.read_only; | |
18 | this.element = $(selector); |
|
18 | this.element = $(selector); | |
19 | this.element.scroll(); |
|
19 | this.element.scroll(); | |
20 | this.element.data("notebook", this); |
|
20 | this.element.data("notebook", this); | |
21 | this.next_prompt_number = 1; |
|
21 | this.next_prompt_number = 1; | |
22 | this.kernel = null; |
|
22 | this.kernel = null; | |
23 | this.clipboard = null; |
|
23 | this.clipboard = null; | |
24 | this.paste_enabled = false; |
|
24 | this.paste_enabled = false; | |
25 | this.dirty = false; |
|
25 | this.dirty = false; | |
26 | this.msg_cell_map = {}; |
|
26 | this.msg_cell_map = {}; | |
27 | this.metadata = {}; |
|
27 | this.metadata = {}; | |
28 | this.control_key_active = false; |
|
28 | this.control_key_active = false; | |
29 | this.style(); |
|
29 | this.style(); | |
30 | this.create_elements(); |
|
30 | this.create_elements(); | |
31 | this.bind_events(); |
|
31 | this.bind_events(); | |
32 | this.set_tooltipontab(true); |
|
32 | this.set_tooltipontab(true); | |
33 | this.set_smartcompleter(true); |
|
33 | this.set_smartcompleter(true); | |
34 | this.set_timebeforetooltip(1200); |
|
34 | this.set_timebeforetooltip(1200); | |
35 | }; |
|
35 | }; | |
36 |
|
36 | |||
37 |
|
37 | |||
38 | Notebook.prototype.style = function () { |
|
38 | Notebook.prototype.style = function () { | |
39 | $('div#notebook').addClass('border-box-sizing'); |
|
39 | $('div#notebook').addClass('border-box-sizing'); | |
40 | }; |
|
40 | }; | |
41 |
|
41 | |||
42 |
|
42 | |||
43 | Notebook.prototype.create_elements = function () { |
|
43 | Notebook.prototype.create_elements = function () { | |
44 | // We add this end_space div to the end of the notebook div to: |
|
44 | // We add this end_space div to the end of the notebook div to: | |
45 | // i) provide a margin between the last cell and the end of the notebook |
|
45 | // i) provide a margin between the last cell and the end of the notebook | |
46 | // ii) to prevent the div from scrolling up when the last cell is being |
|
46 | // ii) to prevent the div from scrolling up when the last cell is being | |
47 | // edited, but is too low on the page, which browsers will do automatically. |
|
47 | // edited, but is too low on the page, which browsers will do automatically. | |
48 | var that = this; |
|
48 | var that = this; | |
49 | var end_space = $('<div/>').addClass('end_space').height("30%"); |
|
49 | var end_space = $('<div/>').addClass('end_space').height("30%"); | |
50 | end_space.dblclick(function (e) { |
|
50 | end_space.dblclick(function (e) { | |
51 | if (that.read_only) return; |
|
51 | if (that.read_only) return; | |
52 | var ncells = that.ncells(); |
|
52 | var ncells = that.ncells(); | |
53 | that.insert_cell_below('code',ncells-1); |
|
53 | that.insert_cell_below('code',ncells-1); | |
54 | }); |
|
54 | }); | |
55 | this.element.append(end_space); |
|
55 | this.element.append(end_space); | |
56 | $('div#notebook').addClass('border-box-sizing'); |
|
56 | $('div#notebook').addClass('border-box-sizing'); | |
57 | }; |
|
57 | }; | |
58 |
|
58 | |||
59 |
|
59 | |||
60 | Notebook.prototype.bind_events = function () { |
|
60 | Notebook.prototype.bind_events = function () { | |
61 | var that = this; |
|
61 | var that = this; | |
62 | $(document).keydown(function (event) { |
|
62 | $(document).keydown(function (event) { | |
63 | // console.log(event); |
|
63 | // console.log(event); | |
64 | if (that.read_only) return true; |
|
64 | if (that.read_only) return true; | |
65 |
|
65 | |||
66 | // Save (CTRL+S) or (AppleKey+S) |
|
66 | // Save (CTRL+S) or (AppleKey+S) | |
67 | //metaKey = applekey on mac |
|
67 | //metaKey = applekey on mac | |
68 | if ((event.ctrlKey || event.metaKey) && event.keyCode==83) { |
|
68 | if ((event.ctrlKey || event.metaKey) && event.keyCode==83) { | |
69 | IPython.save_widget.save_notebook(); |
|
69 | IPython.save_widget.save_notebook(); | |
70 | event.preventDefault(); |
|
70 | event.preventDefault(); | |
71 | return false; |
|
71 | return false; | |
72 | } else if (event.which === 27) { |
|
72 | } else if (event.which === 27) { | |
73 | // Intercept escape at highest level to avoid closing |
|
73 | // Intercept escape at highest level to avoid closing | |
74 | // websocket connection with firefox |
|
74 | // websocket connection with firefox | |
75 | event.preventDefault(); |
|
75 | event.preventDefault(); | |
76 | } |
|
76 | } | |
77 | if (event.which === 38 && !event.shiftKey) { |
|
77 | if (event.which === 38 && !event.shiftKey) { | |
78 | var cell = that.get_selected_cell(); |
|
78 | var cell = that.get_selected_cell(); | |
79 | if (cell.at_top()) { |
|
79 | if (cell.at_top()) { | |
80 | event.preventDefault(); |
|
80 | event.preventDefault(); | |
81 | that.select_prev(); |
|
81 | that.select_prev(); | |
82 | }; |
|
82 | }; | |
83 | } else if (event.which === 40 && !event.shiftKey) { |
|
83 | } else if (event.which === 40 && !event.shiftKey) { | |
84 | var cell = that.get_selected_cell(); |
|
84 | var cell = that.get_selected_cell(); | |
85 | if (cell.at_bottom()) { |
|
85 | if (cell.at_bottom()) { | |
86 | event.preventDefault(); |
|
86 | event.preventDefault(); | |
87 | that.select_next(); |
|
87 | that.select_next(); | |
88 | }; |
|
88 | }; | |
89 | } else if (event.which === 13 && event.shiftKey) { |
|
89 | } else if (event.which === 13 && event.shiftKey) { | |
90 | that.execute_selected_cell(); |
|
90 | that.execute_selected_cell(); | |
91 | return false; |
|
91 | return false; | |
92 | } else if (event.which === 13 && event.ctrlKey) { |
|
92 | } else if (event.which === 13 && event.ctrlKey) { | |
93 | that.execute_selected_cell({terminal:true}); |
|
93 | that.execute_selected_cell({terminal:true}); | |
94 | return false; |
|
94 | return false; | |
95 | } else if (event.which === 77 && event.ctrlKey) { |
|
95 | } else if (event.which === 77 && event.ctrlKey) { | |
96 | that.control_key_active = true; |
|
96 | that.control_key_active = true; | |
97 | return false; |
|
97 | return false; | |
98 | } else if (event.which === 88 && that.control_key_active) { |
|
98 | } else if (event.which === 88 && that.control_key_active) { | |
99 | // Cut selected cell = x |
|
99 | // Cut selected cell = x | |
100 | that.cut_cell(); |
|
100 | that.cut_cell(); | |
101 | that.control_key_active = false; |
|
101 | that.control_key_active = false; | |
102 | return false; |
|
102 | return false; | |
103 | } else if (event.which === 67 && that.control_key_active) { |
|
103 | } else if (event.which === 67 && that.control_key_active) { | |
104 | // Copy selected cell = c |
|
104 | // Copy selected cell = c | |
105 | that.copy_cell(); |
|
105 | that.copy_cell(); | |
106 | that.control_key_active = false; |
|
106 | that.control_key_active = false; | |
107 | return false; |
|
107 | return false; | |
108 | } else if (event.which === 86 && that.control_key_active) { |
|
108 | } else if (event.which === 86 && that.control_key_active) { | |
109 | // Paste selected cell = v |
|
109 | // Paste selected cell = v | |
110 | that.paste_cell(); |
|
110 | that.paste_cell(); | |
111 | that.control_key_active = false; |
|
111 | that.control_key_active = false; | |
112 | return false; |
|
112 | return false; | |
113 | } else if (event.which === 68 && that.control_key_active) { |
|
113 | } else if (event.which === 68 && that.control_key_active) { | |
114 | // Delete selected cell = d |
|
114 | // Delete selected cell = d | |
115 | that.delete_cell(); |
|
115 | that.delete_cell(); | |
116 | that.control_key_active = false; |
|
116 | that.control_key_active = false; | |
117 | return false; |
|
117 | return false; | |
118 | } else if (event.which === 65 && that.control_key_active) { |
|
118 | } else if (event.which === 65 && that.control_key_active) { | |
119 | // Insert code cell above selected = a |
|
119 | // Insert code cell above selected = a | |
120 | that.insert_cell_above('code'); |
|
120 | that.insert_cell_above('code'); | |
121 | that.control_key_active = false; |
|
121 | that.control_key_active = false; | |
122 | return false; |
|
122 | return false; | |
123 | } else if (event.which === 66 && that.control_key_active) { |
|
123 | } else if (event.which === 66 && that.control_key_active) { | |
124 | // Insert code cell below selected = b |
|
124 | // Insert code cell below selected = b | |
125 | that.insert_cell_below('code'); |
|
125 | that.insert_cell_below('code'); | |
126 | that.control_key_active = false; |
|
126 | that.control_key_active = false; | |
127 | return false; |
|
127 | return false; | |
128 | } else if (event.which === 89 && that.control_key_active) { |
|
128 | } else if (event.which === 89 && that.control_key_active) { | |
129 | // To code = y |
|
129 | // To code = y | |
130 | that.to_code(); |
|
130 | that.to_code(); | |
131 | that.control_key_active = false; |
|
131 | that.control_key_active = false; | |
132 | return false; |
|
132 | return false; | |
133 | } else if (event.which === 77 && that.control_key_active) { |
|
133 | } else if (event.which === 77 && that.control_key_active) { | |
134 | // To markdown = m |
|
134 | // To markdown = m | |
135 | that.to_markdown(); |
|
135 | that.to_markdown(); | |
136 | that.control_key_active = false; |
|
136 | that.control_key_active = false; | |
137 | return false; |
|
137 | return false; | |
138 |
} else if (event.which === 8 |
|
138 | } else if (event.which === 84 && that.control_key_active) { | |
139 |
// To |
|
139 | // To Plaintext = r | |
140 |
that.to_ |
|
140 | that.to_plaintext(); | |
141 | that.control_key_active = false; |
|
141 | that.control_key_active = false; | |
142 | return false; |
|
142 | return false; | |
143 | } else if (event.which === 49 && that.control_key_active) { |
|
143 | } else if (event.which === 49 && that.control_key_active) { | |
144 | // To Heading 1 = 1 |
|
144 | // To Heading 1 = 1 | |
145 | that.to_heading(undefined, 1); |
|
145 | that.to_heading(undefined, 1); | |
146 | that.control_key_active = false; |
|
146 | that.control_key_active = false; | |
147 | return false; |
|
147 | return false; | |
148 | } else if (event.which === 50 && that.control_key_active) { |
|
148 | } else if (event.which === 50 && that.control_key_active) { | |
149 | // To Heading 2 = 2 |
|
149 | // To Heading 2 = 2 | |
150 | that.to_heading(undefined, 2); |
|
150 | that.to_heading(undefined, 2); | |
151 | that.control_key_active = false; |
|
151 | that.control_key_active = false; | |
152 | return false; |
|
152 | return false; | |
153 | } else if (event.which === 51 && that.control_key_active) { |
|
153 | } else if (event.which === 51 && that.control_key_active) { | |
154 | // To Heading 3 = 3 |
|
154 | // To Heading 3 = 3 | |
155 | that.to_heading(undefined, 3); |
|
155 | that.to_heading(undefined, 3); | |
156 | that.control_key_active = false; |
|
156 | that.control_key_active = false; | |
157 | return false; |
|
157 | return false; | |
158 | } else if (event.which === 52 && that.control_key_active) { |
|
158 | } else if (event.which === 52 && that.control_key_active) { | |
159 | // To Heading 4 = 4 |
|
159 | // To Heading 4 = 4 | |
160 | that.to_heading(undefined, 4); |
|
160 | that.to_heading(undefined, 4); | |
161 | that.control_key_active = false; |
|
161 | that.control_key_active = false; | |
162 | return false; |
|
162 | return false; | |
163 | } else if (event.which === 53 && that.control_key_active) { |
|
163 | } else if (event.which === 53 && that.control_key_active) { | |
164 | // To Heading 5 = 5 |
|
164 | // To Heading 5 = 5 | |
165 | that.to_heading(undefined, 5); |
|
165 | that.to_heading(undefined, 5); | |
166 | that.control_key_active = false; |
|
166 | that.control_key_active = false; | |
167 | return false; |
|
167 | return false; | |
168 | } else if (event.which === 54 && that.control_key_active) { |
|
168 | } else if (event.which === 54 && that.control_key_active) { | |
169 | // To Heading 6 = 6 |
|
169 | // To Heading 6 = 6 | |
170 | that.to_heading(undefined, 6); |
|
170 | that.to_heading(undefined, 6); | |
171 | that.control_key_active = false; |
|
171 | that.control_key_active = false; | |
172 | return false; |
|
172 | return false; | |
173 |
} else if (event.which === |
|
173 | } else if (event.which === 79 && that.control_key_active) { | |
174 |
// Toggle output = |
|
174 | // Toggle output = o | |
175 | that.toggle_output(); |
|
175 | that.toggle_output(); | |
176 | that.control_key_active = false; |
|
176 | that.control_key_active = false; | |
177 | return false; |
|
177 | return false; | |
178 | } else if (event.which === 83 && that.control_key_active) { |
|
178 | } else if (event.which === 83 && that.control_key_active) { | |
179 | // Save notebook = s |
|
179 | // Save notebook = s | |
180 | IPython.save_widget.save_notebook(); |
|
180 | IPython.save_widget.save_notebook(); | |
181 | that.control_key_active = false; |
|
181 | that.control_key_active = false; | |
182 | return false; |
|
182 | return false; | |
183 | } else if (event.which === 74 && that.control_key_active) { |
|
183 | } else if (event.which === 74 && that.control_key_active) { | |
184 | // Move cell down = j |
|
184 | // Move cell down = j | |
185 | that.move_cell_down(); |
|
185 | that.move_cell_down(); | |
186 | that.control_key_active = false; |
|
186 | that.control_key_active = false; | |
187 | return false; |
|
187 | return false; | |
188 | } else if (event.which === 75 && that.control_key_active) { |
|
188 | } else if (event.which === 75 && that.control_key_active) { | |
189 | // Move cell up = k |
|
189 | // Move cell up = k | |
190 | that.move_cell_up(); |
|
190 | that.move_cell_up(); | |
191 | that.control_key_active = false; |
|
191 | that.control_key_active = false; | |
192 | return false; |
|
192 | return false; | |
193 | } else if (event.which === 80 && that.control_key_active) { |
|
193 | } else if (event.which === 80 && that.control_key_active) { | |
194 | // Select previous = p |
|
194 | // Select previous = p | |
195 | that.select_prev(); |
|
195 | that.select_prev(); | |
196 | that.control_key_active = false; |
|
196 | that.control_key_active = false; | |
197 | return false; |
|
197 | return false; | |
198 | } else if (event.which === 78 && that.control_key_active) { |
|
198 | } else if (event.which === 78 && that.control_key_active) { | |
199 | // Select next = n |
|
199 | // Select next = n | |
200 | that.select_next(); |
|
200 | that.select_next(); | |
201 | that.control_key_active = false; |
|
201 | that.control_key_active = false; | |
202 | return false; |
|
202 | return false; | |
203 | } else if (event.which === 76 && that.control_key_active) { |
|
203 | } else if (event.which === 76 && that.control_key_active) { | |
204 | // Toggle line numbers = l |
|
204 | // Toggle line numbers = l | |
205 | that.cell_toggle_line_numbers(); |
|
205 | that.cell_toggle_line_numbers(); | |
206 | that.control_key_active = false; |
|
206 | that.control_key_active = false; | |
207 | return false; |
|
207 | return false; | |
208 | } else if (event.which === 73 && that.control_key_active) { |
|
208 | } else if (event.which === 73 && that.control_key_active) { | |
209 | // Interrupt kernel = i |
|
209 | // Interrupt kernel = i | |
210 | IPython.notebook.kernel.interrupt(); |
|
210 | IPython.notebook.kernel.interrupt(); | |
211 | that.control_key_active = false; |
|
211 | that.control_key_active = false; | |
212 | return false; |
|
212 | return false; | |
213 | } else if (event.which === 190 && that.control_key_active) { |
|
213 | } else if (event.which === 190 && that.control_key_active) { | |
214 | // Restart kernel = . # matches qt console |
|
214 | // Restart kernel = . # matches qt console | |
215 | IPython.notebook.restart_kernel(); |
|
215 | IPython.notebook.restart_kernel(); | |
216 | that.control_key_active = false; |
|
216 | that.control_key_active = false; | |
217 | return false; |
|
217 | return false; | |
218 | } else if (event.which === 72 && that.control_key_active) { |
|
218 | } else if (event.which === 72 && that.control_key_active) { | |
219 | // Show keyboard shortcuts = h |
|
219 | // Show keyboard shortcuts = h | |
220 | IPython.quick_help.show_keyboard_shortcuts(); |
|
220 | IPython.quick_help.show_keyboard_shortcuts(); | |
221 | that.control_key_active = false; |
|
221 | that.control_key_active = false; | |
222 | return false; |
|
222 | return false; | |
223 | } else if (that.control_key_active) { |
|
223 | } else if (that.control_key_active) { | |
224 | that.control_key_active = false; |
|
224 | that.control_key_active = false; | |
225 | return true; |
|
225 | return true; | |
226 | }; |
|
226 | }; | |
227 | return true; |
|
227 | return true; | |
228 | }); |
|
228 | }); | |
229 |
|
229 | |||
230 | this.element.bind('collapse_pager', function () { |
|
230 | this.element.bind('collapse_pager', function () { | |
231 | var app_height = $('div#main_app').height(); // content height |
|
231 | var app_height = $('div#main_app').height(); // content height | |
232 | var splitter_height = $('div#pager_splitter').outerHeight(true); |
|
232 | var splitter_height = $('div#pager_splitter').outerHeight(true); | |
233 | var new_height = app_height - splitter_height; |
|
233 | var new_height = app_height - splitter_height; | |
234 | that.element.animate({height : new_height + 'px'}, 'fast'); |
|
234 | that.element.animate({height : new_height + 'px'}, 'fast'); | |
235 | }); |
|
235 | }); | |
236 |
|
236 | |||
237 | this.element.bind('expand_pager', function () { |
|
237 | this.element.bind('expand_pager', function () { | |
238 | var app_height = $('div#main_app').height(); // content height |
|
238 | var app_height = $('div#main_app').height(); // content height | |
239 | var splitter_height = $('div#pager_splitter').outerHeight(true); |
|
239 | var splitter_height = $('div#pager_splitter').outerHeight(true); | |
240 | var pager_height = $('div#pager').outerHeight(true); |
|
240 | var pager_height = $('div#pager').outerHeight(true); | |
241 | var new_height = app_height - pager_height - splitter_height; |
|
241 | var new_height = app_height - pager_height - splitter_height; | |
242 | that.element.animate({height : new_height + 'px'}, 'fast'); |
|
242 | that.element.animate({height : new_height + 'px'}, 'fast'); | |
243 | }); |
|
243 | }); | |
244 |
|
244 | |||
245 | $(window).bind('beforeunload', function () { |
|
245 | $(window).bind('beforeunload', function () { | |
246 | // TODO: Make killing the kernel configurable. |
|
246 | // TODO: Make killing the kernel configurable. | |
247 | var kill_kernel = false; |
|
247 | var kill_kernel = false; | |
248 | if (kill_kernel) { |
|
248 | if (kill_kernel) { | |
249 | that.kernel.kill(); |
|
249 | that.kernel.kill(); | |
250 | } |
|
250 | } | |
251 | if (that.dirty && ! that.read_only) { |
|
251 | if (that.dirty && ! that.read_only) { | |
252 | return "You have unsaved changes that will be lost if you leave this page."; |
|
252 | return "You have unsaved changes that will be lost if you leave this page."; | |
253 | }; |
|
253 | }; | |
254 | // Null is the *only* return value that will make the browser not |
|
254 | // Null is the *only* return value that will make the browser not | |
255 | // pop up the "don't leave" dialog. |
|
255 | // pop up the "don't leave" dialog. | |
256 | return null; |
|
256 | return null; | |
257 | }); |
|
257 | }); | |
258 | }; |
|
258 | }; | |
259 |
|
259 | |||
260 |
|
260 | |||
261 | Notebook.prototype.scroll_to_bottom = function () { |
|
261 | Notebook.prototype.scroll_to_bottom = function () { | |
262 | this.element.animate({scrollTop:this.element.get(0).scrollHeight}, 0); |
|
262 | this.element.animate({scrollTop:this.element.get(0).scrollHeight}, 0); | |
263 | }; |
|
263 | }; | |
264 |
|
264 | |||
265 |
|
265 | |||
266 | Notebook.prototype.scroll_to_top = function () { |
|
266 | Notebook.prototype.scroll_to_top = function () { | |
267 | this.element.animate({scrollTop:0}, 0); |
|
267 | this.element.animate({scrollTop:0}, 0); | |
268 | }; |
|
268 | }; | |
269 |
|
269 | |||
270 |
|
270 | |||
271 | // Cell indexing, retrieval, etc. |
|
271 | // Cell indexing, retrieval, etc. | |
272 |
|
272 | |||
273 | Notebook.prototype.get_cell_elements = function () { |
|
273 | Notebook.prototype.get_cell_elements = function () { | |
274 | return this.element.children("div.cell"); |
|
274 | return this.element.children("div.cell"); | |
275 | }; |
|
275 | }; | |
276 |
|
276 | |||
277 |
|
277 | |||
278 | Notebook.prototype.get_cell_element = function (index) { |
|
278 | Notebook.prototype.get_cell_element = function (index) { | |
279 | var result = null; |
|
279 | var result = null; | |
280 | var e = this.get_cell_elements().eq(index); |
|
280 | var e = this.get_cell_elements().eq(index); | |
281 | if (e.length !== 0) { |
|
281 | if (e.length !== 0) { | |
282 | result = e; |
|
282 | result = e; | |
283 | } |
|
283 | } | |
284 | return result; |
|
284 | return result; | |
285 | }; |
|
285 | }; | |
286 |
|
286 | |||
287 |
|
287 | |||
288 | Notebook.prototype.ncells = function (cell) { |
|
288 | Notebook.prototype.ncells = function (cell) { | |
289 | return this.get_cell_elements().length; |
|
289 | return this.get_cell_elements().length; | |
290 | }; |
|
290 | }; | |
291 |
|
291 | |||
292 |
|
292 | |||
293 | // TODO: we are often calling cells as cells()[i], which we should optimize |
|
293 | // TODO: we are often calling cells as cells()[i], which we should optimize | |
294 | // to cells(i) or a new method. |
|
294 | // to cells(i) or a new method. | |
295 | Notebook.prototype.get_cells = function () { |
|
295 | Notebook.prototype.get_cells = function () { | |
296 | return this.get_cell_elements().toArray().map(function (e) { |
|
296 | return this.get_cell_elements().toArray().map(function (e) { | |
297 | return $(e).data("cell"); |
|
297 | return $(e).data("cell"); | |
298 | }); |
|
298 | }); | |
299 | }; |
|
299 | }; | |
300 |
|
300 | |||
301 |
|
301 | |||
302 | Notebook.prototype.get_cell = function (index) { |
|
302 | Notebook.prototype.get_cell = function (index) { | |
303 | var result = null; |
|
303 | var result = null; | |
304 | var ce = this.get_cell_element(index); |
|
304 | var ce = this.get_cell_element(index); | |
305 | if (ce !== null) { |
|
305 | if (ce !== null) { | |
306 | result = ce.data('cell'); |
|
306 | result = ce.data('cell'); | |
307 | } |
|
307 | } | |
308 | return result; |
|
308 | return result; | |
309 | } |
|
309 | } | |
310 |
|
310 | |||
311 |
|
311 | |||
312 | Notebook.prototype.get_next_cell = function (cell) { |
|
312 | Notebook.prototype.get_next_cell = function (cell) { | |
313 | var result = null; |
|
313 | var result = null; | |
314 | var index = this.find_cell_index(cell); |
|
314 | var index = this.find_cell_index(cell); | |
315 | if (index !== null && index < this.ncells()) { |
|
315 | if (index !== null && index < this.ncells()) { | |
316 | result = this.get_cell(index+1); |
|
316 | result = this.get_cell(index+1); | |
317 | } |
|
317 | } | |
318 | return result; |
|
318 | return result; | |
319 | } |
|
319 | } | |
320 |
|
320 | |||
321 |
|
321 | |||
322 | Notebook.prototype.get_prev_cell = function (cell) { |
|
322 | Notebook.prototype.get_prev_cell = function (cell) { | |
323 | var result = null; |
|
323 | var result = null; | |
324 | var index = this.find_cell_index(cell); |
|
324 | var index = this.find_cell_index(cell); | |
325 | if (index !== null && index > 1) { |
|
325 | if (index !== null && index > 1) { | |
326 | result = this.get_cell(index-1); |
|
326 | result = this.get_cell(index-1); | |
327 | } |
|
327 | } | |
328 | return result; |
|
328 | return result; | |
329 | } |
|
329 | } | |
330 |
|
330 | |||
331 | Notebook.prototype.find_cell_index = function (cell) { |
|
331 | Notebook.prototype.find_cell_index = function (cell) { | |
332 | var result = null; |
|
332 | var result = null; | |
333 | this.get_cell_elements().filter(function (index) { |
|
333 | this.get_cell_elements().filter(function (index) { | |
334 | if ($(this).data("cell") === cell) { |
|
334 | if ($(this).data("cell") === cell) { | |
335 | result = index; |
|
335 | result = index; | |
336 | }; |
|
336 | }; | |
337 | }); |
|
337 | }); | |
338 | return result; |
|
338 | return result; | |
339 | }; |
|
339 | }; | |
340 |
|
340 | |||
341 |
|
341 | |||
342 | Notebook.prototype.index_or_selected = function (index) { |
|
342 | Notebook.prototype.index_or_selected = function (index) { | |
343 | var i; |
|
343 | var i; | |
344 | if (index === undefined || index === null) { |
|
344 | if (index === undefined || index === null) { | |
345 | i = this.get_selected_index(); |
|
345 | i = this.get_selected_index(); | |
346 | if (i === null) { |
|
346 | if (i === null) { | |
347 | i = 0; |
|
347 | i = 0; | |
348 | } |
|
348 | } | |
349 | } else { |
|
349 | } else { | |
350 | i = index; |
|
350 | i = index; | |
351 | } |
|
351 | } | |
352 | return i; |
|
352 | return i; | |
353 | }; |
|
353 | }; | |
354 |
|
354 | |||
355 |
|
355 | |||
356 | Notebook.prototype.get_selected_cell = function () { |
|
356 | Notebook.prototype.get_selected_cell = function () { | |
357 | var index = this.get_selected_index(); |
|
357 | var index = this.get_selected_index(); | |
358 | return this.get_cell(index); |
|
358 | return this.get_cell(index); | |
359 | }; |
|
359 | }; | |
360 |
|
360 | |||
361 |
|
361 | |||
362 | Notebook.prototype.is_valid_cell_index = function (index) { |
|
362 | Notebook.prototype.is_valid_cell_index = function (index) { | |
363 | if (index !== null && index >= 0 && index < this.ncells()) { |
|
363 | if (index !== null && index >= 0 && index < this.ncells()) { | |
364 | return true; |
|
364 | return true; | |
365 | } else { |
|
365 | } else { | |
366 | return false; |
|
366 | return false; | |
367 | }; |
|
367 | }; | |
368 | } |
|
368 | } | |
369 |
|
369 | |||
370 | Notebook.prototype.get_selected_index = function () { |
|
370 | Notebook.prototype.get_selected_index = function () { | |
371 | var result = null; |
|
371 | var result = null; | |
372 | this.get_cell_elements().filter(function (index) { |
|
372 | this.get_cell_elements().filter(function (index) { | |
373 | if ($(this).data("cell").selected === true) { |
|
373 | if ($(this).data("cell").selected === true) { | |
374 | result = index; |
|
374 | result = index; | |
375 | }; |
|
375 | }; | |
376 | }); |
|
376 | }); | |
377 | return result; |
|
377 | return result; | |
378 | }; |
|
378 | }; | |
379 |
|
379 | |||
380 |
|
380 | |||
381 | Notebook.prototype.cell_for_msg = function (msg_id) { |
|
381 | Notebook.prototype.cell_for_msg = function (msg_id) { | |
382 | var cell_id = this.msg_cell_map[msg_id]; |
|
382 | var cell_id = this.msg_cell_map[msg_id]; | |
383 | var result = null; |
|
383 | var result = null; | |
384 | this.get_cell_elements().filter(function (index) { |
|
384 | this.get_cell_elements().filter(function (index) { | |
385 | cell = $(this).data("cell"); |
|
385 | cell = $(this).data("cell"); | |
386 | if (cell.cell_id === cell_id) { |
|
386 | if (cell.cell_id === cell_id) { | |
387 | result = cell; |
|
387 | result = cell; | |
388 | }; |
|
388 | }; | |
389 | }); |
|
389 | }); | |
390 | return result; |
|
390 | return result; | |
391 | }; |
|
391 | }; | |
392 |
|
392 | |||
393 |
|
393 | |||
394 | // Cell selection. |
|
394 | // Cell selection. | |
395 |
|
395 | |||
396 | Notebook.prototype.select = function (index) { |
|
396 | Notebook.prototype.select = function (index) { | |
397 | if (index !== undefined && index >= 0 && index < this.ncells()) { |
|
397 | if (index !== undefined && index >= 0 && index < this.ncells()) { | |
398 | sindex = this.get_selected_index() |
|
398 | sindex = this.get_selected_index() | |
399 | if (sindex !== null && index !== sindex) { |
|
399 | if (sindex !== null && index !== sindex) { | |
400 | this.get_cell(sindex).unselect(); |
|
400 | this.get_cell(sindex).unselect(); | |
401 | }; |
|
401 | }; | |
402 | var cell = this.get_cell(index) |
|
402 | var cell = this.get_cell(index) | |
403 | cell.select(); |
|
403 | cell.select(); | |
404 | IPython.toolbar.set_cell_type(cell.cell_type); |
|
404 | IPython.toolbar.set_cell_type(cell.cell_type); | |
405 | }; |
|
405 | }; | |
406 | return this; |
|
406 | return this; | |
407 | }; |
|
407 | }; | |
408 |
|
408 | |||
409 |
|
409 | |||
410 | Notebook.prototype.select_next = function () { |
|
410 | Notebook.prototype.select_next = function () { | |
411 | var index = this.get_selected_index(); |
|
411 | var index = this.get_selected_index(); | |
412 | if (index !== null && index >= 0 && (index+1) < this.ncells()) { |
|
412 | if (index !== null && index >= 0 && (index+1) < this.ncells()) { | |
413 | this.select(index+1); |
|
413 | this.select(index+1); | |
414 | }; |
|
414 | }; | |
415 | return this; |
|
415 | return this; | |
416 | }; |
|
416 | }; | |
417 |
|
417 | |||
418 |
|
418 | |||
419 | Notebook.prototype.select_prev = function () { |
|
419 | Notebook.prototype.select_prev = function () { | |
420 | var index = this.get_selected_index(); |
|
420 | var index = this.get_selected_index(); | |
421 | if (index !== null && index >= 0 && (index-1) < this.ncells()) { |
|
421 | if (index !== null && index >= 0 && (index-1) < this.ncells()) { | |
422 | this.select(index-1); |
|
422 | this.select(index-1); | |
423 | }; |
|
423 | }; | |
424 | return this; |
|
424 | return this; | |
425 | }; |
|
425 | }; | |
426 |
|
426 | |||
427 |
|
427 | |||
428 | // Cell movement |
|
428 | // Cell movement | |
429 |
|
429 | |||
430 | Notebook.prototype.move_cell_up = function (index) { |
|
430 | Notebook.prototype.move_cell_up = function (index) { | |
431 | var i = this.index_or_selected(); |
|
431 | var i = this.index_or_selected(); | |
432 | if (i !== null && i < this.ncells() && i > 0) { |
|
432 | if (i !== null && i < this.ncells() && i > 0) { | |
433 | var pivot = this.get_cell_element(i-1); |
|
433 | var pivot = this.get_cell_element(i-1); | |
434 | var tomove = this.get_cell_element(i); |
|
434 | var tomove = this.get_cell_element(i); | |
435 | if (pivot !== null && tomove !== null) { |
|
435 | if (pivot !== null && tomove !== null) { | |
436 | tomove.detach(); |
|
436 | tomove.detach(); | |
437 | pivot.before(tomove); |
|
437 | pivot.before(tomove); | |
438 | this.select(i-1); |
|
438 | this.select(i-1); | |
439 | }; |
|
439 | }; | |
440 | }; |
|
440 | }; | |
441 | this.dirty = true; |
|
441 | this.dirty = true; | |
442 | return this; |
|
442 | return this; | |
443 | }; |
|
443 | }; | |
444 |
|
444 | |||
445 |
|
445 | |||
446 | Notebook.prototype.move_cell_down = function (index) { |
|
446 | Notebook.prototype.move_cell_down = function (index) { | |
447 | var i = this.index_or_selected(); |
|
447 | var i = this.index_or_selected(); | |
448 | if (i !== null && i < (this.ncells()-1) && i >= 0) { |
|
448 | if (i !== null && i < (this.ncells()-1) && i >= 0) { | |
449 | var pivot = this.get_cell_element(i+1); |
|
449 | var pivot = this.get_cell_element(i+1); | |
450 | var tomove = this.get_cell_element(i); |
|
450 | var tomove = this.get_cell_element(i); | |
451 | if (pivot !== null && tomove !== null) { |
|
451 | if (pivot !== null && tomove !== null) { | |
452 | tomove.detach(); |
|
452 | tomove.detach(); | |
453 | pivot.after(tomove); |
|
453 | pivot.after(tomove); | |
454 | this.select(i+1); |
|
454 | this.select(i+1); | |
455 | }; |
|
455 | }; | |
456 | }; |
|
456 | }; | |
457 | this.dirty = true; |
|
457 | this.dirty = true; | |
458 | return this; |
|
458 | return this; | |
459 | }; |
|
459 | }; | |
460 |
|
460 | |||
461 |
|
461 | |||
462 | Notebook.prototype.sort_cells = function () { |
|
462 | Notebook.prototype.sort_cells = function () { | |
463 | // This is not working right now. Calling this will actually crash |
|
463 | // This is not working right now. Calling this will actually crash | |
464 | // the browser. I think there is an infinite loop in here... |
|
464 | // the browser. I think there is an infinite loop in here... | |
465 | var ncells = this.ncells(); |
|
465 | var ncells = this.ncells(); | |
466 | var sindex = this.get_selected_index(); |
|
466 | var sindex = this.get_selected_index(); | |
467 | var swapped; |
|
467 | var swapped; | |
468 | do { |
|
468 | do { | |
469 | swapped = false; |
|
469 | swapped = false; | |
470 | for (var i=1; i<ncells; i++) { |
|
470 | for (var i=1; i<ncells; i++) { | |
471 | current = this.get_cell(i); |
|
471 | current = this.get_cell(i); | |
472 | previous = this.get_cell(i-1); |
|
472 | previous = this.get_cell(i-1); | |
473 | if (previous.input_prompt_number > current.input_prompt_number) { |
|
473 | if (previous.input_prompt_number > current.input_prompt_number) { | |
474 | this.move_cell_up(i); |
|
474 | this.move_cell_up(i); | |
475 | swapped = true; |
|
475 | swapped = true; | |
476 | }; |
|
476 | }; | |
477 | }; |
|
477 | }; | |
478 | } while (swapped); |
|
478 | } while (swapped); | |
479 | this.select(sindex); |
|
479 | this.select(sindex); | |
480 | return this; |
|
480 | return this; | |
481 | }; |
|
481 | }; | |
482 |
|
482 | |||
483 | // Insertion, deletion. |
|
483 | // Insertion, deletion. | |
484 |
|
484 | |||
485 | Notebook.prototype.delete_cell = function (index) { |
|
485 | Notebook.prototype.delete_cell = function (index) { | |
486 | var i = this.index_or_selected(index); |
|
486 | var i = this.index_or_selected(index); | |
487 | if (this.is_valid_cell_index(i)) { |
|
487 | if (this.is_valid_cell_index(i)) { | |
488 | var ce = this.get_cell_element(i); |
|
488 | var ce = this.get_cell_element(i); | |
489 | ce.remove(); |
|
489 | ce.remove(); | |
490 | if (i === (this.ncells())) { |
|
490 | if (i === (this.ncells())) { | |
491 | this.select(i-1); |
|
491 | this.select(i-1); | |
492 | } else { |
|
492 | } else { | |
493 | this.select(i); |
|
493 | this.select(i); | |
494 | }; |
|
494 | }; | |
495 | this.dirty = true; |
|
495 | this.dirty = true; | |
496 | }; |
|
496 | }; | |
497 | return this; |
|
497 | return this; | |
498 | }; |
|
498 | }; | |
499 |
|
499 | |||
500 |
|
500 | |||
501 | Notebook.prototype.insert_cell_below = function (type, index) { |
|
501 | Notebook.prototype.insert_cell_below = function (type, index) { | |
502 | // type = ('code','html','markdown') |
|
502 | // type = ('code','html','markdown') | |
503 | // index = cell index or undefined to insert below selected |
|
503 | // index = cell index or undefined to insert below selected | |
504 | index = this.index_or_selected(index); |
|
504 | index = this.index_or_selected(index); | |
505 | var cell = null; |
|
505 | var cell = null; | |
506 | if (this.ncells() === 0 || this.is_valid_cell_index(index)) { |
|
506 | if (this.ncells() === 0 || this.is_valid_cell_index(index)) { | |
507 | if (type === 'code') { |
|
507 | if (type === 'code') { | |
508 | cell = new IPython.CodeCell(this); |
|
508 | cell = new IPython.CodeCell(this); | |
509 | cell.set_input_prompt(); |
|
509 | cell.set_input_prompt(); | |
510 | } else if (type === 'markdown') { |
|
510 | } else if (type === 'markdown') { | |
511 | cell = new IPython.MarkdownCell(this); |
|
511 | cell = new IPython.MarkdownCell(this); | |
512 | } else if (type === 'html') { |
|
512 | } else if (type === 'html') { | |
513 | cell = new IPython.HTMLCell(this); |
|
513 | cell = new IPython.HTMLCell(this); | |
514 |
} else if (type === ' |
|
514 | } else if (type === 'plaintext') { | |
515 |
cell = new IPython. |
|
515 | cell = new IPython.PlaintextCell(this); | |
516 | } else if (type === 'heading') { |
|
516 | } else if (type === 'heading') { | |
517 | cell = new IPython.HeadingCell(this); |
|
517 | cell = new IPython.HeadingCell(this); | |
518 | }; |
|
518 | }; | |
519 | if (cell !== null) { |
|
519 | if (cell !== null) { | |
520 | if (this.ncells() === 0) { |
|
520 | if (this.ncells() === 0) { | |
521 | this.element.find('div.end_space').before(cell.element); |
|
521 | this.element.find('div.end_space').before(cell.element); | |
522 | } else if (this.is_valid_cell_index(index)) { |
|
522 | } else if (this.is_valid_cell_index(index)) { | |
523 | this.get_cell_element(index).after(cell.element); |
|
523 | this.get_cell_element(index).after(cell.element); | |
524 | }; |
|
524 | }; | |
525 | cell.render(); |
|
525 | cell.render(); | |
526 | this.select(this.find_cell_index(cell)); |
|
526 | this.select(this.find_cell_index(cell)); | |
527 | this.dirty = true; |
|
527 | this.dirty = true; | |
528 | return cell; |
|
528 | return cell; | |
529 | }; |
|
529 | }; | |
530 | }; |
|
530 | }; | |
531 | return cell; |
|
531 | return cell; | |
532 | }; |
|
532 | }; | |
533 |
|
533 | |||
534 |
|
534 | |||
535 | Notebook.prototype.insert_cell_above = function (type, index) { |
|
535 | Notebook.prototype.insert_cell_above = function (type, index) { | |
536 | // type = ('code','html','markdown') |
|
536 | // type = ('code','html','markdown') | |
537 | // index = cell index or undefined to insert above selected |
|
537 | // index = cell index or undefined to insert above selected | |
538 | index = this.index_or_selected(index); |
|
538 | index = this.index_or_selected(index); | |
539 | var cell = null; |
|
539 | var cell = null; | |
540 | if (this.ncells() === 0 || this.is_valid_cell_index(index)) { |
|
540 | if (this.ncells() === 0 || this.is_valid_cell_index(index)) { | |
541 | if (type === 'code') { |
|
541 | if (type === 'code') { | |
542 | cell = new IPython.CodeCell(this); |
|
542 | cell = new IPython.CodeCell(this); | |
543 | cell.set_input_prompt(); |
|
543 | cell.set_input_prompt(); | |
544 | } else if (type === 'markdown') { |
|
544 | } else if (type === 'markdown') { | |
545 | cell = new IPython.MarkdownCell(this); |
|
545 | cell = new IPython.MarkdownCell(this); | |
546 | } else if (type === 'html') { |
|
546 | } else if (type === 'html') { | |
547 | cell = new IPython.HTMLCell(this); |
|
547 | cell = new IPython.HTMLCell(this); | |
548 |
} else if (type === ' |
|
548 | } else if (type === 'plaintext') { | |
549 |
cell = new IPython. |
|
549 | cell = new IPython.PlaintextCell(this); | |
550 | } else if (type === 'heading') { |
|
550 | } else if (type === 'heading') { | |
551 | cell = new IPython.HeadingCell(this); |
|
551 | cell = new IPython.HeadingCell(this); | |
552 | }; |
|
552 | }; | |
553 | if (cell !== null) { |
|
553 | if (cell !== null) { | |
554 | if (this.ncells() === 0) { |
|
554 | if (this.ncells() === 0) { | |
555 | this.element.find('div.end_space').before(cell.element); |
|
555 | this.element.find('div.end_space').before(cell.element); | |
556 | } else if (this.is_valid_cell_index(index)) { |
|
556 | } else if (this.is_valid_cell_index(index)) { | |
557 | this.get_cell_element(index).before(cell.element); |
|
557 | this.get_cell_element(index).before(cell.element); | |
558 | }; |
|
558 | }; | |
559 | cell.render(); |
|
559 | cell.render(); | |
560 | this.select(this.find_cell_index(cell)); |
|
560 | this.select(this.find_cell_index(cell)); | |
561 | this.dirty = true; |
|
561 | this.dirty = true; | |
562 | return cell; |
|
562 | return cell; | |
563 | }; |
|
563 | }; | |
564 | }; |
|
564 | }; | |
565 | return cell; |
|
565 | return cell; | |
566 | }; |
|
566 | }; | |
567 |
|
567 | |||
568 |
|
568 | |||
569 | Notebook.prototype.to_code = function (index) { |
|
569 | Notebook.prototype.to_code = function (index) { | |
570 | var i = this.index_or_selected(index); |
|
570 | var i = this.index_or_selected(index); | |
571 | if (this.is_valid_cell_index(i)) { |
|
571 | if (this.is_valid_cell_index(i)) { | |
572 | var source_element = this.get_cell_element(i); |
|
572 | var source_element = this.get_cell_element(i); | |
573 | var source_cell = source_element.data("cell"); |
|
573 | var source_cell = source_element.data("cell"); | |
574 | if (!(source_cell instanceof IPython.CodeCell)) { |
|
574 | if (!(source_cell instanceof IPython.CodeCell)) { | |
575 | target_cell = this.insert_cell_below('code',i); |
|
575 | target_cell = this.insert_cell_below('code',i); | |
576 | var text = source_cell.get_text(); |
|
576 | var text = source_cell.get_text(); | |
577 | if (text === source_cell.placeholder) { |
|
577 | if (text === source_cell.placeholder) { | |
578 | text = ''; |
|
578 | text = ''; | |
579 | } |
|
579 | } | |
580 | target_cell.set_text(text); |
|
580 | target_cell.set_text(text); | |
581 | source_element.remove(); |
|
581 | source_element.remove(); | |
582 | this.dirty = true; |
|
582 | this.dirty = true; | |
583 | }; |
|
583 | }; | |
584 | }; |
|
584 | }; | |
585 | }; |
|
585 | }; | |
586 |
|
586 | |||
587 |
|
587 | |||
588 | Notebook.prototype.to_markdown = function (index) { |
|
588 | Notebook.prototype.to_markdown = function (index) { | |
589 | var i = this.index_or_selected(index); |
|
589 | var i = this.index_or_selected(index); | |
590 | if (this.is_valid_cell_index(i)) { |
|
590 | if (this.is_valid_cell_index(i)) { | |
591 | var source_element = this.get_cell_element(i); |
|
591 | var source_element = this.get_cell_element(i); | |
592 | var source_cell = source_element.data("cell"); |
|
592 | var source_cell = source_element.data("cell"); | |
593 | if (!(source_cell instanceof IPython.MarkdownCell)) { |
|
593 | if (!(source_cell instanceof IPython.MarkdownCell)) { | |
594 | target_cell = this.insert_cell_below('markdown',i); |
|
594 | target_cell = this.insert_cell_below('markdown',i); | |
595 | var text = source_cell.get_text(); |
|
595 | var text = source_cell.get_text(); | |
596 | if (text === source_cell.placeholder) { |
|
596 | if (text === source_cell.placeholder) { | |
597 | text = ''; |
|
597 | text = ''; | |
598 | }; |
|
598 | }; | |
599 | // The edit must come before the set_text. |
|
599 | // The edit must come before the set_text. | |
600 | target_cell.edit(); |
|
600 | target_cell.edit(); | |
601 | target_cell.set_text(text); |
|
601 | target_cell.set_text(text); | |
602 | source_element.remove(); |
|
602 | source_element.remove(); | |
603 | this.dirty = true; |
|
603 | this.dirty = true; | |
604 | }; |
|
604 | }; | |
605 | }; |
|
605 | }; | |
606 | }; |
|
606 | }; | |
607 |
|
607 | |||
608 |
|
608 | |||
609 | Notebook.prototype.to_html = function (index) { |
|
609 | Notebook.prototype.to_html = function (index) { | |
610 | var i = this.index_or_selected(index); |
|
610 | var i = this.index_or_selected(index); | |
611 | if (this.is_valid_cell_index(i)) { |
|
611 | if (this.is_valid_cell_index(i)) { | |
612 | var source_element = this.get_cell_element(i); |
|
612 | var source_element = this.get_cell_element(i); | |
613 | var source_cell = source_element.data("cell"); |
|
613 | var source_cell = source_element.data("cell"); | |
614 | var target_cell = null; |
|
614 | var target_cell = null; | |
615 | if (!(source_cell instanceof IPython.HTMLCell)) { |
|
615 | if (!(source_cell instanceof IPython.HTMLCell)) { | |
616 | target_cell = this.insert_cell_below('html',i); |
|
616 | target_cell = this.insert_cell_below('html',i); | |
617 | var text = source_cell.get_text(); |
|
617 | var text = source_cell.get_text(); | |
618 | if (text === source_cell.placeholder) { |
|
618 | if (text === source_cell.placeholder) { | |
619 | text = ''; |
|
619 | text = ''; | |
620 | }; |
|
620 | }; | |
621 | // The edit must come before the set_text. |
|
621 | // The edit must come before the set_text. | |
622 | target_cell.edit(); |
|
622 | target_cell.edit(); | |
623 | target_cell.set_text(text); |
|
623 | target_cell.set_text(text); | |
624 | source_element.remove(); |
|
624 | source_element.remove(); | |
625 | this.dirty = true; |
|
625 | this.dirty = true; | |
626 | }; |
|
626 | }; | |
627 | }; |
|
627 | }; | |
628 | }; |
|
628 | }; | |
629 |
|
629 | |||
630 |
|
630 | |||
631 |
Notebook.prototype.to_ |
|
631 | Notebook.prototype.to_plaintext = function (index) { | |
632 | var i = this.index_or_selected(index); |
|
632 | var i = this.index_or_selected(index); | |
633 | if (this.is_valid_cell_index(i)) { |
|
633 | if (this.is_valid_cell_index(i)) { | |
634 | var source_element = this.get_cell_element(i); |
|
634 | var source_element = this.get_cell_element(i); | |
635 | var source_cell = source_element.data("cell"); |
|
635 | var source_cell = source_element.data("cell"); | |
636 | var target_cell = null; |
|
636 | var target_cell = null; | |
637 |
if (!(source_cell instanceof IPython. |
|
637 | if (!(source_cell instanceof IPython.PlaintextCell)) { | |
638 |
target_cell = this.insert_cell_below(' |
|
638 | target_cell = this.insert_cell_below('plaintext',i); | |
639 | var text = source_cell.get_text(); |
|
639 | var text = source_cell.get_text(); | |
640 | if (text === source_cell.placeholder) { |
|
640 | if (text === source_cell.placeholder) { | |
641 | text = ''; |
|
641 | text = ''; | |
642 | }; |
|
642 | }; | |
643 | // The edit must come before the set_text. |
|
643 | // The edit must come before the set_text. | |
644 | target_cell.edit(); |
|
644 | target_cell.edit(); | |
645 | target_cell.set_text(text); |
|
645 | target_cell.set_text(text); | |
646 | source_element.remove(); |
|
646 | source_element.remove(); | |
647 | this.dirty = true; |
|
647 | this.dirty = true; | |
648 | }; |
|
648 | }; | |
649 | }; |
|
649 | }; | |
650 | }; |
|
650 | }; | |
651 |
|
651 | |||
652 |
|
652 | |||
653 | Notebook.prototype.to_heading = function (index, level) { |
|
653 | Notebook.prototype.to_heading = function (index, level) { | |
654 | level = level || 1; |
|
654 | level = level || 1; | |
655 | var i = this.index_or_selected(index); |
|
655 | var i = this.index_or_selected(index); | |
656 | if (this.is_valid_cell_index(i)) { |
|
656 | if (this.is_valid_cell_index(i)) { | |
657 | var source_element = this.get_cell_element(i); |
|
657 | var source_element = this.get_cell_element(i); | |
658 | var source_cell = source_element.data("cell"); |
|
658 | var source_cell = source_element.data("cell"); | |
659 | var target_cell = null; |
|
659 | var target_cell = null; | |
660 | if (source_cell instanceof IPython.HeadingCell) { |
|
660 | if (source_cell instanceof IPython.HeadingCell) { | |
661 | source_cell.set_level(level); |
|
661 | source_cell.set_level(level); | |
662 | } else { |
|
662 | } else { | |
663 | target_cell = this.insert_cell_below('heading',i); |
|
663 | target_cell = this.insert_cell_below('heading',i); | |
664 | var text = source_cell.get_text(); |
|
664 | var text = source_cell.get_text(); | |
665 | if (text === source_cell.placeholder) { |
|
665 | if (text === source_cell.placeholder) { | |
666 | text = ''; |
|
666 | text = ''; | |
667 | }; |
|
667 | }; | |
668 | // The edit must come before the set_text. |
|
668 | // The edit must come before the set_text. | |
669 | target_cell.set_level(level); |
|
669 | target_cell.set_level(level); | |
670 | target_cell.edit(); |
|
670 | target_cell.edit(); | |
671 | target_cell.set_text(text); |
|
671 | target_cell.set_text(text); | |
672 | source_element.remove(); |
|
672 | source_element.remove(); | |
673 | this.dirty = true; |
|
673 | this.dirty = true; | |
674 | }; |
|
674 | }; | |
675 | }; |
|
675 | }; | |
676 | }; |
|
676 | }; | |
677 |
|
677 | |||
678 |
|
678 | |||
679 | // Cut/Copy/Paste |
|
679 | // Cut/Copy/Paste | |
680 |
|
680 | |||
681 | Notebook.prototype.enable_paste = function () { |
|
681 | Notebook.prototype.enable_paste = function () { | |
682 | var that = this; |
|
682 | var that = this; | |
683 | if (!this.paste_enabled) { |
|
683 | if (!this.paste_enabled) { | |
684 | $('#paste_cell').removeClass('ui-state-disabled') |
|
684 | $('#paste_cell').removeClass('ui-state-disabled') | |
685 | .on('click', function () {that.paste_cell();}); |
|
685 | .on('click', function () {that.paste_cell();}); | |
686 | $('#paste_cell_above').removeClass('ui-state-disabled') |
|
686 | $('#paste_cell_above').removeClass('ui-state-disabled') | |
687 | .on('click', function () {that.paste_cell_above();}); |
|
687 | .on('click', function () {that.paste_cell_above();}); | |
688 | $('#paste_cell_below').removeClass('ui-state-disabled') |
|
688 | $('#paste_cell_below').removeClass('ui-state-disabled') | |
689 | .on('click', function () {that.paste_cell_below();}); |
|
689 | .on('click', function () {that.paste_cell_below();}); | |
690 | this.paste_enabled = true; |
|
690 | this.paste_enabled = true; | |
691 | }; |
|
691 | }; | |
692 | }; |
|
692 | }; | |
693 |
|
693 | |||
694 |
|
694 | |||
695 | Notebook.prototype.disable_paste = function () { |
|
695 | Notebook.prototype.disable_paste = function () { | |
696 | if (this.paste_enabled) { |
|
696 | if (this.paste_enabled) { | |
697 | $('#paste_cell').addClass('ui-state-disabled').off('click'); |
|
697 | $('#paste_cell').addClass('ui-state-disabled').off('click'); | |
698 | $('#paste_cell_above').addClass('ui-state-disabled').off('click'); |
|
698 | $('#paste_cell_above').addClass('ui-state-disabled').off('click'); | |
699 | $('#paste_cell_below').addClass('ui-state-disabled').off('click'); |
|
699 | $('#paste_cell_below').addClass('ui-state-disabled').off('click'); | |
700 | this.paste_enabled = false; |
|
700 | this.paste_enabled = false; | |
701 | }; |
|
701 | }; | |
702 | }; |
|
702 | }; | |
703 |
|
703 | |||
704 |
|
704 | |||
705 | Notebook.prototype.cut_cell = function () { |
|
705 | Notebook.prototype.cut_cell = function () { | |
706 | this.copy_cell(); |
|
706 | this.copy_cell(); | |
707 | this.delete_cell(); |
|
707 | this.delete_cell(); | |
708 | } |
|
708 | } | |
709 |
|
709 | |||
710 | Notebook.prototype.copy_cell = function () { |
|
710 | Notebook.prototype.copy_cell = function () { | |
711 | var cell = this.get_selected_cell(); |
|
711 | var cell = this.get_selected_cell(); | |
712 | this.clipboard = cell.toJSON(); |
|
712 | this.clipboard = cell.toJSON(); | |
713 | this.enable_paste(); |
|
713 | this.enable_paste(); | |
714 | }; |
|
714 | }; | |
715 |
|
715 | |||
716 |
|
716 | |||
717 | Notebook.prototype.paste_cell = function () { |
|
717 | Notebook.prototype.paste_cell = function () { | |
718 | if (this.clipboard !== null && this.paste_enabled) { |
|
718 | if (this.clipboard !== null && this.paste_enabled) { | |
719 | var cell_data = this.clipboard; |
|
719 | var cell_data = this.clipboard; | |
720 | var new_cell = this.insert_cell_above(cell_data.cell_type); |
|
720 | var new_cell = this.insert_cell_above(cell_data.cell_type); | |
721 | new_cell.fromJSON(cell_data); |
|
721 | new_cell.fromJSON(cell_data); | |
722 | old_cell = this.get_next_cell(new_cell); |
|
722 | old_cell = this.get_next_cell(new_cell); | |
723 | this.delete_cell(this.find_cell_index(old_cell)); |
|
723 | this.delete_cell(this.find_cell_index(old_cell)); | |
724 | this.select(this.find_cell_index(new_cell)); |
|
724 | this.select(this.find_cell_index(new_cell)); | |
725 | }; |
|
725 | }; | |
726 | }; |
|
726 | }; | |
727 |
|
727 | |||
728 |
|
728 | |||
729 | Notebook.prototype.paste_cell_above = function () { |
|
729 | Notebook.prototype.paste_cell_above = function () { | |
730 | if (this.clipboard !== null && this.paste_enabled) { |
|
730 | if (this.clipboard !== null && this.paste_enabled) { | |
731 | var cell_data = this.clipboard; |
|
731 | var cell_data = this.clipboard; | |
732 | var new_cell = this.insert_cell_above(cell_data.cell_type); |
|
732 | var new_cell = this.insert_cell_above(cell_data.cell_type); | |
733 | new_cell.fromJSON(cell_data); |
|
733 | new_cell.fromJSON(cell_data); | |
734 | }; |
|
734 | }; | |
735 | }; |
|
735 | }; | |
736 |
|
736 | |||
737 |
|
737 | |||
738 | Notebook.prototype.paste_cell_below = function () { |
|
738 | Notebook.prototype.paste_cell_below = function () { | |
739 | if (this.clipboard !== null && this.paste_enabled) { |
|
739 | if (this.clipboard !== null && this.paste_enabled) { | |
740 | var cell_data = this.clipboard; |
|
740 | var cell_data = this.clipboard; | |
741 | var new_cell = this.insert_cell_below(cell_data.cell_type); |
|
741 | var new_cell = this.insert_cell_below(cell_data.cell_type); | |
742 | new_cell.fromJSON(cell_data); |
|
742 | new_cell.fromJSON(cell_data); | |
743 | }; |
|
743 | }; | |
744 | }; |
|
744 | }; | |
745 |
|
745 | |||
746 |
|
746 | |||
747 | // Split/merge |
|
747 | // Split/merge | |
748 |
|
748 | |||
749 | Notebook.prototype.split_cell = function () { |
|
749 | Notebook.prototype.split_cell = function () { | |
750 | // Todo: implement spliting for other cell types. |
|
750 | // Todo: implement spliting for other cell types. | |
751 | var cell = this.get_selected_cell(); |
|
751 | var cell = this.get_selected_cell(); | |
752 | if (cell.is_splittable()) { |
|
752 | if (cell.is_splittable()) { | |
753 | texta = cell.get_pre_cursor(); |
|
753 | texta = cell.get_pre_cursor(); | |
754 | textb = cell.get_post_cursor(); |
|
754 | textb = cell.get_post_cursor(); | |
755 | if (cell instanceof IPython.CodeCell) { |
|
755 | if (cell instanceof IPython.CodeCell) { | |
756 | cell.set_text(texta); |
|
756 | cell.set_text(texta); | |
757 | var new_cell = this.insert_cell_below('code'); |
|
757 | var new_cell = this.insert_cell_below('code'); | |
758 | new_cell.set_text(textb); |
|
758 | new_cell.set_text(textb); | |
759 | } else if (cell instanceof IPython.MarkdownCell) { |
|
759 | } else if (cell instanceof IPython.MarkdownCell) { | |
760 | cell.set_text(texta); |
|
760 | cell.set_text(texta); | |
761 | cell.render(); |
|
761 | cell.render(); | |
762 | var new_cell = this.insert_cell_below('markdown'); |
|
762 | var new_cell = this.insert_cell_below('markdown'); | |
763 | new_cell.edit(); // editor must be visible to call set_text |
|
763 | new_cell.edit(); // editor must be visible to call set_text | |
764 | new_cell.set_text(textb); |
|
764 | new_cell.set_text(textb); | |
765 | new_cell.render(); |
|
765 | new_cell.render(); | |
766 | } else if (cell instanceof IPython.HTMLCell) { |
|
766 | } else if (cell instanceof IPython.HTMLCell) { | |
767 | cell.set_text(texta); |
|
767 | cell.set_text(texta); | |
768 | cell.render(); |
|
768 | cell.render(); | |
769 | var new_cell = this.insert_cell_below('html'); |
|
769 | var new_cell = this.insert_cell_below('html'); | |
770 | new_cell.edit(); // editor must be visible to call set_text |
|
770 | new_cell.edit(); // editor must be visible to call set_text | |
771 | new_cell.set_text(textb); |
|
771 | new_cell.set_text(textb); | |
772 | new_cell.render(); |
|
772 | new_cell.render(); | |
773 | }; |
|
773 | }; | |
774 | }; |
|
774 | }; | |
775 | }; |
|
775 | }; | |
776 |
|
776 | |||
777 |
|
777 | |||
778 | Notebook.prototype.merge_cell_above = function () { |
|
778 | Notebook.prototype.merge_cell_above = function () { | |
779 | var index = this.get_selected_index(); |
|
779 | var index = this.get_selected_index(); | |
780 | var cell = this.get_cell(index); |
|
780 | var cell = this.get_cell(index); | |
781 | if (index > 0) { |
|
781 | if (index > 0) { | |
782 | upper_cell = this.get_cell(index-1); |
|
782 | upper_cell = this.get_cell(index-1); | |
783 | upper_text = upper_cell.get_text(); |
|
783 | upper_text = upper_cell.get_text(); | |
784 | text = cell.get_text(); |
|
784 | text = cell.get_text(); | |
785 | if (cell instanceof IPython.CodeCell) { |
|
785 | if (cell instanceof IPython.CodeCell) { | |
786 | cell.set_text(upper_text+'\n'+text); |
|
786 | cell.set_text(upper_text+'\n'+text); | |
787 | } else if (cell instanceof IPython.MarkdownCell || cell instanceof IPython.HTMLCell) { |
|
787 | } else if (cell instanceof IPython.MarkdownCell || cell instanceof IPython.HTMLCell) { | |
788 | cell.edit(); |
|
788 | cell.edit(); | |
789 | cell.set_text(upper_text+'\n'+text); |
|
789 | cell.set_text(upper_text+'\n'+text); | |
790 | cell.render(); |
|
790 | cell.render(); | |
791 | }; |
|
791 | }; | |
792 | this.delete_cell(index-1); |
|
792 | this.delete_cell(index-1); | |
793 | this.select(this.find_cell_index(cell)); |
|
793 | this.select(this.find_cell_index(cell)); | |
794 | }; |
|
794 | }; | |
795 | }; |
|
795 | }; | |
796 |
|
796 | |||
797 |
|
797 | |||
798 | Notebook.prototype.merge_cell_below = function () { |
|
798 | Notebook.prototype.merge_cell_below = function () { | |
799 | var index = this.get_selected_index(); |
|
799 | var index = this.get_selected_index(); | |
800 | var cell = this.get_cell(index); |
|
800 | var cell = this.get_cell(index); | |
801 | if (index < this.ncells()-1) { |
|
801 | if (index < this.ncells()-1) { | |
802 | lower_cell = this.get_cell(index+1); |
|
802 | lower_cell = this.get_cell(index+1); | |
803 | lower_text = lower_cell.get_text(); |
|
803 | lower_text = lower_cell.get_text(); | |
804 | text = cell.get_text(); |
|
804 | text = cell.get_text(); | |
805 | if (cell instanceof IPython.CodeCell) { |
|
805 | if (cell instanceof IPython.CodeCell) { | |
806 | cell.set_text(text+'\n'+lower_text); |
|
806 | cell.set_text(text+'\n'+lower_text); | |
807 | } else if (cell instanceof IPython.MarkdownCell || cell instanceof IPython.HTMLCell) { |
|
807 | } else if (cell instanceof IPython.MarkdownCell || cell instanceof IPython.HTMLCell) { | |
808 | cell.edit(); |
|
808 | cell.edit(); | |
809 | cell.set_text(text+'\n'+lower_text); |
|
809 | cell.set_text(text+'\n'+lower_text); | |
810 | cell.render(); |
|
810 | cell.render(); | |
811 | }; |
|
811 | }; | |
812 | this.delete_cell(index+1); |
|
812 | this.delete_cell(index+1); | |
813 | this.select(this.find_cell_index(cell)); |
|
813 | this.select(this.find_cell_index(cell)); | |
814 | }; |
|
814 | }; | |
815 | }; |
|
815 | }; | |
816 |
|
816 | |||
817 |
|
817 | |||
818 | // Cell collapsing and output clearing |
|
818 | // Cell collapsing and output clearing | |
819 |
|
819 | |||
820 | Notebook.prototype.collapse = function (index) { |
|
820 | Notebook.prototype.collapse = function (index) { | |
821 | var i = this.index_or_selected(index); |
|
821 | var i = this.index_or_selected(index); | |
822 | this.get_cell(i).collapse(); |
|
822 | this.get_cell(i).collapse(); | |
823 | this.dirty = true; |
|
823 | this.dirty = true; | |
824 | }; |
|
824 | }; | |
825 |
|
825 | |||
826 |
|
826 | |||
827 | Notebook.prototype.expand = function (index) { |
|
827 | Notebook.prototype.expand = function (index) { | |
828 | var i = this.index_or_selected(index); |
|
828 | var i = this.index_or_selected(index); | |
829 | this.get_cell(i).expand(); |
|
829 | this.get_cell(i).expand(); | |
830 | this.dirty = true; |
|
830 | this.dirty = true; | |
831 | }; |
|
831 | }; | |
832 |
|
832 | |||
833 |
|
833 | |||
834 | Notebook.prototype.toggle_output = function (index) { |
|
834 | Notebook.prototype.toggle_output = function (index) { | |
835 | var i = this.index_or_selected(index); |
|
835 | var i = this.index_or_selected(index); | |
836 | this.get_cell(i).toggle_output(); |
|
836 | this.get_cell(i).toggle_output(); | |
837 | this.dirty = true; |
|
837 | this.dirty = true; | |
838 | }; |
|
838 | }; | |
839 |
|
839 | |||
840 |
|
840 | |||
841 | Notebook.prototype.set_timebeforetooltip = function (time) { |
|
841 | Notebook.prototype.set_timebeforetooltip = function (time) { | |
842 | this.time_before_tooltip = time; |
|
842 | this.time_before_tooltip = time; | |
843 | }; |
|
843 | }; | |
844 |
|
844 | |||
845 |
|
845 | |||
846 | Notebook.prototype.set_tooltipontab = function (state) { |
|
846 | Notebook.prototype.set_tooltipontab = function (state) { | |
847 | this.tooltip_on_tab = state; |
|
847 | this.tooltip_on_tab = state; | |
848 | }; |
|
848 | }; | |
849 |
|
849 | |||
850 |
|
850 | |||
851 | Notebook.prototype.set_smartcompleter = function (state) { |
|
851 | Notebook.prototype.set_smartcompleter = function (state) { | |
852 | this.smart_completer = state; |
|
852 | this.smart_completer = state; | |
853 | }; |
|
853 | }; | |
854 |
|
854 | |||
855 |
|
855 | |||
856 | Notebook.prototype.clear_all_output = function () { |
|
856 | Notebook.prototype.clear_all_output = function () { | |
857 | var ncells = this.ncells(); |
|
857 | var ncells = this.ncells(); | |
858 | var cells = this.get_cells(); |
|
858 | var cells = this.get_cells(); | |
859 | for (var i=0; i<ncells; i++) { |
|
859 | for (var i=0; i<ncells; i++) { | |
860 | if (cells[i] instanceof IPython.CodeCell) { |
|
860 | if (cells[i] instanceof IPython.CodeCell) { | |
861 | cells[i].clear_output(true,true,true); |
|
861 | cells[i].clear_output(true,true,true); | |
862 | } |
|
862 | } | |
863 | }; |
|
863 | }; | |
864 | this.dirty = true; |
|
864 | this.dirty = true; | |
865 | }; |
|
865 | }; | |
866 |
|
866 | |||
867 |
|
867 | |||
868 | // Other cell functions: line numbers, ... |
|
868 | // Other cell functions: line numbers, ... | |
869 |
|
869 | |||
870 | Notebook.prototype.cell_toggle_line_numbers = function() { |
|
870 | Notebook.prototype.cell_toggle_line_numbers = function() { | |
871 | this.get_selected_cell().toggle_line_numbers(); |
|
871 | this.get_selected_cell().toggle_line_numbers(); | |
872 | }; |
|
872 | }; | |
873 |
|
873 | |||
874 | // Kernel related things |
|
874 | // Kernel related things | |
875 |
|
875 | |||
876 | Notebook.prototype.start_kernel = function () { |
|
876 | Notebook.prototype.start_kernel = function () { | |
877 | this.kernel = new IPython.Kernel(); |
|
877 | this.kernel = new IPython.Kernel(); | |
878 | var notebook_id = IPython.save_widget.get_notebook_id(); |
|
878 | var notebook_id = IPython.save_widget.get_notebook_id(); | |
879 | this.kernel.start(notebook_id, $.proxy(this.kernel_started, this)); |
|
879 | this.kernel.start(notebook_id, $.proxy(this.kernel_started, this)); | |
880 | }; |
|
880 | }; | |
881 |
|
881 | |||
882 |
|
882 | |||
883 | Notebook.prototype.restart_kernel = function () { |
|
883 | Notebook.prototype.restart_kernel = function () { | |
884 | var that = this; |
|
884 | var that = this; | |
885 | var notebook_id = IPython.save_widget.get_notebook_id(); |
|
885 | var notebook_id = IPython.save_widget.get_notebook_id(); | |
886 |
|
886 | |||
887 | var dialog = $('<div/>'); |
|
887 | var dialog = $('<div/>'); | |
888 | dialog.html('Do you want to restart the current kernel? You will lose all variables defined in it.'); |
|
888 | dialog.html('Do you want to restart the current kernel? You will lose all variables defined in it.'); | |
889 | $(document).append(dialog); |
|
889 | $(document).append(dialog); | |
890 | dialog.dialog({ |
|
890 | dialog.dialog({ | |
891 | resizable: false, |
|
891 | resizable: false, | |
892 | modal: true, |
|
892 | modal: true, | |
893 | title: "Restart kernel or continue running?", |
|
893 | title: "Restart kernel or continue running?", | |
894 | closeText: '', |
|
894 | closeText: '', | |
895 | buttons : { |
|
895 | buttons : { | |
896 | "Restart": function () { |
|
896 | "Restart": function () { | |
897 | that.kernel.restart($.proxy(that.kernel_started, that)); |
|
897 | that.kernel.restart($.proxy(that.kernel_started, that)); | |
898 | $(this).dialog('close'); |
|
898 | $(this).dialog('close'); | |
899 | }, |
|
899 | }, | |
900 | "Continue running": function () { |
|
900 | "Continue running": function () { | |
901 | $(this).dialog('close'); |
|
901 | $(this).dialog('close'); | |
902 | } |
|
902 | } | |
903 | } |
|
903 | } | |
904 | }); |
|
904 | }); | |
905 | }; |
|
905 | }; | |
906 |
|
906 | |||
907 |
|
907 | |||
908 | Notebook.prototype.kernel_started = function () { |
|
908 | Notebook.prototype.kernel_started = function () { | |
909 | console.log("Kernel started: ", this.kernel.kernel_id); |
|
909 | console.log("Kernel started: ", this.kernel.kernel_id); | |
910 | this.kernel.shell_channel.onmessage = $.proxy(this.handle_shell_reply,this); |
|
910 | this.kernel.shell_channel.onmessage = $.proxy(this.handle_shell_reply,this); | |
911 | this.kernel.iopub_channel.onmessage = $.proxy(this.handle_iopub_reply,this); |
|
911 | this.kernel.iopub_channel.onmessage = $.proxy(this.handle_iopub_reply,this); | |
912 | }; |
|
912 | }; | |
913 |
|
913 | |||
914 |
|
914 | |||
915 | Notebook.prototype.handle_shell_reply = function (e) { |
|
915 | Notebook.prototype.handle_shell_reply = function (e) { | |
916 | reply = $.parseJSON(e.data); |
|
916 | reply = $.parseJSON(e.data); | |
917 | var header = reply.header; |
|
917 | var header = reply.header; | |
918 | var content = reply.content; |
|
918 | var content = reply.content; | |
919 | var msg_type = header.msg_type; |
|
919 | var msg_type = header.msg_type; | |
920 | // console.log(reply); |
|
920 | // console.log(reply); | |
921 | var cell = this.cell_for_msg(reply.parent_header.msg_id); |
|
921 | var cell = this.cell_for_msg(reply.parent_header.msg_id); | |
922 | if (msg_type === "execute_reply") { |
|
922 | if (msg_type === "execute_reply") { | |
923 | cell.set_input_prompt(content.execution_count); |
|
923 | cell.set_input_prompt(content.execution_count); | |
924 | cell.element.removeClass("running"); |
|
924 | cell.element.removeClass("running"); | |
925 | this.dirty = true; |
|
925 | this.dirty = true; | |
926 | } else if (msg_type === "complete_reply") { |
|
926 | } else if (msg_type === "complete_reply") { | |
927 | cell.finish_completing(content.matched_text, content.matches); |
|
927 | cell.finish_completing(content.matched_text, content.matches); | |
928 | } else if (msg_type === "object_info_reply"){ |
|
928 | } else if (msg_type === "object_info_reply"){ | |
929 | //console.log('back from object_info_request : ') |
|
929 | //console.log('back from object_info_request : ') | |
930 | rep = reply.content; |
|
930 | rep = reply.content; | |
931 | if(rep.found) |
|
931 | if(rep.found) | |
932 | { |
|
932 | { | |
933 | cell.finish_tooltip(rep); |
|
933 | cell.finish_tooltip(rep); | |
934 | } |
|
934 | } | |
935 | } else { |
|
935 | } else { | |
936 | //console.log("unknown reply:"+msg_type); |
|
936 | //console.log("unknown reply:"+msg_type); | |
937 | } |
|
937 | } | |
938 | // when having a rely from object_info_reply, |
|
938 | // when having a rely from object_info_reply, | |
939 | // no payload so no nned to handle it |
|
939 | // no payload so no nned to handle it | |
940 | if(typeof(content.payload)!='undefined') { |
|
940 | if(typeof(content.payload)!='undefined') { | |
941 | var payload = content.payload || []; |
|
941 | var payload = content.payload || []; | |
942 | this.handle_payload(cell, payload); |
|
942 | this.handle_payload(cell, payload); | |
943 | } |
|
943 | } | |
944 | }; |
|
944 | }; | |
945 |
|
945 | |||
946 |
|
946 | |||
947 | Notebook.prototype.handle_payload = function (cell, payload) { |
|
947 | Notebook.prototype.handle_payload = function (cell, payload) { | |
948 | var l = payload.length; |
|
948 | var l = payload.length; | |
949 | for (var i=0; i<l; i++) { |
|
949 | for (var i=0; i<l; i++) { | |
950 | if (payload[i].source === 'IPython.zmq.page.page') { |
|
950 | if (payload[i].source === 'IPython.zmq.page.page') { | |
951 | if (payload[i].text.trim() !== '') { |
|
951 | if (payload[i].text.trim() !== '') { | |
952 | IPython.pager.clear(); |
|
952 | IPython.pager.clear(); | |
953 | IPython.pager.expand(); |
|
953 | IPython.pager.expand(); | |
954 | IPython.pager.append_text(payload[i].text); |
|
954 | IPython.pager.append_text(payload[i].text); | |
955 | } |
|
955 | } | |
956 | } else if (payload[i].source === 'IPython.zmq.zmqshell.ZMQInteractiveShell.set_next_input') { |
|
956 | } else if (payload[i].source === 'IPython.zmq.zmqshell.ZMQInteractiveShell.set_next_input') { | |
957 | var index = this.find_cell_index(cell); |
|
957 | var index = this.find_cell_index(cell); | |
958 | var new_cell = this.insert_cell_below('code',index); |
|
958 | var new_cell = this.insert_cell_below('code',index); | |
959 | new_cell.set_text(payload[i].text); |
|
959 | new_cell.set_text(payload[i].text); | |
960 | this.dirty = true; |
|
960 | this.dirty = true; | |
961 | } |
|
961 | } | |
962 | }; |
|
962 | }; | |
963 | }; |
|
963 | }; | |
964 |
|
964 | |||
965 |
|
965 | |||
966 | Notebook.prototype.handle_iopub_reply = function (e) { |
|
966 | Notebook.prototype.handle_iopub_reply = function (e) { | |
967 | reply = $.parseJSON(e.data); |
|
967 | reply = $.parseJSON(e.data); | |
968 | var content = reply.content; |
|
968 | var content = reply.content; | |
969 | // console.log(reply); |
|
969 | // console.log(reply); | |
970 | var msg_type = reply.header.msg_type; |
|
970 | var msg_type = reply.header.msg_type; | |
971 | var cell = this.cell_for_msg(reply.parent_header.msg_id); |
|
971 | var cell = this.cell_for_msg(reply.parent_header.msg_id); | |
972 | if (msg_type !== 'status' && !cell){ |
|
972 | if (msg_type !== 'status' && !cell){ | |
973 | // message not from this notebook, but should be attached to a cell |
|
973 | // message not from this notebook, but should be attached to a cell | |
974 | console.log("Received IOPub message not caused by one of my cells"); |
|
974 | console.log("Received IOPub message not caused by one of my cells"); | |
975 | console.log(reply); |
|
975 | console.log(reply); | |
976 | return; |
|
976 | return; | |
977 | } |
|
977 | } | |
978 | var output_types = ['stream','display_data','pyout','pyerr']; |
|
978 | var output_types = ['stream','display_data','pyout','pyerr']; | |
979 | if (output_types.indexOf(msg_type) >= 0) { |
|
979 | if (output_types.indexOf(msg_type) >= 0) { | |
980 | this.handle_output(cell, msg_type, content); |
|
980 | this.handle_output(cell, msg_type, content); | |
981 | } else if (msg_type === 'status') { |
|
981 | } else if (msg_type === 'status') { | |
982 | if (content.execution_state === 'busy') { |
|
982 | if (content.execution_state === 'busy') { | |
983 | IPython.kernel_status_widget.status_busy(); |
|
983 | IPython.kernel_status_widget.status_busy(); | |
984 | } else if (content.execution_state === 'idle') { |
|
984 | } else if (content.execution_state === 'idle') { | |
985 | IPython.kernel_status_widget.status_idle(); |
|
985 | IPython.kernel_status_widget.status_idle(); | |
986 | } else if (content.execution_state === 'dead') { |
|
986 | } else if (content.execution_state === 'dead') { | |
987 | this.handle_status_dead(); |
|
987 | this.handle_status_dead(); | |
988 | }; |
|
988 | }; | |
989 | } else if (msg_type === 'clear_output') { |
|
989 | } else if (msg_type === 'clear_output') { | |
990 | cell.clear_output(content.stdout, content.stderr, content.other); |
|
990 | cell.clear_output(content.stdout, content.stderr, content.other); | |
991 | }; |
|
991 | }; | |
992 | }; |
|
992 | }; | |
993 |
|
993 | |||
994 |
|
994 | |||
995 | Notebook.prototype.handle_status_dead = function () { |
|
995 | Notebook.prototype.handle_status_dead = function () { | |
996 | var that = this; |
|
996 | var that = this; | |
997 | this.kernel.stop_channels(); |
|
997 | this.kernel.stop_channels(); | |
998 | var dialog = $('<div/>'); |
|
998 | var dialog = $('<div/>'); | |
999 | dialog.html('The kernel has died, would you like to restart it? If you do not restart the kernel, you will be able to save the notebook, but running code will not work until the notebook is reopened.'); |
|
999 | dialog.html('The kernel has died, would you like to restart it? If you do not restart the kernel, you will be able to save the notebook, but running code will not work until the notebook is reopened.'); | |
1000 | $(document).append(dialog); |
|
1000 | $(document).append(dialog); | |
1001 | dialog.dialog({ |
|
1001 | dialog.dialog({ | |
1002 | resizable: false, |
|
1002 | resizable: false, | |
1003 | modal: true, |
|
1003 | modal: true, | |
1004 | title: "Dead kernel", |
|
1004 | title: "Dead kernel", | |
1005 | buttons : { |
|
1005 | buttons : { | |
1006 | "Restart": function () { |
|
1006 | "Restart": function () { | |
1007 | that.start_kernel(); |
|
1007 | that.start_kernel(); | |
1008 | $(this).dialog('close'); |
|
1008 | $(this).dialog('close'); | |
1009 | }, |
|
1009 | }, | |
1010 | "Continue running": function () { |
|
1010 | "Continue running": function () { | |
1011 | $(this).dialog('close'); |
|
1011 | $(this).dialog('close'); | |
1012 | } |
|
1012 | } | |
1013 | } |
|
1013 | } | |
1014 | }); |
|
1014 | }); | |
1015 | }; |
|
1015 | }; | |
1016 |
|
1016 | |||
1017 |
|
1017 | |||
1018 | Notebook.prototype.handle_output = function (cell, msg_type, content) { |
|
1018 | Notebook.prototype.handle_output = function (cell, msg_type, content) { | |
1019 | var json = {}; |
|
1019 | var json = {}; | |
1020 | json.output_type = msg_type; |
|
1020 | json.output_type = msg_type; | |
1021 | if (msg_type === "stream") { |
|
1021 | if (msg_type === "stream") { | |
1022 | json.text = content.data; |
|
1022 | json.text = content.data; | |
1023 | json.stream = content.name; |
|
1023 | json.stream = content.name; | |
1024 | } else if (msg_type === "display_data") { |
|
1024 | } else if (msg_type === "display_data") { | |
1025 | json = this.convert_mime_types(json, content.data); |
|
1025 | json = this.convert_mime_types(json, content.data); | |
1026 | } else if (msg_type === "pyout") { |
|
1026 | } else if (msg_type === "pyout") { | |
1027 | json.prompt_number = content.execution_count; |
|
1027 | json.prompt_number = content.execution_count; | |
1028 | json = this.convert_mime_types(json, content.data); |
|
1028 | json = this.convert_mime_types(json, content.data); | |
1029 | } else if (msg_type === "pyerr") { |
|
1029 | } else if (msg_type === "pyerr") { | |
1030 | json.ename = content.ename; |
|
1030 | json.ename = content.ename; | |
1031 | json.evalue = content.evalue; |
|
1031 | json.evalue = content.evalue; | |
1032 | json.traceback = content.traceback; |
|
1032 | json.traceback = content.traceback; | |
1033 | }; |
|
1033 | }; | |
1034 | cell.append_output(json); |
|
1034 | cell.append_output(json); | |
1035 | this.dirty = true; |
|
1035 | this.dirty = true; | |
1036 | }; |
|
1036 | }; | |
1037 |
|
1037 | |||
1038 |
|
1038 | |||
1039 | Notebook.prototype.convert_mime_types = function (json, data) { |
|
1039 | Notebook.prototype.convert_mime_types = function (json, data) { | |
1040 | if (data['text/plain'] !== undefined) { |
|
1040 | if (data['text/plain'] !== undefined) { | |
1041 | json.text = data['text/plain']; |
|
1041 | json.text = data['text/plain']; | |
1042 | }; |
|
1042 | }; | |
1043 | if (data['text/html'] !== undefined) { |
|
1043 | if (data['text/html'] !== undefined) { | |
1044 | json.html = data['text/html']; |
|
1044 | json.html = data['text/html']; | |
1045 | }; |
|
1045 | }; | |
1046 | if (data['image/svg+xml'] !== undefined) { |
|
1046 | if (data['image/svg+xml'] !== undefined) { | |
1047 | json.svg = data['image/svg+xml']; |
|
1047 | json.svg = data['image/svg+xml']; | |
1048 | }; |
|
1048 | }; | |
1049 | if (data['image/png'] !== undefined) { |
|
1049 | if (data['image/png'] !== undefined) { | |
1050 | json.png = data['image/png']; |
|
1050 | json.png = data['image/png']; | |
1051 | }; |
|
1051 | }; | |
1052 | if (data['image/jpeg'] !== undefined) { |
|
1052 | if (data['image/jpeg'] !== undefined) { | |
1053 | json.jpeg = data['image/jpeg']; |
|
1053 | json.jpeg = data['image/jpeg']; | |
1054 | }; |
|
1054 | }; | |
1055 | if (data['text/latex'] !== undefined) { |
|
1055 | if (data['text/latex'] !== undefined) { | |
1056 | json.latex = data['text/latex']; |
|
1056 | json.latex = data['text/latex']; | |
1057 | }; |
|
1057 | }; | |
1058 | if (data['application/json'] !== undefined) { |
|
1058 | if (data['application/json'] !== undefined) { | |
1059 | json.json = data['application/json']; |
|
1059 | json.json = data['application/json']; | |
1060 | }; |
|
1060 | }; | |
1061 | if (data['application/javascript'] !== undefined) { |
|
1061 | if (data['application/javascript'] !== undefined) { | |
1062 | json.javascript = data['application/javascript']; |
|
1062 | json.javascript = data['application/javascript']; | |
1063 | } |
|
1063 | } | |
1064 | return json; |
|
1064 | return json; | |
1065 | }; |
|
1065 | }; | |
1066 |
|
1066 | |||
1067 |
|
1067 | |||
1068 | Notebook.prototype.execute_selected_cell = function (options) { |
|
1068 | Notebook.prototype.execute_selected_cell = function (options) { | |
1069 | // add_new: should a new cell be added if we are at the end of the nb |
|
1069 | // add_new: should a new cell be added if we are at the end of the nb | |
1070 | // terminal: execute in terminal mode, which stays in the current cell |
|
1070 | // terminal: execute in terminal mode, which stays in the current cell | |
1071 | default_options = {terminal: false, add_new: true}; |
|
1071 | default_options = {terminal: false, add_new: true}; | |
1072 | $.extend(default_options, options); |
|
1072 | $.extend(default_options, options); | |
1073 | var that = this; |
|
1073 | var that = this; | |
1074 | var cell = that.get_selected_cell(); |
|
1074 | var cell = that.get_selected_cell(); | |
1075 | var cell_index = that.find_cell_index(cell); |
|
1075 | var cell_index = that.find_cell_index(cell); | |
1076 | if (cell instanceof IPython.CodeCell) { |
|
1076 | if (cell instanceof IPython.CodeCell) { | |
1077 | cell.clear_output(true, true, true); |
|
1077 | cell.clear_output(true, true, true); | |
1078 | cell.set_input_prompt('*'); |
|
1078 | cell.set_input_prompt('*'); | |
1079 | cell.element.addClass("running"); |
|
1079 | cell.element.addClass("running"); | |
1080 | var code = cell.get_text(); |
|
1080 | var code = cell.get_text(); | |
1081 | var msg_id = that.kernel.execute(cell.get_text()); |
|
1081 | var msg_id = that.kernel.execute(cell.get_text()); | |
1082 | that.msg_cell_map[msg_id] = cell.cell_id; |
|
1082 | that.msg_cell_map[msg_id] = cell.cell_id; | |
1083 | } else if (cell instanceof IPython.HTMLCell) { |
|
1083 | } else if (cell instanceof IPython.HTMLCell) { | |
1084 | cell.render(); |
|
1084 | cell.render(); | |
1085 | } |
|
1085 | } | |
1086 | if (default_options.terminal) { |
|
1086 | if (default_options.terminal) { | |
1087 | cell.select_all(); |
|
1087 | cell.select_all(); | |
1088 | } else { |
|
1088 | } else { | |
1089 | if ((cell_index === (that.ncells()-1)) && default_options.add_new) { |
|
1089 | if ((cell_index === (that.ncells()-1)) && default_options.add_new) { | |
1090 | that.insert_cell_below('code'); |
|
1090 | that.insert_cell_below('code'); | |
1091 | // If we are adding a new cell at the end, scroll down to show it. |
|
1091 | // If we are adding a new cell at the end, scroll down to show it. | |
1092 | that.scroll_to_bottom(); |
|
1092 | that.scroll_to_bottom(); | |
1093 | } else { |
|
1093 | } else { | |
1094 | that.select(cell_index+1); |
|
1094 | that.select(cell_index+1); | |
1095 | }; |
|
1095 | }; | |
1096 | }; |
|
1096 | }; | |
1097 | this.dirty = true; |
|
1097 | this.dirty = true; | |
1098 | }; |
|
1098 | }; | |
1099 |
|
1099 | |||
1100 |
|
1100 | |||
1101 | Notebook.prototype.execute_all_cells = function () { |
|
1101 | Notebook.prototype.execute_all_cells = function () { | |
1102 | var ncells = this.ncells(); |
|
1102 | var ncells = this.ncells(); | |
1103 | for (var i=0; i<ncells; i++) { |
|
1103 | for (var i=0; i<ncells; i++) { | |
1104 | this.select(i); |
|
1104 | this.select(i); | |
1105 | this.execute_selected_cell({add_new:false}); |
|
1105 | this.execute_selected_cell({add_new:false}); | |
1106 | }; |
|
1106 | }; | |
1107 | this.scroll_to_bottom(); |
|
1107 | this.scroll_to_bottom(); | |
1108 | }; |
|
1108 | }; | |
1109 |
|
1109 | |||
1110 |
|
1110 | |||
1111 | Notebook.prototype.request_tool_tip = function (cell,func) { |
|
1111 | Notebook.prototype.request_tool_tip = function (cell,func) { | |
1112 | // Feel free to shorten this logic if you are better |
|
1112 | // Feel free to shorten this logic if you are better | |
1113 | // than me in regEx |
|
1113 | // than me in regEx | |
1114 | // basicaly you shoul be able to get xxx.xxx.xxx from |
|
1114 | // basicaly you shoul be able to get xxx.xxx.xxx from | |
1115 | // something(range(10), kwarg=smth) ; xxx.xxx.xxx( firstarg, rand(234,23), kwarg1=2, |
|
1115 | // something(range(10), kwarg=smth) ; xxx.xxx.xxx( firstarg, rand(234,23), kwarg1=2, | |
1116 | // remove everything between matchin bracket (need to iterate) |
|
1116 | // remove everything between matchin bracket (need to iterate) | |
1117 | matchBracket = /\([^\(\)]+\)/g; |
|
1117 | matchBracket = /\([^\(\)]+\)/g; | |
1118 | oldfunc = func; |
|
1118 | oldfunc = func; | |
1119 | func = func.replace(matchBracket,""); |
|
1119 | func = func.replace(matchBracket,""); | |
1120 | while( oldfunc != func ) |
|
1120 | while( oldfunc != func ) | |
1121 | { |
|
1121 | { | |
1122 | oldfunc = func; |
|
1122 | oldfunc = func; | |
1123 | func = func.replace(matchBracket,""); |
|
1123 | func = func.replace(matchBracket,""); | |
1124 | } |
|
1124 | } | |
1125 | // remove everythin after last open bracket |
|
1125 | // remove everythin after last open bracket | |
1126 | endBracket = /\([^\(]*$/g; |
|
1126 | endBracket = /\([^\(]*$/g; | |
1127 | func = func.replace(endBracket,""); |
|
1127 | func = func.replace(endBracket,""); | |
1128 | var re = /[a-zA-Z._]+$/g; |
|
1128 | var re = /[a-zA-Z._]+$/g; | |
1129 | var msg_id = this.kernel.object_info_request(re.exec(func)); |
|
1129 | var msg_id = this.kernel.object_info_request(re.exec(func)); | |
1130 | if(typeof(msg_id)!='undefined'){ |
|
1130 | if(typeof(msg_id)!='undefined'){ | |
1131 | this.msg_cell_map[msg_id] = cell.cell_id; |
|
1131 | this.msg_cell_map[msg_id] = cell.cell_id; | |
1132 | } |
|
1132 | } | |
1133 | }; |
|
1133 | }; | |
1134 |
|
1134 | |||
1135 | Notebook.prototype.complete_cell = function (cell, line, cursor_pos) { |
|
1135 | Notebook.prototype.complete_cell = function (cell, line, cursor_pos) { | |
1136 | var msg_id = this.kernel.complete(line, cursor_pos); |
|
1136 | var msg_id = this.kernel.complete(line, cursor_pos); | |
1137 | this.msg_cell_map[msg_id] = cell.cell_id; |
|
1137 | this.msg_cell_map[msg_id] = cell.cell_id; | |
1138 | }; |
|
1138 | }; | |
1139 |
|
1139 | |||
1140 | // Persistance and loading |
|
1140 | // Persistance and loading | |
1141 |
|
1141 | |||
1142 |
|
1142 | |||
1143 | Notebook.prototype.fromJSON = function (data) { |
|
1143 | Notebook.prototype.fromJSON = function (data) { | |
1144 | var ncells = this.ncells(); |
|
1144 | var ncells = this.ncells(); | |
1145 | var i; |
|
1145 | var i; | |
1146 | for (i=0; i<ncells; i++) { |
|
1146 | for (i=0; i<ncells; i++) { | |
1147 | // Always delete cell 0 as they get renumbered as they are deleted. |
|
1147 | // Always delete cell 0 as they get renumbered as they are deleted. | |
1148 | this.delete_cell(0); |
|
1148 | this.delete_cell(0); | |
1149 | }; |
|
1149 | }; | |
1150 | // Save the metadata |
|
1150 | // Save the metadata | |
1151 | this.metadata = data.metadata; |
|
1151 | this.metadata = data.metadata; | |
1152 | // Only handle 1 worksheet for now. |
|
1152 | // Only handle 1 worksheet for now. | |
1153 | var worksheet = data.worksheets[0]; |
|
1153 | var worksheet = data.worksheets[0]; | |
1154 | if (worksheet !== undefined) { |
|
1154 | if (worksheet !== undefined) { | |
1155 | var new_cells = worksheet.cells; |
|
1155 | var new_cells = worksheet.cells; | |
1156 | ncells = new_cells.length; |
|
1156 | ncells = new_cells.length; | |
1157 | var cell_data = null; |
|
1157 | var cell_data = null; | |
1158 | var new_cell = null; |
|
1158 | var new_cell = null; | |
1159 | for (i=0; i<ncells; i++) { |
|
1159 | for (i=0; i<ncells; i++) { | |
1160 | cell_data = new_cells[i]; |
|
1160 | cell_data = new_cells[i]; | |
1161 | new_cell = this.insert_cell_below(cell_data.cell_type); |
|
1161 | new_cell = this.insert_cell_below(cell_data.cell_type); | |
1162 | new_cell.fromJSON(cell_data); |
|
1162 | new_cell.fromJSON(cell_data); | |
1163 | }; |
|
1163 | }; | |
1164 | }; |
|
1164 | }; | |
1165 | }; |
|
1165 | }; | |
1166 |
|
1166 | |||
1167 |
|
1167 | |||
1168 | Notebook.prototype.toJSON = function () { |
|
1168 | Notebook.prototype.toJSON = function () { | |
1169 | var cells = this.get_cells(); |
|
1169 | var cells = this.get_cells(); | |
1170 | var ncells = cells.length; |
|
1170 | var ncells = cells.length; | |
1171 | cell_array = new Array(ncells); |
|
1171 | cell_array = new Array(ncells); | |
1172 | for (var i=0; i<ncells; i++) { |
|
1172 | for (var i=0; i<ncells; i++) { | |
1173 | cell_array[i] = cells[i].toJSON(); |
|
1173 | cell_array[i] = cells[i].toJSON(); | |
1174 | }; |
|
1174 | }; | |
1175 | data = { |
|
1175 | data = { | |
1176 | // Only handle 1 worksheet for now. |
|
1176 | // Only handle 1 worksheet for now. | |
1177 | worksheets : [{cells:cell_array}], |
|
1177 | worksheets : [{cells:cell_array}], | |
1178 | metadata : this.metadata |
|
1178 | metadata : this.metadata | |
1179 | }; |
|
1179 | }; | |
1180 | return data; |
|
1180 | return data; | |
1181 | }; |
|
1181 | }; | |
1182 |
|
1182 | |||
1183 | Notebook.prototype.save_notebook = function () { |
|
1183 | Notebook.prototype.save_notebook = function () { | |
1184 | var notebook_id = IPython.save_widget.get_notebook_id(); |
|
1184 | var notebook_id = IPython.save_widget.get_notebook_id(); | |
1185 | var nbname = IPython.save_widget.get_notebook_name(); |
|
1185 | var nbname = IPython.save_widget.get_notebook_name(); | |
1186 | // We may want to move the name/id/nbformat logic inside toJSON? |
|
1186 | // We may want to move the name/id/nbformat logic inside toJSON? | |
1187 | var data = this.toJSON(); |
|
1187 | var data = this.toJSON(); | |
1188 | data.metadata.name = nbname; |
|
1188 | data.metadata.name = nbname; | |
1189 | data.nbformat = 2; |
|
1189 | data.nbformat = 2; | |
1190 | // We do the call with settings so we can set cache to false. |
|
1190 | // We do the call with settings so we can set cache to false. | |
1191 | var settings = { |
|
1191 | var settings = { | |
1192 | processData : false, |
|
1192 | processData : false, | |
1193 | cache : false, |
|
1193 | cache : false, | |
1194 | type : "PUT", |
|
1194 | type : "PUT", | |
1195 | data : JSON.stringify(data), |
|
1195 | data : JSON.stringify(data), | |
1196 | headers : {'Content-Type': 'application/json'}, |
|
1196 | headers : {'Content-Type': 'application/json'}, | |
1197 | success : $.proxy(this.notebook_saved,this), |
|
1197 | success : $.proxy(this.notebook_saved,this), | |
1198 | error : $.proxy(this.notebook_save_failed,this) |
|
1198 | error : $.proxy(this.notebook_save_failed,this) | |
1199 | }; |
|
1199 | }; | |
1200 | IPython.save_widget.status_saving(); |
|
1200 | IPython.save_widget.status_saving(); | |
1201 | var url = $('body').data('baseProjectUrl') + 'notebooks/' + notebook_id; |
|
1201 | var url = $('body').data('baseProjectUrl') + 'notebooks/' + notebook_id; | |
1202 | $.ajax(url, settings); |
|
1202 | $.ajax(url, settings); | |
1203 | }; |
|
1203 | }; | |
1204 |
|
1204 | |||
1205 |
|
1205 | |||
1206 | Notebook.prototype.notebook_saved = function (data, status, xhr) { |
|
1206 | Notebook.prototype.notebook_saved = function (data, status, xhr) { | |
1207 | this.dirty = false; |
|
1207 | this.dirty = false; | |
1208 | IPython.save_widget.notebook_saved(); |
|
1208 | IPython.save_widget.notebook_saved(); | |
1209 | IPython.save_widget.status_last_saved(); |
|
1209 | IPython.save_widget.status_last_saved(); | |
1210 | }; |
|
1210 | }; | |
1211 |
|
1211 | |||
1212 |
|
1212 | |||
1213 | Notebook.prototype.notebook_save_failed = function (xhr, status, error_msg) { |
|
1213 | Notebook.prototype.notebook_save_failed = function (xhr, status, error_msg) { | |
1214 | IPython.save_widget.status_save_failed(); |
|
1214 | IPython.save_widget.status_save_failed(); | |
1215 | }; |
|
1215 | }; | |
1216 |
|
1216 | |||
1217 |
|
1217 | |||
1218 | Notebook.prototype.load_notebook = function () { |
|
1218 | Notebook.prototype.load_notebook = function () { | |
1219 | var that = this; |
|
1219 | var that = this; | |
1220 | var notebook_id = IPython.save_widget.get_notebook_id(); |
|
1220 | var notebook_id = IPython.save_widget.get_notebook_id(); | |
1221 | // We do the call with settings so we can set cache to false. |
|
1221 | // We do the call with settings so we can set cache to false. | |
1222 | var settings = { |
|
1222 | var settings = { | |
1223 | processData : false, |
|
1223 | processData : false, | |
1224 | cache : false, |
|
1224 | cache : false, | |
1225 | type : "GET", |
|
1225 | type : "GET", | |
1226 | dataType : "json", |
|
1226 | dataType : "json", | |
1227 | success : function (data, status, xhr) { |
|
1227 | success : function (data, status, xhr) { | |
1228 | that.notebook_loaded(data, status, xhr); |
|
1228 | that.notebook_loaded(data, status, xhr); | |
1229 | } |
|
1229 | } | |
1230 | }; |
|
1230 | }; | |
1231 | IPython.save_widget.status_loading(); |
|
1231 | IPython.save_widget.status_loading(); | |
1232 | var url = $('body').data('baseProjectUrl') + 'notebooks/' + notebook_id; |
|
1232 | var url = $('body').data('baseProjectUrl') + 'notebooks/' + notebook_id; | |
1233 | $.ajax(url, settings); |
|
1233 | $.ajax(url, settings); | |
1234 | }; |
|
1234 | }; | |
1235 |
|
1235 | |||
1236 |
|
1236 | |||
1237 | Notebook.prototype.notebook_loaded = function (data, status, xhr) { |
|
1237 | Notebook.prototype.notebook_loaded = function (data, status, xhr) { | |
1238 | this.fromJSON(data); |
|
1238 | this.fromJSON(data); | |
1239 | if (this.ncells() === 0) { |
|
1239 | if (this.ncells() === 0) { | |
1240 | this.insert_cell_below('code'); |
|
1240 | this.insert_cell_below('code'); | |
1241 | }; |
|
1241 | }; | |
1242 | IPython.save_widget.status_last_saved(); |
|
1242 | IPython.save_widget.status_last_saved(); | |
1243 | IPython.save_widget.set_notebook_name(data.metadata.name); |
|
1243 | IPython.save_widget.set_notebook_name(data.metadata.name); | |
1244 | this.dirty = false; |
|
1244 | this.dirty = false; | |
1245 | if (! this.read_only) { |
|
1245 | if (! this.read_only) { | |
1246 | this.start_kernel(); |
|
1246 | this.start_kernel(); | |
1247 | } |
|
1247 | } | |
1248 | this.select(0); |
|
1248 | this.select(0); | |
1249 | this.scroll_to_top(); |
|
1249 | this.scroll_to_top(); | |
1250 | IPython.save_widget.update_url(); |
|
1250 | IPython.save_widget.update_url(); | |
1251 | IPython.layout_manager.do_resize(); |
|
1251 | IPython.layout_manager.do_resize(); | |
1252 | }; |
|
1252 | }; | |
1253 |
|
1253 | |||
1254 | IPython.Notebook = Notebook; |
|
1254 | IPython.Notebook = Notebook; | |
1255 |
|
1255 | |||
1256 |
|
1256 | |||
1257 | return IPython; |
|
1257 | return IPython; | |
1258 |
|
1258 | |||
1259 | }(IPython)); |
|
1259 | }(IPython)); | |
1260 |
|
1260 |
@@ -1,68 +1,69 b'' | |||||
1 | //---------------------------------------------------------------------------- |
|
1 | //---------------------------------------------------------------------------- | |
2 | // Copyright (C) 2008-2011 The IPython Development Team |
|
2 | // Copyright (C) 2008-2011 The IPython Development Team | |
3 | // |
|
3 | // | |
4 | // Distributed under the terms of the BSD License. The full license is in |
|
4 | // Distributed under the terms of the BSD License. The full license is in | |
5 | // the file COPYING, distributed as part of this software. |
|
5 | // the file COPYING, distributed as part of this software. | |
6 | //---------------------------------------------------------------------------- |
|
6 | //---------------------------------------------------------------------------- | |
7 |
|
7 | |||
8 | //============================================================================ |
|
8 | //============================================================================ | |
9 | // QuickHelp button |
|
9 | // QuickHelp button | |
10 | //============================================================================ |
|
10 | //============================================================================ | |
11 |
|
11 | |||
12 | var IPython = (function (IPython) { |
|
12 | var IPython = (function (IPython) { | |
13 |
|
13 | |||
14 | var QuickHelp = function (selector) { |
|
14 | var QuickHelp = function (selector) { | |
15 | }; |
|
15 | }; | |
16 |
|
16 | |||
17 | QuickHelp.prototype.show_keyboard_shortcuts = function () { |
|
17 | QuickHelp.prototype.show_keyboard_shortcuts = function () { | |
18 | // toggles display of keyboard shortcut dialog |
|
18 | // toggles display of keyboard shortcut dialog | |
19 | var that = this; |
|
19 | var that = this; | |
20 | if ( this.shortcut_dialog ){ |
|
20 | if ( this.shortcut_dialog ){ | |
21 | // if dialog is already shown, close it |
|
21 | // if dialog is already shown, close it | |
22 | this.shortcut_dialog.dialog("close"); |
|
22 | this.shortcut_dialog.dialog("close"); | |
23 | this.shortcut_dialog = null; |
|
23 | this.shortcut_dialog = null; | |
24 | return; |
|
24 | return; | |
25 | } |
|
25 | } | |
26 | var dialog = $('<div/>'); |
|
26 | var dialog = $('<div/>'); | |
27 | this.shortcut_dialog = dialog; |
|
27 | this.shortcut_dialog = dialog; | |
28 | var shortcuts = [ |
|
28 | var shortcuts = [ | |
29 | {key: 'Shift-Enter', help: 'run cell'}, |
|
29 | {key: 'Shift-Enter', help: 'run cell'}, | |
30 | {key: 'Ctrl-Enter', help: 'run cell in-place'}, |
|
30 | {key: 'Ctrl-Enter', help: 'run cell in-place'}, | |
31 | {key: 'Ctrl-m x', help: 'cut cell'}, |
|
31 | {key: 'Ctrl-m x', help: 'cut cell'}, | |
32 | {key: 'Ctrl-m c', help: 'copy cell'}, |
|
32 | {key: 'Ctrl-m c', help: 'copy cell'}, | |
33 | {key: 'Ctrl-m v', help: 'paste cell'}, |
|
33 | {key: 'Ctrl-m v', help: 'paste cell'}, | |
34 | {key: 'Ctrl-m d', help: 'delete cell'}, |
|
34 | {key: 'Ctrl-m d', help: 'delete cell'}, | |
35 | {key: 'Ctrl-m a', help: 'insert cell above'}, |
|
35 | {key: 'Ctrl-m a', help: 'insert cell above'}, | |
36 | {key: 'Ctrl-m b', help: 'insert cell below'}, |
|
36 | {key: 'Ctrl-m b', help: 'insert cell below'}, | |
37 |
{key: 'Ctrl-m |
|
37 | {key: 'Ctrl-m o', help: 'toggle output'}, | |
38 | {key: 'Ctrl-m l', help: 'toggle line numbers'}, |
|
38 | {key: 'Ctrl-m l', help: 'toggle line numbers'}, | |
39 | {key: 'Ctrl-m s', help: 'save notebook'}, |
|
39 | {key: 'Ctrl-m s', help: 'save notebook'}, | |
40 | {key: 'Ctrl-m j', help: 'move cell down'}, |
|
40 | {key: 'Ctrl-m j', help: 'move cell down'}, | |
41 | {key: 'Ctrl-m k', help: 'move cell up'}, |
|
41 | {key: 'Ctrl-m k', help: 'move cell up'}, | |
42 | {key: 'Ctrl-m y', help: 'code cell'}, |
|
42 | {key: 'Ctrl-m y', help: 'code cell'}, | |
43 | {key: 'Ctrl-m m', help: 'markdown cell'}, |
|
43 | {key: 'Ctrl-m m', help: 'markdown cell'}, | |
|
44 | {key: 'Ctrl-m t', help: 'plaintext cell'}, | |||
44 | {key: 'Ctrl-m p', help: 'select previous'}, |
|
45 | {key: 'Ctrl-m p', help: 'select previous'}, | |
45 | {key: 'Ctrl-m n', help: 'select next'}, |
|
46 | {key: 'Ctrl-m n', help: 'select next'}, | |
46 | {key: 'Ctrl-m i', help: 'interrupt kernel'}, |
|
47 | {key: 'Ctrl-m i', help: 'interrupt kernel'}, | |
47 | {key: 'Ctrl-m .', help: 'restart kernel'}, |
|
48 | {key: 'Ctrl-m .', help: 'restart kernel'}, | |
48 | {key: 'Ctrl-m h', help: 'show keyboard shortcuts'} |
|
49 | {key: 'Ctrl-m h', help: 'show keyboard shortcuts'} | |
49 | ]; |
|
50 | ]; | |
50 | for (var i=0; i<shortcuts.length; i++) { |
|
51 | for (var i=0; i<shortcuts.length; i++) { | |
51 | dialog.append($('<div>'). |
|
52 | dialog.append($('<div>'). | |
52 | append($('<span/>').addClass('shortcut_key').html(shortcuts[i].key)). |
|
53 | append($('<span/>').addClass('shortcut_key').html(shortcuts[i].key)). | |
53 | append($('<span/>').addClass('shortcut_descr').html(' : ' + shortcuts[i].help)) |
|
54 | append($('<span/>').addClass('shortcut_descr').html(' : ' + shortcuts[i].help)) | |
54 | ); |
|
55 | ); | |
55 | }; |
|
56 | }; | |
56 | dialog.bind('dialogclose', function(event) { |
|
57 | dialog.bind('dialogclose', function(event) { | |
57 | // dialog has been closed, allow it to be drawn again. |
|
58 | // dialog has been closed, allow it to be drawn again. | |
58 | that.shortcut_dialog = null; |
|
59 | that.shortcut_dialog = null; | |
59 | }); |
|
60 | }); | |
60 | dialog.dialog({title: 'Keyboard shortcuts', closeText: ''}); |
|
61 | dialog.dialog({title: 'Keyboard shortcuts', closeText: ''}); | |
61 | }; |
|
62 | }; | |
62 |
|
63 | |||
63 | // Set module variables |
|
64 | // Set module variables | |
64 | IPython.QuickHelp = QuickHelp; |
|
65 | IPython.QuickHelp = QuickHelp; | |
65 |
|
66 | |||
66 | return IPython; |
|
67 | return IPython; | |
67 |
|
68 | |||
68 | }(IPython)); |
|
69 | }(IPython)); |
@@ -1,351 +1,351 b'' | |||||
1 | //---------------------------------------------------------------------------- |
|
1 | //---------------------------------------------------------------------------- | |
2 | // Copyright (C) 2008-2011 The IPython Development Team |
|
2 | // Copyright (C) 2008-2011 The IPython Development Team | |
3 | // |
|
3 | // | |
4 | // Distributed under the terms of the BSD License. The full license is in |
|
4 | // Distributed under the terms of the BSD License. The full license is in | |
5 | // the file COPYING, distributed as part of this software. |
|
5 | // the file COPYING, distributed as part of this software. | |
6 | //---------------------------------------------------------------------------- |
|
6 | //---------------------------------------------------------------------------- | |
7 |
|
7 | |||
8 | //============================================================================ |
|
8 | //============================================================================ | |
9 | // TextCell |
|
9 | // TextCell | |
10 | //============================================================================ |
|
10 | //============================================================================ | |
11 |
|
11 | |||
12 | var IPython = (function (IPython) { |
|
12 | var IPython = (function (IPython) { | |
13 |
|
13 | |||
14 | // TextCell base class |
|
14 | // TextCell base class | |
15 |
|
15 | |||
16 | var TextCell = function (notebook) { |
|
16 | var TextCell = function (notebook) { | |
17 | this.code_mirror_mode = this.code_mirror_mode || 'htmlmixed'; |
|
17 | this.code_mirror_mode = this.code_mirror_mode || 'htmlmixed'; | |
18 | IPython.Cell.apply(this, arguments); |
|
18 | IPython.Cell.apply(this, arguments); | |
19 | this.rendered = false; |
|
19 | this.rendered = false; | |
20 | this.cell_type = this.cell_type || 'text'; |
|
20 | this.cell_type = this.cell_type || 'text'; | |
21 | }; |
|
21 | }; | |
22 |
|
22 | |||
23 |
|
23 | |||
24 | TextCell.prototype = new IPython.Cell(); |
|
24 | TextCell.prototype = new IPython.Cell(); | |
25 |
|
25 | |||
26 |
|
26 | |||
27 | TextCell.prototype.create_element = function () { |
|
27 | TextCell.prototype.create_element = function () { | |
28 | var cell = $("<div>").addClass('cell text_cell border-box-sizing'); |
|
28 | var cell = $("<div>").addClass('cell text_cell border-box-sizing'); | |
29 | cell.attr('tabindex','2'); |
|
29 | cell.attr('tabindex','2'); | |
30 | var input_area = $('<div/>').addClass('text_cell_input border-box-sizing'); |
|
30 | var input_area = $('<div/>').addClass('text_cell_input border-box-sizing'); | |
31 | this.code_mirror = CodeMirror(input_area.get(0), { |
|
31 | this.code_mirror = CodeMirror(input_area.get(0), { | |
32 | indentUnit : 4, |
|
32 | indentUnit : 4, | |
33 | mode: this.code_mirror_mode, |
|
33 | mode: this.code_mirror_mode, | |
34 | theme: 'default', |
|
34 | theme: 'default', | |
35 | value: this.placeholder, |
|
35 | value: this.placeholder, | |
36 | readOnly: this.read_only, |
|
36 | readOnly: this.read_only, | |
37 | lineWrapping : true, |
|
37 | lineWrapping : true, | |
38 | onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this) |
|
38 | onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this) | |
39 | }); |
|
39 | }); | |
40 | // The tabindex=-1 makes this div focusable. |
|
40 | // The tabindex=-1 makes this div focusable. | |
41 | var render_area = $('<div/>').addClass('text_cell_render border-box-sizing'). |
|
41 | var render_area = $('<div/>').addClass('text_cell_render border-box-sizing'). | |
42 | addClass('rendered_html').attr('tabindex','-1'); |
|
42 | addClass('rendered_html').attr('tabindex','-1'); | |
43 | cell.append(input_area).append(render_area); |
|
43 | cell.append(input_area).append(render_area); | |
44 | this.element = cell; |
|
44 | this.element = cell; | |
45 | }; |
|
45 | }; | |
46 |
|
46 | |||
47 |
|
47 | |||
48 | TextCell.prototype.bind_events = function () { |
|
48 | TextCell.prototype.bind_events = function () { | |
49 | IPython.Cell.prototype.bind_events.apply(this); |
|
49 | IPython.Cell.prototype.bind_events.apply(this); | |
50 | var that = this; |
|
50 | var that = this; | |
51 | this.element.keydown(function (event) { |
|
51 | this.element.keydown(function (event) { | |
52 | if (event.which === 13) { |
|
52 | if (event.which === 13) { | |
53 | if (that.rendered) { |
|
53 | if (that.rendered) { | |
54 | that.edit(); |
|
54 | that.edit(); | |
55 | return false; |
|
55 | return false; | |
56 | }; |
|
56 | }; | |
57 | }; |
|
57 | }; | |
58 | }); |
|
58 | }); | |
59 | this.element.dblclick(function () { |
|
59 | this.element.dblclick(function () { | |
60 | that.edit(); |
|
60 | that.edit(); | |
61 | }); |
|
61 | }); | |
62 | }; |
|
62 | }; | |
63 |
|
63 | |||
64 |
|
64 | |||
65 | TextCell.prototype.handle_codemirror_keyevent = function (editor, event) { |
|
65 | TextCell.prototype.handle_codemirror_keyevent = function (editor, event) { | |
66 | // This method gets called in CodeMirror's onKeyDown/onKeyPress |
|
66 | // This method gets called in CodeMirror's onKeyDown/onKeyPress | |
67 | // handlers and is used to provide custom key handling. Its return |
|
67 | // handlers and is used to provide custom key handling. Its return | |
68 | // value is used to determine if CodeMirror should ignore the event: |
|
68 | // value is used to determine if CodeMirror should ignore the event: | |
69 | // true = ignore, false = don't ignore. |
|
69 | // true = ignore, false = don't ignore. | |
70 |
|
70 | |||
71 | if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey)) { |
|
71 | if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey)) { | |
72 | // Always ignore shift-enter in CodeMirror as we handle it. |
|
72 | // Always ignore shift-enter in CodeMirror as we handle it. | |
73 | return true; |
|
73 | return true; | |
74 | } |
|
74 | } | |
75 | return false; |
|
75 | return false; | |
76 | }; |
|
76 | }; | |
77 |
|
77 | |||
78 |
|
78 | |||
79 | TextCell.prototype.select = function () { |
|
79 | TextCell.prototype.select = function () { | |
80 | IPython.Cell.prototype.select.apply(this); |
|
80 | IPython.Cell.prototype.select.apply(this); | |
81 | var output = this.element.find("div.text_cell_render"); |
|
81 | var output = this.element.find("div.text_cell_render"); | |
82 | output.trigger('focus'); |
|
82 | output.trigger('focus'); | |
83 | }; |
|
83 | }; | |
84 |
|
84 | |||
85 |
|
85 | |||
86 | TextCell.prototype.unselect = function() { |
|
86 | TextCell.prototype.unselect = function() { | |
87 | // render on selection of another cell |
|
87 | // render on selection of another cell | |
88 | this.render(); |
|
88 | this.render(); | |
89 | IPython.Cell.prototype.unselect.apply(this); |
|
89 | IPython.Cell.prototype.unselect.apply(this); | |
90 | }; |
|
90 | }; | |
91 |
|
91 | |||
92 |
|
92 | |||
93 | TextCell.prototype.edit = function () { |
|
93 | TextCell.prototype.edit = function () { | |
94 | if ( this.read_only ) return; |
|
94 | if ( this.read_only ) return; | |
95 | if (this.rendered === true) { |
|
95 | if (this.rendered === true) { | |
96 | var text_cell = this.element; |
|
96 | var text_cell = this.element; | |
97 | var output = text_cell.find("div.text_cell_render"); |
|
97 | var output = text_cell.find("div.text_cell_render"); | |
98 | output.hide(); |
|
98 | output.hide(); | |
99 | text_cell.find('div.text_cell_input').show(); |
|
99 | text_cell.find('div.text_cell_input').show(); | |
100 | this.code_mirror.refresh(); |
|
100 | this.code_mirror.refresh(); | |
101 | this.code_mirror.focus(); |
|
101 | this.code_mirror.focus(); | |
102 | // We used to need an additional refresh() after the focus, but |
|
102 | // We used to need an additional refresh() after the focus, but | |
103 | // it appears that this has been fixed in CM. This bug would show |
|
103 | // it appears that this has been fixed in CM. This bug would show | |
104 | // up on FF when a newly loaded markdown cell was edited. |
|
104 | // up on FF when a newly loaded markdown cell was edited. | |
105 | this.rendered = false; |
|
105 | this.rendered = false; | |
106 | if (this.get_text() === this.placeholder) { |
|
106 | if (this.get_text() === this.placeholder) { | |
107 | this.set_text(''); |
|
107 | this.set_text(''); | |
108 | this.refresh(); |
|
108 | this.refresh(); | |
109 | } |
|
109 | } | |
110 | } |
|
110 | } | |
111 | }; |
|
111 | }; | |
112 |
|
112 | |||
113 |
|
113 | |||
114 | // Subclasses must define render. |
|
114 | // Subclasses must define render. | |
115 | TextCell.prototype.render = function () {}; |
|
115 | TextCell.prototype.render = function () {}; | |
116 |
|
116 | |||
117 |
|
117 | |||
118 | TextCell.prototype.get_text = function() { |
|
118 | TextCell.prototype.get_text = function() { | |
119 | return this.code_mirror.getValue(); |
|
119 | return this.code_mirror.getValue(); | |
120 | }; |
|
120 | }; | |
121 |
|
121 | |||
122 |
|
122 | |||
123 | TextCell.prototype.set_text = function(text) { |
|
123 | TextCell.prototype.set_text = function(text) { | |
124 | this.code_mirror.setValue(text); |
|
124 | this.code_mirror.setValue(text); | |
125 | this.code_mirror.refresh(); |
|
125 | this.code_mirror.refresh(); | |
126 | }; |
|
126 | }; | |
127 |
|
127 | |||
128 |
|
128 | |||
129 | TextCell.prototype.get_rendered = function() { |
|
129 | TextCell.prototype.get_rendered = function() { | |
130 | return this.element.find('div.text_cell_render').html(); |
|
130 | return this.element.find('div.text_cell_render').html(); | |
131 | }; |
|
131 | }; | |
132 |
|
132 | |||
133 |
|
133 | |||
134 | TextCell.prototype.set_rendered = function(text) { |
|
134 | TextCell.prototype.set_rendered = function(text) { | |
135 | this.element.find('div.text_cell_render').html(text); |
|
135 | this.element.find('div.text_cell_render').html(text); | |
136 | }; |
|
136 | }; | |
137 |
|
137 | |||
138 |
|
138 | |||
139 | TextCell.prototype.at_top = function () { |
|
139 | TextCell.prototype.at_top = function () { | |
140 | if (this.rendered) { |
|
140 | if (this.rendered) { | |
141 | return true; |
|
141 | return true; | |
142 | } else { |
|
142 | } else { | |
143 | return false; |
|
143 | return false; | |
144 | } |
|
144 | } | |
145 | }; |
|
145 | }; | |
146 |
|
146 | |||
147 |
|
147 | |||
148 | TextCell.prototype.at_bottom = function () { |
|
148 | TextCell.prototype.at_bottom = function () { | |
149 | if (this.rendered) { |
|
149 | if (this.rendered) { | |
150 | return true; |
|
150 | return true; | |
151 | } else { |
|
151 | } else { | |
152 | return false; |
|
152 | return false; | |
153 | } |
|
153 | } | |
154 | }; |
|
154 | }; | |
155 |
|
155 | |||
156 |
|
156 | |||
157 | TextCell.prototype.fromJSON = function (data) { |
|
157 | TextCell.prototype.fromJSON = function (data) { | |
158 | if (data.cell_type === this.cell_type) { |
|
158 | if (data.cell_type === this.cell_type) { | |
159 | if (data.source !== undefined) { |
|
159 | if (data.source !== undefined) { | |
160 | this.set_text(data.source); |
|
160 | this.set_text(data.source); | |
161 | this.set_rendered(data.rendered || ''); |
|
161 | this.set_rendered(data.rendered || ''); | |
162 | this.rendered = false; |
|
162 | this.rendered = false; | |
163 | this.render(); |
|
163 | this.render(); | |
164 | } |
|
164 | } | |
165 | } |
|
165 | } | |
166 | }; |
|
166 | }; | |
167 |
|
167 | |||
168 |
|
168 | |||
169 | TextCell.prototype.toJSON = function () { |
|
169 | TextCell.prototype.toJSON = function () { | |
170 | var data = {}; |
|
170 | var data = {}; | |
171 | data.cell_type = this.cell_type; |
|
171 | data.cell_type = this.cell_type; | |
172 | data.source = this.get_text(); |
|
172 | data.source = this.get_text(); | |
173 | return data; |
|
173 | return data; | |
174 | }; |
|
174 | }; | |
175 |
|
175 | |||
176 |
|
176 | |||
177 | // HTMLCell |
|
177 | // HTMLCell | |
178 |
|
178 | |||
179 | var HTMLCell = function (notebook) { |
|
179 | var HTMLCell = function (notebook) { | |
180 | this.placeholder = "Type <strong>HTML</strong> and LaTeX: $\\alpha^2$"; |
|
180 | this.placeholder = "Type <strong>HTML</strong> and LaTeX: $\\alpha^2$"; | |
181 | IPython.TextCell.apply(this, arguments); |
|
181 | IPython.TextCell.apply(this, arguments); | |
182 | this.cell_type = 'html'; |
|
182 | this.cell_type = 'html'; | |
183 | }; |
|
183 | }; | |
184 |
|
184 | |||
185 |
|
185 | |||
186 | HTMLCell.prototype = new TextCell(); |
|
186 | HTMLCell.prototype = new TextCell(); | |
187 |
|
187 | |||
188 |
|
188 | |||
189 | HTMLCell.prototype.render = function () { |
|
189 | HTMLCell.prototype.render = function () { | |
190 | if (this.rendered === false) { |
|
190 | if (this.rendered === false) { | |
191 | var text = this.get_text(); |
|
191 | var text = this.get_text(); | |
192 | if (text === "") { text = this.placeholder; } |
|
192 | if (text === "") { text = this.placeholder; } | |
193 | this.set_rendered(text); |
|
193 | this.set_rendered(text); | |
194 | this.typeset(); |
|
194 | this.typeset(); | |
195 | this.element.find('div.text_cell_input').hide(); |
|
195 | this.element.find('div.text_cell_input').hide(); | |
196 | this.element.find("div.text_cell_render").show(); |
|
196 | this.element.find("div.text_cell_render").show(); | |
197 | this.rendered = true; |
|
197 | this.rendered = true; | |
198 | } |
|
198 | } | |
199 | }; |
|
199 | }; | |
200 |
|
200 | |||
201 |
|
201 | |||
202 | // MarkdownCell |
|
202 | // MarkdownCell | |
203 |
|
203 | |||
204 | var MarkdownCell = function (notebook) { |
|
204 | var MarkdownCell = function (notebook) { | |
205 | this.placeholder = "Type *Markdown* and LaTeX: $\\alpha^2$"; |
|
205 | this.placeholder = "Type *Markdown* and LaTeX: $\\alpha^2$"; | |
206 | IPython.TextCell.apply(this, arguments); |
|
206 | IPython.TextCell.apply(this, arguments); | |
207 | this.cell_type = 'markdown'; |
|
207 | this.cell_type = 'markdown'; | |
208 | }; |
|
208 | }; | |
209 |
|
209 | |||
210 |
|
210 | |||
211 | MarkdownCell.prototype = new TextCell(); |
|
211 | MarkdownCell.prototype = new TextCell(); | |
212 |
|
212 | |||
213 |
|
213 | |||
214 | MarkdownCell.prototype.render = function () { |
|
214 | MarkdownCell.prototype.render = function () { | |
215 | if (this.rendered === false) { |
|
215 | if (this.rendered === false) { | |
216 | var text = this.get_text(); |
|
216 | var text = this.get_text(); | |
217 | if (text === "") { text = this.placeholder; } |
|
217 | if (text === "") { text = this.placeholder; } | |
218 | var html = IPython.markdown_converter.makeHtml(text); |
|
218 | var html = IPython.markdown_converter.makeHtml(text); | |
219 | this.set_rendered(html); |
|
219 | this.set_rendered(html); | |
220 | this.typeset() |
|
220 | this.typeset() | |
221 | this.element.find('div.text_cell_input').hide(); |
|
221 | this.element.find('div.text_cell_input').hide(); | |
222 | this.element.find("div.text_cell_render").show(); |
|
222 | this.element.find("div.text_cell_render").show(); | |
223 | var code_snippets = this.element.find("pre > code"); |
|
223 | var code_snippets = this.element.find("pre > code"); | |
224 | code_snippets.replaceWith(function () { |
|
224 | code_snippets.replaceWith(function () { | |
225 | var code = $(this).html(); |
|
225 | var code = $(this).html(); | |
226 | /* Substitute br for newlines and for spaces |
|
226 | /* Substitute br for newlines and for spaces | |
227 | before highlighting, since prettify doesn't |
|
227 | before highlighting, since prettify doesn't | |
228 | preserve those on all browsers */ |
|
228 | preserve those on all browsers */ | |
229 | code = code.replace(/(\r\n|\n|\r)/gm, "<br/>"); |
|
229 | code = code.replace(/(\r\n|\n|\r)/gm, "<br/>"); | |
230 | code = code.replace(/ /gm, ' '); |
|
230 | code = code.replace(/ /gm, ' '); | |
231 | code = prettyPrintOne(code); |
|
231 | code = prettyPrintOne(code); | |
232 |
|
232 | |||
233 | return '<code class="prettyprint">' + code + '</code>'; |
|
233 | return '<code class="prettyprint">' + code + '</code>'; | |
234 | }); |
|
234 | }); | |
235 | this.rendered = true; |
|
235 | this.rendered = true; | |
236 | } |
|
236 | } | |
237 | }; |
|
237 | }; | |
238 |
|
238 | |||
239 |
|
239 | |||
240 |
// |
|
240 | // PlaintextCell | |
241 |
|
241 | |||
242 |
var |
|
242 | var PlaintextCell = function (notebook) { | |
243 |
this.placeholder = "Type |
|
243 | this.placeholder = "Type plain text and LaTeX: $\\alpha^2$"; | |
244 | this.code_mirror_mode = 'rst'; |
|
244 | this.code_mirror_mode = 'rst'; | |
245 | IPython.TextCell.apply(this, arguments); |
|
245 | IPython.TextCell.apply(this, arguments); | |
246 |
this.cell_type = ' |
|
246 | this.cell_type = 'plaintext'; | |
247 | }; |
|
247 | }; | |
248 |
|
248 | |||
249 |
|
249 | |||
250 |
|
|
250 | PlaintextCell.prototype = new TextCell(); | |
251 |
|
251 | |||
252 |
|
252 | |||
253 |
|
|
253 | PlaintextCell.prototype.render = function () { | |
254 | this.rendered = true; |
|
254 | this.rendered = true; | |
255 | this.edit(); |
|
255 | this.edit(); | |
256 | }; |
|
256 | }; | |
257 |
|
257 | |||
258 |
|
258 | |||
259 |
|
|
259 | PlaintextCell.prototype.select = function () { | |
260 | IPython.Cell.prototype.select.apply(this); |
|
260 | IPython.Cell.prototype.select.apply(this); | |
261 | // In some cases (inserting a new cell) we need a refresh before and |
|
261 | // In some cases (inserting a new cell) we need a refresh before and | |
262 | // after the focus. Not sure why this is the case. |
|
262 | // after the focus. Not sure why this is the case. | |
263 | this.code_mirror.refresh(); |
|
263 | this.code_mirror.refresh(); | |
264 | this.code_mirror.focus(); |
|
264 | this.code_mirror.focus(); | |
265 | this.code_mirror.refresh(); |
|
265 | this.code_mirror.refresh(); | |
266 | }; |
|
266 | }; | |
267 |
|
267 | |||
268 |
|
268 | |||
269 |
|
|
269 | PlaintextCell.prototype.at_top = function () { | |
270 | var cursor = this.code_mirror.getCursor(); |
|
270 | var cursor = this.code_mirror.getCursor(); | |
271 | if (cursor.line === 0) { |
|
271 | if (cursor.line === 0) { | |
272 | return true; |
|
272 | return true; | |
273 | } else { |
|
273 | } else { | |
274 | return false; |
|
274 | return false; | |
275 | } |
|
275 | } | |
276 | }; |
|
276 | }; | |
277 |
|
277 | |||
278 |
|
278 | |||
279 |
|
|
279 | PlaintextCell.prototype.at_bottom = function () { | |
280 | var cursor = this.code_mirror.getCursor(); |
|
280 | var cursor = this.code_mirror.getCursor(); | |
281 | if (cursor.line === (this.code_mirror.lineCount()-1)) { |
|
281 | if (cursor.line === (this.code_mirror.lineCount()-1)) { | |
282 | return true; |
|
282 | return true; | |
283 | } else { |
|
283 | } else { | |
284 | return false; |
|
284 | return false; | |
285 | } |
|
285 | } | |
286 | }; |
|
286 | }; | |
287 |
|
287 | |||
288 |
|
288 | |||
289 | // HTMLCell |
|
289 | // HTMLCell | |
290 |
|
290 | |||
291 | var HeadingCell = function (notebook) { |
|
291 | var HeadingCell = function (notebook) { | |
292 | this.placeholder = "Type Heading Here"; |
|
292 | this.placeholder = "Type Heading Here"; | |
293 | IPython.TextCell.apply(this, arguments); |
|
293 | IPython.TextCell.apply(this, arguments); | |
294 | this.cell_type = 'heading'; |
|
294 | this.cell_type = 'heading'; | |
295 | this.level = 1; |
|
295 | this.level = 1; | |
296 | }; |
|
296 | }; | |
297 |
|
297 | |||
298 |
|
298 | |||
299 | HeadingCell.prototype = new TextCell(); |
|
299 | HeadingCell.prototype = new TextCell(); | |
300 |
|
300 | |||
301 |
|
301 | |||
302 | HeadingCell.prototype.set_level = function (level) { |
|
302 | HeadingCell.prototype.set_level = function (level) { | |
303 | this.level = level; |
|
303 | this.level = level; | |
304 | if (this.rendered) { |
|
304 | if (this.rendered) { | |
305 | this.rendered = false; |
|
305 | this.rendered = false; | |
306 | this.render(); |
|
306 | this.render(); | |
307 | }; |
|
307 | }; | |
308 | }; |
|
308 | }; | |
309 |
|
309 | |||
310 |
|
310 | |||
311 | HeadingCell.prototype.get_level = function () { |
|
311 | HeadingCell.prototype.get_level = function () { | |
312 | return this.level; |
|
312 | return this.level; | |
313 | }; |
|
313 | }; | |
314 |
|
314 | |||
315 |
|
315 | |||
316 | HeadingCell.prototype.set_rendered = function (text) { |
|
316 | HeadingCell.prototype.set_rendered = function (text) { | |
317 | var r = this.element.find("div.text_cell_render"); |
|
317 | var r = this.element.find("div.text_cell_render"); | |
318 | r.empty(); |
|
318 | r.empty(); | |
319 | r.append($('<h'+this.level+'/>').html(text)); |
|
319 | r.append($('<h'+this.level+'/>').html(text)); | |
320 | }; |
|
320 | }; | |
321 |
|
321 | |||
322 |
|
322 | |||
323 | HeadingCell.prototype.get_rendered = function () { |
|
323 | HeadingCell.prototype.get_rendered = function () { | |
324 | var r = this.element.find("div.text_cell_render"); |
|
324 | var r = this.element.find("div.text_cell_render"); | |
325 | return r.children().first().html(); |
|
325 | return r.children().first().html(); | |
326 | }; |
|
326 | }; | |
327 |
|
327 | |||
328 |
|
328 | |||
329 | HeadingCell.prototype.render = function () { |
|
329 | HeadingCell.prototype.render = function () { | |
330 | if (this.rendered === false) { |
|
330 | if (this.rendered === false) { | |
331 | var text = this.get_text(); |
|
331 | var text = this.get_text(); | |
332 | if (text === "") { text = this.placeholder; } |
|
332 | if (text === "") { text = this.placeholder; } | |
333 | this.set_rendered(text); |
|
333 | this.set_rendered(text); | |
334 | this.typeset(); |
|
334 | this.typeset(); | |
335 | this.element.find('div.text_cell_input').hide(); |
|
335 | this.element.find('div.text_cell_input').hide(); | |
336 | this.element.find("div.text_cell_render").show(); |
|
336 | this.element.find("div.text_cell_render").show(); | |
337 | this.rendered = true; |
|
337 | this.rendered = true; | |
338 | }; |
|
338 | }; | |
339 | }; |
|
339 | }; | |
340 |
|
340 | |||
341 | IPython.TextCell = TextCell; |
|
341 | IPython.TextCell = TextCell; | |
342 | IPython.HTMLCell = HTMLCell; |
|
342 | IPython.HTMLCell = HTMLCell; | |
343 | IPython.MarkdownCell = MarkdownCell; |
|
343 | IPython.MarkdownCell = MarkdownCell; | |
344 |
IPython. |
|
344 | IPython.PlaintextCell = PlaintextCell; | |
345 | IPython.HeadingCell = HeadingCell; |
|
345 | IPython.HeadingCell = HeadingCell; | |
346 |
|
346 | |||
347 |
|
347 | |||
348 | return IPython; |
|
348 | return IPython; | |
349 |
|
349 | |||
350 | }(IPython)); |
|
350 | }(IPython)); | |
351 |
|
351 |
@@ -1,234 +1,234 b'' | |||||
1 | <!DOCTYPE HTML> |
|
1 | <!DOCTYPE HTML> | |
2 | <html> |
|
2 | <html> | |
3 |
|
3 | |||
4 | <head> |
|
4 | <head> | |
5 | <meta charset="utf-8"> |
|
5 | <meta charset="utf-8"> | |
6 |
|
6 | |||
7 | <title>IPython Notebook</title> |
|
7 | <title>IPython Notebook</title> | |
8 |
|
8 | |||
9 | {% if mathjax_url %} |
|
9 | {% if mathjax_url %} | |
10 | <script type="text/javascript" src="{{mathjax_url}}?config=TeX-AMS_HTML" charset="utf-8"></script> |
|
10 | <script type="text/javascript" src="{{mathjax_url}}?config=TeX-AMS_HTML" charset="utf-8"></script> | |
11 | {% end %} |
|
11 | {% end %} | |
12 | <script type="text/javascript"> |
|
12 | <script type="text/javascript"> | |
13 | // MathJax disabled, set as null to distingish from *missing* MathJax, |
|
13 | // MathJax disabled, set as null to distingish from *missing* MathJax, | |
14 | // where it will be undefined, and should prompt a dialog later. |
|
14 | // where it will be undefined, and should prompt a dialog later. | |
15 | window.mathjax_url = "{{mathjax_url}}"; |
|
15 | window.mathjax_url = "{{mathjax_url}}"; | |
16 | </script> |
|
16 | </script> | |
17 |
|
17 | |||
18 | <link rel="stylesheet" href="{{ static_url("jquery/css/themes/base/jquery-ui.min.css") }}" type="text/css" /> |
|
18 | <link rel="stylesheet" href="{{ static_url("jquery/css/themes/base/jquery-ui.min.css") }}" type="text/css" /> | |
19 | <link rel="stylesheet" href="{{ static_url("codemirror/lib/codemirror.css") }}"> |
|
19 | <link rel="stylesheet" href="{{ static_url("codemirror/lib/codemirror.css") }}"> | |
20 | <link rel="stylesheet" href="{{ static_url("codemirror/theme/ipython.css") }}"> |
|
20 | <link rel="stylesheet" href="{{ static_url("codemirror/theme/ipython.css") }}"> | |
21 |
|
21 | |||
22 | <link rel="stylesheet" href="{{ static_url("prettify/prettify.css") }}"/> |
|
22 | <link rel="stylesheet" href="{{ static_url("prettify/prettify.css") }}"/> | |
23 |
|
23 | |||
24 | <link rel="stylesheet" href="{{ static_url("css/boilerplate.css") }}" type="text/css" /> |
|
24 | <link rel="stylesheet" href="{{ static_url("css/boilerplate.css") }}" type="text/css" /> | |
25 | <link rel="stylesheet" href="{{ static_url("css/layout.css") }}" type="text/css" /> |
|
25 | <link rel="stylesheet" href="{{ static_url("css/layout.css") }}" type="text/css" /> | |
26 | <link rel="stylesheet" href="{{ static_url("css/base.css") }}" type="text/css" /> |
|
26 | <link rel="stylesheet" href="{{ static_url("css/base.css") }}" type="text/css" /> | |
27 | <link rel="stylesheet" href="{{ static_url("css/notebook.css") }}" type="text/css" /> |
|
27 | <link rel="stylesheet" href="{{ static_url("css/notebook.css") }}" type="text/css" /> | |
28 | <link rel="stylesheet" href="{{ static_url("css/renderedhtml.css") }}" type="text/css" /> |
|
28 | <link rel="stylesheet" href="{{ static_url("css/renderedhtml.css") }}" type="text/css" /> | |
29 |
|
29 | |||
30 | {% comment In the notebook, the read-only flag is used to determine %} |
|
30 | {% comment In the notebook, the read-only flag is used to determine %} | |
31 | {% comment whether to hide the side panels and switch off input %} |
|
31 | {% comment whether to hide the side panels and switch off input %} | |
32 | <meta name="read_only" content="{{read_only and not logged_in}}"/> |
|
32 | <meta name="read_only" content="{{read_only and not logged_in}}"/> | |
33 |
|
33 | |||
34 | </head> |
|
34 | </head> | |
35 |
|
35 | |||
36 | <body |
|
36 | <body | |
37 | data-project={{project}} data-notebook-id={{notebook_id}} |
|
37 | data-project={{project}} data-notebook-id={{notebook_id}} | |
38 | data-base-project-url={{base_project_url}} data-base-kernel-url={{base_kernel_url}} |
|
38 | data-base-project-url={{base_project_url}} data-base-kernel-url={{base_kernel_url}} | |
39 | > |
|
39 | > | |
40 |
|
40 | |||
41 | <div id="header"> |
|
41 | <div id="header"> | |
42 | <span id="ipython_notebook"><h1><a href='..' alt='dashboard'><img src='{{static_url("ipynblogo.png")}}' alt='IPython Notebook'/></a></h1></span> |
|
42 | <span id="ipython_notebook"><h1><a href='..' alt='dashboard'><img src='{{static_url("ipynblogo.png")}}' alt='IPython Notebook'/></a></h1></span> | |
43 | <span id="save_widget"> |
|
43 | <span id="save_widget"> | |
44 | <span id="notebook_name"></span> |
|
44 | <span id="notebook_name"></span> | |
45 | <span id="save_status"></span> |
|
45 | <span id="save_status"></span> | |
46 | </span> |
|
46 | </span> | |
47 |
|
47 | |||
48 | <span id="login_widget"> |
|
48 | <span id="login_widget"> | |
49 | {% comment This is a temporary workaround to hide the logout button %} |
|
49 | {% comment This is a temporary workaround to hide the logout button %} | |
50 | {% comment when appropriate until notebook.html is templated %} |
|
50 | {% comment when appropriate until notebook.html is templated %} | |
51 | {% if logged_in %} |
|
51 | {% if logged_in %} | |
52 | <button id="logout">Logout</button> |
|
52 | <button id="logout">Logout</button> | |
53 | {% elif not logged_in and login_available %} |
|
53 | {% elif not logged_in and login_available %} | |
54 | <button id="login">Login</button> |
|
54 | <button id="login">Login</button> | |
55 | {% end %} |
|
55 | {% end %} | |
56 | </span> |
|
56 | </span> | |
57 |
|
57 | |||
58 | <span id="kernel_status">Idle</span> |
|
58 | <span id="kernel_status">Idle</span> | |
59 | </div> |
|
59 | </div> | |
60 |
|
60 | |||
61 | <div id="menubar"> |
|
61 | <div id="menubar"> | |
62 | <ul id="menus"> |
|
62 | <ul id="menus"> | |
63 | <li><a href="#">File</a> |
|
63 | <li><a href="#">File</a> | |
64 | <ul> |
|
64 | <ul> | |
65 | <li id="new_notebook"><a href="#">New</a></li> |
|
65 | <li id="new_notebook"><a href="#">New</a></li> | |
66 | <li id="open_notebook"><a href="#">Open...</a></li> |
|
66 | <li id="open_notebook"><a href="#">Open...</a></li> | |
67 | <hr/> |
|
67 | <hr/> | |
68 | <li id="copy_notebook"><a href="#">Make a Copy...</a></li> |
|
68 | <li id="copy_notebook"><a href="#">Make a Copy...</a></li> | |
69 | <li id="rename_notebook"><a href="#">Rename...</a></li> |
|
69 | <li id="rename_notebook"><a href="#">Rename...</a></li> | |
70 | <li id="save_notebook"><a href="#">Save</a></li> |
|
70 | <li id="save_notebook"><a href="#">Save</a></li> | |
71 | <hr/> |
|
71 | <hr/> | |
72 | <li><a href="#">Download as</a> |
|
72 | <li><a href="#">Download as</a> | |
73 | <ul> |
|
73 | <ul> | |
74 | <li id="download_ipynb"><a href="#">IPython (.ipynb)</a></li> |
|
74 | <li id="download_ipynb"><a href="#">IPython (.ipynb)</a></li> | |
75 | <li id="download_py"><a href="#">Python (.py)</a></li> |
|
75 | <li id="download_py"><a href="#">Python (.py)</a></li> | |
76 | </ul> |
|
76 | </ul> | |
77 | </li> |
|
77 | </li> | |
78 | <hr/> |
|
78 | <hr/> | |
79 | <li id="print_notebook"><a href="/{{notebook_id}}/print" target="_blank">Print View</a></li> |
|
79 | <li id="print_notebook"><a href="/{{notebook_id}}/print" target="_blank">Print View</a></li> | |
80 | </ul> |
|
80 | </ul> | |
81 | </li> |
|
81 | </li> | |
82 | <li><a href="#">Edit</a> |
|
82 | <li><a href="#">Edit</a> | |
83 | <ul> |
|
83 | <ul> | |
84 | <li id="cut_cell"><a href="#">Cut Cell</a></li> |
|
84 | <li id="cut_cell"><a href="#">Cut Cell</a></li> | |
85 | <li id="copy_cell"><a href="#">Copy Cell</a></li> |
|
85 | <li id="copy_cell"><a href="#">Copy Cell</a></li> | |
86 | <li id="paste_cell" class="ui-state-disabled"><a href="#">Paste Cell</a></li> |
|
86 | <li id="paste_cell" class="ui-state-disabled"><a href="#">Paste Cell</a></li> | |
87 | <li id="paste_cell_above" class="ui-state-disabled"><a href="#">Paste Cell Above</a></li> |
|
87 | <li id="paste_cell_above" class="ui-state-disabled"><a href="#">Paste Cell Above</a></li> | |
88 | <li id="paste_cell_below" class="ui-state-disabled"><a href="#">Paste Cell Below</a></li> |
|
88 | <li id="paste_cell_below" class="ui-state-disabled"><a href="#">Paste Cell Below</a></li> | |
89 | <li id="delete_cell"><a href="#">Delete</a></li> |
|
89 | <li id="delete_cell"><a href="#">Delete</a></li> | |
90 | <hr/> |
|
90 | <hr/> | |
91 | <li id="split_cell"><a href="#">Split Cell</a></li> |
|
91 | <li id="split_cell"><a href="#">Split Cell</a></li> | |
92 | <li id="merge_cell_above"><a href="#">Merge Cell Above</a></li> |
|
92 | <li id="merge_cell_above"><a href="#">Merge Cell Above</a></li> | |
93 | <li id="merge_cell_below"><a href="#">Merge Cell Below</a></li> |
|
93 | <li id="merge_cell_below"><a href="#">Merge Cell Below</a></li> | |
94 | <hr/> |
|
94 | <hr/> | |
95 | <li id="move_cell_up"><a href="#">Move Cell Up</a></li> |
|
95 | <li id="move_cell_up"><a href="#">Move Cell Up</a></li> | |
96 | <li id="move_cell_down"><a href="#">Move Cell Down</a></li> |
|
96 | <li id="move_cell_down"><a href="#">Move Cell Down</a></li> | |
97 | <hr/> |
|
97 | <hr/> | |
98 | <li id="select_previous"><a href="#">Select Previous Cell</a></li> |
|
98 | <li id="select_previous"><a href="#">Select Previous Cell</a></li> | |
99 | <li id="select_next"><a href="#">Select Next Cell</a></li> |
|
99 | <li id="select_next"><a href="#">Select Next Cell</a></li> | |
100 | </ul> |
|
100 | </ul> | |
101 | </li> |
|
101 | </li> | |
102 | <li><a href="#">View</a> |
|
102 | <li><a href="#">View</a> | |
103 | <ul> |
|
103 | <ul> | |
104 | <li id="toggle_header"><a href="#">Toggle Header</a></li> |
|
104 | <li id="toggle_header"><a href="#">Toggle Header</a></li> | |
105 | <li id="toggle_toolbar"><a href="#">Toggle Toolbar</a></li> |
|
105 | <li id="toggle_toolbar"><a href="#">Toggle Toolbar</a></li> | |
106 | </ul> |
|
106 | </ul> | |
107 | </li> |
|
107 | </li> | |
108 | <li><a href="#">Insert</a> |
|
108 | <li><a href="#">Insert</a> | |
109 | <ul> |
|
109 | <ul> | |
110 | <li id="insert_cell_above"><a href="#">Insert Cell Above</a></li> |
|
110 | <li id="insert_cell_above"><a href="#">Insert Cell Above</a></li> | |
111 | <li id="insert_cell_below"><a href="#">Insert Cell Below</a></li> |
|
111 | <li id="insert_cell_below"><a href="#">Insert Cell Below</a></li> | |
112 | </ul> |
|
112 | </ul> | |
113 | </li> |
|
113 | </li> | |
114 | <li><a href="#">Cell</a> |
|
114 | <li><a href="#">Cell</a> | |
115 | <ul> |
|
115 | <ul> | |
116 | <li id="run_cell"><a href="#">Run</a></li> |
|
116 | <li id="run_cell"><a href="#">Run</a></li> | |
117 | <li id="run_cell_in_place"><a href="#">Run in Place</a></li> |
|
117 | <li id="run_cell_in_place"><a href="#">Run in Place</a></li> | |
118 | <li id="run_all_cells"><a href="#">Run All</a></li> |
|
118 | <li id="run_all_cells"><a href="#">Run All</a></li> | |
119 | <hr/> |
|
119 | <hr/> | |
120 | <li id="to_code"><a href="#">Code</a></li> |
|
120 | <li id="to_code"><a href="#">Code</a></li> | |
121 | <li id="to_markdown"><a href="#">Markdown </a></li> |
|
121 | <li id="to_markdown"><a href="#">Markdown </a></li> | |
122 |
<li id="to_ |
|
122 | <li id="to_plaintext"><a href="#">Plaintext</a></li> | |
123 | <li id="to_heading1"><a href="#">Heading 1</a></li> |
|
123 | <li id="to_heading1"><a href="#">Heading 1</a></li> | |
124 | <li id="to_heading2"><a href="#">Heading 2</a></li> |
|
124 | <li id="to_heading2"><a href="#">Heading 2</a></li> | |
125 | <li id="to_heading3"><a href="#">Heading 3</a></li> |
|
125 | <li id="to_heading3"><a href="#">Heading 3</a></li> | |
126 | <li id="to_heading4"><a href="#">Heading 4</a></li> |
|
126 | <li id="to_heading4"><a href="#">Heading 4</a></li> | |
127 | <li id="to_heading5"><a href="#">Heading 5</a></li> |
|
127 | <li id="to_heading5"><a href="#">Heading 5</a></li> | |
128 | <li id="to_heading6"><a href="#">Heading 6</a></li> |
|
128 | <li id="to_heading6"><a href="#">Heading 6</a></li> | |
129 | <hr/> |
|
129 | <hr/> | |
130 | <li id="toggle_output"><a href="#">Toggle Output</a></li> |
|
130 | <li id="toggle_output"><a href="#">Toggle Output</a></li> | |
131 | <li id="clear_all_output"><a href="#">Clear All Output</a></li> |
|
131 | <li id="clear_all_output"><a href="#">Clear All Output</a></li> | |
132 | </ul> |
|
132 | </ul> | |
133 | </li> |
|
133 | </li> | |
134 | <li><a href="#">Kernel</a> |
|
134 | <li><a href="#">Kernel</a> | |
135 | <ul> |
|
135 | <ul> | |
136 | <li id="int_kernel"><a href="#">Interrupt</a></li> |
|
136 | <li id="int_kernel"><a href="#">Interrupt</a></li> | |
137 | <li id="restart_kernel"><a href="#">Restart</a></li> |
|
137 | <li id="restart_kernel"><a href="#">Restart</a></li> | |
138 | </ul> |
|
138 | </ul> | |
139 | </li> |
|
139 | </li> | |
140 | <li><a href="#">Help</a> |
|
140 | <li><a href="#">Help</a> | |
141 | <ul> |
|
141 | <ul> | |
142 | <li><a href="http://ipython.org/documentation.html" target="_blank">IPython Help</a></li> |
|
142 | <li><a href="http://ipython.org/documentation.html" target="_blank">IPython Help</a></li> | |
143 | <li><a href="http://ipython.org/ipython-doc/stable/interactive/htmlnotebook.html" target="_blank">Notebook Help</a></li> |
|
143 | <li><a href="http://ipython.org/ipython-doc/stable/interactive/htmlnotebook.html" target="_blank">Notebook Help</a></li> | |
144 | <li id="keyboard_shortcuts"><a href="#">Keyboard Shortcuts</a></li> |
|
144 | <li id="keyboard_shortcuts"><a href="#">Keyboard Shortcuts</a></li> | |
145 | <hr/> |
|
145 | <hr/> | |
146 | <li><a href="http://docs.python.org" target="_blank">Python</a></li> |
|
146 | <li><a href="http://docs.python.org" target="_blank">Python</a></li> | |
147 | <li><a href="http://docs.scipy.org/doc/numpy/reference/" target="_blank">NumPy</a></li> |
|
147 | <li><a href="http://docs.scipy.org/doc/numpy/reference/" target="_blank">NumPy</a></li> | |
148 | <li><a href="http://docs.scipy.org/doc/scipy/reference/" target="_blank">SciPy</a></li> |
|
148 | <li><a href="http://docs.scipy.org/doc/scipy/reference/" target="_blank">SciPy</a></li> | |
149 | <li><a href="http://docs.sympy.org/dev/index.html" target="_blank">SymPy</a></li> |
|
149 | <li><a href="http://docs.sympy.org/dev/index.html" target="_blank">SymPy</a></li> | |
150 | <li><a href="http://matplotlib.sourceforge.net/" target="_blank">Matplotlib</a></li> |
|
150 | <li><a href="http://matplotlib.sourceforge.net/" target="_blank">Matplotlib</a></li> | |
151 | </ul> |
|
151 | </ul> | |
152 | </li> |
|
152 | </li> | |
153 | </ul> |
|
153 | </ul> | |
154 |
|
154 | |||
155 | </div> |
|
155 | </div> | |
156 |
|
156 | |||
157 | <div id="toolbar"> |
|
157 | <div id="toolbar"> | |
158 |
|
158 | |||
159 | <span> |
|
159 | <span> | |
160 | <button id="save_b">Save</button> |
|
160 | <button id="save_b">Save</button> | |
161 | </span> |
|
161 | </span> | |
162 | <span id="cut_copy_paste"> |
|
162 | <span id="cut_copy_paste"> | |
163 | <button id="cut_b" title="Cut Cell">Cut Cell</button> |
|
163 | <button id="cut_b" title="Cut Cell">Cut Cell</button> | |
164 | <button id="copy_b" title="Copy Cell">Copy Cell</button> |
|
164 | <button id="copy_b" title="Copy Cell">Copy Cell</button> | |
165 | <button id="paste_b" title="Paste Cell">Paste Cell</button> |
|
165 | <button id="paste_b" title="Paste Cell">Paste Cell</button> | |
166 | </span> |
|
166 | </span> | |
167 | <span id="move_up_down"> |
|
167 | <span id="move_up_down"> | |
168 | <button id="move_up_b" title="Move Cell Up">Move Cell Up</button> |
|
168 | <button id="move_up_b" title="Move Cell Up">Move Cell Up</button> | |
169 | <button id="move_down_b" title="Move Cell Down">Move Down</button> |
|
169 | <button id="move_down_b" title="Move Cell Down">Move Down</button> | |
170 | </span> |
|
170 | </span> | |
171 | <span id="insert_above_below"> |
|
171 | <span id="insert_above_below"> | |
172 | <button id="insert_above_b" title="Insert Cell Above">Insert Cell Above</button> |
|
172 | <button id="insert_above_b" title="Insert Cell Above">Insert Cell Above</button> | |
173 | <button id="insert_below_b" title="Insert Cell Below">Insert Cell Below</button> |
|
173 | <button id="insert_below_b" title="Insert Cell Below">Insert Cell Below</button> | |
174 | </span> |
|
174 | </span> | |
175 | <span id="run_int"> |
|
175 | <span id="run_int"> | |
176 | <button id="run_b" title="Run Cell">Run Cell</button> |
|
176 | <button id="run_b" title="Run Cell">Run Cell</button> | |
177 | <button id="interrupt_b" title="Interrupt">Interrupt</button> |
|
177 | <button id="interrupt_b" title="Interrupt">Interrupt</button> | |
178 | </span> |
|
178 | </span> | |
179 | <span> |
|
179 | <span> | |
180 | <select id="cell_type"> |
|
180 | <select id="cell_type"> | |
181 | <option value="code">Code</option> |
|
181 | <option value="code">Code</option> | |
182 | <option value="markdown">Markdown</option> |
|
182 | <option value="markdown">Markdown</option> | |
183 | </select> |
|
183 | </select> | |
184 | </span> |
|
184 | </span> | |
185 |
|
185 | |||
186 | </div> |
|
186 | </div> | |
187 |
|
187 | |||
188 | <div id="main_app"> |
|
188 | <div id="main_app"> | |
189 |
|
189 | |||
190 | <div id="notebook_panel"> |
|
190 | <div id="notebook_panel"> | |
191 | <div id="notebook"></div> |
|
191 | <div id="notebook"></div> | |
192 | <div id="pager_splitter"></div> |
|
192 | <div id="pager_splitter"></div> | |
193 | <div id="pager"></div> |
|
193 | <div id="pager"></div> | |
194 | </div> |
|
194 | </div> | |
195 |
|
195 | |||
196 | </div> |
|
196 | </div> | |
197 |
|
197 | |||
198 | <script src="{{ static_url("jquery/js/jquery-1.7.1.min.js") }}" type="text/javascript" charset="utf-8"></script> |
|
198 | <script src="{{ static_url("jquery/js/jquery-1.7.1.min.js") }}" type="text/javascript" charset="utf-8"></script> | |
199 | <script src="{{ static_url("jquery/js/jquery-ui.min.js") }}" type="text/javascript" charset="utf-8"></script> |
|
199 | <script src="{{ static_url("jquery/js/jquery-ui.min.js") }}" type="text/javascript" charset="utf-8"></script> | |
200 |
|
200 | |||
201 | <script src="{{ static_url("codemirror/lib/codemirror.js") }}" charset="utf-8"></script> |
|
201 | <script src="{{ static_url("codemirror/lib/codemirror.js") }}" charset="utf-8"></script> | |
202 | <script src="{{ static_url("codemirror/mode/python/python.js") }}" charset="utf-8"></script> |
|
202 | <script src="{{ static_url("codemirror/mode/python/python.js") }}" charset="utf-8"></script> | |
203 | <script src="{{ static_url("codemirror/mode/htmlmixed/htmlmixed.js") }}" charset="utf-8"></script> |
|
203 | <script src="{{ static_url("codemirror/mode/htmlmixed/htmlmixed.js") }}" charset="utf-8"></script> | |
204 | <script src="{{ static_url("codemirror/mode/xml/xml.js") }}" charset="utf-8"></script> |
|
204 | <script src="{{ static_url("codemirror/mode/xml/xml.js") }}" charset="utf-8"></script> | |
205 | <script src="{{ static_url("codemirror/mode/javascript/javascript.js") }}" charset="utf-8"></script> |
|
205 | <script src="{{ static_url("codemirror/mode/javascript/javascript.js") }}" charset="utf-8"></script> | |
206 | <script src="{{ static_url("codemirror/mode/css/css.js") }}" charset="utf-8"></script> |
|
206 | <script src="{{ static_url("codemirror/mode/css/css.js") }}" charset="utf-8"></script> | |
207 | <script src="{{ static_url("codemirror/mode/rst/rst.js") }}" charset="utf-8"></script> |
|
207 | <script src="{{ static_url("codemirror/mode/rst/rst.js") }}" charset="utf-8"></script> | |
208 | <script src="{{ static_url("codemirror/mode/markdown/markdown.js") }}" charset="utf-8"></script> |
|
208 | <script src="{{ static_url("codemirror/mode/markdown/markdown.js") }}" charset="utf-8"></script> | |
209 |
|
209 | |||
210 | <script src="{{ static_url("pagedown/Markdown.Converter.js") }}" charset="utf-8"></script> |
|
210 | <script src="{{ static_url("pagedown/Markdown.Converter.js") }}" charset="utf-8"></script> | |
211 |
|
211 | |||
212 | <script src="{{ static_url("prettify/prettify.js") }}" charset="utf-8"></script> |
|
212 | <script src="{{ static_url("prettify/prettify.js") }}" charset="utf-8"></script> | |
213 | <script src="{{ static_url("dateformat/date.format.js") }}" charset="utf-8"></script> |
|
213 | <script src="{{ static_url("dateformat/date.format.js") }}" charset="utf-8"></script> | |
214 |
|
214 | |||
215 | <script src="{{ static_url("js/namespace.js") }}" type="text/javascript" charset="utf-8"></script> |
|
215 | <script src="{{ static_url("js/namespace.js") }}" type="text/javascript" charset="utf-8"></script> | |
216 | <script src="{{ static_url("js/utils.js") }}" type="text/javascript" charset="utf-8"></script> |
|
216 | <script src="{{ static_url("js/utils.js") }}" type="text/javascript" charset="utf-8"></script> | |
217 | <script src="{{ static_url("js/cell.js") }}" type="text/javascript" charset="utf-8"></script> |
|
217 | <script src="{{ static_url("js/cell.js") }}" type="text/javascript" charset="utf-8"></script> | |
218 | <script src="{{ static_url("js/codecell.js") }}" type="text/javascript" charset="utf-8"></script> |
|
218 | <script src="{{ static_url("js/codecell.js") }}" type="text/javascript" charset="utf-8"></script> | |
219 | <script src="{{ static_url("js/textcell.js") }}" type="text/javascript" charset="utf-8"></script> |
|
219 | <script src="{{ static_url("js/textcell.js") }}" type="text/javascript" charset="utf-8"></script> | |
220 | <script src="{{ static_url("js/kernel.js") }}" type="text/javascript" charset="utf-8"></script> |
|
220 | <script src="{{ static_url("js/kernel.js") }}" type="text/javascript" charset="utf-8"></script> | |
221 | <script src="{{ static_url("js/kernelstatus.js") }}" type="text/javascript" charset="utf-8"></script> |
|
221 | <script src="{{ static_url("js/kernelstatus.js") }}" type="text/javascript" charset="utf-8"></script> | |
222 | <script src="{{ static_url("js/layout.js") }}" type="text/javascript" charset="utf-8"></script> |
|
222 | <script src="{{ static_url("js/layout.js") }}" type="text/javascript" charset="utf-8"></script> | |
223 | <script src="{{ static_url("js/savewidget.js") }}" type="text/javascript" charset="utf-8"></script> |
|
223 | <script src="{{ static_url("js/savewidget.js") }}" type="text/javascript" charset="utf-8"></script> | |
224 | <script src="{{ static_url("js/quickhelp.js") }}" type="text/javascript" charset="utf-8"></script> |
|
224 | <script src="{{ static_url("js/quickhelp.js") }}" type="text/javascript" charset="utf-8"></script> | |
225 | <script src="{{ static_url("js/loginwidget.js") }}" type="text/javascript" charset="utf-8"></script> |
|
225 | <script src="{{ static_url("js/loginwidget.js") }}" type="text/javascript" charset="utf-8"></script> | |
226 | <script src="{{ static_url("js/pager.js") }}" type="text/javascript" charset="utf-8"></script> |
|
226 | <script src="{{ static_url("js/pager.js") }}" type="text/javascript" charset="utf-8"></script> | |
227 | <script src="{{ static_url("js/menubar.js") }}" type="text/javascript" charset="utf-8"></script> |
|
227 | <script src="{{ static_url("js/menubar.js") }}" type="text/javascript" charset="utf-8"></script> | |
228 | <script src="{{ static_url("js/toolbar.js") }}" type="text/javascript" charset="utf-8"></script> |
|
228 | <script src="{{ static_url("js/toolbar.js") }}" type="text/javascript" charset="utf-8"></script> | |
229 | <script src="{{ static_url("js/notebook.js") }}" type="text/javascript" charset="utf-8"></script> |
|
229 | <script src="{{ static_url("js/notebook.js") }}" type="text/javascript" charset="utf-8"></script> | |
230 | <script src="{{ static_url("js/notebookmain.js") }}" type="text/javascript" charset="utf-8"></script> |
|
230 | <script src="{{ static_url("js/notebookmain.js") }}" type="text/javascript" charset="utf-8"></script> | |
231 |
|
231 | |||
232 | </body> |
|
232 | </body> | |
233 |
|
233 | |||
234 | </html> |
|
234 | </html> |
General Comments 0
You need to be logged in to leave comments.
Login now