Advertisement
Guest User

Untitled

a guest
Sep 24th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. <script>
  3. /*
  4. PART ONE
  5. In which we READ the cookie
  6. and activate the corresponding flag
  7. */
  8. // Cookie reader function
  9. function getCookie(cname) {
  10.     var name = cname + "=";
  11.     var ca = document.cookie.split(';');
  12.     for(var i=0; i<ca.length; i++) {
  13.         var c = ca[i];
  14.         while (c.charAt(0)==' ') c = c.substring(1);
  15.         if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
  16.     }
  17.     return "";
  18. }
  19. // If our cookie has value
  20. if ( getCookie('FClocale') !== ""){
  21.     // Let's distinguish the link whose 'title' attribute
  22.     // matches the value of the cookie
  23.    
  24.     // Read the cookie first
  25.     var recordedLocale = getCookie('FClocale');
  26.     // Select our locale-changing links
  27.     var availableLocales = document.querySelectorAll('a.currency-option');
  28.     // And check them against the cookie value
  29.     $(availableLocales).each(function(){
  30.         // If the 'title' matches the value of the cookie…
  31.         if ($(this).attr('title') == recordedLocale){
  32.             // …make all flags equally inactive…
  33.             $('.currency-option-active').removeClass('currency-option-active');
  34.             // …and make the matching one active…
  35.             $(this).addClass('currency-option-active');
  36.         }
  37.     });
  38. }
  39. /*
  40.  
  41. PART TWO
  42. In which we WRITE the cookie
  43. based on which flag was clicked
  44. */
  45.     FChostname = window.location.hostname;
  46.     FCactiveLocale = "USD";
  47.     FCcookieName = "FClocale";
  48.     FCd = new Date();
  49.     FCmilliseconds = 365*12*60*60*1000;
  50.     FCd.setTime(FCd.getTime()+FCmilliseconds); // 0.5 year ahead
  51.     FCexpires ="expires="+FCd.toGMTString(); // expire the cookie in 0.5 year
  52.    
  53.     function FCsetCookie(FCL){
  54.         document.cookie = FCcookieName+"="+FCL+";"+FCexpires+";path=/;domain="+FChostname;
  55.     }
  56.  
  57.     document.getElementById('usd').onclick = function(){
  58.         FCsetCookie($(this).attr('title'));
  59.         $('.currency-option-active').removeClass('currency-option-active');  
  60.         $(this).addClass('currency-option-active');
  61.         FC.client.request('https://'+FC.settings.storedomain+'/cart?locale=en_US')
  62.         .done(function(data){
  63.             console.log(data.locale_info.int_curr_symbol);
  64.            
  65.         });
  66.     };
  67.     document.getElementById('mxn').onclick = function(){
  68.         FCsetCookie($(this).attr('title'));
  69.         $('.currency-option-active').removeClass('currency-option-active');  
  70.         $(this).addClass('currency-option-active');
  71.         FC.client.request('https://'+FC.settings.storedomain+'/cart?locale=es_MX')
  72.         .done(function(data){
  73.             console.log(data.locale_info.int_curr_symbol);
  74.         });
  75.     };
  76.     document.getElementById('gbp').onclick = function(){
  77.         FCsetCookie($(this).attr('title'));
  78.         $('.currency-option-active').removeClass('currency-option-active');  
  79.         $(this).addClass('currency-option-active');
  80.         FC.client.request('https://'+FC.settings.storedomain+'/cart?locale=en_GB')
  81.         .done(function(data){
  82.             console.log(data.locale_info.int_curr_symbol);
  83.         });
  84.     };
  85. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement