##// END OF EJS Templates
add option in menubar to set baseproject url
Bussonnier Matthias -
Show More
@@ -1,202 +1,227 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 /**
13 * @module IPython
14 * @namespace IPython
15 * @submodule MenuBar
16 */
17
18
12 var IPython = (function (IPython) {
19 var IPython = (function (IPython) {
13
20
14 var MenuBar = function (selector) {
21 /**
22 * A MenuBar Class to generate the menubar of IPython noteboko
23 * @Class MenuBar
24 *
25 * @constructor
26 *
27 *
28 * @param selector {string} selector for the menubar element in DOM
29 * @param {object} [options]
30 * @param [options.baseProjectUrl] {String} String to use for the
31 * Base Project url, default would be to inspect
32 * $('body').data('baseProjectUrl');
33 * does not support change for now is set through this option
34 */
35 var MenuBar = function (selector, options) {
36 var options = options || {};
37 if(options.baseProjectUrl!= undefined){
38 this._baseProjectUrl = options.baseProjectUrl;
39 }
15 this.selector = selector;
40 this.selector = selector;
16 if (this.selector !== undefined) {
41 if (this.selector !== undefined) {
17 this.element = $(selector);
42 this.element = $(selector);
18 this.style();
43 this.style();
19 this.bind_events();
44 this.bind_events();
20 }
45 }
21 };
46 };
22
47
23 MenuBar.prototype.baseProjectUrl = function(){
48 MenuBar.prototype.baseProjectUrl = function(){
24 return $('body').data('baseProjectUrl');
49 return this._baseProjectUrl || $('body').data('baseProjectUrl');
25 }
50 }
26
51
27
52
28 MenuBar.prototype.style = function () {
53 MenuBar.prototype.style = function () {
29 this.element.addClass('border-box-sizing');
54 this.element.addClass('border-box-sizing');
30 $('ul#menus').menubar({
55 $('ul#menus').menubar({
31 select : function (event, ui) {
56 select : function (event, ui) {
32 // 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
33 // re-select it upon selection.
58 // re-select it upon selection.
34 var i = IPython.notebook.get_selected_index();
59 var i = IPython.notebook.get_selected_index();
35 IPython.notebook.select(i);
60 IPython.notebook.select(i);
36 }
61 }
37 });
62 });
38 };
63 };
39
64
40
65
41 MenuBar.prototype.bind_events = function () {
66 MenuBar.prototype.bind_events = function () {
42 // File
67 // File
43 this.element.find('#new_notebook').click(function () {
68 this.element.find('#new_notebook').click(function () {
44 window.open(this.baseProjectUrl()+'new');
69 window.open(this.baseProjectUrl()+'new');
45 });
70 });
46 this.element.find('#open_notebook').click(function () {
71 this.element.find('#open_notebook').click(function () {
47 window.open(this.baseProjectUrl());
72 window.open(this.baseProjectUrl());
48 });
73 });
49 this.element.find('#rename_notebook').click(function () {
74 this.element.find('#rename_notebook').click(function () {
50 IPython.save_widget.rename_notebook();
75 IPython.save_widget.rename_notebook();
51 });
76 });
52 this.element.find('#copy_notebook').click(function () {
77 this.element.find('#copy_notebook').click(function () {
53 var notebook_id = IPython.notebook.get_notebook_id();
78 var notebook_id = IPython.notebook.get_notebook_id();
54 var url = this.baseProjectUrl() + notebook_id + '/copy';
79 var url = this.baseProjectUrl() + notebook_id + '/copy';
55 window.open(url,'_blank');
80 window.open(url,'_blank');
56 return false;
81 return false;
57 });
82 });
58 this.element.find('#save_notebook').click(function () {
83 this.element.find('#save_notebook').click(function () {
59 IPython.notebook.save_notebook();
84 IPython.notebook.save_notebook();
60 });
85 });
61 this.element.find('#download_ipynb').click(function () {
86 this.element.find('#download_ipynb').click(function () {
62 var notebook_id = IPython.notebook.get_notebook_id();
87 var notebook_id = IPython.notebook.get_notebook_id();
63 var url = this.baseProjectUrl() + 'notebooks/' +
88 var url = this.baseProjectUrl() + 'notebooks/' +
64 notebook_id + '?format=json';
89 notebook_id + '?format=json';
65 window.location.assign(url);
90 window.location.assign(url);
66 });
91 });
67 this.element.find('#download_py').click(function () {
92 this.element.find('#download_py').click(function () {
68 var notebook_id = IPython.notebook.get_notebook_id();
93 var notebook_id = IPython.notebook.get_notebook_id();
69 var url = this.baseProjectUrl() + 'notebooks/' +
94 var url = this.baseProjectUrl() + 'notebooks/' +
70 notebook_id + '?format=py';
95 notebook_id + '?format=py';
71 window.location.assign(url);
96 window.location.assign(url);
72 });
97 });
73 this.element.find('button#print_notebook').click(function () {
98 this.element.find('button#print_notebook').click(function () {
74 IPython.print_widget.print_notebook();
99 IPython.print_widget.print_notebook();
75 });
100 });
76 this.element.find('#kill_and_exit').click(function () {
101 this.element.find('#kill_and_exit').click(function () {
77 IPython.notebook.kernel.kill();
102 IPython.notebook.kernel.kill();
78 setTimeout(function(){window.close();}, 200);
103 setTimeout(function(){window.close();}, 200);
79 });
104 });
80 // Edit
105 // Edit
81 this.element.find('#cut_cell').click(function () {
106 this.element.find('#cut_cell').click(function () {
82 IPython.notebook.cut_cell();
107 IPython.notebook.cut_cell();
83 });
108 });
84 this.element.find('#copy_cell').click(function () {
109 this.element.find('#copy_cell').click(function () {
85 IPython.notebook.copy_cell();
110 IPython.notebook.copy_cell();
86 });
111 });
87 this.element.find('#delete_cell').click(function () {
112 this.element.find('#delete_cell').click(function () {
88 IPython.notebook.delete_cell();
113 IPython.notebook.delete_cell();
89 });
114 });
90 this.element.find('#split_cell').click(function () {
115 this.element.find('#split_cell').click(function () {
91 IPython.notebook.split_cell();
116 IPython.notebook.split_cell();
92 });
117 });
93 this.element.find('#merge_cell_above').click(function () {
118 this.element.find('#merge_cell_above').click(function () {
94 IPython.notebook.merge_cell_above();
119 IPython.notebook.merge_cell_above();
95 });
120 });
96 this.element.find('#merge_cell_below').click(function () {
121 this.element.find('#merge_cell_below').click(function () {
97 IPython.notebook.merge_cell_below();
122 IPython.notebook.merge_cell_below();
98 });
123 });
99 this.element.find('#move_cell_up').click(function () {
124 this.element.find('#move_cell_up').click(function () {
100 IPython.notebook.move_cell_up();
125 IPython.notebook.move_cell_up();
101 });
126 });
102 this.element.find('#move_cell_down').click(function () {
127 this.element.find('#move_cell_down').click(function () {
103 IPython.notebook.move_cell_down();
128 IPython.notebook.move_cell_down();
104 });
129 });
105 this.element.find('#select_previous').click(function () {
130 this.element.find('#select_previous').click(function () {
106 IPython.notebook.select_prev();
131 IPython.notebook.select_prev();
107 });
132 });
108 this.element.find('#select_next').click(function () {
133 this.element.find('#select_next').click(function () {
109 IPython.notebook.select_next();
134 IPython.notebook.select_next();
110 });
135 });
111 // View
136 // View
112 this.element.find('#toggle_header').click(function () {
137 this.element.find('#toggle_header').click(function () {
113 $('div#header').toggle();
138 $('div#header').toggle();
114 IPython.layout_manager.do_resize();
139 IPython.layout_manager.do_resize();
115 });
140 });
116 this.element.find('#toggle_toolbar').click(function () {
141 this.element.find('#toggle_toolbar').click(function () {
117 IPython.toolbar.toggle();
142 IPython.toolbar.toggle();
118 });
143 });
119 // Insert
144 // Insert
120 this.element.find('#insert_cell_above').click(function () {
145 this.element.find('#insert_cell_above').click(function () {
121 IPython.notebook.insert_cell_above('code');
146 IPython.notebook.insert_cell_above('code');
122 });
147 });
123 this.element.find('#insert_cell_below').click(function () {
148 this.element.find('#insert_cell_below').click(function () {
124 IPython.notebook.insert_cell_below('code');
149 IPython.notebook.insert_cell_below('code');
125 });
150 });
126 // Cell
151 // Cell
127 this.element.find('#run_cell').click(function () {
152 this.element.find('#run_cell').click(function () {
128 IPython.notebook.execute_selected_cell();
153 IPython.notebook.execute_selected_cell();
129 });
154 });
130 this.element.find('#run_cell_in_place').click(function () {
155 this.element.find('#run_cell_in_place').click(function () {
131 IPython.notebook.execute_selected_cell({terminal:true});
156 IPython.notebook.execute_selected_cell({terminal:true});
132 });
157 });
133 this.element.find('#run_all_cells').click(function () {
158 this.element.find('#run_all_cells').click(function () {
134 IPython.notebook.execute_all_cells();
159 IPython.notebook.execute_all_cells();
135 }).attr('title', 'Run all cells in the notebook');
160 }).attr('title', 'Run all cells in the notebook');
136 this.element.find('#run_all_cells_above').click(function () {
161 this.element.find('#run_all_cells_above').click(function () {
137 IPython.notebook.execute_cells_above();
162 IPython.notebook.execute_cells_above();
138 }).attr('title', 'Run all cells above (but not including) this cell');
163 }).attr('title', 'Run all cells above (but not including) this cell');
139 this.element.find('#run_all_cells_below').click(function () {
164 this.element.find('#run_all_cells_below').click(function () {
140 IPython.notebook.execute_cells_below();
165 IPython.notebook.execute_cells_below();
141 }).attr('title', 'Run this cell and all cells below it');
166 }).attr('title', 'Run this cell and all cells below it');
142 this.element.find('#to_code').click(function () {
167 this.element.find('#to_code').click(function () {
143 IPython.notebook.to_code();
168 IPython.notebook.to_code();
144 });
169 });
145 this.element.find('#to_markdown').click(function () {
170 this.element.find('#to_markdown').click(function () {
146 IPython.notebook.to_markdown();
171 IPython.notebook.to_markdown();
147 });
172 });
148 this.element.find('#to_raw').click(function () {
173 this.element.find('#to_raw').click(function () {
149 IPython.notebook.to_raw();
174 IPython.notebook.to_raw();
150 });
175 });
151 this.element.find('#to_heading1').click(function () {
176 this.element.find('#to_heading1').click(function () {
152 IPython.notebook.to_heading(undefined, 1);
177 IPython.notebook.to_heading(undefined, 1);
153 });
178 });
154 this.element.find('#to_heading2').click(function () {
179 this.element.find('#to_heading2').click(function () {
155 IPython.notebook.to_heading(undefined, 2);
180 IPython.notebook.to_heading(undefined, 2);
156 });
181 });
157 this.element.find('#to_heading3').click(function () {
182 this.element.find('#to_heading3').click(function () {
158 IPython.notebook.to_heading(undefined, 3);
183 IPython.notebook.to_heading(undefined, 3);
159 });
184 });
160 this.element.find('#to_heading4').click(function () {
185 this.element.find('#to_heading4').click(function () {
161 IPython.notebook.to_heading(undefined, 4);
186 IPython.notebook.to_heading(undefined, 4);
162 });
187 });
163 this.element.find('#to_heading5').click(function () {
188 this.element.find('#to_heading5').click(function () {
164 IPython.notebook.to_heading(undefined, 5);
189 IPython.notebook.to_heading(undefined, 5);
165 });
190 });
166 this.element.find('#to_heading6').click(function () {
191 this.element.find('#to_heading6').click(function () {
167 IPython.notebook.to_heading(undefined, 6);
192 IPython.notebook.to_heading(undefined, 6);
168 });
193 });
169 this.element.find('#toggle_output').click(function () {
194 this.element.find('#toggle_output').click(function () {
170 IPython.notebook.toggle_output();
195 IPython.notebook.toggle_output();
171 });
196 });
172 this.element.find('#collapse_all_output').click(function () {
197 this.element.find('#collapse_all_output').click(function () {
173 IPython.notebook.collapse_all_output();
198 IPython.notebook.collapse_all_output();
174 });
199 });
175 this.element.find('#scroll_all_output').click(function () {
200 this.element.find('#scroll_all_output').click(function () {
176 IPython.notebook.scroll_all_output();
201 IPython.notebook.scroll_all_output();
177 });
202 });
178 this.element.find('#expand_all_output').click(function () {
203 this.element.find('#expand_all_output').click(function () {
179 IPython.notebook.expand_all_output();
204 IPython.notebook.expand_all_output();
180 });
205 });
181 this.element.find('#clear_all_output').click(function () {
206 this.element.find('#clear_all_output').click(function () {
182 IPython.notebook.clear_all_output();
207 IPython.notebook.clear_all_output();
183 });
208 });
184 // Kernel
209 // Kernel
185 this.element.find('#int_kernel').click(function () {
210 this.element.find('#int_kernel').click(function () {
186 IPython.notebook.kernel.interrupt();
211 IPython.notebook.kernel.interrupt();
187 });
212 });
188 this.element.find('#restart_kernel').click(function () {
213 this.element.find('#restart_kernel').click(function () {
189 IPython.notebook.restart_kernel();
214 IPython.notebook.restart_kernel();
190 });
215 });
191 // Help
216 // Help
192 this.element.find('#keyboard_shortcuts').click(function () {
217 this.element.find('#keyboard_shortcuts').click(function () {
193 IPython.quick_help.show_keyboard_shortcuts();
218 IPython.quick_help.show_keyboard_shortcuts();
194 });
219 });
195 };
220 };
196
221
197
222
198 IPython.MenuBar = MenuBar;
223 IPython.MenuBar = MenuBar;
199
224
200 return IPython;
225 return IPython;
201
226
202 }(IPython));
227 }(IPython));
General Comments 0
You need to be logged in to leave comments. Login now