/* dynlite ui components library * peter assenov- aip solutions ltd' 2001-201 * ver 2.4.1 - 2015-10-27 */ /* library extensions */ if(!dl.debug) dl.debug = dl.w.console.debug; if(!dl.cache) dl.cache = {}; //hash if(!dl.hash) dl.hash = function(key, val, top){ //alert('dl.hash: '+key+' = '+val); if(!key) return false; var res = dl.w.encodeURIComponent(val) || ''; var hash = dl.l.hash; var query = {}; if(!hash || hash == '' || hash == '#') query[key] = res; else { var arr = hash.split('&'); for(var i in arr) { var el = arr[i]; var sub = el.split('='); if(sub[0].indexOf('#') === 0) sub[0] = sub[0].substr(1); query[sub[0]] = sub[1]; } if(val !== undefined) query[key] = res; } if(val !== undefined) { var ohash = []; for(var i in query) ohash.push(i+'='+query[i]); dl.l.hash = '#'+ohash.join('&'); if(top) dl.w.scrollTo(0,0); } else return dl.w.decodeURIComponent(query[key]); } //gestures if(!dl.gesture) dl.gesture={ d:40,x0:0,y0:0,active:0,block:0, start:function(e){ if(!e.touches.length) return; dl.gesture.x0=e.touches[0].pageX; dl.gesture.y0=e.touches[0].pageY; dl.gesture.active=1; dl.on('touchmove',dl.gesture.move,false); }, move:function(e){ if(!dl.gesture.active) return; if(dl.gesture.block) e.preventDefault(); var dx = dl.gesture.x0-e.touches[0].pageX; var dy = dl.gesture.y0-e.touches[0].pageY; if(Math.abs(dx)>=dl.gesture.d){ dl.gesture.stop(); if(dx>0) dl.fire('wipeRight'); else dl.fire('wipeLeft'); } else if(Math.abs(dy)>=dl.gesture.d){ dl.gesture.stop(); if(dy>0) dl.fire('wipeUp'); else dl.fire('wipeDown'); } }, stop:function(e){ dl.off('touchmove',dl.gesture.move); dl.gesture.x0=dl.gesture.y0=0; dl.gesture.active=0; } } if(!dl.uri) { //handles qry string parameter management dl.uri=function(uri){ if(!(this instanceof dl.uri)) return new dl.uri(uri); this.uri = uri || ''; var arr = this.uri.split('?'); this.url = arr[0]; this.qry = {}; if(arr[1]) { var list = arr[1].split('&'); for(var i in list) { var par = list[i].split('='); if(par[0]) this.qry[par[0]] = par[1]; } } } dl.Uri=dl.uri.prototype; dl.Uri.query=function(par, val){ if(typeof par == 'object') for(i in par) this.qry[i] = par[i]; else this.qry[par] = val; return this._uri(); } //helpers dl.Uri._uri=function(){ var qry = []; for(var i in this.qry) qry.push(i+'='+this.qry[i]); var uri = this.url; if(qry.length) uri+='?'+qry.join('&'); return uri; } } if(!dl.query) { /* query string management */ dl.query = function(key, val){ if(!key) return false; key = key.replace(/\+/gi,' '); //strange but it seems the space is auto-replaced with + in the url var res = dl.w.encodeURIComponent(val) || ''; var search = dl.l.search; var query = {}; if(!search || search == '' || search == '#') query[key] = res; else { var arr = search.split('&'); for(var i in arr) { var el = arr[i].replace(/\+/gi,' '); var sub = el.split('='); if(sub[0].indexOf('?') === 0) sub[0] = sub[0].substr(1); query[dl.w.decodeURIComponent(sub[0])] = sub[1]; } if(val !== undefined) query[key] = res; } if(val !== undefined) { var oquery = []; for(var i in query) { if(i == key && val === false) continue; oquery.push(i+'='+query[i]); } dl.l.search = '?'+oquery.join('&'); } else return dl.w.decodeURIComponent(query[key]); } } /* json data type */ dl.json = { encode:function(obj){ return JSON.stringify(obj); }, decode:function(str){ if(!str) return ''; var obj = JSON.parse(str); if(typeof obj == 'string') { var out = obj; try{out = JSON.parse(obj);}catch(e){} return out; } else return obj; },//it seems one call do not return object because when the content is sent with ajax is already in json format } /* session handling */ dl.session = { db : dl.w.sessionStorage, get: function(id){ return dl.json.decode(this.db.getItem(id)); }, set: function (id, item) { return this.db.setItem(id, dl.json.encode(item));}, del: function(id){this.db.removeItem(id);} } /* local storage */ dl.storage = { db : dl.w.localStorage, get: function(id){ return dl.json.decode(this.db.getItem(id)); }, set: function (id, item) { return this.db.setItem(id, dl.json.encode(item));}, del: function(id){this.db.removeItem(id);} } /* tab component */ if(!dl.rt) dl.rt = {} dl.rt.tab = {}; dl.tab = function(id){ var id = id||'tab'; if(dl.rt.tab[id]) return dl.rt.tab[id]; if(!(this instanceof dl.tab)) return dl.rt.tab[id] = new dl.tab(id); //finally the class can start :) this.id = id; this.list = []; this.active = false; if(this.init()) this.bind(); } dl.Tab = dl.tab.prototype; dl.Tab.init = function(){ this.el = dl.el(this.id); var list = this.el.list('[data-link]'); var active = 0; for(var i = list.length; i--;) { var el = dl.el(list[i]); //if(el.data('link') != '' && el.data('link') != this.id) // continue; var cont = el.data('link') || el.id.replace('link', 'cont'); var cont = dl.el(cont); this.list[i] = {'link':el,'cont':cont}; if(el.has('active')) active = i; } if(this.el.data('save') == 'hash' && dl.hash(this.id) > 0) active = dl.hash(this.id); if(this.el.data('default')) active = this.el.data('default'); else if(this.el.data('save') == 'hash' && dl.session.get('tab.'+this.id) > 0) active = dl.session.get('tab.'+this.id); this.open(active, false); return true; } dl.Tab.bind = function(){ var self = this; for(var i = this.list.length; i--;) dl.el(this.list[i].link).on('click', this.open.bind(this, i)); } dl.Tab.open = function(i, event){ if(!this.list[i]) return; if(this.active !== false) { if(this.active == i) return; var el = this.list[this.active]; el.link.remove('active'); el.cont.remove('active'); el.cont.css('zIndex', 1); this.active = false; } var el = this.list[i]; this.active = i; el.link.add('active'); el.cont.add('active'); el.cont.css('zIndex', 10); if(this.el.data('save') == 'hash') dl.hash(this.id, this.active); if(this.el.data('save') == 'hash') dl.session.set('tab.'+this.id, this.active); if(this.el.data('init') == 'map') { var el = dl.el(el.cont).list("[data-dl='map']")[0]; if(el.id) dl.map(el.id).open(); } } /* popup component */ dl.popup=function(url,conf,cb){ if(dl.urlbusy) return; cb = (!cb) ? cb : 0; if(!(this instanceof dl.popup)) return new dl.popup(url,conf,cb); if(!conf) conf={}; this.id=conf.id||'popup'; this.el=dl.el(this.id,{id:this.id,cls:this.cls,tag:'IFRAME'}); this.w=conf.w||0; this.h=conf.h||0; this.cls=conf.cls||this.id; this.conf=conf||{}; this.cnt=0; this.close(); if(cb) this.el.cb=cb; if(url) this.open(url); dl.w.popup=this; //static registration } dl.Popup=dl.popup.prototype; dl.Popup.open=function(url){ var self=this; if(!this.el) this.el=dl.el(this.id,{id:this.id,cls:this.cls,tag:'IFRAME'}); if(this.w) this.el.css('width', this.w); if(this.h) this.el.css('height', this.h); this.el.src=url; this.el.center=function(){ if(self.conf.fixed) return false; var w=this.w||this.offsetWidth; var h=this.h||this.offsetHeight; this.css('left', Math.max(10,(dl.width()-w)/2)+'px'); this.css('top', Math.max(10,(dl.height()-h)/2.5)+dl.scroll()+'px'); } this.el.adjust=function(){ //trace(this.cnt, 'adjust'); var self=this; /*old from 2016-03-24: var body=this.contentDocument.getElementsByTagName('body')[0]; if(!body) return false; if(this.h&&this.h==body.offsetHeight) return; this.h=(body)? body.offsetHeight : 0; this.css('height',this.h+'px'); this.center(null, this.h); */ if(!this.h) this.h=this.offsetHeight; else { var body=this.contentDocument.getElementsByTagName('body')[0]; if(body && body.offsetHeight != this.h) { this.h=body.offsetHeight; this.css('height', this.h); this.center(null, this.h); } else return; } if(this.cnt++ < 10) setTimeout(function(){self.adjust()}, 200);//new from 2016-03-24: dl.delay(this.adjust.bind(this), 200) } this.el.show(); this.el.focus(); this.el.center(); this.el.on('load', function(){ this.cnt=0; this.adjust(); this.active=true; }) //sugar dl.on('resize', function(){if(self.el) self.el.center()}) //dl.on('scroll', function(){self.el.center()}) dl.on('click', function(e){ if(e.target&&e.target!==self.el) if(self.el&&self.el.active) self.close(); }) } dl.Popup.close=function(){ this.el.innerHTML=''; this.el.h=0; this.el.hide(); this.el.active=false; if(this.el.cb) this.el.cb(); this.el.parentNode.removeChild(this.el); this.el=null; dl.w.popup=null; } /* rich-text editting */ dl.rte=function(id,conf){ if(!(this instanceof dl.rte)) return new dl.rte(id,conf); var self=this; this.id=id||'rte'; this.conf=conf||{bold:'\ue6ae',italic:'\ue6b0',underline:'\ue6af'} this.list={}; dl.on('ready', function(){self.init()}) } dl.Rte=dl.rte.prototype; dl.Rte.init=function(){ var self=this; this.src=dl.el(this.id); this.cont=dl.el(this.id+'.cont',{id:this.id+'.cont',cls:'rte',tag:'DIV',parent:this.src.parentNode}) this.cont.css('left', this.src.offsetLeft); this.cont.css('top', this.src.offsetTop); this.cont.css('width', this.src.offsetWidth); this.cont.css('height', this.src.offsetHeight); this.menu=dl.el(this.id+'.menu',{id:this.id+'.menu',cls:'rte-menu',tag:'DIV',parent:this.cont}); for(var i in this.conf) { var icon=dl.el(this.id+'.'+i,{id:this.id+'.'+i,cls:'rte-icon',tag:'A',parent:this.menu}); icon.cmd=i; icon.html(this.conf[i]); icon.onmousedown=function(e){ var so = window.getSelection(); var sr = so.getRangeAt(0); self.exec(this.cmd); setTimeout(function(){ self.edit.focus(); so.removeAllRanges(); so.addRange(sr); },1); }; this.list[i]=icon; } this.edit=dl.el(this.id+'.text',{id:this.id+'.edit',cls:'rte-edit',tag:'DIV',parent:this.cont}); this.edit.css('height', this.cont.offsetHeight-this.menu.offsetHeight-6); this.edit.contentEditable=true; this.edit.onblur=function(){trace('blur')}; this.edit.onfocus=function(){trace('focus')}; this.src.parentNode.removeChild(this.src); //this.edit('keyup') this.exec('rtf'); } dl.Rte.exec=function(cmd, val){ if(cmd == 'rtf') { this.edit.innerHTML = this.src.value; this.edit.focus(); this.src.hide(); } else if(cmd == 'txt') { this.edit.value = this.src.innerHTML; this.src.focus(); this.edit.hide(); } else { document.execCommand(cmd, false, false); setTimeout(function(){dl.el('rte.edit').focus();},1); } } /* banner manager class */ dl.cache.banner=[]; //list of active banners dl.banner=function(id, conf) { var id = id||'banner'; if(dl.cache.banner[id]) //cache lookup return dl.cache.banner[id]; if(!(this instanceof dl.banner)) //auto object creation return dl.cache.banner[id] = new dl.banner(id,conf); //finally the class can start :) this.id = id; this.conf = conf || {item:'article', btn:'footer a', delay:5, duration:0.5, autostart:1, active:0, cls:'active'} this.el = dl.el(this.id); this.btn = this.el.list(this.conf.btn); this.list = this.el.list(this.conf.item); this.loop = null; this.active = null; //init this.trans(this.conf.active); if(this.conf.autostart) this.play(); } dl.Banner=dl.banner.prototype; dl.Banner.play=function(){ //starts the slide-show var self = this; if(this.loop) clearInterval(this.loop); if(this.list.length > 1) this.loop = setInterval(function(){self.next()}, this.conf.delay * 1000) if(this.active === null) this.trans(0); } dl.Banner.pause=function(){ //stops the loop //trace('pause'); if(this.loop) clearInterval(this.loop); } dl.Banner.next=function(){ //transition to the next element //trace('next'); this.active++; if(!this.active || this.active < 0 || this.active >= this.list.length) this.active = 0; this.trans(this.active); } dl.Banner.trans=function(i){ //hides all elements and show the selected one //trace('trans'); this.pause(); this.active = i||0; var cls = this.conf.cls; var dur = parseInt(this.conf.duration * 1000); for(var i = this.btn.length;i;) { //process buttons var el = dl.el(this.btn[--i]); (i == this.active)? el.add(cls) : el.remove(cls); } for(var i = this.list.length;i;) { //process banners var el = dl.el(this.list[--i]); (i == this.active)? el.add(cls) : el.remove(cls);//(i == this.active)? el.show() : el.hide(); } var img = this.list[this.active].list('img')[0]; this.el.css('background','linear-gradient(rgba(1, 81, 152, 0.94), rgba(1, 81, 152, 0.94)), url("'+dl.el(img).attr('src')+'")'); this.play(); } /* image swap class */ dl.swapsrc=function(id, el){ if(!id) return false; if(!(this instanceof dl.swapsrc)) return new dl.swapsrc(id, el); this.id = id; this.el = dl.el(el); if(!this.el.src || !this.el.data('swapsrc') || this.el.src.indexOf(this.el.data('swapsrc')) != -1) //missing or same images required no swap return false; //create this.alt = dl.el(this.id+'.alt', { tag: 'IMG', css: { 'position': 'absolute', 'left': this.el.offsetLeft+'px', 'top': this.el.offsetTop+'px', 'max-width': this.el.offsetWidth, 'max-height': this.el.offsetHeight, 'z-index': -1, }, parent: this.el.parentNode }); //bind this.el.css('transition', 'opacity 400ms ease') this.el.on('mouseover', this.swap.bind(this)) this.el.on('mouseout', this.restore.bind(this)) } dl.Swapsrc=dl.swapsrc.prototype; dl.Swapsrc.swap=function(){ if(!this.alt.src) { var self = this; this.alt.src = this.el.data('swapsrc'); this.alt.onload=function(){self.el.css('opacity', 0.01);} //if not delayed the image appears broken if connectio is not good } else this.el.css('opacity', 0.01); } dl.Swapsrc.restore=function(){ this.el.css('opacity', 0.99); } //static initialization dl.swap=function() { var list = dl.list('img[data-swapsrc]'); for(var i in list) dl.swapsrc('swap.'+i, list[i]); } /* image zoom class */ dl.zoom=function(id){ if(!id) return false; //no element to zoom if(!(this instanceof dl.zoom)) return new dl.zoom(id); this.id = id; this.el = dl.el(this.id); if(!this.el.data('zoomsrc')) return false; //no large image if(this.el.zoom) this.el.zoom.clear(); this.area = this.el.data('zoomarea') ? this.el.data('zoomarea') : 'image';//'image','fixed' if (this.area == 'fixed'){ dl.el(this.el.parentNode).add('fixed'); this.area = { type: 'fixed', t: '0', l: '0', w: this.el.parentNode.offsetWidth, h: this.el.parentNode.offsetHeight, }; } else if (this.area == 'image'){ this.area = { type: 'image', t: this.el.offsetTop+'px', l: this.el.offsetLeft+'px', w: this.el.offsetWidth, h: this.el.offsetHeight, }; } this.cont = dl.el(id+'.cont', { cls: 'zoom', css: { 'z-index': 10, 'opacity': 90, position: 'absolute', overflow: 'hidden', top: this.area.t, left: this.area.l, width: this.area.w, height: this.area.h, }, parent: this.el.parentNode }); this.cont.remove('active'); this.mover = dl.el(this.id+'.mover', { id : this.id+'.mover', tag: 'IMG', src: this.el.data('zoomsrc'), cls: 'zoom', css: { position: 'absolute', opacity: 0.01, transition: 'opacity 600ms ease', }, parent: this.cont, }); this.mover.on('load', this.init.bind(this)); this.el.zoom = this; } dl.Zoom=dl.zoom.prototype; dl.Zoom.init=function(){ this.k = { x: (this.mover.clientWidth - this.area.w) / this.area.w, y: (this.mover.clientHeight - this.area.h) / this.area.h, } if(this.k.x > 0 && this.k.y > 0) { //makes sense only if the 'bigger' image is actually bigger this.cont.add('active'); if(dl.is.touch) { this.cont.on('touchstart', this.start.bind(this)); this.cont.on('touchend', this.stop.bind(this)); this.cont.on('touchmove', this.move.bind(this)); } else { this.cont.on('mouseover', this.start.bind(this)); this.cont.on('mouseout', this.stop.bind(this)); this.cont.on('mousemove', this.move.bind(this)); } } //trigger enlarge - mss2015-11-12: var self = this; this.cont.on('click', function(){ self.el.click(); }); } dl.Zoom.clear=function(){ this.cont.parentNode.removeChild(this.cont); this.el.zoom = null; } dl.Zoom.start=function(e){ this.mover.css('opacity', 0.99) } dl.Zoom.stop=function(e){ this.mover.css('opacity', 0.01) } dl.Zoom.move=function(e){ e.preventDefault(); var p = this.cont.getBoundingClientRect(); var y = ((e.clientY - p.top) * -this.k.y).toFixed(1); var x = ((e.clientX - p.left) * -this.k.x).toFixed(1); this.mover.css({top: y+'px', left: x+'px'}); } /* image preview class */ dl.preview=function(id){ if(!id) return false; //no element to zoom if(!(this instanceof dl.preview)) return new dl.preview(id); this.id = id; this.el = dl.el(this.id); this.el.on('load', this.transition.bind(this)); this.lyr = null; this.list = dl.list("[data-preview='"+this.id+"']"); for(var i in this.list) { var el = dl.el(this.list[i]); if(this.el.src.indexOf(el.data('previewsrc')) !== -1) el.add('active'); else el.remove('active'); el.on('click', this.set.bind(this, i)); } this.el.preview = this; } dl.Preview=dl.preview.prototype; dl.Preview.set=function(i) { if(this.lyr) return; var el = dl.el(this.list[i]); dl.el(this.el.parentNode).add('loading'); //handle active state of the link for(var i in this.list) dl.el(this.list[i].parentNode).remove('active'); el.parentNode.add('active');//el.add('active'); //clone big image this.lyr = dl.el(this.el.cloneNode(this.el),{ id: '', css: { position: 'absolute', top: '0px', botom: '0px', left: '0px', right: '0px', width: this.el.offsetWidth, height: this.el.offsetHeight, 'margin': 'auto', 'z-index':20 }, parent: this.el.parentNode, }); //change the src this.el.src = el.data('previewsrc'); if(this.el.data('zoomsrc')) { this.el.data('zoomsrc', el.data('zoomsrc')); this.el.zoom = dl.zoom(this.id); //force container update: if(1){//mss2015-11-23 the container should always updates: if (this.el.zoom.area.type == 'image') { var self = this; this.el.on('load',function(){ self.el.zoom = dl.zoom(self.id); if(self.el.area) self.el.zoom.cont.css('height', self.el.area.h); }) } } if(this.el.data('enlarge')) { this.el.data('enlarge', el.data('enlargesrc')); //this.el.enlarge = dl.enlarge(this.id); } } dl.Preview.set_=function(){ this.el.parentNode.removeChild(this.lyr); this.lyr = null; } dl.Preview.transition=function(){ //make transition if (this.lyr){ this.lyr.css('opacity', [1,0], 400); dl.el(this.el.parentNode).remove('loading'); setTimeout(this.set_(), 400);//setTimeout(this.set_.bind(this), 400); } } /* image enlarge class */ dl.enlarge=function(id){ if(!(this instanceof dl.enlarge)) return new dl.enlarge(id); this.id=id||'enlarge'; this.i=false; if(this.init()) this.bind(); } dl.Enlarge=dl.enlarge.prototype; dl.Enlarge.init=function(){ this.cont=dl.el(this.id+'.cont',{cls:'enlarge'}); this.list=dl.list('img[data-'+this.id+']'); this.img=dl.el(this.id+'.img',{tag:'IMG',parent:this.cont}); this.bc=dl.el(this.id+'.hide',{tag:'A',cls:'hide',parent:this.cont}); this.title=dl.el(this.id+'.title',{tag:'H3',parent:this.cont}); if(this.list.length>1) { this.bp=dl.el(this.id+'.prev',{tag:'A',cls:'prev',parent:this.cont}); this.bn=dl.el(this.id+'.next',{tag:'A',cls:'next',parent:this.cont}); } return true; } dl.Enlarge.bind=function(){ this.bc.on('click',this.close.bind(this)); this.img.on('load',this.load.bind(this)); dl.on('resize',this.load.bind(this)); for(var i=this.list.length;i--; dl.el(this.list[i]).on('click',this.open.bind(this,i)).css('cursor','zoom-in') ); if(this.list.length>1) { if(dl.is.touch) { dl.on('wipeLeft',this.prev.bind(this)); dl.on('wipeRight',this.next.bind(this)); } else { this.img.on('click',this.calc.bind(this)); this.cont.on('click',this.close.bind(this)); } this.bp.on('click',this.prev.bind(this)); this.bn.on('click',this.next.bind(this)); } else this.cont.on('click',this.close.bind(this)); } dl.Enlarge.open=function(i, dir){ this.i=i; this.trans(dir); this.img.src=this.list[this.i].dataset[this.id]; dl.el(this.img).css('opacity', 0.1).css('opacity', 0.99, 200); this.cont.add('active'); if(dl.gesture) dl.gesture.block=1; } dl.Enlarge.load=function(){ var el=this.list[this.i]; var im=this.img; //trace('el: ',el) //trace('im: ',im.offsetHeight) if(el&&im) this.title.html(el.alt||el.title). css({left:im.offsetLeft,top:im.offsetHeight+im.offsetTop-70,width:im.offsetWidth}). css('opacity', 0.1).css('opacity', 0.99, 400); } dl.Enlarge.close=function(){ this.i=false; this.img.src='#'; this.cont.remove('active'); if(dl.gesture) dl.gesture.block=0; } dl.Enlarge.prev=function(e){ if(e) e.stopPropagation(); var i=(this.i)? this.i-1:this.list.length-1; this.open(i, 1); } dl.Enlarge.next=function(e){ if(e) e.stopPropagation(); var i=(this.i>=this.list.length-1)? 0:this.i+1; this.open(i, -1); } dl.Enlarge.calc=function(e){ e.stopPropagation(); if((e.pageX-e.target.offsetLeft) < e.target.offsetWidth/4) this.prev(e); else this.next(e); } dl.Enlarge.trans=function(dir){ var im = this.img; if(im.src==''||im.src.indexOf('#')!=-1) return; var img = im.cloneNode(); dl.el(img).css({position:'absolute',left:im.offsetLeft,top:im.offsetTop,width:im.offsetWidth,height:im.offsetHeight}); im.parentNode.appendChild(img); if(dir) dl.el(img).css('left', dir*dl.width(), 400); dl.el(img).css('opacity', 0.01, 400); dl.delay(function(){img.parentNode.removeChild(img)}); } /* lazy image loading */ dl.lazysrc={state:'idle',wait:1000} dl.lazysrc.update=function(){ //trace('dl.dynlist.update: '+this.state); if(this.state == 'idle') this.process(); if(this.state == 'wait') this.state = 'todo'; //not need to do anything if alredy in state 'todo' } dl.lazysrc.process=function(){ //trace('dl.dynlist.process: '+this.state); this.delay(); var list = dl.list('img[data-lazysrc]'); var vh = dl.height(); for(var i in list) { var el = list[i]; if(!el.dataset || !el.dataset.lazysrc) continue; //if in view loads it and removes it from the search var y = el.getBoundingClientRect().top; if(y > -200 && y < vh + 500) { el.src = el.dataset.lazysrc; el.removeAttribute('data-lazysrc'); } } } dl.lazysrc.delay=function(){ this.state = 'wait'; setTimeout(this.ready.bind(this), this.wait); } dl.lazysrc.ready=function(){ if(this.state == 'todo') this.process(); else this.state = 'idle'; } //static execution dl.lazy = function(){ dl.lazysrc.update(); } /* sticky menu */ dl.sticky=function(){ var list = dl.list('[data-sticky]'); for(var i in list) { var el = dl.el(list[i]); var val = el.data('sticky') || el.offsetHeight; if(dl.scroll() > val) el.add('sticky'); else el.remove('sticky'); } } /* fixed aside */ //TODO need to check where these are used dl.filter=function(id, multi){ if(!id) return false; if(typeof id === 'object') { var fld = id.field; var val = id.value; } else { //multi = (typeof multi === 'undefined')?1:multi; //gets the data var el = dl.el(id); var fld = el.data('field'); var val = el.data('value'); if(val == 'checked') val = el.checked? 1 : 0; } //resets the page //dl.hash('page', 0); //gets the hash var hash = dl.l.hash.replace('#', ''); //transforms it to array var list = hash.split('&'); var found = 0; for(var i in list) { var item = list[i]; var arr = item.split('='); if(arr[0] == fld) { //edit found = 1; //need to process the value list var vlist = '|'+arr[1]+'|'; if(vlist.indexOf('|'+val+'|') !== -1) { //found vlist = vlist.replace('|'+val+'|', '|'); el.remove('active'); } else { // not found if(multi) {//multiple filter values vlist += val+'|'; } else {//one filter value vlist = '|'+val+'|'; } if(el) el.add('active'); } list[i] = (vlist.length > 2)? fld+'='+vlist.replace('||','|').substr(1, vlist.length-2) : ''; } } //adds to it if(!found) { list.push(fld+'='+val); if(el) el.add('active'); } //put it back for(i in list) { if(list[i] == "") list.splice(i, 1)} //cleares the empty spaces dl.l.hash = '#' + list.join('&'); } dl.select=function(){} dl.range=function(id){ if(!(this instanceof dl.range)) return new dl.range(id); this.id=id||'range'; this.lim=[],this.btn=[],this.lbl=[],this.pos=[],this.r=[0,100]; if(this.init()) this.bind(); } dl.Range=dl.range.prototype; dl.Range.init=function(){ this.el=dl.el(this.id); this.un=this.el.data('unit')||''; this.pr=this.el.data('precision')||0; this.plot=dl.el(this.id+'.plot',{tag:'SPAN',parent:this.el}) this.bar=dl.el(this.id+'.bar',{tag:'EM',parent:this.plot}) for(var i in [0,1]){ this.lim[i]=dl.el(this.id+'.lim.'+i,{tag:'I',cls:'p'+i,parent:this.el}); this.btn[i]=dl.el(this.id+'.btn.'+i,{tag:'A',parent:this.el}); this.lbl[i]=dl.el(this.id+'.lbl.'+i,{tag:'B',parent:this.el}); } var r=this.el.data('range'); var v=dl.el(this.id+'.value').value; if(!r) r=v? v:'0-100'; if(!v) v=r; this.r=this.in(r); this.v=this.in(v); this.l=this.plot.offsetLeft; this.w=this.plot.offsetWidth; this.b=this.btn[1].offsetWidth; this.k=(this.r[1]-this.r[0])/(this.w-this.b); for(var i in [0,1]) { this.lim[i].html(this.out(this.r[i])); this.set(i,this.v[i]); } return true; } dl.Range.bind=function(){ if(dl.is.touch){ this.el.on("click",this.click.bind(this)); for(i in [0,1]) this.btn[i].on("touchstart",this.down.bind(this)); this.el.on("touchmove",this.move.bind(this)); this.el.on("touchend",this.stop.bind(this)); this.el.on("touchcancel",this.stop.bind(this)); } else { for(i in [0,1]) this.btn[i].on("mousedown",this.down.bind(this)); this.plot.on("click",this.click.bind(this)); this.el.on("mousemove",this.move.bind(this)); this.el.on("mouseup",this.stop.bind(this)); this.el.on("mouseleave",this.stop.bind(this)); this.el.on("dragstart",function(e){e.preventDefault()},false); } } dl.Range.set=function(i,v){ var v=parseFloat(v); if(i==0){ if(vthis.v[1]) v=this.v[1]; } else if(i==1){ if(v>this.r[1]) v=this.r[1]; if(v0? ((v-this.r[0])/this.k+this.l).toFixed(1):this.l; this.btn[i].css('left',this.pos[i]); this.bar.css('left',this.pos[0]-this.l+'px').css('width',this.pos[1]-this.pos[0]+'px'); this.lbl[i].html(this.out(this.v[i])); var l=+this.pos[i]; var l0=+this.lbl[0].offsetLeft; var l1=+this.lbl[1].offsetLeft; var w0=+this.lbl[0].offsetWidth; var w1=+this.lbl[1].offsetWidth; if(i==0){ if(l1 && l>l1-w0) l=l1-w0; if(lthis.w+this.l) l=this.w-w0+this.l; } else if(i==1){ if(lthis.w+this.l) l=this.w-w1+this.l; if(l0+w0>l) this.lbl[0].css('left',l-w0); } this.lbl[i].css('left',l); if(Math.round(this.v[0])==Math.round(this.v[1])) this.lbl[1].hide(); else this.lbl[1].show(); } dl.Range.update=function(){ dl.el(this.id+'.value').value=this.v.join('-'); dl.el('frm').submit(); } dl.Range.down=function(e){ if(e) e.preventDefault(); var el=e.target; var l=(e.screenX||e.pageX)+this.l; if(this.v[0]*1.1>this.v[1]) this.start(this.btn[0],l); else this.start(el,l); } dl.Range.click=function(e){ if(e.changedTouches) e=e.changedTouches[0]; var l=e.layerX+this.b; if(e.target.id==this.id+'.bar') l+=e.target.offsetLeft; var i=(l cr.left && p.x < cr.right && p.y > cr.top && p.y < cr.bottom) return el; } return false; } dl.Sort.place = function(s, d){ if(!s || !d || s.i == d.i) return false; //data not complete if(s.parentNode != d.parentNode) return false; //not in the same container d.parentNode.removeChild(s); if(s.i < d.i) d.parentNode.insertBefore(s, d.nextSibling); else d.parentNode.insertBefore(s, d); this.list = this.el.list('[data-sort-item]'); for(var i in this.list) this.list[i].i = i; } /* google map */ dl.map = {el:null,conf:null} dl.map.load = function(id){ this.id=id; this.el = dl.el(this.id); this.conf = JSON.parse(this.el.data('map')); if(this.conf.url) dl.include(this.conf.url+'&signed_in=true&callback=dl.map.init') } var map; dl.map.init = function(){ var conf = dl.map.conf; var id = dl.map.id || 'map.google'; var lat = +conf.latitude || 40.704214; var lng = +conf.longitude || -73.984794; var zoom= +conf.zoom || 16; var name= conf.name || 'ZipShop.SE'; var text= conf.text || '18th Bridge St, Brooklyn NY, USA'; var icon= conf.icon || ''; //map var center = new google.maps.LatLng(lat, lng); var mapOptions = { zoom: zoom, center: center, }; map = new google.maps.Map(dl.el(id), mapOptions); //markers var marker = new google.maps.Marker({ position: new google.maps.LatLng(lat, lng), map: map, title: name, icon: icon, }); //info window var infowindow = new google.maps.InfoWindow({ content: text, }); google.maps.event.addListener(marker, 'click', function() { infowindow.open(map, marker); }); } /*2016-03-25mss from zipshop.js: authentication handling class*/ dl.login={id:'', active:false, timer:null} dl.login.open = function(id, frm){ this.id = id || 'login'; if(this.active) this.close(); else { if(this.timer) clearTimeout(this.timer); dl.el(this.id).load('login.ajax.php?action=login&langId='+dl.el(this.id).data('lang')).show(); this.active = true; } /* if(dl.is.el('forgot.btn')){ dl.el('forgot.btn').on('click', dl.el('recover').load('recover.ajax.php').show() ); } */ } dl.login.submit = function(){ var frm = dl.el(this.id+'.frm'); if(!dl.el('login.username').val() || !dl.el('login.password').val()) { dl.el('login.err').show(); return false; } var btn = dl.el('login.btn'); btn.data('text', btn.textContent); dl.el('login.btn').html(btn.data('loading')).css('opacity', 0.5); dl.el('login.err').hide(); dl.submit(new FormData(frm), 'login.ajax.php?action=login&langId='+dl.el('login').data('lang'), function(data){ dl.el('login').html(data); if(dl.is.el('login.mess')) this.timer = setTimeout(function(){dl.l.href=dl.l.href}, 1000); }) } dl.login.register = function(){ var frm = dl.el('register.frm'); if(!dl.el('register.username').val() || !dl.el('register.password').val()) { //trace(dl.el('register.err')) dl.el('register.err').show(); return false; } var btn = dl.el('register.btn'); btn.data('text', btn.textContent); dl.el('register.btn').html(btn.data('sending')).css('opacity', 0.5); dl.el('register.err').hide(); dl.el('loading').add('message'); dl.submit(new FormData(frm), 'register.ajax.php?langId='+dl.el('register').attr('data-lang'), function(data){ dl.el('register').html(data); if(dl.is.el('register.mess') || dl.is.el('register.err')) this.timer = setTimeout(function(){ dl.l.href=dl.l.href }, 5000); }) } dl.login.recover = function(){ var frm = dl.el('recover.frm'); if(!dl.el('recover.username').val()) { dl.el('recover.err').show(); return false; } var btn = dl.el('recover.btn'); btn.data('text', btn.textContent); dl.el('recover.btn').html(btn.data('sending')).css('opacity', 0.5); dl.el('recover.err').hide(); dl.el('recover.loading').add('message'); dl.submit(new FormData(frm), 'recover.ajax.php?langId='+dl.el('recover').attr('data-lang'), function(data){ dl.el('recover').html(data); if(dl.is.el('recover.mess')) this.timer = setTimeout(function(){dl.l.href=dl.l.href}, 5000); }) } dl.login.checkout = function(){ dl.login.open('checkout'); //dl.w.scrollTo(0,0); } dl.login.logout = function(){ if(this.active) this.close(); else { if(this.timer) clearTimeout(this.timer); dl.el('logout').load('login.ajax.php?action=logout&langId='+dl.el('logout').data('lang')).show(); this.active = true; this.timer = setTimeout(function(){dl.l.href=dl.l.href}, 1000); } } dl.login.close = function(){ dl.el(this.id).hide(); this.active = false; } /* image gallery class */ //article gallery dl.is.gallery=[]; dl.gallery=function(id){ if(dl.is.gallery[id]) return dl.is.gallery[id]; if(!(this instanceof dl.gallery)) return new dl.gallery(id); this.i = 0; this.id = id; this.list = []; this.state = 10; if(this.init()) this.select(); } dl.Gallery=dl.gallery.prototype; dl.Gallery.init=function(){ var list = dl.el(this.id).list('img[data-dl]'); if(!list.length) return false; for(var i=list.length;i--;) { var el = list[i]; el.id = this.id+'.'+i; this.list[i] = list[i]; } if(dl.is.el(this.id+'.l')) { var cont = dl.el(this.id+'.l'); dl.el(this.id+'.img',{tag:'IMG',parent:cont}); dl.el(this.id+'.hide',{tag:'A',cls:'hide',parent:cont}); if(list.length > 1){ dl.el(this.id+'.prev',{tag:'A',cls:'prev',parent:cont}); dl.el(this.id+'.next',{tag:'A',cls:'next',parent:cont}); } } this.state = 20; return this.bind(); } dl.Gallery.bind=function(){ if(!this.list.length) return; for(var i=this.list.length;i--;) dl.el(this.id+'.'+i).on('click', this.select.bind(this, i)); if(dl.is.el(this.id+'.l')) { dl.el(this.id+'.m').on('click', this.open.bind(this)); dl.el(this.id+'.hide').on('click', this.close.bind(this)); if(this.list.length > 1) { if(dl.is.touch) { dl.on('wipeLeft', this.prev.bind(this)); dl.on('wipeRight', this.next.bind(this)); } else { dl.el(this.id+'.img').on('click', this.calc.bind(this)); dl.el(this.id+'.l').on('click', this.close.bind(this)); } dl.el(this.id+'.prev').on('click', this.prev.bind(this)); dl.el(this.id+'.next').on('click', this.next.bind(this)); } else dl.el(this.id+'.l').on('click', this.close.bind(this)); } this.state = 25; return true; } dl.Gallery.select=function(i){ var i = i || 0; if(this.i) { if(this.i == i) return; dl.el(this.id+'.'+this.i).remove('active'); } this.i = i; var src = this.list[this.i]; dl.el(this.id+'.'+this.i).add('active'); if(dl.is.el(this.id+'.m')) dl.el(this.id+'.m').src = src.data('m'); if(dl.is.el(this.id+'.l')) dl.el(this.id+'.img').src = src.data('l'); } dl.Gallery.open=function(){ if(!dl.is.el(this.id+'.l')) return; dl.el(this.id+'.m').hide(); dl.el(this.id+'.l').add('active'); dl.d.addEventListener('keyup', this.key.bind(this)); this.state = 50; } dl.Gallery.calc=function(e){ e.stopPropagation(); if((e.pageX-e.target.offsetLeft) < e.target.offsetWidth/4) this.prev(e); else this.next(e); } dl.Gallery.key=function(e){ if(this.state != 50) return; if(e.key == 'Escape') return this.close(); if(e.key == 'ArrowLeft') return this.prev(); if(e.key == 'ArrowRight') return this.next(); } dl.Gallery.close=function(){ if(!dl.is.el(this.id+'.l')) return; dl.el(this.id+'.m').show(); dl.el(this.id+'.l').remove('active'); this.state = 25; } dl.Gallery.prev=function(e){ if(e) e.stopPropagation(); var i=(this.i)? this.i-1:this.list.length-1; this.select(i); } dl.Gallery.next=function(e){ if(e) e.stopPropagation(); var i=(this.i>=this.list.length-1)? 0:this.i+1; this.select(i); } /* aip.Gallery.bind=function(){ for(var i in this.list) this.list[i].link.on('click', this.set.bind(this, i)); //2015-10-14mss - enlarge instead: this.cont.on('click', this.next.bind(this)); this.nextLink.on('click', this.nextSlide.bind(this) ); this.prevLink.on('click', this.prevSlide.bind(this) ); } aip.Gallery.set=function(id){ if(this.active == id) return true; var el = null; if(this.active !== false) { el = this.list[this.active]; el.link.remove('active'); el.item.remove('active'); } this.active = id; el = this.list[this.active]; el.link.add('active'); el.item.add('active'); //scroll to top of the image var pos = this.el.getBoundingClientRect(); if(pos.top < 0) { dl.w.scrollBy(0, pos.top-50); } } aip.Gallery.next=function(e){ var px = (e.layerX - e.target.offsetLeft)/e.target.offsetWidth; var i = this.active; if(px > 0.3) { i++; if(i >= this.list.length) i = 0; } else { i--; if(i <= 0) i = this.list.length - 1; } this.set(i); } aip.Gallery.nextSlide=function(e){ var i = this.active; if(++i >= this.list.length){ i = 0; } var left = this.list[i].item.offsetLeft; var leftValue = ((this.cont.scrollWidth-left)>this.cont.parentNode.offsetWidth) ? -left+'px' : -this.cont.scrollWidth+this.cont.parentNode.offsetWidth+'px' ; this.cont.css('margin-left',leftValue);//this.cont.parentNode.scrollLeft = el.item.offsetLeft; this.set(i); } aip.Gallery.prevSlide=function(){ var i = this.active; if(--i < 0){ i = this.list.length - 1; } var el = this.list[i]; var left = this.list[i].item.offsetLeft; var leftValue = ((this.cont.scrollWidth-left)>this.cont.parentNode.offsetWidth) ? -left+'px' : -this.cont.scrollWidth+this.cont.parentNode.offsetWidth+'px' ; this.cont.css('margin-left',leftValue);//this.cont.parentNode.scrollLeft = el.item.offsetLeft; this.set(i); } */ /* helpers */ dl.qryadd = function(url, par){ var s = (url.indexOf('?') != -1)? '&' : '?'; var u = url+s+par; return u; } dl.money=function(number, currency) { var number = parseFloat(number) || 0; number = number.toFixed(2); if(currency=='BGN') return number+" лв."; if(currency=='EUR') return "€ "+number.replace('.', ',').replace(/(\d)(?=(\d{3})+\,)/g, '$1.'); if(currency=='USD') return "$ "+number; if(currency=='GBP') return "£ "+number; return number; } /* custom code*/ aip = {is:{}} //product tabs aip.tab=function(id){ if(!(this instanceof aip.tab)) return new aip.tab(id); this.id=id; this.cid=null; this.init(); } aip.Tab=aip.tab.prototype; aip.Tab.init=function(){ this.list = dl.el(this.id).list('[data-tab]'); this.bind(); } aip.Tab.bind=function(){ for(i in this.list) { var el = this.list[i]; dl.el(el).on('click', this.active.bind(this, el.id)); } } aip.Tab.active=function(id){ if(!id) return false; if(this.cid) { if(this.cid == id) return true; dl.el(this.cid).remove('active'); dl.el(this.cid+'.cont').remove('active'); } this.cid = id; dl.el(this.cid).add('active'); dl.el(this.cid+'.cont').add('active'); } //brands scrollHor aip.is.scrollHor=[]; aip.scrollHor=function(id){ if(aip.is.scrollHor[id]) return aip.is.scrollHor[id]; if(!(this instanceof aip.scrollHor)) return new aip.scrollHor(id); this.id = id; this.el = null; this.cont = null; this.list = []; this.prev = null; this.next = null; this.visible = 0; this.scrollable = 0; this.init(); } aip.ScrollHor=aip.scrollHor.prototype; aip.ScrollHor.init=function(){ this.el = dl.el(dl.el(this.id).list('div')[0]); this.cont = dl.el(this.el.list('ul')[0]); this.visible = this.cont.offsetWidth;//this.el.scrollWidth; this.scrollable = this.cont.scrollWidth; if(this.visible>=this.scrollable) return false; var list = this.el.list('[data-item]'); if(!list.length) return false; for(var i = list.length;i--;) { var el = dl.el(list[i]); this.list[i] = el; } //console.log(this.list); this.prev = dl.el(this.el.list('[data-prev]')[0],{ id:'prevSlide', tag: 'a', cls:'prev', parent:this.cont.parentNode}); this.next = dl.el(this.el.list('[data-next]')[0],{ id:'nextSlide', tag: 'a', cls:'next', parent:this.cont.parentNode}); this.bind(); } aip.ScrollHor.bind=function(){ this.prev.on('click', this.scrollPrev.bind(this)).add('inactive'); this.next.on('click', this.scrollNext.bind(this)); } aip.ScrollHor.scrollNext=function(){ var px = -this.visible/2; this.next.remove('inactive'); this.prev.remove('inactive'); for(var i = this.list.length;i--;) { var newMargin = parseInt(this.list[i].css('margin-left')) + px; if (Math.abs(newMargin) > (this.scrollable-this.visible)){ newMargin = -(this.scrollable-this.visible); this.next.add('inactive'); } this.list[i].css({ 'margin-left': newMargin+'px' }); } } aip.ScrollHor.scrollPrev=function(){ var px = this.visible/2; this.prev.remove('inactive'); this.next.remove('inactive'); for(var i = this.list.length;i--;) { var newMargin = parseInt(this.list[i].css('margin-left')) + px; if (Math.abs(newMargin-this.visible) < this.visible){ newMargin = 0; this.prev.add('inactive'); } this.list[i].css({ 'margin-left': newMargin+'px' }); } } /* dl.calendar * peter assenov https://aip.solutions 2001-2017 * 2.4.06 2017-03-06 */ //dependencies if(!dl.o) dl.o = {} if(!dl.o.calendar) dl.o.calendar = {} //configuration if(!dl.c) dl.c = {} if(!dl.c.calendar) dl.c.calendar = { 'en': { sep: '/', err: 'Incorrect date!', b: {prev:'<<', today:'∘', next:'>>'}, lw: ['Mon', 'Tue', 'Web', 'Thu', 'Fri', 'Sat', 'Sun'], lm: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], }, 'bg': { sep: '.', err: 'Невалидна дата!', b: {prev:'<<', today:'∘', next:'>>'}, lw: ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Нд'], lm: ['Януари', 'Февруари', 'Март', 'Април', 'Май', 'Юни', 'Юли', 'Август', 'Септември', 'Октомври', 'Ноември', 'Декември'], } } //calendar class dl.calendar = function(id){ if(dl.o.calendar[id]) return dl.o.calendar[id]; if(!(this instanceof dl.calendar)) return new dl.calendar(id); this.id = id; this.date = new Date(); this.busy = false; this.active = false; if(this.init()){ this.bind(); this.el.attr('type', 'text');//prevents default ui this.el.attr('autocomplete', 'off'); dl.o.calendar[this.id] = this; if(this.el.data('open') == 'always') //auto open this.open(); } } dl.Calendar = dl.calendar.prototype; dl.Calendar.init = function(){ if(!this.id) return false; this.el = dl.el(this.id); this.conf = dl.c.calendar; this.lang = this.el.data('lang') || 'en'; if(this.el.data('min')) this.min = this.parse(this.el.data('min')); else { this.min = new Date(); this.min.setFullYear(this.min.getFullYear() - 10); } if(this.el.data('max')) this.max = this.parse(this.el.data('max')); else { this.max = new Date(); this.max.setFullYear(this.max.getFullYear() + 7); } this.cont = dl.el(this.id+'.cont', {parent:this.el.parentNode, cls:'calendar'}); this.cont.css({left:this.el.offsetLeft, top:+this.el.offsetTop+this.el.offsetHeight}); return true; } dl.Calendar.bind = function(){ this.el.on('click', this.mouse.bind(this)) this.el.on('focus', this.focus.bind(this)) this.el.on('blur', this.focus.bind(this)) this.el.on('keydown', this.key.bind(this)) this.cont.on('click', this.click.bind(this)) this.cont.on('mouseenter', this.mouse.bind(this)) this.cont.on('mouseleave', this.mouse.bind(this)) return true; } dl.Calendar.open = function(){ if(dl.o.calendar.active) dl.o.calendar.active.close(); dl.o.calendar.active = this; this.get(); if(this.render()){ if(!this.el.value) this.set(); this.cont.add('active'); //prevents focus and click events to override each other this.active = true; } } dl.Calendar.close = function(cancel){ dl.o.calendar.active = 0; if(cancel) this.el.value = this.el.data('value') || ''; else this.set(); this.active = false; if(this.el.data('open') != 'always') this.cont.remove('active'); } dl.Calendar.get = function(){ return this.parse(this.el.value); } dl.Calendar.set = function(){ var cnf = this.conf[this.lang]; dl.el(this.id).value = this.output(this.date, cnf.sep); } dl.Calendar.render = function(){ if(!this.date) return false; var id = this.id; var d = [this.date.getDate(), this.date.getMonth(), this.date.getFullYear()]; var cd = new Date(); var c = [cd.getDate(), cd.getMonth(), cd.getFullYear()]; var f = this.create(d[2], d[1], 1); var fd = 1; var fdw = f.getDay() || 7; //Sunday=0 var l = this.create(d[2], d[1]+1, 0); var ld = l.getDate(); var ldw = l.getDay() || 7; //Sunday=0 var cnf = this.conf[this.lang]; //normal calendar var h = []; var pcss = this.outside(d[2],d[1],0)? ' readonly' : ''; var ncss = this.outside(d[2],d[1]+1,1)? ' readonly' : ''; var ycss = (this.min.getFullYear()==this.max.getFullYear())? ' class="readonly"' : ''; var mcss = (ycss && this.min.getMonth()==this.max.getMonth())? ' class="readonly"' : ''; h.push('

