/*global jQuery */
/*!
* OTBFitText.js 1.0
*
* Copyright 2019, Out the Box https://www.outtheboxthemes.com
* A variation on the FitText jQuery plugin by Dave Rupert http://daverupert.com
* Released under the WTFPL license
* http://sam.zoy.org/wtfpl/
*
* Date: Wed June 05 21:22:00 2019 -0600
*/

(function ($) {

    $.fn.OTBFitText = function (kompressor, 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 () {
            	console.log(Math.max(Math.min($this.parent().width() / (compressor * 10), parseFloat(settings.maxFontSize)), parseFloat(settings.minFontSize)));
                $this.css('font-size', Math.max(Math.min($this.parent().width() / (compressor * 10), parseFloat(settings.maxFontSize)), parseFloat(settings.minFontSize)));
            };

      // Call once to set.
      resizer();

      // Call on resize. Opera debounces their resize by default.
      $(window).on('resize.fittext orientationchange.fittext', resizer);

    });

  };

})( jQuery );
