diff options
Diffstat (limited to 'docs/index.js')
-rw-r--r-- | docs/index.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/docs/index.js b/docs/index.js index 23773e1bd..ea10bd6c3 100644 --- a/docs/index.js +++ b/docs/index.js @@ -1,5 +1,30 @@ var isMac = false +// fetchjson(url string, cb (err Error, d Object)->nil) +// +var fetchjson = ( + typeof window.fetch == 'function' ? ( + function _fetchjson(url, cb) { + return window.fetch(url) + .then(function(r) { return r.json() }) + .then(function(data) { cb(null, data) }) + .catch(cb) + } + ) : + function _fetchjson(url, cb) { + var r = new XMLHttpRequest() + r.addEventListener("load", function(){ + try { + cb(null, JSON.parse(r.responseText)) + } catch (err) { + cb(err) + } + }) + r.open("GET", url) + r.send() + } +) + ;(function(){ "use strict"; |