1"use strict"; 2var woocs_loading_first_time = true;//simply flag var 3var woocs_sumbit_currency_changing = true;//just a flag variable for drop-down redraws when prices redraws by AJAX 4 5 6// Unique per-browser storage key. Generated once and kept in localStorage forever. 7// Used ONLY in browser key mode as the storage key instead of the visitor IP. 8var woocs_sk = ''; 9if (typeof woocs_browser_key_mode !== 'undefined' && woocs_browser_key_mode) { 10 try { 11 woocs_sk = localStorage.getItem('woocs_sk') || ''; 12 if (!woocs_sk) { 13 woocs_sk = (window.crypto && crypto.randomUUID) 14 ? crypto.randomUUID().replace(/-/g, '') 15 : String(Date.now()) + Math.random().toString(36).slice(2, 12); 16 localStorage.setItem('woocs_sk', woocs_sk); 17 } 18 } catch (e) { 19 woocs_sk = ''; // private mode / storage disabled: silently fall back to the IP based key 20 } 21} 22 23jQuery(function ($) { 24 25 if (typeof woocs_array_of_get === 'undefined') { 26 return;//to avoid notices and errors 27 } 28 29 woocs_array_of_get = JSON.parse(woocs_array_of_get); 30 31 // Attach the browser key to every AJAX request (admin-ajax and wc-ajax), 32 // so the cart and the checkout resolve the same currency as the catalog pages. 33 if (woocs_sk) { 34 $(document).ajaxSend(function (e, xhr, settings) { 35 if (typeof settings.data === 'string' && settings.data.indexOf('woocs_sk=') === -1) { 36 settings.data += (settings.data ? '&' : '') + 'woocs_sk=' + encodeURIComponent(woocs_sk); 37 } 38 }); 39 } 40 41 //wp-content\plugins\woocommerce\assets\js\frontend\cart.js 42 if (Object.keys(woocs_array_of_get).length !== 0) { 43 if ('currency' in woocs_array_of_get) { 44 //this code nessesary for correct redrawing of the shipping methods while currency changes on the cart page 45 $('body.woocommerce-cart .shop_table.cart').closest('form').find('input[name="update_cart"]').prop('disabled', false); 46 $('body.woocommerce-cart .shop_table.cart').closest('form').find('input[name="update_cart"]').trigger('click'); 47 } 48 } 49 50 //keeps data of $_GET array 51 52 if (Object.keys(woocs_array_of_get).length == 0) { 53 woocs_array_of_get = {}; 54 } 55 56 //*** 57 woocs_array_no_cents = JSON.parse(woocs_array_no_cents); 58 59 //*** 60 61 //emptying cart widget after checkout 62 if (!parseInt(woocs_get_cookie('woocommerce_items_in_cart'), 10)) { 63 $('.widget_shopping_cart_content').empty(); 64 $(document.body).trigger('wc_fragment_refresh'); 65 } 66 67 if (woocs_array_of_get.currency != undefined || woocs_array_of_get.removed_item != undefined || woocs_array_of_get.key != undefined) 68 { 69 woocs_refresh_mini_cart(555); 70 } 71 if (woocs_redraw_cart) { 72 //intercept adding to cart event to redraw mini-cart widget 73 jQuery(document).on("adding_to_cart", function () { 74 woocs_refresh_mini_cart(999); 75 }); 76 } 77 78 //to make price popup mobile friendly 79 jQuery('body').on('click', '.woocs_price_info', function () { 80 return false; 81 }); 82 83 //+++++++++++++++++++++++++++++++++++++++++++++++ 84 85 if (woocs_drop_down_view == 'chosen' || woocs_drop_down_view == 'chosen_dark') { 86 try { 87 if (jQuery("select.woocommerce-currency-switcher").not('.woocs_clean_select').length) { 88 jQuery("select.woocommerce-currency-switcher").not('.woocs_clean_select').chosen({ 89 disable_search_threshold: 10 90 }); 91 92 jQuery.each(jQuery('.woocommerce-currency-switcher-form .chosen-container'), function (index, obj) { 93 jQuery(obj).css({'width': jQuery(this).prev('select').data('width')}); 94 }); 95 } 96 } catch (e) { 97 console.log(e); 98 } 99 } 100 101 102 103 if (woocs_drop_down_view == 'ddslick') { 104 try { 105 woocs_init_ddslick_select(); 106 107 } catch (e) { 108 console.log(e); 109 } 110 } 111 112 woocs_loading_first_time = false; 113 114 115 if (woocs_drop_down_view == 'wselect' && woocs_is_mobile != 1) { 116 try { 117 //https://github.com/websanova/wSelect#wselectjs 118 jQuery('select.woocommerce-currency-switcher').not('.woocs_clean_select').wSelect({ 119 size: 7 120 }); 121 } catch (e) { 122 console.log(e); 123 } 124 } 125 126 //for flags view instead of drop-down 127 jQuery('.woocs_flag_view_item').on("click", function () { 128 if (woocs_sumbit_currency_changing) { 129 if (jQuery(this).hasClass('woocs_flag_view_item_current')) { 130 return false; 131 } 132 //*** 133 134 if (Object.keys(woocs_array_of_get).length == 0) { 135 window.location = window.location.href + '?currency=' + jQuery(this).data('currency'); 136 } else { 137 138 woocs_redirect(jQuery(this).data('currency')); 139 140 } 141 } 142 143 return false; 144 });
145 146 //for converter 147 if (jQuery('.woocs_converter_shortcode').length) { 148 jQuery('.woocs_converter_shortcode_button').on("click", function () { 149 var amount = jQuery(this).parent('.woocs_converter_shortcode').find('.woocs_converter_shortcode_amount').eq(0).val(); 150 var from = jQuery(this).parent('.woocs_converter_shortcode').find('.woocs_converter_shortcode_from').eq(0).val(); 151 var to = jQuery(this).parent('.woocs_converter_shortcode').find('.woocs_converter_shortcode_to').eq(0).val(); 152 var precision = jQuery(this).parent('.woocs_converter_shortcode').find('.woocs_converter_shortcode_precision').eq(0).val(); 153 var results_obj = jQuery(this).parent('.woocs_converter_shortcode').find('.woocs_converter_shortcode_results').eq(0); 154 jQuery(results_obj).val(woocs_lang_loading + ' ...'); 155 var data = { 156 action: "woocs_convert_currency", 157 amount: amount, 158 from: from, 159 to: to, 160 precision: precision 161 }; 162 163 jQuery.post(woocs_ajaxurl, data, function (value) { 164 jQuery(results_obj).val(value); 165 }); 166 167 return false; 168 169 }); 170 } 171 172 //for rates 173 if (jQuery('.woocs_rates_shortcode').length) { 174 jQuery('body').on('change', '.woocs_rates_current_currency', function () { 175 var _this = this; 176 var data = { 177 action: "woocs_rates_current_currency", 178 current_currency: jQuery(this).val(), 179 precision: jQuery(this).data('precision'), 180 exclude: jQuery(this).data('exclude') 181 }; 182 183 jQuery.post(woocs_ajaxurl, data, function (html) { 184 jQuery(_this).parent('.woocs_rates_shortcode').html(html); 185 }); 186 187 return false; 188 189 }); 190 } 191 192 //if we using js price update while the site is cached 193 if (typeof woocs_shop_is_cached !== 'undefined') { 194 if (woocs_shop_is_cached) { 195 196 setTimeout(function () { 197 198 woocs_sumbit_currency_changing = false; 199 if (typeof woocs_array_of_get.currency === 'undefined') { 200 201 if (jQuery('body').hasClass('single')) { 202 // jQuery('.woocs_price_info').remove(); 203 } 204 205 /****/ 206 var custom_prices = []; 207 jQuery.each(jQuery('.woocs_amount_custom_price'), function (index, item) { 208 let decimals = jQuery(item).data('decimals'); 209 let value = jQuery(item).data('value'); 210 let currency = jQuery(item).data('currency'); 211 custom_prices.push({ 212 decimals: decimals, 213 value: value, 214 currency: currency 215 }); 216 }); 217 if (custom_prices.length != 0) { 218 219 var data = { 220 action: "woocs_get_custom_price_html", 221 custom_prices: custom_prices, 222 current_currency: woocs_current_currency['name'] 223 }; 224 jQuery.post(woocs_ajaxurl, data, function (data) { 225 // The server answers with wp_send_json (already parsed by jQuery) 226 // in one branch and with wp_die(json_encode()) (plain string) in another. 227 if (typeof data === 'string') { 228 data = JSON.parse(data); 229 } 230 if (!jQuery.isEmptyObject(data)) { 231 jQuery.each(data, function (val, price) { 232 jQuery(".woocs_amount_custom_price[data-value='" + val + "']").replaceWith(price); 233 }); 234 235 } 236 }); 237 } 238 239 240 /****/ 241 242 var variation_ids = []; 243 var var_data = jQuery("form.variations_form").data("product_variations"); 244 if (typeof var_data != "undefined") { 245 jQuery.each(var_data, function (indx, attr) { 246 variation_ids.push(attr['variation_id']); 247 }); 248 if (variation_ids.length != 0) { 249 var data_var = { 250 action: "woocs_get_variation_products_price_html", 251 var_products_ids: variation_ids, 252 current_currency: woocs_current_currency['name'] 253 }; 254 255 jQuery.post(woocs_ajaxurl, data_var, function (data) { 256 // The server answers with wp_send_json (already parsed by jQuery) 257 // in one branch and with wp_die(json_encode()) (plain string) in another. 258 if (typeof data === 'string') { 259 data = JSON.parse(data); 260 } 261 262 if (!jQuery.isEmptyObject(data)) { 263 jQuery.each(var_data, function (indx, attr) { 264 if (typeof data[attr['variation_id']] != "undefined") { 265 var_data[indx]['price_html'] = data[attr['variation_id']]; 266 } 267 }); 268 jQuery("form.variations_form").data("product_variations", var_data); 269 } 270 }); 271 } 272 } 273 274 //*** 275 var products_ids = {}; 276 var products_currency = {}; 277 jQuery.each(jQuery('.woocs_price_code'), function (index, item) { 278 products_ids[jQuery(item).data('redraw-id')] = jQuery(item).data('product-id'); 279 if (jQuery(item).data('currency')) { 280 products_currency[jQuery(item).data('redraw-id')] = jQuery(item).data('currency'); 281 } 282 283 }); 284 285 //if no prices on the page - do nothing 286 if (Object.keys(products_ids).length === 0) { 287 woocs_sumbit_currency_changing = true; 288 return; 289 } 290 291 var data = { 292 action: "woocs_get_products_price_html", 293 products_ids: products_ids, 294 products_currency: products_currency, 295 current_currency: woocs_current_currency['name'] 296 }; 297 298 jQuery.post(woocs_ajaxurl, data, function (data) { 299 300 // The server answers with wp_send_json (already parsed by jQuery) 301 // in one branch and with wp_die(json_encode()) (plain string) in another. 302 if (typeof data === 'string') { 303 data = JSON.parse(data); 304 } 305 306 if (jQuery.isEmptyObject(data)) { 307 woocs_sumbit_currency_changing = true; 308 } 309 if (!jQuery.isEmptyObject(data)) { 310 jQuery('.woocs_price_info').remove(); 311 jQuery('.woocs_price_approx.woocs_cart_item_price').remove(); 312 jQuery.each(jQuery('.woocs_price_code'), function (index, item) { 313 if (data.ids[jQuery(item).data('redraw-id')] != undefined) { 314 jQuery(item).replaceWith(data.ids[jQuery(item).data('redraw-id')]); 315 } 316 317 318 }); 319 jQuery('.woocs_price_code').removeClass('woocs_preloader_ajax'); 320 //*** 321 jQuery('.woocommerce-currency-switcher').val(data.current_currency); 322 //*** 323 if (woocs_drop_down_view == 'chosen' || woocs_drop_down_view == 'chosen_dark') { 324 try { 325 if (jQuery("select.woocommerce-currency-switcher").not('.woocs_clean_select').length) { 326 jQuery("select.woocommerce-currency-switcher").not('.woocs_clean_select').chosen({ 327 disable_search_threshold: 10 328 }); 329 jQuery('select.woocommerce-currency-switcher').trigger("chosen:updated"); 330 } 331 } catch (e) { 332 console.log(e); 333 } 334 } 335 if (typeof data.currency_data != "undefined") { 336 woocs_current_currency = data.currency_data; 337 /* Price slider */ 338 var min = jQuery('.price_slider_amount #min_price').val(); 339 var max = jQuery('.price_slider_amount #max_price').val(); 340 if (typeof max != 'undefined' && typeof min != 'undefined') { 341 max = woocs_convert_price_slider(max); 342 min = woocs_convert_price_slider(min); 343 jQuery(document.body).trigger('price_slider_create', [min, max]); 344 } 345 } 346 //*** 347 if (woocs_drop_down_view == 'ddslick') { 348 try { 349 jQuery('div.dd-container').ddslick('destroy'); 350 jQuery('select.woocommerce-currency-switcher').not('.woocs_clean_select').val(data.current_currency); 351 woocs_init_ddslick_select(); 352 } catch (e) { 353 console.log(e); 354 } 355 } 356 //*** 357 if (woocs_drop_down_view == 'wselect' && woocs_is_mobile != 1) { 358 //https://github.com/websanova/wSelect 359 try { 360 jQuery('select.woocommerce-currency-switcher').not('.woocs_clean_select').val(data.current_currency).trigger("change"); 361 } catch (e) { 362 console.log(e); 363 } 364 } 365 //*** 366 /* auto switcher*/ 367 368 var auto_switcher = jQuery('.woocs_auto_switcher'); 369 if (auto_switcher.length > 0) { 370 woocs_auto_switcher_redraw(data.current_currency, auto_switcher); 371 } 372 woocs_sumbit_currency_changing = true; 373 374 var shortcode_currency = jQuery('strong.woocs_current_currency_code'); 375 if (shortcode_currency.length) { 376 shortcode_currency.text(data.current_currency); 377 } 378 379 380 //*** 381 //for another woocs switchers styles 382 document.dispatchEvent(new CustomEvent('after_woocs_get_products_price_html', {detail: { 383 current_currency: data.current_currency 384 }})); 385 } 386 387 }); 388 389 } else { 390 woocs_sumbit_currency_changing = true; 391 392 } 393 jQuery(".single_variation_wrap").on("show_variation", function (event, variation) { 394 jQuery('.woocs_price_code').removeClass('woocs_preloader_ajax'); 395 }); 396 jQuery('.woocs_price_code').removeClass('woocs_preloader_ajax'); 397 }, 300); 398 399 } 400 } 401 402 //*** 403 //removing price info on single page near variation prices 404 setTimeout(function () {
405 //jQuery('body.single-product .woocommerce-variation-price').find('.woocs_price_info').remove(); 406 }, 300); 407 //*** 408 409 //fix: https://pluginus.net/support/topic/wrong-currency-displayed/#postid-100678 410 //for shortcode [woocs_show_custom_price value="100"] when sites has cache enabled 411 setTimeout(function () { 412 // Check if cache mode is enabled 413 if (typeof woocs_shop_is_cached !== 'undefined' && woocs_shop_is_cached) { 414 415 // Recalculate custom prices function 416 function woocs_recalculate_custom_prices() { 417 jQuery('.woocs_amount_custom_price').each(function () { 418 var $item = jQuery(this); 419 var base_value = parseFloat($item.data('value')); 420 var decimals = parseInt($item.data('decimals')); 421 422 if (isNaN(base_value)) { 423 return; 424 } 425 426 // Convert to current currency 427 var converted_value = base_value * woocs_current_currency.rate; 428 429 // Determine decimals 430 if (decimals === -1 || isNaN(decimals)) { 431 decimals = parseInt(woocs_current_currency.decimals); 432 } 433 434 // Apply hide_cents setting 435 if (woocs_current_currency.hide_cents == 1) { 436 decimals = 0; 437 } 438 439 // Format number 440 var price_formatted = converted_value.toFixed(decimals); 441 442 // Apply separators 443 if (woocs_current_currency.separators === "1") { 444 // European format: 1.234,56 445 price_formatted = price_formatted.replace('.', ','); 446 var parts = price_formatted.split(','); 447 parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, '.'); 448 price_formatted = parts.join(','); 449 } else { 450 // American format: 1,234.56 451 var parts = price_formatted.split('.'); 452 parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ','); 453 price_formatted = parts.join('.'); 454 } 455 456 // Build HTML with currency symbol 457 var symbol = woocs_current_currency.symbol; 458 var position = woocs_current_currency.position; 459 var final_html = ''; 460 461 switch (position) { 462 case 'left': 463 final_html = symbol + price_formatted; 464 break; 465 case 'left_space': 466 final_html = symbol + ' ' + price_formatted; 467 break; 468 case 'right': 469 final_html = price_formatted + symbol; 470 break; 471 case 'right_space': 472 final_html = price_formatted + ' ' + symbol; 473 break; 474 default: 475 final_html = symbol + price_formatted; 476 } 477 478 // Update inner span with class woocs_amount 479 $item.find('.woocs_amount').html(final_html); 480 }); 481 482 console.log('WOOCS custom prices recalculated'); 483 } 484 485 // Run on page load 486 woocs_recalculate_custom_prices(); 487 488 // Run on currency change 489 jQuery(document).on('woocs_currencies_changed', function () { 490 setTimeout(woocs_recalculate_custom_prices, 100); 491 }); 492 } 493 }, 500); 494}); 495 496 497function woocs_redirect(currency) { 498 if (!woocs_sumbit_currency_changing) { 499 return; 500 } 501 502 //*** 503 var l = window.location.href; 504 // l = l.replace('#', ''); 505 var l_tmp = l.split('#'); 506 l = l_tmp[0]; 507 var id_key = ""; 508 if (l_tmp.length > 1) { 509 id_key = "#" + l_tmp[1] 510 } 511 //for #id navigation l = l.replace(/(#.+$)/gi, ''); 512 513 l = l.split('?'); 514 l = l[0];
515 var string_of_get = '?'; 516 woocs_array_of_get.currency = currency; 517 518 /* 519 l = l.replace(/(\?currency=[a-zA-Z]+)/g, '?'); 520 l = l.replace(/(¤cy=[a-zA-Z]+)/g, ''); 521 */ 522 523 if (woocs_special_ajax_mode || woocs_sk) { 524 string_of_get = ""; 525 526 var data = { 527 action: "woocs_set_currency_ajax", 528 currency: currency 529 }; 530 531 jQuery.post(woocs_ajaxurl, data, function (value) { 532 location.reload(); 533 }); 534 535 } else { 536 if (Object.keys(woocs_array_of_get).length > 0) { 537 let get_values = []; 538 jQuery.each(woocs_array_of_get, function (index, value) { 539 get_values.push(index + "=" + value); 540 }); 541 string_of_get += get_values.join("&"); 542 } 543 window.location = l + string_of_get + id_key; 544 } 545} 546 547function woocs_refresh_mini_cart(delay) { 548 /** Cart Handling */ 549 setTimeout(function () { 550 try { 551 552 //for refreshing mini cart 553 $fragment_refresh = { 554 url: wc_cart_fragments_params.ajax_url, 555 type: 'POST', 556 data: {action: 'woocommerce_get_refreshed_fragments', woocs_woocommerce_before_mini_cart: 'mini_cart_refreshing'}, 557 success: function (data) { 558 if (data && data.fragments) { 559 560 jQuery.each(data.fragments, function (key, value) { 561 jQuery(key).replaceWith(value); 562 }); 563 564 try { 565 if ($supports_html5_storage) { 566 sessionStorage.setItem(wc_cart_fragments_params.fragment_name, JSON.stringify(data.fragments)); 567 sessionStorage.setItem('wc_cart_hash', data.cart_hash); 568 } 569 } catch (e) { 570 571 } 572 573 jQuery('body').trigger('wc_fragments_refreshed'); 574 } 575 } 576 }; 577 578 jQuery.ajax($fragment_refresh); 579 580 581 /* Cart hiding */ 582 try { 583 if (woocs_get_cookie('woocommerce_items_in_cart') > 0) 584 { 585 jQuery('.hide_cart_widget_if_empty').closest('.widget_shopping_cart').show(); 586 } else { 587 jQuery('.hide_cart_widget_if_empty').closest('.widget_shopping_cart').hide(); 588 } 589 } catch (e) { 590 //*** 591 } 592 593 594 jQuery('body').on('adding_to_cart', function () { 595 jQuery('.hide_cart_widget_if_empty').closest('.widget_shopping_cart').show(); 596 }); 597 598 } catch (e) { 599 //*** 600 } 601 602 }, delay); 603 604} 605 606function woocs_get_cookie(name) { 607 var matches = document.cookie.match(new RegExp( 608 "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)" 609 )); 610 return matches ? decodeURIComponent(matches[1]) : undefined; 611} 612 613/*auto switcher*/ 614 615jQuery(function () { 616 jQuery('.woocs_auto_switcher_link').on('click', function () { 617 woocs_redirect(jQuery(this).data('currency')); 618 return false; 619 }); 620 621 jQuery('.woocs_auto_switcher li').on('click', function (e) { 622 woocs_redirect(jQuery(this).find('a.woocs_auto_switcher_link').data('currency')); 623 return false; 624 }); 625}); 626 627function woocs_auto_switcher_redraw(curr_curr, switcher) { 628 var view = switcher.data('view'); 629 switch (view) { 630 case 'classic_blocks': 631 switcher.find('a').removeClass('woocs_curr_curr'); 632 switcher.find('a[data-currency="' + curr_curr + '"]').addClass('woocs_curr_curr'); 633 break; 634 case 'roll_blocks': 635 switcher.find('a').removeClass('woocs_curr_curr'); 636 switcher.find('li').removeClass('woocs_auto_bg_woocs_curr_curr'); 637 var current_link = switcher.find('a[data-currency="' + curr_curr + '"]'); 638 current_link.addClass('woocs_curr_curr'); 639 current_link.parents('li').addClass('woocs_auto_bg_woocs_curr_curr'); 640 break; 641 case 'round_select': 642 switcher.find('a').removeClass('woocs_curr_curr'); 643 var current_link = switcher.find('a[data-currency="' + curr_curr + '"]'); 644 current_link.addClass('woocs_curr_curr'); 645 jQuery('.woocs_current_text').html(current_link.find('.woocs_base_text').html()); 646 break; 647 default: 648 break; 649 } 650 651} 652 653function woocs_remove_link_param(key, sourceURL) { 654 var rtn = sourceURL.split("?")[0], 655 param, 656 params_arr = [], 657 queryString = (sourceURL.indexOf("?") !== -1) ? sourceURL.split("?")[1] : ""; 658 if (queryString !== "") { 659 params_arr = queryString.split("&"); 660 for (var i = params_arr.length - 1; i >= 0; i -= 1) { 661 param = params_arr[i].split("=")[0]; 662 if (param === key) { 663 params_arr.splice(i, 1); 664 } 665 } 666 rtn = rtn + "?" + params_arr.join("&"); 667 } 668 return rtn; 669} 670 671function woocs_init_ddslick_select() { 672 jQuery.each(jQuery('select.woocommerce-currency-switcher').not('.woocs_clean_select'), function (index, obj) { 673 var width = jQuery(obj).data('width'); 674 var flag_position = jQuery(obj).data('flag-position'); 675 jQuery(obj).ddslick({ 676 //data: ddData, 677 width: width, 678 imagePosition: flag_position, 679 selectText: "Select currency", 680 //background:'#ff0000', 681 onSelected: function (data) { 682 if (!woocs_loading_first_time) 683 { 684 var form = jQuery(data.selectedItem).closest('form.woocommerce-currency-switcher-form'); 685 jQuery(form).find('input[name="woocommerce-currency-switcher"]').eq(0).val(data.selectedData.value); 686 687 if (Object.keys(woocs_array_of_get).length == 0) { 688 //jQuery(form).submit(); 689 woocs_redirect(data.selectedData.value); 690 } else { 691 woocs_redirect(data.selectedData.value); 692 } 693 } 694 695 } 696 }); 697 });
698} 699
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.