Show More
@@ -1,49 +1,58 b'' | |||||
1 | // leave at least 2 line with only a star on it below, or doc generation fails |
|
1 | // leave at least 2 line with only a star on it below, or doc generation fails | |
2 | /** |
|
2 | /** | |
3 | * |
|
3 | * | |
4 | * |
|
4 | * | |
5 | * Placeholder for custom user javascript |
|
5 | * Placeholder for custom user javascript | |
6 | * mainly to be overridden in profile/static/custom/custom.js |
|
6 | * mainly to be overridden in profile/static/custom/custom.js | |
7 | * This will always be an empty file in IPython |
|
7 | * This will always be an empty file in IPython | |
8 | * |
|
8 | * | |
9 | * User could add any javascript in the `profile/static/custom/custom.js` file |
|
9 | * User could add any javascript in the `profile/static/custom/custom.js` file | |
10 | * (and should create it if it does not exist). |
|
10 | * (and should create it if it does not exist). | |
11 | * It will be executed by the ipython notebook at load time. |
|
11 | * It will be executed by the ipython notebook at load time. | |
12 | * |
|
12 | * | |
13 | * Same thing with `profile/static/custom/custom.css` to inject custom css into the notebook. |
|
13 | * Same thing with `profile/static/custom/custom.css` to inject custom css into the notebook. | |
14 | * |
|
14 | * | |
15 | * Example : |
|
15 | * __Example 1:__ | |
16 | * |
|
16 | * | |
17 | * Create a custom button in toolbar that execute `%qtconsole` in kernel |
|
17 | * Create a custom button in toolbar that execute `%qtconsole` in kernel | |
18 | * and hence open a qtconsole attached to the same kernel as the current notebook |
|
18 | * and hence open a qtconsole attached to the same kernel as the current notebook | |
19 | * |
|
19 | * | |
20 | * $([IPython.events]).on('app_initialized.NotebookApp', function(){ |
|
20 | * $([IPython.events]).on('app_initialized.NotebookApp', function(){ | |
21 | * IPython.toolbar.add_buttons_group([ |
|
21 | * IPython.toolbar.add_buttons_group([ | |
22 | * { |
|
22 | * { | |
23 | * 'label' : 'run qtconsole', |
|
23 | * 'label' : 'run qtconsole', | |
24 | * 'icon' : 'icon-terminal', // select your icon from http://fortawesome.github.io/Font-Awesome/icons |
|
24 | * 'icon' : 'icon-terminal', // select your icon from http://fortawesome.github.io/Font-Awesome/icons | |
25 | * 'callback': function () { |
|
25 | * 'callback': function () { | |
26 | * IPython.notebook.kernel.execute('%qtconsole') |
|
26 | * IPython.notebook.kernel.execute('%qtconsole') | |
27 | * } |
|
27 | * } | |
28 | * } |
|
28 | * } | |
29 | * // add more button here if needed. |
|
29 | * // add more button here if needed. | |
30 | * ]); |
|
30 | * ]); | |
31 | * }); |
|
31 | * }); | |
32 | * |
|
32 | * | |
33 | * Example : |
|
33 | * __Example 2:__ | |
|
34 | * | |||
|
35 | * At the completion of the dashboard loading, load an unofficial javascript extension | |||
|
36 | * that is installed in profile/static/custom/ | |||
|
37 | * | |||
|
38 | * $([IPython.events]).on('app_initialized.DashboardApp', function(){ | |||
|
39 | * require(['custom/unofficial_extension.js']) | |||
|
40 | * }); | |||
|
41 | * | |||
|
42 | * __Example 3:__ | |||
34 | * |
|
43 | * | |
35 | * Use `jQuery.getScript(url [, success(script, textStatus, jqXHR)] );` |
|
44 | * Use `jQuery.getScript(url [, success(script, textStatus, jqXHR)] );` | |
36 | * to load custom script into the notebook. |
|
45 | * to load custom script into the notebook. | |
37 | * |
|
46 | * | |
38 | * // to load the metadata ui extension example. |
|
47 | * // to load the metadata ui extension example. | |
39 | * $.getScript('/static/notebook/js/celltoolbarpresets/example.js'); |
|
48 | * $.getScript('/static/notebook/js/celltoolbarpresets/example.js'); | |
40 | * // or |
|
49 | * // or | |
41 | * // to load the metadata ui extension to control slideshow mode / reveal js for nbconvert |
|
50 | * // to load the metadata ui extension to control slideshow mode / reveal js for nbconvert | |
42 | * $.getScript('/static/notebook/js/celltoolbarpresets/slideshow.js'); |
|
51 | * $.getScript('/static/notebook/js/celltoolbarpresets/slideshow.js'); | |
43 | * |
|
52 | * | |
44 | * |
|
53 | * | |
45 | * @module IPython |
|
54 | * @module IPython | |
46 | * @namespace IPython |
|
55 | * @namespace IPython | |
47 | * @class customjs |
|
56 | * @class customjs | |
48 | * @static |
|
57 | * @static | |
49 | */ |
|
58 | */ |
@@ -1,91 +1,92 b'' | |||||
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 | // On document ready |
|
9 | // On document ready | |
10 | //============================================================================ |
|
10 | //============================================================================ | |
11 |
|
11 | |||
12 |
|
12 | |||
13 | $(document).ready(function () { |
|
13 | $(document).ready(function () { | |
14 |
|
14 | |||
15 | IPython.page = new IPython.Page(); |
|
15 | IPython.page = new IPython.Page(); | |
16 |
|
16 | |||
17 | $('#new_notebook').button().click(function (e) { |
|
17 | $('#new_notebook').button().click(function (e) { | |
18 | IPython.notebook_list.new_notebook() |
|
18 | IPython.notebook_list.new_notebook() | |
19 | }); |
|
19 | }); | |
20 |
|
20 | |||
21 | var opts = { |
|
21 | var opts = { | |
22 | base_url : IPython.utils.get_body_data("baseUrl"), |
|
22 | base_url : IPython.utils.get_body_data("baseUrl"), | |
23 | notebook_path : IPython.utils.get_body_data("notebookPath"), |
|
23 | notebook_path : IPython.utils.get_body_data("notebookPath"), | |
24 | }; |
|
24 | }; | |
25 | IPython.session_list = new IPython.SesssionList(opts); |
|
25 | IPython.session_list = new IPython.SesssionList(opts); | |
26 | IPython.notebook_list = new IPython.NotebookList('#notebook_list', opts); |
|
26 | IPython.notebook_list = new IPython.NotebookList('#notebook_list', opts); | |
27 | IPython.cluster_list = new IPython.ClusterList('#cluster_list', opts); |
|
27 | IPython.cluster_list = new IPython.ClusterList('#cluster_list', opts); | |
28 | IPython.kernel_list = new IPython.KernelList('#running_list', opts); |
|
28 | IPython.kernel_list = new IPython.KernelList('#running_list', opts); | |
29 | IPython.login_widget = new IPython.LoginWidget('#login_widget', opts); |
|
29 | IPython.login_widget = new IPython.LoginWidget('#login_widget', opts); | |
30 |
|
30 | |||
31 | var interval_id=0; |
|
31 | var interval_id=0; | |
32 | // auto refresh every xx secondes, no need to be fast, |
|
32 | // auto refresh every xx secondes, no need to be fast, | |
33 | // update is done at least when page get focus |
|
33 | // update is done at least when page get focus | |
34 | var time_refresh = 60; // in sec |
|
34 | var time_refresh = 60; // in sec | |
35 |
|
35 | |||
36 | var enable_autorefresh = function(){ |
|
36 | var enable_autorefresh = function(){ | |
37 | //refresh immediately , then start interval |
|
37 | //refresh immediately , then start interval | |
38 | if($('.upload_button').length == 0) |
|
38 | if($('.upload_button').length == 0) | |
39 | { |
|
39 | { | |
40 | IPython.session_list.load_sessions(); |
|
40 | IPython.session_list.load_sessions(); | |
41 | IPython.cluster_list.load_list(); |
|
41 | IPython.cluster_list.load_list(); | |
42 | } |
|
42 | } | |
43 | if (!interval_id){ |
|
43 | if (!interval_id){ | |
44 | interval_id = setInterval(function(){ |
|
44 | interval_id = setInterval(function(){ | |
45 | if($('.upload_button').length == 0) |
|
45 | if($('.upload_button').length == 0) | |
46 | { |
|
46 | { | |
47 | IPython.session_list.load_sessions(); |
|
47 | IPython.session_list.load_sessions(); | |
48 | IPython.cluster_list.load_list(); |
|
48 | IPython.cluster_list.load_list(); | |
49 | } |
|
49 | } | |
50 | }, time_refresh*1000); |
|
50 | }, time_refresh*1000); | |
51 | } |
|
51 | } | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | var disable_autorefresh = function(){ |
|
54 | var disable_autorefresh = function(){ | |
55 | clearInterval(interval_id); |
|
55 | clearInterval(interval_id); | |
56 | interval_id = 0; |
|
56 | interval_id = 0; | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | // stop autorefresh when page lose focus |
|
59 | // stop autorefresh when page lose focus | |
60 | $(window).blur(function() { |
|
60 | $(window).blur(function() { | |
61 | disable_autorefresh(); |
|
61 | disable_autorefresh(); | |
62 | }) |
|
62 | }) | |
63 |
|
63 | |||
64 | //re-enable when page get focus back |
|
64 | //re-enable when page get focus back | |
65 | $(window).focus(function() { |
|
65 | $(window).focus(function() { | |
66 | enable_autorefresh(); |
|
66 | enable_autorefresh(); | |
67 | }); |
|
67 | }); | |
68 |
|
68 | |||
69 | // finally start it, it will refresh immediately |
|
69 | // finally start it, it will refresh immediately | |
70 | enable_autorefresh(); |
|
70 | enable_autorefresh(); | |
71 |
|
71 | |||
72 | IPython.page.show(); |
|
72 | IPython.page.show(); | |
|
73 | $([IPython.events]).trigger('app_initialized.DashboardApp'); | |||
73 |
|
74 | |||
74 | // bound the upload method to the on change of the file select list |
|
75 | // bound the upload method to the on change of the file select list | |
75 | $("#alternate_upload").change(function (event){ |
|
76 | $("#alternate_upload").change(function (event){ | |
76 | IPython.notebook_list.handleFilesUpload(event,'form'); |
|
77 | IPython.notebook_list.handleFilesUpload(event,'form'); | |
77 | }); |
|
78 | }); | |
78 |
|
79 | |||
79 | // set hash on tab click |
|
80 | // set hash on tab click | |
80 | $("#tabs").find("a").click(function() { |
|
81 | $("#tabs").find("a").click(function() { | |
81 | window.location.hash = $(this).attr("href"); |
|
82 | window.location.hash = $(this).attr("href"); | |
82 | }) |
|
83 | }) | |
83 |
|
84 | |||
84 | // load tab if url hash |
|
85 | // load tab if url hash | |
85 | if (window.location.hash) { |
|
86 | if (window.location.hash) { | |
86 | $("#tabs").find("a[href=" + window.location.hash + "]").click(); |
|
87 | $("#tabs").find("a[href=" + window.location.hash + "]").click(); | |
87 | } |
|
88 | } | |
88 |
|
89 | |||
89 |
|
90 | |||
90 | }); |
|
91 | }); | |
91 |
|
92 |
General Comments 0
You need to be logged in to leave comments.
Login now