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