##// END OF EJS Templates
Fixing selection and focus logic.
Brian Granger -
Show More
@@ -16,7 +16,7 b' var Notebook = function (selector) {'
16
16
17 Notebook.prototype.bind_events = function () {
17 Notebook.prototype.bind_events = function () {
18 var that = this;
18 var that = this;
19 that.element.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();
@@ -24,6 +24,7 b' Notebook.prototype.bind_events = function () {'
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 that.insert_code_cell_after();
28 that.insert_code_cell_after();
28 }
29 }
29 });
30 });
@@ -155,7 +156,7 b' Notebook.prototype.insert_cell_before = function (cell, index) {'
155 this.append_cell(cell);
156 this.append_cell(cell);
156 return this;
157 return this;
157 };
158 };
158 if (index > 0 && index < ncells) {
159 if (index >= 0 && index < ncells) {
159 this.cell_elements().eq(index).before(cell.element);
160 this.cell_elements().eq(index).before(cell.element);
160 };
161 };
161 return this;
162 return this;
@@ -170,6 +171,7 b' Notebook.prototype.move_cell_up = function (index) {'
170 if (pivot !== null && tomove !== null) {
171 if (pivot !== null && tomove !== null) {
171 tomove.detach();
172 tomove.detach();
172 pivot.before(tomove);
173 pivot.before(tomove);
174 this.select(i-1);
173 };
175 };
174 };
176 };
175 return this;
177 return this;
@@ -184,6 +186,7 b' Notebook.prototype.move_cell_down = function (index) {'
184 if (pivot !== null && tomove !== null) {
186 if (pivot !== null && tomove !== null) {
185 tomove.detach();
187 tomove.detach();
186 pivot.after(tomove);
188 pivot.after(tomove);
189 this.select(i+1);
187 };
190 };
188 };
191 };
189 return this;
192 return this;
@@ -321,7 +324,10 b' var Cell = function (notebook) {'
321 Cell.prototype.select = function () {
324 Cell.prototype.select = function () {
322 this.element.addClass('ui-widget-content ui-corner-all');
325 this.element.addClass('ui-widget-content ui-corner-all');
323 this.selected = true;
326 this.selected = true;
327 // 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.
324 this.element.find('textarea').trigger('focusin');
329 this.element.find('textarea').trigger('focusin');
330 this.element.find('textarea').trigger('focus');
325 };
331 };
326
332
327
333
@@ -445,27 +451,52 b' TextCell.prototype.create_element = function () {'
445 };
451 };
446
452
447
453
448 TextCell.prototype.config_mathjax = function () {
454 TextCell.prototype.select = function () {
455 this.edit();
456 Cell.prototype.select.apply(this);
457 };
458
459
460 TextCell.prototype.edit = function () {
449 var text_cell = this.element;
461 var text_cell = this.element;
450 var input = text_cell.find("textarea.text_cell_input");
462 var input = text_cell.find("textarea.text_cell_input");
451 var output = text_cell.find("div.text_cell_render");
463 var output = text_cell.find("div.text_cell_render");
464 output.hide();
465 input.show().trigger('focus');
466 };
467
452
468
469 TextCell.prototype.render = function () {
470 var text_cell = this.element;
471 var input = text_cell.find("textarea.text_cell_input");
472 var output = text_cell.find("div.text_cell_render");
473 var text = input.val();
474 output.html(text)
475 input.html(text);
476 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
477 input.hide();
478 output.show();
479 };
480
481
482 TextCell.prototype.config_mathjax = function () {
483 var text_cell = this.element;
484 var that = this;
453 text_cell.click(function () {
485 text_cell.click(function () {
454 output.hide();
486 that.edit();
455 input.show().trigger('focus');
456 }).focusout(function () {
487 }).focusout(function () {
457 var text = input.val();
488 that.render();
458 output.html(text)
459 input.html(text);
460 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
461 input.hide();
462 output.show();
463 });
489 });
464
490
465 text_cell.trigger("focusout");
491 text_cell.trigger("focusout");
466 };
492 };
467
493
468
494
495 //============================================================================
496 // On document ready
497 //============================================================================
498
499
469 $(document).ready(function () {
500 $(document).ready(function () {
470
501
471 MathJax.Hub.Config({
502 MathJax.Hub.Config({
General Comments 0
You need to be logged in to leave comments. Login now