From b9fb95f201fc90ae26d14d4ef241bb25bb7adae8 Mon Sep 17 00:00:00 2001 From: Benoit Alessandroni <benoit@happy-dev.fr> Date: Tue, 2 Mar 2021 22:17:16 +0100 Subject: [PATCH] update: fix connector script --- js/connector-script.js | 66 ++++++++++-------------------------------- search-box.js | 2 +- 2 files changed, 16 insertions(+), 52 deletions(-) diff --git a/js/connector-script.js b/js/connector-script.js index 69338a3..4ff1bdb 100644 --- a/js/connector-script.js +++ b/js/connector-script.js @@ -78,44 +78,6 @@ function manageAccordionByStep(){ } } -/** - * Manage select hidden to fullfill them with more "more criterias" selection - * @param {HTMLElement} select_hidden - Hidden select to fullfill. - * @param {HTMLElement} option_selected - Option selcted to set in hidden select. - */ -function selectHiddenManagement(select_hidden, option_selected) { - options_hidden = select_hidden.getElementsByTagName("option"); - for (let option_hidden of options_hidden) { - //Removing the selected attribute from previous selection - option_hidden.removeAttribute("selected"); - - if (option_hidden.value == option_selected.value) { - //Actually selecting the option if it is the good one - option_hidden.setAttribute("selected", "selected"); - select_hidden.setAttribute("value", option_selected.value); - } - } - - //Trigerring a reload of the associated form - let parent_form = select_hidden.closest("sib-form"); - parent_form.component.inputChange(); - refreshPagination(); - }; - - - -/** - * Manage input hidden field to fullfill them with more "more criterias" selection - * @param {HTMLElement} field - Hidden field to fullfill. - * @param {HTMLElement} field_search - Field with the value wanted by the user. - */ -function inputHiddenManagement(field, field_search) { - field.setAttribute("value", field_search.value); - let parent_form = field.closest("sib-form"); - parent_form.component.inputChange(); - refreshPagination(); -} - /** * Manage select hidden for type to fullfill them with more "more criterias" selection * @param {HTMLElement} tab - Selected type tabs. @@ -127,9 +89,9 @@ function selectHiddenManagementForType(tab, form) { let type_field_search = tab .querySelector(`solid-display`) .getAttribute("data-src"); + //Fullfill hidden field let hidden_type_select = form.querySelector('select[name="type"]'); - hidden_options = hidden_type_select.getElementsByTagName("option"); for (let hidden_option of hidden_options) { hidden_option.removeAttribute("selected"); @@ -154,13 +116,16 @@ function selectHiddenManagementForType(tab, form) { /** * Init type to type 1 */ -function InitManagementForType(timeout) { - setTimeout(function() { - var tabs = document.querySelectorAll(".tablink.filter_by_type"); - tabs[0].click(); - tabs[0].classList.add("active"); - refreshPagination(); - }, timeout); +function initManagementForType(filterFormId) { + var tabs = document.querySelectorAll(".tablink.filter_by_type"); + var form = document.getElementById(filterFormId); + var baseElement = document.querySelector('solid-display.resource_by_step.panel'); + + if (baseElement) { + baseElement.addEventListener("populate", event => { + selectHiddenManagementForType(tabs[0], form); + }); + } } /** @@ -171,7 +136,6 @@ function InitManagementForType(timeout) { */ function addProperFilterToSearchComponents(targetId, filterFormId) { var baseElement = document.getElementById(targetId); - if (baseElement) { // Adding default type management var form = document.getElementById(filterFormId); @@ -190,12 +154,12 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXX ON LOAD XXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*/ (function() { - refreshPagination(); - addProperFilterToSearchComponents("coopedia-search-results-component", "coopedia-search-box-component"); window.setTimeout( function() { + refreshPagination(); manageAccordionByStep(); - }, 3000); - InitManagementForType(3000); + addProperFilterToSearchComponents("coopedia-search-results-component", "coopedia-search-box-component"); + initManagementForType("coopedia-search-box-component"); + }, 4000); })(); diff --git a/search-box.js b/search-box.js index 2500d72..6007c8b 100644 --- a/search-box.js +++ b/search-box.js @@ -1,4 +1,4 @@ -import { SolidTemplateElement, Helpers } from 'https://cdn.skypack.dev/@startinblox/core@0.15'; +import { SolidTemplateElement, Helpers } from 'https://cdn.skypack.dev/@startinblox/core@beta'; // Dev Mode // const base_url = import.meta.url.replace(/\/[^\/]*$/, ''); -- GitLab