Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow special value of "initial" for "max" #32

Merged
merged 1 commit into from
Jan 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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