From 8d49f8ef8a35326a2f642cfa372e2d0602db90fc Mon Sep 17 00:00:00 2001 From: danne_j87 Date: Fri, 21 Oct 2016 12:53:47 +0200 Subject: [PATCH 1/2] Add a optional callback to the settings object --- jquery.fittext.js | 67 ++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/jquery.fittext.js b/jquery.fittext.js index 0b3ddef..aaebe80 100644 --- a/jquery.fittext.js +++ b/jquery.fittext.js @@ -1,43 +1,50 @@ /*global jQuery */ /*! -* FitText.js 1.2 -* -* Copyright 2011, Dave Rupert http://daverupert.com -* Released under the WTFPL license -* http://sam.zoy.org/wtfpl/ -* -* Date: Thu May 05 14:23:00 2011 -0600 -*/ + * FitText.js 1.2 + * + * Copyright 2011, Dave Rupert http://daverupert.com + * Released under the WTFPL license + * http://sam.zoy.org/wtfpl/ + * + * Date: Thu May 05 14:23:00 2011 -0600 + */ -(function( $ ){ +(function ($) { - $.fn.fitText = function( kompressor, options ) { + $.fn.fitText = function (kompressor, options) { - // Setup options - var compressor = kompressor || 1, - settings = $.extend({ - 'minFontSize' : Number.NEGATIVE_INFINITY, - 'maxFontSize' : Number.POSITIVE_INFINITY - }, options); + // Setup options + var compressor = kompressor || 1, + settings = $.extend({ + 'minFontSize': Number.NEGATIVE_INFINITY, + 'maxFontSize': Number.POSITIVE_INFINITY, + 'callback': function () {} + }, options), + result = null; - return this.each(function(){ + return this.each(function () { - // Store the object - var $this = $(this); + // 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))); - }; + // 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))); + }; - // Call once to set. - resizer(); + // Call once to set. + resizer(); - // Call on resize. Opera debounces their resize by default. - $(window).on('resize.fittext orientationchange.fittext', resizer); + // Call on resize. Opera debounces their resize by default. + $(window).on('resize.fittext orientationchange.fittext', resizer); - }); + }); - }; + // Run Callback + options.callback.call(this); -})( jQuery ); + return result; + + }; + +})(jQuery); From d7d852bdd5dfefa4555fdf6fe99dd7946a49c0fc Mon Sep 17 00:00:00 2001 From: danne_j87 Date: Fri, 21 Oct 2016 12:58:17 +0200 Subject: [PATCH 2/2] Updated README.md with a callback example --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index cb08849..2c53ec2 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,16 @@ FitText now allows you to specify two optional pixel values: `minFontSize` and ` jQuery("#responsive_headline").fitText(1.2, { minFontSize: '20px', maxFontSize: '40px' }); ``` +## Callback +FitText supports a callback that will run once fitText has iterated over every item and done it's calculations. + +```javascript +function callbackFunc() { + console.log('Done'); +} +jQuery("#responsive_headline").fitText(1.2, {callback: callbackFunc}); +``` + ## CSS FAQ - :warning: Run FitText before anything that hides the element you're trying to size (e.g. before Carousels, Scrollers, Accordions, Tabs, etc). Hiding an element's container removes its width. It can't resize without a width.