forked from tuan2308/tad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tad-aowall2.js
1 lines (1 loc) · 10.4 KB
/
tad-aowall2.js
1
$(document).ready(function(){if(window.location.hostname==tmbq){$("body").append("<input class='cropanh1 d-none' value=''>");$("body").append("<input class='cropanh2 d-none' value=''>");var w=$(".cropanh1");var z=$(".cropanh2");var p=$(".tad-in-text1");var r=$(".tad-in-text2");var t=$(".tad-in-text3");var s=$(".tad-in-texta");$("#cropanh1").click(function(){$(".cropanh1").val(1);n()});$("#cropanh2").click(function(){$(".cropanh2").val(1);n()});p.on("input",function(){n()});r.on("input",function(){n()});t.on("input",function(){n()});s.on("input",function(){n()});function n(){if(undefined!==w.val()&&w.val().length==""){$("#tad-taoanh").addClass("disabled")}else{if(undefined!==z.val()&&z.val().length==""){$("#tad-taoanh").addClass("disabled")}else{if(undefined!==p.val()&&p.val().length==0){$("#tad-taoanh").addClass("disabled")}else{if(undefined!==r.val()&&r.val().length==0){$("#tad-taoanh").addClass("disabled")}else{if(undefined!==t.val()&&t.val().length==0){$("#tad-taoanh").addClass("disabled")}else{if(undefined!==s.val()&&s.val().length==0){$("#tad-taoanh").addClass("disabled")}else{$("#tad-taoanh").removeClass("disabled")}}}}}}}function m(){var c=document.createElement("canvas");c.width=200;c.height=200;var a=c.getContext("2d");x=c.width/2;y=c.height/2;lineHeight=15;a.fillStyle="white";x=c.width/2;y=c.height/2;a.save();a.translate(x,y);a.rotate(-Math.PI/4);a.textAlign="center";var b=$(".tad-in-text1").val();cr=a.measureText(b).width;font=c.width*12/cr;a.font=font+"px UTM Gloria";a.fillText(b,0,lineHeight/2);c.toBlob(function(e){var d=URL.createObjectURL(e);var f=new Image();f.src=d;f.onload=function(){o(f)}})}var l=0;$(".chonmau #kieu1").click(function(){l=0});$(".chonmau #kieu2").click(function(){l=1});function o(h){var d=document.getElementById("temp");var a=d.getContext("2d");a.clearRect(0,0,d.width,d.height);a.fillStyle="#1a1b20";a.fillRect(0,0,d.width,d.height);var h=h;var g=a.createPattern(h,"repeat");a.rect(0,0,d.width,d.height);a.fillStyle=g;a.fill();if(l==0){a.save();let q=document.getElementById("Limg");a.drawImage(q,0,0,d.width,d.height);a.restore();a.save();var e=document.getElementById("Cimg");var c=350;a.rotate(7*Math.PI/180);a.translate(415,170);a.drawImage(e,0,0,c,c*6/9);a.restore();a.save();var f=document.getElementById("Aimg");var b=180;a.rotate(7*Math.PI/180);a.translate(500,300);a.beginPath();a.strokeStyle="white";a.lineWidth=5;a.arc(b/2,b/2,b/2,0,Math.PI*2,true);a.stroke();a.closePath();a.clip();a.drawImage(f,0,0,b,b);a.beginPath();a.arc(0,0,b/2,0,Math.PI*2,true);a.clip();a.closePath();a.restore();a.save();lineHeight=15;a.font="700 30px Arial";a.translate(520,580);a.rotate(7*Math.PI/180);a.textAlign="center";a.fillStyle="black";txt1=$(".tad-in-text1").val();a.fillText(txt1,0,lineHeight/2);a.restore();a.save();lineHeight=15;a.font="15px Arial";a.translate(515,610);a.rotate(7*Math.PI/180);a.textAlign="center";a.fillStyle="#555";txta=$(".tad-in-text2").val();a.fillText(txta,0,lineHeight/2);a.restore();a.save();a.globalCompositeOperation="darken";a.drawImage(q,0,0,d.width,d.height);a.restore()}else{a.save();a.save();let q=document.getElementById("Limg2");a.drawImage(q,0,0,d.width,d.height);a.restore();var e=document.getElementById("Cimg");var c=250;a.translate(420,145);a.drawImage(e,0,0,c,c*6/9);a.restore();a.save();var f=document.getElementById("Aimg");var b=125;a.translate(480,235);a.beginPath();a.strokeStyle="white";a.lineWidth=5;a.arc(b/2,b/2,b/2,0,Math.PI*2,true);a.stroke();a.closePath();a.clip();a.drawImage(f,0,0,b,b);a.beginPath();a.arc(0,0,b/2,0,Math.PI*2,true);a.clip();a.closePath();a.restore();a.save();lineHeight=15;a.font="700 25px Arial";a.translate(540,385);a.textAlign="center";a.fillStyle="black";txt1=$(".tad-in-text1").val();a.fillText(txt1,0,lineHeight/2);a.restore();a.save();lineHeight=15;a.font="15px Arial";a.translate(540,410);a.textAlign="center";a.fillStyle="#555";txta=$(".tad-in-text2").val();a.fillText(txta,0,lineHeight/2);a.restore();a.save();a.globalCompositeOperation="darken";a.drawImage(q,0,0,d.width,d.height);a.restore()}d.toBlob(function(j){var i=URL.createObjectURL(j);$("#img-out").html("<img src='"+i+"' alt='Tạo ảnh đẹp' class='img-thumbnail'></img>");$("#tad-taianhve").attr("download","taoanhdep-aowall.jpg").attr("href",i)});$("#img-out").delay(2000).show(0);$("#tad-taianhve").delay(2000).show(0);$(".tad-ketqua").delay(2000).show(0);$(".load-anh").delay(2000).hide(0)}var u=$("#dk1").val();var v=$("#dk2").val();$("#img-out").hide();$("#tad-taianhve").hide();$(".tad-ketqua").hide();$("#tad-taoanh").addClass("disabled");$("#tad-taoanh").click(function(){$("#img-out").hide();$("#tad-taianhve").hide();$(".tad-ketqua").hide();$(".load-anh").show();document.fonts.load('10pt "UTM Gloria"').then(m)});$(".btn-upanh1").click(function(){$(".cropanh-container1 .cropper-container").remove();"use strict";var i=window.Cropper;var k=window.URL||window.webkitURL;var e=document.querySelector(".img-container1");var d=e.getElementsByTagName("img").item(0);var b=document.getElementById("actions1");var h={aspectRatio:1/1,viewMode:1,preview:".img-preview1",autoCrop:true,strict:true,background:true,autoCropArea:1};var f=new i(d,h);var c=d.src;var g="image/jpeg";var a;if(!document.createElement("canvas").getContext){$('button[data-method="getCroppedCanvas"]').prop("disabled",true)}if(typeof document.createElement("cropper").style.transition==="undefined"){$('button[data-method="rotate"]').prop("disabled",true);$('button[data-method="scale"]').prop("disabled",true)}b.querySelector(".docs-buttons1").onclick=function(F){var H=F||window.event;var I=H.target||H.srcElement;var K;var G;var J;var L;if(!f){return}while(I!==this){if(I.getAttribute("data-method")){break}I=I.parentNode}if(I===this||I.disabled||I.className.indexOf("disabled")>-1){return}L={method:I.getAttribute("data-method"),target:I.getAttribute("data-target"),option:I.getAttribute("data-option")||undefined,secondOption:I.getAttribute("data-second-option")||undefined};K=f.cropped;if(L.method){if(typeof L.target!=="undefined"){J=document.querySelector(L.target);if(!I.hasAttribute("data-option")&&L.target&&J){try{L.option=JSON.parse(J.value)}catch(H){console.log(H.message)}}}switch(L.method){case"rotate":if(K){f.clear()}break;case"getCroppedCanvas":try{L.option=JSON.parse(L.option)}catch(H){console.log(H.message)}if(g==="image/jpeg"){if(!L.option){L.option={}}L.option.fillColor="#fff"}break}G=f[L.method](L.option,L.secondOption);switch(L.method){case"rotate":if(K){f.crop()}break;case"scaleX":case"scaleY":I.setAttribute("data-option",-L.option);break;case"getCroppedCanvas":if(G){G.toBlob(function(B){var A=k.createObjectURL(B);$("#Aimg").attr("src",A);$("#dk1").val(1)})}break;case"destroy":f=null;if(a){k.revokeObjectURL(a);a="";d.src=c}break}if(typeof G==="object"&&G!==f&&J){try{J.value=JSON.stringify(G)}catch(H){console.log(H.message)}}}};document.body.onkeydown=function(A){var B=A||window.event;if(!f||this.scrollTop>300){return}switch(B.keyCode){case 37:B.preventDefault();f.move(-1,0);break;case 38:B.preventDefault();f.move(0,-1);break;case 39:B.preventDefault();f.move(1,0);break;case 40:B.preventDefault();f.move(0,1);break}};$(".cropanh-container1").hide();var j=document.getElementById("inputImage1");if(k){j.onchange=function(){var B=this.files;var A;if(f&&B&&B.length){A=B[0];if(/^image\/\w+/.test(A.type)){g=A.type;if(a){k.revokeObjectURL(a)}d.src=a=k.createObjectURL(A);f.destroy();f=new i(d,h);j.value=null;$(".cropanh-container1").show();$(".btn-upanh1 span,.btn-chonanh1").html("<i class='fas fa-upload'></i> Chọn ảnh khác")}else{window.alert("Please choose an image file.")}}}}else{j.disabled=true;j.parentNode.className+=" disabled"}});$(".btn-upanh2").click(function(){$(".cropanh-container2 .cropper-container").remove();"use strict";var i=window.Cropper;var k=window.URL||window.webkitURL;var e=document.querySelector(".img-container2");var d=e.getElementsByTagName("img").item(0);var b=document.getElementById("actions2");var h={aspectRatio:9/6,viewMode:1,preview:".img-preview2",autoCrop:true,strict:true,background:true,autoCropArea:1};var f=new i(d,h);var c=d.src;var g="image/jpeg";var a;if(!document.createElement("canvas").getContext){$('button[data-method="getCroppedCanvas"]').prop("disabled",true)}if(typeof document.createElement("cropper").style.transition==="undefined"){$('button[data-method="rotate"]').prop("disabled",true);$('button[data-method="scale"]').prop("disabled",true)}b.querySelector(".docs-buttons2").onclick=function(F){var H=F||window.event;var I=H.target||H.srcElement;var K;var G;var J;var L;if(!f){return}while(I!==this){if(I.getAttribute("data-method")){break}I=I.parentNode}if(I===this||I.disabled||I.className.indexOf("disabled")>-1){return}L={method:I.getAttribute("data-method"),target:I.getAttribute("data-target"),option:I.getAttribute("data-option")||undefined,secondOption:I.getAttribute("data-second-option")||undefined};K=f.cropped;if(L.method){if(typeof L.target!=="undefined"){J=document.querySelector(L.target);if(!I.hasAttribute("data-option")&&L.target&&J){try{L.option=JSON.parse(J.value)}catch(H){console.log(H.message)}}}switch(L.method){case"rotate":if(K){f.clear()}break;case"getCroppedCanvas":try{L.option=JSON.parse(L.option)}catch(H){console.log(H.message)}if(g==="image/jpeg"){if(!L.option){L.option={}}L.option.fillColor="#fff"}break}G=f[L.method](L.option,L.secondOption);switch(L.method){case"rotate":if(K){f.crop()}break;case"scaleX":case"scaleY":I.setAttribute("data-option",-L.option);break;case"getCroppedCanvas":if(G){G.toBlob(function(B){var A=k.createObjectURL(B);$("#Cimg").attr("src",A);$("#dk2").val(1)})}break;case"destroy":f=null;if(a){k.revokeObjectURL(a);a="";d.src=c}break}if(typeof G==="object"&&G!==f&&J){try{J.value=JSON.stringify(G)}catch(H){console.log(H.message)}}}};document.body.onkeydown=function(A){var B=A||window.event;if(!f||this.scrollTop>300){return}switch(B.keyCode){case 37:B.preventDefault();f.move(-1,0);break;case 38:B.preventDefault();f.move(0,-1);break;case 39:B.preventDefault();f.move(1,0);break;case 40:B.preventDefault();f.move(0,1);break}};$(".cropanh-container2").hide();var j=document.getElementById("inputImage2");if(k){j.onchange=function(){var B=this.files;var A;if(f&&B&&B.length){A=B[0];if(/^image\/\w+/.test(A.type)){g=A.type;if(a){k.revokeObjectURL(a)}d.src=a=k.createObjectURL(A);f.destroy();f=new i(d,h);j.value=null;$(".cropanh-container2").show();$(".btn-upanh2 span,.btn-chonanh2").html("<i class='fas fa-upload'></i> Chọn ảnh khác")}else{window.alert("Please choose an image file.")}}}}else{j.disabled=true;j.parentNode.className+=" disabled"}})}});