Show More
@@ -1,198 +1,198 | |||||
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 | this.element.addClass('border-box-sizing'); |
|
25 | this.element.addClass('border-box-sizing'); | |
26 | $('ul#menus').menubar({ |
|
26 | $('ul#menus').menubar({ | |
27 | select : function (event, ui) { |
|
27 | select : function (event, ui) { | |
28 | // The selected cell loses focus when the menu is entered, so we |
|
28 | // The selected cell loses focus when the menu is entered, so we | |
29 | // re-select it upon selection. |
|
29 | // re-select it upon selection. | |
30 | var i = IPython.notebook.get_selected_index(); |
|
30 | var i = IPython.notebook.get_selected_index(); | |
31 | IPython.notebook.select(i); |
|
31 | IPython.notebook.select(i); | |
32 | } |
|
32 | } | |
33 | }); |
|
33 | }); | |
34 | }; |
|
34 | }; | |
35 |
|
35 | |||
36 |
|
36 | |||
37 | MenuBar.prototype.bind_events = function () { |
|
37 | MenuBar.prototype.bind_events = function () { | |
38 | // File |
|
38 | // File | |
39 | this.element.find('#new_notebook').click(function () { |
|
39 | this.element.find('#new_notebook').click(function () { | |
40 | window.open($('body').data('baseProjectUrl')+'new'); |
|
40 | window.open($('body').data('baseProjectUrl')+'new'); | |
41 | }); |
|
41 | }); | |
42 | this.element.find('#open_notebook').click(function () { |
|
42 | this.element.find('#open_notebook').click(function () { | |
43 | window.open($('body').data('baseProjectUrl')); |
|
43 | window.open($('body').data('baseProjectUrl')); | |
44 | }); |
|
44 | }); | |
45 | this.element.find('#rename_notebook').click(function () { |
|
45 | this.element.find('#rename_notebook').click(function () { | |
46 | IPython.save_widget.rename_notebook(); |
|
46 | IPython.save_widget.rename_notebook(); | |
47 | }); |
|
47 | }); | |
48 | this.element.find('#copy_notebook').click(function () { |
|
48 | this.element.find('#copy_notebook').click(function () { | |
49 | var notebook_id = IPython.notebook.get_notebook_id(); |
|
49 | var notebook_id = IPython.notebook.get_notebook_id(); | |
50 | var url = $('body').data('baseProjectUrl') + notebook_id + '/copy'; |
|
50 | var url = $('body').data('baseProjectUrl') + notebook_id + '/copy'; | |
51 | window.open(url,'_blank'); |
|
51 | window.open(url,'_blank'); | |
52 | return false; |
|
52 | return false; | |
53 | }); |
|
53 | }); | |
54 | this.element.find('#save_notebook').click(function () { |
|
54 | this.element.find('#save_notebook').click(function () { | |
55 | IPython.notebook.save_notebook(); |
|
55 | IPython.notebook.save_notebook(); | |
56 | }); |
|
56 | }); | |
57 | this.element.find('#download_ipynb').click(function () { |
|
57 | this.element.find('#download_ipynb').click(function () { | |
58 | var notebook_id = IPython.notebook.get_notebook_id(); |
|
58 | var notebook_id = IPython.notebook.get_notebook_id(); | |
59 | var url = $('body').data('baseProjectUrl') + 'notebooks/' + |
|
59 | var url = $('body').data('baseProjectUrl') + 'notebooks/' + | |
60 | notebook_id + '?format=json'; |
|
60 | notebook_id + '?format=json'; | |
61 |
window. |
|
61 | window.location.assign(url); | |
62 | }); |
|
62 | }); | |
63 | this.element.find('#download_py').click(function () { |
|
63 | this.element.find('#download_py').click(function () { | |
64 | var notebook_id = IPython.notebook.get_notebook_id(); |
|
64 | var notebook_id = IPython.notebook.get_notebook_id(); | |
65 | var url = $('body').data('baseProjectUrl') + 'notebooks/' + |
|
65 | var url = $('body').data('baseProjectUrl') + 'notebooks/' + | |
66 | notebook_id + '?format=py'; |
|
66 | notebook_id + '?format=py'; | |
67 |
window. |
|
67 | window.location.assign(url); | |
68 | }); |
|
68 | }); | |
69 | this.element.find('button#print_notebook').click(function () { |
|
69 | this.element.find('button#print_notebook').click(function () { | |
70 | IPython.print_widget.print_notebook(); |
|
70 | IPython.print_widget.print_notebook(); | |
71 | }); |
|
71 | }); | |
72 | this.element.find('#kill_and_exit').click(function () { |
|
72 | this.element.find('#kill_and_exit').click(function () { | |
73 | IPython.notebook.kernel.kill(); |
|
73 | IPython.notebook.kernel.kill(); | |
74 | setTimeout(function(){window.close();}, 200); |
|
74 | setTimeout(function(){window.close();}, 200); | |
75 | }); |
|
75 | }); | |
76 | // Edit |
|
76 | // Edit | |
77 | this.element.find('#cut_cell').click(function () { |
|
77 | this.element.find('#cut_cell').click(function () { | |
78 | IPython.notebook.cut_cell(); |
|
78 | IPython.notebook.cut_cell(); | |
79 | }); |
|
79 | }); | |
80 | this.element.find('#copy_cell').click(function () { |
|
80 | this.element.find('#copy_cell').click(function () { | |
81 | IPython.notebook.copy_cell(); |
|
81 | IPython.notebook.copy_cell(); | |
82 | }); |
|
82 | }); | |
83 | this.element.find('#delete_cell').click(function () { |
|
83 | this.element.find('#delete_cell').click(function () { | |
84 | IPython.notebook.delete_cell(); |
|
84 | IPython.notebook.delete_cell(); | |
85 | }); |
|
85 | }); | |
86 | this.element.find('#split_cell').click(function () { |
|
86 | this.element.find('#split_cell').click(function () { | |
87 | IPython.notebook.split_cell(); |
|
87 | IPython.notebook.split_cell(); | |
88 | }); |
|
88 | }); | |
89 | this.element.find('#merge_cell_above').click(function () { |
|
89 | this.element.find('#merge_cell_above').click(function () { | |
90 | IPython.notebook.merge_cell_above(); |
|
90 | IPython.notebook.merge_cell_above(); | |
91 | }); |
|
91 | }); | |
92 | this.element.find('#merge_cell_below').click(function () { |
|
92 | this.element.find('#merge_cell_below').click(function () { | |
93 | IPython.notebook.merge_cell_below(); |
|
93 | IPython.notebook.merge_cell_below(); | |
94 | }); |
|
94 | }); | |
95 | this.element.find('#move_cell_up').click(function () { |
|
95 | this.element.find('#move_cell_up').click(function () { | |
96 | IPython.notebook.move_cell_up(); |
|
96 | IPython.notebook.move_cell_up(); | |
97 | }); |
|
97 | }); | |
98 | this.element.find('#move_cell_down').click(function () { |
|
98 | this.element.find('#move_cell_down').click(function () { | |
99 | IPython.notebook.move_cell_down(); |
|
99 | IPython.notebook.move_cell_down(); | |
100 | }); |
|
100 | }); | |
101 | this.element.find('#select_previous').click(function () { |
|
101 | this.element.find('#select_previous').click(function () { | |
102 | IPython.notebook.select_prev(); |
|
102 | IPython.notebook.select_prev(); | |
103 | }); |
|
103 | }); | |
104 | this.element.find('#select_next').click(function () { |
|
104 | this.element.find('#select_next').click(function () { | |
105 | IPython.notebook.select_next(); |
|
105 | IPython.notebook.select_next(); | |
106 | }); |
|
106 | }); | |
107 | // View |
|
107 | // View | |
108 | this.element.find('#toggle_header').click(function () { |
|
108 | this.element.find('#toggle_header').click(function () { | |
109 | $('div#header').toggle(); |
|
109 | $('div#header').toggle(); | |
110 | IPython.layout_manager.do_resize(); |
|
110 | IPython.layout_manager.do_resize(); | |
111 | }); |
|
111 | }); | |
112 | this.element.find('#toggle_toolbar').click(function () { |
|
112 | this.element.find('#toggle_toolbar').click(function () { | |
113 | IPython.toolbar.toggle(); |
|
113 | IPython.toolbar.toggle(); | |
114 | }); |
|
114 | }); | |
115 | // Insert |
|
115 | // Insert | |
116 | this.element.find('#insert_cell_above').click(function () { |
|
116 | this.element.find('#insert_cell_above').click(function () { | |
117 | IPython.notebook.insert_cell_above('code'); |
|
117 | IPython.notebook.insert_cell_above('code'); | |
118 | }); |
|
118 | }); | |
119 | this.element.find('#insert_cell_below').click(function () { |
|
119 | this.element.find('#insert_cell_below').click(function () { | |
120 | IPython.notebook.insert_cell_below('code'); |
|
120 | IPython.notebook.insert_cell_below('code'); | |
121 | }); |
|
121 | }); | |
122 | // Cell |
|
122 | // Cell | |
123 | this.element.find('#run_cell').click(function () { |
|
123 | this.element.find('#run_cell').click(function () { | |
124 | IPython.notebook.execute_selected_cell(); |
|
124 | IPython.notebook.execute_selected_cell(); | |
125 | }); |
|
125 | }); | |
126 | this.element.find('#run_cell_in_place').click(function () { |
|
126 | this.element.find('#run_cell_in_place').click(function () { | |
127 | IPython.notebook.execute_selected_cell({terminal:true}); |
|
127 | IPython.notebook.execute_selected_cell({terminal:true}); | |
128 | }); |
|
128 | }); | |
129 | this.element.find('#run_all_cells').click(function () { |
|
129 | this.element.find('#run_all_cells').click(function () { | |
130 | IPython.notebook.execute_all_cells(); |
|
130 | IPython.notebook.execute_all_cells(); | |
131 | }).attr('title', 'Run all cells in the notebook'); |
|
131 | }).attr('title', 'Run all cells in the notebook'); | |
132 | this.element.find('#run_all_cells_above').click(function () { |
|
132 | this.element.find('#run_all_cells_above').click(function () { | |
133 | IPython.notebook.execute_cells_above(); |
|
133 | IPython.notebook.execute_cells_above(); | |
134 | }).attr('title', 'Run all cells above (but not including) this cell'); |
|
134 | }).attr('title', 'Run all cells above (but not including) this cell'); | |
135 | this.element.find('#run_all_cells_below').click(function () { |
|
135 | this.element.find('#run_all_cells_below').click(function () { | |
136 | IPython.notebook.execute_cells_below(); |
|
136 | IPython.notebook.execute_cells_below(); | |
137 | }).attr('title', 'Run this cell and all cells below it'); |
|
137 | }).attr('title', 'Run this cell and all cells below it'); | |
138 | this.element.find('#to_code').click(function () { |
|
138 | this.element.find('#to_code').click(function () { | |
139 | IPython.notebook.to_code(); |
|
139 | IPython.notebook.to_code(); | |
140 | }); |
|
140 | }); | |
141 | this.element.find('#to_markdown').click(function () { |
|
141 | this.element.find('#to_markdown').click(function () { | |
142 | IPython.notebook.to_markdown(); |
|
142 | IPython.notebook.to_markdown(); | |
143 | }); |
|
143 | }); | |
144 | this.element.find('#to_raw').click(function () { |
|
144 | this.element.find('#to_raw').click(function () { | |
145 | IPython.notebook.to_raw(); |
|
145 | IPython.notebook.to_raw(); | |
146 | }); |
|
146 | }); | |
147 | this.element.find('#to_heading1').click(function () { |
|
147 | this.element.find('#to_heading1').click(function () { | |
148 | IPython.notebook.to_heading(undefined, 1); |
|
148 | IPython.notebook.to_heading(undefined, 1); | |
149 | }); |
|
149 | }); | |
150 | this.element.find('#to_heading2').click(function () { |
|
150 | this.element.find('#to_heading2').click(function () { | |
151 | IPython.notebook.to_heading(undefined, 2); |
|
151 | IPython.notebook.to_heading(undefined, 2); | |
152 | }); |
|
152 | }); | |
153 | this.element.find('#to_heading3').click(function () { |
|
153 | this.element.find('#to_heading3').click(function () { | |
154 | IPython.notebook.to_heading(undefined, 3); |
|
154 | IPython.notebook.to_heading(undefined, 3); | |
155 | }); |
|
155 | }); | |
156 | this.element.find('#to_heading4').click(function () { |
|
156 | this.element.find('#to_heading4').click(function () { | |
157 | IPython.notebook.to_heading(undefined, 4); |
|
157 | IPython.notebook.to_heading(undefined, 4); | |
158 | }); |
|
158 | }); | |
159 | this.element.find('#to_heading5').click(function () { |
|
159 | this.element.find('#to_heading5').click(function () { | |
160 | IPython.notebook.to_heading(undefined, 5); |
|
160 | IPython.notebook.to_heading(undefined, 5); | |
161 | }); |
|
161 | }); | |
162 | this.element.find('#to_heading6').click(function () { |
|
162 | this.element.find('#to_heading6').click(function () { | |
163 | IPython.notebook.to_heading(undefined, 6); |
|
163 | IPython.notebook.to_heading(undefined, 6); | |
164 | }); |
|
164 | }); | |
165 | this.element.find('#toggle_output').click(function () { |
|
165 | this.element.find('#toggle_output').click(function () { | |
166 | IPython.notebook.toggle_output(); |
|
166 | IPython.notebook.toggle_output(); | |
167 | }); |
|
167 | }); | |
168 | this.element.find('#collapse_all_output').click(function () { |
|
168 | this.element.find('#collapse_all_output').click(function () { | |
169 | IPython.notebook.collapse_all_output(); |
|
169 | IPython.notebook.collapse_all_output(); | |
170 | }); |
|
170 | }); | |
171 | this.element.find('#scroll_all_output').click(function () { |
|
171 | this.element.find('#scroll_all_output').click(function () { | |
172 | IPython.notebook.scroll_all_output(); |
|
172 | IPython.notebook.scroll_all_output(); | |
173 | }); |
|
173 | }); | |
174 | this.element.find('#expand_all_output').click(function () { |
|
174 | this.element.find('#expand_all_output').click(function () { | |
175 | IPython.notebook.expand_all_output(); |
|
175 | IPython.notebook.expand_all_output(); | |
176 | }); |
|
176 | }); | |
177 | this.element.find('#clear_all_output').click(function () { |
|
177 | this.element.find('#clear_all_output').click(function () { | |
178 | IPython.notebook.clear_all_output(); |
|
178 | IPython.notebook.clear_all_output(); | |
179 | }); |
|
179 | }); | |
180 | // Kernel |
|
180 | // Kernel | |
181 | this.element.find('#int_kernel').click(function () { |
|
181 | this.element.find('#int_kernel').click(function () { | |
182 | IPython.notebook.kernel.interrupt(); |
|
182 | IPython.notebook.kernel.interrupt(); | |
183 | }); |
|
183 | }); | |
184 | this.element.find('#restart_kernel').click(function () { |
|
184 | this.element.find('#restart_kernel').click(function () { | |
185 | IPython.notebook.restart_kernel(); |
|
185 | IPython.notebook.restart_kernel(); | |
186 | }); |
|
186 | }); | |
187 | // Help |
|
187 | // Help | |
188 | this.element.find('#keyboard_shortcuts').click(function () { |
|
188 | this.element.find('#keyboard_shortcuts').click(function () { | |
189 | IPython.quick_help.show_keyboard_shortcuts(); |
|
189 | IPython.quick_help.show_keyboard_shortcuts(); | |
190 | }); |
|
190 | }); | |
191 | }; |
|
191 | }; | |
192 |
|
192 | |||
193 |
|
193 | |||
194 | IPython.MenuBar = MenuBar; |
|
194 | IPython.MenuBar = MenuBar; | |
195 |
|
195 | |||
196 | return IPython; |
|
196 | return IPython; | |
197 |
|
197 | |||
198 | }(IPython)); |
|
198 | }(IPython)); |
General Comments 0
You need to be logged in to leave comments.
Login now