Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

Commit

Permalink
Changes necessary to work standalone similar to ipywidgets examples
Browse files Browse the repository at this point in the history
(c) Copyright IBM Corp. 2015
  • Loading branch information
Gino Bustelo committed Dec 15, 2015
1 parent a5d07b7 commit 12b4d1c
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 5 deletions.
24 changes: 24 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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);
// };
//};

require('./dist/urth_widgets/js/init/init');
10 changes: 10 additions & 0 deletions nb-extension/js/init/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,22 @@
* Loads the web component polyfill and all web components specified in
* elements.html.
*/
debugger;
// npm compatibility
function requireLocalFiles() {
require('jquery');
require('../widgets/DeclWidgetModel');
}

if (typeof define !== 'function') { var define = require('amdefine')(module, require); }

define([
'require',
'jquery',
'../widgets/DeclWidgetModel'], function(require, $) {
'use strict';

debugger;
function loadComponents(bower_root, links) {
console.debug('Bower root is: ', bower_root);

Expand Down
33 changes: 29 additions & 4 deletions nb-extension/js/widgets/DeclWidgetModel.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
// 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(){
debugger;
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";

/**
Expand Down Expand Up @@ -33,7 +58,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;

Expand Down
2 changes: 1 addition & 1 deletion notebooks/examples/urth-scala-widgets.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
{
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 12b4d1c

Please sign in to comment.