Show More
@@ -322,8 +322,10 b' var IPython = (function (IPython) {' | |||
|
322 | 322 | * @static |
|
323 | 323 | * |
|
324 | 324 | * @param name {string} Label in front of the checkbox |
|
325 |
* @param setter {function( metadata_dict, newValue )} |
|
|
326 | * @param getter {function( metadata )} A getter methods which return the current value of the metadata. | |
|
325 | * @param setter {function( metadata_dict, newValue )} | |
|
326 | * A setter method to set the newValue of the metadata dictionnary | |
|
327 | * @param getter {function( metadata )} | |
|
328 | * A getter methods which return the current value of the metadata. | |
|
327 | 329 | * |
|
328 | 330 | * @return callback {function( div, cell )} Callback to be passed to `register_callback` |
|
329 | 331 | * |
@@ -370,6 +372,71 b' var IPython = (function (IPython) {' | |||
|
370 | 372 | } |
|
371 | 373 | } |
|
372 | 374 | |
|
375 | /** | |
|
376 | * A utility function to generate bindings between a dropdown list and metadata | |
|
377 | * @method utils.select_ui_generator | |
|
378 | * @static | |
|
379 | * | |
|
380 | * @param list_list {list of sublist} List of sublist of metadata value and name in the dropdown list. | |
|
381 | * subslit shoud contain 2 element each, first a string that woul be displayed in the dropdown list, | |
|
382 | * and second the corresponding value for the metadata to be passed to setter/return by getter. | |
|
383 | * @param setter {function( metadata_dict, newValue )} | |
|
384 | * A setter method to set the newValue of the metadata dictionnary | |
|
385 | * @param getter {function( metadata )} | |
|
386 | * A getter methods which return the current value of the metadata. | |
|
387 | * @param [label=""] {String} optionnal label for the dropdown menu | |
|
388 | * | |
|
389 | * @return callback {function( div, cell )} Callback to be passed to `register_callback` | |
|
390 | * | |
|
391 | * @example | |
|
392 | * | |
|
393 | * var select_type = MetaUI.utils.select_ui_generator([ | |
|
394 | * ["-" ,undefined ], | |
|
395 | * ["Header Slide" ,"header_slide" ], | |
|
396 | * ["Slide" ,"slide" ], | |
|
397 | * ["Fragment" ,"fragment" ], | |
|
398 | * ["Skip" ,"skip" ], | |
|
399 | * ], | |
|
400 | * // setter | |
|
401 | * function(metadata,value){ | |
|
402 | * // we check that the slideshow namespace exist and create it if needed | |
|
403 | * if (metadata.slideshow == undefined){metadata.slideshow = {}} | |
|
404 | * // set the value | |
|
405 | * metadata.slideshow.slide_type = value | |
|
406 | * }, | |
|
407 | * //geter | |
|
408 | * function(metadata){ var ns = metadata.slideshow; | |
|
409 | * // if the slideshow namespace does not exist return `undefined` | |
|
410 | * // (will be interpreted as `false` by checkbox) otherwise | |
|
411 | * // return the value | |
|
412 | * return (ns == undefined)? undefined: ns.slide_type | |
|
413 | * } | |
|
414 | * MetaUI.register_callback('slideshow.select',select_type); | |
|
415 | * | |
|
416 | */ | |
|
417 | MetaUI.utils.select_ui_generator = function(list_list,setter, getter, label){ | |
|
418 | label= label? label: ""; | |
|
419 | return function(div, cell) { | |
|
420 | var button_container = $(div) | |
|
421 | var lbl = $("<label/>").append($('<span/>').text(label).css('font-size','77%')); | |
|
422 | var select = $('<select/>'); | |
|
423 | for(var itemn in list_list){ | |
|
424 | var opt = $('<option/>'); | |
|
425 | opt.attr('value',list_list[itemn][1]) | |
|
426 | opt.text(list_list[itemn][0]) | |
|
427 | select.append(opt); | |
|
428 | } | |
|
429 | select.val(getter(cell.metadata)); | |
|
430 | ||
|
431 | select.change(function(){ | |
|
432 | setter(cell.metadata,select.val()); | |
|
433 | }); | |
|
434 | button_container.append($('<div/>').append(lbl).append(select)); | |
|
435 | ||
|
436 | } | |
|
437 | }; | |
|
438 | ||
|
439 | ||
|
373 | 440 | IPython.MetaUI = MetaUI; |
|
374 | 441 | |
|
375 | 442 | return IPython; |
General Comments 0
You need to be logged in to leave comments.
Login now