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