'+cnf.lm[d[1]]+''+d[2]+''+cnf.b['prev']+''+cnf.b['today']+''+cnf.b['next']+'

'); h.push('

'+cnf.lw.join('')+'

'); h.push('

'); for(var i=fdw; --i>0; ) h.push(''); for(var i=fd; i<=ld; i++) { var css=[]; if(i==d[0]) css.push('active'); if(i==c[0]&&c[1]==d[1]&&c[2]==d[2]) css.push('current'); if(this.outside(d[2],d[1],i)) css.push('readonly'); h.push(''+i+''); } for(var i=7-ldw; --i>=0;) h.push(''); h.push('

'); //period overlay if(!mcss) { h.push('

'); for(var i=0; i<12; i++) { var css = ['s']; if(i==d[1]) css.push('active'); if(i==c[1]&&c[2]==d[2]) css.push('current'); if(this.outside(d[2],i,1)&&this.outside(d[2],i,30)) css.push('readonly'); h.push(''+cnf.lm[i]+''); } h.push('

'); } if(!ycss) { h.push('

'); for(var i=c[2]; i>= c[2]-17; i--) { var css = ['st']; if(i==d[2]) css.push('active'); if(i==c[2]) css.push('current'); if(this.outside(d[2],1,1)&&this.outside(d[2],12,31)) css.push('readonly'); h.push(''+i+''); } h.push('

