Skip to content

Commit

Permalink
Merge pull request #3 from pnicolli/pnicolli_optimize
Browse files Browse the repository at this point in the history
Optimized calls to getComputedStyle
  • Loading branch information
Nicola Zambello authored Sep 10, 2017
2 parents 82d5156 + d43e234 commit 21ec527
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions lib/ellipsed.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ function ellipsed() {
var textBeforeWrap = '';

el.textContent = '';
var elHeight = window.getComputedStyle(el).height;
var elStyle = window.getComputedStyle(el);
var elHeight = elStyle.height;

var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
Expand All @@ -54,8 +55,8 @@ function ellipsed() {
el.textContent = '' + el.textContent + token + '...';
}

if (parseFloat(window.getComputedStyle(el).height) > parseFloat(elHeight)) {
elHeight = window.getComputedStyle(el).height;
if (parseFloat(elStyle.height) > parseFloat(elHeight)) {
elHeight = elStyle.height;
rowsWrapped++;

if (rowsWrapped === rows + 1) {
Expand Down
7 changes: 4 additions & 3 deletions src/ellipsed.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ function ellipsed(selector = '', rows = 1) {
let textBeforeWrap = '';

el.textContent = '';
let elHeight = window.getComputedStyle(el).height;
const elStyle = window.getComputedStyle(el);
let elHeight = elStyle.height;

for (const token of splittedText) {
if (el.textContent.length) {
Expand All @@ -35,8 +36,8 @@ function ellipsed(selector = '', rows = 1) {
el.textContent = `${el.textContent}${token}...`;
}

if (parseFloat(window.getComputedStyle(el).height) > parseFloat(elHeight)) {
elHeight = window.getComputedStyle(el).height;
if (parseFloat(elStyle.height) > parseFloat(elHeight)) {
elHeight = elStyle.height;
rowsWrapped++;

if (rowsWrapped === rows + 1) {
Expand Down

0 comments on commit 21ec527

Please sign in to comment.