├── README.md ├── convert.php ├── demo ├── index.html ├── scripts │ └── modernizr-1.7.min.js └── style.css ├── jquery.currency.js └── license.txt /README.md: -------------------------------------------------------------------------------- 1 | #jQuery Currency 2 | 3 | Simple, unobtrusive currency converting and formatting 4 | 5 | ##Requirements 6 | 7 | To use jQuery Currency you will need the following: 8 | 9 | * jQuery Version 1.5 - Version 2.1.3 10 | * PHP to perform foreign exchange conversions 11 | 12 | ##Example Usage 13 | 14 | Format an element on a page, using Default Settings 15 | 16 | 21 | 22 | For more examples [see the demo](http://coderspress.com/github/demos/jquery-currency/demo/index.html). 23 | 24 | ## Default Settings 25 | 26 | The following list outlines the settings and their defualt values: 27 | 28 | $("#number").currency({ 29 | region: "USD", // The 3 digit ISO code you want to display your currency in 30 | thousands: ",", // Thousands separator 31 | decimal: ".", // Decimal separator 32 | decimals: 2, // How many decimals to show 33 | hidePrefix: false, // Hide any prefix 34 | hidePostfix: false, // Hide any postfix 35 | convertFrom: "", // If converting, the 3 digit ISO code you want to convert from, 36 | convertLoading: "(Converting...)", // Loading message appended to values while converting 37 | convertLocation: "convert.php" // Location of convert.php file 38 | }); 39 | -------------------------------------------------------------------------------- /convert.php: -------------------------------------------------------------------------------- 1 | ",$get); 7 | $get = explode("",$get[1]); 8 | $converted_amount = preg_replace("/[^0-9\.]/", null, $get[0]); 9 | 10 | // If Same Currency Checker - returns $from 11 | if (is_numeric($converted_amount)) { 12 | echo $converted_amount; 13 | } else { 14 | echo $amount; 15 | } 16 | ?> -------------------------------------------------------------------------------- /demo/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | jQuery Currency - Simple, unobtrusive currency converting and formatting 7 | 8 | 9 | 10 | 11 | 12 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 |
24 | 25 |

jQuery Currency Demo

26 |

Simple, unobtrusive currency converting and formatting.

27 | 28 |
29 | 30 |
31 | 32 |

$("#basic").currency();

33 |

123456.34098 becomes 123456.34098

34 | 35 |

$("#input").currency();

36 |

becomes

37 | 38 |

$("#advanced").currency({ region: "GBP", thousands: ",", decimal: ",", decimals: 3 });

39 |

123456.34098 becomes 123456.34098

40 | 41 |

$(".multiple").currency();

42 |

123456.34098 becomes 123456.34098

43 |

987654.321 becomes 987654.321

44 |

-34.57 becomes -34.57

45 | 46 |

$("#convert").currency({ region: "GBP", convertFrom: "EUR" });

47 |

12456.89 becomes 12456.89

48 |

Note conversion requires the use of a PHP file (sample attached)

49 | 50 |

51 |

52 | 53 | 54 | 58 | 61 |
62 |

