Show More
@@ -9,11 +9,18 b'' | |||||
9 | // TextCell |
|
9 | // TextCell | |
10 | //============================================================================ |
|
10 | //============================================================================ | |
11 |
|
11 | |||
|
12 | /** | |||
|
13 | A module that allow to create different type of Text Cell | |||
|
14 | */ | |||
12 | var IPython = (function (IPython) { |
|
15 | var IPython = (function (IPython) { | |
13 |
|
16 | |||
14 | // TextCell base class |
|
17 | // TextCell base class | |
15 | var key = IPython.utils.keycodes; |
|
18 | var key = IPython.utils.keycodes; | |
16 |
|
19 | |||
|
20 | /** | |||
|
21 | * @class TextCell | |||
|
22 | * @constructs TextCell | |||
|
23 | */ | |||
17 | var TextCell = function () { |
|
24 | var TextCell = function () { | |
18 | this.code_mirror_mode = this.code_mirror_mode || 'htmlmixed'; |
|
25 | this.code_mirror_mode = this.code_mirror_mode || 'htmlmixed'; | |
19 | IPython.Cell.apply(this, arguments); |
|
26 | IPython.Cell.apply(this, arguments); | |
@@ -21,10 +28,12 b' var IPython = (function (IPython) {' | |||||
21 | this.cell_type = this.cell_type || 'text'; |
|
28 | this.cell_type = this.cell_type || 'text'; | |
22 | }; |
|
29 | }; | |
23 |
|
30 | |||
24 |
|
||||
25 | TextCell.prototype = new IPython.Cell(); |
|
31 | TextCell.prototype = new IPython.Cell(); | |
26 |
|
32 | |||
27 |
|
33 | /** create the DOM element of the TextCell | ||
|
34 | * @method create_element | |||
|
35 | * @private | |||
|
36 | */ | |||
28 | TextCell.prototype.create_element = function () { |
|
37 | TextCell.prototype.create_element = function () { | |
29 | var cell = $("<div>").addClass('cell text_cell border-box-sizing'); |
|
38 | var cell = $("<div>").addClass('cell text_cell border-box-sizing'); | |
30 | cell.attr('tabindex','2'); |
|
39 | cell.attr('tabindex','2'); | |
@@ -47,6 +56,11 b' var IPython = (function (IPython) {' | |||||
47 | }; |
|
56 | }; | |
48 |
|
57 | |||
49 |
|
58 | |||
|
59 | /** bind the DOM evet to cell actions | |||
|
60 | * Need to be called after TextCell.create_element | |||
|
61 | * @private | |||
|
62 | * @method bind_event | |||
|
63 | */ | |||
50 | TextCell.prototype.bind_events = function () { |
|
64 | TextCell.prototype.bind_events = function () { | |
51 | IPython.Cell.prototype.bind_events.apply(this); |
|
65 | IPython.Cell.prototype.bind_events.apply(this); | |
52 | var that = this; |
|
66 | var that = this; | |
@@ -63,13 +77,16 b' var IPython = (function (IPython) {' | |||||
63 | }); |
|
77 | }); | |
64 | }; |
|
78 | }; | |
65 |
|
79 | |||
66 |
|
80 | /** This method gets called in CodeMirror's onKeyDown/onKeyPress | ||
|
81 | * handlers and is used to provide custom key handling. | |||
|
82 | * | |||
|
83 | * @method handle_codemirror_keyevent | |||
|
84 | * @param {CodeMirror } editor - The codemirror instance bound to the cell | |||
|
85 | * @param {event} event - | |||
|
86 | * @return {Boolean} <tt>true</tt> if CodeMirror should ignore the event, `false` Otherwise | |||
|
87 | */ | |||
67 | TextCell.prototype.handle_codemirror_keyevent = function (editor, event) { |
|
88 | TextCell.prototype.handle_codemirror_keyevent = function (editor, event) { | |
68 | // This method gets called in CodeMirror's onKeyDown/onKeyPress |
|
89 | ||
69 | // handlers and is used to provide custom key handling. Its return |
|
|||
70 | // value is used to determine if CodeMirror should ignore the event: |
|
|||
71 | // true = ignore, false = don't ignore. |
|
|||
72 |
|
||||
73 | if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey)) { |
|
90 | if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey)) { | |
74 | // Always ignore shift-enter in CodeMirror as we handle it. |
|
91 | // Always ignore shift-enter in CodeMirror as we handle it. | |
75 | return true; |
|
92 | return true; | |
@@ -77,26 +94,33 b' var IPython = (function (IPython) {' | |||||
77 | return false; |
|
94 | return false; | |
78 | }; |
|
95 | }; | |
79 |
|
96 | |||
80 |
|
97 | /** | ||
|
98 | * Select the current cell | |||
|
99 | * @method select | |||
|
100 | */ | |||
81 | TextCell.prototype.select = function () { |
|
101 | TextCell.prototype.select = function () { | |
82 | IPython.Cell.prototype.select.apply(this); |
|
102 | IPython.Cell.prototype.select.apply(this); | |
83 | var output = this.element.find("div.text_cell_render"); |
|
103 | var output = this.element.find("div.text_cell_render"); | |
84 | output.trigger('focus'); |
|
104 | output.trigger('focus'); | |
85 | }; |
|
105 | }; | |
86 |
|
106 | |||
87 |
|
107 | /** unselect the current cell | ||
|
108 | * @method unselect | |||
|
109 | */ | |||
88 | TextCell.prototype.unselect = function() { |
|
110 | TextCell.prototype.unselect = function() { | |
89 | // render on selection of another cell |
|
111 | // render on selection of another cell | |
90 | this.render(); |
|
112 | this.render(); | |
91 | IPython.Cell.prototype.unselect.apply(this); |
|
113 | IPython.Cell.prototype.unselect.apply(this); | |
92 | }; |
|
114 | }; | |
93 |
|
115 | |||
94 |
|
116 | /** put the current cell in edition mode | ||
|
117 | * @method edit | |||
|
118 | */ | |||
95 | TextCell.prototype.edit = function () { |
|
119 | TextCell.prototype.edit = function () { | |
96 | if ( this.read_only ) return; |
|
120 | if ( this.read_only ) return; | |
97 | if (this.rendered === true) { |
|
121 | if (this.rendered === true) { | |
98 | var text_cell = this.element; |
|
122 | var text_cell = this.element; | |
99 |
var output = text_cell.find("div.text_cell_render"); |
|
123 | var output = text_cell.find("div.text_cell_render"); | |
100 | output.hide(); |
|
124 | output.hide(); | |
101 | text_cell.find('div.text_cell_input').show(); |
|
125 | text_cell.find('div.text_cell_input').show(); | |
102 | this.code_mirror.refresh(); |
|
126 | this.code_mirror.refresh(); | |
@@ -113,31 +137,55 b' var IPython = (function (IPython) {' | |||||
113 | }; |
|
137 | }; | |
114 |
|
138 | |||
115 |
|
139 | |||
116 |
/ |
|
140 | /** Subclasses must define render. | |
|
141 | * @method render | |||
|
142 | */ | |||
117 | TextCell.prototype.render = function () {}; |
|
143 | TextCell.prototype.render = function () {}; | |
118 |
|
144 | |||
119 |
|
145 | |||
|
146 | /** | |||
|
147 | * setter: {{#crossLink "TextCell/set_text"}}{{/crossLink}} | |||
|
148 | * @method get_text | |||
|
149 | * @retrun {string} CodeMirror current text value | |||
|
150 | */ | |||
120 | TextCell.prototype.get_text = function() { |
|
151 | TextCell.prototype.get_text = function() { | |
121 | return this.code_mirror.getValue(); |
|
152 | return this.code_mirror.getValue(); | |
122 | }; |
|
153 | }; | |
123 |
|
154 | |||
124 |
|
155 | /** | ||
|
156 | * @param {string} text - Codemiror text value | |||
|
157 | * @see TextCell#get_text | |||
|
158 | * @method set_text | |||
|
159 | * */ | |||
125 | TextCell.prototype.set_text = function(text) { |
|
160 | TextCell.prototype.set_text = function(text) { | |
126 | this.code_mirror.setValue(text); |
|
161 | this.code_mirror.setValue(text); | |
127 | this.code_mirror.refresh(); |
|
162 | this.code_mirror.refresh(); | |
128 | }; |
|
163 | }; | |
129 |
|
164 | |||
130 |
|
165 | /** | ||
|
166 | * setter :{{#crossLink "TextCell/set_rendered"}}{{/crossLink}} | |||
|
167 | * @method get_rendered | |||
|
168 | * @return {html} html of rendered element | |||
|
169 | * */ | |||
131 | TextCell.prototype.get_rendered = function() { |
|
170 | TextCell.prototype.get_rendered = function() { | |
132 | return this.element.find('div.text_cell_render').html(); |
|
171 | return this.element.find('div.text_cell_render').html(); | |
133 | }; |
|
172 | }; | |
134 |
|
173 | |||
135 |
|
174 | /** | ||
|
175 | * @method set_rendered | |||
|
176 | */ | |||
136 | TextCell.prototype.set_rendered = function(text) { |
|
177 | TextCell.prototype.set_rendered = function(text) { | |
137 | this.element.find('div.text_cell_render').html(text); |
|
178 | this.element.find('div.text_cell_render').html(text); | |
138 | }; |
|
179 | }; | |
139 |
|
180 | |||
140 |
|
181 | /** | ||
|
182 | * not deprecated, but implementation wrong | |||
|
183 | * @method at_top | |||
|
184 | * @deprecated | |||
|
185 | * @return {Boolean} true is cell rendered, false otherwise | |||
|
186 | * I doubt this is what it is supposed to do | |||
|
187 | * this implementation is completly false | |||
|
188 | */ | |||
141 | TextCell.prototype.at_top = function () { |
|
189 | TextCell.prototype.at_top = function () { | |
142 | if (this.rendered) { |
|
190 | if (this.rendered) { | |
143 | return true; |
|
191 | return true; | |
@@ -147,6 +195,14 b' var IPython = (function (IPython) {' | |||||
147 | }; |
|
195 | }; | |
148 |
|
196 | |||
149 |
|
197 | |||
|
198 | /** | |||
|
199 | * not deprecated, but implementation wrong | |||
|
200 | * @method at_bottom | |||
|
201 | * @deprecated | |||
|
202 | * @return {Boolean} true is cell rendered, false otherwise | |||
|
203 | * I doubt this is what it is supposed to do | |||
|
204 | * this implementation is completly false | |||
|
205 | * */ | |||
150 | TextCell.prototype.at_bottom = function () { |
|
206 | TextCell.prototype.at_bottom = function () { | |
151 | if (this.rendered) { |
|
207 | if (this.rendered) { | |
152 | return true; |
|
208 | return true; | |
@@ -155,7 +211,9 b' var IPython = (function (IPython) {' | |||||
155 | } |
|
211 | } | |
156 | }; |
|
212 | }; | |
157 |
|
213 | |||
158 |
|
214 | /** Create Text cell from JSON | ||
|
215 | * @param {json} data - JSON serialized text-cell | |||
|
216 | */ | |||
159 | TextCell.prototype.fromJSON = function (data) { |
|
217 | TextCell.prototype.fromJSON = function (data) { | |
160 | IPython.Cell.prototype.fromJSON.apply(this, arguments); |
|
218 | IPython.Cell.prototype.fromJSON.apply(this, arguments); | |
161 | if (data.cell_type === this.cell_type) { |
|
219 | if (data.cell_type === this.cell_type) { | |
@@ -180,8 +238,11 b' var IPython = (function (IPython) {' | |||||
180 | }; |
|
238 | }; | |
181 |
|
239 | |||
182 |
|
240 | |||
183 | // HTMLCell |
|
241 | /** | |
184 |
|
242 | * @constructs HtmlCell | ||
|
243 | * @class HtmlCell | |||
|
244 | * @extends TextCell | |||
|
245 | */ | |||
185 | var HTMLCell = function () { |
|
246 | var HTMLCell = function () { | |
186 | this.placeholder = "Type <strong>HTML</strong> and LaTeX: $\\alpha^2$"; |
|
247 | this.placeholder = "Type <strong>HTML</strong> and LaTeX: $\\alpha^2$"; | |
187 | IPython.TextCell.apply(this, arguments); |
|
248 | IPython.TextCell.apply(this, arguments); | |
@@ -206,7 +267,10 b' var IPython = (function (IPython) {' | |||||
206 |
|
267 | |||
207 |
|
268 | |||
208 | // MarkdownCell |
|
269 | // MarkdownCell | |
209 |
|
270 | /** @class MarkdownCell | ||
|
271 | * @constructs MarkdownCell | |||
|
272 | * @extends HtmlCell | |||
|
273 | */ | |||
210 | var MarkdownCell = function () { |
|
274 | var MarkdownCell = function () { | |
211 | this.placeholder = "Type *Markdown* and LaTeX: $\\alpha^2$"; |
|
275 | this.placeholder = "Type *Markdown* and LaTeX: $\\alpha^2$"; | |
212 | IPython.TextCell.apply(this, arguments); |
|
276 | IPython.TextCell.apply(this, arguments); | |
@@ -255,6 +319,9 b' var IPython = (function (IPython) {' | |||||
255 |
|
319 | |||
256 | // RawCell |
|
320 | // RawCell | |
257 |
|
321 | |||
|
322 | /** @construct RawCell | |||
|
323 | * @extends TextCell | |||
|
324 | */ | |||
258 | var RawCell = function () { |
|
325 | var RawCell = function () { | |
259 | this.placeholder = "Type plain text and LaTeX: $\\alpha^2$"; |
|
326 | this.placeholder = "Type plain text and LaTeX: $\\alpha^2$"; | |
260 | this.code_mirror_mode = 'rst'; |
|
327 | this.code_mirror_mode = 'rst'; | |
@@ -337,8 +404,9 b' var IPython = (function (IPython) {' | |||||
337 | }; |
|
404 | }; | |
338 |
|
405 | |||
339 |
|
406 | |||
340 | // HTMLCell |
|
407 | /** @constructs HeadingCell | |
341 |
|
408 | * @extends TextCell | ||
|
409 | */ | |||
342 | var HeadingCell = function () { |
|
410 | var HeadingCell = function () { | |
343 | this.placeholder = "Type Heading Here"; |
|
411 | this.placeholder = "Type Heading Here"; | |
344 | IPython.TextCell.apply(this, arguments); |
|
412 | IPython.TextCell.apply(this, arguments); | |
@@ -349,7 +417,7 b' var IPython = (function (IPython) {' | |||||
349 |
|
417 | |||
350 | HeadingCell.prototype = new TextCell(); |
|
418 | HeadingCell.prototype = new TextCell(); | |
351 |
|
419 | |||
352 |
|
420 | /** from json */ | ||
353 | HeadingCell.prototype.fromJSON = function (data) { |
|
421 | HeadingCell.prototype.fromJSON = function (data) { | |
354 | if (data.level != undefined){ |
|
422 | if (data.level != undefined){ | |
355 | this.level = data.level; |
|
423 | this.level = data.level; | |
@@ -373,7 +441,9 b' var IPython = (function (IPython) {' | |||||
373 | }; |
|
441 | }; | |
374 | }; |
|
442 | }; | |
375 |
|
443 | |||
376 |
|
444 | /** The depth of header cell, based on html (h1 to h6) | ||
|
445 | * @return {integer} level - for 1 to 6 | |||
|
446 | */ | |||
377 | HeadingCell.prototype.get_level = function () { |
|
447 | HeadingCell.prototype.get_level = function () { | |
378 | return this.level; |
|
448 | return this.level; | |
379 | }; |
|
449 | }; |
General Comments 0
You need to be logged in to leave comments.
Login now