1(function ($) { 2 "use strict"; 3 4 function add_debug_message(product_id, debug) { 5 if(debug){ 6 if(debug.debug_display_type == 'log' || debug.debug_display_type == 'both'){ 7 console.log(product_id, debug); 8 } 9 10 if(debug.debug_display_type == 'screen' || debug.debug_display_type == 'both'){ 11 if($('#pi-edd-debug-msg-'+product_id).length > 0){ 12 $('#pi-edd-debug-msg-'+product_id).html(debug.debug_message); 13 }else{ 14 $('.pi-estimate-' + product_id).after('<div class="debug-info-container"><a class="debug-info-button" data-target="'+product_id+'" title="Click to view the information used to calculate the estimate date"></a><div class="pi-edd-debug-msg" id="pi-edd-debug-msg-'+product_id+'">'+debug.debug_message+'</div></div>'); 15 } 16 } 17 } 18 } 19 20 function debug_info_toggle() { 21 22 $(document).on('click', '.debug-info-button', function (e) { 23 e.preventDefault(); 24 var target = $(this).data('target'); 25 $('#pi-edd-debug-msg-' + target).toggle(); 26 } 27 ); 28 } 29 debug_info_toggle(); 30 31 function variable_product_estimate() { 32 this.reset_called_for_product = ''; 33 this.init = function () { 34 this.variation_change(); 35 this.variation_reset(); 36 /** woocommerce bundled product plugin */ 37 this.variation_change_woobundle(); 38 this.variation_reset_woobundle(); 39 /** end */ 40 this.quantity_change(); 41 this.customTrigger(); 42 } 43 44 this.get_quantity = function (product_id) { 45 if(pi_edd_data.consider_quantity_field != 1) return null; 46 47 var qty = 1; 48 if (jQuery('.pi-quantity-field-' + product_id).length > 0) { 49 qty = jQuery('.pi-quantity-field-' + product_id).val(); 50 } 51 return qty; 52 } 53 54 this.quantity_change = function () { 55 var parent = this; 56 if(pi_edd_data.consider_quantity_field == 1 && pi_edd_data.load_single_by_ajax){ 57 jQuery('.pi-quantity-field').change(function () { 58 var classes = Array.from(jQuery(this).prop('classList')); 59 var product_id = classes.find(element => element.includes('pi-quantity-field-')).split('-').pop(); 60 var variation_id = parseInt(jQuery('.variations_form[data-product_id="' + product_id + '"]').find('input[name="variation_id"]').val()); 61 var qty = jQuery(this).val(); 62 if(variation_id){ 63 parent.set_loading(product_id); 64 var qty = parent.get_quantity(product_id); 65 parent.get_estimate_msg_by_ajax(variation_id, qty).done(function (response) { 66 parent.add_estimate_msg(product_id, response.estimate_msg); 67 add_debug_message(product_id, response.debug); 68 jQuery(document).trigger('pi_edd_variation_estimate_loaded', [response, product_id, variation_id]); 69 }).always(function () { 70 parent.remove_loading(product_id); 71 }); 72 }else{ 73 parent.no_variation_selected(product_id); 74 } 75 }); 76 } 77 } 78 79 this.customTrigger = function () { 80 var parent = this; 81 jQuery(document).on('pi_edd_custom_get_estimate_trigger', function (e, product_id, variation_id) { 82 parent.set_loading(product_id); 83 var qty = parent.get_quantity(product_id); 84 parent.get_estimate_msg_by_ajax(variation_id, qty).done(function (response) { 85 parent.add_estimate_msg(product_id, response.estimate_msg); 86 add_debug_message(product_id, response.debug); 87 jQuery(document).trigger('pi_edd_variation_estimate_loaded', [response, product_id, variation_id]); 88 }).always(function () { 89 parent.remove_loading(product_id); 90 }); 91 92 }); 93 } 94 95 this.variation_change = function () { 96 var parent = this; 97 $(document).on('show_variation.pi_edd_variation_change', "form.variations_form", function (event, data) { 98 99 /** 100 * using this we can prevent the default action of the event 101 */ 102 var get_estimate_event = jQuery.Event('pi_edd_get_single_variation_product_estimate'); 103 104 $(document).trigger(get_estimate_event, {'element': this, 'data': data}); 105 106 if (get_estimate_event.isDefaultPrevented()) { 107 return; 108 } 109 110 var form = $(event.target).closest('form.variations_form'); 111 var product_id = form.data('product_id'); 112 if (data?.variation_id) { 113 var variation_id = data.variation_id; 114 if (pi_edd_data.load_single_by_ajax) { 115 parent.set_loading(product_id); 116 var qty = parent.get_quantity(product_id); 117 parent.get_estimate_msg_by_ajax(variation_id, qty).done(function (response) { 118 parent.add_estimate_msg(product_id, response.estimate_msg); 119 add_debug_message(product_id, response.debug); 120 jQuery(document).trigger('pi_edd_variation_estimate_loaded', [response, product_id, variation_id]); 121 }).always(function () { 122 parent.remove_loading(product_id); 123 }); 124 } else { 125 var estimate_msg = parent.get_estimate_msg_from_data(variation_id, data); 126 parent.add_estimate_msg(product_id, estimate_msg); 127 } 128 } 129 130 }); 131 132 } 133 134 /** 135 * only used for woocommerce bundle product plugin 136 */ 137 this.variation_change_woobundle = function () { 138 var parent = this; 139 $(document).on('show_variation.pi_edd_variation_change', ".bundled_item_cart_content.variations_form", function (event, data) { 140 141 /** 142 * using this we can prevent the default action of the event 143 */ 144 var get_estimate_event = jQuery.Event('pi_edd_get_single_variation_product_estimate'); 145 146 $(document).trigger(get_estimate_event, {'element': this, 'data': data}); 147 148 if (get_estimate_event.isDefaultPrevented()) { 149 return; 150 } 151 152 var product_id = $(this).data('product_id'); 153 console.log(product_id); 154 if (data?.variation_id) { 155 var variation_id = data.variation_id; 156 if (pi_edd_data.load_single_by_ajax) { 157 parent.set_loading(product_id); 158 var qty = parent.get_quantity(product_id); 159 parent.get_estimate_msg_by_ajax(variation_id, qty).done(function (response) { 160 parent.add_estimate_msg(product_id, response.estimate_msg); 161 add_debug_message(product_id, response.debug); 162 jQuery(document).trigger('pi_edd_variation_estimate_loaded', [response, product_id, variation_id]); 163 }).always(function () { 164 parent.remove_loading(product_id); 165 }); 166 } else { 167 var estimate_msg = parent.get_estimate_msg_from_data(variation_id, data); 168 parent.add_estimate_msg(product_id, estimate_msg); 169 } 170 } 171 172 }); 173 174 } 175 176 this.variation_reset = function () { 177 var parent = this; 178 $(document).on('reset_data.pi_edd_variation_reset', "form.variations_form", function (event, data) { 179 180 /** 181 * using this we can prevent the default action of the event 182 */ 183 var get_estimate_event = jQuery.Event('pi_edd_get_single_variation_product_estimate'); 184 185 $(document).trigger(get_estimate_event, {'element': this, 'data': data}); 186 187 if (get_estimate_event.isDefaultPrevented()) { 188 return; 189 } 190 191 var form = $(event.target).closest('form.variations_form'); 192 var product_id = form.data('product_id'); 193 parent.no_variation_selected(product_id); 194 }); 195 } 196 197 /** 198 * only used for woocommerce bundle product plugin 199 */
200 this.variation_reset_woobundle = function () { 201 var parent = this; 202 $(document).on('reset_data.pi_edd_variation_reset', ".bundled_item_cart_content.variations_form", function (event, data) { 203 var product_id = $(this).data('product_id'); 204 parent.no_variation_selected(product_id); 205 }); 206 } 207 208 this.get_estimate_msg_from_data = function (product_id, data) { 209 return data.estimate_msg; 210 } 211 212 this.get_estimate_msg_by_ajax = function (product_id, qty = null) { 213 var action = 'pi-get-single-product-estimate'; 214 var data = { 215 product_id: product_id 216 }; 217 218 if (qty != null) { 219 data['qty'] = qty; 220 } 221 222 return $.ajax({ 223 url: pi_edd_data.wc_ajax_url.toString().replace('%%endpoint%%', action), 224 method: 'POST', 225 dataType: 'json', 226 data: data 227 }); 228 } 229 230 this.set_loading = function (product_id) { 231 $('.pi-estimate-' + product_id).addClass('pi-loading'); 232 } 233 234 this.remove_loading = function (product_id) { 235 $('.pi-estimate-' + product_id).removeClass('pi-loading'); 236 } 237 238 this.add_estimate_msg = function (product_id, msg) { 239 $('.pi-estimate-' + product_id).html(msg); 240 jQuery(document).trigger('pi_edd_update_counter'); 241 } 242 243 this.no_variation_selected = function (product_id) { 244 var parent = this; 245 246 if ('select-variation-msg' != pi_edd_data.show_first_variation_estimate) { 247 /** 248 * reset_data event is fired 3 times on every reset so to avoid making multiple request we have added this check so that it only make one request 249 */ 250 if (parent.reset_called_for_product != product_id) { 251 this.set_loading(product_id); 252 var qty = this.get_quantity(product_id); 253 this.get_estimate_msg_by_ajax(product_id, qty).done(function (response) { 254 parent.add_estimate_msg(product_id, response.estimate_msg); 255 add_debug_message(product_id, response.debug); 256 }).always(function () { 257 parent.reset_called_for_product = ''; 258 parent.remove_loading(product_id); 259 }); 260 parent.reset_called_for_product = product_id; 261 } 262 } else { 263 this.add_estimate_msg(product_id, pi_edd_data.no_variation_selected_msg); 264 } 265 } 266 267 } 268 269 function simple_product_load_by_ajax() { 270 this.products = []; 271 this.init = function () { 272 this.get_estimates(); 273 this.custom_trigger(); 274 this.quantity_change(); 275 } 276 277 this.custom_trigger = function () { 278 var parent = this; 279 jQuery(document).on('pi_edd_load_loop_ajax pisol_shipping_address_updated pisol_load_single_product_estimate', function () { 280 parent.get_estimates(); 281 }); 282 } 283 284 this.get_products = function (product_id = null) { 285 var parent = this; 286 this.products = []; 287 jQuery(".pi-edd-ajax-simple").each(function () { 288 289 if(product_id != null && product_id != $(this).data('product')) return; 290 291 var id = $(this).data('product'); 292 var type = $(this).data('type'); 293 var message = $(this).data('message'); 294 var data = { 295 'product_id': id, 296 'type': type, 297 'message': message 298 } 299 300 if(type == 'single' && pi_edd_data.consider_quantity_field == 1){ 301 var qty = 1; 302 if(jQuery('.pi-quantity-field-'+id).length > 0){ 303 qty = jQuery('.pi-quantity-field-'+id).val(); 304 } 305 data['qty'] = qty; 306 } 307 308 parent.products.push(data); 309 }); 310 } 311 312 this.quantity_change = function () { 313 var parent = this; 314 if(pi_edd_data.consider_quantity_field == 1 && pi_edd_data.load_single_by_ajax){ 315 jQuery('.pi-quantity-field').change(function () { 316 var classes = Array.from(jQuery(this).prop('classList')); 317 var product_id = classes.find(element => element.includes('pi-quantity-field-')).split('-').pop(); 318 parent.get_estimates(product_id); 319 }); 320 } 321 } 322 323 this.get_estimates = function (product_id = null) { 324 this.get_products(product_id); 325 var parent = this; 326 if (this.products.length > 0) { 327 var action = 'pi-get-bulk-product-estimate'; 328 329 jQuery.each(parent.products, function (index, product) { 330 parent.set_loading(product.product_id); 331 }); 332 333 $.ajax({
334 url: pi_edd_data.wc_ajax_url.toString().replace('%%endpoint%%', action), 335 method: 'POST', 336 dataType: 'json', 337 data: { 338 products: parent.products, 339 } 340 }).done(function (response) { 341 parent.set_estimate_msgs(response.estimates); 342 parent.set_debug_msgs(response.debug); 343 }); 344 } 345 } 346 347 this.set_debug_msgs = function (debug) { 348 if(debug){ 349 jQuery.each(debug, function (product_id, data) { 350 add_debug_message(product_id, data); 351 }); 352 } 353 } 354 355 this.set_estimate_msgs = function (estimates) { 356 var parent = this; 357 $.each(estimates, function (product_id, msg) { 358 parent.set_estimate_msg(product_id, msg) 359 }); 360 } 361 362 this.set_estimate_msg = function (product_id, msg) { 363 $('.pi-estimate-' + product_id).html(msg); 364 jQuery(document).trigger('pi_edd_update_counter',{'product_id': product_id, 'msg': msg}); 365 this.remove_loading(product_id); 366 } 367 368 this.set_loading = function (product_id) { 369 $('.pi-estimate-' + product_id).addClass('pi-loading'); 370 } 371 372 this.remove_loading = function (product_id) { 373 $('.pi-estimate-' + product_id).removeClass('pi-loading'); 374 } 375 } 376 377 function frontEndVariables() { 378 this.init = function () { 379 this.detect(); 380 } 381 382 this.detect = function () { 383 var ids = []; 384 jQuery('.pi-min-date').each(function () { 385 var element_id = jQuery(this).data('id'); 386 if (element_id && !isNaN(element_id)) { 387 ids.push(element_id); 388 } 389 }); 390 391 jQuery('.pi-max-date').each(function () { 392 var element_id = jQuery(this).data('id'); 393 if (element_id && !isNaN(element_id)) { 394 ids.push(element_id); 395 } 396 }); 397 398 jQuery('.pi-min-days').each(function () { 399 var element_id = jQuery(this).data('id'); 400 if (element_id && !isNaN(element_id)) { 401 ids.push(element_id); 402 } 403 }); 404 405 jQuery('.pi-max-days').each(function () { 406 var element_id = jQuery(this).data('id'); 407 if (element_id && !isNaN(element_id)) { 408 ids.push(element_id); 409 } 410 }); 411 412 jQuery('.pi-date').each(function () { 413 var element_id = jQuery(this).data('id'); 414 if (element_id && !isNaN(element_id)) { 415 ids.push(element_id); 416 } 417 }); 418 419 jQuery('.pi-days').each(function () { 420 var element_id = jQuery(this).data('id'); 421 if (element_id && !isNaN(element_id)) { 422 ids.push(element_id); 423 } 424 }); 425 426 jQuery('.pi-min-preparation-days').each(function () { 427 var element_id = jQuery(this).data('id'); 428 if (element_id && !isNaN(element_id)) { 429 ids.push(element_id); 430 } 431 }); 432 433 jQuery('.pi-max-preparation-days').each(function () { 434 var element_id = jQuery(this).data('id'); 435 if (element_id && !isNaN(element_id)) { 436 ids.push(element_id); 437 } 438 }); 439 440 jQuery('.pi-preparation-days').each(function () { 441 var element_id = jQuery(this).data('id'); 442 if (element_id && !isNaN(element_id)) { 443 ids.push(element_id); 444 } 445 }); 446 447 448 if (ids.length > 0) { 449 this.ajaxCall(ids); 450 } 451 } 452 453 this.ajaxCall = function (ids) { 454 var parent = this; 455 var action = 'get_estimate_dates'; 456 jQuery.ajax({ 457 url: pi_edd_data.wc_ajax_url.toString().replace('%%endpoint%%', action), 458 method: 'post', 459 data: { 460 ids: ids, 461 }, 462 success: function (response) { 463 if (response?.product_estimates) { 464 parent.replaceElements(response.product_estimates) 465 } 466 } 467 }); 468 } 469 470 this.replaceElements = function (estimates) { 471 var parent = this; 472 jQuery.each(estimates, function (id, estimate) { 473 parent.minDate(id, estimate.min_date); 474 parent.minDays(id, estimate.min_days); 475 parent.maxDate(id, estimate.max_date); 476 parent.maxDays(id, estimate.max_days); 477 parent.date(id, estimate.date); 478 parent.days(id, estimate.days); 479 480 parent.minPreparationDays(id, estimate.min_preparation_days); 481 parent.maxPreparationDays(id, estimate.max_preparation_days); 482 parent.preparationDays(id, estimate.preparation_days); 483 }) 484 } 485 486 this.minDate = function (id, min_date) { 487 if (jQuery('.pi-min-date-' + id).length > 0) { 488 jQuery('.pi-min-date-' + id).html(min_date); 489 } 490 } 491 492 this.minDays = function (id, min_days) { 493 if (jQuery('.pi-min-days-' + id).length > 0) { 494 jQuery('.pi-min-days-' + id).html(min_days); 495 } 496 } 497 498 this.maxDate = function (id, max_date) { 499 if (jQuery('.pi-max-date-' + id).length > 0) { 500 jQuery('.pi-max-date-' + id).html(max_date); 501 } 502 } 503 504 this.maxDays = function (id, max_days) { 505 if (jQuery('.pi-max-days-' + id).length > 0) { 506 jQuery('.pi-max-days-' + id).html(max_days); 507 } 508 } 509 510 this.date = function (id, date) { 511 if (jQuery('.pi-date-' + id).length > 0) { 512 jQuery('.pi-date-' + id).html(date); 513 } 514 } 515 516 this.days = function (id, days) { 517 if (jQuery('.pi-days-' + id).length > 0) { 518 jQuery('.pi-days-' + id).html(days);
519 } 520 } 521 522 this.minPreparationDays = function (id, min_days) { 523 if (jQuery('.pi-min-preparation-days-' + id).length > 0) { 524 jQuery('.pi-min-preparation-days-' + id).html(min_days); 525 } 526 } 527 528 this.maxPreparationDays = function (id, max_days) { 529 if (jQuery('.pi-max-preparation-days-' + id).length > 0) { 530 jQuery('.pi-max-preparation-days-' + id).html(max_days); 531 } 532 } 533 534 this.preparationDays = function (id, days) { 535 if (jQuery('.pi-preparation-days-' + id).length > 0) { 536 jQuery('.pi-preparation-days-' + id).html(days); 537 } 538 } 539 } 540 541 function updateCountdown() { 542 jQuery(".pi-edd-counter").each(function () {//23 56 543 544 try { 545 // Get the countdown details from the data attribute 546 let countdownElement = $(this); 547 let remainingTotalMinutes = parseInt(countdownElement.data('min'), 10); 548 549 // Calculate the remaining time in minutes 550 551 // If the remaining time has reached zero or negative, reload the page 552 if (remainingTotalMinutes <= 0) { 553 location.reload(); 554 return; // Stop the countdown 555 } 556 557 // Calculate hours and minutes from remaining total minutes 558 let remainingHoursToShow = Math.floor(remainingTotalMinutes / 60); 559 let remainingMinutesToShow = remainingTotalMinutes % 60; 560 561 // Display the countdown 562 let countdownElementText = ''; 563 564 let message_template = countdownElement.data('message') ?? '[hr] hours [min] minutes'; 565 566 567 countdownElementText = message_template.replace('[hr]', remainingHoursToShow).replace('[min]', remainingMinutesToShow); 568 569 countdownElement.text(countdownElementText); 570 571 remainingTotalMinutes--; 572 573 countdownElement.data('min', remainingTotalMinutes); 574 575 } catch (error) { 576 console.error('Error updating countdown:', error); 577 } 578 579 }); 580 } 581 582 583 584 jQuery(function ($) { 585 var variable_product_estimate_obj = new variable_product_estimate(); 586 variable_product_estimate_obj.init(); 587 588 var simple_product_load_by_ajax_obj = new simple_product_load_by_ajax(); 589 simple_product_load_by_ajax_obj.init(); 590 591 var frontEndVariablesObj = new frontEndVariables(); 592 frontEndVariablesObj.init(); 593 594 // Update the countdown every second 595 setInterval(function(){ 596 jQuery(document).trigger('pi_edd_update_counter'); 597 }, 60000); 598 599 // Initial update 600 601 jQuery(document).on('pi_edd_update_counter', function () { 602 updateCountdown(); 603 }); 604 605 updateCountdown(); 606 607 }); 608 609})(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.