1/** 2 * Module to add a shipping rates calculator to cart page. 3 * 4 * Copyright (c) 2011-2016 Caroline Schnapp (11heavens.com) 5 * Dual licensed under the MIT and GPL licenses: 6 * http://www.opensource.org/licenses/mit-license.php 7 * http://www.gnu.org/licenses/gpl.html 8 * 9 */ 10/** 11 * Module to add a shipping rates calculator to cart page. 12 * 13 * Copyright (c) 2011-2016 Caroline Schnapp (11heavens.com) 14 * Dual licensed under the MIT and GPL licenses: 15 * http://www.opensource.org/licenses/mit-license.php 16 * http://www.gnu.org/licenses/gpl.html 17 * 18 */ 19if(typeof Countries==='object'){Countries.updateProvinceLabel=function(country,provinceLabelElement){if(typeof country==='string'&&Countries[country]&&Countries[country].provinces){if(typeof provinceLabelElement!=='object'){provinceLabelElement=document.getElementById('address_province_label');if(provinceLabelElement===null)return} 20provinceLabelElement.innerHTML=Countries[country].label;var provinceContainer=jQuery(provinceLabelElement).parent();var provinceSelect=provinceContainer.find('select');provinceContainer.find('.custom-style-select-box-inner').html(Countries[country].provinces[0])}}} 21if(typeof Shopify.Cart==='undefined'){Shopify.Cart={}} 22Shopify.Cart.ShippingCalculator=(function(){var _config={submitButton:'Calculate shipping',submitButtonDisabled:'Calculating...',templateId:'shipping-calculator-response-template',wrapperId:'wrapper-response',customerIsLoggedIn:!1,moneyFormat:'${{amount}}'};var _render=function(response){var template=jQuery('#'+_config.templateId);var wrapper=jQuery('#'+_config.wrapperId);if(template.length&&wrapper.length){_.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var myTemplate=_.template(jQuery.trim(template.text()));var compiled=myTemplate(response);jQuery(compiled).appendTo(wrapper);if(typeof Currency!=='undefined'&&typeof Currency.convertAll==='function'){var newCurrency='';var shopCurrency=$('body').data('shop-currency');if($(window).width()>=798){var $currencySelector=$(".top_bar [data-currency-converter]")}else{var $currencySelector=$("#mobile_menu [data-currency-converter]")} 23if($currencySelector.length){newCurrency=$currencySelector.val()} 24if(newCurrency!==''){Currency.convertAll(shopCurrency,newCurrency,'#wrapper-response span.money, #estimated-shipping span.money',Shopify.theme_settings.currency_format);if(shopCurrency===newCurrency){applyCurrencyFormatSettings()}}else if(shopCurrency!==Shopify.currency.active){Currency.convertAll(shopCurrency,Shopify.currency.active,'#wrapper-response span.money, #estimated-shipping span.money',Shopify.theme_settings.currency_format) 25applyCurrencyFormatSettings()}else{applyCurrencyFormatSettings()}}}};var _enableButtons=function(){jQuery('.get-rates').removeAttr('disabled').removeClass('disabled').val(_config.submitButton)};var _disableButtons=function(){jQuery('.get-rates').val(_config.submitButtonDisabled).attr('disabled','disabled').addClass('disabled')};var _getCartShippingRatesForDestination=function(shippingAddress){var params={type:'POST',url:'/cart/prepare_shipping_rates',data:jQuery.param({'shipping_address':shippingAddress}),success:_pollForCartShippingRatesForDestination(shippingAddress),error:_onError} 26jQuery.ajax(params)};var _pollForCartShippingRatesForDestination=function(shippingAddress){var poller=function(){jQuery.ajax('/cart/async_shipping_rates',{dataType:'json',success:function(response,textStatus,xhr){if(xhr.status===200){_onCartShippingRatesUpdate(response.shipping_rates,shippingAddress)}else{setTimeout(poller,500)}},error:_onError})} 27return poller};var _fullMessagesFromErrors=function(errors){var fullMessages=[];jQuery.each(errors,function(attribute,messages){jQuery.each(messages,function(index,message){fullMessages.push(attribute+' '+message)})});return fullMessages};var _onError=function(XMLHttpRequest,textStatus){jQuery('#estimated-shipping').hide();jQuery('#estimated-shipping em').empty();_enableButtons();var feedback='';var data=eval('('+XMLHttpRequest.responseText+')');if(!!data.message){feedback=data.message+'('+data.status+'): '+data.description}else{feedback='Error : '+_fullMessagesFromErrors(data).join('; ')+'.'} 28if(feedback==='Error : country is not supported.')feedback='We do not ship to this destination.';_render({rates:[],errorFeedback:feedback,success:!1});jQuery('#'+_config.wrapperId).show()};var _onCartShippingRatesUpdate=function(rates,shipping_address){_enableButtons();var readable_address='';if(shipping_address.zip)readable_address+=shipping_address.zip+', ';if(shipping_address.province)readable_address+=shipping_address.province+', ';readable_address+=shipping_address.country;if(rates.length){if(rates[0].price=='0.00'){jQuery('#estimated-shipping em').html('FREE')}else{jQuery('#estimated-shipping em').html(_formatRate(rates[0].price))} 29for(var i=0;i<rates.length;i++){if(Shopify.currency.active=="JPY"){rates[i].price=rates[i].price*100} 30rates[i].price=_formatRate(rates[i].price)}} 31_render({rates:rates,address:readable_address,success:!0});jQuery('#'+_config.wrapperId+', #estimated-shipping').fadeIn()};
31var _formatRate=function(cents){if(typeof Shopify.formatMoney==='function'){if(Shopify.currency.active=="JPY"){cents=cents*100} 32return Shopify.formatMoney(cents,_config.moneyFormat)} 33if(typeof cents=='string'){cents=cents.replace('.','')} 34var value='';var placeholderRegex=/\{\{\s*(\w+)\s*\}\}/;var formatString=_config.moneyFormat;function defaultOption(opt,def){return(typeof opt=='undefined'?def:opt)} 35function formatWithDelimiters(number,precision,thousands,decimal){precision=defaultOption(precision,2);thousands=defaultOption(thousands,',');decimal=defaultOption(decimal,'.');if(isNaN(number)||number==null){return 0} 36number=(number/100.0).toFixed(precision);var parts=number.split('.'),dollars=parts[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g,'$1'+thousands),cents=parts[1]?(decimal+parts[1]):'';return dollars+cents} 37switch(formatString.match(placeholderRegex)[1]){case 'amount':value=formatWithDelimiters(cents,2);break;case 'amount_no_decimals':value=formatWithDelimiters(cents,0);break;case 'amount_with_comma_separator':value=formatWithDelimiters(cents,2,'.',',');break;case 'amount_no_decimals_with_comma_separator':value=formatWithDelimiters(cents,0,'.',',');break} 38return formatString.replace(placeholderRegex,value)};_init=function(){new Shopify.CountryProvinceSelector('address_country','address_province',{hideElement:'address_province_container'});var countriesSelect=jQuery('#address_country');var addressProvinceLabelEl=jQuery('#address_province_label').get(0);if(typeof Countries!=='undefined'){Countries.updateProvinceLabel(countriesSelect.val(),addressProvinceLabelEl);countriesSelect.change(function(){Countries.updateProvinceLabel(countriesSelect.val(),addressProvinceLabelEl)})} 39jQuery('.get-rates').click(function(){_disableButtons();jQuery('#'+_config.wrapperId).empty().hide();var shippingAddress={};shippingAddress.zip=jQuery('#address_zip').val()||'';shippingAddress.country=jQuery('#address_country').val()||'';shippingAddress.province=jQuery('#address_province').val()||'';_getCartShippingRatesForDestination(shippingAddress)});if(_config.customerIsLoggedIn){jQuery('.get-rates:eq(0)').trigger('click')}};return{show:function(params){params=params||{};jQuery.extend(_config,params);jQuery(function(){_init()})},getConfig:function(){return _config},formatRate:function(cents){return _formatRate(cents)}}})()
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.