Show More
@@ -1,123 +1,127 b'' | |||||
1 | //---------------------------------------------------------------------------- |
|
1 | //---------------------------------------------------------------------------- | |
2 | // Copyright (C) 2011 The IPython Development Team |
|
2 | // Copyright (C) 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 | // On document ready |
|
9 | // On document ready | |
10 | //============================================================================ |
|
10 | //============================================================================ | |
11 |
|
11 | |||
12 | // for the time beeing, we have to pass marked as a parameter here, |
|
12 | // for the time beeing, we have to pass marked as a parameter here, | |
13 | // as injecting require.js make marked not to put itself in the globals, |
|
13 | // as injecting require.js make marked not to put itself in the globals, | |
14 | // which make both this file fail at setting marked configuration, and textcell.js |
|
14 | // which make both this file fail at setting marked configuration, and textcell.js | |
15 | // which search marked into global. |
|
15 | // which search marked into global. | |
16 | require(['components/marked/lib/marked', |
|
16 | require(['components/marked/lib/marked', | |
17 | 'widgets/js/init', |
|
17 | 'widgets/js/init', | |
18 | 'components/bootstrap-tour/build/js/bootstrap-tour.min'], |
|
18 | 'components/bootstrap-tour/build/js/bootstrap-tour.min'], | |
19 |
|
19 | |||
20 | function (marked) { |
|
20 | function (marked) { | |
21 | "use strict"; |
|
21 | "use strict"; | |
22 |
|
22 | |||
23 | window.marked = marked; |
|
23 | window.marked = marked; | |
24 |
|
24 | |||
25 | // monkey patch CM to be able to syntax highlight cell magics |
|
25 | // monkey patch CM to be able to syntax highlight cell magics | |
26 | // bug reported upstream, |
|
26 | // bug reported upstream, | |
27 | // see https://github.com/marijnh/CodeMirror2/issues/670 |
|
27 | // see https://github.com/marijnh/CodeMirror2/issues/670 | |
28 | if(CodeMirror.getMode(1,'text/plain').indent === undefined ){ |
|
28 | if(CodeMirror.getMode(1,'text/plain').indent === undefined ){ | |
29 | console.log('patching CM for undefined indent'); |
|
29 | console.log('patching CM for undefined indent'); | |
30 | CodeMirror.modes.null = function() { |
|
30 | CodeMirror.modes.null = function() { | |
31 | return {token: function(stream) {stream.skipToEnd();},indent : function(){return 0;}}; |
|
31 | return {token: function(stream) {stream.skipToEnd();},indent : function(){return 0;}}; | |
32 | }; |
|
32 | }; | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | CodeMirror.patchedGetMode = function(config, mode){ |
|
35 | CodeMirror.patchedGetMode = function(config, mode){ | |
36 | var cmmode = CodeMirror.getMode(config, mode); |
|
36 | var cmmode = CodeMirror.getMode(config, mode); | |
37 | if(cmmode.indent === null) { |
|
37 | if(cmmode.indent === null) { | |
38 | console.log('patch mode "' , mode, '" on the fly'); |
|
38 | console.log('patch mode "' , mode, '" on the fly'); | |
39 | cmmode.indent = function(){return 0;}; |
|
39 | cmmode.indent = function(){return 0;}; | |
40 | } |
|
40 | } | |
41 | return cmmode; |
|
41 | return cmmode; | |
42 | }; |
|
42 | }; | |
43 | // end monkey patching CodeMirror |
|
43 | // end monkey patching CodeMirror | |
44 |
|
44 | |||
45 | IPython.mathjaxutils.init(); |
|
45 | IPython.mathjaxutils.init(); | |
46 |
|
46 | |||
47 | $('#ipython-main-app').addClass('border-box-sizing'); |
|
47 | $('#ipython-main-app').addClass('border-box-sizing'); | |
48 | $('div#notebook_panel').addClass('border-box-sizing'); |
|
48 | $('div#notebook_panel').addClass('border-box-sizing'); | |
49 |
|
49 | |||
50 | var opts = { |
|
50 | var opts = { | |
51 | base_url : IPython.utils.get_body_data("baseUrl"), |
|
51 | base_url : IPython.utils.get_body_data("baseUrl"), | |
52 | notebook_path : IPython.utils.get_body_data("notebookPath"), |
|
52 | notebook_path : IPython.utils.get_body_data("notebookPath"), | |
53 | notebook_name : IPython.utils.get_body_data('notebookName') |
|
53 | notebook_name : IPython.utils.get_body_data('notebookName') | |
54 | }; |
|
54 | }; | |
55 |
|
55 | |||
56 | IPython.page = new IPython.Page(); |
|
56 | IPython.page = new IPython.Page(); | |
57 | IPython.layout_manager = new IPython.LayoutManager(); |
|
57 | IPython.layout_manager = new IPython.LayoutManager(); | |
58 | IPython.pager = new IPython.Pager('div#pager', 'div#pager_splitter'); |
|
58 | IPython.pager = new IPython.Pager('div#pager', 'div#pager_splitter'); | |
59 | IPython.quick_help = new IPython.QuickHelp(); |
|
59 | IPython.quick_help = new IPython.QuickHelp(); | |
60 | IPython.tour = new IPython.NotebookTour(); |
|
60 | try { | |
|
61 | IPython.tour = new IPython.NotebookTour(); | |||
|
62 | } catch (e) { | |||
|
63 | console.log("Failed to instantiate Notebook Tour", e); | |||
|
64 | } | |||
61 | IPython.login_widget = new IPython.LoginWidget('span#login_widget', opts); |
|
65 | IPython.login_widget = new IPython.LoginWidget('span#login_widget', opts); | |
62 | IPython.notebook = new IPython.Notebook('div#notebook', opts); |
|
66 | IPython.notebook = new IPython.Notebook('div#notebook', opts); | |
63 | IPython.keyboard_manager = new IPython.KeyboardManager(); |
|
67 | IPython.keyboard_manager = new IPython.KeyboardManager(); | |
64 | IPython.save_widget = new IPython.SaveWidget('span#save_widget'); |
|
68 | IPython.save_widget = new IPython.SaveWidget('span#save_widget'); | |
65 | IPython.menubar = new IPython.MenuBar('#menubar', opts); |
|
69 | IPython.menubar = new IPython.MenuBar('#menubar', opts); | |
66 | IPython.toolbar = new IPython.MainToolBar('#maintoolbar-container'); |
|
70 | IPython.toolbar = new IPython.MainToolBar('#maintoolbar-container'); | |
67 | IPython.tooltip = new IPython.Tooltip(); |
|
71 | IPython.tooltip = new IPython.Tooltip(); | |
68 | IPython.notification_area = new IPython.NotificationArea('#notification_area'); |
|
72 | IPython.notification_area = new IPython.NotificationArea('#notification_area'); | |
69 | IPython.notification_area.init_notification_widgets(); |
|
73 | IPython.notification_area.init_notification_widgets(); | |
70 |
|
74 | |||
71 | IPython.layout_manager.do_resize(); |
|
75 | IPython.layout_manager.do_resize(); | |
72 |
|
76 | |||
73 | $('body').append('<div id="fonttest"><pre><span id="test1">x</span>'+ |
|
77 | $('body').append('<div id="fonttest"><pre><span id="test1">x</span>'+ | |
74 | '<span id="test2" style="font-weight: bold;">x</span>'+ |
|
78 | '<span id="test2" style="font-weight: bold;">x</span>'+ | |
75 | '<span id="test3" style="font-style: italic;">x</span></pre></div>'); |
|
79 | '<span id="test3" style="font-style: italic;">x</span></pre></div>'); | |
76 | var nh = $('#test1').innerHeight(); |
|
80 | var nh = $('#test1').innerHeight(); | |
77 | var bh = $('#test2').innerHeight(); |
|
81 | var bh = $('#test2').innerHeight(); | |
78 | var ih = $('#test3').innerHeight(); |
|
82 | var ih = $('#test3').innerHeight(); | |
79 | if(nh != bh || nh != ih) { |
|
83 | if(nh != bh || nh != ih) { | |
80 | $('head').append('<style>.CodeMirror span { vertical-align: bottom; }</style>'); |
|
84 | $('head').append('<style>.CodeMirror span { vertical-align: bottom; }</style>'); | |
81 | } |
|
85 | } | |
82 | $('#fonttest').remove(); |
|
86 | $('#fonttest').remove(); | |
83 |
|
87 | |||
84 | IPython.page.show(); |
|
88 | IPython.page.show(); | |
85 |
|
89 | |||
86 | IPython.layout_manager.do_resize(); |
|
90 | IPython.layout_manager.do_resize(); | |
87 | var first_load = function () { |
|
91 | var first_load = function () { | |
88 | IPython.layout_manager.do_resize(); |
|
92 | IPython.layout_manager.do_resize(); | |
89 | var hash = document.location.hash; |
|
93 | var hash = document.location.hash; | |
90 | if (hash) { |
|
94 | if (hash) { | |
91 | document.location.hash = ''; |
|
95 | document.location.hash = ''; | |
92 | document.location.hash = hash; |
|
96 | document.location.hash = hash; | |
93 | } |
|
97 | } | |
94 | IPython.notebook.set_autosave_interval(IPython.notebook.minimum_autosave_interval); |
|
98 | IPython.notebook.set_autosave_interval(IPython.notebook.minimum_autosave_interval); | |
95 | // only do this once |
|
99 | // only do this once | |
96 | $([IPython.events]).off('notebook_loaded.Notebook', first_load); |
|
100 | $([IPython.events]).off('notebook_loaded.Notebook', first_load); | |
97 | }; |
|
101 | }; | |
98 |
|
102 | |||
99 | $([IPython.events]).on('notebook_loaded.Notebook', first_load); |
|
103 | $([IPython.events]).on('notebook_loaded.Notebook', first_load); | |
100 | $([IPython.events]).trigger('app_initialized.NotebookApp'); |
|
104 | $([IPython.events]).trigger('app_initialized.NotebookApp'); | |
101 | IPython.notebook.load_notebook(opts.notebook_name, opts.notebook_path); |
|
105 | IPython.notebook.load_notebook(opts.notebook_name, opts.notebook_path); | |
102 |
|
106 | |||
103 | if (marked) { |
|
107 | if (marked) { | |
104 | marked.setOptions({ |
|
108 | marked.setOptions({ | |
105 | gfm : true, |
|
109 | gfm : true, | |
106 | tables: true, |
|
110 | tables: true, | |
107 | langPrefix: "language-", |
|
111 | langPrefix: "language-", | |
108 | highlight: function(code, lang) { |
|
112 | highlight: function(code, lang) { | |
109 | if (!lang) { |
|
113 | if (!lang) { | |
110 | // no language, no highlight |
|
114 | // no language, no highlight | |
111 | return code; |
|
115 | return code; | |
112 | } |
|
116 | } | |
113 | var highlighted; |
|
117 | var highlighted; | |
114 | try { |
|
118 | try { | |
115 | highlighted = hljs.highlight(lang, code, false); |
|
119 | highlighted = hljs.highlight(lang, code, false); | |
116 | } catch(err) { |
|
120 | } catch(err) { | |
117 | highlighted = hljs.highlightAuto(code); |
|
121 | highlighted = hljs.highlightAuto(code); | |
118 | } |
|
122 | } | |
119 | return highlighted.value; |
|
123 | return highlighted.value; | |
120 | } |
|
124 | } | |
121 | }); |
|
125 | }); | |
122 | } |
|
126 | } | |
123 | }); |
|
127 | }); |
@@ -1,335 +1,339 b'' | |||||
1 | // Copyright (c) IPython Development Team. |
|
1 | // Copyright (c) IPython Development Team. | |
2 | // Distributed under the terms of the Modified BSD License. |
|
2 | // Distributed under the terms of the Modified BSD License. | |
3 |
|
3 | |||
4 | //============================================================================ |
|
4 | //============================================================================ | |
5 | // MenuBar |
|
5 | // MenuBar | |
6 | //============================================================================ |
|
6 | //============================================================================ | |
7 |
|
7 | |||
8 | /** |
|
8 | /** | |
9 | * @module IPython |
|
9 | * @module IPython | |
10 | * @namespace IPython |
|
10 | * @namespace IPython | |
11 | * @submodule MenuBar |
|
11 | * @submodule MenuBar | |
12 | */ |
|
12 | */ | |
13 |
|
13 | |||
14 |
|
14 | |||
15 | var IPython = (function (IPython) { |
|
15 | var IPython = (function (IPython) { | |
16 | "use strict"; |
|
16 | "use strict"; | |
17 |
|
17 | |||
18 | var utils = IPython.utils; |
|
18 | var utils = IPython.utils; | |
19 |
|
19 | |||
20 | /** |
|
20 | /** | |
21 | * A MenuBar Class to generate the menubar of IPython notebook |
|
21 | * A MenuBar Class to generate the menubar of IPython notebook | |
22 | * @Class MenuBar |
|
22 | * @Class MenuBar | |
23 | * |
|
23 | * | |
24 | * @constructor |
|
24 | * @constructor | |
25 | * |
|
25 | * | |
26 | * |
|
26 | * | |
27 | * @param selector {string} selector for the menubar element in DOM |
|
27 | * @param selector {string} selector for the menubar element in DOM | |
28 | * @param {object} [options] |
|
28 | * @param {object} [options] | |
29 | * @param [options.base_url] {String} String to use for the |
|
29 | * @param [options.base_url] {String} String to use for the | |
30 | * base project url. Default is to inspect |
|
30 | * base project url. Default is to inspect | |
31 | * $('body').data('baseUrl'); |
|
31 | * $('body').data('baseUrl'); | |
32 | * does not support change for now is set through this option |
|
32 | * does not support change for now is set through this option | |
33 | */ |
|
33 | */ | |
34 | var MenuBar = function (selector, options) { |
|
34 | var MenuBar = function (selector, options) { | |
35 | options = options || {}; |
|
35 | options = options || {}; | |
36 | this.base_url = options.base_url || IPython.utils.get_body_data("baseUrl"); |
|
36 | this.base_url = options.base_url || IPython.utils.get_body_data("baseUrl"); | |
37 | this.selector = selector; |
|
37 | this.selector = selector; | |
38 | if (this.selector !== undefined) { |
|
38 | if (this.selector !== undefined) { | |
39 | this.element = $(selector); |
|
39 | this.element = $(selector); | |
40 | this.style(); |
|
40 | this.style(); | |
41 | this.bind_events(); |
|
41 | this.bind_events(); | |
42 | } |
|
42 | } | |
43 | }; |
|
43 | }; | |
44 |
|
44 | |||
45 | MenuBar.prototype.style = function () { |
|
45 | MenuBar.prototype.style = function () { | |
46 | this.element.addClass('border-box-sizing'); |
|
46 | this.element.addClass('border-box-sizing'); | |
47 | this.element.find("li").click(function (event, ui) { |
|
47 | this.element.find("li").click(function (event, ui) { | |
48 | // The selected cell loses focus when the menu is entered, so we |
|
48 | // The selected cell loses focus when the menu is entered, so we | |
49 | // re-select it upon selection. |
|
49 | // re-select it upon selection. | |
50 | var i = IPython.notebook.get_selected_index(); |
|
50 | var i = IPython.notebook.get_selected_index(); | |
51 | IPython.notebook.select(i); |
|
51 | IPython.notebook.select(i); | |
52 | } |
|
52 | } | |
53 | ); |
|
53 | ); | |
54 | }; |
|
54 | }; | |
55 |
|
55 | |||
56 | MenuBar.prototype._nbconvert = function (format, download) { |
|
56 | MenuBar.prototype._nbconvert = function (format, download) { | |
57 | download = download || false; |
|
57 | download = download || false; | |
58 | var notebook_path = IPython.notebook.notebook_path; |
|
58 | var notebook_path = IPython.notebook.notebook_path; | |
59 | var notebook_name = IPython.notebook.notebook_name; |
|
59 | var notebook_name = IPython.notebook.notebook_name; | |
60 | if (IPython.notebook.dirty) { |
|
60 | if (IPython.notebook.dirty) { | |
61 | IPython.notebook.save_notebook({async : false}); |
|
61 | IPython.notebook.save_notebook({async : false}); | |
62 | } |
|
62 | } | |
63 | var url = utils.url_join_encode( |
|
63 | var url = utils.url_join_encode( | |
64 | this.base_url, |
|
64 | this.base_url, | |
65 | 'nbconvert', |
|
65 | 'nbconvert', | |
66 | format, |
|
66 | format, | |
67 | notebook_path, |
|
67 | notebook_path, | |
68 | notebook_name |
|
68 | notebook_name | |
69 | ) + "?download=" + download.toString(); |
|
69 | ) + "?download=" + download.toString(); | |
70 |
|
70 | |||
71 | window.open(url); |
|
71 | window.open(url); | |
72 | }; |
|
72 | }; | |
73 |
|
73 | |||
74 | MenuBar.prototype.bind_events = function () { |
|
74 | MenuBar.prototype.bind_events = function () { | |
75 | // File |
|
75 | // File | |
76 | var that = this; |
|
76 | var that = this; | |
77 | this.element.find('#new_notebook').click(function () { |
|
77 | this.element.find('#new_notebook').click(function () { | |
78 | IPython.notebook.new_notebook(); |
|
78 | IPython.notebook.new_notebook(); | |
79 | }); |
|
79 | }); | |
80 | this.element.find('#open_notebook').click(function () { |
|
80 | this.element.find('#open_notebook').click(function () { | |
81 | window.open(utils.url_join_encode( |
|
81 | window.open(utils.url_join_encode( | |
82 | IPython.notebook.base_url, |
|
82 | IPython.notebook.base_url, | |
83 | 'tree', |
|
83 | 'tree', | |
84 | IPython.notebook.notebook_path |
|
84 | IPython.notebook.notebook_path | |
85 | )); |
|
85 | )); | |
86 | }); |
|
86 | }); | |
87 | this.element.find('#copy_notebook').click(function () { |
|
87 | this.element.find('#copy_notebook').click(function () { | |
88 | IPython.notebook.copy_notebook(); |
|
88 | IPython.notebook.copy_notebook(); | |
89 | return false; |
|
89 | return false; | |
90 | }); |
|
90 | }); | |
91 | this.element.find('#download_ipynb').click(function () { |
|
91 | this.element.find('#download_ipynb').click(function () { | |
92 | var base_url = IPython.notebook.base_url; |
|
92 | var base_url = IPython.notebook.base_url; | |
93 | var notebook_path = IPython.notebook.notebook_path; |
|
93 | var notebook_path = IPython.notebook.notebook_path; | |
94 | var notebook_name = IPython.notebook.notebook_name; |
|
94 | var notebook_name = IPython.notebook.notebook_name; | |
95 | if (IPython.notebook.dirty) { |
|
95 | if (IPython.notebook.dirty) { | |
96 | IPython.notebook.save_notebook({async : false}); |
|
96 | IPython.notebook.save_notebook({async : false}); | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | var url = utils.url_join_encode( |
|
99 | var url = utils.url_join_encode( | |
100 | base_url, |
|
100 | base_url, | |
101 | 'files', |
|
101 | 'files', | |
102 | notebook_path, |
|
102 | notebook_path, | |
103 | notebook_name |
|
103 | notebook_name | |
104 | ); |
|
104 | ); | |
105 | window.location.assign(url); |
|
105 | window.location.assign(url); | |
106 | }); |
|
106 | }); | |
107 |
|
107 | |||
108 | this.element.find('#print_preview').click(function () { |
|
108 | this.element.find('#print_preview').click(function () { | |
109 | that._nbconvert('html', false); |
|
109 | that._nbconvert('html', false); | |
110 | }); |
|
110 | }); | |
111 |
|
111 | |||
112 | this.element.find('#download_py').click(function () { |
|
112 | this.element.find('#download_py').click(function () { | |
113 | that._nbconvert('python', true); |
|
113 | that._nbconvert('python', true); | |
114 | }); |
|
114 | }); | |
115 |
|
115 | |||
116 | this.element.find('#download_html').click(function () { |
|
116 | this.element.find('#download_html').click(function () { | |
117 | that._nbconvert('html', true); |
|
117 | that._nbconvert('html', true); | |
118 | }); |
|
118 | }); | |
119 |
|
119 | |||
120 | this.element.find('#download_rst').click(function () { |
|
120 | this.element.find('#download_rst').click(function () { | |
121 | that._nbconvert('rst', true); |
|
121 | that._nbconvert('rst', true); | |
122 | }); |
|
122 | }); | |
123 |
|
123 | |||
124 | this.element.find('#download_pdf').click(function () { |
|
124 | this.element.find('#download_pdf').click(function () { | |
125 | that._nbconvert('pdf', true); |
|
125 | that._nbconvert('pdf', true); | |
126 | }); |
|
126 | }); | |
127 |
|
127 | |||
128 | this.element.find('#rename_notebook').click(function () { |
|
128 | this.element.find('#rename_notebook').click(function () { | |
129 | IPython.save_widget.rename_notebook(); |
|
129 | IPython.save_widget.rename_notebook(); | |
130 | }); |
|
130 | }); | |
131 | this.element.find('#save_checkpoint').click(function () { |
|
131 | this.element.find('#save_checkpoint').click(function () { | |
132 | IPython.notebook.save_checkpoint(); |
|
132 | IPython.notebook.save_checkpoint(); | |
133 | }); |
|
133 | }); | |
134 | this.element.find('#restore_checkpoint').click(function () { |
|
134 | this.element.find('#restore_checkpoint').click(function () { | |
135 | }); |
|
135 | }); | |
136 | this.element.find('#trust_notebook').click(function () { |
|
136 | this.element.find('#trust_notebook').click(function () { | |
137 | IPython.notebook.trust_notebook(); |
|
137 | IPython.notebook.trust_notebook(); | |
138 | }); |
|
138 | }); | |
139 | $([IPython.events]).on('trust_changed.Notebook', function (event, trusted) { |
|
139 | $([IPython.events]).on('trust_changed.Notebook', function (event, trusted) { | |
140 | if (trusted) { |
|
140 | if (trusted) { | |
141 | that.element.find('#trust_notebook') |
|
141 | that.element.find('#trust_notebook') | |
142 | .addClass("disabled") |
|
142 | .addClass("disabled") | |
143 | .find("a").text("Trusted Notebook"); |
|
143 | .find("a").text("Trusted Notebook"); | |
144 | } else { |
|
144 | } else { | |
145 | that.element.find('#trust_notebook') |
|
145 | that.element.find('#trust_notebook') | |
146 | .removeClass("disabled") |
|
146 | .removeClass("disabled") | |
147 | .find("a").text("Trust Notebook"); |
|
147 | .find("a").text("Trust Notebook"); | |
148 | } |
|
148 | } | |
149 | }); |
|
149 | }); | |
150 | this.element.find('#kill_and_exit').click(function () { |
|
150 | this.element.find('#kill_and_exit').click(function () { | |
151 | IPython.notebook.session.delete(); |
|
151 | IPython.notebook.session.delete(); | |
152 | setTimeout(function(){ |
|
152 | setTimeout(function(){ | |
153 | // allow closing of new tabs in Chromium, impossible in FF |
|
153 | // allow closing of new tabs in Chromium, impossible in FF | |
154 | window.open('', '_self', ''); |
|
154 | window.open('', '_self', ''); | |
155 | window.close(); |
|
155 | window.close(); | |
156 | }, 500); |
|
156 | }, 500); | |
157 | }); |
|
157 | }); | |
158 | // Edit |
|
158 | // Edit | |
159 | this.element.find('#cut_cell').click(function () { |
|
159 | this.element.find('#cut_cell').click(function () { | |
160 | IPython.notebook.cut_cell(); |
|
160 | IPython.notebook.cut_cell(); | |
161 | }); |
|
161 | }); | |
162 | this.element.find('#copy_cell').click(function () { |
|
162 | this.element.find('#copy_cell').click(function () { | |
163 | IPython.notebook.copy_cell(); |
|
163 | IPython.notebook.copy_cell(); | |
164 | }); |
|
164 | }); | |
165 | this.element.find('#delete_cell').click(function () { |
|
165 | this.element.find('#delete_cell').click(function () { | |
166 | IPython.notebook.delete_cell(); |
|
166 | IPython.notebook.delete_cell(); | |
167 | }); |
|
167 | }); | |
168 | this.element.find('#undelete_cell').click(function () { |
|
168 | this.element.find('#undelete_cell').click(function () { | |
169 | IPython.notebook.undelete_cell(); |
|
169 | IPython.notebook.undelete_cell(); | |
170 | }); |
|
170 | }); | |
171 | this.element.find('#split_cell').click(function () { |
|
171 | this.element.find('#split_cell').click(function () { | |
172 | IPython.notebook.split_cell(); |
|
172 | IPython.notebook.split_cell(); | |
173 | }); |
|
173 | }); | |
174 | this.element.find('#merge_cell_above').click(function () { |
|
174 | this.element.find('#merge_cell_above').click(function () { | |
175 | IPython.notebook.merge_cell_above(); |
|
175 | IPython.notebook.merge_cell_above(); | |
176 | }); |
|
176 | }); | |
177 | this.element.find('#merge_cell_below').click(function () { |
|
177 | this.element.find('#merge_cell_below').click(function () { | |
178 | IPython.notebook.merge_cell_below(); |
|
178 | IPython.notebook.merge_cell_below(); | |
179 | }); |
|
179 | }); | |
180 | this.element.find('#move_cell_up').click(function () { |
|
180 | this.element.find('#move_cell_up').click(function () { | |
181 | IPython.notebook.move_cell_up(); |
|
181 | IPython.notebook.move_cell_up(); | |
182 | }); |
|
182 | }); | |
183 | this.element.find('#move_cell_down').click(function () { |
|
183 | this.element.find('#move_cell_down').click(function () { | |
184 | IPython.notebook.move_cell_down(); |
|
184 | IPython.notebook.move_cell_down(); | |
185 | }); |
|
185 | }); | |
186 | this.element.find('#edit_nb_metadata').click(function () { |
|
186 | this.element.find('#edit_nb_metadata').click(function () { | |
187 | IPython.notebook.edit_metadata(); |
|
187 | IPython.notebook.edit_metadata(); | |
188 | }); |
|
188 | }); | |
189 |
|
189 | |||
190 | // View |
|
190 | // View | |
191 | this.element.find('#toggle_header').click(function () { |
|
191 | this.element.find('#toggle_header').click(function () { | |
192 | $('div#header').toggle(); |
|
192 | $('div#header').toggle(); | |
193 | IPython.layout_manager.do_resize(); |
|
193 | IPython.layout_manager.do_resize(); | |
194 | }); |
|
194 | }); | |
195 | this.element.find('#toggle_toolbar').click(function () { |
|
195 | this.element.find('#toggle_toolbar').click(function () { | |
196 | $('div#maintoolbar').toggle(); |
|
196 | $('div#maintoolbar').toggle(); | |
197 | IPython.layout_manager.do_resize(); |
|
197 | IPython.layout_manager.do_resize(); | |
198 | }); |
|
198 | }); | |
199 | // Insert |
|
199 | // Insert | |
200 | this.element.find('#insert_cell_above').click(function () { |
|
200 | this.element.find('#insert_cell_above').click(function () { | |
201 | IPython.notebook.insert_cell_above('code'); |
|
201 | IPython.notebook.insert_cell_above('code'); | |
202 | IPython.notebook.select_prev(); |
|
202 | IPython.notebook.select_prev(); | |
203 | }); |
|
203 | }); | |
204 | this.element.find('#insert_cell_below').click(function () { |
|
204 | this.element.find('#insert_cell_below').click(function () { | |
205 | IPython.notebook.insert_cell_below('code'); |
|
205 | IPython.notebook.insert_cell_below('code'); | |
206 | IPython.notebook.select_next(); |
|
206 | IPython.notebook.select_next(); | |
207 | }); |
|
207 | }); | |
208 | // Cell |
|
208 | // Cell | |
209 | this.element.find('#run_cell').click(function () { |
|
209 | this.element.find('#run_cell').click(function () { | |
210 | IPython.notebook.execute_cell(); |
|
210 | IPython.notebook.execute_cell(); | |
211 | }); |
|
211 | }); | |
212 | this.element.find('#run_cell_select_below').click(function () { |
|
212 | this.element.find('#run_cell_select_below').click(function () { | |
213 | IPython.notebook.execute_cell_and_select_below(); |
|
213 | IPython.notebook.execute_cell_and_select_below(); | |
214 | }); |
|
214 | }); | |
215 | this.element.find('#run_cell_insert_below').click(function () { |
|
215 | this.element.find('#run_cell_insert_below').click(function () { | |
216 | IPython.notebook.execute_cell_and_insert_below(); |
|
216 | IPython.notebook.execute_cell_and_insert_below(); | |
217 | }); |
|
217 | }); | |
218 | this.element.find('#run_all_cells').click(function () { |
|
218 | this.element.find('#run_all_cells').click(function () { | |
219 | IPython.notebook.execute_all_cells(); |
|
219 | IPython.notebook.execute_all_cells(); | |
220 | }); |
|
220 | }); | |
221 | this.element.find('#run_all_cells_above').click(function () { |
|
221 | this.element.find('#run_all_cells_above').click(function () { | |
222 | IPython.notebook.execute_cells_above(); |
|
222 | IPython.notebook.execute_cells_above(); | |
223 | }); |
|
223 | }); | |
224 | this.element.find('#run_all_cells_below').click(function () { |
|
224 | this.element.find('#run_all_cells_below').click(function () { | |
225 | IPython.notebook.execute_cells_below(); |
|
225 | IPython.notebook.execute_cells_below(); | |
226 | }); |
|
226 | }); | |
227 | this.element.find('#to_code').click(function () { |
|
227 | this.element.find('#to_code').click(function () { | |
228 | IPython.notebook.to_code(); |
|
228 | IPython.notebook.to_code(); | |
229 | }); |
|
229 | }); | |
230 | this.element.find('#to_markdown').click(function () { |
|
230 | this.element.find('#to_markdown').click(function () { | |
231 | IPython.notebook.to_markdown(); |
|
231 | IPython.notebook.to_markdown(); | |
232 | }); |
|
232 | }); | |
233 | this.element.find('#to_raw').click(function () { |
|
233 | this.element.find('#to_raw').click(function () { | |
234 | IPython.notebook.to_raw(); |
|
234 | IPython.notebook.to_raw(); | |
235 | }); |
|
235 | }); | |
236 | this.element.find('#to_heading1').click(function () { |
|
236 | this.element.find('#to_heading1').click(function () { | |
237 | IPython.notebook.to_heading(undefined, 1); |
|
237 | IPython.notebook.to_heading(undefined, 1); | |
238 | }); |
|
238 | }); | |
239 | this.element.find('#to_heading2').click(function () { |
|
239 | this.element.find('#to_heading2').click(function () { | |
240 | IPython.notebook.to_heading(undefined, 2); |
|
240 | IPython.notebook.to_heading(undefined, 2); | |
241 | }); |
|
241 | }); | |
242 | this.element.find('#to_heading3').click(function () { |
|
242 | this.element.find('#to_heading3').click(function () { | |
243 | IPython.notebook.to_heading(undefined, 3); |
|
243 | IPython.notebook.to_heading(undefined, 3); | |
244 | }); |
|
244 | }); | |
245 | this.element.find('#to_heading4').click(function () { |
|
245 | this.element.find('#to_heading4').click(function () { | |
246 | IPython.notebook.to_heading(undefined, 4); |
|
246 | IPython.notebook.to_heading(undefined, 4); | |
247 | }); |
|
247 | }); | |
248 | this.element.find('#to_heading5').click(function () { |
|
248 | this.element.find('#to_heading5').click(function () { | |
249 | IPython.notebook.to_heading(undefined, 5); |
|
249 | IPython.notebook.to_heading(undefined, 5); | |
250 | }); |
|
250 | }); | |
251 | this.element.find('#to_heading6').click(function () { |
|
251 | this.element.find('#to_heading6').click(function () { | |
252 | IPython.notebook.to_heading(undefined, 6); |
|
252 | IPython.notebook.to_heading(undefined, 6); | |
253 | }); |
|
253 | }); | |
254 |
|
254 | |||
255 | this.element.find('#toggle_current_output').click(function () { |
|
255 | this.element.find('#toggle_current_output').click(function () { | |
256 | IPython.notebook.toggle_output(); |
|
256 | IPython.notebook.toggle_output(); | |
257 | }); |
|
257 | }); | |
258 | this.element.find('#toggle_current_output_scroll').click(function () { |
|
258 | this.element.find('#toggle_current_output_scroll').click(function () { | |
259 | IPython.notebook.toggle_output_scroll(); |
|
259 | IPython.notebook.toggle_output_scroll(); | |
260 | }); |
|
260 | }); | |
261 | this.element.find('#clear_current_output').click(function () { |
|
261 | this.element.find('#clear_current_output').click(function () { | |
262 | IPython.notebook.clear_output(); |
|
262 | IPython.notebook.clear_output(); | |
263 | }); |
|
263 | }); | |
264 |
|
264 | |||
265 | this.element.find('#toggle_all_output').click(function () { |
|
265 | this.element.find('#toggle_all_output').click(function () { | |
266 | IPython.notebook.toggle_all_output(); |
|
266 | IPython.notebook.toggle_all_output(); | |
267 | }); |
|
267 | }); | |
268 | this.element.find('#toggle_all_output_scroll').click(function () { |
|
268 | this.element.find('#toggle_all_output_scroll').click(function () { | |
269 | IPython.notebook.toggle_all_output_scroll(); |
|
269 | IPython.notebook.toggle_all_output_scroll(); | |
270 | }); |
|
270 | }); | |
271 | this.element.find('#clear_all_output').click(function () { |
|
271 | this.element.find('#clear_all_output').click(function () { | |
272 | IPython.notebook.clear_all_output(); |
|
272 | IPython.notebook.clear_all_output(); | |
273 | }); |
|
273 | }); | |
274 |
|
274 | |||
275 | // Kernel |
|
275 | // Kernel | |
276 | this.element.find('#int_kernel').click(function () { |
|
276 | this.element.find('#int_kernel').click(function () { | |
277 | IPython.notebook.session.interrupt_kernel(); |
|
277 | IPython.notebook.session.interrupt_kernel(); | |
278 | }); |
|
278 | }); | |
279 | this.element.find('#restart_kernel').click(function () { |
|
279 | this.element.find('#restart_kernel').click(function () { | |
280 | IPython.notebook.restart_kernel(); |
|
280 | IPython.notebook.restart_kernel(); | |
281 | }); |
|
281 | }); | |
282 | // Help |
|
282 | // Help | |
283 | this.element.find('#notebook_tour').click(function () { |
|
283 | if (IPython.tour) { | |
284 | IPython.tour.start(); |
|
284 | this.element.find('#notebook_tour').click(function () { | |
285 | }); |
|
285 | IPython.tour.start(); | |
|
286 | }); | |||
|
287 | } else { | |||
|
288 | this.element.find('#notebook_tour').addClass("disabled"); | |||
|
289 | } | |||
286 | this.element.find('#keyboard_shortcuts').click(function () { |
|
290 | this.element.find('#keyboard_shortcuts').click(function () { | |
287 | IPython.quick_help.show_keyboard_shortcuts(); |
|
291 | IPython.quick_help.show_keyboard_shortcuts(); | |
288 | }); |
|
292 | }); | |
289 |
|
293 | |||
290 | this.update_restore_checkpoint(null); |
|
294 | this.update_restore_checkpoint(null); | |
291 |
|
295 | |||
292 | $([IPython.events]).on('checkpoints_listed.Notebook', function (event, data) { |
|
296 | $([IPython.events]).on('checkpoints_listed.Notebook', function (event, data) { | |
293 | that.update_restore_checkpoint(IPython.notebook.checkpoints); |
|
297 | that.update_restore_checkpoint(IPython.notebook.checkpoints); | |
294 | }); |
|
298 | }); | |
295 |
|
299 | |||
296 | $([IPython.events]).on('checkpoint_created.Notebook', function (event, data) { |
|
300 | $([IPython.events]).on('checkpoint_created.Notebook', function (event, data) { | |
297 | that.update_restore_checkpoint(IPython.notebook.checkpoints); |
|
301 | that.update_restore_checkpoint(IPython.notebook.checkpoints); | |
298 | }); |
|
302 | }); | |
299 | }; |
|
303 | }; | |
300 |
|
304 | |||
301 | MenuBar.prototype.update_restore_checkpoint = function(checkpoints) { |
|
305 | MenuBar.prototype.update_restore_checkpoint = function(checkpoints) { | |
302 | var ul = this.element.find("#restore_checkpoint").find("ul"); |
|
306 | var ul = this.element.find("#restore_checkpoint").find("ul"); | |
303 | ul.empty(); |
|
307 | ul.empty(); | |
304 | if (!checkpoints || checkpoints.length === 0) { |
|
308 | if (!checkpoints || checkpoints.length === 0) { | |
305 | ul.append( |
|
309 | ul.append( | |
306 | $("<li/>") |
|
310 | $("<li/>") | |
307 | .addClass("disabled") |
|
311 | .addClass("disabled") | |
308 | .append( |
|
312 | .append( | |
309 | $("<a/>") |
|
313 | $("<a/>") | |
310 | .text("No checkpoints") |
|
314 | .text("No checkpoints") | |
311 | ) |
|
315 | ) | |
312 | ); |
|
316 | ); | |
313 | return; |
|
317 | return; | |
314 | } |
|
318 | } | |
315 |
|
319 | |||
316 | checkpoints.map(function (checkpoint) { |
|
320 | checkpoints.map(function (checkpoint) { | |
317 | var d = new Date(checkpoint.last_modified); |
|
321 | var d = new Date(checkpoint.last_modified); | |
318 | ul.append( |
|
322 | ul.append( | |
319 | $("<li/>").append( |
|
323 | $("<li/>").append( | |
320 | $("<a/>") |
|
324 | $("<a/>") | |
321 | .attr("href", "#") |
|
325 | .attr("href", "#") | |
322 | .text(d.format("mmm dd HH:MM:ss")) |
|
326 | .text(d.format("mmm dd HH:MM:ss")) | |
323 | .click(function () { |
|
327 | .click(function () { | |
324 | IPython.notebook.restore_checkpoint_dialog(checkpoint); |
|
328 | IPython.notebook.restore_checkpoint_dialog(checkpoint); | |
325 | }) |
|
329 | }) | |
326 | ) |
|
330 | ) | |
327 | ); |
|
331 | ); | |
328 | }); |
|
332 | }); | |
329 | }; |
|
333 | }; | |
330 |
|
334 | |||
331 | IPython.MenuBar = MenuBar; |
|
335 | IPython.MenuBar = MenuBar; | |
332 |
|
336 | |||
333 | return IPython; |
|
337 | return IPython; | |
334 |
|
338 | |||
335 | }(IPython)); |
|
339 | }(IPython)); |
General Comments 0
You need to be logged in to leave comments.
Login now