Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use requirejs vs. require #1165

Merged
merged 6 commits into from
Dec 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ define([
'require',
'base/js/events',
'base/js/utils',
], function(Jupyter, $, require, events, configmod, utils) {
], function(Jupyter, $, requirejs, events, configmod, utils) {
"use strict";

var load_extension = function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -325,6 +332,5 @@ define(function(require, exports, module) {
});
};

exports.define_plugin = KernelExecOnCells;
return {define_plugin: KernelExecOnCells};
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ define([
'codemirror/addon/fold/foldgutter',
'codemirror/addon/fold/brace-fold',
'codemirror/addon/fold/indent-fold'
], function (Jupyter, $, require, events, configmod, codecell, CodeMirror) {
], function (Jupyter, $, requirejs, events, configmod, codecell, CodeMirror) {
"use strict";

// define default config parameter values
Expand Down Expand Up @@ -221,7 +221,7 @@ define([
var link = document.createElement("link");
link.type = "text/css";
link.rel = "stylesheet";
link.href = require.toUrl(name, 'css');
link.href = requirejs.toUrl(name, 'css');
document.getElementsByTagName("head")[0].appendChild(link);
};

Expand Down Expand Up @@ -256,7 +256,7 @@ define([

if (Jupyter.notebook) {
/* require our additional custom codefolding modes before initialising fully */
require(['./firstline-fold', './magic-fold'], function () {
requirejs(['./firstline-fold', './magic-fold'], function () {
if (Jupyter.notebook._fully_loaded) {
setTimeout(function () {
console.log('Codefolding: Wait for', params.init_delay, 'ms');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
(require.specified('base/js/namespace') ? define : function (deps, callback) {
(requirejs.specified('base/js/namespace') ? define : function (deps, callback) {
// if here, the Jupyter namespace hasn't been specified to be loaded.
// This means that we're probably embedded in a page, so we need to make
// our definition with a specific module name
return define('nbextensions/collapsible_headings/main', deps, callback);
})(['jquery', 'require'], function ($, require) {
})(['jquery', 'require'], function ($, requirejs) {
"use strict";

var mod_name = 'collapsible_headings';
Expand Down Expand Up @@ -55,7 +55,7 @@
// object, but in a non-live notebook, we must construct our own version
var events;
try {
events = require('base/js/events');
events = requirejs('base/js/events');
}
catch (err) {
// in non-live notebook, there's no events structure, so we make our own
Expand Down Expand Up @@ -528,7 +528,7 @@
*/
function patch_Notebook () {
return new Promise(function (resolve, reject) {
require(['notebook/js/notebook'], function on_success (notebook) {
requirejs(['notebook/js/notebook'], function on_success (notebook) {
console.debug(log_prefix, 'patching Notebook.protoype');

// we have to patch select, since the select.Cell event is only fired
Expand Down Expand Up @@ -577,7 +577,7 @@
return Promise.resolve();
}
return new Promise(function (resolve, reject) {
require(['notebook/js/tooltip'], function on_success (tooltip) {
requirejs(['notebook/js/tooltip'], function on_success (tooltip) {
console.debug(log_prefix, 'patching Tooltip.prototype');

var orig_tooltip__show = tooltip.Tooltip.prototype._show;
Expand Down Expand Up @@ -607,7 +607,7 @@
*/
function patch_actions () {
return new Promise(function (resolve, reject) {
require(['notebook/js/tooltip'], function on_success (tooltip) {
requirejs(['notebook/js/tooltip'], function on_success (tooltip) {
console.debug(log_prefix, 'patching Jupyter up/down actions');

var kbm = Jupyter.keyboard_manager;
Expand Down Expand Up @@ -927,7 +927,7 @@
}

return new Promise (function (resolve, reject) {
require(['base/js/events'], function on_success (events) {
requirejs(['base/js/events'], function on_success (events) {

// ensure events are detached while notebook loads, in order to
// speed up loading (otherwise headings are updated for every
Expand Down Expand Up @@ -1000,13 +1000,13 @@
id: 'collapsible_headings_css',
rel: 'stylesheet',
type: 'text/css',
href: require.toUrl('./main.css')
href: requirejs.toUrl('./main.css')
})
.appendTo('head');

// ensure Jupyter module is defined before proceeding further
new Promise(function (resolve, reject) {
require(['base/js/namespace'], function (Jupyter_mod) {
requirejs(['base/js/namespace'], function (Jupyter_mod) {
live_notebook = true;
Jupyter = Jupyter_mod;
resolve(Jupyter);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

define(["require"], function(require) {
define(["require"], function(requirejs) {

/**
* @param element {} DOM element to which add controls
Expand Down Expand Up @@ -36,7 +36,7 @@ define(["require"], function(require) {
var cmtm = styles[val].cm || 'ipyhton';
if(cmtm != undefined){
try{
$tlink.attr('href',require.toUrl('../../components/codemirror/theme/'+cmtm+'.css'))
$tlink.attr('href',requirejs.toUrl('../../components/codemirror/theme/'+cmtm+'.css'))
.attr('rel','stylesheet')
.attr('type','text/css')

Expand All @@ -45,7 +45,7 @@ define(["require"], function(require) {
}
} catch(e){}
}
$link.attr('href',require.toUrl('./css/'+val+'.css'))
$link.attr('href',requirejs.toUrl('./css/'+val+'.css'))
.attr('rel','stylesheet')
.attr('type','text/css');
field.css = [val];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ define([
'require',
'notebook/js/textcell',
'base/js/utils',
], function(Jupyter, $, require, textcell, utils) {
], function(Jupyter, $, requirejs, textcell, utils) {
"use strict";

var MathJax = window.MathJax;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ define([
'base/js/events',
'notebook/js/codecell'
], function (
require,
requirejs,
$,
moment,
Jupyter,
Expand Down Expand Up @@ -286,7 +286,7 @@ define([
$('<link/>')
.attr({
rel: 'stylesheet',
href: require.toUrl(url),
href: requirejs.toUrl(url),
type: 'text/css'
})
.appendTo('head');
Expand All @@ -295,9 +295,9 @@ define([
function load_jupyter_extension () {
// try to load jquery-ui
if ($.ui === undefined && options.highlight.use) {
require(['jquery-ui'], function ($) {}, function (err) {
requirejs(['jquery-ui'], function ($) {}, function (err) {
// try to load using the older, non-standard name (without hyphen)
require(['jqueryui'], function ($) {}, function (err) {
requirejs(['jqueryui'], function ($) {}, function (err) {
console.log(log_prefix, 'couldn\'t find jquery-ui, so no animations');
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ define([
'require',
'base/js/events',
'nbextensions/rubberband/main'
], function(IPython, $, require, events, rubberband) {
], function(IPython, $, requirejs, events, rubberband) {
"use strict";

/**
Expand Down Expand Up @@ -153,7 +153,7 @@ function load_ipython_extension(){
var link = document.createElement("link");
link.type = "text/css";
link.rel = "stylesheet";
link.href = require.toUrl(name);
link.href = requirejs.toUrl(name);
document.getElementsByTagName("head")[0].appendChild(link);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ define([
'require',
'base/js/events',
'nbextensions/rubberband/main'
], function(IPython, $, require, events, rubberband) {
], function(IPython, $, requirejs, events, rubberband) {
"use strict";

var cbx=0;
Expand Down Expand Up @@ -150,7 +150,7 @@ function load_ipython_extension(){
var link = document.createElement("link");
link.type = "text/css";
link.rel = "stylesheet";
link.href = require.toUrl(name);
link.href = requirejs.toUrl(name);
document.getElementsByTagName("head")[0].appendChild(link);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ define([
'base/js/namespace',
'base/js/events',
], function (
require,
requirejs,
$,
IPython,
events
Expand All @@ -19,7 +19,7 @@ define([
* in all Jupyter versions. In this case, we fallback to using jqueryui tooltips.
*/
var have_bs_tooltips = false;
require(
requirejs(
['components/bootstrap/js/tooltip'],
// we don't actually need to do anything with the return
// just ensure that the plugin gets loaded.
Expand Down Expand Up @@ -236,7 +236,7 @@ define([
$('<link/>', {
rel: 'stylesheet',
type:'text/css',
href: require.toUrl('./help_panel.css')
href: requirejs.toUrl('./help_panel.css')
})
);
return IPython.notebook.config.loaded.then(initialize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,21 +296,21 @@ $("#remove_highlights")

define(["require",
'base/js/namespace'
], function(require, Jupyter) {
], function(requirejs, Jupyter) {

var security = require("base/js/security")
var security = requirejs("base/js/security")

var load_css = function(name) {
var link = document.createElement("link");
link.type = "text/css";
link.rel = "stylesheet";
link.href = require.toUrl(name);
link.href = requirejs.toUrl(name);
document.getElementsByTagName("head")[0].appendChild(link);

};

//Load_ipython_extension
var load_ipython_extension = require(['base/js/namespace'], function(Jupyter) {
var load_ipython_extension = requirejs(['base/js/namespace'], function(Jupyter) {
"use strict";
if (Jupyter.version[0] < 3) {
console.log("This extension requires Jupyter or IPython >= 3.x")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
define(function (require, exports, module) {
define([
'module',
'jquery',
'base/js/namespace',
'base/js/keyboard',
'notebook/js/cell',
'notebook/js/codecell',
'notebook/js/completer',
], function (
module,
$,
Jupyter,
keyboard,
cell,
codecell,
completer
) {
'use strict';

var $ = require('jquery');
var Jupyter = require('base/js/namespace');
var keyboard = require('base/js/keyboard');
var Cell = require('notebook/js/cell').Cell;
var CodeCell = require('notebook/js/codecell').CodeCell;
var Completer = require('notebook/js/completer').Completer;
var Cell = cell.Cell;
var CodeCell = codecell.CodeCell;
var Completer = completer.Completer;

var log_prefix = '[' + module.id + ']';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ define([
'./kse_components',
], function (
$,
require,
requirejs,
Jupyter,
dialog,
events,
Expand Down Expand Up @@ -68,7 +68,7 @@ define([
.attr({
'rel': 'stylesheet',
'type': 'text/css',
'href': require.toUrl(url)
'href': requirejs.toUrl(url)
})
.appendTo($('head'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ define([
'codemirror/lib/codemirror',
], function (
$,
require,
requirejs,
Jupyter,
events,
utils,
Expand Down
Loading