Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Currency {
- constructor() {
- this.initCurrency();
- }
- static init() {
- return new Currency();
- }
- initCurrency() {
- let $currencyList = $('#currencyList');
- if (!$currencyList.length) {
- return false;
- }
- this.getCurrency('USD', 'RUB', '#curUSD');
- this.getCurrency('EUR', 'RUB', '#curEUR');
- this.getCurrency('GBP', 'RUB', '#curUK');
- }
- getCurrency(from, to, selector) {
- $.ajax({
- url: `//currency-api.appspot.com/api/${from}/${to}.jsonp`,
- dataType: "jsonp",
- data: {amount: '1.00'},
- async: false,
- success: $.proxy(function(res) {
- if (res.success) {
- this.currencyValue(selector, res.rate);
- }
- }, this)
- });
- }
- currencyValue(selector, value) {
- let cur = parseFloat(value).toFixed(2);
- $(selector).text(cur);
- }
- }
Add Comment
Please, Sign In to add comment