<commit_before>/*
 * HTML5 Forms Chapter JavaScript Library
 * http://thecssninja.com/javascript/H5F
 *
 * Copyright (c) 2010 <NAME> - http://thecssninja.com/
 * Dual-licensed under the BSD and MIT licenses.
 * http://thecssninja.com/H5F/license.txt
 */

var H5F = H5F || {};

(function(d){
    
    var field = d.createElement("input"),
        emailPatt = new RegExp("([a-z0-9_.-]+)@([0-9a-z.-]+).([a-z.]{2,6})","i"), 
        urlPatt = new RegExp("[a-z][-\.+a-z]*:\/\/","i"),
        usrPatt, curEvt, args;
    
    H5F.setup = function(form,settings) {
        var isCollection = !form.nodeType || false;
        
        var opts = {
            validClass : "valid",
            invalidClass : "error",
            requiredClass : "required"
        };

        if(typeof settings === "object") {
            for (var i in opts) {
                if(typeof settings[i] === "undefined") { settings[i] = opts[i]; }
            }
        }
        
        args = settings || opts;
        
        if(isCollection) {
            for(var k=0,len=form.length;k<len;k++) {
                H5F.validation(form[k]);
            }
        } else {
            H5F.validation(form);
        }
    };
    
    H5F.validation = function(form) {
        var    f = form.elements,
            flen = f.length,
            isRequired;
        
        H5F.listen(form,"invalid",H5F.checkField,true);
        H5F.listen(form,"blur",H5F.checkField,true);
        H5F.listen(form,"input",H5F.checkField,true);
        H5F.listen(form,"focus",H5F.checkField,true);
        
        if(!H5F.support()) { 
            form.checkValidity = function() { H5F.checkValidity(form); };
            
            while(flen--) {
                isRequired = !!(f[flen].attributes["required"]);
                // Firefox includes fieldsets inside elements nodelist so we filter it out.
                if(f[flen].nodeName !== "FIELDSET" && isRequired) {
                    H5F.validity(f[flen]); // Add validity object to field
                }
            }
        }
    };
    H5F.validity = function(el) {
        var elem = el,
            missing = H5F.valueMissing(elem),
            type = elem.getAttribute("type"),
            pattern = elem.getAttribute("pattern"),
            placeholder = elem.getAttribute("placeholder"),
            isType = /^(email|url|password)$/i,
            fType = ((isType.test(type)) ? type : ((pattern) ? pattern : false)),
            patt = H5F.pattern(elem,fType),
            step = H5F.range(elem,"step"),
            min = H5F.range(elem,"min"),
            max = H5F.range(elem,"max");
        
        elem.validity = {
            patternMismatch: patt,
            rangeOverflow: max,
            rangeUnderflow: min,
            stepMismatch: step,
            valid: (!missing && !patt && !step && !min && !max),
            valueMissing: missing
        };
        
        if(placeholder && curEvt !== "input") { H5F.placeholder(elem); }
        elem.checkValidity = function() { H5F.checkValidity(elem); };
    };
    H5F.checkField = function (e) {
        var el = H5F.getTarget(e) || e, // checkValidity method passes element not event
            events = /^(input|focusin|focus)$/i;
        
        curEvt = e.type;
        if(!H5F.support()) { H5F.validity(el); }
        
        if(el.validity.valid) {
            H5F.removeClass(el,args.invalidClass);
            H5F.removeClass(el,args.requiredClass);
            H5F.addClass(el,args.validClass);
        } else if(!events.test(curEvt)) {
            if(el.validity.valueMissing) {
                H5F.removeClass(el,args.invalidClass);
                H5F.removeClass(el,args.validClass);
                H5F.addClass(el,args.requiredClass);
            } else {
                H5F.removeClass(el,args.validClass);
                H5F.removeClass(el,args.requiredClass);
                H5F.addClass(el,args.invalidClass);
            }
        } else if(el.validity.valueMissing) {
            H5F.removeClass(el,args.requiredClass);
            H5F.removeClass(el,args.invalidClass);
            H5F.removeClass(el,args.validClass);
        }
    };
    H5F.checkValidity = function (el) {
        var f, ff, isRequired, invalid = false;
        
        if(el.nodeName === "FORM") {
            f = el.elements;
            
            for(var i = 0,len = f.length;i < len;i++) {
                ff = f[i];
                
                isRequired = !!(ff.attributes["required"]);
                
                if(ff.nodeName !== "FIELDSET" && isRequired) {
                    H5F.checkField(ff);
                    if(!ff.validity.valid && !invalid) {
                        ff.focus();
                        invalid = true;
                    }
                }
            }
        } else {
            H5F.checkField(el);
            return el.validity.valid;
        }
    };
    
    H5F.support = function() {
        return (H5F.isHostMethod(field,"validity") && H5F.isHostMethod(field,"checkValidity"));
    };

    // Create helper methods to emulate attributes in older browsers
    H5F.pattern = function(el, type) {
        if(type === "email") {
            return !emailPatt.test(el.value);
        } else if(type === "url") {
            return !urlPatt.test(el.value);
        } else if(!type || type === "password") { // Password can't be evalutated.
            return false;
        } else {
            usrPatt = new RegExp(type);
            return !usrPatt.test(el.value);
        }
    };
    H5F.placeholder = function(el) {
        var placeholder = el.getAttribute("placeholder"),
            focus = /^(focus|focusin)$/i,
            node = /^(input|textarea)$/i,
            isNative = !!("placeholder" in field);
        <commit_msg>explicity return result of H5F.checkValidity<commit_after>/*
 * HTML5 Forms Chapter JavaScript Library
 * http://thecssninja.com/javascript/H5F
 *
 * Copyright (c) 2010 <NAME> - http://thecssninja.com/
 * Dual-licensed under the BSD and MIT licenses.
 * http://thecssninja.com/H5F/license.txt
 */

var H5F = H5F || {};

(function(d){
    
    var field = d.createElement("input"),
        emailPatt = new RegExp("([a-z0-9_.-]+)@([0-9a-z.-]+).([a-z.]{2,6})","i"), 
        urlPatt = new RegExp("[a-z][-\.+a-z]*:\/\/","i"),
        usrPatt, curEvt, args;
    
    H5F.setup = function(form,settings) {
        var isCollection = !form.nodeType || false;
        
        var opts = {
            validClass : "valid",
            invalidClass : "error",
            requiredClass : "required"
        };

        if(typeof settings === "object") {
            for (var i in opts) {
                if(typeof settings[i] === "undefined") { settings[i] = opts[i]; }
            }
        }
        
        args = settings || opts;
        
        if(isCollection) {
            for(var k=0,len=form.length;k<len;k++) {
                H5F.validation(form[k]);
            }
        } else {
            H5F.validation(form);
        }
    };
    
    H5F.validation = function(form) {
        var    f = form.elements,
            flen = f.length,
            isRequired;
        
        H5F.listen(form,"invalid",H5F.checkField,true);
        H5F.listen(form,"blur",H5F.checkField,true);
        H5F.listen(form,"input",H5F.checkField,true);
        H5F.listen(form,"focus",H5F.checkField,true);
        
        if(!H5F.support()) { 
            form.checkValidity = function() { return H5F.checkValidity(form); };
            
            while(flen--) {
                isRequired = !!(f[flen].attributes["required"]);
                // Firefox includes fieldsets inside elements nodelist so we filter it out.
                if(f[flen].nodeName !== "FIELDSET" && isRequired) {
                    H5F.validity(f[flen]); // Add validity object to field
                }
            }
        }
    };
    H5F.validity = function(el) {
        var elem = el,
            missing = H5F.valueMissing(elem),
            type = elem.getAttribute("type"),
            pattern = elem.getAttribute("pattern"),
            placeholder = elem.getAttribute("placeholder"),
            isType = /^(email|url|password)$/i,
            fType = ((isType.test(type)) ? type : ((pattern) ? pattern : false)),
            patt = H5F.pattern(elem,fType),
            step = H5F.range(elem,"step"),
            min = H5F.range(elem,"min"),
            max = H5F.range(elem,"max");
        
        elem.validity = {
            patternMismatch: patt,
            rangeOverflow: max,
            rangeUnderflow: min,
            stepMismatch: step,
            valid: (!missing && !patt && !step && !min && !max),
            valueMissing: missing
        };
        
        if(placeholder && curEvt !== "input") { H5F.placeholder(elem); }
        elem.checkValidity = function() { return H5F.checkValidity(elem); };
    };
    H5F.checkField = function (e) {
        var el = H5F.getTarget(e) || e, // checkValidity method passes element not event
            events = /^(input|focusin|focus)$/i;
        
        curEvt = e.type;
        if(!H5F.support()) { H5F.validity(el); }
        
        if(el.validity.valid) {
            H5F.removeClass(el,args.invalidClass);
            H5F.removeClass(el,args.requiredClass);
            H5F.addClass(el,args.validClass);
        } else if(!events.test(curEvt)) {
            if(el.validity.valueMissing) {
                H5F.removeClass(el,args.invalidClass);
                H5F.removeClass(el,args.validClass);
                H5F.addClass(el,args.requiredClass);
            } else {
                H5F.removeClass(el,args.validClass);
                H5F.removeClass(el,args.requiredClass);
                H5F.addClass(el,args.invalidClass);
            }
        } else if(el.validity.valueMissing) {
            H5F.removeClass(el,args.requiredClass);
            H5F.removeClass(el,args.invalidClass);
            H5F.removeClass(el,args.validClass);
        }
    };
    H5F.checkValidity = function (el) {
        var f, ff, isRequired, invalid = false;
        
        if(el.nodeName === "FORM") {
            f = el.elements;
            
            for(var i = 0,len = f.length;i < len;i++) {
                ff = f[i];
                
                isRequired = !!(ff.attributes["required"]);
                
                if(ff.nodeName !== "FIELDSET" && isRequired) {
                    H5F.checkField(ff);
                    if(!ff.validity.valid && !invalid) {
                        ff.focus();
                        invalid = true;
                    }
                }
            }
            return !invalid;
        } else {
            H5F.checkField(el);
            return el.validity.valid;
        }
    };
    
    H5F.support = function() {
        return (H5F.isHostMethod(field,"validity") && H5F.isHostMethod(field,"checkValidity"));
    };

    // Create helper methods to emulate attributes in older browsers
    H5F.pattern = function(el, type) {
        if(type === "email") {
            return !emailPatt.test(el.value);
        } else if(type === "url") {
            return !urlPatt.test(el.value);
        } else if(!type || type === "password") { // Password can't be evalutated.
            return false;
        } else {
            usrPatt = new RegExp(type);
            return !usrPatt.test(el.value);
        }
    };
    H5F.placeholder = function(el) {
        var placeholder = el.getAttribute("placeholder"),
            focus = /^(focus|focusin)$/i,
            node = /^(input|textarea)$/i,
            isNative = !!("placeholder" in field);
        
{'fraction_non_alphanumeric': 0.14539677086911715, 'fraction_numerical': 0.011078667124699416, 'mean_word_length': 1.6051454138702461, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '1226742', 'n_tokens_mistral': 3598, 'n_tokens_neox': 3527, 'n_words': 592}