Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50654 views
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 Example
10
//============================================================================
11
12
(function(IPython) {
13
"use strict";
14
15
var CellToolbar = IPython.CellToolbar;
16
var raw_cell_preset = [];
17
18
var select_type = CellToolbar.utils.select_ui_generator([
19
["None", "-"],
20
["LaTeX", "text/latex"],
21
["reST", "text/restructuredtext"],
22
["HTML", "text/html"],
23
["Markdown", "text/markdown"],
24
["Python", "text/x-python"],
25
["Custom", "dialog"],
26
27
],
28
// setter
29
function(cell, value) {
30
if (value === "-") {
31
delete cell.metadata.raw_mimetype;
32
} else if (value === 'dialog'){
33
var dialog = $('<div/>').append(
34
$("<p/>")
35
.text("Set the MIME type of the raw cell:")
36
).append(
37
$("<br/>")
38
).append(
39
$('<input/>').attr('type','text').attr('size','25')
40
.val(cell.metadata.raw_mimetype || "-")
41
);
42
IPython.dialog.modal({
43
title: "Raw Cell MIME Type",
44
body: dialog,
45
buttons : {
46
"Cancel": {},
47
"OK": {
48
class: "btn-primary",
49
click: function () {
50
console.log(cell);
51
cell.metadata.raw_mimetype = $(this).find('input').val();
52
console.log(cell.metadata);
53
}
54
}
55
},
56
open : function (event, ui) {
57
var that = $(this);
58
// Upon ENTER, click the OK button.
59
that.find('input[type="text"]').keydown(function (event, ui) {
60
if (event.which === IPython.keyboard.keycodes.enter) {
61
that.find('.btn-primary').first().click();
62
return false;
63
}
64
});
65
that.find('input[type="text"]').focus().select();
66
}
67
});
68
} else {
69
cell.metadata.raw_mimetype = value;
70
}
71
},
72
//getter
73
function(cell) {
74
return cell.metadata.raw_mimetype || "";
75
},
76
// name
77
"Raw NBConvert Format",
78
// cell_types
79
["raw"]
80
);
81
82
CellToolbar.register_callback('raw_cell.select', select_type);
83
84
raw_cell_preset.push('raw_cell.select');
85
86
CellToolbar.register_preset('Raw Cell Format', raw_cell_preset);
87
console.log('Raw Cell Format toolbar preset loaded.');
88
89
}(IPython));
90
91