From 699f31bf911563e74f786070b4af12a3a7c2859e Mon Sep 17 00:00:00 2001 From: Josh Barnes Date: Wed, 23 Aug 2017 00:46:21 +0100 Subject: [PATCH 1/4] [various] use Jupyter.notebook.config instance, where appropriate to avoid reloading (from server!) the same config file for each nbextension. In most cases this also means we don't need to require the 'services/config' module any longer. --- kernel_exec_on_cell.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/kernel_exec_on_cell.js b/kernel_exec_on_cell.js index 87de938..97a0a2e 100755 --- a/kernel_exec_on_cell.js +++ b/kernel_exec_on_cell.js @@ -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 @@ -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); }) From 15d7e02f2f6fdb282e9da4ddb5032aee18ca7ef4 Mon Sep 17 00:00:00 2001 From: Josh Barnes Date: Mon, 4 Dec 2017 12:25:36 +0000 Subject: [PATCH 2/4] [requirejs] don't use commonjs wrapper as it works by searching through the module definition function's toString representation, the commonjs style requirejs wrapper is slower, and prone to subtle errors. We don't actually need it anywhere, so use regular requirejs define calls instead. --- 2to3.js | 4 +--- autopep8.js | 4 +--- code_prettify.js | 4 +--- kernel_exec_on_cell.js | 18 ++++++++++++------ 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/2to3.js b/2to3.js index efbd632..46219b5 100644 --- a/2to3.js +++ b/2to3.js @@ -4,11 +4,9 @@ // Based on: https://github.com/jfbercher/code_prettify and // https://gist.github.com/takluyver/c8839593c615bb2f6e80 -define(function(require, exports, module) { +define(['./kernel_exec_on_cell'], function(kernel_exec_on_cell) { 'use strict'; - var kernel_exec_on_cell = require('./kernel_exec_on_cell'); - var mod_name = '2to3'; // gives default settings diff --git a/autopep8.js b/autopep8.js index 761b656..b09f11e 100644 --- a/autopep8.js +++ b/autopep8.js @@ -2,11 +2,9 @@ // Distributed under the terms of the Modified BSD License. // Authors: @kenkoooo, @jfbercher and @jcb91 -define(function(require, exports, module) { +define(['./kernel_exec_on_cell'], function(kernel_exec_on_cell) { 'use strict'; - var kernel_exec_on_cell = require('./kernel_exec_on_cell'); - var mod_name = 'autopep8'; // gives default settings diff --git a/code_prettify.js b/code_prettify.js index dadc2c7..e7e29fb 100644 --- a/code_prettify.js +++ b/code_prettify.js @@ -2,11 +2,9 @@ // Distributed under the terms of the Modified BSD License. // Authors: @jfbercher and @jcb91 -define(function(require, exports, module) { +define(['./kernel_exec_on_cell'], function(kernel_exec_on_cell) { 'use strict'; - var kernel_exec_on_cell = require('./kernel_exec_on_cell'); - var mod_name = 'code_prettify'; // gives default settings diff --git a/kernel_exec_on_cell.js b/kernel_exec_on_cell.js index 97a0a2e..7b185c6 100755 --- a/kernel_exec_on_cell.js +++ b/kernel_exec_on_cell.js @@ -1,13 +1,20 @@ // Copyright (c) Jupyter-Contrib Team. // Distributed under the terms of the Modified BSD License. -define(function(require, exports, module) { +define([ + 'jquery', + 'base/js/namespace', + 'base/js/events', + 'notebook/js/codecell', +], function( + $, + Jupyter, + events, + codecell +) { 'use strict'; - var $ = require('jquery'); - var Jupyter = require('base/js/namespace'); - var events = require('base/js/events'); - var CodeCell = require('notebook/js/codecell').CodeCell; + var CodeCell = codecell.CodeCell; // this wrapper function allows config & hotkeys to be per-plugin function KernelExecOnCells(mod_name, cfg) { @@ -325,6 +332,5 @@ define(function(require, exports, module) { }); }; - exports.define_plugin = KernelExecOnCells; return {define_plugin: KernelExecOnCells}; }); From a42b3ef52a8a5594c8a1d6063573461dac2522d8 Mon Sep 17 00:00:00 2001 From: Josh Barnes Date: Sun, 21 Jan 2018 22:53:00 +0000 Subject: [PATCH 3/4] [kernel_exec_on_cells] make shift-click on button autoformat all cells as discussed in https://github.com/ipython-contrib/jupyter_contrib_nbextensions/issues/1202#issuecomment-359263483 --- kernel_exec_on_cell.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/kernel_exec_on_cell.js b/kernel_exec_on_cell.js index 7b185c6..4c6df9e 100755 --- a/kernel_exec_on_cell.js +++ b/kernel_exec_on_cell.js @@ -185,8 +185,16 @@ define([ KernelExecOnCells.prototype.add_toolbar_button = function() { if ($('#' + this.mod_name + '_button').length < 1) { var button_group_id = this.mod_name + '_button'; - Jupyter.toolbar.add_buttons_group( - [this.cfg.actions.process_selected.name], button_group_id); + var that = this; + Jupyter.toolbar.add_buttons_group([{ + label: this.cfg.kbd_shortcut_text + ' selected cell(s) (add shift for all cells)', + icon: this.cfg.button_icon, + callback: function(evt) { + that.autoformat_cells( + evt.shiftKey ? Jupyter.notebook.get_cells().map(function (cell, idx) { return idx; }) : undefined + ); + }, + }], button_group_id); } }; @@ -224,12 +232,7 @@ define([ help_index: 'yf', icon: that.cfg.button_icon, handler: function(evt) { - var indices = [], - N = Jupyter.notebook.ncells(); - for (var i = 0; i < N; i++) { - indices.push(i); - } - that.autoformat_cells(indices); + that.autoformat_cells(Jupyter.notebook.get_cells().map(function (cell, idx) { return idx; })); }, }; From e94adbf06cdcbc0122d10ea26a0b750b566e73c0 Mon Sep 17 00:00:00 2001 From: Josh Barnes Date: Sun, 21 Jan 2018 23:49:24 +0000 Subject: [PATCH 4/4] update changelog in readme --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 06805b8..27255a4 100644 --- a/README.md +++ b/README.md @@ -267,6 +267,9 @@ History - [@jfbercher], january 2017 - updated documentation - added autopep8 nbextension as a plugin using the shared library +- [@jcb91], january 2018 + - library: made shift-click of toolbar button affect whole notebook, rather + than single cell [2to3]: README_2to3.md