From 327c9a0d5492b4bf06a6f4edbcfdc6f678ab5c48 Mon Sep 17 00:00:00 2001 From: Luis Neves Date: Tue, 11 Oct 2022 15:34:04 +0100 Subject: [PATCH] adds new file custom-preload that is loaded in a different order before the main.js script is executed (#155) Co-authored-by: Luis Neves --- nbclassic/static/custom/custom-preload.js | 13 +++++++++++++ nbclassic/static/edit/js/main.js | 1 + nbclassic/static/notebook/js/main.js | 3 ++- nbclassic/static/terminal/js/main.js | 1 + nbclassic/static/tree/js/main.js | 1 + nbclassic/templates/page.html | 13 +++++++++++++ tools/build-main.js | 5 ++++- 7 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 nbclassic/static/custom/custom-preload.js diff --git a/nbclassic/static/custom/custom-preload.js b/nbclassic/static/custom/custom-preload.js new file mode 100644 index 000000000..f1f3f8e7d --- /dev/null +++ b/nbclassic/static/custom/custom-preload.js @@ -0,0 +1,13 @@ +// leave at least 2 line with only a star on it below, or doc generation fails +/** + * + * + * Same goal as custom.js, but loaded in a different order, before the main.js script is executed + * + * + * @module IPython + * @namespace IPython + * @class custompreloadjs + * @static + */ + diff --git a/nbclassic/static/edit/js/main.js b/nbclassic/static/edit/js/main.js index 1a7265768..2dbbf1adc 100644 --- a/nbclassic/static/edit/js/main.js +++ b/nbclassic/static/edit/js/main.js @@ -15,6 +15,7 @@ requirejs([ 'edit/js/notificationarea', 'bidi/bidi', 'auth/js/loginwidget', + 'custom-preload' ], function( $, contents_service, diff --git a/nbclassic/static/notebook/js/main.js b/nbclassic/static/notebook/js/main.js index 5524598a3..51e3e7ce0 100644 --- a/nbclassic/static/notebook/js/main.js +++ b/nbclassic/static/notebook/js/main.js @@ -53,7 +53,8 @@ requirejs([ 'notebook/js/searchandreplace', 'notebook/js/clipboard', 'bidi/bidi', - 'notebook/js/celltoolbarpresets/tags' + 'notebook/js/celltoolbarpresets/tags', + 'custom-preload' ], function( $, contents_service, diff --git a/nbclassic/static/terminal/js/main.js b/nbclassic/static/terminal/js/main.js index 03ea2ab2e..2308895d3 100644 --- a/nbclassic/static/terminal/js/main.js +++ b/nbclassic/static/terminal/js/main.js @@ -8,6 +8,7 @@ requirejs([ 'auth/js/loginwidget', 'services/config', 'terminal/js/terminado', + 'custom-preload' ], function( $, utils, diff --git a/nbclassic/static/tree/js/main.js b/nbclassic/static/tree/js/main.js index 1bfb38914..8f1991e9c 100644 --- a/nbclassic/static/tree/js/main.js +++ b/nbclassic/static/tree/js/main.js @@ -38,6 +38,7 @@ requirejs([ 'tree/js/shutdownbutton', 'auth/js/loginwidget', 'bidi/bidi', + 'custom-preload' ], function( $, contents_service, diff --git a/nbclassic/templates/page.html b/nbclassic/templates/page.html index a8d71807d..510e7068b 100644 --- a/nbclassic/templates/page.html +++ b/nbclassic/templates/page.html @@ -30,6 +30,7 @@ paths: { 'auth/js/main': 'auth/js/main.min', custom : '{{ base_url }}custom', + 'custom-preload' : '{{ base_url }}custom-preload', nbextensions : '{{ base_url }}nbextensions', kernelspecs : '{{ base_url }}kernelspecs', underscore : 'components/underscore/underscore-min', @@ -99,6 +100,18 @@ } }) + // error-catching custom-preload.js shim. + define("custom-preload", function (require, exports, module) { + try { + var custom = require('custom/custom-preload'); + console.debug('loaded custom-preload.js'); + return custom; + } catch (e) { + console.error("error loading custom-preload.js", e); + return {}; + } + }) + document.nbjs_translations = {{ nbjs_translations|safe }}; document.documentElement.lang = navigator.language.toLowerCase(); diff --git a/tools/build-main.js b/tools/build-main.js index 6a5b29f23..bcd0db1d6 100644 --- a/tools/build-main.js +++ b/tools/build-main.js @@ -28,7 +28,9 @@ var rjs_config = { "xtermjs-fit": 'components/xterm.js-fit/index', "jquery-typeahead": 'components/jquery-typeahead/dist/jquery.typeahead.min', contents: 'empty:', - custom: 'empty:', + custom: 'empty:', + 'custom-preload': 'empty:', + }, map: { // for backward compatibility "*": { @@ -60,6 +62,7 @@ var rjs_config = { exclude: [ "custom/custom", + "custom/custom-preload", ] };