Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- /*
- PART ONE
- In which we READ the cookie
- and activate the corresponding flag
- */
- // Cookie reader function
- function getCookie(cname) {
- var name = cname + "=";
- var ca = document.cookie.split(';');
- for(var i=0; i<ca.length; i++) {
- var c = ca[i];
- while (c.charAt(0)==' ') c = c.substring(1);
- if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
- }
- return "";
- }
- // If our cookie has value
- if ( getCookie('FClocale') !== ""){
- // Let's distinguish the link whose 'title' attribute
- // matches the value of the cookie
- // Read the cookie first
- var recordedLocale = getCookie('FClocale');
- // Select our locale-changing links
- var availableLocales = document.querySelectorAll('a.currency-option');
- // And check them against the cookie value
- $(availableLocales).each(function(){
- // If the 'title' matches the value of the cookie…
- if ($(this).attr('title') == recordedLocale){
- // …make all flags equally inactive…
- $('.currency-option-active').removeClass('currency-option-active');
- // …and make the matching one active…
- $(this).addClass('currency-option-active');
- }
- });
- }
- /*
- PART TWO
- In which we WRITE the cookie
- based on which flag was clicked
- */
- FChostname = window.location.hostname;
- FCactiveLocale = "USD";
- FCcookieName = "FClocale";
- FCd = new Date();
- FCmilliseconds = 365*12*60*60*1000;
- FCd.setTime(FCd.getTime()+FCmilliseconds); // 0.5 year ahead
- FCexpires ="expires="+FCd.toGMTString(); // expire the cookie in 0.5 year
- function FCsetCookie(FCL){
- document.cookie = FCcookieName+"="+FCL+";"+FCexpires+";path=/;domain="+FChostname;
- }
- document.getElementById('usd').onclick = function(){
- FCsetCookie($(this).attr('title'));
- $('.currency-option-active').removeClass('currency-option-active');
- $(this).addClass('currency-option-active');
- FC.client.request('https://'+FC.settings.storedomain+'/cart?locale=en_US')
- .done(function(data){
- console.log(data.locale_info.int_curr_symbol);
- });
- };
- document.getElementById('mxn').onclick = function(){
- FCsetCookie($(this).attr('title'));
- $('.currency-option-active').removeClass('currency-option-active');
- $(this).addClass('currency-option-active');
- FC.client.request('https://'+FC.settings.storedomain+'/cart?locale=es_MX')
- .done(function(data){
- console.log(data.locale_info.int_curr_symbol);
- });
- };
- document.getElementById('gbp').onclick = function(){
- FCsetCookie($(this).attr('title'));
- $('.currency-option-active').removeClass('currency-option-active');
- $(this).addClass('currency-option-active');
- FC.client.request('https://'+FC.settings.storedomain+'/cart?locale=en_GB')
- .done(function(data){
- console.log(data.locale_info.int_curr_symbol);
- });
- };
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement