diff --git a/IPython/html/static/notebook/js/cell.js b/IPython/html/static/notebook/js/cell.js index 05562a1..13bd925 100644 --- a/IPython/html/static/notebook/js/cell.js +++ b/IPython/html/static/notebook/js/cell.js @@ -38,23 +38,24 @@ define([ * @param {object|undefined} [options] * @param [options.cm_config] {object} config to pass to CodeMirror, will extend default parameters */ - var Cell = function (options, keyboard_manager, events) { - this.keyboard_manager = keyboard_manager; - this.events = events; - options = this.mergeopt(Cell, options); + var Cell = function (options) { + options = options || {}; + this.keyboard_manager = options.keyboard_manager; + this.events = options.events; + var config = this.mergeopt(Cell, options.config); // superclass default overwrite our default - this.placeholder = options.placeholder || ''; - this.read_only = options.cm_config.readOnly; + this.placeholder = config.placeholder || ''; + this.read_only = config.cm_config.readOnly; this.selected = false; this.rendered = false; this.mode = 'command'; this.metadata = {}; // load this from metadata later ? this.user_highlight = 'auto'; - this.cm_config = options.cm_config; + this.cm_config = config.cm_config; this.cell_id = utils.uuid(); - this._options = options; + this._options = config; // For JS VM engines optimization, attributes should be all set (even // to null) in the constructor, and if possible, if different subclass diff --git a/IPython/html/static/notebook/js/codecell.js b/IPython/html/static/notebook/js/codecell.js index b5a63ef..3869d7a 100644 --- a/IPython/html/static/notebook/js/codecell.js +++ b/IPython/html/static/notebook/js/codecell.js @@ -54,13 +54,14 @@ define([ * @param {object|undefined} [options] * @param [options.cm_config] {object} config to pass to CodeMirror */ - var CodeCell = function (kernel, options, events, config, keyboard_manager, notebook) { + var CodeCell = function (kernel, options) { + options = options || {}; this.kernel = kernel || null; - this.notebook = notebook; + this.notebook = options.notebook; this.collapsed = false; - this.tooltip = new tooltip.Tooltip(events); - this.events = events; - this.config = config; + this.events = options.events; + this.tooltip = new tooltip.Tooltip(this.events); + this.config = options.config; // create all attributed in constructor function // even if null for V8 VM optimisation @@ -75,9 +76,11 @@ define([ onKeyEvent: $.proxy(this.handle_keyevent,this) }; - options = this.mergeopt(CodeCell, options, {cm_config:cm_overwrite_options}); - - Cell.apply(this,[options, keyboard_manager, events]); + var config = this.mergeopt(CodeCell, this.config, {cm_config: cm_overwrite_options}); + Cell.apply(this,[{ + config: config, + keyboard_manager: options.keyboard_manager, + events: this.events}]); // Attributes we want to override in this subclass. this.cell_type = "code"; diff --git a/IPython/html/static/notebook/js/keyboardmanager.js b/IPython/html/static/notebook/js/keyboardmanager.js index 519a41f..dad667d 100644 --- a/IPython/html/static/notebook/js/keyboardmanager.js +++ b/IPython/html/static/notebook/js/keyboardmanager.js @@ -15,17 +15,17 @@ define([ // Main keyboard manager for the notebook var keycodes = keyboard.keycodes; - var KeyboardManager = function (pager, events) { + var KeyboardManager = function (options) { this.mode = 'command'; this.enabled = true; - this.pager = pager; + this.pager = options.pager; this.quick_help = undefined; this.notebook = undefined; this.bind_events(); - this.command_shortcuts = new keyboard.ShortcutManager(undefined, events); + this.command_shortcuts = new keyboard.ShortcutManager(undefined, options.events); this.command_shortcuts.add_shortcuts(this.get_default_common_shortcuts()); this.command_shortcuts.add_shortcuts(this.get_default_command_shortcuts()); - this.edit_shortcuts = new keyboard.ShortcutManager(undefined, events); + this.edit_shortcuts = new keyboard.ShortcutManager(undefined, options.events); this.edit_shortcuts.add_shortcuts(this.get_default_common_shortcuts()); this.edit_shortcuts.add_shortcuts(this.get_default_edit_shortcuts()); }; diff --git a/IPython/html/static/notebook/js/main.js b/IPython/html/static/notebook/js/main.js index 53e1d93..6f7a2b8 100644 --- a/IPython/html/static/notebook/js/main.js +++ b/IPython/html/static/notebook/js/main.js @@ -42,7 +42,7 @@ require([ $('#ipython-main-app').addClass('border-box-sizing'); $('div#notebook_panel').addClass('border-box-sizing'); - var options = { + var common_options = { base_url : utils.get_body_data("baseUrl"), notebook_path : utils.get_body_data("notebookPath"), notebook_name : utils.get_body_data('notebookName') @@ -52,15 +52,38 @@ require([ var page = new page.Page(); var layout_manager = new layoutmanager.LayoutManager(); var events = $([new events.Events()]); - var pager = new pager.Pager('div#pager', 'div#pager_splitter', layout_manager, events); - var keyboard_manager = new keyboardmanager.KeyboardManager(pager, events); + var pager = new pager.Pager('div#pager', 'div#pager_splitter', { + layout_manager: layout_manager, + events: events}); + var keyboard_manager = new keyboardmanager.KeyboardManager({ + pager: pager, + events: events}); var save_widget = new savewidget.SaveWidget('span#save_widget', events); - var notebook = new notebook.Notebook('div#notebook', options, events, keyboard_manager, save_widget, user_config); - var login_widget = new loginwidget.LoginWidget('span#login_widget', options); - var toolbar = new maintoolbar.MainToolBar('#maintoolbar-container', layout_manager, notebook, events); - var quick_help = new quickhelp.QuickHelp(undefined, keyboard_manager, events); - var menubar = new menubar.MenuBar('#menubar', options, notebook, layout_manager, events, save_widget, quick_help); - var notification_area = new notificationarea.NotificationArea('#notification_area', events, save_widget, notebook); + var notebook = new notebook.Notebook('div#notebook', $.extend({ + events: events, + keyboard_manager: keyboard_manager, + save_widget: save_widget, + config: user_config}, + common_options)); + var login_widget = new loginwidget.LoginWidget('span#login_widget', common_options); + var toolbar = new maintoolbar.MainToolBar('#maintoolbar-container', { + notebook: notebook, + events: events}); + var quick_help = new quickhelp.QuickHelp({ + keyboard_manager: keyboard_manager, + events: events}); + var menubar = new menubar.MenuBar('#menubar', $.extend({ + notebook: notebook, + layout_manager: layout_manager, + events: events, + save_widget: save_widget, + quick_help: quick_help}, + common_options)); + var notification_area = new notificationarea.NotificationArea( + '#notification_area', { + events: events, + save_widget: save_widget, + notebook: notebook}); notification_area.init_notification_widgets(); $('body').append('<div id="fonttest"><pre><span id="test1">x</span>'+ @@ -91,7 +114,7 @@ require([ events.on('notebook_loaded.Notebook', first_load); events.trigger('app_initialized.NotebookApp'); - notebook.load_notebook(options.notebook_name, options.notebook_path); + notebook.load_notebook(common_options.notebook_name, common_options.notebook_path); ipython.page = page; ipython.layout_manager = layout_manager; diff --git a/IPython/html/static/notebook/js/maintoolbar.js b/IPython/html/static/notebook/js/maintoolbar.js index f899f7d..e14e93f 100644 --- a/IPython/html/static/notebook/js/maintoolbar.js +++ b/IPython/html/static/notebook/js/maintoolbar.js @@ -9,10 +9,10 @@ define([ ], function(IPython, $, toolbar, celltoolbar) { "use strict"; - var MainToolBar = function (selector, layout_manager, notebook, events) { + var MainToolBar = function (selector, options) { toolbar.ToolBar.apply(this, arguments); - this.events = events; - this.notebook = notebook; + this.events = options.events; + this.notebook = options.notebook; this.construct(); this.add_celltype_list(); this.add_celltoolbar_list(); diff --git a/IPython/html/static/notebook/js/menubar.js b/IPython/html/static/notebook/js/menubar.js index c0d79dd..9698d58 100644 --- a/IPython/html/static/notebook/js/menubar.js +++ b/IPython/html/static/notebook/js/menubar.js @@ -24,18 +24,18 @@ define([ * $('body').data('baseUrl'); * does not support change for now is set through this option */ - var MenuBar = function (selector, options, notebook, layout_manager, events, save_widget, quick_help) { + var MenuBar = function (selector, options) { options = options || {}; this.base_url = options.base_url || utils.get_body_data("baseUrl"); this.selector = selector; - this.notebook = notebook; - this.layout_manager = layout_manager; - this.events = events; - this.save_widget = save_widget; - this.quick_help = quick_help; + 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(notebook, events); + this.tour = new tour.Tour(this.notebook, this.events); } catch (e) { this.tour = undefined; console.log("Failed to instantiate Notebook Tour", e); diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index 0a190b3..6389862 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -38,15 +38,18 @@ define([ * @param {Object} [options] A config object * @param {Object} [events] An events object */ - var Notebook = function (selector, options, events, keyboard_manager, save_widget, config) { - this.config = config; - this.events = events; - this.keyboard_manager = keyboard_manager; + var Notebook = function (selector, options) { + 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; // TODO: This code smells (and the other `= this` line a couple lines down) // We need a better way to deal with circular instance references. - keyboard_manager.notebook = this; - this.save_widget = save_widget; - save_widget.notebook = this; + this.keyboard_manager.notebook = this; + this.save_widget.notebook = this; mathjaxutils.init(); @@ -76,10 +79,6 @@ define([ IPython.save_widget = this.save_widget; IPython.keyboard = this.keyboard; - this.options = options = options || {}; - this.base_url = options.base_url; - this.notebook_path = options.notebook_path; - this.notebook_name = options.notebook_name; this.element = $(selector); this.element.scroll(); this.element.data("notebook", this); @@ -806,15 +805,24 @@ define([ type = type || this.get_selected_cell().cell_type; if (ncells === 0 || this.is_valid_cell_index(index) || index === ncells) { + var cell_options = { + base_url: base_url, + notebook_path: notebook_path, + notebook_name: notebook_name, + events: this.events, + config: this.config, + keyboard_manager: this.keyboard_manager, + notebook: this + }; if (type === 'code') { - cell = new codecell.CodeCell(this.kernel, this.options, this.events, this.config, this.keyboard_manager, this); + cell = new codecell.CodeCell(this.kernel, cell_options); cell.set_input_prompt(); } else if (type === 'markdown') { - cell = new cells.MarkdownCell(this.options, this.events, this.config, this.keyboard_manager, this); + cell = new cells.MarkdownCell(cell_options); } else if (type === 'raw') { - cell = new cells.RawCell(this.options, this.events, this.config, this.keyboard_manager, this); + cell = new cells.RawCell(cell_options); } else if (type === 'heading') { - cell = new cells.HeadingCell(this.options, this.events, this.config, this.keyboard_manager, this); + cell = new cells.HeadingCell(cell_options); } if(this._insert_element_at_index(cell.element,index)) { @@ -1465,7 +1473,11 @@ define([ * @method start_session */ Notebook.prototype.start_session = function () { - this.session = new session.Session(this, this.options); + this.session = new session.Session(this, { + base_url: base_url, + notebook_path: notebook_path, + notebook_name: notebook_name, + notebook: this}); this.session.start($.proxy(this._session_started, this)); }; diff --git a/IPython/html/static/notebook/js/notificationarea.js b/IPython/html/static/notebook/js/notificationarea.js index 563615f..59d3a8c 100644 --- a/IPython/html/static/notebook/js/notificationarea.js +++ b/IPython/html/static/notebook/js/notificationarea.js @@ -10,11 +10,11 @@ define([ ], function(IPython, $, utils, dialog, notificationwidget) { "use strict"; - var NotificationArea = function (selector, events, save_widget, notebook) { + var NotificationArea = function (selector, options) { this.selector = selector; - this.events = events; - this.save_widget = save_widget; - this.notebook = notebook; + this.events = options.events; + this.save_widget = options.save_widget; + this.notebook = options.notebook; if (this.selector !== undefined) { this.element = $(selector); } diff --git a/IPython/html/static/notebook/js/pager.js b/IPython/html/static/notebook/js/pager.js index 034e2b3..744f339 100644 --- a/IPython/html/static/notebook/js/pager.js +++ b/IPython/html/static/notebook/js/pager.js @@ -8,13 +8,13 @@ define([ ], function(IPython, $, utils) { "use strict"; - var Pager = function (pager_selector, pager_splitter_selector, layout_manager, events) { - this.events = events; + var Pager = function (pager_selector, pager_splitter_selector, options) { + this.events = options.events; this.pager_element = $(pager_selector); this.pager_button_area = $('#pager_button_area'); var that = this; this.percentage_height = 0.40; - layout_manager.pager = this; + options.layout_manager.pager = this; this.pager_splitter_element = $(pager_splitter_selector) .draggable({ containment: 'window', @@ -23,7 +23,7 @@ define([ drag: function(event, ui) { // recalculate the amount of space the pager should take var pheight = ($(document.body).height()-event.clientY-4); - var downprct = pheight/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 +32,7 @@ define([ that.percentage_height = downprct; that.expand({'duration':0}); } - layout_manager.do_resize(); + options.layout_manager.do_resize(); } }); this.expanded = false; diff --git a/IPython/html/static/notebook/js/quickhelp.js b/IPython/html/static/notebook/js/quickhelp.js index 316208d..aecf961 100644 --- a/IPython/html/static/notebook/js/quickhelp.js +++ b/IPython/html/static/notebook/js/quickhelp.js @@ -10,10 +10,10 @@ define([ "use strict"; var platform = utils.platform; - var QuickHelp = function (selector, keyboard_manager, events) { - this.keyboard_manager = keyboard_manager; - keyboard_manager.quick_help = this; - this.events = events; + var QuickHelp = function (options) { + this.keyboard_manager = options.keyboard_manager; + this.keyboard_manager.quick_help = this; + this.events = options.events; }; var cmd_ctrl = 'Ctrl-'; diff --git a/IPython/html/static/notebook/js/textcell.js b/IPython/html/static/notebook/js/textcell.js index f1db79a..1eb3f57 100644 --- a/IPython/html/static/notebook/js/textcell.js +++ b/IPython/html/static/notebook/js/textcell.js @@ -24,27 +24,28 @@ define([ * @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, events, config, keyboard_manager, notebook) { + var TextCell = function (options) { + 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 = notebook; - this.events = events; - this.config = config; + 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: events}]); this.cell_type = this.cell_type || 'text'; mathjaxutils = mathjaxutils; - - Cell.apply(this, [options, keyboard_manager, events]); - this.rendered = false; }; @@ -218,11 +219,12 @@ define([ * @constructor MarkdownCell * @extends IPython.HTMLCell */ - var MarkdownCell = function (options, events, config, keyboard_manager) { - options = this.mergeopt(MarkdownCell, options); + var MarkdownCell = function (options) { + options = options || {}; + var config = this.mergeopt(MarkdownCell, options.config); + TextCell.apply(this, [$.extend({}, options, {config: config})]); this.cell_type = 'markdown'; - TextCell.apply(this, [options, events, config, keyboard_manager]); }; MarkdownCell.options_default = { @@ -268,13 +270,14 @@ define([ * @constructor RawCell * @extends TextCell */ - var RawCell = function (options, events, config, keyboard_manager) { + var RawCell = function (options) { + 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, events, config, keyboard_manager]); - 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 = { @@ -327,17 +330,13 @@ define([ * @constructor HeadingCell * @extends TextCell */ - var HeadingCell = function (options, events, config, keyboard_manager) { - options = this.mergeopt(HeadingCell, options); + var HeadingCell = function (options) { + 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, events, config, keyboard_manager]); - - /** - * heading level of the cell, use getter and setter to access - * @property level - */ }; HeadingCell.options_default = { diff --git a/IPython/html/static/services/sessions/js/session.js b/IPython/html/static/services/sessions/js/session.js index 6e791e0..9d53d00 100644 --- a/IPython/html/static/services/sessions/js/session.js +++ b/IPython/html/static/services/sessions/js/session.js @@ -9,10 +9,10 @@ define([ ], function(IPython, $, utils, kernel) { "use strict"; - var Session = function(notebook, options){ + var Session = function(options){ this.kernel = null; this.id = null; - this.notebook = notebook; + this.notebook = options.notebook; this.name = notebook.notebook_name; this.path = notebook.notebook_path; this.base_url = notebook.base_url; diff --git a/IPython/html/static/tree/js/kernellist.js b/IPython/html/static/tree/js/kernellist.js index b2e4e70..62305b7 100644 --- a/IPython/html/static/tree/js/kernellist.js +++ b/IPython/html/static/tree/js/kernellist.js @@ -8,8 +8,10 @@ define([ ], function(IPython, $, notebooklist) { "use strict"; - var KernelList = function (selector, options, session_list) { - notebooklist.NotebookList.call(this, selector, options, 'running', session_list); + var KernelList = function (selector, options) { + notebooklist.NotebookList.call(this, selector, $.extend({ + element_name: 'running'}, + options)); }; KernelList.prototype = Object.create(notebooklist.NotebookList.prototype); diff --git a/IPython/html/static/tree/js/main.js b/IPython/html/static/tree/js/main.js index c93bb1d..88ea1ff 100644 --- a/IPython/html/static/tree/js/main.js +++ b/IPython/html/static/tree/js/main.js @@ -1,7 +1,6 @@ // Copyright (c) IPython Development Team. // Distributed under the terms of the Modified BSD License. -var ipython = ipython || {}; require([ 'base/js/namespace', 'jquery', @@ -29,16 +28,22 @@ require([ page = new page.Page(); - var opts = { + 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(opts, events); - notebook_list = new notebooklist.NotebookList('#notebook_list', opts, undefined, session_list); - cluster_list = new clusterlist.ClusterList('#cluster_list', opts); - kernel_list = new kernellist.KernelList('#running_list', opts, session_list); - login_widget = new loginwidget.LoginWidget('#login_widget', opts); + 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) { notebook_list.new_notebook(); @@ -104,11 +109,11 @@ require([ } // 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; + 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 e5e3765..8fe2ba3 100644 --- a/IPython/html/static/tree/js/notebooklist.js +++ b/IPython/html/static/tree/js/notebooklist.js @@ -9,11 +9,11 @@ define([ ], function(IPython, $, utils, dialog) { "use strict"; - var NotebookList = function (selector, options, element_name, session_list) { + var NotebookList = function (selector, options) { var that = this; - this.session_list = session_list; + 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); diff --git a/IPython/html/static/tree/js/sessionlist.js b/IPython/html/static/tree/js/sessionlist.js index 93822d0..206b59e 100644 --- a/IPython/html/static/tree/js/sessionlist.js +++ b/IPython/html/static/tree/js/sessionlist.js @@ -9,7 +9,7 @@ define([ "use strict"; var SesssionList = function (options, events) { - this.events = events; + this.events = options.events; this.sessions = {}; this.base_url = options.base_url || utils.get_body_data("baseUrl"); };