View file jcool-2.2.6.min.js

File size: 18.38Kb
(function(w,d){'use strict';if(!d.querySelectorAll){alert('Ваш браузер устарел,пожалуйста,обновите браузер чтобы продолжить работу с сайтом');return;}function getFadeIn(a){let s=a.style,ani;if(s.display=='block'&&s.opacity===1)return;s.opacity=0;s.MozOpacity=0;s.display='block';ani=requestAnimationFrame(animate);function animate(){if(s.opacity>1||s.MozOpacity>1){cancelAnimationFrame(ani);s.opacity=1;s.MozOpacity=1;}else{s.opacity=+s.opacity+0.1;s.MozOpacity=+s.MozOpacity+0.1;cancelAnimationFrame(ani);ani=requestAnimationFrame(animate);}}return true;}function getFadeOut(a){let s=a.style,ani;if(s.display=='none'||s.opacity===0)return;ani=requestAnimationFrame(animate);function animate(){if(s.opacity<0||s.MozOpacity<0){cancelAnimationFrame(ani);s.display='none';s.opacity=0;s.MozOpacity=0;}else{s.opacity=+s.opacity-0.1;s.MozOpacity=+s.MozOpacity-0.1;cancelAnimationFrame(ani);ani=requestAnimationFrame(animate);}}return true;}let scrolling={scrollTo:function(anchor,duration){let scroll=0;do{scroll+=anchor.offsetTop;anchor=anchor.offsetParent;}while(anchor);scroll=scroll>=0?scroll:1;if(w.event.preventDefault)w.event.preventDefault();w.event.returnValue=false;duration=duration||null;this.animateScroll(scroll,duration);return false;},animateScroll:function(pos,duration){d.documentElement.scrollTop=w.scrollY+1;let element=(d.documentElement&&d.documentElement.scrollTop)?d.documentElement:d.body,start=element.scrollTop,change=pos-start,currentTime=0,increment=20;duration=duration||1000;let animateScroll=function(){currentTime+=increment;let val=Math.easeInOutQuad(currentTime,start,change,duration);element.scrollTop=val;if(currentTime<duration)setTimeout(animateScroll,increment);};animateScroll();}};Math.easeInOutQuad=(t,b,c,d)=>{t /=d / 2;if(t<1)return c / 2*t*t+b;t--;return-c / 2*(t*(t-2)-1)+b;};class App{constructor(a){this.element=a||null;this.obj=typeof this.element=='string'?(a.charAt(0)=='['?d.getElementsByName(a.substr(1).slice(0,-1)):d.querySelectorAll(this.element)):(this.element||null);}addClass(a){if(typeof this.element=='string'||this.element=='object'){for(let i=0;i<this.obj.length;++i)this.obj[i].classList.add(a);}else{this.obj.classList.add(a);}return this;}after(a){if(typeof this.element=='string'){for(let i=0;i<this.obj.length;++i)this.obj[i].appendChild(a);}else{this.obj.appendChild(a);}return this;}append(a){if(typeof this.element=='string'){for(let i=0;i<this.obj.length;++i)this.obj[i].innerHTML=this.obj[i].innerHTML+a;}else{this.obj.innerHTML=this.obj.innerHTML+a;}return this;}attr(a){let b=arguments[1]||null;if(typeof this.element=='string'||this.element=='object'){if(b){for(let i=0;i<this.obj.length;++i)this.obj[i].setAttribute(a,b);return this;}return this.obj[0].getAttribute(a);}else{return b?(this.obj.setAttribute(a,b),this):this.obj.getAttribute(a);}}before(a){if(typeof this.element=='string'){for(let i=0;i<this.obj.length;++i)this.obj[i].insertBefore(a,firstChild);}else{this.obj.insertBefore(a,firstChild);}return this;}blur(){if(typeof this.element=='string'||this.element=='object'){for(let i=0;i<this.obj.length;++i)this.obj[i].blur();}else{this.obj.blur();}return this;}changeClass(a,b){if(typeof this.element=='string'||this.element=='object'){for(let i=0;i<this.obj.length;++i){this.obj[i].classList.remove(a);this.obj[i].classList.add(b);}}else{this.obj.classList.remove(a);this.obj.classList.add(b);}return this;}checked(){return(typeof this.element=='string'||this.element=='object')?(this.obj[0].getAttribute('checked')=='checked'?true:false):(this.obj.getAttribute('checked')=='checked'?true:false);}child(){let a=[],n;n=((typeof this.element=='string'||this.element=='object')?this.obj[0]:this.obj).children;for(let i=0;i<n.length;++i)a.push(n[i]);return a;}css(a){a=a||{};for(let b in a){let c=b.split('-'),f=c[0];if(c.length>1)for(let i=1;i<c.length;++i)f+=c[i].substring(0,1).toUpperCase()+c[i].substring(1).toLowerCase();if(typeof this.element=='string'||this.element=='object'){for(let i=0;i<this.obj.length;++i)this.obj[i].style[f]=a[b];}else{this.obj.style[f]=a[b];}}return this;}data(a){return typeof this.element=='string'?this.obj[0].getAttribute('data-'+a):this.obj.getAttribute('data-'+a);}each(a){for(let i=0;i<this.obj.length;++i)a.apply(this.obj[i],arguments);return this;}empty(){if(typeof this.element=='string'){for(let i=0;i<this.obj.length;++i)this.obj[i].innerHTML='';}else{this.obj.innerHTML='';}return this;}fadeIn(){if(typeof this.element=='string'||this.element=='object'){for(let i=0;i<this.obj.length;++i)getFadeIn(this.obj[i]);}else{getFadeIn(this.obj);}return this;}fadeOut(){if(typeof this.element=='string'||this.element=='object'){for(let i=0;i<this.obj.length;++i)getFadeOut(this.obj[i]);}else{getFadeOut(this.obj);}return this;}files(){let a=[];if(typeof this.element=='string'||this.element=='object'){for(let i=0;i<this.obj.length;++i)for(let j=0;j<this.obj[i].files.length;++j)a.push(this.obj[i].files[j]);return a;}else{for(let i=0;i<this.obj.files;++i)a.push(this.obj.files[i]);return a;}}focus(){if(typeof this.element=='string'||this.element=='object'){this.obj[0].focus();}else{this.obj.focus();}return this;}hasClass(a){return(typeof this.element=='string'||this.element=='object')?this.obj[0].classList.contains(a):this.obj.classList.contains(a);}height(){return this.element==w?w.innerHeight:(this.element==d?d.innerHeight:((typeof this.element=='string'||this.element=='object')?this.obj[0].scrollHeight:this.obj.scrollHeight));}hide(){if(typeof this.element=='string'||this.element=='object'){for(let i=0;i<this.obj.length;++i)this.obj[i].style.display='none';}else{this.obj.style.display='none';}return this;}html(a){a=typeof a!='undefined'?a:null;if(typeof this.element=='string'||this.element=='object'){if(a){for(let i=0;i<this.obj.length;++i)this.obj[i].innerHTML=a;return this;}else{return this.obj[0].innerHTML;}}else{if(a){this.obj.innerHTML=a;return this;}else{return this.obj.innerHTML;}}}insertBefore(a){if(typeof this.element=='string'){for(let i=0;i<this.obj.length;++i)this.obj[i].parentNode.insertBefore(a,firstChild);}else{this.obj.parentNode.insertBefore(a,firstChild);}return this;}insertAfter(a){if(typeof this.element=='string'){for(let i=0;i<this.obj.length;++i)this.obj[i].parentNode.appendChild(a);}else{this.obj.parentNode.appendChild(a);}return this;}next(){let a;if(typeof this.element=='string'||this.element=='object'){for(let i=0;i<this.obj.length;++i)a.push(this.obj[0].nextElementSibling);this.obj=a;}else{this.obj=this.obj.nextElementSibling;}return this;}off(a,b){b=typeof b=='function'?b:null;if(typeof this.element=='string'||this.element=='object'){let i=0,j=this,t=w.setInterval(function(){if(i<j.obj.length){j.obj[i].removeEventListener(a,b);++i;}else{w.clearInterval(t);}},20);}else{this.obj.removeEventListener(a,b);}return this;}offset(){return(typeof this.element=='string'||this.element=='object')?this.obj[0].getBoundingClientRect():this.obj.getBoundingClientRect();}on(a,b,c){if(typeof c=='function'){d.addEventListener(a,function(e){let elem=$(b).obj;for(let i=0;i<elem.length;++i)if(e.target==elem[i])return c.apply(e.target,arguments);},false);}else if(typeof this.element=='string'){let i=0,self=this,tmr=setInterval(function(){if(i<self.obj.length){self.obj[i].addEventListener(a,function(e){return b.apply(e.target,arguments);},false);++i;}else{clearInterval(tmr);}},20);}else{this.element.addEventListener(a,function(e){return b.apply(e.target,arguments);},false);}}outerHtml(){let a=arguments[0]||null;if(typeof this.element=='string'||this.element=='object'){if(a){for(let i=0;i<this.obj.length;++i)this.obj[i].outerHTML=a;return this;}else{return this.obj[0].outerHTML;}}else{if(a){this.obj.outerHTML=a;return this;}else{return this.obj.outerHTML;}}}parent(){let a=[];if(typeof this.element=='string'||this.element=='object'){for(let i=0;i<this.obj.length;++i)a.push(this.obj[i].parentNode);this.obj=a;}else{this.obj=this.obj.parentNode;}return this;}prepend(a){if(typeof this.element=='string'){for(let i=0;i<this.obj.length;++i)this.obj[i].innerHTML=a+this.obj[i].innerHTML;}else{this.obj.innerHTML=a+this.obj.innerHTML;}return this;}prev(){let a;if(typeof this.element=='string'||this.element=='object'){for(let i=0;i<this.obj.length;++i)a.push(this.obj[0].previousElementSibling);this.obj=a;}else{this.obj=this.obj.previousElementSibling;}return this;}ready(fn){if(this.element!=d||!fn)return;d.addEventListener('DOMContentLoaded',fn,false);return true;}remove(){if(typeof this.element=='string'||this.element=='object'){for(let i=0;i<this.obj.length;++i)this.obj[i].remove();}else{this.obj.remove();}return this;}removeAttr(a){if(typeof this.element=='string'||this.element=='object'){for(let i=0;i<this.obj.length;++i)this.obj[i].removeAttribute(a);}else{this.obj.removeAttribute(a);}return this;}removeClass(a){if(typeof this.element=='string'||this.element=='object'){for(let i=0;i<this.obj.length;++i)this.obj[i].classList.remove(a);}else{this.obj.classList.remove(a);}return this;}scrollTo(a,b){typeof a=='number'?scrolling.animateScroll(a,b):scrolling.scrollTo(d.querySelector(a),b);return typeof a.fn=='function'?a.fn():this;}serialized(){let a=(typeof this.element=='string'||this.element=='object')?this.obj[0].querySelectorAll('input,select,textarea'):this.obj.querySelectorAll('input,select,textarea'),b={};for(let i=0;i<a.length;++i){if(a[i].type=='file'){for(let j=0;j<a[i].files.length;++j)b[a[i].getAttribute('name')+j]=a[i].files[j];}else{b[a[i].getAttribute('name')]=a[i].value;}}return b;}show(){let a=arguments[0]||'block';if(typeof this.element=='string'||this.element=='object'){for(let i=0;i<this.obj.length;++i)this.obj[i].style.display=a;}else{this.obj.style.display=a;}return this;}top(){return this.element==w?w.scrollY:null;}toggleClass(a){if(typeof this.element=='string'||this.element=='object'){for(let i=0;i<this.obj.length;++i)this.obj[i].classList.toggle(a);}else{this.obj.classList.toggle(a);}return this;}trigger(a){if(typeof a=='undefined')return;if(this.element==w){w.dispatchEvent(new Event(a));}else if(this.element==d){d.dispatchEvent(new Event(a));}else if(typeof this.element=='string'||this.element=='object'){for(let i=0;i<this.obj.length;++i)this.obj[0].dispatchEvent(new Event(a));}else{this.obj.dispatchEvent(new Event(a));}return this;}val(a){a=typeof a!='undefined'?a:null;if(typeof this.element=='string'||this.element=='object'){if(a){for(let i=0;i<this.obj.length;++i)this.obj[i].value=a;return true;}else{return this.obj[0].value;}}else{return a?(this.obj.value=a,true):this.obj.value;}}validated(){let b=(this.obj[0]||this.obj).querySelectorAll('input,select,textarea'),c=0;for(let key in b){if(isFinite(key)){let k=b[key],valid=k.validity,error=k.getAttribute('error');if(k.required){if(k.tagName==='INPUT'){if(k.type==='number'){if(k.min&&valid.rangeUnderflow){error='Минимальное значение поля '+k.min;++c;}if(k.max&&valid.rangeOverflow){error='Максимальное значение поля '+k.max;++c;}}else if(k.type==='tel'){if(k.value.length>7&&(k.value.length<11||k.value.length>12)){error='Некорректный номер телефона<br>пример: +79123456789,89123456789,88001234567 или 642531';++c;}if(k.value.length===11&&!/^8[8|9]{1}[\d]{2}[\d]{7}$/.test(k.value)){error='Некорректный номер телефона<br>пример: +79123456789,89123456789,88001234567 или 642531';++c;}if(k.value.length===12&&!/^\+79[\d]{2}[\d]{7}$/.test(k.value)){error='Некорректный номер телефона<br>пример: +79123456789,89123456789,88001234567 или 642531';++c;}}else if(k.type==='email'){if(valid.typeDismatch){error='Некорректный ввод email<br>пример: [email protected]';++c;}}if(k.pattern&&valid.patternMismatch){error=error||'Проверьте правильность заполнения полей';++c;}if(valid.typeDismatch){error='Некорректное значение "'+k.value+'"';++c;}}if(valid.valueMissing){error=error||'Обязательные поля не заполнены';++c;}if(c>0){d.querySelector('.modal_info').innerHTML=(error||'Проверьте правильность заполнения полей');fn.modal({over:'none',box:'.modal_event',close:3});return false;}}}}return true;}static test(a){return console.info(a);}}class Set{constructor(){}ajax(a,b,c){c=new XMLHttpRequest(),b={type:'POST',url:null,success:null,json:true,error:null,files:null,callback:null,asinc:true,data:null};for(let c in b)b[c]=typeof a[c]!='undefined'?a[c]:b[c];a=null;c.open(b.type,b.url,b.asinc);c.onreadystatechange=function(){try{if(this.readyState!==4||this.status!==200)return;if(b.success)if(b.json){b.success(JSON.parse(this.responseText));}else{b.success(this.responseText);}}catch(e){if(b.error)b.error(e);}};if(b.files){c.send(this.formFiles(b.data));}else{c.send(this.form(b.data));}return typeof b.callback=='function'?b.callback():this;}bgImage(a,b){if(b.type.match(/image.*/)){let reader=new FileReader();reader.onload=function(e){if(typeof a=='string'){d.querySelector(a).style.backgroundImage='url('+e.target.result+')';}else{(a[0]||a).style.backgroundImage='url('+e.target.result+')';}};reader.readAsDataURL(b);}}copy(a){if(!a||a=='undefined')return false;let b,c=d.createElement('input');c.value=a;d.body.append(c);c.select();if(d.execCommand('copy')){b=true;}else{b=false;}w.getSelection().removeAllRanges();c.remove();localStorage.setItem('clip',a);return b;}countPlus(a){let b={},c=0;b.step=parseFloat(a.dataset.count / 100);setTimeout(function(){b.fn=setInterval(function(){if(c+b.step>=parseFloat(a.dataset.count)){a.innerHTML=a.dataset.count;clearInterval(b.fn);}c+=b.step;a.innerHTML=parseInt(c);},a.dataset.duration / 100);},a.dataset.delay);}form(a,b){b=b||new FormData();for(let key in a)if(a.hasOwnProperty(key))b.append(key,a[key]);return b;}formFiles(a,b){b=b||new FormData();for(var i=0;i<a.length;++i)b.append('file['+i+']',a[i]);return b;}image(a,b){if(b.type.match(/image.*/)){let reader=new FileReader();reader.onload=function(e){var img=d.createElement('img');img.src=e.target.result;if(typeof a=='string'){d.querySelector(a).append(img);}else{(a[0]||a).append(img);}};reader.readAsDataURL(b);}}imgPreview(a,b,c){let f=a.files,g=f.length,h=d.querySelector(b),j=d.querySelector(c);if(g){j.empty();[].forEach.call(f,function(file){if(file.type.match(/image.*/)){var reader=new FileReader();reader.onload=function(e){var img=d.createElement('img');img.src=e.target.result;j.appendChild(img);};reader.readAsDataURL(file);}});h.innerHTML(g==1?f[0].name+' ('+(f[0].size / 1024).toFixed(2)+' Кб)':'Добавлено '+g+' файлов');}else{h.innerHTML('Выберите файл');j.innerHTML('Предпросмотр');}return this;}json(a){return JSON.parse(a);}jstr(a){return JSON.stringify(a);}log(){for(let i=0;i<arguments.length;++i)console.info(arguments[i]);return this;}modal(a){let self=this,b={action:'open',over:'.modal_overlay',box:null,old:null,new:null,close:null,callback:null};for(let c in b)b[c]=typeof a[c]!='undefined'?a[c]:b[c];a=null;if(b.action=='open'){if(!b.box)return;if(b.over)$(b.over).fadeIn();$(b.box).fadeIn();if(b.close){setTimeout(()=>{if(b.over)$(b.over).fadeOut();$(b.box).fadeOut();},b.close*1000);}}else if(b.action=='close'){$(b.over).fadeOut();$('.modal').each(function(){if(this.style.display!='none')$(this).fadeOut();});}else if(b.action=='change'){if(!b.old||!b.new)return;$(b.old).fadeOut();$(b.new).fadeIn();}return typeof b.callback=='function'?b.callback():this;}sleep(a,fn){setTimeout(fn||function(){},a);return this;}translite(a,b){let c=typeof b!='undefined'?{}:{'а':'a','б':'b','в':'v','г':'g','д':'d','е':'e','ж':'g','з':'z','и':'i','й':'y','к':'k','л':'l','м':'m','н':'n','о':'o','п':'p','р':'r','с':'s','т':'t','у':'u','ф':'f','ы':'i','э':'e','А':'A','Б':'B','В':'V','Г':'G','Д':'D','Е':'E','Ж':'G','З':'Z','И':'I','Й':'Y','К':'K','Л':'L','М':'M','Н':'N','О':'O','П':'P','Р':'R','С':'S','Т':'T','У':'U','Ф':'F','Ы':'I','Э':'E','ё':'yo','х':'h','ц':'ts','ч':'ch','ш':'sh','щ':'shch','ъ':'','ь':'','ю':'yu','я':'ya','Ё':'YO','Х':'H','Ц':'TS','Ч':'CH','Ш':'SH','Щ':'SHCH','Ъ':'','Ь':'','Ю':'YU','Я':'YA',' ':'_','  ':'_','.':'_','..':'_',',':'_','?':'_','??':'_','!':'_','!!':'_','-':'_','--':'_','=':'_','+':'_','__':'_'};return a.replace(/[\s\S]/g,function(x){if(c.hasOwnProperty(x))return c[x];return x;});}window(a){let b={width:w.screen.width,height:w.screen.height,url:null,x:w.screen.width / 2,y:w.screen.height / 2,callback:null,full:0,tool:0,status:0,menu:0,resize:0,focus:true};for(let c in b)b[c]=typeof a[c]!='undefined'?a[c]:b[c];let e=w.open('/','White..','fullscreen='+b.full+',toolbar='+b.tool+',status='+b.status+',menubar='+b.menu+',resizable='+b.resize+',width='+b.width+',height='+b.height);e.blur();if(b.url)e.location.href=b.url;e.moveTo(b.x,b.y);if(b.focus)e.focus();if(typeof b.callback=='function')b.callback();return e;}}class Slider{constructor(a){this.element=a||null;this.box=typeof this.element=='string'?d.querySelectorAll(this.element):(this.element||null);}init(a){if(!this.box.length)return;a=a||{};let b={delay:2000,dots:true,dots_list:[],autoplay:true,currentSlide:0,interval:null,before:null,callback:null},self=this;for(let c in b)this[c]=typeof a[c]!='undefined'?a[c]:b[c];this.slides=d.querySelector(this.element).children;this.length=this.slides.length;if(this.dots===true){let br=d.createElement('ul');br.className='slider_dots';for(let i=0;i<this.length;++i){let brs=d.createElement('li');brs.setAttribute('data-slide',i);brs.className='slider_dot';br.appendChild(brs);}d.querySelector(this.element).parentNode.appendChild(br);this.dots_list=d.querySelector('.slider_dots').children;}this.slides[this.currentSlide].classList.add('slide_active');if(this.dots)this.dots_list[this.currentSlide].classList.add('dot_active');if(this.autoplay===true)this.start();return this;}start(){this.interval=w.setInterval(()=>this.next(),this.delay);}stop(){w.clearInterval(this.interval);this.interval=null;}prev(){if(!this.box.length)return;this.go(this.currentSlide-1);}next(){if(!this.box.length)return;this.go(this.currentSlide+1);}go(n){if(!this.box.length)return;if(typeof this.before=='function')this.before();this.slides[this.currentSlide].classList.remove('slide_active');if(this.dots)this.dots_list[this.currentSlide].classList.remove('dot_active');this.currentSlide=parseInt((n+this.length)%this.length);this.slides[this.currentSlide].classList.add('slide_active');if(this.dots)this.dots_list[this.currentSlide].classList.add('dot_active');return typeof this.callback=='function'?this.callback():this;}}w.$=(a)=>new App(a);w.fn=new Set();w.sl=(a)=>new Slider(a);})(window,document);