diff --git a/src/angular-ellipsis.js b/src/angular-ellipsis.js index 1c5eb12..cdbcf05 100644 --- a/src/angular-ellipsis.js +++ b/src/angular-ellipsis.js @@ -114,7 +114,7 @@ angular.module('dibari.angular-ellipsis', []) } if (_isDefined(attributes.ellipsisFallbackFontSize) && isOverflowed(element)) { - element.css('font-size',attributes.ellipsisFallbackFontSize); + element.css('font-size',attributes.ellipsisFallbackFontSize); } // If text has overflow @@ -130,6 +130,9 @@ angular.module('dibari.angular-ellipsis', []) //Set data-overflow on element for targeting element.attr('data-overflowed', 'true'); + // Set variable for full text retrieval in parent scope (like in bootstrap popover, title...) + scope.$parent.$overflowFull = binding; + // Set complete text and remove one word at a time, until there is no overflow for (; i < bindArrayStartingLength; i++) { var current = bindArray.pop(); @@ -168,7 +171,9 @@ angular.module('dibari.angular-ellipsis', []) } } else{ + // remove set data in case text is no longer overflowing element.attr('data-overflowed', 'false'); + scope.$parent.$overflowFull = ''; } } } @@ -221,7 +226,7 @@ angular.module('dibari.angular-ellipsis', []) /** * Execute ellipsis truncate when element becomes visible */ - scope.$watch(function() { return element[0].offsetWidth != 0 && element[0].offsetHeight != 0 }, function() { + scope.$watch(function() { return element[0].offsetWidth !== 0 && element[0].offsetHeight !== 0 }, function() { asyncDigestDebounced.add(buildEllipsis); }); diff --git a/src/angular-ellipsis.min.js b/src/angular-ellipsis.min.js index e0d1fcb..0afc65c 100644 --- a/src/angular-ellipsis.min.js +++ b/src/angular-ellipsis.min.js @@ -1 +1 @@ -angular.module("dibari.angular-ellipsis",[]).directive("ellipsis",["$timeout","$window","$sce",function(a,b,c){var d=function(b){var c=null,d=[];this.remove=function(b){-1!==d.indexOf(b)&&(d.splice(d.indexOf(b),1),0===d.length&&(a.cancel(c),c=null))},this.add=function(e){-1===d.indexOf(e)&&d.push(e),c||(c=a(function(){var a=d.slice();c=null,d.length=0,a.forEach(function(a){a()})},b))}},e=new d(0),f=new d(75);return{restrict:"A",scope:{ngBind:"=",ngBindHtml:"=",ellipsisAppend:"@",ellipsisAppendClick:"&",ellipsisSymbol:"@",ellipsisSeparator:"@",useParent:"@",ellipsisSeparatorReg:"="},compile:function(a,d,g){return function(a,d,g){function h(a){var b=0;return angular.forEach(a.parent().children(),function(c){c!=a[0]&&(b+=c.clientHeight)}),a.parent()[0].clientHeight-b}function i(){var b=a.ngBind||a.ngBindHtml,e=!1;if(c.isEnabled()&&angular.isObject(b)&&c.getTrustedHtml(b)&&(e=!0,b=c.getTrustedHtml(b)),b){var f=!a.ngBind&&!!a.ngBindHtml,i=0,k="undefined"!=typeof g.ellipsisSymbol?g.ellipsisSymbol:"…",l="undefined"!=typeof a.ellipsisSeparator?g.ellipsisSeparator:" ",m="undefined"!=typeof a.ellipsisSeparatorReg?a.ellipsisSeparatorReg:!1,n="undefined"!=typeof a.ellipsisAppend&&""!==a.ellipsisAppend?k+""+a.ellipsisAppend+"":k,o=m?b.match(m):b.split(l);if(g.isTruncated=!1,f?d.html(b):d.text(b),j(d,a.useParent)){var p=o.length,q=a.useParent?h(d):d[0].clientHeight;for(f?d.html(b+n):d.text(b).html(d.html()+n),d.attr("data-overflowed","true");p>i;i++)if(o.pop(),f?d.html(o.join(l)+n):d.text(o.join(l)).html(d.html()+n),(a.useParent?d.parent()[0]:d[0]).scrollHeighta[0].clientHeight}function k(){(g.lastWindowResizeWidth!=window.innerWidth||g.lastWindowResizeHeight!=window.innerHeight)&&i(),g.lastWindowResizeWidth=window.innerWidth,g.lastWindowResizeHeight=window.innerHeight}function l(){f.add(k)}g.lastWindowResizeTime=0,g.lastWindowResizeWidth=0,g.lastWindowResizeHeight=0,g.lastWindowTimeoutEvent=null,g.isTruncated=!1,a.$watch("ngBind",function(){e.add(i)}),a.$watch("ngBindHtml",function(){e.add(i)}),a.$watch("ellipsisAppend",function(){i()});var m=angular.element(b);m.bind("resize",l),a.$on("$destroy",function(){m.unbind("resize",l),e.remove(i),f.remove(k)})}}}}]); \ No newline at end of file +angular.module("dibari.angular-ellipsis",[]).directive("ellipsis",["$timeout","$window","$sce",function(a,b,c){var d=function(b){var c=null,d=[];this.remove=function(b){-1!==d.indexOf(b)&&(d.splice(d.indexOf(b),1),0===d.length&&(a.cancel(c),c=null))},this.add=function(e){-1===d.indexOf(e)&&d.push(e),c||(c=a(function(){var a=d.slice();c=null,d.length=0,a.forEach(function(a){a()})},b))}},e=new d(0),f=new d(75);return{restrict:"A",scope:{ngShow:"=",ngBind:"=",ngBindHtml:"=",ellipsisAppend:"@",ellipsisAppendClick:"&",ellipsisSymbol:"@",ellipsisSeparator:"@",useParent:"@",ellipsisSeparatorReg:"=",ellipsisFallbackFontSize:"@"},compile:function(a,d,g){return function(a,d,g){function h(a){return"undefined"!=typeof a}function i(a){var b=0;return angular.forEach(a.parent().children(),function(c){c!=a[0]&&(b+=c.clientHeight)}),a.parent()[0].clientHeight-b}function j(){var b=a.ngBind||a.ngBindHtml,e=!1;if(c.isEnabled()&&angular.isObject(b)&&c.getTrustedHtml(b)&&(e=!0,b=c.getTrustedHtml(b)),b){var f=!a.ngBind&&!!a.ngBindHtml,j=0,l="undefined"!=typeof g.ellipsisSymbol?g.ellipsisSymbol:"…",m="undefined"!=typeof a.ellipsisSeparator?g.ellipsisSeparator:" ",n="undefined"!=typeof a.ellipsisSeparatorReg?a.ellipsisSeparatorReg:!1,o="undefined"!=typeof a.ellipsisAppend&&""!==a.ellipsisAppend?l+""+a.ellipsisAppend+"":l,p=n?b.match(n):b.split(m);if(g.isTruncated=!1,f?d.html(b):d.text(b),h(g.ellipsisFallbackFontSize)&&k(d)&&d.css("font-size",g.ellipsisFallbackFontSize),k(d,a.useParent)){var q=p.length,r=a.useParent?i(d):d[0].clientHeight;for(f?d.html(b+o):d.text(b).html(d.html()+o),d.attr("data-overflowed","true"),a.$parent.$overflowFull=b;q>j;j++){var s=p.pop();if(0===p.length&&(p[0]=s.substring(0,Math.min(s.length,5))),f?d.html(p.join(m)+o):d.text(p.join(m)).html(d.html()+o),(a.useParent?d.parent()[0]:d[0]).scrollHeighta[0].clientHeight}function l(){(g.lastWindowResizeWidth!=window.innerWidth||g.lastWindowResizeHeight!=window.innerHeight)&&j(),g.lastWindowResizeWidth=window.innerWidth,g.lastWindowResizeHeight=window.innerHeight}function m(){f.add(l)}g.lastWindowResizeTime=0,g.lastWindowResizeWidth=0,g.lastWindowResizeHeight=0,g.lastWindowTimeoutEvent=null,g.isTruncated=!1,a.$watch("ngShow",function(){e.add(j)}),a.$watch("ngBind",function(){e.add(j)}),a.$watch("ngBindHtml",function(){e.add(j)}),a.$watch("ellipsisAppend",function(){j()}),a.$watch(function(){return 0!==d[0].offsetWidth&&0!==d[0].offsetHeight},function(){f.add(j)});var n=a.$on("dibari:refresh-ellipsis",function(){e.add(j)}),o=angular.element(b);o.bind("resize",m),a.$on("$destroy",function(){o.unbind("resize",m),e.remove(j),f.remove(l),n&&(n(),n=null)})}}}}]); \ No newline at end of file