diff --git a/bower.json b/bower.json index 928dde9..ae5eaad 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "validetta", "description": "A tiny jquery plugin for validate your forms", - "version": "1.0.0", + "version": "1.0.1", "homepage": "http://lab.hasanaydogdu.com/validetta/", "author": { "name": "Hasan Aydoğdu", diff --git a/dist/validetta.css b/dist/validetta.css index 0c86760..f4352e6 100644 --- a/dist/validetta.css +++ b/dist/validetta.css @@ -1,42 +1,41 @@ -/*! - * Validetta (http://lab.hasanaydogdu.com/validetta/) - * Version 1.0.0 ( 04-02-2015 ) - * Licensed under MIT (https://github.com/hsnayd/validetta/blob/master/LICENCE) - * Copyright 2013-2015 Hasan Aydoğdu - http://www.hasanaydogdu.com - */ - -.validetta-bubble { - position: absolute; - background-color: #cd2e26; - max-width: 325px; - border-radius: 5px; - color: white; - padding: 5px 12px; - z-index: 9; } - .validetta-bubble--right:before { - top: 7px; - left: -10px; - border-color: transparent #cd2e26 transparent transparent; } - .validetta-bubble--bottom:before { - top: -10px; - left: 10px; - border-color: transparent transparent #cd2e26 transparent; } - -.validetta-bubble:before { - content: ''; - position: absolute; - display: block; - height: 0; - width: 0; - border-width: 5px; - border-style: solid; } - -.validetta-inline, -.validetta-bubble { - display: block; - font: 12px/14px Arial, Helvetica, sans-serif; } - -.validetta-inline { - color: #cd2e26; } - -/*# sourceMappingURL=validetta.css.map */ +/*! + * Validetta (http://lab.hasanaydogdu.com/validetta/) + * Version 1.0.1 ( 16-08-2015 ) + * Licensed under MIT (https://github.com/hsnayd/validetta/blob/master/LICENCE) + * Copyright 2013-2015 Hasan Aydoğdu - http://www.hasanaydogdu.com + */ + +.validetta-bubble { + position: absolute; + background-color: #cd2e26; + max-width: 325px; + border-radius: 5px; + color: white; + padding: 5px 12px; + z-index: 9; } + .validetta-bubble:before { + content: ''; + position: absolute; + display: block; + height: 0; + width: 0; + border-width: 5px; + border-style: solid; } + .validetta-bubble--right:before { + top: 7px; + left: -10px; + border-color: transparent #cd2e26 transparent transparent; } + .validetta-bubble--bottom:before { + top: -10px; + left: 10px; + border-color: transparent transparent #cd2e26 transparent; } + +.validetta-inline, +.validetta-bubble { + display: block; + font: 12px/14px Arial, Helvetica, sans-serif; } + +.validetta-inline { + color: #cd2e26; } + +/*# sourceMappingURL=validetta.css.map */ diff --git a/dist/validetta.js b/dist/validetta.js index c0b0df5..50c43a8 100644 --- a/dist/validetta.js +++ b/dist/validetta.js @@ -1,10 +1,10 @@ -/*! - * Validetta (http://lab.hasanaydogdu.com/validetta/) - * Version 1.0.0 ( 04-02-2015 ) - * Licensed under MIT (https://github.com/hsnayd/validetta/blob/master/LICENCE) - * Copyright 2013-2015 Hasan Aydoğdu - http://www.hasanaydogdu.com - */ - +/*! + * Validetta (http://lab.hasanaydogdu.com/validetta/) + * Version 1.0.1 ( 16-08-2015 ) + * Licensed under MIT (https://github.com/hsnayd/validetta/blob/master/LICENCE) + * Copyright 2013-2015 Hasan Aydoğdu - http://www.hasanaydogdu.com + */ + ;(function( $ ) { "use strict"; /** @@ -48,12 +48,13 @@ errorTemplateClass : 'validetta-bubble', // Class of the element that would receive error message errorClass : 'validetta-error', // Class that would be added on every failing validation field validClass : 'validetta-valid', // Same for valid validation - bubblePosition: 'right', + bubblePosition: 'right', // Bubble position // right / bottom + bubbleGapLeft: 15, // Right gap of bubble + bubbleGapTop: 0, // Top gap of bubble realTime : false, // To enable real-time form control, set this option true. onValid : function(){}, // This function to be called when the user submits the form and there is no error. onError : function(){}, // This function to be called when the user submits the form and there are some errors - custom : {}, // Costum reg method variable - remote : {} + validators: {} // Custom validators stored in this variable }, /** @@ -106,10 +107,10 @@ }, // equalTo check equalTo : function( tmp, self ) { - return $( self.form ).find('input[name="'+ tmp.arg +'"]').val() === tmp.val || messages.notEqual; + return self.form.querySelector('input[name="'+ tmp.arg +'"]').value === tmp.val || messages.notEqual; }, different: function( tmp, self ) { - return $( self.form ).find('input[name="'+ tmp.arg +'"]').val() !== tmp.val || messages.different; + return self.form.querySelector('input[name="'+ tmp.arg +'"]').value !== tmp.val || messages.different; }, /** * Credit Card Control @@ -163,7 +164,7 @@ }, // Radio radio : function( el ) { - var count = $( this.form.querySelectorAll('input[type=radio][name="'+ el.name +'"]') ).filter(':checked').length ; + var count = this.form.querySelectorAll('input[type=radio][name="'+ el.name +'"]:checked').length; return count === 1; }, // Custom reg check @@ -349,7 +350,7 @@ checkRemote : function( el, e ) { var ajaxOptions = {}, data = {}, - fieldName = el.name || el.getAttribute('id'); + fieldName = el.name || el.id; if ( typeof this.remoteCache === 'undefined' ) this.remoteCache = {}; @@ -462,34 +463,25 @@ // If the parent element undefined, that means el is an object. So we need to transform to the element if( typeof elParent === 'undefined' ) elParent = el[0].parentNode; // if there is an error window which previously opened for el, return - if( $( elParent ).find( '.'+ this.options.errorTemplateClass ).length ) return; + if ( elParent.querySelectorAll( '.'+ this.options.errorTemplateClass ).length ) return; // Create the error window object which will be appear var errorObject = document.createElement('span'); errorObject.className = this.options.errorTemplateClass + ' '+this.options.errorTemplateClass + '--' + this.options.bubblePosition; // if error display is bubble, calculate to positions if( this.options.display === 'bubble' ) { - var pos, W, H; + var pos, W = 0, H = 0; // !! Here, JQuery functions are using to support the IE8 pos = $( el ).position(); if ( this.options.bubblePosition === 'bottom' ){ - H = el.clientHeight; - if ( H === 0 ) { - pos = $(el.parentNode).position(); - H = el.parentNode.clientHeight; - } - pos.top += H +10; - pos.left -= 5; + H = el.offsetHeight; } else { - W = $( el ).outerWidth(true); - pos.left += W + 15; + W = el.offsetWidth; } - - $( errorObject ).empty().css({ - 'left' : pos.left +'px', - 'top' : pos.top +'px' - }); + errorObject.innerHTML = ''; + errorObject.style.top = pos.top + H + this.options.bubbleGapTop +'px'; + errorObject.style.left = pos.left + W + this.options.bubbleGapLeft +'px' } elParent.appendChild( errorObject ); errorObject.innerHTML = error ; @@ -519,7 +511,7 @@ // if el is undefined ( This is the process of resetting all
) // or el is an object that has element more than one // and these elements are not checkbox - if( typeof el === 'undefined' || ( el.length > 1 && el[0].getAttribute('type') !== 'checkbox' ) ) { + if( typeof el === 'undefined' || ( el.length > 1 && el[0].type !== 'checkbox' ) ) { _errorMessages = this.form.querySelectorAll( '.'+ this.options.errorTemplateClass ); } else { diff --git a/dist/validetta.min.css b/dist/validetta.min.css index f3d9f81..00e3818 100644 --- a/dist/validetta.min.css +++ b/dist/validetta.min.css @@ -1,8 +1,8 @@ -/*! - * Validetta (http://lab.hasanaydogdu.com/validetta/) - * Version 1.0.0 ( 04-02-2015 ) - * Licensed under MIT (https://github.com/hsnayd/validetta/blob/master/LICENCE) - * Copyright 2013-2015 Hasan Aydoğdu - http://www.hasanaydogdu.com - */ - -.validetta-bubble{position:absolute;background-color:#cd2e26;max-width:325px;border-radius:5px;color:#fff;padding:5px 12px;z-index:9}.validetta-bubble--right:before{top:7px;left:-10px;border-color:transparent #cd2e26 transparent transparent}.validetta-bubble--bottom:before{top:-10px;left:10px;border-color:transparent transparent #cd2e26}.validetta-bubble:before{content:'';position:absolute;display:block;height:0;width:0;border-width:5px;border-style:solid}.validetta-bubble,.validetta-inline{display:block;font:12px/14px Arial,Helvetica,sans-serif}.validetta-inline{color:#cd2e26} \ No newline at end of file +/*! + * Validetta (http://lab.hasanaydogdu.com/validetta/) + * Version 1.0.1 ( 16-08-2015 ) + * Licensed under MIT (https://github.com/hsnayd/validetta/blob/master/LICENCE) + * Copyright 2013-2015 Hasan Aydoğdu - http://www.hasanaydogdu.com + */ + +.validetta-bubble{position:absolute;background-color:#cd2e26;max-width:325px;border-radius:5px;color:#fff;padding:5px 12px;z-index:9}.validetta-bubble:before{content:'';position:absolute;display:block;height:0;width:0;border-width:5px;border-style:solid}.validetta-bubble--right:before{top:7px;left:-10px;border-color:transparent #cd2e26 transparent transparent}.validetta-bubble--bottom:before{top:-10px;left:10px;border-color:transparent transparent #cd2e26}.validetta-bubble,.validetta-inline{display:block;font:12px/14px Arial,Helvetica,sans-serif}.validetta-inline{color:#cd2e26} \ No newline at end of file diff --git a/dist/validetta.min.js b/dist/validetta.min.js index 72d05f1..4600c72 100644 --- a/dist/validetta.min.js +++ b/dist/validetta.min.js @@ -1,7 +1,7 @@ /*! * Validetta (http://lab.hasanaydogdu.com/validetta/) - * Version 1.0.0 ( 04-02-2015 ) + * Version 1.0.1 ( 16-08-2015 ) * Licensed under MIT (https://github.com/hsnayd/validetta/blob/master/LICENCE) * Copyright 2013-2015 Hasan Aydoğdu - http://www.hasanaydogdu.com */ -!function(a){"use strict";var b={},c={},d=new RegExp(/^(minChecked|maxChecked|minSelected|maxSelected|minLength|maxLength|equalTo|different|regExp|remote|callback)\[(\w{1,15})\]/i),e=new RegExp(/^[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])?)*$/),f=new RegExp(/^[\-\+]?(\d+|\d+\.?\d+)$/),g={required:"This field is required. Please be sure to check.",email:"Your E-mail address appears to be invalid. Please be sure to check.",number:"You can enter only numbers in this field.",maxLength:"Maximum {count} characters allowed!",minLength:"Minimum {count} characters allowed!",maxChecked:"Maximum {count} options allowed. Please be sure to check.",minChecked:"Please select minimum {count} options.",maxSelected:"Maximum {count} selection allowed. Please be sure to check.",minSelected:"Minimum {count} selection allowed. Please be sure to check.",notEqual:"Fields do not match. Please be sure to check.",different:"Fields cannot be the same as each other",creditCard:"Invalid credit card number. Please be sure to check."},h={showErrorMessages:!0,display:"bubble",errorTemplateClass:"validetta-bubble",errorClass:"validetta-error",validClass:"validetta-valid",bubblePosition:"right",realTime:!1,onValid:function(){},onError:function(){},custom:{},remote:{}},i=function(a){return"string"==typeof a?a.replace(/^\s+|\s+$/g,""):a},j={required:function(a,b){switch(a.el.type){case"checkbox":return a.el.checked||g.required;case"radio":return this.radio.call(b,a.el)||g.required;case"select-multiple":return null!==a.val||g.required;default:return""!==a.val||g.required}},email:function(a){return e.test(a.val)||g.email},number:function(a){return f.test(a.val)||g.number},minLength:function(a){var b=a.val.length;return 0===b||b>=a.arg||g.minLength.replace("{count}",a.arg)},maxLength:function(a){return a.val.length<=a.arg||g.maxLength.replace("{count}",a.arg)},equalTo:function(b,c){return a(c.form).find('input[name="'+b.arg+'"]').val()===b.val||g.notEqual},different:function(b,c){return a(c.form).find('input[name="'+b.arg+'"]').val()!==b.val||g.different},creditCard:function(a){if(""===a.val)return!0;var b,c,d,e,f,h,i,j=0;if(b=new RegExp(/[^0-9]+/g),c=a.val.replace(b,""),i=c.length,16>i)return g.creditCard;for(f=0;i>f;f++)d=i-f,e=parseInt(c.substring(d-1,d),10),f%2===1?(h=2*e,h>9&&(h=1+(h-10))):h=e,j+=h;return j>0&&j%10===0?!0:g.creditCard},maxChecked:function(b,c){var d=a(c.form.querySelectorAll('input[type=checkbox][name="'+b.el.name+'"]'));if(0===d.index(b.el)){var e=d.filter(":checked").length;if(0!==e)return e<=b.arg||g.maxChecked.replace("{count}",b.arg)}},minChecked:function(b,c){var d=a(c.form.querySelectorAll('input[type=checkbox][name="'+b.el.name+'"]'));if(0===d.index(b.el)){var e=d.filter(":checked").length;return e>=b.arg||g.minChecked.replace("{count}",b.arg)}},maxSelected:function(a){return null!==a.val?a.val.length<=a.arg||g.maxSelected.replace("{count}",a.arg):void 0},minSelected:function(a){return null!==a.val&&a.val.length>=a.arg||g.minSelected.replace("{count}",a.arg)},radio:function(b){var c=a(this.form.querySelectorAll('input[type=radio][name="'+b.name+'"]')).filter(":checked").length;return 1===c},regExp:function(a,b){var c=b.options.validators.regExp[a.arg],d=new RegExp(c.pattern);return d.test(a.val)||c.errorMessage},remote:function(a){a.remote=a.arg},callback:function(a,b){var c=b.options.validators.callback[a.arg];return c.callback(a.el,a.val)||c.errorMessage}};b=function(b,c){this.handler=!1,this.options=a.extend(!0,{},h,c),this.form=b,this.xhr={},this.events()},b.prototype={constructor:b,events:function(){var b=this;a(this.form).submit(function(a){return c=this.querySelectorAll("[data-validetta]"),b.init(a)}),this.options.realTime===!0&&(a(this.form).find("[data-validetta]").not("[type=checkbox]").on("change",function(d){return c=a(this),b.init(d)}),a(this.form).find("[data-validetta][type=checkbox]").on("click",function(a){return c=b.form.querySelectorAll('[data-validetta][type=checkbox][name="'+this.name+'"]'),b.init(a)})),a(this.form).on("reset",function(){return a(b.form.querySelectorAll("."+b.options.errorClass+", ."+b.options.validClass)).removeClass(b.options.errorClass+" "+b.options.validClass),b.reset()})},init:function(a){return this.reset(c),this.checkFields(a),"submit"!==a.type?void 0:"pending"===this.handler?!1:this.handler===!0?(this.options.onError.call(this,a),!1):this.options.onValid.call(this,a)},checkFields:function(b){var e=this,f=[];this.getInvalidFields=function(){return f};for(var g=0,h=c.length;h>g;g++)if(!c[g].disabled){var k,l=c[g],m="",n=i(a(l).val()),o=l.getAttribute("data-validetta").split(",");this.tmp={},this.tmp={el:l,val:n,parent:this.parents(l)};for(var p=0,q=o.length;q>p;p++){var r,s=o[p].match(d);if(null!==s?("undefined"!=typeof s[2]&&(this.tmp.arg=s[2]),r=s[1]):r=o[p],(""!==n||"required"===r||"equalTo"===r)&&j.hasOwnProperty(r)&&(k=j[r](e.tmp,e),"undefined"!=typeof k&&k!==!0)){var t=l.getAttribute("data-vd-message-"+r);null!==t&&(k=t),m+=k+"
"}}""!==m?(f.push({field:l,errors:m}),this.addErrorClass(this.tmp.parent),this.window.open.call(this,l,m)):"undefined"!=typeof this.tmp.remote?this.checkRemote(l,b):("undefined"!=typeof k?this.addValidClass(this.tmp.parent):a(this.tmp.parent).removeClass(this.options.errorClass+" "+this.options.validClass),k=void 0)}},checkRemote:function(b,c){var d={},e={},f=b.name||b.getAttribute("id");"undefined"==typeof this.remoteCache&&(this.remoteCache={}),e[f]=this.tmp.val,d=a.extend(!0,{},{data:e},this.options.validators.remote[this.tmp.remote]||{});var g=a.param(d),h=this.remoteCache[g];if("undefined"!=typeof h)switch(h.state){case"pending":this.handler="pending",h.event=c.type;break;case"rejected":throw c.preventDefault(),new Error(h.result.message);case"resolved":h.result.valid===!1?(this.addErrorClass(this.tmp.parent),this.window.open.call(this,b,h.result.message)):this.addValidClass(this.tmp.parent)}else{var i=this.xhr[f];"undefined"!=typeof i&&"pending"===i.state()&&i.abort(),h=this.remoteCache[g]={state:"pending",event:c.type},this.remoteRequest(d,h,b,f)}},remoteRequest:function(b,c,d,e){var f=this;a(this.tmp.parent).addClass("validetta-pending"),this.xhr[e]=a.ajax(b).done(function(b){"object"!=typeof b&&(b=JSON.parse(b)),c.state="resolved",c.result=b,"submit"===c.event?(f.handler=!1,a(f.form).trigger("submit")):b.valid===!1?(f.addErrorClass(f.tmp.parent),f.window.open.call(f,d,b.message)):f.addValidClass(f.tmp.parent)}).fail(function(a,b){if("abort"!==b){var d="Ajax request failed for field ("+e+") : "+a.status+" "+a.statusText;throw c.state="rejected",c.result={valid:!1,message:d},new Error(d)}}).always(function(){a(f.tmp.parent).removeClass("validetta-pending")}),this.handler="pending"},window:{open:function(b,c){if(!this.options.showErrorMessages)return void(this.handler=!0);var d=this.parents(b);if("undefined"==typeof d&&(d=b[0].parentNode),!a(d).find("."+this.options.errorTemplateClass).length){var e=document.createElement("span");if(e.className=this.options.errorTemplateClass+" "+this.options.errorTemplateClass+"--"+this.options.bubblePosition,"bubble"===this.options.display){var f,g,h;f=a(b).position(),"bottom"===this.options.bubblePosition?(h=b.clientHeight,0===h&&(f=a(b.parentNode).position(),h=b.parentNode.clientHeight),f.top+=h+10,f.left-=5):(g=a(b).outerWidth(!0),f.left+=g+15),a(e).empty().css({left:f.left+"px",top:f.top+"px"})}d.appendChild(e),e.innerHTML=c,this.handler=!0}},close:function(a){a.parentNode.removeChild(a)}},reset:function(a){var b={};b="undefined"==typeof a||a.length>1&&"checkbox"!==a[0].getAttribute("type")?this.form.querySelectorAll("."+this.options.errorTemplateClass):this.parents(a[0]).querySelectorAll("."+this.options.errorTemplateClass);for(var c=0,d=b.length;d>c;c++)this.window.close.call(this,b[c]);this.handler=!1},addErrorClass:function(b){a(b).removeClass(this.options.validClass).addClass(this.options.errorClass)},addValidClass:function(b){a(b).removeClass(this.options.errorClass).addClass(this.options.validClass)},parents:function(a){for(var b=parseInt(a.getAttribute("data-vd-parent-up"),10)||0,c=0;b>=c;c++)a=a.parentNode;return a}},a.fn.validetta=function(c,d){return a.validettaLanguage&&(g=a.extend(!0,{},g,a.validettaLanguage.messages)),"undefined"!=typeof d&&(g=a.extend(!0,{},g,d)),this.each(function(){new b(this,c)})}}(jQuery); \ No newline at end of file +!function(a){"use strict";var b={},c={},d=new RegExp(/^(minChecked|maxChecked|minSelected|maxSelected|minLength|maxLength|equalTo|different|regExp|remote|callback)\[(\w{1,15})\]/i),e=new RegExp(/^[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])?)*$/),f=new RegExp(/^[\-\+]?(\d+|\d+\.?\d+)$/),g={required:"This field is required. Please be sure to check.",email:"Your E-mail address appears to be invalid. Please be sure to check.",number:"You can enter only numbers in this field.",maxLength:"Maximum {count} characters allowed!",minLength:"Minimum {count} characters allowed!",maxChecked:"Maximum {count} options allowed. Please be sure to check.",minChecked:"Please select minimum {count} options.",maxSelected:"Maximum {count} selection allowed. Please be sure to check.",minSelected:"Minimum {count} selection allowed. Please be sure to check.",notEqual:"Fields do not match. Please be sure to check.",different:"Fields cannot be the same as each other",creditCard:"Invalid credit card number. Please be sure to check."},h={showErrorMessages:!0,display:"bubble",errorTemplateClass:"validetta-bubble",errorClass:"validetta-error",validClass:"validetta-valid",bubblePosition:"right",bubbleGapLeft:15,bubbleGapTop:0,realTime:!1,onValid:function(){},onError:function(){},validators:{}},i=function(a){return"string"==typeof a?a.replace(/^\s+|\s+$/g,""):a},j={required:function(a,b){switch(a.el.type){case"checkbox":return a.el.checked||g.required;case"radio":return this.radio.call(b,a.el)||g.required;case"select-multiple":return null!==a.val||g.required;default:return""!==a.val||g.required}},email:function(a){return e.test(a.val)||g.email},number:function(a){return f.test(a.val)||g.number},minLength:function(a){var b=a.val.length;return 0===b||b>=a.arg||g.minLength.replace("{count}",a.arg)},maxLength:function(a){return a.val.length<=a.arg||g.maxLength.replace("{count}",a.arg)},equalTo:function(a,b){return b.form.querySelector('input[name="'+a.arg+'"]').value===a.val||g.notEqual},different:function(a,b){return b.form.querySelector('input[name="'+a.arg+'"]').value!==a.val||g.different},creditCard:function(a){if(""===a.val)return!0;var b,c,d,e,f,h,i,j=0;if(b=new RegExp(/[^0-9]+/g),c=a.val.replace(b,""),i=c.length,16>i)return g.creditCard;for(f=0;i>f;f++)d=i-f,e=parseInt(c.substring(d-1,d),10),f%2===1?(h=2*e,h>9&&(h=1+(h-10))):h=e,j+=h;return j>0&&j%10===0?!0:g.creditCard},maxChecked:function(b,c){var d=a(c.form.querySelectorAll('input[type=checkbox][name="'+b.el.name+'"]'));if(0===d.index(b.el)){var e=d.filter(":checked").length;if(0!==e)return e<=b.arg||g.maxChecked.replace("{count}",b.arg)}},minChecked:function(b,c){var d=a(c.form.querySelectorAll('input[type=checkbox][name="'+b.el.name+'"]'));if(0===d.index(b.el)){var e=d.filter(":checked").length;return e>=b.arg||g.minChecked.replace("{count}",b.arg)}},maxSelected:function(a){return null!==a.val?a.val.length<=a.arg||g.maxSelected.replace("{count}",a.arg):void 0},minSelected:function(a){return null!==a.val&&a.val.length>=a.arg||g.minSelected.replace("{count}",a.arg)},radio:function(a){var b=this.form.querySelectorAll('input[type=radio][name="'+a.name+'"]:checked').length;return 1===b},regExp:function(a,b){var c=b.options.validators.regExp[a.arg],d=new RegExp(c.pattern);return d.test(a.val)||c.errorMessage},remote:function(a){a.remote=a.arg},callback:function(a,b){var c=b.options.validators.callback[a.arg];return c.callback(a.el,a.val)||c.errorMessage}};b=function(b,c){this.handler=!1,this.options=a.extend(!0,{},h,c),this.form=b,this.xhr={},this.events()},b.prototype={constructor:b,events:function(){var b=this;a(this.form).submit(function(a){return c=this.querySelectorAll("[data-validetta]"),b.init(a)}),this.options.realTime===!0&&(a(this.form).find("[data-validetta]").not("[type=checkbox]").on("change",function(d){return c=a(this),b.init(d)}),a(this.form).find("[data-validetta][type=checkbox]").on("click",function(a){return c=b.form.querySelectorAll('[data-validetta][type=checkbox][name="'+this.name+'"]'),b.init(a)})),a(this.form).on("reset",function(){return a(b.form.querySelectorAll("."+b.options.errorClass+", ."+b.options.validClass)).removeClass(b.options.errorClass+" "+b.options.validClass),b.reset()})},init:function(a){return this.reset(c),this.checkFields(a),"submit"!==a.type?void 0:"pending"===this.handler?!1:this.handler===!0?(this.options.onError.call(this,a),!1):this.options.onValid.call(this,a)},checkFields:function(b){var e=this,f=[];this.getInvalidFields=function(){return f};for(var g=0,h=c.length;h>g;g++)if(!c[g].disabled){var k,l=c[g],m="",n=i(a(l).val()),o=l.getAttribute("data-validetta").split(",");this.tmp={},this.tmp={el:l,val:n,parent:this.parents(l)};for(var p=0,q=o.length;q>p;p++){var r,s=o[p].match(d);if(null!==s?("undefined"!=typeof s[2]&&(this.tmp.arg=s[2]),r=s[1]):r=o[p],(""!==n||"required"===r||"equalTo"===r)&&j.hasOwnProperty(r)&&(k=j[r](e.tmp,e),"undefined"!=typeof k&&k!==!0)){var t=l.getAttribute("data-vd-message-"+r);null!==t&&(k=t),m+=k+"
"}}""!==m?(f.push({field:l,errors:m}),this.addErrorClass(this.tmp.parent),this.window.open.call(this,l,m)):"undefined"!=typeof this.tmp.remote?this.checkRemote(l,b):("undefined"!=typeof k?this.addValidClass(this.tmp.parent):a(this.tmp.parent).removeClass(this.options.errorClass+" "+this.options.validClass),k=void 0)}},checkRemote:function(b,c){var d={},e={},f=b.name||b.id;"undefined"==typeof this.remoteCache&&(this.remoteCache={}),e[f]=this.tmp.val,d=a.extend(!0,{},{data:e},this.options.validators.remote[this.tmp.remote]||{});var g=a.param(d),h=this.remoteCache[g];if("undefined"!=typeof h)switch(h.state){case"pending":this.handler="pending",h.event=c.type;break;case"rejected":throw c.preventDefault(),new Error(h.result.message);case"resolved":h.result.valid===!1?(this.addErrorClass(this.tmp.parent),this.window.open.call(this,b,h.result.message)):this.addValidClass(this.tmp.parent)}else{var i=this.xhr[f];"undefined"!=typeof i&&"pending"===i.state()&&i.abort(),h=this.remoteCache[g]={state:"pending",event:c.type},this.remoteRequest(d,h,b,f)}},remoteRequest:function(b,c,d,e,f){var g=this;a(this.tmp.parent).addClass("validetta-pending"),this.xhr[e]=a.ajax(b).done(function(b){"object"!=typeof b&&(b=JSON.parse(b)),c.state="resolved",c.result=b,"submit"===c.event?(g.handler=!1,a(g.form).trigger("submit")):b.valid===!1?(g.addErrorClass(g.tmp.parent),g.window.open.call(g,d,b.message)):g.addValidClass(g.tmp.parent)}).fail(function(a,b){if("abort"!==b){var d="Ajax request failed for field ("+e+") : "+a.status+" "+a.statusText;throw c.state="rejected",c.result={valid:!1,message:d},new Error(d)}}).always(function(b){a(g.tmp.parent).removeClass("validetta-pending")}),this.handler="pending"},window:{open:function(b,c){if(!this.options.showErrorMessages)return void(this.handler=!0);var d=this.parents(b);if("undefined"==typeof d&&(d=b[0].parentNode),!d.querySelectorAll("."+this.options.errorTemplateClass).length){var e=document.createElement("span");if(e.className=this.options.errorTemplateClass+" "+this.options.errorTemplateClass+"--"+this.options.bubblePosition,"bubble"===this.options.display){var f,g=0,h=0;f=a(b).position(),"bottom"===this.options.bubblePosition?h=b.offsetHeight:g=b.offsetWidth,e.innerHTML="",e.style.top=f.top+h+this.options.bubbleGapTop+"px",e.style.left=f.left+g+this.options.bubbleGapLeft+"px"}d.appendChild(e),e.innerHTML=c,this.handler=!0}},close:function(a){a.parentNode.removeChild(a)}},reset:function(a){var b={};b="undefined"==typeof a||a.length>1&&"checkbox"!==a[0].type?this.form.querySelectorAll("."+this.options.errorTemplateClass):this.parents(a[0]).querySelectorAll("."+this.options.errorTemplateClass);for(var c=0,d=b.length;d>c;c++)this.window.close.call(this,b[c]);this.handler=!1},addErrorClass:function(b){a(b).removeClass(this.options.validClass).addClass(this.options.errorClass)},addValidClass:function(b){a(b).removeClass(this.options.errorClass).addClass(this.options.validClass)},parents:function(a){for(var b=parseInt(a.getAttribute("data-vd-parent-up"),10)||0,c=0;b>=c;c++)a=a.parentNode;return a}},a.fn.validetta=function(c,d){return a.validettaLanguage&&(g=a.extend(!0,{},g,a.validettaLanguage.messages)),"undefined"!=typeof d&&(g=a.extend(!0,{},g,d)),this.each(function(){new b(this,c)})}}(jQuery); \ No newline at end of file diff --git a/package.json b/package.json index 593e5f1..ddc329b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "validetta", "description": "A tiny jquery plugin for validate your forms", - "version": "1.0.0", + "version": "1.0.1", "homepage": "http://lab.hasanaydogdu.com/validetta/", "author": { "name": "Hasan Aydoğdu", diff --git a/src/validetta.css b/src/validetta.css index 2c55c09..c58b292 100644 --- a/src/validetta.css +++ b/src/validetta.css @@ -1,35 +1,34 @@ -.validetta-bubble { - position: absolute; - background-color: #cd2e26; - max-width: 325px; - border-radius: 5px; - color: white; - padding: 5px 12px; - z-index: 9; } - .validetta-bubble--right:before { - top: 7px; - left: -10px; - border-color: transparent #cd2e26 transparent transparent; } - .validetta-bubble--bottom:before { - top: -10px; - left: 10px; - border-color: transparent transparent #cd2e26 transparent; } - -.validetta-bubble:before { - content: ''; - position: absolute; - display: block; - height: 0; - width: 0; - border-width: 5px; - border-style: solid; } - -.validetta-inline, -.validetta-bubble { - display: block; - font: 12px/14px Arial, Helvetica, sans-serif; } - -.validetta-inline { - color: #cd2e26; } - -/*# sourceMappingURL=validetta.css.map */ +.validetta-bubble { + position: absolute; + background-color: #cd2e26; + max-width: 325px; + border-radius: 5px; + color: white; + padding: 5px 12px; + z-index: 9; } + .validetta-bubble:before { + content: ''; + position: absolute; + display: block; + height: 0; + width: 0; + border-width: 5px; + border-style: solid; } + .validetta-bubble--right:before { + top: 7px; + left: -10px; + border-color: transparent #cd2e26 transparent transparent; } + .validetta-bubble--bottom:before { + top: -10px; + left: 10px; + border-color: transparent transparent #cd2e26 transparent; } + +.validetta-inline, +.validetta-bubble { + display: block; + font: 12px/14px Arial, Helvetica, sans-serif; } + +.validetta-inline { + color: #cd2e26; } + +/*# sourceMappingURL=validetta.css.map */ diff --git a/validetta.jquery.json b/validetta.jquery.json index e50f36e..311ff28 100644 --- a/validetta.jquery.json +++ b/validetta.jquery.json @@ -1,6 +1,6 @@ { "name" : "validetta", - "version" : "1.0.0", + "version" : "1.0.1", "title" : "Validetta - A tiny jquery plugin for validate your forms", "description" : "Validetta is a tiny jQuery plugin which you can do client-side validation of your forms. It aims to decrease your burden with easy usage and flexible structure.", "keywords": [ @@ -15,7 +15,7 @@ "docs" : "http://lab.hasanaydogdu.com/validetta/#documentation", "demo" : "http://lab.hasanaydogdu.com/validetta/#examples", "bugs" : "http://github.com/hsnayd/validetta/issues", - "download" : "https://github.com/hsnayd/validetta/releases/download/v1.0.0/validetta-1.0.0-dist.zip", + "download" : "https://github.com/hsnayd/validetta/releases/download/v1.0.1/validetta-1.0.1-dist.zip", "author" : { "name": "Hasan Aydoğdu", "url" : "http://github.com/hsnayd"