|
|
@ -1,4 +1,6 @@ |
|
|
|
/*!chibi 3.0.7, Copyright 2012-2016 Kyle Barrow, released under MIT license */ |
|
|
|
/*!chibi 3.0.7, Copyright 2012-2016 Kyle Barrow, released under MIT license */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// MODIFIED VERSION.
|
|
|
|
(function () { |
|
|
|
(function () { |
|
|
|
'use strict'; |
|
|
|
'use strict'; |
|
|
|
|
|
|
|
|
|
|
@ -6,7 +8,6 @@ |
|
|
|
loadedfn = [], |
|
|
|
loadedfn = [], |
|
|
|
domready = false, |
|
|
|
domready = false, |
|
|
|
pageloaded = false, |
|
|
|
pageloaded = false, |
|
|
|
jsonpcount = 0, |
|
|
|
|
|
|
|
d = document, |
|
|
|
d = document, |
|
|
|
w = window; |
|
|
|
w = window; |
|
|
|
|
|
|
|
|
|
|
@ -598,72 +599,22 @@ |
|
|
|
return cb; |
|
|
|
return cb; |
|
|
|
}; |
|
|
|
}; |
|
|
|
// Basic XHR 1, no file support. Shakes fist at IE
|
|
|
|
// Basic XHR 1, no file support. Shakes fist at IE
|
|
|
|
cb.ajax = function (url, method, callback, nocache, nojsonp) { |
|
|
|
cb.ajax = function (url, method, callback) { |
|
|
|
var xhr, |
|
|
|
var xhr, |
|
|
|
query = serializeData(nodes), |
|
|
|
query = serializeData(nodes), |
|
|
|
type = (method) ? method.toUpperCase() : 'GET', |
|
|
|
type = (method) ? method.toUpperCase() : 'GET', |
|
|
|
hostsearch = new RegExp('http[s]?://(.*?)/', 'gi'), |
|
|
|
timestamp = '_ts=' + (+new Date()); |
|
|
|
domain = hostsearch.exec(url), |
|
|
|
|
|
|
|
timestamp = '_ts=' + (+new Date()), |
|
|
|
if (query && (type === 'GET')) { |
|
|
|
head = d.getElementsByTagName('head')[0], |
|
|
|
|
|
|
|
jsonpcallback = 'chibi' + (+new Date()) + (jsonpcount += 1), |
|
|
|
|
|
|
|
script; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (query && (type === 'GET' || type === 'DELETE')) { |
|
|
|
|
|
|
|
url += (url.indexOf('?') === -1) ? '?' + query : '&' + query; |
|
|
|
url += (url.indexOf('?') === -1) ? '?' + query : '&' + query; |
|
|
|
query = null; |
|
|
|
query = null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// JSONP if cross domain url
|
|
|
|
xhr = new XMLHttpRequest(); // we dont support IE < 9
|
|
|
|
if (type === 'GET' && !nojsonp && domain && w.location.host !== domain[1]) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (nocache) { |
|
|
|
|
|
|
|
url += (url.indexOf('?') === -1) ? '?' + timestamp : '&' + timestamp; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Replace possible encoded ?
|
|
|
|
|
|
|
|
url = url.replace('=%3F', '=?'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Replace jsonp ? with callback
|
|
|
|
|
|
|
|
if (callback && url.indexOf('=?') !== -1) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
url = url.replace('=?', '=' + jsonpcallback); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w[jsonpcallback] = function (data) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
callback(data, 200); |
|
|
|
|
|
|
|
} catch (e) {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Tidy up
|
|
|
|
|
|
|
|
w[jsonpcallback] = undefined; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// JSONP
|
|
|
|
|
|
|
|
script = document.createElement('script'); |
|
|
|
|
|
|
|
script.async = true; |
|
|
|
|
|
|
|
script.src = url; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Tidy up
|
|
|
|
|
|
|
|
script.onload = function () { |
|
|
|
|
|
|
|
head.removeChild(script); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
head.appendChild(script); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (w.XMLHttpRequest) { |
|
|
|
|
|
|
|
xhr = new XMLHttpRequest(); |
|
|
|
|
|
|
|
} else if (w.ActiveXObject) { |
|
|
|
|
|
|
|
xhr = new ActiveXObject('Microsoft.XMLHTTP'); // IE < 9
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (xhr) { |
|
|
|
if (xhr) { |
|
|
|
|
|
|
|
// prevent caching
|
|
|
|
if (nocache) { |
|
|
|
|
|
|
|
url += (url.indexOf('?') === -1) ? '?' + timestamp : '&' + timestamp; |
|
|
|
url += (url.indexOf('?') === -1) ? '?' + timestamp : '&' + timestamp; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Douglas Crockford: "Synchronous programming is disrespectful and should not be employed in applications which are used by people"
|
|
|
|
// Douglas Crockford: "Synchronous programming is disrespectful and should not be employed in applications which are used by people"
|
|
|
|
xhr.open(type, url, true); |
|
|
|
xhr.open(type, url, true); |
|
|
@ -683,18 +634,17 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
xhr.send(query); |
|
|
|
xhr.send(query); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return cb; |
|
|
|
return cb; |
|
|
|
}; |
|
|
|
}; |
|
|
|
// Alias to cb.ajax(url, 'get', callback, nocache, nojsonp)
|
|
|
|
// Alias to cb.ajax(url, 'get', callback)
|
|
|
|
cb.get = function (url, callback, nocache, nojsonp) { |
|
|
|
cb.get = function (url, callback) { |
|
|
|
return cb.ajax(url, 'get', callback, nocache, nojsonp); |
|
|
|
return cb.ajax(url, 'get', callback); |
|
|
|
}; |
|
|
|
}; |
|
|
|
// Alias to cb.ajax(url, 'post', callback, nocache)
|
|
|
|
// Alias to cb.ajax(url, 'post', callback)
|
|
|
|
cb.post = function (url, callback, nocache) { |
|
|
|
cb.post = function (url, callback) { |
|
|
|
return cb.ajax(url, 'post', callback, nocache); |
|
|
|
return cb.ajax(url, 'post', callback); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return cb; |
|
|
|
return cb; |
|
|
|