<commit_before>/**
 * Glamorous Utilities - Some cool additions to Javascript and handy functions
 * Documentation and usage in README file
 *
 * @author <NAME> - Glamorous
 * @since 07.04.2010
 * @date 05.09.2011
 * @copyright <NAME> - Glamorous
 * @version 0.2.0
 * @license BSD http://www.opensource.org/licenses/bsd-license.php
 *
 */
(function($) {
	// Set the utilities plugin
	$.glamUtilities = function(settings)
	{
		settings = $.extend({}, $.glamUtilities.defaults, settings);

		// Method to search for all links and add a target='_blank' to it
		function changeExternalLinks()
		{
			var links = $('a');
			var l_length = links.length;
			var external_links = [];
			for (var i=0;i<l_length;i++)
			{
				var href = $(links[i]).attr('href');

				if (href !== undefined && href.match(/^https?\:/i) && !href.match(document.domain))
				{
					external_links.push(links[i]);
				}
			}
			var $extlinks = $(external_links);

			if(settings.externalLinks === true)
			{
				$extlinks.attr('target','_blank');
			}

			if(settings.externalClass !== false)
			{
				$extlinks.addClass(settings.externalClass);
			}
		}

		// Method to set defaultValue as a inside label for text inputs and textareas
		function setInsideLabels(text_inputs)
		{
			var $inputs = (text_inputs === true) ? $("form input[type=text], form textarea, form input[type=email]") : text_inputs;

			$inputs.each(function(){
				var input = $(this);
				input.click(function(){
					if(input.val() == this.defaultValue){
						input.val("");
					}
				});
				input.blur(function(){
					if(input.val() == ""){
						input.val(this.defaultValue);
					}
				});
			});

		}

		// Method to extend the jQuery Validate plugin with a rule for defaultValue
		function setValidateDefault(settings)
		{
			// Test if validator is not undefined
			if(jQuery.validator !== undefined)
			{
				jQuery.validator.addMethod(settings.name, function(value, element) {
					return this.optional(element) || element.defaultValue != value;
				}, settings.error);
			}
		}

		// Look wich custom methods has to be called
		function init()
		{
			if(settings.externalClass !== false || settings.externalLinks === true){changeExternalLinks();}
			if(settings.defaultValueAsLabel !== false){setInsideLabels(settings.defaultValueAsLabel);}
			if(settings.validateDefaultValue !== false){setValidateDefault(settings.validateDefaultValue);}
		}

		init();
	};

	// Default settings for Utilities plugin
	$.glamUtilities.defaults =
	{
		debug: false,
		externalLinks: true,
		externalClass: 'external',
		defaultValueAsLabel: false,
		validateDefaultValue: false
	};

	// Glamorous SCROLLING
	$.glamScroll = function(selector, speed)
	{
		speed = (speed !== undefined) ? speed : 500;
		$('html,body').animate({
			scrollTop: $(selector).offset().top
		}, speed);
	};

	// Glamorous LOGGING
	$.glamLog = function(message, type, plugin)
	{
		var msg = '['+type+'] '+plugin+' - '+message;
		if(window.console !== undefined) {
			switch(type)
			{
				case 'DEBUG':
					console.debug(msg);
					break;
				case 'INFO':
					console.info(msg);
					break;
				case 'WARN':
					console.warn(msg);
					break;
				case 'ERROR':<commit_msg>Changed internal working of custom validator rule with an easier default working<commit_after>/**
 * Glamorous Utilities - Some cool additions to Javascript and handy functions
 * Documentation and usage in README file
 *
 * @author <NAME> - Glamorous
 * @since 07.04.2010
 * @date 05.09.2011
 * @copyright <NAME> - Glamorous
 * @version 0.2.0
 * @license BSD http://www.opensource.org/licenses/bsd-license.php
 *
 */
(function($) {
	// Set the utilities plugin
	$.glamUtilities = function(settings)
	{
		settings = $.extend({}, $.glamUtilities.defaults, settings);

		// Method to search for all links and add a target='_blank' to it
		function changeExternalLinks()
		{
			var links = $('a');
			var l_length = links.length;
			var external_links = [];
			for (var i=0;i<l_length;i++)
			{
				var href = $(links[i]).attr('href');

				if (href !== undefined && href.match(/^https?\:/i) && !href.match(document.domain))
				{
					external_links.push(links[i]);
				}
			}
			var $extlinks = $(external_links);

			if(settings.externalLinks === true)
			{
				$extlinks.attr('target','_blank');
			}

			if(settings.externalClass !== false)
			{
				$extlinks.addClass(settings.externalClass);
			}
		}

		// Method to set defaultValue as a inside label for text inputs and textareas
		function setInsideLabels(text_inputs)
		{
			var $inputs = (text_inputs === true) ? $("form input[type=text], form textarea, form input[type=email]") : text_inputs;

			$inputs.each(function(){
				var input = $(this);
				input.click(function(){
					if(input.val() == this.defaultValue){
						input.val("");
					}
				});
				input.blur(function(){
					if(input.val() == ""){
						input.val(this.defaultValue);
					}
				});
			});

		}

		// Method to extend the jQuery Validate plugin with a rule for defaultValue
		function setValidateDefault(presets)
		{
			// Test if validator is not undefined
			if(jQuery.validator !== undefined)
			{
				var method = (presets.name !== undefined) ? presets.name : settings.validateDefaultMethod;
				var error = (presets.error !== undefined) ? presets.error : settings.validateDefaultErrorMessage;

				jQuery.validator.addMethod(method, function(value, element) {
					return this.optional(element) || element.defaultValue != value;
				}, error);
			}
		}

		// Look wich custom methods has to be called
		function init()
		{
			if(settings.externalClass !== false || settings.externalLinks === true){changeExternalLinks();}
			if(settings.defaultValueAsLabel !== false){setInsideLabels(settings.defaultValueAsLabel);}
			if(settings.validateDefaultValue !== false){setValidateDefault(settings.validateDefaultValue);}
		}

		init();
	};

	// Default settings for Utilities plugin
	$.glamUtilities.defaults =
	{
		debug: false,
		externalLinks: true,
		externalClass: 'external',
		defaultValueAsLabel: false,
		validateDefaultValue: false,
		validateDefaultMethod: 'defaultValue',
		validateDefaultErrorMessage: 'The field can\'t be the default value'
	};

	// Glamorous SCROLLING
	$.glamScroll = function(selector, speed)
	{
		speed = (speed !== undefined) ? speed : 500;
		$('html,body').animate({
			scrollTop: $(selector).offset().top
		}, speed);
	};

	// Glamorous LOGGING
	$.glamLog = function(message, type, plugin)
	{
		var msg = '['+type+'] '+plugin+' - '+message;
		if(window.console !== undefined) {
			switch(type)
			{
				case 'DEBUG':
					console.debug(msg);
					break;
				case 'INFO':
					console.info(msg);
					break;
				case 'WARN':
					console.warn(msg);
					break;
				case 'ERROR':
{'fraction_non_alphanumeric': 0.15076420833951626, 'fraction_numerical': 0.006825938566552901, 'mean_word_length': 3.440052700922266, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, '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': '4116890', 'n_tokens_mistral': 2547, 'n_tokens_neox': 2095, 'n_words': 492}