function _getLayout(){ var x=$(document).width(); var y=$(document).height(); var l=(x/y>3/2 ? "wide" : (x/y<2/3 ? "tall":"square")); console.log(x,y); if(l!=window.currentLayout){ window.currentLayout=l; $("body").attr("layout", window.currentLayout); _log("layout changed = ",l) } return window.currentLayout; } var getTouch=function(e){ if(e.type == 'touchstart' || e.type == 'touchmove' || e.type == 'touchend' || e.type == 'touchcancel'){ var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0]; x = touch.pageX; y = touch.pageY; } else if (e.type == 'mousedown' || e.type == 'mouseup' || e.type == 'mousemove' || e.type == 'mouseover'|| e.type=='mouseout' || e.type=='mouseenter' || e.type=='mouseleave') { x = e.clientX; y = e.clientY; } return {x:x,y:y}; } var determineVis=function(){ var elm=$("main"); elm.children().removeAttr("visible").each(function(){ var mypos=$(this).offset().left-elm.offset().left; var mywidth=$(this).outerWidth(); var myleft=mypos; var myright=mypos+mywidth; var myvis=(myleft+mywidth>mywidth*.5 && myleft+mywidth*.5").appendTo("body"); } var notifications=$("body > notifications"); var notif=$(""+msg+""); notif.hide().appendTo(notifications).fadeIn(); notif.find("a.close").click(function(){ notif.fadeOut(); setTimeout(function(){ notif.remove() },1000); }); setTimeout(function(){ notif.find("a.close").click(); },timer); } function scrollSlider(elm,dir,auto){ auto=auto || false; dir=dir || 1; var crtx=elm.scrollLeft(); var more=elm.children().first().outerWidth(); var x=crtx+dir*more; console.log(crtx,elm.innerWidth()); if(x>elm.innerWidth() || crtx>=elm.innerWidth()) x=0; elm.animate({scrollLeft:x},500); if(auto){ clearTimeout(window.timers[elm.attr("id")]); window.timers[elm.attr("id")]=setTimeout(function(){ scrollSlider(elm,dir,auto); },auto); } } function _log(x,y,z){ console.log(x,y,z); } function validateField(elm){ var val=$(elm).val() || $(elm).attr("value") || null; if(typeof val=="string" && val.trim()=="") val=null; if($(elm).is("[required]") || $(elm).closest("element").is("[required]")){ if(val){ $(elm).closest("element").removeClass("error"); return val; } else { $(elm).closest("element").addClass("error"); return false; } } else { console.log("not req",elm,val); return val; } return true; } function ux(){ if(navigator.share){ $("*[device=mobile]").show(); $("*[device=desktop]").hide(); } else { $("*[device=desktop]").show(); $("*[device=mobile]").hide(); } $("button,.button,input,select,textarea,#features").click(function(e){ e.stopPropagation(); }); $("input,select,textarea").change(function(){ validateField($(this)); }); $("checkbox").each(function(){ $(this).find("a").click(function(e){ e.stopPropagation(); }); $(this).unbind("click").click(function(){ if($(this).is("[checked]")){ $(this).removeAttr("checked"); $(this).attr("value",""); } else { $(this).attr("checked",1); $(this).attr("value","yes"); } console.log("chkbox",validateField($(this))); }); }); $("body[layout=tall]").unbind("touchmove touchstart touchend").on("touchmove",function(e){ if(window.currentLayout!="wide"){ var pos=getTouch(e); var dist=clickX - pos.x; var k=10;//$("main").outerWidth()*.05; if(dist>k || dist.5) $(this).animate({scrollLeft:itw*Math.floor(1+sc/itw)},300); }); */ $("feedback ratings").children().click(function(){ $(this).addClass("selected").siblings().removeClass("selected"); var val=$(this).closest("[value]").attr("value"); var item=$(this).closest("[item]").attr("item") || null; if(item && val){ console.log("sending FBK",item,val); $.post("?action=feedback",{feedback:{item:item,rating:val}},function(res){ console.log(res); }).fail(function(){ alert("Something went wrong"); }); } else { console.log("FBK for what? ",item,val); } }); $("#sendfeedback button[action=send]").click(function(){ //alert("sending message..."); var data={user:{},feedback:{}}; var errors=[]; ['user','feedback'].forEach(function(k){ $("#sendfeedback").find("["+k+"]").each(function(){ data[k]=data[k] || {}; var v=validateField($(this)); var fld=$(this).attr(k); if(v===false){ console.log("BAD ["+k+"."+fld+"]=",v); errors.push(fld); } else { if(v){ data[k][fld]=v; } } }); }); data.feedback.item=$("#sendfeedback").closest("[item]").attr("item"); console.log("errors",data,errors); if(errors.length){ console.log("UNABLE to message",data); } else { console.log("OK to send message",data); $.post("?action=feedback",data,function(res){ alert(res); if(res.indexOf("ERROR")>-1){ } else { $("#sendfeedback [feedback]").val(""); $("#sendfeedback,#sendfeedbackbtn").toggle(); } }).fail(function(){ alert("Error!"); }); } // $("#sendfeedback,#sendfeedbackbtn").toggle(); }); $("button[share]").click(function(){ var media=$(this).attr("share"); var tx=""; tx=$("main p,main h2,main h3").first().text().replace(/\n/g," ")+"[...]"; var url=window.location.href; var title=document.title; var text=($("meta[name=description]").attr("content") || "")+"\n"; var item=$("body").attr("item"); switch(media){ case "facebook": //window.location.href="https://www.facebook.com/sharer/sharer.php?u="+encodeURIComponent(url)+"&t="+encodeURIComponent(title); window.open("https://www.facebook.com/sharer/sharer.php?u="+encodeURIComponent(url)+"&t="+encodeURIComponent(title),"","menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600"); break; case "twitter": window.open("https://twitter.com/share?url="+encodeURIComponent(url)+"&text="+encodeURIComponent(title),"","menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600");break; case "linkedin": window.open("http://www.linkedin.com/shareArticle?mini=true&url="+encodeURIComponent(url)+"&title="+encodeURIComponent(title)+"&summary="+encodeURIComponent(tx),"","menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600");break; case "whatsapp": window.location.href="https://api.whatsapp.com/send?text="+encodeURIComponent("*" + title + "*:\n\n" + tx + "\n\n"+ url); //window.open("https://api.whatsapp.com/send?text="+encodeURIComponent("*" + title + "*:\n\n" + tx + "\n\n"+ url),"","menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600"); break; case "mobile": if (navigator.share) { navigator.share({ title: title, url:url,text:text}) .then(() => { var data={share:{item:item}}; $.post("?action=share",data,function(res){ notify(res); }).fail(function(){ }); }) .catch(console.error); } else { console.log("function is not available"); } break; case "email": alert("Functionalitate disponibila in curand"); /* var recipients=prompt("Email addresses?","mihai.popescu@gmail.com, costel@site.ro,..."); var item=url; if(recipients.trim().length){ $.post("?action=share",{share:{recipients:recipients, item:}}) } */ break; default: break; } }); /* asc */ $("button[window],.button[window]").click(function(){ window.open($(this).attr("window")); }); $("button[url],.button[url]").click(function(){ window.location.href($(this).attr("url")); }); $("*[display=tabs],*[display=slideshow],*[display=cards]").each(function(){ var elm=$(this); if(elm.is("[enabled]")) return; elm.attr("enabled",true); var navholder=elm.children("nav").length ? elm.children("nav").length : $(""); var nav=navholder.children("wrap").first(); elm.children().not("nav").each(function(){ var lbl=$(this).attr("label") || $(this).attr("title") || false; if(!lbl) lbl=($(this).find("label,h2,h3").length ? $(this).find("label,h2,h3").first().text() : "?"); var tab=$(this); $(""+lbl+"").appendTo(nav).click(function(){ clearTimeout(window.cyclefntimer); $(this).addClass("selected").siblings().removeClass("selected"); tab.addClass("active").siblings().not("nav").removeClass("active"); tab.attr("status","active").siblings().not("nav").attr("status","inactive"); if(elm.is("[display=slideshow]")) window.cyclefntimer=setTimeout(cyclefn,10000); }); }); navholder.prependTo(elm); nav.children().first().click(); var nextfn=function(){ var nxt=nav.find(".selected").next(); if(!nxt.length) nxt=nav.children().first(); nxt.click(); } var prevfn=function(){ var prv=nav.find(".selected").prev(); if(!prv.length) prv=nav.children().last(); prv.click(); } var cyclefn=function(){ nextfn(); //window.cyclefntimer=setTimeout(cyclefn,10000); } clearTimeout(window.cyclefntimer); if(elm.is("[display=slideshow]")){ window.cyclefntimer=setTimeout(cyclefn,10000); } }); $("slider[autoscroll]").each(function(){ var elm=$(this); elm.attr("id",elm.attr("id") || "sld"+Math.floor(Math.random()*1000000)); window.timers=window.timers || {}; window.timers[elm.attr("id")]=window.timers[elm.attr("id")] || null; clearTimeout(window.timers[elm.attr("id")]); elm.hover(function(){ clearTimeout(window.timers[elm.attr("id")]);}, function(){ window.timers[elm.attr("id")]=setTimeout(function(){ scrollSlider(elm,1,3000); },5000); }); window.timers[elm.attr("id")]=setTimeout(function(){ scrollSlider(elm,1,3000); },5000); }); $("iframe[src*=youtube]").each(function(){ var h=$("

"); h.insertBefore($(this)); $(this).appendTo(h); }); $("slideshow").each(function(){ var ss=$(this); ss.attr("id",ss.attr("id") || "ss"+Math.floor(Math.random()*1000000) ); var sel=$(""); sel.prependTo(ss); ss.children().not("selector,.mgmt,.hidden").each(function(){ var elm=$(this); elm.addClass("item"); var btn=$(""+(elm.attr("title") || "??")+""); btn.appendTo(sel).click(function(){ $(this).addClass("active").siblings().removeClass("active"); elm.addClass("active").siblings().removeClass("active"); var vid=elm.children("video").first(); elm.siblings().find("video").each(function(){ var v=$(this)[0]; v.pause(); }); clearTimeout(window.timers[ss.attr("id")]); if(vid.length){ setTimeout(function(){ vid[0].play(); },500); //vid[0].onclick=function(){ if(vid[0].paused){ vid[0].play(); } else { vid[0].pause(); } } } }); }); var wait=10000; var nxt=function(){ var n=sel.find(".item.active").next(".item"); clearTimeout(window.timers[ss.attr("id")]); if(n.length){ n.click(); } else { sel.children().first().click(); } window.timers[ss.attr("id")]=setTimeout(nxt,wait); } var prv=function(){ var n=sel.find(".item.active").siblings(".item").prev(); if(n.length){ n.click(); } else { sel.children().last().click(); } } ss.hover(function(){ clearTimeout(window.timers[ss.attr("id")]); }, function(){ clearTimeout(window.timers[ss.attr("id")]); window.timers[ss.attr("id")]=setTimeout(nxt,wait); } ); sel.children().first().click(); setTimeout(function(){ window.timers[ss.attr("id")]=setTimeout(nxt,wait); },500); }); $("banner").click(function(){ var vid=$(this).children("video"); if(vid.length){ vid=vid[0]; if(vid.paused){ vid.play(); } else { vid.pause(); } } }); $("video").click(function(){ var vid=$(this)[0]; console.log("aaa",vid.paused); if(vid.paused){ vid.play(); } else { vid.pause(); } }); $("span.nr").not("[processed]").each(function(){ $(this).attr("processed",true); var val=$(this).text() || "?"; val=val.replace(/\,/,"").replace(/([0-9\.]+)/,"$1"); $(this).html(val); var elm=$(this).find("nr").length ? $(this).find("nr").first() : $(this); var nr=elm.text(); //var incr=parseFloat(nr)/200; var isDeci=nr.indexOf(".")>-1 ? true : false; val=parseFloat(nr); elm.html(isDeci ? "0.0":"0"); var incr=function(){ var v=parseFloat(elm.text()); var nv=v*1.05+val*0.01+(isDeci ? 0.1 : 1); var nv=isDeci ? Math.floor(nv*10)/10 : Math.floor(nv); //console.log(v,nv); if(v"); modal.appendTo("body"); } modal.fadeIn(); var modalBox=$("#modalBox"); modalBox.addClass("loading").html("loading..."); modalBox.click(function(e){ e.stopPropagation(); }); $("main,top").addClass("blur"); modal.click(function(e){ modal.fadeOut(); $("main,top").removeClass("blur"); setTimeout(function(){ modalBox.html(""); },200); }); modalBox.load(url,function(){ modalBox.removeClass("loading"); var acts=$("
"); acts.appendTo(modalBox); $("✖ inchide").appendTo(acts).click(function(){ modal.click(); }); if(elm.next("[modal]").length){ var nxt=elm.next("[modal]").first(); $("").appendTo(acts).click(function(){ nxt.click(); }); } if(elm.prev("[modal]").length){ var prv=elm.prev("[modal]").first(); $("").prependTo(acts).click(function(){ prv.click(); }); } ux(); }); }); $("player").each(function(){ if($(this).is("[processed]")) return; $(this).attr("processed",true); var player=$(this); var playlist=$(this).children("playlist"); var viewer=$(this).children("viewer"); playlist.find("[url]").unbind("click").click(function(e){ e.preventDefault(); $(this).addClass("selected").siblings().removeClass("selected"); var url=$(this).attr("url"); viewer.load(url+" page",function(){ console.log("loaded!",url); ux(); }); }); if(player.attr("autoplay") || playlist.attr("autoplay")) playlist.find("[url]").first().click(); }); /* $("*[url]").click(function(){ if(window.location.href!=$(this).attr("url")) window.location.href=$(this).attr("url"); }); */ $("*[video]").unbind("click").click(function(){ var $video=null; var btn=$(this); ["box","wrap","article","#modal","#video","content"].forEach(function(k){ var elm=btn.closest(""+k); if(elm.length){ //console.log("searching for video tag in ["+k+"]",elm); if(!$video && elm.find("video").length){ console.log("found player in ["+k+"]"); $video=elm.find("video").first(); } } }); if(!$video){ alert("no video player?"); return; } if(!btn.hasClass("active")){ $("video").not("banner > video").each(function(){ $(this)[0].pause(); }); $("*[video]").removeClass("active"); btn.addClass("active"); console.log("playing",$(this).attr("video"),"into:",$video); //videoSrc = $('source', $video).attr('src', $(this).attr("src")); $video.fadeIn(); $video[0].src=$(this).attr("video"); $video[0].load(); $video[0].play(); if($video.closest("#modal").length){ $video.closest("#modal").animate({scrollTop:$video.position().top-100},1000); } else { $("html,body").animate({scrollTop:$video.offset().top-$("top").outerHeight()-100},1000); } } else { console.log("stopping",$(this).attr("video")); btn.removeClass("active"); $video[0].pause(); } }); $("input[filter]").each(function(){ $(this).click(function(){ $(this).select(); }); var dataset=$("#"+$(this).attr("filter")); $(this).keyup(function(){ var q=($(this).val() || "").toLowerCase().trim().split(" "); var visible=0; if(q.length){ dataset.find("tr,li,box").each(function(){ var fnd=0; var elm=$(this).text().toLowerCase(); q.forEach(function(k){ if(elm.indexOf(k)>-1){ fnd++; } }); if(fnd==q.length){ visible++; $(this).show(); } else { $(this).hide(); } }); } if(visible){ dataset.find("empty").remove(); } else { if(!dataset.find("empty").length) $("Nothing found.").appendTo(dataset); } }); }); $("icon[src],visual[src],picture[src]").not("[processed]").each(function(){ $(this).attr("processed",true); var pls=($(this).attr("src") || "").split(",").filter(function(k){ return k.trim().length; }); //console.log(pls); if(pls.length){ var url=pls[0]; var type="image"; if(url.indexOf("=")>-1){ var type=url.split("=")[0]; url=url.split("=")[1]; } if(type=="video"){ $(this).html(""); } else { $(this).css("background-image","url("+url+")"); } if(pls.length>1){ } } else { $(this).hide(); } }); } $(document).ready(function(){ /* before */ var vid=document.getElementById("bgvideo"); var list=($("#bgvideo").attr("playlist") || "").split(","); var crt=0; function playMovie(x){ if(crt>=list.length) crt=0; crt++; //alert(crt); //vid.src="_themes/default/assets/video/"+list[crt-1]; vid.src=list[crt-1]; vid.play(); } playMovie(); vid.addEventListener('ended',playMovie,false); $("main").click(function(e){ e.stopPropagation(); if (vid.paused){ vid.play(); } else { vid.pause(); } }); $("logo,#goup").click(function(e){ if(window.pageYOffset>0){ e.preventDefault(); $("body").animate({scrollTop:0},1000); } else { return true; } }); $("intro img").click(function(e){ e.stopPropagation(); location.href="?"; }); /* asc */ window.timers=window.timers || {}; function arrange(){ //$("main").css("marginTop",$("banner").outerHeight()-10); } arrange(); window.onresize=arrange; $("#goup").css("top",$("top").outerHeight()); var nav=$("").insertAfter("main"); var elms=$("main").children(); $("").appendTo(nav).click(function(){ var nx=$("main").children("[visible=yes]").first().next(); if(nx.length){ $("main").animate({scrollLeft:nx.index()*$("main").outerWidth()},300); } else { //$(this).fadeOut(); } }); $("").prependTo(nav).click(function(){ var nx=$("main").children("[visible=yes]").first().prev(); if(nx.length){ $("main").animate({scrollLeft:nx.index()*$("main").outerWidth()},300); } else { //$(this).fadeOut(); } }); _getLayout(); $(window).resize(function(){ _getLayout(); }).resize(); ux(); });