|
Apache/2.4.41 (Ubuntu) Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) server ip : 62.171.164.128 | your ip : 127.0.0.1 safemode OFF > / home / dev2.destoffenstraat.com / lib / web / mage / requirejs / |
Filename | /home/dev2.destoffenstraat.com/lib/web/mage/requirejs/text.js |
Size | 4.42 kb |
Permission | rw-r--r-- |
Owner | root : root |
Create time | 17-Aug-2025 10:26 |
Last modified | 28-Jan-2025 06:45 |
Last accessed | 22-Aug-2025 06:07 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/* inspired by http://github.com/requirejs/text */
/*global XMLHttpRequest, XDomainRequest */
define(['module'], function (module) {
'use strict';
var xmlRegExp = /^\s*<\?xml(\s)+version=[\'\"](\d)*.(\d)*[\'\"](\s)*\?>/im,
bodyRegExp = /<body[^>]*>\s*([\s\S]+)\s*<\/body>/im,
stripReg = /!strip$/i,
defaultConfig = module.config && module.config() || {};
/**
* Strips <?xml ...?> declarations so that external SVG and XML documents can be
* added to a document without worry.
* Also, if the string is an HTML document, only the part inside the body tag is returned.
*
* @param {String} external
* @returns {String}
*/
function stripContent(external) {
var matches;
if (!external) {
return '';
}
matches = external.match(bodyRegExp);
external = matches ?
matches[1] :
external.replace(xmlRegExp, '');
return external;
}
/**
* Checks that url match current location
*
* @param {String} url
* @returns {Boolean}
*/
function sameDomain(url) {
var uProtocol, uHostName, uPort,
xdRegExp = /^([\w:]+)?\/\/([^\/\\]+)/i,
location = window.location,
match = xdRegExp.exec(url);
if (!match) {
return true;
}
uProtocol = match[1];
uHostName = match[2];
uHostName = uHostName.split(':');
uPort = uHostName[1] || '';
uHostName = uHostName[0];
return (!uProtocol || uProtocol === location.protocol) &&
(!uHostName || uHostName.toLowerCase() === location.hostname.toLowerCase()) &&
(!uPort && !uHostName || uPort === location.port);
}
/**
* @returns {XMLHttpRequest|XDomainRequest|null}
*/
function createRequest(url) {
var xhr = new XMLHttpRequest();
if (!sameDomain(url) && typeof XDomainRequest !== 'undefined') {
xhr = new XDomainRequest();
}
return xhr;
}
/**
* XHR requester. Returns value to callback.
*
* @param {String} url
* @param {Function} callback
* @param {Function} fail
* @param {Object} headers
*/
function getContent(url, callback, fail, headers) {
var xhr = createRequest(url),
header;
xhr.open('GET', url);
/*eslint-disable max-depth */
if ('setRequestHeader' in xhr && headers) {
for (header in headers) {
if (headers.hasOwnProperty(header)) {
xhr.setRequestHeader(header.toLowerCase(), headers[header]);
}
}
}
/**
* @inheritdoc
*/
xhr.onreadystatechange = function () {
var status, err;
//Do not explicitly handle errors, those should be
//visible via console output in the browser.
if (xhr.readyState === 4) {
status = xhr.status || 0;
if (status > 399 && status < 600) {
//An http 4xx or 5xx error. Signal an error.
err = new Error(url + ' HTTP status: ' + status);
err.xhr = xhr;
if (fail) {
fail(err);
}
} else {
callback(xhr.responseText);
if (defaultConfig.onXhrComplete) {
defaultConfig.onXhrComplete(xhr, url);
}
}
}
};
/*eslint-enable max-depth */
if (defaultConfig.onXhr) {
defaultConfig.onXhr(xhr, url);
}
xhr.send();
}
/**
* Main method used by RequireJs.
*
* @param {String} name - has format: some.module.filext!strip
* @param {Function} req
* @param {Function|undefined} onLoad
*/
function loadContent(name, req, onLoad) {
var toStrip = stripReg.test(name),
url = req.toUrl(name.replace(stripReg, '')),
headers = defaultConfig.headers;
getContent(url, function (content) {
content = toStrip ? stripContent(content) : content;
onLoad(content);
}, onLoad.error, headers);
}
return {
load: loadContent,
get: getContent
};
});
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/* inspired by http://github.com/requirejs/text */
/*global XMLHttpRequest, XDomainRequest */
define(['module'], function (module) {
'use strict';
var xmlRegExp = /^\s*<\?xml(\s)+version=[\'\"](\d)*.(\d)*[\'\"](\s)*\?>/im,
bodyRegExp = /<body[^>]*>\s*([\s\S]+)\s*<\/body>/im,
stripReg = /!strip$/i,
defaultConfig = module.config && module.config() || {};
/**
* Strips <?xml ...?> declarations so that external SVG and XML documents can be
* added to a document without worry.
* Also, if the string is an HTML document, only the part inside the body tag is returned.
*
* @param {String} external
* @returns {String}
*/
function stripContent(external) {
var matches;
if (!external) {
return '';
}
matches = external.match(bodyRegExp);
external = matches ?
matches[1] :
external.replace(xmlRegExp, '');
return external;
}
/**
* Checks that url match current location
*
* @param {String} url
* @returns {Boolean}
*/
function sameDomain(url) {
var uProtocol, uHostName, uPort,
xdRegExp = /^([\w:]+)?\/\/([^\/\\]+)/i,
location = window.location,
match = xdRegExp.exec(url);
if (!match) {
return true;
}
uProtocol = match[1];
uHostName = match[2];
uHostName = uHostName.split(':');
uPort = uHostName[1] || '';
uHostName = uHostName[0];
return (!uProtocol || uProtocol === location.protocol) &&
(!uHostName || uHostName.toLowerCase() === location.hostname.toLowerCase()) &&
(!uPort && !uHostName || uPort === location.port);
}
/**
* @returns {XMLHttpRequest|XDomainRequest|null}
*/
function createRequest(url) {
var xhr = new XMLHttpRequest();
if (!sameDomain(url) && typeof XDomainRequest !== 'undefined') {
xhr = new XDomainRequest();
}
return xhr;
}
/**
* XHR requester. Returns value to callback.
*
* @param {String} url
* @param {Function} callback
* @param {Function} fail
* @param {Object} headers
*/
function getContent(url, callback, fail, headers) {
var xhr = createRequest(url),
header;
xhr.open('GET', url);
/*eslint-disable max-depth */
if ('setRequestHeader' in xhr && headers) {
for (header in headers) {
if (headers.hasOwnProperty(header)) {
xhr.setRequestHeader(header.toLowerCase(), headers[header]);
}
}
}
/**
* @inheritdoc
*/
xhr.onreadystatechange = function () {
var status, err;
//Do not explicitly handle errors, those should be
//visible via console output in the browser.
if (xhr.readyState === 4) {
status = xhr.status || 0;
if (status > 399 && status < 600) {
//An http 4xx or 5xx error. Signal an error.
err = new Error(url + ' HTTP status: ' + status);
err.xhr = xhr;
if (fail) {
fail(err);
}
} else {
callback(xhr.responseText);
if (defaultConfig.onXhrComplete) {
defaultConfig.onXhrComplete(xhr, url);
}
}
}
};
/*eslint-enable max-depth */
if (defaultConfig.onXhr) {
defaultConfig.onXhr(xhr, url);
}
xhr.send();
}
/**
* Main method used by RequireJs.
*
* @param {String} name - has format: some.module.filext!strip
* @param {Function} req
* @param {Function|undefined} onLoad
*/
function loadContent(name, req, onLoad) {
var toStrip = stripReg.test(name),
url = req.toUrl(name.replace(stripReg, '')),
headers = defaultConfig.headers;
getContent(url, function (content) {
content = toStrip ? stripContent(content) : content;
onLoad(content);
}, onLoad.error, headers);
}
return {
load: loadContent,
get: getContent
};
});