<commit_before>/*
	jquery forces forms plugin

	Forms validation helper

	requires jquery
	requires jquery.scrollTo plugin
	requires HTML5 constraint validation API (native browser or polyfill)
	tested with polyfill forces.html5.constraintValidationAPI

*/

(function( $ ) {
	'use strict';

	// TODO this is used by 'unique id', better wrap it in a function
	var i = 0,

	SUBMIT_TOLERANCE = 10000, // milliseconds

	DEFAULT_STATUS_HTML = '<div class="status warn"><div class="inner"><h2>Unable to process this form</h2><ol></ol></div></div>',

	// fields that validate
	candidateForValidation = 'input, select, textarea',


	// invalidFilter
	invalidFilter = function() {
		return ! ( this.disabled || this.validity.valid );
	},


	// follow plugin conventions for storing plugin data
	// http://docs.jquery.com/Plugins/Authoring#Data
	pluginDataKey = 'forcesForms',
	pluginData = function( key, value ) {
		var dataHash = this.data( pluginDataKey ) || this.data( pluginDataKey, {}).data( pluginDataKey );

			if ( key ) {
				if ( value ) {
					dataHash[ key ] = value;
					return value;

				} else if ( typeof dataHash[ key ] !== 'undefined' ) {
					return dataHash[ key ];
				}
				return null;
			}

			return dataHash;
	},


	// helper for .label, .hint and .alert
	getLabelComponent = function( component, options ) {
		return this.map(function( index, domElement ) {

			var $element = $( domElement ),
				labelElement = null,
				foundElement = null;

			if ( typeof options === 'object' && options.level === 'group' ) {
				foundElement = $element.closest( '.group' ).find( component )[ 0 ];

			} else if ( $element.is( ':radio' )) {
				foundElement = $element.closest( 'fieldset' ).find( component )[ 0 ];

			} else {
				labelElement = $element.closest( 'form' ).find( 'label[for=' + domElement.id + ']' );
				foundElement = labelElement.children( component )[ 0 ];
				if ( ! foundElement ) {
					if ( component === '.hint' ) {
						labelElement.append( '<small class="hint"></small>' );
						foundElement = labelElement.children( component )[ 0 ];
					}
				}
			}

			return foundElement;

		});
	},
	

	changeValidityCheck = function() {

		var $this = $( this ),
			alertElement = $this.forcesForms( 'alert' ),
			alertLevel = undefined
		;

		// is this control valid?
		if ( this.validity.valid ) {

			alertElement.remove();

			// remove invalid class from ancestors that do not contain invalid fields
			$this.parentsUntil( 'form', '.invalid' ).filter(function() {
				return $( this ).find( candidateForValidation ).filter( invalidFilter ).length === 0;
			})
				// remove .invalid class
				.removeClass( 'invalid' )
				// remove old alerts (change handler should have already done this)
				.find( '.alert' ).remove()
			;<commit_msg>jslint fix (no need to declare a var as undefined)<commit_after>/*
	jquery forces forms plugin

	Forms validation helper

	requires jquery
	requires jquery.scrollTo plugin
	requires HTML5 constraint validation API (native browser or polyfill)
	tested with polyfill forces.html5.constraintValidationAPI

*/

(function( $ ) {
	'use strict';

	// TODO this is used by 'unique id', better wrap it in a function
	var i = 0,

	SUBMIT_TOLERANCE = 10000, // milliseconds

	DEFAULT_STATUS_HTML = '<div class="status warn"><div class="inner"><h2>Unable to process this form</h2><ol></ol></div></div>',

	// fields that validate
	candidateForValidation = 'input, select, textarea',


	// invalidFilter
	invalidFilter = function() {
		return ! ( this.disabled || this.validity.valid );
	},


	// follow plugin conventions for storing plugin data
	// http://docs.jquery.com/Plugins/Authoring#Data
	pluginDataKey = 'forcesForms',
	pluginData = function( key, value ) {
		var dataHash = this.data( pluginDataKey ) || this.data( pluginDataKey, {}).data( pluginDataKey );

			if ( key ) {
				if ( value ) {
					dataHash[ key ] = value;
					return value;

				} else if ( typeof dataHash[ key ] !== 'undefined' ) {
					return dataHash[ key ];
				}
				return null;
			}

			return dataHash;
	},


	// helper for .label, .hint and .alert
	getLabelComponent = function( component, options ) {
		return this.map(function( index, domElement ) {

			var $element = $( domElement ),
				labelElement = null,
				foundElement = null;

			if ( typeof options === 'object' && options.level === 'group' ) {
				foundElement = $element.closest( '.group' ).find( component )[ 0 ];

			} else if ( $element.is( ':radio' )) {
				foundElement = $element.closest( 'fieldset' ).find( component )[ 0 ];

			} else {
				labelElement = $element.closest( 'form' ).find( 'label[for=' + domElement.id + ']' );
				foundElement = labelElement.children( component )[ 0 ];
				if ( ! foundElement ) {
					if ( component === '.hint' ) {
						labelElement.append( '<small class="hint"></small>' );
						foundElement = labelElement.children( component )[ 0 ];
					}
				}
			}

			return foundElement;

		});
	},
	

	changeValidityCheck = function() {

		var $this = $( this ),
			alertElement = $this.forcesForms( 'alert' ),
			alertLevel
		;

		// is this control valid?
		if ( this.validity.valid ) {

			alertElement.remove();

			// remove invalid class from ancestors that do not contain invalid fields
			$this.parentsUntil( 'form', '.invalid' ).filter(function() {
				return $( this ).find( candidateForValidation ).filter( invalidFilter ).length === 0;
			})
				// remove .invalid class
				.removeClass( 'invalid' )
				// remove old alerts (change handler should have already done this)
				.find( '.alert' ).remove()
			;
{'fraction_non_alphanumeric': 0.14193432621568275, 'fraction_numerical': 0.005383097075183922, 'mean_word_length': 3.1784107946026987, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5365538', 'n_tokens_mistral': 1978, 'n_tokens_neox': 1633, 'n_words': 488}