##// END OF EJS Templates
Adjusted "rawcell" toolbar preset to make us of the new "register_callback"...
Raffaele De Feo -
Show More
@@ -1,89 +1,87 b''
1 //----------------------------------------------------------------------------
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2012 The IPython Development Team
2 // Copyright (C) 2012 The IPython Development Team
3 //
3 //
4 // Distributed under the terms of the BSD License. The full license is in
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
6 //----------------------------------------------------------------------------
7
7
8 //============================================================================
8 //============================================================================
9 // CellToolbar Example
9 // CellToolbar Example
10 //============================================================================
10 //============================================================================
11
11
12 (function(IPython) {
12 (function(IPython) {
13 "use strict";
13 "use strict";
14
14
15 var CellToolbar = IPython.CellToolbar;
15 var CellToolbar = IPython.CellToolbar;
16 var raw_cell_preset = [];
16 var raw_cell_preset = [];
17
17
18 var select_type = CellToolbar.utils.select_ui_generator([
18 var select_type = CellToolbar.utils.select_ui_generator([
19 ["None", "-"],
19 ["None", "-"],
20 ["LaTeX", "text/latex"],
20 ["LaTeX", "text/latex"],
21 ["reST", "text/restructuredtext"],
21 ["reST", "text/restructuredtext"],
22 ["HTML", "text/html"],
22 ["HTML", "text/html"],
23 ["Markdown", "text/markdown"],
23 ["Markdown", "text/markdown"],
24 ["Python", "text/x-python"],
24 ["Python", "text/x-python"],
25 ["Custom", "dialog"],
25 ["Custom", "dialog"],
26
26
27 ],
27 ],
28 // setter
28 // setter
29 function(cell, value) {
29 function(cell, value) {
30 if (value === "-") {
30 if (value === "-") {
31 delete cell.metadata.raw_mimetype;
31 delete cell.metadata.raw_mimetype;
32 } else if (value === 'dialog'){
32 } else if (value === 'dialog'){
33 var dialog = $('<div/>').append(
33 var dialog = $('<div/>').append(
34 $("<p/>")
34 $("<p/>")
35 .text("Set the MIME type of the raw cell:")
35 .text("Set the MIME type of the raw cell:")
36 ).append(
36 ).append(
37 $("<br/>")
37 $("<br/>")
38 ).append(
38 ).append(
39 $('<input/>').attr('type','text').attr('size','25')
39 $('<input/>').attr('type','text').attr('size','25')
40 .val(cell.metadata.raw_mimetype || "-")
40 .val(cell.metadata.raw_mimetype || "-")
41 );
41 );
42 IPython.dialog.modal({
42 IPython.dialog.modal({
43 title: "Raw Cell MIME Type",
43 title: "Raw Cell MIME Type",
44 body: dialog,
44 body: dialog,
45 buttons : {
45 buttons : {
46 "Cancel": {},
46 "Cancel": {},
47 "OK": {
47 "OK": {
48 class: "btn-primary",
48 class: "btn-primary",
49 click: function () {
49 click: function () {
50 console.log(cell);
50 console.log(cell);
51 cell.metadata.raw_mimetype = $(this).find('input').val();
51 cell.metadata.raw_mimetype = $(this).find('input').val();
52 console.log(cell.metadata);
52 console.log(cell.metadata);
53 }
53 }
54 }
54 }
55 },
55 },
56 open : function (event, ui) {
56 open : function (event, ui) {
57 var that = $(this);
57 var that = $(this);
58 // Upon ENTER, click the OK button.
58 // Upon ENTER, click the OK button.
59 that.find('input[type="text"]').keydown(function (event, ui) {
59 that.find('input[type="text"]').keydown(function (event, ui) {
60 if (event.which === IPython.keyboard.keycodes.enter) {
60 if (event.which === IPython.keyboard.keycodes.enter) {
61 that.find('.btn-primary').first().click();
61 that.find('.btn-primary').first().click();
62 return false;
62 return false;
63 }
63 }
64 });
64 });
65 that.find('input[type="text"]').focus().select();
65 that.find('input[type="text"]').focus().select();
66 }
66 }
67 });
67 });
68 } else {
68 } else {
69 cell.metadata.raw_mimetype = value;
69 cell.metadata.raw_mimetype = value;
70 }
70 }
71 },
71 },
72 //getter
72 //getter
73 function(cell) {
73 function(cell) {
74 return cell.metadata.raw_mimetype || "";
74 return cell.metadata.raw_mimetype || "";
75 },
75 },
76 // name
76 // name
77 "Raw NBConvert Format",
77 "Raw NBConvert Format"
78 // cell_types
79 ["raw"]
80 );
78 );
81
79
82 CellToolbar.register_callback('raw_cell.select', select_type);
80 CellToolbar.register_callback('raw_cell.select', select_type, ['raw']);
83
81
84 raw_cell_preset.push('raw_cell.select');
82 raw_cell_preset.push('raw_cell.select');
85
83
86 CellToolbar.register_preset('Raw Cell Format', raw_cell_preset);
84 CellToolbar.register_preset('Raw Cell Format', raw_cell_preset);
87 console.log('Raw Cell Format toolbar preset loaded.');
85 console.log('Raw Cell Format toolbar preset loaded.');
88
86
89 }(IPython));
87 }(IPython));
General Comments 0
You need to be logged in to leave comments. Login now