Skip to content

Commit

Permalink
Merge pull request #11 from tomik23:tomik23/issue10
Browse files Browse the repository at this point in the history
No less element #10
  • Loading branch information
tomickigrzegorz committed Jan 17, 2021
2 parents 1ca352b + 63659eb commit f02acfc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
3 changes: 1 addition & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ <h5>Show html</h5>
<section id="example-element">
<h2>Element inline</h2>
<div class="element links-style"
data-config='{ "type": "list", "limit": 5, "element": "div", "more": "&#8595; show more", "less": "&#8593; less" }'
}'>
data-config='{ "type": "list", "limit": 5, "element": "div", "more": "&#8595; show more", "less": "&#8593; less" }'>
<a href="#">Administracja biur,</a>
<a href="#">Badanie i uzdatnianie wody,</a>
<a href="#">Motele i zajazdy,</a>
Expand Down
2 changes: 1 addition & 1 deletion docs/showMore.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "show-more-read",
"version": "1.0.8",
"version": "1.0.9",
"main": "docs/showMore.min.js",
"description": "JavaScript library that truncates text, list or table by chars, elements or rows",
"author": "Grzegorz Tomicki",
Expand Down
15 changes: 9 additions & 6 deletions sources/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class ShowMore {
};

createBtn = ({ element, number, less, more, type }) => {
const typeAria = this.checkExp ? less : more || '';
const typeAria = this.checkExp ? less || '' : more || '';
const aria = this.checkExp ? 'collapse' : 'expand';

const btn = document.createElement('span');
Expand All @@ -119,6 +119,7 @@ class ShowMore {
element,
type,
limit,
less,
typeElement,
originalText,
truncatedText,
Expand All @@ -134,9 +135,11 @@ class ShowMore {
element.innerHTML = '';
element.innerHTML = this.checkExp ? originalText : truncatedText;

const el = document.createElement(typeElement);
el.insertAdjacentElement('beforeend', this.createBtn(object));
element.appendChild(el);
if (less) {
const el = document.createElement(typeElement);
el.insertAdjacentElement('beforeend', this.createBtn(object));
element.appendChild(el);
}
}

// list and table
Expand Down Expand Up @@ -210,9 +213,9 @@ class ShowMore {
target.innerHTML = number
? typeAria + this.getNumber(element, type)
: typeAria;
} else if (this.object.type === 'table') {
} else if (type === 'table') {
target.parentNode.removeChild(target);
} else if (this.object.type === 'list') {
} else if (type === 'list') {
lastChild.parentNode.removeChild(lastChild);
}
};
Expand Down

0 comments on commit f02acfc

Please sign in to comment.