function postFeedback(){ var data={}; var errors=[]; $("[field]").each(function(){ var fld=$(this).attr("field"); var v=validateField($(this)); if(v===false){ console.log("BAD ["+fld+"]=",v); errors.push(fld); } else { if(v){ data[fld]=v; } } }); var detail=getDetail(); data.feedback=detail.feedback || {}; data.comments=detail.comments || {}; $("#datadebug").html(JSON.stringify(data,null,2)); if(errors.length){ $("#formStatus").attr("status","error").html(errors.length+" câmpuri cu erori de completare! ("+errors.join(", ")+")"); //alert(errors.join("\n")); } else { $("#formStatus").attr("status","success").html("Se transmit datele..."); //$("#sendfbk > actions").hide(); $.post("?action=feedback",{feedback:data},function(res){ console.log(res); if(res.indexOf("ERROR")>-1){ $("#formStatus").attr("status","error").html(res); $("#sendfbk > actions").fadeIn(); } else if(res.indexOf("SUCCESS")>-1){ $("#formStatus").attr("status","success").html(res); gtag_report_conversion(); fbq('track', 'SubmitLead', {currency: "RON", value: 10.00}); setTimeout(function(){ location.href='?done'; },2000); } else { gtag_report_conversion(); fbq('track', 'SubmitLead', {currency: "RON", value: 10.00}); $("#formStatus").attr("status","success").html("Multumim!"); setTimeout(function(){ location.href='?done'; },2000); } }).fail(function(){ $("#formStatus").attr("status","error").html("Eroare de comunicare cu serverul. Mai încearcă..."); $("#sendfbk > actions").fadeIn(); }); //alert("OK!"); } } function getDetail(elem){ elem = elem || "#browse scroller"; var data={}; var comments={}; var art=0; var p=0; var item=0; var k="law"; $(elem).find("art,p,item").each(function(){ if($(this).is("art")){ art++; p=0; item=0; k=art; } else if($(this).is("p")){ p++; item=0; k=art+"."+p; } else if($(this).is("item")){ item++; k=art+"."+p+"-"+item; } else { } var v=$(this).attr("feedback"); var c=$(this).attr("comment"); if(v && v.trim().length) data[k]=v; if(c && c.trim().length) comments[k]=c; }); return {feedback:data, comments:comments}; } function notify(msg){ var timer=3000; if(!$("notifications").length){ $("").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 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){ $("*[on=mobile]").show(); $("*[on=desktop]").hide(); } else { $("*[on=desktop]").show(); $("*[on=mobile]").hide(); } $("input,select,textarea").change(function(){ validateField($(this)); }); $("checkbox").each(function(){ $(this).find("a").click(function(e){ e.stopPropagation(); }); var elm=$(this); var prc=function(){ if(elm.is("[checked]")){ elm.removeAttr("checked"); elm.attr("value",""); } else { elm.attr("checked",1); elm.attr("value","yes"); } console.log("chkbox",validateField($(this))); } $(this).unbind("click").click(prc); }); /* $("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; } }); } $(document).ready(function(){ /* 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.play(); } playMovie(); vid.addEventListener('ended',playMovie,false); */ function closeFbk(callback){ $("#itemfbk").removeClass("open"); $("#itemfbk").parent().removeClass("active"); setTimeout(function(){ $("#itemfbk").insertAfter("#browse"); if(typeof callback=='function') callback(); },200); } $("#itemfbk").click(function(e){ e.stopPropagation(); }); $("#itemfbk .close").click(function(){ closeFbk(); }); $("body").click(function(e){ closeFbk(); }); $("#browse scroller").click(function(e){ e.stopPropagation(); }); $("#browse scroller").find("p,item").each(function(){ $(this).hover(function(e){ e.stopPropagation(); $(this).addClass("hover"); $("#browse").find(".hover").not($(this)).removeClass("hover"); }); $(this).click(function(e){ e.stopPropagation(); $(this).toggleClass("active"); var elem=$(this); var fbk=$(this).attr("feedback"); var comm=$(this).attr("comment"); if($(this).is(".active")){ var elem=$(this); closeFbk(function(){ $("#itemfbk").appendTo(elem); // init editor $("#itemfbk textarea").unbind("change").val(comm).change(function(){ var v=$(this).val(); if(v.trim().length){ elem.attr("comment",$(this).val());} else { elem.removeAttr("comment"); } }); $("#itemfbk select").unbind("change").val(fbk).change(function(){ var v=$(this).val(); if(v.trim().length){ elem.attr("feedback",$(this).val());} else { elem.removeAttr("feedback"); } }); // end init setTimeout(function(){ $("#itemfbk").addClass("open"); },100); }); } else { closeFbk(); } $("#browse").find(".active").not($(this)).removeClass("active"); }); }); var vid=document.getElementById("bgvideo"); $("#overlay,intro").click(function(){ if (vid.paused){ vid.play(); } else { vid.pause(); } }); $("logo,footer").click(function(){ if(window.pageYOffset>0){ $("body").animate({scrollTop:0},1000); } else { window.location.href="?"; } }); $("intro img").click(function(e){ e.stopPropagation(); location.href="?"; }); ux(); });