Skip to content

Commit 0af12af

Browse files
Cache element
1 parent 809fb9a commit 0af12af

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

bower.json

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

dist/ng-FitText.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ng-fittext",
3-
"version": "4.1.0",
3+
"version": "4.1.1",
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

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* ng-FitText.js v4.1.0
2+
* ng-FitText.js v4.1.1
33
* https://github.com/patrickmarabeas/ng-FitText.js
44
*
55
* Original jQuery project: https://github.com/davatron5000/FitText.js
@@ -39,6 +39,8 @@
3939
angular.extend(config, fitTextConfig.config);
4040

4141
var parent = element.parent()
42+
, domElem = element[0]
43+
, domElemStyle = domElem.style
4244
, computed = window.getComputedStyle(element[0], null)
4345
, newlines = element.children().length || 1
4446
, loadDelay = attrs.fittextLoadDelay || config.loadDelay
@@ -51,7 +53,7 @@
5153
;
5254

5355
function calculate() {
54-
var ratio = (calcSize * newlines) / element[0].offsetWidth / newlines;
56+
var ratio = (calcSize * newlines) / domElem.offsetWidth / newlines;
5557
return Math.max(
5658
Math.min((parent[0].offsetWidth - 6) * ratio * compressor,
5759
parseFloat(maxFontSize)
@@ -62,18 +64,18 @@
6264

6365
function resizer() {
6466
// Don't calculate for elements with no width or height
65-
if (element[0].offsetHeight * element[0].offsetWidth === 0)
67+
if (domElem.offsetHeight * domElem.offsetWidth === 0)
6668
return;
6769

6870
// Set standard values for calculation
69-
element[0].style.fontSize = calcSize + 'px';
70-
element[0].style.lineHeight = '1';
71-
element[0].style.display = 'inline-block';
71+
domElemStyle.fontSize = calcSize + 'px';
72+
domElemStyle.lineHeight = '1';
73+
domElemStyle.display = 'inline-block';
7274

7375
// Set usage values
74-
element[0].style.fontSize = calculate() + 'px';
75-
element[0].style.lineHeight = lineHeight;
76-
element[0].style.display = display;
76+
domElemStyle.fontSize = calculate() + 'px';
77+
domElemStyle.lineHeight = lineHeight;
78+
domElemStyle.display = display;
7779
}
7880

7981
$timeout( function() { resizer() }, loadDelay);

0 commit comments

Comments
 (0)