From ca2014ad06fd1285718d3a80a8f5c62ece256599 Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Fri, 13 Jun 2014 12:56:32 -0700 Subject: [PATCH] Pager --- IPython/html/static/notebook/js/main.js | 14 +++++--- IPython/html/static/notebook/js/notebook.js | 10 ++---- IPython/html/static/notebook/js/pager.js | 9 ++--- IPython/html/static/notebook/js/quickhelp.js | 37 ++++++++++---------- 4 files changed, 34 insertions(+), 36 deletions(-) diff --git a/IPython/html/static/notebook/js/main.js b/IPython/html/static/notebook/js/main.js index 5ab7e820a..5a8972290 100644 --- a/IPython/html/static/notebook/js/main.js +++ b/IPython/html/static/notebook/js/main.js @@ -16,6 +16,7 @@ require([ 'notebook/js/quickhelp', 'notebook/js/menubar', 'notebook/js/notificationarea', + 'notebook/js/keyboardmanager', ], function( IPython, $, @@ -29,7 +30,8 @@ require([ Pager, QuickHelp, MenuBar, - NotificationArea + NotificationArea, + KeyboardManager ) { "use strict"; @@ -44,13 +46,14 @@ require([ page = new Page(); layout_manager = new LayoutManager(); - pager = new Pager('div#pager', 'div#pager_splitter', layout_manager); - layout_manager.pager = pager; + keyboard_manager = new KeyboardManager(); events = $([new Events()]); - notebook = new Notebook('div#notebook', opts, events); + pager = new Pager('div#pager', 'div#pager_splitter', layout_manager, events); + layout_manager.pager = pager; + notebook = new Notebook('div#notebook', opts, events, keyboard_manager); login_widget = new LoginWidget('span#login_widget', opts); toolbar = new MainToolBar('#maintoolbar-container', notebook, events); - quick_help = new QuickHelp(); + quick_help = new QuickHelp(undefined, keyboard_manager, events); menubar = new MenuBar('#menubar', opts); notification_area = new NotificationArea('#notification_area'); @@ -98,4 +101,5 @@ require([ ipython.toolbar = toolbar; ipython.notification_area = notification_area; ipython.events = events; + ipython.keyboard_manager = keyboard_manager; }); diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index 68426ae22..1fe241233 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -5,9 +5,7 @@ define([ 'base/js/namespace', 'components/jquery/jquery.min', 'base/js/utils', - 'notebook/js/keyboardmanager', 'notebook/js/savewidget', - 'base/js/events', 'base/js/dialog', 'notebook/js/textcell', 'notebook/js/codecell', @@ -23,9 +21,7 @@ define([ IPython, $, Utils, - KeyboardManager, SaveWidget, - Events, Dialog, Cells, CodeCell, @@ -45,9 +41,9 @@ define([ * @param {Object} [options] A config object * @param {Object} [events] An events object */ - var Notebook = function (selector, options, events) { - this.events = events || $([new Events()]); - this.keyboard_manager = new KeyboardManager(); + var Notebook = function (selector, options, events, keyboard_manager) { + this.events = events; + this.keyboard_manager = keyboard_manager; this.keyboard = new Keyboard(); this.save_widget = new SaveWidget('span#save_widget'); diff --git a/IPython/html/static/notebook/js/pager.js b/IPython/html/static/notebook/js/pager.js index dcc10c2fe..08dea0a2b 100644 --- a/IPython/html/static/notebook/js/pager.js +++ b/IPython/html/static/notebook/js/pager.js @@ -4,13 +4,10 @@ define([ 'base/js/namespace', 'components/jquery/jquery.min', - 'notebook/js/toolbar', - 'notebook/js/celltoolbar', -], function(IPython, $, Toolbar, CellToolbar) { + 'base/js/utils', +], function(IPython, $, Utils) { "use strict"; - var utils = IPython.utils; - var Pager = function (pager_selector, pager_splitter_selector, layout_manager, events) { this.events = events; this.pager_element = $(pager_selector); @@ -170,7 +167,7 @@ define([ Pager.prototype.append_text = function (text) { // The only user content injected with this HTML call is escaped by // the fixConsole() method. - this.pager_element.find(".container").append($('
').html(utils.fixCarriageReturn(utils.fixConsole(text))));
+        this.pager_element.find(".container").append($('
').html(Utils.fixCarriageReturn(Utils.fixConsole(text))));
     };
 
     // Backwards compatability.
diff --git a/IPython/html/static/notebook/js/quickhelp.js b/IPython/html/static/notebook/js/quickhelp.js
index 1b80698ce..2873a412f 100644
--- a/IPython/html/static/notebook/js/quickhelp.js
+++ b/IPython/html/static/notebook/js/quickhelp.js
@@ -1,16 +1,18 @@
 // Copyright (c) IPython Development Team.
 // Distributed under the terms of the Modified BSD License.
 
-//============================================================================
-// QuickHelp button
-//============================================================================
-
-var IPython = (function (IPython) {
+define([
+    'base/js/namespace',
+    'components/jquery/jquery.min',
+    'base/js/utils',
+    'base/js/dialog',
+], function(IPython, $, Utils, Dialog) {
     "use strict";
+    var platform = Utils.platform;
 
-    var platform = IPython.utils.platform;
-
-    var QuickHelp = function (selector) {
+    var QuickHelp = function (selector, keyboard_manager, events) {
+        this.keyboard_manager = keyboard_manager;
+        this.events = events;
     };
 
     var cmd_ctrl = 'Ctrl-';
@@ -70,8 +72,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 = keyboard_manager.command_shortcuts.help();
+        var edit_shortcuts = keyboard_manager.edit_shortcuts.help();
         var help, shortcut;
         var i, half, n;
         var element = $('
'); @@ -96,7 +98,7 @@ 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, @@ -106,11 +108,11 @@ var IPython = (function (IPython) { }); 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 = keyboard_manager.command_shortcuts.help(); return build_div('

Command Mode (press Esc to enable)

', command_shortcuts); }; @@ -134,7 +136,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 = keyboard_manager.edit_shortcuts.help(); jQuery.merge(cm_shortcuts, edit_shortcuts); return build_div('

Edit Mode (press Enter to enable)

', cm_shortcuts); }; @@ -163,9 +165,8 @@ var IPython = (function (IPython) { return div; }; - // Set module variables + // Backwards compatability. IPython.QuickHelp = QuickHelp; - return IPython; - -}(IPython)); + return QuickHelp; +});