From f3f1695b06a0eee902a9c5557d09948a5ae39f9d Mon Sep 17 00:00:00 2001 From: MinRK Date: Sat, 8 Feb 2014 21:07:35 -0800 Subject: [PATCH] add IPython.load_extensions in js --- IPython/html/static/base/js/utils.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/IPython/html/static/base/js/utils.js b/IPython/html/static/base/js/utils.js index 0e6c9fb3d..785574361 100644 --- a/IPython/html/static/base/js/utils.js +++ b/IPython/html/static/base/js/utils.js @@ -12,6 +12,34 @@ IPython.namespace('IPython.utils'); IPython.utils = (function (IPython) { "use strict"; + + IPython.load_extensions = function () { + // load one or more IPython notebook extensions with requirejs + + var extensions = []; + var extension_names = arguments; + for (var i = 0; i < extension_names.length; i++) { + extensions.push("nbextensions/" + arguments[i]); + } + + require(extensions, + function () { + for (var i = 0; i < arguments.length; i++) { + var ext = arguments[i]; + var ext_name = extension_names[i]; + // success callback + console.log("Loaded extension: " + ext_name); + if (ext && ext.load_ipython_extension !== undefined) { + ext.load_ipython_extension(); + } + } + }, + function (err) { + // failure callback + console.log("Failed to load extension(s):", err.requireModules, err); + } + ); + }; //============================================================================ // Cross-browser RegEx Split