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