Skip to content

Commit

Permalink
Merge pull request #102 from Carreau/no-global
Browse files Browse the repository at this point in the history
Start working on removing global JS IPython
  • Loading branch information
jdfreder committed Jun 1, 2015
2 parents 1922759 + 26c3628 commit 5c18ecb
Show file tree
Hide file tree
Showing 36 changed files with 173 additions and 212 deletions.
39 changes: 34 additions & 5 deletions examples/Notebook/Custom Keyboard Shortcuts.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Starting with IPython 2.0 keyboard shortcuts in command and edit mode are fully customizable. These customizations are made using the IPython JavaScript API. Here is an example that makes the `r` key available for running a cell:"
"Starting with IPython 2.0 keyboard shortcuts in command and edit mode are fully customizable. These customizations are made using the Jupyter JavaScript API. Here is an example that makes the `r` key available for running a cell:"
]
},
{
Expand All @@ -24,7 +24,7 @@
"source": [
"%%javascript\n",
"\n",
"IPython.keyboard_manager.command_shortcuts.add_shortcut('r', {\n",
"Jupyter.keyboard_manager.command_shortcuts.add_shortcut('r', {\n",
" help : 'run cell',\n",
" help_index : 'zz',\n",
" handler : function (event) {\n",
Expand All @@ -34,6 +34,13 @@
");"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\"By default the keypress `r`, while in command mode, changes the type of the selected cell to `raw`. This shortcut is overridden by the code in the previous cell, and thus the action no longer be available via the keypress `r`.\""
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -55,7 +62,7 @@
"source": [
"%%javascript\n",
"\n",
"IPython.keyboard_manager.command_shortcuts.add_shortcut('r', function (event) {\n",
"Jupyter.keyboard_manager.command_shortcuts.add_shortcut('r', function (event) {\n",
" IPython.notebook.execute_cell();\n",
" return false;\n",
"});"
Expand All @@ -78,14 +85,36 @@
"source": [
"%%javascript\n",
"\n",
"IPython.keyboard_manager.command_shortcuts.remove_shortcut('r');"
"Jupyter.keyboard_manager.command_shortcuts.remove_shortcut('r');"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you want your keyboard shortcuts to be active for all of your notebooks, put the above API calls into your `<profile>/static/custom/custom.js` file."
"If you want your keyboard shortcuts to be active for all of your notebooks, put the above API calls into your `custom.js` file."
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"Of course we provide name for majority of existing action so that you do not have to re-write everything, here is for example how to bind `r` back to it's initial behavior:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%%javascript\n",
"\n",
"Jupyter.keyboard_manager.command_shortcuts.add_shortcut('r', 'ipython.change-selected-cell-to-raw-cell');"
]
}
],
Expand Down
7 changes: 1 addition & 6 deletions notebook/static/auth/js/loginwidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
// Distributed under the terms of the Modified BSD License.

define([
'base/js/namespace',
'base/js/utils',
'jquery',
], function(IPython, utils, $){
], function(utils, $){
"use strict";

var LoginWidget = function (selector, options) {
Expand All @@ -19,7 +18,6 @@ define([
};



LoginWidget.prototype.bind_events = function () {
var that = this;
this.element.find("button#logout").click(function () {
Expand All @@ -36,8 +34,5 @@ define([
});
};

// Set module variables
IPython.LoginWidget = LoginWidget;

return {'LoginWidget': LoginWidget};
});
4 changes: 0 additions & 4 deletions notebook/static/base/js/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ define(function(require) {
"use strict";

var CodeMirror = require('codemirror/lib/codemirror');
var IPython = require('base/js/namespace');
var $ = require('jquery');

/**
Expand Down Expand Up @@ -205,8 +204,5 @@ define(function(require) {
edit_metadata : edit_metadata,
};

// Backwards compatability.
IPython.dialog = dialog;

return dialog;
});
6 changes: 1 addition & 5 deletions notebook/static/base/js/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
*/

define([
'base/js/namespace',
'jquery',
'base/js/utils',
'underscore',
], function(IPython, $, utils, _) {
], function($, utils, _) {
"use strict";


Expand Down Expand Up @@ -447,8 +446,5 @@ define([
event_to_shortcut : event_to_shortcut,
};

// For backwards compatibility.
IPython.keyboard = keyboard;

return keyboard;
});
84 changes: 79 additions & 5 deletions notebook/static/base/js/namespace.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,84 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

var IPython = IPython || {};
define([], function(){

var Jupyter = Jupyter || {};

var jprop = function(name, module_path){
Object.defineProperty(Jupyter, name, {
get: function() {
console.warn('accessing `'+name+'` is deprecated. Use `require("'+module_path+'")`');
return require(module_path);
},
enumerable: true,
configurable: false
});
}

var jglobal = function(name, module_path){
Object.defineProperty(Jupyter, name, {
get: function() {
console.warn('accessing `'+name+'` is deprecated. Use `require("'+module_path+'").'+name+'`');
return require(module_path)[name];
},
enumerable: true,
configurable: false
});
}

define(function(){
"use strict";
IPython.version = "4.0.0.dev";
IPython._target = '_blank';
return IPython;

// expose modules

jprop('utils','base/js/utils')

//Jupyter.load_extensions = Jupyter.utils.load_extensions;
//
jprop('security','base/js/security');
jprop('keyboard','base/js/keyboard');
jprop('dialog','base/js/dialog');
jprop('mathjaxutils','notebook/js/mathjaxutils');


//// exposed constructors
jglobal('CommManager','services/kernels/comm')
jglobal('Comm','services/kernels/comm')

jglobal('NotificationWidget','base/js/notificationwidget');
jglobal('Kernel','services/kernels/kernel');
jglobal('Session','services/sessions/session');
jglobal('LoginWidget','auth/js/loginwidget');
jglobal('Page','base/js/page');

// notebook
jglobal('TextCell','notebook/js/textcell');
jglobal('OutputArea','notebook/js/outputarea');
jglobal('KeyboardManager','notebook/js/keyboardmanager');
jglobal('Completer','notebook/js/completer');
jglobal('Notebook','notebook/js/notebook');
jglobal('Tooltip','notebook/js/tooltip');
jglobal('Toolbar','notebook/js/toolbar');
jglobal('SaveWidget','notebook/js/savewidget');
jglobal('Pager','notebook/js/pager');
jglobal('QuickHelp','notebook/js/quickhelp');
jglobal('MarkdownCell','notebook/js/textcell');
jglobal('RawCell','notebook/js/textcell');
jglobal('Cell','notebook/js/cell');
jglobal('MainToolBar','notebook/js/maintoolbar');
jglobal('NotebookNotificationArea','notebook/js/notificationarea');
jglobal('NotebookTour', 'notebook/js/tour');
jglobal('MenuBar', 'notebook/js/menubar');

// tree
jglobal('SessionList','tree/js/sessionlist');
jglobal('ClusterList','tree/js/clusterlist');
jglobal('ClusterItem','tree/js/clusterlist');

Jupyter.version = "4.0.0.dev";
Jupyter._target = '_blank';
return Jupyter;
});

// deprecated since 4.0, remove in 5+
var IPython = Jupyter
6 changes: 1 addition & 5 deletions notebook/static/base/js/notificationwidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
// Distributed under the terms of the Modified BSD License.

define([
'base/js/namespace',
'jquery',
], function(IPython, $) {
], function($) {
"use strict";

/**
Expand Down Expand Up @@ -167,8 +166,5 @@ define([
return this.inner.html();
};

// For backwards compatibility.
IPython.NotificationWidget = NotificationWidget;

return {'NotificationWidget': NotificationWidget};
});
5 changes: 1 addition & 4 deletions notebook/static/base/js/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
// Distributed under the terms of the Modified BSD License.

define([
'base/js/namespace',
'jquery',
'base/js/events',
], function(IPython, $, events){
], function($, events){
"use strict";

var Page = function () {
Expand Down Expand Up @@ -59,7 +58,5 @@ define([
$('div#site').height($(window).height() - $('#header').height());
};

// Register self in the global namespace for convenience.
IPython.Page = Page;
return {'Page': Page};
});
5 changes: 1 addition & 4 deletions notebook/static/base/js/security.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
// Distributed under the terms of the Modified BSD License.

define([
'base/js/namespace',
'jquery',
'components/google-caja/html-css-sanitizer-minified',
], function(IPython, $) {
], function($, sanitize) {
"use strict";

var noop = function (x) { return x; };
Expand Down Expand Up @@ -123,7 +122,5 @@ define([
sanitize_html: sanitize_html
};

IPython.security = security;

return security;
});
12 changes: 3 additions & 9 deletions notebook/static/base/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
// Distributed under the terms of the Modified BSD License.

define([
'base/js/namespace',
'jquery',
'codemirror/lib/codemirror',
'moment',
// silently upgrades CodeMirror
'codemirror/mode/meta',
], function(IPython, $, CodeMirror, moment){
], function($, CodeMirror, moment){
"use strict";

var load_extensions = function () {
// load one or more IPython notebook extensions with requirejs
// load one or more Jupyter notebook extensions with requirejs

var extensions = [];
var extension_names = arguments;
Expand All @@ -39,8 +38,6 @@ define([
);
};

IPython.load_extensions = load_extensions;

/**
* Wait for a config section to load, and then load the extensions specified
* in a 'load_extensions' key inside it.
Expand Down Expand Up @@ -505,7 +502,7 @@ define([

var from_absolute_cursor_pos = function (cm, cursor_pos) {
/**
* turn absolute cursor postion into CodeMirror col, ch cursor
* turn absolute cursor position into CodeMirror col, ch cursor
*/
var i, line, next_line;
var offset = 0;
Expand Down Expand Up @@ -881,8 +878,5 @@ define([
time: time,
};

// Backwards compatability.
IPython.utils = utils;

return utils;
});
3 changes: 1 addition & 2 deletions notebook/static/edit/js/savewidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
// Distributed under the terms of the Modified BSD License.

define([
'base/js/namespace',
'jquery',
'base/js/utils',
'base/js/dialog',
'base/js/keyboard',
'moment',
], function(IPython, $, utils, dialog, keyboard, moment) {
], function($, utils, dialog, keyboard, moment) {
"use strict";

var SaveWidget = function (selector, options) {
Expand Down
4 changes: 2 additions & 2 deletions notebook/static/notebook/js/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require([
'use strict';
$('#notebook_about').click(function () {
// use underscore template to auto html escape
var text = 'You are using IPython notebook.<br/><br/>';
var text = 'You are using Jupyter notebook.<br/><br/>';
text = text + 'The version of the notebook server is ';
text = text + _.template('<b><%- version %></b>')({ version: sys_info.ipython_version });
if (sys_info.commit_hash) {
Expand All @@ -23,7 +23,7 @@ require([
body.append($('<h4/>').text('Current Kernel Information:'));
body.append(kinfo);
dialog.modal({
title: 'About IPython Notebook',
title: 'About Jupyter Notebook',
body: body,
buttons: { 'OK': {} }
});
Expand Down

0 comments on commit 5c18ecb

Please sign in to comment.