|
|
@ -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,103 +599,52 @@ |
|
|
|
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) { |
|
|
|
if (xhr) { |
|
|
|
xhr = new XMLHttpRequest(); |
|
|
|
// prevent caching
|
|
|
|
} else if (w.ActiveXObject) { |
|
|
|
url += (url.indexOf('?') === -1) ? '?' + timestamp : '&' + timestamp; |
|
|
|
xhr = new ActiveXObject('Microsoft.XMLHTTP'); // IE < 9
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (xhr) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (nocache) { |
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
xhr.onreadystatechange = function () { |
|
|
|
xhr.onreadystatechange = function () { |
|
|
|
if (xhr.readyState === 4) { |
|
|
|
if (xhr.readyState === 4) { |
|
|
|
if (callback) { |
|
|
|
if (callback) { |
|
|
|
callback(xhr.responseText, xhr.status); |
|
|
|
callback(xhr.responseText, xhr.status); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (type === 'POST' || type === 'PUT') { |
|
|
|
|
|
|
|
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
xhr.send(query); |
|
|
|
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (type === 'POST' || type === 'PUT') { |
|
|
|
|
|
|
|
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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; |
|
|
|