From c21f1a1171854cf5c524372d84b6aeae3181adec Mon Sep 17 00:00:00 2001 From: Patrick Marabeas Date: Sat, 23 Jan 2016 15:13:58 +1100 Subject: [PATCH] Ability to set min to inherited CSS font-size value Breaking change: 'initial' replaced with 'inherit' --- bower.json | 2 +- dist/ng-FitText.min.js | 2 +- index.html | 3 ++- package.json | 2 +- src/ng-FitText.js | 9 +++++---- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/bower.json b/bower.json index 74458e7..a3df391 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "ngFitText", - "version": "4.0.0", + "version": "4.1.0", "main": [ "dist/ng-FitText.min.js" ], diff --git a/dist/ng-FitText.min.js b/dist/ng-FitText.min.js index 0f26d5e..e8bb16a 100644 --- a/dist/ng-FitText.min.js +++ b/dist/ng-FitText.min.js @@ -1 +1 @@ -!function(t,e,i,n){"use strict";i.module("ngFitText",[]).value("fitTextDefaultConfig",{debounce:!1,delay:250,loadDelay:10,compressor:1,min:0,max:Number.POSITIVE_INFINITY}).directive("fittext",["$timeout","fitTextDefaultConfig","fitTextConfig",function(e,n,o){return{restrict:"A",scope:!0,link:function(f,l,a){function r(){var t=b*d/l[0].offsetWidth/d;return Math.max(Math.min((u[0].offsetWidth-6)*t*g,parseFloat(p)),parseFloat(h))}function s(){l[0].offsetHeight*l[0].offsetWidth!==0&&(l[0].style.fontSize=b+"px",l[0].style.lineHeight="1",l[0].style.display="inline-block",l[0].style.fontSize=r()+"px",l[0].style.lineHeight=y,l[0].style.display=m)}i.extend(n,o.config);var u=l.parent(),c=t.getComputedStyle(l[0],null),d=l.children().length||1,x=a.fittextLoadDelay||n.loadDelay,g=a.fittext||n.compressor,h=a.fittextMin||n.min,p=("initial"===a.fittextMax?c["font-size"]:a.fittextMax)||n.max,y=c["line-height"],m=c.display,b=10;e(function(){s()},x),f.$watch(a.ngBind,function(){s()}),n.debounce?i.element(t).bind("resize",n.debounce(function(){f.$apply(s)},n.delay)):i.element(t).bind("resize",function(){f.$apply(s)})}}}]).provider("fitTextConfig",function(){var t=this;return this.config={},this.$get=function(){var e={};return e.config=t.config,e},this})}(window,document,angular); \ No newline at end of file +!function(t,e,i,n){"use strict";i.module("ngFitText",[]).value("fitTextDefaultConfig",{debounce:!1,delay:250,loadDelay:10,compressor:1,min:0,max:Number.POSITIVE_INFINITY}).directive("fittext",["$timeout","fitTextDefaultConfig","fitTextConfig",function(e,n,o){return{restrict:"A",scope:!0,link:function(f,l,a){function r(){var t=b*d/l[0].offsetWidth/d;return Math.max(Math.min((u[0].offsetWidth-6)*t*h,parseFloat(p)),parseFloat(g))}function s(){l[0].offsetHeight*l[0].offsetWidth!==0&&(l[0].style.fontSize=b+"px",l[0].style.lineHeight="1",l[0].style.display="inline-block",l[0].style.fontSize=r()+"px",l[0].style.lineHeight=y,l[0].style.display=m)}i.extend(n,o.config);var u=l.parent(),c=t.getComputedStyle(l[0],null),d=l.children().length||1,x=a.fittextLoadDelay||n.loadDelay,h=a.fittext||n.compressor,g=("inherit"===a.fittextMin?c["font-size"]:a.fittextMin)||n.min,p=("inherit"===a.fittextMax?c["font-size"]:a.fittextMax)||n.max,y=c["line-height"],m=c.display,b=10;e(function(){s()},x),f.$watch(a.ngBind,function(){s()}),n.debounce?i.element(t).bind("resize",n.debounce(function(){f.$apply(s)},n.delay)):i.element(t).bind("resize",function(){f.$apply(s)})}}}]).provider("fitTextConfig",function(){var t=this;return this.config={},this.$get=function(){var e={};return e.config=t.config,e},this})}(window,document,angular); \ No newline at end of file diff --git a/index.html b/index.html index d5e0b77..ed09d06 100644 --- a/index.html +++ b/index.html @@ -48,7 +48,8 @@

ng-FitText.js can do that too, at the same price

-

Max font size is CSS font-size

+

Inherit max font size from CSS

+

Inherit min font size from CSS

Child block elements will use font size of longest element

diff --git a/package.json b/package.json index 857249b..16aaa92 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ng-fittext", - "version": "4.0.0", + "version": "4.1.0", "description": "An AngularJS directive for inflating web type", "homepage": "https://github.com/patrickmarabeas/ng-FitText.js", "bugs": "https://github.com/patrickmarabeas/ng-FitText.js/issues", diff --git a/src/ng-FitText.js b/src/ng-FitText.js index 3fae8bb..cee1fc5 100644 --- a/src/ng-FitText.js +++ b/src/ng-FitText.js @@ -1,4 +1,5 @@ -/* ng-FitText.js v4.0.0 +/** + * ng-FitText.js v4.1.0 * https://github.com/patrickmarabeas/ng-FitText.js * * Original jQuery project: https://github.com/davatron5000/FitText.js @@ -7,7 +8,7 @@ * Released under the MIT license * http://opensource.org/licenses/mit-license.php * - * Date: 18/01/2016 + * Date: 23/01/2016 */ (function(window, document, angular, undefined) { @@ -42,8 +43,8 @@ , newlines = element.children().length || 1 , loadDelay = attrs.fittextLoadDelay || config.loadDelay , compressor = attrs.fittext || config.compressor - , minFontSize = attrs.fittextMin || config.min - , maxFontSize = (attrs.fittextMax === 'initial' ? computed['font-size'] : attrs.fittextMax) || config.max + , minFontSize = (attrs.fittextMin ==='inherit' ? computed['font-size'] : attrs.fittextMin) || config.min + , maxFontSize = (attrs.fittextMax === 'inherit' ? computed['font-size'] : attrs.fittextMax) || config.max , lineHeight = computed['line-height'] , display = computed['display'] , calcSize = 10