- 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:
@@ -51,6 +51,7 @@ include_once(PLGNTLS_class::root_path() . 'php/partner_check_page.php');
|
||||
// form builder patch :
|
||||
//include_once(PLGNTLS_class::root_path() . 'php/form_builder_patch/url_validation.php');
|
||||
//include_once(PLGNTLS_class::root_path() . 'php/form_builder_patch/multiple_modals.php');
|
||||
include_once(PLGNTLS_class::root_path() . 'php/form_builder_patch/form_calculation.php');
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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 = '';
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*/
|
||||
function add_form_calculation_patch_CIPF() {
|
||||
error_log('inside wp_enqueue');
|
||||
|
||||
$handle = 'form_calculation_patch';
|
||||
$url = PLGNTLS_class::root_url() . 'js/form_builder_patch/form_calculation.js';
|
||||
$dependencies = array('de_fb_calc');
|
||||
$version = '';
|
||||
$defer = true;
|
||||
wp_enqueue_script( $handle, $url, $dependencies, $version, $defer);
|
||||
}
|
||||
add_action('wp_enqueue_scripts', 'add_form_calculation_patch_CIPF', 999);
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -109,17 +109,16 @@ form_type
|
||||
|
||||
*/
|
||||
|
||||
function test_partner_CIPF($form_id, $post_array, $form_type) {
|
||||
function test_partner_CIPF($form_id, $post_array) {
|
||||
error_log("---");
|
||||
error_log("in test_partner_CIPF");
|
||||
error_log("form_id");
|
||||
error_log(json_encode($form_id));
|
||||
error_log("post_array");
|
||||
error_log(json_encode($post_array));
|
||||
error_log("form_type");
|
||||
error_log(json_encode($form_type));
|
||||
}
|
||||
add_action( 'df_before_process', 'test_partner_CIPF', 10, 3);
|
||||
add_action( 'df_before_process', 'test_partner_CIPF', 10, 2);
|
||||
add_action( 'df_after_process', 'test_partner_CIPF', 10, 2);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -195,13 +195,13 @@ class PLGNTLS_class
|
||||
}
|
||||
|
||||
|
||||
public function add_to_front($srcs_arr = null, $vars = null) {
|
||||
if (!is_array($vars))
|
||||
$vars = array();
|
||||
if (!is_null($srcs_arr)) {
|
||||
$this->add_fetch($srcs_arr, $vars);
|
||||
$this->add_default_css($srcs_arr, $vars);
|
||||
}
|
||||
public function add_to_front($srcs_arr = array(), $vars = array()) {
|
||||
/*
|
||||
* event if the function is called with no srcs
|
||||
* add fetch, because it can be used just for that
|
||||
*/
|
||||
$this->add_fetch($srcs_arr, $vars);
|
||||
$this->add_default_css($srcs_arr, $vars);
|
||||
|
||||
$srcs = array();
|
||||
foreach($srcs_arr as $src_key => $src_value) {
|
||||
@@ -368,14 +368,14 @@ class PLGNTLS_class
|
||||
/*
|
||||
* uncomment to print all enqueued files, can be usefull
|
||||
*/
|
||||
/*
|
||||
global $wp_scripts;
|
||||
error_log("wp_scripts->queue:");
|
||||
error_log(json_encode($wp_scripts->queue));
|
||||
*/
|
||||
/*
|
||||
global $wp_styles;
|
||||
error_log("wp_styles->queue:");
|
||||
error_log(json_encode($wp_styles->queue));
|
||||
*/
|
||||
}
|
||||
private function add_script($script, $previous_js_basename) {
|
||||
if (is_null($this->_first_script))
|
||||
|
||||
Reference in New Issue
Block a user