##// END OF EJS Templates
add default celltoolbar UI
Matthias BUSSONNIER -
Show More
@@ -0,0 +1,94 b''
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2012 The IPython Development Team
3 //
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
7
8 //============================================================================
9 // CellToolbar Default
10 //============================================================================
11
12 /**
13 * Example Use for the CellToolbar library
14 */
15 // IIFE without asignement, we don't modifiy the IPython namespace
16 (function (IPython) {
17 "use strict";
18
19 var CellToolbar = IPython.CellToolbar;
20
21 var raw_edit = function(cell){
22
23 var md = cell.metadata
24 var error_div = $('<div/>').css('color','red')
25
26 var textarea = $('<textarea/>')
27 .attr('rows','13')
28 .attr('cols','75')
29 .attr('name','metadata')
30 .text(JSON.stringify(md, null,4)||'');
31 var dialogform = $('<div/>').attr('title','Edit the metadata')
32 .append(
33 $('<form/>').append(
34 $('<fieldset/>').append(
35 $('<label/>')
36 .attr('for','metadata')
37 .text("Metadata (I know what I'm dooing and I won't complain if it breaks my notebook)")
38 )
39 .append(error_div)
40 .append($('<br/>'))
41 .append(
42 textarea
43 )
44 )
45 );
46 var editor = CodeMirror.fromTextArea(textarea[0], {
47 lineNumbers: true,
48 matchBrackets: true,
49 });
50 $(dialogform).dialog({
51 autoOpen: true,
52 height: 300,
53 width: 650,
54 modal: true,
55 buttons: {
56 "Ok": function() {
57 //validate json and set it
58 try {
59 var json = JSON.parse(editor.getValue());
60 cell.metadata = json;
61 $( this ).dialog( "close" );
62 }
63 catch(e)
64 {
65 error_div.text('Warning, invalid json, not saved');
66 }
67 },
68 Cancel: function() {
69 $( this ).dialog( "close" );
70 }
71 },
72 close: function() {
73 //cleanup on close
74 $(this).remove();
75 }
76 });
77 editor.refresh();
78 }
79
80 var add_raw_edit_button = function(div, cell) {
81 var button_container = div
82 var button = $('<div/>').button({label:'Raw Edit'})
83 .click(function(){raw_edit(cell); return false;})
84 button_container.append(button);
85 }
86
87 CellToolbar.register_callback('default.rawedit',add_raw_edit_button);
88 var example_preset = []
89 example_preset.push('default.rawedit');
90
91 CellToolbar.register_preset('default',example_preset);
92 console.log('Default extension for metadata editting loaded.');
93
94 }(IPython));
@@ -24,78 +24,6 b''
24
24
25 var CellToolbar = IPython.CellToolbar;
25 var CellToolbar = IPython.CellToolbar;
26
26
27
28 var raw_edit = function(cell){
29
30 var md = cell.metadata
31 var error_div = $('<div/>').css('color','red')
32
33 var textarea = $('<textarea/>')
34 .attr('rows','13')
35 .attr('cols','75')
36 .attr('name','metadata')
37 .text(JSON.stringify(md, null,4)||'');
38 var dialogform = $('<div/>').attr('title','Edit the metadata')
39 .append(
40 $('<form/>').append(
41 $('<fieldset/>').append(
42 $('<label/>')
43 .attr('for','metadata')
44 .text("Metadata (I know what I'm dooing and I won't complain if it breaks my notebook)")
45 )
46 .append(error_div)
47 .append($('<br/>'))
48 .append(
49 textarea
50 )
51 )
52 );
53 var editor = CodeMirror.fromTextArea(textarea[0], {
54 lineNumbers: true,
55 matchBrackets: true,
56 });
57 $(dialogform).dialog({
58 autoOpen: true,
59 height: 300,
60 width: 650,
61 modal: true,
62 buttons: {
63 "Ok": function() {
64 //validate json and set it
65 try {
66 var json = JSON.parse(editor.getValue());
67 cell.metadata = json;
68 $( this ).dialog( "close" );
69 }
70 catch(e)
71 {
72 error_div.text('Warning, invalid json, not saved');
73 }
74 },
75 Cancel: function() {
76 $( this ).dialog( "close" );
77 }
78 },
79 close: function() {
80 //cleanup on close
81 $(this).remove();
82 }
83 });
84 editor.refresh();
85 }
86
87 var add_raw_edit_button = function(div, cell) {
88 var button_container = div
89 var button = $('<div/>').button({label:'Raw Edit'})
90 .click(function(){raw_edit(cell); return false;})
91 button_container.append(button);
92 }
93
94 CellToolbar.register_callback('example.rawedit',add_raw_edit_button);
95 var example_preset = []
96 example_preset.push('example.rawedit');
97
98
99 var simple_button = function(div, cell) {
27 var simple_button = function(div, cell) {
100 var button_container = $(div);
28 var button_container = $(div);
101 var button = $('<div/>').button({icons:{primary:'ui-icon-locked'}});
29 var button = $('<div/>').button({icons:{primary:'ui-icon-locked'}});
General Comments 0
You need to be logged in to leave comments. Login now