Show More
@@ -37,8 +37,8 b' var IPython = (function (IPython) {' | |||
|
37 | 37 | |
|
38 | 38 | CellToolbar.dropdown_preset_element = $('<select/>') |
|
39 | 39 | .addClass('ui-widget ui-widget-content') |
|
40 | .attr('id','celltoolbar_selector') | |
|
41 | .append($('<option/>').attr('value','').text('-')) | |
|
40 | .attr('id', 'celltoolbar_selector') | |
|
41 | .append($('<option/>').attr('value', '').text('-')) | |
|
42 | 42 | |
|
43 | 43 | CellToolbar.dropdown_preset_element.change(function(){ |
|
44 | 44 | var val = CellToolbar.dropdown_preset_element.val() |
@@ -117,7 +117,7 b' var IPython = (function (IPython) {' | |||
|
117 | 117 | * button.click(function(){ |
|
118 | 118 | * var v = cell.metadata.foo; |
|
119 | 119 | * cell.metadata.foo = !v; |
|
120 | * button.button("option","label",String(!v)); | |
|
120 | * button.button("option", "label", String(!v)); | |
|
121 | 121 | * }) |
|
122 | 122 | * |
|
123 | 123 | * // add the button to the DOM div. |
@@ -126,7 +126,7 b' var IPython = (function (IPython) {' | |||
|
126 | 126 | * |
|
127 | 127 | * // now we register the callback under the name `foo` to give the |
|
128 | 128 | * // user the ability to use it later |
|
129 | * CellToolbar.register_callback('foo',toggle); | |
|
129 | * CellToolbar.register_callback('foo', toggle); | |
|
130 | 130 | */ |
|
131 | 131 | CellToolbar.register_callback = function(name, callback){ |
|
132 | 132 | // what do we do if name already exist ? |
@@ -145,19 +145,19 b' var IPython = (function (IPython) {' | |||
|
145 | 145 | * @private |
|
146 | 146 | * @example |
|
147 | 147 | * |
|
148 | * CellToolbar.register_callback('foo.c1',function(div,cell){...}); | |
|
149 | * CellToolbar.register_callback('foo.c2',function(div,cell){...}); | |
|
150 | * CellToolbar.register_callback('foo.c3',function(div,cell){...}); | |
|
151 | * CellToolbar.register_callback('foo.c4',function(div,cell){...}); | |
|
152 | * CellToolbar.register_callback('foo.c5',function(div,cell){...}); | |
|
148 | * CellToolbar.register_callback('foo.c1', function(div, cell){...}); | |
|
149 | * CellToolbar.register_callback('foo.c2', function(div, cell){...}); | |
|
150 | * CellToolbar.register_callback('foo.c3', function(div, cell){...}); | |
|
151 | * CellToolbar.register_callback('foo.c4', function(div, cell){...}); | |
|
152 | * CellToolbar.register_callback('foo.c5', function(div, cell){...}); | |
|
153 | 153 | * |
|
154 | * CellToolbar.register_preset('foo.foo_preset1',['foo.c1','foo.c2','foo.c5']) | |
|
155 | * CellToolbar.register_preset('foo.foo_preset2',['foo.c4','foo.c5']) | |
|
154 | * CellToolbar.register_preset('foo.foo_preset1', ['foo.c1', 'foo.c2', 'foo.c5']) | |
|
155 | * CellToolbar.register_preset('foo.foo_preset2', ['foo.c4', 'foo.c5']) | |
|
156 | 156 | */ |
|
157 | 157 | CellToolbar.register_preset = function(name, preset_list){ |
|
158 | 158 | CellToolbar._presets[name] = preset_list |
|
159 | 159 | CellToolbar.dropdown_preset_element.append( |
|
160 | $('<option/>').attr('value',name).text(name) | |
|
160 | $('<option/>').attr('value', name).text(name) | |
|
161 | 161 | ) |
|
162 | 162 | } |
|
163 | 163 | /** |
@@ -213,29 +213,26 b' var IPython = (function (IPython) {' | |||
|
213 | 213 | // Note, |
|
214 | 214 | // do this the other way, wrap in try/catch and don't append if any errors. |
|
215 | 215 | this.inner_element.append(local_div) |
|
216 | cdict[preset[index]](local_div,this.cell) | |
|
216 | cdict[preset[index]](local_div, this.cell) | |
|
217 | 217 | } |
|
218 | 218 | |
|
219 | 219 | } |
|
220 | 220 | |
|
221 | ||
|
222 | ||
|
223 | ||
|
224 | 221 | |
|
225 | 222 | /** |
|
226 | 223 | */ |
|
227 | 224 | CellToolbar.utils = {}; |
|
228 | 225 | |
|
229 | 226 | /** |
|
230 | * A utility function to generate bindings between a checkbox and metadata | |
|
227 | * A utility function to generate bindings between a checkbox and cell/metadata | |
|
231 | 228 | * @method utils.checkbox_ui_generator |
|
232 | 229 | * @static |
|
233 | 230 | * |
|
234 | 231 | * @param name {string} Label in front of the checkbox |
|
235 |
* @param setter {function( |
|
|
236 |
* A setter method to set the newValue |
|
|
237 |
* @param getter {function( |
|
|
238 |
* A getter methods which return the current value |
|
|
232 | * @param setter {function( cell, newValue )} | |
|
233 | * A setter method to set the newValue | |
|
234 | * @param getter {function( cell )} | |
|
235 | * A getter methods which return the current value. | |
|
239 | 236 | * |
|
240 | 237 | * @return callback {function( div, cell )} Callback to be passed to `register_callback` |
|
241 | 238 | * |
@@ -245,14 +242,14 b' var IPython = (function (IPython) {' | |||
|
245 | 242 | * |
|
246 | 243 | * var newSlide = CellToolbar.utils.checkbox_ui_generator('New Slide', |
|
247 | 244 | * // setter |
|
248 |
* function( |
|
|
245 | * function(cell, value){ | |
|
249 | 246 | * // we check that the slideshow namespace exist and create it if needed |
|
250 | * if (metadata.slideshow == undefined){metadata.slideshow = {}} | |
|
247 | * if (cell.metadata.slideshow == undefined){cell.metadata.slideshow = {}} | |
|
251 | 248 | * // set the value |
|
252 | * metadata.slideshow.isSectionStart = value | |
|
249 | * cell.metadata.slideshow.isSectionStart = value | |
|
253 | 250 | * }, |
|
254 | 251 | * //geter |
|
255 |
* function( |
|
|
252 | * function(cell){ var ns = cell.metadata.slideshow; | |
|
256 | 253 | * // if the slideshow namespace does not exist return `undefined` |
|
257 | 254 | * // (will be interpreted as `false` by checkbox) otherwise |
|
258 | 255 | * // return the value |
@@ -263,19 +260,19 b' var IPython = (function (IPython) {' | |||
|
263 | 260 | * CellToolbar.register_callback('newSlide', newSlide); |
|
264 | 261 | * |
|
265 | 262 | */ |
|
266 | CellToolbar.utils.checkbox_ui_generator = function(name,setter,getter){ | |
|
263 | CellToolbar.utils.checkbox_ui_generator = function(name, setter, getter){ | |
|
267 | 264 | return function(div, cell) { |
|
268 | 265 | var button_container = $(div) |
|
269 | 266 | |
|
270 | var chkb = $('<input/>').attr('type','checkbox'); | |
|
271 | var lbl = $('<label/>').append($('<span/>').text(name).css('font-size','77%')); | |
|
267 | var chkb = $('<input/>').attr('type', 'checkbox'); | |
|
268 | var lbl = $('<label/>').append($('<span/>').text(name).css('font-size', '77%')); | |
|
272 | 269 | lbl.append(chkb); |
|
273 |
chkb.attr("checked",getter(cell |
|
|
270 | chkb.attr("checked", getter(cell)); | |
|
274 | 271 | |
|
275 | 272 | chkb.click(function(){ |
|
276 |
var v = getter(cell |
|
|
277 |
setter(cell |
|
|
278 | chkb.attr("checked",!v); | |
|
273 | var v = getter(cell); | |
|
274 | setter(cell, !v); | |
|
275 | chkb.attr("checked", !v); | |
|
279 | 276 | }) |
|
280 | 277 | button_container.append($('<div/>').append(lbl)); |
|
281 | 278 | |
@@ -283,16 +280,16 b' var IPython = (function (IPython) {' | |||
|
283 | 280 | } |
|
284 | 281 | |
|
285 | 282 | /** |
|
286 |
* A utility function to generate bindings between a dropdown list |
|
|
283 | * A utility function to generate bindings between a dropdown list cell | |
|
287 | 284 | * @method utils.select_ui_generator |
|
288 | 285 | * @static |
|
289 | 286 | * |
|
290 | 287 | * @param list_list {list of sublist} List of sublist of metadata value and name in the dropdown list. |
|
291 | 288 | * subslit shoud contain 2 element each, first a string that woul be displayed in the dropdown list, |
|
292 |
* and second the corresponding value |
|
|
293 |
* @param setter {function( |
|
|
294 |
* A setter method to set the newValue |
|
|
295 |
* @param getter {function( |
|
|
289 | * and second the corresponding value to be passed to setter/return by getter. | |
|
290 | * @param setter {function( cell, newValue )} | |
|
291 | * A setter method to set the newValue | |
|
292 | * @param getter {function( cell )} | |
|
296 | 293 | * A getter methods which return the current value of the metadata. |
|
297 | 294 | * @param [label=""] {String} optionnal label for the dropdown menu |
|
298 | 295 | * |
@@ -301,45 +298,44 b' var IPython = (function (IPython) {' | |||
|
301 | 298 | * @example |
|
302 | 299 | * |
|
303 | 300 | * var select_type = CellToolbar.utils.select_ui_generator([ |
|
304 | * ["-" ,undefined ], | |
|
305 | * ["Header Slide" ,"header_slide" ], | |
|
306 | * ["Slide" ,"slide" ], | |
|
307 | * ["Fragment" ,"fragment" ], | |
|
308 | * ["Skip" ,"skip" ], | |
|
301 | * ["-" , undefined ], | |
|
302 | * ["Header Slide" , "header_slide" ], | |
|
303 | * ["Slide" , "slide" ], | |
|
304 | * ["Fragment" , "fragment" ], | |
|
305 | * ["Skip" , "skip" ], | |
|
309 | 306 | * ], |
|
310 | 307 | * // setter |
|
311 |
* function( |
|
|
308 | * function(cell, value){ | |
|
312 | 309 | * // we check that the slideshow namespace exist and create it if needed |
|
313 | * if (metadata.slideshow == undefined){metadata.slideshow = {}} | |
|
310 | * if (cell.metadata.slideshow == undefined){cell.metadata.slideshow = {}} | |
|
314 | 311 | * // set the value |
|
315 | * metadata.slideshow.slide_type = value | |
|
312 | * cell.metadata.slideshow.slide_type = value | |
|
316 | 313 | * }, |
|
317 | 314 | * //geter |
|
318 |
* function( |
|
|
315 | * function(cell){ var ns = cell.metadata.slideshow; | |
|
319 | 316 | * // if the slideshow namespace does not exist return `undefined` |
|
320 | 317 | * // (will be interpreted as `false` by checkbox) otherwise |
|
321 | 318 | * // return the value |
|
322 | 319 | * return (ns == undefined)? undefined: ns.slide_type |
|
323 | 320 | * } |
|
324 | * CellToolbar.register_callback('slideshow.select',select_type); | |
|
321 | * CellToolbar.register_callback('slideshow.select', select_type); | |
|
325 | 322 | * |
|
326 | 323 | */ |
|
327 | CellToolbar.utils.select_ui_generator = function(list_list,setter, getter, label){ | |
|
324 | CellToolbar.utils.select_ui_generator = function(list_list, setter, getter, label){ | |
|
328 | 325 | label= label? label: ""; |
|
329 | 326 | return function(div, cell) { |
|
330 | 327 | var button_container = $(div) |
|
331 | var lbl = $("<label/>").append($('<span/>').text(label).css('font-size','77%')); | |
|
328 | var lbl = $("<label/>").append($('<span/>').text(label).css('font-size', '77%')); | |
|
332 | 329 | var select = $('<select/>'); |
|
333 | 330 | for(var itemn in list_list){ |
|
334 | 331 | var opt = $('<option/>'); |
|
335 | opt.attr('value',list_list[itemn][1]) | |
|
332 | opt.attr('value', list_list[itemn][1]) | |
|
336 | 333 | opt.text(list_list[itemn][0]) |
|
337 | 334 | select.append(opt); |
|
338 | 335 | } |
|
339 |
select.val(getter(cell |
|
|
340 | ||
|
336 | select.val(getter(cell)); | |
|
341 | 337 | select.change(function(){ |
|
342 |
setter(cell |
|
|
338 | setter(cell, select.val()); | |
|
343 | 339 | }); |
|
344 | 340 | button_container.append($('<div/>').append(lbl).append(select)); |
|
345 | 341 |
@@ -142,41 +142,48 b'' | |||
|
142 | 142 | CellToolbar.register_callback('example.toggle',toggle_test); |
|
143 | 143 | example_preset.push('example.toggle'); |
|
144 | 144 | |
|
145 | var checkbox_test = function(div, cell) { | |
|
146 | var button_container = $(div) | |
|
145 | var checkbox_test = CellToolbar.utils.checkbox_ui_generator('Yes/No', | |
|
146 | // setter | |
|
147 | function(cell, value){ | |
|
148 | // we check that the slideshow namespace exist and create it if needed | |
|
149 | if (cell.metadata.yn_test == undefined){cell.metadata.yn_test = {}} | |
|
150 | // set the value | |
|
151 | cell.metadata.yn_test.value = value | |
|
152 | }, | |
|
153 | //geter | |
|
154 | function(cell){ var ns = cell.metadata.yn_test; | |
|
155 | // if the slideshow namespace does not exist return `undefined` | |
|
156 | // (will be interpreted as `false` by checkbox) otherwise | |
|
157 | // return the value | |
|
158 | return (ns == undefined)? undefined: ns.value | |
|
159 | } | |
|
160 | ); | |
|
147 | 161 | |
|
148 | var chkb = $('<input/>').attr('type','checkbox'); | |
|
149 | var lbl = $('<label/>').append($('<span/>').text('bar :').css('font-size','77%')); | |
|
150 | lbl.append(chkb); | |
|
151 | chkb.attr("checked",cell.metadata.bar); | |
|
152 | chkb.click(function(){ | |
|
153 | var v = cell.metadata.bar; | |
|
154 | cell.metadata.bar = !v; | |
|
155 | chkb.attr("checked",!v); | |
|
156 | }) | |
|
157 | button_container.append($('<div/>').append(lbl)); | |
|
158 | ||
|
159 | } | |
|
160 | 162 | |
|
161 | 163 | CellToolbar.register_callback('example.checkbox',checkbox_test); |
|
162 | 164 | example_preset.push('example.checkbox'); |
|
163 | 165 | |
|
164 | var select_test = function(div, cell) { | |
|
165 | var button_container = $(div) | |
|
166 | ||
|
167 | var select = $('<select/>'); | |
|
168 | ||
|
169 | select.append($('<option/>').attr('value','foo').text('foo')); | |
|
170 | select.append($('<option/>').attr('value','bar').text('bar')); | |
|
171 | select.append($('<option/>').attr('value','qux').text('qux')); | |
|
172 | select.append($('<option/>').attr('value','zip').text('zip')); | |
|
173 | select.val(cell.metadata.option); | |
|
174 | select.change(function(){ | |
|
175 | cell.metadata.option = select.val(); | |
|
166 | var select_test = CellToolbar.utils.select_ui_generator([ | |
|
167 | ["-" ,undefined ], | |
|
168 | ["Header Slide" ,"header_slide" ], | |
|
169 | ["Slide" ,"slide" ], | |
|
170 | ["Fragment" ,"fragment" ], | |
|
171 | ["Skip" ,"skip" ], | |
|
172 | ], | |
|
173 | // setter | |
|
174 | function(cell,value){ | |
|
175 | // we check that the slideshow namespace exist and create it if needed | |
|
176 | if (cell.metadata.test == undefined){cell.metadata.test = {}} | |
|
177 | // set the value | |
|
178 | cell.metadata.test.slide_type = value | |
|
179 | }, | |
|
180 | //geter | |
|
181 | function(cell){ var ns = cell.metadata.test; | |
|
182 | // if the slideshow namespace does not exist return `undefined` | |
|
183 | // (will be interpreted as `false` by checkbox) otherwise | |
|
184 | // return the value | |
|
185 | return (ns == undefined)? undefined: ns.slide_type | |
|
176 | 186 | }); |
|
177 | button_container.append($('<div/>').append(select)); | |
|
178 | ||
|
179 | } | |
|
180 | 187 | |
|
181 | 188 | CellToolbar.register_callback('example.select',select_test); |
|
182 | 189 | example_preset.push('example.select'); |
General Comments 0
You need to be logged in to leave comments.
Login now