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; ix'+ 'x'+ @@ -85,43 +100,37 @@ function (marked) { } $('#fonttest').remove(); - IPython.page.show(); + page.show(); - IPython.layout_manager.do_resize(); + layout_manager.do_resize(); var first_load = function () { - IPython.layout_manager.do_resize(); + layout_manager.do_resize(); var hash = document.location.hash; if (hash) { document.location.hash = ''; document.location.hash = hash; } - IPython.notebook.set_autosave_interval(IPython.notebook.minimum_autosave_interval); + notebook.set_autosave_interval(notebook.minimum_autosave_interval); // only do this once - $([IPython.events]).off('notebook_loaded.Notebook', first_load); + events.off('notebook_loaded.Notebook', first_load); }; - $([IPython.events]).on('notebook_loaded.Notebook', first_load); - $([IPython.events]).trigger('app_initialized.NotebookApp'); - IPython.notebook.load_notebook(opts.notebook_name, opts.notebook_path); + events.on('notebook_loaded.Notebook', first_load); + events.trigger('app_initialized.NotebookApp'); + notebook.load_notebook(common_options.notebook_name, common_options.notebook_path); - if (marked) { - marked.setOptions({ - gfm : true, - tables: true, - langPrefix: "language-", - highlight: function(code, lang) { - if (!lang) { - // no language, no highlight - return code; - } - var highlighted; - try { - highlighted = hljs.highlight(lang, code, false); - } catch(err) { - highlighted = hljs.highlightAuto(code); - } - return highlighted.value; - } - }); - } + IPython.page = page; + IPython.layout_manager = layout_manager; + IPython.notebook = notebook; + IPython.pager = pager; + IPython.quick_help = quick_help; + IPython.login_widget = login_widget; + IPython.menubar = menubar; + IPython.toolbar = toolbar; + IPython.notification_area = notification_area; + IPython.events = events; + IPython.keyboard_manager = keyboard_manager; + IPython.save_widget = save_widget; + IPython.config = user_config; + IPython.tooltip = notebook.tooltip; }); diff --git a/IPython/html/static/notebook/js/maintoolbar.js b/IPython/html/static/notebook/js/maintoolbar.js index 01af2622d..bed81dcf9 100644 --- a/IPython/html/static/notebook/js/maintoolbar.js +++ b/IPython/html/static/notebook/js/maintoolbar.js @@ -1,35 +1,43 @@ -//---------------------------------------------------------------------------- -// 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. -//---------------------------------------------------------------------------- - -//============================================================================ -// ToolBar -//============================================================================ - -var IPython = (function (IPython) { +// Copyright (c) IPython Development Team. +// Distributed under the terms of the Modified BSD License. + +define([ + 'base/js/namespace', + 'jquery', + 'notebook/js/toolbar', + 'notebook/js/celltoolbar', +], function(IPython, $, toolbar, celltoolbar) { "use strict"; - var MainToolBar = function (selector) { - IPython.ToolBar.apply(this, arguments); + var MainToolBar = function (selector, options) { + // Constructor + // + // Parameters: + // selector: string + // options: dictionary + // Dictionary of keyword arguments. + // events: $(Events) instance + // notebook: Notebook instance + toolbar.ToolBar.apply(this, arguments); + this.events = options.events; + this.notebook = options.notebook; this.construct(); this.add_celltype_list(); this.add_celltoolbar_list(); this.bind_events(); }; - MainToolBar.prototype = new IPython.ToolBar(); + MainToolBar.prototype = new toolbar.ToolBar(); MainToolBar.prototype.construct = function () { + var that = this; this.add_buttons_group([ { id : 'save_b', label : 'Save and Checkpoint', icon : 'icon-save', callback : function () { - IPython.notebook.save_checkpoint(); + that.notebook.save_checkpoint(); } } ]); @@ -40,9 +48,9 @@ var IPython = (function (IPython) { label : 'Insert Cell Below', icon : 'icon-plus-sign', callback : function () { - IPython.notebook.insert_cell_below('code'); - IPython.notebook.select_next(); - IPython.notebook.focus_cell(); + that.notebook.insert_cell_below('code'); + that.notebook.select_next(); + that.notebook.focus_cell(); } } ],'insert_above_below'); @@ -53,7 +61,7 @@ var IPython = (function (IPython) { label : 'Cut Cell', icon : 'icon-cut', callback : function () { - IPython.notebook.cut_cell(); + that.notebook.cut_cell(); } }, { @@ -61,7 +69,7 @@ var IPython = (function (IPython) { label : 'Copy Cell', icon : 'icon-copy', callback : function () { - IPython.notebook.copy_cell(); + that.notebook.copy_cell(); } }, { @@ -69,7 +77,7 @@ var IPython = (function (IPython) { label : 'Paste Cell Below', icon : 'icon-paste', callback : function () { - IPython.notebook.paste_cell_below(); + that.notebook.paste_cell_below(); } } ],'cut_copy_paste'); @@ -80,7 +88,7 @@ var IPython = (function (IPython) { label : 'Move Cell Up', icon : 'icon-arrow-up', callback : function () { - IPython.notebook.move_cell_up(); + that.notebook.move_cell_up(); } }, { @@ -88,7 +96,7 @@ var IPython = (function (IPython) { label : 'Move Cell Down', icon : 'icon-arrow-down', callback : function () { - IPython.notebook.move_cell_down(); + that.notebook.move_cell_down(); } } ],'move_up_down'); @@ -101,7 +109,7 @@ var IPython = (function (IPython) { icon : 'icon-play', callback : function () { // emulate default shift-enter behavior - IPython.notebook.execute_cell_and_select_below(); + that.notebook.execute_cell_and_select_below(); } }, { @@ -109,7 +117,7 @@ var IPython = (function (IPython) { label : 'Interrupt', icon : 'icon-stop', callback : function () { - IPython.notebook.session.interrupt_kernel(); + that.notebook.session.interrupt_kernel(); } }, { @@ -117,7 +125,7 @@ var IPython = (function (IPython) { label : 'Restart Kernel', icon : 'icon-repeat', callback : function () { - IPython.notebook.restart_kernel(); + that.notebook.restart_kernel(); } } ],'run_int'); @@ -150,30 +158,31 @@ var IPython = (function (IPython) { .addClass('form-control select-xs') .append($('').attr('value', '').text('None')); this.element.append(label).append(select); + var that = this; select.change(function() { - var val = $(this).val() - if (val =='') { - IPython.CellToolbar.global_hide(); - delete IPython.notebook.metadata.celltoolbar; + var val = $(this).val(); + if (val ==='') { + celltoolbar.CellToolbar.global_hide(); + delete that.notebook.metadata.celltoolbar; } else { - IPython.CellToolbar.global_show(); - IPython.CellToolbar.activate_preset(val); - IPython.notebook.metadata.celltoolbar = val; + celltoolbar.CellToolbar.global_show(); + celltoolbar.CellToolbar.activate_preset(val, that.events); + that.notebook.metadata.celltoolbar = val; } }); // Setup the currently registered presets. - var presets = IPython.CellToolbar.list_presets(); + var presets = celltoolbar.CellToolbar.list_presets(); for (var i=0; i').attr('value', name).text(name)); } // Setup future preset registrations. - $([IPython.events]).on('preset_added.CellToolbar', function (event, data) { + this.events.on('preset_added.CellToolbar', function (event, data) { var name = data.name; select.append($('').attr('value', name).text(name)); }); // Update select value when a preset is activated. - $([IPython.events]).on('preset_activated.CellToolbar', function (event, data) { + this.events.on('preset_activated.CellToolbar', function (event, data) { if (select.val() !== data.name) select.val(data.name); }); @@ -186,26 +195,26 @@ var IPython = (function (IPython) { this.element.find('#cell_type').change(function () { var cell_type = $(this).val(); if (cell_type === 'code') { - IPython.notebook.to_code(); + that.notebook.to_code(); } else if (cell_type === 'markdown') { - IPython.notebook.to_markdown(); + that.notebook.to_markdown(); } else if (cell_type === 'raw') { - IPython.notebook.to_raw(); + that.notebook.to_raw(); } else if (cell_type === 'heading1') { - IPython.notebook.to_heading(undefined, 1); + that.notebook.to_heading(undefined, 1); } else if (cell_type === 'heading2') { - IPython.notebook.to_heading(undefined, 2); + that.notebook.to_heading(undefined, 2); } else if (cell_type === 'heading3') { - IPython.notebook.to_heading(undefined, 3); + that.notebook.to_heading(undefined, 3); } else if (cell_type === 'heading4') { - IPython.notebook.to_heading(undefined, 4); + that.notebook.to_heading(undefined, 4); } else if (cell_type === 'heading5') { - IPython.notebook.to_heading(undefined, 5); + that.notebook.to_heading(undefined, 5); } else if (cell_type === 'heading6') { - IPython.notebook.to_heading(undefined, 6); + that.notebook.to_heading(undefined, 6); } }); - $([IPython.events]).on('selected_cell_type_changed.Notebook', function (event, data) { + this.events.on('selected_cell_type_changed.Notebook', function (event, data) { if (data.cell_type === 'heading') { that.element.find('#cell_type').val(data.cell_type+data.level); } else { @@ -214,8 +223,8 @@ var IPython = (function (IPython) { }); }; + // Backwards compatability. IPython.MainToolBar = MainToolBar; - return IPython; - -}(IPython)); + return {'MainToolBar': MainToolBar}; +}); diff --git a/IPython/html/static/notebook/js/mathjaxutils.js b/IPython/html/static/notebook/js/mathjaxutils.js index 62044dc84..ba5b59bb2 100644 --- a/IPython/html/static/notebook/js/mathjaxutils.js +++ b/IPython/html/static/notebook/js/mathjaxutils.js @@ -1,18 +1,12 @@ -//---------------------------------------------------------------------------- -// Copyright (C) 2008-2012 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. -//---------------------------------------------------------------------------- - -//============================================================================ -// MathJax utility functions -//============================================================================ - - -IPython.namespace('IPython.mathjaxutils'); - -IPython.mathjaxutils = (function (IPython) { +// Copyright (c) IPython Development Team. +// Distributed under the terms of the Modified BSD License. + +define([ + 'base/js/namespace', + 'jquery', + 'base/js/utils', + 'base/js/dialog', +], function(IPython, $, utils, dialog) { "use strict"; var init = function () { @@ -75,7 +69,7 @@ IPython.mathjaxutils = (function (IPython) { "which will prevent this dialog from appearing." ) ); - IPython.dialog.modal({ + dialog.modal({ title : "Failed to retrieve MathJax from '" + window.mathjax_url + "'", body : message, buttons : { @@ -110,7 +104,7 @@ IPython.mathjaxutils = (function (IPython) { .replace(//g, ">") // use HTML entity for > ; - if (IPython.utils.browser === 'msie') { + if (utils.browser === 'msie') { block = block.replace(/(%[^\n]*)\n/g, "$1
\n"); } while (j > i) { @@ -159,7 +153,7 @@ IPython.mathjaxutils = (function (IPython) { de_tilde = function (text) { return text; }; } - var blocks = IPython.utils.regex_split(text.replace(/\r\n?/g, "\n"),MATHSPLIT); + var blocks = utils.regex_split(text.replace(/\r\n?/g, "\n"),MATHSPLIT); for (var i = 1, m = blocks.length; i < m; i += 2) { var block = blocks[i]; @@ -242,10 +236,13 @@ IPython.mathjaxutils = (function (IPython) { return text; }; - return { + var mathjaxutils = { init : init, remove_math : remove_math, replace_math : replace_math }; -}(IPython)); + IPython.mathjaxutils = mathjaxutils; + + return mathjaxutils; +}); diff --git a/IPython/html/static/notebook/js/menubar.js b/IPython/html/static/notebook/js/menubar.js index 04c88e2e7..f2c0b6565 100644 --- a/IPython/html/static/notebook/js/menubar.js +++ b/IPython/html/static/notebook/js/menubar.js @@ -1,40 +1,48 @@ // Copyright (c) IPython Development Team. // Distributed under the terms of the Modified BSD License. -//============================================================================ -// MenuBar -//============================================================================ - -/** - * @module IPython - * @namespace IPython - * @submodule MenuBar - */ - - -var IPython = (function (IPython) { +define([ + 'base/js/namespace', + 'jquery', + 'base/js/utils', + 'notebook/js/tour', + 'components/bootstrap/js/bootstrap.min', +], function(IPython, $, utils, tour) { "use strict"; - var utils = IPython.utils; - - /** - * A MenuBar Class to generate the menubar of IPython notebook - * @Class MenuBar - * - * @constructor - * - * - * @param selector {string} selector for the menubar element in DOM - * @param {object} [options] - * @param [options.base_url] {String} String to use for the - * base project url. Default is to inspect - * $('body').data('baseUrl'); - * does not support change for now is set through this option - */ var MenuBar = function (selector, options) { + // Constructor + // + // A MenuBar Class to generate the menubar of IPython notebook + // + // Parameters: + // selector: string + // options: dictionary + // Dictionary of keyword arguments. + // notebook: Notebook instance + // layout_manager: LayoutManager instance + // events: $(Events) instance + // save_widget: SaveWidget instance + // quick_help: QuickHelp instance + // base_url : string + // notebook_path : string + // notebook_name : string 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; + this.notebook = options.notebook; + this.layout_manager = options.layout_manager; + this.events = options.events; + this.save_widget = options.save_widget; + this.quick_help = options.quick_help; + + try { + this.tour = new tour.Tour(this.notebook, this.events); + } catch (e) { + this.tour = undefined; + console.log("Failed to instantiate Notebook Tour", e); + } + if (this.selector !== undefined) { this.element = $(selector); this.style(); @@ -43,22 +51,23 @@ var IPython = (function (IPython) { }; MenuBar.prototype.style = function () { + var that = this; this.element.addClass('border-box-sizing'); this.element.find("li").click(function (event, ui) { // The selected cell loses focus when the menu is entered, so we // re-select it upon selection. - var i = IPython.notebook.get_selected_index(); - IPython.notebook.select(i); + var i = that.notebook.get_selected_index(); + that.notebook.select(i); } ); }; MenuBar.prototype._nbconvert = function (format, download) { download = download || false; - var notebook_path = IPython.notebook.notebook_path; - var notebook_name = IPython.notebook.notebook_name; - if (IPython.notebook.dirty) { - IPython.notebook.save_notebook({async : false}); + var notebook_path = this.notebook.notebook_path; + var notebook_name = this.notebook.notebook_name; + if (this.notebook.dirty) { + this.notebook.save_notebook({async : false}); } var url = utils.url_join_encode( this.base_url, @@ -75,25 +84,25 @@ var IPython = (function (IPython) { // File var that = this; this.element.find('#new_notebook').click(function () { - IPython.notebook.new_notebook(); + that.notebook.new_notebook(); }); this.element.find('#open_notebook').click(function () { window.open(utils.url_join_encode( - IPython.notebook.base_url, + that.notebook.base_url, 'tree', - IPython.notebook.notebook_path + that.notebook.notebook_path )); }); this.element.find('#copy_notebook').click(function () { - IPython.notebook.copy_notebook(); + that.notebook.copy_notebook(); return false; }); this.element.find('#download_ipynb').click(function () { - var base_url = IPython.notebook.base_url; - var notebook_path = IPython.notebook.notebook_path; - var notebook_name = IPython.notebook.notebook_name; - if (IPython.notebook.dirty) { - IPython.notebook.save_notebook({async : false}); + var base_url = that.notebook.base_url; + var notebook_path = that.notebook.notebook_path; + var notebook_name = that.notebook.notebook_name; + if (that.notebook.dirty) { + that.notebook.save_notebook({async : false}); } var url = utils.url_join_encode( @@ -126,17 +135,17 @@ var IPython = (function (IPython) { }); this.element.find('#rename_notebook').click(function () { - IPython.save_widget.rename_notebook(); + that.save_widget.rename_notebook({notebook: that.notebook}); }); this.element.find('#save_checkpoint').click(function () { - IPython.notebook.save_checkpoint(); + that.notebook.save_checkpoint(); }); this.element.find('#restore_checkpoint').click(function () { }); this.element.find('#trust_notebook').click(function () { - IPython.notebook.trust_notebook(); + that.notebook.trust_notebook(); }); - $([IPython.events]).on('trust_changed.Notebook', function (event, trusted) { + this.events.on('trust_changed.Notebook', function (event, trusted) { if (trusted) { that.element.find('#trust_notebook') .addClass("disabled") @@ -148,7 +157,7 @@ var IPython = (function (IPython) { } }); this.element.find('#kill_and_exit').click(function () { - IPython.notebook.session.delete(); + that.notebook.session.delete(); setTimeout(function(){ // allow closing of new tabs in Chromium, impossible in FF window.open('', '_self', ''); @@ -157,148 +166,150 @@ var IPython = (function (IPython) { }); // Edit this.element.find('#cut_cell').click(function () { - IPython.notebook.cut_cell(); + that.notebook.cut_cell(); }); this.element.find('#copy_cell').click(function () { - IPython.notebook.copy_cell(); + that.notebook.copy_cell(); }); this.element.find('#delete_cell').click(function () { - IPython.notebook.delete_cell(); + that.notebook.delete_cell(); }); this.element.find('#undelete_cell').click(function () { - IPython.notebook.undelete_cell(); + that.notebook.undelete_cell(); }); this.element.find('#split_cell').click(function () { - IPython.notebook.split_cell(); + that.notebook.split_cell(); }); this.element.find('#merge_cell_above').click(function () { - IPython.notebook.merge_cell_above(); + that.notebook.merge_cell_above(); }); this.element.find('#merge_cell_below').click(function () { - IPython.notebook.merge_cell_below(); + that.notebook.merge_cell_below(); }); this.element.find('#move_cell_up').click(function () { - IPython.notebook.move_cell_up(); + that.notebook.move_cell_up(); }); this.element.find('#move_cell_down').click(function () { - IPython.notebook.move_cell_down(); + that.notebook.move_cell_down(); }); this.element.find('#edit_nb_metadata').click(function () { - IPython.notebook.edit_metadata(); + that.notebook.edit_metadata({ + notebook: that.notebook, + keyboard_manager: that.notebook.keyboard_manager}); }); // View this.element.find('#toggle_header').click(function () { $('div#header').toggle(); - IPython.layout_manager.do_resize(); + that.layout_manager.do_resize(); }); this.element.find('#toggle_toolbar').click(function () { $('div#maintoolbar').toggle(); - IPython.layout_manager.do_resize(); + that.layout_manager.do_resize(); }); // Insert this.element.find('#insert_cell_above').click(function () { - IPython.notebook.insert_cell_above('code'); - IPython.notebook.select_prev(); + that.notebook.insert_cell_above('code'); + that.notebook.select_prev(); }); this.element.find('#insert_cell_below').click(function () { - IPython.notebook.insert_cell_below('code'); - IPython.notebook.select_next(); + that.notebook.insert_cell_below('code'); + that.notebook.select_next(); }); // Cell this.element.find('#run_cell').click(function () { - IPython.notebook.execute_cell(); + that.notebook.execute_cell(); }); this.element.find('#run_cell_select_below').click(function () { - IPython.notebook.execute_cell_and_select_below(); + that.notebook.execute_cell_and_select_below(); }); this.element.find('#run_cell_insert_below').click(function () { - IPython.notebook.execute_cell_and_insert_below(); + that.notebook.execute_cell_and_insert_below(); }); this.element.find('#run_all_cells').click(function () { - IPython.notebook.execute_all_cells(); + that.notebook.execute_all_cells(); }); this.element.find('#run_all_cells_above').click(function () { - IPython.notebook.execute_cells_above(); + that.notebook.execute_cells_above(); }); this.element.find('#run_all_cells_below').click(function () { - IPython.notebook.execute_cells_below(); + that.notebook.execute_cells_below(); }); this.element.find('#to_code').click(function () { - IPython.notebook.to_code(); + that.notebook.to_code(); }); this.element.find('#to_markdown').click(function () { - IPython.notebook.to_markdown(); + that.notebook.to_markdown(); }); this.element.find('#to_raw').click(function () { - IPython.notebook.to_raw(); + that.notebook.to_raw(); }); this.element.find('#to_heading1').click(function () { - IPython.notebook.to_heading(undefined, 1); + that.notebook.to_heading(undefined, 1); }); this.element.find('#to_heading2').click(function () { - IPython.notebook.to_heading(undefined, 2); + that.notebook.to_heading(undefined, 2); }); this.element.find('#to_heading3').click(function () { - IPython.notebook.to_heading(undefined, 3); + that.notebook.to_heading(undefined, 3); }); this.element.find('#to_heading4').click(function () { - IPython.notebook.to_heading(undefined, 4); + that.notebook.to_heading(undefined, 4); }); this.element.find('#to_heading5').click(function () { - IPython.notebook.to_heading(undefined, 5); + that.notebook.to_heading(undefined, 5); }); this.element.find('#to_heading6').click(function () { - IPython.notebook.to_heading(undefined, 6); + that.notebook.to_heading(undefined, 6); }); this.element.find('#toggle_current_output').click(function () { - IPython.notebook.toggle_output(); + that.notebook.toggle_output(); }); this.element.find('#toggle_current_output_scroll').click(function () { - IPython.notebook.toggle_output_scroll(); + that.notebook.toggle_output_scroll(); }); this.element.find('#clear_current_output').click(function () { - IPython.notebook.clear_output(); + that.notebook.clear_output(); }); this.element.find('#toggle_all_output').click(function () { - IPython.notebook.toggle_all_output(); + that.notebook.toggle_all_output(); }); this.element.find('#toggle_all_output_scroll').click(function () { - IPython.notebook.toggle_all_output_scroll(); + that.notebook.toggle_all_output_scroll(); }); this.element.find('#clear_all_output').click(function () { - IPython.notebook.clear_all_output(); + that.notebook.clear_all_output(); }); // Kernel this.element.find('#int_kernel').click(function () { - IPython.notebook.session.interrupt_kernel(); + that.notebook.session.interrupt_kernel(); }); this.element.find('#restart_kernel').click(function () { - IPython.notebook.restart_kernel(); + that.notebook.restart_kernel(); }); // Help - if (IPython.tour) { + if (this.tour) { this.element.find('#notebook_tour').click(function () { - IPython.tour.start(); + that.tour.start(); }); } else { this.element.find('#notebook_tour').addClass("disabled"); } this.element.find('#keyboard_shortcuts').click(function () { - IPython.quick_help.show_keyboard_shortcuts(); + that.quick_help.show_keyboard_shortcuts(); }); this.update_restore_checkpoint(null); - $([IPython.events]).on('checkpoints_listed.Notebook', function (event, data) { - that.update_restore_checkpoint(IPython.notebook.checkpoints); + this.events.on('checkpoints_listed.Notebook', function (event, data) { + that.update_restore_checkpoint(that.notebook.checkpoints); }); - $([IPython.events]).on('checkpoint_created.Notebook', function (event, data) { - that.update_restore_checkpoint(IPython.notebook.checkpoints); + this.events.on('checkpoint_created.Notebook', function (event, data) { + that.update_restore_checkpoint(that.notebook.checkpoints); }); }; @@ -317,6 +328,7 @@ var IPython = (function (IPython) { return; } + var that = this; checkpoints.map(function (checkpoint) { var d = new Date(checkpoint.last_modified); ul.append( @@ -325,15 +337,15 @@ var IPython = (function (IPython) { .attr("href", "#") .text(d.format("mmm dd HH:MM:ss")) .click(function () { - IPython.notebook.restore_checkpoint_dialog(checkpoint); + that.notebook.restore_checkpoint_dialog(checkpoint); }) ) ); }); }; + // Backwards compatability. IPython.MenuBar = MenuBar; - return IPython; - -}(IPython)); + return {'MenuBar': MenuBar}; +}); diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index c5b1dc33b..7a899f9b7 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -1,32 +1,92 @@ -//---------------------------------------------------------------------------- -// 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. + +define([ + 'base/js/namespace', + 'jquery', + 'base/js/utils', + 'base/js/dialog', + 'notebook/js/textcell', + 'notebook/js/codecell', + 'services/sessions/js/session', + 'notebook/js/celltoolbar', + 'components/marked/lib/marked', + 'notebook/js/mathjaxutils', + 'base/js/keyboard', + 'notebook/js/tooltip', + 'notebook/js/celltoolbarpresets/default', + 'notebook/js/celltoolbarpresets/rawcell', + 'notebook/js/celltoolbarpresets/slideshow', +], function ( + IPython, + $, + utils, + dialog, + textcell, + codecell, + session, + celltoolbar, + marked, + mathjaxutils, + keyboard, + tooltip, + default_celltoolbar, + rawcell_celltoolbar, + slideshow_celltoolbar + ) { -//============================================================================ -// Notebook -//============================================================================ - -var IPython = (function (IPython) { - "use strict"; - - var utils = IPython.utils; - - /** - * A notebook contains and manages cells. - * - * @class Notebook - * @constructor - * @param {String} selector A jQuery selector for the notebook's DOM element - * @param {Object} [options] A config object - */ var Notebook = function (selector, options) { - this.options = options = options || {}; + // Constructor + // + // A notebook contains and manages cells. + // + // Parameters: + // selector: string + // options: dictionary + // Dictionary of keyword arguments. + // events: $(Events) instance + // keyboard_manager: KeyboardManager instance + // save_widget: SaveWidget instance + // config: dictionary + // base_url : string + // notebook_path : string + // notebook_name : string + this.config = options.config || {}; this.base_url = options.base_url; this.notebook_path = options.notebook_path; this.notebook_name = options.notebook_name; + this.events = options.events; + this.keyboard_manager = options.keyboard_manager; + this.save_widget = options.save_widget; + this.tooltip = new tooltip.Tooltip(this.events); + // TODO: This code smells (and the other `= this` line a couple lines down) + // We need a better way to deal with circular instance references. + this.keyboard_manager.notebook = this; + this.save_widget.notebook = this; + + mathjaxutils.init(); + + if (marked) { + marked.setOptions({ + gfm : true, + tables: true, + langPrefix: "language-", + highlight: function(code, lang) { + if (!lang) { + // no language, no highlight + return code; + } + var highlighted; + try { + highlighted = hljs.highlight(lang, code, false); + } catch(err) { + highlighted = hljs.highlightAuto(code); + } + return highlighted.value; + } + }); + } + this.element = $(selector); this.element.scroll(); this.element.data("notebook", this); @@ -61,6 +121,11 @@ var IPython = (function (IPython) { this.save_notebook = function() { // don't allow save until notebook_loaded this.save_notebook_error(null, null, "Load failed, save is disabled"); }; + + // Trigger cell toolbar registration. + default_celltoolbar.register(this, options.events); + rawcell_celltoolbar.register(this, options.events); + slideshow_celltoolbar.register(this, options.events); }; /** @@ -102,36 +167,38 @@ var IPython = (function (IPython) { Notebook.prototype.bind_events = function () { var that = this; - $([IPython.events]).on('set_next_input.Notebook', function (event, data) { + this.events.on('set_next_input.Notebook', function (event, data) { var index = that.find_cell_index(data.cell); var new_cell = that.insert_cell_below('code',index); new_cell.set_text(data.text); that.dirty = true; }); - $([IPython.events]).on('set_dirty.Notebook', function (event, data) { + this.events.on('set_dirty.Notebook', function (event, data) { that.dirty = data.value; }); - $([IPython.events]).on('trust_changed.Notebook', function (event, data) { + this.events.on('trust_changed.Notebook', function (event, data) { that.trusted = data.value; }); - $([IPython.events]).on('select.Cell', function (event, data) { + this.events.on('select.Cell', function (event, data) { var index = that.find_cell_index(data.cell); that.select(index); }); - $([IPython.events]).on('edit_mode.Cell', function (event, data) { + this.events.on('edit_mode.Cell', function (event, data) { that.handle_edit_mode(data.cell); }); - $([IPython.events]).on('command_mode.Cell', function (event, data) { + this.events.on('command_mode.Cell', function (event, data) { that.handle_command_mode(data.cell); }); - $([IPython.events]).on('status_autorestarting.Kernel', function () { - IPython.dialog.modal({ + this.events.on('status_autorestarting.Kernel', function () { + dialog.modal({ + notebook: that, + keyboard_manager: that.keyboard_manager, title: "Kernel Restarting", body: "The kernel appears to have died. It will restart automatically.", buttons: { @@ -211,7 +278,7 @@ var IPython = (function (IPython) { if (this.dirty == value) { return; } - $([IPython.events]).trigger('set_dirty.Notebook', {value: value}); + this.events.trigger('set_dirty.Notebook', {value: value}); }; /** @@ -254,9 +321,14 @@ var IPython = (function (IPython) { Notebook.prototype.edit_metadata = function () { var that = this; - IPython.dialog.edit_metadata(this.metadata, function (md) { - that.metadata = md; - }, 'Notebook'); + dialog.edit_metadata({ + md: this.metadata, + callback: function (md) { + that.metadata = md; + }, + name: 'Notebook', + notebook: this, + keyboard_manager: this.keyboard_manager}); }; // Cell indexing, retrieval, etc. @@ -295,7 +367,7 @@ var IPython = (function (IPython) { * @return {Cell} Cell or null if no cell was found. */ Notebook.prototype.get_msg_cell = function (msg_id) { - return IPython.CodeCell.msg_cells[msg_id] || null; + return codecell.CodeCell.msg_cells[msg_id] || null; }; /** @@ -474,11 +546,11 @@ var IPython = (function (IPython) { var cell = this.get_cell(index); cell.select(); if (cell.cell_type === 'heading') { - $([IPython.events]).trigger('selected_cell_type_changed.Notebook', + this.events.trigger('selected_cell_type_changed.Notebook', {'cell_type':cell.cell_type,level:cell.level} ); } else { - $([IPython.events]).trigger('selected_cell_type_changed.Notebook', + this.events.trigger('selected_cell_type_changed.Notebook', {'cell_type':cell.cell_type} ); } @@ -540,8 +612,8 @@ var IPython = (function (IPython) { if (this.mode !== 'command') { cell.command_mode(); this.mode = 'command'; - $([IPython.events]).trigger('command_mode.Notebook'); - IPython.keyboard_manager.command_mode(); + this.events.trigger('command_mode.Notebook'); + this.keyboard_manager.command_mode(); } }; @@ -570,8 +642,8 @@ var IPython = (function (IPython) { if (cell && this.mode !== 'edit') { cell.edit_mode(); this.mode = 'edit'; - $([IPython.events]).trigger('edit_mode.Notebook'); - IPython.keyboard_manager.edit_mode(); + this.events.trigger('edit_mode.Notebook'); + this.keyboard_manager.edit_mode(); } }; @@ -686,7 +758,7 @@ var IPython = (function (IPython) { this.undelete_index = i; this.undelete_below = false; } - $([IPython.events]).trigger('delete.Cell', {'cell': cell, 'index': i}); + this.events.trigger('delete.Cell', {'cell': cell, 'index': i}); this.set_dirty(true); } return this; @@ -753,20 +825,27 @@ var IPython = (function (IPython) { type = type || this.get_selected_cell().cell_type; if (ncells === 0 || this.is_valid_cell_index(index) || index === ncells) { + var cell_options = { + events: this.events, + config: this.config, + keyboard_manager: this.keyboard_manager, + notebook: this, + tooltip: this.tooltip, + }; if (type === 'code') { - cell = new IPython.CodeCell(this.kernel); + cell = new codecell.CodeCell(this.kernel, cell_options); cell.set_input_prompt(); } else if (type === 'markdown') { - cell = new IPython.MarkdownCell(); + cell = new textcell.MarkdownCell(cell_options); } else if (type === 'raw') { - cell = new IPython.RawCell(); + cell = new textcell.RawCell(cell_options); } else if (type === 'heading') { - cell = new IPython.HeadingCell(); + cell = new textcell.HeadingCell(cell_options); } if(this._insert_element_at_index(cell.element,index)) { cell.render(); - $([IPython.events]).trigger('create.Cell', {'cell': cell, 'index': index}); + this.events.trigger('create.Cell', {'cell': cell, 'index': index}); cell.refresh(); // We used to select the cell after we refresh it, but there // are now cases were this method is called where select is @@ -876,7 +955,7 @@ var IPython = (function (IPython) { if (this.is_valid_cell_index(i)) { var source_element = this.get_cell_element(i); var source_cell = source_element.data("cell"); - if (!(source_cell instanceof IPython.CodeCell)) { + if (!(source_cell instanceof codecell.CodeCell)) { var target_cell = this.insert_cell_below('code',i); var text = source_cell.get_text(); if (text === source_cell.placeholder) { @@ -906,7 +985,7 @@ var IPython = (function (IPython) { if (this.is_valid_cell_index(i)) { var source_element = this.get_cell_element(i); var source_cell = source_element.data("cell"); - if (!(source_cell instanceof IPython.MarkdownCell)) { + if (!(source_cell instanceof textcell.MarkdownCell)) { var target_cell = this.insert_cell_below('markdown',i); var text = source_cell.get_text(); if (text === source_cell.placeholder) { @@ -920,7 +999,7 @@ var IPython = (function (IPython) { target_cell.code_mirror.clearHistory(); source_element.remove(); this.select(i); - if ((source_cell instanceof IPython.TextCell) && source_cell.rendered) { + if ((source_cell instanceof textcell.TextCell) && source_cell.rendered) { target_cell.render(); } var cursor = source_cell.code_mirror.getCursor(); @@ -942,7 +1021,7 @@ var IPython = (function (IPython) { var source_element = this.get_cell_element(i); var source_cell = source_element.data("cell"); var target_cell = null; - if (!(source_cell instanceof IPython.RawCell)) { + if (!(source_cell instanceof textcell.RawCell)) { target_cell = this.insert_cell_below('raw',i); var text = source_cell.get_text(); if (text === source_cell.placeholder) { @@ -977,7 +1056,7 @@ var IPython = (function (IPython) { var source_element = this.get_cell_element(i); var source_cell = source_element.data("cell"); var target_cell = null; - if (source_cell instanceof IPython.HeadingCell) { + if (source_cell instanceof textcell.HeadingCell) { source_cell.set_level(level); } else { target_cell = this.insert_cell_below('heading',i); @@ -996,12 +1075,12 @@ var IPython = (function (IPython) { this.select(i); var cursor = source_cell.code_mirror.getCursor(); target_cell.code_mirror.setCursor(cursor); - if ((source_cell instanceof IPython.TextCell) && source_cell.rendered) { + if ((source_cell instanceof textcell.TextCell) && source_cell.rendered) { target_cell.render(); } } this.set_dirty(true); - $([IPython.events]).trigger('selected_cell_type_changed.Notebook', + this.events.trigger('selected_cell_type_changed.Notebook', {'cell_type':'heading',level:level} ); } @@ -1115,13 +1194,13 @@ var IPython = (function (IPython) { * @method split_cell */ Notebook.prototype.split_cell = function () { - var mdc = IPython.MarkdownCell; - var rc = IPython.RawCell; + var mdc = textcell.MarkdownCell; + var rc = textcell.RawCell; var cell = this.get_selected_cell(); if (cell.is_splittable()) { var texta = cell.get_pre_cursor(); var textb = cell.get_post_cursor(); - if (cell instanceof IPython.CodeCell) { + if (cell instanceof codecell.CodeCell) { // In this case the operations keep the notebook in its existing mode // so we don't need to do any post-op mode changes. cell.set_text(textb); @@ -1144,8 +1223,8 @@ var IPython = (function (IPython) { * @method merge_cell_above */ Notebook.prototype.merge_cell_above = function () { - var mdc = IPython.MarkdownCell; - var rc = IPython.RawCell; + var mdc = textcell.MarkdownCell; + var rc = textcell.RawCell; var index = this.get_selected_index(); var cell = this.get_cell(index); var render = cell.rendered; @@ -1159,7 +1238,7 @@ var IPython = (function (IPython) { } var upper_text = upper_cell.get_text(); var text = cell.get_text(); - if (cell instanceof IPython.CodeCell) { + if (cell instanceof codecell.CodeCell) { cell.set_text(upper_text+'\n'+text); } else if ((cell instanceof mdc) || (cell instanceof rc)) { cell.unrender(); // Must unrender before we set_text. @@ -1181,8 +1260,8 @@ var IPython = (function (IPython) { * @method merge_cell_below */ Notebook.prototype.merge_cell_below = function () { - var mdc = IPython.MarkdownCell; - var rc = IPython.RawCell; + var mdc = textcell.MarkdownCell; + var rc = textcell.RawCell; var index = this.get_selected_index(); var cell = this.get_cell(index); var render = cell.rendered; @@ -1196,7 +1275,7 @@ var IPython = (function (IPython) { } var lower_text = lower_cell.get_text(); var text = cell.get_text(); - if (cell instanceof IPython.CodeCell) { + if (cell instanceof codecell.CodeCell) { cell.set_text(text+'\n'+lower_text); } else if ((cell instanceof mdc) || (cell instanceof rc)) { cell.unrender(); // Must unrender before we set_text. @@ -1224,7 +1303,7 @@ var IPython = (function (IPython) { Notebook.prototype.collapse_output = function (index) { var i = this.index_or_selected(index); var cell = this.get_cell(i); - if (cell !== null && (cell instanceof IPython.CodeCell)) { + if (cell !== null && (cell instanceof codecell.CodeCell)) { cell.collapse_output(); this.set_dirty(true); } @@ -1237,7 +1316,7 @@ var IPython = (function (IPython) { */ Notebook.prototype.collapse_all_output = function () { $.map(this.get_cells(), function (cell, i) { - if (cell instanceof IPython.CodeCell) { + if (cell instanceof codecell.CodeCell) { cell.collapse_output(); } }); @@ -1254,7 +1333,7 @@ var IPython = (function (IPython) { Notebook.prototype.expand_output = function (index) { var i = this.index_or_selected(index); var cell = this.get_cell(i); - if (cell !== null && (cell instanceof IPython.CodeCell)) { + if (cell !== null && (cell instanceof codecell.CodeCell)) { cell.expand_output(); this.set_dirty(true); } @@ -1267,7 +1346,7 @@ var IPython = (function (IPython) { */ Notebook.prototype.expand_all_output = function () { $.map(this.get_cells(), function (cell, i) { - if (cell instanceof IPython.CodeCell) { + if (cell instanceof codecell.CodeCell) { cell.expand_output(); } }); @@ -1284,7 +1363,7 @@ var IPython = (function (IPython) { Notebook.prototype.clear_output = function (index) { var i = this.index_or_selected(index); var cell = this.get_cell(i); - if (cell !== null && (cell instanceof IPython.CodeCell)) { + if (cell !== null && (cell instanceof codecell.CodeCell)) { cell.clear_output(); this.set_dirty(true); } @@ -1297,7 +1376,7 @@ var IPython = (function (IPython) { */ Notebook.prototype.clear_all_output = function () { $.map(this.get_cells(), function (cell, i) { - if (cell instanceof IPython.CodeCell) { + if (cell instanceof codecell.CodeCell) { cell.clear_output(); } }); @@ -1313,7 +1392,7 @@ var IPython = (function (IPython) { Notebook.prototype.scroll_output = function (index) { var i = this.index_or_selected(index); var cell = this.get_cell(i); - if (cell !== null && (cell instanceof IPython.CodeCell)) { + if (cell !== null && (cell instanceof codecell.CodeCell)) { cell.scroll_output(); this.set_dirty(true); } @@ -1326,7 +1405,7 @@ var IPython = (function (IPython) { */ Notebook.prototype.scroll_all_output = function () { $.map(this.get_cells(), function (cell, i) { - if (cell instanceof IPython.CodeCell) { + if (cell instanceof codecell.CodeCell) { cell.scroll_output(); } }); @@ -1342,7 +1421,7 @@ var IPython = (function (IPython) { Notebook.prototype.toggle_output = function (index) { var i = this.index_or_selected(index); var cell = this.get_cell(i); - if (cell !== null && (cell instanceof IPython.CodeCell)) { + if (cell !== null && (cell instanceof codecell.CodeCell)) { cell.toggle_output(); this.set_dirty(true); } @@ -1355,7 +1434,7 @@ var IPython = (function (IPython) { */ Notebook.prototype.toggle_all_output = function () { $.map(this.get_cells(), function (cell, i) { - if (cell instanceof IPython.CodeCell) { + if (cell instanceof codecell.CodeCell) { cell.toggle_output(); } }); @@ -1372,7 +1451,7 @@ var IPython = (function (IPython) { Notebook.prototype.toggle_output_scroll = function (index) { var i = this.index_or_selected(index); var cell = this.get_cell(i); - if (cell !== null && (cell instanceof IPython.CodeCell)) { + if (cell !== null && (cell instanceof codecell.CodeCell)) { cell.toggle_output_scroll(); this.set_dirty(true); } @@ -1385,7 +1464,7 @@ var IPython = (function (IPython) { */ Notebook.prototype.toggle_all_output_scroll = function () { $.map(this.get_cells(), function (cell, i) { - if (cell instanceof IPython.CodeCell) { + if (cell instanceof codecell.CodeCell) { cell.toggle_output_scroll(); } }); @@ -1412,7 +1491,11 @@ var IPython = (function (IPython) { * @method start_session */ Notebook.prototype.start_session = function () { - this.session = new IPython.Session(this, this.options); + this.session = new session.Session({ + base_url: this.base_url, + notebook_path: this.notebook_path, + notebook_name: this.notebook_name, + notebook: this}); this.session.start($.proxy(this._session_started, this)); }; @@ -1427,7 +1510,7 @@ var IPython = (function (IPython) { var ncells = this.ncells(); for (var i=0; i").text( 'Do you want to restart the current kernel? You will lose all variables defined in it.' @@ -1660,10 +1745,12 @@ var IPython = (function (IPython) { } if (trusted != this.trusted) { this.trusted = trusted; - $([IPython.events]).trigger("trust_changed.Notebook", trusted); + this.events.trigger("trust_changed.Notebook", trusted); } if (content.worksheets.length > 1) { - IPython.dialog.modal({ + dialog.modal({ + notebook: this, + keyboard_manager: this.keyboard_manager, title : "Multiple worksheets", body : "This notebook has " + data.worksheets.length + " worksheets, " + "but this version of IPython can only handle the first. " + @@ -1705,7 +1792,7 @@ var IPython = (function (IPython) { }; if (trusted != this.trusted) { this.trusted = trusted; - $([IPython.events]).trigger("trust_changed.Notebook", trusted); + this.events.trigger("trust_changed.Notebook", trusted); } return data; }; @@ -1730,10 +1817,10 @@ var IPython = (function (IPython) { that.save_notebook(); } }, interval); - $([IPython.events]).trigger("autosave_enabled.Notebook", interval); + this.events.trigger("autosave_enabled.Notebook", interval); } else { this.autosave_timer = null; - $([IPython.events]).trigger("autosave_disabled.Notebook"); + this.events.trigger("autosave_disabled.Notebook"); } }; @@ -1768,7 +1855,7 @@ var IPython = (function (IPython) { settings[key] = extra_settings[key]; } } - $([IPython.events]).trigger('notebook_saving.Notebook'); + this.events.trigger('notebook_saving.Notebook'); var url = utils.url_join_encode( this.base_url, 'api/notebooks', @@ -1789,7 +1876,7 @@ var IPython = (function (IPython) { */ Notebook.prototype.save_notebook_success = function (start, data, status, xhr) { this.set_dirty(false); - $([IPython.events]).trigger('notebook_saved.Notebook'); + this.events.trigger('notebook_saved.Notebook'); this._update_autosave_interval(start); if (this._checkpoint_after_save) { this.create_checkpoint(); @@ -1826,7 +1913,7 @@ var IPython = (function (IPython) { * @param {String} error HTTP error message */ Notebook.prototype.save_notebook_error = function (xhr, status, error) { - $([IPython.events]).trigger('notebook_save_failed.Notebook', [xhr, status, error]); + this.events.trigger('notebook_save_failed.Notebook', [xhr, status, error]); }; /** @@ -1851,7 +1938,9 @@ var IPython = (function (IPython) { ); var nb = this; - IPython.dialog.modal({ + dialog.modal({ + notebook: this, + keyboard_manager: this.keyboard_manager, title: "Trust this notebook?", body: body, @@ -1867,7 +1956,7 @@ var IPython = (function (IPython) { cell.output_area.trusted = true; } } - $([IPython.events]).on('notebook_saved.Notebook', function () { + this.events.on('notebook_saved.Notebook', function () { window.location.reload(); }); nb.save_notebook(); @@ -1953,7 +2042,7 @@ var IPython = (function (IPython) { success : $.proxy(that.rename_success, this), error : $.proxy(that.rename_error, this) }; - $([IPython.events]).trigger('rename_notebook.Notebook', data); + this.events.trigger('rename_notebook.Notebook', data); var url = utils.url_join_encode( this.base_url, 'api/notebooks', @@ -1986,32 +2075,34 @@ var IPython = (function (IPython) { var name = this.notebook_name = json.name; var path = json.path; this.session.rename_notebook(name, path); - $([IPython.events]).trigger('notebook_renamed.Notebook', json); + this.events.trigger('notebook_renamed.Notebook', json); }; Notebook.prototype.rename_error = function (xhr, status, error) { var that = this; - var dialog = $('').append( + var dialog_body = $('').append( $("").addClass("rename-message") .text('This notebook name already exists.') ); - $([IPython.events]).trigger('notebook_rename_failed.Notebook', [xhr, status, error]); - IPython.dialog.modal({ + this.events.trigger('notebook_rename_failed.Notebook', [xhr, status, error]); + dialog.modal({ + notebook: this, + keyboard_manager: this.keyboard_manager, title: "Notebook Rename Error!", - body: dialog, + body: dialog_body, buttons : { "Cancel": {}, "OK": { class: "btn-primary", click: function () { - IPython.save_widget.rename_notebook(); + this.save_widget.rename_notebook({notebook:that}); }} }, open : function (event, ui) { var that = $(this); // Upon ENTER, click the OK button. that.find('input[type="text"]').keydown(function (event, ui) { - if (event.which === IPython.keyboard.keycodes.enter) { + if (event.which === this.keyboard.keycodes.enter) { that.find('.btn-primary').first().click(); } }); @@ -2039,7 +2130,7 @@ var IPython = (function (IPython) { success : $.proxy(this.load_notebook_success,this), error : $.proxy(this.load_notebook_error,this), }; - $([IPython.events]).trigger('notebook_loading.Notebook'); + this.events.trigger('notebook_loading.Notebook'); var url = utils.url_join_encode( this.base_url, 'api/notebooks', @@ -2077,7 +2168,9 @@ var IPython = (function (IPython) { "newer notebook format will be used and older versions of IPython " + "may not be able to read it. To keep the older version, close the " + "notebook without saving it."; - IPython.dialog.modal({ + dialog.modal({ + notebook: this, + keyboard_manager: this.keyboard_manager, title : "Notebook converted", body : msg, buttons : { @@ -2094,7 +2187,9 @@ var IPython = (function (IPython) { this_vs + ". You can still work with this notebook, but some features " + "introduced in later notebook versions may not be available."; - IPython.dialog.modal({ + dialog.modal({ + notebook: this, + keyboard_manager: this.keyboard_manager, title : "Newer Notebook", body : msg, buttons : { @@ -2116,15 +2211,15 @@ var IPython = (function (IPython) { // load toolbar state if (this.metadata.celltoolbar) { - IPython.CellToolbar.global_show(); - IPython.CellToolbar.activate_preset(this.metadata.celltoolbar); + celltoolbar.CellToolbar.global_show(); + celltoolbar.CellToolbar.activate_preset(this.metadata.celltoolbar, this.events); } else { - IPython.CellToolbar.global_hide(); + celltoolbar.CellToolbar.global_hide(); } // now that we're fully loaded, it is safe to restore save functionality delete(this.save_notebook); - $([IPython.events]).trigger('notebook_loaded.Notebook'); + this.events.trigger('notebook_loaded.Notebook'); }; /** @@ -2136,7 +2231,7 @@ var IPython = (function (IPython) { * @param {String} error HTTP error message */ Notebook.prototype.load_notebook_error = function (xhr, status, error) { - $([IPython.events]).trigger('notebook_load_failed.Notebook', [xhr, status, error]); + this.events.trigger('notebook_load_failed.Notebook', [xhr, status, error]); var msg; if (xhr.status === 400) { msg = error; @@ -2145,7 +2240,9 @@ var IPython = (function (IPython) { "This version can load notebook formats " + "v" + this.nbformat + " or earlier."; } - IPython.dialog.modal({ + dialog.modal({ + notebook: this, + keyboard_manager: this.keyboard_manager, title: "Error loading notebook", body : msg, buttons : { @@ -2224,7 +2321,7 @@ var IPython = (function (IPython) { } else { this.last_checkpoint = null; } - $([IPython.events]).trigger('checkpoints_listed.Notebook', [data]); + this.events.trigger('checkpoints_listed.Notebook', [data]); }; /** @@ -2236,7 +2333,7 @@ var IPython = (function (IPython) { * @param {String} error_msg HTTP error message */ Notebook.prototype.list_checkpoints_error = function (xhr, status, error_msg) { - $([IPython.events]).trigger('list_checkpoints_failed.Notebook'); + this.events.trigger('list_checkpoints_failed.Notebook'); }; /** @@ -2270,7 +2367,7 @@ var IPython = (function (IPython) { Notebook.prototype.create_checkpoint_success = function (data, status, xhr) { data = $.parseJSON(data); this.add_checkpoint(data); - $([IPython.events]).trigger('checkpoint_created.Notebook', data); + this.events.trigger('checkpoint_created.Notebook', data); }; /** @@ -2282,7 +2379,7 @@ var IPython = (function (IPython) { * @param {String} error_msg HTTP error message */ Notebook.prototype.create_checkpoint_error = function (xhr, status, error_msg) { - $([IPython.events]).trigger('checkpoint_failed.Notebook'); + this.events.trigger('checkpoint_failed.Notebook'); }; Notebook.prototype.restore_checkpoint_dialog = function (checkpoint) { @@ -2309,7 +2406,9 @@ var IPython = (function (IPython) { ).css("text-align", "center") ); - IPython.dialog.modal({ + dialog.modal({ + notebook: this, + keyboard_manager: this.keyboard_manager, title : "Revert notebook to checkpoint", body : body, buttons : { @@ -2331,7 +2430,7 @@ var IPython = (function (IPython) { * @param {String} checkpoint ID */ Notebook.prototype.restore_checkpoint = function (checkpoint) { - $([IPython.events]).trigger('notebook_restoring.Notebook', checkpoint); + this.events.trigger('notebook_restoring.Notebook', checkpoint); var url = utils.url_join_encode( this.base_url, 'api/notebooks', @@ -2356,7 +2455,7 @@ var IPython = (function (IPython) { * @param {jqXHR} xhr jQuery Ajax object */ Notebook.prototype.restore_checkpoint_success = function (data, status, xhr) { - $([IPython.events]).trigger('checkpoint_restored.Notebook'); + this.events.trigger('checkpoint_restored.Notebook'); this.load_notebook(this.notebook_name, this.notebook_path); }; @@ -2369,7 +2468,7 @@ var IPython = (function (IPython) { * @param {String} error_msg HTTP error message */ Notebook.prototype.restore_checkpoint_error = function (xhr, status, error_msg) { - $([IPython.events]).trigger('checkpoint_restore_failed.Notebook'); + this.events.trigger('checkpoint_restore_failed.Notebook'); }; /** @@ -2379,7 +2478,7 @@ var IPython = (function (IPython) { * @param {String} checkpoint ID */ Notebook.prototype.delete_checkpoint = function (checkpoint) { - $([IPython.events]).trigger('notebook_restoring.Notebook', checkpoint); + this.events.trigger('notebook_restoring.Notebook', checkpoint); var url = utils.url_join_encode( this.base_url, 'api/notebooks', @@ -2404,7 +2503,7 @@ var IPython = (function (IPython) { * @param {jqXHR} xhr jQuery Ajax object */ Notebook.prototype.delete_checkpoint_success = function (data, status, xhr) { - $([IPython.events]).trigger('checkpoint_deleted.Notebook', data); + this.events.trigger('checkpoint_deleted.Notebook', data); this.load_notebook(this.notebook_name, this.notebook_path); }; @@ -2417,14 +2516,12 @@ var IPython = (function (IPython) { * @param {String} error_msg HTTP error message */ Notebook.prototype.delete_checkpoint_error = function (xhr, status, error_msg) { - $([IPython.events]).trigger('checkpoint_delete_failed.Notebook'); + this.events.trigger('checkpoint_delete_failed.Notebook'); }; + // For backwards compatability. IPython.Notebook = Notebook; - - return IPython; - -}(IPython)); - + return {'Notebook': Notebook}; +}); diff --git a/IPython/html/static/notebook/js/notificationarea.js b/IPython/html/static/notebook/js/notificationarea.js index a2ecad1dc..0fad72b21 100644 --- a/IPython/html/static/notebook/js/notificationarea.js +++ b/IPython/html/static/notebook/js/notificationarea.js @@ -1,21 +1,30 @@ -//---------------------------------------------------------------------------- -// Copyright (C) 2012 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. -//---------------------------------------------------------------------------- - -//============================================================================ -// Notification widget -//============================================================================ - -var IPython = (function (IPython) { +// Copyright (c) IPython Development Team. +// Distributed under the terms of the Modified BSD License. + +define([ + 'base/js/namespace', + 'jquery', + 'base/js/utils', + 'base/js/dialog', + 'notebook/js/notificationwidget', +], function(IPython, $, utils, dialog, notificationwidget) { "use strict"; - var utils = IPython.utils; - - var NotificationArea = function (selector) { + var NotificationArea = function (selector, options) { + // Constructor + // + // Parameters: + // selector: string + // options: dictionary + // Dictionary of keyword arguments. + // notebook: Notebook instance + // events: $(Events) instance + // save_widget: SaveWidget instance this.selector = selector; + this.events = options.events; + this.save_widget = options.save_widget; + this.notebook = options.notebook; + this.keyboard_manager = options.keyboard_manager; if (this.selector !== undefined) { this.element = $(selector); } @@ -63,23 +72,24 @@ var IPython = (function (IPython) { } var div = $('').attr('id','notification_'+name); $(this.selector).append(div); - this.widget_dict[name] = new IPython.NotificationWidget('#notification_'+name); + this.widget_dict[name] = new notificationwidget.NotificationWidget('#notification_'+name); return this.widget_dict[name]; }; NotificationArea.prototype.init_notification_widgets = function() { + var that = this; var knw = this.new_notification_widget('kernel'); var $kernel_ind_icon = $("#kernel_indicator_icon"); var $modal_ind_icon = $("#modal_indicator_icon"); // Command/Edit mode - $([IPython.events]).on('edit_mode.Notebook',function () { - IPython.save_widget.update_document_title(); + this.events.on('edit_mode.Notebook',function () { + that.save_widget.update_document_title(); $modal_ind_icon.attr('class','edit_mode_icon').attr('title','Edit Mode'); }); - $([IPython.events]).on('command_mode.Notebook',function () { - IPython.save_widget.update_document_title(); + this.events.on('command_mode.Notebook',function () { + that.save_widget.update_document_title(); $modal_ind_icon.attr('class','command_mode_icon').attr('title','Command Mode'); }); @@ -87,22 +97,22 @@ var IPython = (function (IPython) { $modal_ind_icon.attr('class','command-mode_icon').attr('title','Command Mode'); // Kernel events - $([IPython.events]).on('status_idle.Kernel',function () { - IPython.save_widget.update_document_title(); + this.events.on('status_idle.Kernel',function () { + that.save_widget.update_document_title(); $kernel_ind_icon.attr('class','kernel_idle_icon').attr('title','Kernel Idle'); }); - $([IPython.events]).on('status_busy.Kernel',function () { + this.events.on('status_busy.Kernel',function () { window.document.title='(Busy) '+window.document.title; $kernel_ind_icon.attr('class','kernel_busy_icon').attr('title','Kernel Busy'); }); - $([IPython.events]).on('status_restarting.Kernel',function () { - IPython.save_widget.update_document_title(); + this.events.on('status_restarting.Kernel',function () { + that.save_widget.update_document_title(); knw.set_message("Restarting kernel", 2000); }); - $([IPython.events]).on('status_interrupting.Kernel',function () { + this.events.on('status_interrupting.Kernel',function () { knw.set_message("Interrupting kernel", 2000); }); @@ -110,28 +120,30 @@ var IPython = (function (IPython) { // When the kernel_info reply arrives, the kernel is idle. $kernel_ind_icon.attr('class','kernel_busy_icon').attr('title','Kernel Busy'); - $([IPython.events]).on('status_started.Kernel', function (evt, data) { + this.events.on('status_started.Kernel', function (evt, data) { data.kernel.kernel_info(function () { - $([IPython.events]).trigger('status_idle.Kernel'); + that.events.trigger('status_idle.Kernel'); }); }); - $([IPython.events]).on('status_dead.Kernel',function () { + this.events.on('status_dead.Kernel',function () { var msg = 'The kernel has died, and the automatic restart has failed.' + ' It is possible the kernel cannot be restarted.' + ' If you are not able to restart the kernel, you will still be able to save' + ' the notebook, but running code will no longer work until the notebook' + ' is reopened.'; - IPython.dialog.modal({ + dialog.modal({ title: "Dead kernel", body : msg, + keyboard_manager: that.keyboard_manager, + notebook: that.notebook, buttons : { "Manual Restart": { class: "btn-danger", click: function () { - $([IPython.events]).trigger('status_restarting.Kernel'); - IPython.notebook.start_kernel(); + that.events.trigger('status_restarting.Kernel'); + that.notebook.start_kernel(); } }, "Don't restart": {} @@ -139,7 +151,7 @@ var IPython = (function (IPython) { }); }); - $([IPython.events]).on('websocket_closed.Kernel', function (event, data) { + this.events.on('websocket_closed.Kernel', function (event, data) { var kernel = data.kernel; var ws_url = data.ws_url; var early = data.early; @@ -155,9 +167,11 @@ var IPython = (function (IPython) { msg = "A WebSocket connection could not be established." + " You will NOT be able to run code. Check your" + " network connection or notebook server configuration."; - IPython.dialog.modal({ + dialog.modal({ title: "WebSocket connection failed", body: msg, + keyboard_manager: that.keyboard_manager, + notebook: that.notebook, buttons : { "OK": {}, "Reconnect": { @@ -176,24 +190,24 @@ var IPython = (function (IPython) { var nnw = this.new_notification_widget('notebook'); // Notebook events - $([IPython.events]).on('notebook_loading.Notebook', function () { + this.events.on('notebook_loading.Notebook', function () { nnw.set_message("Loading notebook",500); }); - $([IPython.events]).on('notebook_loaded.Notebook', function () { + this.events.on('notebook_loaded.Notebook', function () { nnw.set_message("Notebook loaded",500); }); - $([IPython.events]).on('notebook_saving.Notebook', function () { + this.events.on('notebook_saving.Notebook', function () { nnw.set_message("Saving notebook",500); }); - $([IPython.events]).on('notebook_saved.Notebook', function () { + this.events.on('notebook_saved.Notebook', function () { nnw.set_message("Notebook saved",2000); }); - $([IPython.events]).on('notebook_save_failed.Notebook', function (evt, xhr, status, data) { + this.events.on('notebook_save_failed.Notebook', function (evt, xhr, status, data) { nnw.set_message(data || "Notebook save failed"); }); // Checkpoint events - $([IPython.events]).on('checkpoint_created.Notebook', function (evt, data) { + this.events.on('checkpoint_created.Notebook', function (evt, data) { var msg = "Checkpoint created"; if (data.last_modified) { var d = new Date(data.last_modified); @@ -201,27 +215,27 @@ var IPython = (function (IPython) { } nnw.set_message(msg, 2000); }); - $([IPython.events]).on('checkpoint_failed.Notebook', function () { + this.events.on('checkpoint_failed.Notebook', function () { nnw.set_message("Checkpoint failed"); }); - $([IPython.events]).on('checkpoint_deleted.Notebook', function () { + this.events.on('checkpoint_deleted.Notebook', function () { nnw.set_message("Checkpoint deleted", 500); }); - $([IPython.events]).on('checkpoint_delete_failed.Notebook', function () { + this.events.on('checkpoint_delete_failed.Notebook', function () { nnw.set_message("Checkpoint delete failed"); }); - $([IPython.events]).on('checkpoint_restoring.Notebook', function () { + this.events.on('checkpoint_restoring.Notebook', function () { nnw.set_message("Restoring to checkpoint...", 500); }); - $([IPython.events]).on('checkpoint_restore_failed.Notebook', function () { + this.events.on('checkpoint_restore_failed.Notebook', function () { nnw.set_message("Checkpoint restore failed"); }); // Autosave events - $([IPython.events]).on('autosave_disabled.Notebook', function () { + this.events.on('autosave_disabled.Notebook', function () { nnw.set_message("Autosave disabled", 2000); }); - $([IPython.events]).on('autosave_enabled.Notebook', function (evt, interval) { + this.events.on('autosave_enabled.Notebook', function (evt, interval) { nnw.set_message("Saving every " + interval / 1000 + "s", 1000); }); @@ -229,7 +243,5 @@ var IPython = (function (IPython) { IPython.NotificationArea = NotificationArea; - return IPython; - -}(IPython)); - + return {'NotificationArea': NotificationArea}; +}); diff --git a/IPython/html/static/notebook/js/notificationwidget.js b/IPython/html/static/notebook/js/notificationwidget.js index 51764ea84..51c40e7fa 100644 --- a/IPython/html/static/notebook/js/notificationwidget.js +++ b/IPython/html/static/notebook/js/notificationwidget.js @@ -1,18 +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. -//============================================================================ -// Notification widget -//============================================================================ - -var IPython = (function (IPython) { +define([ + 'base/js/namespace', + 'jquery', +], function(IPython, $) { "use strict"; - var utils = IPython.utils; - var NotificationWidget = function (selector) { this.selector = selector; @@ -31,7 +24,6 @@ var IPython = (function (IPython) { }; - NotificationWidget.prototype.style = function () { this.element.addClass('notification_widget pull-right'); this.element.addClass('border-box-sizing'); @@ -43,12 +35,12 @@ var IPython = (function (IPython) { // if timeout <= 0 // click_callback : function called if user click on notification // could return false to prevent the notification to be dismissed - NotificationWidget.prototype.set_message = function (msg, timeout, click_callback, opts) { - var opts = opts || {}; + NotificationWidget.prototype.set_message = function (msg, timeout, click_callback, options) { + options = options || {}; var callback = click_callback || function() {return false;}; var that = this; - this.inner.attr('class', opts.icon); - this.inner.attr('title', opts.title); + this.inner.attr('class', options.icon); + this.inner.attr('title', options.title); this.inner.text(msg); this.element.fadeIn(100); if (this.timeout !== null) { @@ -62,7 +54,7 @@ var IPython = (function (IPython) { }, timeout); } else { this.element.click(function() { - if( callback() != false ) { + if( callback() !== false ) { that.element.fadeOut(100, function () {that.inner.text('');}); that.element.unbind('click'); } @@ -74,15 +66,12 @@ var IPython = (function (IPython) { } }; - NotificationWidget.prototype.get_message = function () { return this.inner.html(); }; - + // For backwards compatability. IPython.NotificationWidget = NotificationWidget; - return IPython; - -}(IPython)); - + return {'NotificationWidget': NotificationWidget}; +}); diff --git a/IPython/html/static/notebook/js/outputarea.js b/IPython/html/static/notebook/js/outputarea.js index 6aef5f988..65b9641af 100644 --- a/IPython/html/static/notebook/js/outputarea.js +++ b/IPython/html/static/notebook/js/outputarea.js @@ -1,38 +1,36 @@ // Copyright (c) IPython Development Team. // Distributed under the terms of the Modified BSD License. -//============================================================================ -// OutputArea -//============================================================================ - -/** - * @module IPython - * @namespace IPython - * @submodule OutputArea - */ -var IPython = (function (IPython) { +define([ + 'base/js/namespace', + 'jqueryui', + 'base/js/utils', + 'base/js/security', + 'base/js/keyboard', + 'notebook/js/mathjaxutils', +], function(IPython, $, utils, security, keyboard, mathjaxutils) { "use strict"; - var utils = IPython.utils; - /** * @class OutputArea * * @constructor */ - var OutputArea = function (selector, prompt_area) { - this.selector = selector; - this.wrapper = $(selector); + var OutputArea = function (options) { + this.selector = options.selector; + this.events = options.events; + this.keyboard_manager = options.keyboard_manager; + this.wrapper = $(options.selector); this.outputs = []; this.collapsed = false; this.scrolled = false; this.trusted = true; this.clear_queued = null; - if (prompt_area === undefined) { + if (options.prompt_area === undefined) { this.prompt_area = true; } else { - this.prompt_area = prompt_area; + this.prompt_area = options.prompt_area; } this.create_elements(); this.style(); @@ -101,7 +99,7 @@ var IPython = (function (IPython) { this.element.resize(function () { // FIXME: Firefox on Linux misbehaves, so automatic scrolling is disabled - if ( IPython.utils.browser[0] === "Firefox" ) { + if ( utils.browser[0] === "Firefox" ) { return; } // maybe scroll output, @@ -515,7 +513,7 @@ var IPython = (function (IPython) { if (!this.trusted && !OutputArea.safe_outputs[type]) { // not trusted, sanitize HTML if (type==='text/html' || type==='text/svg') { - value = IPython.security.sanitize_html(value); + value = security.sanitize_html(value); } else { // don't display if we don't know how to sanitize it console.log("Ignoring untrusted " + type + " output."); @@ -531,7 +529,7 @@ var IPython = (function (IPython) { if (['image/png', 'image/jpeg'].indexOf(type) < 0 && handle_inserted !== undefined) { setTimeout(handle_inserted, 0); } - $([IPython.events]).trigger('output_appended.OutputArea', [type, value, md, toinsert]); + this.events.trigger('output_appended.OutputArea', [type, value, md, toinsert]); return toinsert; } } @@ -542,7 +540,7 @@ var IPython = (function (IPython) { var append_html = function (html, md, element) { var type = 'text/html'; var toinsert = this.create_output_subarea(md, "output_html rendered_html", type); - IPython.keyboard_manager.register_events(toinsert); + this.keyboard_manager.register_events(toinsert); toinsert.append(html); element.append(toinsert); return toinsert; @@ -552,11 +550,11 @@ var IPython = (function (IPython) { var append_markdown = function(markdown, md, element) { var type = 'text/markdown'; var toinsert = this.create_output_subarea(md, "output_markdown", type); - var text_and_math = IPython.mathjaxutils.remove_math(markdown); + var text_and_math = mathjaxutils.remove_math(markdown); var text = text_and_math[0]; var math = text_and_math[1]; var html = marked.parser(marked.lexer(text)); - html = IPython.mathjaxutils.replace_math(html, math); + html = mathjaxutils.replace_math(html, math); toinsert.append(html); element.append(toinsert); return toinsert; @@ -567,7 +565,7 @@ var IPython = (function (IPython) { // We just eval the JS code, element appears in the local scope. var type = 'application/javascript'; var toinsert = this.create_output_subarea(md, "output_javascript", type); - IPython.keyboard_manager.register_events(toinsert); + this.keyboard_manager.register_events(toinsert); element.append(toinsert); // Fix for ipython/issues/5293, make sure `element` is the area which @@ -758,7 +756,7 @@ var IPython = (function (IPython) { .keydown(function (event, ui) { // make sure we submit on enter, // and don't re-execute the *cell* on shift-enter - if (event.which === IPython.keyboard.keycodes.enter) { + if (event.which === keyboard.keycodes.enter) { that._submit_raw_input(); return false; } @@ -770,7 +768,7 @@ var IPython = (function (IPython) { var raw_input = area.find('input.raw_input'); // Register events that enable/disable the keyboard manager while raw // input is focused. - IPython.keyboard_manager.register_events(raw_input); + this.keyboard_manager.register_events(raw_input); // Note, the following line used to read raw_input.focus().focus(). // This seemed to be needed otherwise only the cell would be focused. // But with the modal UI, this seems to work fine with one call to focus(). @@ -796,7 +794,7 @@ var IPython = (function (IPython) { container.parent().remove(); // replace with plaintext version in stdout this.append_output(content, false); - $([IPython.events]).trigger('send_input_reply.Kernel', value); + this.events.trigger('send_input_reply.Kernel', value); } @@ -987,8 +985,8 @@ var IPython = (function (IPython) { "application/pdf" : append_pdf }; + // For backwards compatability. IPython.OutputArea = OutputArea; - return IPython; - -}(IPython)); + return {'OutputArea': OutputArea}; +}); diff --git a/IPython/html/static/notebook/js/pager.js b/IPython/html/static/notebook/js/pager.js index dd4ead8c4..2c40f37b1 100644 --- a/IPython/html/static/notebook/js/pager.js +++ b/IPython/html/static/notebook/js/pager.js @@ -1,20 +1,29 @@ // Copyright (c) IPython Development Team. // Distributed under the terms of the Modified BSD License. -//============================================================================ -// Pager -//============================================================================ - -var IPython = (function (IPython) { +define([ + 'base/js/namespace', + 'jqueryui', + 'base/js/utils', +], function(IPython, $, utils) { "use strict"; - var utils = IPython.utils; - - var Pager = function (pager_selector, pager_splitter_selector) { + var Pager = function (pager_selector, pager_splitter_selector, options) { + // Constructor + // + // Parameters: + // pager_selector: string + // pager_splitter_selector: string + // options: dictionary + // Dictionary of keyword arguments. + // events: $(Events) instance + // layout_manager: LayoutManager instance + this.events = options.events; this.pager_element = $(pager_selector); this.pager_button_area = $('#pager_button_area'); var that = this; this.percentage_height = 0.40; + options.layout_manager.pager = this; this.pager_splitter_element = $(pager_splitter_selector) .draggable({ containment: 'window', @@ -23,7 +32,7 @@ var IPython = (function (IPython) { drag: function(event, ui) { // recalculate the amount of space the pager should take var pheight = ($(document.body).height()-event.clientY-4); - var downprct = pheight/IPython.layout_manager.app_height(); + var downprct = pheight/options.layout_manager.app_height(); downprct = Math.min(0.9, downprct); if (downprct < 0.1) { that.percentage_height = 0.1; @@ -32,7 +41,7 @@ var IPython = (function (IPython) { that.percentage_height = downprct; that.expand({'duration':0}); } - IPython.layout_manager.do_resize(); + options.layout_manager.do_resize(); } }); this.expanded = false; @@ -47,22 +56,22 @@ var IPython = (function (IPython) { $('').attr('role', "button") .attr('title',"Open the pager in an external window") .addClass('ui-button') - .click(function(){that.detach()}) + .click(function(){that.detach();}) .attr('style','position: absolute; right: 20px;') .append( $('').addClass("ui-icon ui-icon-extlink") ) - ) + ); this.pager_button_area.append( $('').attr('role', "button") .attr('title',"Close the pager") .addClass('ui-button') - .click(function(){that.collapse()}) + .click(function(){that.collapse();}) .attr('style','position: absolute; right: 5px;') .append( $('').addClass("ui-icon ui-icon-close") ) - ) + ); }; Pager.prototype.style = function () { @@ -105,7 +114,7 @@ var IPython = (function (IPython) { that.toggle(); }); - $([IPython.events]).on('open_with_text.Pager', function (event, payload) { + this.events.on('open_with_text.Pager', function (event, payload) { // FIXME: support other mime types if (payload.data['text/plain'] && payload.data['text/plain'] !== "") { that.clear(); @@ -171,10 +180,8 @@ var IPython = (function (IPython) { this.pager_element.find(".container").append($('').html(utils.fixCarriageReturn(utils.fixConsole(text)))); }; - + // Backwards compatability. IPython.Pager = Pager; - return IPython; - -}(IPython)); - + return {'Pager': Pager}; +}); diff --git a/IPython/html/static/notebook/js/quickhelp.js b/IPython/html/static/notebook/js/quickhelp.js index 1b80698ce..4bc179a48 100644 --- a/IPython/html/static/notebook/js/quickhelp.js +++ b/IPython/html/static/notebook/js/quickhelp.js @@ -1,16 +1,28 @@ // Copyright (c) IPython Development Team. // Distributed under the terms of the Modified BSD License. -//============================================================================ -// QuickHelp button -//============================================================================ - -var IPython = (function (IPython) { +define([ + 'base/js/namespace', + 'jquery', + 'base/js/utils', + 'base/js/dialog', +], function(IPython, $, utils, dialog) { "use strict"; - - var platform = IPython.utils.platform; - - var QuickHelp = function (selector) { + var platform = utils.platform; + + var QuickHelp = function (options) { + // Constructor + // + // Parameters: + // options: dictionary + // Dictionary of keyword arguments. + // events: $(Events) instance + // keyboard_manager: KeyboardManager instance + // notebook: Notebook instance + this.keyboard_manager = options.keyboard_manager; + this.notebook = options.notebook; + this.keyboard_manager.quick_help = this; + this.events = options.events; }; var cmd_ctrl = 'Ctrl-'; @@ -70,8 +82,8 @@ var IPython = (function (IPython) { $(this.shortcut_dialog).modal("toggle"); return; } - var command_shortcuts = IPython.keyboard_manager.command_shortcuts.help(); - var edit_shortcuts = IPython.keyboard_manager.edit_shortcuts.help(); + var command_shortcuts = this.keyboard_manager.command_shortcuts.help(); + var edit_shortcuts = this.keyboard_manager.edit_shortcuts.help(); var help, shortcut; var i, half, n; var element = $(''); @@ -96,21 +108,23 @@ var IPython = (function (IPython) { var edit_div = this.build_edit_help(cm_shortcuts); element.append(edit_div); - this.shortcut_dialog = IPython.dialog.modal({ + this.shortcut_dialog = dialog.modal({ title : "Keyboard shortcuts", body : element, destroy : false, buttons : { Close : {} - } + }, + notebook: this.notebook, + keyboard_manager: this.keyboard_manager, }); this.shortcut_dialog.addClass("modal_stretch"); - $([IPython.events]).on('rebuild.QuickHelp', function() { that.force_rebuild = true;}); + this.events.on('rebuild.QuickHelp', function() { that.force_rebuild = true;}); }; QuickHelp.prototype.build_command_help = function () { - var command_shortcuts = IPython.keyboard_manager.command_shortcuts.help(); + var command_shortcuts = this.keyboard_manager.command_shortcuts.help(); return build_div(' Command Mode (press
', command_shortcuts); }; @@ -134,7 +148,7 @@ var IPython = (function (IPython) { }; QuickHelp.prototype.build_edit_help = function (cm_shortcuts) { - var edit_shortcuts = IPython.keyboard_manager.edit_shortcuts.help(); + var edit_shortcuts = this.keyboard_manager.edit_shortcuts.help(); jQuery.merge(cm_shortcuts, edit_shortcuts); return build_div('Escto enable)Edit Mode (press
', cm_shortcuts); }; @@ -163,9 +177,8 @@ var IPython = (function (IPython) { return div; }; - // Set module variables + // Backwards compatability. IPython.QuickHelp = QuickHelp; - return IPython; - -}(IPython)); + return {'QuickHelp': QuickHelp}; +}); diff --git a/IPython/html/static/notebook/js/savewidget.js b/IPython/html/static/notebook/js/savewidget.js index 119314e64..b57abd855 100644 --- a/IPython/html/static/notebook/js/savewidget.js +++ b/IPython/html/static/notebook/js/savewidget.js @@ -1,21 +1,22 @@ -//---------------------------------------------------------------------------- -// 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. -//---------------------------------------------------------------------------- - -//============================================================================ -// SaveWidget -//============================================================================ - -var IPython = (function (IPython) { +// Copyright (c) IPython Development Team. +// Distributed under the terms of the Modified BSD License. + +define([ + 'base/js/namespace', + 'jquery', + 'base/js/utils', + 'base/js/dialog', + 'base/js/keyboard', + 'dateformat', +], function(IPython, $, utils, dialog, keyboard) { "use strict"; - var utils = IPython.utils; - - var SaveWidget = function (selector) { + var SaveWidget = function (selector, options) { + // TODO: Remove circulat ref. + this.notebook = undefined; this.selector = selector; + this.events = options.events; + this.keyboard_manager = options.keyboard_manager; if (this.selector !== undefined) { this.element = $(selector); this.style(); @@ -23,7 +24,6 @@ var IPython = (function (IPython) { } }; - SaveWidget.prototype.style = function () { }; @@ -38,56 +38,59 @@ var IPython = (function (IPython) { }, function () { $(this).removeClass("ui-state-hover"); }); - $([IPython.events]).on('notebook_loaded.Notebook', function () { + this.events.on('notebook_loaded.Notebook', function () { that.update_notebook_name(); that.update_document_title(); }); - $([IPython.events]).on('notebook_saved.Notebook', function () { + this.events.on('notebook_saved.Notebook', function () { that.update_notebook_name(); that.update_document_title(); }); - $([IPython.events]).on('notebook_renamed.Notebook', function () { + this.events.on('notebook_renamed.Notebook', function () { that.update_notebook_name(); that.update_document_title(); that.update_address_bar(); }); - $([IPython.events]).on('notebook_save_failed.Notebook', function () { + this.events.on('notebook_save_failed.Notebook', function () { that.set_save_status('Autosave Failed!'); }); - $([IPython.events]).on('checkpoints_listed.Notebook', function (event, data) { + this.events.on('checkpoints_listed.Notebook', function (event, data) { that.set_last_checkpoint(data[0]); }); - $([IPython.events]).on('checkpoint_created.Notebook', function (event, data) { + this.events.on('checkpoint_created.Notebook', function (event, data) { that.set_last_checkpoint(data); }); - $([IPython.events]).on('set_dirty.Notebook', function (event, data) { + this.events.on('set_dirty.Notebook', function (event, data) { that.set_autosaved(data.value); }); }; - SaveWidget.prototype.rename_notebook = function () { + SaveWidget.prototype.rename_notebook = function (options) { + options = options || {}; var that = this; - var dialog = $('').append( + var dialog_body = $('').append( $("").addClass("rename-message") .text('Enter a new notebook name:') ).append( $("Enterto enable)
") ).append( $('').attr('type','text').attr('size','25').addClass('form-control') - .val(IPython.notebook.get_notebook_name()) + .val(that.notebook.get_notebook_name()) ); - IPython.dialog.modal({ + dialog.modal({ title: "Rename Notebook", - body: dialog, + body: dialog_body, + notebook: options.notebook, + keyboard_manager: this.keyboard_manager, buttons : { "Cancel": {}, "OK": { class: "btn-primary", click: function () { var new_name = $(this).find('input').val(); - if (!IPython.notebook.test_notebook_name(new_name)) { + if (!that.notebook.test_notebook_name(new_name)) { $(this).find('.rename-message').text( "Invalid notebook name. Notebook names must "+ "have 1 or more characters and can contain any characters " + @@ -95,7 +98,7 @@ var IPython = (function (IPython) { ); return false; } else { - IPython.notebook.rename(new_name); + that.notebook.rename(new_name); } }} }, @@ -103,7 +106,7 @@ var IPython = (function (IPython) { var that = $(this); // Upon ENTER, click the OK button. that.find('input[type="text"]').keydown(function (event, ui) { - if (event.which === IPython.keyboard.keycodes.enter) { + if (event.which === keyboard.keycodes.enter) { that.find('.btn-primary').first().click(); return false; } @@ -111,24 +114,24 @@ var IPython = (function (IPython) { that.find('input[type="text"]').focus().select(); } }); - } + }; SaveWidget.prototype.update_notebook_name = function () { - var nbname = IPython.notebook.get_notebook_name(); + var nbname = this.notebook.get_notebook_name(); this.element.find('span#notebook_name').text(nbname); }; SaveWidget.prototype.update_document_title = function () { - var nbname = IPython.notebook.get_notebook_name(); + var nbname = this.notebook.get_notebook_name(); document.title = nbname; }; SaveWidget.prototype.update_address_bar = function(){ - var base_url = IPython.notebook.base_url; - var nbname = IPython.notebook.notebook_name; - var path = IPython.notebook.notebook_path; + var base_url = this.notebook.base_url; + var nbname = this.notebook.notebook_name; + var path = this.notebook.notebook_path; var state = {path : path, name: nbname}; window.history.replaceState(state, "", utils.url_join_encode( base_url, @@ -141,11 +144,11 @@ var IPython = (function (IPython) { SaveWidget.prototype.set_save_status = function (msg) { this.element.find('span#autosave_status').text(msg); - } + }; SaveWidget.prototype.set_checkpoint_status = function (msg) { this.element.find('span#checkpoint_status').text(msg); - } + }; SaveWidget.prototype.set_last_checkpoint = function (checkpoint) { if (!checkpoint) { @@ -156,7 +159,7 @@ var IPython = (function (IPython) { this.set_checkpoint_status( "Last Checkpoint: " + d.format('mmm dd HH:MM') ); - } + }; SaveWidget.prototype.set_autosaved = function (dirty) { if (dirty) { @@ -166,10 +169,9 @@ var IPython = (function (IPython) { } }; - + // Backwards compatability. IPython.SaveWidget = SaveWidget; - return IPython; - -}(IPython)); + return {'SaveWidget': SaveWidget}; +}); diff --git a/IPython/html/static/notebook/js/textcell.js b/IPython/html/static/notebook/js/textcell.js index 0db7af8d9..b99455de0 100644 --- a/IPython/html/static/notebook/js/textcell.js +++ b/IPython/html/static/notebook/js/textcell.js @@ -1,60 +1,57 @@ -//---------------------------------------------------------------------------- -// Copyright (C) 2008-2012 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. -//---------------------------------------------------------------------------- - -//============================================================================ -// TextCell -//============================================================================ - - - -/** - A module that allow to create different type of Text Cell - @module IPython - @namespace IPython - */ -var IPython = (function (IPython) { +// Copyright (c) IPython Development Team. +// Distributed under the terms of the Modified BSD License. + +define([ + 'base/js/namespace', + 'jquery', + 'notebook/js/cell', + 'base/js/security', + 'notebook/js/mathjaxutils', + 'notebook/js/celltoolbar', + 'components/marked/lib/marked', +], function(IPython, $, cell, security, mathjaxutils, celltoolbar, marked) { "use strict"; + var Cell = cell.Cell; - // TextCell base class - var keycodes = IPython.keyboard.keycodes; - var security = IPython.security; - - /** - * Construct a new TextCell, codemirror mode is by default 'htmlmixed', and cell type is 'text' - * cell start as not redered. - * - * @class TextCell - * @constructor TextCell - * @extend IPython.Cell - * @param {object|undefined} [options] - * @param [options.cm_config] {object} config to pass to CodeMirror, will extend/overwrite default config - * @param [options.placeholder] {string} default string to use when souce in empty for rendering (only use in some TextCell subclass) - */ var TextCell = function (options) { + // Constructor + // + // Construct a new TextCell, codemirror mode is by default 'htmlmixed', + // and cell type is 'text' cell start as not redered. + // + // Parameters: + // options: dictionary + // Dictionary of keyword arguments. + // events: $(Events) instance + // config: dictionary + // keyboard_manager: KeyboardManager instance + // notebook: Notebook instance + options = options || {}; + // in all TextCell/Cell subclasses // do not assign most of members here, just pass it down // in the options dict potentially overwriting what you wish. // they will be assigned in the base class. - + this.notebook = options.notebook; + this.events = options.events; + this.config = options.config; + // we cannot put this as a class key as it has handle to "this". var cm_overwrite_options = { onKeyEvent: $.proxy(this.handle_keyevent,this) }; - - options = this.mergeopt(TextCell,options,{cm_config:cm_overwrite_options}); + var config = this.mergeopt(TextCell, this.config, {cm_config:cm_overwrite_options}); + Cell.apply(this, [{ + config: config, + keyboard_manager: options.keyboard_manager, + events: this.events}]); this.cell_type = this.cell_type || 'text'; - - IPython.Cell.apply(this, [options]); - + mathjaxutils = mathjaxutils; this.rendered = false; }; - TextCell.prototype = new IPython.Cell(); + TextCell.prototype = new Cell(); TextCell.options_default = { cm_config : { @@ -71,7 +68,7 @@ var IPython = (function (IPython) { * @private */ TextCell.prototype.create_element = function () { - IPython.Cell.prototype.create_element.apply(this, arguments); + Cell.prototype.create_element.apply(this, arguments); var cell = $("").addClass('cell text_cell border-box-sizing'); cell.attr('tabindex','2'); @@ -79,7 +76,10 @@ var IPython = (function (IPython) { var prompt = $('').addClass('prompt input_prompt'); cell.append(prompt); var inner_cell = $('').addClass('inner_cell'); - this.celltoolbar = new IPython.CellToolbar(this); + this.celltoolbar = new celltoolbar.CellToolbar({ + cell: this, + events: this.events, + notebook: this.notebook}); inner_cell.append(this.celltoolbar.element); var input_area = $('').addClass('input_area'); this.code_mirror = new CodeMirror(input_area.get(0), this.cm_config); @@ -99,12 +99,12 @@ var IPython = (function (IPython) { * @method bind_event */ TextCell.prototype.bind_events = function () { - IPython.Cell.prototype.bind_events.apply(this); + Cell.prototype.bind_events.apply(this); var that = this; this.element.dblclick(function () { if (that.selected === false) { - $([IPython.events]).trigger('select.Cell', {'cell':that}); + this.events.trigger('select.Cell', {'cell':that}); } var cont = that.unrender(); if (cont) { @@ -116,7 +116,7 @@ var IPython = (function (IPython) { // Cell level actions TextCell.prototype.select = function () { - var cont = IPython.Cell.prototype.select.apply(this); + var cont = Cell.prototype.select.apply(this); if (cont) { if (this.mode === 'edit') { this.code_mirror.refresh(); @@ -127,7 +127,7 @@ var IPython = (function (IPython) { TextCell.prototype.unrender = function () { if (this.read_only) return; - var cont = IPython.Cell.prototype.unrender.apply(this); + var cont = Cell.prototype.unrender.apply(this); if (cont) { var text_cell = this.element; var output = text_cell.find("div.text_cell_render"); @@ -170,7 +170,6 @@ var IPython = (function (IPython) { /** * setter :{{#crossLink "TextCell/set_rendered"}}{{/crossLink}} * @method get_rendered - * @return {html} html of rendered element * */ TextCell.prototype.get_rendered = function() { return this.element.find('div.text_cell_render').html(); @@ -191,7 +190,7 @@ var IPython = (function (IPython) { * @method fromJSON */ TextCell.prototype.fromJSON = function (data) { - IPython.Cell.prototype.fromJSON.apply(this, arguments); + Cell.prototype.fromJSON.apply(this, arguments); if (data.cell_type === this.cell_type) { if (data.source !== undefined) { this.set_text(data.source); @@ -211,7 +210,7 @@ var IPython = (function (IPython) { * @return {object} cell data serialised to json */ TextCell.prototype.toJSON = function () { - var data = IPython.Cell.prototype.toJSON.apply(this); + var data = Cell.prototype.toJSON.apply(this); data.source = this.get_text(); if (data.source == this.placeholder) { data.source = ""; @@ -220,16 +219,21 @@ var IPython = (function (IPython) { }; - /** - * @class MarkdownCell - * @constructor MarkdownCell - * @extends IPython.HTMLCell - */ var MarkdownCell = function (options) { - options = this.mergeopt(MarkdownCell, options); + // Constructor + // + // Parameters: + // options: dictionary + // Dictionary of keyword arguments. + // events: $(Events) instance + // config: dictionary + // keyboard_manager: KeyboardManager instance + // notebook: Notebook instance + options = options || {}; + var config = this.mergeopt(MarkdownCell, options.config); + TextCell.apply(this, [$.extend({}, options, {config: config})]); this.cell_type = 'markdown'; - TextCell.apply(this, [options]); }; MarkdownCell.options_default = { @@ -245,16 +249,16 @@ var IPython = (function (IPython) { * @method render */ MarkdownCell.prototype.render = function () { - var cont = IPython.TextCell.prototype.render.apply(this); + var cont = TextCell.prototype.render.apply(this); if (cont) { var text = this.get_text(); var math = null; if (text === "") { text = this.placeholder; } - var text_and_math = IPython.mathjaxutils.remove_math(text); + var text_and_math = mathjaxutils.remove_math(text); text = text_and_math[0]; math = text_and_math[1]; var html = marked.parser(marked.lexer(text)); - html = IPython.mathjaxutils.replace_math(html, math); + html = mathjaxutils.replace_math(html, math); html = security.sanitize_html(html); html = $($.parseHTML(html)); // links in markdown cells should open in new tabs @@ -268,20 +272,23 @@ var IPython = (function (IPython) { }; - // RawCell - - /** - * @class RawCell - * @constructor RawCell - * @extends IPython.TextCell - */ var RawCell = function (options) { + // Constructor + // + // Parameters: + // options: dictionary + // Dictionary of keyword arguments. + // events: $(Events) instance + // config: dictionary + // keyboard_manager: KeyboardManager instance + // notebook: Notebook instance + options = options || {}; + var config = this.mergeopt(RawCell, options.config); + TextCell.apply(this, [$.extend({}, options, {config: config})]); - options = this.mergeopt(RawCell,options); - TextCell.apply(this, [options]); - this.cell_type = 'raw'; // RawCell should always hide its rendered div this.element.find('div.text_cell_render').hide(); + this.cell_type = 'raw'; }; RawCell.options_default = { @@ -309,12 +316,12 @@ var IPython = (function (IPython) { * @method auto_highlight */ RawCell.prototype.auto_highlight = function () { - this._auto_highlight(IPython.config.raw_cell_highlight); + this._auto_highlight(this.config.raw_cell_highlight); }; /** @method render **/ RawCell.prototype.render = function () { - var cont = IPython.TextCell.prototype.render.apply(this); + var cont = TextCell.prototype.render.apply(this); if (cont){ var text = this.get_text(); if (text === "") { text = this.placeholder; } @@ -325,26 +332,22 @@ var IPython = (function (IPython) { }; - /** - * @class HeadingCell - * @extends IPython.TextCell - */ - - /** - * @constructor HeadingCell - * @extends IPython.TextCell - */ var HeadingCell = function (options) { - options = this.mergeopt(HeadingCell, options); + // Constructor + // + // Parameters: + // options: dictionary + // Dictionary of keyword arguments. + // events: $(Events) instance + // config: dictionary + // keyboard_manager: KeyboardManager instance + // notebook: Notebook instance + options = options || {}; + var config = this.mergeopt(HeadingCell, options.config); + TextCell.apply(this, [$.extend({}, options, {config: config})]); this.level = 1; this.cell_type = 'heading'; - TextCell.apply(this, [options]); - - /** - * heading level of the cell, use getter and setter to access - * @property level - */ }; HeadingCell.options_default = { @@ -412,21 +415,20 @@ var IPython = (function (IPython) { return r.children().first().html(); }; - HeadingCell.prototype.render = function () { - var cont = IPython.TextCell.prototype.render.apply(this); + var cont = TextCell.prototype.render.apply(this); if (cont) { var text = this.get_text(); var math = null; // Markdown headings must be a single line text = text.replace(/\n/g, ' '); if (text === "") { text = this.placeholder; } - text = Array(this.level + 1).join("#") + " " + text; - var text_and_math = IPython.mathjaxutils.remove_math(text); + text = new Array(this.level + 1).join("#") + " " + text; + var text_and_math = mathjaxutils.remove_math(text); text = text_and_math[0]; math = text_and_math[1]; var html = marked.parser(marked.lexer(text)); - html = IPython.mathjaxutils.replace_math(html, math); + html = mathjaxutils.replace_math(html, math); html = security.sanitize_html(html); var h = $($.parseHTML(html)); // add id and linkback anchor @@ -446,13 +448,17 @@ var IPython = (function (IPython) { return cont; }; + // Backwards compatability. IPython.TextCell = TextCell; IPython.MarkdownCell = MarkdownCell; IPython.RawCell = RawCell; IPython.HeadingCell = HeadingCell; - - return IPython; - -}(IPython)); - + var textcell = { + 'TextCell': TextCell, + 'MarkdownCell': MarkdownCell, + 'RawCell': RawCell, + 'HeadingCell': HeadingCell, + }; + return textcell; +}); diff --git a/IPython/html/static/notebook/js/toolbar.js b/IPython/html/static/notebook/js/toolbar.js index bf17ae8d0..443475b94 100644 --- a/IPython/html/static/notebook/js/toolbar.js +++ b/IPython/html/static/notebook/js/toolbar.js @@ -1,20 +1,10 @@ -//---------------------------------------------------------------------------- -// Copyright (C) 2008 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. -//============================================================================ -// ToolBar -//============================================================================ -/** - * @module IPython - * @namespace IPython - * @submodule ToolBar - */ - -var IPython = (function (IPython) { +define([ + 'base/js/namespace', + 'jquery', +], function(IPython, $) { "use strict"; /** @@ -23,8 +13,9 @@ var IPython = (function (IPython) { * @constructor * @param {Dom object} selector */ - var ToolBar = function (selector) { + var ToolBar = function (selector, layout_manager) { this.selector = selector; + this.layout_manager = layout_manager; if (this.selector !== undefined) { this.element = $(selector); this.style(); @@ -98,14 +89,13 @@ var IPython = (function (IPython) { */ ToolBar.prototype.toggle = function () { this.element.toggle(); - if (IPython.layout_manager !== undefined) { - IPython.layout_manager.do_resize(); + if (this.layout_manager !== undefined) { + this.layout_manager.do_resize(); } }; - + // Backwards compatability. IPython.ToolBar = ToolBar; - return IPython; - -}(IPython)); + return {'ToolBar': ToolBar}; +}); diff --git a/IPython/html/static/notebook/js/tooltip.js b/IPython/html/static/notebook/js/tooltip.js index 76d1ec049..bec9b418e 100644 --- a/IPython/html/static/notebook/js/tooltip.js +++ b/IPython/html/static/notebook/js/tooltip.js @@ -1,125 +1,115 @@ // Copyright (c) IPython Development Team. // Distributed under the terms of the Modified BSD License. -//============================================================================ -// Tooltip -//============================================================================ -// -// you can set the autocall time by setting `IPython.tooltip.time_before_tooltip` in ms -// -// you can configure the differents action of pressing shift-tab several times in a row by -// setting/appending different fonction in the array -// IPython.tooltip.tabs_functions -// -// eg : -// IPython.tooltip.tabs_functions[4] = function (){console.log('this is the action of the 4th tab pressing')} -// -var IPython = (function (IPython) { +define([ + 'base/js/namespace', + 'jquery', + 'base/js/utils', +], function(IPython, $, utils) { "use strict"; - var utils = IPython.utils; - // tooltip constructor - var Tooltip = function () { - var that = this; - this.time_before_tooltip = 1200; - - // handle to html - this.tooltip = $('#tooltip'); - this._hidden = true; - - // variable for consecutive call - this._old_cell = null; - this._old_request = null; - this._consecutive_counter = 0; - - // 'sticky ?' - this._sticky = false; - - // display tooltip if the docstring is empty? - this._hide_if_no_docstring = false; + var Tooltip = function (events) { + var that = this; + this.events = events; + this.time_before_tooltip = 1200; - // contain the button in the upper right corner - this.buttons = $('').addClass('tooltipbuttons'); + // handle to html + this.tooltip = $('#tooltip'); + this._hidden = true; - // will contain the docstring - this.text = $('').addClass('tooltiptext').addClass('smalltooltip'); + // variable for consecutive call + this._old_cell = null; + this._old_request = null; + this._consecutive_counter = 0; - // build the buttons menu on the upper right - // expand the tooltip to see more - var expandlink = $('').attr('href', "#").addClass("ui-corner-all") //rounded corner - .attr('role', "button").attr('id', 'expanbutton').attr('title', 'Grow the tooltip vertically (press shift-tab twice)').click(function () { - that.expand(); - }).append( - $('').text('Expand').addClass('ui-icon').addClass('ui-icon-plus')); + // 'sticky ?' + this._sticky = false; - // open in pager - var morelink = $('').attr('href', "#").attr('role', "button").addClass('ui-button').attr('title', 'show the current docstring in pager (press shift-tab 4 times)'); - var morespan = $('').text('Open in Pager').addClass('ui-icon').addClass('ui-icon-arrowstop-l-n'); - morelink.append(morespan); - morelink.click(function () { - that.showInPager(that._old_cell); - }); + // display tooltip if the docstring is empty? + this._hide_if_no_docstring = false; + + // contain the button in the upper right corner + this.buttons = $('').addClass('tooltipbuttons'); + + // will contain the docstring + this.text = $('').addClass('tooltiptext').addClass('smalltooltip'); + + // build the buttons menu on the upper right + // expand the tooltip to see more + var expandlink = $('').attr('href', "#").addClass("ui-corner-all") //rounded corner + .attr('role', "button").attr('id', 'expanbutton').attr('title', 'Grow the tooltip vertically (press shift-tab twice)').click(function () { + that.expand(); + }).append( + $('').text('Expand').addClass('ui-icon').addClass('ui-icon-plus')); + + // open in pager + var morelink = $('').attr('href', "#").attr('role', "button").addClass('ui-button').attr('title', 'show the current docstring in pager (press shift-tab 4 times)'); + var morespan = $('').text('Open in Pager').addClass('ui-icon').addClass('ui-icon-arrowstop-l-n'); + morelink.append(morespan); + morelink.click(function () { + that.showInPager(that._old_cell); + }); - // close the tooltip - var closelink = $('').attr('href', "#").attr('role', "button").addClass('ui-button'); - var closespan = $('').text('Close').addClass('ui-icon').addClass('ui-icon-close'); - closelink.append(closespan); - closelink.click(function () { - that.remove_and_cancel_tooltip(true); - }); + // close the tooltip + var closelink = $('').attr('href', "#").attr('role', "button").addClass('ui-button'); + var closespan = $('').text('Close').addClass('ui-icon').addClass('ui-icon-close'); + closelink.append(closespan); + closelink.click(function () { + that.remove_and_cancel_tooltip(true); + }); - this._clocklink = $('').attr('href', "#"); - this._clocklink.attr('role', "button"); - this._clocklink.addClass('ui-button'); - this._clocklink.attr('title', 'Tootip is not dismissed while typing for 10 seconds'); - var clockspan = $('').text('Close'); - clockspan.addClass('ui-icon'); - clockspan.addClass('ui-icon-clock'); - this._clocklink.append(clockspan); - this._clocklink.click(function () { - that.cancel_stick(); - }); + this._clocklink = $('').attr('href', "#"); + this._clocklink.attr('role', "button"); + this._clocklink.addClass('ui-button'); + this._clocklink.attr('title', 'Tootip is not dismissed while typing for 10 seconds'); + var clockspan = $('').text('Close'); + clockspan.addClass('ui-icon'); + clockspan.addClass('ui-icon-clock'); + this._clocklink.append(clockspan); + this._clocklink.click(function () { + that.cancel_stick(); + }); - //construct the tooltip - // add in the reverse order you want them to appear - this.buttons.append(closelink); - this.buttons.append(expandlink); - this.buttons.append(morelink); - this.buttons.append(this._clocklink); - this._clocklink.hide(); - - - // we need a phony element to make the small arrow - // of the tooltip in css - // we will move the arrow later - this.arrow = $('').addClass('pretooltiparrow'); - this.tooltip.append(this.buttons); - this.tooltip.append(this.arrow); - this.tooltip.append(this.text); - - // function that will be called if you press tab 1, 2, 3... times in a row - this.tabs_functions = [function (cell, text, cursor) { - that._request_tooltip(cell, text, cursor); - }, function () { - that.expand(); - }, function () { - that.stick(); - }, function (cell) { - that.cancel_stick(); - that.showInPager(cell); - }]; - // call after all the tabs function above have bee call to clean their effects - // if necessary - this.reset_tabs_function = function (cell, text) { - this._old_cell = (cell) ? cell : null; - this._old_request = (text) ? text : null; - this._consecutive_counter = 0; - }; + //construct the tooltip + // add in the reverse order you want them to appear + this.buttons.append(closelink); + this.buttons.append(expandlink); + this.buttons.append(morelink); + this.buttons.append(this._clocklink); + this._clocklink.hide(); + + + // we need a phony element to make the small arrow + // of the tooltip in css + // we will move the arrow later + this.arrow = $('').addClass('pretooltiparrow'); + this.tooltip.append(this.buttons); + this.tooltip.append(this.arrow); + this.tooltip.append(this.text); + + // function that will be called if you press tab 1, 2, 3... times in a row + this.tabs_functions = [function (cell, text, cursor) { + that._request_tooltip(cell, text, cursor); + }, function () { + that.expand(); + }, function () { + that.stick(); + }, function (cell) { + that.cancel_stick(); + that.showInPager(cell); + }]; + // call after all the tabs function above have bee call to clean their effects + // if necessary + this.reset_tabs_function = function (cell, text) { + this._old_cell = (cell) ? cell : null; + this._old_request = (text) ? text : null; + this._consecutive_counter = 0; }; + }; Tooltip.prototype.is_visible = function () { return !this._hidden; @@ -131,7 +121,7 @@ var IPython = (function (IPython) { var payload = {}; payload.text = that._reply.content.data['text/plain']; - $([IPython.events]).trigger('open_with_text.Pager', payload); + this.events.trigger('open_with_text.Pager', payload); this.remove_and_cancel_tooltip(); }; @@ -338,8 +328,8 @@ var IPython = (function (IPython) { this.text.scrollTop(0); }; + // Backwards compatability. IPython.Tooltip = Tooltip; - return IPython; - -}(IPython)); + return {'Tooltip': Tooltip}; +}); diff --git a/IPython/html/static/notebook/js/tour.js b/IPython/html/static/notebook/js/tour.js index e869247d4..dcd4e347c 100644 --- a/IPython/html/static/notebook/js/tour.js +++ b/IPython/html/static/notebook/js/tour.js @@ -1,135 +1,124 @@ -//---------------------------------------------------------------------------- -// 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. -//============================================================================ -// Tour of IPython Notebok UI (with Bootstrap Tour) -//============================================================================ +define([ + 'base/js/namespace', + 'jquery', + 'bootstraptour', +], function(IPython, $, Tour) { + "use strict"; -var tour_steps = [ - { - title: "Welcome to the Notebook Tour", - placement: 'bottom', - orphan: true, - content: "This tour will take 2 minutes.", - }, { - element: "#notebook_name", - title: "Filename", - placement: 'bottom', - content: "Click here to change the filename for this notebook." - }, { - element: $("#menus").parent(), - placement: 'bottom', - backdrop: true, - title: "Notebook Menubar", - content: "The menubar has menus for actions on the notebook, its cells, and the kernel it communicates with." - }, { - element: "#maintoolbar", - placement: 'bottom', - backdrop: true, - title: "Notebook Toolbar", - content: "The toolbar has buttons for the most common actions. Hover your mouse over each button for more information." - }, { - element: "#modal_indicator", - title: "Mode Indicator", - placement: 'bottom', - content: "The Notebook has two modes: Edit Mode and Command Mode. In this area, an indicator can appear to tell you which mode you are in.", - onShow: function(tour) { command_icon_hack(); } - }, { - element: "#modal_indicator", - title: "Command Mode", - placement: 'bottom', - onShow: function(tour) { IPython.notebook.command_mode(); command_icon_hack(); }, - onNext: function(tour) { edit_mode(); }, - content: "Right now you are in Command Mode, and many keyboard shortcuts are available. In this mode, no icon is displayed in the indicator area." - }, { - element: "#modal_indicator", - title: "Edit Mode", - placement: 'bottom', - onShow: function(tour) { edit_mode(); }, - content: "Pressing- - - - - - - {% block script %} + {% endblock %} diff --git a/IPython/html/templates/tree.html b/IPython/html/templates/tree.html index f74a60864..1635e096a 100644 --- a/IPython/html/templates/tree.html +++ b/IPython/html/templates/tree.html @@ -111,11 +111,6 @@ data-notebook-path="{{notebook_path}}" {% block script %} {{super()}} - - - - - - - + + {% endblock %} diff --git a/IPython/html/tests/notebook/save.js b/IPython/html/tests/notebook/save.js index affe05454..30c670d59 100644 --- a/IPython/html/tests/notebook/save.js +++ b/IPython/html/tests/notebook/save.js @@ -11,10 +11,10 @@ casper.notebook_test(function () { this.evaluate(function (nbname) { IPython.notebook.notebook_name = nbname; IPython._save_success = IPython._save_failed = false; - $([IPython.events]).on('notebook_saved.Notebook', function () { + IPython.events.on('notebook_saved.Notebook', function () { IPython._save_success = true; }); - $([IPython.events]).on('notebook_save_failed.Notebook', + IPython.events.on('notebook_save_failed.Notebook', function (event, xhr, status, error) { IPython._save_failed = "save failed with " + xhr.status + xhr.responseText; }); @@ -41,7 +41,7 @@ casper.notebook_test(function () { }); this.thenEvaluate(function(){ - $([IPython.events]).on('checkpoint_created.Notebook', function (evt, data) { + IPython.events.on('checkpoint_created.Notebook', function (evt, data) { IPython._checkpoint_created = true; }); IPython._checkpoint_created = false; diff --git a/IPython/html/tests/util.js b/IPython/html/tests/util.js index 8523496b1..666f94a52 100644 --- a/IPython/html/tests/util.js +++ b/IPython/html/tests/util.js @@ -12,6 +12,7 @@ casper.open_new_notebook = function () { // Create and open a new notebook. var baseUrl = this.get_notebook_server(); this.start(baseUrl); + this.waitFor(this.page_loaded); this.thenClick('button#new_notebook'); this.waitForPopup(''); @@ -19,15 +20,16 @@ casper.open_new_notebook = function () { this.then(function () { this.open(this.popups[0].url); }); + this.waitFor(this.page_loaded); // Make sure the kernel has started - this.waitFor( this.kernel_running ); + this.waitFor(this.kernel_running); // track the IPython busy/idle state this.thenEvaluate(function () { - $([IPython.events]).on('status_idle.Kernel',function () { + IPython.events.on('status_idle.Kernel',function () { IPython._status = 'idle'; }); - $([IPython.events]).on('status_busy.Kernel',function () { + IPython.events.on('status_busy.Kernel',function () { IPython._status = 'busy'; }); }); @@ -42,9 +44,18 @@ casper.open_new_notebook = function () { }); }; -casper.kernel_running = function kernel_running() { +casper.page_loaded = function() { // Return whether or not the kernel is running. - return this.evaluate(function kernel_running() { + return this.evaluate(function() { + return IPython !== undefined && + IPython.page !== undefined && + IPython.events !== undefined; + }); +}; + +casper.kernel_running = function() { + // Return whether or not the kernel is running. + return this.evaluate(function() { return IPython.notebook.kernel.running; }); }; @@ -503,6 +514,7 @@ casper.open_dashboard = function () { // Start casper by opening the dashboard page. var baseUrl = this.get_notebook_server(); this.start(baseUrl); + this.waitFor(this.page_loaded); this.wait_for_dashboard(); };Enteror clicking in the input text area of the cell switches to Edit Mode." - }, { - element: '.selected', - title: "Edit Mode", - placement: 'bottom', - onShow: function(tour) { edit_mode(); }, - content: "Notice that the border around the currently active cell changed color. Typing will insert text into the currently active cell." - }, { - element: '.selected', - title: "Back to Command Mode", - placement: 'bottom', - onShow: function(tour) { IPython.notebook.command_mode(); }, - onHide: function(tour) { $('#help_menu').parent().children('a').click(); }, - content: "PressingEscor clicking outside of the input text area takes you back to Command Mode." - }, { - element: '#keyboard_shortcuts', - title: "Keyboard Shortcuts", - placement: 'bottom', - onHide: function(tour) { $('#help_menu').parent().children('a').click(); }, - content: "You can click here to get a list of all of the keyboard shortcuts." - }, { - element: "#kernel_indicator", - title: "Kernel Indicator", - placement: 'bottom', - onShow: function(tour) { $([IPython.events]).trigger('status_idle.Kernel');}, - content: "This is the Kernel indicator. It looks like this when the Kernel is idle.", - }, { - element: "#kernel_indicator", - title: "Kernel Indicator", - placement: 'bottom', - onShow: function(tour) { $([IPython.events]).trigger('status_busy.Kernel'); }, - content: "The Kernel indicator looks like this when the Kernel is busy.", - }, { - element: ".icon-stop", - placement: 'bottom', - title: "Interrupting the Kernel", - onHide: function(tour) { $([IPython.events]).trigger('status_idle.Kernel'); }, - content: "To cancel a computation in progress, you can click here." - }, { - element: "#notification_kernel", - placement: 'bottom', - onShow: function(tour) { $('.icon-stop').click(); }, - title: "Notification Area", - content: "Messages in response to user actions (Save, Interrupt, etc) appear here." - }, { - title: "Fin.", - placement: 'bottom', - orphan: true, - content: "This concludes the IPython Notebook User Interface Tour. Happy hacking!", - } -]; + var tour_style = "\n" + + "\n" + + ""; -var tour_style = "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\ - \ -"; - -var command_icon_hack = function() {$('#modal_indicator').css('min-height', 20);} -var toggle_pause_play = function () { $('#tour-pause').toggleClass('icon-pause icon-play'); }; -var edit_mode = function() { - IPython.notebook.focus_cell(); - IPython.notebook.edit_mode(); -;} - -IPython = (function (IPython) { - "use strict"; - - - var NotebookTour = function () { + var NotebookTour = function (notebook, events) { + var that = this; + this.notebook = notebook; this.step_duration = 0; - this.tour_steps = tour_steps ; - this.tour_steps[0].content = "You can use the left and right arrow keys to go backwards and forwards."; + this.events = events; + this.tour_steps = [ + { + title: "Welcome to the Notebook Tour", + placement: 'bottom', + orphan: true, + content: "You can use the left and right arrow keys to go backwards and forwards.", + }, { + element: "#notebook_name", + title: "Filename", + placement: 'bottom', + content: "Click here to change the filename for this notebook." + }, { + element: $("#menus").parent(), + placement: 'bottom', + backdrop: true, + title: "Notebook Menubar", + content: "The menubar has menus for actions on the notebook, its cells, and the kernel it communicates with." + }, { + element: "#maintoolbar", + placement: 'bottom', + backdrop: true, + title: "Notebook Toolbar", + content: "The toolbar has buttons for the most common actions. Hover your mouse over each button for more information." + }, { + element: "#modal_indicator", + title: "Mode Indicator", + placement: 'bottom', + content: "The Notebook has two modes: Edit Mode and Command Mode. In this area, an indicator can appear to tell you which mode you are in.", + onShow: function(tour) { that.command_icon_hack(); } + }, { + element: "#modal_indicator", + title: "Command Mode", + placement: 'bottom', + onShow: function(tour) { notebook.command_mode(); that.command_icon_hack(); }, + onNext: function(tour) { that.edit_mode(); }, + content: "Right now you are in Command Mode, and many keyboard shortcuts are available. In this mode, no icon is displayed in the indicator area." + }, { + element: "#modal_indicator", + title: "Edit Mode", + placement: 'bottom', + onShow: function(tour) { that.edit_mode(); }, + content: "Pressing\ -\ - \ - \ - \ -Enteror clicking in the input text area of the cell switches to Edit Mode." + }, { + element: '.selected', + title: "Edit Mode", + placement: 'bottom', + onShow: function(tour) { that.edit_mode(); }, + content: "Notice that the border around the currently active cell changed color. Typing will insert text into the currently active cell." + }, { + element: '.selected', + title: "Back to Command Mode", + placement: 'bottom', + onShow: function(tour) { notebook.command_mode(); }, + onHide: function(tour) { $('#help_menu').parent().children('a').click(); }, + content: "PressingEscor clicking outside of the input text area takes you back to Command Mode." + }, { + element: '#keyboard_shortcuts', + title: "Keyboard Shortcuts", + placement: 'bottom', + onHide: function(tour) { $('#help_menu').parent().children('a').click(); }, + content: "You can click here to get a list of all of the keyboard shortcuts." + }, { + element: "#kernel_indicator", + title: "Kernel Indicator", + placement: 'bottom', + onShow: function(tour) { events.trigger('status_idle.Kernel');}, + content: "This is the Kernel indicator. It looks like this when the Kernel is idle.", + }, { + element: "#kernel_indicator", + title: "Kernel Indicator", + placement: 'bottom', + onShow: function(tour) { events.trigger('status_busy.Kernel'); }, + content: "The Kernel indicator looks like this when the Kernel is busy.", + }, { + element: ".icon-stop", + placement: 'bottom', + title: "Interrupting the Kernel", + onHide: function(tour) { events.trigger('status_idle.Kernel'); }, + content: "To cancel a computation in progress, you can click here." + }, { + element: "#notification_kernel", + placement: 'bottom', + onShow: function(tour) { $('.icon-stop').click(); }, + title: "Notification Area", + content: "Messages in response to user actions (Save, Interrupt, etc) appear here." + }, { + title: "Fin.", + placement: 'bottom', + orphan: true, + content: "This concludes the IPython Notebook User Interface tour.Tour. Happy hacking!", + } + ]; + this.tour = new Tour({ //orphan: true, storage: false, // start tour from beginning every time @@ -143,8 +132,8 @@ IPython = (function (IPython) { // TODO: remove the onPause/onResume logic once pi's patch has been // merged upstream to make this work via data-resume-class and // data-resume-text attributes. - onPause: toggle_pause_play, - onResume: toggle_pause_play, + onPause: this.toggle_pause_play, + onResume: this.toggle_pause_play, steps: this.tour_steps, template: tour_style, orphan: true @@ -162,9 +151,23 @@ IPython = (function (IPython) { } }; - // Set module variables + NotebookTour.prototype.command_icon_hack = function() { + $('#modal_indicator').css('min-height', 20); + }; + + NotebookTour.prototype.toggle_pause_play = function () { + $('#tour-pause').toggleClass('icon-pause icon-play'); + }; + + NotebookTour.prototype.edit_mode = function() { + this.notebook.focus_cell(); + this.notebook.edit_mode(); + }; + + // For backwards compatability. IPython.NotebookTour = NotebookTour; - return IPython; + return {'Tour': NotebookTour}; + +}); -}(IPython)); diff --git a/IPython/html/static/services/kernels/js/comm.js b/IPython/html/static/services/kernels/js/comm.js index 22e132afb..4cb24a6fa 100644 --- a/IPython/html/static/services/kernels/js/comm.js +++ b/IPython/html/static/services/kernels/js/comm.js @@ -1,21 +1,11 @@ -//---------------------------------------------------------------------------- -// 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. -//============================================================================ -// Comm and CommManager bases -//============================================================================ -/** - * Base Comm classes - * @module IPython - * @namespace IPython - * @submodule comm - */ - -var IPython = (function (IPython) { +define([ + 'base/js/namespace', + 'jquery', + 'base/js/utils', +], function(IPython, $, utils) { "use strict"; //----------------------------------------------------------------------- @@ -125,7 +115,7 @@ var IPython = (function (IPython) { var Comm = function (target_name, comm_id) { this.target_name = target_name; - this.comm_id = comm_id || IPython.utils.uuid(); + this.comm_id = comm_id || utils.uuid(); this._msg_callback = this._close_callback = null; }; @@ -189,10 +179,12 @@ var IPython = (function (IPython) { this._maybe_callback('close', msg); }; + // For backwards compatability. IPython.CommManager = CommManager; IPython.Comm = Comm; - - return IPython; - -}(IPython)); + return { + 'CommManager': CommManager, + 'Comm': Comm + }; +}); diff --git a/IPython/html/static/services/kernels/js/kernel.js b/IPython/html/static/services/kernels/js/kernel.js index 8149f01c7..8004c15b2 100644 --- a/IPython/html/static/services/kernels/js/kernel.js +++ b/IPython/html/static/services/kernels/js/kernel.js @@ -1,27 +1,22 @@ // Copyright (c) IPython Development Team. // Distributed under the terms of the Modified BSD License. -//============================================================================ -// Kernel -//============================================================================ - -/** - * @module IPython - * @namespace IPython - * @submodule Kernel - */ - -var IPython = (function (IPython) { +define([ + 'base/js/namespace', + 'jquery', + 'base/js/utils', + 'services/kernels/js/comm', + 'widgets/js/init', +], function(IPython, $, utils, comm, widgetmanager) { "use strict"; - - var utils = IPython.utils; // Initialization and connection. /** * A Kernel Class to communicate with the Python kernel * @Class Kernel */ - var Kernel = function (kernel_service_url) { + var Kernel = function (kernel_service_url, notebook) { + this.events = notebook.events; this.kernel_id = null; this.shell_channel = null; this.iopub_channel = null; @@ -43,8 +38,8 @@ var IPython = (function (IPython) { this.bind_events(); this.init_iopub_handlers(); - this.comm_manager = new IPython.CommManager(this); - this.widget_manager = new IPython.WidgetManager(this.comm_manager); + this.comm_manager = new comm.CommManager(this); + this.widget_manager = new widgetmanager.WidgetManager(this.comm_manager, notebook); this.last_msg_id = null; this.last_msg_callbacks = {}; @@ -69,7 +64,7 @@ var IPython = (function (IPython) { Kernel.prototype.bind_events = function () { var that = this; - $([IPython.events]).on('send_input_reply.Kernel', function(evt, data) { + this.events.on('send_input_reply.Kernel', function(evt, data) { that.send_input_reply(data); }); }; @@ -111,7 +106,7 @@ var IPython = (function (IPython) { * @method restart */ Kernel.prototype.restart = function () { - $([IPython.events]).trigger('status_restarting.Kernel', {kernel: this}); + this.events.trigger('status_restarting.Kernel', {kernel: this}); if (this.running) { this.stop_channels(); this.post(utils.url_join_encode(this.kernel_url, "restart"), @@ -135,7 +130,7 @@ var IPython = (function (IPython) { Kernel.prototype._websocket_closed = function(ws_url, early) { this.stop_channels(); - $([IPython.events]).trigger('websocket_closed.Kernel', + this.events.trigger('websocket_closed.Kernel', {ws_url: ws_url, kernel: this, early: early} ); }; @@ -215,7 +210,7 @@ var IPython = (function (IPython) { if ( !channels[i].readyState ) return; } // all events ready, trigger started event. - $([IPython.events]).trigger('status_started.Kernel', {kernel: this}); + this.events.trigger('status_started.Kernel', {kernel: this}); }; /** @@ -348,7 +343,7 @@ var IPython = (function (IPython) { content.allow_stdin = true; } $.extend(true, content, options); - $([IPython.events]).trigger('execution_request.Kernel', {kernel: this, content:content}); + this.events.trigger('execution_request.Kernel', {kernel: this, content:content}); return this.send_shell_message("execute_request", content, callbacks); }; @@ -380,7 +375,7 @@ var IPython = (function (IPython) { Kernel.prototype.interrupt = function () { if (this.running) { - $([IPython.events]).trigger('status_interrupting.Kernel', {kernel: this}); + this.events.trigger('status_interrupting.Kernel', {kernel: this}); this.post(utils.url_join_encode(this.kernel_url, "interrupt")); } }; @@ -402,7 +397,7 @@ var IPython = (function (IPython) { var content = { value : input, }; - $([IPython.events]).trigger('input_reply.Kernel', {kernel: this, content:content}); + this.events.trigger('input_reply.Kernel', {kernel: this, content:content}); var msg = this._get_msg("input_reply", content); this.stdin_channel.send(JSON.stringify(msg)); return msg.header.msg_id; @@ -482,7 +477,7 @@ var IPython = (function (IPython) { Kernel.prototype._handle_shell_reply = function (e) { var reply = $.parseJSON(e.data); - $([IPython.events]).trigger('shell_reply.Kernel', {kernel: this, reply:reply}); + this.events.trigger('shell_reply.Kernel', {kernel: this, reply:reply}); var content = reply.content; var metadata = reply.metadata; var parent_id = reply.parent_header.msg_id; @@ -532,7 +527,7 @@ var IPython = (function (IPython) { } if (execution_state === 'busy') { - $([IPython.events]).trigger('status_busy.Kernel', {kernel: this}); + this.events.trigger('status_busy.Kernel', {kernel: this}); } else if (execution_state === 'idle') { // signal that iopub callbacks are (probably) done // async output may still arrive, @@ -540,17 +535,17 @@ var IPython = (function (IPython) { this._finish_iopub(parent_id); // trigger status_idle event - $([IPython.events]).trigger('status_idle.Kernel', {kernel: this}); + this.events.trigger('status_idle.Kernel', {kernel: this}); } else if (execution_state === 'restarting') { // autorestarting is distinct from restarting, // in that it means the kernel died and the server is restarting it. // status_restarting sets the notification widget, // autorestart shows the more prominent dialog. - $([IPython.events]).trigger('status_autorestarting.Kernel', {kernel: this}); - $([IPython.events]).trigger('status_restarting.Kernel', {kernel: this}); + this.events.trigger('status_autorestarting.Kernel', {kernel: this}); + this.events.trigger('status_restarting.Kernel', {kernel: this}); } else if (execution_state === 'dead') { this.stop_channels(); - $([IPython.events]).trigger('status_dead.Kernel', {kernel: this}); + this.events.trigger('status_dead.Kernel', {kernel: this}); } }; @@ -610,10 +605,8 @@ var IPython = (function (IPython) { } }; - + // Backwards compatability. IPython.Kernel = Kernel; - return IPython; - -}(IPython)); - + return {'Kernel': Kernel}; +}); diff --git a/IPython/html/static/services/sessions/js/session.js b/IPython/html/static/services/sessions/js/session.js index 2837d8799..1cfb1a942 100644 --- a/IPython/html/static/services/sessions/js/session.js +++ b/IPython/html/static/services/sessions/js/session.js @@ -1,26 +1,21 @@ -//---------------------------------------------------------------------------- -// 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. -//============================================================================ -// Notebook -//============================================================================ - -var IPython = (function (IPython) { +define([ + 'base/js/namespace', + 'jquery', + 'base/js/utils', + 'services/kernels/js/kernel', +], function(IPython, $, utils, kernel) { "use strict"; - - var utils = IPython.utils; - - var Session = function(notebook, options){ + + var Session = function(options){ this.kernel = null; this.id = null; - this.notebook = notebook; - this.name = notebook.notebook_name; - this.path = notebook.notebook_path; - this.base_url = notebook.base_url; + this.notebook = options.notebook; + this.name = options.notebook_name; + this.path = options.notebook_path; + this.base_url = options.base_url; }; Session.prototype.start = function(callback) { @@ -92,7 +87,7 @@ var IPython = (function (IPython) { Session.prototype._handle_start_success = function (data, status, xhr) { this.id = data.id; var kernel_service_url = utils.url_path_join(this.base_url, "api/kernels"); - this.kernel = new IPython.Kernel(kernel_service_url); + this.kernel = new kernel.Kernel(kernel_service_url, this.notebook); this.kernel._kernel_started(data.kernel); }; @@ -114,8 +109,8 @@ var IPython = (function (IPython) { this.kernel.kill(); }; + // For backwards compatability. IPython.Session = Session; - return IPython; - -}(IPython)); + return {'Session': Session}; +}); diff --git a/IPython/html/static/tree/js/clusterlist.js b/IPython/html/static/tree/js/clusterlist.js index da337c25a..d1626819e 100644 --- a/IPython/html/static/tree/js/clusterlist.js +++ b/IPython/html/static/tree/js/clusterlist.js @@ -1,18 +1,12 @@ -//---------------------------------------------------------------------------- -// 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. -//---------------------------------------------------------------------------- - -//============================================================================ -// NotebookList -//============================================================================ - -var IPython = (function (IPython) { +// Copyright (c) IPython Development Team. +// Distributed under the terms of the Modified BSD License. + +define([ + 'base/js/namespace', + 'jquery', + 'base/js/utils', +], function(IPython, $, utils) { "use strict"; - - var utils = IPython.utils; var ClusterList = function (selector, options) { this.selector = selector; @@ -188,11 +182,12 @@ var IPython = (function (IPython) { }); }; - + // For backwards compatability. IPython.ClusterList = ClusterList; IPython.ClusterItem = ClusterItem; - return IPython; - -}(IPython)); - + return { + 'ClusterList': ClusterList, + 'ClusterItem': ClusterItem, + }; +}); diff --git a/IPython/html/static/tree/js/kernellist.js b/IPython/html/static/tree/js/kernellist.js index f89d52cb0..60b5628ef 100644 --- a/IPython/html/static/tree/js/kernellist.js +++ b/IPython/html/static/tree/js/kernellist.js @@ -1,24 +1,29 @@ -//---------------------------------------------------------------------------- -// Copyright (C) 2014 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. -//---------------------------------------------------------------------------- - -//============================================================================ -// Running Kernels List -//============================================================================ - -var IPython = (function (IPython) { +// Copyright (c) IPython Development Team. +// Distributed under the terms of the Modified BSD License. + +define([ + 'base/js/namespace', + 'jquery', + 'tree/js/notebooklist', +], function(IPython, $, notebooklist) { "use strict"; - var utils = IPython.utils; - var KernelList = function (selector, options) { - IPython.NotebookList.call(this, selector, options, 'running'); + // Constructor + // + // Parameters: + // selector: string + // options: dictionary + // Dictionary of keyword arguments. + // session_list: SessionList instance + // base_url: string + // notebook_path: string + notebooklist.NotebookList.call(this, selector, $.extend({ + element_name: 'running'}, + options)); }; - KernelList.prototype = Object.create(IPython.NotebookList.prototype); + KernelList.prototype = Object.create(notebooklist.NotebookList.prototype); KernelList.prototype.sessions_loaded = function (d) { this.sessions = d; @@ -31,10 +36,10 @@ var IPython = (function (IPython) { } $('#running_list_header').toggle($.isEmptyObject(d)); - } + }; + // Backwards compatability. IPython.KernelList = KernelList; - return IPython; - -}(IPython)); + return {'KernelList': KernelList}; +}); diff --git a/IPython/html/static/tree/js/main.js b/IPython/html/static/tree/js/main.js index acd647dba..88ea1ff46 100644 --- a/IPython/html/static/tree/js/main.js +++ b/IPython/html/static/tree/js/main.js @@ -1,32 +1,53 @@ -//---------------------------------------------------------------------------- -// 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. -//---------------------------------------------------------------------------- - -//============================================================================ -// On document ready -//============================================================================ - - -$(document).ready(function () { - - IPython.page = new IPython.Page(); +// Copyright (c) IPython Development Team. +// Distributed under the terms of the Modified BSD License. + +require([ + 'base/js/namespace', + 'jquery', + 'base/js/events', + 'base/js/page', + 'base/js/utils', + 'tree/js/notebooklist', + 'tree/js/clusterlist', + 'tree/js/sessionlist', + 'tree/js/kernellist', + 'auth/js/loginwidget', + 'components/jquery-ui/ui/minified/jquery-ui.min', + 'components/bootstrap/js/bootstrap.min', +], function( + IPython, + $, + events, + page, + utils, + notebooklist, + clusterlist, + sesssionlist, + kernellist, + loginwidget){ + + page = new page.Page(); + + var common_options = { + base_url: utils.get_body_data("baseUrl"), + notebook_path: utils.get_body_data("notebookPath"), + }; + events = $([new events.Events()]); + session_list = new sesssionlist.SesssionList($.extend({ + events: events}, + common_options)); + notebook_list = new notebooklist.NotebookList('#notebook_list', $.extend({ + session_list: session_list}, + common_options)); + cluster_list = new clusterlist.ClusterList('#cluster_list', common_options); + kernel_list = new kernellist.KernelList('#running_list', $.extend({ + session_list: session_list}, + common_options)); + login_widget = new loginwidget.LoginWidget('#login_widget', common_options); $('#new_notebook').button().click(function (e) { - IPython.notebook_list.new_notebook() + notebook_list.new_notebook(); }); - - var opts = { - base_url : IPython.utils.get_body_data("baseUrl"), - notebook_path : IPython.utils.get_body_data("notebookPath"), - }; - IPython.session_list = new IPython.SesssionList(opts); - IPython.notebook_list = new IPython.NotebookList('#notebook_list', opts); - IPython.cluster_list = new IPython.ClusterList('#cluster_list', opts); - IPython.kernel_list = new IPython.KernelList('#running_list', opts); - IPython.login_widget = new IPython.LoginWidget('#login_widget', opts); var interval_id=0; // auto refresh every xx secondes, no need to be fast, @@ -35,31 +56,31 @@ $(document).ready(function () { var enable_autorefresh = function(){ //refresh immediately , then start interval - if($('.upload_button').length == 0) + if($('.upload_button').length === 0) { - IPython.session_list.load_sessions(); - IPython.cluster_list.load_list(); + session_list.load_sessions(); + cluster_list.load_list(); } if (!interval_id){ interval_id = setInterval(function(){ - if($('.upload_button').length == 0) + if($('.upload_button').length === 0) { - IPython.session_list.load_sessions(); - IPython.cluster_list.load_list(); + session_list.load_sessions(); + cluster_list.load_list(); } }, time_refresh*1000); } - } + }; var disable_autorefresh = function(){ clearInterval(interval_id); interval_id = 0; - } + }; // stop autorefresh when page lose focus $(window).blur(function() { disable_autorefresh(); - }) + }); //re-enable when page get focus back $(window).focus(function() { @@ -69,24 +90,30 @@ $(document).ready(function () { // finally start it, it will refresh immediately enable_autorefresh(); - IPython.page.show(); - $([IPython.events]).trigger('app_initialized.DashboardApp'); - + page.show(); + events.trigger('app_initialized.DashboardApp'); + // bound the upload method to the on change of the file select list $("#alternate_upload").change(function (event){ - IPython.notebook_list.handleFilesUpload(event,'form'); + notebook_list.handleFilesUpload(event,'form'); }); // set hash on tab click $("#tabs").find("a").click(function() { window.location.hash = $(this).attr("href"); - }) + }); // load tab if url hash if (window.location.hash) { $("#tabs").find("a[href=" + window.location.hash + "]").click(); } - + // For backwards compatability. + IPython.page = page; + IPython.notebook_list = notebook_list; + IPython.cluster_list = cluster_list; + IPython.session_list = session_list; + IPython.kernel_list = kernel_list; + IPython.login_widget = login_widget; + IPython.events = events; }); - diff --git a/IPython/html/static/tree/js/notebooklist.js b/IPython/html/static/tree/js/notebooklist.js index 9f118f3e1..4228e3904 100644 --- a/IPython/html/static/tree/js/notebooklist.js +++ b/IPython/html/static/tree/js/notebooklist.js @@ -1,23 +1,29 @@ -//---------------------------------------------------------------------------- -// 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. -//---------------------------------------------------------------------------- - -//============================================================================ -// NotebookList -//============================================================================ - -var IPython = (function (IPython) { +// Copyright (c) IPython Development Team. +// Distributed under the terms of the Modified BSD License. + +define([ + 'base/js/namespace', + 'jquery', + 'base/js/utils', + 'base/js/dialog', +], function(IPython, $, utils, dialog) { "use strict"; - var utils = IPython.utils; - - var NotebookList = function (selector, options, element_name) { - var that = this + var NotebookList = function (selector, options) { + // Constructor + // + // Parameters: + // selector: string + // options: dictionary + // Dictionary of keyword arguments. + // session_list: SessionList instance + // element_name: string + // base_url: string + // notebook_path: string + var that = this; + this.session_list = options.session_list; // allow code re-use by just changing element_name in kernellist.js - this.element_name = element_name || 'notebook'; + this.element_name = options.element_name || 'notebook'; this.selector = selector; if (this.selector !== undefined) { this.element = $(selector); @@ -28,12 +34,14 @@ var IPython = (function (IPython) { this.sessions = {}; this.base_url = options.base_url || utils.get_body_data("baseUrl"); this.notebook_path = options.notebook_path || utils.get_body_data("notebookPath"); - $([IPython.events]).on('sessions_loaded.Dashboard', - function(e, d) { that.sessions_loaded(d); }); + if (this.session_list && this.session_list.events) { + this.session_list.events.on('sessions_loaded.Dashboard', + function(e, d) { that.sessions_loaded(d); }); + } }; NotebookList.prototype.style = function () { - var prefix = '#' + this.element_name + var prefix = '#' + this.element_name; $(prefix + '_toolbar').addClass('list_toolbar'); $(prefix + '_list_info').addClass('toolbar_info'); $(prefix + '_buttons').addClass('toolbar_buttons'); @@ -84,10 +92,10 @@ var IPython = (function (IPython) { that.add_upload_button(nbitem); }; } else { - var dialog = 'Uploaded notebooks must be .ipynb files'; - IPython.dialog.modal({ + var dialog_body = 'Uploaded notebooks must be .ipynb files'; + dialog.modal({ title : 'Invalid file type', - body : dialog, + body : dialog_body, buttons : {'OK' : {'class' : 'btn-primary'}} }); } @@ -114,7 +122,7 @@ var IPython = (function (IPython) { }; NotebookList.prototype.load_sessions = function(){ - IPython.session_list.load_sessions(); + this.session_list.load_sessions(); }; @@ -301,7 +309,7 @@ var IPython = (function (IPython) { var parent_item = that.parents('div.list_item'); var nbname = parent_item.data('nbname'); var message = 'Are you sure you want to permanently delete the notebook: ' + nbname + '?'; - IPython.dialog.modal({ + dialog.modal({ title : "Delete notebook", body : message, buttons : { @@ -426,16 +434,15 @@ var IPython = (function (IPython) { } else { msg = xhr.statusText; } - IPython.dialog.modal({ + dialog.modal({ title : 'Creating Notebook Failed', body : "The error was: " + msg, buttons : {'OK' : {'class' : 'btn-primary'}} }); - } - + }; + // Backwards compatability. IPython.NotebookList = NotebookList; - return IPython; - -}(IPython)); + return {'NotebookList': NotebookList}; +}); diff --git a/IPython/html/static/tree/js/sessionlist.js b/IPython/html/static/tree/js/sessionlist.js index 05dafb190..2f3e62302 100644 --- a/IPython/html/static/tree/js/sessionlist.js +++ b/IPython/html/static/tree/js/sessionlist.js @@ -1,20 +1,22 @@ -//---------------------------------------------------------------------------- -// Copyright (C) 2014 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. -//============================================================================ -// Running Kernels List -//============================================================================ - -var IPython = (function (IPython) { +define([ + 'base/js/namespace', + 'jquery', + 'base/js/utils', +], function(IPython, $, utils) { "use strict"; - var utils = IPython.utils; - var SesssionList = function (options) { + // Constructor + // + // Parameters: + // options: dictionary + // Dictionary of keyword arguments. + // events: $(Events) instance + // base_url : string + this.events = options.events; this.sessions = {}; this.base_url = options.base_url || utils.get_body_data("baseUrl"); }; @@ -44,10 +46,11 @@ var IPython = (function (IPython) { ); this.sessions[nb_path] = data[i].id; } - $([IPython.events]).trigger('sessions_loaded.Dashboard', this.sessions); + this.events.trigger('sessions_loaded.Dashboard', this.sessions); }; - IPython.SesssionList = SesssionList; - return IPython; + // Backwards compatability. + IPython.SesssionList = SesssionList; -}(IPython)); + return {'SesssionList': SesssionList}; +}); diff --git a/IPython/html/static/widgets/js/init.js b/IPython/html/static/widgets/js/init.js index 4c23488b8..1d92668a2 100644 --- a/IPython/html/static/widgets/js/init.js +++ b/IPython/html/static/widgets/js/init.js @@ -1,15 +1,8 @@ -//---------------------------------------------------------------------------- -// 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. -//---------------------------------------------------------------------------- - -//============================================================================ -// Basic Widgets -//============================================================================ +// Copyright (c) IPython Development Team. +// Distributed under the terms of the Modified BSD License. define([ + "widgets/js/manager", "widgets/js/widget_bool", "widgets/js/widget_button", "widgets/js/widget_container", @@ -19,4 +12,16 @@ define([ "widgets/js/widget_selection", "widgets/js/widget_selectioncontainer", "widgets/js/widget_string", -], function(){ return true; }); +], function(widgetmanager) { + + // Register all of the loaded views with the widget manager. + for (var i = 1; i < arguments.length; i++) { + for (var target_name in arguments[i]) { + if (arguments[i].hasOwnProperty(target_name)) { + widgetmanager.WidgetManager.register_widget_view(target_name, arguments[i][target_name]); + } + } + } + + return {'WidgetManager': widgetmanager.WidgetManager}; +}); diff --git a/IPython/html/static/widgets/js/manager.js b/IPython/html/static/widgets/js/manager.js index 4aba4d27e..a7f724dd8 100644 --- a/IPython/html/static/widgets/js/manager.js +++ b/IPython/html/static/widgets/js/manager.js @@ -1,214 +1,201 @@ -//---------------------------------------------------------------------------- -// 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. -//---------------------------------------------------------------------------- - -//============================================================================ -// WidgetModel, WidgetView, and WidgetManager -//============================================================================ -/** - * Base Widget classes - * @module IPython - * @namespace IPython - * @submodule widget - */ - -(function () { - "use strict"; - - // Use require.js 'define' method so that require.js is intelligent enough to - // syncronously load everything within this file when it is being 'required' - // elsewhere. - define(["underscore", - "backbone", - ], function (_, Backbone) { - - //-------------------------------------------------------------------- - // WidgetManager class - //-------------------------------------------------------------------- - var WidgetManager = function (comm_manager) { - // Public constructor - WidgetManager._managers.push(this); - - // Attach a comm manager to the - this.comm_manager = comm_manager; - this._models = {}; /* Dictionary of model ids and model instances */ - - // Register already-registered widget model types with the comm manager. - var that = this; - _.each(WidgetManager._model_types, function(model_type, model_name) { - that.comm_manager.register_target(model_name, $.proxy(that._handle_comm_open, that)); - }); - }; - - //-------------------------------------------------------------------- - // Class level - //-------------------------------------------------------------------- - WidgetManager._model_types = {}; /* Dictionary of model type names (target_name) and model types. */ - WidgetManager._view_types = {}; /* Dictionary of view names and view types. */ - WidgetManager._managers = []; /* List of widget managers */ - - WidgetManager.register_widget_model = function (model_name, model_type) { - // Registers a widget model by name. - WidgetManager._model_types[model_name] = model_type; - - // Register the widget with the comm manager. Make sure to pass this object's context - // in so `this` works in the call back. - _.each(WidgetManager._managers, function(instance, i) { - if (instance.comm_manager !== null) { - instance.comm_manager.register_target(model_name, $.proxy(instance._handle_comm_open, instance)); - } - }); - }; - - WidgetManager.register_widget_view = function (view_name, view_type) { - // Registers a widget view by name. - WidgetManager._view_types[view_name] = view_type; - }; - - //-------------------------------------------------------------------- - // Instance level - //-------------------------------------------------------------------- - WidgetManager.prototype.display_view = function(msg, model) { - // Displays a view for a particular model. - var cell = this.get_msg_cell(msg.parent_header.msg_id); - if (cell === null) { - console.log("Could not determine where the display" + - " message was from. Widget will not be displayed"); - } else { - var view = this.create_view(model, {cell: cell}); - if (view === null) { - console.error("View creation failed", model); - } - if (cell.widget_subarea) { - cell.widget_area.show(); - this._handle_display_view(view); - cell.widget_subarea.append(view.$el); - view.trigger('displayed'); - } +// Copyright (c) IPython Development Team. +// Distributed under the terms of the Modified BSD License. + +define([ + "underscore", + "backbone", + "base/js/namespace" +], function (_, Backbone, IPython) { + + //-------------------------------------------------------------------- + // WidgetManager class + //-------------------------------------------------------------------- + var WidgetManager = function (comm_manager, notebook) { + // Public constructor + WidgetManager._managers.push(this); + + // Attach a comm manager to the + this.keyboard_manager = notebook.keyboard_manager; + this.notebook = notebook; + this.comm_manager = comm_manager; + this._models = {}; /* Dictionary of model ids and model instances */ + + // Register already-registered widget model types with the comm manager. + var that = this; + _.each(WidgetManager._model_types, function(model_type, model_name) { + that.comm_manager.register_target(model_name, $.proxy(that._handle_comm_open, that)); + }); + }; + + //-------------------------------------------------------------------- + // Class level + //-------------------------------------------------------------------- + WidgetManager._model_types = {}; /* Dictionary of model type names (target_name) and model types. */ + WidgetManager._view_types = {}; /* Dictionary of view names and view types. */ + WidgetManager._managers = []; /* List of widget managers */ + + WidgetManager.register_widget_model = function (model_name, model_type) { + // Registers a widget model by name. + WidgetManager._model_types[model_name] = model_type; + + // Register the widget with the comm manager. Make sure to pass this object's context + // in so `this` works in the call back. + _.each(WidgetManager._managers, function(instance, i) { + if (instance.comm_manager !== null) { + instance.comm_manager.register_target(model_name, $.proxy(instance._handle_comm_open, instance)); } - }; - - WidgetManager.prototype._handle_display_view = function (view) { - // Have the IPython keyboard manager disable its event - // handling so the widget can capture keyboard input. - // Note, this is only done on the outer most widgets. - IPython.keyboard_manager.register_events(view.$el); - - if (view.additional_elements) { - for (var i = 0; i < view.additional_elements.length; i++) { - IPython.keyboard_manager.register_events(view.additional_elements[i]); - } - } - }; - - WidgetManager.prototype.create_view = function(model, options, view) { - // Creates a view for a particular model. - var view_name = model.get('_view_name'); - var ViewType = WidgetManager._view_types[view_name]; - if (ViewType) { - - // If a view is passed into the method, use that view's cell as - // the cell for the view that is created. - options = options || {}; - if (view !== undefined) { - options.cell = view.options.cell; - } - - // Create and render the view... - var parameters = {model: model, options: options}; - view = new ViewType(parameters); - view.render(); - model.on('destroy', view.remove, view); - return view; + }); + }; + + WidgetManager.register_widget_view = function (view_name, view_type) { + // Registers a widget view by name. + WidgetManager._view_types[view_name] = view_type; + }; + + //-------------------------------------------------------------------- + // Instance level + //-------------------------------------------------------------------- + WidgetManager.prototype.display_view = function(msg, model) { + // Displays a view for a particular model. + var cell = this.get_msg_cell(msg.parent_header.msg_id); + if (cell === null) { + console.log("Could not determine where the display" + + " message was from. Widget will not be displayed"); + } else { + var view = this.create_view(model, {cell: cell}); + if (view === null) { + console.error("View creation failed", model); } - return null; - }; - - WidgetManager.prototype.get_msg_cell = function (msg_id) { - var cell = null; - // First, check to see if the msg was triggered by cell execution. - if (IPython.notebook) { - cell = IPython.notebook.get_msg_cell(msg_id); + if (cell.widget_subarea) { + cell.widget_area.show(); + this._handle_display_view(view); + cell.widget_subarea.append(view.$el); + view.trigger('displayed'); } - if (cell !== null) { - return cell; + } + }; + + WidgetManager.prototype._handle_display_view = function (view) { + // Have the IPython keyboard manager disable its event + // handling so the widget can capture keyboard input. + // Note, this is only done on the outer most widgets. + if (this.keyboard_manager) { + this.keyboard_manager.register_events(view.$el); + + if (view.additional_elements) { + for (var i = 0; i < view.additional_elements.length; i++) { + this.keyboard_manager.register_events(view.additional_elements[i]); } - // Second, check to see if a get_cell callback was defined - // for the message. get_cell callbacks are registered for - // widget messages, so this block is actually checking to see if the - // message was triggered by a widget. - var kernel = this.comm_manager.kernel; - if (kernel) { - var callbacks = kernel.get_callbacks_for_msg(msg_id); - if (callbacks && callbacks.iopub && - callbacks.iopub.get_cell !== undefined) { - return callbacks.iopub.get_cell(); - } + } + } + }; + + WidgetManager.prototype.create_view = function(model, options, view) { + // Creates a view for a particular model. + var view_name = model.get('_view_name'); + var ViewType = WidgetManager._view_types[view_name]; + if (ViewType) { + + // If a view is passed into the method, use that view's cell as + // the cell for the view that is created. + options = options || {}; + if (view !== undefined) { + options.cell = view.options.cell; } - - // Not triggered by a cell or widget (no get_cell callback - // exists). - return null; - }; - - WidgetManager.prototype.callbacks = function (view) { - // callback handlers specific a view - var callbacks = {}; - if (view && view.options.cell) { - - // Try to get output handlers - var cell = view.options.cell; - var handle_output = null; - var handle_clear_output = null; - if (cell.output_area) { - handle_output = $.proxy(cell.output_area.handle_output, cell.output_area); - handle_clear_output = $.proxy(cell.output_area.handle_clear_output, cell.output_area); - } - - // Create callback dict using what is known - var that = this; - callbacks = { - iopub : { - output : handle_output, - clear_output : handle_clear_output, - - // Special function only registered by widget messages. - // Allows us to get the cell for a message so we know - // where to add widgets if the code requires it. - get_cell : function () { - return cell; - }, - }, - }; + + // Create and render the view... + var parameters = {model: model, options: options}; + view = new ViewType(parameters); + view.render(); + model.on('destroy', view.remove, view); + return view; + } + return null; + }; + + WidgetManager.prototype.get_msg_cell = function (msg_id) { + var cell = null; + // First, check to see if the msg was triggered by cell execution. + if (this.notebook) { + cell = this.notebook.get_msg_cell(msg_id); + } + if (cell !== null) { + return cell; + } + // Second, check to see if a get_cell callback was defined + // for the message. get_cell callbacks are registered for + // widget messages, so this block is actually checking to see if the + // message was triggered by a widget. + var kernel = this.comm_manager.kernel; + if (kernel) { + var callbacks = kernel.get_callbacks_for_msg(msg_id); + if (callbacks && callbacks.iopub && + callbacks.iopub.get_cell !== undefined) { + return callbacks.iopub.get_cell(); } - return callbacks; - }; - - WidgetManager.prototype.get_model = function (model_id) { - // Look-up a model instance by its id. - var model = this._models[model_id]; - if (model !== undefined && model.id == model_id) { - return model; + } + + // Not triggered by a cell or widget (no get_cell callback + // exists). + return null; + }; + + WidgetManager.prototype.callbacks = function (view) { + // callback handlers specific a view + var callbacks = {}; + if (view && view.options.cell) { + + // Try to get output handlers + var cell = view.options.cell; + var handle_output = null; + var handle_clear_output = null; + if (cell.output_area) { + handle_output = $.proxy(cell.output_area.handle_output, cell.output_area); + handle_clear_output = $.proxy(cell.output_area.handle_clear_output, cell.output_area); } - return null; - }; - WidgetManager.prototype._handle_comm_open = function (comm, msg) { - // Handle when a comm is opened. + // Create callback dict using what is known var that = this; - var model_id = comm.comm_id; - var widget_type_name = msg.content.target_name; - var widget_model = new WidgetManager._model_types[widget_type_name](this, model_id, comm); - widget_model.on('comm:close', function () { - delete that._models[model_id]; - }); - this._models[model_id] = widget_model; - }; - - IPython.WidgetManager = WidgetManager; - return IPython.WidgetManager; - }); -}()); + callbacks = { + iopub : { + output : handle_output, + clear_output : handle_clear_output, + + // Special function only registered by widget messages. + // Allows us to get the cell for a message so we know + // where to add widgets if the code requires it. + get_cell : function () { + return cell; + }, + }, + }; + } + return callbacks; + }; + + WidgetManager.prototype.get_model = function (model_id) { + // Look-up a model instance by its id. + var model = this._models[model_id]; + if (model !== undefined && model.id == model_id) { + return model; + } + return null; + }; + + WidgetManager.prototype._handle_comm_open = function (comm, msg) { + // Handle when a comm is opened. + var that = this; + var model_id = comm.comm_id; + var widget_type_name = msg.content.target_name; + var widget_model = new WidgetManager._model_types[widget_type_name](this, model_id, comm); + widget_model.on('comm:close', function () { + delete that._models[model_id]; + }); + this._models[model_id] = widget_model; + }; + + // Backwards compatability. + IPython.WidgetManager = WidgetManager; + + return {'WidgetManager': WidgetManager}; +}); diff --git a/IPython/html/static/widgets/js/widget.js b/IPython/html/static/widgets/js/widget.js index 6c711a96a..92bfcbe4a 100644 --- a/IPython/html/static/widgets/js/widget.js +++ b/IPython/html/static/widgets/js/widget.js @@ -1,23 +1,12 @@ -//---------------------------------------------------------------------------- -// 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. -//---------------------------------------------------------------------------- - -//============================================================================ -// Base Widget Model and View classes -//============================================================================ - -/** - * @module IPython - * @namespace IPython - **/ +// Copyright (c) IPython Development Team. +// Distributed under the terms of the Modified BSD License. define(["widgets/js/manager", "underscore", - "backbone"], -function(WidgetManager, _, Backbone){ + "backbone", + "jquery", + "base/js/namespace", +], function(widgetmanager, _, Backbone, $, IPython){ var WidgetModel = Backbone.Model.extend({ constructor: function (widget_manager, model_id, comm) { @@ -221,20 +210,20 @@ function(WidgetManager, _, Backbone){ _pack_models: function(value) { // Replace models with model ids recursively. + var that = this; + var packed; if (value instanceof Backbone.Model) { return value.id; } else if ($.isArray(value)) { - var packed = []; - var that = this; + packed = []; _.each(value, function(sub_value, key) { packed.push(that._pack_models(sub_value)); }); return packed; } else if (value instanceof Object) { - var packed = {}; - var that = this; + packed = {}; _.each(value, function(sub_value, key) { packed[key] = that._pack_models(sub_value); }); @@ -247,17 +236,17 @@ function(WidgetManager, _, Backbone){ _unpack_models: function(value) { // Replace model ids with models recursively. + var that = this; + var unpacked; if ($.isArray(value)) { - var unpacked = []; - var that = this; + unpacked = []; _.each(value, function(sub_value, key) { unpacked.push(that._unpack_models(sub_value)); }); return unpacked; } else if (value instanceof Object) { - var unpacked = {}; - var that = this; + unpacked = {}; _.each(value, function(sub_value, key) { unpacked[key] = that._unpack_models(sub_value); }); @@ -274,7 +263,7 @@ function(WidgetManager, _, Backbone){ }, }); - WidgetManager.register_widget_model('WidgetModel', WidgetModel); + widgetmanager.WidgetManager.register_widget_model('WidgetModel', WidgetModel); var WidgetView = Backbone.View.extend({ @@ -471,10 +460,14 @@ function(WidgetManager, _, Backbone){ }, }); - IPython.WidgetModel = WidgetModel; - IPython.WidgetView = WidgetView; - IPython.DOMWidgetView = DOMWidgetView; + var widget = { + 'WidgetModel': WidgetModel, + 'WidgetView': WidgetView, + 'DOMWidgetView': DOMWidgetView, + }; + + // For backwards compatability. + $.extend(IPython, widget); - // Pass through WidgetManager namespace. - return WidgetManager; + return widget; }); diff --git a/IPython/html/static/widgets/js/widget_bool.js b/IPython/html/static/widgets/js/widget_bool.js index 8017f9970..5bb86d707 100644 --- a/IPython/html/static/widgets/js/widget_bool.js +++ b/IPython/html/static/widgets/js/widget_bool.js @@ -1,22 +1,13 @@ -//---------------------------------------------------------------------------- -// 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. -//============================================================================ -// BoolWidget -//============================================================================ +define([ + "widgets/js/widget", + "jquery", + "components/bootstrap/js/bootstrap.min", +], function(widget, $){ -/** - * @module IPython - * @namespace IPython - **/ - -define(["widgets/js/widget"], function(WidgetManager){ - - var CheckboxView = IPython.DOMWidgetView.extend({ + var CheckboxView = widget.DOMWidgetView.extend({ render : function(){ // Called when view is rendered. this.$el @@ -68,10 +59,9 @@ define(["widgets/js/widget"], function(WidgetManager){ }, }); - WidgetManager.register_widget_view('CheckboxView', CheckboxView); - var ToggleButtonView = IPython.DOMWidgetView.extend({ + var ToggleButtonView = widget.DOMWidgetView.extend({ render : function() { // Called when view is rendered. var that = this; @@ -122,5 +112,9 @@ define(["widgets/js/widget"], function(WidgetManager){ this.touch(); }, }); - WidgetManager.register_widget_view('ToggleButtonView', ToggleButtonView); + + return { + 'CheckboxView': CheckboxView, + 'ToggleButtonView': ToggleButtonView, + }; }); diff --git a/IPython/html/static/widgets/js/widget_button.js b/IPython/html/static/widgets/js/widget_button.js index 0da9f28b5..071c836fb 100644 --- a/IPython/html/static/widgets/js/widget_button.js +++ b/IPython/html/static/widgets/js/widget_button.js @@ -1,22 +1,13 @@ -//---------------------------------------------------------------------------- -// 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. -//============================================================================ -// ButtonWidget -//============================================================================ +define([ + "widgets/js/widget", + "jquery", + "components/bootstrap/js/bootstrap.min", +], function(widget, $){ -/** - * @module IPython - * @namespace IPython - **/ - -define(["widgets/js/widget"], function(WidgetManager){ - - var ButtonView = IPython.DOMWidgetView.extend({ + var ButtonView = widget.DOMWidgetView.extend({ render : function(){ // Called when view is rendered. this.setElement($("") @@ -56,5 +47,8 @@ define(["widgets/js/widget"], function(WidgetManager){ this.send({event: 'click'}); }, }); - WidgetManager.register_widget_view('ButtonView', ButtonView); + + return { + 'ButtonView': ButtonView, + }; }); diff --git a/IPython/html/static/widgets/js/widget_container.js b/IPython/html/static/widgets/js/widget_container.js index 02bcf03d5..427d3de04 100644 --- a/IPython/html/static/widgets/js/widget_container.js +++ b/IPython/html/static/widgets/js/widget_container.js @@ -1,22 +1,13 @@ -//---------------------------------------------------------------------------- -// 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. -//============================================================================ -// ContainerWidget -//============================================================================ +define([ + "widgets/js/widget", + "jqueryui", + "components/bootstrap/js/bootstrap.min", +], function(widget, $){ -/** - * @module IPython - * @namespace IPython - **/ - -define(["widgets/js/widget"], function(WidgetManager) { - - var ContainerView = IPython.DOMWidgetView.extend({ + var ContainerView = widget.DOMWidgetView.extend({ render: function(){ // Called when view is rendered. this.$el.addClass('widget-container') @@ -73,9 +64,8 @@ define(["widgets/js/widget"], function(WidgetManager) { }, }); - WidgetManager.register_widget_view('ContainerView', ContainerView); - - var PopupView = IPython.DOMWidgetView.extend({ + + var PopupView = widget.DOMWidgetView.extend({ render: function(){ // Called when view is rendered. var that = this; @@ -317,5 +307,9 @@ define(["widgets/js/widget"], function(WidgetManager) { } }, }); - WidgetManager.register_widget_view('PopupView', PopupView); + + return { + 'ContainerView': ContainerView, + 'PopupView': PopupView, + }; }); diff --git a/IPython/html/static/widgets/js/widget_float.js b/IPython/html/static/widgets/js/widget_float.js index 36c2a81a7..b5d808f91 100644 --- a/IPython/html/static/widgets/js/widget_float.js +++ b/IPython/html/static/widgets/js/widget_float.js @@ -1,26 +1,12 @@ -//---------------------------------------------------------------------------- -// 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. -//---------------------------------------------------------------------------- - -//============================================================================ -// FloatWidget -//============================================================================ - -/** - * @module IPython - * @namespace IPython - **/ - -define(["widgets/js/widget", - "widgets/js/widget_int"], - function(WidgetManager, int_widgets){ - - var IntSliderView = int_widgets[0]; - var IntTextView = int_widgets[1]; +// Copyright (c) IPython Development Team. +// Distributed under the terms of the Modified BSD License. +define([ + "widgets/js/widget", + "widgets/js/widget_int", +], function(widget, int_widgets){ + var IntSliderView = int_widgets.IntSliderView; + var IntTextView = int_widgets.IntTextView; var FloatSliderView = IntSliderView.extend({ _validate_slide_value: function(x) { @@ -29,8 +15,6 @@ define(["widgets/js/widget", return x; }, }); - WidgetManager.register_widget_view('FloatSliderView', FloatSliderView); - var FloatTextView = IntTextView.extend({ _parse_value: function(value) { @@ -38,5 +22,9 @@ define(["widgets/js/widget", return parseFloat(value); }, }); - WidgetManager.register_widget_view('FloatTextView', FloatTextView); + + return { + 'FloatSliderView': FloatSliderView, + 'FloatTextView': FloatTextView, + }; }); diff --git a/IPython/html/static/widgets/js/widget_image.js b/IPython/html/static/widgets/js/widget_image.js index c62e18c87..f3a9f1788 100644 --- a/IPython/html/static/widgets/js/widget_image.js +++ b/IPython/html/static/widgets/js/widget_image.js @@ -1,22 +1,12 @@ -//---------------------------------------------------------------------------- -// 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. -//============================================================================ -// ImageWidget -//============================================================================ - -/** - * @module IPython - * @namespace IPython - **/ - -define(["widgets/js/widget"], function(WidgetManager){ - - var ImageView = IPython.DOMWidgetView.extend({ +define([ + "widgets/js/widget", + "jquery", +], function(widget, $){ + + var ImageView = widget.DOMWidgetView.extend({ render : function(){ // Called when view is rendered. this.setElement($("")); @@ -47,5 +37,8 @@ define(["widgets/js/widget"], function(WidgetManager){ return ImageView.__super__.update.apply(this); }, }); - WidgetManager.register_widget_view('ImageView', ImageView); + + return { + 'ImageView': ImageView, + }; }); diff --git a/IPython/html/static/widgets/js/widget_int.js b/IPython/html/static/widgets/js/widget_int.js index 6a9420564..a5fa1968f 100644 --- a/IPython/html/static/widgets/js/widget_int.js +++ b/IPython/html/static/widgets/js/widget_int.js @@ -1,22 +1,13 @@ -//---------------------------------------------------------------------------- -// 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. -//============================================================================ -// IntWidget -//============================================================================ - -/** - * @module IPython - * @namespace IPython - **/ - -define(["widgets/js/widget"], function(WidgetManager){ - - var IntSliderView = IPython.DOMWidgetView.extend({ +define([ + "widgets/js/widget", + "jqueryui", + "components/bootstrap/js/bootstrap.min", +], function(widget, $){ + + var IntSliderView = widget.DOMWidgetView.extend({ render : function(){ // Called when view is rendered. this.$el @@ -152,10 +143,9 @@ define(["widgets/js/widget"], function(WidgetManager){ return ~~x; }, }); - WidgetManager.register_widget_view('IntSliderView', IntSliderView); - var IntTextView = IPython.DOMWidgetView.extend({ + var IntTextView = widget.DOMWidgetView.extend({ render : function(){ // Called when view is rendered. this.$el @@ -257,10 +247,9 @@ define(["widgets/js/widget"], function(WidgetManager){ return parseInt(value); }, }); - WidgetManager.register_widget_view('IntTextView', IntTextView); - var ProgressView = IPython.DOMWidgetView.extend({ + var ProgressView = widget.DOMWidgetView.extend({ render : function(){ // Called when view is rendered. this.$el @@ -303,10 +292,10 @@ define(["widgets/js/widget"], function(WidgetManager){ return ProgressView.__super__.update.apply(this); }, }); - WidgetManager.register_widget_view('ProgressView', ProgressView); - - // Return the slider and text views so they can be inheritted to create the - // float versions. - return [IntSliderView, IntTextView]; + return { + 'IntSliderView': IntSliderView, + 'IntTextView': IntTextView, + 'ProgressView': ProgressView, + }; }); diff --git a/IPython/html/static/widgets/js/widget_selection.js b/IPython/html/static/widgets/js/widget_selection.js index 677d11da6..384cabd4f 100644 --- a/IPython/html/static/widgets/js/widget_selection.js +++ b/IPython/html/static/widgets/js/widget_selection.js @@ -1,22 +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. -//============================================================================ -// SelectionWidget -//============================================================================ +define([ + "widgets/js/widget", + "base/js/utils", + "jquery", + "components/bootstrap/js/bootstrap.min", +], function(widget, utils, $){ -/** - * @module IPython - * @namespace IPython - **/ - -define(["widgets/js/widget"], function(WidgetManager){ - - var DropdownView = IPython.DOMWidgetView.extend({ + var DropdownView = widget.DOMWidgetView.extend({ render : function(){ // Called when view is rendered. this.$el @@ -113,10 +105,9 @@ define(["widgets/js/widget"], function(WidgetManager){ }, }); - WidgetManager.register_widget_view('DropdownView', DropdownView); - var RadioButtonsView = IPython.DOMWidgetView.extend({ + var RadioButtonsView = widget.DOMWidgetView.extend({ render : function(){ // Called when view is rendered. this.$el @@ -204,10 +195,9 @@ define(["widgets/js/widget"], function(WidgetManager){ this.touch(); }, }); - WidgetManager.register_widget_view('RadioButtonsView', RadioButtonsView); + - - var ToggleButtonsView = IPython.DOMWidgetView.extend({ + var ToggleButtonsView = widget.DOMWidgetView.extend({ render : function(){ // Called when view is rendered. this.$el @@ -239,7 +229,7 @@ define(["widgets/js/widget"], function(WidgetManager){ if (item.trim().length == 0) { item_html = " "; } else { - item_html = IPython.utils.escape_html(item); + item_html = utils.escape_html(item); } var item_query = '[data-value="' + item + '"]'; var $item_element = that.$buttongroup.find(item_query); @@ -297,10 +287,9 @@ define(["widgets/js/widget"], function(WidgetManager){ this.touch(); }, }); - WidgetManager.register_widget_view('ToggleButtonsView', ToggleButtonsView); - + - var SelectView = IPython.DOMWidgetView.extend({ + var SelectView = widget.DOMWidgetView.extend({ render : function(){ // Called when view is rendered. this.$el @@ -381,5 +370,11 @@ define(["widgets/js/widget"], function(WidgetManager){ this.touch(); }, }); - WidgetManager.register_widget_view('SelectView', SelectView); + + return { + 'DropdownView': DropdownView, + 'RadioButtonsView': RadioButtonsView, + 'ToggleButtonsView': ToggleButtonsView, + 'SelectView': SelectView, + }; }); diff --git a/IPython/html/static/widgets/js/widget_selectioncontainer.js b/IPython/html/static/widgets/js/widget_selectioncontainer.js index 7dd49e053..14c45b47a 100644 --- a/IPython/html/static/widgets/js/widget_selectioncontainer.js +++ b/IPython/html/static/widgets/js/widget_selectioncontainer.js @@ -1,25 +1,17 @@ -//---------------------------------------------------------------------------- -// 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. -//============================================================================ -// SelectionContainerWidget -//============================================================================ +define([ + "widgets/js/widget", + "base/js/utils", + "jquery", + "components/bootstrap/js/bootstrap.min", +], function(widget, utils, $){ -/** - * @module IPython - * @namespace IPython - **/ - -define(["widgets/js/widget"], function(WidgetManager){ - - var AccordionView = IPython.DOMWidgetView.extend({ + var AccordionView = widget.DOMWidgetView.extend({ render: function(){ // Called when view is rendered. - var guid = 'panel-group' + IPython.utils.uuid(); + var guid = 'panel-group' + utils.uuid(); this.$el .attr('id', guid) .addClass('panel-group'); @@ -99,7 +91,7 @@ define(["widgets/js/widget"], function(WidgetManager){ // Called when a child is added to children list. var view = this.create_child_view(model); var index = this.containers.length; - var uuid = IPython.utils.uuid(); + var uuid = utils.uuid(); var accordion_group = $('') .addClass('panel panel-default') .appendTo(this.$el); @@ -141,10 +133,9 @@ define(["widgets/js/widget"], function(WidgetManager){ } }, }); - WidgetManager.register_widget_view('AccordionView', AccordionView); - var TabView = IPython.DOMWidgetView.extend({ + var TabView = widget.DOMWidgetView.extend({ initialize: function() { // Public constructor. this.containers = []; @@ -153,7 +144,7 @@ define(["widgets/js/widget"], function(WidgetManager){ render: function(){ // Called when view is rendered. - var uuid = 'tabs'+IPython.utils.uuid(); + var uuid = 'tabs'+utils.uuid(); var that = this; this.$tabs = $('', {id: uuid}) .addClass('nav') @@ -201,7 +192,7 @@ define(["widgets/js/widget"], function(WidgetManager){ // Called when a child is added to children list. var view = this.create_child_view(model); var index = this.containers.length; - var uuid = IPython.utils.uuid(); + var uuid = utils.uuid(); var that = this; var tab = $('') @@ -268,5 +259,9 @@ define(["widgets/js/widget"], function(WidgetManager){ this.containers[index].tab('show'); }, }); - WidgetManager.register_widget_view('TabView', TabView); + + return { + 'AccordionView': AccordionView, + 'TabView': TabView, + }; }); diff --git a/IPython/html/static/widgets/js/widget_string.js b/IPython/html/static/widgets/js/widget_string.js index 16608b959..ff09c2627 100644 --- a/IPython/html/static/widgets/js/widget_string.js +++ b/IPython/html/static/widgets/js/widget_string.js @@ -1,22 +1,13 @@ -//---------------------------------------------------------------------------- -// 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. -//============================================================================ -// StringWidget -//============================================================================ +define([ + "widgets/js/widget", + "jquery", + "components/bootstrap/js/bootstrap.min", +], function(widget, $){ -/** - * @module IPython - * @namespace IPython - **/ - -define(["widgets/js/widget"], function(WidgetManager){ - - var HTMLView = IPython.DOMWidgetView.extend({ + var HTMLView = widget.DOMWidgetView.extend({ render : function(){ // Called when view is rendered. this.update(); // Set defaults. @@ -31,10 +22,9 @@ define(["widgets/js/widget"], function(WidgetManager){ return HTMLView.__super__.update.apply(this); }, }); - WidgetManager.register_widget_view('HTMLView', HTMLView); - var LatexView = IPython.DOMWidgetView.extend({ + var LatexView = widget.DOMWidgetView.extend({ render : function(){ // Called when view is rendered. this.update(); // Set defaults. @@ -51,10 +41,9 @@ define(["widgets/js/widget"], function(WidgetManager){ return LatexView.__super__.update.apply(this); }, }); - WidgetManager.register_widget_view('LatexView', LatexView); - var TextareaView = IPython.DOMWidgetView.extend({ + var TextareaView = widget.DOMWidgetView.extend({ render: function(){ // Called when view is rendered. this.$el @@ -136,10 +125,9 @@ define(["widgets/js/widget"], function(WidgetManager){ this.touch(); }, }); - WidgetManager.register_widget_view('TextareaView', TextareaView); - var TextView = IPython.DOMWidgetView.extend({ + var TextView = widget.DOMWidgetView.extend({ render: function(){ // Called when view is rendered. this.$el @@ -244,5 +232,11 @@ define(["widgets/js/widget"], function(WidgetManager){ } }, }); - WidgetManager.register_widget_view('TextView', TextView); + + return { + 'HTMLView': HTMLView, + 'LatexView': LatexView, + 'TextareaView': TextareaView, + 'TextView': TextView, + }; }); diff --git a/IPython/html/templates/login.html b/IPython/html/templates/login.html index 9fab790bd..44dd212f9 100644 --- a/IPython/html/templates/login.html +++ b/IPython/html/templates/login.html @@ -46,6 +46,7 @@ {% block script %} +{{super()}} diff --git a/IPython/html/templates/logout.html b/IPython/html/templates/logout.html index 35c65c570..91595aacb 100644 --- a/IPython/html/templates/logout.html +++ b/IPython/html/templates/logout.html @@ -32,6 +32,7 @@ {% endblock %} {% block script %} +{{super()}} diff --git a/IPython/html/templates/notebook.html b/IPython/html/templates/notebook.html index acd51b241..1193a8fa6 100644 --- a/IPython/html/templates/notebook.html +++ b/IPython/html/templates/notebook.html @@ -293,10 +293,8 @@ class="notebook_app" {% block script %} - {{super()}} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + {% endblock %} diff --git a/IPython/html/templates/page.html b/IPython/html/templates/page.html index 536f94572..512898fd3 100644 --- a/IPython/html/templates/page.html +++ b/IPython/html/templates/page.html @@ -20,8 +20,12 @@ baseUrl: '{{static_url("", include_version=False)}}', paths: { nbextensions : '{{ base_url }}nbextensions', - underscore : '{{static_url("components/underscore/underscore-min.js")}}', - backbone : '{{static_url("components/backbone/backbone-min.js")}}', + underscore : 'components/underscore/underscore-min', + backbone : 'components/backbone/backbone-min', + jquery: 'components/jquery/jquery.min', + bootstraptour: 'components/bootstrap-tour/build/js/bootstrap-tour.min', + dateformat: 'dateformat/date.format', + jqueryui: 'components/jquery-ui/ui/minified/jquery-ui.min', }, shim: { underscore: { @@ -30,6 +34,16 @@ backbone: { deps: ["underscore", "jquery"], exports: "Backbone" + }, + bootstraptour: { + exports: "Tour" + }, + dateformat: { + exports: "dateFormat" + }, + jqueryui: { + deps: ["jquery"], + exports: "$" } } }); @@ -75,14 +89,8 @@ {% endblock %}