1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 13:42:49 +01:00
invoiceninja/public/js/clients/linkify-urls.js
Benjamin Beganović 809236e080 Token billing
2021-11-01 17:11:47 +01:00

269 lines
8.0 KiB
JavaScript
Vendored

/******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ({
/***/ "./node_modules/create-html-element/index.js":
/*!***************************************************!*\
!*** ./node_modules/create-html-element/index.js ***!
\***************************************************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
"use strict";
const stringifyAttributes = __webpack_require__(/*! stringify-attributes */ "./node_modules/stringify-attributes/index.js");
const htmlTags = __webpack_require__(/*! html-tags/void */ "./node_modules/create-html-element/node_modules/html-tags/void.js");
const escapeGoat = __webpack_require__(/*! escape-goat */ "./node_modules/escape-goat/index.js");
const voidHtmlTags = new Set(htmlTags);
module.exports = options => {
options = Object.assign({
name: 'div',
attributes: {},
html: ''
}, options);
if (options.html && options.text) {
throw new Error('The `html` and `text` options are mutually exclusive');
}
const content = options.text ? escapeGoat.escape(options.text) : options.html;
let result = `<${options.name}${stringifyAttributes(options.attributes)}>`;
if (!voidHtmlTags.has(options.name)) {
result += `${content}</${options.name}>`;
}
return result;
};
/***/ }),
/***/ "./node_modules/create-html-element/node_modules/html-tags/void.js":
/*!*************************************************************************!*\
!*** ./node_modules/create-html-element/node_modules/html-tags/void.js ***!
\*************************************************************************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
"use strict";
module.exports = __webpack_require__(/*! ./html-tags-void.json */ "./node_modules/create-html-element/node_modules/html-tags/html-tags-void.json");
/***/ }),
/***/ "./node_modules/escape-goat/index.js":
/*!*******************************************!*\
!*** ./node_modules/escape-goat/index.js ***!
\*******************************************/
/***/ ((__unused_webpack_module, exports) => {
"use strict";
exports.escape = input => input
.replace(/&/g, '&amp;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
exports.unescape = input => input
.replace(/&gt;/g, '>')
.replace(/&lt;/g, '<')
.replace(/&#39;/g, '\'')
.replace(/&quot;/g, '"')
.replace(/&amp;/g, '&');
exports.escapeTag = function (input) {
let output = input[0];
for (let i = 1; i < arguments.length; i++) {
output = output + exports.escape(arguments[i]) + input[i];
}
return output;
};
exports.unescapeTag = function (input) {
let output = input[0];
for (let i = 1; i < arguments.length; i++) {
output = output + exports.unescape(arguments[i]) + input[i];
}
return output;
};
/***/ }),
/***/ "./node_modules/linkify-urls/index.js":
/*!********************************************!*\
!*** ./node_modules/linkify-urls/index.js ***!
\********************************************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
"use strict";
const createHtmlElement = __webpack_require__(/*! create-html-element */ "./node_modules/create-html-element/index.js");
// Capture the whole URL in group 1 to keep `String#split()` support
const urlRegex = () => (/((?<!\+)(?:https?(?::\/\/))(?:www\.)?(?:[a-zA-Z\d-_.]+(?:(?:\.|@)[a-zA-Z\d]{2,})|localhost)(?:(?:[-a-zA-Z\d:%_+.~#*$!?&//=@]*)(?:[,](?![\s]))*)*)/g);
// Get `<a>` element as string
const linkify = (href, options) => createHtmlElement({
name: 'a',
attributes: {
href: '',
...options.attributes,
href // eslint-disable-line no-dupe-keys
},
text: typeof options.value === 'undefined' ? href : undefined,
html: typeof options.value === 'undefined' ? undefined :
(typeof options.value === 'function' ? options.value(href) : options.value)
});
// Get DOM node from HTML
const domify = html => document.createRange().createContextualFragment(html);
const getAsString = (string, options) => {
return string.replace(urlRegex(), match => linkify(match, options));
};
const getAsDocumentFragment = (string, options) => {
const fragment = document.createDocumentFragment();
for (const [index, text] of Object.entries(string.split(urlRegex()))) {
if (index % 2) { // URLs are always in odd positions
fragment.append(domify(linkify(text, options)));
} else if (text.length > 0) {
fragment.append(text);
}
}
return fragment;
};
module.exports = (string, options) => {
options = {
attributes: {},
type: 'string',
...options
};
if (options.type === 'string') {
return getAsString(string, options);
}
if (options.type === 'dom') {
return getAsDocumentFragment(string, options);
}
throw new Error('The type option must be either `dom` or `string`');
};
/***/ }),
/***/ "./node_modules/stringify-attributes/index.js":
/*!****************************************************!*\
!*** ./node_modules/stringify-attributes/index.js ***!
\****************************************************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
"use strict";
const escapeGoat = __webpack_require__(/*! escape-goat */ "./node_modules/escape-goat/index.js");
module.exports = input => {
const attributes = [];
for (const key of Object.keys(input)) {
let value = input[key];
if (value === false) {
continue;
}
if (Array.isArray(value)) {
value = value.join(' ');
}
let attribute = escapeGoat.escape(key);
if (value !== true) {
attribute += `="${escapeGoat.escape(String(value))}"`;
}
attributes.push(attribute);
}
return attributes.length > 0 ? ' ' + attributes.join(' ') : '';
};
/***/ }),
/***/ "./node_modules/create-html-element/node_modules/html-tags/html-tags-void.json":
/*!*************************************************************************************!*\
!*** ./node_modules/create-html-element/node_modules/html-tags/html-tags-void.json ***!
\*************************************************************************************/
/***/ ((module) => {
"use strict";
module.exports = JSON.parse('["area","base","br","col","embed","hr","img","input","link","menuitem","meta","param","source","track","wbr"]');
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
(() => {
/*!**********************************************!*\
!*** ./resources/js/clients/linkify-urls.js ***!
\**********************************************/
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
var linkifyUrls = __webpack_require__(/*! linkify-urls */ "./node_modules/linkify-urls/index.js");
document.querySelectorAll('[data-ref=entity-terms]').forEach(function (text) {
text.innerHTML = linkifyUrls(text.innerText, {
attributes: {
target: '_blank',
"class": 'text-primary'
}
});
});
})();
/******/ })()
;