<commit_before>﻿/*!
 * jQuery bValidator plugin
 *
 * http://code.google.com/p/bvalidator/
 *
 * Copyright (c) 2012 <NAME>
 *
 * Released under the MIT license
 * http://www.opensource.org/licenses/mit-license.php
 *
 * $Id: jquery.bvalidator.js 115 2014-03-03 01:48:19Z bmauser $
 */

(function($){

	// constructor
	$.fn.bValidator = function(overrideOptions, instanceName){
		return this.each(function(){
			new bValidator($(this), overrideOptions, instanceName);
   		});
	};

	// bValidator class
	bValidator = function(mainElement, overrideOptions, instanceName){

		// default options
		var options = {

			singleError:         false,		// validate all inputs at once
			offset:              {x:-23, y:-4},	// offset position for error message tooltip
			position:            {x:'right', y:'top'}, // error message placement x:left|center|right  y:top|center|bottom
			template:            '<div class="{errMsgClass}"><em/>{message}</div>', // template for error message
			templateCloseIcon:   '<div style="display:table"><div style="display:table-cell">{message}</div><div style="display:table-cell"><div class="{closeIconClass}">x</div></div></div>', // template for error message container when showCloseIcon option is true
			showCloseIcon:       true,	// put close icon on error message
			showErrMsgSpeed:    'normal',	// message's fade-in speed 'fast', 'normal', 'slow' or number of milliseconds
			scrollToError:       true,	// scroll to first error
			// css class names
			classNamePrefix:     'bvalidator_',	// prefix for css class names
			closeIconClass:      'close_icon',	// close error message icon class
			errMsgClass:         'errmsg',		// error message class
			errorClass:          'invalid',		// input field class name in case of validation error
			validClass:          '',		// input field class name in case of valid value

			lang: 'en', 				// default language for error messages 
			errorMessageAttr:    'data-bvalidator-msg',// name of the attribute for overridden error message
			validateActionsAttr: 'data-bvalidator', // name of the attribute which stores info what validation actions to do
			forceValidAttr:      'data-bvalidator-forcevalid', // name of the attribute which which makes validator to act like the field is valid
			modifyActionsAttr:   'data-bvalidator-modifier',
			paramsDelimiter:     ':',		// delimiter for validator action options inside []
			actionsDelimiter:    ',',		// delimiter for validator actions

			// when to validate
			validateOn:          null,		// null, 'change', 'blur', 'keyup'
			errorValidateOn:     'keyup',		// null, 'change', 'blur', 'keyup'

			// callback functions
			onBeforeValidate:    null,
			onAfterValidate:     null,
			onValidateFail:      null,
			onValidateSuccess:   null,
			onBeforeElementValidation: null,
			onAfterElementValidation:  null,
			onBeforeAllValidations:    null,
			onAfterAllValidations:     null,
			
			validateOnSubmit: true,  // should validation occur on form submit if validator is bind to a form
			stopSubmitPropagation: true, // should submit event be stopped on error if validator is bind to a form
			noMsgIfExistsForInstance: [],
			validateTillInvalid: false,
			
			autoModifiers: {
				'digit':  ['trim'],
				'number': ['trim'],
				'email':  ['trim'],
				'url':    ['trim'],
				'date':   ['trim'],
				'ip4':    ['trim'],
				'ip6':    ['trim']
				},
			
			ajaxAnswerValid: 'ok',
			ajaxDelay: 300,
			ajaxOptions: {cache: false},
			ajaxParamName: 'bValue',

			// default messages
			errorMessages: {
				en: {
					'default':    'Please correct this value.',
					'equalto':    'Please enter the same value again.',
					'differs':    'Please enter a different value.',
					'minlength':  'The length must be at least {0} characters',
					'maxlength':  'The length must be at max {0} characters',
					'rangelength':'The length must be between {0} and {1}',
					'min':        'Please enter a number greater than or equal to {0}.',
					'max':        'Please enter a number less than or equal to {0}.',
					'between':    'Please enter a number between {0} and {1}.',
					'required':   'This field is required.',
					'alpha':      'Please enter alphabetic characters only.',
					'alphanum':   'Please enter alphanumeric characters only.',
					'digit':      'Please enter only digits.',
					'number':     'Please enter a valid number.',
					'email':      'Please enter a valid email address.',
					'image':      'This field should only contain image types',
					'url':        'Please enter a valid URL.',
					'ip4':        'Please enter a valid IPv4 address.',
					'ip6':        'Please enter a valid IPv6 address.',
					'date':       'Please enter a valid date in format {0}.'
				}
			}
		},

		_ajaxValidation = function(element, instanceName, ajaxUrl, sync){
			
			var ajax_data = element.data("ajaxData.bV" + instanceName);
			
			if(!ajax_data){
				ajax_data = {};
				element.data("ajaxData.bV" + instanceName, ajax_data);
			}
			else{
				clearTimeout(ajax_data.timeOut);
			}
			
			// value to validate
			ajax_data.val = element.val();
			
			// do not do ajax if value is already validated
			if(ajax_data.lastValidated === ajax_data.val)
				return validator.ajax(ajax_data.lastResponse);
			
			var ajaxOptions = $.extend({}, options.ajaxOptions);
			if(typeof ajaxOptions.data != 'object')
				ajaxOptions.data = {}
			ajaxOptions.url = ajaxUrl;
			
			if(sync){
				var ret = false;
				ajaxOptions.async = false;
				ajaxOptions.data[options.ajaxParamName] = ajax_data.val;
				
				$.ajax(ajaxOptions).done(function(ajaxResponse){
					ajax_data.lastValidated = ajax_data.val;
					ajax_data.lastResponse = ajaxResponse;
					ret = validator.ajax(ajaxResponse)
				});
		
				return ret;
			}
			else{
				ajax_data.timeOut = setTimeout(function() {
	
					var val =  element.val();
					
					// only check if the value has not changed
					if(ajax_data.val == val){
						
						ajaxOptions.async = true;
						ajaxOptions.data[options.ajaxParamName] = val;
						
						$.ajax(ajaxOptions).done(function(ajaxResponse){
							ajax_data.lastValidated = val;
							ajax_data.lastResponse = ajaxResponse;
							instance.validate(false, element, undefined, ajaxResponse)
						});
					}
				}, options.ajaxDelay);
			}
			
			return;
		},

		// returns all inputs
		_getElementsForValidation = function(element){
			// skip hidden and input fields witch we do not want to validate
			return element.is(':input') ? element : element.find(':input[' + options.validateActionsAttr + '], :input[' + options.modifyActionsAttr + ']').not(":button, :image, :reset, :submit, :hidden, :disabled");
		},

		// binds validateOn event<commit_msg>ajaxParams option added<commit_after>﻿/*!
 * jQuery bValidator plugin
 *
 * http://code.google.com/p/bvalidator/
 *
 * Copyright (c) 2012 <NAME>
 *
 * Released under the MIT license
 * http://www.opensource.org/licenses/mit-license.php
 *
 * $Id: jquery.bvalidator.js 125 2014-03-14 00:22:10Z bmauser $
 */

(function($){

	// constructor
	$.fn.bValidator = function(overrideOptions, instanceName){
		return this.each(function(){
			new bValidator($(this), overrideOptions, instanceName);
   		});
	};

	// bValidator class
	bValidator = function(mainElement, overrideOptions, instanceName){

		// default options
		var options = {

			singleError:         false,		// validate all inputs at once
			offset:              {x:-23, y:-4},	// offset position for error message tooltip
			position:            {x:'right', y:'top'}, // error message placement x:left|center|right  y:top|center|bottom
			template:            '<div class="{errMsgClass}"><em/>{message}</div>', // template for error message
			templateCloseIcon:   '<div style="display:table"><div style="display:table-cell">{message}</div><div style="display:table-cell"><div class="{closeIconClass}">x</div></div></div>', // template for error message container when showCloseIcon option is true
			showCloseIcon:       true,	// put close icon on error message
			showErrMsgSpeed:    'normal',	// message's fade-in speed 'fast', 'normal', 'slow' or number of milliseconds
			scrollToError:       true,	// scroll to first error
			// css class names
			classNamePrefix:     'bvalidator_',	// prefix for css class names
			closeIconClass:      'close_icon',	// close error message icon class
			errMsgClass:         'errmsg',		// error message class
			errorClass:          'invalid',		// input field class name in case of validation error
			validClass:          '',		// input field class name in case of valid value

			lang: 'en', 				// default language for error messages 
			errorMessageAttr:    'data-bvalidator-msg',// name of the attribute for overridden error message
			validateActionsAttr: 'data-bvalidator', // name of the attribute which stores info what validation actions to do
			forceValidAttr:      'data-bvalidator-forcevalid', // name of the attribute which which makes validator to act like the field is valid
			modifyActionsAttr:   'data-bvalidator-modifier',
			paramsDelimiter:     ':',		// delimiter for validator action options inside []
			actionsDelimiter:    ',',		// delimiter for validator actions

			// when to validate
			validateOn:          null,		// null, 'change', 'blur', 'keyup'
			errorValidateOn:     'keyup',		// null, 'change', 'blur', 'keyup'

			// callback functions
			onBeforeValidate:    null,
			onAfterValidate:     null,
			onValidateFail:      null,
			onValidateSuccess:   null,
			onBeforeElementValidation: null,
			onAfterElementValidation:  null,
			onBeforeAllValidations:    null,
			onAfterAllValidations:     null,
			
			validateOnSubmit: true,  // should validation occur on form submit if validator is bind to a form
			stopSubmitPropagation: true, // should submit event be stopped on error if validator is bind to a form
			noMsgIfExistsForInstance: [],
			validateTillInvalid: false,
			
			autoModifiers: {
				'digit':  ['trim'],
				'number': ['trim'],
				'email':  ['trim'],
				'url':    ['trim'],
				'date':   ['trim'],
				'ip4':    ['trim'],
				'ip6':    ['trim']
				},
			
			ajaxAnswerValid: 'ok',
			ajaxDelay: 300,
			ajaxOptions: {cache: false},
			ajaxParamName: 'bValue',
			ajaxParams: null,

			// default messages
			errorMessages: {
				en: {
					'default':    'Please correct this value.',
					'equalto':    'Please enter the same value again.',
					'differs':    'Please enter a different value.',
					'minlength':  'The length must be at least {0} characters',
					'maxlength':  'The length must be at max {0} characters',
					'rangelength':'The length must be between {0} and {1}',
					'min':        'Please enter a number greater than or equal to {0}.',
					'max':        'Please enter a number less than or equal to {0}.',
					'between':    'Please enter a number between {0} and {1}.',
					'required':   'This field is required.',
					'alpha':      'Please enter alphabetic characters only.',
					'alphanum':   'Please enter alphanumeric characters only.',
					'digit':      'Please enter only digits.',
					'number':     'Please enter a valid number.',
					'email':      'Please enter a valid email address.',
					'image':      'This field should only contain image types',
					'url':        'Please enter a valid URL.',
					'ip4':        'Please enter a valid IPv4 address.',
					'ip6':        'Please enter a valid IPv6 address.',
					'date':       'Please enter a valid date in format {0}.'
				}
			}
		},

		_ajaxValidation = function(element, instanceName, ajaxUrl, sync){
			
			var ajax_data = element.data("ajaxData.bV" + instanceName);
			
			if(!ajax_data){
				ajax_data = {};
				element.data("ajaxData.bV" + instanceName, ajax_data);
			}
			else{
				clearTimeout(ajax_data.timeOut);
			}
			
			// value to validate
			ajax_data.val = element.val();
			
			// do not do ajax if value is already validated
			if(ajax_data.lastValidated === ajax_data.val)
				return validator.ajax(ajax_data.lastResponse);
			
			var ajaxOptions = $.extend({}, options.ajaxOptions);
			if(typeof ajaxOptions.data != 'object')
				ajaxOptions.data = {}
			ajaxOptions.url = ajaxUrl;
			
			if(options.ajaxParams)
				$.extend(true, ajaxOptions.data, typeof options.ajaxParams == 'function' ? options.ajaxParams.call(element[0]) : options.ajaxParams);
			
			if(sync){
				var ret = false;
				ajaxOptions.async = false;
				ajaxOptions.data[options.ajaxParamName] = ajax_data.val;
				
				$.ajax(ajaxOptions).done(function(ajaxResponse){
					ajax_data.lastValidated = ajax_data.val;
					ajax_data.lastResponse = ajaxResponse;
					ret = validator.ajax(ajaxResponse)
				});
		
				return ret;
			}
			else{
				ajax_data.timeOut = setTimeout(function() {
	
					var val = element.val();
					
					// only check if the value has not changed
					if(ajax_data.val == val){
						
						ajaxOptions.async = true;
						ajaxOptions.data[options.ajaxParamName] = val;
						
						$.ajax(ajaxOptions).done(function(ajaxResponse){
							ajax_data.lastValidated = val;
							ajax_data.lastResponse = ajaxResponse;
							instance.validate(false, element, undefined, ajaxResponse)
						});
					}
				}, options.ajaxDelay);
			}
			
			return;
		},

		// returns all inputs
		_getElementsForValidation = function(element){
			// skip hidden and input fields witch we do not want to validate
			return element.is(':input') ? element : element.find(':input[' + options.validateActionsAttr + '], :input[' + options.modifyActionsAttr + ']').not(":button, :image, :reset, :submit, :hidden, :disabled");
		},

		// binds validateOn event
{'fraction_non_alphanumeric': 0.12683607520564041, 'fraction_numerical': 0.006242655699177438, 'mean_word_length': 2.921947004608295, 'pattern_counts': {'":': 2, '<': 27, '<?xml version=': 0, '>': 27, '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': '3352633', 'n_tokens_mistral': 4878, 'n_tokens_neox': 3968, 'n_words': 1185}