##// END OF EJS Templates
remove most of the duplicate example
Matthias BUSSONNIER -
Show More
@@ -203,8 +203,6 var IPython = (function (IPython) {
203 // which is probabli metainner.
203 // which is probabli metainner.
204 // or this.element.
204 // or this.element.
205 this.inner_element.empty();
205 this.inner_element.empty();
206 //this.add_raw_edit_button()
207
208
206
209 var cdict = CellToolbar._callback_dict;
207 var cdict = CellToolbar._callback_dict;
210 var preset = CellToolbar._ui_controls_list;
208 var preset = CellToolbar._ui_controls_list;
@@ -219,151 +217,9 var IPython = (function (IPython) {
219
217
220 }
218 }
221
219
222 var raw_edit = function(cell){
220
223
224 var md = cell.metadata
225
226 var textarea = $('<textarea/>')
227 .attr('rows','13')
228 .attr('cols','75')
229 .attr('name','metadata')
230 .text(JSON.stringify(md, null,4)||'');
231 var dialogform = $('<div/>').attr('title','Edit the metadata')
232 .append(
233 $('<form/>').append(
234 $('<fieldset/>').append(
235 $('<label/>')
236 .attr('for','metadata')
237 .text("Metadata (I know what I'm dooing and I won't complain if it breaks my notebook)")
238 )
239 .append($('<br/>'))
240 .append(
241 textarea
242 )
243 )
244 );
245 var editor = CodeMirror.fromTextArea(textarea[0], {
246 lineNumbers: true,
247 matchBrackets: true,
248 });
249 $(dialogform).dialog({
250 autoOpen: true,
251 height: 300,
252 width: 650,
253 modal: true,
254 buttons: {
255 "Ok": function() {
256 //validate json and set it
257 try {
258 var json = JSON.parse(editor.getValue());
259 cell.metadata = json;
260 $( this ).dialog( "close" );
261 }
262 catch(e)
263 {
264 alert('invalid json');
265 }
266 },
267 Cancel: function() {
268 $( this ).dialog( "close" );
269 }
270 },
271 close: function() {
272 //cleanup on close
273 $(this).remove();
274 }
275 });
276 editor.refresh();
277 }
278
279
280 var add_raw_edit_button = function(div, cell) {
281 var button_container = $(div)
282 var button = $('<div/>').button({label:'Raw Edit'})
283 .click(function(){raw_edit(cell); return false;})
284 button_container.append(button);
285 }
286
287 CellToolbar.register_callback('example.rawedit',add_raw_edit_button);
288 var example_preset = []
289 example_preset.push('example.rawedit');
290
291 var simple_dialog = function(title,text){
292 var dlg = $('<div/>').attr('title',title)
293 .append($('<p/>').text(text))
294 $(dlg).dialog({
295 autoOpen: true,
296 height: 300,
297 width: 650,
298 modal: true,
299 close: function() {
300 //cleanup on close
301 $(this).remove();
302 }
303 });
304 }
305
221
306 var add_simple_dialog_button = function(div, cell) {
307 var help_text = ["This is the Metadata editting UI.",
308 "It heavily rely on plugin to work ",
309 "and is still under developpement. You shouldn't wait too long before",
310 " seeing some customisable buttons in those toolbar."
311 ].join('\n')
312 var button_container = $(div)
313 var button = $('<div/>').button({label:'?'})
314 .click(function(){simple_dialog('help',help_text); return false;})
315 button_container.append(button);
316 }
317
318 CellToolbar.register_callback('default.help',add_simple_dialog_button)
319 var default_preset = []
320 default_preset.push('default.help')
321 CellToolbar.register_preset('default',default_preset)
322 CellToolbar.set_preset('default')
323
324 var simple_button = function(div, cell) {
325 var button_container = $(div);
326 var button = $('<div/>').button({icons:{primary:'ui-icon-locked'}});
327 var fun = function(value){
328 try{
329 if(value){
330 cell.code_mirror.setOption('readOnly','nocursor')
331 button.button('option','icons',{primary:'ui-icon-locked'})
332 } else {
333 cell.code_mirror.setOption('readOnly','false')
334 button.button('option','icons',{primary:'ui-icon-unlocked'})
335 }
336 } catch(e){}
337
338 }
339 fun(cell.metadata.ro)
340 button.click(function(){
341 var v = cell.metadata.ro;
342 var locked = !v;
343 cell.metadata.ro = locked;
344 fun(locked)
345 })
346 .css('height','16px')
347 .css('width','35px');
348 button_container.append(button);
349 }
350
351 CellToolbar.register_callback('example.lock',simple_button);
352 example_preset.push('example.lock');
353
354 var toggle_test = function(div, cell) {
355 var button_container = $(div)
356 var button = $('<div/>').button({label:String(cell.metadata.foo)});
357 button.click(function(){
358 var v = cell.metadata.foo;
359 cell.metadata.foo = !v;
360 button.button("option","label",String(!v));
361 })
362 button_container.append(button);
363 }
364
222
365 CellToolbar.register_callback('example.toggle',toggle_test);
366 example_preset.push('example.toggle');
367
223
368 /**
224 /**
369 */
225 */
@@ -177,8 +177,37
177 CellToolbar.register_callback('example.select',select_test);
177 CellToolbar.register_callback('example.select',select_test);
178 example_preset.push('example.select');
178 example_preset.push('example.select');
179
179
180 var simple_dialog = function(title,text){
181 var dlg = $('<div/>').attr('title',title)
182 .append($('<p/>').text(text))
183 $(dlg).dialog({
184 autoOpen: true,
185 height: 300,
186 width: 650,
187 modal: true,
188 close: function() {
189 //cleanup on close
190 $(this).remove();
191 }
192 });
193 }
194
195 var add_simple_dialog_button = function(div, cell) {
196 var help_text = ["This is the Metadata editting UI.",
197 "It heavily rely on plugin to work ",
198 "and is still under developpement. You shouldn't wait too long before",
199 " seeing some customisable buttons in those toolbar."
200 ].join('\n')
201 var button_container = $(div)
202 var button = $('<div/>').button({label:'?'})
203 .click(function(){simple_dialog('help',help_text); return false;})
204 button_container.append(button);
205 }
206
207 CellToolbar.register_callback('example.help',add_simple_dialog_button)
208 example_preset.push('example.help')
209
180 CellToolbar.register_preset('example',example_preset);
210 CellToolbar.register_preset('example',example_preset);
181 CellToolbar.set_preset('example');
182 console.log('Example extension for metadata editting loaded.');
211 console.log('Example extension for metadata editting loaded.');
183
212
184 }(IPython));
213 }(IPython));
General Comments 0
You need to be logged in to leave comments. Login now