Show More
@@ -22,12 +22,20 var IPython = (function (IPython) { | |||||
22 | /** |
|
22 | /** | |
23 | * The Base `Cell` class from which to inherit |
|
23 | * The Base `Cell` class from which to inherit | |
24 | * @class Cell |
|
24 | * @class Cell | |
25 | */ |
|
25 | **/ | |
26 |
|
26 | |||
27 | /* |
|
27 | /* | |
28 | * @constructor |
|
28 | * @constructor | |
|
29 | * | |||
|
30 | * @param {object|undefined} [options] | |||
|
31 | * @param [options.cm_config] {object} config to pass to CodeMirror, will extend default parameters | |||
29 | */ |
|
32 | */ | |
30 | var Cell = function () { |
|
33 | var Cell = function (options) { | |
|
34 | ||||
|
35 | options = options || {}; | |||
|
36 | // superclass default overwrite our default | |||
|
37 | this.cm_config = $.extend({},Cell.cm_default,options.cm_config); | |||
|
38 | ||||
31 | this.placeholder = this.placeholder || ''; |
|
39 | this.placeholder = this.placeholder || ''; | |
32 | this.read_only = false; |
|
40 | this.read_only = false; | |
33 | this.selected = false; |
|
41 | this.selected = false; | |
@@ -43,6 +51,11 var IPython = (function (IPython) { | |||||
43 | this.cell_id = utils.uuid(); |
|
51 | this.cell_id = utils.uuid(); | |
44 | }; |
|
52 | }; | |
45 |
|
53 | |||
|
54 | Cell.cm_default = { | |||
|
55 | indentUnit : 4, | |||
|
56 | readOnly: this.read_only, | |||
|
57 | }; | |||
|
58 | ||||
46 |
|
59 | |||
47 | /** |
|
60 | /** | |
48 | * Empty. Subclasses must implement create_element. |
|
61 | * Empty. Subclasses must implement create_element. | |
@@ -240,7 +253,7 var IPython = (function (IPython) { | |||||
240 | }; |
|
253 | }; | |
241 |
|
254 | |||
242 | /** |
|
255 | /** | |
243 |
* |
|
256 | * Force codemirror highlight mode | |
244 | * @method force_highlight |
|
257 | * @method force_highlight | |
245 | * @param {object} - CodeMirror mode |
|
258 | * @param {object} - CodeMirror mode | |
246 | **/ |
|
259 | **/ |
@@ -58,14 +58,30 var IPython = (function (IPython) { | |||||
58 | * |
|
58 | * | |
59 | * @constructor |
|
59 | * @constructor | |
60 | * @param {Object|null} kernel |
|
60 | * @param {Object|null} kernel | |
|
61 | * @param {object|undefined} [options] | |||
|
62 | * @param [options.cm_config] {object} config to pass to CodeMirror | |||
61 | */ |
|
63 | */ | |
62 | var CodeCell = function (kernel) { |
|
64 | var CodeCell = function (kernel, options) { | |
|
65 | var options = options || {} | |||
63 | this.kernel = kernel || null; |
|
66 | this.kernel = kernel || null; | |
64 | this.code_mirror = null; |
|
67 | this.code_mirror = null; | |
65 | this.input_prompt_number = null; |
|
68 | this.input_prompt_number = null; | |
66 | this.collapsed = false; |
|
69 | this.collapsed = false; | |
67 | this.default_mode = 'python'; |
|
70 | this.default_mode = 'python'; | |
68 | IPython.Cell.apply(this, arguments); |
|
71 | ||
|
72 | ||||
|
73 | var cm_overwrite_options = { | |||
|
74 | extraKeys: {"Tab": "indentMore","Shift-Tab" : "indentLess",'Backspace':"delSpaceToPrevTabStop"}, | |||
|
75 | onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this) | |||
|
76 | }; | |||
|
77 | ||||
|
78 | var arg_cm_options = options.cm_options || {}; | |||
|
79 | var cm_config = $.extend({},CodeCell.cm_default, arg_cm_options, cm_overwrite_options); | |||
|
80 | ||||
|
81 | var options = {}; | |||
|
82 | options.cm_config = cm_config; | |||
|
83 | ||||
|
84 | IPython.Cell.apply(this,[options]); | |||
69 |
|
85 | |||
70 | var that = this; |
|
86 | var that = this; | |
71 | this.element.focusout( |
|
87 | this.element.focusout( | |
@@ -73,6 +89,13 var IPython = (function (IPython) { | |||||
73 | ); |
|
89 | ); | |
74 | }; |
|
90 | }; | |
75 |
|
91 | |||
|
92 | CodeCell.cm_default = { | |||
|
93 | mode: 'python', | |||
|
94 | theme: 'ipython', | |||
|
95 | matchBrackets: true | |||
|
96 | }; | |||
|
97 | ||||
|
98 | ||||
76 | CodeCell.prototype = new IPython.Cell(); |
|
99 | CodeCell.prototype = new IPython.Cell(); | |
77 |
|
100 | |||
78 | /** |
|
101 | /** | |
@@ -96,15 +119,7 var IPython = (function (IPython) { | |||||
96 | input.append($('<div/>').addClass('prompt input_prompt')); |
|
119 | input.append($('<div/>').addClass('prompt input_prompt')); | |
97 | vbox.append(this.celltoolbar.element); |
|
120 | vbox.append(this.celltoolbar.element); | |
98 | var input_area = $('<div/>').addClass('input_area'); |
|
121 | var input_area = $('<div/>').addClass('input_area'); | |
99 |
this.code_mirror = CodeMirror(input_area.get(0), |
|
122 | this.code_mirror = CodeMirror(input_area.get(0), this.cm_config); | |
100 | indentUnit : 4, |
|
|||
101 | mode: 'python', |
|
|||
102 | theme: 'ipython', |
|
|||
103 | readOnly: this.read_only, |
|
|||
104 | extraKeys: {"Tab": "indentMore","Shift-Tab" : "indentLess",'Backspace':"delSpaceToPrevTabStop"}, |
|
|||
105 | onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this), |
|
|||
106 | matchBrackets: true |
|
|||
107 | }); |
|
|||
108 | vbox.append(input_area); |
|
123 | vbox.append(input_area); | |
109 | input.append(vbox); |
|
124 | input.append(vbox); | |
110 | var output = $('<div></div>'); |
|
125 | var output = $('<div></div>'); |
@@ -26,14 +26,38 var IPython = (function (IPython) { | |||||
26 | * @class TextCell |
|
26 | * @class TextCell | |
27 | * @constructor TextCell |
|
27 | * @constructor TextCell | |
28 | * @extend Ipython.Cell |
|
28 | * @extend Ipython.Cell | |
|
29 | * @param {object|undefined} [options] | |||
|
30 | * @param [options.cm_config] {object} config to pass to CodeMirror, will extend/overwrite default config | |||
29 | */ |
|
31 | */ | |
30 | var TextCell = function () { |
|
32 | var TextCell = function (options) { | |
31 | this.code_mirror_mode = this.code_mirror_mode || 'htmlmixed'; |
|
33 | this.code_mirror_mode = this.code_mirror_mode || 'htmlmixed'; | |
32 | IPython.Cell.apply(this, arguments); |
|
34 | var options = options || {}; | |
|
35 | ||||
|
36 | var cm_overwrite_options = { | |||
|
37 | extraKeys: {"Tab": "indentMore","Shift-Tab" : "indentLess"}, | |||
|
38 | onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this) | |||
|
39 | }; | |||
|
40 | ||||
|
41 | var arg_cm_options = options.cm_options || {}; | |||
|
42 | var cm_config = $.extend({},TextCell.cm_default, arg_cm_options, cm_overwrite_options); | |||
|
43 | ||||
|
44 | var options = {}; | |||
|
45 | options.cm_config = cm_config; | |||
|
46 | ||||
|
47 | ||||
|
48 | IPython.Cell.apply(this, [options]); | |||
33 | this.rendered = false; |
|
49 | this.rendered = false; | |
34 | this.cell_type = this.cell_type || 'text'; |
|
50 | this.cell_type = this.cell_type || 'text'; | |
35 | }; |
|
51 | }; | |
36 |
|
52 | |||
|
53 | TextCell.cm_default = { | |||
|
54 | mode: this.code_mirror_mode, | |||
|
55 | theme: 'default', | |||
|
56 | value: this.placeholder, | |||
|
57 | lineWrapping : true, | |||
|
58 | } | |||
|
59 | ||||
|
60 | ||||
37 | TextCell.prototype = new IPython.Cell(); |
|
61 | TextCell.prototype = new IPython.Cell(); | |
38 |
|
62 | |||
39 | /** |
|
63 | /** | |
@@ -50,16 +74,7 var IPython = (function (IPython) { | |||||
50 | cell.append(this.celltoolbar.element); |
|
74 | cell.append(this.celltoolbar.element); | |
51 |
|
75 | |||
52 | var input_area = $('<div/>').addClass('text_cell_input border-box-sizing'); |
|
76 | var input_area = $('<div/>').addClass('text_cell_input border-box-sizing'); | |
53 |
this.code_mirror = CodeMirror(input_area.get(0), |
|
77 | this.code_mirror = CodeMirror(input_area.get(0), this.cm_config); | |
54 | indentUnit : 4, |
|
|||
55 | mode: this.code_mirror_mode, |
|
|||
56 | theme: 'default', |
|
|||
57 | value: this.placeholder, |
|
|||
58 | readOnly: this.read_only, |
|
|||
59 | lineWrapping : true, |
|
|||
60 | extraKeys: {"Tab": "indentMore","Shift-Tab" : "indentLess"}, |
|
|||
61 | onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this) |
|
|||
62 | }); |
|
|||
63 | // The tabindex=-1 makes this div focusable. |
|
78 | // The tabindex=-1 makes this div focusable. | |
64 | var render_area = $('<div/>').addClass('text_cell_render border-box-sizing'). |
|
79 | var render_area = $('<div/>').addClass('text_cell_render border-box-sizing'). | |
65 | addClass('rendered_html').attr('tabindex','-1'); |
|
80 | addClass('rendered_html').attr('tabindex','-1'); |
General Comments 0
You need to be logged in to leave comments.
Login now