From 2d5d548d79711bcfabba7ab64cbf842cd0a2b1f6 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Thu, 27 Aug 2015 09:00:15 +0200 Subject: [PATCH] Revert "Use NPM, node ES5, and browserify." --- .gitignore | 14 -- .jshintrc | 6 - README.md | 33 --- bower.json | 15 +- notebook/amd.js | 35 --- notebook/base/handlers.py | 4 +- notebook/build.js | 35 --- notebook/static-src/auth/js/loginmain.js | 14 -- notebook/static-src/auth/js/main.js | 5 - notebook/static-src/base/js/globals.js | 94 -------- notebook/static-src/base/js/namespace.js | 70 ------ notebook/static/auth/js/loginmain.js | 14 ++ .../auth/js/loginwidget.js | 9 +- .../auth/js/logoutmain.js | 10 +- notebook/static/auth/js/main.js | 9 + .../{static-src => static}/base/js/dialog.js | 13 +- .../{static-src => static}/base/js/events.js | 18 +- .../base/js/keyboard.js | 20 +- notebook/static/base/js/namespace.js | 82 +++++++ .../base/js/notificationarea.js | 9 +- .../base/js/notificationwidget.js | 8 +- .../{static-src => static}/base/js/page.js | 9 +- .../base/js/security.js | 25 ++- .../{static-src => static}/base/js/utils.js | 63 +++--- .../{static-src => static}/edit/js/editor.js | 34 ++- .../{static-src => static}/edit/js/main.js | 60 +++--- .../{static-src => static}/edit/js/menubar.js | 21 +- .../edit/js/notificationarea.js | 16 +- .../edit/js/savewidget.js | 21 +- .../notebook/js/about.js | 11 +- .../notebook/js/actions.js | 6 +- .../notebook/js/cell.js | 41 ++-- .../notebook/js/celltoolbar.js | 12 +- .../notebook/js/celltoolbarpresets/default.js | 12 +- .../notebook/js/celltoolbarpresets/example.js | 9 +- .../notebook/js/celltoolbarpresets/rawcell.js | 27 ++- .../js/celltoolbarpresets/slideshow.js | 9 +- .../notebook/js/codecell.js | 48 +++-- .../notebook/js/codemirror-ipython.js | 0 .../notebook/js/codemirror-ipythongfm.js | 0 .../notebook/js/commandpalette.js | 7 +- .../notebook/js/completer.js | 15 +- .../notebook/js/contexthint.js | 4 +- .../notebook/js/kernelselector.js | 26 ++- .../notebook/js/keyboardmanager.js | 15 +- .../notebook/js/main.js | 105 +++++---- .../notebook/js/maintoolbar.js | 14 +- .../notebook/js/mathjaxutils.js | 14 +- .../notebook/js/menubar.js | 25 ++- .../notebook/js/notebook.js | 45 ++-- .../notebook/js/notificationarea.js | 24 +-- .../notebook/js/outputarea.js | 32 +-- .../notebook/js/pager.js | 10 +- .../notebook/js/quickhelp.js | 17 +- .../notebook/js/savewidget.js | 21 +- .../notebook/js/scrollmanager.js | 4 +- .../notebook/js/searchandreplace.js | 4 +- .../notebook/js/textcell.js | 43 ++-- .../notebook/js/toolbar.js | 6 +- .../notebook/js/tooltip.js | 10 +- .../notebook/js/tour.js | 48 +++-- .../{static-src => static}/services/config.js | 36 ++-- .../services/contents.js | 12 +- .../services/kernels/comm.js | 57 ++--- .../services/kernels/kernel.js | 32 +-- .../services/kernels/serialize.js | 18 +- .../services/sessions/session.js | 16 +- .../terminal/js/main.js | 40 ++-- .../terminal/js/terminado.js | 14 +- .../tree/js/kernellist.js | 16 +- .../{static-src => static}/tree/js/main.js | 68 +++--- .../tree/js/newnotebook.js | 26 ++- .../tree/js/notebooklist.js | 20 +- .../tree/js/sessionlist.js | 12 +- .../tree/js/terminallist.js | 20 +- notebook/templates/edit.html | 2 +- notebook/templates/notebook.html | 6 +- notebook/templates/page.html | 7 +- notebook/templates/terminal.html | 2 +- notebook/templates/tree.html | 2 +- notebook/tests/base/utils.js | 11 +- notebook/tests/util.js | 4 +- package.json | 33 +-- setup.py | 4 +- setupbase.py | 200 ++++++++++++++---- 85 files changed, 1157 insertions(+), 931 deletions(-) delete mode 100644 .jshintrc delete mode 100644 notebook/amd.js delete mode 100644 notebook/build.js delete mode 100644 notebook/static-src/auth/js/loginmain.js delete mode 100644 notebook/static-src/auth/js/main.js delete mode 100644 notebook/static-src/base/js/globals.js delete mode 100644 notebook/static-src/base/js/namespace.js create mode 100644 notebook/static/auth/js/loginmain.js rename notebook/{static-src => static}/auth/js/loginwidget.js (89%) rename notebook/{static-src => static}/auth/js/logoutmain.js (60%) create mode 100644 notebook/static/auth/js/main.js rename notebook/{static-src => static}/base/js/dialog.js (97%) rename notebook/{static-src => static}/base/js/events.js (64%) rename notebook/{static-src => static}/base/js/keyboard.js (99%) create mode 100644 notebook/static/base/js/namespace.js rename notebook/{static-src => static}/base/js/notificationarea.js (94%) rename notebook/{static-src => static}/base/js/notificationwidget.js (98%) rename notebook/{static-src => static}/base/js/page.js (94%) rename notebook/{static-src => static}/base/js/security.js (95%) rename notebook/{static-src => static}/base/js/utils.js (98%) rename notebook/{static-src => static}/edit/js/editor.js (93%) rename notebook/{static-src => static}/edit/js/main.js (74%) rename notebook/{static-src => static}/edit/js/menubar.js (95%) rename notebook/{static-src => static}/edit/js/notificationarea.js (81%) rename notebook/{static-src => static}/edit/js/savewidget.js (96%) rename notebook/{static-src => static}/notebook/js/about.js (91%) rename notebook/{static-src => static}/notebook/js/actions.js (99%) rename notebook/{static-src => static}/notebook/js/cell.js (98%) rename notebook/{static-src => static}/notebook/js/celltoolbar.js (99%) rename notebook/{static-src => static}/notebook/js/celltoolbarpresets/default.js (89%) rename notebook/{static-src => static}/notebook/js/celltoolbarpresets/example.js (97%) rename notebook/{static-src => static}/notebook/js/celltoolbarpresets/rawcell.js (86%) rename notebook/{static-src => static}/notebook/js/celltoolbarpresets/slideshow.js (92%) rename notebook/{static-src => static}/notebook/js/codecell.js (97%) rename notebook/{static-src => static}/notebook/js/codemirror-ipython.js (100%) rename notebook/{static-src => static}/notebook/js/codemirror-ipythongfm.js (100%) rename notebook/{static-src => static}/notebook/js/commandpalette.js (98%) rename notebook/{static-src => static}/notebook/js/completer.js (98%) rename notebook/{static-src => static}/notebook/js/contexthint.js (96%) rename notebook/{static-src => static}/notebook/js/kernelselector.js (97%) rename notebook/{static-src => static}/notebook/js/keyboardmanager.js (98%) rename notebook/{static-src => static}/notebook/js/main.js (71%) rename notebook/{static-src => static}/notebook/js/maintoolbar.js (97%) rename notebook/{static-src => static}/notebook/js/mathjaxutils.js (98%) rename notebook/{static-src => static}/notebook/js/menubar.js (97%) rename notebook/{static-src => static}/notebook/js/notebook.js (99%) rename notebook/{static-src => static}/notebook/js/notificationarea.js (97%) rename notebook/{static-src => static}/notebook/js/outputarea.js (99%) rename notebook/{static-src => static}/notebook/js/pager.js (98%) rename notebook/{static-src => static}/notebook/js/quickhelp.js (98%) rename notebook/{static-src => static}/notebook/js/savewidget.js (97%) rename notebook/{static-src => static}/notebook/js/scrollmanager.js (99%) rename notebook/{static-src => static}/notebook/js/searchandreplace.js (99%) rename notebook/{static-src => static}/notebook/js/textcell.js (95%) rename notebook/{static-src => static}/notebook/js/toolbar.js (98%) rename notebook/{static-src => static}/notebook/js/tooltip.js (99%) rename notebook/{static-src => static}/notebook/js/tour.js (87%) rename notebook/{static-src => static}/services/config.js (93%) rename notebook/{static-src => static}/services/contents.js (98%) rename notebook/{static-src => static}/services/kernels/comm.js (97%) rename notebook/{static-src => static}/services/kernels/kernel.js (99%) rename notebook/{static-src => static}/services/kernels/serialize.js (97%) rename notebook/{static-src => static}/services/sessions/session.js (98%) rename notebook/{static-src => static}/terminal/js/main.js (83%) rename notebook/{static-src => static}/terminal/js/terminado.js (79%) rename notebook/{static-src => static}/tree/js/kernellist.js (92%) rename notebook/{static-src => static}/tree/js/main.js (84%) rename notebook/{static-src => static}/tree/js/newnotebook.js (94%) rename notebook/{static-src => static}/tree/js/notebooklist.js (99%) rename notebook/{static-src => static}/tree/js/sessionlist.js (95%) rename notebook/{static-src => static}/tree/js/terminallist.js (95%) diff --git a/.gitignore b/.gitignore index 69d1f5272..7af3531a4 100644 --- a/.gitignore +++ b/.gitignore @@ -25,17 +25,3 @@ src *.swp *.map - -.eggs/ - -# Bundled/generated JavaScript -notebook/static/auth/js -notebook/static/base/js -notebook/static/edit/js -notebook/static/notebook/js -notebook/static/services -notebook/static/terminal/js -notebook/static/tree/js - -# npm logs -npm-debug.log diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 8e77cb3a7..000000000 --- a/.jshintrc +++ /dev/null @@ -1,6 +0,0 @@ -{ - "browserify": true, - "node": true, - "jquery": true, - "predef": [ "requirejs", "define", "Promise", "CodeMirror"] -} diff --git a/README.md b/README.md index dab2a4bc7..8208bfcee 100644 --- a/README.md +++ b/README.md @@ -27,36 +27,3 @@ pip install --pre -e . jupyter notebook ``` -## Working on the frontend -The Notebook frontend depends on a wide set of libraries and package managers. -NPM is used to macro manage the frontend build process. You can build the -frontend Javascript and LESS by running - -``` -npm run build -``` - -If you need to build the Javascript alone - -``` -npm run build:js -``` - -Or LESS - -``` -npm run build:css -``` - -To build specific sub components, separate using a colon. i.e. to build only -the terminal's Javascript - -``` -npm run build:js:terminal -``` - -To clean all built output - -``` -npm run clean -``` diff --git a/bower.json b/bower.json index f8114f971..dbebe4be0 100644 --- a/bower.json +++ b/bower.json @@ -2,21 +2,20 @@ "name": "jupyter-notebook-deps", "version": "0.0.1", "dependencies": { + "backbone": "components/backbone#~1.2", + "bootstrap": "components/bootstrap#~3.3", + "bootstrap-tour": "0.9.0", + "codemirror": "~5.5", "es6-promise": "~1.0", "font-awesome": "components/font-awesome#~4.2.0", - "requirejs": "~2.1", "google-caja": "5669", - "MathJax": "components/MathJax#~2.5", - "bootstrap": "components/bootstrap#~3.3", - "bootstrap-tour": "0.9.0", "jquery": "components/jquery#~2.0", "jquery-ui": "components/jqueryui#~1.10", - "codemirror": "~5.5", - - "term.js": "chjj/term.js#~0.0.4", - "backbone": "components/backbone#~1.2", "marked": "~0.3", + "MathJax": "components/MathJax#~2.5", "moment": "~2.8.4", + "requirejs": "~2.1", + "term.js": "chjj/term.js#~0.0.4", "text-encoding": "~0.1", "underscore": "components/underscore#~1.5", "jquery-typeahead": "~2.0.0" diff --git a/notebook/amd.js b/notebook/amd.js deleted file mode 100644 index 4cf2baf32..000000000 --- a/notebook/amd.js +++ /dev/null @@ -1,35 +0,0 @@ -var amdWrap = require("amd-wrap-legacy"); -var glob = require("glob"); -var path = require('path'); -var fs = require('fs'); -var mkdirp = require("mkdirp"); - -var source = "./notebook/static-src"; -var destination = "./notebook/static"; - -glob(path.join(source, "**/*.js"), function(err, files) { - if (err) { - console.error('Could not glob files.', err); - } else { - files.forEach(function(file, index) { - var toFile = path.join(destination, path.relative(source, file)); - fs.readFile(file, 'utf8', function (err, data) { - if (err) { - console.error('Could not read file ' + file, err); - } else { - mkdirp(path.dirname(toFile), function(err) { - if (err) { - console.error('Could not mkdirp ', err); - } else { - fs.writeFile(toFile, amdWrap(data), function(err) { - if(err) { - return console.error('Could not write file ' + toFile, err); - } - }); - } - }); - } - }); - }); - } -}); diff --git a/notebook/base/handlers.py b/notebook/base/handlers.py index cd3241fad..75805955c 100644 --- a/notebook/base/handlers.py +++ b/notebook/base/handlers.py @@ -172,8 +172,8 @@ class IPythonHandler(AuthenticatedHandler): @property def contents_js_source(self): self.log.debug("Using contents: %s", self.settings.get('contents_js_source', - 'services/contents.bundle')) - return self.settings.get('contents_js_source', 'services/contents.bundle') + 'services/contents')) + return self.settings.get('contents_js_source', 'services/contents') #--------------------------------------------------------------- # Manager objects diff --git a/notebook/build.js b/notebook/build.js deleted file mode 100644 index f10a0ee2c..000000000 --- a/notebook/build.js +++ /dev/null @@ -1,35 +0,0 @@ -var fs = require('fs'); -var aliasify = require('aliasify'); -var browserify = require('browserify'); -var mkdirp = require("mkdirp"); -var path = require('path'); - -var aliasifyConfig = { - aliases: { - jqueryui: 'jquery-ui', - termjs: 'term.js', - caja: 'google-caja/html-css-sanitizer-minified' - }, - verbose: false -} - -var b = browserify({ - paths: [ - __dirname + '/static-src', - __dirname + '/static/components', - ], - debug: true, - fullPaths: true -}); - -b.transform(aliasify, aliasifyConfig); -var mkdirp = require("mkdirp"); -b.add(__dirname + '/static-src/' + process.argv[2]); -var toFile = __dirname + '/static/' + process.argv[3]; -mkdirp(path.dirname(toFile), function(err) { - if (err) { - console.error('Could not mkdirp ', err); - } else { - b.bundle().pipe(fs.createWriteStream(toFile)); - } -}); diff --git a/notebook/static-src/auth/js/loginmain.js b/notebook/static-src/auth/js/loginmain.js deleted file mode 100644 index cadbb0ec0..000000000 --- a/notebook/static-src/auth/js/loginmain.js +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) Jupyter Development Team. -// Distributed under the terms of the Modified BSD License. - - var IPython = require('base/js/namespace'); - var page = require('base/js/page'); - - module.exports = function loginMain() { - var page_instance = new page.Page(); - $('button#login_submit').addClass("btn btn-default"); - page_instance.show(); - $('input#password_input').focus(); - - IPython.page = page_instance; - }; diff --git a/notebook/static-src/auth/js/main.js b/notebook/static-src/auth/js/main.js deleted file mode 100644 index d2fb30bcf..000000000 --- a/notebook/static-src/auth/js/main.js +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright (c) Jupyter Development Team. -// Distributed under the terms of the Modified BSD License. - -exports.login_main = require('./loginmain'); -exports.logout_main = require('./logoutmain'); diff --git a/notebook/static-src/base/js/globals.js b/notebook/static-src/base/js/globals.js deleted file mode 100644 index 678c34ea8..000000000 --- a/notebook/static-src/base/js/globals.js +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright (c) Jupyter Development Team. -// Distributed under the terms of the Modified BSD License. - -"use strict"; - -/** - * jquery, jquery-ui, and bootstrap all really on weird window level logic. - * This module handles the global loading of those tools. - */ -module.exports = new Promise(function(resolve, reject) { - if (window.hasOwnProperty('jquery')) { - resolve(); - } - - requirejs(['jquery'], function($) { - var jQueryProperty = { - get: function() { - return $; - }, - configurable: false - }; - Object.defineProperty(window, '$', jQueryProperty); - Object.defineProperty(window, 'jQuery', jQueryProperty); - console.log('jQuery loaded and available in global namespace'); - - requirejs(['jqueryui', 'bootstrap'], function() { - if ($.prototype.modal) { - console.log('bootstrap loaded and injected into jQuery\'s namespace'); - } else { - reject(new Error('bootstrap not injected into jQuery prototype')); - } - - if ($.prototype.draggable && $.prototype.resizable) { - console.log('jQueryUI loaded and injected into jQuery\'s namespace'); - } else { - reject(new Error('jQueryUI not injected into jQuery prototype')); - } - - requirejs([ - 'codemirror/lib/codemirror', - 'codemirror/mode/meta', - 'codemirror/addon/comment/comment', - 'codemirror/addon/dialog/dialog', - 'codemirror/addon/edit/closebrackets', - 'codemirror/addon/edit/matchbrackets', - 'codemirror/addon/search/searchcursor', - 'codemirror/addon/search/search', - 'codemirror/keymap/emacs', - 'codemirror/keymap/sublime', - 'codemirror/keymap/vim', - 'codemirror/mode/python/python', - 'codemirror/addon/runmode/runmode', - 'codemirror/mode/gfm/gfm', - 'notebook/js/codemirror-ipython', - 'notebook/js/codemirror-ipythongfm' - ], function(CodeMirror) { - var codeMirrorProperty = { - get: function() { - return CodeMirror; - }, - configurable: false - }; - Object.defineProperty(window, 'CodeMirror', codeMirrorProperty); - console.log('CodeMirror loaded and available in global namespace'); - - - requirejs(['underscore'], function(_) { - var underscoreProperty = { - get: function() { - return _; - }, - configurable: false - }; - Object.defineProperty(window, '_', underscoreProperty); - console.log('underscore loaded and available in global namespace'); - - resolve(); - }, function(err) { - console.error('could not load underscore'); - reject(err); - }); - }, function(err) { - console.error('could not load CodeMirror and/or it\'s plugins'); - reject(err); - }); - }, function(err) { - console.error('could not load jqueryui and/or bootstrap'); - reject(err); - }); - }, function(err) { - console.error('could not load jquery'); - reject(err); - }); -}); \ No newline at end of file diff --git a/notebook/static-src/base/js/namespace.js b/notebook/static-src/base/js/namespace.js deleted file mode 100644 index 783eb5e9e..000000000 --- a/notebook/static-src/base/js/namespace.js +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (c) Jupyter Development Team. -// Distributed under the terms of the Modified BSD License. - -"use strict"; - -if (!window.Jupyter) { - var Jupyter = {}; - Jupyter.version = "4.1.0.dev"; - window.Jupyter = Jupyter; -} - -var jprop = function(name, loaded, module_path, global_mod) { - if (!(window.Jupyter).hasOwnProperty(name)) { - Object.defineProperty(window.Jupyter, name, { - get: function() { - console.warn('accessing `'+name+'` is deprecated. Use `require(\'' + module_path + '\')' + (global_mod ? '[\'' + name + '\']' : '') + '`'); - return global_mod ? loaded[name] : loaded; - }, - enumerable: true, - configurable: false - }); - } -}; - -// expose modules -jprop('events', require('base/js/events'), 'base/js/events'); -jprop('utils', require('base/js/utils'), 'base/js/utils'); -jprop('security', require('base/js/security'), 'base/js/security'); -jprop('keyboard', require('base/js/keyboard'), 'base/js/keyboard'); -jprop('dialog', require('base/js/dialog'), 'base/js/dialog'); -jprop('mathjaxutils', require('notebook/js/mathjaxutils'), 'notebook/js/mathjaxutils'); - -//// exposed constructors -jprop('CommManager', require('services/kernels/comm'), 'services/kernels/comm', true); -jprop('Comm', require('services/kernels/comm'), 'services/kernels/comm', true); - -jprop('NotificationWidget', require('base/js/notificationwidget'), 'base/js/notificationwidget', true); -jprop('Kernel', require('services/kernels/kernel'), 'services/kernels/kernel', true); -jprop('Session', require('services/sessions/session'), 'services/sessions/session', true); -jprop('LoginWidget', require('auth/js/loginwidget'), 'auth/js/loginwidget', true); -jprop('Page', require('base/js/page'), 'base/js/page', true); - -// notebook -jprop('TextCell', require('notebook/js/textcell'), 'notebook/js/textcell', true); -jprop('OutputArea', require('notebook/js/outputarea'), 'notebook/js/outputarea', true); -jprop('KeyboardManager', require('notebook/js/keyboardmanager'), 'notebook/js/keyboardmanager', true); -jprop('Completer', require('notebook/js/completer'), 'notebook/js/completer', true); -jprop('Notebook', require('notebook/js/notebook'), 'notebook/js/notebook', true); -jprop('Tooltip', require('notebook/js/tooltip'), 'notebook/js/tooltip', true); -jprop('ToolBar', require('notebook/js/toolbar'), 'notebook/js/toolbar', true); -jprop('SaveWidget', require('notebook/js/savewidget'), 'notebook/js/savewidget', true); -jprop('Pager', require('notebook/js/pager'), 'notebook/js/pager', true); -jprop('QuickHelp', require('notebook/js/quickhelp'), 'notebook/js/quickhelp', true); -jprop('MarkdownCell', require('notebook/js/textcell'), 'notebook/js/textcell', true); -jprop('RawCell', require('notebook/js/textcell'), 'notebook/js/textcell', true); -jprop('Cell', require('notebook/js/cell'), 'notebook/js/cell', true); -jprop('MainToolBar', require('notebook/js/maintoolbar'), 'notebook/js/maintoolbar', true); -jprop('NotebookNotificationArea', require('notebook/js/notificationarea'), 'notebook/js/notificationarea', true); -jprop('NotebookTour', require( 'notebook/js/tour'), 'notebook/js/tour', true); -jprop('MenuBar', require( 'notebook/js/menubar'), 'notebook/js/menubar', true); - -// tree -jprop('SessionList', require('tree/js/sessionlist'), 'tree/js/sessionlist', true); - -window.Jupyter._target = '_blank'; - -// deprecated since 4.0, remove in 5+ -window.IPython = window.Jupyter; - -module.exports = window.Jupyter; diff --git a/notebook/static/auth/js/loginmain.js b/notebook/static/auth/js/loginmain.js new file mode 100644 index 000000000..1e312ee69 --- /dev/null +++ b/notebook/static/auth/js/loginmain.js @@ -0,0 +1,14 @@ +// Copyright (c) Jupyter Development Team. +// Distributed under the terms of the Modified BSD License. + +define(['base/js/namespace', 'base/js/page'], function(IPython, page) { + function login_main() { + var page_instance = new page.Page(); + $('button#login_submit').addClass("btn btn-default"); + page_instance.show(); + $('input#password_input').focus(); + + IPython.page = page_instance; + } + return login_main; +}); diff --git a/notebook/static-src/auth/js/loginwidget.js b/notebook/static/auth/js/loginwidget.js similarity index 89% rename from notebook/static-src/auth/js/loginwidget.js rename to notebook/static/auth/js/loginwidget.js index a64ac9233..00d154dde 100644 --- a/notebook/static-src/auth/js/loginwidget.js +++ b/notebook/static/auth/js/loginwidget.js @@ -1,10 +1,12 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. +define([ + 'base/js/utils', + 'jquery', +], function(utils, $){ "use strict"; - var utils = require('base/js/utils'); - var LoginWidget = function (selector, options) { options = options || {}; this.base_url = options.base_url || utils.get_body_data("baseUrl"); @@ -32,4 +34,5 @@ }); }; - exports.LoginWidget = LoginWidget; + return {'LoginWidget': LoginWidget}; +}); diff --git a/notebook/static-src/auth/js/logoutmain.js b/notebook/static/auth/js/logoutmain.js similarity index 60% rename from notebook/static-src/auth/js/logoutmain.js rename to notebook/static/auth/js/logoutmain.js index 5470cb096..7b3f6b4da 100644 --- a/notebook/static-src/auth/js/logoutmain.js +++ b/notebook/static/auth/js/logoutmain.js @@ -1,12 +1,12 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. - var IPython = require('base/js/namespace'); - var page = require('base/js/page'); - - module.exports = function logoutMain() { +define(['base/js/namespace', 'base/js/page'], function(IPython, page) { + function logout_main() { var page_instance = new page.Page(); page_instance.show(); IPython.page = page_instance; - }; + } + return logout_main; +}); diff --git a/notebook/static/auth/js/main.js b/notebook/static/auth/js/main.js new file mode 100644 index 000000000..7be82388e --- /dev/null +++ b/notebook/static/auth/js/main.js @@ -0,0 +1,9 @@ +// Copyright (c) Jupyter Development Team. +// Distributed under the terms of the Modified BSD License. + +define(['./loginmain', './logoutmain'], function (login_main, logout_main) { + return { + login_main: login_main, + logout_main: logout_main + }; +}); diff --git a/notebook/static-src/base/js/dialog.js b/notebook/static/base/js/dialog.js similarity index 97% rename from notebook/static-src/base/js/dialog.js rename to notebook/static/base/js/dialog.js index 05c2879e4..d07315429 100644 --- a/notebook/static-src/base/js/dialog.js +++ b/notebook/static/base/js/dialog.js @@ -1,7 +1,11 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. +define(function(require) { "use strict"; + + var CodeMirror = require('codemirror/lib/codemirror'); + var $ = require('jquery'); /** * A wrapper around bootstrap modal for easier use @@ -33,6 +37,7 @@ * **/ var modal = function (options) { + var modal = $("
") .addClass("modal") .addClass("fade") @@ -193,11 +198,13 @@ }); modal_obj.on('shown.bs.modal', function(){ editor.refresh(); }); - }; - - module.exports = { + + var dialog = { modal : modal, kernel_modal : kernel_modal, edit_metadata : edit_metadata, }; + + return dialog; +}); diff --git a/notebook/static-src/base/js/events.js b/notebook/static/base/js/events.js similarity index 64% rename from notebook/static-src/base/js/events.js rename to notebook/static/base/js/events.js index 5ff73aecc..4cab05db2 100644 --- a/notebook/static-src/base/js/events.js +++ b/notebook/static/base/js/events.js @@ -8,11 +8,17 @@ // require(['base/js/events'], function (events) { // events.on("event.Namespace", function () { do_stuff(); }); // }); -"use strict"; -if (!window.jupyterEvents) { - var Events = function () {}; - window.jupyterEvents = $([new Events()]); -} +define(['base/js/namespace', 'jquery'], function(IPython, $) { + "use strict"; -module.exports = window.jupyterEvents; + var Events = function () {}; + + var events = new Events(); + + // Backwards compatability. + IPython.Events = Events; + IPython.events = events; + + return $([events]); +}); diff --git a/notebook/static-src/base/js/keyboard.js b/notebook/static/base/js/keyboard.js similarity index 99% rename from notebook/static-src/base/js/keyboard.js rename to notebook/static/base/js/keyboard.js index 2aeb8dac2..bc6a33d90 100644 --- a/notebook/static-src/base/js/keyboard.js +++ b/notebook/static/base/js/keyboard.js @@ -8,10 +8,13 @@ * @class ShortcutManager */ +define([ + 'jquery', + 'base/js/utils', + 'underscore', +], function($, utils, _) { "use strict"; - var utils = require('base/js/utils'); - /** * Setup global keycodes and inverse keycodes. @@ -42,20 +45,20 @@ 'end': 35, 'home': 36, 'left': 37, 'up': 38, 'right': 39, 'down': 40, 'insert': 45, 'delete': 46, 'numlock': 144, }; - + // These apply to Firefox and Opera var _mozilla_keycodes = { '; :': 59, '= +': 61, '- _': 173, 'meta': 224, 'minus':173 }; - + // This apply to Webkit and IE var _ie_keycodes = { '; :': 186, '= +': 187, '- _': 189, 'minus':189 }; - + var browser = utils.browser[0]; var platform = utils.platform; - + if (browser === 'Firefox' || browser === 'Opera' || browser === 'Netscape') { $.extend(_keycodes, _mozilla_keycodes); } else if (browser === 'Safari' || browser === 'Chrome' || browser === 'MSIE') { @@ -452,7 +455,7 @@ return (typeof(action_name) !== 'undefined'); }; - module.exports = { + var keyboard = { keycodes : keycodes, inv_keycodes : inv_keycodes, ShortcutManager : ShortcutManager, @@ -461,3 +464,6 @@ shortcut_to_event : shortcut_to_event, event_to_shortcut : event_to_shortcut, }; + + return keyboard; +}); diff --git a/notebook/static/base/js/namespace.js b/notebook/static/base/js/namespace.js new file mode 100644 index 000000000..38056dbe1 --- /dev/null +++ b/notebook/static/base/js/namespace.js @@ -0,0 +1,82 @@ +// Copyright (c) Jupyter Development Team. +// Distributed under the terms of the Modified BSD License. + + +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"; + + // 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'); + + Jupyter.version = "4.1.0.dev"; + Jupyter._target = '_blank'; + return Jupyter; +}); + +// deprecated since 4.0, remove in 5+ +var IPython = Jupyter diff --git a/notebook/static-src/base/js/notificationarea.js b/notebook/static/base/js/notificationarea.js similarity index 94% rename from notebook/static-src/base/js/notificationarea.js rename to notebook/static/base/js/notificationarea.js index 5e93cc28f..94b764998 100644 --- a/notebook/static-src/base/js/notificationarea.js +++ b/notebook/static/base/js/notificationarea.js @@ -1,10 +1,12 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. +define([ + 'jquery', + 'base/js/notificationwidget', +], function($, notificationwidget) { "use strict"; - var notificationwidget = require('base/js/notificationwidget'); - // store reference to the NotificationWidget class var NotificationWidget = notificationwidget.NotificationWidget; @@ -77,4 +79,5 @@ return this.widget_dict[name]; }; - exports.NotificationArea = NotificationArea; + return {'NotificationArea': NotificationArea}; +}); diff --git a/notebook/static-src/base/js/notificationwidget.js b/notebook/static/base/js/notificationwidget.js similarity index 98% rename from notebook/static-src/base/js/notificationwidget.js rename to notebook/static/base/js/notificationwidget.js index c69a84572..660143743 100644 --- a/notebook/static-src/base/js/notificationwidget.js +++ b/notebook/static/base/js/notificationwidget.js @@ -1,6 +1,9 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. +define([ + 'jquery', +], function($) { "use strict"; /** @@ -34,7 +37,7 @@ // for this particular combination this.element.addClass('notification_widget btn btn-xs navbar-btn'); }; - + /** * hide the widget and empty the text **/ @@ -163,4 +166,5 @@ return this.inner.html(); }; - exports.NotificationWidget = NotificationWidget; + return {'NotificationWidget': NotificationWidget}; +}); diff --git a/notebook/static-src/base/js/page.js b/notebook/static/base/js/page.js similarity index 94% rename from notebook/static-src/base/js/page.js rename to notebook/static/base/js/page.js index 538373ba4..9ec72786f 100644 --- a/notebook/static-src/base/js/page.js +++ b/notebook/static/base/js/page.js @@ -1,9 +1,11 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. +define([ + 'jquery', + 'base/js/events', +], function($, events){ "use strict"; - - var events = require('base/js/events'); var Page = function () { this.bind_events(); @@ -56,4 +58,5 @@ $('div#site').height($(window).height() - $('#header').height()); }; - exports.Page = Page; + return {'Page': Page}; +}); diff --git a/notebook/static-src/base/js/security.js b/notebook/static/base/js/security.js similarity index 95% rename from notebook/static-src/base/js/security.js rename to notebook/static/base/js/security.js index 4b8d82f9a..71130fc4b 100644 --- a/notebook/static-src/base/js/security.js +++ b/notebook/static/base/js/security.js @@ -1,19 +1,21 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. +define([ + 'jquery', + 'components/google-caja/html-css-sanitizer-minified', +], function($, sanitize) { "use strict"; - - var caja = require('caja'); - + var noop = function (x) { return x; }; - + var caja; if (window && window.html) { caja = window.html; caja.html4 = window.html4; caja.sanitizeStylesheet = window.sanitizeStylesheet; } - + var sanitizeAttribs = function (tagName, attribs, opt_naiveUriRewriter, opt_nmTokenPolicy, opt_logger) { /** * add trusting data-attributes to the default sanitizeAttribs from caja @@ -31,7 +33,7 @@ } return caja.sanitizeAttribs(tagName, attribs, opt_naiveUriRewriter, opt_nmTokenPolicy, opt_logger); }; - + var sanitize_css = function (css, tagPolicy) { /** * sanitize CSS @@ -50,7 +52,7 @@ noop ); }; - + var sanitize_stylesheets = function (html, tagPolicy) { /** * sanitize just the css in style tags in a block of html @@ -67,7 +69,7 @@ }); return h.html(); }; - + var sanitize_html = function (html, allow_css) { /** * sanitize HTML @@ -114,8 +116,11 @@ return sanitized; }; - - module.exports = { + + var security = { caja: caja, sanitize_html: sanitize_html }; + + return security; +}); diff --git a/notebook/static-src/base/js/utils.js b/notebook/static/base/js/utils.js similarity index 98% rename from notebook/static-src/base/js/utils.js rename to notebook/static/base/js/utils.js index dbefd8120..fc3da3edf 100644 --- a/notebook/static-src/base/js/utils.js +++ b/notebook/static/base/js/utils.js @@ -1,10 +1,15 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. +define([ + 'jquery', + 'codemirror/lib/codemirror', + 'moment', + // silently upgrades CodeMirror + 'codemirror/mode/meta', +], function($, CodeMirror, moment){ "use strict"; - - var moment = require('moment'); - + /** * Load a single extension. * @param {string} extension - extension path. @@ -12,7 +17,7 @@ */ var load_extension = function (extension) { return new Promise(function(resolve, reject) { - requirejs(["nbextensions/" + extension], function(module) { + require(["nbextensions/" + extension], function(module) { console.log("Loaded extension: " + extension); try { module.load_ipython_extension(); @@ -212,7 +217,7 @@ "46":"ansibgcyan", "47":"ansibggray" }; - + function _process_numbers(attrs, numbers) { // process ansi escapes var n = numbers.shift(); @@ -369,7 +374,7 @@ test.remove(); return Math.floor(points*pixel_per_point); }; - + var always_new = function (constructor) { /** * wrapper around contructor to avoid requiring `var a = new constructor()` @@ -402,7 +407,7 @@ url = url.replace(/\/\/+/, '/'); return url; }; - + var url_path_split = function (path) { /** * Like os.path.split for URLs. @@ -416,7 +421,7 @@ return [ path.slice(0, idx), path.slice(idx + 1) ]; } }; - + var parse_url = function (url) { /** * an `a` element with an href allows attr-access to the parsed segments of a URL @@ -432,7 +437,7 @@ a.href = url; return a; }; - + var encode_uri_components = function (uri) { /** * encode just the components of a multi-segment uri, @@ -440,7 +445,7 @@ */ return uri.split('/').map(encodeURIComponent).join('/'); }; - + var url_join_encode = function () { /** * join a sequence of url components with '/', @@ -483,7 +488,7 @@ return val; return decodeURIComponent(val); }; - + var to_absolute_cursor_pos = function (cm, cursor) { /** * get the absolute cursor position from CodeMirror's col, ch @@ -497,7 +502,7 @@ } return cursor_pos; }; - + var from_absolute_cursor_pos = function (cm, cursor_pos) { /** * turn absolute cursor position into CodeMirror col, ch cursor @@ -521,7 +526,7 @@ ch : line.length - 1, }; }; - + // http://stackoverflow.com/questions/2400935/browser-detection-in-javascript var browser = (function() { if (typeof navigator === 'undefined') { @@ -548,7 +553,7 @@ if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux"; return OSName; })(); - + var get_url_param = function (name) { // get a URL parameter. I cannot believe we actually need this. // Based on http://stackoverflow.com/a/25359264/938949 @@ -557,7 +562,7 @@ return decodeURIComponent(match[1] || ''); } }; - + var is_or_has = function (a, b) { /** * Is b a child of a or a itself? @@ -581,13 +586,13 @@ return false; } }; - + var mergeopt = function(_class, options, overwrite){ options = options || {}; overwrite = overwrite || {}; return $.extend(true, {}, _class.options_default, options, overwrite); }; - + var ajax_error_msg = function (jqXHR) { /** * Return a JSON error message if there is one, @@ -621,7 +626,6 @@ var modename = (typeof mode == "string") ? mode : mode.mode || mode.name; - // simplest, cheapest check by mode name: mode may also have config if (CodeMirror.modes.hasOwnProperty(modename)) { // return the full mode object, if it has a name @@ -637,7 +641,7 @@ CodeMirror.findModeByMIME(modename) || {mode: modename, mime: modename}; - requirejs([ + require([ // might want to use CodeMirror.modeURL here ['codemirror/mode', info.mode, info.mode].join('/'), ], function() { @@ -647,10 +651,10 @@ }, errback ); }; - + /** Error type for wrapped XHR errors. */ var XHR_ERROR = 'XhrError'; - + /** * Wraps an AJAX error as an Error object. */ @@ -663,7 +667,7 @@ wrapped_error.xhr_error = error; return wrapped_error; }; - + var promising_ajax = function(url, settings) { /** * Like $.ajax, but returning an ES6 promise. success and error settings @@ -724,7 +728,7 @@ // Try loading the view module using require.js if (module_name) { - requirejs([module_name], function(module) { + require([module_name], function(module) { if (module[class_name] === undefined) { reject(new Error('Class '+class_name+' not found in module '+module_name)); } else { @@ -801,14 +805,14 @@ return MathJax.Hub.Queue(["Typeset", MathJax.Hub, this]); }); }; - + var time = {}; time.milliseconds = {}; time.milliseconds.s = 1000; time.milliseconds.m = 60 * time.milliseconds.s; time.milliseconds.h = 60 * time.milliseconds.m; time.milliseconds.d = 24 * time.milliseconds.h; - + time.thresholds = { // moment.js thresholds in milliseconds s: moment.relativeTimeThreshold('s') * time.milliseconds.s, @@ -816,7 +820,7 @@ h: moment.relativeTimeThreshold('h') * time.milliseconds.h, d: moment.relativeTimeThreshold('d') * time.milliseconds.d, }; - + time.timeout_from_dt = function (dt) { /** compute a timeout based on dt @@ -836,8 +840,8 @@ return time.milliseconds.h; } }; - - module.exports = { + + var utils = { load_extension: load_extension, load_extensions: load_extensions, load_extensions_from_config: load_extensions_from_config, @@ -877,3 +881,6 @@ typeset: typeset, time: time, }; + + return utils; +}); diff --git a/notebook/static-src/edit/js/editor.js b/notebook/static/edit/js/editor.js similarity index 93% rename from notebook/static-src/edit/js/editor.js rename to notebook/static/edit/js/editor.js index 598bd2aad..ddbc2ded2 100644 --- a/notebook/static-src/edit/js/editor.js +++ b/notebook/static/edit/js/editor.js @@ -1,9 +1,26 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. +define([ + 'jquery', + 'base/js/utils', + 'codemirror/lib/codemirror', + 'codemirror/mode/meta', + 'codemirror/addon/comment/comment', + 'codemirror/addon/dialog/dialog', + 'codemirror/addon/edit/closebrackets', + 'codemirror/addon/edit/matchbrackets', + 'codemirror/addon/search/searchcursor', + 'codemirror/addon/search/search', + 'codemirror/keymap/emacs', + 'codemirror/keymap/sublime', + 'codemirror/keymap/vim', + ], +function($, + utils, + CodeMirror +) { "use strict"; - - var utils = require('base/js/utils'); var Editor = function(selector, options) { var that = this; @@ -42,7 +59,7 @@ $('.last_modified').before(this.clean_sel); this.clean_sel.addClass('dirty-indicator-dirty'); }; - + // default CodeMirror options Editor.default_codemirror_options = { extraKeys: { @@ -53,7 +70,7 @@ lineNumbers: true, lineWrapping: true, }; - + Editor.prototype.load = function() { /** load the file */ var that = this; @@ -124,7 +141,7 @@ that.events.trigger("mode_changed.Editor", modeinfo); }); }; - + Editor.prototype.get_filename = function () { return utils.url_path_split(this.file_path)[1]; }; @@ -143,7 +160,7 @@ } ); }; - + Editor.prototype.save = function () { /** save the file */ if (!this.save_enabled) { @@ -193,7 +210,7 @@ }); var that = this; }; - + Editor.prototype.update_codemirror_options = function (options) { /** update codemirror options locally and save changes in config */ var that = this; @@ -207,4 +224,5 @@ ); }; - exports.Editor = Editor; + return {Editor: Editor}; +}); diff --git a/notebook/static-src/edit/js/main.js b/notebook/static/edit/js/main.js similarity index 74% rename from notebook/static-src/edit/js/main.js rename to notebook/static/edit/js/main.js index cd52226cf..3b8ea77a6 100644 --- a/notebook/static-src/edit/js/main.js +++ b/notebook/static/edit/js/main.js @@ -1,22 +1,33 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. -"use strict"; - -require('base/js/globals').then(function() { - - var IPython = require('base/js/namespace'); - var utils = require('base/js/utils'); - var page = require('base/js/page'); - var events = require('base/js/events'); - var configmod = require('services/config'); - var editmod = require('edit/js/editor'); - var menubar = require('edit/js/menubar'); - var savewidget = require('edit/js/savewidget'); - var notificationarea = require('edit/js/notificationarea'); - -// Contents must be loaded at runtime. -requirejs(['contents', 'custom/custom'], function(contents_service) { +require([ + 'jquery', + 'base/js/namespace', + 'base/js/utils', + 'base/js/page', + 'base/js/events', + 'contents', + 'services/config', + 'edit/js/editor', + 'edit/js/menubar', + 'edit/js/savewidget', + 'edit/js/notificationarea', + 'custom/custom', +], function( + $, + IPython, + utils, + page, + events, + contents, + configmod, + editmod, + menubar, + savewidget, + notificationarea + ){ + "use strict"; page = new page.Page(); var base_url = utils.get_body_data('baseUrl'); @@ -25,11 +36,11 @@ requirejs(['contents', 'custom/custom'], function(contents_service) { config.load(); var common_config = new configmod.ConfigSection('common', {base_url: base_url}); common_config.load(); - var contents = new contents_service.Contents({ + contents = new contents.Contents({ base_url: base_url, common_config: common_config }); - + var editor = new editmod.Editor('#texteditor-container', { base_url: base_url, events: events, @@ -37,22 +48,22 @@ requirejs(['contents', 'custom/custom'], function(contents_service) { file_path: file_path, config: config, }); - + // Make it available for debugging IPython.editor = editor; - + var save_widget = new savewidget.SaveWidget('span#save_widget', { editor: editor, events: events, }); - + var menus = new menubar.MenuBar('#menubar', { base_url: base_url, editor: editor, events: events, save_widget: save_widget, }); - + var notification_area = new notificationarea.EditorNotificationArea( '#notification_area', { events: events, @@ -84,8 +95,3 @@ requirejs(['contents', 'custom/custom'], function(contents_service) { // On document ready, resize codemirror. $(document).ready(_handle_resize); }); - -}).catch(function(err) { - console.error('Could not load globals', err); -}); - \ No newline at end of file diff --git a/notebook/static-src/edit/js/menubar.js b/notebook/static/edit/js/menubar.js similarity index 95% rename from notebook/static-src/edit/js/menubar.js rename to notebook/static/edit/js/menubar.js index 434694ad1..fbf7e8043 100644 --- a/notebook/static-src/edit/js/menubar.js +++ b/notebook/static/edit/js/menubar.js @@ -1,11 +1,17 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. - "use strict"; - - var IPython = require('base/js/namespace'); - var utils = require('base/js/utils'); - var dialog = require('base/js/dialog'); +define([ + 'jquery', + 'base/js/namespace', + 'base/js/utils', + 'base/js/dialog', + 'codemirror/lib/codemirror', + 'codemirror/mode/meta', + 'bootstrap', +], function($, IPython, utils, dialog, CodeMirror) { + "use strict"; + var MenuBar = function (selector, options) { /** * Constructor @@ -128,7 +134,7 @@ ); }); }; - + MenuBar.prototype._load_mode_menu = function () { var list = this.element.find("#mode-menu"); var editor = this.editor; @@ -150,4 +156,5 @@ } }; - exports.MenuBar = MenuBar; + return {'MenuBar': MenuBar}; +}); diff --git a/notebook/static-src/edit/js/notificationarea.js b/notebook/static/edit/js/notificationarea.js similarity index 81% rename from notebook/static-src/edit/js/notificationarea.js rename to notebook/static/edit/js/notificationarea.js index 935ff9b09..73f7077d5 100644 --- a/notebook/static-src/edit/js/notificationarea.js +++ b/notebook/static/edit/js/notificationarea.js @@ -1,15 +1,15 @@ - +define([ + 'base/js/notificationarea' +], function(notificationarea) { "use strict"; - - var notificationarea = require('base/js/notificationarea'); var NotificationArea = notificationarea.NotificationArea; - + var EditorNotificationArea = function(selector, options) { NotificationArea.apply(this, [selector, options]); } - + EditorNotificationArea.prototype = Object.create(NotificationArea.prototype); - + /** * Initialize the default set of notification widgets. * @@ -23,5 +23,7 @@ savew.set_message("File saved", 2000); }); }; + - exports.EditorNotificationArea = EditorNotificationArea; + return {EditorNotificationArea: EditorNotificationArea}; +}); diff --git a/notebook/static-src/edit/js/savewidget.js b/notebook/static/edit/js/savewidget.js similarity index 96% rename from notebook/static-src/edit/js/savewidget.js rename to notebook/static/edit/js/savewidget.js index 9ad938ed8..d3ce9aaad 100644 --- a/notebook/static-src/edit/js/savewidget.js +++ b/notebook/static/edit/js/savewidget.js @@ -1,11 +1,14 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. - "use strict"; - var utils = require('base/js/utils'); - var dialog = require('base/js/dialog'); - var keyboard = require('base/js/keyboard'); - var moment = require('moment'); +define([ + 'jquery', + 'base/js/utils', + 'base/js/dialog', + 'base/js/keyboard', + 'moment', +], function($, utils, dialog, keyboard, moment) { + "use strict"; var SaveWidget = function (selector, options) { this.editor = undefined; @@ -131,7 +134,7 @@ } this._render_last_modified(); }; - + SaveWidget.prototype._render_last_modified = function () { /** actually set the text in the element, from our _last_modified value @@ -157,7 +160,7 @@ } el.text(human_date).attr('title', long_date); }; - + SaveWidget.prototype._schedule_render_last_modified = function () { /** schedule the next update to relative date @@ -176,4 +179,6 @@ ); }; - exports.SaveWidget = SaveWidget; + return {'SaveWidget': SaveWidget}; + +}); diff --git a/notebook/static-src/notebook/js/about.js b/notebook/static/notebook/js/about.js similarity index 91% rename from notebook/static-src/notebook/js/about.js rename to notebook/static/notebook/js/about.js index a7df87154..50ef7ad3d 100644 --- a/notebook/static-src/notebook/js/about.js +++ b/notebook/static/notebook/js/about.js @@ -1,10 +1,12 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. +require([ + 'jquery', + 'base/js/dialog', + 'underscore', + 'base/js/namespace' +], function ($, dialog, _, IPython) { 'use strict'; - - var dialog = require('base/js/dialog'); - var IPython = require('base/js/namespace'); - $('#notebook_about').click(function () { // use underscore template to auto html escape var text = 'You are using Jupyter notebook.

