From 04da9da53d6a35e6e874fc6479a17f476ae62c1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Moreira?= Date: Fri, 15 Dec 2023 15:09:36 +0100 Subject: [PATCH] No need to use once() --- clarin_bootstrap.libraries.yml | 3 +-- js/toc.js | 12 ++++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/clarin_bootstrap.libraries.yml b/clarin_bootstrap.libraries.yml index 5f5082b..beda606 100644 --- a/clarin_bootstrap.libraries.yml +++ b/clarin_bootstrap.libraries.yml @@ -23,5 +23,4 @@ clarin_toc: component: css/bootstrap-toc.min.css: { } dependencies: - - core/drupal - - core/once \ No newline at end of file + - core/drupal \ No newline at end of file diff --git a/js/toc.js b/js/toc.js index 39d68d8..1ed7ea0 100644 --- a/js/toc.js +++ b/js/toc.js @@ -3,18 +3,18 @@ * Initialize TOC * */ -(($, Drupal, once) => { +(($, Drupal) => { Drupal.behaviors.clarin_theme_toc = { attach: function attach(context) { - if (context === document) { + if (context === document && document.readyState !== "loading") { $(function initToc() { const navSelector = "#toc"; const scopeSelector = "#tocscope"; Toc.init({ - $nav: $(once("selectorID", navSelector, context)), - $scope: $(once("selectorID", scopeSelector, context)) + $nav: $(navSelector, context), + $scope: $(scopeSelector, context) }); - const body = $(once("selectorID", "body", context)); + const body = $("body", context); body.scrollspy({ target: navSelector }); @@ -22,4 +22,4 @@ } } }; -})(jQuery, Drupal, once); +})(jQuery, Drupal);