diff --git a/jquery.fittext.js b/jquery.fittext.js index eebff96..49478e2 100644 --- a/jquery.fittext.js +++ b/jquery.fittext.js @@ -1,43 +1,42 @@ -/*global jQuery */ -/*! +/*jshint jquery:true strict:false*/ +/*! * FitText.js 1.0 * * Copyright 2011, Dave Rupert http://daverupert.com -* Released under the WTFPL license +* Released under the WTFPL license * http://sam.zoy.org/wtfpl/ * * Date: Thu May 05 14:23:00 2011 -0600 */ -(function( $ ){ +(function($){ + var defaults = { + 'minFontSize' : -9e99, + 'maxFontSize' : +9e99 + }; + + // Resizer() resizes items based on the object width divided by the compressor * 10 + function resizer (self, settings) { + return function () { + self.css('font-size', Math.max(Math.min( + self.width() / (settings.compressor * 10), + parseFloat(settings.maxFontSize)), + parseFloat(settings.minFontSize))); + }; + } - $.fn.fitText = function( kompressor, options ) { - + $.fn.fitText = function(compressor, options) { // Setup options - var compressor = kompressor || 1, - settings = $.extend({ - 'minFontSize' : Number.NEGATIVE_INFINITY, - 'maxFontSize' : Number.POSITIVE_INFINITY - }, options); - - return this.each(function(){ - - // Store the object - var $this = $(this); - - // Resizer() resizes items based on the object width divided by the compressor * 10 - var resizer = function () { - $this.css('font-size', Math.max(Math.min($this.width() / (compressor*10), parseFloat(settings.maxFontSize)), parseFloat(settings.minFontSize))); - }; + var settings = $.extend({'compressor' : compressor || 1}, defaults, options); - // Call once to set. - resizer(); - - // Call on resize. Opera debounces their resize by default. - $(window).on('resize', resizer); - - }); + return this + .each(function(){ + // Call on resize. Opera debounces their resize by default. + $(window) + .on('resize', resizer($(this), settings)) + .trigger('resize'); + }); }; -})( jQuery ); \ No newline at end of file +}(jQuery));