'; @@ -33,3 +35,4 @@ kinfo.html($('

').text('unable to contact kernel')); } }); +}); diff --git a/notebook/static-src/notebook/js/actions.js b/notebook/static/notebook/js/actions.js similarity index 99% rename from notebook/static-src/notebook/js/actions.js rename to notebook/static/notebook/js/actions.js index 5800c6963..a6a3eb1ed 100644 --- a/notebook/static-src/notebook/js/actions.js +++ b/notebook/static/notebook/js/actions.js @@ -1,5 +1,7 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. + +define(function(require){ "use strict"; @@ -573,4 +575,6 @@ return (typeof(this._actions[name]) !== 'undefined'); }; - exports.init = ActionHandler; + return {init:ActionHandler}; + +}); diff --git a/notebook/static-src/notebook/js/cell.js b/notebook/static/notebook/js/cell.js similarity index 98% rename from notebook/static-src/notebook/js/cell.js rename to notebook/static/notebook/js/cell.js index 797d9f842..a2f1a6e7f 100644 --- a/notebook/static-src/notebook/js/cell.js +++ b/notebook/static/notebook/js/cell.js @@ -8,12 +8,20 @@ * @namespace cell * @class Cell */ - "use strict"; - var utils = require('base/js/utils'); +define([ + 'jquery', + 'base/js/utils', + 'codemirror/lib/codemirror', + 'codemirror/addon/edit/matchbrackets', + 'codemirror/addon/edit/closebrackets', + 'codemirror/addon/comment/comment' +], function($, utils, CodeMirror, cm_match, cm_closeb, cm_comment) { + "use strict"; + var overlayHack = CodeMirror.scrollbarModel.native.prototype.overlayHack; - + CodeMirror.scrollbarModel.native.prototype.overlayHack = function () { overlayHack.apply(this, arguments); // Reverse `min-height: 18px` scrollbar hack on OS X @@ -26,7 +34,7 @@ this.horiz.style.minHeight = ""; } }; - + var Cell = function (options) { /* Constructor * @@ -114,7 +122,7 @@ } } }; - + // FIXME: Workaround CM Bug #332 (Safari segfault on drag) // by disabling drag/drop altogether on Safari // https://github.com/codemirror/CodeMirror/issues/332 @@ -193,7 +201,7 @@ } }); }; - + /** * This method gets called in CodeMirror's onKeyDown/onKeyPress * handlers and is used to provide custom key handling. @@ -389,7 +397,7 @@ this.focus_cell(); } } - + /** * Focus the cell in the DOM sense * @method focus_cell @@ -545,7 +553,7 @@ this.user_highlight = mode; this.auto_highlight(); }; - + /** * Trigger autodetection of highlight scheme for current cell * @method auto_highlight @@ -553,7 +561,7 @@ Cell.prototype.auto_highlight = function () { this._auto_highlight(this.class_config.get_sync('highlight_modes')); }; - + /** * Try to autodetect cell highlight mode, or use selected mode * @methods _auto_highlight @@ -651,17 +659,17 @@ }; UnrecognizedCell.prototype = Object.create(Cell.prototype); - - + + // cannot merge or split unrecognized cells UnrecognizedCell.prototype.is_mergeable = function () { return false; }; - + UnrecognizedCell.prototype.is_splittable = function () { return false; }; - + UnrecognizedCell.prototype.toJSON = function () { /** * deepcopy the metadata so copied cells don't share the same object @@ -678,7 +686,7 @@ } this.element.find('.inner_cell').find("a").text("Unrecognized cell type: " + data.cell_type); }; - + UnrecognizedCell.prototype.create_element = function () { Cell.prototype.create_element.apply(this, arguments); var cell = this.element = $("

").addClass('cell unrecognized_cell'); @@ -695,7 +703,7 @@ cell.append(inner_cell); this.element = cell; }; - + UnrecognizedCell.prototype.bind_events = function () { Cell.prototype.bind_events.apply(this, arguments); var cell = this; @@ -705,7 +713,8 @@ }); }; - module.exports = { + return { Cell: Cell, UnrecognizedCell: UnrecognizedCell }; +}); diff --git a/notebook/static-src/notebook/js/celltoolbar.js b/notebook/static/notebook/js/celltoolbar.js similarity index 99% rename from notebook/static-src/notebook/js/celltoolbar.js rename to notebook/static/notebook/js/celltoolbar.js index 19819de3c..654bcc0e0 100644 --- a/notebook/static-src/notebook/js/celltoolbar.js +++ b/notebook/static/notebook/js/celltoolbar.js @@ -1,9 +1,12 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. - "use strict"; - var IPython = require('base/js/namespace'); - var events = require('base/js/events'); +define([ + 'base/js/namespace', + 'jquery', + 'base/js/events' +], function(IPython, $, events) { + "use strict"; var CellToolbar = function (options) { /** @@ -461,4 +464,5 @@ // Backwards compatability. IPython.CellToolbar = CellToolbar; - exports.CellToolbar = CellToolbar; + return {'CellToolbar': CellToolbar}; +}); diff --git a/notebook/static-src/notebook/js/celltoolbarpresets/default.js b/notebook/static/notebook/js/celltoolbarpresets/default.js similarity index 89% rename from notebook/static-src/notebook/js/celltoolbarpresets/default.js rename to notebook/static/notebook/js/celltoolbarpresets/default.js index c3386ab4f..fe457f6c9 100644 --- a/notebook/static-src/notebook/js/celltoolbarpresets/default.js +++ b/notebook/static/notebook/js/celltoolbarpresets/default.js @@ -1,9 +1,12 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. - "use strict"; - var celltoolbar = require('notebook/js/celltoolbar'); - var dialog = require('base/js/dialog'); +define([ + 'jquery', + 'notebook/js/celltoolbar', + 'base/js/dialog', +], function($, celltoolbar, dialog) { + "use strict"; var CellToolbar = celltoolbar.CellToolbar; @@ -44,4 +47,5 @@ CellToolbar.register_preset('Edit Metadata', example_preset, notebook); console.log('Default extension for cell metadata editing loaded.'); }; - exports.register = register; + return {'register': register}; +}); diff --git a/notebook/static-src/notebook/js/celltoolbarpresets/example.js b/notebook/static/notebook/js/celltoolbarpresets/example.js similarity index 97% rename from notebook/static-src/notebook/js/celltoolbarpresets/example.js rename to notebook/static/notebook/js/celltoolbarpresets/example.js index 8e11d2788..0e631706e 100644 --- a/notebook/static-src/notebook/js/celltoolbarpresets/example.js +++ b/notebook/static/notebook/js/celltoolbarpresets/example.js @@ -8,8 +8,12 @@ // ``` // $.getScript('/static/js/celltoolbarpresets/example.js'); // ``` +define([ + 'jquery', + 'notebook/js/celltoolbar', +], function($, celltoolbar) { "use strict"; - var celltoolbar = require('notebook/js/celltoolbar'); + var CellToolbar = celltoolbar.CellToolbar; var example_preset = []; @@ -142,4 +146,5 @@ CellToolbar.register_preset('Example',example_preset, notebook); console.log('Example extension for metadata editing loaded.'); }; - exports.register = register; + return {'register': register}; +}); diff --git a/notebook/static-src/notebook/js/celltoolbarpresets/rawcell.js b/notebook/static/notebook/js/celltoolbarpresets/rawcell.js similarity index 86% rename from notebook/static-src/notebook/js/celltoolbarpresets/rawcell.js rename to notebook/static/notebook/js/celltoolbarpresets/rawcell.js index 9abe6b9e5..f3e23453e 100644 --- a/notebook/static-src/notebook/js/celltoolbarpresets/rawcell.js +++ b/notebook/static/notebook/js/celltoolbarpresets/rawcell.js @@ -1,15 +1,18 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. - "use strict"; - var celltoolbar = require('notebook/js/celltoolbar'); - var dialog = require('base/js/dialog'); - var keyboard = require('base/js/keyboard'); +define([ + 'jquery', + 'notebook/js/celltoolbar', + 'base/js/dialog', + 'base/js/keyboard', +], function($, celltoolbar, dialog, keyboard) { + "use strict"; - var CellToolbar = celltoolbar.CellToolbar; - var raw_cell_preset = []; + var CellToolbar = celltoolbar.CellToolbar; + var raw_cell_preset = []; - var select_type = CellToolbar.utils.select_ui_generator([ + var select_type = CellToolbar.utils.select_ui_generator([ ["None", "-"], ["LaTeX", "text/latex"], ["reST", "text/restructuredtext"], @@ -69,13 +72,15 @@ }, // name "Raw NBConvert Format" - ); + ); - var register = function (notebook) { + var register = function (notebook) { CellToolbar.register_callback('raw_cell.select', select_type, ['raw']); raw_cell_preset.push('raw_cell.select'); CellToolbar.register_preset('Raw Cell Format', raw_cell_preset, notebook); console.log('Raw Cell Format toolbar preset loaded.'); - }; - exports.register = register; + }; + return {'register': register}; + +}); diff --git a/notebook/static-src/notebook/js/celltoolbarpresets/slideshow.js b/notebook/static/notebook/js/celltoolbarpresets/slideshow.js similarity index 92% rename from notebook/static-src/notebook/js/celltoolbarpresets/slideshow.js rename to notebook/static/notebook/js/celltoolbarpresets/slideshow.js index ff84cd1a0..50dc96db2 100644 --- a/notebook/static-src/notebook/js/celltoolbarpresets/slideshow.js +++ b/notebook/static/notebook/js/celltoolbarpresets/slideshow.js @@ -1,8 +1,12 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. + +define([ + 'jquery', + 'notebook/js/celltoolbar', +], function($, celltoolbar) { "use strict"; - var celltoolbar = require('notebook/js/celltoolbar'); var CellToolbar = celltoolbar.CellToolbar; var slideshow_preset = []; @@ -38,4 +42,5 @@ CellToolbar.register_preset('Slideshow',slideshow_preset, notebook); console.log('Slideshow extension for metadata editing loaded.'); }; - exports.register = register; + return {'register': register}; +}); diff --git a/notebook/static-src/notebook/js/codecell.js b/notebook/static/notebook/js/codecell.js similarity index 97% rename from notebook/static-src/notebook/js/codecell.js rename to notebook/static/notebook/js/codecell.js index 0334bd097..6f5ebc19b 100644 --- a/notebook/static-src/notebook/js/codecell.js +++ b/notebook/static/notebook/js/codecell.js @@ -7,17 +7,36 @@ * @namespace codecell * @class CodeCell */ - "use strict"; - var IPython = require('base/js/namespace'); - var utils = require('base/js/utils'); - var keyboard = require('base/js/keyboard'); - var configmod = require('services/config'); - var cell = require('notebook/js/cell'); - var outputarea = require('notebook/js/outputarea'); - var completer = require('notebook/js/completer'); - var celltoolbar = require('notebook/js/celltoolbar'); +define([ + 'base/js/namespace', + 'jquery', + 'base/js/utils', + 'base/js/keyboard', + 'services/config', + 'notebook/js/cell', + 'notebook/js/outputarea', + 'notebook/js/completer', + 'notebook/js/celltoolbar', + 'codemirror/lib/codemirror', + 'codemirror/mode/python/python', + 'notebook/js/codemirror-ipython' +], function(IPython, + $, + utils, + keyboard, + configmod, + cell, + outputarea, + completer, + celltoolbar, + CodeMirror, + cmpython, + cmip + ) { + "use strict"; + var Cell = cell.Cell; /* local util for codemirror */ @@ -125,7 +144,7 @@ CodeCell.msg_cells = {}; CodeCell.prototype = Object.create(Cell.prototype); - + /** @method create_element */ CodeCell.prototype.create_element = function () { Cell.prototype.create_element.apply(this, arguments); @@ -312,7 +331,7 @@ this.render(); this.events.trigger('execute.CodeCell', {cell: this}); }; - + /** * Construct the default callbacks for * @method get_callbacks @@ -338,7 +357,7 @@ input : $.proxy(this._handle_input_request, this) }; }; - + CodeCell.prototype._open_with_pager = function (payload) { this.events.trigger('open_with_text.Pager', payload); }; @@ -387,7 +406,7 @@ // Always execute, even if we are already in the rendered state return cont; }; - + CodeCell.prototype.select_all = function () { var start = {line: 0, ch: 0}; var nlines = this.code_mirror.lineCount(); @@ -536,4 +555,5 @@ // Backwards compatability. IPython.CodeCell = CodeCell; - exports.CodeCell = CodeCell; + return {'CodeCell': CodeCell}; +}); diff --git a/notebook/static-src/notebook/js/codemirror-ipython.js b/notebook/static/notebook/js/codemirror-ipython.js similarity index 100% rename from notebook/static-src/notebook/js/codemirror-ipython.js rename to notebook/static/notebook/js/codemirror-ipython.js diff --git a/notebook/static-src/notebook/js/codemirror-ipythongfm.js b/notebook/static/notebook/js/codemirror-ipythongfm.js similarity index 100% rename from notebook/static-src/notebook/js/codemirror-ipythongfm.js rename to notebook/static/notebook/js/codemirror-ipythongfm.js diff --git a/notebook/static-src/notebook/js/commandpalette.js b/notebook/static/notebook/js/commandpalette.js similarity index 98% rename from notebook/static-src/notebook/js/commandpalette.js rename to notebook/static/notebook/js/commandpalette.js index b6daf0e7d..f8a39ca9b 100644 --- a/notebook/static-src/notebook/js/commandpalette.js +++ b/notebook/static/notebook/js/commandpalette.js @@ -1,10 +1,12 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. +define(function(require){ "use strict"; var QH = require("notebook/js/quickhelp"); - + var $ = require("jquery"); + /** * Humanize the action name to be consumed by user. * internaly the actions anem are of the form @@ -172,4 +174,5 @@ mod.modal('show'); }; - module.exports = {'CommandPalette': CommandPalette}; + return {'CommandPalette': CommandPalette}; +}); diff --git a/notebook/static-src/notebook/js/completer.js b/notebook/static/notebook/js/completer.js similarity index 98% rename from notebook/static-src/notebook/js/completer.js rename to notebook/static/notebook/js/completer.js index b23509288..47d5bef7b 100644 --- a/notebook/static-src/notebook/js/completer.js +++ b/notebook/static/notebook/js/completer.js @@ -1,10 +1,14 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. - "use strict"; - var utils = require('base/js/utils'); - var keyboard = require('base/js/keyboard'); - require('notebook/js/contexthint'); +define([ + 'jquery', + 'base/js/utils', + 'base/js/keyboard', + 'notebook/js/contexthint', + 'codemirror/lib/codemirror', +], function($, utils, keyboard, CodeMirror) { + "use strict"; // easier key mapping var keycodes = keyboard.keycodes; @@ -404,4 +408,5 @@ }, 50); }; - exports.Completer = Completer; + return {'Completer': Completer}; +}); diff --git a/notebook/static-src/notebook/js/contexthint.js b/notebook/static/notebook/js/contexthint.js similarity index 96% rename from notebook/static-src/notebook/js/contexthint.js rename to notebook/static/notebook/js/contexthint.js index ac6736478..22fdbcd8f 100644 --- a/notebook/static-src/notebook/js/contexthint.js +++ b/notebook/static/notebook/js/contexthint.js @@ -2,6 +2,7 @@ // Distributed under the terms of the Modified BSD License. // highly adapted for codemiror jshint +define(['codemirror/lib/codemirror'], function(CodeMirror) { "use strict"; var forEach = function(arr, f) { @@ -93,4 +94,5 @@ return filterd; }; - exports.contextHint = CodeMirror.contextHint; + return {'contextHint': CodeMirror.contextHint}; +}); diff --git a/notebook/static-src/notebook/js/kernelselector.js b/notebook/static/notebook/js/kernelselector.js similarity index 97% rename from notebook/static-src/notebook/js/kernelselector.js rename to notebook/static/notebook/js/kernelselector.js index ce38e3594..40b6b0f3d 100644 --- a/notebook/static-src/notebook/js/kernelselector.js +++ b/notebook/static/notebook/js/kernelselector.js @@ -1,9 +1,14 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. + +define([ + 'jquery', + 'base/js/namespace', + 'base/js/dialog', + 'base/js/utils', +], function($, IPython, dialog, utils) { "use strict"; - var IPython = require('base/js/namespace'); - var dialog = require('base/js/dialog'); - var utils = require('base/js/utils'); + var KernelSelector = function(selector, notebook) { var that = this; this.selector = selector; @@ -27,14 +32,14 @@ Object.seal(this); }; - + KernelSelector.prototype.request_kernelspecs = function() { // Preliminary documentation for kernelspecs api is at // https://github.com/ipython/ipython/wiki/IPEP-25%3A-Registry-of-installed-kernels#rest-api var url = utils.url_join_encode(this.notebook.base_url, 'api/kernelspecs'); utils.promising_ajax(url).then($.proxy(this._got_kernelspecs, this)); }; - + var _sorted_names = function(kernelspecs) { // sort kernel names return Object.keys(kernelspecs).sort(function (a, b) { @@ -50,7 +55,7 @@ } }); }; - + KernelSelector.prototype._got_kernelspecs = function(data) { var that = this; this.kernelspecs = data.kernelspecs; @@ -88,7 +93,7 @@ this._loaded = true; this._finish_load(); }; - + KernelSelector.prototype._spec_changed = function (event, ks) { /** event handler for spec_changed */ var that = this; @@ -142,7 +147,7 @@ // load kernel js if (ks.resources['kernel.js']) { - requirejs([ks.resources['kernel.js']], + require([ks.resources['kernel.js']], function (kernel_mod) { if (kernel_mod && kernel_mod.onload) { kernel_mod.onload(); @@ -233,7 +238,7 @@ this.current_selection = ks.name; this.events.trigger('spec_changed.Kernel', ks); }; - + KernelSelector.prototype._spec_not_found = function (event, data) { var that = this; var select = $("