1jQuery(document).ready(function ($) { 2 'use strict'; 3 $(document.body).on('updated_checkout', function (event, response) { 4 if (response.hasOwnProperty('wmc_update_checkout') && response.wmc_update_checkout) { 5 $(document.body).trigger('update_checkout'); 6 } 7 }); 8 $(document.body).on('payment_method_selected', function (event, response) { 9 let selectedPaymentMethod = $('.woocommerce-checkout input[name="payment_method"]:checked').val(); 10 if (selectedPaymentMethod === 'ppcp-gateway') { 11 $(document.body).trigger('update_checkout'); 12 } 13 }); 14 window.woo_multi_currency = { 15 init: function () { 16 this.design(); 17 this.checkPosition(); 18 this.cacheCompatible(); 19 this.ajaxComplete(); 20 }, 21 22 design: function () { 23 var windowsize = jQuery(window).width(); 24 if (windowsize <= 768) { 25 jQuery('.woo-multi-currency.wmc-sidebar').on('click', function () { 26 jQuery(this).toggleClass('wmc-hover'); 27 if (jQuery(this).hasClass('wmc-hover')) { 28 jQuery('html').css({'overflow': 'hidden'}); 29 } else { 30 jQuery('html').css({'overflow': 'visible'}); 31 } 32 }) 33 } else { 34 /*replace hover with mouseenter mouseleave in some cases to work correctly*/ 35 jQuery('.woo-multi-currency.wmc-sidebar').on('mouseenter', function () { 36 let $this = jQuery(this); 37 $this.addClass('wmc-hover'); 38 }); 39 jQuery('.woo-multi-currency.wmc-sidebar').on('mouseleave', function () { 40 let $this = jQuery(this); 41 $this.removeClass('wmc-hover'); 42 }) 43 } 44 }, 45 46 checkPosition: function () { 47 jQuery('.woo-multi-currency .wmc-currency-wrapper').on('mouseenter', function () { 48 if (this.getBoundingClientRect().top / $(window).height() > 0.5) { 49 $('.woo-multi-currency .wmc-sub-currency').addClass('wmc-show-up'); 50 } else { 51 $('.woo-multi-currency .wmc-sub-currency').removeClass('wmc-show-up'); 52 } 53 }); 54 }, 55 56 cacheCompatible() { 57 if (wooMultiCurrencyParams.enableCacheCompatible === '1') { 58 59 if (typeof wc_checkout_params !== 'undefined') { 60 if (parseInt(wc_checkout_params.is_checkout) === 1) return; 61 } 62 63 let pids = []; 64 let simpleCache = $('.wmc-cache-pid'); 65 if (simpleCache.length) { 66 simpleCache.each(function (i, element) { 67 let wmc_product_id = $(element).data('wmc_product_id'); 68 if (wmc_product_id) { 69 pids.push(wmc_product_id); 70 } 71 }); 72 } 73 74 let variationCache = $('.variations_form'); 75 if (variationCache.length) { 76 variationCache.each(function (index, variation) { 77 let data = $(variation).data('product_variations'); 78 if (data.length) { 79 data.forEach((element) => { 80 pids.push(element.variation_id); 81 }); 82 } 83 }); 84 } 85 86 let $shortcodes = $('.woo-multi-currency.wmc-shortcode').not('.wmc-list-currency-rates'), 87 shortcodes = []; 88 $shortcodes.map(function () { 89 let $shortcode = $(this); 90 shortcodes.push({ 91 layout: $shortcode.data('layout') ? $shortcode.data('layout') : 'default', 92 flag_size: $shortcode.data('flag_size'), 93 }); 94 }); 95 if (pids.length) pids = [...new Set(pids)]; //remove duplicate element 96 97 let exchangePrice = []; 98 $('.wmc-cache-value').each(function (i, element) { 99 exchangePrice.push({ 100 price: $(element).data('price'), 101 original_price: $(element).data('original_price'), 102 currency: $(element).data('currency'), 103 product_id: $(element).data('product_id'), 104 keep_format: $(element).data('keep_format') 105 }); 106 }); 107 exchangePrice = [...new Set(exchangePrice.map(JSON.stringify))].map(JSON.parse); 108 109 $.ajax({
110 url: wooMultiCurrencyParams.ajaxUrl, 111 type: 'POST', 112 data: { 113 action: 'wmc_get_products_price', 114 pids: pids, 115 shortcodes: shortcodes, 116 wmc_current_url: $('.wmc-current-url').val(), 117 exchange: exchangePrice 118 }, 119 success(res) { 120 if (res.success) { 121 let prices = res.data.prices || '', 122 currentCurrency = res.data.current_currency || '', 123 exSc = res.data.exchange || ''; 124 125 if (shortcodes.length > 0 && shortcodes.length === res.data.shortcodes.length) { 126 for (let i = 0; i < shortcodes.length; i++) { 127 $shortcodes.eq(i).replaceWith(res.data.shortcodes[i]); 128 } 129 } 130 131 if (wooMultiCurrencyParams.switchByJS !== '1') { 132 $('.wmc-currency a').unbind(); 133 } 134 135 if (currentCurrency) { 136 /*Sidebar*/ 137 $('.wmc-sidebar .wmc-currency').removeClass('wmc-active'); 138 $(`.wmc-sidebar .wmc-currency[data-currency=${currentCurrency}]`).addClass('wmc-active'); 139 /*Product price switcher*/ 140 $('.wmc-price-switcher .wmc-current-currency i').removeClass().addClass('vi-flag-64 flag-' + res.data.current_country); 141 $(`.wmc-price-switcher .wmc-sub-currency-current`).removeClass('wmc-sub-currency-current'); 142 $(`.wmc-price-switcher .wmc-currency[data-currency=${currentCurrency}]`).addClass('wmc-sub-currency-current'); 143 144 $(`select.wmc-nav option[data-currency=${currentCurrency}]`).prop('selected', true); 145 $('body').removeClass(`woocommerce-multi-currency-${wooMultiCurrencyParams.current_currency}`).addClass(`woocommerce-multi-currency-${currentCurrency}`); 146 } 147 // woo_multi_currency.disableCurrentCurrencyLink(); 148 if (typeof woo_multi_currency_switcher !== 'undefined') { 149 woo_multi_currency_switcher.init(); 150 } 151 152 153 if (prices) { 154 for (let id in prices) { 155 let priceBlock = $(`.wmc-cache-pid[data-wmc_product_id=${id}]`), 156 priceContainer = $(priceBlock).parent(); 157 if (wooMultiCurrencyParams.woo_subscription === '1') { 158 $(priceContainer).find('.subscription-details').remove(); 159 } 160 $(priceBlock).replaceWith(prices[id]); 161 } 162 163 $('.variations_form').each((i, form) => { 164 let data = $(form).data('product_variations'); 165 if (data) { 166 data.map((element) => { 167 let pid = element.variation_id; 168 element.price_html = prices[pid]; 169 return element 170 }); 171 $(form).data('product_variations', data); 172 } 173 }); 174 } 175 176 if (exSc) { 177 for (let i in exSc) { 178 $(`.wmc-cache-value[data-price="${exSc[i]['price']}"][data-product_id="${exSc[i]['product_id']}"][data-keep_format="${exSc[i]['keep_format']}"][data-original_price="${exSc[i]['original_price']}"][data-currency="${exSc[i]['currency']}"]`).replaceWith(exSc[i]['shortcode']); 179 } 180 } 181 jQuery(document.body).trigger("wmc_cache_compatible_finish", [res.data]); 182 } 183 } 184 }); 185 } 186 }, 187 188 ajaxComplete() { 189 $(document).on('append.infiniteScroll', () => { 190 this.cacheCompatible(); 191 }); 192 } 193 }; 194 195 woo_multi_currency.init(); 196});
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.