From 7a300d7ff321987ac47f652135efbb8c3ced5f7e Mon Sep 17 00:00:00 2001 From: Bussonnier Matthias Date: Thu, 7 Feb 2013 23:32:48 +0100 Subject: [PATCH 1/5] make baseProjectUrl a method in Menubar --- .../frontend/html/notebook/static/js/menubar.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/IPython/frontend/html/notebook/static/js/menubar.js b/IPython/frontend/html/notebook/static/js/menubar.js index 0a584648a..0ec481d29 100644 --- a/IPython/frontend/html/notebook/static/js/menubar.js +++ b/IPython/frontend/html/notebook/static/js/menubar.js @@ -20,6 +20,10 @@ var IPython = (function (IPython) { } }; + MenuBar.prototype.baseProjectUrl = function(){ + return $('body').data('baseProjectUrl'); + } + MenuBar.prototype.style = function () { this.element.addClass('border-box-sizing'); @@ -37,17 +41,17 @@ var IPython = (function (IPython) { MenuBar.prototype.bind_events = function () { // File this.element.find('#new_notebook').click(function () { - window.open($('body').data('baseProjectUrl')+'new'); + window.open(this.baseProjectUrl()+'new'); }); this.element.find('#open_notebook').click(function () { - window.open($('body').data('baseProjectUrl')); + window.open(this.baseProjectUrl()); }); this.element.find('#rename_notebook').click(function () { IPython.save_widget.rename_notebook(); }); this.element.find('#copy_notebook').click(function () { var notebook_id = IPython.notebook.get_notebook_id(); - var url = $('body').data('baseProjectUrl') + notebook_id + '/copy'; + var url = this.baseProjectUrl() + notebook_id + '/copy'; window.open(url,'_blank'); return false; }); @@ -56,13 +60,13 @@ var IPython = (function (IPython) { }); this.element.find('#download_ipynb').click(function () { var notebook_id = IPython.notebook.get_notebook_id(); - var url = $('body').data('baseProjectUrl') + 'notebooks/' + + var url = this.baseProjectUrl() + 'notebooks/' + notebook_id + '?format=json'; window.location.assign(url); }); this.element.find('#download_py').click(function () { var notebook_id = IPython.notebook.get_notebook_id(); - var url = $('body').data('baseProjectUrl') + 'notebooks/' + + var url = this.baseProjectUrl() + 'notebooks/' + notebook_id + '?format=py'; window.location.assign(url); }); From 09e221af6bce1a0e572478c55d1fdd17d37c86c2 Mon Sep 17 00:00:00 2001 From: Bussonnier Matthias Date: Thu, 7 Feb 2013 23:56:20 +0100 Subject: [PATCH 2/5] add option in menubar to set baseproject url --- .../html/notebook/static/js/menubar.js | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/IPython/frontend/html/notebook/static/js/menubar.js b/IPython/frontend/html/notebook/static/js/menubar.js index 0ec481d29..eff945946 100644 --- a/IPython/frontend/html/notebook/static/js/menubar.js +++ b/IPython/frontend/html/notebook/static/js/menubar.js @@ -9,9 +9,34 @@ // MenuBar //============================================================================ +/** + * @module IPython + * @namespace IPython + * @submodule MenuBar + */ + + var IPython = (function (IPython) { - var MenuBar = function (selector) { + /** + * A MenuBar Class to generate the menubar of IPython noteboko + * @Class MenuBar + * + * @constructor + * + * + * @param selector {string} selector for the menubar element in DOM + * @param {object} [options] + * @param [options.baseProjectUrl] {String} String to use for the + * Base Project url, default would be to inspect + * $('body').data('baseProjectUrl'); + * does not support change for now is set through this option + */ + var MenuBar = function (selector, options) { + var options = options || {}; + if(options.baseProjectUrl!= undefined){ + this._baseProjectUrl = options.baseProjectUrl; + } this.selector = selector; if (this.selector !== undefined) { this.element = $(selector); @@ -21,7 +46,7 @@ var IPython = (function (IPython) { }; MenuBar.prototype.baseProjectUrl = function(){ - return $('body').data('baseProjectUrl'); + return this._baseProjectUrl || $('body').data('baseProjectUrl'); } From a0b97363974fafe96640c3470bc4de8c6ff0eb15 Mon Sep 17 00:00:00 2001 From: Bussonnier Matthias Date: Fri, 8 Feb 2013 00:10:14 +0100 Subject: [PATCH 3/5] make base project url a method on notebook list --- .../html/notebook/static/js/notebooklist.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/IPython/frontend/html/notebook/static/js/notebooklist.js b/IPython/frontend/html/notebook/static/js/notebooklist.js index 6402eccda..58b681e19 100644 --- a/IPython/frontend/html/notebook/static/js/notebooklist.js +++ b/IPython/frontend/html/notebook/static/js/notebooklist.js @@ -20,6 +20,10 @@ var IPython = (function (IPython) { } }; + NotebookList.prototype.baseProjectUrl = function () { + return $('body').data('baseProjectUrl') + }; + NotebookList.prototype.style = function () { $('#notebook_toolbar').addClass('list_toolbar'); $('#drag_info').addClass('toolbar_info'); @@ -100,7 +104,7 @@ var IPython = (function (IPython) { },this) }; - var url = $('body').data('baseProjectUrl') + 'notebooks'; + var url = this.baseProjectUrl() + 'notebooks'; $.ajax(url, settings); }; @@ -162,7 +166,7 @@ var IPython = (function (IPython) { var new_item_name = $('').addClass('item_name'); new_item_name.append( $(''). - attr('href', $('body').data('baseProjectUrl')+notebook_id). + attr('href', this.baseProjectUrl()+notebook_id). attr('target','_blank'). text(nbname) ); @@ -212,7 +216,7 @@ var IPython = (function (IPython) { that.load_list(); } }; - var url = $('body').data('baseProjectUrl') + 'kernels/'+kernel; + var url = this.baseProjectUrl() + 'kernels/'+kernel; $.ajax(url, settings); }); new_buttons.append(shutdown_button); @@ -253,7 +257,7 @@ var IPython = (function (IPython) { parent_item.remove(); } }; - var url = $('body').data('baseProjectUrl') + 'notebooks/' + notebook_id; + var url = this.baseProjectUrl() + 'notebooks/' + notebook_id; $.ajax(url, settings); $(this).dialog('close'); }, @@ -302,7 +306,7 @@ var IPython = (function (IPython) { }; var qs = $.param({name:nbname, format:nbformat}); - var url = $('body').data('baseProjectUrl') + 'notebooks?' + qs; + var url = this.baseProjectUrl() + 'notebooks?' + qs; $.ajax(url, settings); }); var cancel_button = $('').button(). From 6561a98368c11f46715ffb55d6ccdd6497d73c6e Mon Sep 17 00:00:00 2001 From: Bussonnier Matthias Date: Fri, 8 Feb 2013 00:38:12 +0100 Subject: [PATCH 4/5] change more baseurl --- .../frontend/html/notebook/static/js/clusterlist.js | 10 +++++++--- .../frontend/html/notebook/static/js/loginwidget.js | 9 +++++---- IPython/frontend/html/notebook/static/js/menubar.js | 2 +- IPython/frontend/html/notebook/static/js/notebook.js | 8 ++++++-- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/IPython/frontend/html/notebook/static/js/clusterlist.js b/IPython/frontend/html/notebook/static/js/clusterlist.js index 2808bbfb9..8ef1de082 100644 --- a/IPython/frontend/html/notebook/static/js/clusterlist.js +++ b/IPython/frontend/html/notebook/static/js/clusterlist.js @@ -20,6 +20,10 @@ var IPython = (function (IPython) { } }; + ClusterList.prototype.baseProjectUrl = function(){ + return this._baseProjectUrl || $('body').data('baseProjectUrl'); + }; + ClusterList.prototype.style = function () { $('#cluster_toolbar').addClass('list_toolbar'); $('#cluster_list_info').addClass('toolbar_info'); @@ -52,7 +56,7 @@ var IPython = (function (IPython) { dataType : "json", success : $.proxy(this.load_list_success, this) }; - var url = $('body').data('baseProjectUrl') + 'clusters'; + var url = this.baseProjectUrl() + 'clusters'; $.ajax(url, settings); }; @@ -134,7 +138,7 @@ var IPython = (function (IPython) { } }; status_col.html('starting'); - var url = $('body').data('baseProjectUrl') + 'clusters/' + that.data.profile + '/start'; + var url = this.baseProjectUrl() + 'clusters/' + that.data.profile + '/start'; $.ajax(url, settings); }; }); @@ -168,7 +172,7 @@ var IPython = (function (IPython) { } }; status_col.html('stopping') - var url = $('body').data('baseProjectUrl') + 'clusters/' + that.data.profile + '/stop'; + var url = this.baseProjectUrl() + 'clusters/' + that.data.profile + '/stop'; $.ajax(url, settings); }); }; diff --git a/IPython/frontend/html/notebook/static/js/loginwidget.js b/IPython/frontend/html/notebook/static/js/loginwidget.js index d0d739e3b..96fc030e6 100644 --- a/IPython/frontend/html/notebook/static/js/loginwidget.js +++ b/IPython/frontend/html/notebook/static/js/loginwidget.js @@ -10,9 +10,10 @@ //============================================================================ var IPython = (function (IPython) { - var base_url = $('body').data('baseProjectUrl'); - var LoginWidget = function (selector) { + var LoginWidget = function (selector, options) { + var options = options || {}; + this.base_url = options.baseProjectUrl || $('body').data('baseProjectUrl') ; this.selector = selector; if (this.selector !== undefined) { this.element = $(selector); @@ -30,10 +31,10 @@ var IPython = (function (IPython) { LoginWidget.prototype.bind_events = function () { var that = this; this.element.find("button#logout").click(function () { - window.location = base_url+"logout"; + window.location = that.base_url+"logout"; }); this.element.find("button#login").click(function () { - window.location = base_url+"login"; + window.location = that.base_url+"login"; }); }; diff --git a/IPython/frontend/html/notebook/static/js/menubar.js b/IPython/frontend/html/notebook/static/js/menubar.js index eff945946..99cbc229b 100644 --- a/IPython/frontend/html/notebook/static/js/menubar.js +++ b/IPython/frontend/html/notebook/static/js/menubar.js @@ -47,7 +47,7 @@ var IPython = (function (IPython) { MenuBar.prototype.baseProjectUrl = function(){ return this._baseProjectUrl || $('body').data('baseProjectUrl'); - } + }; MenuBar.prototype.style = function () { diff --git a/IPython/frontend/html/notebook/static/js/notebook.js b/IPython/frontend/html/notebook/static/js/notebook.js index 43714d76b..801bc3fb6 100644 --- a/IPython/frontend/html/notebook/static/js/notebook.js +++ b/IPython/frontend/html/notebook/static/js/notebook.js @@ -46,6 +46,10 @@ var IPython = (function (IPython) { $('div#notebook').addClass('border-box-sizing'); }; + Notebook.prototype.baseProjectUrl = function(){ + return this._baseProjectUrl || $('body').data('baseProjectUrl'); + }; + Notebook.prototype.create_elements = function () { // We add this end_space div to the end of the notebook div to: @@ -1237,7 +1241,7 @@ var IPython = (function (IPython) { error : $.proxy(this.save_notebook_error,this) }; $([IPython.events]).trigger('notebook_saving.Notebook'); - var url = $('body').data('baseProjectUrl') + 'notebooks/' + this.notebook_id; + var url = this.baseProjectUrl() + 'notebooks/' + this.notebook_id; $.ajax(url, settings); }; @@ -1266,7 +1270,7 @@ var IPython = (function (IPython) { error : $.proxy(this.load_notebook_error,this), }; $([IPython.events]).trigger('notebook_loading.Notebook'); - var url = $('body').data('baseProjectUrl') + 'notebooks/' + this.notebook_id; + var url = this.baseProjectUrl() + 'notebooks/' + this.notebook_id; $.ajax(url, settings); }; From 5f135d66eafd224ffdefd03e93651b6161ef9019 Mon Sep 17 00:00:00 2001 From: Matthias BUSSONNIER Date: Fri, 8 Feb 2013 14:12:42 +0100 Subject: [PATCH 5/5] pass baseUrl as option --- IPython/frontend/html/notebook/static/js/notebook.js | 7 +++++-- IPython/frontend/html/notebook/static/js/notebookmain.js | 8 +++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/IPython/frontend/html/notebook/static/js/notebook.js b/IPython/frontend/html/notebook/static/js/notebook.js index 801bc3fb6..7f5111a81 100644 --- a/IPython/frontend/html/notebook/static/js/notebook.js +++ b/IPython/frontend/html/notebook/static/js/notebook.js @@ -14,8 +14,11 @@ var IPython = (function (IPython) { var utils = IPython.utils; var key = IPython.utils.keycodes; - var Notebook = function (selector) { - this.read_only = IPython.read_only; + var Notebook = function (selector, options) { + var options = options || {}; + this._baseProjectUrl = options.baseProjectUrl; + this.read_only = options.read_only || IPython.read_only; + this.element = $(selector); this.element.scroll(); this.element.data("notebook", this); diff --git a/IPython/frontend/html/notebook/static/js/notebookmain.js b/IPython/frontend/html/notebook/static/js/notebookmain.js index c19150d78..297822dba 100644 --- a/IPython/frontend/html/notebook/static/js/notebookmain.js +++ b/IPython/frontend/html/notebook/static/js/notebookmain.js @@ -39,15 +39,17 @@ $(document).ready(function () { // The header's bottom border is provided by the menu bar so we remove it. $('div#header').css('border-bottom-style','none'); + var baseProjectUrl = $('body').data('baseProjectUrl') + IPython.page = new IPython.Page(); IPython.markdown_converter = new Markdown.Converter(); IPython.layout_manager = new IPython.LayoutManager(); IPython.pager = new IPython.Pager('div#pager', 'div#pager_splitter'); IPython.quick_help = new IPython.QuickHelp('span#quick_help_area'); - IPython.login_widget = new IPython.LoginWidget('span#login_widget'); - IPython.notebook = new IPython.Notebook('div#notebook'); + IPython.login_widget = new IPython.LoginWidget('span#login_widget',{baseProjectUrl:baseProjectUrl}); + IPython.notebook = new IPython.Notebook('div#notebook',{baseProjectUrl:baseProjectUrl, read_only:IPython.read_only}); IPython.save_widget = new IPython.SaveWidget('span#save_widget'); - IPython.menubar = new IPython.MenuBar('#menubar') + IPython.menubar = new IPython.MenuBar('#menubar',{baseProjectUrl:baseProjectUrl}) IPython.toolbar = new IPython.MainToolBar('#maintoolbar') IPython.tooltip = new IPython.Tooltip() IPython.notification_area = new IPython.NotificationArea('#notification_area')