various unicode fixes

- remove notebookPath, notebookName, and baseProjectUrl methods everywhere
- use base_project_url *attributes* instead
- we should never use escaped URLs except when making an actual request

Should fix issues with double-escaping
This commit is contained in:
MinRK 2014-02-05 15:18:21 -08:00
parent beaa75b416
commit 13fc9022d9
9 changed files with 118 additions and 149 deletions

View File

@ -10,10 +10,11 @@
//============================================================================
var IPython = (function (IPython) {
"use strict";
var LoginWidget = function (selector, options) {
var options = options || {};
this.base_url = options.baseProjectUrl || $('body').data('baseProjectUrl') ;
options = options || {};
this.base_project_url = options.base_project_url || IPython.utils.get_data("baseProjectUrl");
this.selector = selector;
if (this.selector !== undefined) {
this.element = $(selector);
@ -30,10 +31,16 @@ var IPython = (function (IPython) {
LoginWidget.prototype.bind_events = function () {
var that = this;
this.element.find("button#logout").click(function () {
window.location = that.base_url+"logout";
window.location = IPythin.utils.url_join_encode(
that.base_project_url,
"logout"
);
});
this.element.find("button#login").click(function () {
window.location = that.base_url+"login";
window.location = IPythin.utils.url_join_encode(
that.base_project_url,
"login"
);
});
};

View File

@ -8,7 +8,6 @@
//============================================================================
// On document ready
//============================================================================
"use strict";
// for the time beeing, we have to pass marked as a parameter here,
// as injecting require.js make marked not to put itself in the globals,
@ -18,28 +17,28 @@ require(['components/marked/lib/marked',
'notebook/js/widgets/init'],
function (marked) {
"use strict";
window.marked = marked
window.marked = marked;
// monkey patch CM to be able to syntax highlight cell magics
// bug reported upstream,
// see https://github.com/marijnh/CodeMirror2/issues/670
if(CodeMirror.getMode(1,'text/plain').indent == undefined ){
if(CodeMirror.getMode(1,'text/plain').indent === undefined ){
console.log('patching CM for undefined indent');
CodeMirror.modes.null = function() {
return {token: function(stream) {stream.skipToEnd();},indent : function(){return 0}}
}
return {token: function(stream) {stream.skipToEnd();},indent : function(){return 0;}};
};
}
CodeMirror.patchedGetMode = function(config, mode){
var cmmode = CodeMirror.getMode(config, mode);
if(cmmode.indent == null)
{
if(cmmode.indent === null) {
console.log('patch mode "' , mode, '" on the fly');
cmmode.indent = function(){return 0};
cmmode.indent = function(){return 0;};
}
return cmmode;
}
};
// end monkey patching CodeMirror
IPython.mathjaxutils.init();
@ -47,35 +46,32 @@ function (marked) {
$('#ipython-main-app').addClass('border-box-sizing');
$('div#notebook_panel').addClass('border-box-sizing');
var baseProjectUrl = $('body').data('baseProjectUrl');
var notebookPath = $('body').data('notebookPath');
var notebookName = $('body').data('notebookName');
notebookName = decodeURIComponent(notebookName);
notebookPath = decodeURIComponent(notebookPath);
console.log(notebookName);
if (notebookPath == 'None'){
notebookPath = "";
}
var opts = {
base_project_url : IPython.utils.get_data("baseProjectUrl"),
base_kernel_url : IPython.utils.get_data("baseKernelUrl"),
notebook_path : IPython.utils.get_data("notebookPath"),
notebook_name : IPython.utils.get_data('notebookName')
};
IPython.page = new IPython.Page();
IPython.layout_manager = new IPython.LayoutManager();
IPython.pager = new IPython.Pager('div#pager', 'div#pager_splitter');
IPython.quick_help = new IPython.QuickHelp();
IPython.login_widget = new IPython.LoginWidget('span#login_widget',{baseProjectUrl:baseProjectUrl});
IPython.notebook = new IPython.Notebook('div#notebook',{baseProjectUrl:baseProjectUrl, notebookPath:notebookPath, notebookName:notebookName});
IPython.login_widget = new IPython.LoginWidget('span#login_widget', opts);
IPython.notebook = new IPython.Notebook('div#notebook', opts);
IPython.keyboard_manager = new IPython.KeyboardManager();
IPython.save_widget = new IPython.SaveWidget('span#save_widget');
IPython.menubar = new IPython.MenuBar('#menubar',{baseProjectUrl:baseProjectUrl, notebookPath: notebookPath})
IPython.toolbar = new IPython.MainToolBar('#maintoolbar-container')
IPython.tooltip = new IPython.Tooltip()
IPython.notification_area = new IPython.NotificationArea('#notification_area')
IPython.menubar = new IPython.MenuBar('#menubar', opts);
IPython.toolbar = new IPython.MainToolBar('#maintoolbar-container');
IPython.tooltip = new IPython.Tooltip();
IPython.notification_area = new IPython.NotificationArea('#notification_area');
IPython.notification_area.init_notification_widgets();
IPython.layout_manager.do_resize();
$('body').append('<div id="fonttest"><pre><span id="test1">x</span>'+
'<span id="test2" style="font-weight: bold;">x</span>'+
'<span id="test3" style="font-style: italic;">x</span></pre></div>')
'<span id="test3" style="font-style: italic;">x</span></pre></div>');
var nh = $('#test1').innerHeight();
var bh = $('#test2').innerHeight();
var ih = $('#test3').innerHeight();
@ -101,7 +97,7 @@ function (marked) {
$([IPython.events]).on('notebook_loaded.Notebook', first_load);
$([IPython.events]).trigger('app_initialized.NotebookApp');
IPython.notebook.load_notebook(notebookName, notebookPath);
IPython.notebook.load_notebook(opts.notebook_name, opts.notebook_path);
if (marked) {
marked.setOptions({
@ -121,8 +117,6 @@ function (marked) {
}
return highlighted.value;
}
})
});
}
}
);
});

View File

@ -30,16 +30,14 @@ var IPython = (function (IPython) {
*
* @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
* @param [options.base_project_url] {String} String to use for the
* base project url. Default is to inspect
* $('body').data('baseProjectUrl');
* does not support change for now is set through this option
*/
var MenuBar = function (selector, options) {
options = options || {};
if (options.baseProjectUrl !== undefined) {
this._baseProjectUrl = options.baseProjectUrl;
}
this.base_project_url = options.base_project_url || IPython.utils.get_data("baseProjectUrl");
this.selector = selector;
if (this.selector !== undefined) {
this.element = $(selector);
@ -48,16 +46,6 @@ var IPython = (function (IPython) {
}
};
MenuBar.prototype.baseProjectUrl = function(){
return this._baseProjectUrl || $('body').data('baseProjectUrl');
};
MenuBar.prototype.notebookPath = function() {
var path = $('body').data('notebookPath');
path = decodeURIComponent(path);
return path;
};
MenuBar.prototype.style = function () {
this.element.addClass('border-box-sizing');
this.element.find("li").click(function (event, ui) {
@ -75,16 +63,16 @@ var IPython = (function (IPython) {
if (IPython.notebook.dirty) {
IPython.notebook.save_notebook({async : false});
}
var url = utils.url_path_join(
this.baseProjectUrl(),
var url = utils.url_join_encode(
this.base_project_url,
'nbconvert',
format,
this.notebookPath(),
this.notebook_path,
notebook_name + '.ipynb'
) + "?download=" + download.toString();
window.open(url);
}
};
MenuBar.prototype.bind_events = function () {
// File
@ -94,9 +82,9 @@ var IPython = (function (IPython) {
});
this.element.find('#open_notebook').click(function () {
window.open(utils.url_join_encode(
that.baseProjectUrl(),
IPython.notebook.base_url,
'tree',
that.notebookPath()
IPython.notebook.notebook_path
));
});
this.element.find('#copy_notebook').click(function () {
@ -104,15 +92,17 @@ var IPython = (function (IPython) {
return false;
});
this.element.find('#download_ipynb').click(function () {
var notebook_name = IPython.notebook.get_notebook_name();
var base_url = IPython.notebook.base_url;
var notebook_path = IPython.notebook.notebook_path;
var notebook_name = IPython.notebook.notebook_name;
if (IPython.notebook.dirty) {
IPython.notebook.save_notebook({async : false});
}
var url = utils.url_join_encode(
that.baseProjectUrl(),
base_url,
'files',
that.notebookPath(),
notebook_path,
notebook_name + '.ipynb'
);
window.location.assign(url);

View File

@ -23,10 +23,10 @@ var IPython = (function (IPython) {
* @param {Object} [options] A config object
*/
var Notebook = function (selector, options) {
var options = options || {};
this._baseProjectUrl = options.baseProjectUrl;
this.notebook_path = options.notebookPath;
this.notebook_name = options.notebookName;
this.options = options = options || {};
this.base_project_url = options.base_project_url;
this.notebook_path = options.notebook_path;
this.notebook_name = options.notebook_name;
this.element = $(selector);
this.element.scroll();
this.element.data("notebook", this);
@ -53,8 +53,8 @@ var IPython = (function (IPython) {
// single worksheet for now
this.worksheet_metadata = {};
this.notebook_name_blacklist_re = /[\/\\:]/;
this.nbformat = 3 // Increment this when changing the nbformat
this.nbformat_minor = 0 // Increment this when changing the nbformat
this.nbformat = 3; // Increment this when changing the nbformat
this.nbformat_minor = 0; // Increment this when changing the nbformat
this.style();
this.create_elements();
this.bind_events();
@ -69,24 +69,6 @@ var IPython = (function (IPython) {
$('div#notebook').addClass('border-box-sizing');
};
/**
* Get the root URL of the notebook server.
*
* @method baseProjectUrl
* @return {String} The base project URL
*/
Notebook.prototype.baseProjectUrl = function() {
return this._baseProjectUrl || $('body').data('baseProjectUrl');
};
Notebook.prototype.notebookName = function() {
return $('body').data('notebookName');
};
Notebook.prototype.notebookPath = function() {
return $('body').data('notebookPath');
};
/**
* Create an HTML and CSS representation of the notebook.
*
@ -1365,7 +1347,7 @@ var IPython = (function (IPython) {
* @method start_session
*/
Notebook.prototype.start_session = function () {
this.session = new IPython.Session(this.notebook_name, this.notebook_path, this);
this.session = new IPython.Session(this, this.options);
this.session.start($.proxy(this._session_started, this));
};
@ -1529,7 +1511,7 @@ var IPython = (function (IPython) {
* Getter method for this notebook's name.
*
* @method get_notebook_name
* @return {String} This notebook's name
* @return {String} This notebook's name (excluding file extension)
*/
Notebook.prototype.get_notebook_name = function () {
var nbname = this.notebook_name.substring(0,this.notebook_name.length-6);
@ -1701,7 +1683,7 @@ var IPython = (function (IPython) {
}
$([IPython.events]).trigger('notebook_saving.Notebook');
var url = utils.url_join_encode(
this._baseProjectUrl,
this.base_project_url,
'api/notebooks',
this.notebook_path,
this.notebook_name
@ -1762,7 +1744,7 @@ var IPython = (function (IPython) {
Notebook.prototype.new_notebook = function(){
var path = this.notebook_path;
var base_project_url = this._baseProjectUrl;
var base_project_url = this.base_project_url;
var settings = {
processData : false,
cache : false,
@ -1793,7 +1775,7 @@ var IPython = (function (IPython) {
Notebook.prototype.copy_notebook = function(){
var path = this.notebook_path;
var base_project_url = this._baseProjectUrl;
var base_project_url = this.base_project_url;
var settings = {
processData : false,
cache : false,
@ -1833,7 +1815,7 @@ var IPython = (function (IPython) {
};
$([IPython.events]).trigger('rename_notebook.Notebook', data);
var url = utils.url_join_encode(
this._baseProjectUrl,
this.base_project_url,
'api/notebooks',
this.notebook_path,
this.notebook_name
@ -1850,7 +1832,7 @@ var IPython = (function (IPython) {
dataType: "json",
};
var url = utils.url_join_encode(
this._baseProjectUrl,
this.base_project_url,
'api/notebooks',
this.notebook_path,
this.notebook_name
@ -1919,7 +1901,7 @@ var IPython = (function (IPython) {
};
$([IPython.events]).trigger('notebook_loading.Notebook');
var url = utils.url_join_encode(
this._baseProjectUrl,
this.base_project_url,
'api/notebooks',
this.notebook_path,
this.notebook_name
@ -2069,7 +2051,7 @@ var IPython = (function (IPython) {
*/
Notebook.prototype.list_checkpoints = function () {
var url = utils.url_join_encode(
this._baseProjectUrl,
this.base_project_url,
'api/notebooks',
this.notebook_path,
this.notebook_name,
@ -2120,9 +2102,9 @@ var IPython = (function (IPython) {
*/
Notebook.prototype.create_checkpoint = function () {
var url = utils.url_join_encode(
this._baseProjectUrl,
this.base_project_url,
'api/notebooks',
this.notebookPath(),
this.notebook_path,
this.notebook_name,
'checkpoints'
);
@ -2207,9 +2189,9 @@ var IPython = (function (IPython) {
Notebook.prototype.restore_checkpoint = function (checkpoint) {
$([IPython.events]).trigger('notebook_restoring.Notebook', checkpoint);
var url = utils.url_join_encode(
this._baseProjectUrl,
this.base_project_url,
'api/notebooks',
this.notebookPath(),
this.notebook_path,
this.notebook_name,
'checkpoints',
checkpoint
@ -2255,9 +2237,9 @@ var IPython = (function (IPython) {
Notebook.prototype.delete_checkpoint = function (checkpoint) {
$([IPython.events]).trigger('notebook_restoring.Notebook', checkpoint);
var url = utils.url_join_encode(
this._baseProjectUrl,
this.base_project_url,
'api/notebooks',
this.notebookPath(),
this.notebook_path,
this.notebook_name,
'checkpoints',
checkpoint

View File

@ -127,7 +127,7 @@ var IPython = (function (IPython) {
SaveWidget.prototype.update_address_bar = function(){
var nbname = IPython.notebook.notebook_name;
var path = IPython.notebook.notebookPath();
var path = IPython.notebook.notebook_path;
var state = {path : utils.url_join_encode(path, nbname)};
window.history.replaceState(state, "", utils.url_join_encode(
"/notebooks",

View File

@ -14,13 +14,14 @@ var IPython = (function (IPython) {
var utils = IPython.utils;
var Session = function(notebook_name, notebook_path, notebook){
var Session = function(notebook, options){
this.kernel = null;
this.id = null;
this.name = notebook_name;
this.path = notebook_path;
this.notebook = notebook;
this._baseProjectUrl = notebook.baseProjectUrl();
this.name = notebook.notebook_name;
this.path = notebook.notebook_path;
this.base_project_url = notebook.base_project_url;
this.base_kernel_url = options.base_kernel_url || utils.get_data("baseKernelUrl");
};
Session.prototype.start = function(callback) {
@ -44,7 +45,7 @@ var IPython = (function (IPython) {
}
},
};
var url = utils.url_join_encode(this._baseProjectUrl, 'api/sessions');
var url = utils.url_join_encode(this.base_project_url, 'api/sessions');
$.ajax(url, settings);
};
@ -64,7 +65,7 @@ var IPython = (function (IPython) {
data: JSON.stringify(model),
dataType : "json",
};
var url = utils.url_join_encode(this._baseProjectUrl, 'api/sessions', this.id);
var url = utils.url_join_encode(this.base_project_url, 'api/sessions', this.id);
$.ajax(url, settings);
};
@ -76,7 +77,7 @@ var IPython = (function (IPython) {
dataType : "json",
};
this.kernel.running = false;
var url = utils.url_join_encode(this._baseProjectUrl, 'api/sessions', this.id);
var url = utils.url_join_encode(this.base_project_url, 'api/sessions', this.id);
$.ajax(url, settings);
};
@ -88,7 +89,7 @@ var IPython = (function (IPython) {
*/
Session.prototype._handle_start_success = function (data, status, xhr) {
this.id = data.id;
var base_url = utils.url_path_join($('body').data('baseKernelUrl'), "api/kernels");
var base_url = utils.url_join_encode(this.base_kernel_url, "api/kernels");
this.kernel = new IPython.Kernel(base_url);
this.kernel._kernel_started(data.kernel);
};

View File

@ -14,17 +14,17 @@ var IPython = (function (IPython) {
var utils = IPython.utils;
var ClusterList = function (selector) {
var ClusterList = function (selector, options) {
this.selector = selector;
if (this.selector !== undefined) {
this.element = $(selector);
this.style();
this.bind_events();
}
};
ClusterList.prototype.baseProjectUrl = function(){
return this._baseProjectUrl || $('body').data('baseProjectUrl');
options = options || {};
this.options = options;
this.base_project_url = options.base_project_url || utils.get_data("baseProjectUrl");
this.notebook_path = options.notebook_path || utils.get_data("notebookPath");
};
ClusterList.prototype.style = function () {
@ -51,7 +51,7 @@ var IPython = (function (IPython) {
dataType : "json",
success : $.proxy(this.load_list_success, this)
};
var url = utils.url_join_encode(this.baseProjectUrl(), 'clusters');
var url = utils.url_join_encode(this.base_project_url, 'clusters');
$.ajax(url, settings);
};
@ -65,7 +65,7 @@ var IPython = (function (IPython) {
var len = data.length;
for (var i=0; i<len; i++) {
var element = $('<div/>');
var item = new ClusterItem(element);
var item = new ClusterItem(element, this.options);
item.update_state(data[i]);
element.data('item', item);
this.element.append(element);
@ -73,17 +73,14 @@ var IPython = (function (IPython) {
};
var ClusterItem = function (element) {
var ClusterItem = function (element, options) {
this.element = $(element);
this.base_project_url = options.base_project_url || utils.get_data("baseProjectUrl");
this.notebook_path = options.notebook_path || utils.get_data("notebookPath");
this.data = null;
this.style();
};
ClusterItem.prototype.baseProjectUrl = function(){
return this._baseProjectUrl || $('body').data('baseProjectUrl');
};
ClusterItem.prototype.style = function () {
this.element.addClass('list_item').addClass("row-fluid");
};
@ -138,7 +135,7 @@ var IPython = (function (IPython) {
};
status_col.text('starting');
var url = utils.url_join_encode(
that.baseProjectUrl(),
that.base_project_url,
'clusters',
that.data.profile,
'start'
@ -180,7 +177,7 @@ var IPython = (function (IPython) {
};
status_col.text('stopping');
var url = utils.url_join_encode(
that.baseProjectUrl(),
that.base_project_url,
'clusters',
that.data.profile,
'stop'

View File

@ -15,12 +15,16 @@ $(document).ready(function () {
IPython.page = new IPython.Page();
$('#new_notebook').button().click(function (e) {
IPython.notebook_list.new_notebook($('body').data('baseProjectUrl'))
IPython.notebook_list.new_notebook()
});
IPython.notebook_list = new IPython.NotebookList('#notebook_list');
IPython.cluster_list = new IPython.ClusterList('#cluster_list');
IPython.login_widget = new IPython.LoginWidget('#login_widget');
var opts = {
base_project_url : IPython.utils.get_data("baseProjectUrl"),
notebook_path : IPython.utils.get_data("notebookPath"),
};
IPython.notebook_list = new IPython.NotebookList('#notebook_list', opts);
IPython.cluster_list = new IPython.ClusterList('#cluster_list', opts);
IPython.login_widget = new IPython.LoginWidget('#login_widget', opts);
var interval_id=0;
// auto refresh every xx secondes, no need to be fast,

View File

@ -14,7 +14,7 @@ var IPython = (function (IPython) {
var utils = IPython.utils;
var NotebookList = function (selector) {
var NotebookList = function (selector, options) {
this.selector = selector;
if (this.selector !== undefined) {
this.element = $(selector);
@ -23,16 +23,10 @@ var IPython = (function (IPython) {
}
this.notebooks_list = [];
this.sessions = {};
this.base_project_url = options.base_project_url || utils.get_data("baseProjectUrl");
this.notebook_path = options.notebook_path || utils.get_data("notebookPath");
};
NotebookList.prototype.baseProjectUrl = function () {
return $('body').data('baseProjectUrl');
};
NotebookList.prototype.notebookPath = function() {
return $('body').data('notebookPath');
};
NotebookList.prototype.style = function () {
$('#notebook_toolbar').addClass('list_toolbar');
$('#drag_info').addClass('toolbar_info');
@ -112,7 +106,7 @@ var IPython = (function (IPython) {
dataType : "json",
success : $.proxy(that.sessions_loaded, this)
};
var url = this.baseProjectUrl() + 'api/sessions';
var url = utils.url_join_encode(this.base_project_url, 'api/sessions');
$.ajax(url,settings);
};
@ -152,10 +146,10 @@ var IPython = (function (IPython) {
};
var url = utils.url_join_encode(
this.baseProjectUrl(),
this.base_project_url,
'api',
'notebooks',
this.notebookPath()
this.notebook_path
);
$.ajax(url, settings);
};
@ -175,7 +169,7 @@ var IPython = (function (IPython) {
span12.empty();
span12.append($('<div style="margin:auto;text-align:center;color:grey"/>').text(message));
}
var path = this.notebookPath();
var path = this.notebook_path;
var offset = 0;
if (path !== '') {
item = this.new_notebook_item(0);
@ -233,7 +227,7 @@ var IPython = (function (IPython) {
item.find("a.item_link")
.attr('href',
utils.url_join_encode(
this.baseProjectUrl(),
this.base_project_url,
"tree",
path,
name
@ -250,7 +244,7 @@ var IPython = (function (IPython) {
item.find("a.item_link")
.attr('href',
utils.url_join_encode(
this.baseProjectUrl(),
this.base_project_url,
"notebooks",
path,
nbname
@ -291,7 +285,7 @@ var IPython = (function (IPython) {
}
};
var url = utils.url_join_encode(
that.baseProjectUrl(),
that.base_project_url,
'api/sessions',
session
);
@ -331,9 +325,9 @@ var IPython = (function (IPython) {
}
};
var url = utils.url_join_encode(
notebooklist.baseProjectUrl(),
notebooklist.base_project_url,
'api/notebooks',
notebooklist.notebookPath(),
notebooklist.notebook_path,
nbname
);
$.ajax(url, settings);
@ -357,7 +351,7 @@ var IPython = (function (IPython) {
if (nbname.slice(nbname.length-6, nbname.length) != ".ipynb") {
nbname = nbname + ".ipynb";
}
var path = that.notebookPath();
var path = that.notebook_path;
var nbdata = item.data('nbdata');
var content_type = 'application/json';
var model = {
@ -380,9 +374,9 @@ var IPython = (function (IPython) {
};
var url = utils.url_join_encode(
that.baseProjectUrl(),
that.base_project_url,
'api/notebooks',
that.notebookPath(),
that.notebook_path,
nbname
);
$.ajax(url, settings);
@ -402,8 +396,8 @@ var IPython = (function (IPython) {
NotebookList.prototype.new_notebook = function(){
var path = this.notebookPath();
var base_project_url = this.baseProjectUrl();
var path = this.notebook_path;
var base_project_url = this.base_project_url;
var settings = {
processData : false,
cache : false,