Skip to content

Commit

Permalink
updates shave for textContent prop
Browse files Browse the repository at this point in the history
  • Loading branch information
yowainwright committed Nov 17, 2016
1 parent 5ad96c7 commit 1e3d5e6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
8 changes: 5 additions & 3 deletions dist/shave.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ function shave(target, maxHeight, opts) {
var el = els[i];
var span = el.querySelector('.' + classname);

var textProp = el.textContent === undefined ? 'innerText' : 'textContent';

// If element text has already been shaved
if (span) {
// Remove the ellipsis to recapture the original text
el.removeChild(el.querySelector('.js-shave-char'));
el.textContent = el.textContent; // nuke span, recombine text
el[textProp] = el[textProp]; // nuke span, recombine text
}

var fullText = el.textContent;
Expand Down Expand Up @@ -55,12 +57,12 @@ function shave(target, maxHeight, opts) {
var pivot = void 0;
while (min < max) {
pivot = min + max + 1 >> 1;
el.textContent = spaces ? words.slice(0, pivot).join(' ') : words.slice(0, pivot);
el[textProp] = spaces ? words.slice(0, pivot).join(' ') : words.slice(0, pivot);
el.insertAdjacentHTML('beforeend', charHtml);
if (el.offsetHeight > maxHeight) max = spaces ? pivot - 1 : pivot - 2;else min = pivot;
}

el.textContent = spaces ? words.slice(0, max).join(' ') : words.slice(0, max);
el[textProp] = spaces ? words.slice(0, max).join(' ') : words.slice(0, max);
el.insertAdjacentHTML('beforeend', charHtml);
var diff = spaces ? words.slice(max + 1).join(' ') : words.slice(max);

Expand Down
4 changes: 2 additions & 2 deletions dist/shave.min.js

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

8 changes: 5 additions & 3 deletions src/shave.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ export default function shave(target, maxHeight, opts) {
const el = els[i];
const span = el.querySelector(`.${classname}`);

const textProp = el.textContent === undefined ? 'innerText' : 'textContent';

// If element text has already been shaved
if (span) {
// Remove the ellipsis to recapture the original text
el.removeChild(el.querySelector('.js-shave-char'));
el.textContent = el.textContent; // nuke span, recombine text
el[textProp] = el[textProp]; // nuke span, recombine text
}

const fullText = el.textContent;
Expand Down Expand Up @@ -50,13 +52,13 @@ export default function shave(target, maxHeight, opts) {
let pivot;
while (min < max) {
pivot = (min + max + 1) >> 1;
el.textContent = spaces ? words.slice(0, pivot).join(' ') : words.slice(0, pivot);
el[textProp] = spaces ? words.slice(0, pivot).join(' ') : words.slice(0, pivot);
el.insertAdjacentHTML('beforeend', charHtml);
if (el.offsetHeight > maxHeight) max = spaces ? pivot - 1 : pivot - 2;
else min = pivot;
}

el.textContent = spaces ? words.slice(0, max).join(' ') : words.slice(0, max);
el[textProp] = spaces ? words.slice(0, max).join(' ') : words.slice(0, max);
el.insertAdjacentHTML('beforeend', charHtml);
const diff = spaces ? words.slice(max + 1).join(' ') : words.slice(max);

Expand Down

0 comments on commit 1e3d5e6

Please sign in to comment.