http://2014hs.igem.org/wiki/index.php?title=Team:StuyGem_NYC/foundation.abide.js&feed=atom&action=history
Team:StuyGem NYC/foundation.abide.js - Revision history
2024-03-29T06:56:17Z
Revision history for this page on the wiki
MediaWiki 1.16.5
http://2014hs.igem.org/wiki/index.php?title=Team:StuyGem_NYC/foundation.abide.js&diff=2767&oldid=prev
Kelvinn1996: Created page with ";(function ($, window, document, undefined) { 'use strict'; Foundation.libs.abide = { name : 'abide', version : '5.2.2', settings : { live_validate : tru..."
2014-04-06T03:26:05Z
<p>Created page with ";(function ($, window, document, undefined) { 'use strict'; Foundation.libs.abide = { name : 'abide', version : '5.2.2', settings : { live_validate : tru..."</p>
<p><b>New page</b></p><div>;(function ($, window, document, undefined) {<br />
'use strict';<br />
<br />
Foundation.libs.abide = {<br />
name : 'abide',<br />
<br />
version : '5.2.2',<br />
<br />
settings : {<br />
live_validate : true,<br />
focus_on_invalid : true,<br />
error_labels: true, // labels with a for="inputId" will recieve an `error` class<br />
timeout : 1000,<br />
patterns : {<br />
alpha: /^[a-zA-Z]+$/,<br />
alpha_numeric : /^[a-zA-Z0-9]+$/,<br />
integer: /^[-+]?\d+$/,<br />
number: /^[-+]?\d*(?:\.\d+)?$/,<br />
<br />
// amex, visa, diners<br />
card : /^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$/,<br />
cvv : /^([0-9]){3,4}$/,<br />
<br />
// http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#valid-e-mail-address<br />
email : /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/,<br />
<br />
url: /^(https?|ftp|file|ss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#((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/,<br />
// abc.de<br />
domain: /^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$/,<br />
<br />
datetime: /^([0-2][0-9]{3})\-([0-1][0-9])\-([0-3][0-9])T([0-5][0-9])\:([0-5][0-9])\:([0-5][0-9])(Z|([\-\+]([0-1][0-9])\:00))$/,<br />
// YYYY-MM-DD<br />
date: /(?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31))$/,<br />
// HH:MM:SS<br />
time : /^(0[0-9]|1[0-9]|2[0-3])(:[0-5][0-9]){2}$/,<br />
dateISO: /^\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}$/,<br />
// MM/DD/YYYY<br />
month_day_year : /^(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.](19|20)\d\d$/,<br />
<br />
// #FFF or #FFFFFF<br />
color: /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/<br />
},<br />
validators : {<br />
equalTo: function(el, required, parent) {<br />
var from = document.getElementById(el.getAttribute(this.add_namespace('data-equalto'))).value,<br />
to = el.value,<br />
valid = (from === to);<br />
<br />
return valid;<br />
}<br />
}<br />
},<br />
<br />
timer : null,<br />
<br />
init : function (scope, method, options) {<br />
this.bindings(method, options);<br />
},<br />
<br />
events : function (scope) {<br />
var self = this,<br />
form = self.S(scope).attr('novalidate', 'novalidate'),<br />
settings = form.data(this.attr_name(true) + '-init') || {};<br />
<br />
this.invalid_attr = this.add_namespace('data-invalid');<br />
<br />
form<br />
.off('.abide')<br />
.on('submit.fndtn.abide validate.fndtn.abide', function (e) {<br />
var is_ajax = /ajax/i.test(self.S(this).attr(self.attr_name()));<br />
return self.validate(self.S(this).find('input, textarea, select').get(), e, is_ajax);<br />
})<br />
.on('reset', function() {<br />
return self.reset($(this));<br />
})<br />
.find('input, textarea, select')<br />
.off('.abide')<br />
.on('blur.fndtn.abide change.fndtn.abide', function (e) {<br />
self.validate([this], e);<br />
})<br />
.on('keydown.fndtn.abide', function (e) {<br />
if (settings.live_validate === true) {<br />
clearTimeout(self.timer);<br />
self.timer = setTimeout(function () {<br />
self.validate([this], e);<br />
}.bind(this), settings.timeout);<br />
}<br />
});<br />
},<br />
<br />
reset : function (form) {<br />
form.removeAttr(this.invalid_attr);<br />
$(this.invalid_attr, form).removeAttr(this.invalid_attr);<br />
$('.error', form).not('small').removeClass('error');<br />
},<br />
<br />
validate : function (els, e, is_ajax) {<br />
var validations = this.parse_patterns(els),<br />
validation_count = validations.length,<br />
form = this.S(els[0]).closest('[data-' + this.attr_name(true) + ']'),<br />
settings = form.data(this.attr_name(true) + '-init') || {},<br />
submit_event = /submit/.test(e.type);<br />
<br />
form.trigger('validated');<br />
// Has to count up to make sure the focus gets applied to the top error<br />
for (var i=0; i < validation_count; i++) {<br />
if (!validations[i] && (submit_event || is_ajax)) {<br />
if (settings.focus_on_invalid) els[i].focus();<br />
form.trigger('invalid');<br />
this.S(els[i]).closest('[data-' + this.attr_name(true) + ']').attr(this.invalid_attr, '');<br />
return false;<br />
}<br />
}<br />
<br />
if (submit_event || is_ajax) {<br />
form.trigger('valid');<br />
}<br />
<br />
form.removeAttr(this.invalid_attr);<br />
<br />
if (is_ajax) return false;<br />
<br />
return true;<br />
},<br />
<br />
parse_patterns : function (els) {<br />
var i = els.length,<br />
el_patterns = [];<br />
<br />
while (i--) {<br />
el_patterns.push(this.pattern(els[i]));<br />
}<br />
<br />
return this.check_validation_and_apply_styles(el_patterns);<br />
},<br />
<br />
pattern : function (el) {<br />
var type = el.getAttribute('type'),<br />
required = typeof el.getAttribute('required') === 'string';<br />
<br />
var pattern = el.getAttribute('pattern') || '';<br />
<br />
if (this.settings.patterns.hasOwnProperty(pattern) && pattern.length > 0) {<br />
return [el, this.settings.patterns[pattern], required];<br />
} else if (pattern.length > 0) {<br />
return [el, new RegExp('^'+pattern+'$'), required];<br />
}<br />
<br />
if (this.settings.patterns.hasOwnProperty(type)) {<br />
return [el, this.settings.patterns[type], required];<br />
}<br />
<br />
pattern = /.*/;<br />
<br />
return [el, pattern, required];<br />
},<br />
<br />
check_validation_and_apply_styles : function (el_patterns) {<br />
var i = el_patterns.length,<br />
validations = [],<br />
form = this.S(el_patterns[0][0]).closest('[data-' + this.attr_name(true) + ']'),<br />
settings = form.data(this.attr_name(true) + '-init') || {};<br />
<br />
while (i--) {<br />
var el = el_patterns[i][0],<br />
required = el_patterns[i][2],<br />
value = el.value,<br />
direct_parent = this.S(el).parent(),<br />
validator = el.getAttribute(this.add_namespace('data-abide-validator')),<br />
is_radio = el.type === "radio",<br />
is_checkbox = el.type === "checkbox",<br />
label = this.S('label[for="' + el.getAttribute('id') + '"]'),<br />
valid_length = (required) ? (el.value.length > 0) : true;<br />
<br />
var parent, valid;<br />
<br />
// support old way to do equalTo validations<br />
if(el.getAttribute(this.add_namespace('data-equalto'))) { validator = "equalTo" }<br />
<br />
if (!direct_parent.is('label')) {<br />
parent = direct_parent;<br />
} else {<br />
parent = direct_parent.parent();<br />
}<br />
<br />
if (is_radio && required) {<br />
validations.push(this.valid_radio(el, required));<br />
} else if (is_checkbox && required) {<br />
validations.push(this.valid_checkbox(el, required));<br />
} else if (validator) {<br />
valid = this.settings.validators[validator].apply(this, [el, required, parent])<br />
validations.push(valid);<br />
<br />
if (valid) {<br />
this.S(el).removeAttr(this.invalid_attr);<br />
parent.removeClass('error');<br />
} else {<br />
this.S(el).attr(this.invalid_attr, '');<br />
parent.addClass('error');<br />
}<br />
<br />
} else {<br />
<br />
if (el_patterns[i][1].test(value) && valid_length ||<br />
!required && el.value.length < 1 || $(el).attr('disabled')) {<br />
this.S(el).removeAttr(this.invalid_attr);<br />
parent.removeClass('error');<br />
if (label.length > 0 && settings.error_labels) label.removeClass('error');<br />
<br />
validations.push(true);<br />
$(el).triggerHandler('valid');<br />
} else {<br />
this.S(el).attr(this.invalid_attr, '');<br />
parent.addClass('error');<br />
if (label.length > 0 && settings.error_labels) label.addClass('error');<br />
<br />
validations.push(false);<br />
$(el).triggerHandler('invalid');<br />
}<br />
}<br />
}<br />
<br />
return validations;<br />
},<br />
<br />
valid_checkbox : function(el, required) {<br />
var el = this.S(el),<br />
valid = (el.is(':checked') || !required);<br />
<br />
if (valid) {<br />
el.removeAttr(this.invalid_attr).parent().removeClass('error');<br />
} else {<br />
el.attr(this.invalid_attr, '').parent().addClass('error');<br />
}<br />
<br />
return valid;<br />
},<br />
<br />
valid_radio : function (el, required) {<br />
var name = el.getAttribute('name'),<br />
group = this.S(el).closest('[data-' + this.attr_name(true) + ']').find("[name="+name+"]"),<br />
count = group.length,<br />
valid = false;<br />
<br />
// Has to count up to make sure the focus gets applied to the top error<br />
for (var i=0; i < count; i++) {<br />
if (group[i].checked) valid = true;<br />
}<br />
<br />
// Has to count up to make sure the focus gets applied to the top error<br />
for (var i=0; i < count; i++) {<br />
if (valid) {<br />
this.S(group[i]).removeAttr(this.invalid_attr).parent().removeClass('error');<br />
} else {<br />
this.S(group[i]).attr(this.invalid_attr, '').parent().addClass('error');<br />
}<br />
}<br />
<br />
return valid;<br />
},<br />
<br />
valid_equal: function(el, required, parent) {<br />
var from = document.getElementById(el.getAttribute(this.add_namespace('data-equalto'))).value,<br />
to = el.value,<br />
valid = (from === to);<br />
<br />
if (valid) {<br />
this.S(el).removeAttr(this.invalid_attr);<br />
parent.removeClass('error');<br />
} else {<br />
this.S(el).attr(this.invalid_attr, '');<br />
parent.addClass('error');<br />
}<br />
<br />
return valid;<br />
},<br />
<br />
valid_oneof: function(el, required, parent, doNotValidateOthers) {<br />
var el = this.S(el),<br />
others = this.S('[' + this.add_namespace('data-oneof') + ']'),<br />
valid = others.filter(':checked').length > 0;<br />
<br />
if (valid) {<br />
el.removeAttr(this.invalid_attr).parent().removeClass('error');<br />
} else {<br />
el.attr(this.invalid_attr, '').parent().addClass('error');<br />
}<br />
<br />
if (!doNotValidateOthers) {<br />
var _this = this;<br />
others.each(function() {<br />
_this.valid_oneof.call(_this, this, null, null, true);<br />
});<br />
}<br />
<br />
return valid;<br />
}<br />
};<br />
}(jQuery, this, this.document));</div>
Kelvinn1996