Skip to content

Commit

Permalink
refactor: prettier config
Browse files Browse the repository at this point in the history
  • Loading branch information
tomickigrzegorz committed Sep 8, 2021
1 parent b5c8b41 commit 5006646
Showing 1 changed file with 39 additions and 23 deletions.
62 changes: 39 additions & 23 deletions sources/index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
class ShowMore {
constructor(className, { onMoreLess = () => { }, regex = {} } = {}) {
constructor(className, { onMoreLess = () => {}, regex = {} } = {}) {
this.elements = document.querySelectorAll(className);
this.onMoreLess = onMoreLess;

this.regex = Object.assign({
newLine: {
match: /(\r\n|\n|\r)/gm,
replace: ''
this.regex = Object.assign(
{
newLine: {
match: /(\r\n|\n|\r)/gm,
replace: '',
},
space: {
match: /\s\s+/gm,
replace: ' ',
},
br: {
match: /<br\s*\/?>/gim,
replace: '',
},
html: {
match: /(<((?!b|\/b|!strong|\/strong)[^>]+)>)/gi,
replace: '',
},
},
space: {
match: /\s\s+/gm,
replace: ' '
},
br: {
match: /<br\s*\/?>/gim,
replace: ''
},
html: {
match: /(<((?!b|\/b|!strong|\/strong)[^>]+)>)/ig,
replace: ''
}
}, regex);
regex
);

for (let i = 0; i < this.elements.length; i++) {
const {
Expand Down Expand Up @@ -79,13 +82,17 @@ class ShowMore {
do {
if (node.nodeType === 3) {
fn(node);
} else if (node.nodeType === 1 && node.childNodes && node.childNodes[0]) {
} else if (
node.nodeType === 1 &&
node.childNodes &&
node.childNodes[0]
) {
walk(node, fn);
}
} while (node = node.nextSibling);
} while ((node = node.nextSibling));
}
return div.innerHTML;
}
};

initial = ({ element, after, ellipsis, limit, type }) => {
// set default aria-expande to false
Expand Down Expand Up @@ -144,13 +151,22 @@ class ShowMore {
element.addEventListener('click', this.handleEvent.bind(this, object));
};

createBtn = ({ element, number, less, more, type, btnClass, btnClassAppend }) => {
createBtn = ({
element,
number,
less,
more,
type,
btnClass,
btnClassAppend,
}) => {
const typeAria = this.checkExp ? less || '' : more || '';
const label = this.checkExp ? 'collapse' : 'expand';
const expanded = this.checkExp ? true : false;

const btn = document.createElement('button');
btn.className = btnClassAppend == null ? btnClass : btnClass + ' ' + btnClassAppend;
btn.className =
btnClassAppend == null ? btnClass : btnClass + ' ' + btnClassAppend;
btn.setAttribute('aria-expanded', expanded);
btn.setAttribute('aria-label', label);
btn.setAttribute('tabindex', 0);
Expand Down

0 comments on commit 5006646

Please sign in to comment.