var winScroll=null; var isMobile=false,oldIsMobile; var imgIsLoading=false; var dontUpdateHistory=false; var reCaptchaFaktura; var reCaptchaParagon; var reCaptchaKontakt; window.addEvent('domready',function(){ isMobile=$(document.body).hasClass('mobile'); $$('div.page>div *').each(function(el){ if(el.get('html').stripTags('br')==el.get('html').stripTags()){ var tekst=el.get('html'); tekst=tekst.replace(/(\s)([\S])[\s]+/g,"$1$2 "); tekst = tekst.replace(/(\s)([^<][\S]{1})[\s]+/g,"$1$2 "); // tekst = tekst.replace(/(\s)([^<][\S]{2})[\s]+/g,"$1$2 "); el.set('html',tekst); } }); var allImages=$$('img'); var imgs=new Array(); allImages.each(function(el){ imgs.push(el.getProperty('src')); }); new Asset.images(imgs,{ onProgress:function(c,i){ allImages[i].fade('in'); } }); loaded(); }); function loaded(){ window.scrollTo(0,0); $(document.body).getElement('header input').checked=false; //if(!isMobile){ winScroll=new Fx.Scroll($(window),{ wheelStops:true, duration:2000, onStart:function(){ dontUpdateHistory=true; }, onComplete:function(){ dontUpdateHistory=false; var j=0; if(isMobile){ $$('.page').each(function(page,i){ if(page.isDisplayed()){ colorizeMenu(i); var hash=document.location.hash; hash=hash.replace('#',''); var newHash=page.getProperty('data-name'); if(hash!=newHash&&!dontUpdateHistory){ history.pushState('',page.getProperty('data-title'),window.location.pathname+'#'+(newHash?newHash:'')); document.title=page.getProperty('data-title'); $(document).getElement('meta[name=description]').setProperty('content',page.getProperty('data-description')); $(document).getElement('meta[name=keywords]').setProperty('content',page.getProperty('data-keywords')); } } }); } //document.title=page.getProperty('data-title'); } }); var hash=location.hash.replace('#',''); if(hash){ var page=$$('div.page[data-name="'+hash+'"]')[0]; winScroll.set(0,page.getPosition().y); } $$('nav a:not([href^="http:"])').each(function(el,i){ el.addEvent('click',function(e){ e.stop(); if(!isMobile){ history.pushState('',$$('div.page[data-name="'+this.getProperty('data-name')+'"]')[0].getProperty('data-title'),window.location.pathname+'#'+this.getProperty('data-name')); var currentPage=$$('div.page[data-name="'+this.getProperty('data-name')+'"]')[0]; document.title=currentPage.getProperty('data-title'); $(document).getElement('meta[name=description]').setProperty('content',currentPage.getProperty('data-description')); $(document).getElement('meta[name=keywords]').setProperty('content',currentPage.getProperty('data-keywords')); } else $(document.body).getElement('header input').checked=false; winScroll.toElement($$('div.page[data-name="'+this.getProperty('data-name')+'"]')[0]); $(document.body).getElement('header input').checked=false; }); }); $('toppage').addEvent('click',function(){ window.scrollTo(0,0); }); fixMobileSafariViewport(); $$('a.dropzone').each(function(el){ if(!el.retrieve('hasDropZone')){ el.store('hasDropZone',true); initDropZone(el,5,'.jpeg,.jpg,.png,.bmp,.gif,.zip,.rar,.doc,.docx,.pdf'); } }); $$('form input[name="nip_sklepu"]').each(function(el){ el.addEvent('blur',function(){ if(this.value.length<9){ this.getParent('form').getElement('fieldset.sklepy').setStyle('display','none'); } else{ new Request({ url:'index.php', onComplete:function(html){ el.getParent('form').getElement('fieldset.sklepy').setStyle('display','block').set('html',html);; } }).post('url=sklepy&nip='+this.get('value')); } }); }); $$('#paragon form,#faktura form').each(function(el){ el.addEvent('submit',function(e){ var _this=this; e.stop(); this.getElement('input[type="submit"]').disabled=true; new Request.JSON({ url:'index.php', onComplete:function(resp){ _this.getElement('input[type="submit"]').disabled=false; if(resp.csrftoken){ _this.getElement('input[name="csrftoken"]').setProperty('value',resp.csrftoken); } if(resp.msg){ showMsg(resp.msg,resp.html); } if(resp.clear==1){ $$('fieldset.sklepy').set('html',''); _this.reset(); } grecaptcha.reset(reCaptchaFaktura); grecaptcha.reset(reCaptchaParagon); } }).post('url=sklepy&'+this.toQueryString()); }); }); $('kontakt').addEvent('submit',function(e){ var _this=this; e.stop(); new Request.JSON({ url:'index.php', onComplete:function(resp){ if(resp.csrftoken){ _this.getElement('input[name="csrftoken"]').setProperty('value',resp.csrftoken); } if(resp.msg){ showMsg(resp.msg,resp.html,resp.notclear); } if(resp.clear==1){ _this.reset(); $$('a.dropzone span').set('text','Dodaj plik'); } grecaptcha.reset(reCaptchaKontakt); } }).post(this.toQueryString()); }); $(document.body).addEvent('submit:relay(#newsletter)',function(e,target){ e.stop(); new Request.JSON({ url:'index.php', onComplete:function(resp){ if(resp.msg){ showMsg(resp.msg,resp.html,resp.notclear); } if(resp.clear==1){ target.reset(); } } }).post(target.toQueryString()); }); $('message').getElement('>a').addEvent('click',function(e){ e.stop(); showMsg('',''); $('message').setStyle('display','none'); }); } function showMsg(msg,html,notclear){ $('message').getElement('>p').set('text',msg); if(!notclear){ $('message').getElement('>div').set('html',html); } $('message').setStyle('display','block'); } window.addEvent('scroll',function(){ var ws=$(window).getScroll().y; if(ws>100) $('toppage').setStyle('display','block'); else $('toppage').setStyle('display','none'); var j=0; $$('.page').each(function(page,i){ if(!isMobile){ if(page.isDisplayed()){ colorizeMenu(i); if(i>=1){ $(document.body).getElement('nav span').addClass('visible'); } else{ $(document.body).getElement('nav span').removeClass('visible'); } // $(document.body).getElement('header>span').tween('background-color',page.getProperty('data-stripe')); var hash=document.location.hash; hash=hash.replace('#',''); var newHash=page.getProperty('data-name'); if(hash!=newHash&&!dontUpdateHistory){ history.pushState('',page.getProperty('data-title'),window.location.pathname+'#'+(newHash?newHash:'')); document.title=page.getProperty('data-title'); $(document).getElement('meta[name=description]').setProperty('content',page.getProperty('data-description')); $(document).getElement('meta[name=keywords]').setProperty('content',page.getProperty('data-keywords')); } } else{ } } }); }); window.addEvent('orientationchange',function(){ fixMobileSafariViewport(); }); window.onpopstate=function(e){ if(!isMobile){ e.preventDefault(); dontUpdateHistory=true; var hash=location.hash.replace('#',''); if(hash) winScroll.toElement($$('div.page[data-name="'+hash+'"]')[0]); else winScroll.start(0,0); } } Element.implement({ isDisplayed: function() { var scroll = window.getScroll(); var screenSize = window.getSize(); var coordinates = this.getCoordinates(); // var sizes=this.getSize(); return ( (coordinates.top-scroll.y <= screenSize.y/2 && coordinates.top-scroll.y>=0) || (coordinates.bottom-scroll.y <= screenSize.y && coordinates.bottom-scroll.y>screenSize.y/2) ); } }); function colorizeMenu(i){ $$('nav li').removeClass('active'); if(i>=0) $$('nav li')[i].addClass('active'); } function getNotCachedFiles(imgs) { var a=imgs.filter(function(item,index) { if (item.src && item.src.indexOf('svg') > -1) { return false; } else if (item.readyState !== undefined && item.readyState >= 3) { return false; } else if (item.complete) { return false; } return true; }); return a; } function is_touch_device() { return 'ontouchstart' in window || navigator.msMaxTouchPoints; } function fixMobileSafariViewport() { var is_mobile_safari_7 = !!navigator.userAgent.match(/i(Pad|Phone|Pod).+(Version\/7\.\d+ Mobile)/i); if(is_mobile_safari_7){ $(document.body).setStyle('overflow','auto'); $('start').getElement('>div').setStyles({'width':window.innerWidth,'height':window.innerHeight}); } } function initDropZone(el,mb,accept,container,galleryPaths){ if(el.getElement('strong.imgdel')){ el.getElement('strong.imgdel').addEvent('click',function(e){ e.stop(); var parent=this.getParent(); this.getPrevious().destroy(); this.destroy(); el.getPrevious().set('value',''); parent.set('text','dodaj plik'); }); } new DropZone({ ui_button: el, url: 'uploadfile.php?accept='+accept+'&uploadPath='+el.getProperty('data-upload'), multiple:false, max_file_size:mb*1024*1024, block_size: 101400, accept:accept, onSelectError:function(error, filename, filesize) { alert('Proszę załączać pliki mniejsze niż 1MB.'); }, onUploadStart: function(){ var info=el.getElement('span').get('text'); el.getElement('span').store('info',info); el.getElement('span').empty(); }, onUploadProgress: function(perc){ el.getElement('span').set('text',perc.toInt()+'%'); }, onUploadComplete: function(num_uploaded){ }, onItemComplete: function(element,file,response){ var uploadDir=el.getProperty('data-upload'); if(!file.type) return; /* var strong=new Element('strong.imgdel',{ 'events':{ 'click':function(e){ e.stop(); var _this=this; new Request.HTML({ url:'index.php?main=removeuploadedfile&file='+(container?_this.getPrevious().getProperty('data-src'):el.getPrevious().get('value')), onSuccess:function(els,tree,html,js){ var parent=_this.getParent(); el.getPrevious().set('value',''); parent.set('text','dodaj plik'); _this.getPrevious().destroy(); _this.destroy(); } }).get(); } } }); */ /* var i=new Element('i.file-icon'); i.setProperty('data-type',response.name.split('.').pop()); el.getElement('span').set('text',''); i.inject(el.getElement('span')); strong.inject(el.getElement('span')); */ el.getPrevious().set('value',response.name); el.getElement('span').set('text','Plik dodany'); }, onItemError:function(item,response,id){ if(id.error==8) alert('Tylko pliki '+accept); else alert('Wystąpił błąd'); el.getElement('span').set('text',el.getElement('span').retrieve('info')); } }); } function reCaptchaCallback(){ var siteKey='6Ld3IyIUAAAAAOLYfFa4FHFN_PWt5LmDDGodRZQB'; if($('recaptcha-faktura')) reCaptchaFaktura=grecaptcha.render('recaptcha-faktura', {'sitekey' : siteKey}); if($('recaptcha-paragon')) reCaptchaParagon=grecaptcha.render('recaptcha-paragon', {'sitekey' : siteKey}); if($('recaptcha-kontakt')) reCaptchaKontakt=grecaptcha.render('recaptcha-kontakt', {'sitekey' : siteKey}); };