PageSourceSearch

https://lady2fight.com/wp-content/plugins/woocommerce-currency-switcher/js/front.js?ver=1.4.8

js lady2fight.com collected 2026-09-30 05:04:59 UTC 26,863 bytes, 658 lines download raw bytes

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

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.