|
1 |
| -/* ng-FitText.js v3.0.0 |
| 1 | +/* ng-FitText.js v3.1.0 |
2 | 2 | * https://github.com/patrickmarabeas/ng-FitText.js
|
3 | 3 | *
|
4 | 4 | * Original jQuery project: https://github.com/davatron5000/FitText.js
|
|
8 | 8 | * Released under the MIT license
|
9 | 9 | * http://opensource.org/licenses/mit-license.php
|
10 | 10 | *
|
11 |
| - * Date: 18/09/2014 |
| 11 | + * Date: 18/10/2014 |
12 | 12 | */
|
13 | 13 |
|
14 | 14 | (function(window, document, angular, undefined) {
|
|
27 | 27 | return {
|
28 | 28 | restrict: 'A',
|
29 | 29 | scope: true,
|
30 |
| - transclude: true, |
31 |
| - replace: true, |
32 |
| - template: function(element, attrs) { |
33 |
| - var tag = element[0].nodeName; |
34 |
| - return "<" + tag + " data-ng-transclude data-ng-style='{fontSize:fontSize}'></" + tag + ">"; |
35 |
| - }, |
36 | 30 | link: function(scope, element, attrs) {
|
37 | 31 | angular.extend(config, fitTextConfig.config);
|
38 | 32 |
|
39 | 33 | element[0].style.display = 'inline-block';
|
40 | 34 | element[0].style.whiteSpace = 'nowrap';
|
41 | 35 | element[0].style.lineHeight = '1';
|
42 | 36 |
|
43 |
| - scope.compressor = attrs.fittext || 1; |
44 |
| - scope.minFontSize = attrs.fittextMin || config.min || Number.NEGATIVE_INFINITY; |
45 |
| - scope.maxFontSize = attrs.fittextMax || config.max || Number.POSITIVE_INFINITY; |
| 37 | + var parent = element.parent(); |
| 38 | + var compressor = attrs.fittext || 1; |
| 39 | + var minFontSize = attrs.fittextMin || config.min || Number.NEGATIVE_INFINITY; |
| 40 | + var maxFontSize = attrs.fittextMax || config.max || Number.POSITIVE_INFINITY; |
46 | 41 |
|
47 |
| - (scope.resizer = function() { |
| 42 | + var resizer = function() { |
48 | 43 | $timeout( function() {
|
49 |
| - scope.ratio = element[0].offsetHeight / element[0].offsetWidth; |
50 |
| - scope.fontSize = Math.max( |
51 |
| - Math.min(element.parent()[0].offsetWidth * scope.ratio * scope.compressor, |
52 |
| - parseFloat(scope.maxFontSize) |
53 |
| - ), |
54 |
| - parseFloat(scope.minFontSize) |
55 |
| - ) + 'px'; |
56 |
| - },100); |
57 |
| - })(); |
| 44 | + var ratio = element[0].offsetHeight / element[0].offsetWidth; |
| 45 | + element[0].style.fontSize = Math.max( |
| 46 | + Math.min(parent[0].offsetWidth * ratio * compressor, |
| 47 | + parseFloat(maxFontSize) |
| 48 | + ), |
| 49 | + parseFloat(minFontSize) |
| 50 | + ) + 'px'; |
| 51 | + },50); |
| 52 | + }; resizer(); |
58 | 53 |
|
59 |
| - scope.$watch(attrs.ngModel, function() { scope.resizer() }); |
| 54 | + scope.$watch(attrs.ngModel, function() { resizer() }); |
60 | 55 |
|
61 | 56 | config.debounce
|
62 |
| - ? angular.element(window).bind('resize', config.debounce(function(){ scope.$apply(scope.resizer)}, config.delay)) |
63 |
| - : angular.element(window).bind('resize', function(){ scope.$apply(scope.resizer)}); |
| 57 | + ? angular.element(window).bind('resize', config.debounce(function(){ scope.$apply(resizer)}, config.delay)) |
| 58 | + : angular.element(window).bind('resize', function(){ scope.$apply(resizer)}); |
64 | 59 | }
|
65 | 60 | }
|
66 | 61 | }])
|
|
0 commit comments