From 252c40d09857ca5de42bd98fb87774c1f59ed5a7 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 5 Oct 2017 20:08:28 +0100 Subject: [PATCH 1/2] DOM manipulation is now wrapped inside $timeout DOM manipulation should be wrapped inside setTimeout function. The timeout is required to allow the DOM manipulation from the last angularjs digesty cycle to complete. --- src/angular-ellipsis.js | 87 +++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 42 deletions(-) diff --git a/src/angular-ellipsis.js b/src/angular-ellipsis.js index 1c5eb12..b9b1293 100644 --- a/src/angular-ellipsis.js +++ b/src/angular-ellipsis.js @@ -117,59 +117,62 @@ angular.module('dibari.angular-ellipsis', []) element.css('font-size',attributes.ellipsisFallbackFontSize); } - // If text has overflow - if (isOverflowed(element, scope.useParent)) { - var bindArrayStartingLength = bindArray.length, - initialMaxHeight = scope.useParent ? getParentHeight(element) : element[0].clientHeight; - - if (isHtml) { - element.html(binding + appendString); - } else { - element.text(binding).html(element.html() + appendString); - } - //Set data-overflow on element for targeting - element.attr('data-overflowed', 'true'); - - // Set complete text and remove one word at a time, until there is no overflow - for (; i < bindArrayStartingLength; i++) { - var current = bindArray.pop(); - //if the last string still overflowed, then truncate the last string - if (bindArray.length === 0) { - bindArray[0] = current.substring(0, Math.min(current.length, 5)); - } + $timeout(function(){ + // If text has overflow + if (isOverflowed(element, scope.useParent)) { + var bindArrayStartingLength = bindArray.length, + initialMaxHeight = scope.useParent ? getParentHeight(element) : element[0].clientHeight; if (isHtml) { - element.html(bindArray.join(ellipsisSeparator) + appendString); + element.html(binding + appendString); } else { - element.text(bindArray.join(ellipsisSeparator)).html(element.html() + appendString); + element.text(binding).html(element.html() + appendString); } - - if ((scope.useParent ? element.parent()[0] : element[0]).scrollHeight < initialMaxHeight || isOverflowed(element, scope.useParent) === false) { - attributes.isTruncated = true; - break; + //Set data-overflow on element for targeting + element.attr('data-overflowed', 'true'); + + // Set complete text and remove one word at a time, until there is no overflow + for (; i < bindArrayStartingLength; i++) { + var current = bindArray.pop(); + + //if the last string still overflowed, then truncate the last string + if (bindArray.length === 0) { + bindArray[0] = current.substring(0, Math.min(current.length, 5)); + } + + if (isHtml) { + element.html(bindArray.join(ellipsisSeparator) + appendString); + } else { + element.text(bindArray.join(ellipsisSeparator)).html(element.html() + appendString); + } + + if ((scope.useParent ? element.parent()[0] : element[0]).scrollHeight < initialMaxHeight || isOverflowed(element, scope.useParent) === false) { + attributes.isTruncated = true; + break; + } } - } - // If append string was passed and append click function included - if (ellipsisSymbol != appendString && typeof(scope.ellipsisAppendClick) !== 'undefined' && scope.ellipsisAppendClick !== '') { - element.find('span.angular-ellipsis-append').bind("click", function(e) { - scope.$apply(function() { - scope.ellipsisAppendClick.call(scope, { - event: e + // If append string was passed and append click function included + if (ellipsisSymbol != appendString && typeof(scope.ellipsisAppendClick) !== 'undefined' && scope.ellipsisAppendClick !== '') { + element.find('span.angular-ellipsis-append').bind("click", function(e) { + scope.$apply(function() { + scope.ellipsisAppendClick.call(scope, { + event: e + }); }); }); - }); - } + } - if(!isTrustedHTML && $sce.isEnabled()) - { - $sce.trustAsHtml(binding); + if(!isTrustedHTML && $sce.isEnabled()) + { + $sce.trustAsHtml(binding); + } } - } - else{ - element.attr('data-overflowed', 'false'); - } + else{ + element.attr('data-overflowed', 'false'); + } + }); } } From c7ed91e72b55c60313422b90441b6b9c3f22a6bb Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 5 Oct 2017 20:12:34 +0100 Subject: [PATCH 2/2] fix 252c40d09857ca5de42bd98fb87774c1f59ed5a7 --- src/angular-ellipsis.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/angular-ellipsis.js b/src/angular-ellipsis.js index b9b1293..3bf288f 100644 --- a/src/angular-ellipsis.js +++ b/src/angular-ellipsis.js @@ -116,9 +116,7 @@ angular.module('dibari.angular-ellipsis', []) if (_isDefined(attributes.ellipsisFallbackFontSize) && isOverflowed(element)) { element.css('font-size',attributes.ellipsisFallbackFontSize); } - - - $timeout(function(){ + $timeout(function() { // If text has overflow if (isOverflowed(element, scope.useParent)) { var bindArrayStartingLength = bindArray.length, @@ -172,7 +170,7 @@ angular.module('dibari.angular-ellipsis', []) else{ element.attr('data-overflowed', 'false'); } - }); + }); } }