##// END OF EJS Templates
fix Python mime-type
MinRK -
Show More
@@ -1,90 +1,90 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 var utils = IPython.utils;
17 var utils = IPython.utils;
18
18
19 var select_type = CellToolbar.utils.select_ui_generator([
19 var select_type = CellToolbar.utils.select_ui_generator([
20 ["None", "-"],
20 ["None", "-"],
21 ["LaTeX", "text/latex"],
21 ["LaTeX", "text/latex"],
22 ["restructuredText", "text/restructuredtext"],
22 ["restructuredText", "text/restructuredtext"],
23 ["HTML", "text/html"],
23 ["HTML", "text/html"],
24 ["markdown", "text/markdown"],
24 ["markdown", "text/markdown"],
25 ["Python", "text/python"],
25 ["Python", "application/x-python"],
26 ["Custom", "dialog"],
26 ["Custom", "dialog"],
27
27
28 ],
28 ],
29 // setter
29 // setter
30 function(cell, value) {
30 function(cell, value) {
31 if (value === "-") {
31 if (value === "-") {
32 delete cell.metadata.raw_mimetype;
32 delete cell.metadata.raw_mimetype;
33 } else if (value === 'dialog'){
33 } else if (value === 'dialog'){
34 var dialog = $('<div/>').append(
34 var dialog = $('<div/>').append(
35 $("<p/>")
35 $("<p/>")
36 .html("Set the MIME type of the raw cell:")
36 .html("Set the MIME type of the raw cell:")
37 ).append(
37 ).append(
38 $("<br/>")
38 $("<br/>")
39 ).append(
39 ).append(
40 $('<input/>').attr('type','text').attr('size','25')
40 $('<input/>').attr('type','text').attr('size','25')
41 .val(cell.metadata.raw_mimetype || "-")
41 .val(cell.metadata.raw_mimetype || "-")
42 );
42 );
43 IPython.dialog.modal({
43 IPython.dialog.modal({
44 title: "Raw Cell MIME Type",
44 title: "Raw Cell MIME Type",
45 body: dialog,
45 body: dialog,
46 buttons : {
46 buttons : {
47 "Cancel": {},
47 "Cancel": {},
48 "OK": {
48 "OK": {
49 class: "btn-primary",
49 class: "btn-primary",
50 click: function () {
50 click: function () {
51 console.log(cell);
51 console.log(cell);
52 cell.metadata.raw_mimetype = $(this).find('input').val();
52 cell.metadata.raw_mimetype = $(this).find('input').val();
53 console.log(cell.metadata);
53 console.log(cell.metadata);
54 }
54 }
55 }
55 }
56 },
56 },
57 open : function (event, ui) {
57 open : function (event, ui) {
58 var that = $(this);
58 var that = $(this);
59 // Upon ENTER, click the OK button.
59 // Upon ENTER, click the OK button.
60 that.find('input[type="text"]').keydown(function (event, ui) {
60 that.find('input[type="text"]').keydown(function (event, ui) {
61 if (event.which === utils.keycodes.ENTER) {
61 if (event.which === utils.keycodes.ENTER) {
62 that.find('.btn-primary').first().click();
62 that.find('.btn-primary').first().click();
63 return false;
63 return false;
64 }
64 }
65 });
65 });
66 that.find('input[type="text"]').focus().select();
66 that.find('input[type="text"]').focus().select();
67 }
67 }
68 });
68 });
69 } else {
69 } else {
70 cell.metadata.raw_mimetype = value;
70 cell.metadata.raw_mimetype = value;
71 }
71 }
72 },
72 },
73 //getter
73 //getter
74 function(cell) {
74 function(cell) {
75 return cell.metadata.raw_mimetype || "";
75 return cell.metadata.raw_mimetype || "";
76 },
76 },
77 // name
77 // name
78 "Raw NBConvert Format",
78 "Raw NBConvert Format",
79 // cell_types
79 // cell_types
80 ["raw"]
80 ["raw"]
81 );
81 );
82
82
83 CellToolbar.register_callback('raw_cell.select', select_type);
83 CellToolbar.register_callback('raw_cell.select', select_type);
84
84
85 raw_cell_preset.push('raw_cell.select');
85 raw_cell_preset.push('raw_cell.select');
86
86
87 CellToolbar.register_preset('Raw Cell Format', raw_cell_preset);
87 CellToolbar.register_preset('Raw Cell Format', raw_cell_preset);
88 console.log('Raw Cell Format toolbar preset loaded.');
88 console.log('Raw Cell Format toolbar preset loaded.');
89
89
90 }(IPython)); No newline at end of file
90 }(IPython));
General Comments 0
You need to be logged in to leave comments. Login now