##// END OF EJS Templates
Pager is working again.
Brian E. Granger -
Show More
@@ -1,253 +1,253 b''
1 /**
1 /**
2 * HTML5 ✰ Boilerplate
2 * HTML5 ✰ Boilerplate
3 *
3 *
4 * style.css contains a reset, font normalization and some base styles.
4 * style.css contains a reset, font normalization and some base styles.
5 *
5 *
6 * Credit is left where credit is due.
6 * Credit is left where credit is due.
7 * Much inspiration was taken from these projects:
7 * Much inspiration was taken from these projects:
8 * - yui.yahooapis.com/2.8.1/build/base/base.css
8 * - yui.yahooapis.com/2.8.1/build/base/base.css
9 * - camendesign.com/design/
9 * - camendesign.com/design/
10 * - praegnanz.de/weblog/htmlcssjs-kickstart
10 * - praegnanz.de/weblog/htmlcssjs-kickstart
11 */
11 */
12
12
13
13
14 /**
14 /**
15 * html5doctor.com Reset Stylesheet (Eric Meyer's Reset Reloaded + HTML5 baseline)
15 * html5doctor.com Reset Stylesheet (Eric Meyer's Reset Reloaded + HTML5 baseline)
16 * v1.6.1 2010-09-17 | Authors: Eric Meyer & Richard Clark
16 * v1.6.1 2010-09-17 | Authors: Eric Meyer & Richard Clark
17 * html5doctor.com/html-5-reset-stylesheet/
17 * html5doctor.com/html-5-reset-stylesheet/
18 */
18 */
19
19
20 html, body, div, span, object, iframe,
20 html, body, div, span, object, iframe,
21 h1, h2, h3, h4, h5, h6, p, blockquote, pre,
21 h1, h2, h3, h4, h5, h6, p, blockquote, pre,
22 abbr, address, cite, code, del, dfn, em, img, ins, kbd, q, samp,
22 abbr, address, cite, code, del, dfn, em, img, ins, kbd, q, samp,
23 small, strong, sub, sup, var, b, i, dl, dt, dd, ol, ul, li,
23 small, strong, sub, sup, var, b, i, dl, dt, dd, ol, ul, li,
24 fieldset, form, label, legend,
24 fieldset, form, label, legend,
25 table, caption, tbody, tfoot, thead, tr, th, td,
25 table, caption, tbody, tfoot, thead, tr, th, td,
26 article, aside, canvas, details, figcaption, figure,
26 article, aside, canvas, details, figcaption, figure,
27 footer, header, hgroup, menu, nav, section, summary,
27 footer, header, hgroup, menu, nav, section, summary,
28 time, mark, audio, video {
28 time, mark, audio, video {
29 margin: 0;
29 margin: 0;
30 padding: 0;
30 padding: 0;
31 border: 0;
31 border: 0;
32 /* font-size: 100%;*/
32 /* font-size: 100%;*/
33 font: inherit;
33 font: inherit;
34 vertical-align: baseline;
34 vertical-align: baseline;
35 }
35 }
36
36
37 article, aside, details, figcaption, figure,
37 article, aside, details, figcaption, figure,
38 footer, header, hgroup, menu, nav, section {
38 footer, header, hgroup, menu, nav, section {
39 display: block;
39 display: block;
40 }
40 }
41
41
42 blockquote, q { quotes: none; }
42 blockquote, q { quotes: none; }
43
43
44 blockquote:before, blockquote:after,
44 blockquote:before, blockquote:after,
45 q:before, q:after { content: ""; content: none; }
45 q:before, q:after { content: ""; content: none; }
46
46
47 ins { background-color: #ff9; color: #000; text-decoration: none; }
47 ins { background-color: #ff9; color: #000; text-decoration: none; }
48
48
49 mark { background-color: #ff9; color: #000; font-style: italic; font-weight: bold; }
49 mark { background-color: #ff9; color: #000; font-style: italic; font-weight: bold; }
50
50
51 del { text-decoration: line-through; }
51 del { text-decoration: line-through; }
52
52
53 abbr[title], dfn[title] { border-bottom: 1px dotted; cursor: help; }
53 abbr[title], dfn[title] { border-bottom: 1px dotted; cursor: help; }
54
54
55 table { border-collapse: collapse; border-spacing: 0; }
55 table { border-collapse: collapse; border-spacing: 0; }
56
56
57 hr { display: block; height: 1px; border: 0; border-top: 1px solid #ccc; margin: 1em 0; padding: 0; }
57 hr { display: block; height: 1px; border: 0; border-top: 1px solid #ccc; margin: 1em 0; padding: 0; }
58
58
59 input, select { vertical-align: middle; }
59 input, select { vertical-align: middle; }
60
60
61 body {
61 body {
62 background-color: white;
62 background-color: white;
63 /* This won't propagate to all children so we also set it below */
63 /* This won't propagate to all children so we also set it below */
64 font-size: 12pt;
64 font-size: 12pt;
65 /* This makes sure that the body covers the entire window and needs to
65 /* This makes sure that the body covers the entire window and needs to
66 be in a different element than the display: box in wrapper below */
66 be in a different element than the display: box in wrapper below */
67 position: absolute;
67 position: absolute;
68 left: 0px;
68 left: 0px;
69 right: 0px;
69 right: 0px;
70 top: 0px;
70 top: 0px;
71 bottom: 0px;
71 bottom: 0px;
72 overflow: hidden;
72 overflow: hidden;
73 }
73 }
74
74
75
75
76 span#ipython_notebook h1 {
76 span#ipython_notebook h1 {
77 font-family: Verdana, "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
77 font-family: Verdana, "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
78 font-size: 22pt;
78 font-size: 22pt;
79 height: 35px;
79 height: 35px;
80 padding: 5px;
80 padding: 5px;
81 margin: 0px;
81 margin: 0px;
82
82
83 }
83 }
84
84
85 div#tools {
85 div#tools {
86 font-size: 11pt;
86 font-size: 11pt;
87 }
87 }
88
88
89 span#kernel_status {
89 span#kernel_status {
90 position: absolute;
90 position: absolute;
91 top: 12%;
91 top: 12%;
92 right: 10px;
92 right: 10px;
93 font-weight: bold;
93 font-weight: bold;
94 }
94 }
95
95
96 .status_idle {
96 .status_idle {
97 color: gray;
97 color: gray;
98 }
98 }
99
99
100 .status_busy {
100 .status_busy {
101 color: red;
101 color: red;
102 }
102 }
103
103
104 .status_restarting {
104 .status_restarting {
105 color: black;
105 color: black;
106 }
106 }
107
107
108 div#notebook_app {
108 div#notebook_app {
109 width: 100%;
109 width: 100%;
110 position: relative;
110 position: relative;
111 }
111 }
112
112
113 div#left_panel {
113 div#left_panel {
114 width: 200px;
114 width: 200px;
115 min-height: 300px;
115 min-height: 300px;
116 overflow-y: auto;
116 overflow-y: auto;
117 top: 0px;
117 top: 0px;
118 left: 0px;
118 left: 0px;
119 margin: 0px;
119 margin: 0px;
120 padding: 0px;
120 padding: 0px;
121 position: absolute;
121 position: absolute;
122 }
122 }
123
123
124 div#left_panel_splitter {
124 div#left_panel_splitter {
125 width: 7px;
125 width: 8px;
126 top: 0px;
126 top: 0px;
127 left: 202px;
127 left: 202px;
128 margin: 0px;
128 margin: 0px;
129 padding: 0px;
129 padding: 0px;
130 position: absolute;
130 position: absolute;
131 }
131 }
132
132
133 div#notebook_panel {
133 div#notebook_panel {
134 margin: 0px 0px 0px 211px;
134 margin: 0px 0px 0px 209px;
135 padding: 0px;
135 padding: 0px;
136 }
136 }
137
137
138 div#notebook {
138 div#notebook {
139 overflow-y: scroll;
139 overflow-y: scroll;
140 overflow-x: auto;
140 overflow-x: auto;
141 width: 100%;
141 width: 100%;
142 padding: 0px 0px;
142 padding: 0px 15px 15px 15px;
143 margin: 0px
143 margin: 0px
144 background-color: white;
144 background-color: white;
145 font-size: 12pt;
145 font-size: 12pt;
146 }
146 }
147
147
148 div#pager_splitter {
148 div#pager_splitter {
149 height: 7px;
149 height: 8px;
150 }
150 }
151
151
152 div#pager {
152 div#pager {
153 height: 200px;
153 height: 200px;
154 overflow: auto;
154 overflow: auto;
155 }
155 }
156
156
157 .monospace-font {
157 .monospace-font {
158 font-family: monospace;
158 font-family: monospace;
159 font-size: 12pt;
159 font-size: 12pt;
160 }
160 }
161
161
162 div.cell {
162 div.cell {
163 width: 100%;
163 width: 100%;
164 padding: 0px;
164 padding: 5px;
165 /* This acts as a spacer between cells, that is outside the border */
165 /* This acts as a spacer between cells, that is outside the border */
166 margin: 15px 0px 15px 0px;
166 margin: 15px 0px 15px 0px;
167 }
167 }
168
168
169 div.code_cell {
169 div.code_cell {
170 background-color: white;
170 background-color: white;
171 }
171 }
172
172
173 div.prompt {
173 div.prompt {
174 width: 90px;
174 width: 90px;
175 padding: 0px;
175 padding: 0px;
176 margin: 0px;
176 margin: 0px;
177 }
177 }
178
178
179 div.input_prompt {
179 div.input_prompt {
180 color: navy;
180 color: navy;
181 }
181 }
182
182
183 div.output {
183 div.output {
184 /* This is a spacer between the input and output of each cell */
184 /* This is a spacer between the input and output of each cell */
185 margin-top: 15px;
185 margin-top: 15px;
186 }
186 }
187
187
188 div.output_prompt {
188 div.output_prompt {
189 color: darkred;
189 color: darkred;
190 }
190 }
191
191
192 div.output_area {
192 div.output_area {
193 text-align: left;
193 text-align: left;
194 color: black;
194 color: black;
195 }
195 }
196
196
197 div.output_latex {
197 div.output_latex {
198 /* Slightly bigger than the rest of the notebook */
198 /* Slightly bigger than the rest of the notebook */
199 font-size: 13pt;
199 font-size: 13pt;
200 }
200 }
201
201
202 div.output_png {
202 div.output_png {
203 }
203 }
204
204
205 div.text_cell {
205 div.text_cell {
206 background-color: white;
206 background-color: white;
207 }
207 }
208
208
209 textarea.text_cell_input {
209 textarea.text_cell_input {
210 /* Slightly bigger than the rest of the notebook */
210 /* Slightly bigger than the rest of the notebook */
211 font-size: 13pt;
211 font-size: 13pt;
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.text_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: 13pt;
224 font-size: 13pt;
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.text_cell_render em {font-style: italic;}
234 div.text_cell_render strong {font-weight: bold;}
234 div.text_cell_render strong {font-weight: bold;}
235 div.text_cell_render u {text-decoration: underline;}
235 div.text_cell_render u {text-decoration: underline;}
236 div.text_cell_render :link { text-decoration: underline }
236 div.text_cell_render :link { text-decoration: underline }
237 div.text_cell_render :visited { text-decoration: underline }
237 div.text_cell_render :visited { text-decoration: underline }
238 div.text_cell_render h1 {font-size: 2.0em; margin: .67em 0; font-weight: bold;}
238 div.text_cell_render h1 {font-size: 2.0em; margin: .67em 0; font-weight: bold;}
239 div.text_cell_render h2 {font-size: 1.5em; margin: .75em 0; font-weight: bold;}
239 div.text_cell_render h2 {font-size: 1.5em; margin: .75em 0; font-weight: bold;}
240 div.text_cell_render h3 {font-size: 1.17em; margin: .83em 0; font-weight: bold;}
240 div.text_cell_render h3 {font-size: 1.17em; margin: .83em 0; font-weight: bold;}
241 div.text_cell_render h4 {margin: 1.12em 0; font-weight: bold;}
241 div.text_cell_render h4 {margin: 1.12em 0; font-weight: bold;}
242 div.text_cell_render h5 {font-size: .83em; margin: 1.5em 0; font-weight: bold;}
242 div.text_cell_render h5 {font-size: .83em; margin: 1.5em 0; font-weight: bold;}
243 div.text_cell_render h6 {font-size: .75em; margin: 1.67em 0; font-weight: bold;}
243 div.text_cell_render h6 {font-size: .75em; margin: 1.67em 0; font-weight: bold;}
244 div.text_cell_render ul {list-style:disc; margin-left: 40px;}
244 div.text_cell_render ul {list-style:disc; margin-left: 40px;}
245 div.text_cell_render ul ul {list-style:square; margin-left: 40px;}
245 div.text_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.text_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.text_cell_render ol {list-style:upper-roman; margin-left: 40px;}
248 div.text_cell_render ol ol {list-style:upper-alpha;}
248 div.text_cell_render ol ol {list-style:upper-alpha;}
249 div.text_cell_render ol ol ol {list-style:decimal;}
249 div.text_cell_render ol ol ol {list-style:decimal;}
250 div.text_cell_render ol ol ol ol {list-style:lower-alpha;}
250 div.text_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.text_cell_render ol ol ol ol ol {list-style:lower-roman;}
252
252
253
253
@@ -1,80 +1,63 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 var Cell = function (notebook) {
10 var Cell = function (notebook) {
11 this.notebook = notebook;
11 this.notebook = notebook;
12 this.selected = false;
12 this.selected = false;
13 this.element;
13 this.element;
14 this.create_element();
14 this.create_element();
15 if (this.element !== undefined) {
15 if (this.element !== undefined) {
16 this.element.data("cell", this);
16 this.element.data("cell", this);
17 this.bind_events();
17 this.bind_events();
18 }
18 }
19 this.cell_id = utils.uuid();
19 this.cell_id = utils.uuid();
20 };
20 };
21
21
22
22
23 Cell.prototype.grow = function(element) {
24 // Grow the cell by hand. This is used upon reloading from JSON, when the
25 // autogrow handler is not called.
26 var dom = element.get(0);
27 var lines_count = 0;
28 // modified split rule from
29 // http://stackoverflow.com/questions/2035910/how-to-get-the-number-of-lines-in-a-textarea/2036424#2036424
30 var lines = dom.value.split(/\r|\r\n|\n/);
31 lines_count = lines.length;
32 if (lines_count >= 1) {
33 dom.rows = lines_count;
34 } else {
35 dom.rows = 1;
36 }
37 };
38
39
40 Cell.prototype.select = function () {
23 Cell.prototype.select = function () {
41 this.element.addClass('ui-widget-content ui-corner-all');
24 this.element.addClass('ui-widget-content ui-corner-all');
42 this.selected = true;
25 this.selected = true;
43 // TODO: we need t test across browsers to see if both of these are needed.
26 // TODO: we need t test across browsers to see if both of these are needed.
44 // In the meantime, there should not be any harm in having them both.
27 // In the meantime, there should not be any harm in having them both.
45 this.element.find('textarea').trigger('focusin');
28 this.element.find('textarea').trigger('focusin');
46 this.element.find('textarea').trigger('focus');
29 this.element.find('textarea').trigger('focus');
47 };
30 };
48
31
49
32
50 Cell.prototype.unselect = function () {
33 Cell.prototype.unselect = function () {
51 this.element.removeClass('ui-widget-content ui-corner-all');
34 this.element.removeClass('ui-widget-content ui-corner-all');
52 this.selected = false;
35 this.selected = false;
53 };
36 };
54
37
55
38
56 Cell.prototype.bind_events = function () {
39 Cell.prototype.bind_events = function () {
57 var that = this;
40 var that = this;
58 var nb = that.notebook
41 var nb = that.notebook
59 that.element.click(function (event) {
42 that.element.click(function (event) {
60 if (that.selected === false) {
43 if (that.selected === false) {
61 nb.select(nb.find_cell_index(that));
44 nb.select(nb.find_cell_index(that));
62 };
45 };
63 });
46 });
64 that.element.focusin(function (event) {
47 that.element.focusin(function (event) {
65 if (that.selected === false) {
48 if (that.selected === false) {
66 nb.select(nb.find_cell_index(that));
49 nb.select(nb.find_cell_index(that));
67 };
50 };
68 });
51 });
69 };
52 };
70
53
71
54
72 // Subclasses must implement create_element.
55 // Subclasses must implement create_element.
73 Cell.prototype.create_element = function () {};
56 Cell.prototype.create_element = function () {};
74
57
75 IPython.Cell = Cell;
58 IPython.Cell = Cell;
76
59
77 return IPython;
60 return IPython;
78
61
79 }(IPython));
62 }(IPython));
80
63
@@ -1,201 +1,201 b''
1
1
2 //============================================================================
2 //============================================================================
3 // CodeCell
3 // CodeCell
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 CodeCell = function (notebook) {
10 var CodeCell = function (notebook) {
11 this.code_mirror = null;
11 this.code_mirror = null;
12 this.input_prompt_number = ' ';
12 this.input_prompt_number = ' ';
13 IPython.Cell.apply(this, arguments);
13 IPython.Cell.apply(this, arguments);
14 };
14 };
15
15
16
16
17 CodeCell.prototype = new IPython.Cell();
17 CodeCell.prototype = new IPython.Cell();
18
18
19
19
20 CodeCell.prototype.create_element = function () {
20 CodeCell.prototype.create_element = function () {
21 var cell = $('<div></div>').addClass('cell code_cell vbox');
21 var cell = $('<div></div>').addClass('cell border-box-sizing code_cell vbox');
22 var input = $('<div></div>').addClass('input hbox');
22 var input = $('<div></div>').addClass('input hbox');
23 input.append($('<div/>').addClass('prompt input_prompt monospace-font'));
23 input.append($('<div/>').addClass('prompt input_prompt monospace-font'));
24 var input_area = $('<div/>').addClass('input_area box-flex1');
24 var input_area = $('<div/>').addClass('input_area box-flex1');
25 this.code_mirror = CodeMirror(input_area.get(0), {
25 this.code_mirror = CodeMirror(input_area.get(0), {
26 indentUnit : 4,
26 indentUnit : 4,
27 enterMode : 'flat',
27 enterMode : 'flat',
28 tabMode: 'shift'
28 tabMode: 'shift'
29 });
29 });
30 input.append(input_area);
30 input.append(input_area);
31 var output = $('<div></div>').addClass('output vbox');
31 var output = $('<div></div>').addClass('output vbox');
32 cell.append(input).append(output);
32 cell.append(input).append(output);
33 this.element = cell;
33 this.element = cell;
34 this.collapse()
34 this.collapse()
35 };
35 };
36
36
37
37
38 CodeCell.prototype.select = function () {
38 CodeCell.prototype.select = function () {
39 IPython.Cell.prototype.select.apply(this);
39 IPython.Cell.prototype.select.apply(this);
40 this.code_mirror.focus();
40 this.code_mirror.focus();
41 };
41 };
42
42
43
43
44 CodeCell.prototype.append_pyout = function (data, n) {
44 CodeCell.prototype.append_pyout = function (data, n) {
45 var toinsert = $("<div/>").addClass("output_area output_pyout hbox monospace-font");
45 var toinsert = $("<div/>").addClass("output_area output_pyout hbox monospace-font");
46 toinsert.append($('<div/>').
46 toinsert.append($('<div/>').
47 addClass('prompt output_prompt').
47 addClass('prompt output_prompt').
48 html('Out[' + n + ']:')
48 html('Out[' + n + ']:')
49 );
49 );
50 this.append_display_data(data, toinsert);
50 this.append_display_data(data, toinsert);
51 toinsert.children().last().addClass("box_flex1");
51 toinsert.children().last().addClass("box_flex1");
52 this.element.find("div.output").append(toinsert);
52 this.element.find("div.output").append(toinsert);
53 // If we just output latex, typeset it.
53 // If we just output latex, typeset it.
54 if (data["text/latex"] !== undefined) {
54 if (data["text/latex"] !== undefined) {
55 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
55 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
56 };
56 };
57 };
57 };
58
58
59
59
60 CodeCell.prototype.append_pyerr = function (ename, evalue, tb) {
60 CodeCell.prototype.append_pyerr = function (ename, evalue, tb) {
61 var s = '';
61 var s = '';
62 var len = tb.length;
62 var len = tb.length;
63 for (var i=0; i<len; i++) {
63 for (var i=0; i<len; i++) {
64 s = s + tb[i] + '\n';
64 s = s + tb[i] + '\n';
65 }
65 }
66 s = s + '\n';
66 s = s + '\n';
67 this.append_stream(s);
67 this.append_stream(s);
68 };
68 };
69
69
70
70
71 CodeCell.prototype.append_display_data = function (data, element) {
71 CodeCell.prototype.append_display_data = function (data, element) {
72 if (data["text/latex"] !== undefined) {
72 if (data["text/latex"] !== undefined) {
73 this.append_latex(data["text/latex"], element);
73 this.append_latex(data["text/latex"], element);
74 // If it is undefined, then we just appended to div.output, which
74 // If it is undefined, then we just appended to div.output, which
75 // makes the latex visible and we can typeset it. The typesetting
75 // makes the latex visible and we can typeset it. The typesetting
76 // has to be done after the latex is on the page.
76 // has to be done after the latex is on the page.
77 if (element === undefined) {
77 if (element === undefined) {
78 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
78 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
79 };
79 };
80 } else if (data["image/svg+xml"] !== undefined) {
80 } else if (data["image/svg+xml"] !== undefined) {
81 this.append_svg(data["image/svg+xml"], element);
81 this.append_svg(data["image/svg+xml"], element);
82 } else if (data["image/png"] !== undefined) {
82 } else if (data["image/png"] !== undefined) {
83 this.append_png(data["image/png"], element);
83 this.append_png(data["image/png"], element);
84 } else if (data["text/plain"] !== undefined) {
84 } else if (data["text/plain"] !== undefined) {
85 this.append_stream(data["text/plain"], element);
85 this.append_stream(data["text/plain"], element);
86 };
86 };
87 return element;
87 return element;
88 };
88 };
89
89
90
90
91 CodeCell.prototype.append_stream = function (data, element) {
91 CodeCell.prototype.append_stream = function (data, element) {
92 element = element || this.element.find("div.output");
92 element = element || this.element.find("div.output");
93 var toinsert = $("<div/>").addClass("output_area output_stream monospace-font");
93 var toinsert = $("<div/>").addClass("output_area output_stream monospace-font");
94 toinsert.append($("<pre/>").addClass("monospace-font").html(utils.fixConsole(data)));
94 toinsert.append($("<pre/>").addClass("monospace-font").html(utils.fixConsole(data)));
95 element.append(toinsert);
95 element.append(toinsert);
96 return element;
96 return element;
97 };
97 };
98
98
99
99
100 CodeCell.prototype.append_svg = function (svg, element) {
100 CodeCell.prototype.append_svg = function (svg, element) {
101 element = element || this.element.find("div.output");
101 element = element || this.element.find("div.output");
102 var toinsert = $("<div/>").addClass("output_area output_svg");
102 var toinsert = $("<div/>").addClass("output_area output_svg");
103 toinsert.append(svg);
103 toinsert.append(svg);
104 element.append(toinsert);
104 element.append(toinsert);
105 return element;
105 return element;
106 };
106 };
107
107
108
108
109 CodeCell.prototype.append_png = function (png, element) {
109 CodeCell.prototype.append_png = function (png, element) {
110 element = element || this.element.find("div.output");
110 element = element || this.element.find("div.output");
111 var toinsert = $("<div/>").addClass("output_area output_png");
111 var toinsert = $("<div/>").addClass("output_area output_png");
112 toinsert.append($("<img/>").attr('src','data:image/png;base64,'+png));
112 toinsert.append($("<img/>").attr('src','data:image/png;base64,'+png));
113 element.append(toinsert);
113 element.append(toinsert);
114 return element;
114 return element;
115 };
115 };
116
116
117
117
118 CodeCell.prototype.append_latex = function (latex, element) {
118 CodeCell.prototype.append_latex = function (latex, element) {
119 // This method cannot do the typesetting because the latex first has to
119 // This method cannot do the typesetting because the latex first has to
120 // be on the page.
120 // be on the page.
121 element = element || this.element.find("div.output");
121 element = element || this.element.find("div.output");
122 var toinsert = $("<div/>").addClass("output_area output_latex monospace-font");
122 var toinsert = $("<div/>").addClass("output_area output_latex monospace-font");
123 toinsert.append(latex);
123 toinsert.append(latex);
124 element.append(toinsert);
124 element.append(toinsert);
125 return element;
125 return element;
126 }
126 }
127
127
128
128
129 CodeCell.prototype.clear_output = function () {
129 CodeCell.prototype.clear_output = function () {
130 this.element.find("div.output").html("");
130 this.element.find("div.output").html("");
131 };
131 };
132
132
133
133
134 CodeCell.prototype.collapse = function () {
134 CodeCell.prototype.collapse = function () {
135 this.element.find('div.output').hide();
135 this.element.find('div.output').hide();
136 };
136 };
137
137
138
138
139 CodeCell.prototype.expand = function () {
139 CodeCell.prototype.expand = function () {
140 this.element.find('div.output').show();
140 this.element.find('div.output').show();
141 };
141 };
142
142
143
143
144 CodeCell.prototype.set_input_prompt = function (number) {
144 CodeCell.prototype.set_input_prompt = function (number) {
145 var n = number || ' ';
145 var n = number || ' ';
146 this.input_prompt_number = n
146 this.input_prompt_number = n
147 this.element.find('div.input_prompt').html('In&nbsp;[' + n + ']:');
147 this.element.find('div.input_prompt').html('In&nbsp;[' + n + ']:');
148 };
148 };
149
149
150
150
151 CodeCell.prototype.get_code = function () {
151 CodeCell.prototype.get_code = function () {
152 return this.code_mirror.getValue();
152 return this.code_mirror.getValue();
153 };
153 };
154
154
155
155
156 CodeCell.prototype.set_code = function (code) {
156 CodeCell.prototype.set_code = function (code) {
157 return this.code_mirror.setValue(code);
157 return this.code_mirror.setValue(code);
158 };
158 };
159
159
160
160
161 CodeCell.prototype.at_top = function () {
161 CodeCell.prototype.at_top = function () {
162 var cursor = this.code_mirror.getCursor();
162 var cursor = this.code_mirror.getCursor();
163 if (cursor.line === 0) {
163 if (cursor.line === 0) {
164 return true;
164 return true;
165 } else {
165 } else {
166 return false;
166 return false;
167 }
167 }
168 };
168 };
169
169
170
170
171 CodeCell.prototype.at_bottom = function () {
171 CodeCell.prototype.at_bottom = function () {
172 var cursor = this.code_mirror.getCursor();
172 var cursor = this.code_mirror.getCursor();
173 if (cursor.line === (this.code_mirror.lineCount()-1)) {
173 if (cursor.line === (this.code_mirror.lineCount()-1)) {
174 return true;
174 return true;
175 } else {
175 } else {
176 return false;
176 return false;
177 }
177 }
178 };
178 };
179
179
180
180
181 CodeCell.prototype.fromJSON = function (data) {
181 CodeCell.prototype.fromJSON = function (data) {
182 if (data.cell_type === 'code') {
182 if (data.cell_type === 'code') {
183 this.set_code(data.code);
183 this.set_code(data.code);
184 this.set_input_prompt(data.prompt_number);
184 this.set_input_prompt(data.prompt_number);
185 };
185 };
186 };
186 };
187
187
188
188
189 CodeCell.prototype.toJSON = function () {
189 CodeCell.prototype.toJSON = function () {
190 return {
190 return {
191 code : this.get_code(),
191 code : this.get_code(),
192 cell_type : 'code',
192 cell_type : 'code',
193 prompt_number : this.input_prompt_number
193 prompt_number : this.input_prompt_number
194 };
194 };
195 };
195 };
196
196
197 IPython.CodeCell = CodeCell;
197 IPython.CodeCell = CodeCell;
198
198
199 return IPython;
199 return IPython;
200 }(IPython));
200 }(IPython));
201
201
@@ -1,541 +1,557 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.filename = null;
17 this.filename = null;
18 this.notebook_load_re = /%notebook load/
18 this.notebook_load_re = /%notebook load/
19 this.notebook_save_re = /%notebook save/
19 this.notebook_save_re = /%notebook save/
20 this.notebook_filename_re = /(\w)+.ipynb/
20 this.notebook_filename_re = /(\w)+.ipynb/
21 this.style();
21 this.style();
22 this.bind_events();
22 this.bind_events();
23 this.start_kernel();
23 this.start_kernel();
24 };
24 };
25
25
26
26
27 Notebook.prototype.style = function () {
27 Notebook.prototype.style = function () {
28 };
28 };
29
29
30
30
31 Notebook.prototype.bind_events = function () {
31 Notebook.prototype.bind_events = function () {
32 var that = this;
32 var that = this;
33 $(document).keydown(function (event) {
33 $(document).keydown(function (event) {
34 // console.log(event);
34 // console.log(event);
35 if (event.which === 38) {
35 if (event.which === 38) {
36 var cell = that.selected_cell();
36 var cell = that.selected_cell();
37 if (cell.at_top()) {
37 if (cell.at_top()) {
38 event.preventDefault();
38 event.preventDefault();
39 that.select_prev();
39 that.select_prev();
40 };
40 };
41 } else if (event.which === 40) {
41 } else if (event.which === 40) {
42 var cell = that.selected_cell();
42 var cell = that.selected_cell();
43 if (cell.at_bottom()) {
43 if (cell.at_bottom()) {
44 event.preventDefault();
44 event.preventDefault();
45 that.select_next();
45 that.select_next();
46 };
46 };
47 } else if (event.which === 13 && event.shiftKey) {
47 } else if (event.which === 13 && event.shiftKey) {
48 // The focus is not quite working here.
48 // The focus is not quite working here.
49 var cell = that.selected_cell();
49 var cell = that.selected_cell();
50 var cell_index = that.find_cell_index(cell);
50 var cell_index = that.find_cell_index(cell);
51 // TODO: the logic here needs to be moved into appropriate
51 // TODO: the logic here needs to be moved into appropriate
52 // methods of Notebook.
52 // methods of Notebook.
53 if (cell instanceof IPython.CodeCell) {
53 if (cell instanceof IPython.CodeCell) {
54 event.preventDefault();
54 event.preventDefault();
55 cell.clear_output();
55 cell.clear_output();
56 var code = cell.get_code();
56 var code = cell.get_code();
57 if (that.notebook_load_re.test(code)) {
57 if (that.notebook_load_re.test(code)) {
58 var code_parts = code.split(' ');
58 var code_parts = code.split(' ');
59 if (code_parts.length === 3) {
59 if (code_parts.length === 3) {
60 that.load_notebook(code_parts[2]);
60 that.load_notebook(code_parts[2]);
61 };
61 };
62 } else if (that.notebook_save_re.test(code)) {
62 } else if (that.notebook_save_re.test(code)) {
63 var code_parts = code.split(' ');
63 var code_parts = code.split(' ');
64 if (code_parts.length === 3) {
64 if (code_parts.length === 3) {
65 that.save_notebook(code_parts[2]);
65 that.save_notebook(code_parts[2]);
66 } else {
66 } else {
67 that.save_notebook()
67 that.save_notebook()
68 };
68 };
69 } else {
69 } else {
70 var msg_id = that.kernel.execute(cell.get_code());
70 var msg_id = that.kernel.execute(cell.get_code());
71 that.msg_cell_map[msg_id] = cell.cell_id;
71 that.msg_cell_map[msg_id] = cell.cell_id;
72 };
72 };
73 } else if (cell instanceof IPython.TextCell) {
73 } else if (cell instanceof IPython.TextCell) {
74 event.preventDefault();
74 event.preventDefault();
75 cell.render();
75 cell.render();
76 }
76 }
77 if (cell_index === (that.ncells()-1)) {
77 if (cell_index === (that.ncells()-1)) {
78 that.insert_code_cell_after();
78 that.insert_code_cell_after();
79 } else {
79 } else {
80 that.select(cell_index+1);
80 that.select(cell_index+1);
81 };
81 };
82 };
82 };
83 });
83 });
84
85 this.element.bind('collapse_pager', function () {
86 var that_height = that.element.outerHeight(true);
87 var pager_height = $('div#pager').outerHeight(true);
88 var new_height = that_height + pager_height;
89 console.log('collapse', that_height, pager_height, new_height);
90 that.element.animate({height : new_height + 'px'}, 'fast');
91 });
92
93 this.element.bind('expand_pager', function () {
94 var that_height = that.element.outerHeight(true);
95 var pager_height = $('div#pager').outerHeight(true);
96 var new_height = that_height - pager_height;
97 console.log('expand', that_height, pager_height, new_height);
98 that.element.animate({height : new_height + 'px'}, 'fast');
99 });
84 };
100 };
85
101
86
102
87 // Cell indexing, retrieval, etc.
103 // Cell indexing, retrieval, etc.
88
104
89
105
90 Notebook.prototype.cell_elements = function () {
106 Notebook.prototype.cell_elements = function () {
91 return this.element.children("div.cell");
107 return this.element.children("div.cell");
92 }
108 }
93
109
94
110
95 Notebook.prototype.ncells = function (cell) {
111 Notebook.prototype.ncells = function (cell) {
96 return this.cell_elements().length;
112 return this.cell_elements().length;
97 }
113 }
98
114
99
115
100 // 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
101 // to cells(i) or a new method.
117 // to cells(i) or a new method.
102 Notebook.prototype.cells = function () {
118 Notebook.prototype.cells = function () {
103 return this.cell_elements().toArray().map(function (e) {
119 return this.cell_elements().toArray().map(function (e) {
104 return $(e).data("cell");
120 return $(e).data("cell");
105 });
121 });
106 }
122 }
107
123
108
124
109 Notebook.prototype.find_cell_index = function (cell) {
125 Notebook.prototype.find_cell_index = function (cell) {
110 var result = null;
126 var result = null;
111 this.cell_elements().filter(function (index) {
127 this.cell_elements().filter(function (index) {
112 if ($(this).data("cell") === cell) {
128 if ($(this).data("cell") === cell) {
113 result = index;
129 result = index;
114 };
130 };
115 });
131 });
116 return result;
132 return result;
117 };
133 };
118
134
119
135
120 Notebook.prototype.index_or_selected = function (index) {
136 Notebook.prototype.index_or_selected = function (index) {
121 return index || this.selected_index() || 0;
137 return index || this.selected_index() || 0;
122 }
138 }
123
139
124
140
125 Notebook.prototype.select = function (index) {
141 Notebook.prototype.select = function (index) {
126 if (index !== undefined && index >= 0 && index < this.ncells()) {
142 if (index !== undefined && index >= 0 && index < this.ncells()) {
127 if (this.selected_index() !== null) {
143 if (this.selected_index() !== null) {
128 this.selected_cell().unselect();
144 this.selected_cell().unselect();
129 };
145 };
130 this.cells()[index].select();
146 this.cells()[index].select();
131 };
147 };
132 return this;
148 return this;
133 };
149 };
134
150
135
151
136 Notebook.prototype.select_next = function () {
152 Notebook.prototype.select_next = function () {
137 var index = this.selected_index();
153 var index = this.selected_index();
138 if (index !== null && index >= 0 && (index+1) < this.ncells()) {
154 if (index !== null && index >= 0 && (index+1) < this.ncells()) {
139 this.select(index+1);
155 this.select(index+1);
140 };
156 };
141 return this;
157 return this;
142 };
158 };
143
159
144
160
145 Notebook.prototype.select_prev = function () {
161 Notebook.prototype.select_prev = function () {
146 var index = this.selected_index();
162 var index = this.selected_index();
147 if (index !== null && index >= 0 && (index-1) < this.ncells()) {
163 if (index !== null && index >= 0 && (index-1) < this.ncells()) {
148 this.select(index-1);
164 this.select(index-1);
149 };
165 };
150 return this;
166 return this;
151 };
167 };
152
168
153
169
154 Notebook.prototype.selected_index = function () {
170 Notebook.prototype.selected_index = function () {
155 var result = null;
171 var result = null;
156 this.cell_elements().filter(function (index) {
172 this.cell_elements().filter(function (index) {
157 if ($(this).data("cell").selected === true) {
173 if ($(this).data("cell").selected === true) {
158 result = index;
174 result = index;
159 };
175 };
160 });
176 });
161 return result;
177 return result;
162 };
178 };
163
179
164
180
165 Notebook.prototype.cell_for_msg = function (msg_id) {
181 Notebook.prototype.cell_for_msg = function (msg_id) {
166 var cell_id = this.msg_cell_map[msg_id];
182 var cell_id = this.msg_cell_map[msg_id];
167 var result = null;
183 var result = null;
168 this.cell_elements().filter(function (index) {
184 this.cell_elements().filter(function (index) {
169 cell = $(this).data("cell");
185 cell = $(this).data("cell");
170 if (cell.cell_id === cell_id) {
186 if (cell.cell_id === cell_id) {
171 result = cell;
187 result = cell;
172 };
188 };
173 });
189 });
174 return result;
190 return result;
175 };
191 };
176
192
177
193
178 Notebook.prototype.selected_cell = function () {
194 Notebook.prototype.selected_cell = function () {
179 return this.cell_elements().eq(this.selected_index()).data("cell");
195 return this.cell_elements().eq(this.selected_index()).data("cell");
180 }
196 }
181
197
182
198
183 // Cell insertion, deletion and moving.
199 // Cell insertion, deletion and moving.
184
200
185
201
186 Notebook.prototype.delete_cell = function (index) {
202 Notebook.prototype.delete_cell = function (index) {
187 var i = index || this.selected_index();
203 var i = index || this.selected_index();
188 if (i !== null && i >= 0 && i < this.ncells()) {
204 if (i !== null && i >= 0 && i < this.ncells()) {
189 this.cell_elements().eq(i).remove();
205 this.cell_elements().eq(i).remove();
190 if (i === (this.ncells())) {
206 if (i === (this.ncells())) {
191 this.select(i-1);
207 this.select(i-1);
192 } else {
208 } else {
193 this.select(i);
209 this.select(i);
194 };
210 };
195 };
211 };
196 return this;
212 return this;
197 };
213 };
198
214
199
215
200 Notebook.prototype.append_cell = function (cell) {
216 Notebook.prototype.append_cell = function (cell) {
201 this.element.append(cell.element);
217 this.element.append(cell.element);
202 return this;
218 return this;
203 };
219 };
204
220
205
221
206 Notebook.prototype.insert_cell_after = function (cell, index) {
222 Notebook.prototype.insert_cell_after = function (cell, index) {
207 var ncells = this.ncells();
223 var ncells = this.ncells();
208 if (ncells === 0) {
224 if (ncells === 0) {
209 this.append_cell(cell);
225 this.append_cell(cell);
210 return this;
226 return this;
211 };
227 };
212 if (index >= 0 && index < ncells) {
228 if (index >= 0 && index < ncells) {
213 this.cell_elements().eq(index).after(cell.element);
229 this.cell_elements().eq(index).after(cell.element);
214 };
230 };
215 return this
231 return this
216 };
232 };
217
233
218
234
219 Notebook.prototype.insert_cell_before = function (cell, index) {
235 Notebook.prototype.insert_cell_before = function (cell, index) {
220 var ncells = this.ncells();
236 var ncells = this.ncells();
221 if (ncells === 0) {
237 if (ncells === 0) {
222 this.append_cell(cell);
238 this.append_cell(cell);
223 return this;
239 return this;
224 };
240 };
225 if (index >= 0 && index < ncells) {
241 if (index >= 0 && index < ncells) {
226 this.cell_elements().eq(index).before(cell.element);
242 this.cell_elements().eq(index).before(cell.element);
227 };
243 };
228 return this;
244 return this;
229 };
245 };
230
246
231
247
232 Notebook.prototype.move_cell_up = function (index) {
248 Notebook.prototype.move_cell_up = function (index) {
233 var i = index || this.selected_index();
249 var i = index || this.selected_index();
234 if (i !== null && i < this.ncells() && i > 0) {
250 if (i !== null && i < this.ncells() && i > 0) {
235 var pivot = this.cell_elements().eq(i-1);
251 var pivot = this.cell_elements().eq(i-1);
236 var tomove = this.cell_elements().eq(i);
252 var tomove = this.cell_elements().eq(i);
237 if (pivot !== null && tomove !== null) {
253 if (pivot !== null && tomove !== null) {
238 tomove.detach();
254 tomove.detach();
239 pivot.before(tomove);
255 pivot.before(tomove);
240 this.select(i-1);
256 this.select(i-1);
241 };
257 };
242 };
258 };
243 return this;
259 return this;
244 }
260 }
245
261
246
262
247 Notebook.prototype.move_cell_down = function (index) {
263 Notebook.prototype.move_cell_down = function (index) {
248 var i = index || this.selected_index();
264 var i = index || this.selected_index();
249 if (i !== null && i < (this.ncells()-1) && i >= 0) {
265 if (i !== null && i < (this.ncells()-1) && i >= 0) {
250 var pivot = this.cell_elements().eq(i+1)
266 var pivot = this.cell_elements().eq(i+1)
251 var tomove = this.cell_elements().eq(i)
267 var tomove = this.cell_elements().eq(i)
252 if (pivot !== null && tomove !== null) {
268 if (pivot !== null && tomove !== null) {
253 tomove.detach();
269 tomove.detach();
254 pivot.after(tomove);
270 pivot.after(tomove);
255 this.select(i+1);
271 this.select(i+1);
256 };
272 };
257 };
273 };
258 return this;
274 return this;
259 }
275 }
260
276
261
277
262 Notebook.prototype.sort_cells = function () {
278 Notebook.prototype.sort_cells = function () {
263 var ncells = this.ncells();
279 var ncells = this.ncells();
264 var sindex = this.selected_index();
280 var sindex = this.selected_index();
265 var swapped;
281 var swapped;
266 do {
282 do {
267 swapped = false
283 swapped = false
268 for (var i=1; i<ncells; i++) {
284 for (var i=1; i<ncells; i++) {
269 current = this.cell_elements().eq(i).data("cell");
285 current = this.cell_elements().eq(i).data("cell");
270 previous = this.cell_elements().eq(i-1).data("cell");
286 previous = this.cell_elements().eq(i-1).data("cell");
271 if (previous.input_prompt_number > current.input_prompt_number) {
287 if (previous.input_prompt_number > current.input_prompt_number) {
272 this.move_cell_up(i);
288 this.move_cell_up(i);
273 swapped = true;
289 swapped = true;
274 };
290 };
275 };
291 };
276 } while (swapped);
292 } while (swapped);
277 this.select(sindex);
293 this.select(sindex);
278 return this;
294 return this;
279 };
295 };
280
296
281
297
282 Notebook.prototype.insert_code_cell_before = function (index) {
298 Notebook.prototype.insert_code_cell_before = function (index) {
283 // TODO: Bounds check for i
299 // TODO: Bounds check for i
284 var i = this.index_or_selected(index);
300 var i = this.index_or_selected(index);
285 var cell = new IPython.CodeCell(this);
301 var cell = new IPython.CodeCell(this);
286 cell.set_input_prompt(this.next_prompt_number);
302 cell.set_input_prompt(this.next_prompt_number);
287 this.next_prompt_number = this.next_prompt_number + 1;
303 this.next_prompt_number = this.next_prompt_number + 1;
288 this.insert_cell_before(cell, i);
304 this.insert_cell_before(cell, i);
289 this.select(this.find_cell_index(cell));
305 this.select(this.find_cell_index(cell));
290 return this;
306 return this;
291 }
307 }
292
308
293
309
294 Notebook.prototype.insert_code_cell_after = function (index) {
310 Notebook.prototype.insert_code_cell_after = function (index) {
295 // TODO: Bounds check for i
311 // TODO: Bounds check for i
296 var i = this.index_or_selected(index);
312 var i = this.index_or_selected(index);
297 var cell = new IPython.CodeCell(this);
313 var cell = new IPython.CodeCell(this);
298 cell.set_input_prompt(this.next_prompt_number);
314 cell.set_input_prompt(this.next_prompt_number);
299 this.next_prompt_number = this.next_prompt_number + 1;
315 this.next_prompt_number = this.next_prompt_number + 1;
300 this.insert_cell_after(cell, i);
316 this.insert_cell_after(cell, i);
301 this.select(this.find_cell_index(cell));
317 this.select(this.find_cell_index(cell));
302 return this;
318 return this;
303 }
319 }
304
320
305
321
306 Notebook.prototype.insert_text_cell_before = function (index) {
322 Notebook.prototype.insert_text_cell_before = function (index) {
307 // TODO: Bounds check for i
323 // TODO: Bounds check for i
308 var i = this.index_or_selected(index);
324 var i = this.index_or_selected(index);
309 var cell = new IPython.TextCell(this);
325 var cell = new IPython.TextCell(this);
310 cell.config_mathjax();
326 cell.config_mathjax();
311 this.insert_cell_before(cell, i);
327 this.insert_cell_before(cell, i);
312 this.select(this.find_cell_index(cell));
328 this.select(this.find_cell_index(cell));
313 return this;
329 return this;
314 }
330 }
315
331
316
332
317 Notebook.prototype.insert_text_cell_after = function (index) {
333 Notebook.prototype.insert_text_cell_after = function (index) {
318 // TODO: Bounds check for i
334 // TODO: Bounds check for i
319 var i = this.index_or_selected(index);
335 var i = this.index_or_selected(index);
320 var cell = new IPython.TextCell(this);
336 var cell = new IPython.TextCell(this);
321 cell.config_mathjax();
337 cell.config_mathjax();
322 this.insert_cell_after(cell, i);
338 this.insert_cell_after(cell, i);
323 this.select(this.find_cell_index(cell));
339 this.select(this.find_cell_index(cell));
324 return this;
340 return this;
325 }
341 }
326
342
327
343
328 Notebook.prototype.text_to_code = function (index) {
344 Notebook.prototype.text_to_code = function (index) {
329 // TODO: Bounds check for i
345 // TODO: Bounds check for i
330 var i = this.index_or_selected(index);
346 var i = this.index_or_selected(index);
331 var source_element = this.cell_elements().eq(i);
347 var source_element = this.cell_elements().eq(i);
332 var source_cell = source_element.data("cell");
348 var source_cell = source_element.data("cell");
333 if (source_cell instanceof IPython.TextCell) {
349 if (source_cell instanceof IPython.TextCell) {
334 this.insert_code_cell_after(i);
350 this.insert_code_cell_after(i);
335 var target_cell = this.cells()[i+1];
351 var target_cell = this.cells()[i+1];
336 target_cell.set_code(source_cell.get_text());
352 target_cell.set_code(source_cell.get_text());
337 source_element.remove();
353 source_element.remove();
338 };
354 };
339 };
355 };
340
356
341
357
342 Notebook.prototype.code_to_text = function (index) {
358 Notebook.prototype.code_to_text = function (index) {
343 // TODO: Bounds check for i
359 // TODO: Bounds check for i
344 var i = this.index_or_selected(index);
360 var i = this.index_or_selected(index);
345 var source_element = this.cell_elements().eq(i);
361 var source_element = this.cell_elements().eq(i);
346 var source_cell = source_element.data("cell");
362 var source_cell = source_element.data("cell");
347 if (source_cell instanceof IPython.CodeCell) {
363 if (source_cell instanceof IPython.CodeCell) {
348 this.insert_text_cell_after(i);
364 this.insert_text_cell_after(i);
349 var target_cell = this.cells()[i+1];
365 var target_cell = this.cells()[i+1];
350 var text = source_cell.get_code();
366 var text = source_cell.get_code();
351 if (text === "") {text = target_cell.placeholder;};
367 if (text === "") {text = target_cell.placeholder;};
352 target_cell.set_text(text);
368 target_cell.set_text(text);
353 source_element.remove();
369 source_element.remove();
354 target_cell.edit();
370 target_cell.edit();
355 };
371 };
356 };
372 };
357
373
358
374
359 // Cell collapsing
375 // Cell collapsing
360
376
361 Notebook.prototype.collapse = function (index) {
377 Notebook.prototype.collapse = function (index) {
362 var i = this.index_or_selected(index);
378 var i = this.index_or_selected(index);
363 this.cells()[i].collapse();
379 this.cells()[i].collapse();
364 };
380 };
365
381
366
382
367 Notebook.prototype.expand = function (index) {
383 Notebook.prototype.expand = function (index) {
368 var i = this.index_or_selected(index);
384 var i = this.index_or_selected(index);
369 this.cells()[i].expand();
385 this.cells()[i].expand();
370 };
386 };
371
387
372
388
373 // Kernel related things
389 // Kernel related things
374
390
375 Notebook.prototype.start_kernel = function () {
391 Notebook.prototype.start_kernel = function () {
376 this.kernel = new IPython.Kernel();
392 this.kernel = new IPython.Kernel();
377 this.kernel.start_kernel($.proxy(this.kernel_started, this));
393 this.kernel.start_kernel($.proxy(this.kernel_started, this));
378 };
394 };
379
395
380
396
381 Notebook.prototype.handle_shell_reply = function (e) {
397 Notebook.prototype.handle_shell_reply = function (e) {
382 reply = $.parseJSON(e.data);
398 reply = $.parseJSON(e.data);
383 var header = reply.header;
399 var header = reply.header;
384 var content = reply.content;
400 var content = reply.content;
385 var msg_type = header.msg_type;
401 var msg_type = header.msg_type;
386 console.log(reply);
402 console.log(reply);
387 var cell = this.cell_for_msg(reply.parent_header.msg_id);
403 var cell = this.cell_for_msg(reply.parent_header.msg_id);
388 if (msg_type === "execute_reply") {
404 if (msg_type === "execute_reply") {
389 cell.set_input_prompt(content.execution_count);
405 cell.set_input_prompt(content.execution_count);
390 };
406 };
391 var payload = content.payload || [];
407 var payload = content.payload || [];
392 this.handle_payload(content.payload);
408 this.handle_payload(content.payload);
393 };
409 };
394
410
395
411
396 Notebook.prototype.handle_payload = function (payload) {
412 Notebook.prototype.handle_payload = function (payload) {
397 var l = payload.length;
413 var l = payload.length;
398 if (l > 0) {
414 if (l > 0) {
399 IPython.pager.clear();
415 IPython.pager.clear();
400 IPython.pager.expand();
416 IPython.pager.expand();
401 };
417 };
402 for (var i=0; i<l; i++) {
418 for (var i=0; i<l; i++) {
403 IPython.pager.append_text(payload[i].text);
419 IPython.pager.append_text(payload[i].text);
404 };
420 };
405 };
421 };
406
422
407
423
408 Notebook.prototype.handle_iopub_reply = function (e) {
424 Notebook.prototype.handle_iopub_reply = function (e) {
409 reply = $.parseJSON(e.data);
425 reply = $.parseJSON(e.data);
410 var content = reply.content;
426 var content = reply.content;
411 // console.log(reply);
427 // console.log(reply);
412 var msg_type = reply.header.msg_type;
428 var msg_type = reply.header.msg_type;
413 var cell = this.cell_for_msg(reply.parent_header.msg_id);
429 var cell = this.cell_for_msg(reply.parent_header.msg_id);
414 if (msg_type === "stream") {
430 if (msg_type === "stream") {
415 cell.expand();
431 cell.expand();
416 cell.append_stream(content.data + "\n");
432 cell.append_stream(content.data + "\n");
417 } else if (msg_type === "display_data") {
433 } else if (msg_type === "display_data") {
418 cell.expand();
434 cell.expand();
419 cell.append_display_data(content.data);
435 cell.append_display_data(content.data);
420 } else if (msg_type === "pyout") {
436 } else if (msg_type === "pyout") {
421 cell.expand();
437 cell.expand();
422 cell.append_pyout(content.data, content.execution_count)
438 cell.append_pyout(content.data, content.execution_count)
423 } else if (msg_type === "pyerr") {
439 } else if (msg_type === "pyerr") {
424 cell.expand();
440 cell.expand();
425 cell.append_pyerr(content.ename, content.evalue, content.traceback);
441 cell.append_pyerr(content.ename, content.evalue, content.traceback);
426 } else if (msg_type === "status") {
442 } else if (msg_type === "status") {
427 if (content.execution_state === "busy") {
443 if (content.execution_state === "busy") {
428 this.kernel.status_busy();
444 this.kernel.status_busy();
429 } else if (content.execution_state === "idle") {
445 } else if (content.execution_state === "idle") {
430 this.kernel.status_idle();
446 this.kernel.status_idle();
431 };
447 };
432 }
448 }
433 };
449 };
434
450
435
451
436 Notebook.prototype.kernel_started = function () {
452 Notebook.prototype.kernel_started = function () {
437 console.log("Kernel started: ", this.kernel.kernel_id);
453 console.log("Kernel started: ", this.kernel.kernel_id);
438 this.kernel.shell_channel.onmessage = $.proxy(this.handle_shell_reply,this);
454 this.kernel.shell_channel.onmessage = $.proxy(this.handle_shell_reply,this);
439 this.kernel.iopub_channel.onmessage = $.proxy(this.handle_iopub_reply,this);
455 this.kernel.iopub_channel.onmessage = $.proxy(this.handle_iopub_reply,this);
440 };
456 };
441
457
442
458
443 // Persistance and loading
459 // Persistance and loading
444
460
445
461
446 Notebook.prototype.fromJSON = function (data) {
462 Notebook.prototype.fromJSON = function (data) {
447 var ncells = this.ncells();
463 var ncells = this.ncells();
448 for (var i=0; i<ncells; i++) {
464 for (var i=0; i<ncells; i++) {
449 // Always delete cell 0 as they get renumbered as they are deleted.
465 // Always delete cell 0 as they get renumbered as they are deleted.
450 this.delete_cell(0);
466 this.delete_cell(0);
451 };
467 };
452 var new_cells = data.cells;
468 var new_cells = data.cells;
453 ncells = new_cells.length;
469 ncells = new_cells.length;
454 var cell_data = null;
470 var cell_data = null;
455 for (var i=0; i<ncells; i++) {
471 for (var i=0; i<ncells; i++) {
456 cell_data = new_cells[i];
472 cell_data = new_cells[i];
457 if (cell_data.cell_type == 'code') {
473 if (cell_data.cell_type == 'code') {
458 this.insert_code_cell_after();
474 this.insert_code_cell_after();
459 this.selected_cell().fromJSON(cell_data);
475 this.selected_cell().fromJSON(cell_data);
460 } else if (cell_data.cell_type === 'text') {
476 } else if (cell_data.cell_type === 'text') {
461 this.insert_text_cell_after();
477 this.insert_text_cell_after();
462 this.selected_cell().fromJSON(cell_data);
478 this.selected_cell().fromJSON(cell_data);
463 };
479 };
464 };
480 };
465 };
481 };
466
482
467
483
468 Notebook.prototype.toJSON = function () {
484 Notebook.prototype.toJSON = function () {
469 var cells = this.cells();
485 var cells = this.cells();
470 var ncells = cells.length;
486 var ncells = cells.length;
471 cell_array = new Array(ncells);
487 cell_array = new Array(ncells);
472 for (var i=0; i<ncells; i++) {
488 for (var i=0; i<ncells; i++) {
473 cell_array[i] = cells[i].toJSON();
489 cell_array[i] = cells[i].toJSON();
474 };
490 };
475 json = {
491 json = {
476 cells : cell_array
492 cells : cell_array
477 };
493 };
478 return json
494 return json
479 };
495 };
480
496
481
497
482 Notebook.prototype.test_filename = function (filename) {
498 Notebook.prototype.test_filename = function (filename) {
483 if (this.notebook_filename_re.test(filename)) {
499 if (this.notebook_filename_re.test(filename)) {
484 return true;
500 return true;
485 } else {
501 } else {
486 var bad_filename = $('<div/>');
502 var bad_filename = $('<div/>');
487 bad_filename.html(
503 bad_filename.html(
488 "The filename you entered (" + filename + ") is not valid. Notebook filenames must have the following form: foo.ipynb"
504 "The filename you entered (" + filename + ") is not valid. Notebook filenames must have the following form: foo.ipynb"
489 );
505 );
490 bad_filename.dialog({title: 'Invalid filename', modal: true});
506 bad_filename.dialog({title: 'Invalid filename', modal: true});
491 return false;
507 return false;
492 };
508 };
493 };
509 };
494
510
495 Notebook.prototype.save_notebook = function (filename) {
511 Notebook.prototype.save_notebook = function (filename) {
496 this.filename = filename || this.filename || '';
512 this.filename = filename || this.filename || '';
497 if (this.filename === '') {
513 if (this.filename === '') {
498 var no_filename = $('<div/>');
514 var no_filename = $('<div/>');
499 no_filename.html(
515 no_filename.html(
500 "This notebook has no filename, please specify a filename of the form: foo.ipynb"
516 "This notebook has no filename, please specify a filename of the form: foo.ipynb"
501 );
517 );
502 no_filename.dialog({title: 'Missing filename', modal: true});
518 no_filename.dialog({title: 'Missing filename', modal: true});
503 return;
519 return;
504 }
520 }
505 if (!this.test_filename(this.filename)) {return;}
521 if (!this.test_filename(this.filename)) {return;}
506 var thedata = this.toJSON();
522 var thedata = this.toJSON();
507 var settings = {
523 var settings = {
508 processData : false,
524 processData : false,
509 cache : false,
525 cache : false,
510 type : "PUT",
526 type : "PUT",
511 data : JSON.stringify(thedata),
527 data : JSON.stringify(thedata),
512 success : function (data, status, xhr) {console.log(data);}
528 success : function (data, status, xhr) {console.log(data);}
513 };
529 };
514 $.ajax("/notebooks/" + this.filename, settings);
530 $.ajax("/notebooks/" + this.filename, settings);
515 };
531 };
516
532
517
533
518 Notebook.prototype.load_notebook = function (filename) {
534 Notebook.prototype.load_notebook = function (filename) {
519 if (!this.test_filename(filename)) {return;}
535 if (!this.test_filename(filename)) {return;}
520 var that = this;
536 var that = this;
521 // We do the call with settings so we can set cache to false.
537 // We do the call with settings so we can set cache to false.
522 var settings = {
538 var settings = {
523 processData : false,
539 processData : false,
524 cache : false,
540 cache : false,
525 type : "GET",
541 type : "GET",
526 dataType : "json",
542 dataType : "json",
527 success : function (data, status, xhr) {
543 success : function (data, status, xhr) {
528 that.fromJSON(data);
544 that.fromJSON(data);
529 that.filename = filename;
545 that.filename = filename;
530 that.kernel.restart();
546 that.kernel.restart();
531 }
547 }
532 };
548 };
533 $.ajax("/notebooks/" + filename, settings);
549 $.ajax("/notebooks/" + filename, settings);
534 }
550 }
535
551
536 IPython.Notebook = Notebook;
552 IPython.Notebook = Notebook;
537
553
538 return IPython;
554 return IPython;
539
555
540 }(IPython));
556 }(IPython));
541
557
@@ -1,96 +1,101 b''
1
1
2 //============================================================================
2 //============================================================================
3 // On document ready
3 // On document ready
4 //============================================================================
4 //============================================================================
5
5
6
6
7 $(document).ready(function () {
7 $(document).ready(function () {
8
8
9
9
10 $('div#notebook_app').addClass('ui-widget ui-widget-content')
10 $('div#notebook_app').addClass('border-box-sizing ui-widget ui-widget-content');
11 $('div#left_panel').addClass('ui-widget')
11 $('div#left_panel').addClass('border-box-sizing ui-widget');
12 $('div#left_panel_splitter').addClass('ui-widget ui-widget-content')
12 $('div#left_panel_splitter').addClass('border-box-sizing ui-widget ui-state-default');
13 $('div#notebook_panel').addClass('ui-widget')
13 $('div#notebook_panel').addClass('border-box-sizing ui-widget');
14 $('div#notebook').addClass('border-box-sizing');
14
15
15 $('div#left_panel_splitter').click(function () {
16 $('div#left_panel_splitter').click(function () {
16 $('div#left_panel').toggle('fast');
17 $('div#left_panel').toggle('fast');
17 });
18 });
18
19
19 $('div#left_panel_splitter').hover(
20 $('div#left_panel_splitter').hover(
20 function () {
21 function () {
21 $('div#left_panel_splitter').addClass('ui-state-hover');
22 $('div#left_panel_splitter').addClass('ui-state-hover');
22 },
23 },
23 function () {
24 function () {
24 $('div#left_panel_splitter').removeClass('ui-state-hover');
25 $('div#left_panel_splitter').removeClass('ui-state-hover');
25 }
26 }
26 );
27 );
27
28
28 MathJax.Hub.Config({
29 MathJax.Hub.Config({
29 tex2jax: {
30 tex2jax: {
30 inlineMath: [ ['$','$'], ["\\(","\\)"] ],
31 inlineMath: [ ['$','$'], ["\\(","\\)"] ],
31 displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
32 displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
32 },
33 },
33 displayAlign: 'left', // Change this to 'center' to center equations.
34 displayAlign: 'left', // Change this to 'center' to center equations.
34 "HTML-CSS": {
35 "HTML-CSS": {
35 styles: {'.MathJax_Display': {"margin": 0}}
36 styles: {'.MathJax_Display': {"margin": 0}}
36 }
37 }
37 });
38 });
38
39
39 var do_resize = function () {
40 var do_resize = function () {
40 var win = $(window);
41 var win = $(window);
41 var w = win.width();
42 var w = win.width();
42 var h = win.height();
43 var h = win.height();
43 var app_height = h - 50;
44 var header_height = $('div#header').outerHeight(true);
44 $('div#notebook_app').height(app_height);
45 var app_height = h - header_height - 2;
46 var pager_height = $('div#pager').outerHeight(true);
47 var pager_splitter_height = $('div#pager_splitter').outerHeight(true);
48 $('div#notebook_app').height(app_height + 2);
45 $('div#left_panel').height(app_height);
49 $('div#left_panel').height(app_height);
46 $('div#left_panel_splitter').height(app_height);
50 $('div#left_panel_splitter').height(app_height);
47 $('div#notebook_panel').height(app_height);
51 $('div#notebook_panel').height(app_height);
48 $('div#notebook').height(app_height-211);
52 $('div#notebook').height(app_height-pager_height-pager_splitter_height);
53 console.log('resize: ', app_height);
49 };
54 };
50
55
51 $(window).resize(do_resize);
56 $(window).resize(do_resize);
52
57
53 IPython.notebook = new IPython.Notebook('div#notebook');
58 IPython.notebook = new IPython.Notebook('div#notebook');
54 IPython.notebook.insert_code_cell_after();
59 IPython.notebook.insert_code_cell_after();
55
60
56 IPython.pager = new IPython.Pager('div#pager', 'div#pager_splitter');
61 IPython.pager = new IPython.Pager('div#pager', 'div#pager_splitter');
57
62
58 do_resize();
63 do_resize();
59
64
60 // $("#menu_tabs").tabs();
65 // $("#menu_tabs").tabs();
61
66
62 // $("#help_toolbar").buttonset();
67 // $("#help_toolbar").buttonset();
63
68
64 // $("#kernel_toolbar").buttonset();
69 // $("#kernel_toolbar").buttonset();
65 // $("#interrupt_kernel").click(function () {IPython.notebook.kernel.interrupt();});
70 // $("#interrupt_kernel").click(function () {IPython.notebook.kernel.interrupt();});
66 // $("#restart_kernel").click(function () {IPython.notebook.kernel.restart();});
71 // $("#restart_kernel").click(function () {IPython.notebook.kernel.restart();});
67 // $("#kernel_status").addClass("status_idle");
72 // $("#kernel_status").addClass("status_idle");
68
73
69 // $("#move_cell").buttonset();
74 // $("#move_cell").buttonset();
70 // $("#move_up").button("option", "icons", {primary:"ui-icon-arrowthick-1-n"});
75 // $("#move_up").button("option", "icons", {primary:"ui-icon-arrowthick-1-n"});
71 // $("#move_up").button("option", "text", false);
76 // $("#move_up").button("option", "text", false);
72 // $("#move_up").click(function () {IPython.notebook.move_cell_up();});
77 // $("#move_up").click(function () {IPython.notebook.move_cell_up();});
73 // $("#move_down").button("option", "icons", {primary:"ui-icon-arrowthick-1-s"});
78 // $("#move_down").button("option", "icons", {primary:"ui-icon-arrowthick-1-s"});
74 // $("#move_down").button("option", "text", false);
79 // $("#move_down").button("option", "text", false);
75 // $("#move_down").click(function () {IPython.notebook.move_cell_down();});
80 // $("#move_down").click(function () {IPython.notebook.move_cell_down();});
76
81
77 // $("#insert_delete").buttonset();
82 // $("#insert_delete").buttonset();
78 // $("#insert_cell_before").click(function () {IPython.notebook.insert_code_cell_before();});
83 // $("#insert_cell_before").click(function () {IPython.notebook.insert_code_cell_before();});
79 // $("#insert_cell_after").click(function () {IPython.notebook.insert_code_cell_after();});
84 // $("#insert_cell_after").click(function () {IPython.notebook.insert_code_cell_after();});
80 // $("#delete_cell").button("option", "icons", {primary:"ui-icon-closethick"});
85 // $("#delete_cell").button("option", "icons", {primary:"ui-icon-closethick"});
81 // $("#delete_cell").button("option", "text", false);
86 // $("#delete_cell").button("option", "text", false);
82 // $("#delete_cell").click(function () {IPython.notebook.delete_cell();});
87 // $("#delete_cell").click(function () {IPython.notebook.delete_cell();});
83
88
84 // $("#cell_type").buttonset();
89 // $("#cell_type").buttonset();
85 // $("#to_code").click(function () {IPython.notebook.text_to_code();});
90 // $("#to_code").click(function () {IPython.notebook.text_to_code();});
86 // $("#to_text").click(function () {IPython.notebook.code_to_text();});
91 // $("#to_text").click(function () {IPython.notebook.code_to_text();});
87
92
88 // $("#sort").buttonset();
93 // $("#sort").buttonset();
89 // $("#sort_cells").click(function () {IPython.notebook.sort_cells();});
94 // $("#sort_cells").click(function () {IPython.notebook.sort_cells();});
90
95
91 // $("#toggle").buttonset();
96 // $("#toggle").buttonset();
92 // $("#collapse").click(function () {IPython.notebook.collapse();});
97 // $("#collapse").click(function () {IPython.notebook.collapse();});
93 // $("#expand").click(function () {IPython.notebook.expand();});
98 // $("#expand").click(function () {IPython.notebook.expand();});
94
99
95 });
100 });
96
101
@@ -1,70 +1,94 b''
1
1
2 //============================================================================
2 //============================================================================
3 // Pager
3 // Pager
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 Pager = function (pager_selector, pager_toggle_selector) {
10 var Pager = function (pager_selector, pager_toggle_selector) {
11 this.pager_element = $(pager_selector);
11 this.pager_element = $(pager_selector);
12 this.pager_toggle_element = $(pager_toggle_selector);
12 this.pager_toggle_element = $(pager_toggle_selector);
13 this.expanded = true;
13 this.style();
14 this.style();
14 this.bind_events();
15 this.bind_events();
15 this.collapse();
16 };
16 };
17
17
18
18
19 Pager.prototype.style = function () {
19 Pager.prototype.style = function () {
20 this.pager_toggle_element.addClass('ui-widget ui-widget-content')
20 this.pager_toggle_element.addClass('border-box-sizing ui-widget ui-state-default');
21 this.pager_element.addClass('')
21 this.pager_element.addClass('border-box-sizing ui-widget');
22 };
22 };
23
23
24
24
25 Pager.prototype.bind_events = function () {
25 Pager.prototype.bind_events = function () {
26 var that = this;
26 var that = this;
27 this.pager_toggle_element.click(function () {
27
28 that.pager_element.toggle('fast');
28 this.pager_element.bind('collapse_pager', function () {
29 that.pager_element.hide('fast');
30 });
31
32 this.pager_element.bind('expand_pager', function () {
33 that.pager_element.show('fast');
29 });
34 });
30
35
31 this.pager_toggle_element.hover(
36 this.pager_toggle_element.hover(
32 function () {
37 function () {
33 that.pager_toggle_element.addClass('ui-state-hover');
38 that.pager_toggle_element.addClass('ui-state-hover');
34 },
39 },
35 function () {
40 function () {
36 that.pager_toggle_element.removeClass('ui-state-hover');
41 that.pager_toggle_element.removeClass('ui-state-hover');
37 }
42 }
38 );
43 );
44
45 this.pager_toggle_element.click(function () {
46 that.toggle();
47 });
39 };
48 };
40
49
41
50
42 Pager.prototype.collapse = function () {
51 Pager.prototype.collapse = function () {
43 this.pager_element.hide('fast');
52 if (this.expanded === true) {
53 this.pager_element.add($('div#notebook')).trigger('collapse_pager');
54 this.expanded = false;
55 };
44 };
56 };
45
57
46
58
47 Pager.prototype.expand = function () {
59 Pager.prototype.expand = function () {
48 this.pager_element.show('fast');
60 if (this.expanded !== true) {
61 this.pager_element.add($('div#notebook')).trigger('expand_pager');
62 this.expanded = true;
63 };
64 };
65
66
67 Pager.prototype.toggle = function () {
68 if (this.expanded === true) {
69 this.collapse();
70 } else {
71 this.expand();
72 };
49 };
73 };
50
74
51
75
52 Pager.prototype.clear = function (text) {
76 Pager.prototype.clear = function (text) {
53 this.pager_element.empty();
77 this.pager_element.empty();
54 };
78 };
55
79
56
80
57 Pager.prototype.append_text = function (text) {
81 Pager.prototype.append_text = function (text) {
58 var toinsert = $("<div/>").addClass("output_area output_stream monospace-font");
82 var toinsert = $("<div/>").addClass("output_area output_stream monospace-font");
59 toinsert.append($("<pre/>").addClass("monospace-font").
83 toinsert.append($("<pre/>").addClass("monospace-font").
60 html(utils.fixConsole(text)));
84 html(utils.fixConsole(text)));
61 this.pager_element.append(toinsert);
85 this.pager_element.append(toinsert);
62 };
86 };
63
87
64
88
65 IPython.Pager = Pager;
89 IPython.Pager = Pager;
66
90
67 return IPython;
91 return IPython;
68
92
69 }(IPython));
93 }(IPython));
70
94
@@ -1,72 +1,92 b''
1
1
2 //============================================================================
2 //============================================================================
3 // Utilities
3 // Utilities
4 //============================================================================
4 //============================================================================
5
5
6 IPython.namespace('IPython.utils')
6 IPython.namespace('IPython.utils')
7
7
8 IPython.utils = (function (IPython) {
8 IPython.utils = (function (IPython) {
9
9
10 var uuid = function () {
10 var uuid = function () {
11 // http://www.ietf.org/rfc/rfc4122.txt
11 // http://www.ietf.org/rfc/rfc4122.txt
12 var s = [];
12 var s = [];
13 var hexDigits = "0123456789ABCDEF";
13 var hexDigits = "0123456789ABCDEF";
14 for (var i = 0; i < 32; i++) {
14 for (var i = 0; i < 32; i++) {
15 s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
15 s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
16 }
16 }
17 s[12] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
17 s[12] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
18 s[16] = hexDigits.substr((s[16] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
18 s[16] = hexDigits.substr((s[16] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
19
19
20 var uuid = s.join("");
20 var uuid = s.join("");
21 return uuid;
21 return uuid;
22 };
22 };
23
23
24
24
25 //Fix raw text to parse correctly in crazy XML
25 //Fix raw text to parse correctly in crazy XML
26 function xmlencode(string) {
26 function xmlencode(string) {
27 return string.replace(/\&/g,'&'+'amp;')
27 return string.replace(/\&/g,'&'+'amp;')
28 .replace(/</g,'&'+'lt;')
28 .replace(/</g,'&'+'lt;')
29 .replace(/>/g,'&'+'gt;')
29 .replace(/>/g,'&'+'gt;')
30 .replace(/\'/g,'&'+'apos;')
30 .replace(/\'/g,'&'+'apos;')
31 .replace(/\"/g,'&'+'quot;')
31 .replace(/\"/g,'&'+'quot;')
32 .replace(/`/g,'&'+'#96;')
32 .replace(/`/g,'&'+'#96;')
33 }
33 }
34
34
35
35 //Map from terminal commands to CSS classes
36 //Map from terminal commands to CSS classes
36 attrib = {
37 attrib = {
37 "30":"cblack", "31":"cred",
38 "30":"cblack", "31":"cred",
38 "32":"cgreen", "33":"cyellow",
39 "32":"cgreen", "33":"cyellow",
39 "34":"cblue", "36":"ccyan",
40 "34":"cblue", "36":"ccyan",
40 "37":"cwhite", "01":"cbold"}
41 "37":"cwhite", "01":"cbold"}
41
42
42 //Fixes escaped console commands, IE colors. Turns them into HTML
43 //Fixes escaped console commands, IE colors. Turns them into HTML
43 function fixConsole(txt) {
44 function fixConsole(txt) {
44 txt = xmlencode(txt)
45 txt = xmlencode(txt)
45 var re = /\033\[([\d;]*?)m/
46 var re = /\033\[([\d;]*?)m/
46 var opened = false
47 var opened = false
47 var cmds = []
48 var cmds = []
48 var opener = ""
49 var opener = ""
49 var closer = ""
50 var closer = ""
50
51
51 while (re.test(txt)) {
52 while (re.test(txt)) {
52 var cmds = txt.match(re)[1].split(";")
53 var cmds = txt.match(re)[1].split(";")
53 closer = opened?"</span>":""
54 closer = opened?"</span>":""
54 opened = cmds.length > 1 || cmds[0] != 0
55 opened = cmds.length > 1 || cmds[0] != 0
55 var rep = []
56 var rep = []
56 for (var i in cmds)
57 for (var i in cmds)
57 if (typeof(attrib[cmds[i]]) != "undefined")
58 if (typeof(attrib[cmds[i]]) != "undefined")
58 rep.push(attrib[cmds[i]])
59 rep.push(attrib[cmds[i]])
59 opener = rep.length > 0?"<span class=\""+rep.join(" ")+"\">":""
60 opener = rep.length > 0?"<span class=\""+rep.join(" ")+"\">":""
60 txt = txt.replace(re, closer + opener)
61 txt = txt.replace(re, closer + opener)
61 }
62 }
62 if (opened) txt += "</span>"
63 if (opened) txt += "</span>"
63 return txt.trim()
64 return txt.trim()
64 }
65 }
65
66
67
68 grow = function(element) {
69 // Grow the cell by hand. This is used upon reloading from JSON, when the
70 // autogrow handler is not called.
71 var dom = element.get(0);
72 var lines_count = 0;
73 // modified split rule from
74 // http://stackoverflow.com/questions/2035910/how-to-get-the-number-of-lines-in-a-textarea/2036424#2036424
75 var lines = dom.value.split(/\r|\r\n|\n/);
76 lines_count = lines.length;
77 if (lines_count >= 1) {
78 dom.rows = lines_count;
79 } else {
80 dom.rows = 1;
81 }
82 };
83
84
66 return {
85 return {
67 uuid : uuid,
86 uuid : uuid,
68 fixConsole : fixConsole
87 fixConsole : fixConsole,
88 grow : grow
69 }
89 }
70
90
71 }(IPython));
91 }(IPython));
72
92
@@ -1,120 +1,120 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/layout.css" type="text/css" />
25 <link rel="stylesheet" href="static/css/layout.css" type="text/css" />
26 <link rel="stylesheet" href="static/css/notebook.css" type="text/css" />
26 <link rel="stylesheet" href="static/css/notebook.css" type="text/css" />
27
27
28 </head>
28 </head>
29
29
30 <body>
30 <body>
31
31
32 <div id="header">
32 <div id="header">
33 <span id="ipython_notebook"><h1>IPython Notebook</h1></span>
33 <span id="ipython_notebook"><h1>IPython Notebook</h1></span>
34 </div>
34 </div>
35
35
36 <div id="notebook_app">
36 <div id="notebook_app">
37
37
38 <div id="left_panel"></div>
38 <div id="left_panel"></div>
39 <div id="left_panel_splitter"></div>
39 <div id="left_panel_splitter"></div>
40 <div id="notebook_panel">
40 <div id="notebook_panel">
41 <div id="notebook"></div>
41 <div id="notebook"></div>
42 <div id="pager_splitter"></div>
42 <div id="pager_splitter"></div>
43 <div id="pager"></div>
43 <div id="pager"></div>
44 </div>
44 </div>
45
45
46 </div>
46 </div>
47
47
48 <script src="static/jquery/js/jquery-1.6.2.min.js" type="text/javascript" charset="utf-8"></script>
48 <script src="static/jquery/js/jquery-1.6.2.min.js" type="text/javascript" charset="utf-8"></script>
49 <script src="static/jquery/js/jquery-ui-1.8.14.custom.min.js" type="text/javascript" charset="utf-8"></script>
49 <script src="static/jquery/js/jquery-ui-1.8.14.custom.min.js" type="text/javascript" charset="utf-8"></script>
50 <script src="static/jquery/js/jquery.autogrow.js" type="text/javascript" charset="utf-8"></script>
50 <script src="static/jquery/js/jquery.autogrow.js" type="text/javascript" charset="utf-8"></script>
51 <script src="static/js/namespace.js" type="text/javascript" charset="utf-8"></script>
51 <script src="static/js/namespace.js" type="text/javascript" charset="utf-8"></script>
52 <script src="static/js/utils.js" type="text/javascript" charset="utf-8"></script>
52 <script src="static/js/utils.js" type="text/javascript" charset="utf-8"></script>
53 <script src="static/js/cell.js" type="text/javascript" charset="utf-8"></script>
53 <script src="static/js/cell.js" type="text/javascript" charset="utf-8"></script>
54 <script src="static/js/codecell.js" type="text/javascript" charset="utf-8"></script>
54 <script src="static/js/codecell.js" type="text/javascript" charset="utf-8"></script>
55 <script src="static/js/textcell.js" type="text/javascript" charset="utf-8"></script>
55 <script src="static/js/textcell.js" type="text/javascript" charset="utf-8"></script>
56 <script src="static/js/kernel.js" type="text/javascript" charset="utf-8"></script>
56 <script src="static/js/kernel.js" type="text/javascript" charset="utf-8"></script>
57 <script src="static/js/pager.js" type="text/javascript" charset="utf-8"></script>
57 <script src="static/js/pager.js" type="text/javascript" charset="utf-8"></script>
58 <script src="static/js/notebook.js" type="text/javascript" charset="utf-8"></script>
58 <script src="static/js/notebook.js" type="text/javascript" charset="utf-8"></script>
59 <script src="static/js/notebook_main.js" type="text/javascript" charset="utf-8"></script>
59 <script src="static/js/notebook_main.js" type="text/javascript" charset="utf-8"></script>
60 <script src="static/codemirror2/lib/codemirror.js"></script>
60 <script src="static/codemirror2/lib/codemirror.js"></script>
61 <script src="static/codemirror2/mode/python/python.js"></script>
61 <script src="static/codemirror2/mode/python/python.js"></script>
62
62
63 </body>
63 </body>
64
64
65 </html>
65 </html>
66
66
67
67
68 <!--<div id="tools">-->
68 <!--<div id="tools">-->
69
69
70 <!--<div id="menu_tabs">-->
70 <!--<div id="menu_tabs">-->
71 <!-- <span id="kernel_status">Idle</span>-->
71 <!-- <span id="kernel_status">Idle</span>-->
72 <!-- <ul>-->
72 <!-- <ul>-->
73 <!-- <li><a href="#cell_tab">Cell</a></li>-->
73 <!-- <li><a href="#cell_tab">Cell</a></li>-->
74 <!-- <li><a href="#kernel_tab">Kernel</a></li>-->
74 <!-- <li><a href="#kernel_tab">Kernel</a></li>-->
75 <!-- <li><a href="#help_tab">Help</a></li>-->
75 <!-- <li><a href="#help_tab">Help</a></li>-->
76 <!-- </ul>-->
76 <!-- </ul>-->
77 <!-- <div id="cell_tab">-->
77 <!-- <div id="cell_tab">-->
78 <!-- <span id="cell_toolbar">-->
78 <!-- <span id="cell_toolbar">-->
79 <!-- <span id="move_cell">-->
79 <!-- <span id="move_cell">-->
80 <!-- <button id="move_up">Move up</button>-->
80 <!-- <button id="move_up">Move up</button>-->
81 <!-- <button id="move_down">Move down</button>-->
81 <!-- <button id="move_down">Move down</button>-->
82 <!-- </span>-->
82 <!-- </span>-->
83 <!-- <span id="insert_delete">-->
83 <!-- <span id="insert_delete">-->
84 <!-- <button id="insert_cell_before">Before</button>-->
84 <!-- <button id="insert_cell_before">Before</button>-->
85 <!-- <button id="insert_cell_after">After</button>-->
85 <!-- <button id="insert_cell_after">After</button>-->
86 <!-- <button id="delete_cell">Delete</button>-->
86 <!-- <button id="delete_cell">Delete</button>-->
87 <!-- </span>-->
87 <!-- </span>-->
88 <!-- <span id="cell_type">-->
88 <!-- <span id="cell_type">-->
89 <!-- <button id="to_code">Code</button>-->
89 <!-- <button id="to_code">Code</button>-->
90 <!-- <button id="to_text">Text</button>-->
90 <!-- <button id="to_text">Text</button>-->
91 <!-- </span>-->
91 <!-- </span>-->
92 <!-- <span id="sort">-->
92 <!-- <span id="sort">-->
93 <!-- <button id="sort_cells">Sort</button>-->
93 <!-- <button id="sort_cells">Sort</button>-->
94 <!-- </span>-->
94 <!-- </span>-->
95 <!-- <span id="toggle">-->
95 <!-- <span id="toggle">-->
96 <!-- <button id="collapse">Collapse</button>-->
96 <!-- <button id="collapse">Collapse</button>-->
97 <!-- <button id="expand">Expand</button>-->
97 <!-- <button id="expand">Expand</button>-->
98 <!-- </span>-->
98 <!-- </span>-->
99 <!-- </span>-->
99 <!-- </span>-->
100 <!-- </div>-->
100 <!-- </div>-->
101 <!-- <div id="kernel_tab">-->
101 <!-- <div id="kernel_tab">-->
102 <!-- <span id="kernel_toolbar">-->
102 <!-- <span id="kernel_toolbar">-->
103 <!-- <button id="interrupt_kernel">Interrupt</button>-->
103 <!-- <button id="interrupt_kernel">Interrupt</button>-->
104 <!-- <button id="restart_kernel">Restart</button>-->
104 <!-- <button id="restart_kernel">Restart</button>-->
105 <!-- </span>-->
105 <!-- </span>-->
106 <!-- </div>-->
106 <!-- </div>-->
107 <!-- <div id="help_tab">-->
107 <!-- <div id="help_tab">-->
108 <!-- <span id="help_toolbar">-->
108 <!-- <span id="help_toolbar">-->
109 <!-- <button><a href="http://docs.python.org" target="_blank">Python</a></button>-->
109 <!-- <button><a href="http://docs.python.org" target="_blank">Python</a></button>-->
110 <!-- <button><a href="http://ipython.github.com/ipython-doc/dev/index.html" target="_blank">IPython</a></button>-->
110 <!-- <button><a href="http://ipython.github.com/ipython-doc/dev/index.html" target="_blank">IPython</a></button>-->
111 <!-- <button><a href="http://matplotlib.sourceforge.net/" target="_blank">Matplotlib</a></button>-->
111 <!-- <button><a href="http://matplotlib.sourceforge.net/" target="_blank">Matplotlib</a></button>-->
112 <!-- <button><a href="http://docs.scipy.org/doc/numpy/reference/" target="_blank">NumPy</a></button>-->
112 <!-- <button><a href="http://docs.scipy.org/doc/numpy/reference/" target="_blank">NumPy</a></button>-->
113 <!-- <button><a href="http://docs.scipy.org/doc/scipy/reference/" target="_blank">SciPy</a></button>-->
113 <!-- <button><a href="http://docs.scipy.org/doc/scipy/reference/" target="_blank">SciPy</a></button>-->
114 <!-- <button><a href="http://docs.sympy.org/dev/index.html" target="_blank">SymPy</a></button>-->
114 <!-- <button><a href="http://docs.sympy.org/dev/index.html" target="_blank">SymPy</a></button>-->
115 <!-- </span>-->
115 <!-- </span>-->
116 <!-- </div>-->
116 <!-- </div>-->
117 <!--</div>-->
117 <!--</div>-->
118
118
119 <!--</div>-->
119 <!--</div>-->
120
120
General Comments 0
You need to be logged in to leave comments. Login now