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