Curry - Currency Conversion DDM


Curry is a self contained, (almost) self generated currency converter for many different currencies.

v0.8.1

Project Update

Curry has been updated to v0.8.1:
  • Added support for comma based prices.
    Curry now supports commas in the initial price field. €184,33 is valid.

  • Curry uses yql to fetch raw currencies from yahoo and currently only supports INR, EUR, CAD, GBP, ILS.
    In the mean time a suggested alternative is a custom list or to use openexchangerates.org.

Basic setup

<div id="my-element"></div>
<span class="price">$100</span>
$(function(){ // document ready alias
    $('#my-element').curry(); // init curry
});
Price: $100

Options

@stringtarget

Default is set up as .price

Sets which element you want the currency conversion to take place on.

@booleanchange

If you want Curry to handle the currency change, set this to true.

@stringbase

Curry uses USD (US Dollars) as the base for it's conversion.
Change this option if you want the base to be calculated according to another currency (must be in the currency list).

@objectsymbols

You can add your own symbols to this list or overwrite the existing ones.
Curry will match up the currency key (GBP = £) with your symbol.

@objectcustomCurrency

By default Curry uses the currency conversion figures found at Yahoo finance.
Curry uses yql and you can see a live example of the exact code here.
You can supply your own currency rates via an object where the key is the currency name and the value a number to use for the conversion.
Curry can also be used interchangeably with openexchangerates.org.

var options = {
    target: '.price',
    change: false,
    base:   'USD',
    symbols: {
        'ILS' : '₪'
    },
    customCurrency: {
        'USD': 1,
        'GBP': 0.67,
        'EUR': 0.42,
        ...
    }
$(function(){ // document ready alias
    $('#my-element').curry( options ); // init custom options
});
Price: $100

Disclaimer

Curry is based on the Yahoo finance API and as such is only as reliable as it's source.
Curry uses an extrnal service and that service has data usage limits, please read more about it if you have a high traffic site.

You are reponsible for notifying anybody who uses Curry that any calculations or conversion are for informational purposes only.
By using the Curry jQuery plugin you agree that the developer of Curry is not responsible or liable for any miss information or issues resulting from the use of the Curry jQuery plugin.

Setup

Just like any other jQuery plugin, the javascript goes just before the closing body tag and after a jQuery library call.
The following code simply generates the Curry ddm which by default targets a .price class, look to the right.


<div class="my-future-ddm"></div>
<div><span class="price">$200</span></div>

...

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="curry.js"></script>

<script>
$(function(){ // document ready
    $('.my-future-ddm').curry(); // startup curry
});
</script>

</body>
</html>
Price: $200

Interaction

You can override Currys conversion event by setting change to false.

This can be achived with the following code:

$(function(){ // document ready
    $('.my-future-ddm').curry({ change: false }).change(function(){

        var selected = $(this).find(':selected'), // get selected currency
            rate = selected.data('rate'), // get currency rate
            currency = selected.val(); // get currency name

        console.log( currency, rate );

    });
});

Changing targets

Curry can target any valid jQuery selector.
Simply use target and set it to point to your custom selector:

$(function(){ // document ready
    $('.my-future-ddm').curry({
        // Target is set to '.price' by default but can use any valid jQuery selctor
        target: '.hproduct .price'
    });
});
Product Price: $2.99

Adding custom symbols

The default symbols that come with Curry are $ (USD), £ (GBP), € (EUR), ¥ (JPY).

You can replace these or add more by adding a setting called symbols with a hash map value.
For correct conversion consider using html entities.

$(function(){
    $('.my-future-ddm').curry({
        symbols: {
            'ILS' : '₪', // Add Shekel currency symbol. ( HTML entity code &#8362; )
            'GBP' : '₤'  // Replace GBP sign. ( HTML entity code &#8356; )
        }
    });
});
Product Price: $2.99

Adding custom curency values

If you don't want to use curry's currency rates you can supply your own currency rates object.

Keep in mind that if you set yor rates according to another base or if USD is not included. You must set the base manually using the base property:

$(function(){
    $('.my-future-ddm').curry({
        base:   'EUR',
        customCurrency: {
            'EUR': 1,
            'GBP': 0.8013,
            'USD': 1.27
        }
    });
});
Price: €200

comments powered by Disqus

© 2013. Curry is distributed under the MIT or GPL license.

Curry was developed by NetYou.