Skip to content

Commit c424a29

Browse files
Remove scope clutter and fix directive usage within transcluded templates
1 parent b335aa1 commit c424a29

File tree

3 files changed

+21
-26
lines changed

3 files changed

+21
-26
lines changed

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ngFitText",
3-
"version": "3.0.0",
3+
"version": "3.1.0",
44
"main": [
55
"/src/ng-FitText.js"
66
],

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ngFitText",
3-
"version": "3.0.0",
3+
"version": "3.1.0",
44
"description": "An AngularJS directive for inflating web type",
55
"homepage": "https://github.com/patrickmarabeas/ng-FitText.js",
66
"bugs": "https://github.com/patrickmarabeas/ng-FitText.js/issues",

src/ng-FitText.js

+19-24
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* ng-FitText.js v3.0.0
1+
/* ng-FitText.js v3.1.0
22
* https://github.com/patrickmarabeas/ng-FitText.js
33
*
44
* Original jQuery project: https://github.com/davatron5000/FitText.js
@@ -8,7 +8,7 @@
88
* Released under the MIT license
99
* http://opensource.org/licenses/mit-license.php
1010
*
11-
* Date: 18/09/2014
11+
* Date: 18/10/2014
1212
*/
1313

1414
(function(window, document, angular, undefined) {
@@ -27,40 +27,35 @@
2727
return {
2828
restrict: 'A',
2929
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-
},
3630
link: function(scope, element, attrs) {
3731
angular.extend(config, fitTextConfig.config);
3832

3933
element[0].style.display = 'inline-block';
4034
element[0].style.whiteSpace = 'nowrap';
4135
element[0].style.lineHeight = '1';
4236

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;
4641

47-
(scope.resizer = function() {
42+
var resizer = function() {
4843
$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();
5853

59-
scope.$watch(attrs.ngModel, function() { scope.resizer() });
54+
scope.$watch(attrs.ngModel, function() { resizer() });
6055

6156
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)});
6459
}
6560
}
6661
}])

0 commit comments

Comments
 (0)