Show More
@@ -0,0 +1,31 | |||
|
1 | //---------------------------------------------------------------------------- | |
|
2 | // Copyright (C) 2008-2011 The IPython Development Team | |
|
3 | // | |
|
4 | // Distributed under the terms of the BSD License. The full license is in | |
|
5 | // the file COPYING, distributed as part of this software. | |
|
6 | //---------------------------------------------------------------------------- | |
|
7 | ||
|
8 | //============================================================================ | |
|
9 | // Events | |
|
10 | //============================================================================ | |
|
11 | ||
|
12 | // Give us an object to bind all events to. This object should be created | |
|
13 | // before all other objects so it exists when others register event handlers. | |
|
14 | // To trigger an event handler: | |
|
15 | // $([IPython.events]).trigger('event.Namespace); | |
|
16 | // To handle it: | |
|
17 | // $([IPython.events]).on('event.Namespace',function () {}); | |
|
18 | ||
|
19 | var IPython = (function (IPython) { | |
|
20 | ||
|
21 | var utils = IPython.utils; | |
|
22 | ||
|
23 | var Events = function () {}; | |
|
24 | ||
|
25 | IPython.Events = Events; | |
|
26 | IPython.events = new Events(); | |
|
27 | ||
|
28 | return IPython; | |
|
29 | ||
|
30 | }(IPython)); | |
|
31 |
@@ -0,0 +1,102 | |||
|
1 | //---------------------------------------------------------------------------- | |
|
2 | // Copyright (C) 2008-2011 The IPython Development Team | |
|
3 | // | |
|
4 | // Distributed under the terms of the BSD License. The full license is in | |
|
5 | // the file COPYING, distributed as part of this software. | |
|
6 | //---------------------------------------------------------------------------- | |
|
7 | ||
|
8 | //============================================================================ | |
|
9 | // Notification widget | |
|
10 | //============================================================================ | |
|
11 | ||
|
12 | var IPython = (function (IPython) { | |
|
13 | ||
|
14 | var utils = IPython.utils; | |
|
15 | ||
|
16 | ||
|
17 | var NotificationWidget = function (selector) { | |
|
18 | this.selector = selector; | |
|
19 | this.timeout = null; | |
|
20 | this.busy = false; | |
|
21 | if (this.selector !== undefined) { | |
|
22 | this.element = $(selector); | |
|
23 | this.style(); | |
|
24 | this.bind_events(); | |
|
25 | } | |
|
26 | }; | |
|
27 | ||
|
28 | ||
|
29 | NotificationWidget.prototype.style = function () { | |
|
30 | this.element.addClass('ui-widget ui-widget-content ui-corner-all'); | |
|
31 | this.element.addClass('border-box-sizing'); | |
|
32 | }; | |
|
33 | ||
|
34 | ||
|
35 | NotificationWidget.prototype.bind_events = function () { | |
|
36 | var that = this; | |
|
37 | // Kernel events | |
|
38 | $([IPython.events]).on('status_idle.Kernel',function () { | |
|
39 | IPython.save_widget.update_document_title(); | |
|
40 | if (that.get_message() === 'Kernel busy') { | |
|
41 | that.element.fadeOut(100, function () { | |
|
42 | that.element.html(''); | |
|
43 | }); | |
|
44 | }; | |
|
45 | }); | |
|
46 | $([IPython.events]).on('status_busy.Kernel',function () { | |
|
47 | window.document.title='(Busy) '+window.document.title; | |
|
48 | that.set_message("Kernel busy"); | |
|
49 | }); | |
|
50 | $([IPython.events]).on('status_restarting.Kernel',function () { | |
|
51 | that.set_message("Restarting kernel",500); | |
|
52 | }); | |
|
53 | $([IPython.events]).on('status_interrupting.Kernel',function () { | |
|
54 | that.set_message("Interrupting kernel",500); | |
|
55 | }); | |
|
56 | // Notebook events | |
|
57 | $([IPython.events]).on('notebook_loading.Notebook', function () { | |
|
58 | that.set_message("Loading notebook",500); | |
|
59 | }); | |
|
60 | $([IPython.events]).on('notebook_loaded.Notebook', function () { | |
|
61 | that.set_message("Notebook loaded",500); | |
|
62 | }); | |
|
63 | $([IPython.events]).on('notebook_saving.Notebook', function () { | |
|
64 | that.set_message("Saving notebook",500); | |
|
65 | }); | |
|
66 | $([IPython.events]).on('notebook_saved.Notebook', function () { | |
|
67 | that.set_message("Notebook saved",500); | |
|
68 | }); | |
|
69 | $([IPython.events]).on('notebook_save_failed.Notebook', function () { | |
|
70 | that.set_message("Notebook save failed",500); | |
|
71 | }); | |
|
72 | }; | |
|
73 | ||
|
74 | ||
|
75 | NotificationWidget.prototype.set_message = function (msg, timeout) { | |
|
76 | var that = this; | |
|
77 | this.element.html(msg); | |
|
78 | this.element.fadeIn(100); | |
|
79 | if (this.timeout !== null) { | |
|
80 | clearTimeout(this.timeout); | |
|
81 | this.timeout = null; | |
|
82 | }; | |
|
83 | if (timeout !== undefined) { | |
|
84 | this.timeout = setTimeout(function () { | |
|
85 | that.element.fadeOut(100, function () {that.element.html('');}); | |
|
86 | that.timeout = null; | |
|
87 | }, timeout) | |
|
88 | }; | |
|
89 | }; | |
|
90 | ||
|
91 | ||
|
92 | NotificationWidget.prototype.get_message = function () { | |
|
93 | return this.element.html(); | |
|
94 | }; | |
|
95 | ||
|
96 | ||
|
97 | IPython.NotificationWidget = NotificationWidget; | |
|
98 | ||
|
99 | return IPython; | |
|
100 | ||
|
101 | }(IPython)); | |
|
102 |
@@ -55,6 +55,19 span#notebook_name { | |||
|
55 | 55 | margin: 0.3em 0; |
|
56 | 56 | } |
|
57 | 57 | |
|
58 | #menubar_container { | |
|
59 | position: relative; | |
|
60 | } | |
|
61 | ||
|
62 | #notification { | |
|
63 | position: absolute; | |
|
64 | right: 3px; | |
|
65 | top: 3px; | |
|
66 | height: 25px; | |
|
67 | padding: 3px 6px; | |
|
68 | z-index: 10; | |
|
69 | } | |
|
70 | ||
|
58 | 71 | #toolbar { |
|
59 | 72 | /* Initially hidden to prevent FLOUC */ |
|
60 | 73 | display: none; |
@@ -71,31 +84,6 span#quick_help_area { | |||
|
71 | 84 | margin: 0px 0px 0px 0px; |
|
72 | 85 | } |
|
73 | 86 | |
|
74 | span#kernel_status { | |
|
75 | position: absolute; | |
|
76 | padding: 8px 5px 5px 5px; | |
|
77 | right: 10px; | |
|
78 | font-weight: bold; | |
|
79 | } | |
|
80 | ||
|
81 | ||
|
82 | .status_idle { | |
|
83 | color: gray; | |
|
84 | visibility: hidden; | |
|
85 | } | |
|
86 | ||
|
87 | .status_busy { | |
|
88 | color: red; | |
|
89 | } | |
|
90 | ||
|
91 | .status_restarting { | |
|
92 | color: black; | |
|
93 | } | |
|
94 | ||
|
95 | #kernel_persist { | |
|
96 | float: right; | |
|
97 | } | |
|
98 | ||
|
99 | 87 | .help_string { |
|
100 | 88 | float: right; |
|
101 | 89 | width: 170px; |
@@ -62,7 +62,7 var IPython = (function (IPython) { | |||
|
62 | 62 | |
|
63 | 63 | |
|
64 | 64 | Kernel.prototype.restart = function (callback) { |
|
65 |
IPython. |
|
|
65 | $([IPython.events]).trigger('status_restarting.Kernel'); | |
|
66 | 66 | var url = this.kernel_url + "/restart"; |
|
67 | 67 | var that = this; |
|
68 | 68 | if (this.running) { |
@@ -84,20 +84,19 var IPython = (function (IPython) { | |||
|
84 | 84 | this.kernel_url = this.base_url + "/" + this.kernel_id; |
|
85 | 85 | this.start_channels(); |
|
86 | 86 | callback(); |
|
87 | IPython.kernel_status_widget.status_idle(); | |
|
88 | 87 | }; |
|
89 | 88 | |
|
90 | 89 | Kernel.prototype._websocket_closed = function(ws_url, early){ |
|
91 | 90 | var msg; |
|
92 | 91 | var parent_item = $('body'); |
|
93 | 92 | if (early) { |
|
94 |
msg = "Websocket connection to " + ws_url + " could not be established. |
|
|
95 |
" You will NOT be able to run code. |
|
|
93 | msg = "Websocket connection to " + ws_url + " could not be established." + | |
|
94 | " You will NOT be able to run code." + | |
|
96 | 95 | " Your browser may not be compatible with the websocket version in the server," + |
|
97 | 96 | " or if the url does not look right, there could be an error in the" + |
|
98 | 97 | " server's configuration."; |
|
99 | 98 | } else { |
|
100 |
msg = "Websocket connection closed unexpectedly. |
|
|
99 | msg = "Websocket connection closed unexpectedly." + | |
|
101 | 100 | " The kernel will no longer be responsive."; |
|
102 | 101 | } |
|
103 | 102 | var dialog = $('<div/>'); |
@@ -211,6 +210,7 var IPython = (function (IPython) { | |||
|
211 | 210 | |
|
212 | 211 | Kernel.prototype.interrupt = function () { |
|
213 | 212 | if (this.running) { |
|
213 | $([IPython.events]).trigger('status_interrupting.Kernel'); | |
|
214 | 214 | $.post(this.kernel_url + "/interrupt"); |
|
215 | 215 | }; |
|
216 | 216 | }; |
@@ -45,21 +45,21 var IPython = (function (IPython) { | |||
|
45 | 45 | IPython.save_widget.rename_notebook(); |
|
46 | 46 | }); |
|
47 | 47 | this.element.find('#copy_notebook').click(function () { |
|
48 |
var notebook_id = IPython. |
|
|
48 | var notebook_id = IPython.notebook.get_notebook_id(); | |
|
49 | 49 | var url = $('body').data('baseProjectUrl') + notebook_id + '/copy'; |
|
50 | 50 | window.open(url,'_newtab'); |
|
51 | 51 | }); |
|
52 | 52 | this.element.find('#save_notebook').click(function () { |
|
53 |
IPython. |
|
|
53 | IPython.notebook.save_notebook(); | |
|
54 | 54 | }); |
|
55 | 55 | this.element.find('#download_ipynb').click(function () { |
|
56 |
var notebook_id = IPython. |
|
|
56 | var notebook_id = IPython.notebook.get_notebook_id(); | |
|
57 | 57 | var url = $('body').data('baseProjectUrl') + 'notebooks/' + |
|
58 | 58 | notebook_id + '?format=json'; |
|
59 | 59 | window.open(url,'_newtab'); |
|
60 | 60 | }); |
|
61 | 61 | this.element.find('#download_py').click(function () { |
|
62 |
var notebook_id = IPython. |
|
|
62 | var notebook_id = IPython.notebook.get_notebook_id(); | |
|
63 | 63 | var url = $('body').data('baseProjectUrl') + 'notebooks/' + |
|
64 | 64 | notebook_id + '?format=py'; |
|
65 | 65 | window.open(url,'_newtab'); |
@@ -26,6 +26,9 var IPython = (function (IPython) { | |||
|
26 | 26 | this.msg_cell_map = {}; |
|
27 | 27 | this.metadata = {}; |
|
28 | 28 | this.control_key_active = false; |
|
29 | this.notebook_id = null; | |
|
30 | this.notebook_name = null; | |
|
31 | this.notebook_name_blacklist_re = /[\/\\]/; | |
|
29 | 32 | this.style(); |
|
30 | 33 | this.create_elements(); |
|
31 | 34 | this.bind_events(); |
@@ -66,7 +69,7 var IPython = (function (IPython) { | |||
|
66 | 69 | // Save (CTRL+S) or (AppleKey+S) |
|
67 | 70 | //metaKey = applekey on mac |
|
68 | 71 | if ((event.ctrlKey || event.metaKey) && event.keyCode==83) { |
|
69 |
|
|
|
72 | that.save_notebook(); | |
|
70 | 73 | event.preventDefault(); |
|
71 | 74 | return false; |
|
72 | 75 | } else if (event.which === 27) { |
@@ -177,7 +180,7 var IPython = (function (IPython) { | |||
|
177 | 180 | return false; |
|
178 | 181 | } else if (event.which === 83 && that.control_key_active) { |
|
179 | 182 | // Save notebook = s |
|
180 |
|
|
|
183 | that.save_notebook(); | |
|
181 | 184 | that.control_key_active = false; |
|
182 | 185 | return false; |
|
183 | 186 | } else if (event.which === 74 && that.control_key_active) { |
@@ -207,12 +210,12 var IPython = (function (IPython) { | |||
|
207 | 210 | return false; |
|
208 | 211 | } else if (event.which === 73 && that.control_key_active) { |
|
209 | 212 | // Interrupt kernel = i |
|
210 |
|
|
|
213 | that.kernel.interrupt(); | |
|
211 | 214 | that.control_key_active = false; |
|
212 | 215 | return false; |
|
213 | 216 | } else if (event.which === 190 && that.control_key_active) { |
|
214 | 217 | // Restart kernel = . # matches qt console |
|
215 |
|
|
|
218 | that.restart_kernel(); | |
|
216 | 219 | that.control_key_active = false; |
|
217 | 220 | return false; |
|
218 | 221 | } else if (event.which === 72 && that.control_key_active) { |
@@ -402,10 +405,14 var IPython = (function (IPython) { | |||
|
402 | 405 | var cell = this.get_cell(index) |
|
403 | 406 | cell.select(); |
|
404 | 407 | if (cell.cell_type === 'heading') { |
|
405 | IPython.toolbar.set_cell_type(cell.cell_type+cell.level); | |
|
408 | $([IPython.events]).trigger('selected_cell_type_changed.Notebook', | |
|
409 | {'cell_type':cell.cell_type,level:cell.level} | |
|
410 | ); | |
|
406 | 411 | } else { |
|
407 |
IPython. |
|
|
408 | } | |
|
412 | $([IPython.events]).trigger('selected_cell_type_changed.Notebook', | |
|
413 | {'cell_type':cell.cell_type} | |
|
414 | ); | |
|
415 | }; | |
|
409 | 416 | }; |
|
410 | 417 | return this; |
|
411 | 418 | }; |
@@ -676,7 +683,9 var IPython = (function (IPython) { | |||
|
676 | 683 | source_element.remove(); |
|
677 | 684 | this.dirty = true; |
|
678 | 685 | }; |
|
679 | IPython.toolbar.set_cell_type("heading"+level); | |
|
686 | $([IPython.events]).trigger('selected_cell_type_changed.Notebook', | |
|
687 | {'cell_type':'heading',level:level} | |
|
688 | ); | |
|
680 | 689 | }; |
|
681 | 690 | }; |
|
682 | 691 | |
@@ -880,15 +889,12 var IPython = (function (IPython) { | |||
|
880 | 889 | |
|
881 | 890 | Notebook.prototype.start_kernel = function () { |
|
882 | 891 | this.kernel = new IPython.Kernel(); |
|
883 | var notebook_id = IPython.save_widget.get_notebook_id(); | |
|
884 | this.kernel.start(notebook_id, $.proxy(this.kernel_started, this)); | |
|
892 | this.kernel.start(this.notebook_id, $.proxy(this.kernel_started, this)); | |
|
885 | 893 | }; |
|
886 | 894 | |
|
887 | 895 | |
|
888 | 896 | Notebook.prototype.restart_kernel = function () { |
|
889 | 897 | var that = this; |
|
890 | var notebook_id = IPython.save_widget.get_notebook_id(); | |
|
891 | ||
|
892 | 898 | var dialog = $('<div/>'); |
|
893 | 899 | dialog.html('Do you want to restart the current kernel? You will lose all variables defined in it.'); |
|
894 | 900 | $(document).append(dialog); |
@@ -976,8 +982,8 var IPython = (function (IPython) { | |||
|
976 | 982 | var cell = this.cell_for_msg(reply.parent_header.msg_id); |
|
977 | 983 | if (msg_type !== 'status' && !cell){ |
|
978 | 984 | // message not from this notebook, but should be attached to a cell |
|
979 | console.log("Received IOPub message not caused by one of my cells"); | |
|
980 | console.log(reply); | |
|
985 | // console.log("Received IOPub message not caused by one of my cells"); | |
|
986 | // console.log(reply); | |
|
981 | 987 | return; |
|
982 | 988 | } |
|
983 | 989 | var output_types = ['stream','display_data','pyout','pyerr']; |
@@ -985,9 +991,10 var IPython = (function (IPython) { | |||
|
985 | 991 | this.handle_output(cell, msg_type, content); |
|
986 | 992 | } else if (msg_type === 'status') { |
|
987 | 993 | if (content.execution_state === 'busy') { |
|
994 | $([IPython.events]).trigger('status_busy.Kernel'); | |
|
988 | 995 | IPython.kernel_status_widget.status_busy(); |
|
989 | 996 | } else if (content.execution_state === 'idle') { |
|
990 |
IPython. |
|
|
997 | $([IPython.events]).trigger('status_idle.Kernel'); | |
|
991 | 998 | } else if (content.execution_state === 'dead') { |
|
992 | 999 | this.handle_status_dead(); |
|
993 | 1000 | }; |
@@ -1142,8 +1149,33 var IPython = (function (IPython) { | |||
|
1142 | 1149 | this.msg_cell_map[msg_id] = cell.cell_id; |
|
1143 | 1150 | }; |
|
1144 | 1151 | |
|
1152 | ||
|
1145 | 1153 | // Persistance and loading |
|
1146 | 1154 | |
|
1155 | Notebook.prototype.get_notebook_id = function () { | |
|
1156 | return this.notebook_id; | |
|
1157 | }; | |
|
1158 | ||
|
1159 | ||
|
1160 | Notebook.prototype.get_notebook_name = function () { | |
|
1161 | return this.notebook_name; | |
|
1162 | }; | |
|
1163 | ||
|
1164 | ||
|
1165 | Notebook.prototype.set_notebook_name = function (name) { | |
|
1166 | this.notebook_name = name; | |
|
1167 | }; | |
|
1168 | ||
|
1169 | ||
|
1170 | Notebook.prototype.test_notebook_name = function (nbname) { | |
|
1171 | nbname = nbname || ''; | |
|
1172 | if (this.notebook_name_blacklist_re.test(nbname) == false && nbname.length>0) { | |
|
1173 | return true; | |
|
1174 | } else { | |
|
1175 | return false; | |
|
1176 | }; | |
|
1177 | }; | |
|
1178 | ||
|
1147 | 1179 | |
|
1148 | 1180 | Notebook.prototype.fromJSON = function (data) { |
|
1149 | 1181 | var ncells = this.ncells(); |
@@ -1152,8 +1184,9 var IPython = (function (IPython) { | |||
|
1152 | 1184 | // Always delete cell 0 as they get renumbered as they are deleted. |
|
1153 | 1185 | this.delete_cell(0); |
|
1154 | 1186 | }; |
|
1155 | // Save the metadata | |
|
1187 | // Save the metadata and name. | |
|
1156 | 1188 | this.metadata = data.metadata; |
|
1189 | this.notebook_name = data.metadata.name; | |
|
1157 | 1190 | // Only handle 1 worksheet for now. |
|
1158 | 1191 | var worksheet = data.worksheets[0]; |
|
1159 | 1192 | if (worksheet !== undefined) { |
@@ -1186,11 +1219,9 var IPython = (function (IPython) { | |||
|
1186 | 1219 | }; |
|
1187 | 1220 | |
|
1188 | 1221 | Notebook.prototype.save_notebook = function () { |
|
1189 | var notebook_id = IPython.save_widget.get_notebook_id(); | |
|
1190 | var nbname = IPython.save_widget.get_notebook_name(); | |
|
1191 | 1222 | // We may want to move the name/id/nbformat logic inside toJSON? |
|
1192 | 1223 | var data = this.toJSON(); |
|
1193 | data.metadata.name = nbname; | |
|
1224 | data.metadata.name = this.notebook_name; | |
|
1194 | 1225 | data.nbformat = 3; |
|
1195 | 1226 | // We do the call with settings so we can set cache to false. |
|
1196 | 1227 | var settings = { |
@@ -1199,30 +1230,29 var IPython = (function (IPython) { | |||
|
1199 | 1230 | type : "PUT", |
|
1200 | 1231 | data : JSON.stringify(data), |
|
1201 | 1232 | headers : {'Content-Type': 'application/json'}, |
|
1202 |
success : $.proxy(this.notebook_save |
|
|
1233 | success : $.proxy(this.notebook_save_success,this), | |
|
1203 | 1234 | error : $.proxy(this.notebook_save_failed,this) |
|
1204 | 1235 | }; |
|
1205 | IPython.save_widget.status_saving(); | |
|
1206 | var url = $('body').data('baseProjectUrl') + 'notebooks/' + notebook_id; | |
|
1236 | $([IPython.events]).trigger('notebook_saving.Notebook'); | |
|
1237 | var url = $('body').data('baseProjectUrl') + 'notebooks/' + this.notebook_id; | |
|
1207 | 1238 | $.ajax(url, settings); |
|
1208 | 1239 | }; |
|
1209 | 1240 | |
|
1210 | 1241 | |
|
1211 |
Notebook.prototype.notebook_save |
|
|
1242 | Notebook.prototype.notebook_save_success = function (data, status, xhr) { | |
|
1212 | 1243 | this.dirty = false; |
|
1213 |
IPython. |
|
|
1214 | IPython.save_widget.status_last_saved(); | |
|
1244 | $([IPython.events]).trigger('notebook_saved.Notebook'); | |
|
1215 | 1245 | }; |
|
1216 | 1246 | |
|
1217 | 1247 | |
|
1218 | 1248 | Notebook.prototype.notebook_save_failed = function (xhr, status, error_msg) { |
|
1219 |
IPython. |
|
|
1249 | $([IPython.events]).trigger('notebook_save_failed.Notebook'); | |
|
1220 | 1250 | }; |
|
1221 | 1251 | |
|
1222 | 1252 | |
|
1223 | Notebook.prototype.load_notebook = function () { | |
|
1253 | Notebook.prototype.load_notebook = function (notebook_id) { | |
|
1224 | 1254 | var that = this; |
|
1225 |
|
|
|
1255 | this.notebook_id = notebook_id; | |
|
1226 | 1256 | // We do the call with settings so we can set cache to false. |
|
1227 | 1257 | var settings = { |
|
1228 | 1258 | processData : false, |
@@ -1230,30 +1260,27 var IPython = (function (IPython) { | |||
|
1230 | 1260 | type : "GET", |
|
1231 | 1261 | dataType : "json", |
|
1232 | 1262 | success : function (data, status, xhr) { |
|
1233 |
that.notebook_ |
|
|
1263 | that.load_notebook_success(data, status, xhr); | |
|
1234 | 1264 | } |
|
1235 | 1265 | }; |
|
1236 | IPython.save_widget.status_loading(); | |
|
1237 | var url = $('body').data('baseProjectUrl') + 'notebooks/' + notebook_id; | |
|
1266 | $([IPython.events]).trigger('notebook_loading.Notebook'); | |
|
1267 | var url = $('body').data('baseProjectUrl') + 'notebooks/' + this.notebook_id; | |
|
1238 | 1268 | $.ajax(url, settings); |
|
1239 | 1269 | }; |
|
1240 | 1270 | |
|
1241 | 1271 | |
|
1242 |
Notebook.prototype.notebook_ |
|
|
1272 | Notebook.prototype.load_notebook_success = function (data, status, xhr) { | |
|
1243 | 1273 | this.fromJSON(data); |
|
1244 | 1274 | if (this.ncells() === 0) { |
|
1245 | 1275 | this.insert_cell_below('code'); |
|
1246 | 1276 | }; |
|
1247 | IPython.save_widget.status_last_saved(); | |
|
1248 | IPython.save_widget.set_notebook_name(data.metadata.name); | |
|
1249 | 1277 | this.dirty = false; |
|
1250 | 1278 | if (! this.read_only) { |
|
1251 | 1279 | this.start_kernel(); |
|
1252 | 1280 | } |
|
1253 | 1281 | this.select(0); |
|
1254 | 1282 | this.scroll_to_top(); |
|
1255 | IPython.save_widget.update_url(); | |
|
1256 | IPython.layout_manager.do_resize(); | |
|
1283 | $([IPython.events]).trigger('notebook_loaded.Notebook'); | |
|
1257 | 1284 | }; |
|
1258 | 1285 | |
|
1259 | 1286 | IPython.Notebook = Notebook; |
@@ -82,14 +82,13 $(document).ready(function () { | |||
|
82 | 82 | |
|
83 | 83 | IPython.layout_manager = new IPython.LayoutManager(); |
|
84 | 84 | IPython.pager = new IPython.Pager('div#pager', 'div#pager_splitter'); |
|
85 | IPython.save_widget = new IPython.SaveWidget('span#save_widget'); | |
|
86 | 85 | IPython.quick_help = new IPython.QuickHelp('span#quick_help_area'); |
|
87 | 86 | IPython.login_widget = new IPython.LoginWidget('span#login_widget'); |
|
88 | 87 | IPython.notebook = new IPython.Notebook('div#notebook'); |
|
89 |
IPython. |
|
|
88 | IPython.save_widget = new IPython.SaveWidget('span#save_widget'); | |
|
90 | 89 | IPython.menubar = new IPython.MenuBar('#menubar') |
|
91 | 90 | IPython.toolbar = new IPython.ToolBar('#toolbar') |
|
92 | IPython.kernel_status_widget.status_idle(); | |
|
91 | IPython.notification_widget = new IPython.NotificationWidget('#notification') | |
|
93 | 92 | |
|
94 | 93 | IPython.layout_manager.do_resize(); |
|
95 | 94 | |
@@ -111,7 +110,11 $(document).ready(function () { | |||
|
111 | 110 | $('div#main_app').css('display','block'); |
|
112 | 111 | |
|
113 | 112 | IPython.layout_manager.do_resize(); |
|
114 |
IPython. |
|
|
113 | $([IPython.events]).on('notebook_loaded.Notebook', function () { | |
|
114 | IPython.layout_manager.do_resize(); | |
|
115 | IPython.save_widget.update_url(); | |
|
116 | }) | |
|
117 | IPython.notebook.load_notebook($('body').data('notebookId')); | |
|
115 | 118 | |
|
116 | 119 | }); |
|
117 | 120 |
@@ -79,16 +79,15 $(document).ready(function () { | |||
|
79 | 79 | $('div#main_app').addClass('border-box-sizing ui-widget ui-widget-content'); |
|
80 | 80 | $('div#notebook_panel').addClass('border-box-sizing ui-widget'); |
|
81 | 81 | |
|
82 | IPython.save_widget = new IPython.SaveWidget('span#save_widget'); | |
|
83 | 82 | IPython.login_widget = new IPython.LoginWidget('span#login_widget'); |
|
84 | 83 | IPython.notebook = new IPython.Notebook('div#notebook'); |
|
84 | IPython.save_widget = new IPython.SaveWidget('span#save_widget'); | |
|
85 | 85 | |
|
86 | 86 | // These have display: none in the css file and are made visible here to prevent FLOUC. |
|
87 | 87 | $('div#header').css('display','block'); |
|
88 | 88 | $('div#main_app').css('display','block'); |
|
89 | 89 | |
|
90 | // Perform these actions after the notebook has been loaded. | |
|
91 | IPython.notebook.load_notebook(function () {}); | |
|
90 | IPython.notebook.load_notebook($('body').data('notebookId')); | |
|
92 | 91 | |
|
93 | 92 | }); |
|
94 | 93 |
@@ -15,8 +15,6 var IPython = (function (IPython) { | |||
|
15 | 15 | |
|
16 | 16 | var SaveWidget = function (selector) { |
|
17 | 17 | this.selector = selector; |
|
18 | this.notebook_name_blacklist_re = /[\/\\]/; | |
|
19 | this.last_saved_name = ''; | |
|
20 | 18 | if (this.selector !== undefined) { |
|
21 | 19 | this.element = $(selector); |
|
22 | 20 | this.style(); |
@@ -43,11 +41,19 var IPython = (function (IPython) { | |||
|
43 | 41 | }, function () { |
|
44 | 42 | $(this).removeClass("ui-state-hover"); |
|
45 | 43 | }); |
|
46 | }; | |
|
47 | ||
|
48 | ||
|
49 | SaveWidget.prototype.save_notebook = function () { | |
|
50 | IPython.notebook.save_notebook(); | |
|
44 | $([IPython.events]).on('notebook_loaded.Notebook', function () { | |
|
45 | that.set_last_saved(); | |
|
46 | that.update_notebook_name(); | |
|
47 | that.update_document_title(); | |
|
48 | }); | |
|
49 | $([IPython.events]).on('notebook_saved.Notebook', function () { | |
|
50 | that.set_last_saved(); | |
|
51 | that.update_notebook_name(); | |
|
52 | that.update_document_title(); | |
|
53 | }); | |
|
54 | $([IPython.events]).on('notebook_save_failed.Notebook', function () { | |
|
55 | that.set_save_status(''); | |
|
56 | }); | |
|
51 | 57 | }; |
|
52 | 58 | |
|
53 | 59 | |
@@ -61,7 +67,7 var IPython = (function (IPython) { | |||
|
61 | 67 | dialog.append( |
|
62 | 68 | $('<input/>').attr('type','text').attr('size','25') |
|
63 | 69 | .addClass('ui-widget ui-widget-content') |
|
64 |
.attr('value', |
|
|
70 | .attr('value',IPython.notebook.get_notebook_name()) | |
|
65 | 71 | ); |
|
66 | 72 | // $(document).append(dialog); |
|
67 | 73 | dialog.dialog({ |
@@ -73,15 +79,15 var IPython = (function (IPython) { | |||
|
73 | 79 | buttons : { |
|
74 | 80 | "OK": function () { |
|
75 | 81 | var new_name = $(this).find('input').attr('value'); |
|
76 |
if (! |
|
|
82 | if (!IPython.notebook.test_notebook_name(new_name)) { | |
|
77 | 83 | $(this).find('h3').html( |
|
78 | 84 | "Invalid notebook name. Notebook names must "+ |
|
79 | 85 | "have 1 or more characters and can contain any characters " + |
|
80 | 86 | "except / and \\. Please enter a new notebook name:" |
|
81 | 87 | ); |
|
82 | 88 | } else { |
|
83 |
|
|
|
84 |
|
|
|
89 | IPython.notebook.set_notebook_name(new_name); | |
|
90 | IPython.notebook.save_notebook(); | |
|
85 | 91 | $(this).dialog('close'); |
|
86 | 92 | } |
|
87 | 93 | }, |
@@ -92,82 +98,36 var IPython = (function (IPython) { | |||
|
92 | 98 | }); |
|
93 | 99 | } |
|
94 | 100 | |
|
95 | SaveWidget.prototype.notebook_saved = function () { | |
|
96 | this.set_document_title(); | |
|
97 | this.last_saved_name = this.get_notebook_name(); | |
|
98 | }; | |
|
99 | ||
|
100 | 101 | |
|
101 |
SaveWidget.prototype. |
|
|
102 | return this.element.find('span#notebook_name').html(); | |
|
103 | }; | |
|
104 | ||
|
105 | ||
|
106 | SaveWidget.prototype.set_notebook_name = function (nbname) { | |
|
102 | SaveWidget.prototype.update_notebook_name = function () { | |
|
103 | var nbname = IPython.notebook.get_notebook_name(); | |
|
107 | 104 | this.element.find('span#notebook_name').html(nbname); |
|
108 | this.set_document_title(); | |
|
109 | this.last_saved_name = nbname; | |
|
110 | 105 | }; |
|
111 | 106 | |
|
112 | 107 | |
|
113 |
SaveWidget.prototype. |
|
|
114 |
nbname = |
|
|
108 | SaveWidget.prototype.update_document_title = function () { | |
|
109 | var nbname = IPython.notebook.get_notebook_name(); | |
|
115 | 110 | document.title = nbname; |
|
116 | 111 | }; |
|
117 | ||
|
118 | ||
|
119 | SaveWidget.prototype.get_notebook_id = function () { | |
|
120 | return $('body').data('notebookId'); | |
|
121 | }; | |
|
122 | 112 | |
|
123 | 113 | |
|
124 | 114 | SaveWidget.prototype.update_url = function () { |
|
125 |
var notebook_id = |
|
|
126 |
if (notebook_id !== |
|
|
115 | var notebook_id = IPython.notebook.get_notebook_id(); | |
|
116 | if (notebook_id !== null) { | |
|
127 | 117 | var new_url = $('body').data('baseProjectUrl') + notebook_id; |
|
128 | 118 | window.history.replaceState({}, '', new_url); |
|
129 | 119 | }; |
|
130 | 120 | }; |
|
131 | 121 | |
|
132 | 122 | |
|
133 |
SaveWidget.prototype. |
|
|
134 | nbname = nbname || ''; | |
|
135 | if (this.notebook_name_blacklist_re.test(nbname) == false && nbname.length>0) { | |
|
136 | return true; | |
|
137 | } else { | |
|
138 | return false; | |
|
139 | }; | |
|
140 | }; | |
|
123 | SaveWidget.prototype.set_save_status = function (msg) { | |
|
124 | this.element.find('span#save_status').html(msg); | |
|
125 | } | |
|
141 | 126 | |
|
142 | 127 | |
|
143 | 128 | SaveWidget.prototype.set_last_saved = function () { |
|
144 | 129 | var d = new Date(); |
|
145 |
|
|
|
146 | ||
|
147 | }; | |
|
148 | ||
|
149 | SaveWidget.prototype.reset_status = function () { | |
|
150 | this.element.find('span#save_status').html(''); | |
|
151 | }; | |
|
152 | ||
|
153 | ||
|
154 | SaveWidget.prototype.status_last_saved = function () { | |
|
155 | this.set_last_saved(); | |
|
156 | }; | |
|
157 | ||
|
158 | ||
|
159 | SaveWidget.prototype.status_saving = function () { | |
|
160 | this.element.find('span#save_status').html('Saving...'); | |
|
161 | }; | |
|
162 | ||
|
163 | ||
|
164 | SaveWidget.prototype.status_save_failed = function () { | |
|
165 | this.element.find('span#save_status').html('Save failed'); | |
|
166 | }; | |
|
167 | ||
|
168 | ||
|
169 | SaveWidget.prototype.status_loading = function () { | |
|
170 | this.element.find('span#save_status').html('Loading...'); | |
|
130 | this.set_save_status('Last saved: '+d.format('mmm dd h:MM TT')); | |
|
171 | 131 | }; |
|
172 | 132 | |
|
173 | 133 |
@@ -72,8 +72,9 var IPython = (function (IPython) { | |||
|
72 | 72 | |
|
73 | 73 | |
|
74 | 74 | ToolBar.prototype.bind_events = function () { |
|
75 | var that = this; | |
|
75 | 76 | this.element.find('#save_b').click(function () { |
|
76 |
IPython. |
|
|
77 | IPython.notebook.save_notebook(); | |
|
77 | 78 | }); |
|
78 | 79 | this.element.find('#cut_b').click(function () { |
|
79 | 80 | IPython.notebook.cut_cell(); |
@@ -124,12 +125,13 var IPython = (function (IPython) { | |||
|
124 | 125 | IPython.notebook.to_heading(undefined, 6); |
|
125 | 126 | }; |
|
126 | 127 | }); |
|
127 | ||
|
128 | }; | |
|
129 | ||
|
130 | ||
|
131 | ToolBar.prototype.set_cell_type = function (cell_type) { | |
|
132 | this.element.find('#cell_type').val(cell_type); | |
|
128 | $([IPython.events]).on('selected_cell_type_changed', function (event, data) { | |
|
129 | if (data.cell_type === 'heading') { | |
|
130 | that.element.find('#cell_type').val(data.cell_type+data.level); | |
|
131 | } else { | |
|
132 | that.element.find('#cell_type').val(data.cell_type); | |
|
133 | } | |
|
134 | }); | |
|
133 | 135 | }; |
|
134 | 136 | |
|
135 | 137 |
@@ -54,10 +54,9 | |||
|
54 | 54 | <button id="login">Login</button> |
|
55 | 55 | {% end %} |
|
56 | 56 | </span> |
|
57 | ||
|
58 | <span id="kernel_status">Idle</span> | |
|
59 | 57 | </div> |
|
60 | 58 | |
|
59 | <div id="menubar_container"> | |
|
61 | 60 | <div id="menubar"> |
|
62 | 61 | <ul id="menus"> |
|
63 | 62 | <li><a href="#">File</a> |
@@ -153,6 +152,9 | |||
|
153 | 152 | </ul> |
|
154 | 153 | |
|
155 | 154 | </div> |
|
155 | <div id="notification"></div> | |
|
156 | </div> | |
|
157 | ||
|
156 | 158 | |
|
157 | 159 | <div id="toolbar"> |
|
158 | 160 | |
@@ -220,12 +222,12 | |||
|
220 | 222 | <script src="{{ static_url("dateformat/date.format.js") }}" charset="utf-8"></script> |
|
221 | 223 | |
|
222 | 224 | <script src="{{ static_url("js/namespace.js") }}" type="text/javascript" charset="utf-8"></script> |
|
225 | <script src="{{ static_url("js/events.js") }}" type="text/javascript" charset="utf-8"></script> | |
|
223 | 226 | <script src="{{ static_url("js/utils.js") }}" type="text/javascript" charset="utf-8"></script> |
|
224 | 227 | <script src="{{ static_url("js/cell.js") }}" type="text/javascript" charset="utf-8"></script> |
|
225 | 228 | <script src="{{ static_url("js/codecell.js") }}" type="text/javascript" charset="utf-8"></script> |
|
226 | 229 | <script src="{{ static_url("js/textcell.js") }}" type="text/javascript" charset="utf-8"></script> |
|
227 | 230 | <script src="{{ static_url("js/kernel.js") }}" type="text/javascript" charset="utf-8"></script> |
|
228 | <script src="{{ static_url("js/kernelstatus.js") }}" type="text/javascript" charset="utf-8"></script> | |
|
229 | 231 | <script src="{{ static_url("js/layout.js") }}" type="text/javascript" charset="utf-8"></script> |
|
230 | 232 | <script src="{{ static_url("js/savewidget.js") }}" type="text/javascript" charset="utf-8"></script> |
|
231 | 233 | <script src="{{ static_url("js/quickhelp.js") }}" type="text/javascript" charset="utf-8"></script> |
@@ -234,6 +236,7 | |||
|
234 | 236 | <script src="{{ static_url("js/menubar.js") }}" type="text/javascript" charset="utf-8"></script> |
|
235 | 237 | <script src="{{ static_url("js/toolbar.js") }}" type="text/javascript" charset="utf-8"></script> |
|
236 | 238 | <script src="{{ static_url("js/notebook.js") }}" type="text/javascript" charset="utf-8"></script> |
|
239 | <script src="{{ static_url("js/notificationwidget.js") }}" type="text/javascript" charset="utf-8"></script> | |
|
237 | 240 | <script src="{{ static_url("js/notebookmain.js") }}" type="text/javascript" charset="utf-8"></script> |
|
238 | 241 | |
|
239 | 242 | </body> |
@@ -17,10 +17,7 | |||
|
17 | 17 | |
|
18 | 18 | <link rel="stylesheet" href="{{ static_url("jquery/css/themes/base/jquery-ui.min.css") }}" type="text/css" /> |
|
19 | 19 | <link rel="stylesheet" href="{{ static_url("codemirror/lib/codemirror.css") }}"> |
|
20 | <link rel="stylesheet" href="{{ static_url("codemirror/mode/markdown/markdown.css") }}"> | |
|
21 | <link rel="stylesheet" href="{{ static_url("codemirror/mode/rst/rst.css") }}"> | |
|
22 | 20 | <link rel="stylesheet" href="{{ static_url("codemirror/theme/ipython.css") }}"> |
|
23 | <link rel="stylesheet" href="{{ static_url("codemirror/theme/default.css") }}"> | |
|
24 | 21 | |
|
25 | 22 | <link rel="stylesheet" href="{{ static_url("prettify/prettify.css") }}"/> |
|
26 | 23 | |
@@ -88,6 +85,7 | |||
|
88 | 85 | <script src="{{ static_url("dateformat/date.format.js") }}" charset="utf-8"></script> |
|
89 | 86 | |
|
90 | 87 | <script src="{{ static_url("js/namespace.js") }}" type="text/javascript" charset="utf-8"></script> |
|
88 | <script src="{{ static_url("js/events.js") }}" type="text/javascript" charset="utf-8"></script> | |
|
91 | 89 | <script src="{{ static_url("js/utils.js") }}" type="text/javascript" charset="utf-8"></script> |
|
92 | 90 | <script src="{{ static_url("js/cell.js") }}" type="text/javascript" charset="utf-8"></script> |
|
93 | 91 | <script src="{{ static_url("js/codecell.js") }}" type="text/javascript" charset="utf-8"></script> |
|
1 | NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now