From abadaee2dcd9a8830539dd6bd52736d56460e147 Mon Sep 17 00:00:00 2001 From: yacchin1205 <968739+yacchin1205@users.noreply.github.com> Date: Fri, 2 Jun 2023 16:42:54 +0900 Subject: [PATCH] Fix version check for nbclassic --- .../nbextensions/collapsible_headings/main.js | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/jupyter_contrib_nbextensions/nbextensions/collapsible_headings/main.js b/src/jupyter_contrib_nbextensions/nbextensions/collapsible_headings/main.js index 1c8617fd3..ac9854824 100644 --- a/src/jupyter_contrib_nbextensions/nbextensions/collapsible_headings/main.js +++ b/src/jupyter_contrib_nbextensions/nbextensions/collapsible_headings/main.js @@ -579,6 +579,26 @@ }); } + /** + * Returns whether the version of Jupyter Notebook that needs to be patched, + * see also the description of patch_Tooltip. + * + * @returns {boolean} + */ + function no_patches_required() { + var major = Number(((sys_info && sys_info.notebook_version) ? + sys_info.notebook_version : Jupyter.version).split(".")[0]); + if (major >= 5) { + return true; + } + // Compatibility with nbclassic: nbclassic returns 1.x.0 as Jupyter.version, + // no patches required. + if (major === 1) { + return true; + } + return false; + } + /** * Return a promise which resolves when the Tooltip class methods have * been appropriately patched. @@ -595,7 +615,7 @@ * @return {Promise} */ function patch_Tooltip () { - if (Number(((sys_info) ? sys_info.notebook_version : Jupyter.version).split(".")[0]) >= 5) { + if (no_patches_required()) { return Promise.resolve(); } return new Promise(function (resolve, reject) {