function setSettings(n){switch(n){case"drawing":$("#drawingSettings").show();$("#textSettings").hide();$("#imageSettings").hide();break;case"text":$("#drawingSettings").hide();$("#textSettings").show();$("#imageSettings").hide();break;case"image":$("#drawingSettings").hide();$("#textSettings").hide();$("#imageSettings").show()}}function AssignSaveToButtonText(n){var t=$(n).text();document.getElementById("SaveToButton").innerHTML=t;document.getElementById("SaveToHidden").value=t}function setSignatureType(n){var t=$(n).text();document.getElementById("signatureType").innerHTML=t;o.signatureType=$(n).data("val");setSettings(o.signatureType)}function removefileimage(){$("#fileUploadImage").hide();$("#fileUploadImageInput").show()}function Canvas(n,t){function l(n){u.lineWidth=2;u.lineJoin="round";u.lineCap="round";u.strokeStyle=n}var i=document.querySelector(n),c;if(i!==null){var u=i.getContext("2d"),r={x:null,y:null},f={x:0,y:0};l($(t).val());$(t).change(function(){points_count=0;l($(this).val())});var a=function(n,t){i.addEventListener(n,function(){i.addEventListener(t,c,!1)},!1)},v=function(n,t){i.addEventListener(n,function(){r.x=null;r.y=null;i.removeEventListener(t,c,!1)},!1)},y=function(n){i.addEventListener(n,function(n){f.x=r.x;f.y=r.y;var t=i.getBoundingClientRect();r.x=(n.clientX-t.left)*(i.width/t.width);r.y=(n.clientY-t.top)*(i.height/t.height)},!1)},h=function(n){var t=document.createElement("canvas"),i=n in t;return i||(t.setAttribute(n,"return;"),i=typeof t[n]=="function"),t=null,i},o=null,s=null,e=null;h("onpointerdown")?(o="pointerdown",s="pointerup",e="pointermove"):h("ontouchstart")?(o="touchstart",s="touchend",e="touchmove"):h("onmousedown")&&(o="mousedown",s="mouseup",e="mousemove");o!==null&&s!==null&&e!==null&&(a(o,e),v(s,e),y(e));c=function(){f.x===null&&f.y===null&&(f.x=r.x,f.y=r.y);u.beginPath();u.moveTo(f.x,f.y);points_count++;u.lineTo(r.x,r.y);u.closePath();u.stroke()};this.clearSignature=function(){points_count=0;i.width=i.width;var n=i.getContext("2d");n.lineWidth=2;n.lineJoin="round";n.lineCap="round";n.strokeStyle=$(t).val();r.x=null;r.y=null}}}function colorPicker(n){for(var r=["000000","993300","333300","003300","003366","000066","333399","333333","660000","FF6633","666633","336633","336666","0066FF","666699","666666","CC3333","FF9933","99CC33","669966","66CCCC","3366FF","663366","999999","CC66FF","FFCC33","FFFF66","99FF66","99CCCC","66CCFF","993366","CCCCCC","FF99CC","FFCC99","FFFF99","CCffCC","CCFFff","99CCFF","CC99FF","FFFFFF"],t=$(n),i=0;i<r.length;i++)t.append('<li class="color-item" data-hex="#'+r[i]+'" style="background-color:#'+r[i]+';"><\/li>');return $("body").click(function(){t.fadeOut()}),t.siblings(".call-picker").click(function(n){n.stopPropagation();t.fadeIn();t.children("li").hover(function(){var n=$(this).data("hex");t.siblings(".color-holder").css("background-color",n);t.siblings("input.call-picker").val(n).trigger("change")})}),t}function validateSignature(){var t,n;switch(o.signatureType){case"drawing":if(points_count===0)return showAlert(o.validationDrawMessage),!1;break;case"text":if(t=$("#signText").val(),t.length===0)return showAlert(o.validationTextMessage),!1;break;case"image":if(n=$("#fileUploadImageInput")[0].files,n===undefined||n.length===0)return showAlert(o.FileSelectMessage),!1}return!0}function requestSignature(){var t,i;if(validateSignature()){let n=fileDrop.prepareFormData();if(n!==null){switch(o.signatureType){case"drawing":t=$("#signCanvas")[0].toDataURL("image/png");t=t.replace("data:image/png;base64,","");n.append("image",t);break;case"text":n.append("text",$("#signText").val());n.append("textColor",$("#pickcolorText").val());break;case"image":i=$("#fileUploadImageInput")[0].files[0];n.append("imageFile",i,i.name)}let r=o.APIBasePath+"AsposeWordsSignature/Sign?outputType="+$("#saveAs").val()+"&signatureType="+o.signatureType;request(r,n)}}}var drawCanvas=null,pickerDraw=null,pickerText=null,points_count=0;$(document).ready(function(){$("#fileUploadImage").hide();$("#fileUploadImageInput").change(function(){var n=$("#fileUploadImageInput")[0].files[0].name;$("#fileUploadImage label").text(n);$("#fileUploadImage").show()});drawCanvas=new Canvas("#signCanvas","#pickcolorDrawing");pickerDraw=new colorPicker("#color-pickerDraw");pickerText=new colorPicker("#color-pickerText");setSettings(o.signatureType)});