From e117f31645c28e43c28a8692c7e81c7882e8f5ed 2014-07-10 20:47:23 From: Jonathan Frederic Date: 2014-07-10 20:47:23 Subject: [PATCH] Some JS test fixes --- diff --git a/IPython/html/static/base/js/dialog.js b/IPython/html/static/base/js/dialog.js index c4d6c11..c3ea0fc 100644 --- a/IPython/html/static/base/js/dialog.js +++ b/IPython/html/static/base/js/dialog.js @@ -7,7 +7,8 @@ define([ ], function(IPython, $) { "use strict"; - var modal = function (options, keyboard_manager, notebook) { + var modal = function (options) { + var modal = $("
") .addClass("modal") .addClass("fade") @@ -72,16 +73,18 @@ define([ }); } modal.on("hidden.bs.modal", function () { - if (notebook) { - var cell = notebook.get_selected_cell(); + if (options.notebook) { + var cell = options.notebook.get_selected_cell(); if (cell) cell.select(); - keyboard_manager.enable(); - keyboard_manager.command_mode(); + if (options.keyboard_manager) { + options.keyboard_manager.enable(); + options.keyboard_manager.command_mode(); + } } }); - if (keyboard_manager) { - keyboard_manager.disable(); + if (options.keyboard_manager) { + options.keyboard_manager.disable(); } return modal.modal(options); diff --git a/IPython/html/static/base/js/security.js b/IPython/html/static/base/js/security.js index 97121f7..c8301f1 100644 --- a/IPython/html/static/base/js/security.js +++ b/IPython/html/static/base/js/security.js @@ -110,8 +110,12 @@ define([ return sanitized; }; - return { + var security = { caja: caja, sanitize_html: sanitize_html }; + + IPython.security = security; + + return security; }); diff --git a/IPython/html/static/notebook/js/main.js b/IPython/html/static/notebook/js/main.js index 6f7a2b8..0824a06 100644 --- a/IPython/html/static/notebook/js/main.js +++ b/IPython/html/static/notebook/js/main.js @@ -1,12 +1,12 @@ // Copyright (c) IPython Development Team. // Distributed under the terms of the Modified BSD License. -var ipython = ipython || {}; require([ 'base/js/namespace', 'jquery', 'notebook/js/notebook', 'base/js/utils', + 'base/js/keyboard', 'base/js/page', 'notebook/js/layoutmanager', 'base/js/events', @@ -24,6 +24,7 @@ require([ $, notebook, utils, + keyboard, page, layoutmanager, events, @@ -71,7 +72,8 @@ require([ events: events}); var quick_help = new quickhelp.QuickHelp({ keyboard_manager: keyboard_manager, - events: events}); + events: events, + notebook: notebook}); var menubar = new menubar.MenuBar('#menubar', $.extend({ notebook: notebook, layout_manager: layout_manager, @@ -83,7 +85,8 @@ require([ '#notification_area', { events: events, save_widget: save_widget, - notebook: notebook}); + notebook: notebook, + keyboard_manager: keyboard_manager}); notification_area.init_notification_widgets(); $('body').append('
x'+
@@ -116,17 +119,18 @@ require([
     events.trigger('app_initialized.NotebookApp');
     notebook.load_notebook(common_options.notebook_name, common_options.notebook_path);
 
-    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.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.keyboard = keyboard;
 });
diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js
index f7aaee5..b6251e2 100644
--- a/IPython/html/static/notebook/js/notebook.js
+++ b/IPython/html/static/notebook/js/notebook.js
@@ -190,6 +190,8 @@ define([
 
         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: {
@@ -1476,10 +1478,10 @@ define([
      * @method start_session
      */
     Notebook.prototype.start_session = function () {
-        this.session = new session.Session(this, {
-            base_url: base_url,
-            notebook_path: notebook_path,
-            notebook_name: notebook_name,
+        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));
     };
@@ -1509,6 +1511,8 @@ define([
     Notebook.prototype.restart_kernel = function () {
         var that = this;
         dialog.modal({
+            notebook: this,
+            keyboard_manager: this.keyboard_manager,
             title : "Restart kernel or continue running?",
             body : $("

").text( 'Do you want to restart the current kernel? You will lose all variables defined in it.' @@ -1732,6 +1736,8 @@ define([ } if (content.worksheets.length > 1) { 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. " + @@ -1920,6 +1926,8 @@ define([ var nb = this; dialog.modal({ + notebook: this, + keyboard_manager: this.keyboard_manager, title: "Trust this notebook?", body: body, @@ -2065,6 +2073,8 @@ define([ ); 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, buttons : { @@ -2146,6 +2156,8 @@ define([ "may not be able to read it. To keep the older version, close the " + "notebook without saving it."; dialog.modal({ + notebook: this, + keyboard_manager: this.keyboard_manager, title : "Notebook converted", body : msg, buttons : { @@ -2163,6 +2175,8 @@ define([ "introduced in later notebook versions may not be available."; dialog.modal({ + notebook: this, + keyboard_manager: this.keyboard_manager, title : "Newer Notebook", body : msg, buttons : { @@ -2214,6 +2228,8 @@ define([ "v" + this.nbformat + " or earlier."; } dialog.modal({ + notebook: this, + keyboard_manager: this.keyboard_manager, title: "Error loading notebook", body : msg, buttons : { @@ -2378,6 +2394,8 @@ define([ ); dialog.modal({ + notebook: this, + keyboard_manager: this.keyboard_manager, title : "Revert notebook to checkpoint", body : body, buttons : { diff --git a/IPython/html/static/notebook/js/notificationarea.js b/IPython/html/static/notebook/js/notificationarea.js index 11d03bd..0fad72b 100644 --- a/IPython/html/static/notebook/js/notificationarea.js +++ b/IPython/html/static/notebook/js/notificationarea.js @@ -24,6 +24,7 @@ define([ 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); } @@ -135,6 +136,8 @@ define([ dialog.modal({ title: "Dead kernel", body : msg, + keyboard_manager: that.keyboard_manager, + notebook: that.notebook, buttons : { "Manual Restart": { class: "btn-danger", @@ -167,6 +170,8 @@ define([ dialog.modal({ title: "WebSocket connection failed", body: msg, + keyboard_manager: that.keyboard_manager, + notebook: that.notebook, buttons : { "OK": {}, "Reconnect": { diff --git a/IPython/html/static/notebook/js/quickhelp.js b/IPython/html/static/notebook/js/quickhelp.js index fff4f35..4bc179a 100644 --- a/IPython/html/static/notebook/js/quickhelp.js +++ b/IPython/html/static/notebook/js/quickhelp.js @@ -18,7 +18,9 @@ define([ // 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; }; @@ -112,7 +114,9 @@ define([ destroy : false, buttons : { Close : {} - } + }, + notebook: this.notebook, + keyboard_manager: this.keyboard_manager, }); this.shortcut_dialog.addClass("modal_stretch"); diff --git a/IPython/html/static/notebook/js/textcell.js b/IPython/html/static/notebook/js/textcell.js index 8f2755c..393a9fb 100644 --- a/IPython/html/static/notebook/js/textcell.js +++ b/IPython/html/static/notebook/js/textcell.js @@ -44,7 +44,7 @@ define([ Cell.apply(this, [{ config: config, keyboard_manager: options.keyboard_manager, - events: events}]); + events: this.events}]); this.cell_type = this.cell_type || 'text'; mathjaxutils = mathjaxutils; diff --git a/IPython/html/static/notebook/js/tour.js b/IPython/html/static/notebook/js/tour.js index 0059319..dcd4e34 100644 --- a/IPython/html/static/notebook/js/tour.js +++ b/IPython/html/static/notebook/js/tour.js @@ -4,7 +4,7 @@ define([ 'base/js/namespace', 'jquery', - 'components/bootstrap-tour/build/js/bootstrap-tour.min', + 'bootstraptour', ], function(IPython, $, Tour) { "use strict"; diff --git a/IPython/html/static/services/sessions/js/session.js b/IPython/html/static/services/sessions/js/session.js index 9d53d00..1cfb1a9 100644 --- a/IPython/html/static/services/sessions/js/session.js +++ b/IPython/html/static/services/sessions/js/session.js @@ -13,9 +13,9 @@ define([ this.kernel = null; this.id = null; this.notebook = options.notebook; - this.name = notebook.notebook_name; - this.path = notebook.notebook_path; - this.base_url = notebook.base_url; + this.name = options.notebook_name; + this.path = options.notebook_path; + this.base_url = options.base_url; }; Session.prototype.start = function(callback) { diff --git a/IPython/html/templates/page.html b/IPython/html/templates/page.html index 9321b14..a693ac0 100644 --- a/IPython/html/templates/page.html +++ b/IPython/html/templates/page.html @@ -23,6 +23,7 @@ underscore : 'components/underscore/underscore-min', backbone : 'components/backbone/backbone-min', jquery: 'components/jquery/jquery.min', + bootstraptour: 'components/bootstrap-tour/build/js/bootstrap-tour.min', }, shim: { underscore: { @@ -31,6 +32,9 @@ backbone: { deps: ["underscore", "jquery"], exports: "Backbone" + }, + bootstraptour: { + exports: "Tour" } } }); diff --git a/IPython/html/tests/util.js b/IPython/html/tests/util.js index 8523496..a184bc8 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,11 +20,13 @@ 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._status = 'idle'; $([IPython.events]).on('status_idle.Kernel',function () { IPython._status = 'idle'; }); @@ -42,9 +45,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 +515,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(); };