63 | 64 |
65 | 66 | 70 | 71 |
72 | 73 | 74 | 75 | 76 | 87 | 88 | Fork me on GitHub 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /demo/scripts/modernizr-1.7.min.js: -------------------------------------------------------------------------------- 1 | // (old file) Modernizr v1.7 www.modernizr.com 2 | window.Modernizr=function(a,b,c){function G(){e.input=function(a){for(var b=0,c=a.length;b7)},r.history=function(){return !!(a.history&&history.pushState)},r.draganddrop=function(){return x("dragstart")&&x("drop")},r.websockets=function(){return"WebSocket"in a},r.rgba=function(){A("background-color:rgba(150,255,150,.5)");return D(k.backgroundColor,"rgba")},r.hsla=function(){A("background-color:hsla(120,40%,100%,.5)");return D(k.backgroundColor,"rgba")||D(k.backgroundColor,"hsla")},r.multiplebgs=function(){A("background:url(//:),url(//:),red url(//:)");return(new RegExp("(url\\s*\\(.*?){3}")).test(k.background)},r.backgroundsize=function(){return F("backgroundSize")},r.borderimage=function(){return F("borderImage")},r.borderradius=function(){return F("borderRadius","",function(a){return D(a,"orderRadius")})},r.boxshadow=function(){return F("boxShadow")},r.textshadow=function(){return b.createElement("div").style.textShadow===""},r.opacity=function(){B("opacity:.55");return/^0.55$/.test(k.opacity)},r.cssanimations=function(){return F("animationName")},r.csscolumns=function(){return F("columnCount")},r.cssgradients=function(){var a="background-image:",b="gradient(linear,left top,right bottom,from(#9f9),to(white));",c="linear-gradient(left top,#9f9, white);";A((a+o.join(b+a)+o.join(c+a)).slice(0,-a.length));return D(k.backgroundImage,"gradient")},r.cssreflections=function(){return F("boxReflect")},r.csstransforms=function(){return!!E(["transformProperty","WebkitTransform","MozTransform","OTransform","msTransform"])},r.csstransforms3d=function(){var a=!!E(["perspectiveProperty","WebkitPerspective","MozPerspective","OPerspective","msPerspective"]);a&&"webkitPerspective"in g.style&&(a=w("@media ("+o.join("transform-3d),(")+"modernizr)"));return a},r.csstransitions=function(){return F("transitionProperty")},r.fontface=function(){var a,c,d=h||g,e=b.createElement("style"),f=b.implementation||{hasFeature:function(){return!1}};e.type="text/css",d.insertBefore(e,d.firstChild),a=e.sheet||e.styleSheet;var i=f.hasFeature("CSS2","")?function(b){if(!a||!b)return!1;var c=!1;try{a.insertRule(b,0),c=/src/i.test(a.cssRules[0].cssText),a.deleteRule(a.cssRules.length-1)}catch(d){}return c}:function(b){if(!a||!b)return!1;a.cssText=b;return a.cssText.length!==0&&/src/i.test(a.cssText)&&a.cssText.replace(/\r+|\n+/g,"").indexOf(b.split(" ")[0])===0};c=i('@font-face { font-family: "font"; src: url(data:,); }'),d.removeChild(e);return c},r.video=function(){var a=b.createElement("video"),c=!!a.canPlayType;if(c){c=new Boolean(c),c.ogg=a.canPlayType('video/ogg; codecs="theora"');var d='video/mp4; codecs="avc1.42E01E';c.h264=a.canPlayType(d+'"')||a.canPlayType(d+', mp4a.40.2"'),c.webm=a.canPlayType('video/webm; codecs="vp8, vorbis"')}return c},r.audio=function(){var a=b.createElement("audio"),c=!!a.canPlayType;c&&(c=new Boolean(c),c.ogg=a.canPlayType('audio/ogg; codecs="vorbis"'),c.mp3=a.canPlayType("audio/mpeg;"),c.wav=a.canPlayType('audio/wav; codecs="1"'),c.m4a=a.canPlayType("audio/x-m4a;")||a.canPlayType("audio/aac;"));return c},r.localstorage=function(){try{return!!localStorage.getItem}catch(a){return!1}},r.sessionstorage=function(){try{return!!sessionStorage.getItem}catch(a){return!1}},r.webWorkers=function(){return!!a.Worker},r.applicationcache=function(){return!!a.applicationCache},r.svg=function(){return!!b.createElementNS&&!!b.createElementNS(q.svg,"svg").createSVGRect},r.inlinesvg=function(){var a=b.createElement("div");a.innerHTML="";return(a.firstChild&&a.firstChild.namespaceURI)==q.svg},r.smil=function(){return!!b.createElementNS&&/SVG/.test(n.call(b.createElementNS(q.svg,"animate")))},r.svgclippaths=function(){return!!b.createElementNS&&/SVG/.test(n.call(b.createElementNS(q.svg,"clipPath")))};for(var H in r)z(r,H)&&(v=H.toLowerCase(),e[v]=r[H](),u.push((e[v]?"":"no-")+v));e.input||G(),e.crosswindowmessaging=e.postmessage,e.historymanagement=e.history,e.addTest=function(a,b){a=a.toLowerCase();if(!e[a]){b=!!b(),g.className+=" "+(b?"":"no-")+a,e[a]=b;return e}},A(""),j=l=null,f&&a.attachEvent&&function(){var a=b.createElement("div");a.innerHTML="";return a.childNodes.length!==1}()&&function(a,b){function p(a,b){var c=-1,d=a.length,e,f=[];while(++c 3) { 182 | s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep); 183 | } 184 | 185 | if ((s[1] || '').length < prec) { 186 | s[1] = s[1] || ''; 187 | s[1] += new Array(prec - s[1].length + 1).join('0'); 188 | } 189 | return s.join(dec); 190 | }, 191 | isNumber: function (n) { 192 | return !isNaN(parseFloat(n)) && isFinite(n); 193 | } 194 | } 195 | 196 | if (methods[method]) { 197 | return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); 198 | } else if (typeof method === 'object' || !method) { 199 | return methods.init.apply(this, arguments); 200 | } else { 201 | $.error('Method "' + method + '" does not exist in currency plugin!'); 202 | } 203 | } 204 | 205 | $.fn.currency.defaults = { 206 | region: "USD", // The 3 digit ISO code you want to display your currency in 207 | thousands: ",", // Thousands separator 208 | decimal: ".", // Decimal separator 209 | decimals: 2, // How many decimals to show 210 | hidePrefix: false, // Hide any prefix 211 | hidePostfix: false, // Hide any postfix 212 | convertFrom: "", // If converting, the 3 digit ISO code you want to convert from, 213 | convertLoading: "(Converting...)", // Loading message appended to values while converting 214 | convertLocation: "convert.php" // Location of convert.php file 215 | } 216 | 217 | $.fn.currency.settings = {} 218 | 219 | })(jQuery); 220 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 sMarty @ http://coderspress.com 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | --------------------------------------------------------------------------------