Show More
@@ -46,22 +46,6 var IPython = (function (IPython) { | |||||
46 | }; |
|
46 | }; | |
47 |
|
47 | |||
48 |
|
48 | |||
49 | CellToolbar.dropdown_preset_element = $('<select/>') |
|
|||
50 | .addClass('ui-widget ui-widget-content') |
|
|||
51 | .attr('id', 'celltoolbar_selector') |
|
|||
52 | .append($('<option/>').attr('value', '').text('None')) |
|
|||
53 |
|
||||
54 |
|
||||
55 | CellToolbar.dropdown_preset_element.change(function() { |
|
|||
56 | var val = CellToolbar.dropdown_preset_element.val() |
|
|||
57 | if(val ==''){ |
|
|||
58 | CellToolbar.global_hide(); |
|
|||
59 | } else { |
|
|||
60 | CellToolbar.global_show(); |
|
|||
61 | CellToolbar.activate_preset(val); |
|
|||
62 | } |
|
|||
63 | }) |
|
|||
64 |
|
||||
65 | // The default css style for the outer celltoolbar div |
|
49 | // The default css style for the outer celltoolbar div | |
66 | // (ctb_hideshow) is display: none. We add the ctb_show |
|
50 | // (ctb_hideshow) is display: none. We add the ctb_show | |
67 | // class to either 1) the body to show all cell's toolbars |
|
51 | // class to either 1) the body to show all cell's toolbars | |
@@ -98,6 +82,7 var IPython = (function (IPython) { | |||||
98 | */ |
|
82 | */ | |
99 | CellToolbar._callback_dict = {}; |
|
83 | CellToolbar._callback_dict = {}; | |
100 |
|
84 | |||
|
85 | ||||
101 | /** |
|
86 | /** | |
102 | * Class variable that should contain the reverse order list of the button |
|
87 | * Class variable that should contain the reverse order list of the button | |
103 | * to add to the toolbar of each cell |
|
88 | * to add to the toolbar of each cell | |
@@ -108,6 +93,7 var IPython = (function (IPython) { | |||||
108 | */ |
|
93 | */ | |
109 | CellToolbar._ui_controls_list = []; |
|
94 | CellToolbar._ui_controls_list = []; | |
110 |
|
95 | |||
|
96 | ||||
111 | /** |
|
97 | /** | |
112 | * Class variable that should contains the CellToolbar instances for each |
|
98 | * Class variable that should contains the CellToolbar instances for each | |
113 | * cell of the notebook |
|
99 | * cell of the notebook | |
@@ -119,6 +105,7 var IPython = (function (IPython) { | |||||
119 | */ |
|
105 | */ | |
120 | CellToolbar._instances =[] |
|
106 | CellToolbar._instances =[] | |
121 |
|
107 | |||
|
108 | ||||
122 | /** |
|
109 | /** | |
123 | * keep a list of all the availlabel presets for the toolbar |
|
110 | * keep a list of all the availlabel presets for the toolbar | |
124 | * @private |
|
111 | * @private | |
@@ -128,6 +115,7 var IPython = (function (IPython) { | |||||
128 | */ |
|
115 | */ | |
129 | CellToolbar._presets ={} |
|
116 | CellToolbar._presets ={} | |
130 |
|
117 | |||
|
118 | ||||
131 | // this is by design not a prototype. |
|
119 | // this is by design not a prototype. | |
132 | /** |
|
120 | /** | |
133 | * Register a callback to create an UI element in a cell toolbar. |
|
121 | * Register a callback to create an UI element in a cell toolbar. | |
@@ -175,6 +163,7 var IPython = (function (IPython) { | |||||
175 | CellToolbar._callback_dict[name] = callback; |
|
163 | CellToolbar._callback_dict[name] = callback; | |
176 | }; |
|
164 | }; | |
177 |
|
165 | |||
|
166 | ||||
178 | /** |
|
167 | /** | |
179 | * Register a preset of UI element in a cell toolbar. |
|
168 | * Register a preset of UI element in a cell toolbar. | |
180 | * Not supported Yet. |
|
169 | * Not supported Yet. | |
@@ -196,12 +185,28 var IPython = (function (IPython) { | |||||
196 | * CellToolbar.register_preset('foo.foo_preset1', ['foo.c1', 'foo.c2', 'foo.c5']) |
|
185 | * CellToolbar.register_preset('foo.foo_preset1', ['foo.c1', 'foo.c2', 'foo.c5']) | |
197 | * CellToolbar.register_preset('foo.foo_preset2', ['foo.c4', 'foo.c5']) |
|
186 | * CellToolbar.register_preset('foo.foo_preset2', ['foo.c4', 'foo.c5']) | |
198 | */ |
|
187 | */ | |
199 | CellToolbar.register_preset = function(name, preset_list){ |
|
188 | CellToolbar.register_preset = function(name, preset_list) { | |
200 | CellToolbar._presets[name] = preset_list |
|
189 | CellToolbar._presets[name] = preset_list | |
201 | CellToolbar.dropdown_preset_element.append( |
|
190 | $([IPython.events]).trigger('preset_added.CellToolbar', {name: name}); | |
202 | $('<option/>').attr('value', name).text(name) |
|
191 | }; | |
203 | ) |
|
192 | ||
204 | } |
|
193 | ||
|
194 | /** | |||
|
195 | * List the names of the presets that are currently registered. | |||
|
196 | * | |||
|
197 | * @method list_presets | |||
|
198 | * @static | |||
|
199 | */ | |||
|
200 | CellToolbar.list_presets = function() { | |||
|
201 | var keys = []; | |||
|
202 | for (var k in CellToolbar._presets) { | |||
|
203 | keys.push(k); | |||
|
204 | } | |||
|
205 | console.log(keys); | |||
|
206 | return keys; | |||
|
207 | }; | |||
|
208 | ||||
|
209 | ||||
205 | /** |
|
210 | /** | |
206 | * Activate an UI preset from `register_preset` |
|
211 | * Activate an UI preset from `register_preset` | |
207 | * |
|
212 | * | |
@@ -226,7 +231,6 var IPython = (function (IPython) { | |||||
226 | } |
|
231 | } | |
227 |
|
232 | |||
228 |
|
233 | |||
229 | // this is by design not a prototype. |
|
|||
230 | /** |
|
234 | /** | |
231 | * This should be called on the class and not on a instance as it will trigger |
|
235 | * This should be called on the class and not on a instance as it will trigger | |
232 | * rebuild of all the instances. |
|
236 | * rebuild of all the instances. | |
@@ -260,7 +264,6 var IPython = (function (IPython) { | |||||
260 | this.inner_element.append(local_div) |
|
264 | this.inner_element.append(local_div) | |
261 | cdict[preset[index]](local_div, this.cell) |
|
265 | cdict[preset[index]](local_div, this.cell) | |
262 | } |
|
266 | } | |
263 |
|
||||
264 | } |
|
267 | } | |
265 |
|
268 | |||
266 |
|
269 | |||
@@ -268,6 +271,7 var IPython = (function (IPython) { | |||||
268 | */ |
|
271 | */ | |
269 | CellToolbar.utils = {}; |
|
272 | CellToolbar.utils = {}; | |
270 |
|
273 | |||
|
274 | ||||
271 | /** |
|
275 | /** | |
272 | * A utility function to generate bindings between a checkbox and cell/metadata |
|
276 | * A utility function to generate bindings between a checkbox and cell/metadata | |
273 | * @method utils.checkbox_ui_generator |
|
277 | * @method utils.checkbox_ui_generator | |
@@ -324,6 +328,7 var IPython = (function (IPython) { | |||||
324 | } |
|
328 | } | |
325 | } |
|
329 | } | |
326 |
|
330 | |||
|
331 | ||||
327 | /** |
|
332 | /** | |
328 | * A utility function to generate bindings between a dropdown list cell |
|
333 | * A utility function to generate bindings between a dropdown list cell | |
329 | * @method utils.select_ui_generator |
|
334 | * @method utils.select_ui_generator |
@@ -89,6 +89,6 | |||||
89 | example_preset.push('default.rawedit'); |
|
89 | example_preset.push('default.rawedit'); | |
90 |
|
90 | |||
91 | CellToolbar.register_preset('Default',example_preset); |
|
91 | CellToolbar.register_preset('Default',example_preset); | |
92 |
console.log('Default extension for metadata edit |
|
92 | console.log('Default extension for metadata editing loaded.'); | |
93 |
|
93 | |||
94 | }(IPython)); |
|
94 | }(IPython)); |
@@ -12,14 +12,11 | |||||
12 | var IPython = (function (IPython) { |
|
12 | var IPython = (function (IPython) { | |
13 |
|
13 | |||
14 | var MainToolBar = function (selector) { |
|
14 | var MainToolBar = function (selector) { | |
15 | this.selector = selector; |
|
|||
16 | IPython.ToolBar.apply(this, arguments); |
|
15 | IPython.ToolBar.apply(this, arguments); | |
17 | this.construct(); |
|
16 | this.construct(); | |
18 |
this.add_ |
|
17 | this.add_celltype_list(); | |
|
18 | this.add_celltoolbar_list(); | |||
19 | this.bind_events(); |
|
19 | this.bind_events(); | |
20 | $(this.selector) |
|
|||
21 | .append($('<label/>').text('Cell Toolbar:')) |
|
|||
22 | .append(IPython.CellToolbar.dropdown_preset_element) |
|
|||
23 | }; |
|
20 | }; | |
24 |
|
21 | |||
25 | MainToolBar.prototype = new IPython.ToolBar(); |
|
22 | MainToolBar.prototype = new IPython.ToolBar(); | |
@@ -120,23 +117,54 var IPython = (function (IPython) { | |||||
120 | ],'run_int'); |
|
117 | ],'run_int'); | |
121 | }; |
|
118 | }; | |
122 |
|
119 | |||
123 |
MainToolBar.prototype.add_ |
|
120 | MainToolBar.prototype.add_celltype_list = function () { | |
124 | var select = $(this.selector) |
|
121 | this.element | |
125 | .append($('<select/>') |
|
122 | .append($('<select/>') | |
126 | .attr('id','cell_type') |
|
123 | .attr('id','cell_type') | |
127 | .addClass('ui-widget ui-widget-content') |
|
124 | .addClass('ui-widget ui-widget-content') | |
128 |
|
|
125 | .append($('<option/>').attr('value','code').text('Code')) | |
129 |
|
|
126 | .append($('<option/>').attr('value','markdown').text('Markdown')) | |
130 |
|
|
127 | .append($('<option/>').attr('value','raw').text('Raw Text')) | |
131 |
|
|
128 | .append($('<option/>').attr('value','heading1').text('Heading 1')) | |
132 |
|
|
129 | .append($('<option/>').attr('value','heading2').text('Heading 2')) | |
133 |
|
|
130 | .append($('<option/>').attr('value','heading3').text('Heading 3')) | |
134 |
|
|
131 | .append($('<option/>').attr('value','heading4').text('Heading 4')) | |
135 |
|
|
132 | .append($('<option/>').attr('value','heading5').text('Heading 5')) | |
136 |
|
|
133 | .append($('<option/>').attr('value','heading6').text('Heading 6')) | |
137 |
|
|
134 | ); | |
138 | }; |
|
135 | }; | |
139 |
|
136 | |||
|
137 | ||||
|
138 | MainToolBar.prototype.add_celltoolbar_list = function () { | |||
|
139 | var label = $('<label/>').text('Cell Toolbar:'); | |||
|
140 | var select = $('<select/>') | |||
|
141 | .addClass('ui-widget ui-widget-content') | |||
|
142 | .attr('id', 'ctb_select') | |||
|
143 | .append($('<option/>').attr('value', '').text('None')); | |||
|
144 | this.element.append(label).append(select); | |||
|
145 | select.change(function() { | |||
|
146 | var val = $(this).val() | |||
|
147 | if (val =='') { | |||
|
148 | IPython.CellToolbar.global_hide(); | |||
|
149 | } else { | |||
|
150 | IPython.CellToolbar.global_show(); | |||
|
151 | IPython.CellToolbar.activate_preset(val); | |||
|
152 | } | |||
|
153 | }); | |||
|
154 | // Setup the currently registered presets. | |||
|
155 | var presets = IPython.CellToolbar.list_presets(); | |||
|
156 | for (var i=0; i<presets.length; i++) { | |||
|
157 | var name = presets[i]; | |||
|
158 | select.append($('<option/>').attr('value', name).text(name)); | |||
|
159 | } | |||
|
160 | // Setup future preset registrations. | |||
|
161 | $([IPython.events]).on('preset_added.CellToolbar', function (event, data) { | |||
|
162 | var name = data.name; | |||
|
163 | select.append($('<option/>').attr('value', name).text(name)); | |||
|
164 | }); | |||
|
165 | }; | |||
|
166 | ||||
|
167 | ||||
140 | MainToolBar.prototype.bind_events = function () { |
|
168 | MainToolBar.prototype.bind_events = function () { | |
141 | var that = this; |
|
169 | var that = this; | |
142 |
|
170 |
General Comments 0
You need to be logged in to leave comments.
Login now