/*! H5F - v1.0.0 - 2012-07-18 * https://github.com/ryanseddon/H5F/ * Copyright (c) 2012 Ryan Seddon; Licensed MIT */ var H5F = H5F || {}; (function(d){ var 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, usrPatt, curEvt, args, custMsg = "", // Methods setup, validation, validity, checkField, checkValidity, setCustomValidity, support, pattern, placeholder, range, required, valueMissing, listen, unlisten, preventActions, getTarget, addClass, removeClass, isHostMethod; setup = function(form,settings) { var isCollection = !form.nodeType || false; var opts = { validClass : "valid", invalidClass : "error", requiredClass : "required", placeholderClass : "placeholder" }; 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"), isRequired = !!(el.attributes["required"]); return !!(isRequired && (el.value === "" || el.value === placeholder)); }; /* 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'); }; // Since all methods are only used internally no need to expose globally window["H5F"] = { setup: setup }; }(document));