1(function ($) { 2 "use strict"; 3 var extcf7_show_animation = { 4 "height": "show", 5 "marginTop": "show", 6 "marginBottom": "show", 7 "paddingTop": "show", 8 "paddingBottom": "show" 9 }; 10 11 var extcf7_hide_animation = { 12 "height": "hide", 13 "marginTop": "hide", 14 "marginBottom": "hide", 15 "paddingTop": "hide", 16 "paddingBottom": "hide" 17 }; 18 19 var extcf7_animation_status = extcf7_conditional_settings.animitation_status; 20 var extcf7_animation_intime = parseInt(extcf7_conditional_settings.animitation_in_time); 21 var extcf7_animation_out_time = parseInt(extcf7_conditional_settings.animitation_out_time); 22 var condition_depends_field = []; 23 24 // Initialize the all form field. 25 function extcf7_global(){ 26 $('.wpcf7-form').each(function(){ 27 const form = $(this), 28 conditional_options = form.find('input[name="_extcf7_conditional_options"]'); 29 if( !conditional_options.length ){ 30 return; 31 } 32 33 const options_element = conditional_options.eq(0); 34 35 if (!options_element.length || !options_element.val()) { 36 return; 37 } 38 39 const form_options = JSON.parse(options_element.val()); 40 41 form_options.conditions.forEach(function(condition){ 42 const rule_applied_field = $('[data-id="'+condition.rule_applied_field+'"]');
43 condition.and_condition_rules.forEach(function(rules){ 44 45 if(!condition_depends_field.includes(rules.if_field_input)){ 46 condition_depends_field.push(rules.if_field_input); 47 } 48 49 const from_field_selector = extcf7_input_checkbox_name(form, rules.if_field_input); 50 extcf7_check_condition(form, condition.and_condition_rules, rule_applied_field); 51 52 from_field_selector.each(function(){ 53 const tag = $(this).get(0); 54 55 if( tag.tagName == 'INPUT' ){ 56 var input_attr_type = $(this).attr('type'); 57 if(input_attr_type == 'text'){ 58 from_field_selector.on('keyup', function(){ 59 extcf7_check_condition(form, condition.and_condition_rules, rule_applied_field); 60 }); 61 }else if(input_attr_type == 'email'){ 62 from_field_selector.on('keyup', function(){ 63 extcf7_check_condition(form, condition.and_condition_rules, rule_applied_field); 64 }); 65 }else if(input_attr_type == 'radio'){ 66 from_field_selector.on('change', function(){ 67 extcf7_check_condition(form, condition.and_condition_rules, rule_applied_field); 68 }); 69 }else if(input_attr_type == 'checkbox'){ 70 from_field_selector.on('change', function(){ 71 extcf7_check_condition(form, condition.and_condition_rules, rule_applied_field); 72 }); 73 } 74 }else if( tag.tagName == 'SELECT' ){ 75 from_field_selector.on('change', function(){ 76 extcf7_check_condition(form, condition.and_condition_rules, rule_applied_field); 77 }); 78 }else if( tag.tagName == 'TEXTAREA' ){ 79 from_field_selector.on('keyup', function(){ 80 extcf7_check_condition(form, condition.and_condition_rules, rule_applied_field); 81 }); 82 } 83 }); 84 }); 85 }); 86 87 }); 88 } 89 90 // show hide field based on conditional value 91 function extcf7_check_condition(form, coditions_rules, rule_applied_field){ 92 var condition_status = extcf7_is_condition_ok(form, coditions_rules); 93 if(condition_status){ 94 if('on' == extcf7_animation_status){ 95 rule_applied_field.animate(extcf7_show_animation, extcf7_animation_intime); 96 }else{ 97 rule_applied_field.show(); 98 } 99 }else{ 100 if(rule_applied_field.data('clear') !== undefined){ 101 clear_fied_on_hide(rule_applied_field); 102 } 103 if('on' == extcf7_animation_status){ 104 rule_applied_field.animate(extcf7_hide_animation, extcf7_animation_out_time); 105 }else{ 106 rule_applied_field.hide(); 107 } 108 } 109 } 110 111 //check input type checkbox name 112 function extcf7_input_checkbox_name(form, from_field_selector){ 113 var input_tag =$(form).find(`[name="${from_field_selector}"]`); 114 if( typeof input_tag.get(0) === "undefined"){ 115 input_tag = $(form).find(`[name="${from_field_selector}[]"]`); 116 } 117 return input_tag; 118 } 119 120 //check applied condition is true or flase basen on field value 121 function extcf7_is_condition_ok(form, conditions){ 122 123 var condition_status; 124 var conditon_length = conditions.length; 125 var pre_input_val; 126 var current_input_val; 127 var pre_cnd; 128 var current_cnd; 129 var next_input_val; 130 var next_cnd; 131 132 for (var k = 0; k < conditon_length; k++){ 133 134 if('and' == conditions[k].if_type_input || 'or' == conditions[k].if_type_input){ 135 pre_input_val = extcf7_get_input_val(form, conditions[k-1]); 136 current_input_val = extcf7_get_input_val(form, conditions[k]); 137 pre_cnd = extcf7_compare_condition(conditions[k-1], pre_input_val); 138 current_cnd = extcf7_compare_condition(conditions[k], current_input_val); 139 if( k < conditon_length - 1 ){ 140 next_input_val = extcf7_get_input_val(form, conditions[k+1]); 141 next_cnd = extcf7_compare_condition(conditions[k+1], next_input_val); 142 } 143 } 144 145 if(!conditions[k].if_type_input){ 146 var if_field_input_value = extcf7_get_input_val(form, conditions[k]); 147 var field_value_status = extcf7_compare_condition(conditions[k],if_field_input_value); 148 149 if( conditon_length > 1 ){ 150 condition_status = extcf7_1st_cnd_method(form, conditions,field_value_status); 151 return condition_status; 152 break; 153 }else{ 154 condition_status = field_value_status; 155 } 156 157 }else if('and' == conditions[k].if_type_input){ 158 159 if(conditions[k+1].if_type_input == 'and'){ 160 condition_status = pre_cnd && current_cnd && next_cnd ? true : false;
161 }else{ 162 condition_status = (pre_cnd && current_cnd) || next_cnd ? true : false; 163 } 164 165 }else if('or' == conditions[k].if_type_input){ 166 167 if(conditions[k+1].if_type_input == 'and'){ 168 condition_status = (pre_cnd || current_cnd) && next_cnd ? true : false; 169 }else{ 170 condition_status = (pre_cnd || current_cnd) || next_cnd ? true : false; 171 } 172 173 } 174 } 175 return condition_status; 176 } 177 178 // compare conditonal logic for the very fast if condition 179 function extcf7_1st_cnd_method(form, conditions,first_value_status){ 180 var cnd_status = first_value_status; 181 var input_value; 182 var value_status; 183 for (var i = 1; i < conditions.length; i++) { 184 input_value = extcf7_get_input_val(form, conditions[i]); 185 value_status = extcf7_compare_condition(conditions[i],input_value); 186 if(conditions[i].if_type_input == 'and'){ 187 cnd_status = cnd_status && value_status; 188 }else{ 189 cnd_status = cnd_status || value_status; 190 } 191 } 192 193 return cnd_status; 194 } 195 196 // compare the input field value with conditional field value 197 function extcf7_compare_condition(rules,input_value){ 198 if(rules.operator_input == "equal"){ 199 if(input_value == rules.if_value_input){ 200 return true; 201 } 202 }else if(rules.operator_input == "not-equal"){ 203 if(input_value != rules.if_value_input){ 204 return true; 205 } 206 } 207 208 return false; 209 } 210 211 // get the form input field value 212 function extcf7_get_input_val(form, rules){ 213 214 var if_input_value; 215 var if_input_selector = extcf7_input_checkbox_name(form, rules.if_field_input); 216 217 if(if_input_selector.get(0).tagName == 'INPUT' && if_input_selector.attr('type') == 'checkbox'){ 218 if(if_input_selector.prop("checked") == true){ 219 if_input_value = "checked" 220 }else if(if_input_selector.prop("checked") == false){ 221 if_input_value = "unchecked" 222 } 223 }else if(if_input_selector.get(0).tagName == 'INPUT' && if_input_selector.attr('type') == 'radio'){ 224 var radio_selector = $(form).find(':input[value="'+rules.if_value_input+'"]'); 225 if(radio_selector.prop("checked")){ 226 if_input_value = radio_selector.val(); 227 } 228 }else{ 229 if_input_value = if_input_selector.val(); 230 } 231 232 return if_input_value; 233 } 234 235 //clear field on hide 236 function clear_fied_on_hide(rule_applied_field ){ 237 var $inputs = $(':input', rule_applied_field).not(':button, :submit, :reset, :hidden'); 238 $inputs.each(function(){ 239 var $this = $(this); 240 $this.val(this.defaultValue); 241 $this.prop('checked', this.defaultChecked); 242 if(condition_depends_field.includes($this.attr('name'))){ 243 $this.trigger("change"); 244 $this.trigger("keyup"); 245 } 246 }); 247 248 $('textarea', rule_applied_field).each(function() { 249 var $this = $(this); 250 $this.val(this.defaultValue); 251 if(condition_depends_field.includes($this.attr('name'))){ 252 $this.trigger("keyup"); 253 } 254 }); 255 256 $('select', rule_applied_field).each(function() { 257 var $this = $(this); 258 if ($this.val() === null) { 259 $this.val($("option:first",$this).val()); 260 if(condition_depends_field.includes($this.attr('name'))){ 261 $this.trigger("change"); 262 } 263 } 264 }); 265 } 266 267 extcf7_global(); 268 269 if ( 'true' === extcf7_conditional_settings.elementor_editor_mode ) { 270 $( window ).on( 'elementor/frontend/init', function () { 271 elementorFrontend.hooks.addAction( 'frontend/element_ready/widget', function ( $scope, $ ) { 272 extcf7_global(); 273 } ); 274 } ); 275 } 276 277})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.