'); } this.cont.html(h.join('')); return true; } dl.Calendar.update = function(what){ var _date = [this.date.getDate(), this.date.getMonth(), this.date.getFullYear()]; var _close = false; if(what == 'prev') { this.date.setUTCDate(1); this.date.setUTCMonth(this.date.getUTCMonth()-1); } else if(what == 'next') { this.date.setUTCDate(1); this.date.setUTCMonth(this.date.getUTCMonth()+1); this.date.setUTCDate(this.lday()); } else if(what == 'today') this.date = new Date(); else if(what.indexOf('-') !== -1) { var a = what.split('-'); if(a[0] == this.id+'.d'){ this.date.setDate(a[1]); _close = true; this.close(); } if(a[0] == this.id+'.m') this.date.setMonth(a[1]); else if(a[0] == this.id+'.y') this.date.setYear(a[1]); } if(this.outside(this.date.getFullYear(), this.date.getMonth(), this.date.getDate())) { //restores the original date if the new is out of range if(what=='prev'&&!this.outside(this.date.getFullYear(), this.date.getMonth(), this.lday())) this.date.setDate(this.min.getDate()); else if(what=='next'&&!this.outside(this.date.getFullYear(), this.date.getMonth(), 1)) this.date.setDate(this.min.getDate()); else this.date = this.create(_date[2], _date[1], _date[0]); } this.set(); this.render(); if(_close) this.close(); if(this.el.data('change') && dl.w[this.el.data('change')]) dl.w[this.el.data('change')](); } dl.Calendar.click = function(e){ e.stopPropagation(); e.preventDefault(); this.el.focus(); var id = e.target.id; if(!id) return; if(id == this.id+'.m'){ dl.el(this.id+'.mo').toggle('active'); dl.el(this.id+'.yo').remove('active'); return; } if(id == this.id+'.y'){ dl.el(this.id+'.yo').toggle('active'); dl.el(this.id+'.mo').remove('active'); return; } if(id == this.id+'.prev') return this.update('prev'); if(id == this.id+'.next') return this.update('next'); if(id == this.id+'.today') return this.update('today'); if(id.indexOf('-') !== -1) return this.update(id); } dl.Calendar.focus = function(e){ if(e.type == 'focus') { if(!this.active) { this.busy = true this.open(); } } else if(e.type == 'blur') { if(!this.active) this.close(); } } dl.Calendar.mouse = function(e){ if(e.type == 'mouseenter') this.active = 1; if(e.type == 'mouseleave') this.active = 0; if(e.type == 'click') { if(this.busy) { this.busy = 0; return; } if(!this.cont.has('active')) this.open(); else this.close(); } } dl.Calendar.key = function(e){ if(this.el.value.length == 10) { this.get(); this.render(); } if(e.key == 'Enter') return this.close(); if(e.key == 'Escape') return this.close('cancel'); if(e.key == 'ArrowUp') return this.update('prev'); if(e.key == 'ArrowDown') return this.update('next'); if(e.key == 'Tab') this.active = 0; } dl.Calendar.create = function(y, m, d){return new Date(Date.UTC(y, m, d))} dl.Calendar.parse = function(src){ src = src.toString().trim(); if(src && src.length == 10) { if(src.indexOf('-') != -1) { //iso format var d = src.split('-'); if(d.length == 3) return this.create(d[0], d[1]-1, d[2]); } else { var cnf = this.conf[this.lang]; var d = src.split(cnf.sep); if(d.length == 3) return this.create(d[2], d[1]-1, d[0]); } } //when the field is empty suggest today return new Date(); } dl.Calendar.outside = function(y, m, d){ var id = this.output(this.create(y,m,d)); return (idthis.output(this.max))? true:false; } dl.Calendar.output = function(date, sep){ if(!date) return false; var arr = [('00'+date.getDate()).slice(-2), ('00'+(date.getMonth()+1)).slice(-2), date.getFullYear()]; return (sep)? arr.join(sep) : [arr[2], arr[1], arr[0]].join("-") } dl.Calendar.lday = function(){return (this.create(this.date.getYear(), this.date.getMonth()+1,0)).getDate()} /* dl.ext - experimental functionality */ //carousel// let gap =1; const carousel = document.getElementById("carousel"), content = document.getElementById("content"), nextt = document.getElementById("nextt"), preview = document.getElementById("preview"); nextt.addEventListener("click", e => { carousel.scrollBy(gap+205, 0); if (carousel.scrollWidth !== 5) { preview.style.display = "block"; } }); preview.addEventListener("click", e => { carousel.scrollBy(-(205 + gap), 0); if (carousel.scrollLeft - gap <= 205) { preview.style.display = "none"; } // if (!content.scrollWidth - width - gap <= carousel.scrollLeft + width) { // next.style.display = "block"; // } }); let width = carousel.offsetWidth; window.addEventListener("resize", e => (width = carousel.offsetWidth)); if (carousel.scrollWidth <= width - carousel.scrollLeft ) { nextt.style.display = "none"; } // function autoPlay(){ // timer = setTimeout(function(e){ // carousel.scrollBy(gap+205, 0); // if (carousel.scrollWidth !== 5) { // gap++; // for (var j = 0; j < carousel.scrollWidth; j++) { // gap + [j]; // preview.style.display = "block"; // carousel.onmouseover = clearTimeout(timer); // } // console.log(gap); // clearTimeout(timer); // } // // autoPlay(); // }, 2000); // } // autoPlay(); //end of code, enjoy...