# HG changeset patch # User nanaya # Date 1466127775 -32400 # Node ID 13d740477326ec02661c6c7263482d3071a718db # Parent 1b8c5c3afaf502ca9362964e29e6bc62b101272e Split off fetcher functions diff -r 1b8c5c3afaf5 -r 13d740477326 index.html --- a/index.html Fri Jun 17 10:36:02 2016 +0900 +++ b/index.html Fri Jun 17 10:42:55 2016 +0900 @@ -128,6 +128,52 @@ lock(false); }; + var fetchFixer = function() { + if (rates.fixer !== undefined) { return; } + + lock(true); + locks.fixer = true; + + $.getJSON("https://api.fixer.io/latest", { base: "JPY", symbols: "IDR" }) + .done(function(data) { + rates.fixer = parseFloat(data.rates["IDR"]); + + displayResult(); + }) + .fail(function() { + $("#error").show(); + }) + .always(function() { + locks.fixer = false; + lock(false); + }); + }; + + var fetchBni = function() { + if (rates.bni !== undefined) { return; } + + lock(true); + locks.bni = true; + + $.get("bni-jpyidr.txt") + .done(function(data) { + if (data === "") { + rates.bni = 0; + } else { + rates.bni = parseFloat(data); + } + + displayResult(); + }) + .fail(function() { + $("#error").show(); + }) + .always(function() { + locks.bni = false; + lock(false); + }); + }; + var action = function(e) { e.preventDefault() $(".js").hide() @@ -136,47 +182,8 @@ if (x === NaN || x === undefined) { return false; }; - if (rates.fixer === undefined) { - lock(true); - locks.fixer = true; - - $.getJSON("https://api.fixer.io/latest", { base: "JPY", symbols: "IDR" }) - .done(function(data) { - rates.fixer = parseFloat(data.rates["IDR"]); - - displayResult(); - }) - .fail(function() { - $("#error").show(); - }) - .always(function() { - locks.fixer = false; - lock(false); - }); - }; - - if (rates.bni === undefined) { - lock(true); - locks.bni = true; - - $.get("bni-jpyidr.txt") - .done(function(data) { - if (data === "") { - rates.bni = 0; - } else { - rates.bni = parseFloat(data); - } - - displayResult(); - }) - .fail(function() { - $("#error").show(); - }) - .always(function() { - locks.bni = false; - lock(false); - }); - }; + fetchFixer(); + fetchBni(); displayResult(); };