##// END OF EJS Templates
javascript is no place to start adding title tags
Paul Ivanov -
Show More
@@ -1,274 +1,274
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 /**
12 /**
13 * @module IPython
13 * @module IPython
14 * @namespace IPython
14 * @namespace IPython
15 * @submodule MenuBar
15 * @submodule MenuBar
16 */
16 */
17
17
18
18
19 var IPython = (function (IPython) {
19 var IPython = (function (IPython) {
20 "use strict";
20 "use strict";
21
21
22 /**
22 /**
23 * A MenuBar Class to generate the menubar of IPython noteboko
23 * A MenuBar Class to generate the menubar of IPython noteboko
24 * @Class MenuBar
24 * @Class MenuBar
25 *
25 *
26 * @constructor
26 * @constructor
27 *
27 *
28 *
28 *
29 * @param selector {string} selector for the menubar element in DOM
29 * @param selector {string} selector for the menubar element in DOM
30 * @param {object} [options]
30 * @param {object} [options]
31 * @param [options.baseProjectUrl] {String} String to use for the
31 * @param [options.baseProjectUrl] {String} String to use for the
32 * Base Project url, default would be to inspect
32 * Base Project url, default would be to inspect
33 * $('body').data('baseProjectUrl');
33 * $('body').data('baseProjectUrl');
34 * does not support change for now is set through this option
34 * does not support change for now is set through this option
35 */
35 */
36 var MenuBar = function (selector, options) {
36 var MenuBar = function (selector, options) {
37 var options = options || {};
37 var options = options || {};
38 if(options.baseProjectUrl!= undefined){
38 if(options.baseProjectUrl!= undefined){
39 this._baseProjectUrl = options.baseProjectUrl;
39 this._baseProjectUrl = options.baseProjectUrl;
40 }
40 }
41 this.selector = selector;
41 this.selector = selector;
42 if (this.selector !== undefined) {
42 if (this.selector !== undefined) {
43 this.element = $(selector);
43 this.element = $(selector);
44 this.style();
44 this.style();
45 this.bind_events();
45 this.bind_events();
46 }
46 }
47 };
47 };
48
48
49 MenuBar.prototype.baseProjectUrl = function(){
49 MenuBar.prototype.baseProjectUrl = function(){
50 return this._baseProjectUrl || $('body').data('baseProjectUrl');
50 return this._baseProjectUrl || $('body').data('baseProjectUrl');
51 };
51 };
52
52
53
53
54 MenuBar.prototype.style = function () {
54 MenuBar.prototype.style = function () {
55 this.element.addClass('border-box-sizing');
55 this.element.addClass('border-box-sizing');
56 this.element.find("li").click(function (event, ui) {
56 this.element.find("li").click(function (event, ui) {
57 // The selected cell loses focus when the menu is entered, so we
57 // The selected cell loses focus when the menu is entered, so we
58 // re-select it upon selection.
58 // re-select it upon selection.
59 var i = IPython.notebook.get_selected_index();
59 var i = IPython.notebook.get_selected_index();
60 IPython.notebook.select(i);
60 IPython.notebook.select(i);
61 }
61 }
62 );
62 );
63 };
63 };
64
64
65
65
66 MenuBar.prototype.bind_events = function () {
66 MenuBar.prototype.bind_events = function () {
67 // File
67 // File
68 var that = this;
68 var that = this;
69 this.element.find('#new_notebook').click(function () {
69 this.element.find('#new_notebook').click(function () {
70 window.open(that.baseProjectUrl()+'new');
70 window.open(that.baseProjectUrl()+'new');
71 });
71 });
72 this.element.find('#open_notebook').click(function () {
72 this.element.find('#open_notebook').click(function () {
73 window.open(that.baseProjectUrl());
73 window.open(that.baseProjectUrl());
74 });
74 });
75 this.element.find('#rename_notebook').click(function () {
75 this.element.find('#rename_notebook').click(function () {
76 IPython.save_widget.rename_notebook();
76 IPython.save_widget.rename_notebook();
77 });
77 });
78 this.element.find('#copy_notebook').click(function () {
78 this.element.find('#copy_notebook').click(function () {
79 var notebook_id = IPython.notebook.get_notebook_id();
79 var notebook_id = IPython.notebook.get_notebook_id();
80 var url = that.baseProjectUrl() + notebook_id + '/copy';
80 var url = that.baseProjectUrl() + notebook_id + '/copy';
81 window.open(url,'_blank');
81 window.open(url,'_blank');
82 return false;
82 return false;
83 });
83 });
84 this.element.find('#save_checkpoint').click(function () {
84 this.element.find('#save_checkpoint').click(function () {
85 IPython.notebook.save_checkpoint();
85 IPython.notebook.save_checkpoint();
86 });
86 });
87 this.element.find('#restore_checkpoint').click(function () {
87 this.element.find('#restore_checkpoint').click(function () {
88 });
88 });
89 this.element.find('#download_ipynb').click(function () {
89 this.element.find('#download_ipynb').click(function () {
90 var notebook_id = IPython.notebook.get_notebook_id();
90 var notebook_id = IPython.notebook.get_notebook_id();
91 var url = that.baseProjectUrl() + 'notebooks/' +
91 var url = that.baseProjectUrl() + 'notebooks/' +
92 notebook_id + '?format=json';
92 notebook_id + '?format=json';
93 window.location.assign(url);
93 window.location.assign(url);
94 });
94 });
95 this.element.find('#download_py').click(function () {
95 this.element.find('#download_py').click(function () {
96 var notebook_id = IPython.notebook.get_notebook_id();
96 var notebook_id = IPython.notebook.get_notebook_id();
97 var url = that.baseProjectUrl() + 'notebooks/' +
97 var url = that.baseProjectUrl() + 'notebooks/' +
98 notebook_id + '?format=py';
98 notebook_id + '?format=py';
99 window.location.assign(url);
99 window.location.assign(url);
100 });
100 });
101 this.element.find('#kill_and_exit').click(function () {
101 this.element.find('#kill_and_exit').click(function () {
102 IPython.notebook.kernel.kill();
102 IPython.notebook.kernel.kill();
103 setTimeout(function(){window.close();}, 200);
103 setTimeout(function(){window.close();}, 200);
104 });
104 });
105 // Edit
105 // Edit
106 this.element.find('#cut_cell').click(function () {
106 this.element.find('#cut_cell').click(function () {
107 IPython.notebook.cut_cell();
107 IPython.notebook.cut_cell();
108 });
108 });
109 this.element.find('#copy_cell').click(function () {
109 this.element.find('#copy_cell').click(function () {
110 IPython.notebook.copy_cell();
110 IPython.notebook.copy_cell();
111 });
111 });
112 this.element.find('#delete_cell').click(function () {
112 this.element.find('#delete_cell').click(function () {
113 IPython.notebook.delete_cell();
113 IPython.notebook.delete_cell();
114 });
114 });
115 this.element.find('#undelete_cell').click(function () {
115 this.element.find('#undelete_cell').click(function () {
116 IPython.notebook.undelete();
116 IPython.notebook.undelete();
117 });
117 });
118 this.element.find('#split_cell').click(function () {
118 this.element.find('#split_cell').click(function () {
119 IPython.notebook.split_cell();
119 IPython.notebook.split_cell();
120 });
120 });
121 this.element.find('#merge_cell_above').click(function () {
121 this.element.find('#merge_cell_above').click(function () {
122 IPython.notebook.merge_cell_above();
122 IPython.notebook.merge_cell_above();
123 });
123 });
124 this.element.find('#merge_cell_below').click(function () {
124 this.element.find('#merge_cell_below').click(function () {
125 IPython.notebook.merge_cell_below();
125 IPython.notebook.merge_cell_below();
126 });
126 });
127 this.element.find('#move_cell_up').click(function () {
127 this.element.find('#move_cell_up').click(function () {
128 IPython.notebook.move_cell_up();
128 IPython.notebook.move_cell_up();
129 });
129 });
130 this.element.find('#move_cell_down').click(function () {
130 this.element.find('#move_cell_down').click(function () {
131 IPython.notebook.move_cell_down();
131 IPython.notebook.move_cell_down();
132 });
132 });
133 this.element.find('#select_previous').click(function () {
133 this.element.find('#select_previous').click(function () {
134 IPython.notebook.select_prev();
134 IPython.notebook.select_prev();
135 });
135 });
136 this.element.find('#select_next').click(function () {
136 this.element.find('#select_next').click(function () {
137 IPython.notebook.select_next();
137 IPython.notebook.select_next();
138 });
138 });
139 this.element.find('#edit_nb_metadata').click(function () {
139 this.element.find('#edit_nb_metadata').click(function () {
140 IPython.notebook.edit_metadata();
140 IPython.notebook.edit_metadata();
141 });
141 });
142
142
143 // View
143 // View
144 this.element.find('#toggle_header').click(function () {
144 this.element.find('#toggle_header').click(function () {
145 $('div#header').toggle();
145 $('div#header').toggle();
146 IPython.layout_manager.do_resize();
146 IPython.layout_manager.do_resize();
147 });
147 });
148 this.element.find('#toggle_toolbar').click(function () {
148 this.element.find('#toggle_toolbar').click(function () {
149 $('div#maintoolbar').toggle();
149 $('div#maintoolbar').toggle();
150 IPython.layout_manager.do_resize();
150 IPython.layout_manager.do_resize();
151 });
151 });
152 // Insert
152 // Insert
153 this.element.find('#insert_cell_above').click(function () {
153 this.element.find('#insert_cell_above').click(function () {
154 IPython.notebook.insert_cell_above('code');
154 IPython.notebook.insert_cell_above('code');
155 });
155 });
156 this.element.find('#insert_cell_below').click(function () {
156 this.element.find('#insert_cell_below').click(function () {
157 IPython.notebook.insert_cell_below('code');
157 IPython.notebook.insert_cell_below('code');
158 });
158 });
159 // Cell
159 // Cell
160 this.element.find('#run_cell').click(function () {
160 this.element.find('#run_cell').click(function () {
161 IPython.notebook.execute_selected_cell();
161 IPython.notebook.execute_selected_cell();
162 });
162 });
163 this.element.find('#run_cell_in_place').click(function () {
163 this.element.find('#run_cell_in_place').click(function () {
164 IPython.notebook.execute_selected_cell({terminal:true});
164 IPython.notebook.execute_selected_cell({terminal:true});
165 });
165 });
166 this.element.find('#run_all_cells').click(function () {
166 this.element.find('#run_all_cells').click(function () {
167 IPython.notebook.execute_all_cells();
167 IPython.notebook.execute_all_cells();
168 }).attr('title', 'Run all cells in the notebook');
168 });
169 this.element.find('#run_all_cells_above').click(function () {
169 this.element.find('#run_all_cells_above').click(function () {
170 IPython.notebook.execute_cells_above();
170 IPython.notebook.execute_cells_above();
171 }).attr('title', 'Run all cells above (but not including) this cell');
171 });
172 this.element.find('#run_all_cells_below').click(function () {
172 this.element.find('#run_all_cells_below').click(function () {
173 IPython.notebook.execute_cells_below();
173 IPython.notebook.execute_cells_below();
174 }).attr('title', 'Run this cell and all cells below it');
174 });
175 this.element.find('#to_code').click(function () {
175 this.element.find('#to_code').click(function () {
176 IPython.notebook.to_code();
176 IPython.notebook.to_code();
177 });
177 });
178 this.element.find('#to_markdown').click(function () {
178 this.element.find('#to_markdown').click(function () {
179 IPython.notebook.to_markdown();
179 IPython.notebook.to_markdown();
180 });
180 });
181 this.element.find('#to_raw').click(function () {
181 this.element.find('#to_raw').click(function () {
182 IPython.notebook.to_raw();
182 IPython.notebook.to_raw();
183 });
183 });
184 this.element.find('#to_heading1').click(function () {
184 this.element.find('#to_heading1').click(function () {
185 IPython.notebook.to_heading(undefined, 1);
185 IPython.notebook.to_heading(undefined, 1);
186 });
186 });
187 this.element.find('#to_heading2').click(function () {
187 this.element.find('#to_heading2').click(function () {
188 IPython.notebook.to_heading(undefined, 2);
188 IPython.notebook.to_heading(undefined, 2);
189 });
189 });
190 this.element.find('#to_heading3').click(function () {
190 this.element.find('#to_heading3').click(function () {
191 IPython.notebook.to_heading(undefined, 3);
191 IPython.notebook.to_heading(undefined, 3);
192 });
192 });
193 this.element.find('#to_heading4').click(function () {
193 this.element.find('#to_heading4').click(function () {
194 IPython.notebook.to_heading(undefined, 4);
194 IPython.notebook.to_heading(undefined, 4);
195 });
195 });
196 this.element.find('#to_heading5').click(function () {
196 this.element.find('#to_heading5').click(function () {
197 IPython.notebook.to_heading(undefined, 5);
197 IPython.notebook.to_heading(undefined, 5);
198 });
198 });
199 this.element.find('#to_heading6').click(function () {
199 this.element.find('#to_heading6').click(function () {
200 IPython.notebook.to_heading(undefined, 6);
200 IPython.notebook.to_heading(undefined, 6);
201 });
201 });
202 this.element.find('#toggle_output').click(function () {
202 this.element.find('#toggle_output').click(function () {
203 IPython.notebook.toggle_output();
203 IPython.notebook.toggle_output();
204 });
204 });
205 this.element.find('#collapse_all_output').click(function () {
205 this.element.find('#collapse_all_output').click(function () {
206 IPython.notebook.collapse_all_output();
206 IPython.notebook.collapse_all_output();
207 });
207 });
208 this.element.find('#scroll_all_output').click(function () {
208 this.element.find('#scroll_all_output').click(function () {
209 IPython.notebook.scroll_all_output();
209 IPython.notebook.scroll_all_output();
210 });
210 });
211 this.element.find('#expand_all_output').click(function () {
211 this.element.find('#expand_all_output').click(function () {
212 IPython.notebook.expand_all_output();
212 IPython.notebook.expand_all_output();
213 });
213 });
214 this.element.find('#clear_all_output').click(function () {
214 this.element.find('#clear_all_output').click(function () {
215 IPython.notebook.clear_all_output();
215 IPython.notebook.clear_all_output();
216 });
216 });
217 // Kernel
217 // Kernel
218 this.element.find('#int_kernel').click(function () {
218 this.element.find('#int_kernel').click(function () {
219 IPython.notebook.kernel.interrupt();
219 IPython.notebook.kernel.interrupt();
220 });
220 });
221 this.element.find('#restart_kernel').click(function () {
221 this.element.find('#restart_kernel').click(function () {
222 IPython.notebook.restart_kernel();
222 IPython.notebook.restart_kernel();
223 });
223 });
224 // Help
224 // Help
225 this.element.find('#keyboard_shortcuts').click(function () {
225 this.element.find('#keyboard_shortcuts').click(function () {
226 IPython.quick_help.show_keyboard_shortcuts();
226 IPython.quick_help.show_keyboard_shortcuts();
227 });
227 });
228
228
229 this.update_restore_checkpoint(null);
229 this.update_restore_checkpoint(null);
230
230
231 $([IPython.events]).on('checkpoints_listed.Notebook', function (event, data) {
231 $([IPython.events]).on('checkpoints_listed.Notebook', function (event, data) {
232 that.update_restore_checkpoint(IPython.notebook.checkpoints);
232 that.update_restore_checkpoint(IPython.notebook.checkpoints);
233 });
233 });
234
234
235 $([IPython.events]).on('checkpoint_created.Notebook', function (event, data) {
235 $([IPython.events]).on('checkpoint_created.Notebook', function (event, data) {
236 that.update_restore_checkpoint(IPython.notebook.checkpoints);
236 that.update_restore_checkpoint(IPython.notebook.checkpoints);
237 });
237 });
238 };
238 };
239
239
240 MenuBar.prototype.update_restore_checkpoint = function(checkpoints) {
240 MenuBar.prototype.update_restore_checkpoint = function(checkpoints) {
241 var ul = this.element.find("#restore_checkpoint").find("ul");
241 var ul = this.element.find("#restore_checkpoint").find("ul");
242 ul.empty();
242 ul.empty();
243 if (! checkpoints || checkpoints.length == 0) {
243 if (! checkpoints || checkpoints.length == 0) {
244 ul.append(
244 ul.append(
245 $("<li/>")
245 $("<li/>")
246 .addClass("disabled")
246 .addClass("disabled")
247 .append(
247 .append(
248 $("<a/>")
248 $("<a/>")
249 .text("No checkpoints")
249 .text("No checkpoints")
250 )
250 )
251 );
251 );
252 return;
252 return;
253 };
253 };
254
254
255 checkpoints.map(function (checkpoint) {
255 checkpoints.map(function (checkpoint) {
256 var d = new Date(checkpoint.last_modified);
256 var d = new Date(checkpoint.last_modified);
257 ul.append(
257 ul.append(
258 $("<li/>").append(
258 $("<li/>").append(
259 $("<a/>")
259 $("<a/>")
260 .attr("href", "#")
260 .attr("href", "#")
261 .text(d.format("mmm dd HH:MM:ss"))
261 .text(d.format("mmm dd HH:MM:ss"))
262 .click(function () {
262 .click(function () {
263 IPython.notebook.restore_checkpoint_dialog(checkpoint);
263 IPython.notebook.restore_checkpoint_dialog(checkpoint);
264 })
264 })
265 )
265 )
266 );
266 );
267 });
267 });
268 };
268 };
269
269
270 IPython.MenuBar = MenuBar;
270 IPython.MenuBar = MenuBar;
271
271
272 return IPython;
272 return IPython;
273
273
274 }(IPython));
274 }(IPython));
General Comments 0
You need to be logged in to leave comments. Login now