- in plgntls transformed process to add fetch script even if list of srcs is empty

- created a patch for form builder calculation
This commit is contained in:
asus
2024-03-12 19:54:18 +01:00
parent 591add448f
commit 38f9b0ba72
8 changed files with 109 additions and 22 deletions

View File

@@ -0,0 +1,66 @@
/*
* finds the input:checked in the element .calculate_field
* and trigger the event 'change' on it
* - this event 'change' is added by form builder in divi-form-calc-min.js :
* $(document).on(
* 'change',
* '.calculate_field input:not([type="hidden"]), .calculate_field select',
* function () {
* ...
* }
* );
*
*/
function trigger_change_CIPF(element) {
/*
* jquery version
*
let inputs = $(element).find('input:checked');
inputs.trigger('change');
*/
/*
* js version
*
*/
let inputs = element.querySelectorAll('input:checked');
// loop through inputs and trigger 'change' event on each
inputs.forEach(function(input) {
// Triggering 'change' event
let change_event = new Event('change', {
bubbles: true,
cancelable: true,
});
input.dispatchEvent(change_event);
});
}
let form_CIPF = document.querySelector('form.fb_form.multistep');
// create an observer on form to check if child nodes are modified
const observer_form_CIPF = new MutationObserver(wait_for_calculation_class_CIPF);
observer_form_CIPF.observe(form_CIPF, {
subtree: true,
attributes: true,
});
// observe mutations to see if they include the addition of class .calculate_field
// if the class is added, call the function that might trigger the change event on it
function wait_for_calculation_class_CIPF(mutationsList) {
mutationsList.forEach((mutation) => {
// check if class where added
if (mutation.type !== 'attributes')
return;
if (mutation.attributeName !== 'class')
return;
// check if added class is .calculate_field
let target = mutation.target;
if (target.classList.contains('calculate_field')) {
// If the class is added, trigger the 'change' event
trigger_change_CIPF(target);
}
});
}

View File

@@ -1,16 +1,16 @@
let modal_wrapper_UNIQ_ID_7623 = document.querySelector('#de-fb-modal-wrapper-');
let modal_wrapper_CIPF = document.querySelector('#de-fb-modal-wrapper-');
// create an observer on first #de-fb-modal-wrapper- to check if child nodes are added
const observer_UNIQ_ID_7623 = new MutationObserver(wait_for_close_button_UNIQ_ID_7623);
observer_UNIQ_ID_7623.observe(modal_wrapper_UNIQ_ID_7623, {
const observer_CIPF = new MutationObserver(wait_for_close_button_CIPF);
observer_CIPF.observe(modal_wrapper_CIPF, {
subtree: true,
childList: true,
});
// observe mutations to see if they include the creation of the button .modal-close
// if the button is created, add an eventListener to it
function wait_for_close_button_UNIQ_ID_7623(mutationsList) {
function wait_for_close_button_CIPF(mutationsList) {
mutationsList.forEach((mutation) => {
// check if nodes were added
if (mutation.type !== 'childList')
@@ -18,13 +18,13 @@ function wait_for_close_button_UNIQ_ID_7623(mutationsList) {
// check if added nodes includes the button .modal-close
let modal_close = document.querySelector('#de-fb-modal-wrapper- .modal-close');
if (modal_close !== null) {
modal_close.addEventListener("click", delete_modal_UNIQ_ID_7623);
modal_close.addEventListener("click", delete_modal_CIPF);
}
});
}
// when triggered, the .modal-close button will remove all childs from #de-fb-modal-wrapper-
function delete_modal_UNIQ_ID_7623() {
modal_wrapper_UNIQ_ID_7623.innerHTML = '';
function delete_modal_CIPF() {
modal_wrapper_CIPF.innerHTML = '';
}