##// END OF EJS Templates
Added function to create Bootstrap specific drop down.
jon -
Show More
@@ -1,219 +1,219 b''
1 1 //----------------------------------------------------------------------------
2 2 // Copyright (C) 2011 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 // ToolBar
10 10 //============================================================================
11 11
12 12 var IPython = (function (IPython) {
13 13 "use strict";
14 14
15 15 var MainToolBar = function (selector) {
16 16 IPython.ToolBar.apply(this, arguments);
17 17 this.construct();
18 18 this.add_celltype_list();
19 19 this.add_celltoolbar_list();
20 20 this.bind_events();
21 21 };
22 22
23 23 MainToolBar.prototype = new IPython.ToolBar();
24 24
25 25 MainToolBar.prototype.construct = function () {
26 26 this.add_buttons_group([
27 27 {
28 28 id : 'save_b',
29 29 label : 'Save and Checkpoint',
30 30 icon : 'icon-save',
31 31 callback : function () {
32 32 IPython.notebook.save_checkpoint();
33 33 }
34 34 }
35 35 ]);
36 36
37 37 this.add_buttons_group([
38 38 {
39 39 id : 'insert_below_b',
40 40 label : 'Insert Cell Below',
41 41 icon : 'icon-plus-sign',
42 42 callback : function () {
43 43 IPython.notebook.insert_cell_below('code');
44 44 IPython.notebook.select_next();
45 45 IPython.notebook.focus_cell();
46 46 }
47 47 }
48 48 ],'insert_above_below');
49 49
50 50 this.add_buttons_group([
51 51 {
52 52 id : 'cut_b',
53 53 label : 'Cut Cell',
54 54 icon : 'icon-cut',
55 55 callback : function () {
56 56 IPython.notebook.cut_cell();
57 57 }
58 58 },
59 59 {
60 60 id : 'copy_b',
61 61 label : 'Copy Cell',
62 62 icon : 'icon-copy',
63 63 callback : function () {
64 64 IPython.notebook.copy_cell();
65 65 }
66 66 },
67 67 {
68 68 id : 'paste_b',
69 69 label : 'Paste Cell Below',
70 70 icon : 'icon-paste',
71 71 callback : function () {
72 72 IPython.notebook.paste_cell_below();
73 73 }
74 74 }
75 75 ],'cut_copy_paste');
76 76
77 77 this.add_buttons_group([
78 78 {
79 79 id : 'move_up_b',
80 80 label : 'Move Cell Up',
81 81 icon : 'icon-arrow-up',
82 82 callback : function () {
83 83 IPython.notebook.move_cell_up();
84 84 }
85 85 },
86 86 {
87 87 id : 'move_down_b',
88 88 label : 'Move Cell Down',
89 89 icon : 'icon-arrow-down',
90 90 callback : function () {
91 91 IPython.notebook.move_cell_down();
92 92 }
93 93 }
94 94 ],'move_up_down');
95
95
96 96
97 97 this.add_buttons_group([
98 98 {
99 99 id : 'run_b',
100 100 label : 'Run Cell',
101 101 icon : 'icon-play',
102 102 callback : function () {
103 103 // emulate default shift-enter behavior
104 104 IPython.notebook.execute_cell_and_select_below();
105 105 }
106 106 },
107 107 {
108 108 id : 'interrupt_b',
109 109 label : 'Interrupt',
110 110 icon : 'icon-stop',
111 111 callback : function () {
112 112 IPython.notebook.session.interrupt_kernel();
113 113 }
114 114 },
115 115 {
116 116 id : 'repeat_b',
117 117 label : 'Restart Kernel',
118 118 icon : 'icon-repeat',
119 119 callback : function () {
120 120 IPython.notebook.restart_kernel();
121 121 }
122 122 }
123 123 ],'run_int');
124 124 };
125 125
126 126 MainToolBar.prototype.add_celltype_list = function () {
127 127 this.element
128 128 .append($('<select/>')
129 129 .attr('id','cell_type')
130 130 // .addClass('ui-widget-content')
131 131 .append($('<option/>').attr('value','code').text('Code'))
132 132 .append($('<option/>').attr('value','markdown').text('Markdown'))
133 133 .append($('<option/>').attr('value','raw').text('Raw NBConvert'))
134 134 .append($('<option/>').attr('value','heading1').text('Heading 1'))
135 135 .append($('<option/>').attr('value','heading2').text('Heading 2'))
136 136 .append($('<option/>').attr('value','heading3').text('Heading 3'))
137 137 .append($('<option/>').attr('value','heading4').text('Heading 4'))
138 138 .append($('<option/>').attr('value','heading5').text('Heading 5'))
139 139 .append($('<option/>').attr('value','heading6').text('Heading 6'))
140 140 );
141 141 };
142 142
143 143
144 144 MainToolBar.prototype.add_celltoolbar_list = function () {
145 145 var label = $('<span/>').addClass("navbar-text").text('Cell Toolbar:');
146 146 var select = $('<select/>')
147 147 // .addClass('ui-widget-content')
148 148 .attr('id', 'ctb_select')
149 149 .append($('<option/>').attr('value', '').text('None'));
150 150 this.element.append(label).append(select);
151 151 select.change(function() {
152 152 var val = $(this).val()
153 153 if (val =='') {
154 154 IPython.CellToolbar.global_hide();
155 155 delete IPython.notebook.metadata.celltoolbar;
156 156 } else {
157 157 IPython.CellToolbar.global_show();
158 158 IPython.CellToolbar.activate_preset(val);
159 159 IPython.notebook.metadata.celltoolbar = val;
160 160 }
161 161 });
162 162 // Setup the currently registered presets.
163 163 var presets = IPython.CellToolbar.list_presets();
164 164 for (var i=0; i<presets.length; i++) {
165 165 var name = presets[i];
166 166 select.append($('<option/>').attr('value', name).text(name));
167 167 }
168 168 // Setup future preset registrations.
169 169 $([IPython.events]).on('preset_added.CellToolbar', function (event, data) {
170 170 var name = data.name;
171 171 select.append($('<option/>').attr('value', name).text(name));
172 172 });
173 173 // Update select value when a preset is activated.
174 174 $([IPython.events]).on('preset_activated.CellToolbar', function (event, data) {
175 175 if (select.val() !== data.name)
176 176 select.val(data.name);
177 177 });
178 178 };
179 179
180 180
181 181 MainToolBar.prototype.bind_events = function () {
182 182 var that = this;
183
183
184 184 this.element.find('#cell_type').change(function () {
185 185 var cell_type = $(this).val();
186 186 if (cell_type === 'code') {
187 187 IPython.notebook.to_code();
188 188 } else if (cell_type === 'markdown') {
189 189 IPython.notebook.to_markdown();
190 190 } else if (cell_type === 'raw') {
191 191 IPython.notebook.to_raw();
192 192 } else if (cell_type === 'heading1') {
193 193 IPython.notebook.to_heading(undefined, 1);
194 194 } else if (cell_type === 'heading2') {
195 195 IPython.notebook.to_heading(undefined, 2);
196 196 } else if (cell_type === 'heading3') {
197 197 IPython.notebook.to_heading(undefined, 3);
198 198 } else if (cell_type === 'heading4') {
199 199 IPython.notebook.to_heading(undefined, 4);
200 200 } else if (cell_type === 'heading5') {
201 201 IPython.notebook.to_heading(undefined, 5);
202 202 } else if (cell_type === 'heading6') {
203 203 IPython.notebook.to_heading(undefined, 6);
204 204 }
205 205 });
206 206 $([IPython.events]).on('selected_cell_type_changed.Notebook', function (event, data) {
207 207 if (data.cell_type === 'heading') {
208 208 that.element.find('#cell_type').val(data.cell_type+data.level);
209 209 } else {
210 210 that.element.find('#cell_type').val(data.cell_type);
211 211 }
212 212 });
213 213 };
214 214
215 215 IPython.MainToolBar = MainToolBar;
216 216
217 217 return IPython;
218 218
219 219 }(IPython));
General Comments 0
You need to be logged in to leave comments. Login now