/*! H5F * https://github.com/ryanseddon/H5F/ * Copyright (c) Ryan Seddon | Licensed MIT */ (function (root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. define(factory); } else if (typeof module === 'object' && module.exports) { // CommonJS module.exports = factory(); } else { // Browser globals root.H5F = factory(); } }(this, function () { var d = document, field = d.createElement("input"), emailPatt = /^[a-zA-Z0-9.!#$%&'*+-\/=?\^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/, urlPatt = /[a-z][\-\.+a-z]*:\/\//i, nodes = /^(input|select|textarea)$/i, isSubmit, bypassSubmit, usrPatt, curEvt, args, // Methods setup, validation, validity, checkField, bypassChecks, checkValidity, setCustomValidity, support, pattern, placeholder, range, required, valueMissing, listen, unlisten, preventActions, getTarget, addClass, removeClass, isHostMethod, isSiblingChecked; setup = function(form, settings) { var isCollection = !form.nodeType || false; var opts = { validClass : "valid", invalidClass : "error", requiredClass : "required", placeholderClass : "placeholder", onSubmit : Function.prototype, onInvalid : Function.prototype }; 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 max) : false; } } else if(el.getAttribute("type") === "number") { return true; } else { return false; } }; required = function(el) { var required = !!(el.attributes["required"]); return (required) ? valueMissing(el) : false; }; valueMissing = function(el) { var placeholder = el.getAttribute("placeholder"), specialTypes = /^(checkbox|radio)$/i, isRequired = !!(el.attributes["required"]); return !!(isRequired && (el.value === "" || el.value === placeholder || (specialTypes.test(el.type) && !isSiblingChecked(el)))); }; /* Util methods */ listen = function (node,type,fn,capture) { if(isHostMethod(window,"addEventListener")) { /* FF & Other Browsers */ node.addEventListener( type, fn, capture ); } else if(isHostMethod(window,"attachEvent") && typeof window.event !== "undefined") { /* Internet Explorer way */ if(type === "blur") { type = "focusout"; } else if(type === "focus") { type = "focusin"; } node.attachEvent( "on" + type, fn ); } }; unlisten = function (node,type,fn,capture) { if(isHostMethod(window,"removeEventListener")) { /* FF & Other Browsers */ node.removeEventListener( type, fn, capture ); } else if(isHostMethod(window,"detachEvent") && typeof window.event !== "undefined") { /* Internet Explorer way */ node.detachEvent( "on" + type, fn ); } }; preventActions = function (evt) { evt = evt || window.event; if(evt.stopPropagation && evt.preventDefault) { evt.stopPropagation(); evt.preventDefault(); } else { evt.cancelBubble = true; evt.returnValue = false; } }; getTarget = function (evt) { evt = evt || window.event; return evt.target || evt.srcElement; }; addClass = function (e,c) { var re; if (!e.className) { e.className = c; } else { re = new RegExp('(^|\\s)' + c + '(\\s|$)'); if (!re.test(e.className)) { e.className += ' ' + c; } } }; removeClass = function (e,c) { var re, m, arr = (typeof c === "object") ? c.length : 1, len = arr; if (e.className) { if (e.className === c) { e.className = ''; } else { while(arr--) { re = new RegExp('(^|\\s)' + ((len > 1) ? c[arr] : c) + '(\\s|$)'); m = e.className.match(re); if (m && m.length === 3) { e.className = e.className.replace(re, (m[1] && m[2])?' ':''); } } } } }; isHostMethod = function(o, m) { var t = typeof o[m], reFeaturedMethod = new RegExp('^function|object$', 'i'); return !!((reFeaturedMethod.test(t) && o[m]) || t === 'unknown'); }; /* Checking if one of the radio siblings is checked */ isSiblingChecked = function(el) { var siblings = document.getElementsByName(el.name); for(var i=0; i