##// END OF EJS Templates
New HTMl cell working with CodeMirror editing.
Brian E. Granger -
Show More
@@ -1,288 +1,288 b''
1
1
2 /**
2 /**
3 * Primary styles
3 * Primary styles
4 *
4 *
5 * Author: IPython Development Team
5 * Author: IPython Development Team
6 */
6 */
7
7
8
8
9 body {
9 body {
10 background-color: white;
10 background-color: white;
11 /* This makes sure that the body covers the entire window and needs to
11 /* This makes sure that the body covers the entire window and needs to
12 be in a different element than the display: box in wrapper below */
12 be in a different element than the display: box in wrapper below */
13 position: absolute;
13 position: absolute;
14 left: 0px;
14 left: 0px;
15 right: 0px;
15 right: 0px;
16 top: 0px;
16 top: 0px;
17 bottom: 0px;
17 bottom: 0px;
18 overflow: hidden;
18 overflow: hidden;
19 }
19 }
20
20
21 span#save_widget {
21 span#save_widget {
22 position: absolute;
22 position: absolute;
23 left: 0px;
23 left: 0px;
24 padding: 5px 0px;
24 padding: 5px 0px;
25 margin: 0px 0px 0px 0px;
25 margin: 0px 0px 0px 0px;
26 }
26 }
27
27
28 input#notebook_name {
28 input#notebook_name {
29 height: 1em;
29 height: 1em;
30 line-height: 1em;
30 line-height: 1em;
31 padding: 5px;
31 padding: 5px;
32 }
32 }
33
33
34 span#kernel_status {
34 span#kernel_status {
35 position: absolute;
35 position: absolute;
36 padding: 8px 5px 5px 5px;
36 padding: 8px 5px 5px 5px;
37 right: 10px;
37 right: 10px;
38 font-weight: bold;
38 font-weight: bold;
39 }
39 }
40
40
41 .status_idle {
41 .status_idle {
42 color: gray;
42 color: gray;
43 }
43 }
44
44
45 .status_busy {
45 .status_busy {
46 color: red;
46 color: red;
47 }
47 }
48
48
49 .status_restarting {
49 .status_restarting {
50 color: black;
50 color: black;
51 }
51 }
52
52
53 div#left_panel {
53 div#left_panel {
54 overflow-y: auto;
54 overflow-y: auto;
55 top: 0px;
55 top: 0px;
56 left: 0px;
56 left: 0px;
57 margin: 0px;
57 margin: 0px;
58 padding: 0px;
58 padding: 0px;
59 position: absolute;
59 position: absolute;
60 }
60 }
61
61
62 h3.section_header {
62 h3.section_header {
63 padding: 5px;
63 padding: 5px;
64 }
64 }
65
65
66 div.section_content {
66 div.section_content {
67 padding: 5px;
67 padding: 5px;
68 }
68 }
69
69
70
70
71 span.section_row_buttons > button {
71 span.section_row_buttons > button {
72 width: 60px;
72 width: 60px;
73 }
73 }
74
74
75 .section_row {
75 .section_row {
76 margin: 5px 0px;
76 margin: 5px 0px;
77 }
77 }
78
78
79 .section_row_buttons {
79 .section_row_buttons {
80 float: right;
80 float: right;
81 }
81 }
82
82
83 #kernel_persist {
83 #kernel_persist {
84 float: right;
84 float: right;
85 }
85 }
86
86
87 .checkbox_label {
87 .checkbox_label {
88 font-size: 85%;
88 font-size: 85%;
89 float: right;
89 float: right;
90 padding: 0.3em;
90 padding: 0.3em;
91 }
91 }
92
92
93 .section_row_header {
93 .section_row_header {
94 float: left;
94 float: left;
95 font-size: 85%;
95 font-size: 85%;
96 padding: 0.4em 0em;
96 padding: 0.4em 0em;
97 font-weight: bold;
97 font-weight: bold;
98 }
98 }
99
99
100 span.button_label {
100 span.button_label {
101 padding: 0.2em 1em;
101 padding: 0.2em 1em;
102 font-size: 77%;
102 font-size: 77%;
103 float: right;
103 float: right;
104 }
104 }
105
105
106 /* This is needed because FF was adding a 2px margin top and bottom. */
106 /* This is needed because FF was adding a 2px margin top and bottom. */
107 .section_row .ui-button {
107 .section_row .ui-button {
108 margin-top: 0px;
108 margin-top: 0px;
109 margin-bottom: 0px;
109 margin-bottom: 0px;
110 }
110 }
111
111
112 #download_format {
112 #download_format {
113 float: right;
113 float: right;
114 font-size: 85%;
114 font-size: 85%;
115 width: 60px;
115 width: 60px;
116 margin: 1px 5px;
116 margin: 1px 5px;
117 }
117 }
118
118
119 div#left_panel_splitter {
119 div#left_panel_splitter {
120 width: 8px;
120 width: 8px;
121 top: 0px;
121 top: 0px;
122 left: 202px;
122 left: 202px;
123 margin: 0px;
123 margin: 0px;
124 padding: 0px;
124 padding: 0px;
125 position: absolute;
125 position: absolute;
126 }
126 }
127
127
128 div#notebook_panel {
128 div#notebook_panel {
129 /* The L margin will be set in the Javascript code*/
129 /* The L margin will be set in the Javascript code*/
130 margin: 0px 0px 0px 0px;
130 margin: 0px 0px 0px 0px;
131 padding: 0px;
131 padding: 0px;
132 }
132 }
133
133
134 div#notebook {
134 div#notebook {
135 overflow-y: scroll;
135 overflow-y: scroll;
136 overflow-x: auto;
136 overflow-x: auto;
137 width: 100%;
137 width: 100%;
138 padding: 0px 15px 0px 15px;
138 padding: 0px 15px 0px 15px;
139 margin: 0px
139 margin: 0px
140 background-color: white;
140 background-color: white;
141 }
141 }
142
142
143 div#pager_splitter {
143 div#pager_splitter {
144 height: 8px;
144 height: 8px;
145 }
145 }
146
146
147 div#pager {
147 div#pager {
148 padding: 15px;
148 padding: 15px;
149 overflow: auto;
149 overflow: auto;
150 }
150 }
151
151
152 div.cell {
152 div.cell {
153 width: 100%;
153 width: 100%;
154 padding: 5px;
154 padding: 5px;
155 /* This acts as a spacer between cells, that is outside the border */
155 /* This acts as a spacer between cells, that is outside the border */
156 margin: 15px 0px 15px 0px;
156 margin: 15px 0px 15px 0px;
157 }
157 }
158
158
159 div.code_cell {
159 div.code_cell {
160 background-color: white;
160 background-color: white;
161 }
161 }
162
162
163 div.prompt {
163 div.prompt {
164 width: 80px;
164 width: 80px;
165 padding: 0.4em;
165 padding: 0.4em;
166 margin: 0px;
166 margin: 0px;
167 font-family: monospace;
167 font-family: monospace;
168 }
168 }
169
169
170 div.input_prompt {
170 div.input_prompt {
171 color: navy;
171 color: navy;
172 }
172 }
173
173
174 div.output {
174 div.output {
175 /* This is a spacer between the input and output of each cell */
175 /* This is a spacer between the input and output of each cell */
176 margin-top: 15px;
176 margin-top: 15px;
177 }
177 }
178
178
179 div.output_prompt {
179 div.output_prompt {
180 color: darkred;
180 color: darkred;
181 }
181 }
182
182
183 div.output_area {
183 div.output_area {
184 text-align: left;
184 text-align: left;
185 color: black;
185 color: black;
186 font-family: monospace;
186 font-family: monospace;
187 }
187 }
188
188
189 div.output_stream {
189 div.output_stream {
190 padding: 0.4em;
190 padding: 0.4em;
191 }
191 }
192
192
193 div.output_latex {
193 div.output_latex {
194 /* Slightly bigger than the rest of the notebook */
194 /* Slightly bigger than the rest of the notebook */
195 font-size: 116%;
195 font-size: 116%;
196 }
196 }
197
197
198 div.output_html {
198 div.output_html {
199 }
199 }
200
200
201 div.output_png {
201 div.output_png {
202 }
202 }
203
203
204 div.text_cell {
204 div.html_cell {
205 background-color: white;
205 background-color: white;
206 }
206 }
207
207
208 textarea.text_cell_input {
208 textarea.html_cell_input {
209 /* Slightly bigger than the rest of the notebook */
209 /* Slightly bigger than the rest of the notebook */
210 font-size: 116%;
210 font-size: 116%;
211 font-family: monospace;
211 font-family: monospace;
212 outline: none;
212 outline: none;
213 resize: none;
213 resize: none;
214 width: inherit;
214 width: inherit;
215 border-style: none;
215 border-style: none;
216 padding: 0px;
216 padding: 0px;
217 margin: 0px;
217 margin: 0px;
218 color: black;
218 color: black;
219 }
219 }
220
220
221 div.text_cell_render {
221 div.html_cell_render {
222 font-family: "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
222 font-family: "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
223 /* Slightly bigger than the rest of the notebook */
223 /* Slightly bigger than the rest of the notebook */
224 font-size: 116%;
224 font-size: 116%;
225 outline: none;
225 outline: none;
226 resize: none;
226 resize: none;
227 width: inherit;
227 width: inherit;
228 border-style: none;
228 border-style: none;
229 padding: 5px;
229 padding: 5px;
230 color: black;
230 color: black;
231 }
231 }
232
232
233 div.text_cell_render em {font-style: italic;}
233 div.html_cell_render em {font-style: italic;}
234 div.text_cell_render strong {font-weight: bold;}
234 div.html_cell_render strong {font-weight: bold;}
235 div.text_cell_render u {text-decoration: underline;}
235 div.html_cell_render u {text-decoration: underline;}
236 div.text_cell_render :link { text-decoration: underline }
236 div.html_cell_render :link { text-decoration: underline }
237 div.text_cell_render :visited { text-decoration: underline }
237 div.html_cell_render :visited { text-decoration: underline }
238 div.text_cell_render h1 {font-size: 197%; margin: .67em 0; font-weight: bold;}
238 div.html_cell_render h1 {font-size: 197%; margin: .67em 0; font-weight: bold;}
239 div.text_cell_render h2 {font-size: 153.9%; margin: .75em 0; font-weight: bold;}
239 div.html_cell_render h2 {font-size: 153.9%; margin: .75em 0; font-weight: bold;}
240 div.text_cell_render h3 {font-size: 116%; margin: .83em 0; font-weight: bold;}
240 div.html_cell_render h3 {font-size: 116%; margin: .83em 0; font-weight: bold;}
241 div.text_cell_render h4 {margin: 1.12em 0; font-weight: bold;}
241 div.html_cell_render h4 {margin: 1.12em 0; font-weight: bold;}
242 div.text_cell_render h5 {font-size: 85%.; margin: 1.5em 0; font-weight: bold;}
242 div.html_cell_render h5 {font-size: 85%.; margin: 1.5em 0; font-weight: bold;}
243 div.text_cell_render h6 {font-size: 77%; margin: 1.67em 0; font-weight: bold;}
243 div.html_cell_render h6 {font-size: 77%; margin: 1.67em 0; font-weight: bold;}
244 div.text_cell_render ul {list-style:disc; margin-left: 40px;}
244 div.html_cell_render ul {list-style:disc; margin-left: 40px;}
245 div.text_cell_render ul ul {list-style:square; margin-left: 40px;}
245 div.html_cell_render ul ul {list-style:square; margin-left: 40px;}
246 div.text_cell_render ul ul ul {list-style:circle; margin-left: 40px;}
246 div.html_cell_render ul ul ul {list-style:circle; margin-left: 40px;}
247 div.text_cell_render ol {list-style:upper-roman; margin-left: 40px;}
247 div.html_cell_render ol {list-style:upper-roman; margin-left: 40px;}
248 div.text_cell_render ol ol {list-style:upper-alpha;}
248 div.html_cell_render ol ol {list-style:upper-alpha;}
249 div.text_cell_render ol ol ol {list-style:decimal;}
249 div.html_cell_render ol ol ol {list-style:decimal;}
250 div.text_cell_render ol ol ol ol {list-style:lower-alpha;}
250 div.html_cell_render ol ol ol ol {list-style:lower-alpha;}
251 div.text_cell_render ol ol ol ol ol {list-style:lower-roman;}
251 div.html_cell_render ol ol ol ol ol {list-style:lower-roman;}
252
252
253
253
254 .CodeMirror {
254 .CodeMirror {
255 overflow: hidden; /* Changed from auto to remove scrollbar */
255 overflow: hidden; /* Changed from auto to remove scrollbar */
256 height: auto; /* Changed to auto to autogrow */
256 height: auto; /* Changed to auto to autogrow */
257 line-height: 1.231; /* Changed from 1em to our global default */
257 line-height: 1.231; /* Changed from 1em to our global default */
258 }
258 }
259
259
260 /* CSS font colors for translated ANSI colors. */
260 /* CSS font colors for translated ANSI colors. */
261
261
262
262
263 .ansiblack {color: black;}
263 .ansiblack {color: black;}
264 .ansired {color: darkred;}
264 .ansired {color: darkred;}
265 .ansigreen {color: darkgreen;}
265 .ansigreen {color: darkgreen;}
266 .ansiyellow {color: brown;}
266 .ansiyellow {color: brown;}
267 .ansiblue {color: darkblue;}
267 .ansiblue {color: darkblue;}
268 .ansipurple {color: darkviolet;}
268 .ansipurple {color: darkviolet;}
269 .ansicyan {color: steelblue;}
269 .ansicyan {color: steelblue;}
270 .ansigrey {color: grey;}
270 .ansigrey {color: grey;}
271 .ansibold {font-weight: bold;}
271 .ansibold {font-weight: bold;}
272
272
273 .completions {
273 .completions {
274 position: absolute;
274 position: absolute;
275 z-index: 10;
275 z-index: 10;
276 overflow: auto;
276 overflow: auto;
277 border: 1px solid black;
277 border: 1px solid black;
278 }
278 }
279
279
280 .completions select {
280 .completions select {
281 background: white;
281 background: white;
282 outline: none;
282 outline: none;
283 border: none;
283 border: none;
284 padding: 0px;
284 padding: 0px;
285 margin: 0px;
285 margin: 0px;
286 font-family: monospace;
286 font-family: monospace;
287 }
287 }
288
288
@@ -1,152 +1,153 b''
1
1
2 //============================================================================
2 //============================================================================
3 // TextCell
3 // HTMLCell
4 //============================================================================
4 //============================================================================
5
5
6 var IPython = (function (IPython) {
6 var IPython = (function (IPython) {
7
7
8 var TextCell = function (notebook) {
8 var HTMLCell = function (notebook) {
9 IPython.Cell.apply(this, arguments);
9 IPython.Cell.apply(this, arguments);
10 this.placeholder = "Type <strong>HTML</strong> and LaTeX: $\\alpha^2$"
10 this.placeholder = "Type <strong>HTML</strong> and LaTeX: $\\alpha^2$"
11 this.rendered = false;
11 this.rendered = false;
12 };
12 };
13
13
14
14
15 TextCell.prototype = new IPython.Cell();
15 HTMLCell.prototype = new IPython.Cell();
16
16
17
17
18 TextCell.prototype.create_element = function () {
18
19 var cell = $("<div>").addClass('cell text_cell border-box-sizing').
19 HTMLCell.prototype.create_element = function () {
20 append(
20 var cell = $("<div>").addClass('cell html_cell border-box-sizing');
21 $("<textarea>" + this.placeholder + "</textarea>").
21 var input_area = $('<div/>').addClass('html_cell_input');
22 addClass('text_cell_input').
22 this.code_mirror = CodeMirror(input_area.get(0), {
23 attr('rows',1).
23 indentUnit : 4,
24 attr('cols',80).
24 enterMode : 'flat',
25 autogrow()
25 tabMode: 'shift',
26 ).append(
26 value: this.placeholder
27 // The tabindex=-1 makes this div focusable.
27 });
28 $('<div></div>').addClass('text_cell_render').attr('tabindex','-1')
28 // The tabindex=-1 makes this div focusable.
29 )
29 var render_area = $('<div/>').addClass('html_cell_render').attr('tabindex','-1');
30 cell.append(input_area).append(render_area);
30 this.element = cell;
31 this.element = cell;
31 };
32 };
32
33
33
34
34 TextCell.prototype.bind_events = function () {
35 HTMLCell.prototype.bind_events = function () {
35 IPython.Cell.prototype.bind_events.apply(this);
36 IPython.Cell.prototype.bind_events.apply(this);
36 var that = this;
37 var that = this;
37 this.element.keydown(function (event) {
38 this.element.keydown(function (event) {
38 if (event.which === 13) {
39 if (event.which === 13) {
39 if (that.rendered) {
40 if (that.rendered) {
40 that.edit();
41 that.edit();
41 event.preventDefault();
42 event.preventDefault();
42 };
43 };
43 };
44 };
44 });
45 });
45 };
46 };
46
47
47
48
48 TextCell.prototype.select = function () {
49 HTMLCell.prototype.select = function () {
49 IPython.Cell.prototype.select.apply(this);
50 IPython.Cell.prototype.select.apply(this);
50 var output = this.element.find("div.text_cell_render");
51 var output = this.element.find("div.html_cell_render");
51 output.trigger('focus');
52 output.trigger('focus');
52 };
53 };
53
54
54
55
55 TextCell.prototype.edit = function () {
56 HTMLCell.prototype.edit = function () {
56 if (this.rendered === true) {
57 if (this.rendered === true) {
57 var text_cell = this.element;
58 var html_cell = this.element;
58 var input = text_cell.find("textarea.text_cell_input");
59 var output = html_cell.find("div.html_cell_render");
59 var output = text_cell.find("div.text_cell_render");
60 output.hide();
60 output.hide();
61 input.show().trigger('focus');
61 html_cell.find('div.html_cell_input').show();
62 this.code_mirror.focus();
63 this.code_mirror.refresh();
62 this.rendered = false;
64 this.rendered = false;
63 };
65 };
64 };
66 };
65
67
66
68
67 TextCell.prototype.render = function () {
69 HTMLCell.prototype.render = function () {
68 if (this.rendered === false) {
70 if (this.rendered === false) {
69 var text_cell = this.element;
71 var html_cell = this.element;
70 var input = text_cell.find("textarea.text_cell_input");
72 var output = html_cell.find("div.html_cell_render");
71 var output = text_cell.find("div.text_cell_render");
73 var text = this.get_source();
72 var text = input.val();
74 if (text === "") {text = this.placeholder;};
73 if (text === "") {
75 this.set_render(text);
74 text = this.placeholder;
75 input.val(text);
76 };
77 output.html(text)
78 input.html(text);
79 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
76 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
80 input.hide();
77 html_cell.find('div.html_cell_input').hide();
81 output.show();
78 output.show();
82 this.rendered = true;
79 this.rendered = true;
83 };
80 };
84 };
81 };
85
82
86
83
87 TextCell.prototype.config_mathjax = function () {
84 HTMLCell.prototype.config_mathjax = function () {
88 var text_cell = this.element;
85 var html_cell = this.element;
89 var that = this;
86 var that = this;
90 text_cell.click(function () {
87 html_cell.click(function () {
91 that.edit();
88 that.edit();
92 }).focusout(function () {
89 }).focusout(function () {
93 that.render();
90 that.render();
94 });
91 });
95
92
96 text_cell.trigger("focusout");
93 html_cell.trigger("focusout");
94 };
95
96
97 HTMLCell.prototype.get_source = function() {
98 return this.code_mirror.getValue();
97 };
99 };
98
100
99
101
100 TextCell.prototype.get_text = function() {
102 HTMLCell.prototype.set_source = function(text) {
101 return this.element.find("textarea.text_cell_input").val();
103 this.code_mirror.setValue(text);
104 this.code_mirror.refresh();
102 };
105 };
103
106
104
107
105 TextCell.prototype.set_text = function(text) {
108 HTMLCell.prototype.set_render = function(text) {
106 this.element.find("textarea.text_cell_input").val(text);
109 this.element.find('div.html_cell_render').html(text);
107 this.element.find("textarea.text_cell_input").html(text);
108 this.element.find("div.text_cell_render").html(text);
109 };
110 };
110
111
111
112
112 TextCell.prototype.at_top = function () {
113 HTMLCell.prototype.at_top = function () {
113 if (this.rendered) {
114 if (this.rendered) {
114 return true;
115 return true;
115 } else {
116 } else {
116 return false;
117 return false;
117 }
118 }
118 };
119 };
119
120
120
121
121 TextCell.prototype.at_bottom = function () {
122 HTMLCell.prototype.at_bottom = function () {
122 if (this.rendered) {
123 if (this.rendered) {
123 return true;
124 return true;
124 } else {
125 } else {
125 return false;
126 return false;
126 }
127 }
127 };
128 };
128
129
129
130
130 TextCell.prototype.fromJSON = function (data) {
131 HTMLCell.prototype.fromJSON = function (data) {
131 if (data.cell_type === 'text') {
132 if (data.cell_type === 'html') {
132 if (data.text !== undefined) {
133 if (data.source !== undefined) {
133 this.set_text(data.text);
134 this.set_source(data.source);
134 this.grow(this.element.find("textarea.text_cell_input"));
135 this.set_render(data.source);
135 };
136 };
136 };
137 };
137 }
138 }
138
139
139
140
140 TextCell.prototype.toJSON = function () {
141 HTMLCell.prototype.toJSON = function () {
141 var data = {}
142 var data = {}
142 data.cell_type = 'text';
143 data.cell_type = 'html';
143 data.text = this.get_text();
144 data.source = this.get_source();
144 return data;
145 return data;
145 };
146 };
146
147
147 IPython.TextCell = TextCell;
148 IPython.HTMLCell = HTMLCell;
148
149
149 return IPython;
150 return IPython;
150
151
151 }(IPython));
152 }(IPython));
152
153
@@ -1,658 +1,659 b''
1
1
2 //============================================================================
2 //============================================================================
3 // Notebook
3 // Notebook
4 //============================================================================
4 //============================================================================
5
5
6 var IPython = (function (IPython) {
6 var IPython = (function (IPython) {
7
7
8 var utils = IPython.utils;
8 var utils = IPython.utils;
9
9
10 var Notebook = function (selector) {
10 var Notebook = function (selector) {
11 this.element = $(selector);
11 this.element = $(selector);
12 this.element.scroll();
12 this.element.scroll();
13 this.element.data("notebook", this);
13 this.element.data("notebook", this);
14 this.next_prompt_number = 1;
14 this.next_prompt_number = 1;
15 this.kernel = null;
15 this.kernel = null;
16 this.msg_cell_map = {};
16 this.msg_cell_map = {};
17 this.style();
17 this.style();
18 this.create_elements();
18 this.create_elements();
19 this.bind_events();
19 this.bind_events();
20 };
20 };
21
21
22
22
23 Notebook.prototype.style = function () {
23 Notebook.prototype.style = function () {
24 $('div#notebook').addClass('border-box-sizing');
24 $('div#notebook').addClass('border-box-sizing');
25 };
25 };
26
26
27
27
28 Notebook.prototype.create_elements = function () {
28 Notebook.prototype.create_elements = function () {
29 // We add this end_space div to the end of the notebook div to:
29 // We add this end_space div to the end of the notebook div to:
30 // i) provide a margin between the last cell and the end of the notebook
30 // i) provide a margin between the last cell and the end of the notebook
31 // ii) to prevent the div from scrolling up when the last cell is being
31 // ii) to prevent the div from scrolling up when the last cell is being
32 // edited, but is too low on the page, which browsers will do automatically.
32 // edited, but is too low on the page, which browsers will do automatically.
33 this.element.append($('<div class="end_space"></div>').height(50));
33 this.element.append($('<div class="end_space"></div>').height(50));
34 $('div#notebook').addClass('border-box-sizing');
34 $('div#notebook').addClass('border-box-sizing');
35 };
35 };
36
36
37
37
38 Notebook.prototype.bind_events = function () {
38 Notebook.prototype.bind_events = function () {
39 var that = this;
39 var that = this;
40 $(document).keydown(function (event) {
40 $(document).keydown(function (event) {
41 // console.log(event);
41 // console.log(event);
42 if (event.which === 38) {
42 if (event.which === 38) {
43 var cell = that.selected_cell();
43 var cell = that.selected_cell();
44 if (cell.at_top()) {
44 if (cell.at_top()) {
45 event.preventDefault();
45 event.preventDefault();
46 that.select_prev();
46 that.select_prev();
47 };
47 };
48 } else if (event.which === 40) {
48 } else if (event.which === 40) {
49 var cell = that.selected_cell();
49 var cell = that.selected_cell();
50 if (cell.at_bottom()) {
50 if (cell.at_bottom()) {
51 event.preventDefault();
51 event.preventDefault();
52 that.select_next();
52 that.select_next();
53 };
53 };
54 } else if (event.which === 13 && event.shiftKey) {
54 } else if (event.which === 13 && event.shiftKey) {
55 that.execute_selected_cell();
55 that.execute_selected_cell();
56 return false;
56 return false;
57 } else if (event.which === 13 && event.ctrlKey) {
57 } else if (event.which === 13 && event.ctrlKey) {
58 that.execute_selected_cell({terminal:true});
58 that.execute_selected_cell({terminal:true});
59 return false;
59 return false;
60 };
60 };
61 });
61 });
62
62
63 this.element.bind('collapse_pager', function () {
63 this.element.bind('collapse_pager', function () {
64 var app_height = $('div#main_app').height(); // content height
64 var app_height = $('div#main_app').height(); // content height
65 var splitter_height = $('div#pager_splitter').outerHeight(true);
65 var splitter_height = $('div#pager_splitter').outerHeight(true);
66 var new_height = app_height - splitter_height;
66 var new_height = app_height - splitter_height;
67 that.element.animate({height : new_height + 'px'}, 'fast');
67 that.element.animate({height : new_height + 'px'}, 'fast');
68 });
68 });
69
69
70 this.element.bind('expand_pager', function () {
70 this.element.bind('expand_pager', function () {
71 var app_height = $('div#main_app').height(); // content height
71 var app_height = $('div#main_app').height(); // content height
72 var splitter_height = $('div#pager_splitter').outerHeight(true);
72 var splitter_height = $('div#pager_splitter').outerHeight(true);
73 var pager_height = $('div#pager').outerHeight(true);
73 var pager_height = $('div#pager').outerHeight(true);
74 var new_height = app_height - pager_height - splitter_height;
74 var new_height = app_height - pager_height - splitter_height;
75 that.element.animate({height : new_height + 'px'}, 'fast');
75 that.element.animate({height : new_height + 'px'}, 'fast');
76 });
76 });
77
77
78 this.element.bind('collapse_left_panel', function () {
78 this.element.bind('collapse_left_panel', function () {
79 var splitter_width = $('div#left_panel_splitter').outerWidth(true);
79 var splitter_width = $('div#left_panel_splitter').outerWidth(true);
80 var new_margin = splitter_width;
80 var new_margin = splitter_width;
81 $('div#notebook_panel').animate({marginLeft : new_margin + 'px'}, 'fast');
81 $('div#notebook_panel').animate({marginLeft : new_margin + 'px'}, 'fast');
82 });
82 });
83
83
84 this.element.bind('expand_left_panel', function () {
84 this.element.bind('expand_left_panel', function () {
85 var splitter_width = $('div#left_panel_splitter').outerWidth(true);
85 var splitter_width = $('div#left_panel_splitter').outerWidth(true);
86 var left_panel_width = IPython.left_panel.width;
86 var left_panel_width = IPython.left_panel.width;
87 var new_margin = splitter_width + left_panel_width;
87 var new_margin = splitter_width + left_panel_width;
88 $('div#notebook_panel').animate({marginLeft : new_margin + 'px'}, 'fast');
88 $('div#notebook_panel').animate({marginLeft : new_margin + 'px'}, 'fast');
89 });
89 });
90 };
90 };
91
91
92
92
93 Notebook.prototype.scroll_to_bottom = function () {
93 Notebook.prototype.scroll_to_bottom = function () {
94 this.element.animate({scrollTop:this.element.get(0).scrollHeight}, 0);
94 this.element.animate({scrollTop:this.element.get(0).scrollHeight}, 0);
95 };
95 };
96
96
97
97
98 Notebook.prototype.scroll_to_top = function () {
98 Notebook.prototype.scroll_to_top = function () {
99 this.element.animate({scrollTop:0}, 0);
99 this.element.animate({scrollTop:0}, 0);
100 };
100 };
101
101
102
102
103 // Cell indexing, retrieval, etc.
103 // Cell indexing, retrieval, etc.
104
104
105
105
106 Notebook.prototype.cell_elements = function () {
106 Notebook.prototype.cell_elements = function () {
107 return this.element.children("div.cell");
107 return this.element.children("div.cell");
108 }
108 }
109
109
110
110
111 Notebook.prototype.ncells = function (cell) {
111 Notebook.prototype.ncells = function (cell) {
112 return this.cell_elements().length;
112 return this.cell_elements().length;
113 }
113 }
114
114
115
115
116 // TODO: we are often calling cells as cells()[i], which we should optimize
116 // TODO: we are often calling cells as cells()[i], which we should optimize
117 // to cells(i) or a new method.
117 // to cells(i) or a new method.
118 Notebook.prototype.cells = function () {
118 Notebook.prototype.cells = function () {
119 return this.cell_elements().toArray().map(function (e) {
119 return this.cell_elements().toArray().map(function (e) {
120 return $(e).data("cell");
120 return $(e).data("cell");
121 });
121 });
122 }
122 }
123
123
124
124
125 Notebook.prototype.find_cell_index = function (cell) {
125 Notebook.prototype.find_cell_index = function (cell) {
126 var result = null;
126 var result = null;
127 this.cell_elements().filter(function (index) {
127 this.cell_elements().filter(function (index) {
128 if ($(this).data("cell") === cell) {
128 if ($(this).data("cell") === cell) {
129 result = index;
129 result = index;
130 };
130 };
131 });
131 });
132 return result;
132 return result;
133 };
133 };
134
134
135
135
136 Notebook.prototype.index_or_selected = function (index) {
136 Notebook.prototype.index_or_selected = function (index) {
137 return index || this.selected_index() || 0;
137 return index || this.selected_index() || 0;
138 }
138 }
139
139
140
140
141 Notebook.prototype.select = function (index) {
141 Notebook.prototype.select = function (index) {
142 if (index !== undefined && index >= 0 && index < this.ncells()) {
142 if (index !== undefined && index >= 0 && index < this.ncells()) {
143 if (this.selected_index() !== null) {
143 if (this.selected_index() !== null) {
144 this.selected_cell().unselect();
144 this.selected_cell().unselect();
145 };
145 };
146 this.cells()[index].select();
146 this.cells()[index].select();
147 if (index === (this.ncells()-1)) {
147 if (index === (this.ncells()-1)) {
148 this.scroll_to_bottom();
148 this.scroll_to_bottom();
149 };
149 };
150 };
150 };
151 return this;
151 return this;
152 };
152 };
153
153
154
154
155 Notebook.prototype.select_next = function () {
155 Notebook.prototype.select_next = function () {
156 var index = this.selected_index();
156 var index = this.selected_index();
157 if (index !== null && index >= 0 && (index+1) < this.ncells()) {
157 if (index !== null && index >= 0 && (index+1) < this.ncells()) {
158 this.select(index+1);
158 this.select(index+1);
159 };
159 };
160 return this;
160 return this;
161 };
161 };
162
162
163
163
164 Notebook.prototype.select_prev = function () {
164 Notebook.prototype.select_prev = function () {
165 var index = this.selected_index();
165 var index = this.selected_index();
166 if (index !== null && index >= 0 && (index-1) < this.ncells()) {
166 if (index !== null && index >= 0 && (index-1) < this.ncells()) {
167 this.select(index-1);
167 this.select(index-1);
168 };
168 };
169 return this;
169 return this;
170 };
170 };
171
171
172
172
173 Notebook.prototype.selected_index = function () {
173 Notebook.prototype.selected_index = function () {
174 var result = null;
174 var result = null;
175 this.cell_elements().filter(function (index) {
175 this.cell_elements().filter(function (index) {
176 if ($(this).data("cell").selected === true) {
176 if ($(this).data("cell").selected === true) {
177 result = index;
177 result = index;
178 };
178 };
179 });
179 });
180 return result;
180 return result;
181 };
181 };
182
182
183
183
184 Notebook.prototype.cell_for_msg = function (msg_id) {
184 Notebook.prototype.cell_for_msg = function (msg_id) {
185 var cell_id = this.msg_cell_map[msg_id];
185 var cell_id = this.msg_cell_map[msg_id];
186 var result = null;
186 var result = null;
187 this.cell_elements().filter(function (index) {
187 this.cell_elements().filter(function (index) {
188 cell = $(this).data("cell");
188 cell = $(this).data("cell");
189 if (cell.cell_id === cell_id) {
189 if (cell.cell_id === cell_id) {
190 result = cell;
190 result = cell;
191 };
191 };
192 });
192 });
193 return result;
193 return result;
194 };
194 };
195
195
196
196
197 Notebook.prototype.selected_cell = function () {
197 Notebook.prototype.selected_cell = function () {
198 return this.cell_elements().eq(this.selected_index()).data("cell");
198 return this.cell_elements().eq(this.selected_index()).data("cell");
199 }
199 }
200
200
201
201
202 // Cell insertion, deletion and moving.
202 // Cell insertion, deletion and moving.
203
203
204
204
205 Notebook.prototype.delete_cell = function (index) {
205 Notebook.prototype.delete_cell = function (index) {
206 var i = index || this.selected_index();
206 var i = index || this.selected_index();
207 if (i !== null && i >= 0 && i < this.ncells()) {
207 if (i !== null && i >= 0 && i < this.ncells()) {
208 this.cell_elements().eq(i).remove();
208 this.cell_elements().eq(i).remove();
209 if (i === (this.ncells())) {
209 if (i === (this.ncells())) {
210 this.select(i-1);
210 this.select(i-1);
211 } else {
211 } else {
212 this.select(i);
212 this.select(i);
213 };
213 };
214 };
214 };
215 return this;
215 return this;
216 };
216 };
217
217
218
218
219 Notebook.prototype.append_cell = function (cell) {
219 Notebook.prototype.append_cell = function (cell) {
220 this.element.find('div.end_space').before(cell.element);
220 this.element.find('div.end_space').before(cell.element);
221 return this;
221 return this;
222 };
222 };
223
223
224
224
225 Notebook.prototype.insert_cell_after = function (cell, index) {
225 Notebook.prototype.insert_cell_after = function (cell, index) {
226 var ncells = this.ncells();
226 var ncells = this.ncells();
227 if (ncells === 0) {
227 if (ncells === 0) {
228 this.append_cell(cell);
228 this.append_cell(cell);
229 return this;
229 return this;
230 };
230 };
231 if (index >= 0 && index < ncells) {
231 if (index >= 0 && index < ncells) {
232 this.cell_elements().eq(index).after(cell.element);
232 this.cell_elements().eq(index).after(cell.element);
233 };
233 };
234 return this
234 return this
235 };
235 };
236
236
237
237
238 Notebook.prototype.insert_cell_before = function (cell, index) {
238 Notebook.prototype.insert_cell_before = function (cell, index) {
239 var ncells = this.ncells();
239 var ncells = this.ncells();
240 if (ncells === 0) {
240 if (ncells === 0) {
241 this.append_cell(cell);
241 this.append_cell(cell);
242 return this;
242 return this;
243 };
243 };
244 if (index >= 0 && index < ncells) {
244 if (index >= 0 && index < ncells) {
245 this.cell_elements().eq(index).before(cell.element);
245 this.cell_elements().eq(index).before(cell.element);
246 };
246 };
247 return this;
247 return this;
248 };
248 };
249
249
250
250
251 Notebook.prototype.move_cell_up = function (index) {
251 Notebook.prototype.move_cell_up = function (index) {
252 var i = index || this.selected_index();
252 var i = index || this.selected_index();
253 if (i !== null && i < this.ncells() && i > 0) {
253 if (i !== null && i < this.ncells() && i > 0) {
254 var pivot = this.cell_elements().eq(i-1);
254 var pivot = this.cell_elements().eq(i-1);
255 var tomove = this.cell_elements().eq(i);
255 var tomove = this.cell_elements().eq(i);
256 if (pivot !== null && tomove !== null) {
256 if (pivot !== null && tomove !== null) {
257 tomove.detach();
257 tomove.detach();
258 pivot.before(tomove);
258 pivot.before(tomove);
259 this.select(i-1);
259 this.select(i-1);
260 };
260 };
261 };
261 };
262 return this;
262 return this;
263 }
263 }
264
264
265
265
266 Notebook.prototype.move_cell_down = function (index) {
266 Notebook.prototype.move_cell_down = function (index) {
267 var i = index || this.selected_index();
267 var i = index || this.selected_index();
268 if (i !== null && i < (this.ncells()-1) && i >= 0) {
268 if (i !== null && i < (this.ncells()-1) && i >= 0) {
269 var pivot = this.cell_elements().eq(i+1)
269 var pivot = this.cell_elements().eq(i+1)
270 var tomove = this.cell_elements().eq(i)
270 var tomove = this.cell_elements().eq(i)
271 if (pivot !== null && tomove !== null) {
271 if (pivot !== null && tomove !== null) {
272 tomove.detach();
272 tomove.detach();
273 pivot.after(tomove);
273 pivot.after(tomove);
274 this.select(i+1);
274 this.select(i+1);
275 };
275 };
276 };
276 };
277 return this;
277 return this;
278 }
278 }
279
279
280
280
281 Notebook.prototype.sort_cells = function () {
281 Notebook.prototype.sort_cells = function () {
282 var ncells = this.ncells();
282 var ncells = this.ncells();
283 var sindex = this.selected_index();
283 var sindex = this.selected_index();
284 var swapped;
284 var swapped;
285 do {
285 do {
286 swapped = false
286 swapped = false
287 for (var i=1; i<ncells; i++) {
287 for (var i=1; i<ncells; i++) {
288 current = this.cell_elements().eq(i).data("cell");
288 current = this.cell_elements().eq(i).data("cell");
289 previous = this.cell_elements().eq(i-1).data("cell");
289 previous = this.cell_elements().eq(i-1).data("cell");
290 if (previous.input_prompt_number > current.input_prompt_number) {
290 if (previous.input_prompt_number > current.input_prompt_number) {
291 this.move_cell_up(i);
291 this.move_cell_up(i);
292 swapped = true;
292 swapped = true;
293 };
293 };
294 };
294 };
295 } while (swapped);
295 } while (swapped);
296 this.select(sindex);
296 this.select(sindex);
297 return this;
297 return this;
298 };
298 };
299
299
300
300
301 Notebook.prototype.insert_code_cell_before = function (index) {
301 Notebook.prototype.insert_code_cell_before = function (index) {
302 // TODO: Bounds check for i
302 // TODO: Bounds check for i
303 var i = this.index_or_selected(index);
303 var i = this.index_or_selected(index);
304 var cell = new IPython.CodeCell(this);
304 var cell = new IPython.CodeCell(this);
305 cell.set_input_prompt();
305 cell.set_input_prompt();
306 this.insert_cell_before(cell, i);
306 this.insert_cell_before(cell, i);
307 this.select(this.find_cell_index(cell));
307 this.select(this.find_cell_index(cell));
308 return cell;
308 return cell;
309 }
309 }
310
310
311
311
312 Notebook.prototype.insert_code_cell_after = function (index) {
312 Notebook.prototype.insert_code_cell_after = function (index) {
313 // TODO: Bounds check for i
313 // TODO: Bounds check for i
314 var i = this.index_or_selected(index);
314 var i = this.index_or_selected(index);
315 var cell = new IPython.CodeCell(this);
315 var cell = new IPython.CodeCell(this);
316 cell.set_input_prompt();
316 cell.set_input_prompt();
317 this.insert_cell_after(cell, i);
317 this.insert_cell_after(cell, i);
318 this.select(this.find_cell_index(cell));
318 this.select(this.find_cell_index(cell));
319 return cell;
319 return cell;
320 }
320 }
321
321
322
322
323 Notebook.prototype.insert_text_cell_before = function (index) {
323 Notebook.prototype.insert_html_cell_before = function (index) {
324 // TODO: Bounds check for i
324 // TODO: Bounds check for i
325 var i = this.index_or_selected(index);
325 var i = this.index_or_selected(index);
326 var cell = new IPython.TextCell(this);
326 var cell = new IPython.HTMLCell(this);
327 cell.config_mathjax();
327 cell.config_mathjax();
328 this.insert_cell_before(cell, i);
328 this.insert_cell_before(cell, i);
329 this.select(this.find_cell_index(cell));
329 this.select(this.find_cell_index(cell));
330 return cell;
330 return cell;
331 }
331 }
332
332
333
333
334 Notebook.prototype.insert_text_cell_after = function (index) {
334 Notebook.prototype.insert_html_cell_after = function (index) {
335 // TODO: Bounds check for i
335 // TODO: Bounds check for i
336 var i = this.index_or_selected(index);
336 var i = this.index_or_selected(index);
337 var cell = new IPython.TextCell(this);
337 var cell = new IPython.HTMLCell(this);
338 cell.config_mathjax();
338 cell.config_mathjax();
339 this.insert_cell_after(cell, i);
339 this.insert_cell_after(cell, i);
340 this.select(this.find_cell_index(cell));
340 this.select(this.find_cell_index(cell));
341 return cell;
341 return cell;
342 }
342 }
343
343
344
344
345 Notebook.prototype.text_to_code = function (index) {
345 Notebook.prototype.html_to_code = function (index) {
346 // TODO: Bounds check for i
346 // TODO: Bounds check for i
347 var i = this.index_or_selected(index);
347 var i = this.index_or_selected(index);
348 var source_element = this.cell_elements().eq(i);
348 var source_element = this.cell_elements().eq(i);
349 var source_cell = source_element.data("cell");
349 var source_cell = source_element.data("cell");
350 if (source_cell instanceof IPython.TextCell) {
350 if (source_cell instanceof IPython.HTMLCell) {
351 this.insert_code_cell_after(i);
351 this.insert_code_cell_after(i);
352 var target_cell = this.cells()[i+1];
352 var target_cell = this.cells()[i+1];
353 target_cell.set_code(source_cell.get_text());
353 target_cell.set_code(source_cell.get_source());
354 source_element.remove();
354 source_element.remove();
355 };
355 };
356 };
356 };
357
357
358
358
359 Notebook.prototype.code_to_text = function (index) {
359 Notebook.prototype.code_to_html = function (index) {
360 // TODO: Bounds check for i
360 // TODO: Bounds check for i
361 var i = this.index_or_selected(index);
361 var i = this.index_or_selected(index);
362 var source_element = this.cell_elements().eq(i);
362 var source_element = this.cell_elements().eq(i);
363 var source_cell = source_element.data("cell");
363 var source_cell = source_element.data("cell");
364 if (source_cell instanceof IPython.CodeCell) {
364 if (source_cell instanceof IPython.CodeCell) {
365 this.insert_text_cell_after(i);
365 this.insert_html_cell_after(i);
366 var target_cell = this.cells()[i+1];
366 var target_cell = this.cells()[i+1];
367 var text = source_cell.get_code();
367 var text = source_cell.get_code();
368 if (text === "") {text = target_cell.placeholder;};
368 if (text === "") {text = target_cell.placeholder;};
369 target_cell.set_text(text);
369 target_cell.set_source(text);
370 target_cell.set_render(text);
370 source_element.remove();
371 source_element.remove();
371 target_cell.edit();
372 target_cell.edit();
372 };
373 };
373 };
374 };
374
375
375
376
376 // Cell collapsing
377 // Cell collapsing
377
378
378 Notebook.prototype.collapse = function (index) {
379 Notebook.prototype.collapse = function (index) {
379 var i = this.index_or_selected(index);
380 var i = this.index_or_selected(index);
380 this.cells()[i].collapse();
381 this.cells()[i].collapse();
381 };
382 };
382
383
383
384
384 Notebook.prototype.expand = function (index) {
385 Notebook.prototype.expand = function (index) {
385 var i = this.index_or_selected(index);
386 var i = this.index_or_selected(index);
386 this.cells()[i].expand();
387 this.cells()[i].expand();
387 };
388 };
388
389
389
390
390 // Kernel related things
391 // Kernel related things
391
392
392 Notebook.prototype.start_kernel = function () {
393 Notebook.prototype.start_kernel = function () {
393 this.kernel = new IPython.Kernel();
394 this.kernel = new IPython.Kernel();
394 var notebook_id = IPython.save_widget.get_notebook_id();
395 var notebook_id = IPython.save_widget.get_notebook_id();
395 this.kernel.start_kernel(notebook_id, $.proxy(this.kernel_started, this));
396 this.kernel.start_kernel(notebook_id, $.proxy(this.kernel_started, this));
396 };
397 };
397
398
398
399
399 Notebook.prototype.handle_shell_reply = function (e) {
400 Notebook.prototype.handle_shell_reply = function (e) {
400 reply = $.parseJSON(e.data);
401 reply = $.parseJSON(e.data);
401 var header = reply.header;
402 var header = reply.header;
402 var content = reply.content;
403 var content = reply.content;
403 var msg_type = header.msg_type;
404 var msg_type = header.msg_type;
404 // console.log(reply);
405 // console.log(reply);
405 var cell = this.cell_for_msg(reply.parent_header.msg_id);
406 var cell = this.cell_for_msg(reply.parent_header.msg_id);
406 if (msg_type === "execute_reply") {
407 if (msg_type === "execute_reply") {
407 cell.set_input_prompt(content.execution_count);
408 cell.set_input_prompt(content.execution_count);
408 } else if (msg_type === "complete_reply") {
409 } else if (msg_type === "complete_reply") {
409 cell.finish_completing(content.matched_text, content.matches);
410 cell.finish_completing(content.matched_text, content.matches);
410 };
411 };
411 var payload = content.payload || [];
412 var payload = content.payload || [];
412 this.handle_payload(payload);
413 this.handle_payload(payload);
413 };
414 };
414
415
415
416
416 Notebook.prototype.handle_payload = function (payload) {
417 Notebook.prototype.handle_payload = function (payload) {
417 var l = payload.length;
418 var l = payload.length;
418 if (l > 0) {
419 if (l > 0) {
419 IPython.pager.clear();
420 IPython.pager.clear();
420 IPython.pager.expand();
421 IPython.pager.expand();
421 };
422 };
422 for (var i=0; i<l; i++) {
423 for (var i=0; i<l; i++) {
423 IPython.pager.append_text(payload[i].text);
424 IPython.pager.append_text(payload[i].text);
424 };
425 };
425 };
426 };
426
427
427
428
428 Notebook.prototype.handle_iopub_reply = function (e) {
429 Notebook.prototype.handle_iopub_reply = function (e) {
429 reply = $.parseJSON(e.data);
430 reply = $.parseJSON(e.data);
430 var content = reply.content;
431 var content = reply.content;
431 // console.log(reply);
432 // console.log(reply);
432 var msg_type = reply.header.msg_type;
433 var msg_type = reply.header.msg_type;
433 var cell = this.cell_for_msg(reply.parent_header.msg_id);
434 var cell = this.cell_for_msg(reply.parent_header.msg_id);
434 var output_types = ['stream','display_data','pyout','pyerr'];
435 var output_types = ['stream','display_data','pyout','pyerr'];
435 if (output_types.indexOf(msg_type) >= 0) {
436 if (output_types.indexOf(msg_type) >= 0) {
436 this.handle_output(cell, msg_type, content);
437 this.handle_output(cell, msg_type, content);
437 } else if (msg_type === "status") {
438 } else if (msg_type === "status") {
438 if (content.execution_state === "busy") {
439 if (content.execution_state === "busy") {
439 IPython.kernel_status_widget.status_busy();
440 IPython.kernel_status_widget.status_busy();
440 } else if (content.execution_state === "idle") {
441 } else if (content.execution_state === "idle") {
441 IPython.kernel_status_widget.status_idle();
442 IPython.kernel_status_widget.status_idle();
442 };
443 };
443 }
444 }
444 };
445 };
445
446
446
447
447 Notebook.prototype.handle_output = function (cell, msg_type, content) {
448 Notebook.prototype.handle_output = function (cell, msg_type, content) {
448 var json = {};
449 var json = {};
449 json.output_type = msg_type;
450 json.output_type = msg_type;
450 if (msg_type === "stream") {
451 if (msg_type === "stream") {
451 json.text = content.data + '\n';
452 json.text = content.data + '\n';
452 } else if (msg_type === "display_data") {
453 } else if (msg_type === "display_data") {
453 json = this.convert_mime_types(json, content.data);
454 json = this.convert_mime_types(json, content.data);
454 } else if (msg_type === "pyout") {
455 } else if (msg_type === "pyout") {
455 json.prompt_number = content.execution_count;
456 json.prompt_number = content.execution_count;
456 json = this.convert_mime_types(json, content.data);
457 json = this.convert_mime_types(json, content.data);
457 } else if (msg_type === "pyerr") {
458 } else if (msg_type === "pyerr") {
458 json.ename = content.ename;
459 json.ename = content.ename;
459 json.evalue = content.evalue;
460 json.evalue = content.evalue;
460 json.traceback = content.traceback;
461 json.traceback = content.traceback;
461 };
462 };
462 cell.append_output(json);
463 cell.append_output(json);
463 };
464 };
464
465
465
466
466 Notebook.prototype.convert_mime_types = function (json, data) {
467 Notebook.prototype.convert_mime_types = function (json, data) {
467 if (data['text/plain'] !== undefined) {
468 if (data['text/plain'] !== undefined) {
468 json.text = data['text/plain'];
469 json.text = data['text/plain'];
469 };
470 };
470 if (data['text/html'] !== undefined) {
471 if (data['text/html'] !== undefined) {
471 json.html = data['text/html'];
472 json.html = data['text/html'];
472 };
473 };
473 if (data['image/svg+xml'] !== undefined) {
474 if (data['image/svg+xml'] !== undefined) {
474 json.svg = data['image/svg+xml'];
475 json.svg = data['image/svg+xml'];
475 };
476 };
476 if (data['image/png'] !== undefined) {
477 if (data['image/png'] !== undefined) {
477 json.png = data['image/png'];
478 json.png = data['image/png'];
478 };
479 };
479 if (data['text/latex'] !== undefined) {
480 if (data['text/latex'] !== undefined) {
480 json.latex = data['text/latex'];
481 json.latex = data['text/latex'];
481 };
482 };
482 if (data['application/json'] !== undefined) {
483 if (data['application/json'] !== undefined) {
483 json.json = data['application/json'];
484 json.json = data['application/json'];
484 };
485 };
485 if (data['application/javascript'] !== undefined) {
486 if (data['application/javascript'] !== undefined) {
486 json.javascript = data['application/javascript'];
487 json.javascript = data['application/javascript'];
487 }
488 }
488 return json;
489 return json;
489 };
490 };
490
491
491 Notebook.prototype.kernel_started = function () {
492 Notebook.prototype.kernel_started = function () {
492 console.log("Kernel started: ", this.kernel.kernel_id);
493 console.log("Kernel started: ", this.kernel.kernel_id);
493 this.kernel.shell_channel.onmessage = $.proxy(this.handle_shell_reply,this);
494 this.kernel.shell_channel.onmessage = $.proxy(this.handle_shell_reply,this);
494 this.kernel.iopub_channel.onmessage = $.proxy(this.handle_iopub_reply,this);
495 this.kernel.iopub_channel.onmessage = $.proxy(this.handle_iopub_reply,this);
495 };
496 };
496
497
497
498
498 Notebook.prototype.execute_selected_cell = function (options) {
499 Notebook.prototype.execute_selected_cell = function (options) {
499 // add_new: should a new cell be added if we are at the end of the nb
500 // add_new: should a new cell be added if we are at the end of the nb
500 // terminal: execute in terminal mode, which stays in the current cell
501 // terminal: execute in terminal mode, which stays in the current cell
501 default_options = {terminal: false, add_new: true}
502 default_options = {terminal: false, add_new: true}
502 $.extend(default_options, options)
503 $.extend(default_options, options)
503 var that = this;
504 var that = this;
504 var cell = that.selected_cell();
505 var cell = that.selected_cell();
505 var cell_index = that.find_cell_index(cell);
506 var cell_index = that.find_cell_index(cell);
506 if (cell instanceof IPython.CodeCell) {
507 if (cell instanceof IPython.CodeCell) {
507 cell.clear_output();
508 cell.clear_output();
508 var code = cell.get_code();
509 var code = cell.get_code();
509 var msg_id = that.kernel.execute(cell.get_code());
510 var msg_id = that.kernel.execute(cell.get_code());
510 that.msg_cell_map[msg_id] = cell.cell_id;
511 that.msg_cell_map[msg_id] = cell.cell_id;
511 } else if (cell instanceof IPython.TextCell) {
512 } else if (cell instanceof IPython.HTMLCell) {
512 cell.render();
513 cell.render();
513 }
514 }
514 if (default_options.terminal) {
515 if (default_options.terminal) {
515 cell.clear_input();
516 cell.clear_input();
516 } else {
517 } else {
517 if ((cell_index === (that.ncells()-1)) && default_options.add_new) {
518 if ((cell_index === (that.ncells()-1)) && default_options.add_new) {
518 that.insert_code_cell_after();
519 that.insert_code_cell_after();
519 // If we are adding a new cell at the end, scroll down to show it.
520 // If we are adding a new cell at the end, scroll down to show it.
520 that.scroll_to_bottom();
521 that.scroll_to_bottom();
521 } else {
522 } else {
522 that.select(cell_index+1);
523 that.select(cell_index+1);
523 };
524 };
524 };
525 };
525 };
526 };
526
527
527
528
528 Notebook.prototype.execute_all_cells = function () {
529 Notebook.prototype.execute_all_cells = function () {
529 var ncells = this.ncells();
530 var ncells = this.ncells();
530 for (var i=0; i<ncells; i++) {
531 for (var i=0; i<ncells; i++) {
531 this.select(i);
532 this.select(i);
532 this.execute_selected_cell({add_new:false});
533 this.execute_selected_cell({add_new:false});
533 };
534 };
534 this.scroll_to_bottom();
535 this.scroll_to_bottom();
535 };
536 };
536
537
537
538
538 Notebook.prototype.complete_cell = function (cell, line, cursor_pos) {
539 Notebook.prototype.complete_cell = function (cell, line, cursor_pos) {
539 var msg_id = this.kernel.complete(line, cursor_pos);
540 var msg_id = this.kernel.complete(line, cursor_pos);
540 this.msg_cell_map[msg_id] = cell.cell_id;
541 this.msg_cell_map[msg_id] = cell.cell_id;
541 };
542 };
542
543
543 // Persistance and loading
544 // Persistance and loading
544
545
545
546
546 Notebook.prototype.fromJSON = function (data) {
547 Notebook.prototype.fromJSON = function (data) {
547 var ncells = this.ncells();
548 var ncells = this.ncells();
548 for (var i=0; i<ncells; i++) {
549 for (var i=0; i<ncells; i++) {
549 // Always delete cell 0 as they get renumbered as they are deleted.
550 // Always delete cell 0 as they get renumbered as they are deleted.
550 this.delete_cell(0);
551 this.delete_cell(0);
551 };
552 };
552 // Only handle 1 worksheet for now.
553 // Only handle 1 worksheet for now.
553 var worksheet = data.worksheets[0];
554 var worksheet = data.worksheets[0];
554 if (worksheet !== undefined) {
555 if (worksheet !== undefined) {
555 var new_cells = worksheet.cells;
556 var new_cells = worksheet.cells;
556 ncells = new_cells.length;
557 ncells = new_cells.length;
557 var cell_data = null;
558 var cell_data = null;
558 var new_cell = null;
559 var new_cell = null;
559 for (var i=0; i<ncells; i++) {
560 for (var i=0; i<ncells; i++) {
560 cell_data = new_cells[i];
561 cell_data = new_cells[i];
561 if (cell_data.cell_type == 'code') {
562 if (cell_data.cell_type == 'code') {
562 new_cell = this.insert_code_cell_after();
563 new_cell = this.insert_code_cell_after();
563 new_cell.fromJSON(cell_data);
564 new_cell.fromJSON(cell_data);
564 } else if (cell_data.cell_type === 'text') {
565 } else if (cell_data.cell_type === 'html') {
565 new_cell = this.insert_text_cell_after();
566 new_cell = this.insert_html_cell_after();
566 new_cell.fromJSON(cell_data);
567 new_cell.fromJSON(cell_data);
567 };
568 };
568 };
569 };
569 };
570 };
570 };
571 };
571
572
572
573
573 Notebook.prototype.toJSON = function () {
574 Notebook.prototype.toJSON = function () {
574 var cells = this.cells();
575 var cells = this.cells();
575 var ncells = cells.length;
576 var ncells = cells.length;
576 cell_array = new Array(ncells);
577 cell_array = new Array(ncells);
577 for (var i=0; i<ncells; i++) {
578 for (var i=0; i<ncells; i++) {
578 cell_array[i] = cells[i].toJSON();
579 cell_array[i] = cells[i].toJSON();
579 };
580 };
580 data = {
581 data = {
581 // Only handle 1 worksheet for now.
582 // Only handle 1 worksheet for now.
582 worksheets : [{cells:cell_array}]
583 worksheets : [{cells:cell_array}]
583 }
584 }
584 return data
585 return data
585 };
586 };
586
587
587 Notebook.prototype.save_notebook = function () {
588 Notebook.prototype.save_notebook = function () {
588 if (IPython.save_widget.test_notebook_name()) {
589 if (IPython.save_widget.test_notebook_name()) {
589 var notebook_id = IPython.save_widget.get_notebook_id();
590 var notebook_id = IPython.save_widget.get_notebook_id();
590 var nbname = IPython.save_widget.get_notebook_name();
591 var nbname = IPython.save_widget.get_notebook_name();
591 // We may want to move the name/id/nbformat logic inside toJSON?
592 // We may want to move the name/id/nbformat logic inside toJSON?
592 var data = this.toJSON();
593 var data = this.toJSON();
593 data.name = nbname;
594 data.name = nbname;
594 data.nbformat = 2;
595 data.nbformat = 2;
595 data.id = notebook_id
596 data.id = notebook_id
596 // We do the call with settings so we can set cache to false.
597 // We do the call with settings so we can set cache to false.
597 var settings = {
598 var settings = {
598 processData : false,
599 processData : false,
599 cache : false,
600 cache : false,
600 type : "PUT",
601 type : "PUT",
601 data : JSON.stringify(data),
602 data : JSON.stringify(data),
602 headers : {'Content-Type': 'application/json'},
603 headers : {'Content-Type': 'application/json'},
603 success : $.proxy(this.notebook_saved,this)
604 success : $.proxy(this.notebook_saved,this)
604 };
605 };
605 IPython.save_widget.status_saving();
606 IPython.save_widget.status_saving();
606 $.ajax("/notebooks/" + notebook_id, settings);
607 $.ajax("/notebooks/" + notebook_id, settings);
607 };
608 };
608 };
609 };
609
610
610
611
611 Notebook.prototype.notebook_saved = function (data, status, xhr) {
612 Notebook.prototype.notebook_saved = function (data, status, xhr) {
612 IPython.save_widget.status_save();
613 IPython.save_widget.status_save();
613 }
614 }
614
615
615
616
616 Notebook.prototype.load_notebook = function (callback) {
617 Notebook.prototype.load_notebook = function (callback) {
617 var that = this;
618 var that = this;
618 var notebook_id = IPython.save_widget.get_notebook_id();
619 var notebook_id = IPython.save_widget.get_notebook_id();
619 // We do the call with settings so we can set cache to false.
620 // We do the call with settings so we can set cache to false.
620 var settings = {
621 var settings = {
621 processData : false,
622 processData : false,
622 cache : false,
623 cache : false,
623 type : "GET",
624 type : "GET",
624 dataType : "json",
625 dataType : "json",
625 success : function (data, status, xhr) {
626 success : function (data, status, xhr) {
626 that.notebook_loaded(data, status, xhr);
627 that.notebook_loaded(data, status, xhr);
627 if (callback !== undefined) {
628 if (callback !== undefined) {
628 callback();
629 callback();
629 };
630 };
630 }
631 }
631 };
632 };
632 IPython.save_widget.status_loading();
633 IPython.save_widget.status_loading();
633 $.ajax("/notebooks/" + notebook_id, settings);
634 $.ajax("/notebooks/" + notebook_id, settings);
634 }
635 }
635
636
636
637
637 Notebook.prototype.notebook_loaded = function (data, status, xhr) {
638 Notebook.prototype.notebook_loaded = function (data, status, xhr) {
638 this.fromJSON(data);
639 this.fromJSON(data);
639 if (this.ncells() === 0) {
640 if (this.ncells() === 0) {
640 this.insert_code_cell_after();
641 this.insert_code_cell_after();
641 };
642 };
642 IPython.save_widget.status_save();
643 IPython.save_widget.status_save();
643 IPython.save_widget.set_notebook_name(data.name);
644 IPython.save_widget.set_notebook_name(data.name);
644 this.start_kernel();
645 this.start_kernel();
645 // fromJSON always selects the last cell inserted. We need to wait
646 // fromJSON always selects the last cell inserted. We need to wait
646 // until that is done before scrolling to the top.
647 // until that is done before scrolling to the top.
647 setTimeout(function () {
648 setTimeout(function () {
648 IPython.notebook.select(0);
649 IPython.notebook.select(0);
649 IPython.notebook.scroll_to_top();
650 IPython.notebook.scroll_to_top();
650 }, 50);
651 }, 50);
651 };
652 };
652
653
653 IPython.Notebook = Notebook;
654 IPython.Notebook = Notebook;
654
655
655 return IPython;
656 return IPython;
656
657
657 }(IPython));
658 }(IPython));
658
659
@@ -1,235 +1,235 b''
1
1
2 //============================================================================
2 //============================================================================
3 // Cell
3 // Cell
4 //============================================================================
4 //============================================================================
5
5
6 var IPython = (function (IPython) {
6 var IPython = (function (IPython) {
7
7
8 var utils = IPython.utils;
8 var utils = IPython.utils;
9
9
10 // Base PanelSection class
10 // Base PanelSection class
11
11
12 var PanelSection = function (selector) {
12 var PanelSection = function (selector) {
13 this.selector = selector;
13 this.selector = selector;
14 if (this.selector !== undefined) {
14 if (this.selector !== undefined) {
15 this.element = $(selector);
15 this.element = $(selector);
16 this.header = this.element.find('h3.section_header');
16 this.header = this.element.find('h3.section_header');
17 this.content = this.element.find('div.section_content');
17 this.content = this.element.find('div.section_content');
18 this.style();
18 this.style();
19 this.bind_events();
19 this.bind_events();
20 }
20 }
21 this.expanded = true;
21 this.expanded = true;
22 };
22 };
23
23
24
24
25 PanelSection.prototype.style = function () {
25 PanelSection.prototype.style = function () {
26 this.header.addClass('ui-widget ui-state-default');
26 this.header.addClass('ui-widget ui-state-default');
27 this.content.addClass('ui-widget section_content');
27 this.content.addClass('ui-widget section_content');
28 };
28 };
29
29
30
30
31 PanelSection.prototype.bind_events = function () {
31 PanelSection.prototype.bind_events = function () {
32 var that = this;
32 var that = this;
33 this.header.click(function () {
33 this.header.click(function () {
34 that.toggle();
34 that.toggle();
35 });
35 });
36 this.header.hover(function () {
36 this.header.hover(function () {
37 that.header.toggleClass('ui-state-hover');
37 that.header.toggleClass('ui-state-hover');
38 });
38 });
39 };
39 };
40
40
41
41
42 PanelSection.prototype.expand = function () {
42 PanelSection.prototype.expand = function () {
43 if (!this.expanded) {
43 if (!this.expanded) {
44 this.content.slideDown('fast');
44 this.content.slideDown('fast');
45 this.expanded = true;
45 this.expanded = true;
46 };
46 };
47 };
47 };
48
48
49
49
50 PanelSection.prototype.collapse = function () {
50 PanelSection.prototype.collapse = function () {
51 if (this.expanded) {
51 if (this.expanded) {
52 this.content.slideUp('fast');
52 this.content.slideUp('fast');
53 this.expanded = false;
53 this.expanded = false;
54 };
54 };
55 };
55 };
56
56
57
57
58 PanelSection.prototype.toggle = function () {
58 PanelSection.prototype.toggle = function () {
59 if (this.expanded === true) {
59 if (this.expanded === true) {
60 this.collapse();
60 this.collapse();
61 } else {
61 } else {
62 this.expand();
62 this.expand();
63 };
63 };
64 };
64 };
65
65
66
66
67 PanelSection.prototype.create_children = function () {};
67 PanelSection.prototype.create_children = function () {};
68
68
69
69
70 // NotebookSection
70 // NotebookSection
71
71
72 var NotebookSection = function () {
72 var NotebookSection = function () {
73 PanelSection.apply(this, arguments);
73 PanelSection.apply(this, arguments);
74 };
74 };
75
75
76
76
77 NotebookSection.prototype = new PanelSection();
77 NotebookSection.prototype = new PanelSection();
78
78
79
79
80 NotebookSection.prototype.style = function () {
80 NotebookSection.prototype.style = function () {
81 PanelSection.prototype.style.apply(this);
81 PanelSection.prototype.style.apply(this);
82 this.content.addClass('ui-helper-clearfix');
82 this.content.addClass('ui-helper-clearfix');
83 this.content.find('div.section_row').addClass('ui-helper-clearfix');
83 this.content.find('div.section_row').addClass('ui-helper-clearfix');
84 this.content.find('#new_open').buttonset();
84 this.content.find('#new_open').buttonset();
85 this.content.find('#download_notebook').button();
85 this.content.find('#download_notebook').button();
86 this.content.find('#upload_notebook').button();
86 this.content.find('#upload_notebook').button();
87 this.content.find('#download_format').addClass('ui-widget ui-widget-content');
87 this.content.find('#download_format').addClass('ui-widget ui-widget-content');
88 this.content.find('#download_format option').addClass('ui-widget ui-widget-content');
88 this.content.find('#download_format option').addClass('ui-widget ui-widget-content');
89 };
89 };
90
90
91
91
92 NotebookSection.prototype.bind_events = function () {
92 NotebookSection.prototype.bind_events = function () {
93 PanelSection.prototype.bind_events.apply(this);
93 PanelSection.prototype.bind_events.apply(this);
94 var that = this;
94 var that = this;
95 this.content.find('#new_notebook').click(function () {
95 this.content.find('#new_notebook').click(function () {
96 window.open('/new');
96 window.open('/new');
97 });
97 });
98 this.content.find('#open_notebook').click(function () {
98 this.content.find('#open_notebook').click(function () {
99 window.open('/');
99 window.open('/');
100 });
100 });
101 this.content.find('#download_notebook').click(function () {
101 this.content.find('#download_notebook').click(function () {
102 var format = that.content.find('#download_format').val();
102 var format = that.content.find('#download_format').val();
103 var notebook_id = IPython.save_widget.get_notebook_id();
103 var notebook_id = IPython.save_widget.get_notebook_id();
104 var url = '/notebooks/' + notebook_id + '?format=' + format;
104 var url = '/notebooks/' + notebook_id + '?format=' + format;
105 window.open(url,'_newtab');
105 window.open(url,'_newtab');
106 });
106 });
107 };
107 };
108
108
109 // CellSection
109 // CellSection
110
110
111 var CellSection = function () {
111 var CellSection = function () {
112 PanelSection.apply(this, arguments);
112 PanelSection.apply(this, arguments);
113 };
113 };
114
114
115
115
116 CellSection.prototype = new PanelSection();
116 CellSection.prototype = new PanelSection();
117
117
118
118
119 CellSection.prototype.style = function () {
119 CellSection.prototype.style = function () {
120 PanelSection.prototype.style.apply(this);
120 PanelSection.prototype.style.apply(this);
121 this.content.addClass('ui-helper-clearfix');
121 this.content.addClass('ui-helper-clearfix');
122 this.content.find('div.section_row').addClass('ui-helper-clearfix');
122 this.content.find('div.section_row').addClass('ui-helper-clearfix');
123 this.content.find('#delete_cell').button();
123 this.content.find('#delete_cell').button();
124 this.content.find('#insert').buttonset();
124 this.content.find('#insert').buttonset();
125 this.content.find('#move').buttonset();
125 this.content.find('#move').buttonset();
126 this.content.find('#cell_type').buttonset();
126 this.content.find('#cell_type').buttonset();
127 this.content.find('#toggle_output').buttonset();
127 this.content.find('#toggle_output').buttonset();
128 this.content.find('#run_cells').buttonset();
128 this.content.find('#run_cells').buttonset();
129 };
129 };
130
130
131
131
132 CellSection.prototype.bind_events = function () {
132 CellSection.prototype.bind_events = function () {
133 PanelSection.prototype.bind_events.apply(this);
133 PanelSection.prototype.bind_events.apply(this);
134 this.content.find('#collapse_cell').click(function () {
134 this.content.find('#collapse_cell').click(function () {
135 IPython.notebook.collapse();
135 IPython.notebook.collapse();
136 });
136 });
137 this.content.find('#expand_cell').click(function () {
137 this.content.find('#expand_cell').click(function () {
138 IPython.notebook.expand();
138 IPython.notebook.expand();
139 });
139 });
140 this.content.find('#delete_cell').click(function () {
140 this.content.find('#delete_cell').click(function () {
141 IPython.notebook.delete_cell();
141 IPython.notebook.delete_cell();
142 });
142 });
143 this.content.find('#insert_cell_above').click(function () {
143 this.content.find('#insert_cell_above').click(function () {
144 IPython.notebook.insert_code_cell_before();
144 IPython.notebook.insert_code_cell_before();
145 });
145 });
146 this.content.find('#insert_cell_below').click(function () {
146 this.content.find('#insert_cell_below').click(function () {
147 IPython.notebook.insert_code_cell_after();
147 IPython.notebook.insert_code_cell_after();
148 });
148 });
149 this.content.find('#move_cell_up').click(function () {
149 this.content.find('#move_cell_up').click(function () {
150 IPython.notebook.move_cell_up();
150 IPython.notebook.move_cell_up();
151 });
151 });
152 this.content.find('#move_cell_down').click(function () {
152 this.content.find('#move_cell_down').click(function () {
153 IPython.notebook.move_cell_down();
153 IPython.notebook.move_cell_down();
154 });
154 });
155 this.content.find('#to_code').click(function () {
155 this.content.find('#to_code').click(function () {
156 IPython.notebook.text_to_code();
156 IPython.notebook.html_to_code();
157 });
157 });
158 this.content.find('#to_text').click(function () {
158 this.content.find('#to_html').click(function () {
159 IPython.notebook.code_to_text();
159 IPython.notebook.code_to_html();
160 });
160 });
161 this.content.find('#run_selected_cell').click(function () {
161 this.content.find('#run_selected_cell').click(function () {
162 IPython.notebook.execute_selected_cell();
162 IPython.notebook.execute_selected_cell();
163 });
163 });
164 this.content.find('#run_all_cells').click(function () {
164 this.content.find('#run_all_cells').click(function () {
165 IPython.notebook.execute_all_cells();
165 IPython.notebook.execute_all_cells();
166 });
166 });
167 };
167 };
168
168
169
169
170 // KernelSection
170 // KernelSection
171
171
172 var KernelSection = function () {
172 var KernelSection = function () {
173 PanelSection.apply(this, arguments);
173 PanelSection.apply(this, arguments);
174 };
174 };
175
175
176
176
177 KernelSection.prototype = new PanelSection();
177 KernelSection.prototype = new PanelSection();
178
178
179
179
180 KernelSection.prototype.style = function () {
180 KernelSection.prototype.style = function () {
181 PanelSection.prototype.style.apply(this);
181 PanelSection.prototype.style.apply(this);
182 this.content.addClass('ui-helper-clearfix');
182 this.content.addClass('ui-helper-clearfix');
183 this.content.find('div.section_row').addClass('ui-helper-clearfix');
183 this.content.find('div.section_row').addClass('ui-helper-clearfix');
184 this.content.find('#int_restart').buttonset();
184 this.content.find('#int_restart').buttonset();
185 };
185 };
186
186
187
187
188 KernelSection.prototype.bind_events = function () {
188 KernelSection.prototype.bind_events = function () {
189 PanelSection.prototype.bind_events.apply(this);
189 PanelSection.prototype.bind_events.apply(this);
190 this.content.find('#restart_kernel').click(function () {
190 this.content.find('#restart_kernel').click(function () {
191 IPython.notebook.kernel.restart();
191 IPython.notebook.kernel.restart();
192 });
192 });
193 this.content.find('#int_kernel').click(function () {
193 this.content.find('#int_kernel').click(function () {
194 IPython.notebook.kernel.interrupt();
194 IPython.notebook.kernel.interrupt();
195 });
195 });
196 };
196 };
197
197
198
198
199 // HelpSection
199 // HelpSection
200
200
201 var HelpSection = function () {
201 var HelpSection = function () {
202 PanelSection.apply(this, arguments);
202 PanelSection.apply(this, arguments);
203 };
203 };
204
204
205
205
206 HelpSection.prototype = new PanelSection();
206 HelpSection.prototype = new PanelSection();
207
207
208
208
209 HelpSection.prototype.style = function () {
209 HelpSection.prototype.style = function () {
210 PanelSection.prototype.style.apply(this);
210 PanelSection.prototype.style.apply(this);
211 PanelSection.prototype.style.apply(this);
211 PanelSection.prototype.style.apply(this);
212 this.content.addClass('ui-helper-clearfix');
212 this.content.addClass('ui-helper-clearfix');
213 this.content.find('div.section_row').addClass('ui-helper-clearfix');
213 this.content.find('div.section_row').addClass('ui-helper-clearfix');
214 this.content.find('#help_buttons0').buttonset();
214 this.content.find('#help_buttons0').buttonset();
215 this.content.find('#help_buttons1').buttonset();
215 this.content.find('#help_buttons1').buttonset();
216 };
216 };
217
217
218
218
219 HelpSection.prototype.bind_events = function () {
219 HelpSection.prototype.bind_events = function () {
220 PanelSection.prototype.bind_events.apply(this);
220 PanelSection.prototype.bind_events.apply(this);
221 };
221 };
222
222
223
223
224 // Set module variables
224 // Set module variables
225
225
226 IPython.PanelSection = PanelSection;
226 IPython.PanelSection = PanelSection;
227 IPython.NotebookSection = NotebookSection;
227 IPython.NotebookSection = NotebookSection;
228 IPython.CellSection = CellSection;
228 IPython.CellSection = CellSection;
229 IPython.KernelSection = KernelSection;
229 IPython.KernelSection = KernelSection;
230 IPython.HelpSection = HelpSection;
230 IPython.HelpSection = HelpSection;
231
231
232 return IPython;
232 return IPython;
233
233
234 }(IPython));
234 }(IPython));
235
235
@@ -1,194 +1,194 b''
1 <!DOCTYPE HTML>
1 <!DOCTYPE HTML>
2 <html>
2 <html>
3
3
4 <head>
4 <head>
5 <meta charset="utf-8">
5 <meta charset="utf-8">
6
6
7 <title>IPython Notebook</title>
7 <title>IPython Notebook</title>
8
8
9 <link rel="stylesheet" href="static/jquery/css/themes/aristo/jquery-wijmo.css" type="text/css" />
9 <link rel="stylesheet" href="static/jquery/css/themes/aristo/jquery-wijmo.css" type="text/css" />
10 <!-- <link rel="stylesheet" href="static/jquery/css/themes/rocket/jquery-wijmo.css" type="text/css" /> -->
10 <!-- <link rel="stylesheet" href="static/jquery/css/themes/rocket/jquery-wijmo.css" type="text/css" /> -->
11 <!-- <link rel="stylesheet" href="static/jquery/css/themes/smoothness/jquery-ui-1.8.14.custom.css" type="text/css" />-->
11 <!-- <link rel="stylesheet" href="static/jquery/css/themes/smoothness/jquery-ui-1.8.14.custom.css" type="text/css" />-->
12
12
13 <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML" charset="utf-8"></script>
13 <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML" charset="utf-8"></script>
14 <!-- <script type='text/javascript' src='static/mathjax/MathJax.js?config=TeX-AMS_HTML' charset='utf-8'></script> -->
14 <!-- <script type='text/javascript' src='static/mathjax/MathJax.js?config=TeX-AMS_HTML' charset='utf-8'></script> -->
15 <script type="text/javascript">
15 <script type="text/javascript">
16 if (typeof MathJax == 'undefined') {
16 if (typeof MathJax == 'undefined') {
17 console.log("Trying to load local copy of MathJax");
17 console.log("Trying to load local copy of MathJax");
18 document.write(unescape("%3Cscript type='text/javascript' src='static/mathjax/MathJax.js%3Fconfig=TeX-AMS_HTML' charset='utf-8'%3E%3C/script%3E"));
18 document.write(unescape("%3Cscript type='text/javascript' src='static/mathjax/MathJax.js%3Fconfig=TeX-AMS_HTML' charset='utf-8'%3E%3C/script%3E"));
19 }
19 }
20 </script>
20 </script>
21
21
22 <link rel="stylesheet" href="static/codemirror2/lib/codemirror.css">
22 <link rel="stylesheet" href="static/codemirror2/lib/codemirror.css">
23 <link rel="stylesheet" href="static/codemirror2/mode/python/python.css">
23 <link rel="stylesheet" href="static/codemirror2/mode/python/python.css">
24
24
25 <link rel="stylesheet" href="static/css/boilerplate.css" type="text/css" />
25 <link rel="stylesheet" href="static/css/boilerplate.css" type="text/css" />
26 <link rel="stylesheet" href="static/css/layout.css" type="text/css" />
26 <link rel="stylesheet" href="static/css/layout.css" type="text/css" />
27 <link rel="stylesheet" href="static/css/base.css" type="text/css" />
27 <link rel="stylesheet" href="static/css/base.css" type="text/css" />
28 <link rel="stylesheet" href="static/css/notebook.css" type="text/css" />
28 <link rel="stylesheet" href="static/css/notebook.css" type="text/css" />
29
29
30 </head>
30 </head>
31
31
32 <body>
32 <body>
33
33
34 <div id="header">
34 <div id="header">
35 <span id="ipython_notebook"><h1>IPython Notebook</h1></span>
35 <span id="ipython_notebook"><h1>IPython Notebook</h1></span>
36 <span id="save_widget">
36 <span id="save_widget">
37 <input type="text" id="notebook_name" size="20"></textarea>
37 <input type="text" id="notebook_name" size="20"></textarea>
38 <span id="notebook_id" style="display:none">{{notebook_id}}</span>
38 <span id="notebook_id" style="display:none">{{notebook_id}}</span>
39 <button id="save_notebook">Save</button>
39 <button id="save_notebook">Save</button>
40 </span>
40 </span>
41 <span id="kernel_status">Idle</span>
41 <span id="kernel_status">Idle</span>
42 </div>
42 </div>
43
43
44 <div id="main_app">
44 <div id="main_app">
45
45
46 <div id="left_panel">
46 <div id="left_panel">
47
47
48 <div id="notebook_section">
48 <div id="notebook_section">
49 <h3 class="section_header">Notebook</h3>
49 <h3 class="section_header">Notebook</h3>
50 <div class="section_content">
50 <div class="section_content">
51 <div class="section_row">
51 <div class="section_row">
52 <span id="new_open" class="section_row_buttons">
52 <span id="new_open" class="section_row_buttons">
53 <button id="new_notebook">New</button>
53 <button id="new_notebook">New</button>
54 <button id="open_notebook">Open</button>
54 <button id="open_notebook">Open</button>
55 </span>
55 </span>
56 <span class="section_row_header">Actions</span>
56 <span class="section_row_header">Actions</span>
57 </div>
57 </div>
58 <div class="section_row">
58 <div class="section_row">
59 <span class="section_row_buttons">
59 <span class="section_row_buttons">
60 <button id="download_notebook">Export</button>
60 <button id="download_notebook">Export</button>
61 </span>
61 </span>
62 <span>
62 <span>
63 <select id="download_format">
63 <select id="download_format">
64 <option value="xml">xml</option>
64 <option value="xml">xml</option>
65 <option value="json">json</option>
65 <option value="json">json</option>
66 <option value="py">py</option>
66 <option value="py">py</option>
67 </select>
67 </select>
68 </span>
68 </span>
69 </div>
69 </div>
70 </div>
70 </div>
71 </div>
71 </div>
72
72
73 <div id="cell_section">
73 <div id="cell_section">
74 <h3 class="section_header">Cell</h3>
74 <h3 class="section_header">Cell</h3>
75 <div class="section_content">
75 <div class="section_content">
76 <div class="section_row">
76 <div class="section_row">
77 <span class="section_row_buttons">
77 <span class="section_row_buttons">
78 <button id="delete_cell">Delete</button>
78 <button id="delete_cell">Delete</button>
79 </span>
79 </span>
80 <span class="section_row_header">Actions</span>
80 <span class="section_row_header">Actions</span>
81 </div>
81 </div>
82 <div class="section_row">
82 <div class="section_row">
83 <span id="insert" class="section_row_buttons">
83 <span id="insert" class="section_row_buttons">
84 <button id="insert_cell_above">Above</button>
84 <button id="insert_cell_above">Above</button>
85 <button id="insert_cell_below">Below</button>
85 <button id="insert_cell_below">Below</button>
86 </span>
86 </span>
87 <span class="button_label">Insert</span>
87 <span class="button_label">Insert</span>
88 </div>
88 </div>
89 <div class="section_row">
89 <div class="section_row">
90 <span id="move" class="section_row_buttons">
90 <span id="move" class="section_row_buttons">
91 <button id="move_cell_up">Up</button>
91 <button id="move_cell_up">Up</button>
92 <button id="move_cell_down">Down</button>
92 <button id="move_cell_down">Down</button>
93 </span>
93 </span>
94 <span class="button_label">Move</span>
94 <span class="button_label">Move</span>
95 </div>
95 </div>
96 <div class="section_row">
96 <div class="section_row">
97 <span id="cell_type" class="section_row_buttons">
97 <span id="cell_type" class="section_row_buttons">
98 <button id="to_code">Code</button>
98 <button id="to_code">Code</button>
99 <button id="to_text">Text</button>
99 <button id="to_html">HTML</button>
100 </span>
100 </span>
101 <span class="button_label">Cell Type</span>
101 <span class="button_label">Cell Type</span>
102 </div>
102 </div>
103 <div class="section_row">
103 <div class="section_row">
104 <span id="toggle_output" class="section_row_buttons">
104 <span id="toggle_output" class="section_row_buttons">
105 <button id="collapse_cell">Collapse</button>
105 <button id="collapse_cell">Collapse</button>
106 <button id="expand_cell">Expand</button>
106 <button id="expand_cell">Expand</button>
107 </span>
107 </span>
108 <span class="button_label">Output</span>
108 <span class="button_label">Output</span>
109 </div>
109 </div>
110 <div class="section_row">
110 <div class="section_row">
111 <span id="run_cells" class="section_row_buttons">
111 <span id="run_cells" class="section_row_buttons">
112 <button id="run_selected_cell">Selected</button>
112 <button id="run_selected_cell">Selected</button>
113 <button id="run_all_cells">All</button>
113 <button id="run_all_cells">All</button>
114 </span>
114 </span>
115 <span class="button_label">Run</span>
115 <span class="button_label">Run</span>
116 </div>
116 </div>
117 </div>
117 </div>
118 </div>
118 </div>
119
119
120 <div id="kernel_section">
120 <div id="kernel_section">
121 <h3 class="section_header">Kernel</h3>
121 <h3 class="section_header">Kernel</h3>
122 <div class="section_content">
122 <div class="section_content">
123 <div class="section_row">
123 <div class="section_row">
124 <span id="int_restart" class="section_row_buttons">
124 <span id="int_restart" class="section_row_buttons">
125 <button id="int_kernel">Interrupt</button>
125 <button id="int_kernel">Interrupt</button>
126 <button id="restart_kernel">Restart</button>
126 <button id="restart_kernel">Restart</button>
127 </span>
127 </span>
128 <span class="section_row_header">Actions</span>
128 <span class="section_row_header">Actions</span>
129 </div>
129 </div>
130 <div class="section_row">
130 <div class="section_row">
131 <span id="kernel_persist">
131 <span id="kernel_persist">
132 <input type="checkbox" id="kill_kernel"></input>
132 <input type="checkbox" id="kill_kernel"></input>
133 </span>
133 </span>
134 <span class="checkbox_label">Kill kernel upon exit:</span>
134 <span class="checkbox_label">Kill kernel upon exit:</span>
135 </div>
135 </div>
136 </div>
136 </div>
137 </div>
137 </div>
138
138
139 <div id="help_section">
139 <div id="help_section">
140 <h3 class="section_header">Help</h3>
140 <h3 class="section_header">Help</h3>
141 <div class="section_content">
141 <div class="section_content">
142 <div class="section_row">
142 <div class="section_row">
143 <span id="help_buttons0" class="section_row_buttons">
143 <span id="help_buttons0" class="section_row_buttons">
144 <button id="python_help"><a href="http://docs.python.org" target="_blank">Python</a></button>
144 <button id="python_help"><a href="http://docs.python.org" target="_blank">Python</a></button>
145 <button id="ipython_help"><a href="http://ipython.org/documentation.html" target="_blank">IPython</a></button>
145 <button id="ipython_help"><a href="http://ipython.org/documentation.html" target="_blank">IPython</a></button>
146 <button id="numpy_help"><a href="http://docs.scipy.org/doc/numpy/reference/" target="_blank">NumPy</a></button>
146 <button id="numpy_help"><a href="http://docs.scipy.org/doc/numpy/reference/" target="_blank">NumPy</a></button>
147 </span>
147 </span>
148 <span class="section_row_header">Links</span>
148 <span class="section_row_header">Links</span>
149 </div>
149 </div>
150 <div class="section_row">
150 <div class="section_row">
151 <span id="help_buttons1" class="section_row_buttons">
151 <span id="help_buttons1" class="section_row_buttons">
152 <button id="matplotlib_help"><a href="http://matplotlib.sourceforge.net/" target="_blank">MPL</a></button>
152 <button id="matplotlib_help"><a href="http://matplotlib.sourceforge.net/" target="_blank">MPL</a></button>
153 <button id="scipy_help"><a href="http://docs.scipy.org/doc/scipy/reference/" target="_blank">SciPy</a></button>
153 <button id="scipy_help"><a href="http://docs.scipy.org/doc/scipy/reference/" target="_blank">SciPy</a></button>
154 <button id="sympy_help"><a href="http://docs.sympy.org/dev/index.html" target="_blank">SymPy</a></button>
154 <button id="sympy_help"><a href="http://docs.sympy.org/dev/index.html" target="_blank">SymPy</a></button>
155 </span>
155 </span>
156 </div>
156 </div>
157 </div>
157 </div>
158 </div>
158 </div>
159
159
160 </div>
160 </div>
161 <div id="left_panel_splitter"></div>
161 <div id="left_panel_splitter"></div>
162 <div id="notebook_panel">
162 <div id="notebook_panel">
163 <div id="notebook"></div>
163 <div id="notebook"></div>
164 <div id="pager_splitter"></div>
164 <div id="pager_splitter"></div>
165 <div id="pager"></div>
165 <div id="pager"></div>
166 </div>
166 </div>
167
167
168 </div>
168 </div>
169
169
170 <script src="static/jquery/js/jquery-1.6.2.min.js" type="text/javascript" charset="utf-8"></script>
170 <script src="static/jquery/js/jquery-1.6.2.min.js" type="text/javascript" charset="utf-8"></script>
171 <script src="static/jquery/js/jquery-ui-1.8.14.custom.min.js" type="text/javascript" charset="utf-8"></script>
171 <script src="static/jquery/js/jquery-ui-1.8.14.custom.min.js" type="text/javascript" charset="utf-8"></script>
172 <script src="static/jquery/js/jquery.autogrow.js" type="text/javascript" charset="utf-8"></script>
172 <script src="static/jquery/js/jquery.autogrow.js" type="text/javascript" charset="utf-8"></script>
173 <script src="static/js/namespace.js" type="text/javascript" charset="utf-8"></script>
173 <script src="static/js/namespace.js" type="text/javascript" charset="utf-8"></script>
174 <script src="static/js/utils.js" type="text/javascript" charset="utf-8"></script>
174 <script src="static/js/utils.js" type="text/javascript" charset="utf-8"></script>
175 <script src="static/js/cell.js" type="text/javascript" charset="utf-8"></script>
175 <script src="static/js/cell.js" type="text/javascript" charset="utf-8"></script>
176 <script src="static/js/codecell.js" type="text/javascript" charset="utf-8"></script>
176 <script src="static/js/codecell.js" type="text/javascript" charset="utf-8"></script>
177 <script src="static/js/textcell.js" type="text/javascript" charset="utf-8"></script>
177 <script src="static/js/htmlcell.js" type="text/javascript" charset="utf-8"></script>
178 <script src="static/js/kernel.js" type="text/javascript" charset="utf-8"></script>
178 <script src="static/js/kernel.js" type="text/javascript" charset="utf-8"></script>
179 <script src="static/js/kernelstatus.js" type="text/javascript" charset="utf-8"></script>
179 <script src="static/js/kernelstatus.js" type="text/javascript" charset="utf-8"></script>
180 <script src="static/js/layout.js" type="text/javascript" charset="utf-8"></script>
180 <script src="static/js/layout.js" type="text/javascript" charset="utf-8"></script>
181 <script src="static/js/savewidget.js" type="text/javascript" charset="utf-8"></script>
181 <script src="static/js/savewidget.js" type="text/javascript" charset="utf-8"></script>
182 <script src="static/js/pager.js" type="text/javascript" charset="utf-8"></script>
182 <script src="static/js/pager.js" type="text/javascript" charset="utf-8"></script>
183 <script src="static/js/panelsection.js" type="text/javascript" charset="utf-8"></script>
183 <script src="static/js/panelsection.js" type="text/javascript" charset="utf-8"></script>
184 <script src="static/js/leftpanel.js" type="text/javascript" charset="utf-8"></script>
184 <script src="static/js/leftpanel.js" type="text/javascript" charset="utf-8"></script>
185 <script src="static/js/notebook.js" type="text/javascript" charset="utf-8"></script>
185 <script src="static/js/notebook.js" type="text/javascript" charset="utf-8"></script>
186 <script src="static/js/notebook_main.js" type="text/javascript" charset="utf-8"></script>
186 <script src="static/js/notebook_main.js" type="text/javascript" charset="utf-8"></script>
187 <script src="static/codemirror2/lib/codemirror.js"></script>
187 <script src="static/codemirror2/lib/codemirror.js"></script>
188 <script src="static/codemirror2/mode/python/python.js"></script>
188 <script src="static/codemirror2/mode/python/python.js"></script>
189
189
190 </body>
190 </body>
191
191
192 </html>
192 </html>
193
193
194
194
General Comments 0
You need to be logged in to leave comments. Login now