From 94666de268e3fbb5121cf6abd96e7fde6052e840 2014-07-10 20:25:08 From: Jonathan Frederic Date: 2014-07-10 20:25:08 Subject: [PATCH] Finished making tree.html requirejs friendly --- diff --git a/IPython/html/static/base/js/dialog.js b/IPython/html/static/base/js/dialog.js index 56a5391..9d184f5 100644 --- a/IPython/html/static/base/js/dialog.js +++ b/IPython/html/static/base/js/dialog.js @@ -87,7 +87,7 @@ define([ return modal.modal(options); }; - var edit_metadata = function (md, callback, name) { + var edit_metadata = function (md, callback, name, keyboard_manager, notebook) { name = name || "Cell"; var error_div = $('
').css('color', 'red'); var message = @@ -141,7 +141,7 @@ define([ }, Cancel: {} } - }); + }, keyboard_manager, notebook); modal.on('shown.bs.modal', function(){ editor.refresh(); }); }; diff --git a/IPython/html/static/base/js/events.js b/IPython/html/static/base/js/events.js index 133c097..34c9512 100644 --- a/IPython/html/static/base/js/events.js +++ b/IPython/html/static/base/js/events.js @@ -17,5 +17,9 @@ define(['base/js/namespace'], function(IPython) { IPython.Events = Events; IPython.events = events; + // This behavior is an akward exception to the normal design pattern of + // returning the namespace. Events are used eveywhere in IPython, + // and only one instance is ever used. For convenience, create and + // return that instance here instead of the namespace. return events; }); diff --git a/IPython/html/static/tree/js/clusterlist.js b/IPython/html/static/tree/js/clusterlist.js index da337c2..466244c 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', + 'components/jquery/jquery.min', + 'base/js/utils', +], function(IPython, $, Utils) { "use strict"; - - var utils = IPython.utils; var ClusterList = function (selector, options) { this.selector = selector; @@ -23,8 +17,8 @@ var IPython = (function (IPython) { } options = options || {}; this.options = options; - this.base_url = options.base_url || utils.get_body_data("baseUrl"); - this.notebook_path = options.notebook_path || utils.get_body_data("notebookPath"); + this.base_url = options.base_url || Utils.get_body_data("baseUrl"); + this.notebook_path = options.notebook_path || Utils.get_body_data("notebookPath"); }; ClusterList.prototype.style = function () { @@ -50,9 +44,9 @@ var IPython = (function (IPython) { type : "GET", dataType : "json", success : $.proxy(this.load_list_success, this), - error : utils.log_ajax_error, + error : Utils.log_ajax_error, }; - var url = utils.url_join_encode(this.base_url, 'clusters'); + var url = Utils.url_join_encode(this.base_url, 'clusters'); $.ajax(url, settings); }; @@ -76,8 +70,8 @@ var IPython = (function (IPython) { var ClusterItem = function (element, options) { this.element = $(element); - this.base_url = options.base_url || utils.get_body_data("baseUrl"); - this.notebook_path = options.notebook_path || utils.get_body_data("notebookPath"); + this.base_url = options.base_url || Utils.get_body_data("baseUrl"); + this.notebook_path = options.notebook_path || Utils.get_body_data("notebookPath"); this.data = null; this.style(); }; @@ -132,11 +126,11 @@ var IPython = (function (IPython) { }, error : function (xhr, status, error) { status_col.text("error starting cluster"); - utils.log_ajax_error(xhr, status, error); + Utils.log_ajax_error(xhr, status, error); } }; status_col.text('starting'); - var url = utils.url_join_encode( + var url = Utils.url_join_encode( that.base_url, 'clusters', that.data.profile, @@ -188,11 +182,9 @@ var IPython = (function (IPython) { }); }; - + // For backwards compatability. IPython.ClusterList = ClusterList; IPython.ClusterItem = ClusterItem; - return IPython; - -}(IPython)); - + return ClusterList; +}); diff --git a/IPython/html/static/tree/js/kernellist.js b/IPython/html/static/tree/js/kernellist.js index f89d52c..16b9216 100644 --- a/IPython/html/static/tree/js/kernellist.js +++ b/IPython/html/static/tree/js/kernellist.js @@ -1,24 +1,18 @@ -//---------------------------------------------------------------------------- -// 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', + 'components/jquery/jquery.min', + 'tree/js/notebooklist', +], function(IPython, $, NotebookList) { "use strict"; - var utils = IPython.utils; - - var KernelList = function (selector, options) { - IPython.NotebookList.call(this, selector, options, 'running'); + var KernelList = function (selector, options, session_list) { + NotebookList.call(this, selector, options, 'running', session_list); }; - KernelList.prototype = Object.create(IPython.NotebookList.prototype); + KernelList.prototype = Object.create(NotebookList.prototype); KernelList.prototype.sessions_loaded = function (d) { this.sessions = d; @@ -31,10 +25,10 @@ var IPython = (function (IPython) { } $('#running_list_header').toggle($.isEmptyObject(d)); - } + }; + // Backwards compatability. IPython.KernelList = KernelList; - return IPython; - -}(IPython)); + return KernelList; +}); diff --git a/IPython/html/static/tree/js/main.js b/IPython/html/static/tree/js/main.js index 5632094..4d38e04 100644 --- a/IPython/html/static/tree/js/main.js +++ b/IPython/html/static/tree/js/main.js @@ -13,7 +13,6 @@ define([ 'auth/js/loginwidget', 'components/jquery-ui/ui/minified/jquery-ui.min', 'components/bootstrap/js/bootstrap.min', - 'base/js/dialog', ], function( IPython, $, @@ -28,13 +27,13 @@ define([ page = new Page(); var opts = { - base_url : Utils.get_body_data("baseUrl"), - notebook_path : Utils.get_body_data("notebookPath"), + base_url: Utils.get_body_data("baseUrl"), + notebook_path: Utils.get_body_data("notebookPath"), }; session_list = new SesssionList(opts); notebook_list = new NotebookList('#notebook_list', opts, undefined, session_list); cluster_list = new ClusterList('#cluster_list', opts); - kernel_list = new KernelList('#running_list', opts); + kernel_list = new KernelList('#running_list', opts, session_list); login_widget = new LoginWidget('#login_widget', opts); $('#new_notebook').button().click(function (e) { diff --git a/IPython/html/static/tree/js/sessionlist.js b/IPython/html/static/tree/js/sessionlist.js index 05dafb1..b7ec80e 100644 --- a/IPython/html/static/tree/js/sessionlist.js +++ b/IPython/html/static/tree/js/sessionlist.js @@ -1,22 +1,17 @@ -//---------------------------------------------------------------------------- -// 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', + 'components/jquery/jquery.min', + 'base/js/utils', + 'base/js/events', +], function(IPython, $, Utils, Events) { "use strict"; - var utils = IPython.utils; - var SesssionList = function (options) { this.sessions = {}; - this.base_url = options.base_url || utils.get_body_data("baseUrl"); + this.base_url = options.base_url || Utils.get_body_data("baseUrl"); }; SesssionList.prototype.load_sessions = function(){ @@ -27,9 +22,9 @@ var IPython = (function (IPython) { type : "GET", dataType : "json", success : $.proxy(that.sessions_loaded, this), - error : utils.log_ajax_error, + error : Utils.log_ajax_error, }; - var url = utils.url_join_encode(this.base_url, 'api/sessions'); + var url = Utils.url_join_encode(this.base_url, 'api/sessions'); $.ajax(url, settings); }; @@ -38,16 +33,17 @@ var IPython = (function (IPython) { var len = data.length; var nb_path; for (var i=0; i