<commit_before>﻿/*
@todo: New event binding method to avoid binding multiple events for the same element.
85% :(
Fix IE8
https://github.com/davatron5000/FitText.js/commit/57ce345437f9b1871ece163a15954595a6e02b1e
Put up forkable codepen-link
Set up grunt-script for minification
*/

/**
 * textStretch.js pre-version alpha (2013.11.29)
 *
 * Copyright (c) 2012, 2013 <NAME> (<EMAIL>)
 * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
 *
 **/

(function ($) {
	"use strict";
	//  add class for calculating width. let me know if you see this and know a better way
	$("<style>").text(".textStretch-calc{ *display: inline !important; display: inline-block !important; white-space: nowrap !important; width: auto !important; text-align: left !important; }").appendTo("head");

	$.fn.textStretch = function (options) {
		var _settings, _dotextStretch, _useElementWidth, _recalc, _letterAverage, _fontSize, _width, _i, $this, $elements = $(this);

		// import user settings
		_settings = $.extend($.textStretch.defaults, options);

		// no width specified. use element width (doesn't work for for inline or inline-blocks)
		_useElementWidth = (_settings.width === null);

		_dotextStretch = function () {
			for (_i = 0; _i < $elements.length; _i += 1) {
				$this = $($elements[_i]);

				// use element's width if no width specified
				if (_useElementWidth) {
					_width = $this.width();
				} else {
					if (typeof _settings.width !== "number") {
						throw "$.textStretch error: Width is not a number";
					}
					_width = _settings.width;
				}

				// checking if we already have pre-stored _letterAverage
				if(_settings.refresh || !(_letterAverage = $this.data("textStretchLetterAverage"))){
					// temporarily apply class for measuring width
					$this.addClass("textStretch-calc");

					// width of text / 90% of font-size (to be safe)
					_letterAverage = ($this.width() / (parseInt($this.css("fontSize"), 10) * 0.90));

					// remove measuring-class
					$this.removeClass("textStretch-calc");

					// store in element for faster regeneration
					$this.data("textStretchLetterAverage", _letterAverage);
				}

				// overwritten unless within specified font-size span
				_fontSize = Math.min(Math.max(parseInt(_width / _letterAverage, 10), _settings.minFontSize), _settings.maxFontSize);

				// apply font-size
				$this.css("fontSize", _fontSize + "px");

				// determine if a vertical scrollbar has been added or removed, in which case we have to recalculate
				_recalc = (_useElementWidth && _width !== $this.width());
			}
		};

		// run
		_dotextStretch();

		// recalculate if needed
		if (_recalc) {
			_dotextStretch();
		}
		// bind to resize ands viewport-change. not needed for fixed width
		if (_useElementWidth) {
			$(window).on("orientationchange resize", _dotextStretch);
		}
		return $elements;
	};
	$.textStretch = {
		defaults: {
			width: null,
			minFontSize: 0,
			maxFontSize: Number.POSITIVE_INFINITY,
			refresh: false
		}
	};
}(jQuery));<commit_msg>fallback to element width if NaN width given<commit_after>﻿/*
@todo: New event binding method to avoid binding multiple events for the same element.
85% :(
Fix IE8
https://github.com/davatron5000/FitText.js/commit/57ce345437f9b1871ece163a15954595a6e02b1e
Put up forkable codepen-link
Set up grunt-script for minification
*/

/**
 * textStretch.js pre-version alpha (2013.11.29)
 *
 * Copyright (c) 2012, 2013 <NAME> (<EMAIL>)
 * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
 *
 **/

(function ($) {
	"use strict";
	//  add class for calculating width. let me know if you see this and know a better way
	$("<style>").text(".textStretch-calc{ *display: inline !important; display: inline-block !important; white-space: nowrap !important; width: auto !important; text-align: left !important; }").appendTo("head");

	$.fn.textStretch = function (options) {
		var _settings, _dotextStretch, _useElementWidth, _recalc, _letterAverage, _fontSize, _width, _i, $this, $elements = $(this);

		// import user settings
		_settings = $.extend($.textStretch.defaults, options);

		// no width specified. use element width (doesn't work for for inline or inline-blocks)
		_useElementWidth = (_settings.width === null);

		_dotextStretch = function () {
			for (_i = 0; _i < $elements.length; _i += 1) {
				$this = $($elements[_i]);

				// use element's width if no width specified
				if (_useElementWidth) {
					_width = $this.width();
				} else {
					if (typeof _settings.width !== "number") {
						throw "$.textStretch error: Width is not a number";
					}
					else {
						_width = _settings.width;
					}
				}

				// checking if we already have pre-stored _letterAverage
				if(_settings.refresh || !(_letterAverage = $this.data("textStretchLetterAverage"))){
					// temporarily apply class for measuring width
					$this.addClass("textStretch-calc");

					// width of text / 90% of font-size (to be safe)
					_letterAverage = ($this.width() / (parseInt($this.css("fontSize"), 10) * 0.90));

					// remove measuring-class
					$this.removeClass("textStretch-calc");

					// store in element for faster regeneration
					$this.data("textStretchLetterAverage", _letterAverage);
				}

				// overwritten unless within specified font-size span
				_fontSize = Math.min(Math.max(parseInt(_width / _letterAverage, 10), _settings.minFontSize), _settings.maxFontSize);

				// apply font-size
				$this.css("fontSize", _fontSize + "px");

				// determine if a vertical scrollbar has been added or removed, in which case we have to recalculate
				_recalc = (_useElementWidth && _width !== $this.width());
			}
		};

		// run
		_dotextStretch();

		// recalculate if needed
		if (_recalc) {
			_dotextStretch();
		}
		// bind to resize ands viewport-change. not needed for fixed width
		if (_useElementWidth) {
			$(window).on("orientationchange resize", _dotextStretch);
		}
		return $elements;
	};
	$.textStretch = {
		defaults: {
			width: null,
			minFontSize: 0,
			maxFontSize: Number.POSITIVE_INFINITY,
			refresh: false
		}
	};
}(jQuery));
{'fraction_non_alphanumeric': 0.13081441498650578, 'fraction_numerical': 0.020003175107159866, 'mean_word_length': 3.106910039113429, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3474974', 'n_tokens_mistral': 2432, 'n_tokens_neox': 1941, 'n_words': 549}