From 03b5cf094ebc59ed6e98e269e26c37e1dbaf2e27 2013-10-17 21:09:18 From: MinRK Date: 2013-10-17 21:09:18 Subject: [PATCH] review pass on multidir js --- diff --git a/IPython/html/static/notebook/js/menubar.js b/IPython/html/static/notebook/js/menubar.js index e4c8251..48e8937 100644 --- a/IPython/html/static/notebook/js/menubar.js +++ b/IPython/html/static/notebook/js/menubar.js @@ -36,8 +36,8 @@ var IPython = (function (IPython) { * does not support change for now is set through this option */ var MenuBar = function (selector, options) { - var options = options || {}; - if(options.baseProjectUrl!= undefined){ + options = options || {}; + if (options.baseProjectUrl !== undefined) { this._baseProjectUrl = options.baseProjectUrl; } this.selector = selector; @@ -55,7 +55,7 @@ var IPython = (function (IPython) { MenuBar.prototype.notebookPath = function() { var path = $('body').data('notebookPath'); path = decodeURIComponent(path); - return path + return path; }; MenuBar.prototype.style = function () { @@ -77,7 +77,11 @@ var IPython = (function (IPython) { IPython.notebook.new_notebook(); }); this.element.find('#open_notebook').click(function () { - window.open(that.baseProjectUrl() + 'tree' + that.notebookPath()); + window.open(utils.url_path_join( + that.baseProjectUrl(), + 'tree', + that.notebookPath() + )); }); this.element.find('#copy_notebook').click(function () { IPython.notebook.copy_notebook(); @@ -260,7 +264,7 @@ var IPython = (function (IPython) { MenuBar.prototype.update_restore_checkpoint = function(checkpoints) { var ul = this.element.find("#restore_checkpoint").find("ul"); ul.empty(); - if (! checkpoints || checkpoints.length == 0) { + if (!checkpoints || checkpoints.length === 0) { ul.append( $("
  • ") .addClass("disabled") @@ -270,7 +274,7 @@ var IPython = (function (IPython) { ) ); return; - }; + } checkpoints.map(function (checkpoint) { var d = new Date(checkpoint.last_modified); diff --git a/IPython/html/static/notebook/js/savewidget.js b/IPython/html/static/notebook/js/savewidget.js index 3db92b6..dadec6a 100644 --- a/IPython/html/static/notebook/js/savewidget.js +++ b/IPython/html/static/notebook/js/savewidget.js @@ -128,8 +128,12 @@ var IPython = (function (IPython) { SaveWidget.prototype.update_address_bar = function(){ var nbname = IPython.notebook.notebook_name; var path = IPython.notebook.notebookPath(); - var state = {"path": path+nbname} - window.history.replaceState(state, "", "/notebooks" + path+nbname); + var state = {path : utils.url_path_join(path,nbname)}; + window.history.replaceState(state, "", utils.url_path_join( + "/notebooks", + path, + nbname) + ); } diff --git a/IPython/html/static/services/kernels/js/kernel.js b/IPython/html/static/services/kernels/js/kernel.js index ac9db71..48afd2f 100644 --- a/IPython/html/static/services/kernels/js/kernel.js +++ b/IPython/html/static/services/kernels/js/kernel.js @@ -72,18 +72,17 @@ var IPython = (function (IPython) { * Start the Python kernel * @method start */ - Kernel.prototype.start = function (params) { - var that = this; - params = params || {}; - if (!this.running) { - var qs = $.param(params); - var url = this.base_url + '?' + qs; - $.post(url, - $.proxy(that._kernel_started,that), - 'json' - ); - }; - }; + Kernel.prototype.start = function (params) { + params = params || {}; + if (!this.running) { + var qs = $.param(params); + var url = this.base_url + '?' + qs; + $.post(url, + $.proxy(this._kernel_started, this), + 'json' + ); + }; + }; /** * Restart the python kernel. @@ -95,12 +94,11 @@ var IPython = (function (IPython) { */ Kernel.prototype.restart = function () { $([IPython.events]).trigger('status_restarting.Kernel', {kernel: this}); - var that = this; if (this.running) { this.stop_channels(); - var url = this.kernel_url + "/restart"; + var url = utils.url_path_join(this.kernel_url, "restart"); $.post(url, - $.proxy(that._kernel_started, that), + $.proxy(this._kernel_started, this), 'json' ); }; @@ -118,14 +116,14 @@ var IPython = (function (IPython) { ws_url = prot + location.host + ws_url; }; this.ws_url = ws_url; - this.kernel_url = this.base_url + "/" + this.kernel_id; + this.kernel_url = utils.url_path_join(this.base_url, this.kernel_id); this.start_channels(); }; Kernel.prototype._websocket_closed = function(ws_url, early) { this.stop_channels(); - $([IPython.events]).trigger('websocket_closed.Kernel', + $([IPython.events]).trigger('websocket_closed.Kernel', {ws_url: ws_url, kernel: this, early: early} ); }; diff --git a/IPython/html/static/services/sessions/js/session.js b/IPython/html/static/services/sessions/js/session.js index 9242007..8f33f3b 100644 --- a/IPython/html/static/services/sessions/js/session.js +++ b/IPython/html/static/services/sessions/js/session.js @@ -1,5 +1,5 @@ //---------------------------------------------------------------------------- -// Copyright (C) 2008-2011 The IPython Development Team +// 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. @@ -10,45 +10,58 @@ //============================================================================ var IPython = (function (IPython) { + "use strict"; - var Session = function(notebook_name, notebook_path, Notebook){ + var utils = IPython.utils; + + var Session = function(notebook_name, notebook_path, notebook){ this.kernel = null; this.id = null; this.name = notebook_name; this.path = notebook_path; - this.notebook = Notebook; - this._baseProjectUrl = Notebook.baseProjectUrl() + this.notebook = notebook; + this._baseProjectUrl = notebook.baseProjectUrl(); }; Session.prototype.start = function() { - var that = this - var notebook = {'notebook':{'name': this.name, 'path': this.path}} + var that = this; + var model = { + notebook : { + name : this.name, + path : this.path + } + }; var settings = { processData : false, cache : false, type : "POST", - data: JSON.stringify(notebook), + data: JSON.stringify(model), dataType : "json", success : $.proxy(this.start_kernel, that), }; - var url = this._baseProjectUrl + 'api/sessions'; + var url = utils.url_path_join(this._baseProjectUrl, 'api/sessions'); $.ajax(url, settings); }; Session.prototype.notebook_rename = function (name, path) { this.name = name; this.path = path; - var notebook = {'notebook':{'name':name, 'path': path}}; + var model = { + notebook : { + name : this.name, + path : this.path + } + }; var settings = { processData : false, cache : false, type : "PATCH", - data: JSON.stringify(notebook), + data: JSON.stringify(model), dataType : "json", }; - var url = this._baseProjectUrl + 'api/sessions/' + this.session_id; + var url = utils.url_path_join(this._baseProjectUrl, 'api/sessions', this.session_id); $.ajax(url, settings); - } + }; Session.prototype.delete_session = function() { var settings = { @@ -57,7 +70,7 @@ var IPython = (function (IPython) { type : "DELETE", dataType : "json", }; - var url = this._baseProjectUrl + 'api/sessions/' + this.session_id; + var url = utils.url_path_join(this._baseProjectUrl, 'api/sessions', this.session_id); $.ajax(url, settings); }; @@ -70,7 +83,7 @@ var IPython = (function (IPython) { Session.prototype.start_kernel = function (json) { this.id = json.id; this.kernel_content = json.kernel; - var base_url = $('body').data('baseKernelUrl') + "api/kernels"; + var base_url = utils.url_path_join($('body').data('baseKernelUrl'), "api/kernels"); this.kernel = new IPython.Kernel(base_url, this.session_id); this.kernel._kernel_started(this.kernel_content); }; @@ -90,12 +103,11 @@ var IPython = (function (IPython) { Session.prototype.kill_kernel = function() { - this.kernel.kill(); + this.kernel.kill(); }; IPython.Session = Session; - return IPython; }(IPython));