shareyourfingerprint/res/js/lib/jquery.idealforms.js

1366 lines
88 KiB
JavaScript
Raw Permalink Normal View History

2014-10-18 02:55:45 +02:00
;(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
/**
* Errors
*/
module.exports = {
required: 'This field is required',
digits: 'Must be only digits',
name: 'Must be at least 3 characters long and must only contain letters',
email: 'Must be a valid email',
username: 'Must be at between 4 and 32 characters long and start with a letter. You may use letters, numbers, underscores, and one dot',
pass: 'Must be at least 6 characters long, and contain at least one number, one uppercase and one lowercase letter',
strongpass: 'Must be at least 8 characters long and contain at least one uppercase and one lowercase letter and one number or special character',
phone: 'Must be a valid phone number',
zip: 'Must be a valid zip code',
url: 'Must be a valid URL',
number: 'Must be a number',
range: 'Must be a number between {0} and {1}',
min: 'Must be at least {0} characters long',
max: 'Must be under {0} characters',
minoption: 'Select at least {0} options',
maxoption: 'Select no more than {0} options',
minmax: 'Must be between {0} and {1} characters long',
select: 'Select an option',
extension: 'File(s) must have a valid extension ({*})',
equalto: 'Must have the same value as the "{0}" field',
date: 'Must be a valid date {0}'
};
},{}],2:[function(require,module,exports){
/**
* Adaptive
*/
module.exports = {
name: 'adaptive',
options: {
adaptiveWidth: $('<p class="idealforms-field-width"/>').appendTo('body').css('width').replace('px','')
},
methods: {
// @extend
_init: function () {
var self = this;
function adapt() {
var formWidth = self.$form.outerWidth()
, isAdaptive = self.opts.adaptiveWidth > formWidth;
self.$form.toggleClass('adaptive', isAdaptive);
if (self._hasExtension('steps')) {
self.$stepsContainer.toggleClass('adaptive', isAdaptive);
}
$('#ui-datepicker-div').hide();
}
$(window).resize(adapt);
adapt();
this.$form.find('select, .datepicker').each(function() {
self._getField(this).find(self.opts.error).addClass('hidden');
});
$('p.idealforms-field-width').remove();
}
}
};
},{}],3:[function(require,module,exports){
module.exports = {
name: 'ajax',
methods: {
// @extend
_init: function() {
$.extend($.idealforms, { _requests: {} });
$.idealforms.errors.ajax = $.idealforms.errors.ajax || 'Loading...';
$.extend($.idealforms.rules, {
ajax: function(input) {
var self = this
, $field = this._getField(input)
, url = $(input).data('idealforms-ajax')
, userError = $.idealforms._getKey('errors.'+ input.name +'.ajaxError', self.opts)
, requests = $.idealforms._requests
, data = {};
data[input.name] = input.value;
$field.addClass('ajax');
if (requests[input.name]) requests[input.name].abort();
requests[input.name] = $.post(url, data, function(resp) {
if (resp === true) {
$field.data('idealforms-valid', true);
self._handleError(input);
self._handleStyle(input);
} else {
self._handleError(input, userError);
}
self.opts.onValidate.call(self, input, 'ajax', resp);
$field.removeClass('ajax');
}, 'json');
return false;
}
});
},
// @extend
_validate: function(input, rule) {
if (rule != 'ajax' && $.idealforms._requests[input.name]) {
$.idealforms._requests[input.name].abort();
this._getField(input).removeClass('ajax');
}
}
}
};
},{}],4:[function(require,module,exports){
require('./idealfile');
require('./idealradiocheck');
module.exports = {
name: 'customInputs',
options: {
customInputs: {
i18n: {
open: 'Open'
}
}
},
methods: {
// @extend
_init: function() {
this._buildCustomInputs();
},
addFields: function() {
this._buildCustomInputs();
},
_buildCustomInputs: function() {
this.$form.find(':file').idealfile(this.opts.customInputs.i18n);
this.$form.find(':checkbox, :radio').idealradiocheck();
}
}
};
},{"./idealfile":5,"./idealradiocheck":6}],5:[function(require,module,exports){
/**
* Ideal File
*/
(function($, win, doc, undefined) {
// Browser supports HTML5 multiple file?
var multipleSupport = typeof $('<input/>')[0].multiple !== 'undefined'
, isIE = /msie/i.test(navigator.userAgent)
, plugin = {};
plugin.name = 'idealfile';
plugin.defaults = {
open: 'Open'
};
plugin.methods = {
_init: function() {
var $file = $(this.el).addClass('ideal-file') // the original file input
, $wrap = $('<div class="ideal-file-wrap">')
, $input = $('<input type="text" class="ideal-file-filename" />')
// Button that will be used in non-IE browsers
, $button = $('<button type="button" class="ideal-file-upload">'+ this.opts.open +'</button>')
// Hack for IE
, $label = $('<label class="ideal-file-upload" for="' + $file[0].id + '">'+ this.opts.open +'</label>');
if (isIE) $label.add($button).addClass('ie');
// Hide by shifting to the left so we
// can still trigger events
$file.css({
position: 'absolute',
left: '-9999px'
});
$wrap.append($input, (isIE ? $label : $button)).insertAfter($file);
// Prevent focus
$file.attr('tabIndex', -1);
$button.attr('tabIndex', -1);
$button.click(function () {
$file.focus().click(); // Open dialog
});
$file.change(function () {
var files = []
, fileArr, filename;
// If multiple is supported then extract
// all filenames from the file array
if (multipleSupport) {
fileArr = $file[0].files;
for (var i = 0, len = fileArr.length; i < len; i++) {
files.push(fileArr[i].name);
}
filename = files.join(', ');
// If not supported then just take the value
// and remove the path to just show the filename
} else {
filename = $file.val().split('\\').pop();
}
$input .val(filename).attr('title', filename);
});
$input.on({
blur: function () {
$file.trigger('blur');
},
keydown: function (e) {
if (e.which === 13) { // Enter
if (!isIE) $file.trigger('click');
$(this).closest('form').one('keydown', function(e) {
if (e.which === 13) e.preventDefault();
});
} else if (e.which === 8 || e.which === 46) { // Backspace & Del
// In IE the value is read-only
// with this trick we remove the old input and add
// a clean clone with all the original events attached
if (isIE) $file.replaceWith($file = $file.clone(true));
$file.val('').trigger('change');
$input.val('');
} else if (e.which === 9) { // TAB
return;
} else { // All other keys
return false;
}
}
});
}
};
require('../../plugin')(plugin);
}(jQuery, window, document));
},{"../../plugin":12}],6:[function(require,module,exports){
/*
* idealRadioCheck: jQuery plguin for checkbox and radio replacement
* Usage: $('input[type=checkbox], input[type=radio]').idealRadioCheck()
*/
(function($, win, doc, undefined) {
var plugin = {};
plugin.name = 'idealradiocheck';
plugin.methods = {
_init: function() {
var $input = $(this.el);
var $span = $('<span/>');
$span.addClass('ideal-'+ ($input.is(':checkbox') ? 'check' : 'radio'));
$input.is(':checked') && $span.addClass('checked'); // init
$span.insertAfter($input);
$input.parent('label')
.addClass('ideal-radiocheck-label')
.attr('onclick', ''); // Fix clicking label in iOS
$input.css({ position: 'absolute', left: '-9999px' }); // hide by shifting left
// Events
$input.on({
change: function() {
var $input = $(this);
if ( $input.is('input[type="radio"]') ) {
$input.parent().siblings('label').find('.ideal-radio').removeClass('checked');
}
$span.toggleClass('checked', $input.is(':checked'));
},
focus: function() { $span.addClass('focus') },
blur: function() { $span.removeClass('focus') },
click: function() { $(this).trigger('focus') }
});
}
};
require('../../plugin')(plugin);
}(jQuery, window, document));
},{"../../plugin":12}],7:[function(require,module,exports){
module.exports = {
name: 'datepicker',
methods: {
// @extend
_init: function() {
this._buildDatepicker();
},
_buildDatepicker: function() {
var $datepicker = this.$form.find('input.datepicker');
// Always show datepicker below the input
if (jQuery.ui) {
$.datepicker._checkOffset = function(a,b,c){ return b };
}
if (jQuery.ui && $datepicker.length) {
$datepicker.each(function() {
$(this).datepicker({
beforeShow: function(input) {
$(input).addClass('open');
},
onChangeMonthYear: function() {
// Hack to fix IE9 not resizing
var $this = $(this)
, width = $this.outerWidth(); // cache first!
setTimeout(function() {
$this.datepicker('widget').css('width', width);
}, 1);
},
onClose: function() {
$(this).removeClass('open');
}
});
});
// Adjust width
$datepicker.on('focus keyup', function() {
var t = $(this), w = t.outerWidth();
t.datepicker('widget').css('width', w);
});
}
}
}
};
},{}],8:[function(require,module,exports){
function template(html, data) {
var loop = /\{@([^}]+)\}(.+?)\{\/\1\}/g
, loopVariable = /\{#([^}]+)\}/g
, variable = /\{([^}]+)\}/g;
return html
.replace(loop, function(_, key, list) {
return $.map(data[key], function(item) {
return list.replace(loopVariable, function(_, k) {
return item[k];
});
}).join('');
})
.replace(variable, function(_, key) {
return data[key] || '';
});
}
module.exports = {
name: 'dynamicFields',
options: {
templates: {
base:'\
<div class="field">\
<label class="main">{label}</label>\
{field}\
<span class="error"></span>\
</div>\
',
text: '<input name="{name}" type="{subtype}" value="{value}" {attrs}>',
file: '<input id="{name} "name="{name}" type="file" {attrs}>',
textarea: '<textarea name="{name}" {attrs}>{text}</textarea>',
group: '\
<p class="group">\
{@list}\
<label><input name="{name}" type="{subtype}" value="{#value}" {#attrs}>{#text}</label>\
{/list}\
</p>\
',
select: '\
<select name={name}>\
{@list}\
<option value="{#value}">{#text}</option>\
{/list}\
</select>\
'
}
},
methods: {
addFields: function(fields) {
var self = this;
$.each(fields, function(name, field) {
var typeArray = field.type.split(':')
, rules = {}
, $last = self.$form.find(self.opts.field).last();
field.name = name;
field.type = typeArray[0];
if (typeArray[1]) field.subtype = typeArray[1];
field.html = template(self.opts.templates.base, {
label: field.label,
field: template(self.opts.templates[field.type], field)
});
self._inject('addFields', field);
if (field.after || field.before) {
self.$form.find('[name="'+ (field.after || field.before) +'"]').first().each(function() {
self._getField(this)[field.after ? 'after' : 'before'](field.html);
});
} else {
// Form has at least one field
if ($last.length) $last.after(field.html);
// Form has no fields
else self.$form.append(field.html);
}
if (field.rules) {
rules[name] = field.rules;
self.addRules(rules);
}
});
},
removeFields: function(names) {
var self = this;
$.each(names.split(' '), function(i, name) {
var $field = self._getField($('[name="'+ name +'"]'));
self.$fields = self.$fields.filter(function() {
return ! $(this).is($field);
});
$field.remove();
});
this._inject('removeFields');
},
toggleFields: function(names) {
var self = this;
$.each(names.split(' '), function(i, name) {
var $field = self._getField($('[name="'+ name +'"]'));
$field.data('idealforms-valid', $field.is(':visible')).toggle();
});
this._inject('toggleFields');
}
}
};
},{}],9:[function(require,module,exports){
/*!
* Ideal Steps
*/
(function($, win, doc, undefined) {
var plugin = {};
plugin.name = 'idealsteps';
plugin.defaults = {
nav: '.idealsteps-nav',
navItems: 'li',
buildNavItems: true,
wrap: '.idealsteps-wrap',
step: '.idealsteps-step',
activeClass: 'idealsteps-step-active',
before: $.noop,
after: $.noop,
fadeSpeed: 0
};
plugin.methods = {
_init: function() {
var self = this,
active = this.opts.activeClass;
this.$el = $(this.el);
this.$nav = this.$el.find(this.opts.nav);
this.$navItems = this.$nav.find(this.opts.navItems);
this.$wrap = this.$el.find(this.opts.wrap);
this.$steps = this.$wrap.find(this.opts.step);
if (this.opts.buildNavItems) this._buildNavItems();
this.$steps.hide().first().show();
this.$navItems.removeClass(active).first().addClass(active);
this.$navItems.click(function(e) {
e.preventDefault();
if (! $(this).is('.'+ self.opts.activeClass)) {
self.go(self.$navItems.index(this));
}
});
},
_buildNavItems: function() {
var self = this,
isCustom = typeof this.opts.buildNavItems == 'function',
item = function(val){ return '<li><a href="#" tabindex="-1">'+ val +'</a></li>'; },
items;
items = isCustom ?
this.$steps.map(function(i){ return item(self.opts.buildNavItems.call(self, i)) }).get() :
this.$steps.map(function(i){ return item(++i); }).get();
this.$navItems = $(items.join(''));
this.$nav.append($('<ul/>').append(this.$navItems));
},
_getCurIdx: function() {
return this.$steps.index(this.$steps.filter(':visible'));
},
go: function(idx) {
var active = this.opts.activeClass,
fadeSpeed = this.opts.fadeSpeed;
if (typeof idx == 'function') idx = idx.call(this, this._getCurIdx());
if (idx >= this.$steps.length) idx = 0;
if (idx < 0) idx = this.$steps.length-1;
this.opts.before.call(this, idx);
this.$navItems.removeClass(active).eq(idx).addClass(active);
this.$steps.hide().eq(idx).fadeIn(fadeSpeed);
this.opts.after.call(this, idx);
},
prev: function() {
this.go(this._getCurIdx() - 1);
},
next: function() {
this.go(this._getCurIdx() + 1);
},
first: function() {
this.go(0);
},
last: function() {
this.go(this.$steps.length-1);
}
};
require('../../plugin')(plugin);
}(jQuery, window, document));
},{"../../plugin":12}],10:[function(require,module,exports){
require('./idealsteps');
module.exports = {
name: 'steps',
options: {
steps: {
container: '.idealsteps-container',
nav: '.idealsteps-nav',
navItems: 'li',
buildNavItems: function(i) {
return this.opts.steps.i18n.step +' '+ (i+1);
},
wrap: '.idealsteps-wrap',
step: '.idealsteps-step',
activeClass: 'idealsteps-step-active',
before: $.noop,
after: $.noop,
fadeSpeed: 0,
i18n: {
step: 'Step'
}
}
},
methods: {
// @extend
_init: function() {
this._buildSteps();
},
// @extend
_validate: function() {
var self = this;
this._updateSteps();
if (this._hasExtension('ajax')) {
$.each($.idealforms._requests, function(key, request) {
request.done(function(){ self._updateSteps() });
});
}
},
// @extend
focusFirstInvalid: function(firstInvalid) {
var self = this;
this.$stepsContainer.idealsteps('go', function() {
return this.$steps.filter(function() {
return $(this).find(firstInvalid).length;
}).index();
});
setTimeout(function(){ $(firstInvalid).focus() }, this.opts.steps.fadeSpeed);
},
_buildSteps: function() {
var self = this, options
, hasRules = ! $.isEmptyObject(this.opts.rules)
, buildNavItems = this.opts.steps.buildNavItems
, counter = hasRules
? '<span class="counter"/>'
: '<span class="counter zero">0</span>';
if (this.opts.steps.buildNavItems) {
this.opts.steps.buildNavItems = function(i) {
return buildNavItems.call(self, i) + counter;
};
}
this.$stepsContainer = this.$form
.closest(this.opts.steps.container)
.idealsteps(this.opts.steps);
},
_updateSteps: function() {
var self = this;
this.$stepsContainer.idealsteps('_inject', function() {
var idealsteps = this;
this.$navItems.each(function(i) {
var invalid = idealsteps.$steps.eq(i).find(self.getInvalid()).length;
$(this).find('span').text(invalid).toggleClass('zero', ! invalid);
});
});
},
// @extend
addRules: function() {
this.firstStep();
},
// @extend
addFields: function(field) {
if (field.after || field.before) return;
var $steps = this.$stepsContainer.find(this.opts.steps.step);
if (! ('appendToStep' in field)) {
field.appendToStep = $steps.length-1;
}
field.after = $steps
.eq(field.appendToStep)
.find('input, select, textarea')
.last()[0].name;
},
// @extend
toggleFields: function() {
this._updateSteps();
},
// @extend
removeFields: function() {
this._updateSteps();
},
goToStep: function(idx) {
this.$stepsContainer.idealsteps('go', idx);
},
prevStep: function() {
this.$stepsContainer.idealsteps('prev');
},
nextStep: function() {
this.$stepsContainer.idealsteps('next');
},
firstStep: function() {
this.$stepsContainer.idealsteps('first');
},
lastStep: function() {
this.$stepsContainer.idealsteps('last');
}
}
};
},{"./idealsteps":9}],11:[function(require,module,exports){
/*!
* jQuery Ideal Forms
* @author: Cedric Ruiz
* @version: 3.0
* @license GPL or MIT
*/
(function($, win, doc, undefined) {
var plugin = {};
plugin.name = 'idealforms';
plugin.defaults = {
field: '.field',
error: '.error',
iconHtml: '<i/>',
iconClass: 'icon',
invalidClass: 'invalid',
validClass: 'valid',
silentLoad: true,
onValidate: $.noop,
onSubmit: $.noop,
rules: {},
errors: {}
};
plugin.global = {
_format: function(str) {
var args = [].slice.call(arguments, 1);
return str.replace(/\{(\d)\}/g, function(_, match) {
return args[+match] || '';
}).replace(/\{\*([^*}]*)\}/g, function(_, sep) {
return args.join(sep || ', ');
});
},
_getKey: function(key, obj) {
return key.split('.').reduce(function(a,b) {
return a && a[b];
}, obj);
},
i18n: {},
ruleSeparator: ' ',
argSeparator: ':',
rules: require('./rules'),
errors: require('./errors'),
extensions: [
require('./extensions/dynamic-fields/dynamic-fields.ext'),
require('./extensions/ajax/ajax.ext'),
require('./extensions/steps/steps.ext'),
require('./extensions/custom-inputs/custom-inputs.ext'),
require('./extensions/datepicker/datepicker.ext'),
require('./extensions/adaptive/adaptive.ext')
]
};
plugin.methods = $.extend({}, require('./private'), require('./public'));
require('./plugin')(plugin);
}(jQuery, window, document));
},{"./errors":1,"./extensions/adaptive/adaptive.ext":2,"./extensions/ajax/ajax.ext":3,"./extensions/custom-inputs/custom-inputs.ext":4,"./extensions/datepicker/datepicker.ext":7,"./extensions/dynamic-fields/dynamic-fields.ext":8,"./extensions/steps/steps.ext":10,"./plugin":12,"./private":13,"./public":14,"./rules":15}],12:[function(require,module,exports){
/**
* Plugin boilerplate
*/
module.exports = (function() {
var AP = Array.prototype;
return function(plugin) {
plugin = $.extend(true, {
name: 'plugin',
defaults: {
disabledExtensions: 'none'
},
methods: {},
global: {},
}, plugin);
$[plugin.name] = $.extend({
addExtension: function(extension) {
plugin.global.extensions.push(extension);
}
}, plugin.global);
function Plugin(element, options) {
this.opts = $.extend({}, plugin.defaults, options);
this.el = element;
this._name = plugin.name;
this._init();
}
Plugin._extended = {};
Plugin.prototype._hasExtension = function(extension) {
var self = this;
return plugin.global.extensions.filter(function(ext) {
return ext.name == extension && self.opts.disabledExtensions.indexOf(ext.name) < 0;
}).length;
};
Plugin.prototype._extend = function(extensions) {
var self = this;
$.each(extensions, function(i, extension) {
$.extend(self.opts, $.extend(true, extension.options, self.opts));
$.each(extension.methods, function(method, fn) {
if (self.opts.disabledExtensions.indexOf(extension.name) > -1) {
return;
}
if (Plugin.prototype[method]) {
Plugin._extended[method] = Plugin._extended[method] || [];
Plugin._extended[method].push({ name: extension.name, fn: fn });
} else {
Plugin.prototype[method] = fn;
}
});
});
};
Plugin.prototype._inject = function(method) {
var args = [].slice.call(arguments, 1);
if (typeof method == 'function') return method.call(this);
var self = this;
if (Plugin._extended[method]) {
$.each(Plugin._extended[method], function(i, plugin) {
plugin.fn.apply(self, args);
});
}
};
Plugin.prototype._init = $.noop;
Plugin.prototype[plugin.name] = function(method) {
if (!method) return this;
try { return this[method].apply(this, AP.slice.call(arguments, 1)); }
catch(e) {}
};
$.extend(Plugin.prototype, plugin.methods);
$.fn[plugin.name] = function() {
var args = AP.slice.call(arguments)
, methodArray = typeof args[0] == 'string' && args[0].split(':')
, method = methodArray[methodArray.length > 1 ? 1 : 0]
, prefix = methodArray.length > 1 && methodArray[0]
, opts = typeof args[0] == 'object' && args[0]
, params = args.slice(1)
, ret;
if (prefix) {
method = prefix + method.substr(0,1).toUpperCase() + method.substr(1,method.length-1);
}
this.each(function() {
var instance = $.data(this, plugin.name);
// Method
if (instance) {
return ret = instance[plugin.name].apply(instance, [method].concat(params));
}
// Init
return $.data(this, plugin.name, new Plugin(this, opts));
});
return prefix ? ret : this;
};
};
}());
},{}],13:[function(require,module,exports){
/**
* Private methods
*/
module.exports = {
_init: function() {
var self = this;
this.$form = $(this.el);
this.$fields = $();
this.$inputs = $();
this._extend($.idealforms.extensions);
this._i18n();
this._inject('_init');
this._addMarkupRules();
this.addRules(this.opts.rules || {});
this.$form.submit(function(e) {
self._validateAll();
self.focusFirstInvalid();
self.opts.onSubmit.call(self, self.getInvalid().length, e);
});
if (! this.opts.silentLoad) {
// 1ms timeout to make sure error shows up
setTimeout($.proxy(this.focusFirstInvalid, this), 1);
}
},
_addMarkupRules: function() {
var rules = {};
this.$form.find('input, select, textarea').each(function() {
var rule = $(this).data('idealforms-rules');
if (rule && ! rules[this.name]) rules[this.name] = rule;
});
this.addRules(rules);
},
_i18n: function() {
var self = this;
$.each($.idealforms.i18n, function(locale, lang) {
var errors = lang.errors
, options = {};
delete lang.errors;
for (var ext in lang) options[ext] = { i18n: lang[ext] };
$.extend($.idealforms.errors, errors);
$.extend(true, self.opts, options);
});
},
_buildField: function(input) {
var self = this
, $field = this._getField(input)
, $icon;
$icon = $(this.opts.iconHtml, {
class: this.opts.iconClass,
click: function(){ $(input).focus() }
});
if (! this.$fields.filter($field).length) {
this.$fields = this.$fields.add($field);
if (this.opts.iconHtml) $field.append($icon);
$field.addClass('idealforms-field idealforms-field-'+ input.type);
}
this._addEvents(input);
this._inject('_buildField', input);
},
_addEvents: function(input) {
var self = this
, $field = this._getField(input);
$(input)
.on('change keyup', function(e) {
if (e.which == 9 || e.which == 16) return;
self._validate(this, true, true);
})
.focus(function() {
if (! self.isValid(this.name)) {
$field.find(self.opts.error).show();
}
})
.blur(function() {
$field.find(self.opts.error).hide();
});
},
_isRequired: function(input) {
// We assume non-text inputs with rules are required
if ($(input).is(':checkbox, :radio, select')) return true;
return this.opts.rules[input.name].indexOf('required') > -1;
},
_getRelated: function(input) {
return this._getField(input).find('[name="'+ input.name +'"]');
},
_getField: function(input) {
return $(input).closest(this.opts.field);
},
_getFirstInvalid: function() {
return this.getInvalid().first().find('input:first, textarea, select');
},
_handleError: function(input, error, valid) {
valid = valid || this.isValid(input.name);
var $error = this._getField(input).find(this.opts.error);
this.$form.find(this.opts.error).hide();
if (error) $error.text(error);
$error.toggle(!valid);
},
_handleStyle: function(input, valid) {
valid = valid || this.isValid(input.name);
this._getField(input)
.removeClass(this.opts.validClass +' '+ this.opts.invalidClass)
.addClass(valid ? this.opts.validClass : this.opts.invalidClass)
.find('.'+ this.opts.iconClass).show();
},
_fresh: function(input) {
this._getField(input)
.removeClass(this.opts.validClass +' '+ this.opts.invalidClass)
.find(this.opts.error).hide()
.end()
.find('.'+ this.opts.iconClass).toggle(this._isRequired(input));
},
_validate: function(input, handleError, handleStyle) {
var self = this
, $field = this._getField(input)
, userRules = this.opts.rules[input.name].split($.idealforms.ruleSeparator)
, oldValue = $field.data('idealforms-value')
, valid = true
, rule;
// Don't validate input if value hasn't changed
if (! $(input).is(':checkbox, :radio') && oldValue == input.value) {
return $field.data('idealforms-valid');
}
$field.data('idealforms-value', input.value);
// Non-required input with empty value must pass validation
if (! input.value && ! this._isRequired(input)) {
$field.removeData('idealforms-valid');
this._fresh(input);
// Inputs with value or required
} else {
$.each(userRules, function(i, userRule) {
userRule = userRule.split($.idealforms.argSeparator);
rule = userRule[0];
var theRule = $.idealforms.rules[rule]
, args = userRule.slice(1)
, error;
error = $.idealforms._format.apply(null, [
$.idealforms._getKey('errors.'+ input.name +'.'+ rule, self.opts) ||
$.idealforms.errors[rule]
].concat(args));
valid = typeof theRule == 'function'
? theRule.apply(self, [input, input.value].concat(args))
: theRule.test(input.value);
$field.data('idealforms-valid', valid);
if (handleError) self._handleError(input, error, valid);
if (handleStyle) self._handleStyle(input, valid);
self.opts.onValidate.call(self, input, rule, valid);
return valid;
});
}
this._inject('_validate', input, rule, valid);
return valid;
},
_validateAll: function() {
var self = this;
this.$inputs.each(function(){ self._validate(this, true); });
}
};
},{}],14:[function(require,module,exports){
/**
* Public methods
*/
module.exports = {
addRules: function(rules) {
var self = this;
var $inputs = this.$form.find($.map(rules, function(_, name) {
return '[name="'+ name +'"]';
}).join(','));
$.extend(this.opts.rules, rules);
$inputs.each(function(){ self._buildField(this) });
this.$inputs = this.$inputs.add($inputs);
this._validateAll();
this.$fields.find(this.opts.error).hide();
this._inject('addRules');
},
getInvalid: function() {
return this.$fields.filter(function() {
return $(this).data('idealforms-valid') === false;
});
},
focusFirstInvalid: function() {
var firstInvalid = this._getFirstInvalid()[0];
if (firstInvalid) {
this._handleError(firstInvalid);
this._handleStyle(firstInvalid);
this._inject('focusFirstInvalid', firstInvalid);
$(firstInvalid).focus();
}
},
isValid: function(name) {
if (name) return ! this.getInvalid().find('[name="'+ name +'"]').length;
return ! this.getInvalid().length;
},
reset: function(name) {
var self = this
, $inputs = this.$inputs;
if (name) $inputs = $inputs.filter('[name="'+ name +'"]');
$inputs.filter('input:not(:checkbox, :radio)').val('');
$inputs.filter(':checkbox, :radio').prop('checked', false);
$inputs.filter('select').find('option').prop('selected', function() {
return this.defaultSelected;
});
$inputs.change().each(function(){ self._fresh(this) });
this._inject('reset', name);
}
};
},{}],15:[function(require,module,exports){
/**
* Rules
*/
module.exports = {
required: /.+/,
digits: /^\d+$/,
email: /^[^@]+@[^@]+\..{2,6}$/,
username: /^[a-z](?=[\w.]{3,31}$)\w*\.?\w*$/i,
pass: /(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}/,
strongpass: /(?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/,
phone: /^[2-9]\d{2}-\d{3}-\d{4}$/,
zip: /^\d{5}$|^\d{5}-\d{4}$/,
url: /^(?:(ftp|http|https):\/\/)?(?:[\w\-]+\.)+[a-z]{2,6}([\:\/?#].*)?$/i,
number: function(input, value) {
return !isNaN(value);
},
range: function(input, value, min, max) {
return Number(value) >= min && Number(value) <= max;
},
min: function(input, value, min) {
return value.length >= min;
},
max: function(input, value, max) {
return value.length <= max;
},
minoption: function(input, value, min) {
return this._getRelated(input).filter(':checked').length >= min;
},
maxoption: function(input, value, max) {
return this._getRelated(input).filter(':checked').length <= max;
},
minmax: function(input, value, min, max) {
return value.length >= min && value.length <= max;
},
select: function(input, value, def) {
return value != def;
},
extension: function(input) {
var extensions = [].slice.call(arguments, 1)
, valid = false;
$.each(input.files || [{name: input.value}], function(i, file) {
valid = $.inArray(file.name.split('.').pop().toLowerCase(), extensions) > -1;
});
return valid;
},
equalto: function(input, value, target) {
var self = this
, $target = $('[name="'+ target +'"]');
if (this.getInvalid().find($target).length) return false;
$target.off('keyup.equalto').on('keyup.equalto', function() {
self._getField(input).removeData('idealforms-value');
self._validate(input, false, true);
});
return input.value == $target.val();
},
date: function(input, value, format) {
format = format || 'mm/dd/yyyy';
var delimiter = /[^mdy]/.exec(format)[0]
, theFormat = format.split(delimiter)
, theDate = value.split(delimiter);
function isDate(date, format) {
var m, d, y;
for (var i = 0, len = format.length; i < len; i++) {
if (/m/.test(format[i])) m = date[i];
if (/d/.test(format[i])) d = date[i];
if (/y/.test(format[i])) y = date[i];
}
if (!m || !d || !y) return false;
return m > 0 && m < 13 &&
y && y.length == 4 &&
d > 0 && d <= (new Date(y, m, 0)).getDate();
}
return isDate(theDate, theFormat);
}
};
},{}]},{},[11])
//@ sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2VuZXJhdGVkLmpzIiwic291cmNlcyI6WyIvdmFyL3d3dy9qcS1pZGVhbGZvcm1zL2pzL2Vycm9ycy5qcyIsIi92YXIvd3d3L2pxLWlkZWFsZm9ybXMvanMvZXh0ZW5zaW9ucy9hZGFwdGl2ZS9hZGFwdGl2ZS5leHQuanMiLCIvdmFyL3d3dy9qcS1pZGVhbGZvcm1zL2pzL2V4dGVuc2lvbnMvYWpheC9hamF4LmV4dC5qcyIsIi92YXIvd3d3L2pxLWlkZWFsZm9ybXMvanMvZXh0ZW5zaW9ucy9jdXN0b20taW5wdXRzL2N1c3RvbS1pbnB1dHMuZXh0LmpzIiwiL3Zhci93d3cvanEtaWRlYWxmb3Jtcy9qcy9leHRlbnNpb25zL2N1c3RvbS1pbnB1dHMvaWRlYWxmaWxlLmpzIiwiL3Zhci93d3cvanEtaWRlYWxmb3Jtcy9qcy9leHRlbnNpb25zL2N1c3RvbS1pbnB1dHMvaWRlYWxyYWRpb2NoZWNrLmpzIiwiL3Z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