Skip to content

Commit

Permalink
Merge pull request #71 from ventralnet/master
Browse files Browse the repository at this point in the history
#70 Ability to specify a fall back font size before ellipsising takes place
  • Loading branch information
MauMaGau authored Aug 26, 2016
2 parents 0aca49a + 93b3742 commit d67a1c6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ If a custom append string is included, a function can be executed on the resulti
You can use string separator to split the string by something else than " " (space). Example (split by characters):
``<p data-ng-bind="paragraphText" data-ellipsis data-separator=""></p>``

* **Fallback Font-Size**
You can specify a fallback font size. If text is detected to overflow an attempt to resize the text to the fallback font-size will be made before ellipsis are added.
``<p data-ng-bind="paragraphText" data-ellipsis data.ellipsis-falback-font-size="90%"></p>``

COMPATIBILITY
--------
Works on modern web browers, which includes any relatively recent version of Chrome, Firefox, Safari, and IE 9+. Although there is no formally-maintained list, mobile device support is quite thorough. I will update cross-browser and device issues if they are entered as issues.
Expand Down
11 changes: 10 additions & 1 deletion src/angular-ellipsis.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ angular.module('dibari.angular-ellipsis', [])
ellipsisSymbol: '@',
ellipsisSeparator: '@',
useParent: "@",
ellipsisSeparatorReg: '='
ellipsisSeparatorReg: '=',
ellipsisFallbackFontSize:'@'
},
compile: function(elem, attr, linker) {

Expand All @@ -75,6 +76,10 @@ angular.module('dibari.angular-ellipsis', [])
/* State Variables */
attributes.isTruncated = false;

function _isDefined(value) {
return typeof(value) !== 'undefined';
}

function getParentHeight(element) {
var heightOfChildren = 0;
angular.forEach(element.parent().children(), function(child) {
Expand Down Expand Up @@ -108,6 +113,10 @@ angular.module('dibari.angular-ellipsis', [])
element.text(binding);
}

if (_isDefined(attributes.ellipsisFallbackFontSize) && isOverflowed(element)) {
element.css('font-size',attributes.ellipsisFallbackFontSize);
}

// If text has overflow
if (isOverflowed(element, scope.useParent)) {
var bindArrayStartingLength = bindArray.length,
Expand Down

0 comments on commit d67a1c6

Please sign in to comment.