Skip to content

Commit

Permalink
allow special value of "initial" for "max" option to avoid increasing…
Browse files Browse the repository at this point in the history
… font size
  • Loading branch information
Merott committed Jul 31, 2015
1 parent 6d60c52 commit ebffb34
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ The FitText directive will also watch the `ng-model` placed on the element, so g

The `data-fittext-max=""` and `data-fittext-min=""` attributes respectfully limit the font size. This can also be set globally in the `fitTextConfigProvider` via `min` and `max`.

You may set `data-fittext-max` to the special value `"initial"` in order to prevent the font size from increasing beyond the CSS-computed style. This requires the `font-size` property to have been either inherited, or applied via a CSS selector. It does not work for inline `font-size` set via an inline `style` attribute. It also requires support for `window.getComputedStyle()` (IE 9+).

#### New lines

To make use of new lines within a single FitText block you will need to use the `data-fittext-nl` attribute on each line wrapper. See the demo page for an example.
Expand Down
5 changes: 5 additions & 0 deletions src/ng-FitText.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
var minFontSize = attrs.fittextMin || config.min || Number.NEGATIVE_INFINITY;
var maxFontSize = attrs.fittextMax || config.max || Number.POSITIVE_INFINITY;

if(maxFontSize == 'initial' && window.getComputedStyle) {
element[0].style['font-size'] = "";
maxFontSize = window.getComputedStyle(element[0])['font-size'];
}

var resizer = function() {
element[0].style.fontSize = '10px';
var ratio = element[0].offsetHeight / element[0].offsetWidth / nl;
Expand Down

0 comments on commit ebffb34

Please sign in to comment.