From d227b4acb38700bf643cd6c72ac9a80acc6445ce Mon Sep 17 00:00:00 2001 From: Gino Bustelo Date: Tue, 15 Dec 2015 08:38:40 -0600 Subject: [PATCH] [ci skip] Changes necessary to work standalone similar to ipywidgets examples (c) Copyright IBM Corp. 2015 --- index.js | 26 +++++++++++++++++ nb-extension/js/init/init.js | 8 ++++++ nb-extension/js/widgets/DeclWidgetModel.js | 32 ++++++++++++++++++--- notebooks/examples/urth-scala-widgets.ipynb | 2 +- package.json | 4 +++ 5 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 index.js diff --git a/index.js b/index.js new file mode 100644 index 00000000..84967c8b --- /dev/null +++ b/index.js @@ -0,0 +1,26 @@ +// Copyright (c) Jupyter Development Team. +// Distributed under the terms of the Modified BSD License. + +// This is the main file that will be loaded when urth-widgets is required in an +// npm environment. +// +//module.exports = function createDefine(targetModule) { +// var amdefine = require('amdefine')(targetModule, require); +// +// return function define() { +// var args = Array.prototype.slice.call(arguments); +// //if (args.length > 1) { +// // args[0] = args[0].map(function(arg) { +// // if (arg === 'jqueryui') arg = 'jquery'; +// // arg = arg.replace('nbextensions/widgets/widgets/css/', '../css/'); +// // arg = arg.replace('nbextensions/widgets/components/require-css/css!', ''); +// // return arg; +// // }); +// //} +// amdefine.apply(this, args); +// }; +//}; + +var init = require('./dist/urth_widgets/js/init/init'); + +exports.init = init; diff --git a/nb-extension/js/init/init.js b/nb-extension/js/init/init.js index ae41ef5b..01e2730f 100644 --- a/nb-extension/js/init/init.js +++ b/nb-extension/js/init/init.js @@ -7,6 +7,14 @@ * Loads the web component polyfill and all web components specified in * elements.html. */ +// npm compatibility +function requireLocalFiles() { + require('jquery'); + require('../widgets/DeclWidgetModel'); +} + +if (typeof define !== 'function') { var define = require('amdefine')(module, require); } + define([ 'require', 'jquery', diff --git a/nb-extension/js/widgets/DeclWidgetModel.js b/nb-extension/js/widgets/DeclWidgetModel.js index 4747ad16..3641c970 100644 --- a/nb-extension/js/widgets/DeclWidgetModel.js +++ b/nb-extension/js/widgets/DeclWidgetModel.js @@ -1,10 +1,34 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. +// npm compatibility +function requireLocalFiles() { + require('../../../../node_modules/jupyter-js-widgets/static/widgets/js/manager-base'); + require('../../../../node_modules/jupyter-js-widgets/static/widgets/js/widget'); +} + +if (typeof define !== 'function') { + var amdefine = require('amdefine')(module, require); + + var mapping = {} + mapping['nbextensions/widgets/widgets/js/manager'] = '../../../../node_modules/jupyter-js-widgets/static/widgets/js/manager-base' + mapping['nbextensions/widgets/widgets/js/widget'] = '../../../../node_modules/jupyter-js-widgets/static/widgets/js/widget' + + var define = function(){ + var args = Array.prototype.slice.call(arguments); + if (args.length > 1) { + args[0] = args[0].map(function(arg) { + arg = mapping[arg] || arg; + return arg; + }); + } + amdefine.apply(this, args); + } +} + define(["nbextensions/widgets/widgets/js/manager", - "nbextensions/widgets/widgets/js/widget", - "base/js/namespace" -], function(widgetmanager, ipywidget, IPython) { + "nbextensions/widgets/widgets/js/widget" +], function(widgetmanager, ipywidget) { "use strict"; /** @@ -33,7 +57,7 @@ define(["nbextensions/widgets/widgets/js/manager", this.comm.send(data, callbacks); }; - widgetmanager.WidgetManager.register_widget_model('DeclWidgetModel', DeclWidgetModel); + widgetmanager.ManagerBase.register_widget_model('DeclWidgetModel', DeclWidgetModel); return DeclWidgetModel; diff --git a/notebooks/examples/urth-scala-widgets.ipynb b/notebooks/examples/urth-scala-widgets.ipynb index 267b8f60..0557d653 100644 --- a/notebooks/examples/urth-scala-widgets.ipynb +++ b/notebooks/examples/urth-scala-widgets.ipynb @@ -35,7 +35,7 @@ "outputs": [], "source": [ "// modify to IP and Port of this notebook server\n", - "%addjar http://192.168.99.100:8888/nbextensions/urth_widgets/urth-widgets.jar" + "%addjar http://192.168.99.100:8888/nbexten tsions/urth_widgets/urth-widgets.jar" ] }, { diff --git a/package.json b/package.json index ecf4f50b..9f206af6 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,10 @@ "selenium-standalone": "latest", "web-component-tester": "~3.4" }, + "dependencies": { + "amdefine": "^1.0.0", + "jquery": "^2.1.4" + }, "config": {}, "scripts": { "bower": "bower",