diff --git a/plugins/cipf_plugin/fipfcard_plugin.php b/plugins/cipf_plugin/fipfcard_plugin.php index 7241b04..4dbe7b5 100644 --- a/plugins/cipf_plugin/fipfcard_plugin.php +++ b/plugins/cipf_plugin/fipfcard_plugin.php @@ -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'); diff --git a/plugins/cipf_plugin/js/form_builder_patch/form_calculation.js b/plugins/cipf_plugin/js/form_builder_patch/form_calculation.js new file mode 100644 index 0000000..d420f3d --- /dev/null +++ b/plugins/cipf_plugin/js/form_builder_patch/form_calculation.js @@ -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); + } + }); +} + diff --git a/plugins/cipf_plugin/js/form_builder_patch/multiple_modals.js b/plugins/cipf_plugin/js/form_builder_patch/multiple_modals.js index cd418c1..946f8b6 100644 --- a/plugins/cipf_plugin/js/form_builder_patch/multiple_modals.js +++ b/plugins/cipf_plugin/js/form_builder_patch/multiple_modals.js @@ -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 = ''; } diff --git a/plugins/cipf_plugin/php/form_builder_patch/form_calculation.php b/plugins/cipf_plugin/php/form_builder_patch/form_calculation.php new file mode 100644 index 0000000..bfb1407 --- /dev/null +++ b/plugins/cipf_plugin/php/form_builder_patch/form_calculation.php @@ -0,0 +1,21 @@ + diff --git a/plugins/cipf_plugin/php/partner_check_page.php b/plugins/cipf_plugin/php/partner_check_page.php index e77253b..a658f67 100644 --- a/plugins/cipf_plugin/php/partner_check_page.php +++ b/plugins/cipf_plugin/php/partner_check_page.php @@ -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); diff --git a/plugins/cipf_plugin/utils/plgntls_class.php b/plugins/cipf_plugin/utils/plgntls_class.php index 6dee13c..9dfbf68 100644 --- a/plugins/cipf_plugin/utils/plgntls_class.php +++ b/plugins/cipf_plugin/utils/plgntls_class.php @@ -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)) diff --git a/private b/private index a85c727..a37c901 160000 --- a/private +++ b/private @@ -1 +1 @@ -Subproject commit a85c727e9d882e1e2645eca32b6f17d60275fb21 +Subproject commit a37c901a74caf6422783fcf73e82242d58978015 diff --git a/wordpress_docker b/wordpress_docker index 3181248..3c0a32e 160000 --- a/wordpress_docker +++ b/wordpress_docker @@ -1 +1 @@ -Subproject commit 3181248be9b7f2b16d607b2bbb21a959cd7adc4f +Subproject commit 3c0a32e6ac325f7983ef51be3196173297b9aa05