From 349078d61fbb9d1bf8a41b76163b943bbd72be65 Mon Sep 17 00:00:00 2001 From: Grzegorz Tomicki Date: Sun, 3 Jul 2022 22:07:37 +0200 Subject: [PATCH] fix: Bug with table button - clickEvent added on wrong element? --- dist/js/showMore.esm.js | 4 +++- dist/js/showMore.esm.js.map | 2 +- dist/js/showMore.esm.min.js | 2 +- dist/js/showMore.ie.min.js | 2 +- dist/js/showMore.js | 4 +++- dist/js/showMore.js.map | 2 +- dist/js/showMore.min.js | 2 +- dist/js/showMore.umd.js | 4 +++- dist/js/showMore.umd.js.map | 2 +- dist/js/showMore.umd.min.js | 2 +- docs/showMore.min.js | 2 +- docs/showMore.min.js.map | 2 +- 12 files changed, 18 insertions(+), 12 deletions(-) diff --git a/dist/js/showMore.esm.js b/dist/js/showMore.esm.js index 3ebedcd..b027b5b 100644 --- a/dist/js/showMore.esm.js +++ b/dist/js/showMore.esm.js @@ -127,9 +127,11 @@ class ShowMore { for (let i = limit; i < items.length; i++) { addRemoveClass(items[i], true); } + if (!nobutton) { + this._addBtn(this._object); + } this._clickEvent(type === "list" ? element : element.nextElementSibling, this._object); if (nobutton) return; - this._addBtn(this._object); } } }; diff --git a/dist/js/showMore.esm.js.map b/dist/js/showMore.esm.js.map index f4b98c0..7a22240 100644 --- a/dist/js/showMore.esm.js.map +++ b/dist/js/showMore.esm.js.map @@ -1 +1 @@ -{"version":3,"file":"showMore.esm.js","sources":["../../sources/utils/function.js","../../sources/utils/regex.js","../../sources/utils/defaults.js","../../sources/index.js"],"sourcesContent":["/**\r\n * Get hidden element\r\n *\r\n * @param {object} object\r\n * @param {String} type - type of element table | div\r\n * @returns\r\n */\r\nconst getNumber = ({ rows, children }, type) => {\r\n const elementType = type === \"table\" ? rows : children;\r\n\r\n const numbersElementHidden = [].slice\r\n .call(elementType)\r\n .filter((el) => el.className === \"hidden\").length;\r\n return numbersElementHidden !== 0 ? ` ${numbersElementHidden}` : \"\";\r\n};\r\n\r\n// https://stackoverflow.com/questions/6003271/substring-text-with-html-tags-in-javascript\r\n/**\r\n * Substring text width html tags\r\n *\r\n * @param {String} originalText - text with html tags\r\n * @param {String} count - limit of characters\r\n * @returns\r\n */\r\nconst htmlSubstr = (originalText, count) => {\r\n let div = createElement(\"div\");\r\n div.insertAdjacentHTML(\"afterbegin\", originalText);\r\n\r\n walk(div, track);\r\n\r\n function track(el) {\r\n if (count > 0) {\r\n let len = el.data.length;\r\n count -= len;\r\n if (count <= 0) {\r\n el.data = el.substringData(0, el.data.length + count);\r\n }\r\n } else {\r\n el.data = \"\";\r\n }\r\n }\r\n\r\n function walk(el, fn) {\r\n let node = el.firstChild;\r\n do {\r\n if (node.nodeType === 3) {\r\n fn(node);\r\n } else if (node.nodeType === 1 && node.childNodes && node.childNodes[0]) {\r\n walk(node, fn);\r\n }\r\n } while ((node = node.nextSibling));\r\n }\r\n return div.innerHTML;\r\n};\r\n\r\n/**\r\n * Add/remove class 'hidden' to element\r\n *\r\n * @param {HTMLElement} element\r\n * @param {String} type - type of element add or remove\r\n */\r\nconst addRemoveClass = (element, type = false) => {\r\n return element.classList[type ? \"add\" : \"remove\"](\"hidden\");\r\n};\r\n\r\n/**\r\n * Set attributes to element\r\n *\r\n * @param {HTMLElement} el\r\n * @param {Object} object\r\n */\r\nconst setAttributes = (el, object) => {\r\n for (let key in object) {\r\n el.setAttribute(key, object[key]);\r\n }\r\n};\r\n\r\n/**\r\n * Create element\r\n *\r\n * @param {String} type - type of element\r\n * @returns {HTMLElement}\r\n */\r\nconst createElement = (type) => document.createElement(type);\r\n\r\nexport { addRemoveClass, createElement, getNumber, htmlSubstr, setAttributes };\r\n","/**\r\n * Default regexes for validation\r\n */\r\nconst defaultRegex = {\r\n newLine: {\r\n match: /(\\r\\n|\\n|\\r)/gm,\r\n replace: \"\",\r\n },\r\n space: {\r\n match: /\\s\\s+/gm,\r\n replace: \" \",\r\n },\r\n br: {\r\n match: //gim,\r\n replace: \"\",\r\n },\r\n html: {\r\n match: /(<((?!b|\\/b|!strong|\\/strong)[^>]+)>)/gi,\r\n replace: \"\",\r\n },\r\n};\r\n\r\nexport default defaultRegex;\r\n","const defaultOptions = {\r\n typeElement: \"span\",\r\n more: false,\r\n less: false,\r\n number: false,\r\n nobutton: false,\r\n after: 0,\r\n btnClass: \"show-more-btn\",\r\n btnClassAppend: null,\r\n};\r\n\r\nexport default defaultOptions;\r\n","import {\r\n addRemoveClass,\r\n createElement,\r\n getNumber,\r\n htmlSubstr,\r\n setAttributes,\r\n} from \"./utils/function\";\r\nimport defaultRegex from \"./utils/regex\";\r\nimport defaultOptions from \"./utils/defaults\";\r\n\r\n/**\r\n * @class ShowMore\r\n */\r\nexport default class ShowMore {\r\n /**\r\n * Constructor\r\n *\r\n * @param {HTMLElement} className\r\n * @param {Object} object\r\n */\r\n constructor(className, { onMoreLess = () => {}, regex = {}, config } = {}) {\r\n // all html elements\r\n const elements = [].slice.call(document.querySelectorAll(className));\r\n\r\n // colback function\r\n this._onMoreLess = onMoreLess;\r\n\r\n // global regex\r\n this._regex = { ...defaultRegex, ...regex };\r\n\r\n elements.map((item, index) => {\r\n const configData = JSON.parse(item.getAttribute(\"data-config\"));\r\n const configGlobal = config;\r\n\r\n const configDataAndGlobal = { ...configGlobal, ...configData };\r\n\r\n this._object = {\r\n index,\r\n classArray: item.classList,\r\n ...defaultOptions,\r\n ...configDataAndGlobal,\r\n typeElement: configDataAndGlobal.element || \"span\",\r\n element: item,\r\n };\r\n\r\n this._initial();\r\n });\r\n }\r\n\r\n /**\r\n * Initail function\r\n *\r\n * @param {Object} object\r\n */\r\n _initial = () => {\r\n const { element, after, ellipsis, nobutton, limit, type } = this._object;\r\n // set default aria-expande to false\r\n setAttributes(element, { \"aria-expanded\": \"false\" });\r\n\r\n const limitCounts = limit + after;\r\n const ellips = ellipsis === false ? \"\" : \"...\";\r\n\r\n // console.log(nobutton);\r\n\r\n // text\r\n if (type === \"text\") {\r\n const originalText = element.innerHTML.trim();\r\n const elementText = element.textContent.trim();\r\n\r\n if (elementText.length > limitCounts) {\r\n let orgTexReg = originalText;\r\n\r\n for (let key in this._regex) {\r\n const { match, replace } = this._regex[key];\r\n if (key && match) orgTexReg = orgTexReg.replace(match, replace);\r\n }\r\n\r\n const truncatedText = htmlSubstr(orgTexReg, limit - 1).concat(ellips);\r\n\r\n element.textContent = \"\";\r\n element.insertAdjacentHTML(\"beforeend\", truncatedText);\r\n\r\n this._clickEvent(element, {\r\n ...this._object,\r\n originalText,\r\n truncatedText,\r\n });\r\n\r\n if (nobutton) return;\r\n this._addBtn(this._object);\r\n }\r\n }\r\n\r\n // list and table\r\n if (type === \"list\" || type === \"table\") {\r\n const items = this._getNumberCount(element, type);\r\n\r\n if (items.length > limitCounts) {\r\n for (let i = limit; i < items.length; i++) {\r\n addRemoveClass(items[i], true);\r\n }\r\n\r\n // add event click\r\n this._clickEvent(\r\n type === \"list\" ? element : element.nextElementSibling,\r\n this._object\r\n );\r\n\r\n if (nobutton) return;\r\n // add button to the list and table\r\n this._addBtn(this._object);\r\n }\r\n }\r\n };\r\n\r\n /**\r\n * Event click\r\n *\r\n * @param {HTMLElement} element\r\n * @param {Object} object\r\n */\r\n _clickEvent = (element, object) =>\r\n element.addEventListener(\"click\", this._handleEvent.bind(this, object));\r\n\r\n /**\r\n * Create button\r\n *\r\n * @param {Object} object\r\n * @returns HTMLElement\r\n */\r\n _createBtn = ({\r\n element,\r\n number,\r\n less,\r\n more,\r\n type,\r\n btnClass,\r\n btnClassAppend,\r\n }) => {\r\n const typeAria = this._checkExp ? less || \"\" : more || \"\";\r\n const label = this._checkExp ? \"collapse\" : \"expand\";\r\n const expanded = this._checkExp ? true : false;\r\n\r\n const button = createElement(\"button\");\r\n button.className =\r\n btnClassAppend == null ? btnClass : btnClass + \" \" + btnClassAppend;\r\n setAttributes(button, {\r\n \"aria-expanded\": expanded,\r\n \"aria-label\": label,\r\n tabindex: 0,\r\n });\r\n\r\n button.insertAdjacentHTML(\r\n \"beforeend\",\r\n number ? typeAria + getNumber(element, type) : typeAria\r\n );\r\n return button;\r\n };\r\n\r\n /**\r\n * Event handler\r\n *\r\n * @param {Object} object\r\n * @param {Event} event\r\n */\r\n _handleEvent = (object, { target }) => {\r\n const {\r\n element,\r\n type,\r\n limit,\r\n less,\r\n typeElement,\r\n originalText,\r\n truncatedText,\r\n btnClass,\r\n } = object;\r\n\r\n // check if the button is clicked\r\n const checkContainsClass = target.classList.contains(btnClass);\r\n\r\n if (!checkContainsClass) return;\r\n\r\n const ariaExpanded = element.getAttribute(\"aria-expanded\");\r\n this._checkExp = ariaExpanded === \"false\";\r\n\r\n // --------------------------------------------------\r\n // text\r\n if (type === \"text\" && checkContainsClass) {\r\n element.textContent = \"\";\r\n\r\n element.insertAdjacentHTML(\r\n \"beforeend\",\r\n this._checkExp ? originalText : truncatedText\r\n );\r\n\r\n if (less) {\r\n const el = createElement(typeElement);\r\n el.classList.add(\"show-more-wrapper\");\r\n el.insertAdjacentElement(\"beforeend\", this._createBtn(object));\r\n element.appendChild(el);\r\n }\r\n }\r\n\r\n // --------------------------------------------------\r\n // list and table\r\n if (type === \"list\" || type === \"table\") {\r\n const items = this._getNumberCount(element, type);\r\n\r\n for (let i = 0; i < items.length; i++) {\r\n const typeRemove =\r\n type === \"list\" ? i >= limit && i < items.length - 1 : i >= limit;\r\n\r\n if (ariaExpanded === \"false\") {\r\n addRemoveClass(items[i]);\r\n } else if (typeRemove) {\r\n addRemoveClass(items[i], true);\r\n }\r\n }\r\n }\r\n\r\n // set aria-expanded\r\n if (type) {\r\n this._setExpand({ ...object, target });\r\n }\r\n };\r\n\r\n _getNumberCount = (element, type) => {\r\n return type === \"list\" ? [].slice.call(element.children) : element.rows;\r\n };\r\n\r\n /**\r\n * Add button\r\n *\r\n * @param {Object} object\r\n */\r\n _addBtn = (object) => {\r\n const { type, element, more, typeElement } = object;\r\n\r\n if (!more) return;\r\n\r\n if (type === \"table\") {\r\n element.insertAdjacentElement(\"afterend\", this._createBtn(object));\r\n } else {\r\n const el = createElement(typeElement);\r\n el.classList.add(\"show-more-wrapper\");\r\n el.appendChild(this._createBtn(object));\r\n element.appendChild(el);\r\n }\r\n };\r\n\r\n /**\r\n * Set aria-expanded\r\n *\r\n * @param {Object} object\r\n */\r\n _setExpand = (object) => {\r\n const { element, type, less, more, number, target } = object;\r\n\r\n const typeAria = this._checkExp ? less : more;\r\n const aria = this._checkExp ? \"expand\" : \"collapse\";\r\n const ariaText = type === \"table\" ? type : `the ${type}`;\r\n const lastChild = element.lastElementChild;\r\n\r\n setAttributes(element, { \"aria-expanded\": this._checkExp });\r\n setAttributes(target, {\r\n \"aria-expanded\": this._checkExp,\r\n \"aria-label\": `${aria} ${ariaText}`,\r\n });\r\n\r\n // callback function on more/less\r\n this._onMoreLess(aria, object);\r\n\r\n if (typeAria) {\r\n target.innerHTML = number\r\n ? typeAria + getNumber(element, type)\r\n : typeAria;\r\n } else if (type === \"table\") {\r\n target.parentNode.removeChild(target);\r\n } else if (type === \"list\") {\r\n lastChild.parentNode.removeChild(lastChild);\r\n }\r\n };\r\n}\r\n"],"names":["getNumber","type","rows","children","elementType","numbersElementHidden","slice","call","filter","el","className","length","htmlSubstr","originalText","count","div","createElement","insertAdjacentHTML","walk","track","len","data","substringData","fn","node","firstChild","nodeType","childNodes","nextSibling","innerHTML","addRemoveClass","element","classList","setAttributes","object","key","setAttribute","document","defaultRegex","newLine","match","replace","space","br","html","defaultOptions","typeElement","more","less","number","nobutton","after","btnClass","btnClassAppend","ShowMore","constructor","onMoreLess","regex","config","_initial","ellipsis","limit","_object","limitCounts","ellips","trim","elementText","textContent","orgTexReg","_regex","truncatedText","concat","_clickEvent","_addBtn","items","_getNumberCount","i","nextElementSibling","addEventListener","_handleEvent","bind","_createBtn","typeAria","_checkExp","label","expanded","button","tabindex","target","checkContainsClass","contains","ariaExpanded","getAttribute","add","insertAdjacentElement","appendChild","typeRemove","_setExpand","aria","ariaText","lastChild","lastElementChild","_onMoreLess","parentNode","removeChild","elements","querySelectorAll","map","item","index","configData","JSON","par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,CAAqBC,WAArB,CAAiCJ,SAAjC;AACD;AACF,KArQ0E;AAEzE,UAAMK,QAAQ,GAAG,GAAGnG,KAAH,CAASC,IAAT,CAAc8B,QAAQ,CAACqE,gBAAT,CAA0BhG,SAA1B,CAAd,CAAjB,CAFyE;AAKzE,SAAK4F,WAAL,GAAmB9C,UAAnB,CALyE;AAQzE,SAAKa,MAAL,GAAc,EAAE,GAAG/B,YAAL;AAAmB,SAAGmB;AAAtB,KAAd;AAEAgD,IAAAA,QAAQ,CAACE,GAAT,CAAa,CAACC,IAAD,EAAOC,KAAP,KAAiB;AAC5B,YAAMC,UAAU,GAAGC,IAAI,CAACC,KAAL,CAAWJ,IAAI,CAAChB,YAAL,CAAkB,aAAlB,CAAX,CAAnB;AACA,YAAMqB,YAAY,GAAGvD,MAArB;AAEA,YAAMwD,mBAAmB,GAAG,EAAE,GAAGD,YAAL;AAAmB,WAAGH;AAAtB,OAA5B;AAEA,WAAKhD,OAAL,GAAe;AACb+C,QAAAA,KADa;AAEbM,QAAAA,UAAU,EAAEP,IAAI,CAAC5E,SAFJ;AAGb,WAAGa,cAHU;AAIb,WAAGqE,mBAJU;AAKbpE,QAAAA,WAAW,EAAEoE,mBAAmB,CAACnF,OAApB,IAA+B,MAL/B;AAMbA,QAAAA,OAAO,EAAE6E;AANI,OAAf;AASA,WAAKjD,QAAL;AACD,KAhBD;AAiBD;AAlC2B;;;;"} \ No newline at end of file +{"version":3,"file":"showMore.esm.js","sources":["../../sources/utils/function.js","../../sources/utils/regex.js","../../sources/utils/defaults.js","../../sources/index.js"],"sourcesContent":["/**\r\n * Get hidden element\r\n *\r\n * @param {object} object\r\n * @param {String} type - type of element table | div\r\n * @returns\r\n */\r\nconst getNumber = ({ rows, children }, type) => {\r\n const elementType = type === \"table\" ? rows : children;\r\n\r\n const numbersElementHidden = [].slice\r\n .call(elementType)\r\n .filter((el) => el.className === \"hidden\").length;\r\n return numbersElementHidden !== 0 ? ` ${numbersElementHidden}` : \"\";\r\n};\r\n\r\n// https://stackoverflow.com/questions/6003271/substring-text-with-html-tags-in-javascript\r\n/**\r\n * Substring text width html tags\r\n *\r\n * @param {String} originalText - text with html tags\r\n * @param {String} count - limit of characters\r\n * @returns\r\n */\r\nconst htmlSubstr = (originalText, count) => {\r\n let div = createElement(\"div\");\r\n div.insertAdjacentHTML(\"afterbegin\", originalText);\r\n\r\n walk(div, track);\r\n\r\n function track(el) {\r\n if (count > 0) {\r\n let len = el.data.length;\r\n count -= len;\r\n if (count <= 0) {\r\n el.data = el.substringData(0, el.data.length + count);\r\n }\r\n } else {\r\n el.data = \"\";\r\n }\r\n }\r\n\r\n function walk(el, fn) {\r\n let node = el.firstChild;\r\n do {\r\n if (node.nodeType === 3) {\r\n fn(node);\r\n } else if (node.nodeType === 1 && node.childNodes && node.childNodes[0]) {\r\n walk(node, fn);\r\n }\r\n } while ((node = node.nextSibling));\r\n }\r\n return div.innerHTML;\r\n};\r\n\r\n/**\r\n * Add/remove class 'hidden' to element\r\n *\r\n * @param {HTMLElement} element\r\n * @param {String} type - type of element add or remove\r\n */\r\nconst addRemoveClass = (element, type = false) => {\r\n return element.classList[type ? \"add\" : \"remove\"](\"hidden\");\r\n};\r\n\r\n/**\r\n * Set attributes to element\r\n *\r\n * @param {HTMLElement} el\r\n * @param {Object} object\r\n */\r\nconst setAttributes = (el, object) => {\r\n for (let key in object) {\r\n el.setAttribute(key, object[key]);\r\n }\r\n};\r\n\r\n/**\r\n * Create element\r\n *\r\n * @param {String} type - type of element\r\n * @returns {HTMLElement}\r\n */\r\nconst createElement = (type) => document.createElement(type);\r\n\r\nexport { addRemoveClass, createElement, getNumber, htmlSubstr, setAttributes };\r\n","/**\r\n * Default regexes for validation\r\n */\r\nconst defaultRegex = {\r\n newLine: {\r\n match: /(\\r\\n|\\n|\\r)/gm,\r\n replace: \"\",\r\n },\r\n space: {\r\n match: /\\s\\s+/gm,\r\n replace: \" \",\r\n },\r\n br: {\r\n match: //gim,\r\n replace: \"\",\r\n },\r\n html: {\r\n match: /(<((?!b|\\/b|!strong|\\/strong)[^>]+)>)/gi,\r\n replace: \"\",\r\n },\r\n};\r\n\r\nexport default defaultRegex;\r\n","const defaultOptions = {\r\n typeElement: \"span\",\r\n more: false,\r\n less: false,\r\n number: false,\r\n nobutton: false,\r\n after: 0,\r\n btnClass: \"show-more-btn\",\r\n btnClassAppend: null,\r\n};\r\n\r\nexport default defaultOptions;\r\n","import {\r\n addRemoveClass,\r\n createElement,\r\n getNumber,\r\n htmlSubstr,\r\n setAttributes,\r\n} from \"./utils/function\";\r\nimport defaultRegex from \"./utils/regex\";\r\nimport defaultOptions from \"./utils/defaults\";\r\n\r\n/**\r\n * @class ShowMore\r\n */\r\nexport default class ShowMore {\r\n /**\r\n * Constructor\r\n *\r\n * @param {HTMLElement} className\r\n * @param {Object} object\r\n */\r\n constructor(className, { onMoreLess = () => {}, regex = {}, config } = {}) {\r\n // all html elements\r\n const elements = [].slice.call(document.querySelectorAll(className));\r\n\r\n // colback function\r\n this._onMoreLess = onMoreLess;\r\n\r\n // global regex\r\n this._regex = { ...defaultRegex, ...regex };\r\n\r\n elements.map((item, index) => {\r\n const configData = JSON.parse(item.getAttribute(\"data-config\"));\r\n const configGlobal = config;\r\n\r\n const configDataAndGlobal = { ...configGlobal, ...configData };\r\n\r\n this._object = {\r\n index,\r\n classArray: item.classList,\r\n ...defaultOptions,\r\n ...configDataAndGlobal,\r\n typeElement: configDataAndGlobal.element || \"span\",\r\n element: item,\r\n };\r\n\r\n this._initial();\r\n });\r\n }\r\n\r\n /**\r\n * Initail function\r\n *\r\n * @param {Object} object\r\n */\r\n _initial = () => {\r\n const { element, after, ellipsis, nobutton, limit, type } = this._object;\r\n // set default aria-expande to false\r\n setAttributes(element, { \"aria-expanded\": \"false\" });\r\n\r\n const limitCounts = limit + after;\r\n const ellips = ellipsis === false ? \"\" : \"...\";\r\n\r\n // console.log(nobutton);\r\n\r\n // text\r\n if (type === \"text\") {\r\n const originalText = element.innerHTML.trim();\r\n const elementText = element.textContent.trim();\r\n\r\n if (elementText.length > limitCounts) {\r\n let orgTexReg = originalText;\r\n\r\n for (let key in this._regex) {\r\n const { match, replace } = this._regex[key];\r\n if (key && match) orgTexReg = orgTexReg.replace(match, replace);\r\n }\r\n\r\n const truncatedText = htmlSubstr(orgTexReg, limit - 1).concat(ellips);\r\n\r\n element.textContent = \"\";\r\n element.insertAdjacentHTML(\"beforeend\", truncatedText);\r\n\r\n this._clickEvent(element, {\r\n ...this._object,\r\n originalText,\r\n truncatedText,\r\n });\r\n\r\n if (nobutton) return;\r\n this._addBtn(this._object);\r\n }\r\n }\r\n\r\n // list and table\r\n if (type === \"list\" || type === \"table\") {\r\n const items = this._getNumberCount(element, type);\r\n\r\n if (items.length > limitCounts) {\r\n for (let i = limit; i < items.length; i++) {\r\n addRemoveClass(items[i], true);\r\n }\r\n\r\n if (!nobutton) {\r\n // add button to the list and table\r\n this._addBtn(this._object);\r\n }\r\n\r\n // add event click\r\n this._clickEvent(\r\n type === \"list\" ? element : element.nextElementSibling,\r\n this._object\r\n );\r\n\r\n if (nobutton) return;\r\n }\r\n }\r\n };\r\n\r\n /**\r\n * Event click\r\n *\r\n * @param {HTMLElement} element\r\n * @param {Object} object\r\n */\r\n _clickEvent = (element, object) =>\r\n element.addEventListener(\"click\", this._handleEvent.bind(this, object));\r\n\r\n /**\r\n * Create button\r\n *\r\n * @param {Object} object\r\n * @returns HTMLElement\r\n */\r\n _createBtn = ({\r\n element,\r\n number,\r\n less,\r\n more,\r\n type,\r\n btnClass,\r\n btnClassAppend,\r\n }) => {\r\n const typeAria = this._checkExp ? less || \"\" : more || \"\";\r\n const label = this._checkExp ? \"collapse\" : \"expand\";\r\n const expanded = this._checkExp ? true : false;\r\n\r\n const button = createElement(\"button\");\r\n button.className =\r\n btnClassAppend == null ? btnClass : btnClass + \" \" + btnClassAppend;\r\n setAttributes(button, {\r\n \"aria-expanded\": expanded,\r\n \"aria-label\": label,\r\n tabindex: 0,\r\n });\r\n\r\n button.insertAdjacentHTML(\r\n \"beforeend\",\r\n number ? typeAria + getNumber(element, type) : typeAria\r\n );\r\n return button;\r\n };\r\n\r\n /**\r\n * Event handler\r\n *\r\n * @param {Object} object\r\n * @param {Event} event\r\n */\r\n _handleEvent = (object, { target }) => {\r\n const {\r\n element,\r\n type,\r\n limit,\r\n less,\r\n typeElement,\r\n originalText,\r\n truncatedText,\r\n btnClass,\r\n } = object;\r\n\r\n // check if the button is clicked\r\n const checkContainsClass = target.classList.contains(btnClass);\r\n\r\n if (!checkContainsClass) return;\r\n\r\n const ariaExpanded = element.getAttribute(\"aria-expanded\");\r\n this._checkExp = ariaExpanded === \"false\";\r\n\r\n // --------------------------------------------------\r\n // text\r\n if (type === \"text\" && checkContainsClass) {\r\n element.textContent = \"\";\r\n\r\n element.insertAdjacentHTML(\r\n \"beforeend\",\r\n this._checkExp ? originalText : truncatedText\r\n );\r\n\r\n if (less) {\r\n const el = createElement(typeElement);\r\n el.classList.add(\"show-more-wrapper\");\r\n el.insertAdjacentElement(\"beforeend\", this._createBtn(object));\r\n element.appendChild(el);\r\n }\r\n }\r\n\r\n // --------------------------------------------------\r\n // list and table\r\n if (type === \"list\" || type === \"table\") {\r\n const items = this._getNumberCount(element, type);\r\n\r\n for (let i = 0; i < items.length; i++) {\r\n const typeRemove =\r\n type === \"list\" ? i >= limit && i < items.length - 1 : i >= limit;\r\n\r\n if (ariaExpanded === \"false\") {\r\n addRemoveClass(items[i]);\r\n } else if (typeRemove) {\r\n addRemoveClass(items[i], true);\r\n }\r\n }\r\n }\r\n\r\n // set aria-expanded\r\n if (type) {\r\n this._setExpand({ ...object, target });\r\n }\r\n };\r\n\r\n _getNumberCount = (element, type) => {\r\n return type === \"list\" ? [].slice.call(element.children) : element.rows;\r\n };\r\n\r\n /**\r\n * Add button\r\n *\r\n * @param {Object} object\r\n */\r\n _addBtn = (object) => {\r\n const { type, element, more, typeElement } = object;\r\n\r\n if (!more) return;\r\n\r\n if (type === \"table\") {\r\n element.insertAdjacentElement(\"afterend\", this._createBtn(object));\r\n } else {\r\n const el = createElement(typeElement);\r\n el.classList.add(\"show-more-wrapper\");\r\n el.appendChild(this._createBtn(object));\r\n element.appendChild(el);\r\n }\r\n };\r\n\r\n /**\r\n * Set aria-expanded\r\n *\r\n * @param {Object} object\r\n */\r\n _setExpand = (object) => {\r\n const { element, type, less, more, number, target } = object;\r\n\r\n const typeAria = this._checkExp ? less : more;\r\n const aria = this._checkExp ? \"expand\" : \"collapse\";\r\n const ariaText = type === \"table\" ? type : `the ${type}`;\r\n const lastChild = element.lastElementChild;\r\n\r\n setAttributes(element, { \"aria-expanded\": this._checkExp });\r\n setAttributes(target, {\r\n \"aria-expanded\": this._checkExp,\r\n \"aria-label\": `${aria} ${ariaText}`,\r\n });\r\n\r\n // callback function on more/less\r\n this._onMoreLess(aria, object);\r\n\r\n if (typeAria) {\r\n target.innerHTML = number\r\n ? typeAria + getNumber(element, type)\r\n : typeAria;\r\n } else if (type === \"table\") {\r\n target.parentNode.removeChild(target);\r\n } else if (type === \"list\") {\r\n lastChild.parentNode.removeChild(lastChild);\r\n }\r\n };\r\n}\r\n"],"names":["getNumber","type","rows","children","elementType","numbersElementHidden","slice","call","filter","el","className","length","htmlSubstr","originalText","count","div","createElement","insertAdjacentHTML","walk","track","len","data","substringData","fn","node","firstChild","nodeType","childNodes","nextSibling","innerHTML","addRemoveClass","element","classList","setAttributes","object","key","setAttribute","document","defaultRegex","newLine","match","replace","space","br","html","defaultOptions","typeElement","more","less","number","nobutton","after","btnClass","btnClassAppend","ShowMore","constructor","onMoreLess","regex","config","_initial","ellipsis","limit","_object","limitCounts","ellips","trim","elementText","textContent","orgTexReg","_regex","truncatedText","concat","_clickEvent","_addBtn","items","_getNumberCount","i","nextElementSibling","addEventListener","_handleEvent","bind","_createBtn","typeAria","_checkExp","label","expanded","button","tabindex","target","checkContainsClass","contains","ariaExpanded","getAttribute","add","insertAdjacentElement","appendChild","typeRemove","_setExpand","aria","ariaText","lastChild","lastElementChild","_onMoreLess","parentNode","removeChild","elements","querySelectorAll","map","item","index","configData","JSON","parse","configGlobal","configDataAndGlobal","classArray"],"mappings":"AAOA,MAAMA,SAAS,GAAG,OAAqBC,IAArB,KAA8B;AAAA,MAA7B;AAAEC,IAAAA,IAAF;AAAQC,IAAAA;AAAR,GAA6B;AAC9C,QAAMC,WAAW,GAAGH,IAAI,KAAK,OAAT,GAAmBC,IAAnB,GAA0BC,QAA9C;AAEA,QAAME,oBAAoB,GAAG,GAAGC,KAAH,CAC1BC,IAD0B,CACrBH,WADqB,EAE1BI,MAF0B,CAElBC,EAAD,IAAQA,EAAE,CAACC,SAAH,KAAiB,QAFN,EAEgBC,MAF7C;AAGA,SAAON,oBAAoB,KAAK,CAAzB,SAAiCA,oBAAjC,GAA0D,EAAjE;AACD,CAPD;AAiBA,MAAMO,UAAU,GAAG,CAACC,YAAD,EAAeC,KAAf,KAAyB;AAC1C,MAAIC,GAAG,GAAGC,aAAa,CAAC,KAAD,CAAvB;AACAD,EAAAA,GAAG,CAACE,kBAAJ,CAAuB,YAAvB,EAAqCJ,YAArC;AAEAK,EAAAA,IAAI,CAACH,GAAD,EAAMI,KAAN,CAAJ;AAEA,WAASA,KAAT,CAAeV,EAAf,EAAmB;AACjB,QAAIK,KAAK,GAAG,CAAZ,EAAe;AACb,UAAIM,GAAG,GAAGX,EAAE,CAACY,IAAH,CAAQV,MAAlB;AACAG,MAAAA,KAAK,IAAIM,GAAT;AACA,UAAIN,KAAK,IAAI,CAAb,EAAgB;AACdL,QAAAA,EAAE,CAACY,IAAH,GAAUZ,EAAE,CAACa,aAAH,CAAiB,CAAjB,EAAoBb,EAAE,CAACY,IAAH,CAAQV,MAAR,GAAiBG,KAArC,CAAV;AACD;AACF,KAND,MAMO;AACLL,MAAAA,EAAE,CAACY,IAAH,GAAU,EAAV;AACD;AACF;AAED,WAASH,IAAT,CAAcT,EAAd,EAAkBc,EAAlB,EAAsB;AACpB,QAAIC,IAAI,GAAGf,EAAE,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AA9B;AACD,OAFM,MAEA,IAAIvF,IAAI,KAAK,MAAb,EAAqB;AAC1BmG,QAAAA,SAAS,CAACG,UAAV,CAAqBC,WAArB,CAAiCJ,SAAjC;AACD;AACF,KAxQ0E;AAEzE,UAAMK,QAAQ,GAAG,GAAGnG,KAAH,CAASC,IAAT,CAAc8B,QAAQ,CAACqE,gBAAT,CAA0BhG,SAA1B,CAAd,CAAjB,CAFyE;AAKzE,SAAK4F,WAAL,GAAmB9C,UAAnB,CALyE;AAQzE,SAAKa,MAAL,GAAc,EAAE,GAAG/B,YAAL;AAAmB,SAAGmB;AAAtB,KAAd;AAEAgD,IAAAA,QAAQ,CAACE,GAAT,CAAa,CAACC,IAAD,EAAOC,KAAP,KAAiB;AAC5B,YAAMC,UAAU,GAAGC,IAAI,CAACC,KAAL,CAAWJ,IAAI,CAAChB,YAAL,CAAkB,aAAlB,CAAX,CAAnB;AACA,YAAMqB,YAAY,GAAGvD,MAArB;AAEA,YAAMwD,mBAAmB,GAAG,EAAE,GAAGD,YAAL;AAAmB,WAAGH;AAAtB,OAA5B;AAEA,WAAKhD,OAAL,GAAe;AACb+C,QAAAA,KADa;AAEbM,QAAAA,UAAU,EAAEP,IAAI,CAAC5E,SAFJ;AAGb,WAAGa,cAHU;AAIb,WAAGqE,mBAJU;AAKbpE,QAAAA,WAAW,EAAEoE,mBAAmB,CAACnF,OAApB,IAA+B,MAL/B;AAMbA,QAAAA,OAAO,EAAE6E;AANI,OAAf;AASA,WAAKjD,QAAL;AACD,KAhBD;AAiBD;AAlC2B;;;;"} \ No newline at end of file diff --git a/dist/js/showMore.esm.min.js b/dist/js/showMore.esm.min.js index e1d8278..bb6b558 100644 --- a/dist/js/showMore.esm.min.js +++ b/dist/js/showMore.esm.min.js @@ -1 +1 @@ -const t=(t,e)=>{let{rows:s,children:n}=t;const i="table"===e?s:n,l=[].slice.call(i).filter(t=>"hidden"===t.className).length;return 0!==l?" "+l:""},e=function(t,e){return void 0===e&&(e=!1),t.classList[e?"add":"remove"]("hidden")},s=(t,e)=>{for(let s in e)t.setAttribute(s,e[s])},n=t=>document.createElement(t),i={newLine:{match:/(\r\n|\n|\r)/gm,replace:""},space:{match:/\s\s+/gm,replace:" "},br:{match://gim,replace:""},html:{match:/(<((?!b|\/b|!strong|\/strong)[^>]+)>)/gi,replace:""}},l={typeElement:"span",more:!1,less:!1,number:!1,nobutton:!1,after:0,btnClass:"show-more-btn",btnClassAppend:null};class r{constructor(r,a){let{onMoreLess:o=(()=>{}),regex:h={},config:c}=void 0===a?{}:a;this.t=()=>{const{element:t,after:i,ellipsis:l,nobutton:r,limit:a,type:o}=this.s;s(t,{"aria-expanded":"false"});const h=a+i,c=!1===l?"":"...";if("text"===o){const e=t.innerHTML.trim();if(t.textContent.trim().length>h){let s=e;for(let t in this.i){const{match:e,replace:n}=this.i[t];t&&e&&(s=s.replace(e,n))}const i=((t,e)=>{let s=n("div");return s.insertAdjacentHTML("afterbegin",t),function t(e,s){let n=e.firstChild;do{3===n.nodeType?s(n):1===n.nodeType&&n.childNodes&&n.childNodes[0]&&t(n,s)}while(n=n.nextSibling)}(s,(function(t){if(e>0){let s=t.data.length;(e-=s)<=0&&(t.data=t.substringData(0,t.data.length+e))}else t.data=""})),s.innerHTML})(s,a-1).concat(c);if(t.textContent="",t.insertAdjacentHTML("beforeend",i),this.l(t,{...this.s,originalText:e,truncatedText:i}),r)return;this.o(this.s)}}if("list"===o||"table"===o){const s=this.h(t,o);if(s.length>h){for(let t=a;tt.addEventListener("click",this.p.bind(this,e)),this.m=e=>{let{element:i,number:l,less:r,more:a,type:o,btnClass:h,btnClassAppend:c}=e;const d=this.u?r||"":a||"",p=this.u?"collapse":"expand",f=!!this.u,m=n("button");return m.className=null==c?h:h+" "+c,s(m,{"aria-expanded":f,"aria-label":p,tabindex:0}),m.insertAdjacentHTML("beforeend",l?d+t(i,o):d),m},this.p=(t,s)=>{let{target:i}=s;const{element:l,type:r,limit:a,less:o,typeElement:h,originalText:c,truncatedText:d,btnClass:p}=t,f=i.classList.contains(p);if(!f)return;const m=l.getAttribute("aria-expanded");if(this.u="false"===m,"text"===r&&f&&(l.textContent="",l.insertAdjacentHTML("beforeend",this.u?c:d),o)){const e=n(h);e.classList.add("show-more-wrapper"),e.insertAdjacentElement("beforeend",this.m(t)),l.appendChild(e)}if("list"===r||"table"===r){const t=this.h(l,r);for(let s=0;s=a&&s=a;"false"===m?e(t[s]):n&&e(t[s],!0)}}r&&this.g({...t,target:i})},this.h=(t,e)=>"list"===e?[].slice.call(t.children):t.rows,this.o=t=>{const{type:e,element:s,more:i,typeElement:l}=t;if(i)if("table"===e)s.insertAdjacentElement("afterend",this.m(t));else{const e=n(l);e.classList.add("show-more-wrapper"),e.appendChild(this.m(t)),s.appendChild(e)}},this.g=e=>{const{element:n,type:i,less:l,more:r,number:a,target:o}=e,h=this.u?l:r,c=this.u?"expand":"collapse",d="table"===i?i:"the "+i,p=n.lastElementChild;s(n,{"aria-expanded":this.u}),s(o,{"aria-expanded":this.u,"aria-label":c+" "+d}),this.C(c,e),h?o.innerHTML=a?h+t(n,i):h:"table"===i?o.parentNode.removeChild(o):"list"===i&&p.parentNode.removeChild(p)};const d=[].slice.call(document.querySelectorAll(r));this.C=o,this.i={...i,...h},d.map((t,e)=>{const s=JSON.parse(t.getAttribute("data-config")),n={...c,...s};this.s={index:e,classArray:t.classList,...l,...n,typeElement:n.element||"span",element:t},this.t()})}}export{r as default}; +const t=(t,e)=>{let{rows:s,children:n}=t;const i="table"===e?s:n,l=[].slice.call(i).filter(t=>"hidden"===t.className).length;return 0!==l?" "+l:""},e=function(t,e){return void 0===e&&(e=!1),t.classList[e?"add":"remove"]("hidden")},s=(t,e)=>{for(let s in e)t.setAttribute(s,e[s])},n=t=>document.createElement(t),i={newLine:{match:/(\r\n|\n|\r)/gm,replace:""},space:{match:/\s\s+/gm,replace:" "},br:{match://gim,replace:""},html:{match:/(<((?!b|\/b|!strong|\/strong)[^>]+)>)/gi,replace:""}},l={typeElement:"span",more:!1,less:!1,number:!1,nobutton:!1,after:0,btnClass:"show-more-btn",btnClassAppend:null};class r{constructor(r,a){let{onMoreLess:o=(()=>{}),regex:h={},config:c}=void 0===a?{}:a;this.t=()=>{const{element:t,after:i,ellipsis:l,nobutton:r,limit:a,type:o}=this.s;s(t,{"aria-expanded":"false"});const h=a+i,c=!1===l?"":"...";if("text"===o){const e=t.innerHTML.trim();if(t.textContent.trim().length>h){let s=e;for(let t in this.i){const{match:e,replace:n}=this.i[t];t&&e&&(s=s.replace(e,n))}const i=((t,e)=>{let s=n("div");return s.insertAdjacentHTML("afterbegin",t),function t(e,s){let n=e.firstChild;do{3===n.nodeType?s(n):1===n.nodeType&&n.childNodes&&n.childNodes[0]&&t(n,s)}while(n=n.nextSibling)}(s,(function(t){if(e>0){let s=t.data.length;(e-=s)<=0&&(t.data=t.substringData(0,t.data.length+e))}else t.data=""})),s.innerHTML})(s,a-1).concat(c);if(t.textContent="",t.insertAdjacentHTML("beforeend",i),this.l(t,{...this.s,originalText:e,truncatedText:i}),r)return;this.o(this.s)}}if("list"===o||"table"===o){const s=this.h(t,o);if(s.length>h){for(let t=a;tt.addEventListener("click",this.p.bind(this,e)),this.m=e=>{let{element:i,number:l,less:r,more:a,type:o,btnClass:h,btnClassAppend:c}=e;const d=this.u?r||"":a||"",p=this.u?"collapse":"expand",f=!!this.u,m=n("button");return m.className=null==c?h:h+" "+c,s(m,{"aria-expanded":f,"aria-label":p,tabindex:0}),m.insertAdjacentHTML("beforeend",l?d+t(i,o):d),m},this.p=(t,s)=>{let{target:i}=s;const{element:l,type:r,limit:a,less:o,typeElement:h,originalText:c,truncatedText:d,btnClass:p}=t,f=i.classList.contains(p);if(!f)return;const m=l.getAttribute("aria-expanded");if(this.u="false"===m,"text"===r&&f&&(l.textContent="",l.insertAdjacentHTML("beforeend",this.u?c:d),o)){const e=n(h);e.classList.add("show-more-wrapper"),e.insertAdjacentElement("beforeend",this.m(t)),l.appendChild(e)}if("list"===r||"table"===r){const t=this.h(l,r);for(let s=0;s=a&&s=a;"false"===m?e(t[s]):n&&e(t[s],!0)}}r&&this.g({...t,target:i})},this.h=(t,e)=>"list"===e?[].slice.call(t.children):t.rows,this.o=t=>{const{type:e,element:s,more:i,typeElement:l}=t;if(i)if("table"===e)s.insertAdjacentElement("afterend",this.m(t));else{const e=n(l);e.classList.add("show-more-wrapper"),e.appendChild(this.m(t)),s.appendChild(e)}},this.g=e=>{const{element:n,type:i,less:l,more:r,number:a,target:o}=e,h=this.u?l:r,c=this.u?"expand":"collapse",d="table"===i?i:"the "+i,p=n.lastElementChild;s(n,{"aria-expanded":this.u}),s(o,{"aria-expanded":this.u,"aria-label":c+" "+d}),this.C(c,e),h?o.innerHTML=a?h+t(n,i):h:"table"===i?o.parentNode.removeChild(o):"list"===i&&p.parentNode.removeChild(p)};const d=[].slice.call(document.querySelectorAll(r));this.C=o,this.i={...i,...h},d.map((t,e)=>{const s=JSON.parse(t.getAttribute("data-config")),n={...c,...s};this.s={index:e,classArray:t.classList,...l,...n,typeElement:n.element||"span",element:t},this.t()})}}export{r as default}; diff --git a/dist/js/showMore.ie.min.js b/dist/js/showMore.ie.min.js index ae96879..b50fa07 100644 --- a/dist/js/showMore.ie.min.js +++ b/dist/js/showMore.ie.min.js @@ -1 +1 @@ -var ShowMore=function(){"use strict";var e=function(e,t){var n=e.rows,r=e.children,a="table"===t?n:r,i=[].slice.call(a).filter((function(e){return"hidden"===e.className})).length;return 0!==i?" "+i:""},t=function(e,t){return void 0===t&&(t=!1),e.classList[t?"add":"remove"]("hidden")},n=function(e,t){for(var n in t)e.setAttribute(n,t[n])},r=function(e){return document.createElement(e)},a={newLine:{match:/(\r\n|\n|\r)/gm,replace:""},space:{match:/\s\s+/gm,replace:" "},br:{match://gim,replace:""},html:{match:/(<((?!b|\/b|!strong|\/strong)[^>]+)>)/gi,replace:""}},i={typeElement:"span",more:!1,less:!1,number:!1,nobutton:!1,after:0,btnClass:"show-more-btn",btnClassAppend:null};return function(o,f){var l=this,s=void 0===f?{}:f,c=s.onMoreLess,u=void 0===c?function(){}:c,d=s.regex,v=void 0===d?{}:d,b=s.config;this.t=function(){var e=l.i,a=e.element,i=e.after,o=e.ellipsis,f=e.nobutton,s=e.limit,c=e.type;n(a,{"aria-expanded":"false"});var u=s+i,d=!1===o?"":"...";if("text"===c){var v=a.innerHTML.trim();if(a.textContent.trim().length>u){var b=v;for(var p in l.o){var h=l.o[p],m=h.match,x=h.replace;p&&m&&(b=b.replace(m,x))}var g=function(e,t){var n=r("div");return n.insertAdjacentHTML("afterbegin",e),function e(t,n){var r=t.firstChild;do{3===r.nodeType?n(r):1===r.nodeType&&r.childNodes&&r.childNodes[0]&&e(r,n)}while(r=r.nextSibling)}(n,(function(e){if(t>0){var n=e.data.length;(t-=n)<=0&&(e.data=e.substringData(0,e.data.length+t))}else e.data=""})),n.innerHTML}(b,s-1).concat(d);if(a.textContent="",a.insertAdjacentHTML("beforeend",g),l.l(a,Object.assign({},l.i,{originalText:v,truncatedText:g})),f)return;l.s(l.i)}}if("list"===c||"table"===c){var w=l.u(a,c);if(w.length>u){for(var O=s;O=f&&x=f;"false"===p?t(m[x]):g&&t(m[x],!0)}o&&l.m(Object.assign({},e,{target:a}))}},this.u=function(e,t){return"list"===t?[].slice.call(e.children):e.rows},this.s=function(e){var t=e.type,n=e.element,a=e.more,i=e.typeElement;if(a)if("table"===t)n.insertAdjacentElement("afterend",l.p(e));else{var o=r(i);o.classList.add("show-more-wrapper"),o.appendChild(l.p(e)),n.appendChild(o)}},this.m=function(t){var r=t.element,a=t.type,i=t.less,o=t.more,f=t.number,s=t.target,c=l.h?i:o,u=l.h?"expand":"collapse",d="table"===a?a:"the "+a,v=r.lastElementChild;n(r,{"aria-expanded":l.h}),n(s,{"aria-expanded":l.h,"aria-label":u+" "+d}),l.g(u,t),c?s.innerHTML=f?c+e(r,a):c:"table"===a?s.parentNode.removeChild(s):"list"===a&&v.parentNode.removeChild(v)};var p=[].slice.call(document.querySelectorAll(o));this.g=u,this.o=Object.assign({},a,v),p.map((function(e,t){var n=JSON.parse(e.getAttribute("data-config")),r=b,a=Object.assign({},r,n);l.i=Object.assign({index:t,classArray:e.classList},i,a,{typeElement:a.element||"span",element:e}),l.t()}))}}(); +var ShowMore=function(){"use strict";var e=function(e,t){var n=e.rows,r=e.children,a="table"===t?n:r,i=[].slice.call(a).filter((function(e){return"hidden"===e.className})).length;return 0!==i?" "+i:""},t=function(e,t){return void 0===t&&(t=!1),e.classList[t?"add":"remove"]("hidden")},n=function(e,t){for(var n in t)e.setAttribute(n,t[n])},r=function(e){return document.createElement(e)},a={newLine:{match:/(\r\n|\n|\r)/gm,replace:""},space:{match:/\s\s+/gm,replace:" "},br:{match://gim,replace:""},html:{match:/(<((?!b|\/b|!strong|\/strong)[^>]+)>)/gi,replace:""}},i={typeElement:"span",more:!1,less:!1,number:!1,nobutton:!1,after:0,btnClass:"show-more-btn",btnClassAppend:null};return function(o,f){var l=this,s=void 0===f?{}:f,c=s.onMoreLess,u=void 0===c?function(){}:c,d=s.regex,v=void 0===d?{}:d,b=s.config;this.t=function(){var e=l.i,a=e.element,i=e.after,o=e.ellipsis,f=e.nobutton,s=e.limit,c=e.type;n(a,{"aria-expanded":"false"});var u=s+i,d=!1===o?"":"...";if("text"===c){var v=a.innerHTML.trim();if(a.textContent.trim().length>u){var b=v;for(var p in l.o){var h=l.o[p],m=h.match,x=h.replace;p&&m&&(b=b.replace(m,x))}var g=function(e,t){var n=r("div");return n.insertAdjacentHTML("afterbegin",e),function e(t,n){var r=t.firstChild;do{3===r.nodeType?n(r):1===r.nodeType&&r.childNodes&&r.childNodes[0]&&e(r,n)}while(r=r.nextSibling)}(n,(function(e){if(t>0){var n=e.data.length;(t-=n)<=0&&(e.data=e.substringData(0,e.data.length+t))}else e.data=""})),n.innerHTML}(b,s-1).concat(d);if(a.textContent="",a.insertAdjacentHTML("beforeend",g),l.l(a,Object.assign({},l.i,{originalText:v,truncatedText:g})),f)return;l.s(l.i)}}if("list"===c||"table"===c){var w=l.u(a,c);if(w.length>u){for(var O=s;O=f&&x=f;"false"===p?t(m[x]):g&&t(m[x],!0)}o&&l.m(Object.assign({},e,{target:a}))}},this.u=function(e,t){return"list"===t?[].slice.call(e.children):e.rows},this.s=function(e){var t=e.type,n=e.element,a=e.more,i=e.typeElement;if(a)if("table"===t)n.insertAdjacentElement("afterend",l.p(e));else{var o=r(i);o.classList.add("show-more-wrapper"),o.appendChild(l.p(e)),n.appendChild(o)}},this.m=function(t){var r=t.element,a=t.type,i=t.less,o=t.more,f=t.number,s=t.target,c=l.h?i:o,u=l.h?"expand":"collapse",d="table"===a?a:"the "+a,v=r.lastElementChild;n(r,{"aria-expanded":l.h}),n(s,{"aria-expanded":l.h,"aria-label":u+" "+d}),l.g(u,t),c?s.innerHTML=f?c+e(r,a):c:"table"===a?s.parentNode.removeChild(s):"list"===a&&v.parentNode.removeChild(v)};var p=[].slice.call(document.querySelectorAll(o));this.g=u,this.o=Object.assign({},a,v),p.map((function(e,t){var n=JSON.parse(e.getAttribute("data-config")),r=b,a=Object.assign({},r,n);l.i=Object.assign({index:t,classArray:e.classList},i,a,{typeElement:a.element||"span",element:e}),l.t()}))}}(); diff --git a/dist/js/showMore.js b/dist/js/showMore.js index 5633468..290eddf 100644 --- a/dist/js/showMore.js +++ b/dist/js/showMore.js @@ -130,9 +130,11 @@ var ShowMore = (function () { for (let i = limit; i < items.length; i++) { addRemoveClass(items[i], true); } + if (!nobutton) { + this._addBtn(this._object); + } this._clickEvent(type === "list" ? element : element.nextElementSibling, this._object); if (nobutton) return; - this._addBtn(this._object); } } }; diff --git a/dist/js/showMore.js.map b/dist/js/showMore.js.map index 3860f65..a844581 100644 --- a/dist/js/showMore.js.map +++ b/dist/js/showMore.js.map @@ -1 +1 @@ -{"version":3,"file":"showMore.js","sources":["../../sources/utils/function.js","../../sources/utils/regex.js","../../sources/utils/defaults.js","../../sources/index.js"],"sourcesContent":["/**\r\n * Get hidden element\r\n *\r\n * @param {object} object\r\n * @param {String} type - type of element table | div\r\n * @returns\r\n */\r\nconst getNumber = ({ rows, children }, type) => {\r\n const elementType = type === \"table\" ? rows : children;\r\n\r\n const numbersElementHidden = [].slice\r\n .call(elementType)\r\n .filter((el) => el.className === \"hidden\").length;\r\n return numbersElementHidden !== 0 ? ` ${numbersElementHidden}` : \"\";\r\n};\r\n\r\n// https://stackoverflow.com/questions/6003271/substring-text-with-html-tags-in-javascript\r\n/**\r\n * Substring text width html tags\r\n *\r\n * @param {String} originalText - text with html tags\r\n * @param {String} count - limit of characters\r\n * @returns\r\n */\r\nconst htmlSubstr = (originalText, count) => {\r\n let div = createElement(\"div\");\r\n div.insertAdjacentHTML(\"afterbegin\", originalText);\r\n\r\n walk(div, track);\r\n\r\n function track(el) {\r\n if (count > 0) {\r\n let len = el.data.length;\r\n count -= len;\r\n if (count <= 0) {\r\n el.data = el.substringData(0, el.data.length + count);\r\n }\r\n } else {\r\n el.data = \"\";\r\n }\r\n }\r\n\r\n function walk(el, fn) {\r\n let node = el.firstChild;\r\n do {\r\n if (node.nodeType === 3) {\r\n fn(node);\r\n } else if (node.nodeType === 1 && node.childNodes && node.childNodes[0]) {\r\n walk(node, fn);\r\n }\r\n } while ((node = node.nextSibling));\r\n }\r\n return div.innerHTML;\r\n};\r\n\r\n/**\r\n * Add/remove class 'hidden' to element\r\n *\r\n * @param {HTMLElement} element\r\n * @param {String} type - type of element add or remove\r\n */\r\nconst addRemoveClass = (element, type = false) => {\r\n return element.classList[type ? \"add\" : \"remove\"](\"hidden\");\r\n};\r\n\r\n/**\r\n * Set attributes to element\r\n *\r\n * @param {HTMLElement} el\r\n * @param {Object} object\r\n */\r\nconst setAttributes = (el, object) => {\r\n for (let key in object) {\r\n el.setAttribute(key, object[key]);\r\n }\r\n};\r\n\r\n/**\r\n * Create element\r\n *\r\n * @param {String} type - type of element\r\n * @returns {HTMLElement}\r\n */\r\nconst createElement = (type) => document.createElement(type);\r\n\r\nexport { addRemoveClass, createElement, getNumber, htmlSubstr, setAttributes };\r\n","/**\r\n * Default regexes for validation\r\n */\r\nconst defaultRegex = {\r\n newLine: {\r\n match: /(\\r\\n|\\n|\\r)/gm,\r\n replace: \"\",\r\n },\r\n space: {\r\n match: /\\s\\s+/gm,\r\n replace: \" \",\r\n },\r\n br: {\r\n match: //gim,\r\n replace: \"\",\r\n },\r\n html: {\r\n match: /(<((?!b|\\/b|!strong|\\/strong)[^>]+)>)/gi,\r\n replace: \"\",\r\n },\r\n};\r\n\r\nexport default defaultRegex;\r\n","const defaultOptions = {\r\n typeElement: \"span\",\r\n more: false,\r\n less: false,\r\n number: false,\r\n nobutton: false,\r\n after: 0,\r\n btnClass: \"show-more-btn\",\r\n btnClassAppend: null,\r\n};\r\n\r\nexport default defaultOptions;\r\n","import {\r\n addRemoveClass,\r\n createElement,\r\n getNumber,\r\n htmlSubstr,\r\n setAttributes,\r\n} from \"./utils/function\";\r\nimport defaultRegex from \"./utils/regex\";\r\nimport defaultOptions from \"./utils/defaults\";\r\n\r\n/**\r\n * @class ShowMore\r\n */\r\nexport default class ShowMore {\r\n /**\r\n * Constructor\r\n *\r\n * @param {HTMLElement} className\r\n * @param {Object} object\r\n */\r\n constructor(className, { onMoreLess = () => {}, regex = {}, config } = {}) {\r\n // all html elements\r\n const elements = [].slice.call(document.querySelectorAll(className));\r\n\r\n // colback function\r\n this._onMoreLess = onMoreLess;\r\n\r\n // global regex\r\n this._regex = { ...defaultRegex, ...regex };\r\n\r\n elements.map((item, index) => {\r\n const configData = JSON.parse(item.getAttribute(\"data-config\"));\r\n const configGlobal = config;\r\n\r\n const configDataAndGlobal = { ...configGlobal, ...configData };\r\n\r\n this._object = {\r\n index,\r\n classArray: item.classList,\r\n ...defaultOptions,\r\n ...configDataAndGlobal,\r\n typeElement: configDataAndGlobal.element || \"span\",\r\n element: item,\r\n };\r\n\r\n this._initial();\r\n });\r\n }\r\n\r\n /**\r\n * Initail function\r\n *\r\n * @param {Object} object\r\n */\r\n _initial = () => {\r\n const { element, after, ellipsis, nobutton, limit, type } = this._object;\r\n // set default aria-expande to false\r\n setAttributes(element, { \"aria-expanded\": \"false\" });\r\n\r\n const limitCounts = limit + after;\r\n const ellips = ellipsis === false ? \"\" : \"...\";\r\n\r\n // console.log(nobutton);\r\n\r\n // text\r\n if (type === \"text\") {\r\n const originalText = element.innerHTML.trim();\r\n const elementText = element.textContent.trim();\r\n\r\n if (elementText.length > limitCounts) {\r\n let orgTexReg = originalText;\r\n\r\n for (let key in this._regex) {\r\n const { match, replace } = this._regex[key];\r\n if (key && match) orgTexReg = orgTexReg.replace(match, replace);\r\n }\r\n\r\n const truncatedText = htmlSubstr(orgTexReg, limit - 1).concat(ellips);\r\n\r\n element.textContent = \"\";\r\n element.insertAdjacentHTML(\"beforeend\", truncatedText);\r\n\r\n this._clickEvent(element, {\r\n ...this._object,\r\n originalText,\r\n truncatedText,\r\n });\r\n\r\n if (nobutton) return;\r\n this._addBtn(this._object);\r\n }\r\n }\r\n\r\n // list and table\r\n if (type === \"list\" || type === \"table\") {\r\n const items = this._getNumberCount(element, type);\r\n\r\n if (items.length > limitCounts) {\r\n for (let i = limit; i < items.length; i++) {\r\n addRemoveClass(items[i], true);\r\n }\r\n\r\n // add event click\r\n this._clickEvent(\r\n type === \"list\" ? element : element.nextElementSibling,\r\n this._object\r\n );\r\n\r\n if (nobutton) return;\r\n // add button to the list and table\r\n this._addBtn(this._object);\r\n }\r\n }\r\n };\r\n\r\n /**\r\n * Event click\r\n *\r\n * @param {HTMLElement} element\r\n * @param {Object} object\r\n */\r\n _clickEvent = (element, object) =>\r\n element.addEventListener(\"click\", this._handleEvent.bind(this, object));\r\n\r\n /**\r\n * Create button\r\n *\r\n * @param {Object} object\r\n * @returns HTMLElement\r\n */\r\n _createBtn = ({\r\n element,\r\n number,\r\n less,\r\n more,\r\n type,\r\n btnClass,\r\n btnClassAppend,\r\n }) => {\r\n const typeAria = this._checkExp ? less || \"\" : more || \"\";\r\n const label = this._checkExp ? \"collapse\" : \"expand\";\r\n const expanded = this._checkExp ? true : false;\r\n\r\n const button = createElement(\"button\");\r\n button.className =\r\n btnClassAppend == null ? btnClass : btnClass + \" \" + btnClassAppend;\r\n setAttributes(button, {\r\n \"aria-expanded\": expanded,\r\n \"aria-label\": label,\r\n tabindex: 0,\r\n });\r\n\r\n button.insertAdjacentHTML(\r\n \"beforeend\",\r\n number ? typeAria + getNumber(element, type) : typeAria\r\n );\r\n return button;\r\n };\r\n\r\n /**\r\n * Event handler\r\n *\r\n * @param {Object} object\r\n * @param {Event} event\r\n */\r\n _handleEvent = (object, { target }) => {\r\n const {\r\n element,\r\n type,\r\n limit,\r\n less,\r\n typeElement,\r\n originalText,\r\n truncatedText,\r\n btnClass,\r\n } = object;\r\n\r\n // check if the button is clicked\r\n const checkContainsClass = target.classList.contains(btnClass);\r\n\r\n if (!checkContainsClass) return;\r\n\r\n const ariaExpanded = element.getAttribute(\"aria-expanded\");\r\n this._checkExp = ariaExpanded === \"false\";\r\n\r\n // --------------------------------------------------\r\n // text\r\n if (type === \"text\" && checkContainsClass) {\r\n element.textContent = \"\";\r\n\r\n element.insertAdjacentHTML(\r\n \"beforeend\",\r\n this._checkExp ? originalText : truncatedText\r\n );\r\n\r\n if (less) {\r\n const el = createElement(typeElement);\r\n el.classList.add(\"show-more-wrapper\");\r\n el.insertAdjacentElement(\"beforeend\", this._createBtn(object));\r\n element.appendChild(el);\r\n }\r\n }\r\n\r\n // --------------------------------------------------\r\n // list and table\r\n if (type === \"list\" || type === \"table\") {\r\n const items = this._getNumberCount(element, type);\r\n\r\n for (let i = 0; i < items.length; i++) {\r\n const typeRemove =\r\n type === \"list\" ? i >= limit && i < items.length - 1 : i >= limit;\r\n\r\n if (ariaExpanded === \"false\") {\r\n addRemoveClass(items[i]);\r\n } else if (typeRemove) {\r\n addRemoveClass(items[i], true);\r\n }\r\n }\r\n }\r\n\r\n // set aria-expanded\r\n if (type) {\r\n this._setExpand({ ...object, target });\r\n }\r\n };\r\n\r\n _getNumberCount = (element, type) => {\r\n return type === \"list\" ? [].slice.call(element.children) : element.rows;\r\n };\r\n\r\n /**\r\n * Add button\r\n *\r\n * @param {Object} object\r\n */\r\n _addBtn = (object) => {\r\n const { type, element, more, typeElement } = object;\r\n\r\n if (!more) return;\r\n\r\n if (type === \"table\") {\r\n element.insertAdjacentElement(\"afterend\", this._createBtn(object));\r\n } else {\r\n const el = createElement(typeElement);\r\n el.classList.add(\"show-more-wrapper\");\r\n el.appendChild(this._createBtn(object));\r\n element.appendChild(el);\r\n }\r\n };\r\n\r\n /**\r\n * Set aria-expanded\r\n *\r\n * @param {Object} object\r\n */\r\n _setExpand = (object) => {\r\n const { element, type, less, more, number, target } = object;\r\n\r\n const typeAria = this._checkExp ? less : more;\r\n const aria = this._checkExp ? \"expand\" : \"collapse\";\r\n const ariaText = type === \"table\" ? type : `the ${type}`;\r\n const lastChild = element.lastElementChild;\r\n\r\n setAttributes(element, { \"aria-expanded\": this._checkExp });\r\n setAttributes(target, {\r\n \"aria-expanded\": this._checkExp,\r\n \"aria-label\": `${aria} ${ariaText}`,\r\n });\r\n\r\n // callback function on more/less\r\n this._onMoreLess(aria, object);\r\n\r\n if (typeAria) {\r\n target.innerHTML = number\r\n ? typeAria + getNumber(element, type)\r\n : typeAria;\r\n } else if (type === \"table\") {\r\n target.parentNode.removeChild(target);\r\n } else if (type === \"list\") {\r\n lastChild.parentNode.removeChild(lastChild);\r\n }\r\n };\r\n}\r\n"],"names":["getNumber","type","rows","children","elementType","numbersElementHidden","slice","call","filter","el","className","length","htmlSubstr","originalText","count","div","createElement","insertAdjacentHTML","walk","track","len","data","substringData","fn","node","firstChild","nodeType","childNodes","nextSibling","innerHTML","addRemoveClass","element","classList","setAttributes","object","key","setAttribute","document","defaultRegex","newLine","match","replace","space","br","html","defaultOptions","typeElement","more","less","number","nobutton","after","btnClass","btnClassAppend","ShowMore","constructor","onMoreLess","regex","config","_initial","ellipsis","limit","_object","limitCounts","ellips","trim","elementText","textContent","orgTexReg","_regex","truncatedText","concat","_clickEvent","_addBtn","items","_getNumberCount","i","nextElementSibling","addEventListener","_handleEvent","bind","_createBtn","typeAria","_checkExp","label","expanded","button","tabindex","target","checkContainsClass","contains","ariaExpanded","getAttribute","add","insertAdjacentElement","appendChild","typeRemove","_setExpand","aria","ariaText","lastChild","lastElementChild","_onMoreLess","parentNode","removeChild","elements","querySelectorAll","map","item","index","configData","JSON","parse","configGlobal","configDataAndGlobal","classArray"],"mappings":";;;EAOA,MAAMA,SAAS,GAAG,OAAqBC,IAArB,KAA8B;EAAA,MAA7B;EAAEC,IAAAA,IAAF;EAAQC,IAAAA;EAAR,GAA6B;EAC9C,QAAMC,WAAW,GAAGH,IAAI,KAAK,OAAT,GAAmBC,IAAnB,GAA0BC,QAA9C;EAEA,QAAME,oBAAoB,GAAG,GAAGC,KAAH,CAC1BC,IAD0B,CACrBH,WADqB,EAE1BI,MAF0B,CAElBC,EAAD,IAAQA,EAAE,CAACC,SAAH,KAAiB,QAFN,EAEgBC,MAF7C;EAGA,SAAON,oBAAoB,KAAK,CAAzB,SAAiCA,oBAAjC,GAA0D,EAAjE;EACD,CAPD;EAiBA,MAAMO,UAAU,GAAG,CAACC,YAAD,EAAeC,KAAf,KAAyB;EAC1C,MAAIC,GAAG,GAAGC,aAAa,CAAC,KAAD,CAAvB;EACAD,EAAAA,GAAG,CAACE,kBAAJ,CAAuB,YAAvB,EAAqCJ,YAArC;EAEAK,EAAAA,IAAI,CAACH,GAAD,EAAMI,KAAN,CAAJ;EAEA,WAASA,KAAT,CAAeV,EAAf,EAAmB;EACjB,QAAIK,KAAK,GAAG,CAAZ,EAAe;EACb,UAAIM,GAAG,GAAGX,EAAE,CAACY,IAAH,CAAQV,MAAlB;EACAG,MAAAA,KAAK,IAAIM,GAAT;EACA,UAAIN,KAAK,IAAI,CAAb,EAAgB;EACdL,QAAAA,EAAE,CAACY,IAAH,GAAUZ,EAAE,CAACa,aAAH,CAAiB,CAAjB,EAAoBb,EAAE,CAACY,IAAH,CAAQV,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,OAAD,EAAU9B,IAAV,CADC,GAErBiF,QAFJ;EAGD,OAJD,MAIO,IAAIjF,IAAI,KAAK,OAAb,EAAsB;EAC3BuF,QAAAA,MAAM,CAACe,UAAP,CAAkBC,WAAlB,CAA8BhB,MAA9B;EACD,OAFM,MAEA,IAAIvF,IAAI,KAAK,MAAb,EAAqB;EAC1BmG,QAAAA,SAAS,CAACG,UAAV,CAAqBC,WAArB,CAAiCJ,SAAjC;EACD;EACF,KArQ0E;EAEzE,UAAMK,QAAQ,GAAG,GAAGnG,KAAH,CAASC,IAAT,CAAc8B,QAAQ,CAACqE,gBAAT,CAA0BhG,SAA1B,CAAd,CAAjB,CAFyE;EAKzE,SAAK4F,WAAL,GAAmB9C,UAAnB,CALyE;EAQzE,SAAKa,MAAL,GAAc,EAAE,GAAG/B,YAAL;EAAmB,SAAGmB;EAAtB,KAAd;EAEAgD,IAAAA,QAAQ,CAACE,GAAT,CAAa,CAACC,IAAD,EAAOC,KAAP,KAAiB;EAC5B,YAAMC,UAAU,GAAGC,IAAI,CAACC,KAAL,CAAWJ,IAAI,CAAChB,YAAL,CAAkB,aAAlB,CAAX,CAAnB;EACA,YAAMqB,YAAY,GAAGvD,MAArB;EAEA,YAAMwD,mBAAmB,GAAG,EAAE,GAAGD,YAAL;EAAmB,WAAGH;EAAtB,OAA5B;EAEA,WAAKhD,OAAL,GAAe;EACb+C,QAAAA,KADa;EAEbM,QAAAA,UAAU,EAAEP,IAAI,CAAC5E,SAFJ;EAGb,WAAGa,cAHU;EAIb,WAAGqE,mBAJU;EAKbpE,QAAAA,WAAW,EAAEoE,mBAAmB,CAACnF,OAApB,IAA+B,MAL/B;EAMbA,QAAAA,OAAO,EAAE6E;EANI,OAAf;EASA,WAAKjD,QAAL;EACD,KAhBD;EAiBD;EAlC2B;;;;;;;;"} \ No newline at end of file +{"version":3,"file":"showMore.js","sources":["../../sources/utils/function.js","../../sources/utils/regex.js","../../sources/utils/defaults.js","../../sources/index.js"],"sourcesContent":["/**\r\n * Get hidden element\r\n *\r\n * @param {object} object\r\n * @param {String} type - type of element table | div\r\n * @returns\r\n */\r\nconst getNumber = ({ rows, children }, type) => {\r\n const elementType = type === \"table\" ? rows : children;\r\n\r\n const numbersElementHidden = [].slice\r\n .call(elementType)\r\n .filter((el) => el.className === \"hidden\").length;\r\n return numbersElementHidden !== 0 ? ` ${numbersElementHidden}` : \"\";\r\n};\r\n\r\n// https://stackoverflow.com/questions/6003271/substring-text-with-html-tags-in-javascript\r\n/**\r\n * Substring text width html tags\r\n *\r\n * @param {String} originalText - text with html tags\r\n * @param {String} count - limit of characters\r\n * @returns\r\n */\r\nconst htmlSubstr = (originalText, count) => {\r\n let div = createElement(\"div\");\r\n div.insertAdjacentHTML(\"afterbegin\", originalText);\r\n\r\n walk(div, track);\r\n\r\n function track(el) {\r\n if (count > 0) {\r\n let len = el.data.length;\r\n count -= len;\r\n if (count <= 0) {\r\n el.data = el.substringData(0, el.data.length + count);\r\n }\r\n } else {\r\n el.data = \"\";\r\n }\r\n }\r\n\r\n function walk(el, fn) {\r\n let node = el.firstChild;\r\n do {\r\n if (node.nodeType === 3) {\r\n fn(node);\r\n } else if (node.nodeType === 1 && node.childNodes && node.childNodes[0]) {\r\n walk(node, fn);\r\n }\r\n } while ((node = node.nextSibling));\r\n }\r\n return div.innerHTML;\r\n};\r\n\r\n/**\r\n * Add/remove class 'hidden' to element\r\n *\r\n * @param {HTMLElement} element\r\n * @param {String} type - type of element add or remove\r\n */\r\nconst addRemoveClass = (element, type = false) => {\r\n return element.classList[type ? \"add\" : \"remove\"](\"hidden\");\r\n};\r\n\r\n/**\r\n * Set attributes to element\r\n *\r\n * @param {HTMLElement} el\r\n * @param {Object} object\r\n */\r\nconst setAttributes = (el, object) => {\r\n for (let key in object) {\r\n el.setAttribute(key, object[key]);\r\n }\r\n};\r\n\r\n/**\r\n * Create element\r\n *\r\n * @param {String} type - type of element\r\n * @returns {HTMLElement}\r\n */\r\nconst createElement = (type) => document.createElement(type);\r\n\r\nexport { addRemoveClass, createElement, getNumber, htmlSubstr, setAttributes };\r\n","/**\r\n * Default regexes for validation\r\n */\r\nconst defaultRegex = {\r\n newLine: {\r\n match: /(\\r\\n|\\n|\\r)/gm,\r\n replace: \"\",\r\n },\r\n space: {\r\n match: /\\s\\s+/gm,\r\n replace: \" \",\r\n },\r\n br: {\r\n match: //gim,\r\n replace: \"\",\r\n },\r\n html: {\r\n match: /(<((?!b|\\/b|!strong|\\/strong)[^>]+)>)/gi,\r\n replace: \"\",\r\n },\r\n};\r\n\r\nexport default defaultRegex;\r\n","const defaultOptions = {\r\n typeElement: \"span\",\r\n more: false,\r\n less: false,\r\n number: false,\r\n nobutton: false,\r\n after: 0,\r\n btnClass: \"show-more-btn\",\r\n btnClassAppend: null,\r\n};\r\n\r\nexport default defaultOptions;\r\n","import {\r\n addRemoveClass,\r\n createElement,\r\n getNumber,\r\n htmlSubstr,\r\n setAttributes,\r\n} from \"./utils/function\";\r\nimport defaultRegex from \"./utils/regex\";\r\nimport defaultOptions from \"./utils/defaults\";\r\n\r\n/**\r\n * @class ShowMore\r\n */\r\nexport default class ShowMore {\r\n /**\r\n * Constructor\r\n *\r\n * @param {HTMLElement} className\r\n * @param {Object} object\r\n */\r\n constructor(className, { onMoreLess = () => {}, regex = {}, config } = {}) {\r\n // all html elements\r\n const elements = [].slice.call(document.querySelectorAll(className));\r\n\r\n // colback function\r\n this._onMoreLess = onMoreLess;\r\n\r\n // global regex\r\n this._regex = { ...defaultRegex, ...regex };\r\n\r\n elements.map((item, index) => {\r\n const configData = JSON.parse(item.getAttribute(\"data-config\"));\r\n const configGlobal = config;\r\n\r\n const configDataAndGlobal = { ...configGlobal, ...configData };\r\n\r\n this._object = {\r\n index,\r\n classArray: item.classList,\r\n ...defaultOptions,\r\n ...configDataAndGlobal,\r\n typeElement: configDataAndGlobal.element || \"span\",\r\n element: item,\r\n };\r\n\r\n this._initial();\r\n });\r\n }\r\n\r\n /**\r\n * Initail function\r\n *\r\n * @param {Object} object\r\n */\r\n _initial = () => {\r\n const { element, after, ellipsis, nobutton, limit, type } = this._object;\r\n // set default aria-expande to false\r\n setAttributes(element, { \"aria-expanded\": \"false\" });\r\n\r\n const limitCounts = limit + after;\r\n const ellips = ellipsis === false ? \"\" : \"...\";\r\n\r\n // console.log(nobutton);\r\n\r\n // text\r\n if (type === \"text\") {\r\n const originalText = element.innerHTML.trim();\r\n const elementText = element.textContent.trim();\r\n\r\n if (elementText.length > limitCounts) {\r\n let orgTexReg = originalText;\r\n\r\n for (let key in this._regex) {\r\n const { match, replace } = this._regex[key];\r\n if (key && match) orgTexReg = orgTexReg.replace(match, replace);\r\n }\r\n\r\n const truncatedText = htmlSubstr(orgTexReg, limit - 1).concat(ellips);\r\n\r\n element.textContent = \"\";\r\n element.insertAdjacentHTML(\"beforeend\", truncatedText);\r\n\r\n this._clickEvent(element, {\r\n ...this._object,\r\n originalText,\r\n truncatedText,\r\n });\r\n\r\n if (nobutton) return;\r\n this._addBtn(this._object);\r\n }\r\n }\r\n\r\n // list and table\r\n if (type === \"list\" || type === \"table\") {\r\n const items = this._getNumberCount(element, type);\r\n\r\n if (items.length > limitCounts) {\r\n for (let i = limit; i < items.length; i++) {\r\n addRemoveClass(items[i], true);\r\n }\r\n\r\n if (!nobutton) {\r\n // add button to the list and table\r\n this._addBtn(this._object);\r\n }\r\n\r\n // add event click\r\n this._clickEvent(\r\n type === \"list\" ? element : element.nextElementSibling,\r\n this._object\r\n );\r\n\r\n if (nobutton) return;\r\n }\r\n }\r\n };\r\n\r\n /**\r\n * Event click\r\n *\r\n * @param {HTMLElement} element\r\n * @param {Object} object\r\n */\r\n _clickEvent = (element, object) =>\r\n element.addEventListener(\"click\", this._handleEvent.bind(this, object));\r\n\r\n /**\r\n * Create button\r\n *\r\n * @param {Object} object\r\n * @returns HTMLElement\r\n */\r\n _createBtn = ({\r\n element,\r\n number,\r\n less,\r\n more,\r\n type,\r\n btnClass,\r\n btnClassAppend,\r\n }) => {\r\n const typeAria = this._checkExp ? less || \"\" : more || \"\";\r\n const label = this._checkExp ? \"collapse\" : \"expand\";\r\n const expanded = this._checkExp ? true : false;\r\n\r\n const button = createElement(\"button\");\r\n button.className =\r\n btnClassAppend == null ? btnClass : btnClass + \" \" + btnClassAppend;\r\n setAttributes(button, {\r\n \"aria-expanded\": expanded,\r\n \"aria-label\": label,\r\n tabindex: 0,\r\n });\r\n\r\n button.insertAdjacentHTML(\r\n \"beforeend\",\r\n number ? typeAria + getNumber(element, type) : typeAria\r\n );\r\n return button;\r\n };\r\n\r\n /**\r\n * Event handler\r\n *\r\n * @param {Object} object\r\n * @param {Event} event\r\n */\r\n _handleEvent = (object, { target }) => {\r\n const {\r\n element,\r\n type,\r\n limit,\r\n less,\r\n typeElement,\r\n originalText,\r\n truncatedText,\r\n btnClass,\r\n } = object;\r\n\r\n // check if the button is clicked\r\n const checkContainsClass = target.classList.contains(btnClass);\r\n\r\n if (!checkContainsClass) return;\r\n\r\n const ariaExpanded = element.getAttribute(\"aria-expanded\");\r\n this._checkExp = ariaExpanded === \"false\";\r\n\r\n // --------------------------------------------------\r\n // text\r\n if (type === \"text\" && checkContainsClass) {\r\n element.textContent = \"\";\r\n\r\n element.insertAdjacentHTML(\r\n \"beforeend\",\r\n this._checkExp ? originalText : truncatedText\r\n );\r\n\r\n if (less) {\r\n const el = createElement(typeElement);\r\n el.classList.add(\"show-more-wrapper\");\r\n el.insertAdjacentElement(\"beforeend\", this._createBtn(object));\r\n element.appendChild(el);\r\n }\r\n }\r\n\r\n // --------------------------------------------------\r\n // list and table\r\n if (type === \"list\" || type === \"table\") {\r\n const items = this._getNumberCount(element, type);\r\n\r\n for (let i = 0; i < items.length; i++) {\r\n const typeRemove =\r\n type === \"list\" ? i >= limit && i < items.length - 1 : i >= limit;\r\n\r\n if (ariaExpanded === \"false\") {\r\n addRemoveClass(items[i]);\r\n } else if (typeRemove) {\r\n addRemoveClass(items[i], true);\r\n }\r\n }\r\n }\r\n\r\n // set aria-expanded\r\n if (type) {\r\n this._setExpand({ ...object, target });\r\n }\r\n };\r\n\r\n _getNumberCount = (element, type) => {\r\n return type === \"list\" ? [].slice.call(element.children) : element.rows;\r\n };\r\n\r\n /**\r\n * Add button\r\n *\r\n * @param {Object} object\r\n */\r\n _addBtn = (object) => {\r\n const { type, element, more, typeElement } = object;\r\n\r\n if (!more) return;\r\n\r\n if (type === \"table\") {\r\n element.insertAdjacentElement(\"afterend\", this._createBtn(object));\r\n } else {\r\n const el = createElement(typeElement);\r\n el.classList.add(\"show-more-wrapper\");\r\n el.appendChild(this._createBtn(object));\r\n element.appendChild(el);\r\n }\r\n };\r\n\r\n /**\r\n * Set aria-expanded\r\n *\r\n * @param {Object} object\r\n */\r\n _setExpand = (object) => {\r\n const { element, type, less, more, number, target } = object;\r\n\r\n const typeAria = this._checkExp ? less : more;\r\n const aria = this._checkExp ? \"expand\" : \"collapse\";\r\n const ariaText = type === \"table\" ? type : `the ${type}`;\r\n const lastChild = element.lastElementChild;\r\n\r\n setAttributes(element, { \"aria-expanded\": this._checkExp });\r\n setAttributes(target, {\r\n \"aria-expanded\": this._checkExp,\r\n \"aria-label\": `${aria} ${ariaText}`,\r\n });\r\n\r\n // callback function on more/less\r\n this._onMoreLess(aria, object);\r\n\r\n if (typeAria) {\r\n target.innerHTML = number\r\n ? typeAria + getNumber(element, type)\r\n : typeAria;\r\n } else if (type === \"table\") {\r\n target.parentNode.removeChild(target);\r\n } else if (type === \"list\") {\r\n lastChild.parentNode.removeChild(lastChild);\r\n }\r\n };\r\n}\r\n"],"names":["getNumber","type","rows","children","elementType","numbersElementHidden","slice","call","filter","el","className","length","htmlSubstr","originalText","count","div","createElement","insertAdjacentHTML","walk","track","len","data","substringData","fn","node","firstChild","nodeType","childNodes","nextSibling","innerHTML","addRemoveClass","element","classList","setAttributes","object","key","setAttribute","document","defaultRegex","newLine","match","replace","space","br","html","defaultOptions","typeElement","more","less","number","nobutton","after","btnClass","btnClassAppend","ShowMore","constructor","onMoreLess","regex","config","_initial","ellipsis","limit","_object","limitCounts","ellips","trim","elementText","textContent","orgTexReg","_regex","truncatedText","concat","_clickEvent","_addBtn","items","_getNumberCount","i","nextElementSibling","addEventListener","_handleEvent","bind","_createBtn","typeAria","_checkExp","label","expanded","button","tabindex","target","checkContainsClass","contains","ariaExpanded","getAttribute","add","insertAdjacentElement","appendChild","typeRemove","_setExpand","aria","ariaText","lastChild","lastElementChild","_onMoreLess","parentNode","removeChild","elements","querySelectorAll","map","item","index","configData","JSON","parse","configGlobal","configDataAndGlobal","classArray"],"mappings":";;;EAOA,MAAMA,SAAS,GAAG,OAAqBC,IAArB,KAA8B;EAAA,MAA7B;EAAEC,IAAAA,IAAF;EAAQC,IAAAA;EAAR,GAA6B;EAC9C,QAAMC,WAAW,GAAGH,IAAI,KAAK,OAAT,GAAmBC,IAAnB,GAA0BC,QAA9C;EAEA,QAAME,oBAAoB,GAAG,GAAGC,KAAH,CAC1BC,IAD0B,CACrBH,WADqB,EAE1BI,MAF0B,CAElBC,EAAD,IAAQA,EAAE,CAACC,SAAH,KAAiB,QAFN,EAEgBC,MAF7C;EAGA,SAAON,oBAAoB,KAAK,CAAzB,SAAiCA,oBAAjC,GAA0D,EAAjE;EACD,CAPD;EAiBA,MAAMO,UAAU,GAAG,CAACC,YAAD,EAAeC,KAAf,KAAyB;EAC1C,MAAIC,GAAG,GAAGC,aAAa,CAAC,KAAD,CAAvB;EACAD,EAAAA,GAAG,CAACE,kBAAJ,CAAuB,YAAvB,EAAqCJ,YAArC;EAEAK,EAAAA,IAAI,CAACH,GAAD,EAAMI,KAAN,CAAJ;EAEA,WAASA,KAAT,CAAeV,EAAf,EAAmB;EACjB,QAAIK,KAAK,GAAG,CAAZ,EAAe;EACb,UAAIM,GAAG,GAAGX,EAAE,CAACY,IAAH,CAAQV,MAAlB;EACAG,MAAAA,KAAK,IAAIM,GAAT;EACA,UAAIN,KAAK,IAAI,CAAb,EAAgB;EACdL,QAAAA,EAAE,CAACY,IAAH,GAAUZ,EA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git a/dist/js/showMore.min.js b/dist/js/showMore.min.js index f511112..3e7e0d6 100644 --- a/dist/js/showMore.min.js +++ b/dist/js/showMore.min.js @@ -1 +1 @@ -var ShowMore=function(){"use strict";const t=(t,e)=>{let{rows:s,children:n}=t;const i="table"===e?s:n,r=[].slice.call(i).filter(t=>"hidden"===t.className).length;return 0!==r?" "+r:""},e=function(t,e){return void 0===e&&(e=!1),t.classList[e?"add":"remove"]("hidden")},s=(t,e)=>{for(let s in e)t.setAttribute(s,e[s])},n=t=>document.createElement(t),i={newLine:{match:/(\r\n|\n|\r)/gm,replace:""},space:{match:/\s\s+/gm,replace:" "},br:{match://gim,replace:""},html:{match:/(<((?!b|\/b|!strong|\/strong)[^>]+)>)/gi,replace:""}},r={typeElement:"span",more:!1,less:!1,number:!1,nobutton:!1,after:0,btnClass:"show-more-btn",btnClassAppend:null};return class{constructor(l,a){let{onMoreLess:o=(()=>{}),regex:h={},config:c}=void 0===a?{}:a;this.t=()=>{const{element:t,after:i,ellipsis:r,nobutton:l,limit:a,type:o}=this.s;s(t,{"aria-expanded":"false"});const h=a+i,c=!1===r?"":"...";if("text"===o){const e=t.innerHTML.trim();if(t.textContent.trim().length>h){let s=e;for(let t in this.i){const{match:e,replace:n}=this.i[t];t&&e&&(s=s.replace(e,n))}const i=((t,e)=>{let s=n("div");return s.insertAdjacentHTML("afterbegin",t),function t(e,s){let n=e.firstChild;do{3===n.nodeType?s(n):1===n.nodeType&&n.childNodes&&n.childNodes[0]&&t(n,s)}while(n=n.nextSibling)}(s,(function(t){if(e>0){let s=t.data.length;(e-=s)<=0&&(t.data=t.substringData(0,t.data.length+e))}else t.data=""})),s.innerHTML})(s,a-1).concat(c);if(t.textContent="",t.insertAdjacentHTML("beforeend",i),this.l(t,{...this.s,originalText:e,truncatedText:i}),l)return;this.o(this.s)}}if("list"===o||"table"===o){const s=this.h(t,o);if(s.length>h){for(let t=a;tt.addEventListener("click",this.p.bind(this,e)),this.m=e=>{let{element:i,number:r,less:l,more:a,type:o,btnClass:h,btnClassAppend:c}=e;const d=this.u?l||"":a||"",p=this.u?"collapse":"expand",f=!!this.u,m=n("button");return m.className=null==c?h:h+" "+c,s(m,{"aria-expanded":f,"aria-label":p,tabindex:0}),m.insertAdjacentHTML("beforeend",r?d+t(i,o):d),m},this.p=(t,s)=>{let{target:i}=s;const{element:r,type:l,limit:a,less:o,typeElement:h,originalText:c,truncatedText:d,btnClass:p}=t,f=i.classList.contains(p);if(!f)return;const m=r.getAttribute("aria-expanded");if(this.u="false"===m,"text"===l&&f&&(r.textContent="",r.insertAdjacentHTML("beforeend",this.u?c:d),o)){const e=n(h);e.classList.add("show-more-wrapper"),e.insertAdjacentElement("beforeend",this.m(t)),r.appendChild(e)}if("list"===l||"table"===l){const t=this.h(r,l);for(let s=0;s=a&&s=a;"false"===m?e(t[s]):n&&e(t[s],!0)}}l&&this.g({...t,target:i})},this.h=(t,e)=>"list"===e?[].slice.call(t.children):t.rows,this.o=t=>{const{type:e,element:s,more:i,typeElement:r}=t;if(i)if("table"===e)s.insertAdjacentElement("afterend",this.m(t));else{const e=n(r);e.classList.add("show-more-wrapper"),e.appendChild(this.m(t)),s.appendChild(e)}},this.g=e=>{const{element:n,type:i,less:r,more:l,number:a,target:o}=e,h=this.u?r:l,c=this.u?"expand":"collapse",d="table"===i?i:"the "+i,p=n.lastElementChild;s(n,{"aria-expanded":this.u}),s(o,{"aria-expanded":this.u,"aria-label":c+" "+d}),this.C(c,e),h?o.innerHTML=a?h+t(n,i):h:"table"===i?o.parentNode.removeChild(o):"list"===i&&p.parentNode.removeChild(p)};const d=[].slice.call(document.querySelectorAll(l));this.C=o,this.i={...i,...h},d.map((t,e)=>{const s=JSON.parse(t.getAttribute("data-config")),n={...c,...s};this.s={index:e,classArray:t.classList,...r,...n,typeElement:n.element||"span",element:t},this.t()})}}}(); +var ShowMore=function(){"use strict";const t=(t,e)=>{let{rows:s,children:n}=t;const i="table"===e?s:n,r=[].slice.call(i).filter(t=>"hidden"===t.className).length;return 0!==r?" "+r:""},e=function(t,e){return void 0===e&&(e=!1),t.classList[e?"add":"remove"]("hidden")},s=(t,e)=>{for(let s in e)t.setAttribute(s,e[s])},n=t=>document.createElement(t),i={newLine:{match:/(\r\n|\n|\r)/gm,replace:""},space:{match:/\s\s+/gm,replace:" "},br:{match://gim,replace:""},html:{match:/(<((?!b|\/b|!strong|\/strong)[^>]+)>)/gi,replace:""}},r={typeElement:"span",more:!1,less:!1,number:!1,nobutton:!1,after:0,btnClass:"show-more-btn",btnClassAppend:null};return class{constructor(l,a){let{onMoreLess:o=(()=>{}),regex:h={},config:c}=void 0===a?{}:a;this.t=()=>{const{element:t,after:i,ellipsis:r,nobutton:l,limit:a,type:o}=this.s;s(t,{"aria-expanded":"false"});const h=a+i,c=!1===r?"":"...";if("text"===o){const e=t.innerHTML.trim();if(t.textContent.trim().length>h){let s=e;for(let t in this.i){const{match:e,replace:n}=this.i[t];t&&e&&(s=s.replace(e,n))}const i=((t,e)=>{let s=n("div");return s.insertAdjacentHTML("afterbegin",t),function t(e,s){let n=e.firstChild;do{3===n.nodeType?s(n):1===n.nodeType&&n.childNodes&&n.childNodes[0]&&t(n,s)}while(n=n.nextSibling)}(s,(function(t){if(e>0){let s=t.data.length;(e-=s)<=0&&(t.data=t.substringData(0,t.data.length+e))}else t.data=""})),s.innerHTML})(s,a-1).concat(c);if(t.textContent="",t.insertAdjacentHTML("beforeend",i),this.l(t,{...this.s,originalText:e,truncatedText:i}),l)return;this.o(this.s)}}if("list"===o||"table"===o){const s=this.h(t,o);if(s.length>h){for(let t=a;tt.addEventListener("click",this.p.bind(this,e)),this.m=e=>{let{element:i,number:r,less:l,more:a,type:o,btnClass:h,btnClassAppend:c}=e;const d=this.u?l||"":a||"",p=this.u?"collapse":"expand",f=!!this.u,m=n("button");return m.className=null==c?h:h+" "+c,s(m,{"aria-expanded":f,"aria-label":p,tabindex:0}),m.insertAdjacentHTML("beforeend",r?d+t(i,o):d),m},this.p=(t,s)=>{let{target:i}=s;const{element:r,type:l,limit:a,less:o,typeElement:h,originalText:c,truncatedText:d,btnClass:p}=t,f=i.classList.contains(p);if(!f)return;const m=r.getAttribute("aria-expanded");if(this.u="false"===m,"text"===l&&f&&(r.textContent="",r.insertAdjacentHTML("beforeend",this.u?c:d),o)){const e=n(h);e.classList.add("show-more-wrapper"),e.insertAdjacentElement("beforeend",this.m(t)),r.appendChild(e)}if("list"===l||"table"===l){const t=this.h(r,l);for(let s=0;s=a&&s=a;"false"===m?e(t[s]):n&&e(t[s],!0)}}l&&this.g({...t,target:i})},this.h=(t,e)=>"list"===e?[].slice.call(t.children):t.rows,this.o=t=>{const{type:e,element:s,more:i,typeElement:r}=t;if(i)if("table"===e)s.insertAdjacentElement("afterend",this.m(t));else{const e=n(r);e.classList.add("show-more-wrapper"),e.appendChild(this.m(t)),s.appendChild(e)}},this.g=e=>{const{element:n,type:i,less:r,more:l,number:a,target:o}=e,h=this.u?r:l,c=this.u?"expand":"collapse",d="table"===i?i:"the "+i,p=n.lastElementChild;s(n,{"aria-expanded":this.u}),s(o,{"aria-expanded":this.u,"aria-label":c+" "+d}),this.C(c,e),h?o.innerHTML=a?h+t(n,i):h:"table"===i?o.parentNode.removeChild(o):"list"===i&&p.parentNode.removeChild(p)};const d=[].slice.call(document.querySelectorAll(l));this.C=o,this.i={...i,...h},d.map((t,e)=>{const s=JSON.parse(t.getAttribute("data-config")),n={...c,...s};this.s={index:e,classArray:t.classList,...r,...n,typeElement:n.element||"span",element:t},this.t()})}}}(); diff --git a/dist/js/showMore.umd.js b/dist/js/showMore.umd.js index 6233bdb..a6c2671 100644 --- a/dist/js/showMore.umd.js +++ b/dist/js/showMore.umd.js @@ -133,9 +133,11 @@ for (let i = limit; i < items.length; i++) { addRemoveClass(items[i], true); } + if (!nobutton) { + this._addBtn(this._object); + } this._clickEvent(type === "list" ? element : element.nextElementSibling, this._object); if (nobutton) return; - this._addBtn(this._object); } } }; diff --git a/dist/js/showMore.umd.js.map b/dist/js/showMore.umd.js.map index a2c955c..c3160b3 100644 --- a/dist/js/showMore.umd.js.map +++ b/dist/js/showMore.umd.js.map @@ -1 +1 @@ -{"version":3,"file":"showMore.umd.js","sources":["../../sources/utils/function.js","../../sources/utils/regex.js","../../sources/utils/defaults.js","../../sources/index.js"],"sourcesContent":["/**\r\n * Get hidden element\r\n *\r\n * @param {object} object\r\n * @param {String} type - type of element table | div\r\n * @returns\r\n */\r\nconst getNumber = ({ rows, children }, type) => {\r\n const elementType = type === \"table\" ? rows : children;\r\n\r\n const numbersElementHidden = [].slice\r\n .call(elementType)\r\n .filter((el) => el.className === \"hidden\").length;\r\n return numbersElementHidden !== 0 ? ` ${numbersElementHidden}` : \"\";\r\n};\r\n\r\n// https://stackoverflow.com/questions/6003271/substring-text-with-html-tags-in-javascript\r\n/**\r\n * Substring text width html tags\r\n *\r\n * @param {String} originalText - text with html tags\r\n * @param {String} count - limit of characters\r\n * @returns\r\n */\r\nconst htmlSubstr = (originalText, count) => {\r\n let div = createElement(\"div\");\r\n div.insertAdjacentHTML(\"afterbegin\", originalText);\r\n\r\n walk(div, track);\r\n\r\n function track(el) {\r\n if (count > 0) {\r\n let len = el.data.length;\r\n count -= len;\r\n if (count <= 0) {\r\n el.data = el.substringData(0, el.data.length + count);\r\n }\r\n } else {\r\n el.data = \"\";\r\n }\r\n }\r\n\r\n function walk(el, fn) {\r\n let node = el.firstChild;\r\n do {\r\n if (node.nodeType === 3) {\r\n fn(node);\r\n } else if (node.nodeType === 1 && node.childNodes && node.childNodes[0]) {\r\n walk(node, fn);\r\n }\r\n } while ((node = node.nextSibling));\r\n }\r\n return div.innerHTML;\r\n};\r\n\r\n/**\r\n * Add/remove class 'hidden' to element\r\n *\r\n * @param {HTMLElement} element\r\n * @param {String} type - type of element add or remove\r\n */\r\nconst addRemoveClass = (element, type = false) => {\r\n return element.classList[type ? \"add\" : \"remove\"](\"hidden\");\r\n};\r\n\r\n/**\r\n * Set attributes to element\r\n *\r\n * @param {HTMLElement} el\r\n * @param {Object} object\r\n */\r\nconst setAttributes = (el, object) => {\r\n for (let key in object) {\r\n el.setAttribute(key, object[key]);\r\n }\r\n};\r\n\r\n/**\r\n * Create element\r\n *\r\n * @param {String} type - type of element\r\n * @returns {HTMLElement}\r\n */\r\nconst createElement = (type) => document.createElement(type);\r\n\r\nexport { addRemoveClass, createElement, getNumber, htmlSubstr, setAttributes };\r\n","/**\r\n * Default regexes for validation\r\n */\r\nconst defaultRegex = {\r\n newLine: {\r\n match: /(\\r\\n|\\n|\\r)/gm,\r\n replace: \"\",\r\n },\r\n space: {\r\n match: /\\s\\s+/gm,\r\n replace: \" \",\r\n },\r\n br: {\r\n match: //gim,\r\n replace: \"\",\r\n },\r\n html: {\r\n match: /(<((?!b|\\/b|!strong|\\/strong)[^>]+)>)/gi,\r\n replace: \"\",\r\n },\r\n};\r\n\r\nexport default defaultRegex;\r\n","const defaultOptions = {\r\n typeElement: \"span\",\r\n more: false,\r\n less: false,\r\n number: false,\r\n nobutton: false,\r\n after: 0,\r\n btnClass: \"show-more-btn\",\r\n btnClassAppend: null,\r\n};\r\n\r\nexport default defaultOptions;\r\n","import {\r\n addRemoveClass,\r\n createElement,\r\n getNumber,\r\n htmlSubstr,\r\n setAttributes,\r\n} from \"./utils/function\";\r\nimport defaultRegex from \"./utils/regex\";\r\nimport defaultOptions from \"./utils/defaults\";\r\n\r\n/**\r\n * @class ShowMore\r\n */\r\nexport default class ShowMore {\r\n /**\r\n * Constructor\r\n *\r\n * @param {HTMLElement} className\r\n * @param {Object} object\r\n */\r\n constructor(className, { onMoreLess = () => {}, regex = {}, config } = {}) {\r\n // all html elements\r\n const elements = [].slice.call(document.querySelectorAll(className));\r\n\r\n // colback function\r\n this._onMoreLess = onMoreLess;\r\n\r\n // global regex\r\n this._regex = { ...defaultRegex, ...regex };\r\n\r\n elements.map((item, index) => {\r\n const configData = JSON.parse(item.getAttribute(\"data-config\"));\r\n const configGlobal = config;\r\n\r\n const configDataAndGlobal = { ...configGlobal, ...configData };\r\n\r\n this._object = {\r\n index,\r\n classArray: item.classList,\r\n ...defaultOptions,\r\n ...configDataAndGlobal,\r\n typeElement: configDataAndGlobal.element || \"span\",\r\n element: item,\r\n };\r\n\r\n this._initial();\r\n });\r\n }\r\n\r\n /**\r\n * Initail function\r\n *\r\n * @param {Object} object\r\n */\r\n _initial = () => {\r\n const { element, after, ellipsis, nobutton, limit, type } = this._object;\r\n // set default aria-expande to false\r\n setAttributes(element, { \"aria-expanded\": \"false\" });\r\n\r\n const limitCounts = limit + after;\r\n const ellips = ellipsis === false ? \"\" : \"...\";\r\n\r\n // console.log(nobutton);\r\n\r\n // text\r\n if (type === \"text\") {\r\n const originalText = element.innerHTML.trim();\r\n const elementText = element.textContent.trim();\r\n\r\n if (elementText.length > limitCounts) {\r\n let orgTexReg = originalText;\r\n\r\n for (let key in this._regex) {\r\n const { match, replace } = this._regex[key];\r\n if (key && match) orgTexReg = orgTexReg.replace(match, replace);\r\n }\r\n\r\n const truncatedText = htmlSubstr(orgTexReg, limit - 1).concat(ellips);\r\n\r\n element.textContent = \"\";\r\n element.insertAdjacentHTML(\"beforeend\", truncatedText);\r\n\r\n this._clickEvent(element, {\r\n ...this._object,\r\n originalText,\r\n truncatedText,\r\n });\r\n\r\n if (nobutton) return;\r\n this._addBtn(this._object);\r\n }\r\n }\r\n\r\n // list and table\r\n if (type === \"list\" || type === \"table\") {\r\n const items = this._getNumberCount(element, type);\r\n\r\n if (items.length > limitCounts) {\r\n for (let i = limit; i < items.length; i++) {\r\n addRemoveClass(items[i], true);\r\n }\r\n\r\n // add event click\r\n this._clickEvent(\r\n type === \"list\" ? element : element.nextElementSibling,\r\n this._object\r\n );\r\n\r\n if (nobutton) return;\r\n // add button to the list and table\r\n this._addBtn(this._object);\r\n }\r\n }\r\n };\r\n\r\n /**\r\n * Event click\r\n *\r\n * @param {HTMLElement} element\r\n * @param {Object} object\r\n */\r\n _clickEvent = (element, object) =>\r\n element.addEventListener(\"click\", this._handleEvent.bind(this, object));\r\n\r\n /**\r\n * Create button\r\n *\r\n * @param {Object} object\r\n * @returns HTMLElement\r\n */\r\n _createBtn = ({\r\n element,\r\n number,\r\n less,\r\n more,\r\n type,\r\n btnClass,\r\n btnClassAppend,\r\n }) => {\r\n const typeAria = this._checkExp ? less || \"\" : more || \"\";\r\n const label = this._checkExp ? \"collapse\" : \"expand\";\r\n const expanded = this._checkExp ? true : false;\r\n\r\n const button = createElement(\"button\");\r\n button.className =\r\n btnClassAppend == null ? btnClass : btnClass + \" \" + btnClassAppend;\r\n setAttributes(button, {\r\n \"aria-expanded\": expanded,\r\n \"aria-label\": label,\r\n tabindex: 0,\r\n });\r\n\r\n button.insertAdjacentHTML(\r\n \"beforeend\",\r\n number ? typeAria + getNumber(element, type) : typeAria\r\n );\r\n return button;\r\n };\r\n\r\n /**\r\n * Event handler\r\n *\r\n * @param {Object} object\r\n * @param {Event} event\r\n */\r\n _handleEvent = (object, { target }) => {\r\n const {\r\n element,\r\n type,\r\n limit,\r\n less,\r\n typeElement,\r\n originalText,\r\n truncatedText,\r\n btnClass,\r\n } = object;\r\n\r\n // check if the button is clicked\r\n const checkContainsClass = target.classList.contains(btnClass);\r\n\r\n if (!checkContainsClass) return;\r\n\r\n const ariaExpanded = element.getAttribute(\"aria-expanded\");\r\n this._checkExp = ariaExpanded === \"false\";\r\n\r\n // --------------------------------------------------\r\n // text\r\n if (type === \"text\" && checkContainsClass) {\r\n element.textContent = \"\";\r\n\r\n element.insertAdjacentHTML(\r\n \"beforeend\",\r\n this._checkExp ? originalText : truncatedText\r\n );\r\n\r\n if (less) {\r\n const el = createElement(typeElement);\r\n el.classList.add(\"show-more-wrapper\");\r\n el.insertAdjacentElement(\"beforeend\", this._createBtn(object));\r\n element.appendChild(el);\r\n }\r\n }\r\n\r\n // --------------------------------------------------\r\n // list and table\r\n if (type === \"list\" || type === \"table\") {\r\n const items = this._getNumberCount(element, type);\r\n\r\n for (let i = 0; i < items.length; i++) {\r\n const typeRemove =\r\n type === \"list\" ? i >= limit && i < items.length - 1 : i >= limit;\r\n\r\n if (ariaExpanded === \"false\") {\r\n addRemoveClass(items[i]);\r\n } else if (typeRemove) {\r\n addRemoveClass(items[i], true);\r\n }\r\n }\r\n }\r\n\r\n // set aria-expanded\r\n if (type) {\r\n this._setExpand({ ...object, target });\r\n }\r\n };\r\n\r\n _getNumberCount = (element, type) => {\r\n return type === \"list\" ? [].slice.call(element.children) : element.rows;\r\n };\r\n\r\n /**\r\n * Add button\r\n *\r\n * @param {Object} object\r\n */\r\n _addBtn = (object) => {\r\n const { type, element, more, typeElement } = object;\r\n\r\n if (!more) return;\r\n\r\n if (type === \"table\") {\r\n element.insertAdjacentElement(\"afterend\", this._createBtn(object));\r\n } else {\r\n const el = createElement(typeElement);\r\n el.classList.add(\"show-more-wrapper\");\r\n el.appendChild(this._createBtn(object));\r\n element.appendChild(el);\r\n }\r\n };\r\n\r\n /**\r\n * Set aria-expanded\r\n *\r\n * @param {Object} object\r\n */\r\n _setExpand = (object) => {\r\n const { element, type, less, more, number, target } = object;\r\n\r\n const typeAria = this._checkExp ? less : more;\r\n const aria = this._checkExp ? \"expand\" : \"collapse\";\r\n const ariaText = type === \"table\" ? type : `the ${type}`;\r\n const lastChild = element.lastElementChild;\r\n\r\n setAttributes(element, { \"aria-expanded\": this._checkExp });\r\n setAttributes(target, {\r\n \"aria-expanded\": this._checkExp,\r\n \"aria-label\": `${aria} ${ariaText}`,\r\n });\r\n\r\n // callback function on more/less\r\n this._onMoreLess(aria, object);\r\n\r\n if (typeAria) {\r\n target.innerHTML = number\r\n ? typeAria + getNumber(element, type)\r\n : typeAria;\r\n } else if (type === \"table\") {\r\n target.parentNode.removeChild(target);\r\n } else if (type === \"list\") {\r\n lastChild.parentNode.removeChild(lastChild);\r\n }\r\n };\r\n}\r\n"],"names":["getNumber","type","rows","children","elementType","numbersElementHidden","slice","call","filter","el","className","length","htmlSubstr","originalText","count","div","createElement","insertAdjacentHTML","walk","track","len","data","substringData","fn","node","firstChild","nodeType","childNodes","nextSibling","innerHTML","addRemoveClass","element","classList","setAttributes","object","key","setAttribute","document","defaultRegex","newLine","match","replace","space","br","html","defaultOptions","typeElement","more","less","number","nobutton","after","btnClass","btnClassAppend","ShowMore","constructor","onMoreLess","regex","config","_initial","ellipsis","limit","_object","limitCounts","ellips","trim","elementText","textContent","orgTexReg","_regex","truncatedText","concat","_clickEvent","_addBtn","items","_getNumberCount","i","nextElementSibling","addEventListener","_handleEvent","bind","_createBtn","typeAria","_checkExp","label","expanded","button","tabindex","target","checkContainsClass","contains","ariaExpanded","getAttribute","add","insertAdjacentElement","appendChild","typeRemove","_setExpand","aria","ariaText","lastChild","lastElementChild","_onMoreLess","parentNode","removeChild","elements","querySelectorAll","map","item","index","configData","JSON","parse","configGlobal","configDataAndGlobal","classArray"],"mappings":";;;;;;EAOA,MAAMA,SAAS,GAAG,OAAqBC,IAArB,KAA8B;EAAA,MAA7B;EAAEC,IAAAA,IAAF;EAAQC,IAAAA;EAAR,GAA6B;EAC9C,QAAMC,WAAW,GAAGH,IAAI,KAAK,OAAT,GAAmBC,IAAnB,GAA0BC,QAA9C;EAEA,QAAME,oBAAoB,GAAG,GAAGC,KAAH,CAC1BC,IAD0B,CACrBH,WADqB,EAE1BI,MAF0B,CAElBC,EAAD,IAAQA,EAAE,CAACC,SAAH,KAAiB,QAFN,EAEgBC,MAF7C;EAGA,SAAON,oBAAoB,KAAK,CAAzB,SAAiCA,oBAAjC,GAA0D,EAAjE;EACD,CAPD;EAiBA,MAAMO,UAAU,GAAG,CAACC,YAAD,EAAeC,KAAf,KAAyB;EAC1C,MAAIC,GAAG,GAAGC,aAAa,CAAC,KAAD,CAAvB;EACAD,EAAAA,GAAG,CAACE,kBAAJ,CAAuB,YAAvB,EAAqCJ,YAArC;EAEAK,EAAAA,IAAI,CAACH,GAAD,EAAMI,KAAN,CAAJ;EAEA,WAASA,KAAT,CAAeV,EAAf,EAAmB;EACjB,QAAIK,KAAK,GAAG,CAAZ,EAAe;EACb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F,OAApB,IAA+B,MAL/B;EAMbA,QAAAA,OAAO,EAAE6E;EANI,OAAf;EASA,WAAKjD,QAAL;EACD,KAhBD;EAiBD;EAlC2B;;;;;;;;"} \ No newline at end of file +{"version":3,"file":"showMore.umd.js","sources":["../../sources/utils/function.js","../../sources/utils/regex.js","../../sources/utils/defaults.js","../../sources/index.js"],"sourcesContent":["/**\r\n * Get hidden element\r\n *\r\n * @param {object} object\r\n * @param {String} type - type of element table | div\r\n * @returns\r\n */\r\nconst getNumber = ({ rows, children }, type) => {\r\n const elementType = type === \"table\" ? rows : children;\r\n\r\n const numbersElementHidden = [].slice\r\n .call(elementType)\r\n .filter((el) => el.className === \"hidden\").length;\r\n return numbersElementHidden !== 0 ? ` ${numbersElementHidden}` : \"\";\r\n};\r\n\r\n// https://stackoverflow.com/questions/6003271/substring-text-with-html-tags-in-javascript\r\n/**\r\n * Substring text width html tags\r\n *\r\n * @param {String} originalText - text with html tags\r\n * @param {String} count - limit of characters\r\n * @returns\r\n */\r\nconst htmlSubstr = (originalText, count) => {\r\n let div = createElement(\"div\");\r\n div.insertAdjacentHTML(\"afterbegin\", originalText);\r\n\r\n walk(div, track);\r\n\r\n function track(el) {\r\n if (count > 0) {\r\n let len = el.data.length;\r\n count -= len;\r\n if (count <= 0) {\r\n el.data = el.substringData(0, el.data.length + count);\r\n }\r\n } else {\r\n el.data = \"\";\r\n }\r\n }\r\n\r\n function walk(el, fn) {\r\n let node = el.firstChild;\r\n do {\r\n if (node.nodeType === 3) {\r\n fn(node);\r\n } else if (node.nodeType === 1 && node.childNodes && node.childNodes[0]) {\r\n walk(node, fn);\r\n }\r\n } while ((node = node.nextSibling));\r\n }\r\n return div.innerHTML;\r\n};\r\n\r\n/**\r\n * Add/remove class 'hidden' to element\r\n *\r\n * @param {HTMLElement} element\r\n * @param {String} type - type of element add or remove\r\n */\r\nconst addRemoveClass = (element, type = false) => {\r\n return element.classList[type ? \"add\" : \"remove\"](\"hidden\");\r\n};\r\n\r\n/**\r\n * Set attributes to element\r\n *\r\n * @param {HTMLElement} el\r\n * @param {Object} object\r\n */\r\nconst setAttributes = (el, object) => {\r\n for (let key in object) {\r\n el.setAttribute(key, object[key]);\r\n }\r\n};\r\n\r\n/**\r\n * Create element\r\n *\r\n * @param {String} type - type of element\r\n * @returns {HTMLElement}\r\n */\r\nconst createElement = (type) => document.createElement(type);\r\n\r\nexport { addRemoveClass, createElement, getNumber, htmlSubstr, setAttributes };\r\n","/**\r\n * Default regexes for validation\r\n */\r\nconst defaultRegex = {\r\n newLine: {\r\n match: /(\\r\\n|\\n|\\r)/gm,\r\n replace: \"\",\r\n },\r\n space: {\r\n match: /\\s\\s+/gm,\r\n replace: \" \",\r\n },\r\n br: {\r\n match: //gim,\r\n replace: \"\",\r\n },\r\n html: {\r\n match: /(<((?!b|\\/b|!strong|\\/strong)[^>]+)>)/gi,\r\n replace: \"\",\r\n },\r\n};\r\n\r\nexport default defaultRegex;\r\n","const defaultOptions = {\r\n typeElement: \"span\",\r\n more: false,\r\n less: false,\r\n number: false,\r\n nobutton: false,\r\n after: 0,\r\n btnClass: \"show-more-btn\",\r\n btnClassAppend: null,\r\n};\r\n\r\nexport default defaultOptions;\r\n","import {\r\n addRemoveClass,\r\n createElement,\r\n getNumber,\r\n htmlSubstr,\r\n setAttributes,\r\n} from \"./utils/function\";\r\nimport defaultRegex from \"./utils/regex\";\r\nimport defaultOptions from \"./utils/defaults\";\r\n\r\n/**\r\n * @class ShowMore\r\n */\r\nexport default class ShowMore {\r\n /**\r\n * Constructor\r\n *\r\n * @param {HTMLElement} className\r\n * @param {Object} object\r\n */\r\n constructor(className, { onMoreLess = () => {}, regex = {}, config } = {}) {\r\n // all html elements\r\n const elements = [].slice.call(document.querySelectorAll(className));\r\n\r\n // colback function\r\n this._onMoreLess = onMoreLess;\r\n\r\n // global regex\r\n this._regex = { ...defaultRegex, ...regex };\r\n\r\n elements.map((item, index) => {\r\n const configData = JSON.parse(item.getAttribute(\"data-config\"));\r\n const configGlobal = config;\r\n\r\n const configDataAndGlobal = { ...configGlobal, ...configData };\r\n\r\n this._object = {\r\n index,\r\n classArray: item.classList,\r\n ...defaultOptions,\r\n ...configDataAndGlobal,\r\n typeElement: configDataAndGlobal.element || \"span\",\r\n element: item,\r\n };\r\n\r\n this._initial();\r\n });\r\n }\r\n\r\n /**\r\n * Initail function\r\n *\r\n * @param {Object} object\r\n */\r\n _initial = () => {\r\n const { element, after, ellipsis, nobutton, limit, type } = this._object;\r\n // set default aria-expande to false\r\n setAttributes(element, { \"aria-expanded\": \"false\" });\r\n\r\n const limitCounts = limit + after;\r\n const ellips = ellipsis === false ? \"\" : \"...\";\r\n\r\n // console.log(nobutton);\r\n\r\n // text\r\n if (type === \"text\") {\r\n const originalText = element.innerHTML.trim();\r\n const elementText = element.textContent.trim();\r\n\r\n if (elementText.length > limitCounts) {\r\n let orgTexReg = originalText;\r\n\r\n for (let key in this._regex) {\r\n const { match, replace } = this._regex[key];\r\n if (key && match) orgTexReg = orgTexReg.replace(match, replace);\r\n }\r\n\r\n const truncatedText = htmlSubstr(orgTexReg, limit - 1).concat(ellips);\r\n\r\n element.textContent = \"\";\r\n element.insertAdjacentHTML(\"beforeend\", truncatedText);\r\n\r\n this._clickEvent(element, {\r\n ...this._object,\r\n originalText,\r\n truncatedText,\r\n });\r\n\r\n if (nobutton) return;\r\n this._addBtn(this._object);\r\n }\r\n }\r\n\r\n // list and table\r\n if (type === \"list\" || type === \"table\") {\r\n const items = this._getNumberCount(element, type);\r\n\r\n if (items.length > limitCounts) {\r\n for (let i = limit; i < items.length; i++) {\r\n addRemoveClass(items[i], true);\r\n }\r\n\r\n if (!nobutton) {\r\n // add button to the list and table\r\n this._addBtn(this._object);\r\n }\r\n\r\n // add event click\r\n this._clickEvent(\r\n type === \"list\" ? element : element.nextElementSibling,\r\n this._object\r\n );\r\n\r\n if (nobutton) return;\r\n }\r\n }\r\n };\r\n\r\n /**\r\n * Event click\r\n *\r\n * @param {HTMLElement} element\r\n * @param {Object} object\r\n */\r\n _clickEvent = (element, object) =>\r\n element.addEventListener(\"click\", this._handleEvent.bind(this, object));\r\n\r\n /**\r\n * Create button\r\n *\r\n * @param {Object} object\r\n * @returns HTMLElement\r\n */\r\n _createBtn = ({\r\n element,\r\n number,\r\n less,\r\n more,\r\n type,\r\n btnClass,\r\n btnClassAppend,\r\n }) => {\r\n const typeAria = this._checkExp ? less || \"\" : more || \"\";\r\n const label = this._checkExp ? \"collapse\" : \"expand\";\r\n const expanded = this._checkExp ? true : false;\r\n\r\n const button = createElement(\"button\");\r\n button.className =\r\n btnClassAppend == null ? btnClass : btnClass + \" \" + btnClassAppend;\r\n setAttributes(button, {\r\n \"aria-expanded\": expanded,\r\n \"aria-label\": label,\r\n tabindex: 0,\r\n });\r\n\r\n button.insertAdjacentHTML(\r\n \"beforeend\",\r\n number ? typeAria + getNumber(element, type) : typeAria\r\n );\r\n return button;\r\n };\r\n\r\n /**\r\n * Event handler\r\n *\r\n * @param {Object} object\r\n * @param {Event} event\r\n */\r\n _handleEvent = (object, { target }) => {\r\n const {\r\n element,\r\n type,\r\n limit,\r\n less,\r\n typeElement,\r\n originalText,\r\n truncatedText,\r\n btnClass,\r\n } = object;\r\n\r\n // check if the button is clicked\r\n const checkContainsClass = target.classList.contains(btnClass);\r\n\r\n if (!checkContainsClass) return;\r\n\r\n const ariaExpanded = element.getAttribute(\"aria-expanded\");\r\n this._checkExp = ariaExpanded === \"false\";\r\n\r\n // --------------------------------------------------\r\n // text\r\n if (type === \"text\" && checkContainsClass) {\r\n element.textContent = \"\";\r\n\r\n element.insertAdjacentHTML(\r\n \"beforeend\",\r\n this._checkExp ? originalText : truncatedText\r\n );\r\n\r\n if (less) {\r\n const el = createElement(typeElement);\r\n el.classList.add(\"show-more-wrapper\");\r\n el.insertAdjacentElement(\"beforeend\", this._createBtn(object));\r\n element.appendChild(el);\r\n }\r\n }\r\n\r\n // --------------------------------------------------\r\n // list and table\r\n if (type === \"list\" || type === \"table\") {\r\n const items = this._getNumberCount(element, type);\r\n\r\n for (let i = 0; i < items.length; i++) {\r\n const typeRemove =\r\n type === \"list\" ? i >= limit && i < items.length - 1 : i >= limit;\r\n\r\n if (ariaExpanded === \"false\") {\r\n addRemoveClass(items[i]);\r\n } else if (typeRemove) {\r\n addRemoveClass(items[i], true);\r\n }\r\n }\r\n }\r\n\r\n // set aria-expanded\r\n if (type) {\r\n this._setExpand({ ...object, target });\r\n }\r\n };\r\n\r\n _getNumberCount = (element, type) => {\r\n return type === \"list\" ? [].slice.call(element.children) : element.rows;\r\n };\r\n\r\n /**\r\n * Add button\r\n *\r\n * @param {Object} object\r\n */\r\n _addBtn = (object) => {\r\n const { type, element, more, typeElement } = object;\r\n\r\n if (!more) return;\r\n\r\n if (type === \"table\") {\r\n element.insertAdjacentElement(\"afterend\", this._createBtn(object));\r\n } else {\r\n const el = createElement(typeElement);\r\n el.classList.add(\"show-more-wrapper\");\r\n el.appendChild(this._createBtn(object));\r\n element.appendChild(el);\r\n }\r\n };\r\n\r\n /**\r\n * Set aria-expanded\r\n *\r\n * @param {Object} object\r\n */\r\n _setExpand = (object) => {\r\n const { element, type, less, more, number, target } = object;\r\n\r\n const typeAria = this._checkExp ? less : more;\r\n const aria = this._checkExp ? \"expand\" : \"collapse\";\r\n const ariaText = type === \"table\" ? type : `the ${type}`;\r\n const lastChild = element.lastElementChild;\r\n\r\n setAttributes(element, { \"aria-expanded\": this._checkExp });\r\n setAttributes(target, {\r\n \"aria-expanded\": this._checkExp,\r\n \"aria-label\": `${aria} ${ariaText}`,\r\n });\r\n\r\n // callback function on more/less\r\n this._onMoreLess(aria, object);\r\n\r\n if (typeAria) {\r\n target.innerHTML = number\r\n ? typeAria + getNumber(element, type)\r\n : typeAria;\r\n } else if (type === \"table\") {\r\n target.parentNode.removeChild(target);\r\n } else if (type === \"list\") {\r\n lastChild.parentNode.removeChild(lastChild);\r\n }\r\n };\r\n}\r\n"],"names":["getNumber","type","rows","children","elementType","numbersElementHidden","slice","call","filter","el","className","length","htmlSubstr","originalText","count","div","createElement","insertAdjacentHTML","walk","track","len","data","substringData","fn","node","firstChild","nodeType","childNodes","nextSibling","innerHTML","addRemoveClass","element","classList","setAttributes","object","key","setAttribute","document","defaultRegex","newLine","match","replace","space","br","html","defaultOptions","typeElement","more","less","number","nobutton","after","btnClass","btnClassAppend","ShowMore","constructor","onMoreLess","regex","config","_initial","ellipsis","limit","_object","limitCounts","ellips","trim","elementText","textContent","orgTexReg","_regex","truncatedText","concat","_clickEvent","_addBtn","items","_getNumberCount","i","nextElementSibling","addEventListener","_handleEvent","bind","_createBtn","typeAria","_checkExp","label","expanded","button","tabindex","target","checkContainsClass","contains","ariaExpanded","getAttribute","add","insertAdjacentElement","appendChild","typeRemove","_setExpand","aria","ariaText","lastChild","lastElementChild","_onMoreLess","parentNode","removeChild","elements","querySelectorAll","map","item","index","configData","JSON","parse","configGlobal","configDataAndGlobal","classArray"],"mappings":";;;;;;EAOA,MAAMA,SAAS,GAAG,OAAqBC,IAArB,KAA8B;EAAA,MAA7B;EAAEC,IAAAA,IAAF;EAAQC,IAAAA;EAAR,GAA6B;EAC9C,QAAMC,WAAW,GAAGH,IAAI,KAAK,OAAT,GAAmBC,IAAnB,GAA0BC,QAA9C;EAEA,QAAME,oBAAoB,GAAG,GAAGC,KAAH,CAC1BC,IAD0B,CACrBH,WADqB,EAE1BI,MAF0B,CAElBC,EAAD,IAAQA,EAAE,CAACC,SAAH,KAAiB,QAFN,EAEgBC,MAF7C;EAGA,SAAON,oBAAoB,KAAK,CAAzB,SAAiCA,oBAAjC,GAA0D,EAAjE;EACD,CAPD;EAiBA,MAAMO,UAAU,GAAG,CAACC,YAAD,EAAeC,KAAf,KAAyB;EAC1C,MAAIC,GAAG,GAAGC,aAAa,CAAC,KAAD,CAAvB;EACAD,EAAAA,GAAG,CAACE,kBAAJ,CAAuB,YAAvB,EAAqCJ,YAArC;EAEAK,EAAAA,IAAI,CAACH,GAAD,EAAMI,KAAN,CAAJ;EAEA,WAAS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I,CAAC5E,SAFJ;EAGb,WAAGa,cAHU;EAIb,WAAGqE,mBAJU;EAKbpE,QAAAA,WAAW,EAAEoE,mBAAmB,CAACnF,OAApB,IAA+B,MAL/B;EAMbA,QAAAA,OAAO,EAAE6E;EANI,OAAf;EASA,WAAKjD,QAAL;EACD,KAhBD;EAiBD;EAlC2B;;;;;;;;"} \ No newline at end of file diff --git a/dist/js/showMore.umd.min.js b/dist/js/showMore.umd.min.js index 499ba02..a636afd 100644 --- a/dist/js/showMore.umd.min.js +++ b/dist/js/showMore.umd.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).ShowMore=t()}(this,(function(){"use strict";const e=(e,t)=>{let{rows:s,children:n}=e;const i="table"===t?s:n,l=[].slice.call(i).filter(e=>"hidden"===e.className).length;return 0!==l?" "+l:""},t=function(e,t){return void 0===t&&(t=!1),e.classList[t?"add":"remove"]("hidden")},s=(e,t)=>{for(let s in t)e.setAttribute(s,t[s])},n=e=>document.createElement(e),i={newLine:{match:/(\r\n|\n|\r)/gm,replace:""},space:{match:/\s\s+/gm,replace:" "},br:{match://gim,replace:""},html:{match:/(<((?!b|\/b|!strong|\/strong)[^>]+)>)/gi,replace:""}},l={typeElement:"span",more:!1,less:!1,number:!1,nobutton:!1,after:0,btnClass:"show-more-btn",btnClassAppend:null};return class{constructor(r,o){let{onMoreLess:a=(()=>{}),regex:h={},config:c}=void 0===o?{}:o;this.t=()=>{const{element:e,after:i,ellipsis:l,nobutton:r,limit:o,type:a}=this.s;s(e,{"aria-expanded":"false"});const h=o+i,c=!1===l?"":"...";if("text"===a){const t=e.innerHTML.trim();if(e.textContent.trim().length>h){let s=t;for(let e in this.i){const{match:t,replace:n}=this.i[e];e&&t&&(s=s.replace(t,n))}const i=((e,t)=>{let s=n("div");return s.insertAdjacentHTML("afterbegin",e),function e(t,s){let n=t.firstChild;do{3===n.nodeType?s(n):1===n.nodeType&&n.childNodes&&n.childNodes[0]&&e(n,s)}while(n=n.nextSibling)}(s,(function(e){if(t>0){let s=e.data.length;(t-=s)<=0&&(e.data=e.substringData(0,e.data.length+t))}else e.data=""})),s.innerHTML})(s,o-1).concat(c);if(e.textContent="",e.insertAdjacentHTML("beforeend",i),this.l(e,{...this.s,originalText:t,truncatedText:i}),r)return;this.o(this.s)}}if("list"===a||"table"===a){const s=this.h(e,a);if(s.length>h){for(let e=o;ee.addEventListener("click",this.p.bind(this,t)),this.m=t=>{let{element:i,number:l,less:r,more:o,type:a,btnClass:h,btnClassAppend:c}=t;const f=this.u?r||"":o||"",d=this.u?"collapse":"expand",p=!!this.u,m=n("button");return m.className=null==c?h:h+" "+c,s(m,{"aria-expanded":p,"aria-label":d,tabindex:0}),m.insertAdjacentHTML("beforeend",l?f+e(i,a):f),m},this.p=(e,s)=>{let{target:i}=s;const{element:l,type:r,limit:o,less:a,typeElement:h,originalText:c,truncatedText:f,btnClass:d}=e,p=i.classList.contains(d);if(!p)return;const m=l.getAttribute("aria-expanded");if(this.u="false"===m,"text"===r&&p&&(l.textContent="",l.insertAdjacentHTML("beforeend",this.u?c:f),a)){const t=n(h);t.classList.add("show-more-wrapper"),t.insertAdjacentElement("beforeend",this.m(e)),l.appendChild(t)}if("list"===r||"table"===r){const e=this.h(l,r);for(let s=0;s=o&&s=o;"false"===m?t(e[s]):n&&t(e[s],!0)}}r&&this.g({...e,target:i})},this.h=(e,t)=>"list"===t?[].slice.call(e.children):e.rows,this.o=e=>{const{type:t,element:s,more:i,typeElement:l}=e;if(i)if("table"===t)s.insertAdjacentElement("afterend",this.m(e));else{const t=n(l);t.classList.add("show-more-wrapper"),t.appendChild(this.m(e)),s.appendChild(t)}},this.g=t=>{const{element:n,type:i,less:l,more:r,number:o,target:a}=t,h=this.u?l:r,c=this.u?"expand":"collapse",f="table"===i?i:"the "+i,d=n.lastElementChild;s(n,{"aria-expanded":this.u}),s(a,{"aria-expanded":this.u,"aria-label":c+" "+f}),this.T(c,t),h?a.innerHTML=o?h+e(n,i):h:"table"===i?a.parentNode.removeChild(a):"list"===i&&d.parentNode.removeChild(d)};const f=[].slice.call(document.querySelectorAll(r));this.T=a,this.i={...i,...h},f.map((e,t)=>{const s=JSON.parse(e.getAttribute("data-config")),n={...c,...s};this.s={index:t,classArray:e.classList,...l,...n,typeElement:n.element||"span",element:e},this.t()})}}})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).ShowMore=t()}(this,(function(){"use strict";const e=(e,t)=>{let{rows:s,children:n}=e;const i="table"===t?s:n,l=[].slice.call(i).filter(e=>"hidden"===e.className).length;return 0!==l?" "+l:""},t=function(e,t){return void 0===t&&(t=!1),e.classList[t?"add":"remove"]("hidden")},s=(e,t)=>{for(let s in t)e.setAttribute(s,t[s])},n=e=>document.createElement(e),i={newLine:{match:/(\r\n|\n|\r)/gm,replace:""},space:{match:/\s\s+/gm,replace:" "},br:{match://gim,replace:""},html:{match:/(<((?!b|\/b|!strong|\/strong)[^>]+)>)/gi,replace:""}},l={typeElement:"span",more:!1,less:!1,number:!1,nobutton:!1,after:0,btnClass:"show-more-btn",btnClassAppend:null};return class{constructor(r,o){let{onMoreLess:a=(()=>{}),regex:h={},config:c}=void 0===o?{}:o;this.t=()=>{const{element:e,after:i,ellipsis:l,nobutton:r,limit:o,type:a}=this.s;s(e,{"aria-expanded":"false"});const h=o+i,c=!1===l?"":"...";if("text"===a){const t=e.innerHTML.trim();if(e.textContent.trim().length>h){let s=t;for(let e in this.i){const{match:t,replace:n}=this.i[e];e&&t&&(s=s.replace(t,n))}const i=((e,t)=>{let s=n("div");return s.insertAdjacentHTML("afterbegin",e),function e(t,s){let n=t.firstChild;do{3===n.nodeType?s(n):1===n.nodeType&&n.childNodes&&n.childNodes[0]&&e(n,s)}while(n=n.nextSibling)}(s,(function(e){if(t>0){let s=e.data.length;(t-=s)<=0&&(e.data=e.substringData(0,e.data.length+t))}else e.data=""})),s.innerHTML})(s,o-1).concat(c);if(e.textContent="",e.insertAdjacentHTML("beforeend",i),this.l(e,{...this.s,originalText:t,truncatedText:i}),r)return;this.o(this.s)}}if("list"===a||"table"===a){const s=this.h(e,a);if(s.length>h){for(let e=o;ee.addEventListener("click",this.p.bind(this,t)),this.m=t=>{let{element:i,number:l,less:r,more:o,type:a,btnClass:h,btnClassAppend:c}=t;const f=this.u?r||"":o||"",d=this.u?"collapse":"expand",p=!!this.u,m=n("button");return m.className=null==c?h:h+" "+c,s(m,{"aria-expanded":p,"aria-label":d,tabindex:0}),m.insertAdjacentHTML("beforeend",l?f+e(i,a):f),m},this.p=(e,s)=>{let{target:i}=s;const{element:l,type:r,limit:o,less:a,typeElement:h,originalText:c,truncatedText:f,btnClass:d}=e,p=i.classList.contains(d);if(!p)return;const m=l.getAttribute("aria-expanded");if(this.u="false"===m,"text"===r&&p&&(l.textContent="",l.insertAdjacentHTML("beforeend",this.u?c:f),a)){const t=n(h);t.classList.add("show-more-wrapper"),t.insertAdjacentElement("beforeend",this.m(e)),l.appendChild(t)}if("list"===r||"table"===r){const e=this.h(l,r);for(let s=0;s=o&&s=o;"false"===m?t(e[s]):n&&t(e[s],!0)}}r&&this.g({...e,target:i})},this.h=(e,t)=>"list"===t?[].slice.call(e.children):e.rows,this.o=e=>{const{type:t,element:s,more:i,typeElement:l}=e;if(i)if("table"===t)s.insertAdjacentElement("afterend",this.m(e));else{const t=n(l);t.classList.add("show-more-wrapper"),t.appendChild(this.m(e)),s.appendChild(t)}},this.g=t=>{const{element:n,type:i,less:l,more:r,number:o,target:a}=t,h=this.u?l:r,c=this.u?"expand":"collapse",f="table"===i?i:"the "+i,d=n.lastElementChild;s(n,{"aria-expanded":this.u}),s(a,{"aria-expanded":this.u,"aria-label":c+" "+f}),this.T(c,t),h?a.innerHTML=o?h+e(n,i):h:"table"===i?a.parentNode.removeChild(a):"list"===i&&d.parentNode.removeChild(d)};const f=[].slice.call(document.querySelectorAll(r));this.T=a,this.i={...i,...h},f.map((e,t)=>{const s=JSON.parse(e.getAttribute("data-config")),n={...c,...s};this.s={index:t,classArray:e.classList,...l,...n,typeElement:n.element||"span",element:e},this.t()})}}})); diff --git a/docs/showMore.min.js b/docs/showMore.min.js index f3ad3b1..bc96608 100644 --- a/docs/showMore.min.js +++ b/docs/showMore.min.js @@ -1,2 +1,2 @@ -var ShowMore=function(){"use strict";const t=(t,e)=>{let{rows:s,children:n}=t;const i="table"===e?s:n,r=[].slice.call(i).filter(t=>"hidden"===t.className).length;return 0!==r?" "+r:""},e=function(t,e){return void 0===e&&(e=!1),t.classList[e?"add":"remove"]("hidden")},s=(t,e)=>{for(let s in e)t.setAttribute(s,e[s])},n=t=>document.createElement(t),i={newLine:{match:/(\r\n|\n|\r)/gm,replace:""},space:{match:/\s\s+/gm,replace:" "},br:{match://gim,replace:""},html:{match:/(<((?!b|\/b|!strong|\/strong)[^>]+)>)/gi,replace:""}},r={typeElement:"span",more:!1,less:!1,number:!1,nobutton:!1,after:0,btnClass:"show-more-btn",btnClassAppend:null};return class{constructor(l,a){let{onMoreLess:o=(()=>{}),regex:h={},config:c}=void 0===a?{}:a;this.t=()=>{const{element:t,after:i,ellipsis:r,nobutton:l,limit:a,type:o}=this.s;s(t,{"aria-expanded":"false"});const h=a+i,c=!1===r?"":"...";if("text"===o){const e=t.innerHTML.trim();if(t.textContent.trim().length>h){let s=e;for(let t in this.i){const{match:e,replace:n}=this.i[t];t&&e&&(s=s.replace(e,n))}const i=((t,e)=>{let s=n("div");return s.insertAdjacentHTML("afterbegin",t),function t(e,s){let n=e.firstChild;do{3===n.nodeType?s(n):1===n.nodeType&&n.childNodes&&n.childNodes[0]&&t(n,s)}while(n=n.nextSibling)}(s,(function(t){if(e>0){let s=t.data.length;(e-=s)<=0&&(t.data=t.substringData(0,t.data.length+e))}else t.data=""})),s.innerHTML})(s,a-1).concat(c);if(t.textContent="",t.insertAdjacentHTML("beforeend",i),this.l(t,{...this.s,originalText:e,truncatedText:i}),l)return;this.o(this.s)}}if("list"===o||"table"===o){const s=this.h(t,o);if(s.length>h){for(let t=a;tt.addEventListener("click",this.p.bind(this,e)),this.m=e=>{let{element:i,number:r,less:l,more:a,type:o,btnClass:h,btnClassAppend:c}=e;const d=this.u?l||"":a||"",p=this.u?"collapse":"expand",f=!!this.u,m=n("button");return m.className=null==c?h:h+" "+c,s(m,{"aria-expanded":f,"aria-label":p,tabindex:0}),m.insertAdjacentHTML("beforeend",r?d+t(i,o):d),m},this.p=(t,s)=>{let{target:i}=s;const{element:r,type:l,limit:a,less:o,typeElement:h,originalText:c,truncatedText:d,btnClass:p}=t,f=i.classList.contains(p);if(!f)return;const m=r.getAttribute("aria-expanded");if(this.u="false"===m,"text"===l&&f&&(r.textContent="",r.insertAdjacentHTML("beforeend",this.u?c:d),o)){const e=n(h);e.classList.add("show-more-wrapper"),e.insertAdjacentElement("beforeend",this.m(t)),r.appendChild(e)}if("list"===l||"table"===l){const t=this.h(r,l);for(let s=0;s=a&&s=a;"false"===m?e(t[s]):n&&e(t[s],!0)}}l&&this.g({...t,target:i})},this.h=(t,e)=>"list"===e?[].slice.call(t.children):t.rows,this.o=t=>{const{type:e,element:s,more:i,typeElement:r}=t;if(i)if("table"===e)s.insertAdjacentElement("afterend",this.m(t));else{const e=n(r);e.classList.add("show-more-wrapper"),e.appendChild(this.m(t)),s.appendChild(e)}},this.g=e=>{const{element:n,type:i,less:r,more:l,number:a,target:o}=e,h=this.u?r:l,c=this.u?"expand":"collapse",d="table"===i?i:"the "+i,p=n.lastElementChild;s(n,{"aria-expanded":this.u}),s(o,{"aria-expanded":this.u,"aria-label":c+" "+d}),this.C(c,e),h?o.innerHTML=a?h+t(n,i):h:"table"===i?o.parentNode.removeChild(o):"list"===i&&p.parentNode.removeChild(p)};const d=[].slice.call(document.querySelectorAll(l));this.C=o,this.i={...i,...h},d.map((t,e)=>{const s=JSON.parse(t.getAttribute("data-config")),n={...c,...s};this.s={index:e,classArray:t.classList,...r,...n,typeElement:n.element||"span",element:t},this.t()})}}}(); +var ShowMore=function(){"use strict";const t=(t,e)=>{let{rows:s,children:n}=t;const i="table"===e?s:n,r=[].slice.call(i).filter(t=>"hidden"===t.className).length;return 0!==r?" "+r:""},e=function(t,e){return void 0===e&&(e=!1),t.classList[e?"add":"remove"]("hidden")},s=(t,e)=>{for(let s in e)t.setAttribute(s,e[s])},n=t=>document.createElement(t),i={newLine:{match:/(\r\n|\n|\r)/gm,replace:""},space:{match:/\s\s+/gm,replace:" "},br:{match://gim,replace:""},html:{match:/(<((?!b|\/b|!strong|\/strong)[^>]+)>)/gi,replace:""}},r={typeElement:"span",more:!1,less:!1,number:!1,nobutton:!1,after:0,btnClass:"show-more-btn",btnClassAppend:null};return class{constructor(l,a){let{onMoreLess:o=(()=>{}),regex:h={},config:c}=void 0===a?{}:a;this.t=()=>{const{element:t,after:i,ellipsis:r,nobutton:l,limit:a,type:o}=this.s;s(t,{"aria-expanded":"false"});const h=a+i,c=!1===r?"":"...";if("text"===o){const e=t.innerHTML.trim();if(t.textContent.trim().length>h){let s=e;for(let t in this.i){const{match:e,replace:n}=this.i[t];t&&e&&(s=s.replace(e,n))}const i=((t,e)=>{let s=n("div");return s.insertAdjacentHTML("afterbegin",t),function t(e,s){let n=e.firstChild;do{3===n.nodeType?s(n):1===n.nodeType&&n.childNodes&&n.childNodes[0]&&t(n,s)}while(n=n.nextSibling)}(s,(function(t){if(e>0){let s=t.data.length;(e-=s)<=0&&(t.data=t.substringData(0,t.data.length+e))}else t.data=""})),s.innerHTML})(s,a-1).concat(c);if(t.textContent="",t.insertAdjacentHTML("beforeend",i),this.l(t,{...this.s,originalText:e,truncatedText:i}),l)return;this.o(this.s)}}if("list"===o||"table"===o){const s=this.h(t,o);if(s.length>h){for(let t=a;tt.addEventListener("click",this.p.bind(this,e)),this.m=e=>{let{element:i,number:r,less:l,more:a,type:o,btnClass:h,btnClassAppend:c}=e;const d=this.u?l||"":a||"",p=this.u?"collapse":"expand",f=!!this.u,m=n("button");return m.className=null==c?h:h+" "+c,s(m,{"aria-expanded":f,"aria-label":p,tabindex:0}),m.insertAdjacentHTML("beforeend",r?d+t(i,o):d),m},this.p=(t,s)=>{let{target:i}=s;const{element:r,type:l,limit:a,less:o,typeElement:h,originalText:c,truncatedText:d,btnClass:p}=t,f=i.classList.contains(p);if(!f)return;const m=r.getAttribute("aria-expanded");if(this.u="false"===m,"text"===l&&f&&(r.textContent="",r.insertAdjacentHTML("beforeend",this.u?c:d),o)){const e=n(h);e.classList.add("show-more-wrapper"),e.insertAdjacentElement("beforeend",this.m(t)),r.appendChild(e)}if("list"===l||"table"===l){const t=this.h(r,l);for(let s=0;s=a&&s=a;"false"===m?e(t[s]):n&&e(t[s],!0)}}l&&this.g({...t,target:i})},this.h=(t,e)=>"list"===e?[].slice.call(t.children):t.rows,this.o=t=>{const{type:e,element:s,more:i,typeElement:r}=t;if(i)if("table"===e)s.insertAdjacentElement("afterend",this.m(t));else{const e=n(r);e.classList.add("show-more-wrapper"),e.appendChild(this.m(t)),s.appendChild(e)}},this.g=e=>{const{element:n,type:i,less:r,more:l,number:a,target:o}=e,h=this.u?r:l,c=this.u?"expand":"collapse",d="table"===i?i:"the "+i,p=n.lastElementChild;s(n,{"aria-expanded":this.u}),s(o,{"aria-expanded":this.u,"aria-label":c+" "+d}),this.C(c,e),h?o.innerHTML=a?h+t(n,i):h:"table"===i?o.parentNode.removeChild(o):"list"===i&&p.parentNode.removeChild(p)};const d=[].slice.call(document.querySelectorAll(l));this.C=o,this.i={...i,...h},d.map((t,e)=>{const s=JSON.parse(t.getAttribute("data-config")),n={...c,...s};this.s={index:e,classArray:t.classList,...r,...n,typeElement:n.element||"span",element:t},this.t()})}}}(); //# sourceMappingURL=showMore.min.js.map diff --git a/docs/showMore.min.js.map b/docs/showMore.min.js.map index 0336905..e0a48d1 100644 --- a/docs/showMore.min.js.map +++ b/docs/showMore.min.js.map @@ -1 +1 @@ -{"version":3,"file":"showMore.min.js","sources":["../sources/utils/function.js","../sources/utils/regex.js","../sources/utils/defaults.js","../sources/index.js"],"sourcesContent":["/**\r\n * Get hidden element\r\n *\r\n * @param {object} object\r\n * @param {String} type - type of element table | div\r\n * @returns\r\n */\r\nconst getNumber = ({ rows, children }, type) => {\r\n const elementType = type === \"table\" ? rows : children;\r\n\r\n const numbersElementHidden = [].slice\r\n .call(elementType)\r\n .filter((el) => el.className === \"hidden\").length;\r\n return numbersElementHidden !== 0 ? ` ${numbersElementHidden}` : \"\";\r\n};\r\n\r\n// https://stackoverflow.com/questions/6003271/substring-text-with-html-tags-in-javascript\r\n/**\r\n * Substring text width html tags\r\n *\r\n * @param {String} originalText - text with html tags\r\n * @param {String} count - limit of characters\r\n * @returns\r\n */\r\nconst htmlSubstr = (originalText, count) => {\r\n let div = createElement(\"div\");\r\n div.insertAdjacentHTML(\"afterbegin\", originalText);\r\n\r\n walk(div, track);\r\n\r\n function track(el) {\r\n if (count > 0) {\r\n let len = el.data.length;\r\n count -= len;\r\n if (count <= 0) {\r\n el.data = el.substringData(0, el.data.length + count);\r\n }\r\n } else {\r\n el.data = \"\";\r\n }\r\n }\r\n\r\n function walk(el, fn) {\r\n let node = el.firstChild;\r\n do {\r\n if (node.nodeType === 3) {\r\n fn(node);\r\n } else if (node.nodeType === 1 && node.childNodes && node.childNodes[0]) {\r\n walk(node, fn);\r\n }\r\n } while ((node = node.nextSibling));\r\n }\r\n return div.innerHTML;\r\n};\r\n\r\n/**\r\n * Add/remove class 'hidden' to element\r\n *\r\n * @param {HTMLElement} element\r\n * @param {String} type - type of element add or remove\r\n */\r\nconst addRemoveClass = (element, type = false) => {\r\n return element.classList[type ? \"add\" : \"remove\"](\"hidden\");\r\n};\r\n\r\n/**\r\n * Set attributes to element\r\n *\r\n * @param {HTMLElement} el\r\n * @param {Object} object\r\n */\r\nconst setAttributes = (el, object) => {\r\n for (let key in object) {\r\n el.setAttribute(key, object[key]);\r\n }\r\n};\r\n\r\n/**\r\n * Create element\r\n *\r\n * @param {String} type - type of element\r\n * @returns {HTMLElement}\r\n */\r\nconst createElement = (type) => document.createElement(type);\r\n\r\nexport { addRemoveClass, createElement, getNumber, htmlSubstr, setAttributes };\r\n","/**\r\n * Default regexes for validation\r\n */\r\nconst defaultRegex = {\r\n newLine: {\r\n match: /(\\r\\n|\\n|\\r)/gm,\r\n replace: \"\",\r\n },\r\n space: {\r\n match: /\\s\\s+/gm,\r\n replace: \" \",\r\n },\r\n br: {\r\n match: //gim,\r\n replace: \"\",\r\n },\r\n html: {\r\n match: /(<((?!b|\\/b|!strong|\\/strong)[^>]+)>)/gi,\r\n replace: \"\",\r\n },\r\n};\r\n\r\nexport default defaultRegex;\r\n","const defaultOptions = {\r\n typeElement: \"span\",\r\n more: false,\r\n less: false,\r\n number: false,\r\n nobutton: false,\r\n after: 0,\r\n btnClass: \"show-more-btn\",\r\n btnClassAppend: null,\r\n};\r\n\r\nexport default defaultOptions;\r\n","import {\r\n addRemoveClass,\r\n createElement,\r\n getNumber,\r\n htmlSubstr,\r\n setAttributes,\r\n} from \"./utils/function\";\r\nimport defaultRegex from \"./utils/regex\";\r\nimport defaultOptions from \"./utils/defaults\";\r\n\r\n/**\r\n * @class ShowMore\r\n */\r\nexport default class ShowMore {\r\n /**\r\n * Constructor\r\n *\r\n * @param {HTMLElement} className\r\n * @param {Object} object\r\n */\r\n constructor(className, { onMoreLess = () => {}, regex = {}, config } = {}) {\r\n // all html elements\r\n const elements = [].slice.call(document.querySelectorAll(className));\r\n\r\n // colback function\r\n this._onMoreLess = onMoreLess;\r\n\r\n // global regex\r\n this._regex = { ...defaultRegex, ...regex };\r\n\r\n elements.map((item, index) => {\r\n const configData = JSON.parse(item.getAttribute(\"data-config\"));\r\n const configGlobal = config;\r\n\r\n const configDataAndGlobal = { ...configGlobal, ...configData };\r\n\r\n this._object = {\r\n index,\r\n classArray: item.classList,\r\n ...defaultOptions,\r\n ...configDataAndGlobal,\r\n typeElement: configDataAndGlobal.element || \"span\",\r\n element: item,\r\n };\r\n\r\n this._initial();\r\n });\r\n }\r\n\r\n /**\r\n * Initail function\r\n *\r\n * @param {Object} object\r\n */\r\n _initial = () => {\r\n const { element, after, ellipsis, nobutton, limit, type } = this._object;\r\n // set default aria-expande to false\r\n setAttributes(element, { \"aria-expanded\": \"false\" });\r\n\r\n const limitCounts = limit + after;\r\n const ellips = ellipsis === false ? \"\" : \"...\";\r\n\r\n // console.log(nobutton);\r\n\r\n // text\r\n if (type === \"text\") {\r\n const originalText = element.innerHTML.trim();\r\n const elementText = element.textContent.trim();\r\n\r\n if (elementText.length > limitCounts) {\r\n let orgTexReg = originalText;\r\n\r\n for (let key in this._regex) {\r\n const { match, replace } = this._regex[key];\r\n if (key && match) orgTexReg = orgTexReg.replace(match, replace);\r\n }\r\n\r\n const truncatedText = htmlSubstr(orgTexReg, limit - 1).concat(ellips);\r\n\r\n element.textContent = \"\";\r\n element.insertAdjacentHTML(\"beforeend\", truncatedText);\r\n\r\n this._clickEvent(element, {\r\n ...this._object,\r\n originalText,\r\n truncatedText,\r\n });\r\n\r\n if (nobutton) return;\r\n this._addBtn(this._object);\r\n }\r\n }\r\n\r\n // list and table\r\n if (type === \"list\" || type === \"table\") {\r\n const items = this._getNumberCount(element, type);\r\n\r\n if (items.length > limitCounts) {\r\n for (let i = limit; i < items.length; i++) {\r\n addRemoveClass(items[i], true);\r\n }\r\n\r\n // add event click\r\n this._clickEvent(\r\n type === \"list\" ? element : element.nextElementSibling,\r\n this._object\r\n );\r\n\r\n if (nobutton) return;\r\n // add button to the list and table\r\n this._addBtn(this._object);\r\n }\r\n }\r\n };\r\n\r\n /**\r\n * Event click\r\n *\r\n * @param {HTMLElement} element\r\n * @param {Object} object\r\n */\r\n _clickEvent = (element, object) =>\r\n element.addEventListener(\"click\", this._handleEvent.bind(this, object));\r\n\r\n /**\r\n * Create button\r\n *\r\n * @param {Object} object\r\n * @returns HTMLElement\r\n */\r\n _createBtn = ({\r\n element,\r\n number,\r\n less,\r\n more,\r\n type,\r\n btnClass,\r\n btnClassAppend,\r\n }) => {\r\n const typeAria = this._checkExp ? less || \"\" : more || \"\";\r\n const label = this._checkExp ? \"collapse\" : \"expand\";\r\n const expanded = this._checkExp ? true : false;\r\n\r\n const button = createElement(\"button\");\r\n button.className =\r\n btnClassAppend == null ? btnClass : btnClass + \" \" + btnClassAppend;\r\n setAttributes(button, {\r\n \"aria-expanded\": expanded,\r\n \"aria-label\": label,\r\n tabindex: 0,\r\n });\r\n\r\n button.insertAdjacentHTML(\r\n \"beforeend\",\r\n number ? typeAria + getNumber(element, type) : typeAria\r\n );\r\n return button;\r\n };\r\n\r\n /**\r\n * Event handler\r\n *\r\n * @param {Object} object\r\n * @param {Event} event\r\n */\r\n _handleEvent = (object, { target }) => {\r\n const {\r\n element,\r\n type,\r\n limit,\r\n less,\r\n typeElement,\r\n originalText,\r\n truncatedText,\r\n btnClass,\r\n } = object;\r\n\r\n // check if the button is clicked\r\n const checkContainsClass = target.classList.contains(btnClass);\r\n\r\n if (!checkContainsClass) return;\r\n\r\n const ariaExpanded = element.getAttribute(\"aria-expanded\");\r\n this._checkExp = ariaExpanded === \"false\";\r\n\r\n // --------------------------------------------------\r\n // text\r\n if (type === \"text\" && checkContainsClass) {\r\n element.textContent = \"\";\r\n\r\n element.insertAdjacentHTML(\r\n \"beforeend\",\r\n this._checkExp ? originalText : truncatedText\r\n );\r\n\r\n if (less) {\r\n const el = createElement(typeElement);\r\n el.classList.add(\"show-more-wrapper\");\r\n el.insertAdjacentElement(\"beforeend\", this._createBtn(object));\r\n element.appendChild(el);\r\n }\r\n }\r\n\r\n // --------------------------------------------------\r\n // list and table\r\n if (type === \"list\" || type === \"table\") {\r\n const items = this._getNumberCount(element, type);\r\n\r\n for (let i = 0; i < items.length; i++) {\r\n const typeRemove =\r\n type === \"list\" ? i >= limit && i < items.length - 1 : i >= limit;\r\n\r\n if (ariaExpanded === \"false\") {\r\n addRemoveClass(items[i]);\r\n } else if (typeRemove) {\r\n addRemoveClass(items[i], true);\r\n }\r\n }\r\n }\r\n\r\n // set aria-expanded\r\n if (type) {\r\n this._setExpand({ ...object, target });\r\n }\r\n };\r\n\r\n _getNumberCount = (element, type) => {\r\n return type === \"list\" ? [].slice.call(element.children) : element.rows;\r\n };\r\n\r\n /**\r\n * Add button\r\n *\r\n * @param {Object} object\r\n */\r\n _addBtn = (object) => {\r\n const { type, element, more, typeElement } = object;\r\n\r\n if (!more) return;\r\n\r\n if (type === \"table\") {\r\n element.insertAdjacentElement(\"afterend\", this._createBtn(object));\r\n } else {\r\n const el = createElement(typeElement);\r\n el.classList.add(\"show-more-wrapper\");\r\n el.appendChild(this._createBtn(object));\r\n element.appendChild(el);\r\n }\r\n };\r\n\r\n /**\r\n * Set aria-expanded\r\n *\r\n * @param {Object} object\r\n */\r\n _setExpand = (object) => {\r\n const { element, type, less, more, number, target } = object;\r\n\r\n const typeAria = this._checkExp ? less : more;\r\n const aria = this._checkExp ? \"expand\" : \"collapse\";\r\n const ariaText = type === \"table\" ? type : `the ${type}`;\r\n const lastChild = element.lastElementChild;\r\n\r\n setAttributes(element, { \"aria-expanded\": this._checkExp });\r\n setAttributes(target, {\r\n \"aria-expanded\": this._checkExp,\r\n \"aria-label\": `${aria} ${ariaText}`,\r\n });\r\n\r\n // callback function on more/less\r\n this._onMoreLess(aria, object);\r\n\r\n if (typeAria) {\r\n target.innerHTML = number\r\n ? typeAria + getNumber(element, type)\r\n : typeAria;\r\n } else if (type === \"table\") {\r\n target.parentNode.removeChild(target);\r\n } else if (type === \"list\") {\r\n lastChild.parentNode.removeChild(lastChild);\r\n }\r\n };\r\n}\r\n"],"names":["getNumber","type","rows","children","elementType","numbersElementHidden","slice","call","filter","el","className","length","addRemoveClass","element","classList","setAttributes","object","key","setAttribute","createElement","document","defaultRegex","newLine","match","replace","space","br","html","defaultOptions","typeElement","more","less","number","nobutton","after","btnClass","btnClassAppend","constructor","onMoreLess","regex","config","_initial","ellipsis","limit","this","_object","limitCounts","ellips","originalText","innerHTML","trim","textContent","orgTexReg","_regex","truncatedText","count","div","insertAdjacentHTML","walk","fn","node","firstChild","nodeType","childNodes","nextSibling","len","data","substringData","htmlSubstr","concat","_clickEvent","_addBtn","items","_getNumberCount","i","nextElementSibling","addEventListener","_handleEvent","bind","_createBtn","_ref","typeAria","_checkExp","label","expanded","button","tabindex","target","checkContainsClass","contains","ariaExpanded","getAttribute","add","insertAdjacentElement","appendChild","typeRemove","_setExpand","aria","ariaText","lastChild","lastElementChild","_onMoreLess","parentNode","removeChild","elements","querySelectorAll","map","item","index","configData","JSON","parse","configDataAndGlobal","classArray"],"mappings":"qCAOA,MAAMA,EAAY,GAAqBC,SAApBC,KAAEA,EAAFC,SAAQA,WACnBC,EAAuB,UAATH,EAAmBC,EAAOC,EAExCE,EAAuB,GAAGC,MAC7BC,KAAKH,GACLI,OAAQC,GAAwB,WAAjBA,EAAGC,WAAwBC,cACb,IAAzBN,MAAiCA,EAAyB,IAgD7DO,EAAiB,SAACC,EAASZ,mBAAAA,IAAAA,GAAO,GAC/BY,EAAQC,UAAUb,EAAO,MAAQ,UAAU,WAS9Cc,EAAgB,CAACN,EAAIO,SACpB,IAAIC,KAAOD,EACdP,EAAGS,aAAaD,EAAKD,EAAOC,KAU1BE,EAAiBlB,GAASmB,SAASD,cAAclB,GChFjDoB,EAAe,CACnBC,QAAS,CACPC,MAAO,iBACPC,QAAS,IAEXC,MAAO,CACLF,MAAO,UACPC,QAAS,KAEXE,GAAI,CACFH,MAAO,gBACPC,QAAS,IAEXG,KAAM,CACJJ,MAAO,0CACPC,QAAS,KClBPI,EAAiB,CACrBC,YAAa,OACbC,MAAM,EACNC,MAAM,EACNC,QAAQ,EACRC,UAAU,EACVC,MAAO,EACPC,SAAU,gBACVC,eAAgB,aCKH,MAObC,YAAY3B,SAAW4B,WAAEA,EAAa,SAAfC,MAAyBA,EAAQ,GAAjCC,OAAqCA,cAAW,UAkCvEC,EAAW,WACH5B,QAAEA,EAAFqB,MA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Z,SAATtF,GACTkG,EAAUG,WAAWC,YAAYJ,UAjQ7BK,EAAW,GAAGlG,MAAMC,KAAKa,SAASqF,iBAAiB/F,SAGpD2F,EAAc/D,OAGde,EAAS,IAAKhC,KAAiBkB,GAEpCiE,EAASE,IAAI,CAACC,EAAMC,WACZC,EAAaC,KAAKC,MAAMJ,EAAKhB,aAAa,gBAG1CqB,EAAsB,IAFPxE,KAE6BqE,QAE7ChE,EAAU,CACb+D,MAAAA,EACAK,WAAYN,EAAK7F,aACdc,KACAoF,EACHnF,YAAamF,EAAoBnG,SAAW,OAC5CA,QAAS8F,QAGNlE"} \ No newline at end of file +{"version":3,"file":"showMore.min.js","sources":["../sources/utils/function.js","../sources/utils/regex.js","../sources/utils/defaults.js","../sources/index.js"],"sourcesContent":["/**\r\n * Get hidden element\r\n *\r\n * @param {object} object\r\n * @param {String} type - type of element table | div\r\n * @returns\r\n */\r\nconst getNumber = ({ rows, children }, type) => {\r\n const elementType = type === \"table\" ? rows : children;\r\n\r\n const numbersElementHidden = [].slice\r\n .call(elementType)\r\n .filter((el) => el.className === \"hidden\").length;\r\n return numbersElementHidden !== 0 ? ` ${numbersElementHidden}` : \"\";\r\n};\r\n\r\n// https://stackoverflow.com/questions/6003271/substring-text-with-html-tags-in-javascript\r\n/**\r\n * Substring text width html tags\r\n *\r\n * @param {String} originalText - text with html tags\r\n * @param {String} count - limit of characters\r\n * @returns\r\n */\r\nconst htmlSubstr = (originalText, count) => {\r\n let div = createElement(\"div\");\r\n div.insertAdjacentHTML(\"afterbegin\", originalText);\r\n\r\n walk(div, track);\r\n\r\n function track(el) {\r\n if (count > 0) {\r\n let len = el.data.length;\r\n count -= len;\r\n if (count <= 0) {\r\n el.data = el.substringData(0, el.data.length + count);\r\n }\r\n } else {\r\n el.data = \"\";\r\n }\r\n }\r\n\r\n function walk(el, fn) {\r\n let node = el.firstChild;\r\n do {\r\n if (node.nodeType === 3) {\r\n fn(node);\r\n } else if (node.nodeType === 1 && node.childNodes && node.childNodes[0]) {\r\n walk(node, fn);\r\n }\r\n } while ((node = node.nextSibling));\r\n }\r\n return div.innerHTML;\r\n};\r\n\r\n/**\r\n * Add/remove class 'hidden' to element\r\n *\r\n * @param {HTMLElement} element\r\n * @param {String} type - type of element add or remove\r\n */\r\nconst addRemoveClass = (element, type = false) => {\r\n return element.classList[type ? \"add\" : \"remove\"](\"hidden\");\r\n};\r\n\r\n/**\r\n * Set attributes to element\r\n *\r\n * @param {HTMLElement} el\r\n * @param {Object} object\r\n */\r\nconst setAttributes = (el, object) => {\r\n for (let key in object) {\r\n el.setAttribute(key, object[key]);\r\n }\r\n};\r\n\r\n/**\r\n * Create element\r\n *\r\n * @param {String} type - type of element\r\n * @returns {HTMLElement}\r\n */\r\nconst createElement = (type) => document.createElement(type);\r\n\r\nexport { addRemoveClass, createElement, getNumber, htmlSubstr, setAttributes };\r\n","/**\r\n * Default regexes for validation\r\n */\r\nconst defaultRegex = {\r\n newLine: {\r\n match: /(\\r\\n|\\n|\\r)/gm,\r\n replace: \"\",\r\n },\r\n space: {\r\n match: /\\s\\s+/gm,\r\n replace: \" \",\r\n },\r\n br: {\r\n match: //gim,\r\n replace: \"\",\r\n },\r\n html: {\r\n match: /(<((?!b|\\/b|!strong|\\/strong)[^>]+)>)/gi,\r\n replace: \"\",\r\n },\r\n};\r\n\r\nexport default defaultRegex;\r\n","const defaultOptions = {\r\n typeElement: \"span\",\r\n more: false,\r\n less: false,\r\n number: false,\r\n nobutton: false,\r\n after: 0,\r\n btnClass: \"show-more-btn\",\r\n btnClassAppend: null,\r\n};\r\n\r\nexport default defaultOptions;\r\n","import {\r\n addRemoveClass,\r\n createElement,\r\n getNumber,\r\n htmlSubstr,\r\n setAttributes,\r\n} from \"./utils/function\";\r\nimport defaultRegex from \"./utils/regex\";\r\nimport defaultOptions from \"./utils/defaults\";\r\n\r\n/**\r\n * @class ShowMore\r\n */\r\nexport default class ShowMore {\r\n /**\r\n * Constructor\r\n *\r\n * @param {HTMLElement} className\r\n * @param {Object} object\r\n */\r\n constructor(className, { onMoreLess = () => {}, regex = {}, config } = {}) {\r\n // all html elements\r\n const elements = [].slice.call(document.querySelectorAll(className));\r\n\r\n // colback function\r\n this._onMoreLess = onMoreLess;\r\n\r\n // global regex\r\n this._regex = { ...defaultRegex, ...regex };\r\n\r\n elements.map((item, index) => {\r\n const configData = JSON.parse(item.getAttribute(\"data-config\"));\r\n const configGlobal = config;\r\n\r\n const configDataAndGlobal = { ...configGlobal, ...configData };\r\n\r\n this._object = {\r\n index,\r\n classArray: item.classList,\r\n ...defaultOptions,\r\n ...configDataAndGlobal,\r\n typeElement: configDataAndGlobal.element || \"span\",\r\n element: item,\r\n };\r\n\r\n this._initial();\r\n });\r\n }\r\n\r\n /**\r\n * Initail function\r\n *\r\n * @param {Object} object\r\n */\r\n _initial = () => {\r\n const { element, after, ellipsis, nobutton, limit, type } = this._object;\r\n // set default aria-expande to false\r\n setAttributes(element, { \"aria-expanded\": \"false\" });\r\n\r\n const limitCounts = limit + after;\r\n const ellips = ellipsis === false ? \"\" : \"...\";\r\n\r\n // console.log(nobutton);\r\n\r\n // text\r\n if (type === \"text\") {\r\n const originalText = element.innerHTML.trim();\r\n const elementText = element.textContent.trim();\r\n\r\n if (elementText.length > limitCounts) {\r\n let orgTexReg = originalText;\r\n\r\n for (let key in this._regex) {\r\n const { match, replace } = this._regex[key];\r\n if (key && match) orgTexReg = orgTexReg.replace(match, replace);\r\n }\r\n\r\n const truncatedText = htmlSubstr(orgTexReg, limit - 1).concat(ellips);\r\n\r\n element.textContent = \"\";\r\n element.insertAdjacentHTML(\"beforeend\", truncatedText);\r\n\r\n this._clickEvent(element, {\r\n ...this._object,\r\n originalText,\r\n truncatedText,\r\n });\r\n\r\n if (nobutton) return;\r\n this._addBtn(this._object);\r\n }\r\n }\r\n\r\n // list and table\r\n if (type === \"list\" || type === \"table\") {\r\n const items = this._getNumberCount(element, type);\r\n\r\n if (items.length > limitCounts) {\r\n for (let i = limit; i < items.length; i++) {\r\n addRemoveClass(items[i], true);\r\n }\r\n\r\n if (!nobutton) {\r\n // add button to the list and table\r\n this._addBtn(this._object);\r\n }\r\n\r\n // add event click\r\n this._clickEvent(\r\n type === \"list\" ? element : element.nextElementSibling,\r\n this._object\r\n );\r\n\r\n if (nobutton) return;\r\n }\r\n }\r\n };\r\n\r\n /**\r\n * Event click\r\n *\r\n * @param {HTMLElement} element\r\n * @param {Object} object\r\n */\r\n _clickEvent = (element, object) =>\r\n element.addEventListener(\"click\", this._handleEvent.bind(this, object));\r\n\r\n /**\r\n * Create button\r\n *\r\n * @param {Object} object\r\n * @returns HTMLElement\r\n */\r\n _createBtn = ({\r\n element,\r\n number,\r\n less,\r\n more,\r\n type,\r\n btnClass,\r\n btnClassAppend,\r\n }) => {\r\n const typeAria = this._checkExp ? less || \"\" : more || \"\";\r\n const label = this._checkExp ? \"collapse\" : \"expand\";\r\n const expanded = this._checkExp ? true : false;\r\n\r\n const button = createElement(\"button\");\r\n button.className =\r\n btnClassAppend == null ? btnClass : btnClass + \" \" + btnClassAppend;\r\n setAttributes(button, {\r\n \"aria-expanded\": expanded,\r\n \"aria-label\": label,\r\n tabindex: 0,\r\n });\r\n\r\n button.insertAdjacentHTML(\r\n \"beforeend\",\r\n number ? typeAria + getNumber(element, type) : typeAria\r\n );\r\n return button;\r\n };\r\n\r\n /**\r\n * Event handler\r\n *\r\n * @param {Object} object\r\n * @param {Event} event\r\n */\r\n _handleEvent = (object, { target }) => {\r\n const {\r\n element,\r\n type,\r\n limit,\r\n less,\r\n typeElement,\r\n originalText,\r\n truncatedText,\r\n btnClass,\r\n } = object;\r\n\r\n // check if the button is clicked\r\n const checkContainsClass = target.classList.contains(btnClass);\r\n\r\n if (!checkContainsClass) return;\r\n\r\n const ariaExpanded = element.getAttribute(\"aria-expanded\");\r\n this._checkExp = ariaExpanded === \"false\";\r\n\r\n // --------------------------------------------------\r\n // text\r\n if (type === \"text\" && checkContainsClass) {\r\n element.textContent = \"\";\r\n\r\n element.insertAdjacentHTML(\r\n \"beforeend\",\r\n this._checkExp ? originalText : truncatedText\r\n );\r\n\r\n if (less) {\r\n const el = createElement(typeElement);\r\n el.classList.add(\"show-more-wrapper\");\r\n el.insertAdjacentElement(\"beforeend\", this._createBtn(object));\r\n element.appendChild(el);\r\n }\r\n }\r\n\r\n // --------------------------------------------------\r\n // list and table\r\n if (type === \"list\" || type === \"table\") {\r\n const items = this._getNumberCount(element, type);\r\n\r\n for (let i = 0; i < items.length; i++) {\r\n const typeRemove =\r\n type === \"list\" ? i >= limit && i < items.length - 1 : i >= limit;\r\n\r\n if (ariaExpanded === \"false\") {\r\n addRemoveClass(items[i]);\r\n } else if (typeRemove) {\r\n addRemoveClass(items[i], true);\r\n }\r\n }\r\n }\r\n\r\n // set aria-expanded\r\n if (type) {\r\n this._setExpand({ ...object, target });\r\n }\r\n };\r\n\r\n _getNumberCount = (element, type) => {\r\n return type === \"list\" ? [].slice.call(element.children) : element.rows;\r\n };\r\n\r\n /**\r\n * Add button\r\n *\r\n * @param {Object} object\r\n */\r\n _addBtn = (object) => {\r\n const { type, element, more, typeElement } = object;\r\n\r\n if (!more) return;\r\n\r\n if (type === \"table\") {\r\n element.insertAdjacentElement(\"afterend\", this._createBtn(object));\r\n } else {\r\n const el = createElement(typeElement);\r\n el.classList.add(\"show-more-wrapper\");\r\n el.appendChild(this._createBtn(object));\r\n element.appendChild(el);\r\n }\r\n };\r\n\r\n /**\r\n * Set aria-expanded\r\n *\r\n * @param {Object} object\r\n */\r\n _setExpand = (object) => {\r\n const { element, type, less, more, number, target } = object;\r\n\r\n const typeAria = this._checkExp ? less : more;\r\n const aria = this._checkExp ? \"expand\" : \"collapse\";\r\n const ariaText = type === \"table\" ? type : `the ${type}`;\r\n const lastChild = element.lastElementChild;\r\n\r\n setAttributes(element, { \"aria-expanded\": this._checkExp });\r\n setAttributes(target, {\r\n \"aria-expanded\": this._checkExp,\r\n \"aria-label\": `${aria} ${ariaText}`,\r\n });\r\n\r\n // callback function on more/less\r\n this._onMoreLess(aria, object);\r\n\r\n if (typeAria) {\r\n target.innerHTML = number\r\n ? typeAria + getNumber(element, type)\r\n : typeAria;\r\n } else if (type === \"table\") {\r\n target.parentNode.removeChild(target);\r\n } else if (type === \"list\") {\r\n lastChild.parentNode.removeChild(lastChild);\r\n }\r\n };\r\n}\r\n"],"names":["getNumber","type","rows","children","elementType","numbersElementHidden","slice","call","filter","el","className","length","addRemoveClass","element","classList","setAttributes","object","key","setAttribute","createElement","document","defaultRegex","newLine","match","replace","space","br","html","defaultOptions","typeElement","more","less","number","nobutton","after","btnClass","btnClassAppend","constructor","onMoreLess","regex","config","_initial","ellipsis","limit","this","_object","limitCounts","ellips","originalText","innerHTML","trim","textContent","orgTexReg","_regex","truncatedText","count","div","insertAdjacentHTML","walk","fn","node","firstChild","nodeType","childNodes","nextSibling","len","data","substringData","htmlSubstr","concat","_clickEvent","_addBtn","items","_getNumberCount","i","nextElementSibling","addEventListener","_handleEvent","bind","_createBtn","_ref","typeAria","_checkExp","label","expanded","button","tabindex","target","checkContainsClass","contains","ariaExpanded","getAttribute","add","insertAdjacentElement","appendChild","typeRemove","_setExpand","aria","ariaText","lastChild","lastElementChild","_onMoreLess","parentNode","removeChild","elements","querySelectorAll","map","item","index","configData","JSON","parse","configDataAndGlobal","classArray"],"mappings":"qCAOA,MAAMA,EAAY,GAAqBC,SAApBC,KAAEA,EAAFC,SAAQA,WACnBC,EAAuB,UAATH,EAAmBC,EAAOC,EAExCE,EAAuB,GAAGC,MAC7BC,KAAKH,GACLI,OAAQC,GAAwB,WAAjBA,EAAGC,WAAwBC,cACb,IAAzBN,MAAiCA,EAAyB,IAgD7DO,EAAiB,SAACC,EAASZ,mBAAAA,IAAAA,GAAO,GAC/BY,EAAQC,UAAUb,EAAO,MAAQ,UAAU,WAS9Cc,EAAgB,CAACN,EAAIO,SACpB,IAAIC,KAAOD,EACdP,EAAGS,aAAaD,EAAKD,EAAOC,KAU1BE,EAAiBlB,GAASmB,SAASD,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