Skip to content

Commit

Permalink
Allow NBClassic to work if ServerApp.base_url is set and Notebook 7 i…
Browse files Browse the repository at this point in the history
…s installed

Also resolves an issue where New->New Notebook did not respect the "/nbclassic/" in the url if it was set
Personally not a fan of the var still being called base_url_prefix but wans't willing to make that big of a change
Closes jupyter#164
  • Loading branch information
mcrutch committed Oct 17, 2022
1 parent 26e49b4 commit 2ec4d64
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion nbclassic/static/edit/js/menubar.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ define([
editor.contents.new_untitled(parent, {type: "file"}).then(
function (data) {
w.location = utils.url_path_join(
that.base_url_prefix, that.base_url, 'edit', utils.encode_uri_components(data.path)
that.base_url, that.base_url_prefix, 'edit', utils.encode_uri_components(data.path)
);
},
function(error) {
Expand Down
6 changes: 4 additions & 2 deletions nbclassic/static/notebook/js/kernelselector.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ define([
], function($, IPython, dialog, utils, i18n) {
"use strict";

var KernelSelector = function(selector, notebook) {
var KernelSelector = function(selector, notebook, options) {
options = options || {};
var that = this;
this.selector = selector;
this.notebook = notebook;
this.base_url_prefix = options.base_url_prefix;
this.notebook.set_kernelselector(this);
this.events = notebook.events;
this.current_selection = null;
Expand Down Expand Up @@ -307,7 +309,7 @@ define([
that.notebook.contents.new_untitled(parent, {type: "notebook"}).then(
function (data) {
var url = utils.url_path_join(
that.notebook.base_url, 'notebooks',
that.notebook.base_url, that.base_url_prefix, 'notebooks',
utils.encode_uri_components(data.path)
);
url += "?kernel_name=" + kernel_name;
Expand Down
3 changes: 2 additions & 1 deletion nbclassic/static/notebook/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ requirejs([
var common_options = {
ws_url : utils.get_body_data("wsUrl"),
base_url : utils.get_body_data("baseUrl"),
base_url_prefix: document.baseUrlPrefix || "",
notebook_path : utils.get_body_data("notebookPath"),
notebook_name : utils.get_body_data('notebookName')
};
Expand Down Expand Up @@ -168,7 +169,7 @@ requirejs([
keyboard_manager: keyboard_manager});
notification_area.init_notification_widgets();
var kernel_selector = new kernelselector.KernelSelector(
'#kernel_logo_widget', notebook);
'#kernel_logo_widget', notebook, common_options);
searchandreplace.load(keyboard_manager);

$('body').append('<div id="fonttest"><pre><span id="test1">x</span>'+
Expand Down
2 changes: 1 addition & 1 deletion nbclassic/static/notebook/js/menubar.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ define([
var parent = utils.url_path_split(that.notebook.notebook_path)[0];
window.open(
utils.url_path_join(
that.base_url_prefix, that.base_url, 'tree',
that.base_url, that.base_url_prefix, 'tree',
utils.encode_uri_components(parent)
), IPython._target);
});
Expand Down
2 changes: 1 addition & 1 deletion nbclassic/static/tree/js/newnotebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ define([
this.contents.new_untitled(dir_path, {type: "notebook"}).then(
function (data) {
var url = utils.url_path_join(
that.base_url_prefix, that.base_url, 'notebooks',
that.base_url, that.base_url_prefix, 'notebooks',
utils.encode_uri_components(data.path)
);
if (kernel_name) {
Expand Down
12 changes: 6 additions & 6 deletions nbclassic/static/tree/js/notebooklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ define([
var w = window.open('', IPython._target);
that.contents.new_untitled(that.notebook_path || '', {type: 'file', ext: '.txt'}).then(function(data) {
w.location = utils.url_path_join(
that.base_url_prefix, that.base_url, 'edit',
that.base_url, that.base_url_prefix, 'edit',
utils.encode_uri_components(data.path)
);
}).catch(function (e) {
Expand Down Expand Up @@ -385,7 +385,7 @@ define([
var breadcrumb = $('.breadcrumb');
breadcrumb.empty();
var list_item = $('<li/>');
var root_url = utils.url_path_join(that.base_url_prefix, that.base_url, '/tree');
var root_url = utils.url_path_join(that.base_url, that.base_url_prefix, '/tree');
var root = $('<li/>').append(
$("<a/>")
.attr('href', root_url)
Expand All @@ -403,7 +403,7 @@ define([
window.history.pushState(
{path: path},
'Home',
utils.url_path_join(that.base_url_prefix, that.base_url, 'tree')
utils.url_path_join(that.base_url, that.base_url_prefix, 'tree')
);
that.update_location(path);
return false;
Expand All @@ -415,8 +415,8 @@ define([
path_parts.push(path_part);
var path = path_parts.join('/');
var url = utils.url_path_join(
that.base_url_prefix,
that.base_url,
that.base_url_prefix,
'/tree',
utils.encode_uri_components(path)
);
Expand Down Expand Up @@ -907,8 +907,8 @@ define([
var link = item.find("a.item_link")
.attr('href',
utils.url_path_join(
this.base_url_prefix,
this.base_url,
this.base_url_prefix,
uri_prefix,
utils.encode_uri_components(model.path)
)
Expand All @@ -931,8 +931,8 @@ define([
window.history.pushState({
path: model.path
}, model.path, utils.url_path_join(
that.base_url_prefix,
that.base_url,
that.base_url_prefix,
'tree',
utils.encode_uri_components(model.path)
));
Expand Down

0 comments on commit 2ec4d64

Please sign in to comment.