Guest User

Untitled

a guest
Nov 23rd, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. class Currency {
  2.  
  3. constructor() {
  4. this.initCurrency();
  5. }
  6.  
  7. static init() {
  8. return new Currency();
  9. }
  10.  
  11. initCurrency() {
  12. let $currencyList = $('#currencyList');
  13.  
  14. if (!$currencyList.length) {
  15. return false;
  16. }
  17.  
  18. this.getCurrency('USD', 'RUB', '#curUSD');
  19. this.getCurrency('EUR', 'RUB', '#curEUR');
  20. this.getCurrency('GBP', 'RUB', '#curUK');
  21. }
  22.  
  23. getCurrency(from, to, selector) {
  24. $.ajax({
  25. url: `//currency-api.appspot.com/api/${from}/${to}.jsonp`,
  26. dataType: "jsonp",
  27. data: {amount: '1.00'},
  28. async: false,
  29. success: $.proxy(function(res) {
  30. if (res.success) {
  31. this.currencyValue(selector, res.rate);
  32. }
  33. }, this)
  34. });
  35. }
  36.  
  37. currencyValue(selector, value) {
  38. let cur = parseFloat(value).toFixed(2);
  39. $(selector).text(cur);
  40. }
  41.  
  42. }
Add Comment
Please, Sign In to add comment