From 6e519e960d818b0dd97aebd4cd940f8a7f01e228 Mon Sep 17 00:00:00 2001 From: Mingsong <2151-AMDS@users.noreply.drupalcode.org> Date: Tue, 21 Feb 2023 12:40:05 +1100 Subject: [PATCH] Issue #3341369 by SirClickALot, Mingsong: No tree visible on clean install on Drupal 10 --- hierarchy_manager.libraries.yml | 1 + js/Plugin/jstree/hm.jstree.js | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/hierarchy_manager.libraries.yml b/hierarchy_manager.libraries.yml index 39c511b..e4db988 100644 --- a/hierarchy_manager.libraries.yml +++ b/hierarchy_manager.libraries.yml @@ -10,6 +10,7 @@ feature.hm.jstree: - hierarchy_manager/libraries.jquery.jstree - core/drupalSettings - core/drupal.message + - core/once feature.hm.jsoneditor: js: diff --git a/js/Plugin/jstree/hm.jstree.js b/js/Plugin/jstree/hm.jstree.js index ed9b21b..b87e959 100644 --- a/js/Plugin/jstree/hm.jstree.js +++ b/js/Plugin/jstree/hm.jstree.js @@ -5,13 +5,13 @@ // Codes run both on normal page loads and when data is loaded by AJAX (or BigPipe!) // @See https://www.drupal.org/docs/8/api/javascript-api/javascript-api-overview -(function($, Drupal) { +(function($, Drupal, once) { Drupal.behaviors.hmJSTree = { attach: function(context, settings) { - $(".hm-jstree", context) - .once("jstreeBehavior") - .each(function() { - const treeContainer = $(this); + const hmJstree = once('hmJSTree', '.hm-jstree', context); + // Render all trees. + hmJstree.forEach(function(hmJstree) { + const treeContainer = $(hmJstree); const parentID = treeContainer.attr('parent-id'); const searchTextID = (parentID) ? '#hm-jstree-search-' + parentID : '#hm-jstree-search'; const optionsJson = treeContainer.attr("options"); @@ -251,4 +251,4 @@ return modalConfirmationForm.dialog('open'); } -})(jQuery, Drupal); +})(jQuery, Drupal, once); -- GitLab