-
Notifications
You must be signed in to change notification settings - Fork 0
/
Allfred.min.js
3 lines (3 loc) · 6.69 KB
/
Allfred.min.js
1
2
3
'use strict';function Alang(a){var b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},c=function(d,e){if(!d||!e)return'';var f=d.indexOf('.');return-1===f?e[d]:c(d.slice(f+1),e[d.slice(0,f)])};fetch('/Alang/'+a+'.json').then(function(d){return d.json()}).then(function(d){Array.from(document.getElementsByClassName('a-lang')).forEach(function(e){e.innerText=c(e.getAttribute('a-key'),d)}),b.success&&b.success()}).catch(function(d){b.error?b.error(d):console.log(d)})}
'use strict';var _style,_typeof='function'==typeof Symbol&&'symbol'==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&'function'==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?'symbol':typeof a},_createClass=function(){function a(b,e){for(var g,f=0;f<e.length;f++)g=e[f],g.enumerable=g.enumerable||!1,g.configurable=!0,'value'in g&&(g.writable=!0),Object.defineProperty(b,g.key,g)}return function(b,e,f){return e&&a(b.prototype,e),f&&a(b,f),b}}();function _defineProperty(a,b,e){return b in a?Object.defineProperty(a,b,{value:e,enumerable:!0,configurable:!0,writable:!0}):a[b]=e,a}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError('Cannot call a class as a function')}var Allert=function(){function a(){_classCallCheck(this,a)}return _createClass(a,null,[{key:'setConfig',value:function setConfig(b){for(var e in b)if(this.config.hasOwnProperty(e)&&'colors'!==e)if('object'===_typeof(this.config[e]))for(var f in b[e])this.config[e].hasOwnProperty(f)&&(this.config[e][f]=b[e][f]);else this.config[e]=b[e]}},{key:'message',value:function message(b){return'string'==typeof b?void a.displayMessage({message:b}):void this.displayMessage(b)}},{key:'adjustTop',value:function adjustTop(){for(var b=this,_loop=function(e){var e=b.stack[e].getAttribute('hval'),f='calc('+e+' - '+b.stack.reduce(function(h,j,k){return k>=e?h:h+10+j.offsetHeight},0)+'px )';b.stack[e].style.top=f};i<this.stack.length;i++)_loop(0)}},{key:'displayMessage',value:function displayMessage(b){var h=this,e=document.createElement('div');for(var f in this.stack||(this.stack=[]),e.innerText=b.message,this.config.style)switch(f){case'top':var g=b.style&&b.style[f]||this.config.style[f];e.setAttribute('hval',g);break;default:e.style[f]=b.style&&b.style[f]||this.config.style[f];}e.style.backgroundColor=this.config.colors[b.color]||b.color||this.config.colors.default,document.body.appendChild(e),setTimeout(function(){h.stack=h.stack.filter(function(j){return j!==e}),e.remove(),h.adjustTop()},b.time||this.config.time),setTimeout(function(){e.style.opacity=0},(b.time||this.config.time)-+(b.style?b.style.transitionDuration:this.config.style.transitionDuration).split('').filter(function(j){return /\d/.test(j)}).join('')),this.stack.push(e),this.adjustTop()}}]),a}();Allert.config={colors:{error:'#f94d40',danger:'#f94d40','default':'#53f940',success:'#53f940',warning:'#f2fc64'},style:(_style={transitionDuration:'700ms',borderRadius:'.3em',transform:'translate(calc( -100% - .5em ),calc( -100% - .5em ))',position:'fixed'},_defineProperty(_style,'position','fixed'),_defineProperty(_style,'maxWidth','90vw'),_defineProperty(_style,'padding','.5em'),_defineProperty(_style,'color','#000'),_defineProperty(_style,'left','100vw'),_defineProperty(_style,'top','100vh'),_style),time:3e3};
'use strict';document.addEventListener('DOMContentLoaded',function(){var b={addError:function addError(d){var f=1<arguments.length&&arguments[1]!==void 0?arguments[1]:'error',g=d.parentNode.querySelector('span');g&&d.parentNode.removeChild(g);var h=document.createElement('span');h.innerText='\u2717 '+f,d.parentNode.appendChild(h),d.parentNode.className='error'},check:function check(d){var f=d.parentNode.querySelector('span');if(f&&d.parentNode.removeChild(f),!d.value)return void(d.parentNode.className='');var g=document.createElement('span');g.innerText='\u2713',d.parentNode.appendChild(g),d.parentNode.className='checked'},required:function required(d){return d.value?(b.check(d),!0):(b.addError(d,'El campo es obligatorio'),!1)},isLink:function isLink(d){return /^https?:\/\//.test(d.value)?(b.check(d),!0):(b.addError(d,'Debe ingresar un enlace!'),!1)},isFloat:function isFloat(d){return d.value&&!/^[0-9][0-9]*[\.[0-9][0-9]*]?$/.test(d.value)?(b.addError(d,'Debe ingresar un n\xFAmero!'),!1):(b.check(d),!0)},isInt:function isInt(d){return /^[0-9]*$/.test(d.value)?(b.check(d),!0):(b.addError(d,'Debe ingresar un n\xFAmero entero!'),!1)},maxlength:function maxlength(d,f){return d.value.length>=+f?(b.addError(d,'L\xEDmite de '+f+' caracteres'),!1):(b.check(d),!0)},porcentaje:function porcentaje(d){var f=+d.value;return 0<=f&&100>=f?(b.addError(d,'Debe ingresar un n\xFAmero entre 1 y 100'),!1):(b.check(d),!0)},depends:function depends(){}};Array.from(document.getElementsByClassName('alfred-form')||[]).forEach(function(d){Array.from(d.querySelectorAll('input,textarea')||[]).filter(function(j){return'radio'!==j.type}).forEach(function(j){var k=function(){var m=j.getAttribute('a-reqs');if(m){var o=m.split(' '),p=!0;(o.includes('r')||o.includes('req')||o.includes('required'))&&(p=p&&b.required(j)),p&&(o.includes('l')||o.includes('link'))&&(p=p&&b.isLink(j)),p&&(o.includes('f')||o.includes('float'))&&(p=p&&b.isFloat(j)),p&&(o.includes('i')||o.includes('int'))&&(p=p&&b.isInt(j));var q=o.filter(function(r){return /^m:/.test(r)||/^max:/.test(r)||/^maxlength:/.test(r)});p&&q.length&&(p=p&&b.maxlength(j,q[0].split(':')[1]))}};j.addEventListener('change',k),j.addEventListener('focusout',k)}),Array.from(d.querySelectorAll('select')||[]).forEach(function(j){var k=function(){var m=j.getAttribute('a-reqs').split(' '),o=!0;(m.includes('r')||m.includes('req')||m.includes('required'))&&(o=o&&b.required(j))};j.addEventListener('change',k),j.addEventListener('focusout',k)});var f=Array.from(d.querySelectorAll('input[type="radio"]')||[]),g=[];f.forEach(function(j){g.includes(j.name)||g.push(j.name)});var h=g.map(function(j){return{name:j,elements:f.filter(function(k){return k.name===j})}});h.forEach(function(j){var k=function(){var m=j.elements[0].getAttribute('a-reqs').split(' ');if(m.includes('r')||m.includes('req')||m.includes('required')){var o=!1;j.elements.forEach(function(p){p.checked&&(o=!0)}),o?b.check(j.elements[0]):b.addError(j.elements[0],'El campo es obligatorio')}};j.elements.forEach(function(l){l.addEventListener('change',k),l.addEventListener('focusout',k)})}),d.addEventListener('submit',function(j){var k=Array.from(d.querySelectorAll('[a-reqs="r"],[a-reqs^="r "],[a-reqs$=" r"],[a-reqs*=" r "]')),l=!0;if(k.forEach(function(o){'checked'!==o.parentNode.className&&(l=!1)}),!l)return alert('A\xFAn faltan campos por llenar'),void j.preventDefault();var m=Array.from(d.querySelectorAll('div'));m.forEach(function(o){'error'===o.className&&(l=!1)}),l||(alert('A\xFAn hay campos con errores'),j.preventDefault())})})});