﻿$(function(){function b(){for(var G=0;G<s.getObjects().length;++G)if("img"==s.item(G).id){s.remove(s.item(G));break}}function d(G){b();var H=[];fabric.loadSVGFromURL(G,function(){var K=s.getWidth()/2,L=s.getHeight()/2,M=new fabric.Group(H);M.scale(q);var N=M.getHeight()/2,O=M.getWidth()/2;M.set({left:K-O}),M.set({top:L-N}),M.set({id:"img"}),s.add(M),s.renderAll(),s.sendToBack(M)},function(I,J){J.set("id",I.getAttribute("id")),H.push(J)})}function g(G){if(m.setHeight(m.getHeight()*G),m.setWidth(m.getWidth()*G),m.backgroundImage){var H=m.backgroundImage;H.width*=G,H.height*=G}var I=m.getObjects();for(var J in I){var K=I[J].scaleX,L=I[J].scaleY,M=I[J].left,N=I[J].top;I[J].scaleX=K*G,I[J].scaleY=L*G,I[J].left=M*G,I[J].top=N*G,I[J].setCoords()}m.renderAll(),m.calcOffset()}var j=document.getElementById("canvasbox").offsetWidth;j-=10;var k=500,m=document.getElementById("display");m.width=j,m.height=k,height2=k-25,$(".panel1, .panel3, panel4").height(height2),$("#finish").height($("#contedit").height()).width($("#canvasbox").width());var n="90",p="40",q=0.6;if(1e3>=j)var n="80",p="40",q=0.6;if(800>=j)var n="70",p="30",q=0.4;if(700>=j)var n="55",p="30",q=0.35;if(600>=j)var n="55",p="30",q=0.3;if(500>=j)var n="50",p="30",q=0.3;if(400>=j)var n="30",p="20",q=0.3;""==comp&&(comp="Your Company"),""==tipe&&(tipe="BullpenItalic"),""==col&&(col="000000");var s=this.__canvas=new fabric.Canvas("display"),m=new fabric.Canvas("canvas2"),u=new fabric.Text(comp,{fontFamily:tipe,lineHeight:1.2,fontSize:n,textAlign:"center",id:"title"});s.centerObject(u);var v=s.getHeight()/2;u.set({top:v+10}),s.add(u),s.bringForward(u);var u=new fabric.Text("Your Slogan",{fontFamily:"Century Gothic",fontSize:p,lineHeight:1.2,top:s.getHeight()/2+160});u.id="claim",s.centerObject(u);var x=s.item(0).getHeight(),v=s.getHeight()/2;u.set({top:v+(x+20)}),s.add(u),s.bringForward(u),document.getElementById("text1").onkeyup=function(){var G=s.getActiveObject();G&&(G.setText(this.value),s.renderAll())},$("#color").simpleColorPicker({onChangeColor:function(G){var H=s.getActiveObject();if(H&&"text"===s.getActiveObject().get("type")){H.setColor(G);showEffect:"fade",s.renderAll()}}}),$(".fontsel").click(function(){var G=$(this).text();$("#text-font").val(G),$("#text-font").css("font-family",G);var H=document.getElementById("text-font").value;s.getActiveObject().set("fontFamily",H),s.renderAll(),$("#fontbox").slideToggle(500),$("#text-font").css({background:"url("+baseurl+"/img/m13.png)no-repeat right 7px center #fff;"})}),document.getElementById("text-norm").onclick=function(){s.getActiveObject().set("fontWeight","normal"),s.renderAll()},document.getElementById("text-bold").onclick=function(){s.getActiveObject().set("fontWeight","bold"),s.renderAll()},document.getElementById("text-ital").onclick=function(){s.getActiveObject().set("fontWeight","italic"),s.renderAll()},$(".lineheight").click(function(){var G=document.getElementById("line-height").value;s.getActiveObject().set("lineHeight",G),s.renderAll()}),document.getElementById("align-right").onclick=function(){s.getActiveObject().set("textAlign","right"),s.renderAll()},document.getElementById("align-left").onclick=function(){s.getActiveObject().set("textAlign","left"),s.renderAll()},document.getElementById("align-center").onclick=function(){s.getActiveObject().set("textAlign","center"),s.renderAll()},document.getElementById("avanti").onclick=function(){var G=s.getActiveObject();G&&(s.bringToFront(G),s.renderAll(),$("#avanti").css("display","none"),$("#indietro").css("display","block"))},document.getElementById("indietro").onclick=function(){var G=s.getActiveObject();G&&(s.sendToBack(G),s.renderAll(),$("#avanti").css("display","block"),$("#indietro").css("display","none"))};var z={color:"rgba(0,0,0,0.6)",blur:8,offsetX:4,offsetY:4,opacity:0.4,fillShadow:!0,strokeShadow:!0},A={color:"rgba(0,0,0,0.6)",blur:0,offsetX:0,offsetY:0,opacity:0,fillShadow:!1,strokeShadow:!1};document.getElementById("shadow").onclick=function(){var G=s.getActiveObject();G&&(G.shadow&&0!=G.shadow?(G.setShadow(A),G.shadow=0,$("#shadow").css({background:"",opacity:"0.5"})):(G.setShadow(z),$("#shadow").css({background:"#fff",opacity:"1.0"})),s.renderAll())},document.getElementById("rottincu").onclick=function(){"example.png"==$("#newimg").text()?($("#moment").fadeIn(),timedMsg()):$("#finish").fadeIn()},document.getElementById("save").onclick=function(){m.clear().renderAll(),m.loadFromJSON(JSON.stringify(s),function(){g(3),m.renderAll()});var G=[];G=m._objects.filter(function(K){return K});var H=new fabric.Group(G,{top:50,left:50});m.clear().renderAll(),m.add(H);var I=H.getWidth(),J=H.getHeight();return m.setHeight(J+100),m.setWidth(I+100),m.discardActiveObject(),m.renderAll(),CanvasSaver2(),waitdownload(),!1};if($(".addImage1").on("click",function(){fabric.Image.fromURL("logo.png",function(G){var H=s.getWidth()/2,I=s.getHeight()/2;G.scale(1),G.set({left:H}),G.set({top:I}),s.add(G),s.sendToBack(G)})}),document.getElementById("newimg").onclick=function(){s.discardActiveObject();var G=baseurl+"/imgbit0317/"+$("#newimg").text()+".svg";d(G),$(".panel3").fadeOut(),zizza()},""==temp){var D=[];fabric.loadSVGFromURL(baseurl+"/imgbit0317/example.svg",function(){var I=s.getWidth()/2,J=s.getHeight()/2,K=new fabric.Group(D);K.scale(q);var L=K.getHeight()/2,M=K.getWidth()/2;K.set({left:I-M}),K.set({top:J-L-90}),K.set({id:"img"}),s.add(K),s.renderAll(),s.sendToBack(K)},function(G,H){H.set("id",G.getAttribute("id")),D.push(H)})}s.on("object:selected",function(G){if(activeObject=G.target,activeObject.isType("text")){var H=s.getActiveObject();H=H.getText(),$("#text1").val(H),$("#remtxt").removeClass("panico8").addClass("panico7"),$("#color").css("opacity","1"),mystil=s.getActiveObject().get("fontFamily"),$("#text-font").css("font-family",mystil),$("#text-font").val(mystil),"Your Company"==$("#text1").val(),activeObject.shadow&&0!=activeObject.shadow?$("#shadow").css({background:"#fff",opacity:"1.0"}):$("#shadow").css({background:"",opacity:"0.5"})}else activeObject.isType("group")?$("#remtxt").removeClass("panico7").addClass("panico8"):activeObject.isType("rect")?($(".comandSbox").fadeIn(),$(".opa1").css("opacity","1")):activeObject.isType("circle")&&($(".comandSbox").fadeIn(),$(".opa1").css("opacity","1"));"group"!=s.getActiveObject().get("type"),$("#avanti").css("opacity","1"),1<=s.getObjects().indexOf(activeObject)?($("#avanti").css("display","none"),$("#indietro").css("display","block")):($("#indietro").css("display","none"),$("#avanti").css("display","block"))}),s.on("selection:cleared",function(){$("#remtxt").removeClass("panico7").addClass("panico8"),$(".comandSbox").fadeOut(),$("#color").css("opacity","0.5"),$("#avanti").css({opacity:"0.5",display:"block"}),$("#indietro").css("display","none"),$(".alerttext").fadeOut(),$(".opa1").css("opacity","0.3")}),document.getElementById("showLeftPush").onclick=function(){activeObject=s.getActiveObject(),void 0!=activeObject&&activeObject.isType("text")?$(".alerttext").fadeOut():$(".alerttext").fadeIn()};var E="OK";E="OK"==E?"KO":"OK",document.getElementById("addtxt").onclick=function(){var G=new fabric.Text("new text",{fontFamily:"Century Gothic",fontSize:"60",lineHeight:1.2,left:s.getWidth()/2-127,top:s.getHeight()/2-50});return G.id="newtext",s.add(G),s.bringForward(G),!1},document.getElementById("remtxt").onclick=function(){var G=s.getActiveObject();return G&&"text"===s.getActiveObject().get("type")&&s.remove(G),!1},document.getElementById("box").onclick=function(){var G=new fabric.Rect({width:100,height:100,left:s.getWidth()/2-50,top:s.getHeight()/2+100,fill:"#DEB887"});s.add(G),s.renderAll(),s.setActiveObject(G),s.sendToBack(G)},document.getElementById("circle").onclick=function(){var G=new fabric.Circle({radius:50,left:s.getWidth()/2-50,top:s.getHeight()/2+100,fill:"#E97451"});s.add(G),s.renderAll(),s.setActiveObject(G),s.sendToBack(G)},document.getElementById("formdel").onclick=function(){var G=s.getActiveObject();G&&("rect"!==s.getActiveObject().get("type")&&"circle"!==s.getActiveObject().get("type")||s.remove(G))},$("#color1").simpleColorPicker({onChangeColor:function(G){var H=s.getActiveObject();if(H&&("rect"===s.getActiveObject().get("type")||"circle"===s.getActiveObject().get("type"))){H.setColor(G);showEffect:"fade",s.renderAll()}}}),$(window).keydown(function(G){switch(G.keyCode){case 46:var H=s.getActiveObject();return s.remove(H),s.renderAll(),console.log("fdsf"),!1;}});var F=$("#ciro");$(F).click(function(){s.discardActiveObject()}),s.on("object:selected",function(G){G.target.transparentCorners=!1,G.target.borderColor="#ff6600",G.target.cornerColor="#ff9900"}),s.on("mouse:over",function(G){console.log(G.target.type),"group"==G.target.type?($(".mA").css("border","1px solid #ff9900"),$("#frex1").fadeIn()):"text"===G.target.type?($(".mB").css("border","1px solid #ff9900"),$("#frex2").fadeIn()):"rect"===G.target.type?($(".zjon").css("border","1px solid #ff9900"),$("#frex3").fadeIn()):"circle"===G.target.type&&($(".zjon").css("border","1px solid #ff9900"),$("#frex3").fadeIn())}),s.on("mouse:out",function(){$(".m2").css("border","1px solid #ccc"),$(".zjon").css({border:"none",borderRight:"1px solid #ccc",borderBottom:"1px solid #ccc"}),$(".frex").fadeOut()}),""!=temp&&($("#newimg").text(temp+".svg"),function(G){b(),G=baseurl+"/imgbit0317/"+G+".svg";var H=[];fabric.loadSVGFromURL(G,function(){var K=s.getWidth()/2,L=s.getHeight()/2,M=new fabric.Group(H);M.scale(q);var N=M.getHeight(),O=M.getWidth()/2;M.set({left:K-O}),M.set({top:L-N}),M.set({id:"img"}),s.add(M),s.renderAll(),s.sendToBack(M)},function(I,J){J.set("id",I.getAttribute("id")),H.push(J)})}(temp),$("#opgall").fadeOut()),s.on("mouse:down",function(G){console.log(G.target),"KO"==E&&(E="OK")})});function CanvasSaver(){var a=document.getElementById("canvas2"),b="http://www.logookay.com/saveme.php";this.url=b;var d=a.toDataURL("image/png");d=d.substr(d.indexOf(",")+1).toString();var f=document.createElement("input");f.setAttribute("name","imgdata"),f.setAttribute("value",d),f.setAttribute("type","hidden");var g=document.createElement("input");g.setAttribute("name","name"),g.setAttribute("value","LogoOkay.com"+".png");var j=document.createElement("form");j.method="post",j.action=b,j.appendChild(f),j.appendChild(g),document.body.appendChild(j),j.submit(),document.body.removeChild(j)}function CanvasSaver2(){var a=document.getElementById("canvas2"),b="https://www.logofactoryweb.com/editor_invio.asp?sid="+Math.random();this.url=b;var d=a.toDataURL("image/png");d=d.substr(d.indexOf(",")+1).toString(),$("#imgdata").val(d),download()}function timedMsg(){setTimeout("$('#moment').fadeOut()",3e3)}