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