Show More
@@ -1,148 +1,148 | |||||
1 | //---------------------------------------------------------------------------- |
|
1 | //---------------------------------------------------------------------------- | |
2 | // Copyright (C) 2008-2011 The IPython Development Team |
|
2 | // Copyright (C) 2008-2011 The IPython Development Team | |
3 | // |
|
3 | // | |
4 | // Distributed under the terms of the BSD License. The full license is in |
|
4 | // Distributed under the terms of the BSD License. The full license is in | |
5 | // the file COPYING, distributed as part of this software. |
|
5 | // the file COPYING, distributed as part of this software. | |
6 | //---------------------------------------------------------------------------- |
|
6 | //---------------------------------------------------------------------------- | |
7 |
|
7 | |||
8 | //============================================================================ |
|
8 | //============================================================================ | |
9 | // SaveWidget |
|
9 | // SaveWidget | |
10 | //============================================================================ |
|
10 | //============================================================================ | |
11 |
|
11 | |||
12 | var IPython = (function (IPython) { |
|
12 | var IPython = (function (IPython) { | |
13 |
|
13 | |||
14 | var utils = IPython.utils; |
|
14 | var utils = IPython.utils; | |
15 |
|
15 | |||
16 | var SaveWidget = function (selector) { |
|
16 | var SaveWidget = function (selector) { | |
17 | this.selector = selector; |
|
17 | this.selector = selector; | |
18 | if (this.selector !== undefined) { |
|
18 | if (this.selector !== undefined) { | |
19 | this.element = $(selector); |
|
19 | this.element = $(selector); | |
20 | this.style(); |
|
20 | this.style(); | |
21 | this.bind_events(); |
|
21 | this.bind_events(); | |
22 | } |
|
22 | } | |
23 | }; |
|
23 | }; | |
24 |
|
24 | |||
25 |
|
25 | |||
26 | SaveWidget.prototype.style = function () { |
|
26 | SaveWidget.prototype.style = function () { | |
27 | this.element.find('span#save_widget').addClass('ui-widget'); |
|
27 | this.element.find('span#save_widget').addClass('ui-widget'); | |
28 | this.element.find('span#notebook_name').addClass('ui-widget ui-widget-content'); |
|
28 | this.element.find('span#notebook_name').addClass('ui-widget ui-widget-content'); | |
29 | this.element.find('span#save_status').addClass('ui-widget ui-widget-content') |
|
29 | this.element.find('span#save_status').addClass('ui-widget ui-widget-content') | |
30 | .css({border: 'none', 'margin-left': '20px'}); |
|
30 | .css({border: 'none', 'margin-left': '20px'}); | |
31 | }; |
|
31 | }; | |
32 |
|
32 | |||
33 |
|
33 | |||
34 | SaveWidget.prototype.bind_events = function () { |
|
34 | SaveWidget.prototype.bind_events = function () { | |
35 | var that = this; |
|
35 | var that = this; | |
36 | this.element.find('span#notebook_name').click(function () { |
|
36 | this.element.find('span#notebook_name').click(function () { | |
37 | that.rename_notebook(); |
|
37 | that.rename_notebook(); | |
38 | }); |
|
38 | }); | |
39 | this.element.find('span#notebook_name').hover(function () { |
|
39 | this.element.find('span#notebook_name').hover(function () { | |
40 | $(this).addClass("ui-state-hover"); |
|
40 | $(this).addClass("ui-state-hover"); | |
41 | }, function () { |
|
41 | }, function () { | |
42 | $(this).removeClass("ui-state-hover"); |
|
42 | $(this).removeClass("ui-state-hover"); | |
43 | }); |
|
43 | }); | |
44 | $([IPython.events]).on('notebook_loaded.Notebook', function () { |
|
44 | $([IPython.events]).on('notebook_loaded.Notebook', function () { | |
45 | that.set_last_saved(); |
|
45 | that.set_last_saved(); | |
46 | that.update_notebook_name(); |
|
46 | that.update_notebook_name(); | |
47 | that.update_document_title(); |
|
47 | that.update_document_title(); | |
48 | }); |
|
48 | }); | |
49 | $([IPython.events]).on('notebook_saved.Notebook', function () { |
|
49 | $([IPython.events]).on('notebook_saved.Notebook', function () { | |
50 | that.set_last_saved(); |
|
50 | that.set_last_saved(); | |
51 | that.update_notebook_name(); |
|
51 | that.update_notebook_name(); | |
52 | that.update_document_title(); |
|
52 | that.update_document_title(); | |
53 | }); |
|
53 | }); | |
54 | $([IPython.events]).on('notebook_save_failed.Notebook', function () { |
|
54 | $([IPython.events]).on('notebook_save_failed.Notebook', function () { | |
55 | that.set_save_status(''); |
|
55 | that.set_save_status(''); | |
56 | }); |
|
56 | }); | |
57 | }; |
|
57 | }; | |
58 |
|
58 | |||
59 |
|
59 | |||
60 | SaveWidget.prototype.rename_notebook = function () { |
|
60 | SaveWidget.prototype.rename_notebook = function () { | |
61 | var that = this; |
|
61 | var that = this; | |
62 | var dialog = $('<div/>'); |
|
62 | var dialog = $('<div/>'); | |
63 | dialog.append( |
|
63 | dialog.append( | |
64 | $('<h3/>').html('Enter a new notebook name:') |
|
64 | $('<h3/>').html('Enter a new notebook name:') | |
65 | .css({'margin-bottom': '10px'}) |
|
65 | .css({'margin-bottom': '10px'}) | |
66 | ); |
|
66 | ); | |
67 | dialog.append( |
|
67 | dialog.append( | |
68 | $('<input/>').attr('type','text').attr('size','25') |
|
68 | $('<input/>').attr('type','text').attr('size','25') | |
69 | .addClass('ui-widget ui-widget-content') |
|
69 | .addClass('ui-widget ui-widget-content') | |
70 | .attr('value',IPython.notebook.get_notebook_name()) |
|
70 | .attr('value',IPython.notebook.get_notebook_name()) | |
71 | ); |
|
71 | ); | |
72 | // $(document).append(dialog); |
|
72 | // $(document).append(dialog); | |
73 | dialog.dialog({ |
|
73 | dialog.dialog({ | |
74 | resizable: false, |
|
74 | resizable: false, | |
75 | modal: true, |
|
75 | modal: true, | |
76 | title: "Rename Notebook", |
|
76 | title: "Rename Notebook", | |
77 | closeText: "", |
|
77 | closeText: "", | |
78 | close: function(event, ui) {$(this).dialog('destroy').remove();}, |
|
78 | close: function(event, ui) {$(this).dialog('destroy').remove();}, | |
79 | buttons : { |
|
79 | buttons : { | |
80 | "OK": function () { |
|
80 | "OK": function () { | |
81 | var new_name = $(this).find('input').attr('value'); |
|
81 | var new_name = $(this).find('input').attr('value'); | |
82 | if (!IPython.notebook.test_notebook_name(new_name)) { |
|
82 | if (!IPython.notebook.test_notebook_name(new_name)) { | |
83 | $(this).find('h3').html( |
|
83 | $(this).find('h3').html( | |
84 | "Invalid notebook name. Notebook names must "+ |
|
84 | "Invalid notebook name. Notebook names must "+ | |
85 | "have 1 or more characters and can contain any characters " + |
|
85 | "have 1 or more characters and can contain any characters " + | |
86 | "except / and \\. Please enter a new notebook name:" |
|
86 | "except / and \\. Please enter a new notebook name:" | |
87 | ); |
|
87 | ); | |
88 | } else { |
|
88 | } else { | |
89 | IPython.notebook.set_notebook_name(new_name); |
|
89 | IPython.notebook.set_notebook_name(new_name); | |
90 | IPython.notebook.save_notebook(); |
|
90 | IPython.notebook.save_notebook(); | |
91 | $(this).dialog('close'); |
|
91 | $(this).dialog('close'); | |
92 | } |
|
92 | } | |
93 | }, |
|
93 | }, | |
94 | "Cancel": function () { |
|
94 | "Cancel": function () { | |
95 | $(this).dialog('close'); |
|
95 | $(this).dialog('close'); | |
96 | } |
|
96 | } | |
97 | }, |
|
97 | }, | |
98 | open : function (event, ui) { |
|
98 | open : function (event, ui) { | |
99 | var that = $(this); |
|
99 | var that = $(this); | |
100 | // Upon ENTER, click the OK button. |
|
100 | // Upon ENTER, click the OK button. | |
101 | that.find('input[type="text"]').keydown(function (event, ui) { |
|
101 | that.find('input[type="text"]').keydown(function (event, ui) { | |
102 |
if (event.which === |
|
102 | if (event.which === utils.keycodes.ENTER) { | |
103 | that.parent().find('button').first().click(); |
|
103 | that.parent().find('button').first().click(); | |
104 | } |
|
104 | } | |
105 | }); |
|
105 | }); | |
106 | } |
|
106 | } | |
107 | }); |
|
107 | }); | |
108 | } |
|
108 | } | |
109 |
|
109 | |||
110 |
|
110 | |||
111 | SaveWidget.prototype.update_notebook_name = function () { |
|
111 | SaveWidget.prototype.update_notebook_name = function () { | |
112 | var nbname = IPython.notebook.get_notebook_name(); |
|
112 | var nbname = IPython.notebook.get_notebook_name(); | |
113 | this.element.find('span#notebook_name').html(nbname); |
|
113 | this.element.find('span#notebook_name').html(nbname); | |
114 | }; |
|
114 | }; | |
115 |
|
115 | |||
116 |
|
116 | |||
117 | SaveWidget.prototype.update_document_title = function () { |
|
117 | SaveWidget.prototype.update_document_title = function () { | |
118 | var nbname = IPython.notebook.get_notebook_name(); |
|
118 | var nbname = IPython.notebook.get_notebook_name(); | |
119 | document.title = nbname; |
|
119 | document.title = nbname; | |
120 | }; |
|
120 | }; | |
121 |
|
121 | |||
122 |
|
122 | |||
123 | SaveWidget.prototype.update_url = function () { |
|
123 | SaveWidget.prototype.update_url = function () { | |
124 | var notebook_id = IPython.notebook.get_notebook_id(); |
|
124 | var notebook_id = IPython.notebook.get_notebook_id(); | |
125 | if (notebook_id !== null) { |
|
125 | if (notebook_id !== null) { | |
126 | var new_url = $('body').data('baseProjectUrl') + notebook_id; |
|
126 | var new_url = $('body').data('baseProjectUrl') + notebook_id; | |
127 | window.history.replaceState({}, '', new_url); |
|
127 | window.history.replaceState({}, '', new_url); | |
128 | }; |
|
128 | }; | |
129 | }; |
|
129 | }; | |
130 |
|
130 | |||
131 |
|
131 | |||
132 | SaveWidget.prototype.set_save_status = function (msg) { |
|
132 | SaveWidget.prototype.set_save_status = function (msg) { | |
133 | this.element.find('span#save_status').html(msg); |
|
133 | this.element.find('span#save_status').html(msg); | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 |
|
136 | |||
137 | SaveWidget.prototype.set_last_saved = function () { |
|
137 | SaveWidget.prototype.set_last_saved = function () { | |
138 | var d = new Date(); |
|
138 | var d = new Date(); | |
139 | this.set_save_status('Last saved: '+d.format('mmm dd h:MM TT')); |
|
139 | this.set_save_status('Last saved: '+d.format('mmm dd h:MM TT')); | |
140 | }; |
|
140 | }; | |
141 |
|
141 | |||
142 |
|
142 | |||
143 | IPython.SaveWidget = SaveWidget; |
|
143 | IPython.SaveWidget = SaveWidget; | |
144 |
|
144 | |||
145 | return IPython; |
|
145 | return IPython; | |
146 |
|
146 | |||
147 | }(IPython)); |
|
147 | }(IPython)); | |
148 |
|
148 |
General Comments 0
You need to be logged in to leave comments.
Login now