Curry - Currency Conversion DDM


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

v0.8.3

Project Update

29th of August 2017
Curry has been updated to v0.8.3:
  • The yql api has become very unstable over the last few days and as a result Curry has now been rebased and is using the fixer.io api.
  • Tested with the latest jQuery version v3.2.1.

Curry uses fixer.io to fetch raw currencies and currently only supports INR, EUR, CAD, GBP, ILS.
Version 1.0.0 is coming soon will include all currencies fixer.io supports and much more.
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 Fixer.io.
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 uses an external service and that service is not 100% reliable.
Please read more about it at Fixer.io if you have a high traffic site or need your data to be available with guaranteed up time.

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

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/3.2.1/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

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

Curry was developed by NetYou.