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/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 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 87de938..4c6df9e 100755 --- a/kernel_exec_on_cell.js +++ b/kernel_exec_on_cell.js @@ -1,15 +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 utils = require('base/js/utils'); - var ConfigSection = require('services/config').ConfigSection; - 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) { @@ -180,8 +185,16 @@ define(function(require, exports, module) { 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); } }; @@ -219,12 +232,7 @@ define(function(require, exports, module) { 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; })); }, }; @@ -286,13 +294,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); }) @@ -329,6 +335,5 @@ define(function(require, exports, module) { }); }; - exports.define_plugin = KernelExecOnCells; return {define_plugin: KernelExecOnCells}; });