From f979bf6f972bd0fa5fc4a73be5bdb3b600c8a80f Mon Sep 17 00:00:00 2001 From: vivien anglesio Date: Sun, 16 Aug 2015 16:42:20 +0200 Subject: [PATCH 1/4] add fitHeight option --- src/ng-FitText.js | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/ng-FitText.js b/src/ng-FitText.js index e5cc8a3..588d729 100644 --- a/src/ng-FitText.js +++ b/src/ng-FitText.js @@ -19,6 +19,7 @@ 'debounce': false, 'delay': 250, 'loadDelay': 10, + 'fitHeight': false, 'min': undefined, 'max': undefined }) @@ -27,7 +28,8 @@ return { restrict: 'A', scope: true, - link: function(scope, element, attrs) { + link: function(scope, element, attrs) + { angular.extend(config, fitTextConfig.config); element[0].style.display = 'inline-block'; @@ -36,6 +38,7 @@ var parent = element.parent(); var compressor = attrs.fittext || 1; var loadDelay = attrs.fittextLoadDelay || config.loadDelay; + var fitHeight = attrs.fittextFitHeight || config.fitHeight; var nl = element[0].querySelectorAll('[fittext-nl],[data-fittext-nl]').length || 1; var minFontSize = attrs.fittextMin || config.min || Number.NEGATIVE_INFINITY; var maxFontSize = attrs.fittextMax || config.max || Number.POSITIVE_INFINITY; @@ -43,12 +46,23 @@ var resizer = function() { element[0].style.fontSize = '10px'; var ratio = element[0].offsetHeight / element[0].offsetWidth / nl; - element[0].style.fontSize = Math.max( - Math.min((parent[0].offsetWidth - 6) * ratio * compressor, - parseFloat(maxFontSize) - ), - parseFloat(minFontSize) - ) + 'px'; + var parentRatio = parent[0].offsetHeight / parent[0].offsetWidth + if (fitHeight && ratio < parentRatio) { + element[0].style.fontSize = Math.max( + Math.min((parent[0].offsetWidth - 6) * ratio * compressor, + parseFloat(maxFontSize) + ), + parseFloat(minFontSize) + ) + 'px'; + } + else { + element[0].style.fontSize = Math.max( + Math.min((parent[0].offsetHeight) * compressor, + parseFloat(maxFontSize) + ), + parseFloat(minFontSize) + ) + 'px'; + } }; $timeout( function() { resizer() }, loadDelay); From ca885dfb1f6ada09fe411ca319ccf2860b8a3567 Mon Sep 17 00:00:00 2001 From: vivien anglesio Date: Sun, 16 Aug 2015 18:18:30 +0200 Subject: [PATCH 2/4] add fitHeight option --- src/ng-FitText.js | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/ng-FitText.js b/src/ng-FitText.js index 588d729..c2892a6 100644 --- a/src/ng-FitText.js +++ b/src/ng-FitText.js @@ -47,22 +47,21 @@ element[0].style.fontSize = '10px'; var ratio = element[0].offsetHeight / element[0].offsetWidth / nl; var parentRatio = parent[0].offsetHeight / parent[0].offsetWidth - if (fitHeight && ratio < parentRatio) { - element[0].style.fontSize = Math.max( - Math.min((parent[0].offsetWidth - 6) * ratio * compressor, - parseFloat(maxFontSize) - ), - parseFloat(minFontSize) - ) + 'px'; - } - else { - element[0].style.fontSize = Math.max( - Math.min((parent[0].offsetHeight) * compressor, - parseFloat(maxFontSize) - ), - parseFloat(minFontSize) - ) + 'px'; - } + if (fitHeight && ratio < parentRatio) { + element[0].style.fontSize = Math.max( + Math.min((parent[0].offsetWidth - 6) * ratio * compressor, + parseFloat(maxFontSize) + ), + parseFloat(minFontSize) + ) + 'px'; + } else { + element[0].style.fontSize = Math.max( + Math.min((parent[0].offsetHeight) * compressor, + parseFloat(maxFontSize) + ), + parseFloat(minFontSize) + ) + 'px'; + } }; $timeout( function() { resizer() }, loadDelay); From f073d46fa28f97d99a4f3bd4f786ecfeb01d06fe Mon Sep 17 00:00:00 2001 From: vivien anglesio Date: Sun, 16 Aug 2015 18:22:34 +0200 Subject: [PATCH 3/4] indentation fix --- src/ng-FitText.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/ng-FitText.js b/src/ng-FitText.js index c2892a6..d27cb03 100644 --- a/src/ng-FitText.js +++ b/src/ng-FitText.js @@ -19,7 +19,7 @@ 'debounce': false, 'delay': 250, 'loadDelay': 10, - 'fitHeight': false, + 'fitHeight': false, 'min': undefined, 'max': undefined }) @@ -28,8 +28,7 @@ return { restrict: 'A', scope: true, - link: function(scope, element, attrs) - { + link: function(scope, element, attrs) { angular.extend(config, fitTextConfig.config); element[0].style.display = 'inline-block'; @@ -46,7 +45,7 @@ var resizer = function() { element[0].style.fontSize = '10px'; var ratio = element[0].offsetHeight / element[0].offsetWidth / nl; - var parentRatio = parent[0].offsetHeight / parent[0].offsetWidth + var parentRatio = parent[0].offsetHeight / parent[0].offsetWidth if (fitHeight && ratio < parentRatio) { element[0].style.fontSize = Math.max( Math.min((parent[0].offsetWidth - 6) * ratio * compressor, From a354adcd965394d529d383b8832ba2ff8fd06ce6 Mon Sep 17 00:00:00 2001 From: vivien anglesio Date: Sun, 16 Aug 2015 18:24:23 +0200 Subject: [PATCH 4/4] indentation fix --- src/ng-FitText.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ng-FitText.js b/src/ng-FitText.js index d27cb03..33c0448 100644 --- a/src/ng-FitText.js +++ b/src/ng-FitText.js @@ -37,7 +37,7 @@ var parent = element.parent(); var compressor = attrs.fittext || 1; var loadDelay = attrs.fittextLoadDelay || config.loadDelay; - var fitHeight = attrs.fittextFitHeight || config.fitHeight; + var fitHeight = attrs.fittextFitHeight || config.fitHeight; var nl = element[0].querySelectorAll('[fittext-nl],[data-fittext-nl]').length || 1; var minFontSize = attrs.fittextMin || config.min || Number.NEGATIVE_INFINITY; var maxFontSize = attrs.fittextMax || config.max || Number.POSITIVE_INFINITY;