Skip to content

Commit

Permalink
Merge pull request dollarshaveclub#30 from dollarshaveclub/feature/ie-8
Browse files Browse the repository at this point in the history
updates shave for textContent prop
  • Loading branch information
yowainwright authored Nov 18, 2016
2 parents 5ad96c7 + 83ed031 commit b03cab0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
10 changes: 6 additions & 4 deletions dist/shave.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ 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;
var fullText = el[textProp];
var words = spaces ? fullText.split(' ') : fullText;

// If 0 or 1 words, we're done
Expand All @@ -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.

10 changes: 6 additions & 4 deletions src/shave.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ 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;
const fullText = el[textProp];
const words = spaces ? fullText.split(' ') : fullText;

// If 0 or 1 words, we're done
Expand All @@ -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 b03cab0

Please sign in to comment.