Show More
@@ -32,30 +32,41 var IPython = (function (IPython) { | |||
|
32 | 32 | */ |
|
33 | 33 | var Cell = function (options) { |
|
34 | 34 | |
|
35 |
options = options |
|
|
35 | options = this.mergeopt(Cell, options) | |
|
36 | 36 | // superclass default overwrite our default |
|
37 | this.cm_config = $.extend({},Cell.cm_default,options.cm_config); | |
|
38 | 37 | |
|
39 |
this.placeholder = t |
|
|
40 |
this.read_only = |
|
|
38 | this.placeholder = options.placeholder || ''; | |
|
39 | this.read_only = options.cm_config.readOnly; | |
|
41 | 40 | this.selected = false; |
|
42 | 41 | this.element = null; |
|
43 | 42 | this.metadata = {}; |
|
44 | 43 | // load this from metadata later ? |
|
45 | 44 | this.user_highlight = 'auto'; |
|
45 | this.cm_config = options.cm_config; | |
|
46 | 46 | this.create_element(); |
|
47 | 47 | if (this.element !== null) { |
|
48 | 48 | this.element.data("cell", this); |
|
49 | 49 | this.bind_events(); |
|
50 | 50 | } |
|
51 | 51 | this.cell_id = utils.uuid(); |
|
52 | this._options = options; | |
|
52 | 53 | }; |
|
53 | 54 | |
|
54 |
Cell. |
|
|
55 | Cell.options_default = { | |
|
56 | cm_config : { | |
|
55 | 57 | indentUnit : 4, |
|
56 |
readOnly: |
|
|
58 | readOnly: false, | |
|
59 | theme: "default" | |
|
60 | } | |
|
57 | 61 | }; |
|
58 | 62 | |
|
63 | Cell.prototype.mergeopt = function(_class, options, overwrite){ | |
|
64 | overwrite = overwrite || {}; | |
|
65 | return $.extend(true, {}, _class.options_default, options, overwrite) | |
|
66 | ||
|
67 | } | |
|
68 | ||
|
69 | ||
|
59 | 70 | |
|
60 | 71 | /** |
|
61 | 72 | * Empty. Subclasses must implement create_element. |
@@ -95,7 +106,7 var IPython = (function (IPython) { | |||
|
95 | 106 | Cell.prototype.typeset = function () { |
|
96 | 107 | if (window.MathJax){ |
|
97 | 108 | var cell_math = this.element.get(0); |
|
98 | MathJax.Hub.Queue(["Typeset",MathJax.Hub,cell_math]); | |
|
109 | MathJax.Hub.Queue(["Typeset", MathJax.Hub, cell_math]); | |
|
99 | 110 | } |
|
100 | 111 | }; |
|
101 | 112 | |
@@ -196,7 +207,7 var IPython = (function (IPython) { | |||
|
196 | 207 | **/ |
|
197 | 208 | Cell.prototype.get_pre_cursor = function () { |
|
198 | 209 | var cursor = this.code_mirror.getCursor(); |
|
199 | var text = this.code_mirror.getRange({line:0,ch:0}, cursor); | |
|
210 | var text = this.code_mirror.getRange({line:0, ch:0}, cursor); | |
|
200 | 211 | text = text.replace(/^\n+/, '').replace(/\n+$/, ''); |
|
201 | 212 | return text; |
|
202 | 213 | } |
@@ -293,7 +304,7 var IPython = (function (IPython) { | |||
|
293 | 304 | // here we handle non magic_modes |
|
294 | 305 | if(first_line.match(regs[reg]) != null) { |
|
295 | 306 | if (mode.search('magic_') != 0) { |
|
296 | this.code_mirror.setOption('mode',mode); | |
|
307 | this.code_mirror.setOption('mode', mode); | |
|
297 | 308 | CodeMirror.autoLoadMode(this.code_mirror, mode); |
|
298 | 309 | return; |
|
299 | 310 | } |
@@ -62,7 +62,6 var IPython = (function (IPython) { | |||
|
62 | 62 | * @param [options.cm_config] {object} config to pass to CodeMirror |
|
63 | 63 | */ |
|
64 | 64 | var CodeCell = function (kernel, options) { |
|
65 | var options = options || {} | |
|
66 | 65 | this.kernel = kernel || null; |
|
67 | 66 | this.code_mirror = null; |
|
68 | 67 | this.input_prompt_number = null; |
@@ -71,15 +70,10 var IPython = (function (IPython) { | |||
|
71 | 70 | |
|
72 | 71 | |
|
73 | 72 | var cm_overwrite_options = { |
|
74 | extraKeys: {"Tab": "indentMore","Shift-Tab" : "indentLess",'Backspace':"delSpaceToPrevTabStop"}, | |
|
75 | 73 | onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this) |
|
76 | 74 | }; |
|
77 | 75 | |
|
78 | var arg_cm_options = options.cm_options || {}; | |
|
79 | var cm_config = $.extend({},CodeCell.cm_default, arg_cm_options, cm_overwrite_options); | |
|
80 | ||
|
81 | var options = {}; | |
|
82 | options.cm_config = cm_config; | |
|
76 | options = this.mergeopt(CodeCell, options, {cm_config:cm_overwrite_options}); | |
|
83 | 77 | |
|
84 | 78 | IPython.Cell.apply(this,[options]); |
|
85 | 79 | |
@@ -89,10 +83,13 var IPython = (function (IPython) { | |||
|
89 | 83 | ); |
|
90 | 84 | }; |
|
91 | 85 | |
|
92 |
CodeCell. |
|
|
86 | CodeCell.options_default = { | |
|
87 | cm_config : { | |
|
88 | extraKeys: {"Tab": "indentMore","Shift-Tab" : "indentLess",'Backspace':"delSpaceToPrevTabStop"}, | |
|
93 | 89 | mode: 'python', |
|
94 | 90 | theme: 'ipython', |
|
95 | 91 | matchBrackets: true |
|
92 | } | |
|
96 | 93 | }; |
|
97 | 94 | |
|
98 | 95 |
@@ -9,6 +9,8 | |||
|
9 | 9 | // TextCell |
|
10 | 10 | //============================================================================ |
|
11 | 11 | |
|
12 | ||
|
13 | ||
|
12 | 14 | /** |
|
13 | 15 | A module that allow to create different type of Text Cell |
|
14 | 16 | @module IPython |
@@ -28,37 +30,39 var IPython = (function (IPython) { | |||
|
28 | 30 | * @extend Ipython.Cell |
|
29 | 31 | * @param {object|undefined} [options] |
|
30 | 32 | * @param [options.cm_config] {object} config to pass to CodeMirror, will extend/overwrite default config |
|
33 | * @param [options.placeholder] {string} default string to use when souce in empty for rendering (only use in some TextCell subclass) | |
|
31 | 34 | */ |
|
32 | 35 | var TextCell = function (options) { |
|
33 | this.code_mirror_mode = this.code_mirror_mode || 'htmlmixed'; | |
|
34 | var options = options || {}; | |
|
36 | // in all TextCell/Cell subclasses | |
|
37 | // do not assign most of members here, just pass it down | |
|
38 | // in the options dict potentially overwriting what you wish. | |
|
39 | // they will be assigned in the base class. | |
|
35 | 40 | |
|
41 | // we cannot put this as a class key as it has handle to "this". | |
|
36 | 42 | var cm_overwrite_options = { |
|
37 | extraKeys: {"Tab": "indentMore","Shift-Tab" : "indentLess"}, | |
|
38 | 43 | onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this) |
|
39 | 44 | }; |
|
40 | 45 | |
|
41 | var arg_cm_options = options.cm_options || {}; | |
|
42 | var cm_config = $.extend({},TextCell.cm_default, arg_cm_options, cm_overwrite_options); | |
|
46 | options = this.mergeopt(TextCell,options,{cm_config:cm_overwrite_options}); | |
|
43 | 47 | |
|
44 | var options = {}; | |
|
45 | options.cm_config = cm_config; | |
|
48 | IPython.Cell.apply(this, [options]); | |
|
46 | 49 | |
|
47 | 50 | |
|
48 | IPython.Cell.apply(this, [options]); | |
|
49 | 51 | this.rendered = false; |
|
50 | 52 | this.cell_type = this.cell_type || 'text'; |
|
51 | 53 | }; |
|
52 | 54 | |
|
53 | TextCell.cm_default = { | |
|
54 | mode: this.code_mirror_mode, | |
|
55 | theme: 'default', | |
|
56 | value: this.placeholder, | |
|
55 | TextCell.prototype = new IPython.Cell(); | |
|
56 | ||
|
57 | TextCell.options_default = { | |
|
58 | cm_config : { | |
|
59 | extraKeys: {"Tab": "indentMore","Shift-Tab" : "indentLess"}, | |
|
60 | mode: 'htmlmixed', | |
|
57 | 61 | lineWrapping : true, |
|
58 | 62 | } |
|
63 | }; | |
|
59 | 64 | |
|
60 | 65 | |
|
61 | TextCell.prototype = new IPython.Cell(); | |
|
62 | 66 | |
|
63 | 67 | /** |
|
64 | 68 | * Create the DOM element of the TextCell |
@@ -75,6 +79,7 var IPython = (function (IPython) { | |||
|
75 | 79 | |
|
76 | 80 | var input_area = $('<div/>').addClass('text_cell_input border-box-sizing'); |
|
77 | 81 | this.code_mirror = CodeMirror(input_area.get(0), this.cm_config); |
|
82 | ||
|
78 | 83 | // The tabindex=-1 makes this div focusable. |
|
79 | 84 | var render_area = $('<div/>').addClass('text_cell_render border-box-sizing'). |
|
80 | 85 | addClass('rendered_html').attr('tabindex','-1'); |
@@ -282,12 +287,21 var IPython = (function (IPython) { | |||
|
282 | 287 | * @class HtmlCell |
|
283 | 288 | * @extends Ipython.TextCell |
|
284 | 289 | */ |
|
285 | var HTMLCell = function () { | |
|
286 | this.placeholder = "Type <strong>HTML</strong> and LaTeX: $\\alpha^2$"; | |
|
287 | IPython.TextCell.apply(this, arguments); | |
|
290 | var HTMLCell = function (options) { | |
|
291 | ||
|
292 | options = this.mergeopt(HTMLCell,options); | |
|
293 | TextCell.apply(this, [options]); | |
|
294 | ||
|
288 | 295 | this.cell_type = 'html'; |
|
289 | 296 | }; |
|
290 | 297 | |
|
298 | HTMLCell.options_default = { | |
|
299 | cm_config : { | |
|
300 | mode: 'htmlmixed', | |
|
301 | }, | |
|
302 | placeholder: "Type <strong>HTML</strong> and LaTeX: $\\alpha^2$" | |
|
303 | }; | |
|
304 | ||
|
291 | 305 | |
|
292 | 306 | HTMLCell.prototype = new TextCell(); |
|
293 | 307 | |
@@ -312,12 +326,24 var IPython = (function (IPython) { | |||
|
312 | 326 | * @constructor MarkdownCell |
|
313 | 327 | * @extends Ipython.HtmlCell |
|
314 | 328 | */ |
|
315 | var MarkdownCell = function () { | |
|
316 | this.placeholder = "Type *Markdown* and LaTeX: $\\alpha^2$"; | |
|
317 | IPython.TextCell.apply(this, arguments); | |
|
329 | var MarkdownCell = function (options) { | |
|
330 | var options = options || {}; | |
|
331 | ||
|
332 | options = this.mergeopt(MarkdownCell,options); | |
|
333 | TextCell.apply(this, [options]); | |
|
334 | ||
|
318 | 335 | this.cell_type = 'markdown'; |
|
319 | 336 | }; |
|
320 | 337 | |
|
338 | MarkdownCell.options_default = { | |
|
339 | cm_config: { | |
|
340 | mode: 'markdown' | |
|
341 | }, | |
|
342 | placeholder: "Type *Markdown* and LaTeX: $\\alpha^2$" | |
|
343 | } | |
|
344 | ||
|
345 | ||
|
346 | ||
|
321 | 347 | |
|
322 | 348 | MarkdownCell.prototype = new TextCell(); |
|
323 | 349 | |
@@ -367,18 +393,24 var IPython = (function (IPython) { | |||
|
367 | 393 | * @constructor RawCell |
|
368 | 394 | * @extends Ipython.TextCell |
|
369 | 395 | */ |
|
370 | var RawCell = function () { | |
|
371 | this.placeholder = "Type plain text and LaTeX: $\\alpha^2$"; | |
|
372 | this.code_mirror_mode = 'rst'; | |
|
373 |
|
|
|
396 | var RawCell = function (options) { | |
|
397 | ||
|
398 | options = this.mergeopt(RawCell,options) | |
|
399 | TextCell.apply(this, [options]); | |
|
400 | ||
|
374 | 401 | this.cell_type = 'raw'; |
|
375 | var that = this | |
|
376 | 402 | |
|
403 | var that = this | |
|
377 | 404 | this.element.focusout( |
|
378 | 405 | function() { that.auto_highlight(); } |
|
379 | 406 | ); |
|
380 | 407 | }; |
|
381 | 408 | |
|
409 | RawCell.options_default = { | |
|
410 | placeholder : "Type plain text and LaTeX: $\\alpha^2$" | |
|
411 | }; | |
|
412 | ||
|
413 | ||
|
382 | 414 | |
|
383 | 415 | RawCell.prototype = new TextCell(); |
|
384 | 416 | |
@@ -461,9 +493,11 var IPython = (function (IPython) { | |||
|
461 | 493 | * @constructor HeadingCell |
|
462 | 494 | * @extends Ipython.TextCell |
|
463 | 495 | */ |
|
464 | var HeadingCell = function () { | |
|
465 | this.placeholder = "Type Heading Here"; | |
|
466 | IPython.TextCell.apply(this, arguments); | |
|
496 | var HeadingCell = function (options) { | |
|
497 | ||
|
498 | options = this.mergeopt(HeadingCell,options) | |
|
499 | TextCell.apply(this, [options]); | |
|
500 | ||
|
467 | 501 | /** |
|
468 | 502 | * heading level of the cell, use getter and setter to access |
|
469 | 503 | * @property level |
@@ -472,6 +506,9 var IPython = (function (IPython) { | |||
|
472 | 506 | this.cell_type = 'heading'; |
|
473 | 507 | }; |
|
474 | 508 | |
|
509 | HeadingCell.options_default = { | |
|
510 | placeholder: "Type Heading Here" | |
|
511 | }; | |
|
475 | 512 | |
|
476 | 513 | HeadingCell.prototype = new TextCell(); |
|
477 | 514 | |
@@ -480,13 +517,13 var IPython = (function (IPython) { | |||
|
480 | 517 | if (data.level != undefined){ |
|
481 | 518 | this.level = data.level; |
|
482 | 519 | } |
|
483 |
|
|
|
520 | TextCell.prototype.fromJSON.apply(this, arguments); | |
|
484 | 521 | }; |
|
485 | 522 | |
|
486 | 523 | |
|
487 | 524 | /** @method toJSON */ |
|
488 | 525 | HeadingCell.prototype.toJSON = function () { |
|
489 |
var data = |
|
|
526 | var data = TextCell.prototype.toJSON.apply(this); | |
|
490 | 527 | data.level = this.get_level(); |
|
491 | 528 | return data; |
|
492 | 529 | }; |
General Comments 0
You need to be logged in to leave comments.
Login now