1/**/ 2function cff_woocommerce_integration() 3{ 4 if('cff_woocommerce_integration' in fbuilderjQuery) return; 5 fbuilderjQuery['cff_woocommerce_integration'] = 1; 6 7 var $ = fbuilderjQuery, 8 quote_requesting = false; 9 10 function _aux() { 11 $( '[name="woocommerce_cpcff_request_quote_action"]' ).remove(); 12 quote_requesting = false; 13 }; 14 15 $(document).on( 'cff-form-submitted', function(){ _aux(); } ); 16 17 window[ 'cpcff_woocommerce_validate'] = function( fId, e ) 18 { 19 var r = true; 20 21 $(e).find('[max=""]').removeAttr('max'); 22 $(e).find('[min=""]').removeAttr('min'); 23 $(e).find('[name="quantity"][type="input"]').attr('type','number'); 24 $(e).find('[type="input"][step],[type="hidden"][step]').removeAttr('step'); 25 26 if( typeof $.fn.valid !== 'undefined' ) r = $( e ).valid(); 27 28 if( !r ) 29 { 30 setTimeout( 31 (function( $, e ) 32 { 33 return function() 34 { 35 $( e ).find( ':submit' ).removeAttr( 'disabled' ); 36 }; 37 })( $, e ), 38 500 39 ); 40 } 41 else 42 { 43 if( typeof fbuilderjQuery !== 'undefined' && fbuilderjQuery.fn.valid !== 'undefined' ) r = fbuilderjQuery( e ).valid(); 44 if( typeof window[ 'doValidate'+fId ] != 'undefined' ) r = window[ 'doValidate'+fId ]( e ); 45 } 46 47 if ( ! r ) { 48 _aux(); 49 } 50 return r; 51 }; 52 53 $('[name="cp_calculatedfieldsf_pform_psequence"]').each( 54 function() 55 { 56 var e = $( this ), 57 fId = e.val(), 58 w = e.closest( '.cpcff-woocommerce-wrapper' ); 59 60 if( 61 w.length && 62 typeof window[ 'doValidate' + fId ] != 'undefined' 63 ) 64 { 65 let f = w.closest( 'form' ); 66 f.attr( 'id', 'cp_calculatedfieldsf_pform' + fId ) 67 .attr( 'name', 'cp_calculatedfieldsf_pform' + fId ) 68 .attr( 'onsubmit', 'return cpcff_woocommerce_validate( "' + fId + '", this )' ) 69 .css('display', 'block') 70 .addClass('no-prefetch') 71 .parent().on('submit', function(evt){ /* Fix conflict with Side Cart Woocommerce (Ajax) - XootiX */ 72 evt.preventDefault(); 73 evt.stopPropagation(); 74 return false; 75 }); 76 w.find( '.pbSubmit' ).remove(); 77 if ( w.attr('data-request-quote-button') ) { 78 $(document).on('formReady', function( evt, form_identifier ){ 79 if ( form_identifier == f.attr('id') ) { 80 if ( ! f.find( '.cff-request-quote-button' ).length ) { 81 let p = w.find('.pbreak').last(); 82 if ( !p.hasClass('pb0')) p = $('.cff-form-buttons-container', p).last(); 83 p.append('<div class="fields cff-button-field cff-request-quote-button-container"><input type="button" value="'+w.attr('data-request-quote-button')+'" class="field cff-request-quote-button"></div>'); 84 } 85 86 // The events. 87 $(document).on( 'click', '#'+form_identifier+' .cff-request-quote-button', function(){ 88 _aux(); 89 quote_requesting = true; 90 $(this.form).append('<input type="hidden" name="woocommerce_cpcff_request_quote_action" value="1">'); 91 $(this.form).submit(); 92 } ); 93 } 94 }); 95 } 96 } 97 } 98 ); 99 100 // Fix a conflict with Divi and other third-party themes 101 102 $('form[name*="cp_calculatedfieldsf_pform_"] [type="hidden"][step]').removeAttr('step'); 103 $('form[name*="cp_calculatedfieldsf_pform_"] [max=""]').removeAttr('max'); 104 $('form[name*="cp_calculatedfieldsf_pform_"] [min=""]').removeAttr('min'); 105 $('form[name*="cp_calculatedfieldsf_pform_"] [name="add-to-cart"]').on('mousedown', function(evt){ 106 $('form[name*="cp_calculatedfieldsf_pform_"] [max=""]').removeAttr('max'); 107 $('form[name*="cp_calculatedfieldsf_pform_"] [min=""]').removeAttr('min'); 108 cff_woocommerce_stop_submission = false; 109 let me = $(this); 110 if(!me.closest('form').valid()){ 111 cff_woocommerce_stop_submission = true; 112 setTimeout(function(){me.removeClass('loading');}, 1000); 113 evt.stopPropagation(); 114 evt.preventDefault(); 115 setTimeout(function(){$.fbuilder.openErrorDlg(me.closest('form'));},50); 116 return false; 117 } 118 }) 119 .on('mouseup click', function(evt){ 120 if(cff_woocommerce_stop_submission) { 121 evt.stopPropagation(); 122 evt.preventDefault(); 123 return false; 124 } else { 125 $(this).closest('form').submit(); 126 } 127 }); 128 129 // Integration with "opc_add_remove_product" 130 $(document).on( 'opc_add_remove_product', function(evt, data, e, selectors){ 131 if( 132 'action' in data && 133 data['action'] == 'pp_add_to_cart' && 134 'input_data' in data && 135 data['input_data'].indexOf('woocommerce_cpcff_form') != -1 136 ) 137 { 138 data['invalid'] = true; 139 jQuery(selectors).closest('form').submit(); 140 } 141 }); 142 143 // Quantity 144 $('[name="woocommerce_cpcff_quantity_field"]').each( function(){ 145 var f = $(this.form), 146 s = String(this.value).trim(), 147 q = f.find('[name="quantity"]'), 148 i = $('[name="cp_calculatedfieldsf_pform_psequence"]', f).val(), 149 changeFlag = false; 150 151 if(q.length) 152 { 153 $(document).on('change', '[id*="'+s+i+'"]', function(){q.val(this.value); if(!changeFlag){changeFlag = true; q.trigger('change');} else changeFlag = false;}); 154 q.on('change', function(){var e = $('[id*="'+s+i+'"]'); if(e.length){e.val(this.value); if(!changeFlag){changeFlag = true; e.trigger('change');} else changeFlag = false;}}); 155 156 $(document).on( 157 'formReady', 158 ( 159 function( selector, quantity ){ 160 return function() { 161 let e = $( selector ); 162 if ( e.length ) { 163 // Updates min/max in the form field. 164 let q_min = quantity.attr('min'), 165 q_max = quantity.attr('max'), 166 e_min = e.attr('min'), 167 e_max = e.attr('max'); 168 169 if( q_max ) { 170 if ( e_max ) e.attr('max', Math.min(q_max, e_max)); 171 else e.attr('max', q_max); 172 } 173 174 if( q_min ) { 175 if ( e_min ) e.attr('min', Math.max(q_min, e_min, 0)); 176 else e.attr('min', Math.max(q_min, 0)); 177 } 178 179 let v = e.val(); 180 if ( ! isNaN( v*1 ) && v*1 ) e.trigger('change'); 181 else quantity.trigger('change'); 182 } else quantity.trigger('change'); 183 }; 184 } 185 ) ( '[id*="'+s+i+'"]', q ) 186 ); 187 } 188 }); 189 190 // Refresh the product price. 191 $('[name="woocommerce_cpcff_field"]').each( 192 function() 193 { 194 var e = $( this ), 195 f = e.siblings( '[name="woocommerce_cpcff_form"]' ), 196 a = f.siblings( '[name="woocommerce_cpcff_product"]' ), 197 s = $( '[name="cp_calculatedfieldsf_id"][value="' + f.val() + '"]' ).siblings( '[name="cp_calculatedfieldsf_pform_psequence"]' ).val(), 198 p = e.val()+s; 199 200 if ( ! $(a).length ) return; 201 202 function replacePrice(e, product) 203 { 204 let price = e.val(); 205 206 function setPrice( price ) { 207 if(typeof woocommerce_price_selector != 'undefined') 208 { 209 $(woocommerce_price_selector).html(price); 210 } 211 else 212 { 213 $( '[id="product-'+product+'"],.post-'+product+',.postid-'+product ) 214 .find( '.summary .woocommerce-Price-amount.amount,.wp-block-woocommerce-product-price .wc-block-components-product-price,.summary .price' ) 215 .each( 216 function() 217 { 218 if( 219 $( this ).closest( 'del' ).length == 0 && 220 $( this ).closest( '.widget_shopping_cart' ).length == 0 221 ) { 222 $( this ).html( price ); 223 return false; 224 } 225 } 226 ); 227 } 228 }; 229 230 if ( typeof woocommerce_cpcff_product_price_tax != 'undefined' && woocommerce_cpcff_product_price_tax ) { 231 let o = getField(e); 232 if (o) price = o.val(false, true); 233 GET_PRODUCT_PRICE_WITH_TAX( String(price).replace(/[^\d\.]/i, ''), product, null, function( price ){ 234 setPrice( price ); 235 }, true ); 236 } else { 237 setPrice( price ); 238 } 239 } 240 241 $( document ).on('change cff_wc_update', '#'+e.val()+s, (function(a){ 242 return function(evt){ 243 replacePrice($(evt.target), a); 244 }; 245 })(a.val())); 246 247 $( document ).on( 248 'cpcff_default_calc', 249 '#cp_calculatedfieldsf_pform'+s, 250 (function(a, p){ 251 return function( evt ){ 252 replacePrice($( '#'+p ), a); 253 } 254 })(a.val(), e.val()+s) 255 ); 256 257 // Update price when form load. 258 if ( String(p).length && $('#'+p).length ) { 259 replacePrice($( '#'+p ), a.val() ); 260 } else { 261 $(document).on('formReady', function(){ 262 if ( String(p).length && $('#'+p).length ) { 263 replacePrice($( '#'+p ), a.val() ); 264 } 265 }); 266 } 267 } 268 ); 269 270 // To get variation prices and evaluate the equations 271 function check_forms_and_evaluate_equations(to_search) 272 { 273 var form, equation, fields = [], e, bk; 274 for(var i in document.forms) 275 { 276 form = document.forms[i]; 277 if(typeof form == 'object' && 'equations' in form) 278 { 279 for(var j in form.equations) 280 { 281 equation = form.equations[j]; 282 if(equation.equation.search(to_search) != -1) 283 {
284 EVALEQUATION(form, equation.result.replace(/_\d+$/, '')); 285 fields.push(equation.result); 286 } 287 } 288 } 289 } 290 return fields; 291 }; 292 293 $(document).on( 294 'found_variation', 295 function( evt, variation ) 296 { 297 if( ! $(evt.target).closest('form[name*="cp_calculatedfieldsf_pform_"]').length ) return; 298 woocommerce_cpcff_product_price = variation.display_price; 299 check_forms_and_evaluate_equations(/woocommerce_cpcff_product_price/).forEach( 300 ( f ) => { 301 fbuilderjQuery('#'+f).trigger('cff_wc_update'); 302 } 303 ); 304 } 305 ); 306 307} // End cff_woocommerce_integration 308 309fbuilderjQuery = (typeof fbuilderjQuery != 'undefined' ) ? fbuilderjQuery : jQuery; 310fbuilderjQuery(cff_woocommerce_integration); 311fbuilderjQuery(window).on('load',cff_woocommerce_integration); 312 313// Get Price with TAX 314 315 (function(){ 316 if(typeof fbuilderjQuery != 'undefined') 317 { 318 var $ = fbuilderjQuery, 319 prices = {}; 320 321 window['get_product_price_with_tax'] = window['GET_PRODUCT_PRICE_WITH_TAX'] = function( price, product_id, quantity, callback, formatted ) 322 { 323 324 product_id = product_id || 0; 325 quantity = Math.max( quantity || 0, 1 ); 326 327 if( ! product_id || ! price ) return price; 328 329 if( 330 product_id in prices && 331 quantity in prices[ product_id ] && 332 price in prices[ product_id ][ quantity ] 333 ) return prices[ product_id ][ quantity ][ price ]; // The product's price was read previously 334 335 336 var url = document.location.href.split('?')[0], 337 form = 'currentFormId' in $.fbuilder ? $('[id="'+$.fbuilder.currentFormId+'"]') : '', 338 field = 'currentEq' in $.fbuilder ? $.fbuilder.currentEq['result'] : '', 339 data = { 340 'cff_woocommerce_product_price_including_tax' : 1, 341 'product_id' : product_id, 342 'product_quantity' : quantity, 343 'product_price' : price, 344 '_cpcff_public_nonce' : form.length ? form.find( '[name="_cpcff_public_nonce"]' ).val() : '', 345 'form_id' : form.length ? form.find( '[name="cp_calculatedfieldsf_id"]' ).val() : 0, 346 'form_number' : form.length ? form.find( '[name="cp_calculatedfieldsf_pform_psequence"]' ).val() : 0 347 }; 348 349 if ( typeof formatted != 'undefined' && formatted ) data['formatted'] = 1; 350 351 $.ajax( 352 { 353 'url' : url, 354 'method' : 'POST', 355 'data' : data, 356 'dataType' : 'json', 357 'success' : (function(product_id, price, quantity, field){ 358 return function(data) 359 { 360 if(typeof data['error'] != 'undefined') 361 { 362 if(typeof console != 'undefined') console.log(data['error']); 363 } 364 else if( 'result' in data ) 365 { 366 if ( ! ( product_id in prices ) ) prices[ product_id ] = {}; 367 if ( ! ( quantity in prices[ product_id ] ) ) prices[ product_id ][ quantity ] = {}; 368 369 prices[product_id][quantity][price] = data['result']; 370 if ( typeof callback != 'undefined' ) { 371 callback( data['result'] ); 372 } else { 373 EVALEQUATION(field); 374 } 375 } 376 }; 377 })(product_id, price, quantity, field ) 378 } 379 ); 380 }; 381 } 382})();
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.