forked from jquery-textfill/jquery-textfill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.textfill.min.js
15 lines (15 loc) · 1.31 KB
/
jquery.textfill.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*
textfill
@name jquery.textfill.js
@author Russ Painter
@author Yu-Jie Lin
@version 0.4.0
@date 2013-08-16
@copyright (c) 2012-2013 Yu-Jie Lin
@copyright (c) 2009 Russ Painter
@license MIT License
@homepage https://github.com/jquery-textfill/jquery-textfill
@example http://jquery-textfill.github.io/jquery-textfill/index.html
*/
(function(b){b.fn.textfill=function(k){function m(a,c,e,b,g,l,f,h){for(;f<h-1;)if(a=Math.floor((f+h)/2),c.css("font-size",a),e.call(c)<=b){if(f=a,e.call(c)==b)break}else h=a;c.css("font-size",h);e.call(c)<=b&&(f=h);return f}var a=b.extend({debug:!1,maxFontPixels:40,minFontPixels:4,innerTag:"span",widthOnly:!1,success:null,callback:null,fail:null,complete:null,explicitWidth:null,explicitHeight:null},k);this.each(function(){var d=b(a.innerTag+":visible:first",this),c=a.explicitHeight||b(this).height(),
e=a.explicitWidth||b(this).width(),k=d.css("font-size"),g=a.minFontPixels,l=0>=a.maxFontPixels?c:a.maxFontPixels,f=void 0;a.widthOnly||(f=m("H",d,b.fn.height,c,c,e,g,l));g=m("W",d,b.fn.width,e,c,e,g,l);a.widthOnly?d.css("font-size",g):d.css("font-size",Math.min(f,g));d.width()>e||d.height()>c&&!a.widthOnly?(d.css("font-size",k),a.fail&&a.fail(this)):a.success?a.success(this):a.callback&&a.callback(this)});a.complete&&a.complete(this);return this}})(window.jQuery);