Created
January 26, 2021 00:50
-
-
Save langheran/540727c8b1aca0d6155072498b71478a to your computer and use it in GitHub Desktop.
~/.jupyter/custom/custom.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// leave at least 2 line with only a star on it below, or doc generation fails | |
/** | |
* | |
* | |
* Placeholder for custom user javascript | |
* mainly to be overridden in profile/static/custom/custom.js | |
* This will always be an empty file in IPython | |
* | |
* User could add any javascript in the `profile/static/custom/custom.js` file. | |
* It will be executed by the ipython notebook at load time. | |
* | |
* Same thing with `profile/static/custom/custom.css` to inject custom css into the notebook. | |
* | |
* | |
* The object available at load time depend on the version of IPython in use. | |
* there is no guaranties of API stability. | |
* | |
* The example below explain the principle, and might not be valid. | |
* | |
* Instances are created after the loading of this file and might need to be accessed using events: | |
* define([ | |
* 'base/js/namespace', | |
* 'base/js/events' | |
* ], function(IPython, events) { | |
* events.on("app_initialized.NotebookApp", function () { | |
* IPython.keyboard_manager.... | |
* }); | |
* }); | |
* | |
* __Example 1:__ | |
* | |
* Create a custom button in toolbar that execute `%qtconsole` in kernel | |
* and hence open a qtconsole attached to the same kernel as the current notebook | |
* | |
* define([ | |
* 'base/js/namespace', | |
* 'base/js/events' | |
* ], function(IPython, events) { | |
* events.on('app_initialized.NotebookApp', function(){ | |
* IPython.toolbar.add_buttons_group([ | |
* { | |
* 'label' : 'run qtconsole', | |
* 'icon' : 'icon-terminal', // select your icon from http://fortawesome.github.io/Font-Awesome/icons | |
* 'callback': function () { | |
* IPython.notebook.kernel.execute('%qtconsole') | |
* } | |
* } | |
* // add more button here if needed. | |
* ]); | |
* }); | |
* }); | |
* | |
* __Example 2:__ | |
* | |
* At the completion of the dashboard loading, load an unofficial javascript extension | |
* that is installed in profile/static/custom/ | |
* | |
* define([ | |
* 'base/js/events' | |
* ], function(events) { | |
* events.on('app_initialized.DashboardApp', function(){ | |
* require(['custom/unofficial_extension.js']) | |
* }); | |
* }); | |
* | |
* __Example 3:__ | |
* | |
* Use `jQuery.getScript(url [, success(script, textStatus, jqXHR)] );` | |
* to load custom script into the notebook. | |
* | |
* // to load the metadata ui extension example. | |
* $.getScript('/static/notebook/js/celltoolbarpresets/example.js'); | |
* // or | |
* // to load the metadata ui extension to control slideshow mode / reveal js for nbconvert | |
* $.getScript('/static/notebook/js/celltoolbarpresets/slideshow.js'); | |
* | |
* | |
* @module IPython | |
* @namespace IPython | |
* @class customjs | |
* @static | |
*/ | |
define([ | |
'base/js/namespace', | |
'base/js/events' | |
], | |
function(IPython, events) { | |
events.on("app_initialized.NotebookApp", | |
function () { | |
IPython.Cell.options_default.cm_config.lineNumbers = true; | |
} | |
); | |
} | |
); | |
IPython.keyboard_manager.command_shortcuts.add_shortcut('Ctrl-k', { | |
help : 'move up selected cells', | |
help_index : 'jupyter-notebook:move-selection-up', | |
handler : function (event) { | |
IPython.notebook.move_selection_up(); | |
return false; | |
}} | |
); | |
IPython.keyboard_manager.command_shortcuts.add_shortcut('Ctrl-j', { | |
help : 'move down selected cells', | |
help_index : 'jupyter-notebook:move-selection-down', | |
handler : function (event) { | |
IPython.notebook.move_selection_down(); | |
return false; | |
}} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment