##// END OF EJS Templates
cleanup style fixed in separate PR and few other things
cleanup style fixed in separate PR and few other things

File last commit:

r18282:ba2ee9ad
r18290:b725fa90
Show More
celltoolbar.js
448 lines | 15.8 KiB | application/javascript | JavascriptLexer
Jonathan Frederic
Progress...
r17196 // Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
define([
'base/js/namespace',
Jonathan Frederic
MWE,...
r17200 'jquery',
Matthias BUSSONNIER
Use global event for celltoolbar
r17454 'base/js/events'
Matthias BUSSONNIER
rename ipevents to events for consistency
r17455 ], function(IPython, $, events) {
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 "use strict";
Jonathan Frederic
More review changes
r17214 var CellToolbar = function (options) {
// Constructor
//
// Parameters:
// options: dictionary
// Dictionary of keyword arguments.
// events: $(Events) instance
// cell: Cell instance
// notebook: Notebook instance
Matthias BUSSONNIER
a few todo
r17421 //
// TODO: This leaks, when cell are deleted
// There is still a reference to each celltoolbars.
Matthias BUSSONNIER
rename metaui -> celltoolbar
r9064 CellToolbar._instances.push(this);
Jonathan Frederic
More review changes
r17214 this.notebook = options.notebook;
this.cell = options.cell;
Brian E. Granger
Fixing styling issues with CellToolbar....
r9142 this.create_element();
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 this.rebuild();
return this;
};
Brian E. Granger
Fixing styling issues with CellToolbar....
r9142
CellToolbar.prototype.create_element = function () {
Jonathan Frederic
Progress...
r17196 this.inner_element = $('<div/>').addClass('celltoolbar');
Brian Granger
Further cleanup for celltoolbars.
r9144 this.element = $('<div/>').addClass('ctb_hideshow')
Matthias BUSSONNIER
remove one useless element
r9462 .append(this.inner_element);
Brian E. Granger
Fixing styling issues with CellToolbar....
r9142 };
Brian Granger
Minor tweaks to the css to enable single cell hide/show.
r9145 // The default css style for the outer celltoolbar div
MinRK
tweak global hide/show...
r13667 // (ctb_hideshow) is display: none.
// To show the cell toolbar, *both* of the following conditions must be met:
// - A parent container has class `ctb_global_show`
// - The celltoolbar has the class `ctb_show`
// This allows global show/hide, as well as per-cell show/hide.
Matthias BUSSONNIER
enable dropdown preset change
r9062
Matthias BUSSONNIER
gshow
r9143 CellToolbar.global_hide = function () {
MinRK
tweak global hide/show...
r13667 $('body').removeClass('ctb_global_show');
};
Brian E. Granger
Fixing styling issues with CellToolbar....
r9142
Matthias BUSSONNIER
gshow
r9143 CellToolbar.global_show = function () {
MinRK
tweak global hide/show...
r13667 $('body').addClass('ctb_global_show');
};
Brian Granger
Minor tweaks to the css to enable single cell hide/show.
r9145
Matthias BUSSONNIER
gshow
r9143 CellToolbar.prototype.hide = function () {
Brian Granger
Further cleanup for celltoolbars.
r9144 this.element.removeClass('ctb_show');
MinRK
tweak global hide/show...
r13667 };
Matthias BUSSONNIER
gshow
r9143
CellToolbar.prototype.show = function () {
Brian Granger
Further cleanup for celltoolbars.
r9144 this.element.addClass('ctb_show');
MinRK
tweak global hide/show...
r13667 };
Brian E. Granger
Fixing styling issues with CellToolbar....
r9142
Matthias BUSSONNIER
enable dropdown preset change
r9062
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 /**
MinRK
tweak global hide/show...
r13667 * Class variable that should contain a dict of all available callback
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 * we need to think of wether or not we allow nested namespace
* @property _callback_dict
* @private
Matthias BUSSONNIER
change set_preset to activate_preset...
r9077 * @static
* @type Dict
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 */
Matthias BUSSONNIER
rename metaui -> celltoolbar
r9064 CellToolbar._callback_dict = {};
Matthias BUSSONNIER
Add a per cell toolbar....
r9055
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 /**
* Class variable that should contain the reverse order list of the button
* to add to the toolbar of each cell
Matthias BUSSONNIER
rename _button_list to _ui_controls_list
r9066 * @property _ui_controls_list
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 * @private
Matthias BUSSONNIER
change set_preset to activate_preset...
r9077 * @static
* @type List
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 */
Matthias BUSSONNIER
rename _button_list to _ui_controls_list
r9066 CellToolbar._ui_controls_list = [];
Matthias BUSSONNIER
Add a per cell toolbar....
r9055
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 /**
MinRK
allow cell toolbar presets to apply only to specific cell types
r13670 * Class variable that should contain the CellToolbar instances for each
Matthias BUSSONNIER
change set_preset to activate_preset...
r9077 * cell of the notebook
*
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 * @private
* @property _instances
Matthias BUSSONNIER
change set_preset to activate_preset...
r9077 * @static
* @type List
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 */
MinRK
allow cell toolbar presets to apply only to specific cell types
r13670 CellToolbar._instances = [];
Matthias BUSSONNIER
Add a per cell toolbar....
r9055
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 /**
MinRK
allow cell toolbar presets to apply only to specific cell types
r13670 * keep a list of all the available presets for the toolbar
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 * @private
* @property _presets
Matthias BUSSONNIER
change set_preset to activate_preset...
r9077 * @static
* @type Dict
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 */
MinRK
allow cell toolbar presets to apply only to specific cell types
r13670 CellToolbar._presets = {};
Matthias BUSSONNIER
Add a per cell toolbar....
r9055
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 // this is by design not a prototype.
/**
* Register a callback to create an UI element in a cell toolbar.
* @method register_callback
* @param name {String} name to use to refer to the callback. It is advised to use a prefix with the name
* for easier sorting and avoid collision
Raffaele De Feo
Added an optional parameter to "CellToolbar.register_callback"....
r16285 * @param callback {function(div, cell)} callback that will be called to generate the ui element
Matthias Bussonnier
rework keyboard management to avoit completer and up/down bugs
r18282 * @param [cell_types] {List_of_String|undefined} optional list of cell types. If present the UI element
Raffaele De Feo
Added an optional parameter to "CellToolbar.register_callback"....
r16285 * will be added only to cells of types in the list.
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 *
*
* The callback will receive the following element :
*
* * a div in which to add element.
Matthias BUSSONNIER
change set_preset to activate_preset...
r9077 * * the cell it is responsible from
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 *
* @example
*
* Example that create callback for a button that toggle between `true` and `false` label,
* with the metadata under the key 'foo' to reflect the status of the button.
*
* // first param reference to a DOM div
* // second param reference to the cell.
* var toggle = function(div, cell) {
* var button_container = $(div)
*
* // let's create a button that show the current value of the metadata
* var button = $('<div/>').button({label:String(cell.metadata.foo)});
*
* // On click, change the metadata value and update the button label
* button.click(function(){
* var v = cell.metadata.foo;
* cell.metadata.foo = !v;
Matthias BUSSONNIER
slightly generalize utils generator
r9072 * button.button("option", "label", String(!v));
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 * })
*
* // add the button to the DOM div.
* button_container.append(button);
* }
*
* // now we register the callback under the name `foo` to give the
* // user the ability to use it later
Matthias BUSSONNIER
slightly generalize utils generator
r9072 * CellToolbar.register_callback('foo', toggle);
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 */
Raffaele De Feo
Added an optional parameter to "CellToolbar.register_callback"....
r16285 CellToolbar.register_callback = function(name, callback, cell_types) {
Matthias BUSSONNIER
change set_preset to activate_preset...
r9077 // Overwrite if it already exists.
Raffaele De Feo
Added an optional parameter to "CellToolbar.register_callback"....
r16285 CellToolbar._callback_dict[name] = cell_types ? {callback: callback, cell_types: cell_types} : callback;
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 };
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 /**
* Register a preset of UI element in a cell toolbar.
* Not supported Yet.
* @method register_preset
* @param name {String} name to use to refer to the preset. It is advised to use a prefix with the name
* for easier sorting and avoid collision
Matthias Bussonnier
rework keyboard management to avoit completer and up/down bugs
r18282 * @param preset_list {List_of_String} reverse order of the button in the toolbar. Each String of the list
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 * should correspond to a name of a registerd callback.
*
* @private
* @example
*
Matthias BUSSONNIER
slightly generalize utils generator
r9072 * CellToolbar.register_callback('foo.c1', function(div, cell){...});
* CellToolbar.register_callback('foo.c2', function(div, cell){...});
* CellToolbar.register_callback('foo.c3', function(div, cell){...});
* CellToolbar.register_callback('foo.c4', function(div, cell){...});
* CellToolbar.register_callback('foo.c5', function(div, cell){...});
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 *
Matthias BUSSONNIER
slightly generalize utils generator
r9072 * CellToolbar.register_preset('foo.foo_preset1', ['foo.c1', 'foo.c2', 'foo.c5'])
* CellToolbar.register_preset('foo.foo_preset2', ['foo.c4', 'foo.c5'])
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 */
Matthias BUSSONNIER
Use global event for celltoolbar
r17454 CellToolbar.register_preset = function(name, preset_list, notebook) {
MinRK
allow cell toolbar presets to apply only to specific cell types
r13670 CellToolbar._presets[name] = preset_list;
Matthias BUSSONNIER
rename ipevents to events for consistency
r17455 events.trigger('preset_added.CellToolbar', {name: name});
Raffaele De Feo
When a preset is activated fire "preset_activated" event....
r16533 // When "register_callback" is called by a custom extension, it may be executed after notebook is loaded.
// In that case, activate the preset if needed.
Matthias BUSSONNIER
Use global event for celltoolbar
r17454 if (notebook && notebook.metadata && notebook.metadata.celltoolbar === name){
CellToolbar.activate_preset(name);
}
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146 };
/**
* List the names of the presets that are currently registered.
*
* @method list_presets
* @static
*/
CellToolbar.list_presets = function() {
var keys = [];
for (var k in CellToolbar._presets) {
keys.push(k);
}
return keys;
};
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 /**
Matthias BUSSONNIER
change set_preset to activate_preset...
r9077 * Activate an UI preset from `register_preset`
*
* This does not update the selection UI.
*
* @method activate_preset
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 * @param preset_name {String} string corresponding to the preset name
*
* @static
* @private
* @example
*
Matthias BUSSONNIER
change set_preset to activate_preset...
r9077 * CellToolbar.activate_preset('foo.foo_preset1');
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 */
Matthias BUSSONNIER
Use global event for celltoolbar
r17454 CellToolbar.activate_preset = function(preset_name){
Matthias BUSSONNIER
rename metaui -> celltoolbar
r9064 var preset = CellToolbar._presets[preset_name];
Matthias BUSSONNIER
Add a per cell toolbar....
r9055
MinRK
allow cell toolbar presets to apply only to specific cell types
r13670 if(preset !== undefined){
Matthias BUSSONNIER
rename _button_list to _ui_controls_list
r9066 CellToolbar._ui_controls_list = preset;
Matthias BUSSONNIER
rename metaui -> celltoolbar
r9064 CellToolbar.rebuild_all();
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 }
Raffaele De Feo
When a preset is activated fire "preset_activated" event....
r16533
Matthias BUSSONNIER
rename ipevents to events for consistency
r17455 events.trigger('preset_activated.CellToolbar', {name: preset_name});
MinRK
allow cell toolbar presets to apply only to specific cell types
r13670 };
Matthias BUSSONNIER
Add a per cell toolbar....
r9055
Matthias BUSSONNIER
enable dropdown preset change
r9062
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 /**
* This should be called on the class and not on a instance as it will trigger
* rebuild of all the instances.
* @method rebuild_all
* @static
*
*/
Matthias BUSSONNIER
rename metaui -> celltoolbar
r9064 CellToolbar.rebuild_all = function(){
MinRK
never use `for (var i in array)`...
r16226 for(var i=0; i < CellToolbar._instances.length; i++){
Matthias BUSSONNIER
rename metaui -> celltoolbar
r9064 CellToolbar._instances[i].rebuild();
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 }
MinRK
allow cell toolbar presets to apply only to specific cell types
r13670 };
Matthias BUSSONNIER
Add a per cell toolbar....
r9055
/**
MinRK
allow cell toolbar presets to apply only to specific cell types
r13670 * Rebuild all the button on the toolbar to update its state.
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 * @method rebuild
*/
Matthias BUSSONNIER
rename metaui -> celltoolbar
r9064 CellToolbar.prototype.rebuild = function(){
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 // strip evrything from the div
MinRK
allow cell toolbar presets to apply only to specific cell types
r13670 // which is probably inner_element
Matthias BUSSONNIER
rename metaui -> celltoolbar
r9064 // or this.element.
this.inner_element.empty();
Raffaele De Feo
Hide the cell toolbar if there are no ui controls in it.
r16286 this.ui_controls_list = [];
Matthias BUSSONNIER
Add a per cell toolbar....
r9055
MinRK
allow cell toolbar presets to apply only to specific cell types
r13670 var callbacks = CellToolbar._callback_dict;
Matthias BUSSONNIER
rename _button_list to _ui_controls_list
r9066 var preset = CellToolbar._ui_controls_list;
MinRK
allow cell toolbar presets to apply only to specific cell types
r13670 // Yes we iterate on the class variable, not the instance one.
MinRK
never use `for (var i in array)`...
r16226 for (var i=0; i < preset.length; i++) {
var key = preset[i];
MinRK
allow cell toolbar presets to apply only to specific cell types
r13670 var callback = callbacks[key];
if (!callback) continue;
Raffaele De Feo
Added an optional parameter to "CellToolbar.register_callback"....
r16285
if (typeof callback === 'object') {
if (callback.cell_types.indexOf(this.cell.cell_type) === -1) continue;
callback = callback.callback;
}
MinRK
allow cell toolbar presets to apply only to specific cell types
r13670
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 var local_div = $('<div/>').addClass('button_container');
MinRK
allow cell toolbar presets to apply only to specific cell types
r13670 try {
callback(local_div, this.cell, this);
Raffaele De Feo
Hide the cell toolbar if there are no ui controls in it.
r16286 this.ui_controls_list.push(key);
MinRK
allow cell toolbar presets to apply only to specific cell types
r13670 } catch (e) {
console.log("Error in cell toolbar callback " + key, e);
continue;
}
// only append if callback succeeded.
this.inner_element.append(local_div);
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 }
Raffaele De Feo
Hide the cell toolbar if there are no ui controls in it.
r16286
Raffaele De Feo
Hide toolbar of rendered text cells.
r16287 // If there are no controls or the cell is a rendered TextCell hide the toolbar.
MinRK
don't hide cell toolbar on rendered text cells...
r17763 if (!this.ui_controls_list.length) {
Raffaele De Feo
Hide the cell toolbar if there are no ui controls in it.
r16286 this.hide();
Raffaele De Feo
Hide toolbar of rendered text cells.
r16287 } else {
this.show();
Raffaele De Feo
Hide the cell toolbar if there are no ui controls in it.
r16286 }
MinRK
allow cell toolbar presets to apply only to specific cell types
r13670 };
Matthias BUSSONNIER
Add a per cell toolbar....
r9055
Matthias BUSSONNIER
rename metaui -> celltoolbar
r9064 CellToolbar.utils = {};
Matthias BUSSONNIER
add utils and docs for metadata UI...
r9056
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146
Matthias BUSSONNIER
add utils and docs for metadata UI...
r9056 /**
Matthias BUSSONNIER
slightly generalize utils generator
r9072 * A utility function to generate bindings between a checkbox and cell/metadata
Matthias BUSSONNIER
add utils and docs for metadata UI...
r9056 * @method utils.checkbox_ui_generator
* @static
*
* @param name {string} Label in front of the checkbox
Matthias BUSSONNIER
slightly generalize utils generator
r9072 * @param setter {function( cell, newValue )}
* A setter method to set the newValue
* @param getter {function( cell )}
* A getter methods which return the current value.
Matthias BUSSONNIER
add utils and docs for metadata UI...
r9056 *
* @return callback {function( div, cell )} Callback to be passed to `register_callback`
*
* @example
*
* An exmple that bind the subkey `slideshow.isSectionStart` to a checkbox with a `New Slide` label
*
Matthias BUSSONNIER
rename metaui -> celltoolbar
r9064 * var newSlide = CellToolbar.utils.checkbox_ui_generator('New Slide',
Matthias BUSSONNIER
add utils and docs for metadata UI...
r9056 * // setter
Matthias BUSSONNIER
slightly generalize utils generator
r9072 * function(cell, value){
Matthias BUSSONNIER
add utils and docs for metadata UI...
r9056 * // we check that the slideshow namespace exist and create it if needed
Matthias BUSSONNIER
slightly generalize utils generator
r9072 * if (cell.metadata.slideshow == undefined){cell.metadata.slideshow = {}}
Matthias BUSSONNIER
add utils and docs for metadata UI...
r9056 * // set the value
Matthias BUSSONNIER
slightly generalize utils generator
r9072 * cell.metadata.slideshow.isSectionStart = value
Matthias BUSSONNIER
add utils and docs for metadata UI...
r9056 * },
* //geter
Matthias BUSSONNIER
slightly generalize utils generator
r9072 * function(cell){ var ns = cell.metadata.slideshow;
Matthias BUSSONNIER
add utils and docs for metadata UI...
r9056 * // if the slideshow namespace does not exist return `undefined`
* // (will be interpreted as `false` by checkbox) otherwise
* // return the value
* return (ns == undefined)? undefined: ns.isSectionStart
* }
* );
*
Matthias BUSSONNIER
rename metaui -> celltoolbar
r9064 * CellToolbar.register_callback('newSlide', newSlide);
Matthias BUSSONNIER
add utils and docs for metadata UI...
r9056 *
*/
Matthias BUSSONNIER
slightly generalize utils generator
r9072 CellToolbar.utils.checkbox_ui_generator = function(name, setter, getter){
MinRK
allow cell toolbar presets to apply only to specific cell types
r13670 return function(div, cell, celltoolbar) {
var button_container = $(div);
Matthias BUSSONNIER
add utils and docs for metadata UI...
r9056
Matthias BUSSONNIER
slightly generalize utils generator
r9072 var chkb = $('<input/>').attr('type', 'checkbox');
Brian E. Granger
Fixing styling issues with CellToolbar....
r9142 var lbl = $('<label/>').append($('<span/>').text(name));
Matthias BUSSONNIER
add utils and docs for metadata UI...
r9056 lbl.append(chkb);
Matthias BUSSONNIER
slightly generalize utils generator
r9072 chkb.attr("checked", getter(cell));
Matthias BUSSONNIER
add utils and docs for metadata UI...
r9056
chkb.click(function(){
Matthias BUSSONNIER
slightly generalize utils generator
r9072 var v = getter(cell);
setter(cell, !v);
chkb.attr("checked", !v);
MinRK
allow cell toolbar presets to apply only to specific cell types
r13670 });
Pierre Gerold
Update celltoolbar.js...
r17265 button_container.append($('<span/>').append(lbl));
MinRK
allow cell toolbar presets to apply only to specific cell types
r13670 };
};
Matthias BUSSONNIER
Add a per cell toolbar....
r9055
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146
Matthias BUSSONNIER
create metadata-dropdowm-menu generator
r9058 /**
Jessica B. Hamrick
Initial version of textbox celltoolbar ui element
r17791 * A utility function to generate bindings between a input field and cell/metadata
* @method utils.input_ui_generator
* @static
*
* @param name {string} Label in front of the input field
* @param setter {function( cell, newValue )}
* A setter method to set the newValue
* @param getter {function( cell )}
* A getter methods which return the current value.
*
* @return callback {function( div, cell )} Callback to be passed to `register_callback`
*
*/
CellToolbar.utils.input_ui_generator = function(name, setter, getter){
return function(div, cell, celltoolbar) {
var button_container = $(div);
Jessica B. Hamrick
Rename chkb to text
r17793 var text = $('<input/>').attr('type', 'text');
Jessica B. Hamrick
Initial version of textbox celltoolbar ui element
r17791 var lbl = $('<label/>').append($('<span/>').text(name));
Jessica B. Hamrick
Rename chkb to text
r17793 lbl.append(text);
text.attr("value", getter(cell));
Jessica B. Hamrick
Initial version of textbox celltoolbar ui element
r17791
Jessica B. Hamrick
Rename chkb to text
r17793 text.keyup(function(){
setter(cell, text.val());
Jessica B. Hamrick
Initial version of textbox celltoolbar ui element
r17791 });
button_container.append($('<span/>').append(lbl));
Jessica B. Hamrick
Register input with keyboard manager, fixes #6426
r17800 IPython.keyboard_manager.register_events(text);
Jessica B. Hamrick
Initial version of textbox celltoolbar ui element
r17791 };
};
/**
Matthias BUSSONNIER
slightly generalize utils generator
r9072 * A utility function to generate bindings between a dropdown list cell
Matthias BUSSONNIER
create metadata-dropdowm-menu generator
r9058 * @method utils.select_ui_generator
* @static
*
Matthias Bussonnier
rework keyboard management to avoit completer and up/down bugs
r18282 * @param list_list {list_of_sublist} List of sublist of metadata value and name in the dropdown list.
Matthias BUSSONNIER
create metadata-dropdowm-menu generator
r9058 * subslit shoud contain 2 element each, first a string that woul be displayed in the dropdown list,
Matthias BUSSONNIER
fixes #4039....
r12649 * and second the corresponding value to be passed to setter/return by getter. the corresponding value
* should not be "undefined" or behavior can be unexpected.
Matthias BUSSONNIER
slightly generalize utils generator
r9072 * @param setter {function( cell, newValue )}
* A setter method to set the newValue
* @param getter {function( cell )}
Matthias BUSSONNIER
create metadata-dropdowm-menu generator
r9058 * A getter methods which return the current value of the metadata.
* @param [label=""] {String} optionnal label for the dropdown menu
*
* @return callback {function( div, cell )} Callback to be passed to `register_callback`
*
* @example
*
Matthias BUSSONNIER
rename metaui -> celltoolbar
r9064 * var select_type = CellToolbar.utils.select_ui_generator([
Matthias BUSSONNIER
fixes #4039....
r12649 * ["<None>" , "None" ],
Matthias BUSSONNIER
slightly generalize utils generator
r9072 * ["Header Slide" , "header_slide" ],
* ["Slide" , "slide" ],
* ["Fragment" , "fragment" ],
* ["Skip" , "skip" ],
Matthias BUSSONNIER
create metadata-dropdowm-menu generator
r9058 * ],
* // setter
Matthias BUSSONNIER
slightly generalize utils generator
r9072 * function(cell, value){
Matthias BUSSONNIER
create metadata-dropdowm-menu generator
r9058 * // we check that the slideshow namespace exist and create it if needed
Matthias BUSSONNIER
slightly generalize utils generator
r9072 * if (cell.metadata.slideshow == undefined){cell.metadata.slideshow = {}}
Matthias BUSSONNIER
create metadata-dropdowm-menu generator
r9058 * // set the value
Matthias BUSSONNIER
slightly generalize utils generator
r9072 * cell.metadata.slideshow.slide_type = value
Matthias BUSSONNIER
create metadata-dropdowm-menu generator
r9058 * },
* //geter
Matthias BUSSONNIER
slightly generalize utils generator
r9072 * function(cell){ var ns = cell.metadata.slideshow;
Matthias BUSSONNIER
create metadata-dropdowm-menu generator
r9058 * // if the slideshow namespace does not exist return `undefined`
* // (will be interpreted as `false` by checkbox) otherwise
* // return the value
* return (ns == undefined)? undefined: ns.slide_type
* }
Matthias BUSSONNIER
slightly generalize utils generator
r9072 * CellToolbar.register_callback('slideshow.select', select_type);
Matthias BUSSONNIER
create metadata-dropdowm-menu generator
r9058 *
*/
Raffaele De Feo
Removed "cell_types" parameter from "select_ui_generator"....
r16316 CellToolbar.utils.select_ui_generator = function(list_list, setter, getter, label) {
MinRK
allow cell toolbar presets to apply only to specific cell types
r13670 label = label || "";
return function(div, cell, celltoolbar) {
var button_container = $(div);
Brian E. Granger
Fixing styling issues with CellToolbar....
r9142 var lbl = $("<label/>").append($('<span/>').text(label));
Matthias BUSSONNIER
get rid of some jq-ui- style
r17759 var select = $('<select/>');
MinRK
never use `for (var i in array)`...
r16226 for(var i=0; i < list_list.length; i++){
MinRK
allow cell toolbar presets to apply only to specific cell types
r13670 var opt = $('<option/>')
MinRK
never use `for (var i in array)`...
r16226 .attr('value', list_list[i][1])
.text(list_list[i][0]);
Matthias BUSSONNIER
create metadata-dropdowm-menu generator
r9058 select.append(opt);
}
Matthias BUSSONNIER
slightly generalize utils generator
r9072 select.val(getter(cell));
Matthias BUSSONNIER
create metadata-dropdowm-menu generator
r9058 select.change(function(){
Matthias BUSSONNIER
slightly generalize utils generator
r9072 setter(cell, select.val());
Matthias BUSSONNIER
create metadata-dropdowm-menu generator
r9058 });
Pierre Gerold
Update celltoolbar.js...
r17265 button_container.append($('<span/>').append(lbl).append(select));
MinRK
allow cell toolbar presets to apply only to specific cell types
r13670 };
Matthias BUSSONNIER
create metadata-dropdowm-menu generator
r9058 };
Jonathan Frederic
Progress...
r17196 // Backwards compatability.
Matthias BUSSONNIER
rename metaui -> celltoolbar
r9064 IPython.CellToolbar = CellToolbar;
Matthias BUSSONNIER
Add a per cell toolbar....
r9055
Jonathan Frederic
Return dicts instead of classes,...
r17201 return {'CellToolbar': CellToolbar};
Jonathan Frederic
Progress...
r17196 });