forked from carolineschnapp/currencies
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.currencies.min.js
22 lines (19 loc) · 7.75 KB
/
jquery.currencies.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
* Cookie plugin
*
* Copyright (c) 2006 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
jQuery.cookie=function(b,j,m){if(typeof j!="undefined"){m=m||{};if(j===null){j="";m.expires=-1}var e="";if(m.expires&&(typeof m.expires=="number"||m.expires.toUTCString)){var f;if(typeof m.expires=="number"){f=new Date();f.setTime(f.getTime()+(m.expires*24*60*60*1000))}else{f=m.expires}e="; expires="+f.toUTCString()}var l=m.path?"; path="+(m.path):"";var g=m.domain?"; domain="+(m.domain):"";var a=m.secure?"; secure":"";document.cookie=[b,"=",encodeURIComponent(j),e,l,g,a].join("")}else{var d=null;if(document.cookie&&document.cookie!=""){var k=document.cookie.split(";");for(var h=0;h<k.length;h++){var c=jQuery.trim(k[h]);if(c.substring(0,b.length+1)==(b+"=")){d=decodeURIComponent(c.substring(b.length+1));break}}}return d}};
/*
* Currency tools
*
* Copyright (c) 2012 Caroline Schnapp ([email protected])
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*
*/
if(typeof Currency==="undefined"){var Currency={}}Currency.cookie={configuration:{expires:365,path:"/",domain:window.location.hostname},name:"currency",write:function(a){jQuery.cookie(this.name,a,this.configuration)},read:function(){return jQuery.cookie(this.name)},destroy:function(){jQuery.cookie(this.name,null,this.configuration)}};Currency.money_with_currency_format={USD:"${{amount}} USD",EUR:"€{{amount}} EUR",GBP:"£{{amount}} GBP",CAD:"${{amount}} CAD",ARS:"${{amount_with_comma_separator}} ARS",AUD:"${{amount}} AUD",BBD:"${{amount}} Bds",BDT:"Tk {{amount}} BDT",BSD:"BS${{amount}} BSD",BHD:"{{amount}}0 BHD",BRL:"R$ {{amount_with_comma_separator}} BRL",BOB:"Bs{{amount_with_comma_separator}} BOB",BND:"${{amount}} BND",BGN:"{{amount}} лв BGN",MMK:"K{{amount}} MMK",KYD:"${{amount}} KYD",CLP:"${{amount_no_decimals}} CLP",CNY:"¥{{amount}} CNY",COP:"${{amount_with_comma_separator}} COP",CRC:"₡ {{amount_with_comma_separator}} CRC",HRK:"{{amount_with_comma_separator}} kn HRK",CZK:"{{amount_with_comma_separator}} Kč",DKK:"kr.{{amount_with_comma_separator}}",DOP:"RD$ {{amount_with_comma_separator}}",XCD:"EC${{amount}}",EGP:"LE {{amount}} EGP",XPF:"{{amount_no_decimals_with_space_separator}}} XPF",FJD:"FJ${{amount}}",GHS:"GH₵{{amount}}",GTQ:"{{amount}} GTQ",GYD:"${{amount}} GYD",GEL:"{{amount}} GEL",HKD:"HK${{amount}}",HUF:"{{amount_no_decimals_with_comma_separator}} Ft",ISK:"{{amount_no_decimals}} kr ISK",INR:"Rs.{{amount}}",IDR:"Rp {{amount_with_comma_separator}}",NIS:"{{amount}} NIS",JMD:"${{amount}} JMD",JPY:"¥{{amount_no_decimals}} JPY",JOD:"{{amount}}0 JOD",KZT:"{{amount}} KZT",KES:"KSh{{amount}}",KWD:"{{amount}}0 KWD",LVL:"Ls {{amount}} LVL",LTL:"{{amount}} Lt",MXN:"$ {{amount}} MXN",MYR:"RM{{amount}} MYR",MUR:"Rs {{amount}} MUR",MDL:"{{amount}} MDL",MAD:"Dh {{amount}} MAD",MNT:"{{amount_no_decimals}} MNT",MZN:"Mt {{amount}} MZN",ANG:"{{amount}} NAƒ",NZD:"${{amount}} NZD",NGN:"₦{{amount}} NGN",NOK:"kr {{amount_with_comma_separator}} NOK",OMR:"{{amount_with_comma_separator}} OMR",PKR:"Rs.{{amount}} PKR",PYG:"Gs. {{amount_no_decimals_with_comma_separator}} PYG",PEN:"S/. {{amount}} PEN",PHP:"₱{{amount}} PHP",PLN:"{{amount_with_comma_separator}} zl PLN",QAR:"QAR {{amount_with_comma_separator}}",RON:"{{amount_with_comma_separator}} lei RON",RUB:"руб{{amount_with_comma_separator}} RUB",SAR:"{{amount}} SAR",RSD:"{{amount}} RSD",SCR:"Rs {{amount}} SCR",SGD:"${{amount}} SGD",SYP:"S£{{amount}} SYP",ZAR:"R {{amount}} ZAR",KRW:"₩{{amount_no_decimals}} KRW",LKR:"Rs {{amount}} LKR",SEK:"{{amount_no_decimals}} kr SEK",CHF:"SFr. {{amount}} CHF",TWD:"${{amount}} TWD",THB:"{{amount}} ฿ THB",TZS:"{{amount}} TZS",TTD:"${{amount}} TTD",TRY:"{{amount}}TL",UAH:"₴{{amount}} UAH",AED:"Dhs. {{amount}} AED",UYU:"${{amount_with_comma_separator}} UYU",VEB:"Bs. {{amount_with_comma_separator}} VEB",VND:"{{amount_no_decimals_with_comma_separator}} VND",ZMK:"ZMK{{amount_no_decimals_with_comma_separator}}"};Currency.money_format={USD:"${{amount}}",EUR:"€{{amount}}",GBP:"£{{amount}}",CAD:"${{amount}}",ARS:"${{amount_with_comma_separator}}",AUD:"${{amount}}",BBD:"${{amount}}",BDT:"Tk {{amount}}",BSD:"BS${{amount}}",BHD:"{{amount}}0 BHD",BRL:"R$ {{amount_with_comma_separator}}",BOB:"Bs{{amount_with_comma_separator}}",BND:"${{amount}}",BGN:"{{amount}} лв",MMK:"K{{amount}}",KYD:"${{amount}}",CLP:"${{amount_no_decimals}}",CNY:"¥{{amount}}",COP:"${{amount_with_comma_separator}}",CRC:"₡ {{amount_with_comma_separator}}",HRK:"{{amount_with_comma_separator}} kn",CZK:"{{amount_with_comma_separator}} Kč",DKK:"{{amount_with_comma_separator}}",DOP:"RD$ {{amount_with_comma_separator}}",XCD:"${{amount}}",EGP:"LE {{amount}}",XPF:"{{amount_no_decimals_with_space_separator}}} XPF",FJD:"${{amount}}",GHS:"GH₵{{amount}}",GTQ:"{{amount}}",GYD:"${{amount}}",GEL:"{{amount}} GEL",HKD:"${{amount}}",HUF:"{{amount_no_decimals_with_comma_separator}}",ISK:"{{amount_no_decimals}} kr",INR:"{{amount}}",IDR:"{{amount_with_comma_separator}}",NIS:"{{amount}} NIS",JMD:"${{amount}}",JPY:"¥{{amount_no_decimals}}",JOD:"{{amount}}0 JD",KZT:"{{amount}} KZT",KES:"KSh{{amount}}",KWD:"{{amount}}0 KD",LVL:"Ls {{amount}}",LTL:"{{amount}} Lt",MXN:"$ {{amount}}",MYR:"RM{{amount}} MYR",MUR:"Rs {{amount}}",MDL:"{{amount}} MDL",MAD:"{{amount}} dh",MNT:"{{amount_no_decimals}} ₮",MZN:"{{amount}} Mt",ANG:"ƒ{{amount}}",NZD:"${{amount}}",NGN:"₦{{amount}}",NOK:"kr {{amount_with_comma_separator}}",OMR:"{{amount_with_comma_separator}} OMR",PKR:"Rs.{{amount}}",PYG:"Gs. {{amount_no_decimals_with_comma_separator}}",PEN:"S/. {{amount}}",PHP:"₱{{amount}}",PLN:"{{amount_with_comma_separator}} zl",QAR:"QAR {{amount_with_comma_separator}}",RON:"{{amount_with_comma_separator}} lei",RUB:"руб{{amount_with_comma_separator}}",SAR:"{{amount}} SR",RSD:"{{amount}} RSD",SCR:"Rs {{amount}}",SGD:"${{amount}}",SYP:"S£{{amount}}",ZAR:"R {{amount}}",KRW:"₩{{amount_no_decimals}}",LKR:"Rs {{amount}}",SEK:"{{amount_no_decimals}} kr",CHF:"SFr. {{amount}}",TWD:"${{amount}}",THB:"{{amount}} ฿",TZS:"{{amount}} TZS",TTD:"${{amount}}",TRY:"{{amount}}TL",UAH:"₴{{amount}}",AED:"Dhs. {{amount}}",UYU:"${{amount_with_comma_separator}}",VEB:"Bs. {{amount_with_comma_separator}}",VND:"{{amount_no_decimals_with_comma_separator}}₫",ZMK:"K{{amount_no_decimals_with_comma_separator}}"};Currency.formatMoney=function(b,e){var d="";var c=/\{\{\s*(\w+)\s*\}\}/;var a=(e||this.money_format);switch(a.match(c)[1]){case"amount":d=floatToString(b/100,2).replace(/(\d+)(\d{3}[\.,]?)/,"$1,$2");break;case"amount_no_decimals":d=floatToString(b/100,0).replace(/(\d+)(\d{3}[\.,]?)/,"$1,$2");break;case"amount_with_comma_separator":d=floatToString(b/100,2).replace(/\./,",").replace(/(\d+)(\d{3}[\.,]?)/,"$1.$2");break}return a.replace(c,d)};function floatToString(c,a){var b=c.toFixed(a).toString();if(b.match(/^\.\d+/)){return"0"+b}else{return b}}Currency.currentCurrency="";Currency.format="money_with_currency_format";Currency.convertAll=function(c,b,a,d){jQuery(a||".money").each(function(){if(jQuery(this).attr("data-currency")===b){return}if(jQuery(this).attr("data-currency-"+b)){jQuery(this).html(jQuery(this).attr("data-currency-"+b))}else{var e=0;var f=Currency[d||Currency.format][c]||"{{amount}}";var g=Currency[d||Currency.format][b]||"{{amount}}";if(f.indexOf("{{amount_no_decimals}}")!==-1){e=Currency.convert(parseInt(jQuery(this).html().replace(/[^0-9]/g,""),10)*100,c,b)}else{e=Currency.convert(parseInt(jQuery(this).html().replace(/[^0-9]/g,""),10),c,b)}var h=Currency.formatMoney(e,g);jQuery(this).html(h);jQuery(this).attr("data-currency-"+b,h)}jQuery(this).attr("data-currency",b)});this.currentCurrency=b;this.cookie.write(b)};