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