##// END OF EJS Templates
Merge pull request #6227 from Carreau/cellt-g-event...
Min RK -
r17463:11a830f4 merge
parent child Browse files
Show More
@@ -4,7 +4,8 b''
4 4 define([
5 5 'base/js/namespace',
6 6 'jquery',
7 ], function(IPython, $) {
7 'base/js/events'
8 ], function(IPython, $, events) {
8 9 "use strict";
9 10
10 11 var CellToolbar = function (options) {
@@ -18,7 +19,6 b' define(['
18 19 // notebook: Notebook instance
19 20 CellToolbar._instances.push(this);
20 21 this.notebook = options.notebook;
21 this.events = options.events;
22 22 this.cell = options.cell;
23 23 this.create_element();
24 24 this.rebuild();
@@ -175,13 +175,14 b' define(['
175 175 * CellToolbar.register_preset('foo.foo_preset1', ['foo.c1', 'foo.c2', 'foo.c5'])
176 176 * CellToolbar.register_preset('foo.foo_preset2', ['foo.c4', 'foo.c5'])
177 177 */
178 CellToolbar.register_preset = function(name, preset_list, notebook, events) {
178 CellToolbar.register_preset = function(name, preset_list, notebook) {
179 179 CellToolbar._presets[name] = preset_list;
180 180 events.trigger('preset_added.CellToolbar', {name: name});
181 181 // When "register_callback" is called by a custom extension, it may be executed after notebook is loaded.
182 182 // In that case, activate the preset if needed.
183 if (notebook && notebook.metadata && notebook.metadata.celltoolbar === name)
184 CellToolbar.activate_preset(name, events);
183 if (notebook && notebook.metadata && notebook.metadata.celltoolbar === name){
184 CellToolbar.activate_preset(name);
185 }
185 186 };
186 187
187 188
@@ -214,7 +215,7 b' define(['
214 215 *
215 216 * CellToolbar.activate_preset('foo.foo_preset1');
216 217 */
217 CellToolbar.activate_preset = function(preset_name, events){
218 CellToolbar.activate_preset = function(preset_name){
218 219 var preset = CellToolbar._presets[preset_name];
219 220
220 221 if(preset !== undefined){
@@ -222,9 +223,7 b' define(['
222 223 CellToolbar.rebuild_all();
223 224 }
224 225
225 if (events) {
226 events.trigger('preset_activated.CellToolbar', {name: preset_name});
227 }
226 events.trigger('preset_activated.CellToolbar', {name: preset_name});
228 227 };
229 228
230 229
@@ -34,7 +34,7 b' define(['
34 34 button_container.append(button);
35 35 };
36 36
37 var register = function (notebook, events) {
37 var register = function (notebook) {
38 38 CellToolbar.register_callback('default.rawedit', add_raw_edit_button);
39 39 raw_edit = $.proxy(raw_edit, {
40 40 notebook: notebook,
@@ -44,7 +44,7 b' define(['
44 44 var example_preset = [];
45 45 example_preset.push('default.rawedit');
46 46
47 CellToolbar.register_preset('Edit Metadata', example_preset, notebook, events);
47 CellToolbar.register_preset('Edit Metadata', example_preset, notebook);
48 48 console.log('Default extension for cell metadata editing loaded.');
49 49 };
50 50 return {'register': register};
@@ -137,11 +137,11 b' define(['
137 137 button_container.append(button);
138 138 };
139 139
140 var register = function (notebook, events) {
140 var register = function (notebook) {
141 141 CellToolbar.register_callback('example.help',add_simple_dialog_button);
142 142 example_preset.push('example.help');
143 143
144 CellToolbar.register_preset('Example',example_preset, notebook, events);
144 CellToolbar.register_preset('Example',example_preset, notebook);
145 145 console.log('Example extension for metadata editing loaded.');
146 146 };
147 147 return {'register': register};
@@ -74,11 +74,11 b' define(['
74 74 "Raw NBConvert Format"
75 75 );
76 76
77 var register = function (notebook, events) {
77 var register = function (notebook) {
78 78 CellToolbar.register_callback('raw_cell.select', select_type, ['raw']);
79 79 raw_cell_preset.push('raw_cell.select');
80 80
81 CellToolbar.register_preset('Raw Cell Format', raw_cell_preset, notebook, events);
81 CellToolbar.register_preset('Raw Cell Format', raw_cell_preset, notebook);
82 82 console.log('Raw Cell Format toolbar preset loaded.');
83 83 };
84 84 return {'register': register};
@@ -35,11 +35,11 b' define(['
35 35 },
36 36 "Slide Type");
37 37
38 var register = function (notebook, events) {
38 var register = function (notebook) {
39 39 CellToolbar.register_callback('slideshow.select',select_type);
40 40 slideshow_preset.push('slideshow.select');
41 41
42 CellToolbar.register_preset('Slideshow',slideshow_preset, notebook, events);
42 CellToolbar.register_preset('Slideshow',slideshow_preset, notebook);
43 43 console.log('Slideshow extension for metadata editing loaded.');
44 44 };
45 45 return {'register': register};
@@ -131,7 +131,6 b' define(['
131 131 var inner_cell = $('<div/>').addClass('inner_cell');
132 132 this.celltoolbar = new celltoolbar.CellToolbar({
133 133 cell: this,
134 events: this.events,
135 134 notebook: this.notebook});
136 135 inner_cell.append(this.celltoolbar.element);
137 136 var input_area = $('<div/>').addClass('input_area');
@@ -130,9 +130,9 b' define(['
130 130 };
131 131
132 132 // Trigger cell toolbar registration.
133 default_celltoolbar.register(this, options.events);
134 rawcell_celltoolbar.register(this, options.events);
135 slideshow_celltoolbar.register(this, options.events);
133 default_celltoolbar.register(this);
134 rawcell_celltoolbar.register(this);
135 slideshow_celltoolbar.register(this);
136 136 };
137 137
138 138 /**
@@ -2274,7 +2274,7 b' define(['
2274 2274 // load toolbar state
2275 2275 if (this.metadata.celltoolbar) {
2276 2276 celltoolbar.CellToolbar.global_show();
2277 celltoolbar.CellToolbar.activate_preset(this.metadata.celltoolbar, this.events);
2277 celltoolbar.CellToolbar.activate_preset(this.metadata.celltoolbar);
2278 2278 } else {
2279 2279 celltoolbar.CellToolbar.global_hide();
2280 2280 }
@@ -78,7 +78,6 b' define(['
78 78 var inner_cell = $('<div/>').addClass('inner_cell');
79 79 this.celltoolbar = new celltoolbar.CellToolbar({
80 80 cell: this,
81 events: this.events,
82 81 notebook: this.notebook});
83 82 inner_cell.append(this.celltoolbar.element);
84 83 var input_area = $('<div/>').addClass('input_area');
General Comments 0
You need to be logged in to leave comments. Login now