PageSourceSearch

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

js masterswiss.com collected 2026-10-02 07:13:40 UTC 23,066 bytes, 574 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
369});
370
371
372function woocs_redirect(currency) {
373    if (!woocs_sumbit_currency_changing) {
374        return;
375    }
376
377    //***
378    var l = window.location.href;
379    //  l = l.replace('#', '');
380    var l_tmp = l.split('#');
381    l = l_tmp[0];
382    var id_key = "";
383    if (l_tmp.length > 1) {
384        id_key = "#" + l_tmp[1]
385    }
386    //for #id navigation     l = l.replace(/(#.+$)/gi, '');
387
388    l = l.split('?');
389    l = l[0];
390    var string_of_get = '?';
391    woocs_array_of_get.currency = currency;
392
393    /*
394     l = l.replace(/(\?currency=[a-zA-Z]+)/g, '?');
395     l = l.replace(/(&currency=[a-zA-Z]+)/g, '');
396     */
397
398    if (woocs_special_ajax_mode) {
399        string_of_get = "";
400
401        var data = {
402            action: "woocs_set_currency_ajax",
403            currency: currency
404        };
405
406        jQuery.post(woocs_ajaxurl, data, function (value) {
407            location.reload();
408        });
409
410    } else {
411        if (Object.keys(woocs_array_of_get).length > 0) {
412	    let get_values = [];
413            jQuery.each(woocs_array_of_get, function (index, value) {
414                get_values.push(index + "=" + value);
415            });
416	    string_of_get += get_values.join("&");
417	}
418        window.location = l + string_of_get + id_key;
419    }
420}
421
422function woocs_refresh_mini_cart(delay) {
423    /** Cart Handling */
424    setTimeout(function () {
425        try {
426
427            //for refreshing mini cart
428            $fragment_refresh = {
429                url: wc_cart_fragments_params.ajax_url,
430                type: 'POST',
431                data: {action: 'woocommerce_get_refreshed_fragments', woocs_woocommerce_before_mini_cart: 'mini_cart_refreshing'},
432                success: function (data) {
433                    if (data && data.fragments) {
434
435                        jQuery.each(data.fragments, function (key, value) {
436                            jQuery(key).replaceWith(value);
437                        });
438
439                        try {
440                            if ($supports_html5_storage) {
441                                sessionStorage.setItem(wc_cart_fragments_params.fragment_name, JSON.stringify(data.fragments));
442                                sessionStorage.setItem('wc_cart_hash', data.cart_hash);
443                            }
444                        } catch (e) {
445
446                        }
447
448                        jQuery('body').trigger('wc_fragments_refreshed');
449                    }
450                }
451            };
452
453            jQuery.ajax($fragment_refresh);
454
455
456            /* Cart hiding */
457            try {
458                if (woocs_get_cookie('woocommerce_items_in_cart') > 0)
459                {
460                    jQuery('.hide_cart_widget_if_empty').closest('.widget_shopping_cart').show();
461                } else {
462                    jQuery('.hide_cart_widget_if_empty').closest('.widget_shopping_cart').hide();
463                }
464            } catch (e) {
465                //***
466            }
467
468
469            jQuery('body').on('adding_to_cart', function () {
470                jQuery('.hide_cart_widget_if_empty').closest('.widget_shopping_cart').show();
471            });
472
473        } catch (e) {
474            //***
475        }
476
477    }, delay);
478
479}
480
481function woocs_get_cookie(name) {
482    var matches = document.cookie.match(new RegExp(
483            "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
484            ));
485    return matches ? decodeURIComponent(matches[1]) : undefined;
486}
487
488/*auto switcher*/
489
490jQuery(function () {
491    jQuery('.woocs_auto_switcher_link').on('click', function () {
492        woocs_redirect(jQuery(this).data('currency'));
493        return false;
494    });
495
496    jQuery('.woocs_auto_switcher li').on('click', function (e) {
497        woocs_redirect(jQuery(this).find('a.woocs_auto_switcher_link').data('currency'));
498        return false;
499    });
500});
501
502function woocs_auto_switcher_redraw(curr_curr, switcher) {
503    var view = switcher.data('view');
504    switch (view) {
505        case 'classic_blocks':
506            switcher.find('a').removeClass('woocs_curr_curr');
507            switcher.find('a[data-currency="' + curr_curr + '"]').addClass('woocs_curr_curr');
508            break;
509        case 'roll_blocks':
510            switcher.find('a').removeClass('woocs_curr_curr');
511            switcher.find('li').removeClass('woocs_auto_bg_woocs_curr_curr');
512            var current_link = switcher.find('a[data-currency="' + curr_curr + '"]');
513            current_link.addClass('woocs_curr_curr');
514            current_link.parents('li').addClass('woocs_auto_bg_woocs_curr_curr');
515            break;
516        case 'round_select':
517            switcher.find('a').removeClass('woocs_curr_curr');
518            var current_link = switcher.find('a[data-currency="' + curr_curr + '"]');
519            current_link.addClass('woocs_curr_curr');
520            jQuery('.woocs_current_text').html(current_link.find('.woocs_base_text').html());
521            break;
522        default:
523            break;
524    }
525
526}
527
528function woocs_remove_link_param(key, sourceURL) {
529    var rtn = sourceURL.split("?")[0],
530            param,
531            params_arr = [],
532            queryString = (sourceURL.indexOf("?") !== -1) ? sourceURL.split("?")[1] : "";
533    if (queryString !== "") {
534        params_arr = queryString.split("&");
535        for (var i = params_arr.length - 1; i >= 0; i -= 1) {
536            param = params_arr[i].split("=")[0];
537            if (param === key) {
538                params_arr.splice(i, 1);
539            }
540        }
541        rtn = rtn + "?" + params_arr.join("&");
542    }
543    return rtn;
544}
545
546function woocs_init_ddslick_select() {
547    jQuery.each(jQuery('select.woocommerce-currency-switcher').not('.woocs_clean_select'), function (index, obj) {
548        var width = jQuery(obj).data('width');
549        var flag_position = jQuery(obj).data('flag-position');
550        jQuery(obj).ddslick({
551            //data: ddData,
552            width: width,
553            imagePosition: flag_position,
554            selectText: "Select currency",
555            //background:'#ff0000',
556            onSelected: function (data) {
557                if (!woocs_loading_first_time)
558                {
559                    var form = jQuery(data.selectedItem).closest('form.woocommerce-currency-switcher-form');
560                    jQuery(form).find('input[name="woocommerce-currency-switcher"]').eq(0).val(data.selectedData.value);
561
562                    if (Object.keys(woocs_array_of_get).length == 0) {
563                        //jQuery(form).submit();
564                        woocs_redirect(data.selectedData.value);
565                    } else {
566                        woocs_redirect(data.selectedData.value);
567                    }
568                }
569
570            }
571        });
572    });
573}
574

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.