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

Commit da7371b

Browse files
authored
[version] patch; @digitalcraft createTextNode() πŸš€ (#146)
1 parent 1876911 commit da7371b

File tree

6 files changed

+17
-8
lines changed

6 files changed

+17
-8
lines changed

β€Ždist/jquery.shave.min.jsβ€Ž

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Ždist/shave.es.jsβ€Ž

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
shave - Shave is a javascript plugin that truncates multi-line text within a html element based on set max height
3-
@version v2.5.2
3+
@version v2.5.3
44
@link https://github.com/dollarshaveclub/shave#readme
55
@author Jeff Wainwright <yowainwright@gmail.com> (jeffry.in)
66
@license MIT
@@ -61,7 +61,12 @@ function shave(target, maxHeight) {
6161
el[textProp] = spaces ? words.slice(0, max).join(' ') : words.slice(0, max);
6262
el.insertAdjacentHTML('beforeend', charHtml);
6363
var diff = spaces ? " ".concat(words.slice(max).join(' ')) : words.slice(max);
64-
el.insertAdjacentHTML('beforeend', "<span class=\"".concat(classname, "\" style=\"display:none;\">").concat(diff, "</span>"));
64+
var shavedText = document.createTextNode(diff);
65+
var elWithShavedText = document.createElement('span');
66+
elWithShavedText.classList.add(classname);
67+
elWithShavedText.style.display = 'none';
68+
elWithShavedText.appendChild(shavedText);
69+
el.insertAdjacentElement('beforeend', elWithShavedText);
6570
styles.height = heightStyle;
6671
styles.maxHeight = maxHeightStyle;
6772
}

β€Ždist/shave.jsβ€Ž

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
shave - Shave is a javascript plugin that truncates multi-line text within a html element based on set max height
3-
@version v2.5.2
3+
@version v2.5.3
44
@link https://github.com/dollarshaveclub/shave#readme
55
@author Jeff Wainwright <yowainwright@gmail.com> (jeffry.in)
66
@license MIT
@@ -67,7 +67,12 @@
6767
el[textProp] = spaces ? words.slice(0, max).join(' ') : words.slice(0, max);
6868
el.insertAdjacentHTML('beforeend', charHtml);
6969
var diff = spaces ? " ".concat(words.slice(max).join(' ')) : words.slice(max);
70-
el.insertAdjacentHTML('beforeend', "<span class=\"".concat(classname, "\" style=\"display:none;\">").concat(diff, "</span>"));
70+
var shavedText = document.createTextNode(diff);
71+
var elWithShavedText = document.createElement('span');
72+
elWithShavedText.classList.add(classname);
73+
elWithShavedText.style.display = 'none';
74+
elWithShavedText.appendChild(shavedText);
75+
el.insertAdjacentElement('beforeend', elWithShavedText);
7176
styles.height = heightStyle;
7277
styles.maxHeight = maxHeightStyle;
7378
}

β€Ždist/shave.min.jsβ€Ž

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žpackage.jsonβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "shave",
3-
"version": "2.5.2",
3+
"version": "2.5.3",
44
"description": "Shave is a javascript plugin that truncates multi-line text within a html element based on set max height",
55
"main": "dist/shave.js",
66
"module": "dist/shave.es.js",

β€Žsrc/shave.jsβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ export default function shave (target, maxHeight, opts = {}) {
5757
el.insertAdjacentHTML('beforeend', charHtml)
5858
const diff = spaces ? ` ${words.slice(max).join(' ')}` : words.slice(max)
5959

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

0 commit comments

Comments
Β (0)