##// END OF EJS Templates
start to document js
Matthias BUSSONNIER -
Show More
@@ -9,11 +9,18
9 9 // TextCell
10 10 //============================================================================
11 11
12 /**
13 A module that allow to create different type of Text Cell
14 */
12 15 var IPython = (function (IPython) {
13 16
14 17 // TextCell base class
15 18 var key = IPython.utils.keycodes;
16 19
20 /**
21 * @class TextCell
22 * @constructs TextCell
23 */
17 24 var TextCell = function () {
18 25 this.code_mirror_mode = this.code_mirror_mode || 'htmlmixed';
19 26 IPython.Cell.apply(this, arguments);
@@ -21,10 +28,12 var IPython = (function (IPython) {
21 28 this.cell_type = this.cell_type || 'text';
22 29 };
23 30
24
25 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 37 TextCell.prototype.create_element = function () {
29 38 var cell = $("<div>").addClass('cell text_cell border-box-sizing');
30 39 cell.attr('tabindex','2');
@@ -47,6 +56,11 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 64 TextCell.prototype.bind_events = function () {
51 65 IPython.Cell.prototype.bind_events.apply(this);
52 66 var that = this;
@@ -63,13 +77,16 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 88 TextCell.prototype.handle_codemirror_keyevent = function (editor, event) {
68 // This method gets called in CodeMirror's onKeyDown/onKeyPress
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
89
73 90 if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey)) {
74 91 // Always ignore shift-enter in CodeMirror as we handle it.
75 92 return true;
@@ -77,26 +94,33 var IPython = (function (IPython) {
77 94 return false;
78 95 };
79 96
80
97 /**
98 * Select the current cell
99 * @method select
100 */
81 101 TextCell.prototype.select = function () {
82 102 IPython.Cell.prototype.select.apply(this);
83 103 var output = this.element.find("div.text_cell_render");
84 104 output.trigger('focus');
85 105 };
86 106
87
107 /** unselect the current cell
108 * @method unselect
109 */
88 110 TextCell.prototype.unselect = function() {
89 111 // render on selection of another cell
90 112 this.render();
91 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 119 TextCell.prototype.edit = function () {
96 120 if ( this.read_only ) return;
97 121 if (this.rendered === true) {
98 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 124 output.hide();
101 125 text_cell.find('div.text_cell_input').show();
102 126 this.code_mirror.refresh();
@@ -113,31 +137,55 var IPython = (function (IPython) {
113 137 };
114 138
115 139
116 // Subclasses must define render.
140 /** Subclasses must define render.
141 * @method render
142 */
117 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 151 TextCell.prototype.get_text = function() {
121 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 160 TextCell.prototype.set_text = function(text) {
126 161 this.code_mirror.setValue(text);
127 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 170 TextCell.prototype.get_rendered = function() {
132 171 return this.element.find('div.text_cell_render').html();
133 172 };
134 173
135
174 /**
175 * @method set_rendered
176 */
136 177 TextCell.prototype.set_rendered = function(text) {
137 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 189 TextCell.prototype.at_top = function () {
142 190 if (this.rendered) {
143 191 return true;
@@ -147,6 +195,14 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 206 TextCell.prototype.at_bottom = function () {
151 207 if (this.rendered) {
152 208 return true;
@@ -155,7 +211,9 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 217 TextCell.prototype.fromJSON = function (data) {
160 218 IPython.Cell.prototype.fromJSON.apply(this, arguments);
161 219 if (data.cell_type === this.cell_type) {
@@ -180,8 +238,11 var IPython = (function (IPython) {
180 238 };
181 239
182 240
183 // HTMLCell
184
241 /**
242 * @constructs HtmlCell
243 * @class HtmlCell
244 * @extends TextCell
245 */
185 246 var HTMLCell = function () {
186 247 this.placeholder = "Type <strong>HTML</strong> and LaTeX: $\\alpha^2$";
187 248 IPython.TextCell.apply(this, arguments);
@@ -206,7 +267,10 var IPython = (function (IPython) {
206 267
207 268
208 269 // MarkdownCell
209
270 /** @class MarkdownCell
271 * @constructs MarkdownCell
272 * @extends HtmlCell
273 */
210 274 var MarkdownCell = function () {
211 275 this.placeholder = "Type *Markdown* and LaTeX: $\\alpha^2$";
212 276 IPython.TextCell.apply(this, arguments);
@@ -255,6 +319,9 var IPython = (function (IPython) {
255 319
256 320 // RawCell
257 321
322 /** @construct RawCell
323 * @extends TextCell
324 */
258 325 var RawCell = function () {
259 326 this.placeholder = "Type plain text and LaTeX: $\\alpha^2$";
260 327 this.code_mirror_mode = 'rst';
@@ -337,8 +404,9 var IPython = (function (IPython) {
337 404 };
338 405
339 406
340 // HTMLCell
341
407 /** @constructs HeadingCell
408 * @extends TextCell
409 */
342 410 var HeadingCell = function () {
343 411 this.placeholder = "Type Heading Here";
344 412 IPython.TextCell.apply(this, arguments);
@@ -349,7 +417,7 var IPython = (function (IPython) {
349 417
350 418 HeadingCell.prototype = new TextCell();
351 419
352
420 /** from json */
353 421 HeadingCell.prototype.fromJSON = function (data) {
354 422 if (data.level != undefined){
355 423 this.level = data.level;
@@ -373,7 +441,9 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 447 HeadingCell.prototype.get_level = function () {
378 448 return this.level;
379 449 };
General Comments 0
You need to be logged in to leave comments. Login now