Show More
@@ -118,7 +118,9 b' var IPython = (function (IPython) {' | |||||
118 | * @method register_callback |
|
118 | * @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 |
|
119 | * @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 |
|
120 | * for easier sorting and avoid collision | |
121 |
* @param |
|
121 | * @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 | |||
|
123 | * will be added only to cells of types in the list. | |||
122 | * |
|
124 | * | |
123 | * |
|
125 | * | |
124 | * The callback will receive the following element : |
|
126 | * The callback will receive the following element : | |
@@ -154,9 +156,9 b' var IPython = (function (IPython) {' | |||||
154 | * // user the ability to use it later |
|
156 | * // user the ability to use it later | |
155 | * CellToolbar.register_callback('foo', toggle); |
|
157 | * CellToolbar.register_callback('foo', toggle); | |
156 | */ |
|
158 | */ | |
157 | CellToolbar.register_callback = function(name, callback){ |
|
159 | CellToolbar.register_callback = function(name, callback, cell_types) { | |
158 | // Overwrite if it already exists. |
|
160 | // Overwrite if it already exists. | |
159 | CellToolbar._callback_dict[name] = callback; |
|
161 | CellToolbar._callback_dict[name] = cell_types ? {callback: callback, cell_types: cell_types} : callback; | |
160 | }; |
|
162 | }; | |
161 |
|
163 | |||
162 |
|
164 | |||
@@ -256,6 +258,11 b' var IPython = (function (IPython) {' | |||||
256 | var key = preset[i]; |
|
258 | var key = preset[i]; | |
257 | var callback = callbacks[key]; |
|
259 | var callback = callbacks[key]; | |
258 | if (!callback) continue; |
|
260 | if (!callback) continue; | |
|
261 | ||||
|
262 | if (typeof callback === 'object') { | |||
|
263 | if (callback.cell_types.indexOf(this.cell.cell_type) === -1) continue; | |||
|
264 | callback = callback.callback; | |||
|
265 | } | |||
259 |
|
266 | |||
260 | var local_div = $('<div/>').addClass('button_container'); |
|
267 | var local_div = $('<div/>').addClass('button_container'); | |
261 | try { |
|
268 | try { |
General Comments 0
You need to be logged in to leave comments.
Login now