var doc=new jsPDF,zip=new JSZip,Print=function(){function e(e){var a=document.createElement("canvas");a.width=e.width,a.height=e.height;var t=a.getContext("2d");t.drawImage(e,0,0);var n=a.toDataURL("image/jpeg");return n.replace(/^data:image\/(png|jpg);base64,/,"")}function a(){var a=$(".slide-image").length,t=new Array(a),n=0;$(".slide-image").each(function(i){var r=this,g=new Image;g.setAttribute("crossOrigin","anonymous"),g.src=$(this).attr("src"),g.onload=function(){var i=e(g),d=$(r)[0].getBoundingClientRect().width,o=$(r)[0].getBoundingClientRect().height,s=$(r).data("order");if(t[s]={dataUri:i,widthPage:d,heightPage:o},n++,"pdf"===$("#print").val()){if(n===a){for(var c=0;c<a;c++)doc.addPage(t[c].widthPage+20,t[c].heightPage+20),doc.addImage(t[c].dataUri,"JPEG",10,10,t[c].widthPage,t[c].heightPage);return doc.deletePage(1),doc.save("genially-"+$("#idGenially").val()+".pdf"),$("#generatingMessage").remove(),void $("#doneMessage").fadeIn()}}else if(n===a){for(var l=0;l<a;l++)zip.file("page_"+l+".jpg",t[l].dataUri.replace("data:image/jpeg;base64,",""),{base64:!0});return zip.generateAsync({type:"blob"}).then(function(e){saveAs(e,"genially_"+$("#idGenially").val()+"_images.zip")}),$("#generatingMessage").remove(),void $("#doneMessage").fadeIn()}}})}function t(){var e=0;$.each(arrayImages,function(a,t){$("body").append('<img data-order="'+e+'" src="'+t+'" class="slide-image" />'),e++}),a()}function n(){try{ga("send","event","Behaviour","ExportToPDF",currentData.IdGenially)}catch(e){}t()}return{start:n,process:t,triggerPrint:a}}(),width=$(document).width()-40,height=$(document).height(),arrayImages;$(document).ready(function(){function e(){return $.ajax({data:i,url:r,type:"GET",contentType:"application/json; charset=utf-8"})}function a(e){arrayImages=e,Print.start()}function t(){$("#generatingMessage").remove(),$("#errorMessage").fadeIn()}var n=$("#idGenially").val(),i={id:n},r="/api/Print/GetImagesForPdf";e().done(a).fail(t)});