1'use strict'; 2 3function changeAjaxCall(dataObj) { 4 $.ajax({ 5 type: 'get', 6 url: dataObj.url, 7 data: dataObj, 8 success:function(response){ 9 if(dataObj.changeAddressAjax) { 10 alert(dataObj.successMsg); 11 window.location.href=dataObj.redirect; 12 }else { 13 window.location.href=response.redirectUrl; 14 } 15 } 16 }); 17} 18 19function setDefaultCurrency($selectedCurrency) { 20 var $currencySelector = $('.esw-country-selector.selectCurrency .select-field'); 21 var $currencySelectorDropDown = $('.esw-country-selector.selectCurrency .select-field .current-country'); 22 var $selectedCountry = $('#selected-country'); 23 var selectedCountry = $selectedCountry.attr('data-value'); 24 var urlGetDefaultCurrency = $selectedCountry.attr('data-url'); 25 26 $.ajax({ 27 type: 'get', 28 url: urlGetDefaultCurrency, 29 data: { 30 'country' : selectedCountry 31 }, 32 success: function (response) { 33 if (response.success) { 34 // Setting the default mapped currency 35 $selectedCurrency.html(response.currency); 36 $selectedCurrency.attr('data-value', response.currency); 37 38 // Check if country is esw allowed country and not fixed price country 39 if (response.isAllowed && !response.isFixedPriceCountry) { 40 // Yes, Enable Currency Selectors 41 $currencySelector.removeClass('disabled'); 42 $currencySelectorDropDown.removeClass('disabled'); 43 } else { 44 // No, Disable Currency Selectors 45 $currencySelector.addClass('disabled'); 46 $currencySelectorDropDown.addClass('disabled'); 47 } 48 } 49 } 50 }); 51} 52 53function openEswCountrySwitcher(dataObj){ 54 $.ajax({ 55 type: 'get', 56 url: dataObj.eswLandingPageUrl, 57 data: dataObj, 58 success:function(response){ 59 $('header').prepend(response); 60 var $selectedCurrency = $('#selected-currency'); 61 62 if ($selectedCurrency.length > 0) { 63 setDefaultCurrency($selectedCurrency); 64 } 65 } 66 }); 67} 68 69function updateCountryList () { 70 $(document).on('click','.btnCheckout', function(e) { 71 e.preventDefault(); 72 $('.eshopworld-loader').removeClass('d-none'); 73 $('.btnCheckout').addClass("disabled"); 74 $.ajax({ 75 type : 'get', 76 url : $(this).attr('data-url'), 77 data: '', 78 success : function (response) { 79 window.open(response.redirectURL,'_self'); 80 } 81 }); 82 }); 83 84 $(document).on('click','.closeLandingPage', function() { 85 $('.eswModal').hide(); 86 $('.modalBg').hide(); 87 }); 88 89 // set currency first before reload 90 $('body').on('click','.esw-country-selector .selector a.landing-link', function (e) { 91 e.preventDefault(); 92 var element = $(this).parents('.select-field'); 93 $(element).find('span').attr('data-value',$(this).attr('data-param')); 94 $(element).find('.current-country .flag-icon').attr('class','flag-icon flag-icon-'+$(this).attr('data-param').toLowerCase()); 95 $(element).find('span').text($(this).text()); 96 $('.selector-active').removeClass('selector-active'); 97 $(this).parents('.active').removeClass('active'); 98 }); 99 100 // This function selects default currency based on the selected country. 101 $('body').on('click', '.esw-country-selector .selector .country.landing-link', function(){ 102 var $selectedCurrency = $('#selected-currency'); 103 104 if ($selectedCurrency.length > 0) { 105 setDefaultCurrency($selectedCurrency); 106 } 107 }); 108 109 // This function selects default currency based on the selected country. 110 $('body').on('click', '.esw-country-selector .selector .country.landing-link', function(){ 111 var $selectedCurrency = $('#selected-currency'); 112 var $selectedCountry = $('#selected-country'); 113 var selectedCountry = $selectedCountry.attr('data-value'); 114 115 var dataUrl = $selectedCountry.attr('data-url'); 116 117 if ($selectedCurrency.length > 0) { 118 $.ajax({ 119 type: 'get', 120 url: dataUrl, 121 data: { 122 'country' : selectedCountry 123 }, 124 success: function (response) { 125 if (response.success) { 126 $selectedCurrency.html(response.currency); 127 $selectedCurrency.attr('data-value', response.currency); 128 } 129 } 130 }); 131 } 132 }); 133 134 $(document).on('click','.esw-btn',function(){ 135 var country = $("#selected-country").attr('data-value'); 136 var currency = $("#selected-currency").attr('data-value'); 137 var language = $("#selected-locale").attr('data-value'); 138 139 if (country){ 140 if(!currency){ 141 currency = $("#selected-country").closest('.select-field').find('.country a:first').attr('data-currency'); 142 } 143 if(!language){ 144 language = $("#selected-country").closest('.select-field').find('.country a:first').attr('data-locale'); 145 } 146 }else if (language){ 147 if(!currency){ 148 currency = $("#selected-locale").closest('.select-field').find('.country a:first').attr('data-currency'); 149 } 150 if(!country){ 151 country = $("#selected-locale").closest('.select-field').find('.country a:first').attr('data-country'); 152 } 153 }else if (currency){ 154 if(!country){ 155 country = $("#selected-currency").closest('.select-field').find('.country a:first').attr('data-currency'); 156 } 157 if(!language){ 158 language = $("#selected-currency").closest('.select-field').find('.country a:first').attr('data-locale'); 159 } 160 } 161 var dataObj = { 162 'country': country, 163 'currency': currency, 164 'language': language, 165 'url': $(this).attr('data-url'), 166 'action':'Home-Show' 167 }; 168 changeAjaxCall(dataObj); 169 }); 170 171 $('.headerDropdown, .footerDropdown').click(function(e){ 172 var eswLandingPageUrl = $(this).attr('data-url'); 173 var dataObj = { 174 'eswLandingPageUrl': eswLandingPageUrl, 175 'dropDownSelection': 'true' 176 } 177 openEswCountrySwitcher(dataObj); 178 }); 179 180 $(document).on('click','.selected-link', function () { 181 var dataObj = { 182 'country': $(this).attr('data-country'), 183 'currency': $(this).attr('data-currency'), 184 'language': $(this).attr('data-locale'), 185 'url': $(this).attr('data-url'), 186 'action': $('.page').data('action'), 187 'queryString': $('.page').data('querystring') 188 }; 189 changeAjaxCall(dataObj); 190 }); 191 192 $(document).on('change','#shippingCountrydefault',function(){ 193 var selectedData = {'country' : $('#shippingCountrydefault').val().toUpperCase(), 194 'url' : $('#shippingCountrydefault').attr('data-url') 195 }; 196 $.ajax({ 197 type: 'get', 198 url: selectedData.url, 199 data: selectedData, 200 success:function(response){ 201 if(response.success == false){ 202 return; 203 } else { 204 var dataObj = { 205 'country': response.country, 206 'currency': response.currency, 207 'language': response.language, 208 'url' : response.url, 209 'action': $('.page').data('action'), 210 'queryString': $('.page').data('querystring'), 211 'redirect' : response.redirect, 212 'successMsg' : response.successMsg, 213 'changeAddressAjax' : true 214 }; 215 changeAjaxCall(dataObj); 216 } 217 } 218 }); 219 }); 220 $('body').on('click','.esw-country-selector .current-country', function (e){ 221 e.stopPropagation(); 222 var siblingSelector = $(this).siblings('.selector'); 223 siblingSelector.toggleClass('active'); 224 $(this).toggleClass('selector-active'); 225 $('.esw-country-selector .selector').not(siblingSelector).removeClass('active'); 226 $('.esw-country-selector .current-country').not(this).removeClass('selector-active'); 227 }); 228 229 $(document).on('click',function(e){ 230 $('.esw-country-selector .selector').removeClass('active'); 231 $('.esw-country-selector .current-country').removeClass('selector-active'); 232 }); 233 $('body').on('product:afterAttributeSelect', function (e, response) { 234 if (response.data.product.isProductRestricted) { 235 $('.modal.show').find('button.update-cart-product-global').addClass('d-none'); 236 $('.modal.show').find('.price').addClass('d-none'); 237 $('.modal.show').find('.product-not-available-msg').removeClass('d-none'); 238 } else { 239 $('.modal.show').find('button.update-cart-product-global').removeClass('d-none'); 240 $('.modal.show').find('.price').removeClass('d-none'); 241 $('.modal.show').find('.product-not-available-msg').addClass('d-none'); 242 } 243 }); 244}; 245 246/* 247 * applies rounding method as per the rounding model. 248 */ 249function applyRoundingMethod(price, model, roundingModel, isFractionalPart) { 250 var roundingMethod = model.split(/(\d+)/)[0]; 251 var roundedPrice; 252 var fractionalPrice; 253 if (roundingMethod.toLowerCase() == 'none') { 254 if (isFractionalPart) { 255 fractionalPrice = (price / 100) % 1; 256 return fractionalPrice; 257 } 258 return price; 259 } 260 var roundingTarget = model.split(/(\d+)/)[1]; 261 var rTLength = roundingTarget.length; 262 263 if (isFractionalPart) { 264 // Truncate or make roundingTarget to only two digits for fractional part. 265 roundingTarget = rTLength === 1 ? roundingTarget + '0' : roundingTarget.substring(0, 2); 266 rTLength = roundingTarget.length; 267 } 268 269 if (roundingMethod.toLowerCase() == 'fixed') { 270 var otherPart = price % Math.pow(10, rTLength); 271 var priceWithoutOtherPart = price - otherPart; 272 273 // Logic for fixed rounding method. 274 if (roundingModel.direction.toLowerCase() == 'up') { 275 roundedPrice = (roundingTarget < otherPart ? priceWithoutOtherPart + 1 * Math.pow(10, rTLength) : priceWithoutOtherPart) + Number(roundingTarget); 276 } else if (roundingModel.direction.toLowerCase() == 'down') { 277 roundedPrice = (roundingTarget > otherPart ? priceWithoutOtherPart - 1 * Math.pow(10, rTLength) : priceWithoutOtherPart) + Number(roundingTarget); 278 roundedPrice = roundedPrice < 0 && !isFractionalPart ? price : roundedPrice; 279 } else if (roundingModel.direction.toLowerCase() == 'nearest') { 280 var roundedUp = (roundingTarget < otherPart ? priceWithoutOtherPart + 1 * Math.pow(10, rTLength) : priceWithoutOtherPart) + Number(roundingTarget); 281 var roundedDown = (roundingTarget > otherPart ? priceWithoutOtherPart - 1 * Math.pow(10, rTLength) : priceWithoutOtherPart) + Number(roundingTarget); 282 roundedDown = roundedDown < 0 && !isFractionalPart ? price : roundedDown; 283 roundedPrice = Math.abs(roundedUp - price) >= Math.abs(price - roundedDown) ? roundedDown : roundedUp; 284 } 285 } else { 286 // Logic for multiple rounding method. 287 // eslint-disable-next-line no-lonely-if 288 if (roundingModel.direction.toLowerCase() == 'up') {
289 roundedPrice = Math.ceil(price / roundingTarget) * roundingTarget; 290 } else if (roundingModel.direction.toLowerCase() == 'down') { 291 roundedPrice = Math.floor(price / roundingTarget) * roundingTarget; 292 } else if (roundingModel.direction == 'nearest') { 293 // eslint-disable-next-line no-unused-expressions, no-sequences 294 roundedUp = Math.ceil(price / roundingTarget) * roundingTarget, 295 roundedDown = Math.floor(price / roundingTarget) * roundingTarget, 296 roundedPrice = Math.abs(roundedUp - price) >= Math.abs(price - roundedDown) ? roundedDown : roundedUp; 297 } 298 } 299 if (isFractionalPart) { 300 return roundedPrice / Math.pow(10, rTLength); 301 } 302 return roundedPrice; 303} 304 305// function to apply rounding on the content static price conversion 306function applyRoundingModel(price) { 307 var roundingModel = window.SitePreferences.ESW_SELECTED_ROUNDING ? JSON.parse(window.SitePreferences.ESW_SELECTED_ROUNDING) : false; 308 var roundedWholeNumber = 0; 309 var roundedPrice = 0; 310 if (!roundingModel || price === 0) { 311 return price; 312 } 313 314 if (roundingModel) { 315 // eslint-disable-next-line no-param-reassign 316 price = price.toFixed(2); 317 318 var wholeNumber = parseInt(price, 10); 319 var model = roundingModel.model.split('.')[0]; 320 321 var fractionalPart = Math.round((price % 1) * 100); 322 var fractionalModel = roundingModel.model.split('.')[1]; 323 324 // First, Apply rounding on the fractional part. 325 var roundedFractionalPart = applyRoundingMethod(fractionalPart, fractionalModel, roundingModel, true); 326 327 328 // Update the whole number based on the fractional part rounding. 329 wholeNumber = parseInt(wholeNumber + roundedFractionalPart, 10); 330 roundedFractionalPart = (wholeNumber + roundedFractionalPart) % 1; 331 332 // then, Apply rounding on the whole number. 333 roundedWholeNumber = applyRoundingMethod(wholeNumber, model, roundingModel, false); 334 335 roundedPrice = roundedWholeNumber + roundedFractionalPart; 336 337 return roundingModel.currencyExponent === 0 ? parseInt(roundedPrice, 10) : roundedPrice.toFixed(roundingModel.currencyExponent); 338 } 339 340 return price; 341} 342 343// function to convert static prices on the page. 344function convertPrice() { 345 var priceElements = $('.esw-price:not(.esw-price-converted)'); 346 var selectedCurrencySymbol = window.SitePreferences.ESW_CURRENCY_SYMBOL; 347 348 // Update price elements 349 if (!window.SitePreferences.ESW_FIXED_COUNTRY) { 350 var selectedCountryAdjustment = window.SitePreferences.ESW_SELECTED_COUNTRY_ADJUSTMENT ? JSON.parse(window.SitePreferences.ESW_SELECTED_COUNTRY_ADJUSTMENT) : ''; 351 var selectedFxRate = window.SitePreferences.ESW_SELECTED_FXRATE ? JSON.parse(window.SitePreferences.ESW_SELECTED_FXRATE) : ''; 352 var enableRounding = window.SitePreferences.ESW_ENABLE_ROUNDING; 353 if (!selectedFxRate) { 354 return false; 355 } 356 357 priceElements.each(function () { 358 var element = $(this); 359 var disableRounding = (element.attr('data-disable-rounding') && element.attr('data-disable-rounding') == 'true') ? true : false; 360 var disableAdjustment = (element.attr('data-disable-adjustments') && element.attr('data-disable-adjustments') == 'true') ? true : false; 361 var eswPrice = Number($.trim(element.text()).replace(/[^0-9\.-]+/g, '')); 362 if (selectedCountryAdjustment && !disableAdjustment) { 363 // applying adjustment 364 eswPrice += Number((selectedCountryAdjustment.retailerAdjustments.priceUpliftPercentage / 100 * eswPrice)); 365 // applying duty 366 eswPrice += Number((selectedCountryAdjustment.estimatedRates.dutyPercentage / 100 * eswPrice)); 367 // applying tax 368 eswPrice += Number((selectedCountryAdjustment.estimatedRates.taxPercentage / 100 * eswPrice)); 369 } 370 eswPrice = Number((eswPrice * selectedFxRate.rate).toFixed(2)); 371 if (!disableRounding && enableRounding) { 372 eswPrice = applyRoundingModel(eswPrice); 373 } 374 element.text(selectedCurrencySymbol + eswPrice); 375 element.addClass('esw-price-converted'); 376 }); 377 } else { 378 priceElements.each(function () { 379 var element = $(this); 380 var eswPrice = Number($.trim(element.text()).replace(/[^0-9\.-]+/g, '')); 381 element.text(selectedCurrencySymbol + eswPrice); 382 element.addClass('esw-price-converted'); 383 }); 384 } 385} 386 387$(document).ready(function () { 388 updateCountryList(); 389 if($('.eswModal').length>0){
390 //Logic to enable/disable welcome matt currency dropdowns 391 var $selectedCurrency = $('#selected-currency'); 392 setDefaultCurrency($selectedCurrency); 393 } 394 if (typeof window.SitePreferences !== 'undefined' && window.SitePreferences.ESW_ENABLE_PRICECONVERSION) { 395 convertPrice(); 396 $(document).ajaxComplete(function (event, request, settings) { 397 convertPrice(); 398 }); 399 } 400 $('body').on('click', '.submit-customer', function (e) { 401 if ( $('#email-guest').val() && $('#email-guest').val().indexOf('@') >0) { 402 $( ".submit-customer" ).prop( "disabled", true ); 403 } 404 }); 405});
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.