From 83e5676352803d93488c3a8c22b78e585f9d633a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20Aydo=C4=9Fdu?= Date: Sat, 18 Feb 2017 23:24:37 +0300 Subject: [PATCH] Corrected some part of `bower.json` and `package.json` and builded for v2.0.0-beta --- bower.json | 20 ++++++-------------- dist/validetta.css | 4 ++-- dist/validetta.js | 26 +++++++++++++++----------- dist/validetta.min.css | 4 ++-- dist/validetta.min.js | 6 +++--- package.json | 4 ++-- 6 files changed, 30 insertions(+), 34 deletions(-) diff --git a/bower.json b/bower.json index 32f5413..93fe96e 100644 --- a/bower.json +++ b/bower.json @@ -1,20 +1,13 @@ { "name": "validetta", - "description": "A tiny jquery plugin for validate your forms", - "version": "1.0.1", + "description": "A tiny javascript library for validate your forms", + "version": "2.0.0-beta", "homepage": "http://lab.hasanaydogdu.com/validetta/", - "author": { - "name": "Hasan Aydoğdu", - "email": "hasan_aydogdu@windowslive.com", - "url": "http://www.hasanaydogdu.com" - }, - "license": { - "type": "MIT", - "url": "https://github.com/hsnayd/validetta/blob/master/LICENCE" - }, + "author": "Hasan Aydoğdu ", + "license": "MIT", "repository": { "type": "git", - "url": "https://github.com/hsnayd/validetta.git" + "url": "https://github.com/hsnaydd/validetta.git" }, "main": [ "dist/validetta.css", @@ -39,7 +32,6 @@ "LICENCE", "Gruntfile.js", "package.json", - "validetta.jquery.json", "bower.json" ] -} \ No newline at end of file +} diff --git a/dist/validetta.css b/dist/validetta.css index 115dc26..78f7aeb 100644 --- a/dist/validetta.css +++ b/dist/validetta.css @@ -1,8 +1,8 @@ /*! * Validetta (https://github.com/hsnaydd/validetta) - * Version 1.0.1 (27-08-2016 16:21) + * Version 2.0.0-beta (18-02-2017 23:22) * Licensed under MIT (https://github.com/hsnaydd/validetta/blob/master/LICENCE) - * Copyright 2013-2016 Hasan Aydoğdu + * Copyright 2013-2017 Hasan Aydoğdu */ .validetta-bubble { diff --git a/dist/validetta.js b/dist/validetta.js index e314545..6e1957a 100644 --- a/dist/validetta.js +++ b/dist/validetta.js @@ -1,8 +1,8 @@ /*! * Validetta (https://github.com/hsnaydd/validetta) - * Version 1.0.1 (27-08-2016 16:21) + * Version 2.0.0-beta (18-02-2017 23:22) * Licensed under MIT (https://github.com/hsnaydd/validetta/blob/master/LICENCE) - * Copyright 2013-2016 Hasan Aydoğdu + * Copyright 2013-2017 Hasan Aydoğdu */ (function() { @@ -15,7 +15,7 @@ // Current fields/fields var FIELDS = {}; // RegExp for input validate rules - var RRULE = new RegExp(/^(minChecked|maxChecked|minSelected|maxSelected|minLength|maxLength|equalTo|different|regExp|remote|callback)\[([\w\[\]]+)\]/i); + var RRULE = new RegExp(/^([a-zA-Z]+)\[([\w\[\]]+)\]/i); // RegExp for mail control method // @from ( http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#e-mail-state-%28type=email%29 ) var RMAIL = 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])?)*$/); @@ -121,7 +121,8 @@ * @return {Object} merged object */ var mergeObject = function(obj1, obj2) { - var obj3 = {}, propertyName; + var obj3 = {}, + propertyName; for (propertyName in obj1) { if (obj1.hasOwnProperty(propertyName)) { obj3[propertyName] = obj1[propertyName]; @@ -275,12 +276,15 @@ creditCard: function(tmp) { // allow empty because empty check does by required metheod if (tmp.val === '') return true; - var reg, cardNumber, pos, digit, i, subTotal, sum = 0, strlen; - reg = new RegExp(/[^0-9]+/g); - cardNumber = tmp.val.replace(reg, ''); - strlen = cardNumber.length; + var pos, + digit, + subTotal, + sum = 0; + var reg = new RegExp(/[^0-9]+/g); + var cardNumber = tmp.val.replace(reg, ''); + var strlen = cardNumber.length; if (strlen < 16) return messages.creditCard; - for (i = 0; i < strlen; i++) { + for (var i = 0; i < strlen; i++) { pos = strlen - i; digit = parseInt(cardNumber.substring(pos - 1, pos), 10); if (i % 2 === 1) { @@ -325,8 +329,8 @@ return count === 1; }, // Custom reg check - regExp: function(tmp, self) { - var _arg = self.options.validators.regExp[tmp.arg], + pattern: function(tmp, self) { + var _arg = self.options.validators.pattern[tmp.arg], _reg = new RegExp(_arg.pattern); return _reg.test(tmp.val) || _arg.errorMessage; }, diff --git a/dist/validetta.min.css b/dist/validetta.min.css index 01829f3..bc65479 100644 --- a/dist/validetta.min.css +++ b/dist/validetta.min.css @@ -1,8 +1,8 @@ /*! * Validetta (https://github.com/hsnaydd/validetta) - * Version 1.0.1 (27-08-2016 16:21) + * Version 2.0.0-beta (18-02-2017 23:22) * Licensed under MIT (https://github.com/hsnaydd/validetta/blob/master/LICENCE) - * Copyright 2013-2016 Hasan Aydoğdu + * Copyright 2013-2017 Hasan Aydoğdu */ .validetta-bubble{position:absolute;background-color:#cd2e26;max-width:325px;border-radius:5px;color:#fff;padding:5px 12px;z-index:1}.validetta-bubble:before{content:"";position:absolute;display:block;height:0;width:0;border:5px solid transparent}.validetta-bubble--left:before{top:7px;right:-10px;border-left-color:#cd2e26}.validetta-bubble--right:before{top:7px;left:-10px;border-right-color:#cd2e26}.validetta-bubble--top:before{bottom:-10px;left:10px;border-top-color:#cd2e26}.validetta-bubble--bottom:before{top:-10px;left:10px;border-bottom-color:#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 3be11ea..ae7fb03 100644 --- a/dist/validetta.min.js +++ b/dist/validetta.min.js @@ -1,8 +1,8 @@ /*! * Validetta (https://github.com/hsnaydd/validetta) - * Version 1.0.1 (27-08-2016 16:21) + * Version 2.0.0-beta (18-02-2017 23:22) * Licensed under MIT (https://github.com/hsnaydd/validetta/blob/master/LICENCE) - * Copyright 2013-2016 Hasan Aydoğdu + * Copyright 2013-2017 Hasan Aydoğdu */ -!function(){"use strict";var e={},t={},r=new RegExp(/^(minChecked|maxChecked|minSelected|maxSelected|minLength|maxLength|equalTo|different|regExp|remote|callback)\[([\w\[\]]+)\]/i),a=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])?)*$/),n=new RegExp(/^[\-\+]?(\d+|\d+\.?\d+)$/),i={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."},s={showErrorMessages:!0,display:"bubble",errorTemplateClass:"validetta-bubble",errorClass:"validetta-error",validClass:"validetta-valid",bubblePosition:"right",bubbleGapX:15,bubbleGapY:0,realTime:!1,realTimeEvents:"change blur",onValid:function(){},onError:function(){},validators:{}},o=function(e){return"string"==typeof e?e.replace(/^\s+|\s+$/g,""):e},l=function(e){for(var t=0,r=0;r=e.arg||i.minLength.replace("{count}",e.arg)},maxLength:function(e){return e.val.length<=e.arg||i.maxLength.replace("{count}",e.arg)},equalTo:function(e,t){return t.form[e.arg].value===e.val||i.notEqual},different:function(e,t){return t.form[e.arg].value!==e.val||i.different},creditCard:function(e){if(""===e.val)return!0;var t,r,a,n,s,o,l,d=0;if(t=new RegExp(/[^0-9]+/g),r=e.val.replace(t,""),l=r.length,l<16)return i.creditCard;for(s=0;s9&&(o=1+(o-10))):o=n,d+=o;return d>0&&d%10===0||i.creditCard},maxChecked:function(e,t){var r=t.form.querySelectorAll('[name="'+e.el.name+'"]:not([disabled])');if(r[0]===e.el){var a=l(r);if(0!==a)return a<=e.arg||i.maxChecked.replace("{count}",e.arg)}},minChecked:function(e,t){var r=t.form.querySelectorAll('[name="'+e.el.name+'"]:not([disabled])');if(r[0]===e.el){var a=l(r);return a>=e.arg||i.minChecked.replace("{count}",e.arg)}},maxSelected:function(e){if(null!==e.val)return e.val.length<=e.arg||i.maxSelected.replace("{count}",e.arg)},minSelected:function(e){return null!==e.val&&e.val.length>=e.arg||i.minSelected.replace("{count}",e.arg)},radio:function(e){var t=this.form.querySelectorAll('[name="'+e.name+'"]:checked').length;return 1===t},regExp:function(e,t){var r=t.options.validators.regExp[e.arg],a=new RegExp(r.pattern);return a.test(e.val)||r.errorMessage},remote:function(e){e.remote=e.arg},callback:function(e,t){var r=t.options.validators.callback[e.arg];return r.callback(e.el,e.val)||r.errorMessage}},events:function(){var e=this;this.form.addEventListener("submit",function(r){return t=this.querySelectorAll("[data-validetta]"),e.init(r)}),this.options.realTime===!0&&(d(this.form.querySelectorAll("[data-validetta]:not([type=checkbox])"),this.options.realTimeEvents,function(r){return t=[this],e.init(r)}),d(this.form.querySelectorAll("[data-validetta][type=checkbox]"),"click",function(r){return t=e.form.querySelectorAll('[data-validetta][type=checkbox][name="'+this.name+'"]'),e.init(r)})),this.form.addEventListener("reset",function(){return e.reset(this.querySelectorAll("[data-validetta]"))})},init:function(e){if(this.reset(t),this.checkFields(e),"submit"===e.type)return"pending"===this.handler?e.preventDefault():this.handler===!0?(this.options.onError.call(this,e),e.preventDefault()):this.options.onValid.call(this,e)},checkFields:function(e){var a=this;this.invalidFields=[];for(var n=0,i=t.length;n"}}""!==d?(this.setInvalidField(l,d),this.window.open.call(this,l,d)):"undefined"!=typeof this.tmp.remote?this.checkRemote(l,e):("undefined"!=typeof s&&this.addValidClass(this.tmp.parent),s=void 0),this.scopeOptions={}}},checkRemote:function(e,t){var r={},a={},n=e.name||e.id;"undefined"==typeof this.remoteCache&&(this.remoteCache={}),a[n]=this.tmp.val,r=c({data:a},this.options.validators.remote[this.tmp.remote]||{});var i=n+":"+this.tmp.val,s=this.remoteCache[i];if("undefined"!=typeof s)switch(s.state){case"pending":this.handler="pending",s.event=t.type;break;case"rejected":throw t.preventDefault(),new Error(s.result.message);case"resolved":s.result.valid===!1?(this.addErrorClass(this.tmp.parent),this.setInvalidField(e,s.result.message),this.window.open.call(this,e,s.result.message)):this.addValidClass(this.tmp.parent)}else{var o=this.xhr[n];"undefined"!=typeof o&&4!==o.readyState&&o.abort(),s=this.remoteCache[i]={state:"pending",event:t.type},this.remoteRequest(r,s,e,n)}},remoteRequest:function(e,t,r,a){var n=this;this.tmp.parent.classList.add("validetta-pending");var i=new XMLHttpRequest;i.open(e.type,e.url,!0),"POST"===e.type.toUpperCase()&&i.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"),i.onload=function(){if(i.status>=200&&i.status<400){var e=i.responseText;"object"!=typeof e&&(e=JSON.parse(e)),t.state="resolved",t.result=e,"submit"===t.event?(n.handler=!1,h(n.form,"submit")):e.valid===!1?(n.addErrorClass(n.tmp.parent),n.triggerError(r,e.message)):n.addValidClass(n.tmp.parent)}else if(0!==i.status){var s="Ajax request failed for field ("+a+"): "+i.status+" "+i.statusText;throw t.state="rejected",t.result={valid:!1,message:s},new Error(s)}n.tmp.parent.classList.remove("validetta-pending")},i.onerror=function(){var e="There was a connection error of some sort";throw t.state="rejected",t.result={valid:!1,message:e},new Error(e)},this.xhr[a]=i,this.xhr[a].send(a+"="+e.data[a]),this.handler="pending"},window:{open:function(e,t){if(!this.scopeOptions.showErrorMessages)return void(this.handler=!0);var r=this.parents(e);if(this.addErrorClass(r),"undefined"==typeof r&&(r=e[0].parentNode),!r.querySelectorAll("."+this.options.errorTemplateClass).length){var a=document.createElement("span");if(a.className=this.options.errorTemplateClass,a.innerHTML=t,r.appendChild(a),"bubble"===this.options.display){var n=0,i=0,s="left"===this.scopeOptions.bubblePosition?-1:1,o="top"===this.scopeOptions.bubblePosition?-1:1;switch(a.classList.add(this.options.errorTemplateClass+"--"+this.scopeOptions.bubblePosition),this.scopeOptions.bubblePosition){case"top":case"bottom":i=e.offsetHeight;break;case"left":n=a.offsetWidth;break;default:n=e.offsetWidth}a.style.top=e.offsetTop+(i+this.scopeOptions.bubbleGapY)*o+"px",a.style.left=e.offsetLeft+(n+this.scopeOptions.bubbleGapX)*s+"px"}this.handler=!0}},close:function(e){var t=this.parents(e);t.classList.remove(this.options.errorClass,this.options.validClass);var r=t.getElementsByClassName(this.options.errorTemplateClass)[0];"undefined"!=typeof r&&t.removeChild(r)}},generateScopeOptions:function(e){for(var t=e.attributes,r={},a=0;a=e.arg||i.minLength.replace("{count}",e.arg)},maxLength:function(e){return e.val.length<=e.arg||i.maxLength.replace("{count}",e.arg)},equalTo:function(e,t){return t.form[e.arg].value===e.val||i.notEqual},different:function(e,t){return t.form[e.arg].value!==e.val||i.different},creditCard:function(e){if(""===e.val)return!0;var t,r,a,n=0,s=new RegExp(/[^0-9]+/g),o=e.val.replace(s,""),l=o.length;if(l<16)return i.creditCard;for(var d=0;d9&&(a=1+(a-10))):a=r,n+=a;return n>0&&n%10===0||i.creditCard},maxChecked:function(e,t){var r=t.form.querySelectorAll('[name="'+e.el.name+'"]:not([disabled])');if(r[0]===e.el){var a=l(r);if(0!==a)return a<=e.arg||i.maxChecked.replace("{count}",e.arg)}},minChecked:function(e,t){var r=t.form.querySelectorAll('[name="'+e.el.name+'"]:not([disabled])');if(r[0]===e.el){var a=l(r);return a>=e.arg||i.minChecked.replace("{count}",e.arg)}},maxSelected:function(e){if(null!==e.val)return e.val.length<=e.arg||i.maxSelected.replace("{count}",e.arg)},minSelected:function(e){return null!==e.val&&e.val.length>=e.arg||i.minSelected.replace("{count}",e.arg)},radio:function(e){var t=this.form.querySelectorAll('[name="'+e.name+'"]:checked').length;return 1===t},pattern:function(e,t){var r=t.options.validators.pattern[e.arg],a=new RegExp(r.pattern);return a.test(e.val)||r.errorMessage},remote:function(e){e.remote=e.arg},callback:function(e,t){var r=t.options.validators.callback[e.arg];return r.callback(e.el,e.val)||r.errorMessage}},events:function(){var e=this;this.form.addEventListener("submit",function(r){return t=this.querySelectorAll("[data-validetta]"),e.init(r)}),this.options.realTime===!0&&(d(this.form.querySelectorAll("[data-validetta]:not([type=checkbox])"),this.options.realTimeEvents,function(r){return t=[this],e.init(r)}),d(this.form.querySelectorAll("[data-validetta][type=checkbox]"),"click",function(r){return t=e.form.querySelectorAll('[data-validetta][type=checkbox][name="'+this.name+'"]'),e.init(r)})),this.form.addEventListener("reset",function(){return e.reset(this.querySelectorAll("[data-validetta]"))})},init:function(e){if(this.reset(t),this.checkFields(e),"submit"===e.type)return"pending"===this.handler?e.preventDefault():this.handler===!0?(this.options.onError.call(this,e),e.preventDefault()):this.options.onValid.call(this,e)},checkFields:function(e){var a=this;this.invalidFields=[];for(var n=0,i=t.length;n"}}""!==d?(this.setInvalidField(l,d),this.window.open.call(this,l,d)):"undefined"!=typeof this.tmp.remote?this.checkRemote(l,e):("undefined"!=typeof s&&this.addValidClass(this.tmp.parent),s=void 0),this.scopeOptions={}}},checkRemote:function(e,t){var r={},a={},n=e.name||e.id;"undefined"==typeof this.remoteCache&&(this.remoteCache={}),a[n]=this.tmp.val,r=c({data:a},this.options.validators.remote[this.tmp.remote]||{});var i=n+":"+this.tmp.val,s=this.remoteCache[i];if("undefined"!=typeof s)switch(s.state){case"pending":this.handler="pending",s.event=t.type;break;case"rejected":throw t.preventDefault(),new Error(s.result.message);case"resolved":s.result.valid===!1?(this.addErrorClass(this.tmp.parent),this.setInvalidField(e,s.result.message),this.window.open.call(this,e,s.result.message)):this.addValidClass(this.tmp.parent)}else{var o=this.xhr[n];"undefined"!=typeof o&&4!==o.readyState&&o.abort(),s=this.remoteCache[i]={state:"pending",event:t.type},this.remoteRequest(r,s,e,n)}},remoteRequest:function(e,t,r,a){var n=this;this.tmp.parent.classList.add("validetta-pending");var i=new XMLHttpRequest;i.open(e.type,e.url,!0),"POST"===e.type.toUpperCase()&&i.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"),i.onload=function(){if(i.status>=200&&i.status<400){var e=i.responseText;"object"!=typeof e&&(e=JSON.parse(e)),t.state="resolved",t.result=e,"submit"===t.event?(n.handler=!1,h(n.form,"submit")):e.valid===!1?(n.addErrorClass(n.tmp.parent),n.triggerError(r,e.message)):n.addValidClass(n.tmp.parent)}else if(0!==i.status){var s="Ajax request failed for field ("+a+"): "+i.status+" "+i.statusText;throw t.state="rejected",t.result={valid:!1,message:s},new Error(s)}n.tmp.parent.classList.remove("validetta-pending")},i.onerror=function(){var e="There was a connection error of some sort";throw t.state="rejected",t.result={valid:!1,message:e},new Error(e)},this.xhr[a]=i,this.xhr[a].send(a+"="+e.data[a]),this.handler="pending"},window:{open:function(e,t){if(!this.scopeOptions.showErrorMessages)return void(this.handler=!0);var r=this.parents(e);if(this.addErrorClass(r),"undefined"==typeof r&&(r=e[0].parentNode),!r.querySelectorAll("."+this.options.errorTemplateClass).length){var a=document.createElement("span");if(a.className=this.options.errorTemplateClass,a.innerHTML=t,r.appendChild(a),"bubble"===this.options.display){var n=0,i=0,s="left"===this.scopeOptions.bubblePosition?-1:1,o="top"===this.scopeOptions.bubblePosition?-1:1;switch(a.classList.add(this.options.errorTemplateClass+"--"+this.scopeOptions.bubblePosition),this.scopeOptions.bubblePosition){case"top":case"bottom":i=e.offsetHeight;break;case"left":n=a.offsetWidth;break;default:n=e.offsetWidth}a.style.top=e.offsetTop+(i+this.scopeOptions.bubbleGapY)*o+"px",a.style.left=e.offsetLeft+(n+this.scopeOptions.bubbleGapX)*s+"px"}this.handler=!0}},close:function(e){var t=this.parents(e);t.classList.remove(this.options.errorClass,this.options.validClass);var r=t.getElementsByClassName(this.options.errorTemplateClass)[0];"undefined"!=typeof r&&t.removeChild(r)}},generateScopeOptions:function(e){for(var t=e.attributes,r={},a=0;a