Show More
@@ -0,0 +1,5 b'' | |||
|
1 | @corner_radius: 3px; | |
|
2 | @notebook_background : white; | |
|
3 | @cell_selected_background: darken(@notebook_background, 2%); | |
|
4 | @cell_background: darken(@notebook_background, 3.2%); | |
|
5 | @border_color: darken(@cell_selected_background, 10%); |
@@ -1,438 +1,444 b'' | |||
|
1 | 1 | /** |
|
2 | 2 | * Primary styles |
|
3 | 3 | * |
|
4 | 4 | * Author: IPython Development Team |
|
5 | 5 | */ |
|
6 | 6 | |
|
7 | @import "variables.less"; | |
|
8 | ||
|
7 | 9 | |
|
8 | 10 | body { |
|
9 | 11 | overflow: hidden; |
|
10 | 12 | } |
|
11 | 13 | |
|
12 | 14 | blockquote { |
|
13 | 15 | border-left: 4px solid #DDD; |
|
14 | 16 | padding: 0 15px; |
|
15 | 17 | color: #777; |
|
16 | 18 | } |
|
17 | 19 | |
|
18 | 20 | span#save_widget { |
|
19 | 21 | padding: 5px; |
|
20 | 22 | margin: 0px 0px 0px 300px; |
|
21 | 23 | display:inline-block; |
|
22 | 24 | } |
|
23 | 25 | |
|
24 | 26 | span#notebook_name { |
|
25 | 27 | height: 1em; |
|
26 | 28 | line-height: 1em; |
|
27 | 29 | padding: 3px; |
|
28 | 30 | border: none; |
|
29 | 31 | font-size: 146.5%; |
|
30 | 32 | } |
|
31 | 33 | |
|
32 | 34 | |
|
33 | 35 | .ui-menubar-item .ui-button .ui-button-text { |
|
34 | 36 | padding: 0.4em 1.0em; |
|
35 | 37 | font-size: 100%; |
|
36 | 38 | } |
|
37 | 39 | |
|
38 | 40 | .ui-menu { |
|
39 | 41 | -moz-box-shadow: 0px 6px 10px -1px #adadad; |
|
40 | 42 | -webkit-box-shadow: 0px 6px 10px -1px #adadad; |
|
41 | 43 | box-shadow: 0px 6px 10px -1px #adadad; |
|
42 | 44 | } |
|
43 | 45 | |
|
44 | 46 | .ui-menu .ui-menu-item a { |
|
45 | 47 | border: 1px solid transparent; |
|
46 | 48 | padding: 2px 1.6em; |
|
47 | 49 | } |
|
48 | 50 | |
|
49 | 51 | .ui-menu .ui-menu-item a.ui-state-focus { |
|
50 | 52 | margin: 0; |
|
51 | 53 | } |
|
52 | 54 | |
|
53 | 55 | .ui-menu hr { |
|
54 | 56 | margin: 0.3em 0; |
|
55 | 57 | } |
|
56 | 58 | |
|
57 | 59 | #menubar_container { |
|
58 | 60 | position: relative; |
|
59 | 61 | } |
|
60 | 62 | |
|
61 | 63 | #notification_area { |
|
62 | 64 | position: absolute; |
|
63 | 65 | right: 0px; |
|
64 | 66 | top: 0px; |
|
65 | 67 | height: 25px; |
|
66 | 68 | padding: 3px 0px; |
|
67 | 69 | padding-right: 3px; |
|
68 | 70 | z-index: 10; |
|
69 | 71 | } |
|
70 | 72 | |
|
71 | 73 | .notification_widget{ |
|
72 | 74 | float : right; |
|
73 | 75 | right: 0px; |
|
74 | 76 | top: 1px; |
|
75 | 77 | height: 25px; |
|
76 | 78 | padding: 3px 6px; |
|
77 | 79 | z-index: 10; |
|
78 | 80 | } |
|
79 | 81 | |
|
80 | 82 | .toolbar { |
|
81 | 83 | padding: 3px 15px; |
|
82 | 84 | } |
|
83 | 85 | |
|
84 | 86 | #maintoolbar > select, #maintoolbar label { |
|
85 | 87 | font-size: 85%; |
|
86 | 88 | margin-left:0.3em; |
|
87 | 89 | margin-right:0.3em; |
|
88 | 90 | |
|
89 | 91 | } |
|
90 | 92 | |
|
91 | 93 | |
|
92 | 94 | div#main_app { |
|
93 | 95 | width: 100%; |
|
94 | 96 | position: relative; |
|
95 | 97 | } |
|
96 | 98 | |
|
97 | 99 | span#quick_help_area { |
|
98 | 100 | position: static; |
|
99 | 101 | padding: 5px 0px; |
|
100 | 102 | margin: 0px 0px 0px 0px; |
|
101 | 103 | } |
|
102 | 104 | |
|
103 | 105 | .help_string { |
|
104 | 106 | float: right; |
|
105 | 107 | width: 170px; |
|
106 | 108 | padding: 0px 5px; |
|
107 | 109 | text-align: left; |
|
108 | 110 | font-size: 85%; |
|
109 | 111 | } |
|
110 | 112 | |
|
111 | 113 | .help_string_label { |
|
112 | 114 | float: right; |
|
113 | 115 | font-size: 85%; |
|
114 | 116 | } |
|
115 | 117 | |
|
116 | 118 | div#notebook_panel { |
|
117 | 119 | margin: 0px 0px 0px 0px; |
|
118 | 120 | padding: 0px; |
|
119 | 121 | } |
|
120 | 122 | |
|
121 | 123 | div#notebook { |
|
122 | 124 | overflow-y: scroll; |
|
123 | 125 | overflow-x: auto; |
|
124 | 126 | width: 100%; |
|
125 | 127 | /* This spaces the cell away from the edge of the notebook area */ |
|
126 | 128 | padding: 5px 5px 15px 5px; |
|
127 | 129 | margin: 0px; |
|
128 |
background-color: |
|
|
130 | background-color: @notebook_background; | |
|
129 | 131 | } |
|
130 | 132 | |
|
131 | 133 | div#pager_splitter { |
|
132 | 134 | height: 8px; |
|
133 | 135 | } |
|
134 | 136 | |
|
135 | 137 | #pager_container { |
|
136 | 138 | position : relative; |
|
137 | 139 | } |
|
138 | 140 | |
|
139 | 141 | div#pager { |
|
140 | 142 | padding: 15px; |
|
141 | 143 | overflow: auto; |
|
142 | 144 | display: none; |
|
143 | 145 | } |
|
144 | 146 | |
|
145 | 147 | div.ui-widget-content { |
|
146 |
border: 1px solid |
|
|
148 | border: 1px solid @border_color; | |
|
147 | 149 | outline: none; |
|
148 | 150 | } |
|
149 | 151 | |
|
150 | 152 | .cell { |
|
151 | 153 | border: 1px solid transparent; |
|
154 | ||
|
155 | &.selected { | |
|
156 | border-radius: @corner_radius; | |
|
157 | background-color:@cell_selected_background; | |
|
158 | border : thin @border_color solid; | |
|
159 | } | |
|
152 | 160 | } |
|
153 | 161 | |
|
154 | 162 | div.cell { |
|
155 | 163 | width: 100%; |
|
156 | 164 | padding: 5px 5px 5px 0px; |
|
157 | 165 | /* This acts as a spacer between cells, that is outside the border */ |
|
158 | 166 | margin: 2px 0px 2px 0px; |
|
159 | 167 | outline: none; |
|
160 | 168 | } |
|
161 | 169 | |
|
162 | 170 | div.code_cell { |
|
163 | background-color: white; | |
|
164 | 171 | } |
|
165 | 172 | |
|
166 | 173 | /* any special styling for code cells that are currently running goes here */ |
|
167 | 174 | div.code_cell.running { |
|
168 | 175 | } |
|
169 | 176 | |
|
170 | 177 | div.prompt { |
|
171 | 178 | /* This needs to be wide enough for 3 digit prompt numbers: In[100]: */ |
|
172 | 179 | width: 11ex; |
|
173 | 180 | /* This 0.4em is tuned to match the padding on the CodeMirror editor. */ |
|
174 | 181 | padding: 0.4em; |
|
175 | 182 | margin: 0px; |
|
176 | 183 | font-family: monospace; |
|
177 | 184 | text-align: right; |
|
178 | 185 | /* This has to match that of the the CodeMirror class line-height below */ |
|
179 | 186 | line-height: 1.231; |
|
180 | 187 | } |
|
181 | 188 | |
|
182 | 189 | div.input { |
|
183 | 190 | page-break-inside: avoid; |
|
184 | 191 | } |
|
185 | 192 | |
|
186 | 193 | /* input_area and input_prompt must match in top border and margin for alignment */ |
|
187 | 194 | div.input_area { |
|
188 | 195 | color: black; |
|
189 |
border: 1px solid |
|
|
190 |
border-radius: |
|
|
191 | background: #f7f7f7; | |
|
196 | border: 1px solid @border_color; | |
|
197 | border-radius: @corner_radius; | |
|
198 | background: @cell_background; | |
|
192 | 199 | } |
|
193 | 200 | |
|
194 | 201 | div.input_prompt { |
|
195 | 202 | color: navy; |
|
196 | 203 | border-top: 1px solid transparent; |
|
197 | 204 | } |
|
198 | 205 | |
|
199 | 206 | div.output_wrapper { |
|
200 | 207 | /* This is a spacer between the input and output of each cell */ |
|
201 | 208 | margin-top: 5px; |
|
202 | 209 | margin-left: 5px; |
|
203 | 210 | /* FF needs explicit width to stretch */ |
|
204 | 211 | width: 100%; |
|
205 | 212 | /* this position must be relative to enable descendents to be absolute within it */ |
|
206 | 213 | position: relative; |
|
207 | 214 | } |
|
208 | 215 | |
|
209 | 216 | /* class for the output area when it should be height-limited */ |
|
210 | 217 | div.output_scroll { |
|
211 | 218 | /* ideally, this would be max-height, but FF barfs all over that */ |
|
212 | 219 | height: 24em; |
|
213 | 220 | /* FF needs this *and the wrapper* to specify full width, or it will shrinkwrap */ |
|
214 | 221 | width: 100%; |
|
215 | 222 | |
|
216 | 223 | overflow: auto; |
|
217 |
border-radius: |
|
|
224 | border-radius: @corner_radius; | |
|
218 | 225 | box-shadow: inset 0 2px 8px rgba(0, 0, 0, .8); |
|
219 | 226 | } |
|
220 | 227 | |
|
221 | 228 | /* output div while it is collapsed */ |
|
222 | 229 | div.output_collapsed { |
|
223 | 230 | margin-right: 5px; |
|
224 | 231 | } |
|
225 | 232 | |
|
226 | 233 | div.out_prompt_overlay { |
|
227 | 234 | height: 100%; |
|
228 | 235 | padding: 0px; |
|
229 | 236 | position: absolute; |
|
230 |
border-radius: |
|
|
237 | border-radius: @corner_radius; | |
|
231 | 238 | } |
|
232 | 239 | |
|
233 | 240 | div.out_prompt_overlay:hover { |
|
234 | 241 | /* use inner shadow to get border that is computed the same on WebKit/FF */ |
|
235 | 242 | box-shadow: inset 0 0 1px #000; |
|
236 | 243 | background: rgba(240, 240, 240, 0.5); |
|
237 | 244 | } |
|
238 | 245 | |
|
239 | 246 | div.output_prompt { |
|
240 | 247 | color: darkred; |
|
241 | 248 | /* 5px right shift to account for margin in parent container */ |
|
242 | 249 | margin: 0 5px 0 -5px; |
|
243 | 250 | } |
|
244 | 251 | |
|
245 | 252 | /* This class is the outer container of all output sections. */ |
|
246 | 253 | div.output_area { |
|
247 | 254 | padding: 0px; |
|
248 | 255 | page-break-inside: avoid; |
|
249 | 256 | } |
|
250 | 257 | |
|
251 | 258 | |
|
252 | 259 | /* This is needed to protect the pre formating from global settings such |
|
253 | 260 | as that of bootstrap */ |
|
254 | 261 | div.output_area pre { |
|
255 | 262 | font-family: monospace; |
|
256 | 263 | margin: 0; |
|
257 | 264 | padding: 0; |
|
258 | 265 | border: 0; |
|
259 | 266 | font-size: 100%; |
|
260 | 267 | font: inherit; |
|
261 | 268 | vertical-align: baseline; |
|
262 | 269 | color: black; |
|
263 | 270 | background-color: white; |
|
264 | 271 | } |
|
265 | 272 | |
|
266 | 273 | /* This class is for the output subarea inside the output_area and after |
|
267 | 274 | the prompt div. */ |
|
268 | 275 | div.output_subarea { |
|
269 | 276 | padding: 0.44em 0.4em 0.4em 1px; |
|
270 | 277 | } |
|
271 | 278 | |
|
272 | 279 | /* The rest of the output_* classes are for special styling of the different |
|
273 | 280 | output types */ |
|
274 | 281 | |
|
275 | 282 | /* all text output has this class: */ |
|
276 | 283 | div.output_text { |
|
277 | 284 | text-align: left; |
|
278 | 285 | color: black; |
|
279 | 286 | font-family: monospace; |
|
280 | 287 | /* This has to match that of the the CodeMirror class line-height below */ |
|
281 | 288 | line-height: 1.231; |
|
282 | 289 | } |
|
283 | 290 | |
|
284 | 291 | /* stdout/stderr are 'text' as well as 'stream', but pyout/pyerr are *not* streams */ |
|
285 | 292 | div.output_stream { |
|
286 | 293 | padding-top: 0.0em; |
|
287 | 294 | padding-bottom: 0.0em; |
|
288 | 295 | } |
|
289 | 296 | div.output_stdout { |
|
290 | 297 | } |
|
291 | 298 | div.output_stderr { |
|
292 | 299 | background: #fdd; /* very light red background for stderr */ |
|
293 | 300 | } |
|
294 | 301 | |
|
295 | 302 | div.output_latex { |
|
296 | 303 | text-align: left; |
|
297 | 304 | color: black; |
|
298 | 305 | } |
|
299 | 306 | |
|
300 | 307 | div.output_html { |
|
301 | 308 | } |
|
302 | 309 | |
|
303 | 310 | div.output_png { |
|
304 | 311 | } |
|
305 | 312 | |
|
306 | 313 | div.output_jpeg { |
|
307 | 314 | } |
|
308 | 315 | |
|
309 | 316 | div.text_cell { |
|
310 | background-color: white; | |
|
311 | 317 | padding: 5px 5px 5px 5px; |
|
312 | 318 | } |
|
313 | 319 | |
|
314 | 320 | div.text_cell_input { |
|
315 | 321 | color: black; |
|
316 |
border: 1px solid |
|
|
317 |
border-radius: |
|
|
318 | background: #f7f7f7; | |
|
322 | border: 1px solid @border_color; | |
|
323 | border-radius: @corner_radius; | |
|
324 | background: @cell_background; | |
|
319 | 325 | } |
|
320 | 326 | |
|
321 | 327 | div.text_cell_render { |
|
322 | 328 | font-family: "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif; |
|
323 | 329 | outline: none; |
|
324 | 330 | resize: none; |
|
325 | 331 | width: inherit; |
|
326 | 332 | border-style: none; |
|
327 | 333 | padding: 5px; |
|
328 | 334 | color: black; |
|
329 | 335 | } |
|
330 | 336 | |
|
331 | 337 | /* The following gets added to the <head> if it is detected that the user has a |
|
332 | 338 | * monospace font with inconsistent normal/bold/italic height. See |
|
333 | 339 | * notebookmain.js. Such fonts will have keywords vertically offset with |
|
334 | 340 | * respect to the rest of the text. The user should select a better font. |
|
335 | 341 | * See: https://github.com/ipython/ipython/issues/1503 |
|
336 | 342 | * |
|
337 | 343 | * .CodeMirror span { |
|
338 | 344 | * vertical-align: bottom; |
|
339 | 345 | * } |
|
340 | 346 | */ |
|
341 | 347 | |
|
342 | 348 | .CodeMirror { |
|
343 | 349 | line-height: 1.231; /* Changed from 1em to our global default */ |
|
344 | 350 | } |
|
345 | 351 | |
|
346 | 352 | .CodeMirror-scroll { |
|
347 | 353 | height: auto; /* Changed to auto to autogrow */ |
|
348 | 354 | /* The CodeMirror docs are a bit fuzzy on if overflow-y should be hidden or visible.*/ |
|
349 | 355 | /* We have found that if it is visible, vertical scrollbars appear with font size changes.*/ |
|
350 | 356 | overflow-y: hidden; |
|
351 | 357 | overflow-x: auto; /* Changed from auto to remove scrollbar */ |
|
352 | 358 | } |
|
353 | 359 | |
|
354 | 360 | /* CSS font colors for translated ANSI colors. */ |
|
355 | 361 | |
|
356 | 362 | |
|
357 | 363 | .ansiblack {color: black;} |
|
358 | 364 | .ansired {color: darkred;} |
|
359 | 365 | .ansigreen {color: darkgreen;} |
|
360 | 366 | .ansiyellow {color: brown;} |
|
361 | 367 | .ansiblue {color: darkblue;} |
|
362 | 368 | .ansipurple {color: darkviolet;} |
|
363 | 369 | .ansicyan {color: steelblue;} |
|
364 | 370 | .ansigrey {color: grey;} |
|
365 | 371 | .ansibold {font-weight: bold;} |
|
366 | 372 | |
|
367 | 373 | .completions { |
|
368 | 374 | position: absolute; |
|
369 | 375 | z-index: 10; |
|
370 | 376 | overflow: hidden; |
|
371 |
border: 1px solid |
|
|
377 | border: 1px solid @border_color; | |
|
372 | 378 | } |
|
373 | 379 | |
|
374 | 380 | .completions select { |
|
375 | 381 | background: white; |
|
376 | 382 | outline: none; |
|
377 | 383 | border: none; |
|
378 | 384 | padding: 0px; |
|
379 | 385 | margin: 0px; |
|
380 | 386 | overflow: auto; |
|
381 | 387 | font-family: monospace; |
|
382 | 388 | } |
|
383 | 389 | |
|
384 | 390 | option.context { |
|
385 | 391 | background-color: #DEF7FF; |
|
386 | 392 | } |
|
387 | 393 | option.introspection { |
|
388 | 394 | background-color: #EBF4EB; |
|
389 | 395 | } |
|
390 | 396 | |
|
391 | 397 | /*fixed part of the completion*/ |
|
392 | 398 | .completions p b { |
|
393 | 399 | font-weight:bold; |
|
394 | 400 | } |
|
395 | 401 | |
|
396 | 402 | .completions p { |
|
397 | 403 | background: #DDF; |
|
398 | 404 | /*outline: none; |
|
399 | 405 | padding: 0px;*/ |
|
400 | 406 | border-bottom: black solid 1px; |
|
401 | 407 | padding: 1px; |
|
402 | 408 | font-family: monospace; |
|
403 | 409 | } |
|
404 | 410 | |
|
405 | 411 | pre.dialog { |
|
406 |
background-color: |
|
|
412 | background-color: @cell_background; | |
|
407 | 413 | border: 1px solid #ddd; |
|
408 |
border-radius: |
|
|
414 | border-radius: @corner_radius; | |
|
409 | 415 | padding: 0.4em; |
|
410 | 416 | padding-left: 2em; |
|
411 | 417 | } |
|
412 | 418 | |
|
413 | 419 | p.dialog { |
|
414 | 420 | padding : 0.2em; |
|
415 | 421 | } |
|
416 | 422 | |
|
417 | 423 | .shortcut_key { |
|
418 | 424 | display: inline-block; |
|
419 | 425 | width: 15ex; |
|
420 | 426 | text-align: right; |
|
421 | 427 | font-family: monospace; |
|
422 | 428 | } |
|
423 | 429 | |
|
424 | 430 | .shortcut_descr { |
|
425 | 431 | } |
|
426 | 432 | |
|
427 | 433 | /* Word-wrap output correctly. This is the CSS3 spelling, though Firefox seems |
|
428 | 434 | to not honor it correctly. Webkit browsers (Chrome, rekonq, Safari) do. |
|
429 | 435 | */ |
|
430 | 436 | pre, code, kbd, samp { white-space: pre-wrap; } |
|
431 | 437 | |
|
432 | 438 | #fonttest { |
|
433 | 439 | font-family: monospace; |
|
434 | 440 | } |
|
435 | 441 | |
|
436 | 442 | .js-error { |
|
437 | 443 | color: darkred; |
|
438 | 444 | } |
@@ -1,314 +1,314 b'' | |||
|
1 | 1 | //---------------------------------------------------------------------------- |
|
2 | 2 | // Copyright (C) 2008-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 | // Cell |
|
10 | 10 | //============================================================================ |
|
11 | 11 | /** |
|
12 | 12 | * An extendable module that provide base functionnality to create cell for notebook. |
|
13 | 13 | * @module IPython |
|
14 | 14 | * @namespace IPython |
|
15 | 15 | * @submodule Cell |
|
16 | 16 | */ |
|
17 | 17 | |
|
18 | 18 | var IPython = (function (IPython) { |
|
19 | 19 | |
|
20 | 20 | var utils = IPython.utils; |
|
21 | 21 | |
|
22 | 22 | /** |
|
23 | 23 | * The Base `Cell` class from which to inherit |
|
24 | 24 | * @class Cell |
|
25 | 25 | */ |
|
26 | 26 | |
|
27 | 27 | /* |
|
28 | 28 | * @constructor |
|
29 | 29 | */ |
|
30 | 30 | var Cell = function () { |
|
31 | 31 | this.placeholder = this.placeholder || ''; |
|
32 | 32 | this.read_only = false; |
|
33 | 33 | this.selected = false; |
|
34 | 34 | this.element = null; |
|
35 | 35 | this.metadata = {}; |
|
36 | 36 | // load this from metadata later ? |
|
37 | 37 | this.user_highlight = 'auto'; |
|
38 | 38 | this.create_element(); |
|
39 | 39 | if (this.element !== null) { |
|
40 | 40 | this.element.data("cell", this); |
|
41 | 41 | this.bind_events(); |
|
42 | 42 | } |
|
43 | 43 | this.cell_id = utils.uuid(); |
|
44 | 44 | }; |
|
45 | 45 | |
|
46 | 46 | |
|
47 | 47 | /** |
|
48 | 48 | * Empty. Subclasses must implement create_element. |
|
49 | 49 | * This should contain all the code to create the DOM element in notebook |
|
50 | 50 | * and will be called by Base Class constructor. |
|
51 | 51 | * @method create_element |
|
52 | 52 | */ |
|
53 | 53 | Cell.prototype.create_element = function () { |
|
54 | 54 | }; |
|
55 | 55 | |
|
56 | 56 | |
|
57 | 57 | /** |
|
58 | 58 | * Subclasses can implement override bind_events. |
|
59 | 59 | * Be carefull to call the parent method when overwriting as it fires event. |
|
60 | 60 | * this will be triggerd after create_element in constructor. |
|
61 | 61 | * @method bind_events |
|
62 | 62 | */ |
|
63 | 63 | Cell.prototype.bind_events = function () { |
|
64 | 64 | var that = this; |
|
65 | 65 | // We trigger events so that Cell doesn't have to depend on Notebook. |
|
66 | 66 | that.element.click(function (event) { |
|
67 | 67 | if (that.selected === false) { |
|
68 | 68 | $([IPython.events]).trigger('select.Cell', {'cell':that}); |
|
69 | 69 | } |
|
70 | 70 | }); |
|
71 | 71 | that.element.focusin(function (event) { |
|
72 | 72 | if (that.selected === false) { |
|
73 | 73 | $([IPython.events]).trigger('select.Cell', {'cell':that}); |
|
74 | 74 | } |
|
75 | 75 | }); |
|
76 | 76 | }; |
|
77 | 77 | |
|
78 | 78 | /** |
|
79 | 79 | * Triger typsetting of math by mathjax on current cell element |
|
80 | 80 | * @method typeset |
|
81 | 81 | */ |
|
82 | 82 | Cell.prototype.typeset = function () { |
|
83 | 83 | if (window.MathJax){ |
|
84 | 84 | var cell_math = this.element.get(0); |
|
85 | 85 | MathJax.Hub.Queue(["Typeset",MathJax.Hub,cell_math]); |
|
86 | 86 | } |
|
87 | 87 | }; |
|
88 | 88 | |
|
89 | 89 | /** |
|
90 | 90 | * should be triggerd when cell is selected |
|
91 | 91 | * @method select |
|
92 | 92 | */ |
|
93 | 93 | Cell.prototype.select = function () { |
|
94 |
this.element.addClass(' |
|
|
94 | this.element.addClass('selected'); | |
|
95 | 95 | this.selected = true; |
|
96 | 96 | }; |
|
97 | 97 | |
|
98 | 98 | |
|
99 | 99 | /** |
|
100 | 100 | * should be triggerd when cell is unselected |
|
101 | 101 | * @method unselect |
|
102 | 102 | */ |
|
103 | 103 | Cell.prototype.unselect = function () { |
|
104 |
this.element.removeClass(' |
|
|
104 | this.element.removeClass('selected'); | |
|
105 | 105 | this.selected = false; |
|
106 | 106 | }; |
|
107 | 107 | |
|
108 | 108 | /** |
|
109 | 109 | * should be overritten by subclass |
|
110 | 110 | * @method get_text |
|
111 | 111 | */ |
|
112 | 112 | Cell.prototype.get_text = function () { |
|
113 | 113 | }; |
|
114 | 114 | |
|
115 | 115 | /** |
|
116 | 116 | * should be overritten by subclass |
|
117 | 117 | * @method set_text |
|
118 | 118 | * @param {string} text |
|
119 | 119 | */ |
|
120 | 120 | Cell.prototype.set_text = function (text) { |
|
121 | 121 | }; |
|
122 | 122 | |
|
123 | 123 | /** |
|
124 | 124 | * Refresh codemirror instance |
|
125 | 125 | * @method refresh |
|
126 | 126 | */ |
|
127 | 127 | Cell.prototype.refresh = function () { |
|
128 | 128 | this.code_mirror.refresh(); |
|
129 | 129 | }; |
|
130 | 130 | |
|
131 | 131 | |
|
132 | 132 | /** |
|
133 | 133 | * should be overritten by subclass |
|
134 | 134 | * @method edit |
|
135 | 135 | **/ |
|
136 | 136 | Cell.prototype.edit = function () { |
|
137 | 137 | }; |
|
138 | 138 | |
|
139 | 139 | |
|
140 | 140 | /** |
|
141 | 141 | * should be overritten by subclass |
|
142 | 142 | * @method render |
|
143 | 143 | **/ |
|
144 | 144 | Cell.prototype.render = function () { |
|
145 | 145 | }; |
|
146 | 146 | |
|
147 | 147 | /** |
|
148 | 148 | * should be overritten by subclass |
|
149 | 149 | * serialise cell to json. |
|
150 | 150 | * @method toJSON |
|
151 | 151 | **/ |
|
152 | 152 | Cell.prototype.toJSON = function () { |
|
153 | 153 | var data = {}; |
|
154 | 154 | data.metadata = this.metadata; |
|
155 | 155 | return data; |
|
156 | 156 | }; |
|
157 | 157 | |
|
158 | 158 | |
|
159 | 159 | /** |
|
160 | 160 | * should be overritten by subclass |
|
161 | 161 | * @method fromJSON |
|
162 | 162 | **/ |
|
163 | 163 | Cell.prototype.fromJSON = function (data) { |
|
164 | 164 | if (data.metadata !== undefined) { |
|
165 | 165 | this.metadata = data.metadata; |
|
166 | 166 | } |
|
167 | 167 | this.celltoolbar.rebuild(); |
|
168 | 168 | }; |
|
169 | 169 | |
|
170 | 170 | |
|
171 | 171 | /** |
|
172 | 172 | * can the cell be splitted in 2 cells. |
|
173 | 173 | * @method is_splittable |
|
174 | 174 | **/ |
|
175 | 175 | Cell.prototype.is_splittable = function () { |
|
176 | 176 | return true; |
|
177 | 177 | }; |
|
178 | 178 | |
|
179 | 179 | |
|
180 | 180 | /** |
|
181 | 181 | * @return {String} - the text before the cursor |
|
182 | 182 | * @method get_pre_cursor |
|
183 | 183 | **/ |
|
184 | 184 | Cell.prototype.get_pre_cursor = function () { |
|
185 | 185 | var cursor = this.code_mirror.getCursor(); |
|
186 | 186 | var text = this.code_mirror.getRange({line:0,ch:0}, cursor); |
|
187 | 187 | text = text.replace(/^\n+/, '').replace(/\n+$/, ''); |
|
188 | 188 | return text; |
|
189 | 189 | } |
|
190 | 190 | |
|
191 | 191 | |
|
192 | 192 | /** |
|
193 | 193 | * @return {String} - the text after the cursor |
|
194 | 194 | * @method get_post_cursor |
|
195 | 195 | **/ |
|
196 | 196 | Cell.prototype.get_post_cursor = function () { |
|
197 | 197 | var cursor = this.code_mirror.getCursor(); |
|
198 | 198 | var last_line_num = this.code_mirror.lineCount()-1; |
|
199 | 199 | var last_line_len = this.code_mirror.getLine(last_line_num).length; |
|
200 | 200 | var end = {line:last_line_num, ch:last_line_len} |
|
201 | 201 | var text = this.code_mirror.getRange(cursor, end); |
|
202 | 202 | text = text.replace(/^\n+/, '').replace(/\n+$/, ''); |
|
203 | 203 | return text; |
|
204 | 204 | }; |
|
205 | 205 | |
|
206 | 206 | |
|
207 | 207 | /** Grow the cell by hand. This is used upon reloading from JSON, when the |
|
208 | 208 | * autogrow handler is not called. |
|
209 | 209 | * |
|
210 | 210 | * could be made static |
|
211 | 211 | * |
|
212 | 212 | * @param {Dom element} - element |
|
213 | 213 | * @method grow |
|
214 | 214 | **/ |
|
215 | 215 | Cell.prototype.grow = function(element) { |
|
216 | 216 | var dom = element.get(0); |
|
217 | 217 | var lines_count = 0; |
|
218 | 218 | // modified split rule from |
|
219 | 219 | // http://stackoverflow.com/questions/2035910/how-to-get-the-number-of-lines-in-a-textarea/2036424#2036424 |
|
220 | 220 | var lines = dom.value.split(/\r|\r\n|\n/); |
|
221 | 221 | lines_count = lines.length; |
|
222 | 222 | if (lines_count >= 1) { |
|
223 | 223 | dom.rows = lines_count; |
|
224 | 224 | } else { |
|
225 | 225 | dom.rows = 1; |
|
226 | 226 | } |
|
227 | 227 | }; |
|
228 | 228 | |
|
229 | 229 | /** |
|
230 | 230 | * Toggle CodeMirror LineNumber |
|
231 | 231 | * @method toggle_line_numbers |
|
232 | 232 | **/ |
|
233 | 233 | Cell.prototype.toggle_line_numbers = function () { |
|
234 | 234 | if (this.code_mirror.getOption('lineNumbers') == false) { |
|
235 | 235 | this.code_mirror.setOption('lineNumbers', true); |
|
236 | 236 | } else { |
|
237 | 237 | this.code_mirror.setOption('lineNumbers', false); |
|
238 | 238 | } |
|
239 | 239 | this.code_mirror.refresh(); |
|
240 | 240 | }; |
|
241 | 241 | |
|
242 | 242 | /** |
|
243 | 243 | * force codemirror highlight mode |
|
244 | 244 | * @method force_highlight |
|
245 | 245 | * @param {object} - CodeMirror mode |
|
246 | 246 | **/ |
|
247 | 247 | Cell.prototype.force_highlight = function(mode) { |
|
248 | 248 | this.user_highlight = mode; |
|
249 | 249 | this.auto_highlight(); |
|
250 | 250 | }; |
|
251 | 251 | |
|
252 | 252 | /** |
|
253 | 253 | * Try to autodetect cell highlight mode, or use selected mode |
|
254 | 254 | * @methods _auto_highlight |
|
255 | 255 | * @private |
|
256 | 256 | * @param {String|object|undefined} - CodeMirror mode | 'auto' |
|
257 | 257 | **/ |
|
258 | 258 | Cell.prototype._auto_highlight = function (modes) { |
|
259 | 259 | //Here we handle manually selected modes |
|
260 | 260 | if( this.user_highlight != undefined && this.user_highlight != 'auto' ) |
|
261 | 261 | { |
|
262 | 262 | var mode = this.user_highlight; |
|
263 | 263 | CodeMirror.autoLoadMode(this.code_mirror, mode); |
|
264 | 264 | this.code_mirror.setOption('mode', mode); |
|
265 | 265 | return; |
|
266 | 266 | } |
|
267 | 267 | var first_line = this.code_mirror.getLine(0); |
|
268 | 268 | // loop on every pairs |
|
269 | 269 | for( var mode in modes) { |
|
270 | 270 | var regs = modes[mode]['reg']; |
|
271 | 271 | // only one key every time but regexp can't be keys... |
|
272 | 272 | for(var reg in regs ) { |
|
273 | 273 | // here we handle non magic_modes |
|
274 | 274 | if(first_line.match(regs[reg]) != null) { |
|
275 | 275 | if (mode.search('magic_') != 0) { |
|
276 | 276 | this.code_mirror.setOption('mode',mode); |
|
277 | 277 | CodeMirror.autoLoadMode(this.code_mirror, mode); |
|
278 | 278 | return; |
|
279 | 279 | } |
|
280 | 280 | var open = modes[mode]['open']|| "%%"; |
|
281 | 281 | var close = modes[mode]['close']|| "%%end"; |
|
282 | 282 | var mmode = mode; |
|
283 | 283 | mode = mmode.substr(6); |
|
284 | 284 | CodeMirror.autoLoadMode(this.code_mirror, mode); |
|
285 | 285 | // create on the fly a mode that swhitch between |
|
286 | 286 | // plain/text and smth else otherwise `%%` is |
|
287 | 287 | // source of some highlight issues. |
|
288 | 288 | // we use patchedGetMode to circumvent a bug in CM |
|
289 | 289 | CodeMirror.defineMode(mmode , function(config) { |
|
290 | 290 | return CodeMirror.multiplexingMode( |
|
291 | 291 | CodeMirror.patchedGetMode(config, 'text/plain'), |
|
292 | 292 | // always set someting on close |
|
293 | 293 | {open: open, close: close, |
|
294 | 294 | mode: CodeMirror.patchedGetMode(config, mode), |
|
295 | 295 | delimStyle: "delimit" |
|
296 | 296 | } |
|
297 | 297 | ); |
|
298 | 298 | }); |
|
299 | 299 | this.code_mirror.setOption('mode', mmode); |
|
300 | 300 | return; |
|
301 | 301 | } |
|
302 | 302 | } |
|
303 | 303 | } |
|
304 | 304 | // fallback on default (python) |
|
305 | 305 | var default_mode = this.default_mode || 'text/plain'; |
|
306 | 306 | this.code_mirror.setOption('mode', default_mode); |
|
307 | 307 | }; |
|
308 | 308 | |
|
309 | 309 | IPython.Cell = Cell; |
|
310 | 310 | |
|
311 | 311 | return IPython; |
|
312 | 312 | |
|
313 | 313 | }(IPython)); |
|
314 | 314 |
General Comments 0
You need to be logged in to leave comments.
Login now