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