##// END OF EJS Templates
Added placeholder text for TextCell.
Brian Granger -
Show More
@@ -1,535 +1,537 b''
1 var IPYTHON = {};
1 var IPYTHON = {};
2
2
3
3
4 //============================================================================
4 //============================================================================
5 // Notebook
5 // Notebook
6 //============================================================================
6 //============================================================================
7
7
8
8
9 var Notebook = function (selector) {
9 var Notebook = function (selector) {
10 this.element = $(selector);
10 this.element = $(selector);
11 this.element.data("notebook", this);
11 this.element.data("notebook", this);
12 this.next_prompt_number = 1;
12 this.next_prompt_number = 1;
13 this.bind_events();
13 this.bind_events();
14 }
14 }
15
15
16
16
17 Notebook.prototype.bind_events = function () {
17 Notebook.prototype.bind_events = function () {
18 var that = this;
18 var that = this;
19 $(document).keydown(function (event) {
19 $(document).keydown(function (event) {
20 console.log(event);
20 console.log(event);
21 if (event.which == 38 && event.shiftKey) {
21 if (event.which == 38 && event.shiftKey) {
22 that.select_prev();
22 that.select_prev();
23 } else if (event.which == 40 && event.shiftKey) {
23 } else if (event.which == 40 && event.shiftKey) {
24 that.select_next();
24 that.select_next();
25 } else if (event.which == 13 && event.shiftKey) {
25 } else if (event.which == 13 && event.shiftKey) {
26 // The focus is not quite working here.
26 // The focus is not quite working here.
27 event.preventDefault();
27 event.preventDefault();
28 that.insert_code_cell_after();
28 that.insert_code_cell_after();
29 }
29 }
30 });
30 });
31 };
31 };
32
32
33
33
34 // Cell indexing, retrieval, etc.
34 // Cell indexing, retrieval, etc.
35
35
36
36
37 Notebook.prototype.cell_elements = function () {
37 Notebook.prototype.cell_elements = function () {
38 return this.element.children("div.cell");
38 return this.element.children("div.cell");
39 }
39 }
40
40
41
41
42 Notebook.prototype.ncells = function (cell) {
42 Notebook.prototype.ncells = function (cell) {
43 return this.cell_elements().length;
43 return this.cell_elements().length;
44 }
44 }
45
45
46
46
47 // TODO: we are often calling cells as cells()[i], which we should optimize
47 // TODO: we are often calling cells as cells()[i], which we should optimize
48 // to cells(i) or a new method.
48 // to cells(i) or a new method.
49 Notebook.prototype.cells = function () {
49 Notebook.prototype.cells = function () {
50 return this.cell_elements().toArray().map(function (e) {
50 return this.cell_elements().toArray().map(function (e) {
51 return $(e).data("cell");
51 return $(e).data("cell");
52 });
52 });
53 }
53 }
54
54
55
55
56 Notebook.prototype.find_cell_index = function (cell) {
56 Notebook.prototype.find_cell_index = function (cell) {
57 var result = null;
57 var result = null;
58 this.cell_elements().filter(function (index) {
58 this.cell_elements().filter(function (index) {
59 if ($(this).data("cell") === cell) {
59 if ($(this).data("cell") === cell) {
60 result = index;
60 result = index;
61 };
61 };
62 });
62 });
63 return result;
63 return result;
64 };
64 };
65
65
66
66
67 Notebook.prototype.index_or_selected = function (index) {
67 Notebook.prototype.index_or_selected = function (index) {
68 return index || this.selected_index() || 0;
68 return index || this.selected_index() || 0;
69 }
69 }
70
70
71
71
72 Notebook.prototype.select = function (index) {
72 Notebook.prototype.select = function (index) {
73 if (index !== undefined && index >= 0 && index < this.ncells()) {
73 if (index !== undefined && index >= 0 && index < this.ncells()) {
74 if (this.selected_index() !== null) {
74 if (this.selected_index() !== null) {
75 this.selected_cell().unselect();
75 this.selected_cell().unselect();
76 };
76 };
77 this.cells()[index].select();
77 this.cells()[index].select();
78 };
78 };
79 return this;
79 return this;
80 };
80 };
81
81
82
82
83 Notebook.prototype.select_next = function () {
83 Notebook.prototype.select_next = function () {
84 var index = this.selected_index();
84 var index = this.selected_index();
85 if (index !== null && index >= 0 && (index+1) < this.ncells()) {
85 if (index !== null && index >= 0 && (index+1) < this.ncells()) {
86 this.select(index+1);
86 this.select(index+1);
87 };
87 };
88 return this;
88 return this;
89 };
89 };
90
90
91
91
92 Notebook.prototype.select_prev = function () {
92 Notebook.prototype.select_prev = function () {
93 var index = this.selected_index();
93 var index = this.selected_index();
94 if (index !== null && index >= 0 && (index-1) < this.ncells()) {
94 if (index !== null && index >= 0 && (index-1) < this.ncells()) {
95 this.select(index-1);
95 this.select(index-1);
96 };
96 };
97 return this;
97 return this;
98 };
98 };
99
99
100
100
101 Notebook.prototype.selected_index = function () {
101 Notebook.prototype.selected_index = function () {
102 var result = null;
102 var result = null;
103 this.cell_elements().filter(function (index) {
103 this.cell_elements().filter(function (index) {
104 if ($(this).data("cell").selected === true) {
104 if ($(this).data("cell").selected === true) {
105 result = index;
105 result = index;
106 };
106 };
107 });
107 });
108 return result;
108 return result;
109 };
109 };
110
110
111
111
112 Notebook.prototype.selected_cell = function () {
112 Notebook.prototype.selected_cell = function () {
113 return this.cell_elements().eq(this.selected_index()).data("cell");
113 return this.cell_elements().eq(this.selected_index()).data("cell");
114 }
114 }
115
115
116
116
117 // Cell insertion, deletion and moving.
117 // Cell insertion, deletion and moving.
118
118
119
119
120 Notebook.prototype.delete_cell = function (index) {
120 Notebook.prototype.delete_cell = function (index) {
121 var i = index || this.selected_index();
121 var i = index || this.selected_index();
122 if (i !== null && i >= 0 && i < this.ncells()) {
122 if (i !== null && i >= 0 && i < this.ncells()) {
123 this.cell_elements().eq(i).remove();
123 this.cell_elements().eq(i).remove();
124 if (i === (this.ncells())) {
124 if (i === (this.ncells())) {
125 this.select(i-1);
125 this.select(i-1);
126 } else {
126 } else {
127 this.select(i);
127 this.select(i);
128 };
128 };
129 };
129 };
130 return this;
130 return this;
131 };
131 };
132
132
133
133
134 Notebook.prototype.append_cell = function (cell) {
134 Notebook.prototype.append_cell = function (cell) {
135 this.element.append(cell.element);
135 this.element.append(cell.element);
136 return this;
136 return this;
137 };
137 };
138
138
139
139
140 Notebook.prototype.insert_cell_after = function (cell, index) {
140 Notebook.prototype.insert_cell_after = function (cell, index) {
141 var ncells = this.ncells();
141 var ncells = this.ncells();
142 if (ncells === 0) {
142 if (ncells === 0) {
143 this.append_cell(cell);
143 this.append_cell(cell);
144 return this;
144 return this;
145 };
145 };
146 if (index >= 0 && index < ncells) {
146 if (index >= 0 && index < ncells) {
147 this.cell_elements().eq(index).after(cell.element);
147 this.cell_elements().eq(index).after(cell.element);
148 };
148 };
149 return this
149 return this
150 };
150 };
151
151
152
152
153 Notebook.prototype.insert_cell_before = function (cell, index) {
153 Notebook.prototype.insert_cell_before = function (cell, index) {
154 var ncells = this.ncells();
154 var ncells = this.ncells();
155 if (ncells === 0) {
155 if (ncells === 0) {
156 this.append_cell(cell);
156 this.append_cell(cell);
157 return this;
157 return this;
158 };
158 };
159 if (index >= 0 && index < ncells) {
159 if (index >= 0 && index < ncells) {
160 this.cell_elements().eq(index).before(cell.element);
160 this.cell_elements().eq(index).before(cell.element);
161 };
161 };
162 return this;
162 return this;
163 };
163 };
164
164
165
165
166 Notebook.prototype.move_cell_up = function (index) {
166 Notebook.prototype.move_cell_up = function (index) {
167 var i = index || this.selected_index();
167 var i = index || this.selected_index();
168 if (i !== null && i < this.ncells() && i > 0) {
168 if (i !== null && i < this.ncells() && i > 0) {
169 var pivot = this.cell_elements().eq(i-1);
169 var pivot = this.cell_elements().eq(i-1);
170 var tomove = this.cell_elements().eq(i);
170 var tomove = this.cell_elements().eq(i);
171 if (pivot !== null && tomove !== null) {
171 if (pivot !== null && tomove !== null) {
172 tomove.detach();
172 tomove.detach();
173 pivot.before(tomove);
173 pivot.before(tomove);
174 this.select(i-1);
174 this.select(i-1);
175 };
175 };
176 };
176 };
177 return this;
177 return this;
178 }
178 }
179
179
180
180
181 Notebook.prototype.move_cell_down = function (index) {
181 Notebook.prototype.move_cell_down = function (index) {
182 var i = index || this.selected_index();
182 var i = index || this.selected_index();
183 if (i !== null && i < (this.ncells()-1) && i >= 0) {
183 if (i !== null && i < (this.ncells()-1) && i >= 0) {
184 var pivot = this.cell_elements().eq(i+1)
184 var pivot = this.cell_elements().eq(i+1)
185 var tomove = this.cell_elements().eq(i)
185 var tomove = this.cell_elements().eq(i)
186 if (pivot !== null && tomove !== null) {
186 if (pivot !== null && tomove !== null) {
187 tomove.detach();
187 tomove.detach();
188 pivot.after(tomove);
188 pivot.after(tomove);
189 this.select(i+1);
189 this.select(i+1);
190 };
190 };
191 };
191 };
192 return this;
192 return this;
193 }
193 }
194
194
195
195
196 Notebook.prototype.sort_cells = function () {
196 Notebook.prototype.sort_cells = function () {
197 var ncells = this.ncells();
197 var ncells = this.ncells();
198 var swapped;
198 var swapped;
199 do {
199 do {
200 swapped = false
200 swapped = false
201 for (var i=1; i<ncells; i++) {
201 for (var i=1; i<ncells; i++) {
202 current = this.cell_elements().eq(i).data("cell");
202 current = this.cell_elements().eq(i).data("cell");
203 previous = this.cell_elements().eq(i-1).data("cell");
203 previous = this.cell_elements().eq(i-1).data("cell");
204 if (previous.input_prompt_number > current.input_prompt_number) {
204 if (previous.input_prompt_number > current.input_prompt_number) {
205 this.move_cell_up(i);
205 this.move_cell_up(i);
206 swapped = true;
206 swapped = true;
207 };
207 };
208 };
208 };
209 } while (swapped);
209 } while (swapped);
210 return this;
210 return this;
211 };
211 };
212
212
213
213
214 Notebook.prototype.insert_code_cell_before = function (index) {
214 Notebook.prototype.insert_code_cell_before = function (index) {
215 // TODO: Bounds check for i
215 // TODO: Bounds check for i
216 var i = this.index_or_selected(index);
216 var i = this.index_or_selected(index);
217 var cell = new CodeCell(this);
217 var cell = new CodeCell(this);
218 cell.set_input_prompt(this.next_prompt_number);
218 cell.set_input_prompt(this.next_prompt_number);
219 this.next_prompt_number = this.next_prompt_number + 1;
219 this.next_prompt_number = this.next_prompt_number + 1;
220 this.insert_cell_before(cell, i);
220 this.insert_cell_before(cell, i);
221 this.select(this.find_cell_index(cell));
221 this.select(this.find_cell_index(cell));
222 return this;
222 return this;
223 }
223 }
224
224
225
225
226 Notebook.prototype.insert_code_cell_after = function (index) {
226 Notebook.prototype.insert_code_cell_after = function (index) {
227 // TODO: Bounds check for i
227 // TODO: Bounds check for i
228 var i = this.index_or_selected(index);
228 var i = this.index_or_selected(index);
229 var cell = new CodeCell(this);
229 var cell = new CodeCell(this);
230 cell.set_input_prompt(this.next_prompt_number);
230 cell.set_input_prompt(this.next_prompt_number);
231 this.next_prompt_number = this.next_prompt_number + 1;
231 this.next_prompt_number = this.next_prompt_number + 1;
232 this.insert_cell_after(cell, i);
232 this.insert_cell_after(cell, i);
233 this.select(this.find_cell_index(cell));
233 this.select(this.find_cell_index(cell));
234 return this;
234 return this;
235 }
235 }
236
236
237
237
238 Notebook.prototype.insert_text_cell_before = function (index) {
238 Notebook.prototype.insert_text_cell_before = function (index) {
239 // TODO: Bounds check for i
239 // TODO: Bounds check for i
240 var i = this.index_or_selected(index);
240 var i = this.index_or_selected(index);
241 var cell = new TextCell(this);
241 var cell = new TextCell(this);
242 cell.config_mathjax();
242 cell.config_mathjax();
243 this.insert_cell_before(cell, i);
243 this.insert_cell_before(cell, i);
244 this.select(this.find_cell_index(cell));
244 this.select(this.find_cell_index(cell));
245 return this;
245 return this;
246 }
246 }
247
247
248
248
249 Notebook.prototype.insert_text_cell_after = function (index) {
249 Notebook.prototype.insert_text_cell_after = function (index) {
250 // TODO: Bounds check for i
250 // TODO: Bounds check for i
251 var i = this.index_or_selected(index);
251 var i = this.index_or_selected(index);
252 var cell = new TextCell(this);
252 var cell = new TextCell(this);
253 cell.config_mathjax();
253 cell.config_mathjax();
254 this.insert_cell_after(cell, i);
254 this.insert_cell_after(cell, i);
255 this.select(this.find_cell_index(cell));
255 this.select(this.find_cell_index(cell));
256 return this;
256 return this;
257 }
257 }
258
258
259
259
260 Notebook.prototype.text_to_code = function (index) {
260 Notebook.prototype.text_to_code = function (index) {
261 // TODO: Bounds check for i
261 // TODO: Bounds check for i
262 var i = this.index_or_selected(index);
262 var i = this.index_or_selected(index);
263 var source_element = this.cell_elements().eq(i);
263 var source_element = this.cell_elements().eq(i);
264 var source_cell = source_element.data("cell");
264 var source_cell = source_element.data("cell");
265 if (source_cell instanceof TextCell) {
265 if (source_cell instanceof TextCell) {
266 this.insert_code_cell_after(i);
266 this.insert_code_cell_after(i);
267 var target_cell = this.cells()[i+1];
267 var target_cell = this.cells()[i+1];
268 var text = source_element.find("textarea.text_cell_input").val();
268 var text = source_element.find("textarea.text_cell_input").val();
269 target_cell.element.find("textarea.input_area").val(text);
269 target_cell.element.find("textarea.input_area").val(text);
270 source_element.remove();
270 source_element.remove();
271 };
271 };
272 };
272 };
273
273
274
274
275 Notebook.prototype.code_to_text = function (index) {
275 Notebook.prototype.code_to_text = function (index) {
276 // TODO: Bounds check for i
276 // TODO: Bounds check for i
277 var i = this.index_or_selected(index);
277 var i = this.index_or_selected(index);
278 var source_element = this.cell_elements().eq(i);
278 var source_element = this.cell_elements().eq(i);
279 var source_cell = source_element.data("cell");
279 var source_cell = source_element.data("cell");
280 if (source_cell instanceof CodeCell) {
280 if (source_cell instanceof CodeCell) {
281 this.insert_text_cell_after(i);
281 this.insert_text_cell_after(i);
282 var target_cell = this.cells()[i+1];
282 var target_cell = this.cells()[i+1];
283 var text = source_element.find("textarea.input_area").val();
283 var text = source_element.find("textarea.input_area").val();
284 if (text === "") {text = target_cell.placeholder;};
284 target_cell.element.find("textarea.text_cell_input").val(text);
285 target_cell.element.find("textarea.text_cell_input").val(text);
285 target_cell.element.find("textarea.text_cell_input").html(text);
286 target_cell.element.find("textarea.text_cell_input").html(text);
286 target_cell.element.find("div.text_cell_render").html(text);
287 target_cell.element.find("div.text_cell_render").html(text);
287
288
288 source_element.remove();
289 source_element.remove();
289 };
290 };
290 };
291 };
291
292
292
293
293 // Cell collapsing
294 // Cell collapsing
294
295
295 Notebook.prototype.collapse = function (index) {
296 Notebook.prototype.collapse = function (index) {
296 var i = this.index_or_selected(index);
297 var i = this.index_or_selected(index);
297 this.cells()[i].collapse();
298 this.cells()[i].collapse();
298 }
299 }
299
300
300
301
301 Notebook.prototype.expand = function (index) {
302 Notebook.prototype.expand = function (index) {
302 var i = this.index_or_selected(index);
303 var i = this.index_or_selected(index);
303 this.cells()[i].expand();
304 this.cells()[i].expand();
304 }
305 }
305
306
306
307
307 //============================================================================
308 //============================================================================
308 // Cell
309 // Cell
309 //============================================================================
310 //============================================================================
310
311
311
312
312 var Cell = function (notebook) {
313 var Cell = function (notebook) {
313 this.notebook = notebook;
314 this.notebook = notebook;
314 this.selected = false;
315 this.selected = false;
315 this.element;
316 this.element;
316 this.create_element();
317 this.create_element();
317 if (this.element !== undefined) {
318 if (this.element !== undefined) {
318 this.element.data("cell", this);
319 this.element.data("cell", this);
319 this.bind_events();
320 this.bind_events();
320 }
321 }
321 };
322 };
322
323
323
324
324 Cell.prototype.select = function () {
325 Cell.prototype.select = function () {
325 this.element.addClass('ui-widget-content ui-corner-all');
326 this.element.addClass('ui-widget-content ui-corner-all');
326 this.selected = true;
327 this.selected = true;
327 // TODO: we need t test across browsers to see if both of these are needed.
328 // TODO: we need t test across browsers to see if both of these are needed.
328 // In the meantime, there should not be any harm in having them both.
329 // In the meantime, there should not be any harm in having them both.
329 this.element.find('textarea').trigger('focusin');
330 this.element.find('textarea').trigger('focusin');
330 this.element.find('textarea').trigger('focus');
331 this.element.find('textarea').trigger('focus');
331 };
332 };
332
333
333
334
334 Cell.prototype.unselect = function () {
335 Cell.prototype.unselect = function () {
335 this.element.removeClass('ui-widget-content ui-corner-all');
336 this.element.removeClass('ui-widget-content ui-corner-all');
336 this.selected = false;
337 this.selected = false;
337 };
338 };
338
339
339
340
340 Cell.prototype.bind_events = function () {
341 Cell.prototype.bind_events = function () {
341 var that = this;
342 var that = this;
342 var nb = that.notebook
343 var nb = that.notebook
343 that.element.click(function (event) {
344 that.element.click(function (event) {
344 if (that.selected === false) {
345 if (that.selected === false) {
345 nb.select(nb.find_cell_index(that));
346 nb.select(nb.find_cell_index(that));
346 };
347 };
347 });
348 });
348 that.element.focusin(function (event) {
349 that.element.focusin(function (event) {
349 if (that.selected === false) {
350 if (that.selected === false) {
350 nb.select(nb.find_cell_index(that));
351 nb.select(nb.find_cell_index(that));
351 };
352 };
352 });
353 });
353 };
354 };
354
355
355
356
356 // Subclasses must implement create_element.
357 // Subclasses must implement create_element.
357 Cell.prototype.create_element = function () {};
358 Cell.prototype.create_element = function () {};
358
359
359
360
360 //============================================================================
361 //============================================================================
361 // CodeCell
362 // CodeCell
362 //============================================================================
363 //============================================================================
363
364
364
365
365 var CodeCell = function (notebook) {
366 var CodeCell = function (notebook) {
366 Cell.apply(this, arguments);
367 Cell.apply(this, arguments);
367 this.input_prompt_number = ' ';
368 this.input_prompt_number = ' ';
368 this.output_prompt_number = ' ';
369 this.output_prompt_number = ' ';
369 };
370 };
370
371
371
372
372 CodeCell.prototype = new Cell();
373 CodeCell.prototype = new Cell();
373
374
374
375
375 CodeCell.prototype.create_element = function () {
376 CodeCell.prototype.create_element = function () {
376 var cell = $('<div></div>').addClass('cell code_cell')
377 var cell = $('<div></div>').addClass('cell code_cell')
377 var input = $('<div></div>').addClass('input').append(
378 var input = $('<div></div>').addClass('input').append(
378 $('<div/>').addClass('prompt input_prompt')
379 $('<div/>').addClass('prompt input_prompt')
379 ).append(
380 ).append(
380 $('<textarea/>').addClass('input_area').
381 $('<textarea/>').addClass('input_area').
381 attr('rows',1).
382 attr('rows',1).
382 attr('cols',80).
383 attr('cols',80).
383 attr('wrap','hard').
384 attr('wrap','hard').
384 autoGrow()
385 autoGrow()
385 );
386 );
386 var output = $('<div></div>').addClass('output').append(
387 var output = $('<div></div>').addClass('output').append(
387 $('<div/>').addClass('prompt output_prompt')
388 $('<div/>').addClass('prompt output_prompt')
388 ).append(
389 ).append(
389 $('<div/>').addClass('output_area')
390 $('<div/>').addClass('output_area')
390 );
391 );
391 output.hide();
392 output.hide();
392 cell.append(input).append(output);
393 cell.append(input).append(output);
393 this.element = cell;
394 this.element = cell;
394 };
395 };
395
396
396
397
397 CodeCell.prototype.collapse = function () {
398 CodeCell.prototype.collapse = function () {
398 this.element.find('div.output').hide();
399 this.element.find('div.output').hide();
399 };
400 };
400
401
401
402
402 CodeCell.prototype.expand = function () {
403 CodeCell.prototype.expand = function () {
403 this.element.find('div.output').show();
404 this.element.find('div.output').show();
404 };
405 };
405
406
406
407
407 CodeCell.prototype.set_prompt = function (number) {
408 CodeCell.prototype.set_prompt = function (number) {
408 this.set_input_prompt(number);
409 this.set_input_prompt(number);
409 this.set_output_prompt(number);
410 this.set_output_prompt(number);
410 };
411 };
411
412
412 CodeCell.prototype.set_input_prompt = function (number) {
413 CodeCell.prototype.set_input_prompt = function (number) {
413 var n = number || ' ';
414 var n = number || ' ';
414 this.input_prompt_number = n
415 this.input_prompt_number = n
415 this.element.find('div.input_prompt').html('In&nbsp;[' + n + ']:');
416 this.element.find('div.input_prompt').html('In&nbsp;[' + n + ']:');
416 };
417 };
417
418
418
419
419 CodeCell.prototype.set_output_prompt = function (number) {
420 CodeCell.prototype.set_output_prompt = function (number) {
420 var n = number || ' ';
421 var n = number || ' ';
421 this.output_prompt_number = n
422 this.output_prompt_number = n
422 this.element.find('div.output_prompt').html('Out[' + n + ']:');
423 this.element.find('div.output_prompt').html('Out[' + n + ']:');
423 };
424 };
424
425
425
426
426 //============================================================================
427 //============================================================================
427 // TextCell
428 // TextCell
428 //============================================================================
429 //============================================================================
429
430
430
431
431 var TextCell = function (notebook) {
432 var TextCell = function (notebook) {
432 Cell.apply(this, arguments);
433 Cell.apply(this, arguments);
434 this.placeholder = "Type <strong>HTML</strong> and LaTeX: $\\alpha^2$"
433 };
435 };
434
436
435
437
436 TextCell.prototype = new Cell();
438 TextCell.prototype = new Cell();
437
439
438
440
439 TextCell.prototype.create_element = function () {
441 TextCell.prototype.create_element = function () {
440 var cell = $('<div></div').addClass('cell text_cell').
442 var cell = $("<div>").addClass('cell text_cell').
441 append(
443 append(
442 $('<textarea>Type HTML/LaTex content here</textarea>').
444 $("<textarea>" + this.placeholder + "</textarea>").
443 addClass('text_cell_input').
445 addClass('text_cell_input').
444 attr('rows',1).
446 attr('rows',1).
445 attr('cols',80).
447 attr('cols',80).
446 autoGrow()
448 autoGrow()
447 ).append(
449 ).append(
448 $('<div></div>').addClass('text_cell_render')
450 $('<div></div>').addClass('text_cell_render')
449 )
451 )
450 this.element = cell;
452 this.element = cell;
451 };
453 };
452
454
453
455
454 TextCell.prototype.select = function () {
456 TextCell.prototype.select = function () {
455 this.edit();
457 this.edit();
456 Cell.prototype.select.apply(this);
458 Cell.prototype.select.apply(this);
457 };
459 };
458
460
459
461
460 TextCell.prototype.edit = function () {
462 TextCell.prototype.edit = function () {
461 var text_cell = this.element;
463 var text_cell = this.element;
462 var input = text_cell.find("textarea.text_cell_input");
464 var input = text_cell.find("textarea.text_cell_input");
463 var output = text_cell.find("div.text_cell_render");
465 var output = text_cell.find("div.text_cell_render");
464 output.hide();
466 output.hide();
465 input.show().trigger('focus');
467 input.show().trigger('focus');
466 };
468 };
467
469
468
470
469 TextCell.prototype.render = function () {
471 TextCell.prototype.render = function () {
470 var text_cell = this.element;
472 var text_cell = this.element;
471 var input = text_cell.find("textarea.text_cell_input");
473 var input = text_cell.find("textarea.text_cell_input");
472 var output = text_cell.find("div.text_cell_render");
474 var output = text_cell.find("div.text_cell_render");
473 var text = input.val();
475 var text = input.val();
474 output.html(text)
476 output.html(text)
475 input.html(text);
477 input.html(text);
476 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
478 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
477 input.hide();
479 input.hide();
478 output.show();
480 output.show();
479 };
481 };
480
482
481
483
482 TextCell.prototype.config_mathjax = function () {
484 TextCell.prototype.config_mathjax = function () {
483 var text_cell = this.element;
485 var text_cell = this.element;
484 var that = this;
486 var that = this;
485 text_cell.click(function () {
487 text_cell.click(function () {
486 that.edit();
488 that.edit();
487 }).focusout(function () {
489 }).focusout(function () {
488 that.render();
490 that.render();
489 });
491 });
490
492
491 text_cell.trigger("focusout");
493 text_cell.trigger("focusout");
492 };
494 };
493
495
494
496
495 //============================================================================
497 //============================================================================
496 // On document ready
498 // On document ready
497 //============================================================================
499 //============================================================================
498
500
499
501
500 $(document).ready(function () {
502 $(document).ready(function () {
501
503
502 MathJax.Hub.Config({
504 MathJax.Hub.Config({
503 tex2jax: {
505 tex2jax: {
504 inlineMath: [ ['$','$'], ["\\(","\\)"] ],
506 inlineMath: [ ['$','$'], ["\\(","\\)"] ],
505 displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
507 displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
506 }
508 }
507 });
509 });
508
510
509 $("ul#main_menu").wijmenu({animation:{animated: "slide", duration: 100, easing: null}});
511 $("ul#main_menu").wijmenu({animation:{animated: "slide", duration: 100, easing: null}});
510 IPYTHON.notebook = new Notebook('div.notebook');
512 IPYTHON.notebook = new Notebook('div.notebook');
511 IPYTHON.notebook.insert_code_cell_after();
513 IPYTHON.notebook.insert_code_cell_after();
512
514
513 $("#move_cell").buttonset();
515 $("#move_cell").buttonset();
514 $("#move_up").button("option", "icons", {primary:"ui-icon-arrowthick-1-n"});
516 $("#move_up").button("option", "icons", {primary:"ui-icon-arrowthick-1-n"});
515 $("#move_up").button("option", "text", false);
517 $("#move_up").button("option", "text", false);
516 $("#move_up").click(function () {IPYTHON.notebook.move_cell_up();});
518 $("#move_up").click(function () {IPYTHON.notebook.move_cell_up();});
517 $("#move_down").button("option", "icons", {primary:"ui-icon-arrowthick-1-s"});
519 $("#move_down").button("option", "icons", {primary:"ui-icon-arrowthick-1-s"});
518 $("#move_down").button("option", "text", false);
520 $("#move_down").button("option", "text", false);
519 $("#move_down").click(function () {IPYTHON.notebook.move_cell_down();});
521 $("#move_down").click(function () {IPYTHON.notebook.move_cell_down();});
520
522
521 $("#insert_delete").buttonset();
523 $("#insert_delete").buttonset();
522 $("#insert_cell_before").click(function () {IPYTHON.notebook.insert_code_cell_before();});
524 $("#insert_cell_before").click(function () {IPYTHON.notebook.insert_code_cell_before();});
523 $("#insert_cell_after").click(function () {IPYTHON.notebook.insert_code_cell_after();});
525 $("#insert_cell_after").click(function () {IPYTHON.notebook.insert_code_cell_after();});
524 $("#delete_cell").button("option", "icons", {primary:"ui-icon-closethick"});
526 $("#delete_cell").button("option", "icons", {primary:"ui-icon-closethick"});
525 $("#delete_cell").button("option", "text", false);
527 $("#delete_cell").button("option", "text", false);
526 $("#delete_cell").click(function () {IPYTHON.notebook.delete_cell();});
528 $("#delete_cell").click(function () {IPYTHON.notebook.delete_cell();});
527
529
528 $("#cell_type").buttonset();
530 $("#cell_type").buttonset();
529 $("#to_code").click(function () {IPYTHON.notebook.text_to_code();});
531 $("#to_code").click(function () {IPYTHON.notebook.text_to_code();});
530 $("#to_text").click(function () {IPYTHON.notebook.code_to_text();});
532 $("#to_text").click(function () {IPYTHON.notebook.code_to_text();});
531
533
532 $("#sort").buttonset();
534 $("#sort").buttonset();
533 $("#sort_cells").click(function () {IPYTHON.notebook.sort_cells();});
535 $("#sort_cells").click(function () {IPYTHON.notebook.sort_cells();});
534
536
535 }); No newline at end of file
537 });
General Comments 0
You need to be logged in to leave comments. Login now