Skip to content

Instantly share code, notes, and snippets.

@hitautodestruct
Last active August 22, 2017 18:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save hitautodestruct/7e48a5dcab1d8c88f287 to your computer and use it in GitHub Desktop.
Save hitautodestruct/7e48a5dcab1d8c88f287 to your computer and use it in GitHub Desktop.
Allow usage of curry with js-cookie plugin
<script src="curry.min.js"></script>
<script src="js.cookie.js"></script>
<script>
var savedRate, savedCurrency;
var customCurrency = {
'USD': 1,
'COP': 2670,
};
var symbols = {
'USD' : '$ ',
'COP' : '$ ',
}
$(function(){
$('#price-selector').curry({
change: true,
base: savedCurrency,
symbols: symbols,
customCurrency: customCurrency
}).change(function(){
var selected = $(this).find(':selected'), // get selected currency
rate = selected.data('rate'), // get currency rate
currency = selected.val(); // get currency name
Cookies.remove('site_currency', { path: '' });
Cookies.remove('site_rate', { path: '' });
Cookies.set('site_currency', currency, { expires: 7, path: '' });
Cookies.set('site_rate', rate, { expires: 7, path: '' });
console.log( currency, rate );
});
});
$('document').ready(function() {
var CookieSet = Cookies.get('site_currency')
if (CookieSet == 'undefined') {
savedRate = 1;
savedCurrency = '$ USD';
console.log('CookieSet Empty. Set to '+savedCurrency);
}
else {
savedRate = Cookies.get('site_rate');
savedCurrency = Cookies.get('site_currency');
console.log('CookieSet readed from cookie. Saved Rate: '+savedRate+' Saved currency: '+savedCurrency);
}
$('#price-selector').val( savedCurrency );
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment