Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

Commit

Permalink
[version] patch; @digitalcraft createTextNode() 🚀 (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
yowainwright authored Apr 17, 2019
1 parent 1876911 commit da7371b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dist/jquery.shave.min.js

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

9 changes: 7 additions & 2 deletions dist/shave.es.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
shave - Shave is a javascript plugin that truncates multi-line text within a html element based on set max height
@version v2.5.2
@version v2.5.3
@link https://github.com/dollarshaveclub/shave#readme
@author Jeff Wainwright <yowainwright@gmail.com> (jeffry.in)
@license MIT
Expand Down Expand Up @@ -61,7 +61,12 @@ function shave(target, maxHeight) {
el[textProp] = spaces ? words.slice(0, max).join(' ') : words.slice(0, max);
el.insertAdjacentHTML('beforeend', charHtml);
var diff = spaces ? " ".concat(words.slice(max).join(' ')) : words.slice(max);
el.insertAdjacentHTML('beforeend', "<span class=\"".concat(classname, "\" style=\"display:none;\">").concat(diff, "</span>"));
var shavedText = document.createTextNode(diff);
var elWithShavedText = document.createElement('span');
elWithShavedText.classList.add(classname);
elWithShavedText.style.display = 'none';
elWithShavedText.appendChild(shavedText);
el.insertAdjacentElement('beforeend', elWithShavedText);
styles.height = heightStyle;
styles.maxHeight = maxHeightStyle;
}
Expand Down
9 changes: 7 additions & 2 deletions dist/shave.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
shave - Shave is a javascript plugin that truncates multi-line text within a html element based on set max height
@version v2.5.2
@version v2.5.3
@link https://github.com/dollarshaveclub/shave#readme
@author Jeff Wainwright <yowainwright@gmail.com> (jeffry.in)
@license MIT
Expand Down Expand Up @@ -67,7 +67,12 @@
el[textProp] = spaces ? words.slice(0, max).join(' ') : words.slice(0, max);
el.insertAdjacentHTML('beforeend', charHtml);
var diff = spaces ? " ".concat(words.slice(max).join(' ')) : words.slice(max);
el.insertAdjacentHTML('beforeend', "<span class=\"".concat(classname, "\" style=\"display:none;\">").concat(diff, "</span>"));
var shavedText = document.createTextNode(diff);
var elWithShavedText = document.createElement('span');
elWithShavedText.classList.add(classname);
elWithShavedText.style.display = 'none';
elWithShavedText.appendChild(shavedText);
el.insertAdjacentElement('beforeend', elWithShavedText);
styles.height = heightStyle;
styles.maxHeight = maxHeightStyle;
}
Expand Down
2 changes: 1 addition & 1 deletion dist/shave.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": "shave",
"version": "2.5.2",
"version": "2.5.3",
"description": "Shave is a javascript plugin that truncates multi-line text within a html element based on set max height",
"main": "dist/shave.js",
"module": "dist/shave.es.js",
Expand Down
1 change: 0 additions & 1 deletion src/shave.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export default function shave (target, maxHeight, opts = {}) {
el.insertAdjacentHTML('beforeend', charHtml)
const diff = spaces ? ` ${words.slice(max).join(' ')}` : words.slice(max)

// https://stackoverflow.com/questions/476821/is-a-dom-text-node-guaranteed-to-not-be-interpreted-as-html
const shavedText = document.createTextNode(diff)
const elWithShavedText = document.createElement('span')
elWithShavedText.classList.add(classname)
Expand Down

0 comments on commit da7371b

Please # to comment.