Show More
@@ -88,23 +88,19 b' Notebook.prototype.bind_events = function () {' | |||||
88 | var that = this; |
|
88 | var that = this; | |
89 | $(document).keydown(function (event) { |
|
89 | $(document).keydown(function (event) { | |
90 | // console.log(event); |
|
90 | // console.log(event); | |
91 | if (event.which == 38) { |
|
91 | if (event.which === 38) { | |
92 | var cell = that.selected_cell(); |
|
92 | var cell = that.selected_cell(); | |
93 |
if (cell |
|
93 | if (cell.at_top()) { | |
94 | if (cell.at_top()) { |
|
94 | event.preventDefault(); | |
95 |
|
|
95 | that.select_prev(); | |
96 | that.select_prev(); |
|
|||
97 | }; |
|
|||
98 | }; |
|
96 | }; | |
99 | } else if (event.which == 40) { |
|
97 | } else if (event.which === 40) { | |
100 | var cell = that.selected_cell(); |
|
98 | var cell = that.selected_cell(); | |
101 |
if (cell |
|
99 | if (cell.at_bottom()) { | |
102 | if (cell.at_bottom()) { |
|
100 | event.preventDefault(); | |
103 |
|
|
101 | that.select_next(); | |
104 | that.select_next(); |
|
|||
105 | }; |
|
|||
106 | }; |
|
102 | }; | |
107 | } else if (event.which == 13 && event.shiftKey) { |
|
103 | } else if (event.which === 13 && event.shiftKey) { | |
108 | // The focus is not quite working here. |
|
104 | // The focus is not quite working here. | |
109 | var cell = that.selected_cell(); |
|
105 | var cell = that.selected_cell(); | |
110 | var cell_index = that.find_cell_index(cell); |
|
106 | var cell_index = that.find_cell_index(cell); | |
@@ -130,17 +126,15 b' Notebook.prototype.bind_events = function () {' | |||||
130 | var msg_id = that.kernel.execute(cell.get_code()); |
|
126 | var msg_id = that.kernel.execute(cell.get_code()); | |
131 | that.msg_cell_map[msg_id] = cell.cell_id; |
|
127 | that.msg_cell_map[msg_id] = cell.cell_id; | |
132 | }; |
|
128 | }; | |
133 |
|
|
129 | } else if (cell instanceof TextCell) { | |
134 | that.insert_code_cell_after(); |
|
130 | event.preventDefault(); | |
135 |
|
|
131 | cell.render(); | |
136 | // Select the next cell if it is a CodeCell, but not |
|
|||
137 | // if it is a TextCell. |
|
|||
138 | var next_cell = that.cells()[cell_index+1]; |
|
|||
139 | if (!(next_cell instanceof TextCell)) { |
|
|||
140 | that.select(cell_index+1); |
|
|||
141 | }; |
|
|||
142 | }; |
|
|||
143 | } |
|
132 | } | |
|
133 | if (cell_index === (that.ncells()-1)) { | |||
|
134 | that.insert_code_cell_after(); | |||
|
135 | } else { | |||
|
136 | that.select(cell_index+1); | |||
|
137 | }; | |||
144 | }; |
|
138 | }; | |
145 | }); |
|
139 | }); | |
146 | }; |
|
140 | }; | |
@@ -413,6 +407,7 b' Notebook.prototype.code_to_text = function (index) {' | |||||
413 | if (text === "") {text = target_cell.placeholder;}; |
|
407 | if (text === "") {text = target_cell.placeholder;}; | |
414 | target_cell.set_text(text); |
|
408 | target_cell.set_text(text); | |
415 | source_element.remove(); |
|
409 | source_element.remove(); | |
|
410 | target_cell.edit(); | |||
416 | }; |
|
411 | }; | |
417 | }; |
|
412 | }; | |
418 |
|
413 | |||
@@ -836,6 +831,7 b' CodeCell.prototype.toJSON = function () {' | |||||
836 | var TextCell = function (notebook) { |
|
831 | var TextCell = function (notebook) { | |
837 | Cell.apply(this, arguments); |
|
832 | Cell.apply(this, arguments); | |
838 | this.placeholder = "Type <strong>HTML</strong> and LaTeX: $\\alpha^2$" |
|
833 | this.placeholder = "Type <strong>HTML</strong> and LaTeX: $\\alpha^2$" | |
|
834 | this.rendered = false; | |||
839 | }; |
|
835 | }; | |
840 |
|
836 | |||
841 |
|
837 | |||
@@ -851,41 +847,63 b' TextCell.prototype.create_element = function () {' | |||||
851 | attr('cols',80). |
|
847 | attr('cols',80). | |
852 | autogrow() |
|
848 | autogrow() | |
853 | ).append( |
|
849 | ).append( | |
854 | $('<div></div>').addClass('text_cell_render') |
|
850 | // The tabindex=-1 makes this div focusable. | |
|
851 | $('<div></div>').addClass('text_cell_render').attr('tabindex','-1') | |||
855 | ) |
|
852 | ) | |
856 | this.element = cell; |
|
853 | this.element = cell; | |
857 | }; |
|
854 | }; | |
858 |
|
855 | |||
859 |
|
856 | |||
|
857 | TextCell.prototype.bind_events = function () { | |||
|
858 | Cell.prototype.bind_events.apply(this); | |||
|
859 | var that = this; | |||
|
860 | this.element.keydown(function (event) { | |||
|
861 | if (event.which === 13) { | |||
|
862 | if (that.rendered) { | |||
|
863 | that.edit(); | |||
|
864 | event.preventDefault(); | |||
|
865 | }; | |||
|
866 | }; | |||
|
867 | }); | |||
|
868 | }; | |||
|
869 | ||||
|
870 | ||||
860 | TextCell.prototype.select = function () { |
|
871 | TextCell.prototype.select = function () { | |
861 | this.edit(); |
|
|||
862 | Cell.prototype.select.apply(this); |
|
872 | Cell.prototype.select.apply(this); | |
|
873 | var output = this.element.find("div.text_cell_render"); | |||
|
874 | output.trigger('focus'); | |||
863 | }; |
|
875 | }; | |
864 |
|
876 | |||
865 |
|
877 | |||
866 | TextCell.prototype.edit = function () { |
|
878 | TextCell.prototype.edit = function () { | |
867 | var text_cell = this.element; |
|
879 | if (this.rendered === true) { | |
868 | var input = text_cell.find("textarea.text_cell_input"); |
|
880 | var text_cell = this.element; | |
869 |
var |
|
881 | var input = text_cell.find("textarea.text_cell_input"); | |
870 | output.hide(); |
|
882 | var output = text_cell.find("div.text_cell_render"); | |
871 | input.show().trigger('focus'); |
|
883 | output.hide(); | |
|
884 | input.show().trigger('focus'); | |||
|
885 | this.rendered = false; | |||
|
886 | }; | |||
872 | }; |
|
887 | }; | |
873 |
|
888 | |||
874 |
|
889 | |||
875 | TextCell.prototype.render = function () { |
|
890 | TextCell.prototype.render = function () { | |
876 | var text_cell = this.element; |
|
891 | if (this.rendered === false) { | |
877 | var input = text_cell.find("textarea.text_cell_input"); |
|
892 | var text_cell = this.element; | |
878 |
var |
|
893 | var input = text_cell.find("textarea.text_cell_input"); | |
879 | var text = input.val(); |
|
894 | var output = text_cell.find("div.text_cell_render"); | |
880 | if (text === "") { |
|
895 | var text = input.val(); | |
881 | text = this.placeholder; |
|
896 | if (text === "") { | |
882 | input.val(text); |
|
897 | text = this.placeholder; | |
|
898 | input.val(text); | |||
|
899 | }; | |||
|
900 | output.html(text) | |||
|
901 | input.html(text); | |||
|
902 | MathJax.Hub.Queue(["Typeset",MathJax.Hub]); | |||
|
903 | input.hide(); | |||
|
904 | output.show(); | |||
|
905 | this.rendered = true; | |||
883 | }; |
|
906 | }; | |
884 | output.html(text) |
|
|||
885 | input.html(text); |
|
|||
886 | MathJax.Hub.Queue(["Typeset",MathJax.Hub]); |
|
|||
887 | input.hide(); |
|
|||
888 | output.show(); |
|
|||
889 | }; |
|
907 | }; | |
890 |
|
908 | |||
891 |
|
909 | |||
@@ -914,6 +932,24 b' TextCell.prototype.set_text = function(text) {' | |||||
914 | }; |
|
932 | }; | |
915 |
|
933 | |||
916 |
|
934 | |||
|
935 | TextCell.prototype.at_top = function () { | |||
|
936 | if (this.rendered) { | |||
|
937 | return true; | |||
|
938 | } else { | |||
|
939 | return false; | |||
|
940 | } | |||
|
941 | }; | |||
|
942 | ||||
|
943 | ||||
|
944 | TextCell.prototype.at_bottom = function () { | |||
|
945 | if (this.rendered) { | |||
|
946 | return true; | |||
|
947 | } else { | |||
|
948 | return false; | |||
|
949 | } | |||
|
950 | }; | |||
|
951 | ||||
|
952 | ||||
917 | TextCell.prototype.fromJSON = function (data) { |
|
953 | TextCell.prototype.fromJSON = function (data) { | |
918 | if (data.cell_type === 'text') { |
|
954 | if (data.cell_type === 'text') { | |
919 | this.set_text(data.text); |
|
955 | this.set_text(data.text); |
General Comments 0
You need to be logged in to leave comments.
Login now