1/** 2 * Main iubenda frontend functions 3 * 4 * @package Iubenda 5 */ 6 7(function ($) { 8 9 $( document ).ready( 10 function () { 11 12 var iubendaConsentSolution = new function () { 13 var _this = this; 14 15 // parse args. 16 var args = iubForms; 17 18 // console.log( args );. 19 20 // get forms. 21 this.init = function () { 22 // loop though plugins. 23 if ($( args ).length > 0) { 24 $.each( 25 args, 26 function (source, forms) { 27 // loop through forms. 28 if ($( forms ).length > 0) { 29 $.each( 30 forms, 31 function (id, form) { 32 // console.log( form );. 33 34 // get corresponding html form id. 35 switch (source) { 36 37 // WooCommerce Checkout Form. 38 case 'woocommerce' : 39 var htmlFormContainer = $( '.woocommerce-checkout' ); 40 41 // form exists, let's use it. 42 if (htmlFormContainer.length > 0) { 43 // setup vars. 44 formArgs = { 45 submitElement: null, 46 form: { 47 selector: document.querySelectorAll( 'form.woocommerce-checkout' )[0], 48 map: form.form.map 49 } 50 }; 51 52 // handle ajax submit. 53 $( htmlFormContainer ).on( 54 'checkout_place_order', 55 function (e) { 56 _this.submitForm( form, formArgs ); 57 58 _iub.cons.sendData(); 59 // don't send before page refresh. 60 // on successful submit it will be sent automatically. 61 // _iub.cons.sendFromLocalStorage();. 62 } 63 ); 64 } 65 66 break; 67 68 // WordPress Comment Form. 69 case 'wp_comment_form' : 70 var htmlFormContainer = $( '#commentform' ); 71 72 // form exists, let's use it. 73 if (htmlFormContainer.length > 0) { 74 // adjust submit element id. 75 var submitElement = document.getElementById( htmlFormContainer.attr( 'id' ) ).querySelectorAll( 'input[type=submit]' )[0]; 76 77 /* id="submit" override 78 if ( typeof submitElement !== 'undefined' && submitElement.name == 'submit' ) { 79 submitElement.id = 'wp-comment-submit'; 80 submitElement.name = 'wp-comment-submit'; 81 } 82 */ 83 84 // setup vars. 85 formArgs = { 86 // submitElement: submitElement,. 87 submitElement: null, 88 form: { 89 selector: document.getElementById( htmlFormContainer.attr( 'id' ) ), 90 map: form.form.map 91 } 92 }; 93 94 $( submitElement ).on( 95 'click touchstart', 96 function (e) { 97 _this.submitForm( form, formArgs ); 98 99 _iub.cons.sendData(); 100 // don't send before page refresh. 101 // on successful submit it will be sent automatically. 102 // _iub.cons.sendFromLocalStorage();. 103 } 104 ); 105 } 106 107 break; 108 109 // Contact Form 7. 110 case 'wpcf7' : 111 // var regex = new RegExp( '^wpcf7-f([0-9]*)-' );. 112 var htmlFormContainer = $( 'div[id^="wpcf7-f' + id + '-"]' ); 113 114 // form exists, let's use it. 115 if (htmlFormContainer.length > 0) { 116 var selector = document.getElementById( htmlFormContainer.attr( 'id' ) ).getElementsByClassName( 'wpcf7-form' )[0]; 117 118 // handle ajax submit. 119 $( document ).on( 120 'wpcf7mailsent', 121 selector, 122 function (e) { 123 // setup vars. 124 formArgs = { 125 // submitElement: document.getElementById( htmlFormContainer.attr( 'id' ) ).getElementsByClassName( 'wpcf7-submit' )[0],. 126 submitElement: null, 127 form: { 128 selector: selector, 129 map: form.form.map 130 } 131 }; 132 133 // send only if specific form has been submitted. 134 if ((selector.parentElement.id == e.target.parentElement.id) || (selector.parentElement.id == e.target.id)) { 135 _this.submitForm( form, formArgs ); 136 137 _iub.cons.sendData(); 138 _iub.cons.sendFromLocalStorage(); 139 } 140 } 141 ); 142 143 }; 144 145 break; 146 147 // WP Forms. 148 case 'wpforms' : 149 var htmlFormContainer = $( 'div[id^="wpforms-' + id + '"]' ); 150 151 // form exists, let's use it. 152 if (htmlFormContainer.length > 0) { 153 var selector = document.getElementById( 'wpforms-form-' + id ); 154 var isAjax = $( '#wpforms-form-' + id ).hasClass( 'wpforms-ajax-form' ); 155 156 // handle ajax submit. 157 $( document ).on( 158 'wpformsAjaxSubmitSuccess', 159 selector, 160 function (e) { 161 // setup vars. 162 formArgs = { 163 submitElement: (isAjax ? null : document.getElementById( 'wpforms-submit-' + id )), 164 form: { 165 selector: selector, 166 map: form.form.map 167 } 168 }; 169 170 // send only if specific form has been submitted. 171 if (selector.id == e.target.id) { 172 _this.submitForm( form, formArgs ); 173 174 _iub.cons.sendData(); 175 _iub.cons.sendFromLocalStorage(); 176 } 177 } 178 ); 179 }; 180 181 break; 182 // Elementor forms. 183 case 'elementor_forms' : 184 // Iterate over each Elementor form with a parent div that has data-elementor-id="id" and attach the submit_success event listener. 185 form_id = id 186 if (id.indexOf( '-' ) >= 0) { 187 var form_id = id.split( '-' )[1]; 188 } 189 190 $( 'div[data-id="' + form_id + '"] form.elementor-form' ).each( 191 function (index, item) { 192 $( item ).on( 193 'submit_success', 194 function (event) { 195 var formElement = event.target; 196 197 // Set up form arguments. 198 var formArgs = { 199 form: { 200 selector: formElement, 201 map: form.form.map 202 } 203 }; 204 205 _this.submitForm( form, formArgs ); 206 _iub.cons.sendData(); 207 _iub.cons.sendFromLocalStorage(); 208 } 209 ); 210 } 211 ); 212 213 break; 214 } 215 216 // console.log( source );. 217 } 218 ); 219 } 220 } 221 ); 222 } 223 }; 224 225 // submit form. 226 this.submitForm = function (form, formArgs) { 227 // push consent vars. 228 if (typeof form.consent !== 'undefined' && form.consent.legal_notices.length > 0) { 229 formArgs.consent = {}; 230 formArgs.consent.legal_notices = form.consent.legal_notices; 231 } 232 233 console.log( formArgs ); 234 235 // build form consent data. 236 _iub.cons_instructions.push( ['load', formArgs] ); 237 }; 238 239 }; 240 241 // initialize.
242 iubendaConsentSolution.init(); 243 244 } 245 ); 246 247 // Integrate with mailchimp. 248 // Remove the hidden input of mailchimp to avoid the duplicate while saving the cons. 249 if ($( '#_mc4wp_subscribe_woocommerce' ).length) { 250 $( window ).load( 251 function () { 252 var mc_subscribe_checkbox = $( '#_mc4wp_subscribe_woocommerce' ) 253 mc_subscribe_checkbox.on( 254 'change', 255 function (event) { 256 if (event.currentTarget.checked) { 257 $( 'input:hidden[name=_mc4wp_subscribe_woocommerce]' ).remove(); 258 return; 259 } 260 mc_subscribe_checkbox.before( '<input type="hidden" name="_mc4wp_subscribe_woocommerce" value="0">' ); 261 } 262 ); 263 } 264 ); 265 } 266 267})( 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.