var DocumentViewer=function(a){_thisViewer=this;_thisViewer.mimeType=a.mimeType;_thisViewer.staticContentUrl=a.staticContentUrl;_thisViewer.pdfTronLicense=a.pdfTronLicense;_thisViewer.chunkSize=a.chunkSize;_thisViewer.modelKey=a.modelKey;_thisViewer.fileName=a.fileName;_thisViewer.fileUrl=a.fileUrl;_thisViewer.initialize();_thisViewer.initializeLoader(a.loaderMessageText,a.loaderCompleteWord);_thisViewer.completeWord=a.loaderCompleteWord;$(document).ready(function(){$(window).resize()})};
DocumentViewer.prototype={saveIconSvg:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M0 0h24v24H0z" fill="none"/><path d="M17 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V7l-4-4zm-5 16c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3zm3-10H5V5h10v4z"/></svg>',cancelIconSvg:'<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="24" height="24" viewBox="0 0 6.3499999 6.3500002" version="1.1" id="svg8" inkscape:version="0.92.4 (5da689c313, 2019-01-14)" sodipodi:docname="cancel.svg"><defs id="defs2" /><sodipodi:namedview id="base" pagecolor="#ffffff" bordercolor="#666666" borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="22.627417" inkscape:cx="28.997004" inkscape:cy="14.547098" inkscape:document-units="mm" inkscape:current-layer="layer1" showgrid="false" showguides="true" inkscape:guide-bbox="true" units="px" inkscape:window-width="1920" inkscape:window-height="1027" inkscape:window-x="-8" inkscape:window-y="-8" inkscape:window-maximized="1" /><metadata id="metadata5"><rdf:RDF><cc:Work rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><g inkscape:label="Layer 1" inkscape:groupmode="layer" id="layer1" transform="translate(0,-290.64998)"><path id="path4550" d="m 4.08162,293.82498 1.35979,-1.35979 c 0.16687,-0.16687 0.16687,-0.43742 0,-0.60442 l -0.3022,-0.3022 c -0.16687,-0.16687 -0.43742,-0.16687 -0.60442,0 L 3.175,292.91836 1.81521,291.55857 c -0.16687,-0.16687 -0.43741,-0.16687 -0.60442,0 l -0.30220001,0.3022 c -0.16687,0.16687 -0.16687,0.43741 0,0.60442 l 1.35979001,1.35979 -1.35979001,1.3598 c -0.16687,0.16686 -0.16687,0.43741 0,0.60441 l 0.30220001,0.3022 c 0.16687,0.16687 0.43755,0.16687 0.60442,0 l 1.35979,-1.35979 1.35979,1.35979 c 0.16687,0.16687 0.43755,0.16687 0.60442,0 l 0.3022,-0.3022 c 0.16687,-0.16687 0.16687,-0.43741 0,-0.60441 z" inkscape:connector-curvature="0" style="fill:currentColor;stroke-width:0.01358843" /></g></svg>',
initialize:function(){_thisViewer.viewerElement=document.getElementById("divPdfViewer");switch(_thisViewer.mimeType.toLowerCase()){case "application/pdf":_thisViewer.webViewer=_thisViewer.initializePdfViewer()}},initializePdfViewer:function(){_thisViewer.pdfTronViewer=new PDFTron.WebViewer({path:_thisViewer.staticContentUrl,l:_thisViewer.pdfTronLicense,disabledElements:["signatureToolButton"]},_thisViewer.viewerElement);_thisViewer.viewerElement.addEventListener("ready",function(){var a=_thisViewer.pdfTronViewer.getInstance();
annotationManager=a.docViewer.getAnnotationManager();_thisViewer.pdfTronViewer.loadDocument(_thisViewer.fileUrl,{filename:_thisViewer.fileName});a.setHeaderItems(function(a){a.push({type:"actionButton",img:_thisViewer.saveIconSvg,onClick:function(){_thisViewer.showLoader();_thisViewer.pdfTronViewer.getInstance().docViewer.getDocument().getFileData({xfdfString:annotationManager.exportAnnotations()}).then(function(a){_thisViewer.uploadFile(a)})}});a.push({type:"actionButton",img:_thisViewer.cancelIconSvg,
onClick:function(){window.close()}})})})},uploadFile:function(a){a=new Uint8Array(a);a=new Blob([a],{type:_thisViewer.mimeType.toLowerCase()});var b=Math.ceil(a.size/_thisViewer.chunkSize),c=_thisViewer.getFileIdentifier();_thisViewer.currentChunk=0;_thisViewer.currentChunksCount=b;_thisViewer.processChunks(1,_thisViewer.currentChunksCount,a,c)},processChunks:function(a,b,c,f){console.log(a,b,f);var g=_thisViewer.chunkSize*(a-1),h=g+_thisViewer.chunkSize;console.log({start:g,end:h,mimetype:_thisViewer.mimeType,
chunksize:_thisViewer.chunkSize});var k=c.slice(g,h,_thisViewer.mimeType),d=new FormData,e=new XMLHttpRequest;d.append("chunksFileId",f);d.append("chunkData",k);d.append("currentChunk",a);d.append("chunksCount",b);e.onload=function(){console.log({start:g,end:h,mimetype:_thisViewer.mimeType,chunksize:_thisViewer.chunkSize,response:e.response});if(a<b){var d=Math.round(100*a/b);_thisViewer.updateLoader(d);_thisViewer.processChunks(a+1,b,c,f)}else $("body").append(e.response)};e.open("POST","Upload?mkey="+
_thisViewer.modelKey);e.send(d)},getFileIdentifier:function(){var a=(new Date).getTime();return"PDFEDITION-"+"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(b){var c=(a+16*Math.random())%16|0;a=Math.floor(a/16);return("x"==b?c:c&3|8).toString(16)}).toUpperCase()},initializeLoader:function(a,b){var c=document.createElement("div"),f=document.createElement("div"),g=document.createElement("table"),h=document.createElement("tr"),k=document.createElement("td"),d=document.createElement("td"),
e=document.createElement("img"),l=document.createElement("h4"),m=document.createElement("h5");m.id="message-percentage";m.className="percentage";m.innerText="0% "+b;l.id="message-text";l.className="text";l.innerText=a;e.src=_thisViewer.staticContentUrl+"/loader.gif";e.width="32";e.height="32";f.id="loader-message";f.className="message";c.className="loader";d.appendChild(l);d.appendChild(m);k.appendChild(e);h.appendChild(k);h.appendChild(d);g.appendChild(h);f.appendChild(g);c.appendChild(f);document.getElementsByTagName("body")[0].appendChild(c);
$(window).resize(function(){var a=window.innerWidth/2-$("#loader-message").width()/2,b=window.innerHeight/2-$("#loader-message").height()/2;$("#loader-message").css("top",b+"px");$("#loader-message").css("left",a+"px")});$(".loader:eq(0)").hide()},showLoader:function(){_thisViewer.updateLoader(0);$(".loader").fadeIn()},hideLoader:function(){$(".load").fadeOut()},updateLoader:function(a){$("#message-percentage").html(a+"% "+_thisViewer.completeWord)}};
