##// END OF EJS Templates
fix css size
Matthias BUSSONNIER -
Show More
@@ -1,415 +1,415
1 /**
1 /**
2 * Primary styles
2 * Primary styles
3 *
3 *
4 * Author: IPython Development Team
4 * Author: IPython Development Team
5 */
5 */
6
6
7
7
8 body {
8 body {
9 overflow: hidden;
9 overflow: hidden;
10 }
10 }
11
11
12 blockquote {
12 blockquote {
13 border-left: 4px solid #DDD;
13 border-left: 4px solid #DDD;
14 padding: 0 15px;
14 padding: 0 15px;
15 color: #777;
15 color: #777;
16 }
16 }
17
17
18 span#save_widget {
18 span#save_widget {
19 padding: 5px;
19 padding: 5px;
20 margin: 0px 0px 0px 300px;
20 margin: 0px 0px 0px 300px;
21 display:inline-block;
21 display:inline-block;
22 }
22 }
23
23
24 span#notebook_name {
24 span#notebook_name {
25 height: 1em;
25 height: 1em;
26 line-height: 1em;
26 line-height: 1em;
27 padding: 3px;
27 padding: 3px;
28 border: none;
28 border: none;
29 font-size: 146.5%;
29 font-size: 146.5%;
30 }
30 }
31
31
32
32
33 .ui-menubar-item .ui-button .ui-button-text {
33 .ui-menubar-item .ui-button .ui-button-text {
34 padding: 0.4em 1.0em;
34 padding: 0.4em 1.0em;
35 font-size: 100%;
35 font-size: 100%;
36 }
36 }
37
37
38 .ui-menu {
38 .ui-menu {
39 -moz-box-shadow: 0px 6px 10px -1px #adadad;
39 -moz-box-shadow: 0px 6px 10px -1px #adadad;
40 -webkit-box-shadow: 0px 6px 10px -1px #adadad;
40 -webkit-box-shadow: 0px 6px 10px -1px #adadad;
41 box-shadow: 0px 6px 10px -1px #adadad;
41 box-shadow: 0px 6px 10px -1px #adadad;
42 }
42 }
43
43
44 .ui-menu .ui-menu-item a {
44 .ui-menu .ui-menu-item a {
45 border: 1px solid transparent;
45 border: 1px solid transparent;
46 padding: 2px 1.6em;
46 padding: 2px 1.6em;
47 }
47 }
48
48
49 .ui-menu .ui-menu-item a.ui-state-focus {
49 .ui-menu .ui-menu-item a.ui-state-focus {
50 margin: 0;
50 margin: 0;
51 }
51 }
52
52
53 .ui-menu hr {
53 .ui-menu hr {
54 margin: 0.3em 0;
54 margin: 0.3em 0;
55 }
55 }
56
56
57 #menubar_container {
57 #menubar_container {
58 position: relative;
58 position: relative;
59 }
59 }
60
60
61 #notification_area {
61 #notification_area {
62 position: absolute;
62 position: absolute;
63 right: 0px;
63 right: 0px;
64 top: 0px;
64 top: 0px;
65 height: 25px;
65 height: 25px;
66 padding: 3px 0px;
66 padding: 3px 0px;
67 padding-right: 3px;
67 padding-right: 3px;
68 z-index: 10;
68 z-index: 10;
69 }
69 }
70
70
71 .notification_widget{
71 .notification_widget{
72 float : right;
72 float : right;
73 right: 0px;
73 right: 0px;
74 top: 1px;
74 top: 1px;
75 height: 25px;
75 height: 25px;
76 padding: 3px 6px;
76 padding: 3px 6px;
77 z-index: 10;
77 z-index: 10;
78 }
78 }
79
79
80 .toolbar {
80 .toolbar {
81 padding: 3px 15px;
81 padding: 3px 15px;
82 }
82 }
83
83
84 #cell_type {
84 #maintoolbar > select, #maintoolbar label {
85 font-size: 85%;
85 font-size: 85%;
86 }
86 }
87
87
88
88
89 div#main_app {
89 div#main_app {
90 width: 100%;
90 width: 100%;
91 position: relative;
91 position: relative;
92 }
92 }
93
93
94 span#quick_help_area {
94 span#quick_help_area {
95 position: static;
95 position: static;
96 padding: 5px 0px;
96 padding: 5px 0px;
97 margin: 0px 0px 0px 0px;
97 margin: 0px 0px 0px 0px;
98 }
98 }
99
99
100 .help_string {
100 .help_string {
101 float: right;
101 float: right;
102 width: 170px;
102 width: 170px;
103 padding: 0px 5px;
103 padding: 0px 5px;
104 text-align: left;
104 text-align: left;
105 font-size: 85%;
105 font-size: 85%;
106 }
106 }
107
107
108 .help_string_label {
108 .help_string_label {
109 float: right;
109 float: right;
110 font-size: 85%;
110 font-size: 85%;
111 }
111 }
112
112
113 div#notebook_panel {
113 div#notebook_panel {
114 margin: 0px 0px 0px 0px;
114 margin: 0px 0px 0px 0px;
115 padding: 0px;
115 padding: 0px;
116 }
116 }
117
117
118 div#notebook {
118 div#notebook {
119 overflow-y: scroll;
119 overflow-y: scroll;
120 overflow-x: auto;
120 overflow-x: auto;
121 width: 100%;
121 width: 100%;
122 /* This spaces the cell away from the edge of the notebook area */
122 /* This spaces the cell away from the edge of the notebook area */
123 padding: 5px 5px 15px 5px;
123 padding: 5px 5px 15px 5px;
124 margin: 0px;
124 margin: 0px;
125 background-color: white;
125 background-color: white;
126 }
126 }
127
127
128 div#pager_splitter {
128 div#pager_splitter {
129 height: 8px;
129 height: 8px;
130 }
130 }
131
131
132 #pager_container {
132 #pager_container {
133 position : relative;
133 position : relative;
134 }
134 }
135
135
136 div#pager {
136 div#pager {
137 padding: 15px;
137 padding: 15px;
138 overflow: auto;
138 overflow: auto;
139 display: none;
139 display: none;
140 }
140 }
141
141
142 div.ui-widget-content {
142 div.ui-widget-content {
143 border: 1px solid #aaa;
143 border: 1px solid #aaa;
144 outline: none;
144 outline: none;
145 }
145 }
146
146
147 .cell {
147 .cell {
148 border: 1px solid transparent;
148 border: 1px solid transparent;
149 }
149 }
150
150
151 div.cell {
151 div.cell {
152 width: 100%;
152 width: 100%;
153 padding: 5px 5px 5px 0px;
153 padding: 5px 5px 5px 0px;
154 /* This acts as a spacer between cells, that is outside the border */
154 /* This acts as a spacer between cells, that is outside the border */
155 margin: 2px 0px 2px 0px;
155 margin: 2px 0px 2px 0px;
156 }
156 }
157
157
158 div.code_cell {
158 div.code_cell {
159 background-color: white;
159 background-color: white;
160 }
160 }
161
161
162 /* any special styling for code cells that are currently running goes here */
162 /* any special styling for code cells that are currently running goes here */
163 div.code_cell.running {
163 div.code_cell.running {
164 }
164 }
165
165
166 div.prompt {
166 div.prompt {
167 /* This needs to be wide enough for 3 digit prompt numbers: In[100]: */
167 /* This needs to be wide enough for 3 digit prompt numbers: In[100]: */
168 width: 11ex;
168 width: 11ex;
169 /* This 0.4em is tuned to match the padding on the CodeMirror editor. */
169 /* This 0.4em is tuned to match the padding on the CodeMirror editor. */
170 padding: 0.4em;
170 padding: 0.4em;
171 margin: 0px;
171 margin: 0px;
172 font-family: monospace;
172 font-family: monospace;
173 text-align:right;
173 text-align:right;
174 }
174 }
175
175
176 div.input {
176 div.input {
177 page-break-inside: avoid;
177 page-break-inside: avoid;
178 }
178 }
179
179
180 /* input_area and input_prompt must match in top border and margin for alignment */
180 /* input_area and input_prompt must match in top border and margin for alignment */
181 div.input_area {
181 div.input_area {
182 color: black;
182 color: black;
183 border: 1px solid #ddd;
183 border: 1px solid #ddd;
184 border-radius: 3px;
184 border-radius: 3px;
185 background: #f7f7f7;
185 background: #f7f7f7;
186 }
186 }
187
187
188 div.input_prompt {
188 div.input_prompt {
189 color: navy;
189 color: navy;
190 border-top: 1px solid transparent;
190 border-top: 1px solid transparent;
191 }
191 }
192
192
193 div.output_wrapper {
193 div.output_wrapper {
194 /* This is a spacer between the input and output of each cell */
194 /* This is a spacer between the input and output of each cell */
195 margin-top: 5px;
195 margin-top: 5px;
196 margin-left: 5px;
196 margin-left: 5px;
197 /* FF needs explicit width to stretch */
197 /* FF needs explicit width to stretch */
198 width: 100%;
198 width: 100%;
199 /* this position must be relative to enable descendents to be absolute within it */
199 /* this position must be relative to enable descendents to be absolute within it */
200 position: relative;
200 position: relative;
201 }
201 }
202
202
203 /* class for the output area when it should be height-limited */
203 /* class for the output area when it should be height-limited */
204 div.output_scroll {
204 div.output_scroll {
205 /* ideally, this would be max-height, but FF barfs all over that */
205 /* ideally, this would be max-height, but FF barfs all over that */
206 height: 24em;
206 height: 24em;
207 /* FF needs this *and the wrapper* to specify full width, or it will shrinkwrap */
207 /* FF needs this *and the wrapper* to specify full width, or it will shrinkwrap */
208 width: 100%;
208 width: 100%;
209
209
210 overflow: auto;
210 overflow: auto;
211 border-radius: 3px;
211 border-radius: 3px;
212 box-shadow: inset 0 2px 8px rgba(0, 0, 0, .8);
212 box-shadow: inset 0 2px 8px rgba(0, 0, 0, .8);
213 }
213 }
214
214
215 /* output div while it is collapsed */
215 /* output div while it is collapsed */
216 div.output_collapsed {
216 div.output_collapsed {
217 margin-right: 5px;
217 margin-right: 5px;
218 }
218 }
219
219
220 div.out_prompt_overlay {
220 div.out_prompt_overlay {
221 height: 100%;
221 height: 100%;
222 padding: 0px;
222 padding: 0px;
223 position: absolute;
223 position: absolute;
224 border-radius: 3px;
224 border-radius: 3px;
225 }
225 }
226
226
227 div.out_prompt_overlay:hover {
227 div.out_prompt_overlay:hover {
228 /* use inner shadow to get border that is computed the same on WebKit/FF */
228 /* use inner shadow to get border that is computed the same on WebKit/FF */
229 box-shadow: inset 0 0 1px #000;
229 box-shadow: inset 0 0 1px #000;
230 background: rgba(240, 240, 240, 0.5);
230 background: rgba(240, 240, 240, 0.5);
231 }
231 }
232
232
233 div.output_prompt {
233 div.output_prompt {
234 color: darkred;
234 color: darkred;
235 /* 5px right shift to account for margin in parent container */
235 /* 5px right shift to account for margin in parent container */
236 margin: 0 5px 0 -5px;
236 margin: 0 5px 0 -5px;
237 }
237 }
238
238
239 /* This class is the outer container of all output sections. */
239 /* This class is the outer container of all output sections. */
240 div.output_area {
240 div.output_area {
241 padding: 0px;
241 padding: 0px;
242 page-break-inside: avoid;
242 page-break-inside: avoid;
243 }
243 }
244
244
245 /* This class is for the output subarea inside the output_area and after
245 /* This class is for the output subarea inside the output_area and after
246 the prompt div. */
246 the prompt div. */
247 div.output_subarea {
247 div.output_subarea {
248 padding: 0.44em 0.4em 0.4em 1px;
248 padding: 0.44em 0.4em 0.4em 1px;
249 }
249 }
250
250
251 /* The rest of the output_* classes are for special styling of the different
251 /* The rest of the output_* classes are for special styling of the different
252 output types */
252 output types */
253
253
254 /* all text output has this class: */
254 /* all text output has this class: */
255 div.output_text {
255 div.output_text {
256 text-align: left;
256 text-align: left;
257 color: black;
257 color: black;
258 font-family: monospace;
258 font-family: monospace;
259 }
259 }
260
260
261 /* stdout/stderr are 'text' as well as 'stream', but pyout/pyerr are *not* streams */
261 /* stdout/stderr are 'text' as well as 'stream', but pyout/pyerr are *not* streams */
262 div.output_stream {
262 div.output_stream {
263 padding-top: 0.0em;
263 padding-top: 0.0em;
264 padding-bottom: 0.0em;
264 padding-bottom: 0.0em;
265 }
265 }
266 div.output_stdout {
266 div.output_stdout {
267 }
267 }
268 div.output_stderr {
268 div.output_stderr {
269 background: #fdd; /* very light red background for stderr */
269 background: #fdd; /* very light red background for stderr */
270 }
270 }
271
271
272 div.output_latex {
272 div.output_latex {
273 text-align: left;
273 text-align: left;
274 color: black;
274 color: black;
275 }
275 }
276
276
277 div.output_html {
277 div.output_html {
278 }
278 }
279
279
280 div.output_png {
280 div.output_png {
281 }
281 }
282
282
283 div.output_jpeg {
283 div.output_jpeg {
284 }
284 }
285
285
286 div.text_cell {
286 div.text_cell {
287 background-color: white;
287 background-color: white;
288 padding: 5px 5px 5px 5px;
288 padding: 5px 5px 5px 5px;
289 }
289 }
290
290
291 div.text_cell_input {
291 div.text_cell_input {
292 color: black;
292 color: black;
293 border: 1px solid #ddd;
293 border: 1px solid #ddd;
294 border-radius: 3px;
294 border-radius: 3px;
295 background: #f7f7f7;
295 background: #f7f7f7;
296 }
296 }
297
297
298 div.text_cell_render {
298 div.text_cell_render {
299 font-family: "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
299 font-family: "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
300 outline: none;
300 outline: none;
301 resize: none;
301 resize: none;
302 width: inherit;
302 width: inherit;
303 border-style: none;
303 border-style: none;
304 padding: 5px;
304 padding: 5px;
305 color: black;
305 color: black;
306 }
306 }
307
307
308 /* The following gets added to the <head> if it is detected that the user has a
308 /* The following gets added to the <head> if it is detected that the user has a
309 * monospace font with inconsistent normal/bold/italic height. See
309 * monospace font with inconsistent normal/bold/italic height. See
310 * notebookmain.js. Such fonts will have keywords vertically offset with
310 * notebookmain.js. Such fonts will have keywords vertically offset with
311 * respect to the rest of the text. The user should select a better font.
311 * respect to the rest of the text. The user should select a better font.
312 * See: https://github.com/ipython/ipython/issues/1503
312 * See: https://github.com/ipython/ipython/issues/1503
313 *
313 *
314 * .CodeMirror span {
314 * .CodeMirror span {
315 * vertical-align: bottom;
315 * vertical-align: bottom;
316 * }
316 * }
317 */
317 */
318
318
319 .CodeMirror {
319 .CodeMirror {
320 line-height: 1.231; /* Changed from 1em to our global default */
320 line-height: 1.231; /* Changed from 1em to our global default */
321 }
321 }
322
322
323 .CodeMirror-scroll {
323 .CodeMirror-scroll {
324 height: auto; /* Changed to auto to autogrow */
324 height: auto; /* Changed to auto to autogrow */
325 /* The CodeMirror docs are a bit fuzzy on if overflow-y should be hidden or visible.*/
325 /* The CodeMirror docs are a bit fuzzy on if overflow-y should be hidden or visible.*/
326 /* We have found that if it is visible, vertical scrollbars appear with font size changes.*/
326 /* We have found that if it is visible, vertical scrollbars appear with font size changes.*/
327 overflow-y: hidden;
327 overflow-y: hidden;
328 overflow-x: auto; /* Changed from auto to remove scrollbar */
328 overflow-x: auto; /* Changed from auto to remove scrollbar */
329 }
329 }
330
330
331 /* CSS font colors for translated ANSI colors. */
331 /* CSS font colors for translated ANSI colors. */
332
332
333
333
334 .ansiblack {color: black;}
334 .ansiblack {color: black;}
335 .ansired {color: darkred;}
335 .ansired {color: darkred;}
336 .ansigreen {color: darkgreen;}
336 .ansigreen {color: darkgreen;}
337 .ansiyellow {color: brown;}
337 .ansiyellow {color: brown;}
338 .ansiblue {color: darkblue;}
338 .ansiblue {color: darkblue;}
339 .ansipurple {color: darkviolet;}
339 .ansipurple {color: darkviolet;}
340 .ansicyan {color: steelblue;}
340 .ansicyan {color: steelblue;}
341 .ansigrey {color: grey;}
341 .ansigrey {color: grey;}
342 .ansibold {font-weight: bold;}
342 .ansibold {font-weight: bold;}
343
343
344 .completions {
344 .completions {
345 position: absolute;
345 position: absolute;
346 z-index: 10;
346 z-index: 10;
347 overflow: hidden;
347 overflow: hidden;
348 border: 1px solid grey;
348 border: 1px solid grey;
349 }
349 }
350
350
351 .completions select {
351 .completions select {
352 background: white;
352 background: white;
353 outline: none;
353 outline: none;
354 border: none;
354 border: none;
355 padding: 0px;
355 padding: 0px;
356 margin: 0px;
356 margin: 0px;
357 overflow: auto;
357 overflow: auto;
358 font-family: monospace;
358 font-family: monospace;
359 }
359 }
360
360
361 option.context {
361 option.context {
362 background-color: #DEF7FF;
362 background-color: #DEF7FF;
363 }
363 }
364 option.introspection {
364 option.introspection {
365 background-color: #EBF4EB;
365 background-color: #EBF4EB;
366 }
366 }
367
367
368 /*fixed part of the completion*/
368 /*fixed part of the completion*/
369 .completions p b {
369 .completions p b {
370 font-weight:bold;
370 font-weight:bold;
371 }
371 }
372
372
373 .completions p {
373 .completions p {
374 background: #DDF;
374 background: #DDF;
375 /*outline: none;
375 /*outline: none;
376 padding: 0px;*/
376 padding: 0px;*/
377 border-bottom: black solid 1px;
377 border-bottom: black solid 1px;
378 padding: 1px;
378 padding: 1px;
379 font-family: monospace;
379 font-family: monospace;
380 }
380 }
381
381
382 pre.dialog {
382 pre.dialog {
383 background-color: #f7f7f7;
383 background-color: #f7f7f7;
384 border: 1px solid #ddd;
384 border: 1px solid #ddd;
385 border-radius: 3px;
385 border-radius: 3px;
386 padding: 0.4em;
386 padding: 0.4em;
387 padding-left: 2em;
387 padding-left: 2em;
388 }
388 }
389
389
390 p.dialog {
390 p.dialog {
391 padding : 0.2em;
391 padding : 0.2em;
392 }
392 }
393
393
394 .shortcut_key {
394 .shortcut_key {
395 display: inline-block;
395 display: inline-block;
396 width: 15ex;
396 width: 15ex;
397 text-align: right;
397 text-align: right;
398 font-family: monospace;
398 font-family: monospace;
399 }
399 }
400
400
401 .shortcut_descr {
401 .shortcut_descr {
402 }
402 }
403
403
404 /* Word-wrap output correctly. This is the CSS3 spelling, though Firefox seems
404 /* Word-wrap output correctly. This is the CSS3 spelling, though Firefox seems
405 to not honor it correctly. Webkit browsers (Chrome, rekonq, Safari) do.
405 to not honor it correctly. Webkit browsers (Chrome, rekonq, Safari) do.
406 */
406 */
407 pre, code, kbd, samp { white-space: pre-wrap; }
407 pre, code, kbd, samp { white-space: pre-wrap; }
408
408
409 #fonttest {
409 #fonttest {
410 font-family: monospace;
410 font-family: monospace;
411 }
411 }
412
412
413 .js-error {
413 .js-error {
414 color: darkred;
414 color: darkred;
415 }
415 }
@@ -1,352 +1,353
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
9 // CellToolbar
10 //============================================================================
10 //============================================================================
11
11
12
12
13 /**
13 /**
14 * A Module to control the per-cell toolbar.
14 * A Module to control the per-cell toolbar.
15 * @module IPython
15 * @module IPython
16 * @namespace IPython
16 * @namespace IPython
17 * @submodule CellToolbar
17 * @submodule CellToolbar
18 */
18 */
19 var IPython = (function (IPython) {
19 var IPython = (function (IPython) {
20 "use strict";
20 "use strict";
21
21
22
22
23 /**
23 /**
24 * @constructor
24 * @constructor
25 * @class CellToolbar
25 * @class CellToolbar
26 * @param {The cell to attach the metadata UI to} cell
26 * @param {The cell to attach the metadata UI to} cell
27 */
27 */
28 var CellToolbar = function (cell) {
28 var CellToolbar = function (cell) {
29 CellToolbar._instances.push(this);
29 CellToolbar._instances.push(this);
30 this.inner_element = $('<div/>');
30 this.inner_element = $('<div/>');
31 this.cell = cell;
31 this.cell = cell;
32 this.element = $('<div/>').addClass('celltoolbar')
32 this.element = $('<div/>').addClass('celltoolbar')
33 .append(this.inner_element)
33 .append(this.inner_element)
34 this.rebuild();
34 this.rebuild();
35 return this;
35 return this;
36 };
36 };
37
37
38 CellToolbar.dropdown_preset_element = $('<select/>')
38 CellToolbar.dropdown_preset_element = $('<select/>')
39 .addClass('ui-widget ui-widget-content')
39 .attr('id','celltoolbar_selector')
40 .attr('id','celltoolbar_selector')
40 .append($('<option/>').attr('value','').text('-'))
41 .append($('<option/>').attr('value','').text('-'))
41
42
42 CellToolbar.dropdown_preset_element.change(function(){
43 CellToolbar.dropdown_preset_element.change(function(){
43 var val = CellToolbar.dropdown_preset_element.val()
44 var val = CellToolbar.dropdown_preset_element.val()
44 if(val ==''){
45 if(val ==''){
45 $('body').removeClass('celltoolbar-on')
46 $('body').removeClass('celltoolbar-on')
46 } else {
47 } else {
47 $('body').addClass('celltoolbar-on')
48 $('body').addClass('celltoolbar-on')
48 CellToolbar.set_preset(val)
49 CellToolbar.set_preset(val)
49 }
50 }
50 })
51 })
51
52
52
53
53
54
54 /**
55 /**
55 * Class variable that should contain a dict of all availlable callback
56 * Class variable that should contain a dict of all availlable callback
56 * we need to think of wether or not we allow nested namespace
57 * we need to think of wether or not we allow nested namespace
57 * @property _callback_dict
58 * @property _callback_dict
58 * @private
59 * @private
59 */
60 */
60 CellToolbar._callback_dict = {};
61 CellToolbar._callback_dict = {};
61
62
62 /**
63 /**
63 * Class variable that should contain the reverse order list of the button
64 * Class variable that should contain the reverse order list of the button
64 * to add to the toolbar of each cell
65 * to add to the toolbar of each cell
65 * @property _ui_controls_list
66 * @property _ui_controls_list
66 * @private
67 * @private
67 */
68 */
68 CellToolbar._ui_controls_list = [];
69 CellToolbar._ui_controls_list = [];
69
70
70 /**
71 /**
71 * keep a list of all instances to
72 * keep a list of all instances to
72 * be able to llop over them...
73 * be able to llop over them...
73 * but how to 'destroy' them ?
74 * but how to 'destroy' them ?
74 * have to think about it...
75 * have to think about it...
75 * or loop over the cells, and find their CellToolbar instances.
76 * or loop over the cells, and find their CellToolbar instances.
76 * @private
77 * @private
77 * @property _instances
78 * @property _instances
78 */
79 */
79 CellToolbar._instances =[]
80 CellToolbar._instances =[]
80
81
81 /**
82 /**
82 * keep a list of all the availlabel presets for the toolbar
83 * keep a list of all the availlabel presets for the toolbar
83 * @private
84 * @private
84 * @property _presets
85 * @property _presets
85 */
86 */
86 CellToolbar._presets ={}
87 CellToolbar._presets ={}
87
88
88 // this is by design not a prototype.
89 // this is by design not a prototype.
89 /**
90 /**
90 * Register a callback to create an UI element in a cell toolbar.
91 * Register a callback to create an UI element in a cell toolbar.
91 * @method register_callback
92 * @method register_callback
92 * @param name {String} name to use to refer to the callback. It is advised to use a prefix with the name
93 * @param name {String} name to use to refer to the callback. It is advised to use a prefix with the name
93 * for easier sorting and avoid collision
94 * for easier sorting and avoid collision
94 * @param callback {function(div, cell)} callback that will be called to generate the ui element
95 * @param callback {function(div, cell)} callback that will be called to generate the ui element
95 *
96 *
96 *
97 *
97 * The callback will receive the following element :
98 * The callback will receive the following element :
98 *
99 *
99 * * a div in which to add element.
100 * * a div in which to add element.
100 * * the cell it is responsable from
101 * * the cell it is responsable from
101 *
102 *
102 * @example
103 * @example
103 *
104 *
104 * Example that create callback for a button that toggle between `true` and `false` label,
105 * Example that create callback for a button that toggle between `true` and `false` label,
105 * with the metadata under the key 'foo' to reflect the status of the button.
106 * with the metadata under the key 'foo' to reflect the status of the button.
106 *
107 *
107 * // first param reference to a DOM div
108 * // first param reference to a DOM div
108 * // second param reference to the cell.
109 * // second param reference to the cell.
109 * var toggle = function(div, cell) {
110 * var toggle = function(div, cell) {
110 * var button_container = $(div)
111 * var button_container = $(div)
111 *
112 *
112 * // let's create a button that show the current value of the metadata
113 * // let's create a button that show the current value of the metadata
113 * var button = $('<div/>').button({label:String(cell.metadata.foo)});
114 * var button = $('<div/>').button({label:String(cell.metadata.foo)});
114 *
115 *
115 * // On click, change the metadata value and update the button label
116 * // On click, change the metadata value and update the button label
116 * button.click(function(){
117 * button.click(function(){
117 * var v = cell.metadata.foo;
118 * var v = cell.metadata.foo;
118 * cell.metadata.foo = !v;
119 * cell.metadata.foo = !v;
119 * button.button("option","label",String(!v));
120 * button.button("option","label",String(!v));
120 * })
121 * })
121 *
122 *
122 * // add the button to the DOM div.
123 * // add the button to the DOM div.
123 * button_container.append(button);
124 * button_container.append(button);
124 * }
125 * }
125 *
126 *
126 * // now we register the callback under the name `foo` to give the
127 * // now we register the callback under the name `foo` to give the
127 * // user the ability to use it later
128 * // user the ability to use it later
128 * CellToolbar.register_callback('foo',toggle);
129 * CellToolbar.register_callback('foo',toggle);
129 */
130 */
130 CellToolbar.register_callback = function(name, callback){
131 CellToolbar.register_callback = function(name, callback){
131 // what do we do if name already exist ?
132 // what do we do if name already exist ?
132 CellToolbar._callback_dict[name] = callback;
133 CellToolbar._callback_dict[name] = callback;
133 };
134 };
134
135
135 /**
136 /**
136 * Register a preset of UI element in a cell toolbar.
137 * Register a preset of UI element in a cell toolbar.
137 * Not supported Yet.
138 * Not supported Yet.
138 * @method register_preset
139 * @method register_preset
139 * @param name {String} name to use to refer to the preset. It is advised to use a prefix with the name
140 * @param name {String} name to use to refer to the preset. It is advised to use a prefix with the name
140 * for easier sorting and avoid collision
141 * for easier sorting and avoid collision
141 * @param preset_list {List of String} reverse order of the button in the toolbar. Each String of the list
142 * @param preset_list {List of String} reverse order of the button in the toolbar. Each String of the list
142 * should correspond to a name of a registerd callback.
143 * should correspond to a name of a registerd callback.
143 *
144 *
144 * @private
145 * @private
145 * @example
146 * @example
146 *
147 *
147 * CellToolbar.register_callback('foo.c1',function(div,cell){...});
148 * CellToolbar.register_callback('foo.c1',function(div,cell){...});
148 * CellToolbar.register_callback('foo.c2',function(div,cell){...});
149 * CellToolbar.register_callback('foo.c2',function(div,cell){...});
149 * CellToolbar.register_callback('foo.c3',function(div,cell){...});
150 * CellToolbar.register_callback('foo.c3',function(div,cell){...});
150 * CellToolbar.register_callback('foo.c4',function(div,cell){...});
151 * CellToolbar.register_callback('foo.c4',function(div,cell){...});
151 * CellToolbar.register_callback('foo.c5',function(div,cell){...});
152 * CellToolbar.register_callback('foo.c5',function(div,cell){...});
152 *
153 *
153 * CellToolbar.register_preset('foo.foo_preset1',['foo.c1','foo.c2','foo.c5'])
154 * CellToolbar.register_preset('foo.foo_preset1',['foo.c1','foo.c2','foo.c5'])
154 * CellToolbar.register_preset('foo.foo_preset2',['foo.c4','foo.c5'])
155 * CellToolbar.register_preset('foo.foo_preset2',['foo.c4','foo.c5'])
155 */
156 */
156 CellToolbar.register_preset = function(name, preset_list){
157 CellToolbar.register_preset = function(name, preset_list){
157 CellToolbar._presets[name] = preset_list
158 CellToolbar._presets[name] = preset_list
158 CellToolbar.dropdown_preset_element.append(
159 CellToolbar.dropdown_preset_element.append(
159 $('<option/>').attr('value',name).text(name)
160 $('<option/>').attr('value',name).text(name)
160 )
161 )
161 }
162 }
162 /**
163 /**
163 * set an UI preset from `register_preset`
164 * set an UI preset from `register_preset`
164 * @method set_preset
165 * @method set_preset
165 * @param preset_name {String} string corresponding to the preset name
166 * @param preset_name {String} string corresponding to the preset name
166 *
167 *
167 * @static
168 * @static
168 * @private
169 * @private
169 * @example
170 * @example
170 *
171 *
171 * CellToolbar.set_preset('foo.foo_preset1');
172 * CellToolbar.set_preset('foo.foo_preset1');
172 */
173 */
173 CellToolbar.set_preset= function(preset_name){
174 CellToolbar.set_preset= function(preset_name){
174 var preset = CellToolbar._presets[preset_name];
175 var preset = CellToolbar._presets[preset_name];
175
176
176 if(preset != undefined){
177 if(preset != undefined){
177 CellToolbar._ui_controls_list = preset;
178 CellToolbar._ui_controls_list = preset;
178 CellToolbar.rebuild_all();
179 CellToolbar.rebuild_all();
179 }
180 }
180 }
181 }
181
182
182
183
183 // this is by design not a prototype.
184 // this is by design not a prototype.
184 /**
185 /**
185 * This should be called on the class and not on a instance as it will trigger
186 * This should be called on the class and not on a instance as it will trigger
186 * rebuild of all the instances.
187 * rebuild of all the instances.
187 * @method rebuild_all
188 * @method rebuild_all
188 * @static
189 * @static
189 *
190 *
190 */
191 */
191 CellToolbar.rebuild_all = function(){
192 CellToolbar.rebuild_all = function(){
192 for(var i in CellToolbar._instances){
193 for(var i in CellToolbar._instances){
193 CellToolbar._instances[i].rebuild();
194 CellToolbar._instances[i].rebuild();
194 }
195 }
195 }
196 }
196
197
197 /**
198 /**
198 * Rebuild all the button on the toolbar to update it's state.
199 * Rebuild all the button on the toolbar to update it's state.
199 * @method rebuild
200 * @method rebuild
200 */
201 */
201 CellToolbar.prototype.rebuild = function(){
202 CellToolbar.prototype.rebuild = function(){
202 // strip evrything from the div
203 // strip evrything from the div
203 // which is probabli metainner.
204 // which is probabli metainner.
204 // or this.element.
205 // or this.element.
205 this.inner_element.empty();
206 this.inner_element.empty();
206
207
207 var cdict = CellToolbar._callback_dict;
208 var cdict = CellToolbar._callback_dict;
208 var preset = CellToolbar._ui_controls_list;
209 var preset = CellToolbar._ui_controls_list;
209 // Yes we iterate on the class varaible, not the instance one.
210 // Yes we iterate on the class varaible, not the instance one.
210 for ( var index in CellToolbar._ui_controls_list){
211 for ( var index in CellToolbar._ui_controls_list){
211 var local_div = $('<div/>').addClass('button_container');
212 var local_div = $('<div/>').addClass('button_container');
212 // Note,
213 // Note,
213 // do this the other way, wrap in try/catch and don't append if any errors.
214 // do this the other way, wrap in try/catch and don't append if any errors.
214 this.inner_element.append(local_div)
215 this.inner_element.append(local_div)
215 cdict[preset[index]](local_div,this.cell)
216 cdict[preset[index]](local_div,this.cell)
216 }
217 }
217
218
218 }
219 }
219
220
220
221
221
222
222
223
223
224
224 /**
225 /**
225 */
226 */
226 CellToolbar.utils = {};
227 CellToolbar.utils = {};
227
228
228 /**
229 /**
229 * A utility function to generate bindings between a checkbox and metadata
230 * A utility function to generate bindings between a checkbox and metadata
230 * @method utils.checkbox_ui_generator
231 * @method utils.checkbox_ui_generator
231 * @static
232 * @static
232 *
233 *
233 * @param name {string} Label in front of the checkbox
234 * @param name {string} Label in front of the checkbox
234 * @param setter {function( metadata_dict, newValue )}
235 * @param setter {function( metadata_dict, newValue )}
235 * A setter method to set the newValue of the metadata dictionnary
236 * A setter method to set the newValue of the metadata dictionnary
236 * @param getter {function( metadata )}
237 * @param getter {function( metadata )}
237 * A getter methods which return the current value of the metadata.
238 * A getter methods which return the current value of the metadata.
238 *
239 *
239 * @return callback {function( div, cell )} Callback to be passed to `register_callback`
240 * @return callback {function( div, cell )} Callback to be passed to `register_callback`
240 *
241 *
241 * @example
242 * @example
242 *
243 *
243 * An exmple that bind the subkey `slideshow.isSectionStart` to a checkbox with a `New Slide` label
244 * An exmple that bind the subkey `slideshow.isSectionStart` to a checkbox with a `New Slide` label
244 *
245 *
245 * var newSlide = CellToolbar.utils.checkbox_ui_generator('New Slide',
246 * var newSlide = CellToolbar.utils.checkbox_ui_generator('New Slide',
246 * // setter
247 * // setter
247 * function(metadata,value){
248 * function(metadata,value){
248 * // we check that the slideshow namespace exist and create it if needed
249 * // we check that the slideshow namespace exist and create it if needed
249 * if (metadata.slideshow == undefined){metadata.slideshow = {}}
250 * if (metadata.slideshow == undefined){metadata.slideshow = {}}
250 * // set the value
251 * // set the value
251 * metadata.slideshow.isSectionStart = value
252 * metadata.slideshow.isSectionStart = value
252 * },
253 * },
253 * //geter
254 * //geter
254 * function(metadata){ var ns = metadata.slideshow;
255 * function(metadata){ var ns = metadata.slideshow;
255 * // if the slideshow namespace does not exist return `undefined`
256 * // if the slideshow namespace does not exist return `undefined`
256 * // (will be interpreted as `false` by checkbox) otherwise
257 * // (will be interpreted as `false` by checkbox) otherwise
257 * // return the value
258 * // return the value
258 * return (ns == undefined)? undefined: ns.isSectionStart
259 * return (ns == undefined)? undefined: ns.isSectionStart
259 * }
260 * }
260 * );
261 * );
261 *
262 *
262 * CellToolbar.register_callback('newSlide', newSlide);
263 * CellToolbar.register_callback('newSlide', newSlide);
263 *
264 *
264 */
265 */
265 CellToolbar.utils.checkbox_ui_generator = function(name,setter,getter){
266 CellToolbar.utils.checkbox_ui_generator = function(name,setter,getter){
266 return function(div, cell) {
267 return function(div, cell) {
267 var button_container = $(div)
268 var button_container = $(div)
268
269
269 var chkb = $('<input/>').attr('type','checkbox');
270 var chkb = $('<input/>').attr('type','checkbox');
270 var lbl = $('<label/>').append($('<span/>').text(name).css('font-size','77%'));
271 var lbl = $('<label/>').append($('<span/>').text(name).css('font-size','77%'));
271 lbl.append(chkb);
272 lbl.append(chkb);
272 chkb.attr("checked",getter(cell.metadata));
273 chkb.attr("checked",getter(cell.metadata));
273
274
274 chkb.click(function(){
275 chkb.click(function(){
275 var v = getter(cell.metadata);
276 var v = getter(cell.metadata);
276 setter(cell.metadata,!v);
277 setter(cell.metadata,!v);
277 chkb.attr("checked",!v);
278 chkb.attr("checked",!v);
278 })
279 })
279 button_container.append($('<div/>').append(lbl));
280 button_container.append($('<div/>').append(lbl));
280
281
281 }
282 }
282 }
283 }
283
284
284 /**
285 /**
285 * A utility function to generate bindings between a dropdown list and metadata
286 * A utility function to generate bindings between a dropdown list and metadata
286 * @method utils.select_ui_generator
287 * @method utils.select_ui_generator
287 * @static
288 * @static
288 *
289 *
289 * @param list_list {list of sublist} List of sublist of metadata value and name in the dropdown list.
290 * @param list_list {list of sublist} List of sublist of metadata value and name in the dropdown list.
290 * subslit shoud contain 2 element each, first a string that woul be displayed in the dropdown list,
291 * subslit shoud contain 2 element each, first a string that woul be displayed in the dropdown list,
291 * and second the corresponding value for the metadata to be passed to setter/return by getter.
292 * and second the corresponding value for the metadata to be passed to setter/return by getter.
292 * @param setter {function( metadata_dict, newValue )}
293 * @param setter {function( metadata_dict, newValue )}
293 * A setter method to set the newValue of the metadata dictionnary
294 * A setter method to set the newValue of the metadata dictionnary
294 * @param getter {function( metadata )}
295 * @param getter {function( metadata )}
295 * A getter methods which return the current value of the metadata.
296 * A getter methods which return the current value of the metadata.
296 * @param [label=""] {String} optionnal label for the dropdown menu
297 * @param [label=""] {String} optionnal label for the dropdown menu
297 *
298 *
298 * @return callback {function( div, cell )} Callback to be passed to `register_callback`
299 * @return callback {function( div, cell )} Callback to be passed to `register_callback`
299 *
300 *
300 * @example
301 * @example
301 *
302 *
302 * var select_type = CellToolbar.utils.select_ui_generator([
303 * var select_type = CellToolbar.utils.select_ui_generator([
303 * ["-" ,undefined ],
304 * ["-" ,undefined ],
304 * ["Header Slide" ,"header_slide" ],
305 * ["Header Slide" ,"header_slide" ],
305 * ["Slide" ,"slide" ],
306 * ["Slide" ,"slide" ],
306 * ["Fragment" ,"fragment" ],
307 * ["Fragment" ,"fragment" ],
307 * ["Skip" ,"skip" ],
308 * ["Skip" ,"skip" ],
308 * ],
309 * ],
309 * // setter
310 * // setter
310 * function(metadata,value){
311 * function(metadata,value){
311 * // we check that the slideshow namespace exist and create it if needed
312 * // we check that the slideshow namespace exist and create it if needed
312 * if (metadata.slideshow == undefined){metadata.slideshow = {}}
313 * if (metadata.slideshow == undefined){metadata.slideshow = {}}
313 * // set the value
314 * // set the value
314 * metadata.slideshow.slide_type = value
315 * metadata.slideshow.slide_type = value
315 * },
316 * },
316 * //geter
317 * //geter
317 * function(metadata){ var ns = metadata.slideshow;
318 * function(metadata){ var ns = metadata.slideshow;
318 * // if the slideshow namespace does not exist return `undefined`
319 * // if the slideshow namespace does not exist return `undefined`
319 * // (will be interpreted as `false` by checkbox) otherwise
320 * // (will be interpreted as `false` by checkbox) otherwise
320 * // return the value
321 * // return the value
321 * return (ns == undefined)? undefined: ns.slide_type
322 * return (ns == undefined)? undefined: ns.slide_type
322 * }
323 * }
323 * CellToolbar.register_callback('slideshow.select',select_type);
324 * CellToolbar.register_callback('slideshow.select',select_type);
324 *
325 *
325 */
326 */
326 CellToolbar.utils.select_ui_generator = function(list_list,setter, getter, label){
327 CellToolbar.utils.select_ui_generator = function(list_list,setter, getter, label){
327 label= label? label: "";
328 label= label? label: "";
328 return function(div, cell) {
329 return function(div, cell) {
329 var button_container = $(div)
330 var button_container = $(div)
330 var lbl = $("<label/>").append($('<span/>').text(label).css('font-size','77%'));
331 var lbl = $("<label/>").append($('<span/>').text(label).css('font-size','77%'));
331 var select = $('<select/>');
332 var select = $('<select/>');
332 for(var itemn in list_list){
333 for(var itemn in list_list){
333 var opt = $('<option/>');
334 var opt = $('<option/>');
334 opt.attr('value',list_list[itemn][1])
335 opt.attr('value',list_list[itemn][1])
335 opt.text(list_list[itemn][0])
336 opt.text(list_list[itemn][0])
336 select.append(opt);
337 select.append(opt);
337 }
338 }
338 select.val(getter(cell.metadata));
339 select.val(getter(cell.metadata));
339
340
340 select.change(function(){
341 select.change(function(){
341 setter(cell.metadata,select.val());
342 setter(cell.metadata,select.val());
342 });
343 });
343 button_container.append($('<div/>').append(lbl).append(select));
344 button_container.append($('<div/>').append(lbl).append(select));
344
345
345 }
346 }
346 };
347 };
347
348
348
349
349 IPython.CellToolbar = CellToolbar;
350 IPython.CellToolbar = CellToolbar;
350
351
351 return IPython;
352 return IPython;
352 }(IPython));
353 }(IPython));
@@ -1,215 +1,217
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 /**
12 /**
13 * Example Use for the CellToolbar library
13 * Example Use for the CellToolbar library
14 * add the following to your custom.js to load
14 * add the following to your custom.js to load
15 * Celltoolbar UI for slideshow
15 * Celltoolbar UI for slideshow
16 *
16 *
17 * ```
17 * ```
18 * $.getScript('/static/js/examples/celltoolbar.example.js');
18 * $.getScript('/static/js/examples/celltoolbar.example.js');
19 * ```
19 * ```
20 */
20 */
21 // IIFE without asignement, we don't modifiy the IPython namespace
21 // IIFE without asignement, we don't modifiy the IPython namespace
22 (function (IPython) {
22 (function (IPython) {
23 "use strict";
23 "use strict";
24
24
25 var CellToolbar = IPython.CellToolbar;
25 var CellToolbar = IPython.CellToolbar;
26
26
27
27
28 var raw_edit = function(cell){
28 var raw_edit = function(cell){
29
29
30 var md = cell.metadata
30 var md = cell.metadata
31 var error_div = $('<div/>').css('color','red')
31 var error_div = $('<div/>').css('color','red')
32
32
33 var textarea = $('<textarea/>')
33 var textarea = $('<textarea/>')
34 .attr('rows','13')
34 .attr('rows','13')
35 .attr('cols','75')
35 .attr('cols','75')
36 .attr('name','metadata')
36 .attr('name','metadata')
37 .text(JSON.stringify(md, null,4)||'');
37 .text(JSON.stringify(md, null,4)||'');
38 var dialogform = $('<div/>').attr('title','Edit the metadata')
38 var dialogform = $('<div/>').attr('title','Edit the metadata')
39 .append(
39 .append(
40 $('<form/>').append(
40 $('<form/>').append(
41 $('<fieldset/>').append(
41 $('<fieldset/>').append(
42 $('<label/>')
42 $('<label/>')
43 .attr('for','metadata')
43 .attr('for','metadata')
44 .text("Metadata (I know what I'm dooing and I won't complain if it breaks my notebook)")
44 .text("Metadata (I know what I'm dooing and I won't complain if it breaks my notebook)")
45 )
45 )
46 .append(error_div)
46 .append(error_div)
47 .append($('<br/>'))
47 .append($('<br/>'))
48 .append(
48 .append(
49 textarea
49 textarea
50 )
50 )
51 )
51 )
52 );
52 );
53 var editor = CodeMirror.fromTextArea(textarea[0], {
53 var editor = CodeMirror.fromTextArea(textarea[0], {
54 lineNumbers: true,
54 lineNumbers: true,
55 matchBrackets: true,
55 matchBrackets: true,
56 });
56 });
57 $(dialogform).dialog({
57 $(dialogform).dialog({
58 autoOpen: true,
58 autoOpen: true,
59 height: 300,
59 height: 300,
60 width: 650,
60 width: 650,
61 modal: true,
61 modal: true,
62 buttons: {
62 buttons: {
63 "Ok": function() {
63 "Ok": function() {
64 //validate json and set it
64 //validate json and set it
65 try {
65 try {
66 var json = JSON.parse(editor.getValue());
66 var json = JSON.parse(editor.getValue());
67 cell.metadata = json;
67 cell.metadata = json;
68 $( this ).dialog( "close" );
68 $( this ).dialog( "close" );
69 }
69 }
70 catch(e)
70 catch(e)
71 {
71 {
72 error_div.text('Warning, invalid json, not saved');
72 error_div.text('Warning, invalid json, not saved');
73 }
73 }
74 },
74 },
75 Cancel: function() {
75 Cancel: function() {
76 $( this ).dialog( "close" );
76 $( this ).dialog( "close" );
77 }
77 }
78 },
78 },
79 close: function() {
79 close: function() {
80 //cleanup on close
80 //cleanup on close
81 $(this).remove();
81 $(this).remove();
82 }
82 }
83 });
83 });
84 editor.refresh();
84 editor.refresh();
85 }
85 }
86
86
87 var add_raw_edit_button = function(div, cell) {
87 var add_raw_edit_button = function(div, cell) {
88 var button_container = $(div)
88 var button_container = $(div)
89 var button = $('<div/>').button({label:'Raw Edit'})
89 var button = $('<div/>').button({label:'Raw Edit'})
90 .click(function(){raw_edit(cell); return false;})
90 .click(function(){raw_edit(cell); return false;})
91 button_container.append(button);
91 button_container.append(button);
92 }
92 }
93
93
94 CellToolbar.register_callback('example.rawedit',add_raw_edit_button);
94 CellToolbar.register_callback('example.rawedit',add_raw_edit_button);
95 var example_preset = []
95 var example_preset = []
96 example_preset.push('example.rawedit');
96 example_preset.push('example.rawedit');
97
97
98
98
99 var simple_button = function(div, cell) {
99 var simple_button = function(div, cell) {
100 var button_container = $(div);
100 var button_container = $(div);
101 var button = $('<div/>').button({icons:{primary:'ui-icon-locked'}});
101 var button = $('<div/>').button({icons:{primary:'ui-icon-locked'}});
102 var fun = function(value){
102 var fun = function(value){
103 try{
103 try{
104 if(value){
104 if(value){
105 cell.code_mirror.setOption('readOnly','nocursor')
105 cell.code_mirror.setOption('readOnly','nocursor')
106 button.button('option','icons',{primary:'ui-icon-locked'})
106 button.button('option','icons',{primary:'ui-icon-locked'})
107 } else {
107 } else {
108 cell.code_mirror.setOption('readOnly','false')
108 cell.code_mirror.setOption('readOnly','false')
109 button.button('option','icons',{primary:'ui-icon-unlocked'})
109 button.button('option','icons',{primary:'ui-icon-unlocked'})
110 }
110 }
111 } catch(e){}
111 } catch(e){}
112
112
113 }
113 }
114 fun(cell.metadata.ro)
114 fun(cell.metadata.ro)
115 button.click(function(){
115 button.click(function(){
116 var v = cell.metadata.ro;
116 var v = cell.metadata.ro;
117 var locked = !v;
117 var locked = !v;
118 cell.metadata.ro = locked;
118 cell.metadata.ro = locked;
119 fun(locked)
119 fun(locked)
120 })
120 })
121 .css('height','16px')
121 .css('height','16px')
122 .css('width','35px');
122 .css('width','35px');
123 button_container.append(button);
123 button_container.append(button);
124 }
124 }
125
125
126 CellToolbar.register_callback('example.lock',simple_button);
126 CellToolbar.register_callback('example.lock',simple_button);
127 example_preset.push('example.lock');
127 example_preset.push('example.lock');
128
128
129 var toggle_test = function(div, cell) {
129 var toggle_test = function(div, cell) {
130 var button_container = $(div)
130 var button_container = $(div)
131 var button = $('<div/>').button({label:String(cell.metadata.foo)});
131 var button = $('<div/>')
132 .button({label:String(cell.metadata.foo)}).
133 css('width','65px');
132 button.click(function(){
134 button.click(function(){
133 var v = cell.metadata.foo;
135 var v = cell.metadata.foo;
134 cell.metadata.foo = !v;
136 cell.metadata.foo = !v;
135 button.button("option","label",String(!v));
137 button.button("option","label",String(!v));
136 })
138 })
137 button_container.append(button);
139 button_container.append(button);
138 }
140 }
139
141
140 CellToolbar.register_callback('example.toggle',toggle_test);
142 CellToolbar.register_callback('example.toggle',toggle_test);
141 example_preset.push('example.toggle');
143 example_preset.push('example.toggle');
142
144
143 var checkbox_test = function(div, cell) {
145 var checkbox_test = function(div, cell) {
144 var button_container = $(div)
146 var button_container = $(div)
145
147
146 var chkb = $('<input/>').attr('type','checkbox');
148 var chkb = $('<input/>').attr('type','checkbox');
147 var lbl = $('<label/>').append($('<span/>').text('bar :').css('font-size','77%'));
149 var lbl = $('<label/>').append($('<span/>').text('bar :').css('font-size','77%'));
148 lbl.append(chkb);
150 lbl.append(chkb);
149 chkb.attr("checked",cell.metadata.bar);
151 chkb.attr("checked",cell.metadata.bar);
150 chkb.click(function(){
152 chkb.click(function(){
151 var v = cell.metadata.bar;
153 var v = cell.metadata.bar;
152 cell.metadata.bar = !v;
154 cell.metadata.bar = !v;
153 chkb.attr("checked",!v);
155 chkb.attr("checked",!v);
154 })
156 })
155 button_container.append($('<div/>').append(lbl));
157 button_container.append($('<div/>').append(lbl));
156
158
157 }
159 }
158
160
159 CellToolbar.register_callback('example.checkbox',checkbox_test);
161 CellToolbar.register_callback('example.checkbox',checkbox_test);
160 example_preset.push('example.checkbox');
162 example_preset.push('example.checkbox');
161
163
162 var select_test = function(div, cell) {
164 var select_test = function(div, cell) {
163 var button_container = $(div)
165 var button_container = $(div)
164
166
165 var select = $('<select/>');
167 var select = $('<select/>');
166
168
167 select.append($('<option/>').attr('value','foo').text('foo'));
169 select.append($('<option/>').attr('value','foo').text('foo'));
168 select.append($('<option/>').attr('value','bar').text('bar'));
170 select.append($('<option/>').attr('value','bar').text('bar'));
169 select.append($('<option/>').attr('value','qux').text('qux'));
171 select.append($('<option/>').attr('value','qux').text('qux'));
170 select.append($('<option/>').attr('value','zip').text('zip'));
172 select.append($('<option/>').attr('value','zip').text('zip'));
171 select.val(cell.metadata.option);
173 select.val(cell.metadata.option);
172 select.change(function(){
174 select.change(function(){
173 cell.metadata.option = select.val();
175 cell.metadata.option = select.val();
174 });
176 });
175 button_container.append($('<div/>').append(select));
177 button_container.append($('<div/>').append(select));
176
178
177 }
179 }
178
180
179 CellToolbar.register_callback('example.select',select_test);
181 CellToolbar.register_callback('example.select',select_test);
180 example_preset.push('example.select');
182 example_preset.push('example.select');
181
183
182 var simple_dialog = function(title,text){
184 var simple_dialog = function(title,text){
183 var dlg = $('<div/>').attr('title',title)
185 var dlg = $('<div/>').attr('title',title)
184 .append($('<p/>').text(text))
186 .append($('<p/>').text(text))
185 $(dlg).dialog({
187 $(dlg).dialog({
186 autoOpen: true,
188 autoOpen: true,
187 height: 300,
189 height: 300,
188 width: 650,
190 width: 650,
189 modal: true,
191 modal: true,
190 close: function() {
192 close: function() {
191 //cleanup on close
193 //cleanup on close
192 $(this).remove();
194 $(this).remove();
193 }
195 }
194 });
196 });
195 }
197 }
196
198
197 var add_simple_dialog_button = function(div, cell) {
199 var add_simple_dialog_button = function(div, cell) {
198 var help_text = ["This is the Metadata editting UI.",
200 var help_text = ["This is the Metadata editting UI.",
199 "It heavily rely on plugin to work ",
201 "It heavily rely on plugin to work ",
200 "and is still under developpement. You shouldn't wait too long before",
202 "and is still under developpement. You shouldn't wait too long before",
201 " seeing some customisable buttons in those toolbar."
203 " seeing some customisable buttons in those toolbar."
202 ].join('\n')
204 ].join('\n')
203 var button_container = $(div)
205 var button_container = $(div)
204 var button = $('<div/>').button({label:'?'})
206 var button = $('<div/>').button({label:'?'})
205 .click(function(){simple_dialog('help',help_text); return false;})
207 .click(function(){simple_dialog('help',help_text); return false;})
206 button_container.append(button);
208 button_container.append(button);
207 }
209 }
208
210
209 CellToolbar.register_callback('example.help',add_simple_dialog_button)
211 CellToolbar.register_callback('example.help',add_simple_dialog_button)
210 example_preset.push('example.help')
212 example_preset.push('example.help')
211
213
212 CellToolbar.register_preset('example',example_preset);
214 CellToolbar.register_preset('example',example_preset);
213 console.log('Example extension for metadata editting loaded.');
215 console.log('Example extension for metadata editting loaded.');
214
216
215 }(IPython));
217 }(IPython));
General Comments 0
You need to be logged in to leave comments. Login now