PageSourceSearch

https://cartoys.com.au/wp-content/plugins/woocommerce-currency-switcher/js/front.js?ver=2.3.3.2

js cartoys.com.au collected 2026-09-25 22:56:03 UTC 20,343 bytes, 537 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    jQuery.fn.life = function (types, data, fn) {
8        jQuery(this.context).on(types, this.selector, data, fn);
9        return this;
10    };
11
12    woocs_array_of_get = jQuery.parseJSON(woocs_array_of_get);
13
14    //wp-content\plugins\woocommerce\assets\js\frontend\cart.js
15    if (Object.keys(woocs_array_of_get).length !== 0) {
16        if ('currency' in woocs_array_of_get) {
17            //console.log('here');
18            //this code nessesary for correct redrawing of the shipping methods while currency changes on the cart page
19            $('body.woocommerce-cart .shop_table.cart').closest('form').find('input[name="update_cart"]').prop('disabled', false);
20            $('body.woocommerce-cart .shop_table.cart').closest('form').find('input[name="update_cart"]').trigger('click');
21        }
22    }
23
24    //keeps data of $_GET array
25
26    if (Object.keys(woocs_array_of_get).length == 0) {
27        woocs_array_of_get = {};
28    }
29
30    //***
31    woocs_array_no_cents = jQuery.parseJSON(woocs_array_no_cents);
32
33    //***
34
35    //emptying cart widget after checkout
36    if (!parseInt(woocs_get_cookie('woocommerce_items_in_cart'), 10)) {
37        $('.widget_shopping_cart_content').empty();
38        $(document.body).trigger('wc_fragment_refresh');
39    }
40
41    if (woocs_array_of_get.currency != undefined || woocs_array_of_get.removed_item != undefined || woocs_array_of_get.key != undefined)
42    {
43        woocs_refresh_mini_cart(555);
44    }
45    if(woocs_redraw_cart){
46        //intercept adding to cart event to redraw mini-cart widget
47        jQuery(document).on("adding_to_cart", function () {
48            woocs_refresh_mini_cart(999);
49        });
50    }
51
52    //to make price popup mobile friendly
53    jQuery('.woocs_price_info').life('click', function () {
54        return false;
55    });
56
57    //+++++++++++++++++++++++++++++++++++++++++++++++
58    //console.log(woocs_drop_down_view);
59    if (woocs_drop_down_view == 'chosen' || woocs_drop_down_view == 'chosen_dark') {
60        try {
61            if (jQuery("select.woocommerce-currency-switcher").length) {
62                jQuery("select.woocommerce-currency-switcher").chosen({
63                    disable_search_threshold: 10
64                });
65
66                jQuery.each(jQuery('.woocommerce-currency-switcher-form .chosen-container'), function (index, obj) {
67                    jQuery(obj).css({'width': jQuery(this).prev('select').data('width')});
68                });
69            }
70        } catch (e) {
71            console.log(e);
72        }
73    }
74
75
76
77    if (woocs_drop_down_view == 'ddslick') {
78        try {
79            jQuery.each(jQuery('select.woocommerce-currency-switcher'), function (index, obj) {
80                var width = jQuery(obj).data('width');
81                var flag_position = jQuery(obj).data('flag-position');
82                jQuery(obj).ddslick({
83                    //data: ddData,
84                    width: width,
85                    imagePosition: flag_position,
86                    selectText: "Select currency",
87                    //background:'#ff0000',
88                    onSelected: function (data) {
89                        if (!woocs_loading_first_time)
90                        {
91                            var form = jQuery(data.selectedItem).closest('form.woocommerce-currency-switcher-form');
92                            jQuery(form).find('input[name="woocommerce-currency-switcher"]').eq(0).val(data.selectedData.value);
93
94                            if (Object.keys(woocs_array_of_get).length == 0) {
95                                //jQuery(form).submit();
96                                woocs_redirect(data.selectedData.value);
97                            } else {
98                                woocs_redirect(data.selectedData.value);
99                            }
100
101
102                        }
103                    }
104                });
105            });
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').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('.woocs_rates_current_currency').life('change', 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            woocs_sumbit_currency_changing = false;
197            if (typeof woocs_array_of_get.currency === 'undefined') {
198
199                if (jQuery('body').hasClass('single')) {
200                    jQuery('.woocs_price_info').remove();
201                }
202
203                /****/
204                var custom_prices = [];
205                jQuery.each(jQuery('.woocs_amount_custom_price'), function (index, item) {
206                    custom_prices.push(jQuery(item).data('value'));
207                });
208                if (custom_prices.length != 0) {
209
210                    var data = {
211                        action: "woocs_get_custom_price_html",
212                        custom_prices: custom_prices
213                    };
214                    jQuery.post(woocs_ajaxurl, data, function (data) {
215                        data = jQuery.parseJSON(data);
216
217                        if (!jQuery.isEmptyObject(data)) {
218                            jQuery.each(data, function (val, price) {
219                                jQuery(".woocs_amount_custom_price[data-value='" + val + "']").replaceWith(price);
220                                //console.log(price);
221
222                            });
223
224                        }
225                    });
226                }
227                
228
229                /****/
230
231                var variation_ids = [];
232                var var_data = jQuery("form.variations_form").data("product_variations");
233                if (typeof var_data != "undefined") {
234                    jQuery.each(var_data, function (indx, attr) {
235                        variation_ids.push(attr['variation_id']);
236                    });
237                    if (variation_ids.length != 0) {
238                        var data_var = {
239                            action: "woocs_get_variation_products_price_html",
240                            var_products_ids: variation_ids
241                        };
242
243                        jQuery.post(woocs_ajaxurl, data_var, function (data) {
244                            data = jQuery.parseJSON(data);
245
246                            if (!jQuery.isEmptyObject(data)) {
247                                jQuery.each(var_data, function (indx, attr) {
248                                    if (typeof data[attr['variation_id']] != "undefined") {
249                                        var_data[indx]['price_html'] = data[attr['variation_id']];
250                                    }
251                                });
252                                jQuery("form.variations_form").data("product_variations", var_data);
253                            }
254                        });
255                    }
256                }
257
258                //***
259                var products_ids = [];
260                jQuery.each(jQuery('.woocs_price_code'), function (index, item) {
261                    products_ids.push(jQuery(item).data('product-id'));
262                });
263
264                //if no prices on the page - do nothing
265                if (products_ids.length === 0) {
266                    woocs_sumbit_currency_changing = true;
267                    return;
268                }
269
270
271                var data = {
272                    action: "woocs_get_products_price_html",
273                    products_ids: products_ids,
274                };
275                jQuery.post(woocs_ajaxurl, data, function (data) {
276
277                    data = jQuery.parseJSON(data);
278                    if (!jQuery.isEmptyObject(data)) {
279                        jQuery('.woocs_price_info').remove();
280                        jQuery.each(jQuery('.woocs_price_code'), function (index, item) {
281
282                            if (data.ids[jQuery(item).data('product-id')] != undefined) {
283                                jQuery(item).replaceWith(data.ids[jQuery(item).data('product-id')]);
284                            }
285
286                        });
287                        jQuery('.woocs_price_code').removeClass('woocs_preloader_ajax');
288                        //***
289                        jQuery('.woocommerce-currency-switcher').val(data.current_currency);
290                        //***
291                        if (woocs_drop_down_view == 'chosen' || woocs_drop_down_view == 'chosen_dark') {
292                            try {
293                                if (jQuery("select.woocommerce-currency-switcher").length) {
294                                    jQuery("select.woocommerce-currency-switcher").chosen({
295                                        disable_search_threshold: 10
296                                    });
297                                    jQuery('select.woocommerce-currency-switcher').trigger("chosen:updated");
298                                }
299                            } catch (e) {
300                                console.log(e);
301                            }
302                        }
303                        if(typeof data.currency_data!="undefined"){
304                            woocs_current_currency=data.currency_data;                            
305                            /* Price  slider */                           
306                            var min =jQuery('.price_slider_amount #min_price').val();
307                            var max =jQuery('.price_slider_amount #max_price').val();
308                            if(typeof max!='undefined' && typeof min!='undefined' ){
309                                max =woocs_convert_price_slider(max);
310                                min =woocs_convert_price_slider(min);
311                                jQuery(document.body).trigger('price_slider_create',[min,max]);                                                               
312                            }                           
313                        }
314                        //***
315                        if (woocs_drop_down_view == 'ddslick') {
316                            try {
317                                jQuery('select.woocommerce-currency-switcher').ddslick('select', {index: data.current_currency, disableTrigger: true});
318                            } catch (e) {
319                                console.log(e);
320                            }
321                        }
322                        //***
323                        if (woocs_drop_down_view == 'wselect' && woocs_is_mobile != 1) {
324                            //https://github.com/websanova/wSelect
325                            try {
326                                jQuery('select.woocommerce-currency-switcher').val(data.current_currency).change();
327                            } catch (e) {
328                                console.log(e);
329                            }
330                        }
331                        //***
332                        /* auto switcher*/
333
334                        var auto_switcher = jQuery('.woocs_auto_switcher');
335                        if (auto_switcher.length > 0) {
336                            woocs_auto_switcher_redraw(data.current_currency, auto_switcher);
337                        }
338                        woocs_sumbit_currency_changing = true;
339
340
341                        //***
342                        //for another woocs switchers styles
343                        document.dispatchEvent(new CustomEvent('after_woocs_get_products_price_html', {detail: {
344                                current_currency: data.current_currency
345                            }}));
346                    }
347
348                });
349
350            } else {
351                woocs_sumbit_currency_changing = true;
352                jQuery('.woocs_price_code').removeClass('woocs_preloader_ajax');
353            }
354        }
355    }
356
357    //***
358    //removing price info on single page near variation prices
359    setTimeout(function () {
360        //jQuery('body.single-product .woocommerce-variation-price').find('.woocs_price_info').remove();
361    }, 300);
362    //***
363
364
365});
366
367
368function woocs_redirect(currency) {
369    if (!woocs_sumbit_currency_changing) {
370        return;
371    }
372
373    //***
374    var l = window.location.href;
375    l = l.replace('#', '');
376
377    //for #id navigation     l = l.replace(/(#.+$)/gi, '');
378
379    l = l.split('?');
380    l = l[0];
381    var string_of_get = '?';
382    woocs_array_of_get.currency = currency;
383
384    /*
385     l = l.replace(/(\?currency=[a-zA-Z]+)/g, '?');
386     l = l.replace(/(&currency=[a-zA-Z]+)/g, '');
387     */
388
389    if (woocs_special_ajax_mode) {
390        string_of_get = "";
391
392        var data = {
393            action: "woocs_set_currency_ajax",
394            currency: currency
395        };
396
397        jQuery.post(woocs_ajaxurl, data, function (value) {
398            location.reload();
399        });
400
401    } else {
402        if (Object.keys(woocs_array_of_get).length > 0) {
403            jQuery.each(woocs_array_of_get, function (index, value) {
404                string_of_get = string_of_get + "&" + index + "=" + value;
405            });
406            //string_of_get+=decodeURIComponent(jQuery.param(woocs_array_of_get));        
407        }
408        window.location = l + string_of_get;
409    }
410
411
412}
413
414function woocs_refresh_mini_cart(delay) {
415    /** Cart Handling */
416    setTimeout(function () {
417        try {
418            //for refreshing mini cart
419            $fragment_refresh = {
420                url: wc_cart_fragments_params.ajax_url,
421                type: 'POST',
422                data: {action: 'woocommerce_get_refreshed_fragments', woocs_woocommerce_before_mini_cart: 'mini_cart_refreshing'},
423                success: function (data) {
424                    if (data && data.fragments) {
425
426                        jQuery.each(data.fragments, function (key, value) {
427                            jQuery(key).replaceWith(value);
428                        });
429
430                        try {
431                            if ($supports_html5_storage) {
432                                sessionStorage.setItem(wc_cart_fragments_params.fragment_name, JSON.stringify(data.fragments));
433                                sessionStorage.setItem('wc_cart_hash', data.cart_hash);
434                            }
435                        } catch (e) {
436
437                        }
438
439                        jQuery('body').trigger('wc_fragments_refreshed');
440                    }
441                }
442            };
443
444            jQuery.ajax($fragment_refresh);
445
446
447            /* Cart hiding */
448            try {
449                //if (jQuery.cookie('woocommerce_items_in_cart') > 0)
450                if (woocs_get_cookie('woocommerce_items_in_cart') > 0)
451                {
452                    jQuery('.hide_cart_widget_if_empty').closest('.widget_shopping_cart').show();
453                } else {
454                    jQuery('.hide_cart_widget_if_empty').closest('.widget_shopping_cart').hide();
455                }
456            } catch (e) {
457                //***
458            }
459
460
461            jQuery('body').bind('adding_to_cart', function () {
462                jQuery('.hide_cart_widget_if_empty').closest('.widget_shopping_cart').show();
463            });
464
465        } catch (e) {
466            //***
467        }
468
469    }, delay);
470
471}
472
473function woocs_get_cookie(name) {
474    var matches = document.cookie.match(new RegExp(
475            "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
476            ));
477    return matches ? decodeURIComponent(matches[1]) : undefined;
478}
479
480/*auto switcher*/
481
482jQuery(function () {
483    jQuery('.woocs_auto_switcher_link').on('click', function () {
484        woocs_redirect(jQuery(this).data('currency'));
485        return false;
486    });
487
488    jQuery('.woocs_auto_switcher li').on('click', function (e) {
489        woocs_redirect(jQuery(this).find('a.woocs_auto_switcher_link').data('currency'));
490        return false;
491    });
492});
493
494function woocs_auto_switcher_redraw(curr_curr, switcher) {
495    var view = switcher.data('view');
496    switch (view) {
497        case 'classic_blocks':
498            switcher.find('a').removeClass('woocs_curr_curr');
499            switcher.find('a[data-currency="' + curr_curr + '"]').addClass('woocs_curr_curr');
500            break;
501        case 'roll_blocks':
502            switcher.find('a').removeClass('woocs_curr_curr');
503            switcher.find('li').removeClass('woocs_auto_bg_woocs_curr_curr');
504            var current_link = switcher.find('a[data-currency="' + curr_curr + '"]');
505            current_link.addClass('woocs_curr_curr');
506            current_link.parents('li').addClass('woocs_auto_bg_woocs_curr_curr');
507            break;
508        case 'round_select':
509            switcher.find('a').removeClass('woocs_curr_curr');
510            var current_link = switcher.find('a[data-currency="' + curr_curr + '"]');
511            current_link.addClass('woocs_curr_curr');
512            jQuery('.woocs_current_text').html(current_link.find('.woocs_base_text').html());
513            break;
514        default:
515            break;
516    }
517
518}
519
520function woocs_remove_link_param(key, sourceURL) {
521    var rtn = sourceURL.split("?")[0],
522            param,
523            params_arr = [],
524            queryString = (sourceURL.indexOf("?") !== -1) ? sourceURL.split("?")[1] : "";
525    if (queryString !== "") {
526        params_arr = queryString.split("&");
527        for (var i = params_arr.length - 1; i >= 0; i -= 1) {
528            param = params_arr[i].split("=")[0];
529            if (param === key) {
530                params_arr.splice(i, 1);
531            }
532        }
533        rtn = rtn + "?" + params_arr.join("&");
534    }
535    return rtn;
536}
537

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.