##// END OF EJS Templates
gshow
Matthias BUSSONNIER -
Show More
@@ -1,53 +1,74 b''
1 /* Css for the metadata edit area */
1 /* Css for the metadata edit area */
2
2
3
3
4 .celltoolbar {
4 .celltoolbar {
5 border: thin solid #DDD;
5 border: thin solid #DDD;
6 margin-left: 0px;
6 margin-left: 0px;
7 border-bottom: none;
7 border-bottom: none;
8 background : #EEE;
8 background : #EEE;
9 border-top-right-radius: 3px;
9 border-top-right-radius: 3px;
10 border-top-left-radius: 3px;
10 border-top-left-radius: 3px;
11 }
11 }
12
12
13 .no_input_radius {
13 .no_input_radius {
14 border-top-right-radius: 0px;
14 border-top-right-radius: 0px;
15 border-top-left-radius: 0px;
15 border-top-left-radius: 0px;
16 }
16 }
17
17
18 .text_cell .ctb_prompt {
18 .text_cell .ctb_prompt {
19 display: none;
19 display: none;
20 }
20 }
21
21
22 .code_cell .ctb_prompt {
22 .code_cell .ctb_prompt {
23 display: block;
23 display: block;
24 }
24 }
25
25
26 .ctb_wrapper{
27 display: none;
28 }
29
30 .toolbaron .ctb_wrapper{
31 display: block;
32 display: -webkit-box;
33 }
34
35 .toolbaron .ctb_wrapper + div > div.input_area,
36 .toolbaron .ctb_wrapper + div.text_cell_input{
37 border-top-right-radius: 0px;
38 border-top-left-radius: 0px;
39 }
40
41 .toolbaron > .celltoolbar {
42 border-bottom-right-radius: 0px;
43 border-bottom-left-radius: 0px;
44 }
45
46
26 .button_container {
47 .button_container {
27 float: right;
48 float: right;
28 }
49 }
29
50
30 .button_container .ui-state-default, .button_container .ui-state-hover, .button_container .ui-state-hover span{
51 .button_container .ui-state-default, .button_container .ui-state-hover, .button_container .ui-state-hover span{
31 border-radius : 0 0 0 0;
52 border-radius : 0 0 0 0;
32 border : none;
53 border : none;
33 }
54 }
34
55
35 .celltoolbar .button_container select {
56 .celltoolbar .button_container select {
36 margin: 10px;
57 margin: 10px;
37 margin-top: 0px;
58 margin-top: 0px;
38 margin-bottom: 0px;
59 margin-bottom: 0px;
39 font-size: 77%;
60 font-size: 77%;
40 }
61 }
41
62
42 .celltoolbar label span {
63 .celltoolbar label span {
43 font-size: 77%;
64 font-size: 77%;
44 }
65 }
45
66
46 .celltoolbar input[type=checkbox] {
67 .celltoolbar input[type=checkbox] {
47 margin-bottom: 1px;
68 margin-bottom: 1px;
48 }
69 }
49
70
50 .celltoolbar ui-button {
71 .celltoolbar ui-button {
51 border: none;
72 border: none;
52 }
73 }
53
74
@@ -1,381 +1,386 b''
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/>');
37 this.inner_element = $('<div/>');
38 var ctb_element = $('<div/>').addClass('celltoolbar')
38 var ctb_element = $('<div/>').addClass('celltoolbar')
39 .append(this.inner_element);
39 .append(this.inner_element);
40 this.element = $('<div/>').addClass('ctb_wrapper hbox');
40 this.element = $('<div/>').addClass('ctb_wrapper hbox');
41 ctb_element.addClass('box-flex1');
41 ctb_element.addClass('box-flex1');
42 var ctb_prompt = $('<div/>').addClass('ctb_prompt prompt');
42 var ctb_prompt = $('<div/>').addClass('ctb_prompt prompt');
43 this.element.append(ctb_prompt).append(ctb_element);
43 this.element.append(ctb_prompt).append(ctb_element);
44 };
44 };
45
45
46
46
47 CellToolbar.dropdown_preset_element = $('<select/>')
47 CellToolbar.dropdown_preset_element = $('<select/>')
48 .addClass('ui-widget ui-widget-content')
48 .addClass('ui-widget ui-widget-content')
49 .attr('id', 'celltoolbar_selector')
49 .attr('id', 'celltoolbar_selector')
50 .append($('<option/>').attr('value', '').text('None'))
50 .append($('<option/>').attr('value', '').text('None'))
51
51
52
52
53 CellToolbar.dropdown_preset_element.change(function() {
53 CellToolbar.dropdown_preset_element.change(function() {
54 var val = CellToolbar.dropdown_preset_element.val()
54 var val = CellToolbar.dropdown_preset_element.val()
55 if(val ==''){
55 if(val ==''){
56 CellToolbar.hide();
56 CellToolbar.global_hide();
57 } else {
57 } else {
58 CellToolbar.show();
58 CellToolbar.global_show();
59 CellToolbar.activate_preset(val);
59 CellToolbar.activate_preset(val);
60 }
60 }
61 })
61 })
62
62
63
63
64 CellToolbar.hide = function () {
64 CellToolbar.global_hide = function () {
65 $('.ctb_wrapper').hide();
65 $('body').removeClass('toolbaron');
66 $('.input_area').addClass('no_input_radius');
67 $('.text_cell_input').addClass('no_input_radius');
68 }
66 }
69
67
70
68
71 CellToolbar.show = function () {
69 CellToolbar.global_show = function () {
72 $('.ctb_wrapper').show();
70 $('body').addClass('toolbaron');
73 $('.input_area').removeClass('no_input_radius');
71 }
74 $('.text_cell_input').removeClass('no_input_radius');
72
73 CellToolbar.prototype.hide = function () {
74 this.element.removeClass('toolbaron');
75 }
76
77
78 CellToolbar.prototype.show = function () {
79 this.element.addClass('toolbaron');
75 }
80 }
76
81
77
82
78 /**
83 /**
79 * Class variable that should contain a dict of all availlable callback
84 * Class variable that should contain a dict of all availlable callback
80 * we need to think of wether or not we allow nested namespace
85 * we need to think of wether or not we allow nested namespace
81 * @property _callback_dict
86 * @property _callback_dict
82 * @private
87 * @private
83 * @static
88 * @static
84 * @type Dict
89 * @type Dict
85 */
90 */
86 CellToolbar._callback_dict = {};
91 CellToolbar._callback_dict = {};
87
92
88 /**
93 /**
89 * Class variable that should contain the reverse order list of the button
94 * Class variable that should contain the reverse order list of the button
90 * to add to the toolbar of each cell
95 * to add to the toolbar of each cell
91 * @property _ui_controls_list
96 * @property _ui_controls_list
92 * @private
97 * @private
93 * @static
98 * @static
94 * @type List
99 * @type List
95 */
100 */
96 CellToolbar._ui_controls_list = [];
101 CellToolbar._ui_controls_list = [];
97
102
98 /**
103 /**
99 * Class variable that should contains the CellToolbar instances for each
104 * Class variable that should contains the CellToolbar instances for each
100 * cell of the notebook
105 * cell of the notebook
101 *
106 *
102 * @private
107 * @private
103 * @property _instances
108 * @property _instances
104 * @static
109 * @static
105 * @type List
110 * @type List
106 */
111 */
107 CellToolbar._instances =[]
112 CellToolbar._instances =[]
108
113
109 /**
114 /**
110 * keep a list of all the availlabel presets for the toolbar
115 * keep a list of all the availlabel presets for the toolbar
111 * @private
116 * @private
112 * @property _presets
117 * @property _presets
113 * @static
118 * @static
114 * @type Dict
119 * @type Dict
115 */
120 */
116 CellToolbar._presets ={}
121 CellToolbar._presets ={}
117
122
118 // this is by design not a prototype.
123 // this is by design not a prototype.
119 /**
124 /**
120 * Register a callback to create an UI element in a cell toolbar.
125 * Register a callback to create an UI element in a cell toolbar.
121 * @method register_callback
126 * @method register_callback
122 * @param name {String} name to use to refer to the callback. It is advised to use a prefix with the name
127 * @param name {String} name to use to refer to the callback. It is advised to use a prefix with the name
123 * for easier sorting and avoid collision
128 * for easier sorting and avoid collision
124 * @param callback {function(div, cell)} callback that will be called to generate the ui element
129 * @param callback {function(div, cell)} callback that will be called to generate the ui element
125 *
130 *
126 *
131 *
127 * The callback will receive the following element :
132 * The callback will receive the following element :
128 *
133 *
129 * * a div in which to add element.
134 * * a div in which to add element.
130 * * the cell it is responsible from
135 * * the cell it is responsible from
131 *
136 *
132 * @example
137 * @example
133 *
138 *
134 * Example that create callback for a button that toggle between `true` and `false` label,
139 * Example that create callback for a button that toggle between `true` and `false` label,
135 * with the metadata under the key 'foo' to reflect the status of the button.
140 * with the metadata under the key 'foo' to reflect the status of the button.
136 *
141 *
137 * // first param reference to a DOM div
142 * // first param reference to a DOM div
138 * // second param reference to the cell.
143 * // second param reference to the cell.
139 * var toggle = function(div, cell) {
144 * var toggle = function(div, cell) {
140 * var button_container = $(div)
145 * var button_container = $(div)
141 *
146 *
142 * // let's create a button that show the current value of the metadata
147 * // let's create a button that show the current value of the metadata
143 * var button = $('<div/>').button({label:String(cell.metadata.foo)});
148 * var button = $('<div/>').button({label:String(cell.metadata.foo)});
144 *
149 *
145 * // On click, change the metadata value and update the button label
150 * // On click, change the metadata value and update the button label
146 * button.click(function(){
151 * button.click(function(){
147 * var v = cell.metadata.foo;
152 * var v = cell.metadata.foo;
148 * cell.metadata.foo = !v;
153 * cell.metadata.foo = !v;
149 * button.button("option", "label", String(!v));
154 * button.button("option", "label", String(!v));
150 * })
155 * })
151 *
156 *
152 * // add the button to the DOM div.
157 * // add the button to the DOM div.
153 * button_container.append(button);
158 * button_container.append(button);
154 * }
159 * }
155 *
160 *
156 * // now we register the callback under the name `foo` to give the
161 * // now we register the callback under the name `foo` to give the
157 * // user the ability to use it later
162 * // user the ability to use it later
158 * CellToolbar.register_callback('foo', toggle);
163 * CellToolbar.register_callback('foo', toggle);
159 */
164 */
160 CellToolbar.register_callback = function(name, callback){
165 CellToolbar.register_callback = function(name, callback){
161 // Overwrite if it already exists.
166 // Overwrite if it already exists.
162 CellToolbar._callback_dict[name] = callback;
167 CellToolbar._callback_dict[name] = callback;
163 };
168 };
164
169
165 /**
170 /**
166 * Register a preset of UI element in a cell toolbar.
171 * Register a preset of UI element in a cell toolbar.
167 * Not supported Yet.
172 * Not supported Yet.
168 * @method register_preset
173 * @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
174 * @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
175 * 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
176 * @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.
177 * should correspond to a name of a registerd callback.
173 *
178 *
174 * @private
179 * @private
175 * @example
180 * @example
176 *
181 *
177 * CellToolbar.register_callback('foo.c1', function(div, cell){...});
182 * CellToolbar.register_callback('foo.c1', function(div, cell){...});
178 * CellToolbar.register_callback('foo.c2', function(div, cell){...});
183 * CellToolbar.register_callback('foo.c2', function(div, cell){...});
179 * CellToolbar.register_callback('foo.c3', function(div, cell){...});
184 * CellToolbar.register_callback('foo.c3', function(div, cell){...});
180 * CellToolbar.register_callback('foo.c4', function(div, cell){...});
185 * CellToolbar.register_callback('foo.c4', function(div, cell){...});
181 * CellToolbar.register_callback('foo.c5', function(div, cell){...});
186 * CellToolbar.register_callback('foo.c5', function(div, cell){...});
182 *
187 *
183 * CellToolbar.register_preset('foo.foo_preset1', ['foo.c1', 'foo.c2', 'foo.c5'])
188 * CellToolbar.register_preset('foo.foo_preset1', ['foo.c1', 'foo.c2', 'foo.c5'])
184 * CellToolbar.register_preset('foo.foo_preset2', ['foo.c4', 'foo.c5'])
189 * CellToolbar.register_preset('foo.foo_preset2', ['foo.c4', 'foo.c5'])
185 */
190 */
186 CellToolbar.register_preset = function(name, preset_list){
191 CellToolbar.register_preset = function(name, preset_list){
187 CellToolbar._presets[name] = preset_list
192 CellToolbar._presets[name] = preset_list
188 CellToolbar.dropdown_preset_element.append(
193 CellToolbar.dropdown_preset_element.append(
189 $('<option/>').attr('value', name).text(name)
194 $('<option/>').attr('value', name).text(name)
190 )
195 )
191 }
196 }
192 /**
197 /**
193 * Activate an UI preset from `register_preset`
198 * Activate an UI preset from `register_preset`
194 *
199 *
195 * This does not update the selection UI.
200 * This does not update the selection UI.
196 *
201 *
197 * @method activate_preset
202 * @method activate_preset
198 * @param preset_name {String} string corresponding to the preset name
203 * @param preset_name {String} string corresponding to the preset name
199 *
204 *
200 * @static
205 * @static
201 * @private
206 * @private
202 * @example
207 * @example
203 *
208 *
204 * CellToolbar.activate_preset('foo.foo_preset1');
209 * CellToolbar.activate_preset('foo.foo_preset1');
205 */
210 */
206 CellToolbar.activate_preset= function(preset_name){
211 CellToolbar.activate_preset= function(preset_name){
207 var preset = CellToolbar._presets[preset_name];
212 var preset = CellToolbar._presets[preset_name];
208
213
209 if(preset != undefined){
214 if(preset != undefined){
210 CellToolbar._ui_controls_list = preset;
215 CellToolbar._ui_controls_list = preset;
211 CellToolbar.rebuild_all();
216 CellToolbar.rebuild_all();
212 }
217 }
213 }
218 }
214
219
215
220
216 // this is by design not a prototype.
221 // this is by design not a prototype.
217 /**
222 /**
218 * This should be called on the class and not on a instance as it will trigger
223 * This should be called on the class and not on a instance as it will trigger
219 * rebuild of all the instances.
224 * rebuild of all the instances.
220 * @method rebuild_all
225 * @method rebuild_all
221 * @static
226 * @static
222 *
227 *
223 */
228 */
224 CellToolbar.rebuild_all = function(){
229 CellToolbar.rebuild_all = function(){
225 for(var i in CellToolbar._instances){
230 for(var i in CellToolbar._instances){
226 CellToolbar._instances[i].rebuild();
231 CellToolbar._instances[i].rebuild();
227 }
232 }
228 }
233 }
229
234
230 /**
235 /**
231 * Rebuild all the button on the toolbar to update it's state.
236 * Rebuild all the button on the toolbar to update it's state.
232 * @method rebuild
237 * @method rebuild
233 */
238 */
234 CellToolbar.prototype.rebuild = function(){
239 CellToolbar.prototype.rebuild = function(){
235 // strip evrything from the div
240 // strip evrything from the div
236 // which is probabli metainner.
241 // which is probabli metainner.
237 // or this.element.
242 // or this.element.
238 this.inner_element.empty();
243 this.inner_element.empty();
239
244
240 var cdict = CellToolbar._callback_dict;
245 var cdict = CellToolbar._callback_dict;
241 var preset = CellToolbar._ui_controls_list;
246 var preset = CellToolbar._ui_controls_list;
242 // Yes we iterate on the class varaible, not the instance one.
247 // Yes we iterate on the class varaible, not the instance one.
243 for ( var index in CellToolbar._ui_controls_list){
248 for ( var index in CellToolbar._ui_controls_list){
244 var local_div = $('<div/>').addClass('button_container');
249 var local_div = $('<div/>').addClass('button_container');
245 // Note,
250 // Note,
246 // do this the other way, wrap in try/catch and don't append if any errors.
251 // do this the other way, wrap in try/catch and don't append if any errors.
247 this.inner_element.append(local_div)
252 this.inner_element.append(local_div)
248 cdict[preset[index]](local_div, this.cell)
253 cdict[preset[index]](local_div, this.cell)
249 }
254 }
250
255
251 }
256 }
252
257
253
258
254 /**
259 /**
255 */
260 */
256 CellToolbar.utils = {};
261 CellToolbar.utils = {};
257
262
258 /**
263 /**
259 * A utility function to generate bindings between a checkbox and cell/metadata
264 * A utility function to generate bindings between a checkbox and cell/metadata
260 * @method utils.checkbox_ui_generator
265 * @method utils.checkbox_ui_generator
261 * @static
266 * @static
262 *
267 *
263 * @param name {string} Label in front of the checkbox
268 * @param name {string} Label in front of the checkbox
264 * @param setter {function( cell, newValue )}
269 * @param setter {function( cell, newValue )}
265 * A setter method to set the newValue
270 * A setter method to set the newValue
266 * @param getter {function( cell )}
271 * @param getter {function( cell )}
267 * A getter methods which return the current value.
272 * A getter methods which return the current value.
268 *
273 *
269 * @return callback {function( div, cell )} Callback to be passed to `register_callback`
274 * @return callback {function( div, cell )} Callback to be passed to `register_callback`
270 *
275 *
271 * @example
276 * @example
272 *
277 *
273 * An exmple that bind the subkey `slideshow.isSectionStart` to a checkbox with a `New Slide` label
278 * An exmple that bind the subkey `slideshow.isSectionStart` to a checkbox with a `New Slide` label
274 *
279 *
275 * var newSlide = CellToolbar.utils.checkbox_ui_generator('New Slide',
280 * var newSlide = CellToolbar.utils.checkbox_ui_generator('New Slide',
276 * // setter
281 * // setter
277 * function(cell, value){
282 * function(cell, value){
278 * // we check that the slideshow namespace exist and create it if needed
283 * // we check that the slideshow namespace exist and create it if needed
279 * if (cell.metadata.slideshow == undefined){cell.metadata.slideshow = {}}
284 * if (cell.metadata.slideshow == undefined){cell.metadata.slideshow = {}}
280 * // set the value
285 * // set the value
281 * cell.metadata.slideshow.isSectionStart = value
286 * cell.metadata.slideshow.isSectionStart = value
282 * },
287 * },
283 * //geter
288 * //geter
284 * function(cell){ var ns = cell.metadata.slideshow;
289 * function(cell){ var ns = cell.metadata.slideshow;
285 * // if the slideshow namespace does not exist return `undefined`
290 * // if the slideshow namespace does not exist return `undefined`
286 * // (will be interpreted as `false` by checkbox) otherwise
291 * // (will be interpreted as `false` by checkbox) otherwise
287 * // return the value
292 * // return the value
288 * return (ns == undefined)? undefined: ns.isSectionStart
293 * return (ns == undefined)? undefined: ns.isSectionStart
289 * }
294 * }
290 * );
295 * );
291 *
296 *
292 * CellToolbar.register_callback('newSlide', newSlide);
297 * CellToolbar.register_callback('newSlide', newSlide);
293 *
298 *
294 */
299 */
295 CellToolbar.utils.checkbox_ui_generator = function(name, setter, getter){
300 CellToolbar.utils.checkbox_ui_generator = function(name, setter, getter){
296 return function(div, cell) {
301 return function(div, cell) {
297 var button_container = $(div)
302 var button_container = $(div)
298
303
299 var chkb = $('<input/>').attr('type', 'checkbox');
304 var chkb = $('<input/>').attr('type', 'checkbox');
300 var lbl = $('<label/>').append($('<span/>').text(name));
305 var lbl = $('<label/>').append($('<span/>').text(name));
301 lbl.append(chkb);
306 lbl.append(chkb);
302 chkb.attr("checked", getter(cell));
307 chkb.attr("checked", getter(cell));
303
308
304 chkb.click(function(){
309 chkb.click(function(){
305 var v = getter(cell);
310 var v = getter(cell);
306 setter(cell, !v);
311 setter(cell, !v);
307 chkb.attr("checked", !v);
312 chkb.attr("checked", !v);
308 })
313 })
309 button_container.append($('<div/>').append(lbl));
314 button_container.append($('<div/>').append(lbl));
310
315
311 }
316 }
312 }
317 }
313
318
314 /**
319 /**
315 * A utility function to generate bindings between a dropdown list cell
320 * A utility function to generate bindings between a dropdown list cell
316 * @method utils.select_ui_generator
321 * @method utils.select_ui_generator
317 * @static
322 * @static
318 *
323 *
319 * @param list_list {list of sublist} List of sublist of metadata value and name in the dropdown list.
324 * @param list_list {list of sublist} List of sublist of metadata value and name in the dropdown list.
320 * subslit shoud contain 2 element each, first a string that woul be displayed in the dropdown list,
325 * subslit shoud contain 2 element each, first a string that woul be displayed in the dropdown list,
321 * and second the corresponding value to be passed to setter/return by getter.
326 * and second the corresponding value to be passed to setter/return by getter.
322 * @param setter {function( cell, newValue )}
327 * @param setter {function( cell, newValue )}
323 * A setter method to set the newValue
328 * A setter method to set the newValue
324 * @param getter {function( cell )}
329 * @param getter {function( cell )}
325 * A getter methods which return the current value of the metadata.
330 * A getter methods which return the current value of the metadata.
326 * @param [label=""] {String} optionnal label for the dropdown menu
331 * @param [label=""] {String} optionnal label for the dropdown menu
327 *
332 *
328 * @return callback {function( div, cell )} Callback to be passed to `register_callback`
333 * @return callback {function( div, cell )} Callback to be passed to `register_callback`
329 *
334 *
330 * @example
335 * @example
331 *
336 *
332 * var select_type = CellToolbar.utils.select_ui_generator([
337 * var select_type = CellToolbar.utils.select_ui_generator([
333 * ["<None>" , undefined ],
338 * ["<None>" , undefined ],
334 * ["Header Slide" , "header_slide" ],
339 * ["Header Slide" , "header_slide" ],
335 * ["Slide" , "slide" ],
340 * ["Slide" , "slide" ],
336 * ["Fragment" , "fragment" ],
341 * ["Fragment" , "fragment" ],
337 * ["Skip" , "skip" ],
342 * ["Skip" , "skip" ],
338 * ],
343 * ],
339 * // setter
344 * // setter
340 * function(cell, value){
345 * function(cell, value){
341 * // we check that the slideshow namespace exist and create it if needed
346 * // we check that the slideshow namespace exist and create it if needed
342 * if (cell.metadata.slideshow == undefined){cell.metadata.slideshow = {}}
347 * if (cell.metadata.slideshow == undefined){cell.metadata.slideshow = {}}
343 * // set the value
348 * // set the value
344 * cell.metadata.slideshow.slide_type = value
349 * cell.metadata.slideshow.slide_type = value
345 * },
350 * },
346 * //geter
351 * //geter
347 * function(cell){ var ns = cell.metadata.slideshow;
352 * function(cell){ var ns = cell.metadata.slideshow;
348 * // if the slideshow namespace does not exist return `undefined`
353 * // if the slideshow namespace does not exist return `undefined`
349 * // (will be interpreted as `false` by checkbox) otherwise
354 * // (will be interpreted as `false` by checkbox) otherwise
350 * // return the value
355 * // return the value
351 * return (ns == undefined)? undefined: ns.slide_type
356 * return (ns == undefined)? undefined: ns.slide_type
352 * }
357 * }
353 * CellToolbar.register_callback('slideshow.select', select_type);
358 * CellToolbar.register_callback('slideshow.select', select_type);
354 *
359 *
355 */
360 */
356 CellToolbar.utils.select_ui_generator = function(list_list, setter, getter, label){
361 CellToolbar.utils.select_ui_generator = function(list_list, setter, getter, label){
357 label= label? label: "";
362 label= label? label: "";
358 return function(div, cell) {
363 return function(div, cell) {
359 var button_container = $(div)
364 var button_container = $(div)
360 var lbl = $("<label/>").append($('<span/>').text(label));
365 var lbl = $("<label/>").append($('<span/>').text(label));
361 var select = $('<select/>').addClass('ui-widget ui-widget-content');
366 var select = $('<select/>').addClass('ui-widget ui-widget-content');
362 for(var itemn in list_list){
367 for(var itemn in list_list){
363 var opt = $('<option/>');
368 var opt = $('<option/>');
364 opt.attr('value', list_list[itemn][1])
369 opt.attr('value', list_list[itemn][1])
365 opt.text(list_list[itemn][0])
370 opt.text(list_list[itemn][0])
366 select.append(opt);
371 select.append(opt);
367 }
372 }
368 select.val(getter(cell));
373 select.val(getter(cell));
369 select.change(function(){
374 select.change(function(){
370 setter(cell, select.val());
375 setter(cell, select.val());
371 });
376 });
372 button_container.append($('<div/>').append(lbl).append(select));
377 button_container.append($('<div/>').append(lbl).append(select));
373
378
374 }
379 }
375 };
380 };
376
381
377
382
378 IPython.CellToolbar = CellToolbar;
383 IPython.CellToolbar = CellToolbar;
379
384
380 return IPython;
385 return IPython;
381 }(IPython));
386 }(IPython));
General Comments 0
You need to be logged in to leave comments. Login now