Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[various] use Jupyter.notebook.config instance, where appropriate #1061

Merged
merged 1 commit into from
Aug 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions src/jupyter_contrib_nbextensions/nbextensions/autosavetime/main.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
define([
'jquery',
'base/js/namespace',
'base/js/events',
'base/js/utils',
'services/config'
'base/js/events'
], function(
$,
IPython,
events,
utils,
configmod
events
) {
"use strict";

// create config object to load parameters
var base_url = utils.get_body_data("baseUrl");
var config = new configmod.ConfigSection('notebook', {base_url: base_url});

// define default values for config parameters
var params = {
autosavetime_set_starting_interval : false,
Expand All @@ -26,13 +18,14 @@ define([

// update params with any specified in the server's config file
var update_params = function() {
var config = IPython.notebook.config;
for (var key in params) {
if (config.data.hasOwnProperty(key))
params[key] = config.data[key];
}
};

config.loaded.then( function() {
var initialize = function () {
update_params();

var si = params.autosavetime_starting_interval;
Expand Down Expand Up @@ -76,10 +69,10 @@ define([
}
}
});
});
};

var load_ipython_extension = function() {
config.load();
return IPython.notebook.config.loaded.then(initialize);
};

return {
Expand Down
22 changes: 9 additions & 13 deletions src/jupyter_contrib_nbextensions/nbextensions/autoscroll/main.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
define([
'jquery',
'base/js/namespace',
'base/js/utils',
'services/config',
'base/js/events',
'notebook/js/outputarea',
'notebook/js/codecell'
], function (
$,
IPython,
utils,
configmod,
oa, codecell
events,
oa,
codecell
) {
"use strict";

Expand All @@ -25,12 +24,9 @@ define([
autoscroll_show_button : false
};

// create config object to load parameters
var base_url = utils.get_body_data("baseUrl");
var config = new configmod.ConfigSection('notebook', {base_url: base_url});

// update params with any specified in the server's config file
var update_params = function() {
var config = IPython.notebook.config;
for (var key in params) {
if (config.data.hasOwnProperty(key))
params[key] = config.data[key];
Expand Down Expand Up @@ -69,7 +65,7 @@ define([
initAutoScroll();
};

config.loaded.then( function() {
var initialize = function() {
update_params();

var thresholds = [-1, 1, 10, 20, 50, 100, 200, 500, 1000];
Expand Down Expand Up @@ -107,7 +103,7 @@ define([
IPython.toolbar.add_buttons_group([action_full_name]);
}
initAutoScroll();
});
};

var load_ipython_extension = function () {
var prefix = 'auto';
Expand All @@ -121,8 +117,8 @@ define([

action_full_name = IPython.keyboard_manager.actions.register(action, action_name, prefix);

config.load();
$([IPython.events]).on("notebook_loaded.Notebook", function(){
IPython.notebook.config.loaded.then(initialize);
events.on("notebook_loaded.Notebook", function(){
initAutoScroll();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@
// works with images and notebook cells (MIME-type 'notebook-cell/json')

define([
'base/js/namespace',
'jquery',
'base/js/utils',
'services/config',
'base/js/namespace',
'base/js/events'
], function(IPython, $, utils, configmod, events) {
], function(
$,
IPython,
events
) {
"use strict";
if (window.chrome === undefined) return;

var params = {
subdirectory : '',
};

var base_url = utils.get_body_data("baseUrl");
var config = new configmod.ConfigSection('notebook', {base_url: base_url});

/* http://stackoverflow.com/questions/3231459/create-unique-id-with-javascript */
function uniqueid(){
// always start with a letter (for DOM friendlyness)
Expand Down Expand Up @@ -58,7 +57,7 @@ define([
name = uniqueid() + '.' + msg.match(/data:image\/(\S+);/)[1];
}
create_dir(path);
var url = '//' + location.host + utils.url_path_join(base_url, 'api/contents', path, name);
var url = '//' + location.host + utils.url_path_join(IPython.notebook.base_url, 'api/contents', path, name);

var img = msg.replace(/(^\S+,)/, ''); // strip header
//console.log("send_to_server:", url, img);
Expand Down Expand Up @@ -90,10 +89,9 @@ define([
*/
var load_ipython_extension = function() {

config.load();
config.loaded
IPython.notebook.config.loaded
.then(function () {
$.extend(true, params, config.data.dragdrop); // update params
$.extend(true, params, IPython.notebook.config.data.dragdrop); // update params
if (params.subdirectory) {
console.log('subdir:', params.subdirectory)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ define(function(require, exports, module) {
var $ = require('jquery');
var Jupyter = require('base/js/namespace');
var events = require('base/js/events');
var utils = require('base/js/utils');
var ConfigSection = require('services/config').ConfigSection;
var CodeCell = require('notebook/js/codecell').CodeCell;

// this wrapper function allows config & hotkeys to be per-plugin
Expand Down Expand Up @@ -286,13 +284,11 @@ define(function(require, exports, module) {

KernelExecOnCells.prototype.initialize_plugin = function() {
var that = this;
var base_url = utils.get_body_data("baseUrl");
var conf_section = new ConfigSection('notebook', { base_url: base_url });
// first, load config
conf_section.load()
Jupyter.notebook.config.loaded
// now update default config with that loaded from server
.then(function on_success(config_data) {
$.extend(true, that.cfg, config_data[that.mod_name]);
.then(function on_success() {
$.extend(true, that.cfg, Jupyter.notebook.config.data[that.mod_name]);
}, function on_error(err) {
console.warn(that.mod_log_prefix, 'error loading config:', err);
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,11 @@

define([
'base/js/namespace',
'services/config',
'base/js/utils'
], function(
IPython,
configmod,
utils
IPython
) {
"use strict";

// create config object to load parameters
var base_url = utils.get_body_data("baseUrl");
var config = new configmod.ConfigSection('notebook', {base_url: base_url});

// define default config parameter values
var params = {
comment_uncomment_keybinding : 'alt-c',
Expand All @@ -23,14 +15,15 @@ define([

// updates default params with any specified in the server's config
var update_params = function() {
var config = IPython.notebook.config;
for (var key in params){
if (config.data.hasOwnProperty(key) ){
params[key] = config.data[key];
}
}
};

config.loaded.then(function() {
var initialize = function () {
// update defaults
update_params();

Expand All @@ -52,7 +45,7 @@ define([

// register keyboard shortcuts with keyboard_manager
IPython.notebook.keyboard_manager.edit_shortcuts.add_shortcuts(edit_mode_shortcuts);
});
};

var toggle_comment = function() {
var cm = IPython.notebook.get_selected_cell().code_mirror;
Expand All @@ -61,8 +54,7 @@ define([
};

var load_ipython_extension = function () {
// load config to trigger keybinding registration
config.load();
return IPython.notebook.config.loaded.then(initialize);
};

return {
Expand Down
20 changes: 9 additions & 11 deletions src/jupyter_contrib_nbextensions/nbextensions/dragdrop/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@ define([
'base/js/namespace',
'jquery',
'base/js/utils',
'services/config',
"base/js/events"
], function(IPython, $, utils, configmod, events) {
], function(IPython, $, utils, events) {
"use strict";

var params = {
subdirectory : '',
};

var base_url = utils.get_body_data("baseUrl");
var config = new configmod.ConfigSection('notebook', {base_url: base_url});

/* http://stackoverflow.com/questions/3231459/create-unique-id-with-javascript */
function uniqueid(){
Expand Down Expand Up @@ -193,14 +191,14 @@ define([

var load_jupyter_extension = function() {
events.on('create.Cell', create_cell);
config.load();
config.loaded
.then(function () {
$.extend(true, params, config.data.dragdrop); // update params
if (params.subdirectory) {
console.log('subdir:', params.subdirectory)
}
})

return IPython.notebook.config.loaded.then(function () {
// update params
$.extend(true, params, IPython.notebook.config.data.dragdrop);
if (params.subdirectory) {
console.log('[dragdrop] subdir:', params.subdirectory);
}
});
};

return {
Expand Down
19 changes: 6 additions & 13 deletions src/jupyter_contrib_nbextensions/nbextensions/gist_it/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,11 @@
define([
'jquery',
'base/js/namespace',
'base/js/dialog',
'base/js/utils',
'services/config'
'base/js/dialog'
], function (
$,
Jupyter,
dialog,
utils,
configmod
dialog
) {
"use strict";

Expand All @@ -45,21 +41,18 @@ define([
gist_it_personal_access_token: '',
};

// create config object to load parameters
var base_url = utils.get_body_data("baseUrl");
var config = new configmod.ConfigSection('notebook', {base_url: base_url});

config.loaded.then(function() {
var initialize = function () {
update_params();
Jupyter.toolbar.add_buttons_group([{
label : 'Create/Edit Gist of Notebook',
icon : 'fa-github',
callback: show_gist_editor_modal
}]);
});
};

// update params with any specified in the server's config file
var update_params = function() {
var config = Jupyter.notebook.config;
for (var key in params) {
if (config.data.hasOwnProperty(key))
params[key] = config.data[key];
Expand Down Expand Up @@ -459,7 +452,7 @@ define([
};

function load_jupyter_extension () {
config.load();
return Jupyter.notebook.config.loaded.then(initialize);
}

return {
Expand Down
Loading