1// ON READY 2jQuery(document).on('ready', function () { 3 update_not_converted_prices(); 4}); 5 6// ON LOAD 7jQuery(window).on('load', function () { 8 update_not_converted_prices(); 9}); 10 11// AJAX COMPLETE 12jQuery(document).on( "ajaxComplete", function(event, request, settings) { 13 update_not_converted_prices(); 14}); 15 16 17jQuery(document).on('click', '.currency-buttons .button, .currency-buttons .button-new', set_multi_currency_cookie); 18 19function set_multi_currency_cookie(e) { 20 e.preventDefault(); 21 22 setEsCookie("multi_currency", jQuery(this).data('currency'), 365); 23 location.reload(true); 24 return false; 25} 26function update_not_converted_prices() { 27 28 var currency_cookie = getEsCookie("multi_currency"); 29 30 if (typeof multi_currency_default === 'undefined' || currency_cookie === "" || currency_cookie === multi_currency_default || !(currency_cookie in multi_currency_data)) { 31 return; 32 } 33 34 var base_currency = multi_currency_default; 35 var base_currency_seperator = mutti_currency_decimal_seperator; 36 var base_currency_data = multi_currency_default_data; 37 var currency_data = multi_currency_data[currency_cookie]; 38 var new_currency = currency_data['symbol']; 39 var currency_factor = currency_data['factor']; 40 var currency_decimal = currency_data['decimal']; 41 var decimal_seperator = currency_decimal == "comma" ? "," : "."; 42 var thousand_seperator = currency_decimal == "comma" ? "." : "?"; 43 44 jQuery('.currency-toggle .currency-symbol').text(new_currency); 45 46 var regex_as_string = ""; 47 if (base_currency_seperator == "comma") { 48 regex_as_string = "([\\d.]+)(?:\\,(-|\\d{1,2}))"; 49 } else { 50 regex_as_string = "([\\d,]+)(?:\\.(-|\\d{1,2}))"; 51 } 52 53 var replace_regex = new RegExp(regex_as_string, "g"); 54 var replace_regex_full = new RegExp("(" + base_currency_data[1] + ".*?)" + regex_as_string, "g"); 55 56 jQuery(".woocommerce-Price-amount:not(.multi-currency)").each(function () { 57 58 jQuery(this).find('.woocommerce-Price-currencySymbol').text(jQuery(this).find('.woocommerce-Price-currencySymbol').text().replace(base_currency_data[1], new_currency)); 59 jQuery(this).html(jQuery(this).html().replace(replace_regex, function (regex, units, cents) { 60 if (cents == "-") { 61 cents = 0; 62 63 } else { 64 cents = +(cents || 0); 65 66 } 67 68 units = parseInt(units.replace(",", "").replace(".", "")); 69 70 var new_value = (units + cents / 100) * currency_factor; 71 if (isNaN(new_value + Number.EPSILON)) { 72 console.log("Error!", [this, regex, units, cents]); 73 return regex; 74 } 75 76 var formatted_result = format_money_custom(new_value + Number.EPSILON, decimal_seperator, thousand_seperator); 77 78 79 return formatted_result; 80 })); 81 jQuery(this).addClass('multi-currency'); 82 }); 83 84 85 jQuery('p:contains("' + base_currency_data[1] + '"), span:contains("' + base_currency_data[1] + '")').each(function () { 86 87 var new_html = jQuery(this).html().replace(replace_regex_full, function (regex, symbol, units, cents) { 88 if (cents == "-") { 89 cents = 0; 90 91 } else { 92 cents = +(cents || 0); 93 94 } 95 96 units = parseInt(units.replace(",", "").replace(".", "")); 97 98 var new_value = (units + cents / 100) * currency_factor; 99 100 101 if (isNaN(new_value + Number.EPSILON)) { 102 console.log("Error!", [regex, symbol, units, cents]); 103 } 104 105 var formatted_result = format_money_custom(new_value + Number.EPSILON, decimal_seperator, thousand_seperator); 106 107 return symbol.replace(base_currency_data[1], new_currency) + formatted_result; 108 }); 109 110 111 jQuery(this).html(new_html); 112 }); 113}
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.