Show More
@@ -18,8 +18,11 var IPython = (function (IPython) { | |||
|
18 | 18 | var key = IPython.utils.keycodes; |
|
19 | 19 | |
|
20 | 20 | /** |
|
21 | * Construct a new TextCell, codemirror mode is by default 'htmlmixed', and cell type is 'text' | |
|
22 | * cell start as not redered. | |
|
23 | * | |
|
21 | 24 | * @class TextCell |
|
22 |
* @construct |
|
|
25 | * @constructor TextCell | |
|
23 | 26 | */ |
|
24 | 27 | var TextCell = function () { |
|
25 | 28 | this.code_mirror_mode = this.code_mirror_mode || 'htmlmixed'; |
@@ -30,7 +33,8 var IPython = (function (IPython) { | |||
|
30 | 33 | |
|
31 | 34 | TextCell.prototype = new IPython.Cell(); |
|
32 | 35 | |
|
33 | /** create the DOM element of the TextCell | |
|
36 | /** | |
|
37 | * Create the DOM element of the TextCell | |
|
34 | 38 | * @method create_element |
|
35 | 39 | * @private |
|
36 | 40 | */ |
@@ -56,7 +60,8 var IPython = (function (IPython) { | |||
|
56 | 60 | }; |
|
57 | 61 | |
|
58 | 62 | |
|
59 | /** bind the DOM evet to cell actions | |
|
63 | /** | |
|
64 | * Bind the DOM evet to cell actions | |
|
60 | 65 | * Need to be called after TextCell.create_element |
|
61 | 66 | * @private |
|
62 | 67 | * @method bind_event |
@@ -77,13 +82,16 var IPython = (function (IPython) { | |||
|
77 | 82 | }); |
|
78 | 83 | }; |
|
79 | 84 | |
|
80 | /** This method gets called in CodeMirror's onKeyDown/onKeyPress | |
|
85 | /** | |
|
86 | * This method gets called in CodeMirror's onKeyDown/onKeyPress | |
|
81 | 87 | * handlers and is used to provide custom key handling. |
|
82 | 88 | * |
|
89 | * Subclass should override this method to have custom handeling | |
|
90 | * | |
|
83 | 91 | * @method handle_codemirror_keyevent |
|
84 |
* @param {CodeMirror |
|
|
92 | * @param {CodeMirror} editor - The codemirror instance bound to the cell | |
|
85 | 93 | * @param {event} event - |
|
86 |
* @return {Boolean} |
|
|
94 | * @return {Boolean} `true` if CodeMirror should ignore the event, `false` Otherwise | |
|
87 | 95 | */ |
|
88 | 96 | TextCell.prototype.handle_codemirror_keyevent = function (editor, event) { |
|
89 | 97 | |
@@ -95,7 +103,7 var IPython = (function (IPython) { | |||
|
95 | 103 | }; |
|
96 | 104 | |
|
97 | 105 | /** |
|
98 | * Select the current cell | |
|
106 | * Select the current cell and trigger 'focus' | |
|
99 | 107 | * @method select |
|
100 | 108 | */ |
|
101 | 109 | TextCell.prototype.select = function () { |
@@ -104,7 +112,8 var IPython = (function (IPython) { | |||
|
104 | 112 | output.trigger('focus'); |
|
105 | 113 | }; |
|
106 | 114 | |
|
107 | /** unselect the current cell | |
|
115 | /** | |
|
116 | * unselect the current cell and `render` it | |
|
108 | 117 | * @method unselect |
|
109 | 118 | */ |
|
110 | 119 | TextCell.prototype.unselect = function() { |
@@ -113,7 +122,9 var IPython = (function (IPython) { | |||
|
113 | 122 | IPython.Cell.prototype.unselect.apply(this); |
|
114 | 123 | }; |
|
115 | 124 | |
|
116 | /** put the current cell in edition mode | |
|
125 | /** | |
|
126 | * | |
|
127 | * put the current cell in edition mode | |
|
117 | 128 | * @method edit |
|
118 | 129 | */ |
|
119 | 130 | TextCell.prototype.edit = function () { |
@@ -137,7 +148,8 var IPython = (function (IPython) { | |||
|
137 | 148 | }; |
|
138 | 149 | |
|
139 | 150 | |
|
140 | /** Subclasses must define render. | |
|
151 | /** | |
|
152 | * Empty, Subclasses must define render. | |
|
141 | 153 | * @method render |
|
142 | 154 | */ |
|
143 | 155 | TextCell.prototype.render = function () {}; |
@@ -211,8 +223,10 var IPython = (function (IPython) { | |||
|
211 | 223 | } |
|
212 | 224 | }; |
|
213 | 225 | |
|
214 | /** Create Text cell from JSON | |
|
226 | /** | |
|
227 | * Create Text cell from JSON | |
|
215 | 228 | * @param {json} data - JSON serialized text-cell |
|
229 | * @method fromJSON | |
|
216 | 230 | */ |
|
217 | 231 | TextCell.prototype.fromJSON = function (data) { |
|
218 | 232 | IPython.Cell.prototype.fromJSON.apply(this, arguments); |
@@ -229,7 +243,9 var IPython = (function (IPython) { | |||
|
229 | 243 | } |
|
230 | 244 | }; |
|
231 | 245 | |
|
232 | ||
|
246 | /** Generate JSON from cell | |
|
247 | * @return {object} cell data serialised to json | |
|
248 | */ | |
|
233 | 249 | TextCell.prototype.toJSON = function () { |
|
234 | 250 | var data = IPython.Cell.prototype.toJSON.apply(this); |
|
235 | 251 | data.cell_type = this.cell_type; |
@@ -239,7 +255,7 var IPython = (function (IPython) { | |||
|
239 | 255 | |
|
240 | 256 | |
|
241 | 257 | /** |
|
242 |
* @construct |
|
|
258 | * @constructor HtmlCell | |
|
243 | 259 | * @class HtmlCell |
|
244 | 260 | * @extends TextCell |
|
245 | 261 | */ |
@@ -252,7 +268,9 var IPython = (function (IPython) { | |||
|
252 | 268 | |
|
253 | 269 | HTMLCell.prototype = new TextCell(); |
|
254 | 270 | |
|
255 | ||
|
271 | /** | |
|
272 | * @method render | |
|
273 | */ | |
|
256 | 274 | HTMLCell.prototype.render = function () { |
|
257 | 275 | if (this.rendered === false) { |
|
258 | 276 | var text = this.get_text(); |
@@ -266,9 +284,9 var IPython = (function (IPython) { | |||
|
266 | 284 | }; |
|
267 | 285 | |
|
268 | 286 | |
|
269 | // MarkdownCell | |
|
270 |
|
|
|
271 |
* @construct |
|
|
287 | /** | |
|
288 | * @class MarkdownCell | |
|
289 | * @constructor MarkdownCell | |
|
272 | 290 | * @extends HtmlCell |
|
273 | 291 | */ |
|
274 | 292 | var MarkdownCell = function () { |
@@ -280,7 +298,9 var IPython = (function (IPython) { | |||
|
280 | 298 | |
|
281 | 299 | MarkdownCell.prototype = new TextCell(); |
|
282 | 300 | |
|
283 | ||
|
301 | /** | |
|
302 | * @method render | |
|
303 | */ | |
|
284 | 304 | MarkdownCell.prototype.render = function () { |
|
285 | 305 | if (this.rendered === false) { |
|
286 | 306 | var text = this.get_text(); |
@@ -319,7 +339,9 var IPython = (function (IPython) { | |||
|
319 | 339 | |
|
320 | 340 | // RawCell |
|
321 | 341 | |
|
322 | /** @construct RawCell | |
|
342 | /** | |
|
343 | * @class RawCell | |
|
344 | * @constructor RawCell | |
|
323 | 345 | * @extends TextCell |
|
324 | 346 | */ |
|
325 | 347 | var RawCell = function () { |
@@ -337,21 +359,23 var IPython = (function (IPython) { | |||
|
337 | 359 | |
|
338 | 360 | RawCell.prototype = new TextCell(); |
|
339 | 361 | |
|
362 | /** | |
|
363 | * Trigger autodetection of highlight scheme for current cell | |
|
364 | * @method auto_highlight | |
|
365 | */ | |
|
340 | 366 | RawCell.prototype.auto_highlight = function () { |
|
341 | 367 | this._auto_highlight(IPython.config.raw_cell_highlight); |
|
342 | 368 | }; |
|
343 | 369 | |
|
370 | /** @method render **/ | |
|
344 | 371 | RawCell.prototype.render = function () { |
|
345 | 372 | this.rendered = true; |
|
346 | 373 | this.edit(); |
|
347 | 374 | }; |
|
348 | 375 | |
|
349 | 376 | |
|
377 | /** @method handle_codemirror_keyevent **/ | |
|
350 | 378 | RawCell.prototype.handle_codemirror_keyevent = function (editor, event) { |
|
351 | // This method gets called in CodeMirror's onKeyDown/onKeyPress | |
|
352 | // handlers and is used to provide custom key handling. Its return | |
|
353 | // value is used to determine if CodeMirror should ignore the event: | |
|
354 | // true = ignore, false = don't ignore. | |
|
355 | 379 | |
|
356 | 380 | var that = this; |
|
357 | 381 | if (event.which === key.UPARROW && event.type === 'keydown') { |
@@ -376,14 +400,14 var IPython = (function (IPython) { | |||
|
376 | 400 | return false; |
|
377 | 401 | }; |
|
378 | 402 | |
|
379 | ||
|
403 | /** @method select **/ | |
|
380 | 404 | RawCell.prototype.select = function () { |
|
381 | 405 | IPython.Cell.prototype.select.apply(this); |
|
382 | 406 | this.code_mirror.refresh(); |
|
383 | 407 | this.code_mirror.focus(); |
|
384 | 408 | }; |
|
385 | 409 | |
|
386 | ||
|
410 | /** @method at_top **/ | |
|
387 | 411 | RawCell.prototype.at_top = function () { |
|
388 | 412 | var cursor = this.code_mirror.getCursor(); |
|
389 | 413 | if (cursor.line === 0 && cursor.ch === 0) { |
@@ -394,6 +418,7 var IPython = (function (IPython) { | |||
|
394 | 418 | }; |
|
395 | 419 | |
|
396 | 420 | |
|
421 | /** @method at_bottom **/ | |
|
397 | 422 | RawCell.prototype.at_bottom = function () { |
|
398 | 423 | var cursor = this.code_mirror.getCursor(); |
|
399 | 424 | if (cursor.line === (this.code_mirror.lineCount()-1) && cursor.ch === this.code_mirror.getLine(cursor.line).length) { |
@@ -404,20 +429,30 var IPython = (function (IPython) { | |||
|
404 | 429 | }; |
|
405 | 430 | |
|
406 | 431 | |
|
407 | /** @constructs HeadingCell | |
|
432 | /** | |
|
433 | * @class HeadingCell | |
|
434 | * @extends TextCell | |
|
435 | */ | |
|
436 | ||
|
437 | /** | |
|
438 | * @constructor HeadingCell | |
|
408 | 439 | * @extends TextCell |
|
409 | 440 | */ |
|
410 | 441 | var HeadingCell = function () { |
|
411 | 442 | this.placeholder = "Type Heading Here"; |
|
412 | 443 | IPython.TextCell.apply(this, arguments); |
|
413 | this.cell_type = 'heading'; | |
|
444 | /** | |
|
445 | * heading level of the cell, use getter and setter to access | |
|
446 | * @property level | |
|
447 | */ | |
|
414 | 448 | this.level = 1; |
|
449 | this.cell_type = 'heading'; | |
|
415 | 450 | }; |
|
416 | 451 | |
|
417 | 452 | |
|
418 | 453 | HeadingCell.prototype = new TextCell(); |
|
419 | 454 | |
|
420 |
/** |
|
|
455 | /** @method fromJSON */ | |
|
421 | 456 | HeadingCell.prototype.fromJSON = function (data) { |
|
422 | 457 | if (data.level != undefined){ |
|
423 | 458 | this.level = data.level; |
@@ -426,6 +461,7 var IPython = (function (IPython) { | |||
|
426 | 461 | }; |
|
427 | 462 | |
|
428 | 463 | |
|
464 | /** @method toJSON */ | |
|
429 | 465 | HeadingCell.prototype.toJSON = function () { |
|
430 | 466 | var data = IPython.TextCell.prototype.toJSON.apply(this); |
|
431 | 467 | data.level = this.get_level(); |
@@ -433,6 +469,10 var IPython = (function (IPython) { | |||
|
433 | 469 | }; |
|
434 | 470 | |
|
435 | 471 | |
|
472 | /** | |
|
473 | * Change heading level of cell, and re-render | |
|
474 | * @method set_level | |
|
475 | */ | |
|
436 | 476 | HeadingCell.prototype.set_level = function (level) { |
|
437 | 477 | this.level = level; |
|
438 | 478 | if (this.rendered) { |
@@ -442,6 +482,7 var IPython = (function (IPython) { | |||
|
442 | 482 | }; |
|
443 | 483 | |
|
444 | 484 | /** The depth of header cell, based on html (h1 to h6) |
|
485 | * @method get_level | |
|
445 | 486 | * @return {integer} level - for 1 to 6 |
|
446 | 487 | */ |
|
447 | 488 | HeadingCell.prototype.get_level = function () { |
General Comments 0
You need to be logged in to leave comments.
Login now