diff --git a/IPython/html/static/auth/js/loginmain.js b/IPython/html/static/auth/js/loginmain.js index d914bf743..a59b3fbb1 100644 --- a/IPython/html/static/auth/js/loginmain.js +++ b/IPython/html/static/auth/js/loginmain.js @@ -1,21 +1,12 @@ -//---------------------------------------------------------------------------- -// Copyright (C) 2008-2011 The IPython Development Team -// -// Distributed under the terms of the BSD License. The full license is in -// the file COPYING, distributed as part of this software. -//---------------------------------------------------------------------------- +// Copyright (c) IPython Development Team. +// Distributed under the terms of the Modified BSD License. -//============================================================================ -// On document ready -//============================================================================ - - -$(document).ready(function () { - - IPython.page = new IPython.Page(); +var ipython = ipython || {}; +require(['base/js/page'], function(page) { + var page_instance = new page.Page(); $('button#login_submit').addClass("btn btn-default"); - IPython.page.show(); + page_instance.show(); $('input#password_input').focus(); - + + ipython.page = page_instance; }); - diff --git a/IPython/html/static/auth/js/loginwidget.js b/IPython/html/static/auth/js/loginwidget.js index 329ba0e0e..8d9f5a2eb 100644 --- a/IPython/html/static/auth/js/loginwidget.js +++ b/IPython/html/static/auth/js/loginwidget.js @@ -1,20 +1,16 @@ -//---------------------------------------------------------------------------- -// Copyright (C) 2008-2011 The IPython Development Team -// -// Distributed under the terms of the BSD License. The full license is in -// the file COPYING, distributed as part of this software. -//---------------------------------------------------------------------------- - -//============================================================================ -// Login button -//============================================================================ - -var IPython = (function (IPython) { +// Copyright (c) IPython Development Team. +// Distributed under the terms of the Modified BSD License. + +define([ + 'base/js/namespace', + 'base/js/utils', + 'jquery', +], function(IPython, utils, $){ "use strict"; var LoginWidget = function (selector, options) { options = options || {}; - this.base_url = options.base_url || IPython.utils.get_body_data("baseUrl"); + this.base_url = options.base_url || utils.get_body_data("baseUrl"); this.selector = selector; if (this.selector !== undefined) { this.element = $(selector); @@ -31,13 +27,13 @@ var IPython = (function (IPython) { LoginWidget.prototype.bind_events = function () { var that = this; this.element.find("button#logout").click(function () { - window.location = IPython.utils.url_join_encode( + window.location = utils.url_join_encode( that.base_url, "logout" ); }); this.element.find("button#login").click(function () { - window.location = IPython.utils.url_join_encode( + window.location = utils.url_join_encode( that.base_url, "login" ); @@ -47,6 +43,5 @@ var IPython = (function (IPython) { // Set module variables IPython.LoginWidget = LoginWidget; - return IPython; - -}(IPython)); + return {'LoginWidget': LoginWidget}; +}); \ No newline at end of file diff --git a/IPython/html/static/auth/js/logoutmain.js b/IPython/html/static/auth/js/logoutmain.js index df107c6f6..ccb8d05c3 100644 --- a/IPython/html/static/auth/js/logoutmain.js +++ b/IPython/html/static/auth/js/logoutmain.js @@ -1,20 +1,11 @@ -//---------------------------------------------------------------------------- -// Copyright (C) 2008-2011 The IPython Development Team -// -// Distributed under the terms of the BSD License. The full license is in -// the file COPYING, distributed as part of this software. -//---------------------------------------------------------------------------- +// Copyright (c) IPython Development Team. +// Distributed under the terms of the Modified BSD License. -//============================================================================ -// On document ready -//============================================================================ - - -$(document).ready(function () { - - IPython.page = new IPython.Page(); +var ipython = ipython || {}; +require(['base/js/page'], function(page) { + var page_instance = new page.Page(); $('#ipython-main-app').addClass('border-box-sizing'); - IPython.page.show(); + page_instance.show(); + ipython.page = page_instance; }); - diff --git a/IPython/html/static/base/js/dialog.js b/IPython/html/static/base/js/dialog.js index d71c32468..246f93f36 100644 --- a/IPython/html/static/base/js/dialog.js +++ b/IPython/html/static/base/js/dialog.js @@ -1,20 +1,14 @@ -//---------------------------------------------------------------------------- -// Copyright (C) 2013 The IPython Development Team -// -// Distributed under the terms of the BSD License. The full license is in -// the file COPYING, distributed as part of this software. -//---------------------------------------------------------------------------- +// Copyright (c) IPython Development Team. +// Distributed under the terms of the Modified BSD License. -//============================================================================ -// Utility for modal dialogs with bootstrap -//============================================================================ - -IPython.namespace('IPython.dialog'); - -IPython.dialog = (function (IPython) { +define([ + 'base/js/namespace', + 'jquery', +], function(IPython, $) { "use strict"; var modal = function (options) { + var modal = $("
") .addClass("modal") .addClass("fade") @@ -79,26 +73,28 @@ IPython.dialog = (function (IPython) { }); } modal.on("hidden.bs.modal", function () { - if (IPython.notebook) { - var cell = IPython.notebook.get_selected_cell(); + if (options.notebook) { + var cell = options.notebook.get_selected_cell(); if (cell) cell.select(); - IPython.keyboard_manager.enable(); - IPython.keyboard_manager.command_mode(); + } + if (options.keyboard_manager) { + options.keyboard_manager.enable(); + options.keyboard_manager.command_mode(); } }); - if (IPython.keyboard_manager) { - IPython.keyboard_manager.disable(); + if (options.keyboard_manager) { + options.keyboard_manager.disable(); } return modal.modal(options); }; - var edit_metadata = function (md, callback, name) { - name = name || "Cell"; + var edit_metadata = function (options) { + options.name = options.name || "Cell"; var error_div = $('
').css('color', 'red'); var message = - "Manually edit the JSON below to manipulate the metadata for this " + name + "." + + "Manually edit the JSON below to manipulate the metadata for this " + options.name + "." + " We recommend putting custom metadata attributes in an appropriately named sub-structure," + " so they don't conflict with those of others."; @@ -106,7 +102,7 @@ IPython.dialog = (function (IPython) { .attr('rows', '13') .attr('cols', '80') .attr('name', 'metadata') - .text(JSON.stringify(md || {}, null, 2)); + .text(JSON.stringify(options.md || {}, null, 2)); var dialogform = $('
').attr('title', 'Edit the metadata') .append( @@ -128,8 +124,8 @@ IPython.dialog = (function (IPython) { autoIndent: true, mode: 'application/json', }); - var modal = IPython.dialog.modal({ - title: "Edit " + name + " Metadata", + var modal = modal({ + title: "Edit " + options.name + " Metadata", body: dialogform, buttons: { OK: { class : "btn-primary", @@ -143,19 +139,25 @@ IPython.dialog = (function (IPython) { error_div.text('WARNING: Could not save invalid JSON.'); return false; } - callback(new_md); + options.callback(new_md); } }, Cancel: {} - } + }, + notebook: options.notebook, + keyboard_manager: options.keyboard_manager, }); modal.on('shown.bs.modal', function(){ editor.refresh(); }); }; - return { + var dialog = { modal : modal, edit_metadata : edit_metadata, }; -}(IPython)); + // Backwards compatability. + IPython.dialog = dialog; + + return dialog; +}); diff --git a/IPython/html/static/base/js/events.js b/IPython/html/static/base/js/events.js index 3d7d78436..e49271ac5 100644 --- a/IPython/html/static/base/js/events.js +++ b/IPython/html/static/base/js/events.js @@ -1,13 +1,5 @@ -//---------------------------------------------------------------------------- -// Copyright (C) 2008-2011 The IPython Development Team -// -// Distributed under the terms of the BSD License. The full license is in -// the file COPYING, distributed as part of this software. -//---------------------------------------------------------------------------- - -//============================================================================ -// Events -//============================================================================ +// Copyright (c) IPython Development Team. +// Distributed under the terms of the Modified BSD License. // Give us an object to bind all events to. This object should be created // before all other objects so it exists when others register event handlers. @@ -15,18 +7,13 @@ // $([IPython.events]).trigger('event.Namespace'); // To handle it: // $([IPython.events]).on('event.Namespace',function () {}); - -var IPython = (function (IPython) { +define(['base/js/namespace'], function(IPython) { "use strict"; - var utils = IPython.utils; - var Events = function () {}; - + + // Backwards compatability. IPython.Events = Events; - IPython.events = new Events(); - - return IPython; - -}(IPython)); - + + return {'Events': Events}; +}); diff --git a/IPython/html/static/base/js/keyboard.js b/IPython/html/static/base/js/keyboard.js index 56391e6d6..211ce2a08 100644 --- a/IPython/html/static/base/js/keyboard.js +++ b/IPython/html/static/base/js/keyboard.js @@ -1,19 +1,14 @@ -//---------------------------------------------------------------------------- -// Copyright (C) 2011 The IPython Development Team -// -// Distributed under the terms of the BSD License. The full license is in -// the file COPYING, distributed as part of this software. -//---------------------------------------------------------------------------- +// Copyright (c) IPython Development Team. +// Distributed under the terms of the Modified BSD License. -//============================================================================ -// Keyboard management -//============================================================================ - -IPython.namespace('IPython.keyboard'); - -IPython.keyboard = (function (IPython) { +define([ + 'base/js/namespace', + 'jquery', + 'base/js/utils', +], function(IPython, $, utils) { "use strict"; + // Setup global keycodes and inverse keycodes. // See http://unixpapa.com/js/key.html for a complete description. The short of @@ -51,8 +46,8 @@ IPython.keyboard = (function (IPython) { '; :': 186, '= +': 187, '- _': 189 }; - var browser = IPython.utils.browser[0]; - var platform = IPython.utils.platform; + var browser = utils.browser[0]; + var platform = utils.platform; if (browser === 'Firefox' || browser === 'Opera' || browser === 'Netscape') { $.extend(_keycodes, _mozilla_keycodes); @@ -130,18 +125,19 @@ IPython.keyboard = (function (IPython) { // Shortcut manager class - var ShortcutManager = function (delay) { + var ShortcutManager = function (delay, events) { this._shortcuts = {}; this._counts = {}; this._timers = {}; this.delay = delay || 800; // delay in milliseconds + this.events = events; }; ShortcutManager.prototype.help = function () { var help = []; for (var shortcut in this._shortcuts) { - var help_string = this._shortcuts[shortcut]['help']; - var help_index = this._shortcuts[shortcut]['help_index']; + var help_string = this._shortcuts[shortcut].help; + var help_index = this._shortcuts[shortcut].help_index; if (help_string) { if (platform === 'MacOS') { shortcut = shortcut.replace('meta', 'cmd'); @@ -182,7 +178,7 @@ IPython.keyboard = (function (IPython) { this._shortcuts[shortcut] = data; if (!suppress_help_update) { // update the keyboard shortcuts notebook help - $([IPython.events]).trigger('rebuild.QuickHelp'); + this.events.trigger('rebuild.QuickHelp'); } }; @@ -191,7 +187,7 @@ IPython.keyboard = (function (IPython) { this.add_shortcut(shortcut, data[shortcut], true); } // update the keyboard shortcuts notebook help - $([IPython.events]).trigger('rebuild.QuickHelp'); + this.events.trigger('rebuild.QuickHelp'); }; ShortcutManager.prototype.remove_shortcut = function (shortcut, suppress_help_update) { @@ -200,7 +196,7 @@ IPython.keyboard = (function (IPython) { delete this._shortcuts[shortcut]; if (!suppress_help_update) { // update the keyboard shortcuts notebook help - $([IPython.events]).trigger('rebuild.QuickHelp'); + this.events.trigger('rebuild.QuickHelp'); } }; @@ -211,7 +207,7 @@ IPython.keyboard = (function (IPython) { var timer = null; if (c[shortcut] === data.count-1) { c[shortcut] = 0; - var timer = t[shortcut]; + timer = t[shortcut]; if (timer) {clearTimeout(timer); delete t[shortcut];} return data.handler(event); } else { @@ -228,7 +224,7 @@ IPython.keyboard = (function (IPython) { var shortcut = event_to_shortcut(event); var data = this._shortcuts[shortcut]; if (data) { - var handler = data['handler']; + var handler = data.handler; if (handler) { if (data.count === 1) { return handler(event); @@ -243,10 +239,10 @@ IPython.keyboard = (function (IPython) { ShortcutManager.prototype.handles = function (event) { var shortcut = event_to_shortcut(event); var data = this._shortcuts[shortcut]; - return !( data === undefined || data.handler === undefined ) - } + return !( data === undefined || data.handler === undefined ); + }; - return { + var keyboard = { keycodes : keycodes, inv_keycodes : inv_keycodes, ShortcutManager : ShortcutManager, @@ -256,4 +252,8 @@ IPython.keyboard = (function (IPython) { event_to_shortcut : event_to_shortcut }; -}(IPython)); + // For backwards compatability. + IPython.keyboard = keyboard; + + return keyboard; +}); diff --git a/IPython/html/static/base/js/namespace.js b/IPython/html/static/base/js/namespace.js index 3b36198f5..c89cbc75c 100644 --- a/IPython/html/static/base/js/namespace.js +++ b/IPython/html/static/base/js/namespace.js @@ -1,34 +1,8 @@ -//---------------------------------------------------------------------------- -// Copyright (C) 2011 The IPython Development Team -// -// Distributed under the terms of the BSD License. The full license is in -// the file COPYING, distributed as part of this software. -//---------------------------------------------------------------------------- +// Copyright (c) IPython Development Team. +// Distributed under the terms of the Modified BSD License. var IPython = IPython || {}; - -IPython.version = "3.0.0-dev"; - -IPython.namespace = function (ns_string) { - "use strict"; - - var parts = ns_string.split('.'), - parent = IPython, - i; - - // String redundant leading global - if (parts[0] === "IPython") { - parts = parts.slice(1); - } - - for (i=0; i