##// END OF EJS Templates
Hide the cell toolbar if there are no ui controls in it.
Raffaele De Feo -
Show More
@@ -1,414 +1,422
1 //----------------------------------------------------------------------------
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2012 The IPython Development Team
2 // Copyright (C) 2012 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 // CellToolbar
9 // CellToolbar
10 //============================================================================
10 //============================================================================
11
11
12
12
13 /**
13 /**
14 * A Module to control the per-cell toolbar.
14 * A Module to control the per-cell toolbar.
15 * @module IPython
15 * @module IPython
16 * @namespace IPython
16 * @namespace IPython
17 * @submodule CellToolbar
17 * @submodule CellToolbar
18 */
18 */
19 var IPython = (function (IPython) {
19 var IPython = (function (IPython) {
20 "use strict";
20 "use strict";
21
21
22 /**
22 /**
23 * @constructor
23 * @constructor
24 * @class CellToolbar
24 * @class CellToolbar
25 * @param {The cell to attach the metadata UI to} cell
25 * @param {The cell to attach the metadata UI to} cell
26 */
26 */
27 var CellToolbar = function (cell) {
27 var CellToolbar = function (cell) {
28 CellToolbar._instances.push(this);
28 CellToolbar._instances.push(this);
29 this.cell = cell;
29 this.cell = cell;
30 this.create_element();
30 this.create_element();
31 this.rebuild();
31 this.rebuild();
32 return this;
32 return this;
33 };
33 };
34
34
35
35
36 CellToolbar.prototype.create_element = function () {
36 CellToolbar.prototype.create_element = function () {
37 this.inner_element = $('<div/>').addClass('celltoolbar')
37 this.inner_element = $('<div/>').addClass('celltoolbar')
38 this.element = $('<div/>').addClass('ctb_hideshow')
38 this.element = $('<div/>').addClass('ctb_hideshow')
39 .append(this.inner_element);
39 .append(this.inner_element);
40 this.show();
41 };
40 };
42
41
43
42
44 // The default css style for the outer celltoolbar div
43 // The default css style for the outer celltoolbar div
45 // (ctb_hideshow) is display: none.
44 // (ctb_hideshow) is display: none.
46 // To show the cell toolbar, *both* of the following conditions must be met:
45 // To show the cell toolbar, *both* of the following conditions must be met:
47 // - A parent container has class `ctb_global_show`
46 // - A parent container has class `ctb_global_show`
48 // - The celltoolbar has the class `ctb_show`
47 // - The celltoolbar has the class `ctb_show`
49 // This allows global show/hide, as well as per-cell show/hide.
48 // This allows global show/hide, as well as per-cell show/hide.
50
49
51 CellToolbar.global_hide = function () {
50 CellToolbar.global_hide = function () {
52 $('body').removeClass('ctb_global_show');
51 $('body').removeClass('ctb_global_show');
53 };
52 };
54
53
55
54
56 CellToolbar.global_show = function () {
55 CellToolbar.global_show = function () {
57 $('body').addClass('ctb_global_show');
56 $('body').addClass('ctb_global_show');
58 };
57 };
59
58
60
59
61 CellToolbar.prototype.hide = function () {
60 CellToolbar.prototype.hide = function () {
62 this.element.removeClass('ctb_show');
61 this.element.removeClass('ctb_show');
63 };
62 };
64
63
65
64
66 CellToolbar.prototype.show = function () {
65 CellToolbar.prototype.show = function () {
67 this.element.addClass('ctb_show');
66 this.element.addClass('ctb_show');
68 };
67 };
69
68
70
69
71 /**
70 /**
72 * Class variable that should contain a dict of all available callback
71 * Class variable that should contain a dict of all available callback
73 * we need to think of wether or not we allow nested namespace
72 * we need to think of wether or not we allow nested namespace
74 * @property _callback_dict
73 * @property _callback_dict
75 * @private
74 * @private
76 * @static
75 * @static
77 * @type Dict
76 * @type Dict
78 */
77 */
79 CellToolbar._callback_dict = {};
78 CellToolbar._callback_dict = {};
80
79
81
80
82 /**
81 /**
83 * Class variable that should contain the reverse order list of the button
82 * Class variable that should contain the reverse order list of the button
84 * to add to the toolbar of each cell
83 * to add to the toolbar of each cell
85 * @property _ui_controls_list
84 * @property _ui_controls_list
86 * @private
85 * @private
87 * @static
86 * @static
88 * @type List
87 * @type List
89 */
88 */
90 CellToolbar._ui_controls_list = [];
89 CellToolbar._ui_controls_list = [];
91
90
92
91
93 /**
92 /**
94 * Class variable that should contain the CellToolbar instances for each
93 * Class variable that should contain the CellToolbar instances for each
95 * cell of the notebook
94 * cell of the notebook
96 *
95 *
97 * @private
96 * @private
98 * @property _instances
97 * @property _instances
99 * @static
98 * @static
100 * @type List
99 * @type List
101 */
100 */
102 CellToolbar._instances = [];
101 CellToolbar._instances = [];
103
102
104
103
105 /**
104 /**
106 * keep a list of all the available presets for the toolbar
105 * keep a list of all the available presets for the toolbar
107 * @private
106 * @private
108 * @property _presets
107 * @property _presets
109 * @static
108 * @static
110 * @type Dict
109 * @type Dict
111 */
110 */
112 CellToolbar._presets = {};
111 CellToolbar._presets = {};
113
112
114
113
115 // this is by design not a prototype.
114 // this is by design not a prototype.
116 /**
115 /**
117 * Register a callback to create an UI element in a cell toolbar.
116 * Register a callback to create an UI element in a cell toolbar.
118 * @method register_callback
117 * @method register_callback
119 * @param name {String} name to use to refer to the callback. It is advised to use a prefix with the name
118 * @param name {String} name to use to refer to the callback. It is advised to use a prefix with the name
120 * for easier sorting and avoid collision
119 * for easier sorting and avoid collision
121 * @param callback {function(div, cell)} callback that will be called to generate the ui element
120 * @param callback {function(div, cell)} callback that will be called to generate the ui element
122 * @param [cell_types] {List of String|undefined} optional list of cell types. If present the UI element
121 * @param [cell_types] {List of String|undefined} optional list of cell types. If present the UI element
123 * will be added only to cells of types in the list.
122 * will be added only to cells of types in the list.
124 *
123 *
125 *
124 *
126 * The callback will receive the following element :
125 * The callback will receive the following element :
127 *
126 *
128 * * a div in which to add element.
127 * * a div in which to add element.
129 * * the cell it is responsible from
128 * * the cell it is responsible from
130 *
129 *
131 * @example
130 * @example
132 *
131 *
133 * Example that create callback for a button that toggle between `true` and `false` label,
132 * Example that create callback for a button that toggle between `true` and `false` label,
134 * with the metadata under the key 'foo' to reflect the status of the button.
133 * with the metadata under the key 'foo' to reflect the status of the button.
135 *
134 *
136 * // first param reference to a DOM div
135 * // first param reference to a DOM div
137 * // second param reference to the cell.
136 * // second param reference to the cell.
138 * var toggle = function(div, cell) {
137 * var toggle = function(div, cell) {
139 * var button_container = $(div)
138 * var button_container = $(div)
140 *
139 *
141 * // let's create a button that show the current value of the metadata
140 * // let's create a button that show the current value of the metadata
142 * var button = $('<div/>').button({label:String(cell.metadata.foo)});
141 * var button = $('<div/>').button({label:String(cell.metadata.foo)});
143 *
142 *
144 * // On click, change the metadata value and update the button label
143 * // On click, change the metadata value and update the button label
145 * button.click(function(){
144 * button.click(function(){
146 * var v = cell.metadata.foo;
145 * var v = cell.metadata.foo;
147 * cell.metadata.foo = !v;
146 * cell.metadata.foo = !v;
148 * button.button("option", "label", String(!v));
147 * button.button("option", "label", String(!v));
149 * })
148 * })
150 *
149 *
151 * // add the button to the DOM div.
150 * // add the button to the DOM div.
152 * button_container.append(button);
151 * button_container.append(button);
153 * }
152 * }
154 *
153 *
155 * // now we register the callback under the name `foo` to give the
154 * // now we register the callback under the name `foo` to give the
156 * // user the ability to use it later
155 * // user the ability to use it later
157 * CellToolbar.register_callback('foo', toggle);
156 * CellToolbar.register_callback('foo', toggle);
158 */
157 */
159 CellToolbar.register_callback = function(name, callback, cell_types) {
158 CellToolbar.register_callback = function(name, callback, cell_types) {
160 // Overwrite if it already exists.
159 // Overwrite if it already exists.
161 CellToolbar._callback_dict[name] = cell_types ? {callback: callback, cell_types: cell_types} : callback;
160 CellToolbar._callback_dict[name] = cell_types ? {callback: callback, cell_types: cell_types} : callback;
162 };
161 };
163
162
164
163
165 /**
164 /**
166 * Register a preset of UI element in a cell toolbar.
165 * Register a preset of UI element in a cell toolbar.
167 * Not supported Yet.
166 * Not supported Yet.
168 * @method register_preset
167 * @method register_preset
169 * @param name {String} name to use to refer to the preset. It is advised to use a prefix with the name
168 * @param name {String} name to use to refer to the preset. It is advised to use a prefix with the name
170 * for easier sorting and avoid collision
169 * for easier sorting and avoid collision
171 * @param preset_list {List of String} reverse order of the button in the toolbar. Each String of the list
170 * @param preset_list {List of String} reverse order of the button in the toolbar. Each String of the list
172 * should correspond to a name of a registerd callback.
171 * should correspond to a name of a registerd callback.
173 *
172 *
174 * @private
173 * @private
175 * @example
174 * @example
176 *
175 *
177 * CellToolbar.register_callback('foo.c1', function(div, cell){...});
176 * CellToolbar.register_callback('foo.c1', function(div, cell){...});
178 * CellToolbar.register_callback('foo.c2', function(div, cell){...});
177 * CellToolbar.register_callback('foo.c2', function(div, cell){...});
179 * CellToolbar.register_callback('foo.c3', function(div, cell){...});
178 * CellToolbar.register_callback('foo.c3', function(div, cell){...});
180 * CellToolbar.register_callback('foo.c4', function(div, cell){...});
179 * CellToolbar.register_callback('foo.c4', function(div, cell){...});
181 * CellToolbar.register_callback('foo.c5', function(div, cell){...});
180 * CellToolbar.register_callback('foo.c5', function(div, cell){...});
182 *
181 *
183 * CellToolbar.register_preset('foo.foo_preset1', ['foo.c1', 'foo.c2', 'foo.c5'])
182 * CellToolbar.register_preset('foo.foo_preset1', ['foo.c1', 'foo.c2', 'foo.c5'])
184 * CellToolbar.register_preset('foo.foo_preset2', ['foo.c4', 'foo.c5'])
183 * CellToolbar.register_preset('foo.foo_preset2', ['foo.c4', 'foo.c5'])
185 */
184 */
186 CellToolbar.register_preset = function(name, preset_list) {
185 CellToolbar.register_preset = function(name, preset_list) {
187 CellToolbar._presets[name] = preset_list;
186 CellToolbar._presets[name] = preset_list;
188 $([IPython.events]).trigger('preset_added.CellToolbar', {name: name});
187 $([IPython.events]).trigger('preset_added.CellToolbar', {name: name});
189 };
188 };
190
189
191
190
192 /**
191 /**
193 * List the names of the presets that are currently registered.
192 * List the names of the presets that are currently registered.
194 *
193 *
195 * @method list_presets
194 * @method list_presets
196 * @static
195 * @static
197 */
196 */
198 CellToolbar.list_presets = function() {
197 CellToolbar.list_presets = function() {
199 var keys = [];
198 var keys = [];
200 for (var k in CellToolbar._presets) {
199 for (var k in CellToolbar._presets) {
201 keys.push(k);
200 keys.push(k);
202 }
201 }
203 return keys;
202 return keys;
204 };
203 };
205
204
206
205
207 /**
206 /**
208 * Activate an UI preset from `register_preset`
207 * Activate an UI preset from `register_preset`
209 *
208 *
210 * This does not update the selection UI.
209 * This does not update the selection UI.
211 *
210 *
212 * @method activate_preset
211 * @method activate_preset
213 * @param preset_name {String} string corresponding to the preset name
212 * @param preset_name {String} string corresponding to the preset name
214 *
213 *
215 * @static
214 * @static
216 * @private
215 * @private
217 * @example
216 * @example
218 *
217 *
219 * CellToolbar.activate_preset('foo.foo_preset1');
218 * CellToolbar.activate_preset('foo.foo_preset1');
220 */
219 */
221 CellToolbar.activate_preset = function(preset_name){
220 CellToolbar.activate_preset = function(preset_name){
222 var preset = CellToolbar._presets[preset_name];
221 var preset = CellToolbar._presets[preset_name];
223
222
224 if(preset !== undefined){
223 if(preset !== undefined){
225 CellToolbar._ui_controls_list = preset;
224 CellToolbar._ui_controls_list = preset;
226 CellToolbar.rebuild_all();
225 CellToolbar.rebuild_all();
227 }
226 }
228 };
227 };
229
228
230
229
231 /**
230 /**
232 * This should be called on the class and not on a instance as it will trigger
231 * This should be called on the class and not on a instance as it will trigger
233 * rebuild of all the instances.
232 * rebuild of all the instances.
234 * @method rebuild_all
233 * @method rebuild_all
235 * @static
234 * @static
236 *
235 *
237 */
236 */
238 CellToolbar.rebuild_all = function(){
237 CellToolbar.rebuild_all = function(){
239 for(var i=0; i < CellToolbar._instances.length; i++){
238 for(var i=0; i < CellToolbar._instances.length; i++){
240 CellToolbar._instances[i].rebuild();
239 CellToolbar._instances[i].rebuild();
241 }
240 }
242 };
241 };
243
242
244 /**
243 /**
245 * Rebuild all the button on the toolbar to update its state.
244 * Rebuild all the button on the toolbar to update its state.
246 * @method rebuild
245 * @method rebuild
247 */
246 */
248 CellToolbar.prototype.rebuild = function(){
247 CellToolbar.prototype.rebuild = function(){
249 // strip evrything from the div
248 // strip evrything from the div
250 // which is probably inner_element
249 // which is probably inner_element
251 // or this.element.
250 // or this.element.
252 this.inner_element.empty();
251 this.inner_element.empty();
252 this.ui_controls_list = [];
253
253
254 var callbacks = CellToolbar._callback_dict;
254 var callbacks = CellToolbar._callback_dict;
255 var preset = CellToolbar._ui_controls_list;
255 var preset = CellToolbar._ui_controls_list;
256 // Yes we iterate on the class variable, not the instance one.
256 // Yes we iterate on the class variable, not the instance one.
257 for (var i=0; i < preset.length; i++) {
257 for (var i=0; i < preset.length; i++) {
258 var key = preset[i];
258 var key = preset[i];
259 var callback = callbacks[key];
259 var callback = callbacks[key];
260 if (!callback) continue;
260 if (!callback) continue;
261
261
262 if (typeof callback === 'object') {
262 if (typeof callback === 'object') {
263 if (callback.cell_types.indexOf(this.cell.cell_type) === -1) continue;
263 if (callback.cell_types.indexOf(this.cell.cell_type) === -1) continue;
264 callback = callback.callback;
264 callback = callback.callback;
265 }
265 }
266
266
267 var local_div = $('<div/>').addClass('button_container');
267 var local_div = $('<div/>').addClass('button_container');
268 try {
268 try {
269 callback(local_div, this.cell, this);
269 callback(local_div, this.cell, this);
270 this.ui_controls_list.push(key);
270 } catch (e) {
271 } catch (e) {
271 console.log("Error in cell toolbar callback " + key, e);
272 console.log("Error in cell toolbar callback " + key, e);
272 continue;
273 continue;
273 }
274 }
274 // only append if callback succeeded.
275 // only append if callback succeeded.
275 this.inner_element.append(local_div);
276 this.inner_element.append(local_div);
276 }
277 }
278
279 // If there are no controls hide the toolbar.
280 if (this.ui_controls_list.length) {
281 this.show();
282 } else {
283 this.hide();
284 }
277 };
285 };
278
286
279
287
280 /**
288 /**
281 */
289 */
282 CellToolbar.utils = {};
290 CellToolbar.utils = {};
283
291
284
292
285 /**
293 /**
286 * A utility function to generate bindings between a checkbox and cell/metadata
294 * A utility function to generate bindings between a checkbox and cell/metadata
287 * @method utils.checkbox_ui_generator
295 * @method utils.checkbox_ui_generator
288 * @static
296 * @static
289 *
297 *
290 * @param name {string} Label in front of the checkbox
298 * @param name {string} Label in front of the checkbox
291 * @param setter {function( cell, newValue )}
299 * @param setter {function( cell, newValue )}
292 * A setter method to set the newValue
300 * A setter method to set the newValue
293 * @param getter {function( cell )}
301 * @param getter {function( cell )}
294 * A getter methods which return the current value.
302 * A getter methods which return the current value.
295 *
303 *
296 * @return callback {function( div, cell )} Callback to be passed to `register_callback`
304 * @return callback {function( div, cell )} Callback to be passed to `register_callback`
297 *
305 *
298 * @example
306 * @example
299 *
307 *
300 * An exmple that bind the subkey `slideshow.isSectionStart` to a checkbox with a `New Slide` label
308 * An exmple that bind the subkey `slideshow.isSectionStart` to a checkbox with a `New Slide` label
301 *
309 *
302 * var newSlide = CellToolbar.utils.checkbox_ui_generator('New Slide',
310 * var newSlide = CellToolbar.utils.checkbox_ui_generator('New Slide',
303 * // setter
311 * // setter
304 * function(cell, value){
312 * function(cell, value){
305 * // we check that the slideshow namespace exist and create it if needed
313 * // we check that the slideshow namespace exist and create it if needed
306 * if (cell.metadata.slideshow == undefined){cell.metadata.slideshow = {}}
314 * if (cell.metadata.slideshow == undefined){cell.metadata.slideshow = {}}
307 * // set the value
315 * // set the value
308 * cell.metadata.slideshow.isSectionStart = value
316 * cell.metadata.slideshow.isSectionStart = value
309 * },
317 * },
310 * //geter
318 * //geter
311 * function(cell){ var ns = cell.metadata.slideshow;
319 * function(cell){ var ns = cell.metadata.slideshow;
312 * // if the slideshow namespace does not exist return `undefined`
320 * // if the slideshow namespace does not exist return `undefined`
313 * // (will be interpreted as `false` by checkbox) otherwise
321 * // (will be interpreted as `false` by checkbox) otherwise
314 * // return the value
322 * // return the value
315 * return (ns == undefined)? undefined: ns.isSectionStart
323 * return (ns == undefined)? undefined: ns.isSectionStart
316 * }
324 * }
317 * );
325 * );
318 *
326 *
319 * CellToolbar.register_callback('newSlide', newSlide);
327 * CellToolbar.register_callback('newSlide', newSlide);
320 *
328 *
321 */
329 */
322 CellToolbar.utils.checkbox_ui_generator = function(name, setter, getter){
330 CellToolbar.utils.checkbox_ui_generator = function(name, setter, getter){
323 return function(div, cell, celltoolbar) {
331 return function(div, cell, celltoolbar) {
324 var button_container = $(div);
332 var button_container = $(div);
325
333
326 var chkb = $('<input/>').attr('type', 'checkbox');
334 var chkb = $('<input/>').attr('type', 'checkbox');
327 var lbl = $('<label/>').append($('<span/>').text(name));
335 var lbl = $('<label/>').append($('<span/>').text(name));
328 lbl.append(chkb);
336 lbl.append(chkb);
329 chkb.attr("checked", getter(cell));
337 chkb.attr("checked", getter(cell));
330
338
331 chkb.click(function(){
339 chkb.click(function(){
332 var v = getter(cell);
340 var v = getter(cell);
333 setter(cell, !v);
341 setter(cell, !v);
334 chkb.attr("checked", !v);
342 chkb.attr("checked", !v);
335 });
343 });
336 button_container.append($('<div/>').append(lbl));
344 button_container.append($('<div/>').append(lbl));
337 };
345 };
338 };
346 };
339
347
340
348
341 /**
349 /**
342 * A utility function to generate bindings between a dropdown list cell
350 * A utility function to generate bindings between a dropdown list cell
343 * @method utils.select_ui_generator
351 * @method utils.select_ui_generator
344 * @static
352 * @static
345 *
353 *
346 * @param list_list {list of sublist} List of sublist of metadata value and name in the dropdown list.
354 * @param list_list {list of sublist} List of sublist of metadata value and name in the dropdown list.
347 * subslit shoud contain 2 element each, first a string that woul be displayed in the dropdown list,
355 * subslit shoud contain 2 element each, first a string that woul be displayed in the dropdown list,
348 * and second the corresponding value to be passed to setter/return by getter. the corresponding value
356 * and second the corresponding value to be passed to setter/return by getter. the corresponding value
349 * should not be "undefined" or behavior can be unexpected.
357 * should not be "undefined" or behavior can be unexpected.
350 * @param setter {function( cell, newValue )}
358 * @param setter {function( cell, newValue )}
351 * A setter method to set the newValue
359 * A setter method to set the newValue
352 * @param getter {function( cell )}
360 * @param getter {function( cell )}
353 * A getter methods which return the current value of the metadata.
361 * A getter methods which return the current value of the metadata.
354 * @param [label=""] {String} optionnal label for the dropdown menu
362 * @param [label=""] {String} optionnal label for the dropdown menu
355 *
363 *
356 * @return callback {function( div, cell )} Callback to be passed to `register_callback`
364 * @return callback {function( div, cell )} Callback to be passed to `register_callback`
357 *
365 *
358 * @example
366 * @example
359 *
367 *
360 * var select_type = CellToolbar.utils.select_ui_generator([
368 * var select_type = CellToolbar.utils.select_ui_generator([
361 * ["<None>" , "None" ],
369 * ["<None>" , "None" ],
362 * ["Header Slide" , "header_slide" ],
370 * ["Header Slide" , "header_slide" ],
363 * ["Slide" , "slide" ],
371 * ["Slide" , "slide" ],
364 * ["Fragment" , "fragment" ],
372 * ["Fragment" , "fragment" ],
365 * ["Skip" , "skip" ],
373 * ["Skip" , "skip" ],
366 * ],
374 * ],
367 * // setter
375 * // setter
368 * function(cell, value){
376 * function(cell, value){
369 * // we check that the slideshow namespace exist and create it if needed
377 * // we check that the slideshow namespace exist and create it if needed
370 * if (cell.metadata.slideshow == undefined){cell.metadata.slideshow = {}}
378 * if (cell.metadata.slideshow == undefined){cell.metadata.slideshow = {}}
371 * // set the value
379 * // set the value
372 * cell.metadata.slideshow.slide_type = value
380 * cell.metadata.slideshow.slide_type = value
373 * },
381 * },
374 * //geter
382 * //geter
375 * function(cell){ var ns = cell.metadata.slideshow;
383 * function(cell){ var ns = cell.metadata.slideshow;
376 * // if the slideshow namespace does not exist return `undefined`
384 * // if the slideshow namespace does not exist return `undefined`
377 * // (will be interpreted as `false` by checkbox) otherwise
385 * // (will be interpreted as `false` by checkbox) otherwise
378 * // return the value
386 * // return the value
379 * return (ns == undefined)? undefined: ns.slide_type
387 * return (ns == undefined)? undefined: ns.slide_type
380 * }
388 * }
381 * CellToolbar.register_callback('slideshow.select', select_type);
389 * CellToolbar.register_callback('slideshow.select', select_type);
382 *
390 *
383 */
391 */
384 CellToolbar.utils.select_ui_generator = function(list_list, setter, getter, label, cell_types){
392 CellToolbar.utils.select_ui_generator = function(list_list, setter, getter, label, cell_types){
385 label = label || "";
393 label = label || "";
386 return function(div, cell, celltoolbar) {
394 return function(div, cell, celltoolbar) {
387 var button_container = $(div);
395 var button_container = $(div);
388 var lbl = $("<label/>").append($('<span/>').text(label));
396 var lbl = $("<label/>").append($('<span/>').text(label));
389 var select = $('<select/>').addClass('ui-widget ui-widget-content');
397 var select = $('<select/>').addClass('ui-widget ui-widget-content');
390 for(var i=0; i < list_list.length; i++){
398 for(var i=0; i < list_list.length; i++){
391 var opt = $('<option/>')
399 var opt = $('<option/>')
392 .attr('value', list_list[i][1])
400 .attr('value', list_list[i][1])
393 .text(list_list[i][0]);
401 .text(list_list[i][0]);
394 select.append(opt);
402 select.append(opt);
395 }
403 }
396 select.val(getter(cell));
404 select.val(getter(cell));
397 select.change(function(){
405 select.change(function(){
398 setter(cell, select.val());
406 setter(cell, select.val());
399 });
407 });
400 button_container.append($('<div/>').append(lbl).append(select));
408 button_container.append($('<div/>').append(lbl).append(select));
401 if (cell_types && cell_types.indexOf(cell.cell_type) == -1) {
409 if (cell_types && cell_types.indexOf(cell.cell_type) == -1) {
402 celltoolbar.hide();
410 celltoolbar.hide();
403 } else {
411 } else {
404 celltoolbar.show();
412 celltoolbar.show();
405 }
413 }
406
414
407 };
415 };
408 };
416 };
409
417
410
418
411 IPython.CellToolbar = CellToolbar;
419 IPython.CellToolbar = CellToolbar;
412
420
413 return IPython;
421 return IPython;
414 }(IPython));
422 }(IPython));
General Comments 0
You need to be logged in to leave comments. Login now