MCPcopy
hub / github.com/CodeboxIDE/codebox / doXHR

Function doXHR

core/cb.addons/require-tools/less/lessc.js:6654–6690  ·  view source on GitHub ↗
(url, type, callback, errback)

Source from the content-addressed store, hash-verified

6652}
6653
6654function doXHR(url, type, callback, errback) {
6655 var xhr = getXMLHttpRequest();
6656 var async = isFileProtocol ? less.fileAsync : less.async;
6657
6658 if (typeof(xhr.overrideMimeType) === 'function') {
6659 xhr.overrideMimeType('text/css');
6660 }
6661 log("XHR: Getting '" + url + "'", logLevel.info);
6662 xhr.open('GET', url, async);
6663 xhr.setRequestHeader('Accept', type || 'text/x-less, text/css; q=0.9, */*; q=0.5');
6664 xhr.send(null);
6665
6666 function handleResponse(xhr, callback, errback) {
6667 if (xhr.status >= 200 && xhr.status < 300) {
6668 callback(xhr.responseText,
6669 xhr.getResponseHeader("Last-Modified"));
6670 } else if (typeof(errback) === 'function') {
6671 errback(xhr.status, url);
6672 }
6673 }
6674
6675 if (isFileProtocol && !less.fileAsync) {
6676 if (xhr.status === 0 || (xhr.status >= 200 && xhr.status < 300)) {
6677 callback(xhr.responseText);
6678 } else {
6679 errback(xhr.status, url);
6680 }
6681 } else if (async) {
6682 xhr.onreadystatechange = function () {
6683 if (xhr.readyState == 4) {
6684 handleResponse(xhr, callback, errback);
6685 }
6686 };
6687 } else {
6688 handleResponse(xhr, callback, errback);
6689 }
6690}
6691
6692function loadFile(originalHref, currentFileInfo, callback, env, newVars) {
6693

Callers 1

loadFileFunction · 0.85

Calls 4

getXMLHttpRequestFunction · 0.85
logFunction · 0.85
handleResponseFunction · 0.85
callbackFunction · 0.50

Tested by

no test coverage detected