mirror of
https://git.sindominio.net/estibadores/wordpress.git
synced 2024-11-14 23:21:07 +01:00
1 line
19 KiB
JavaScript
1 line
19 KiB
JavaScript
var pdfembGrabToPan=function(){function e(e){this.element=e.element,this.document=e.element.ownerDocument,"function"==typeof e.ignoreTarget&&(this.ignoreTarget=e.ignoreTarget),this.onActiveChanged=e.onActiveChanged,this.activate=this.activate.bind(this),this.deactivate=this.deactivate.bind(this),this.toggle=this.toggle.bind(this),this._onmousedown=this._onmousedown.bind(this),this._onmousemove=this._onmousemove.bind(this),this._onmousewheel=this._onmousewheel.bind(this),this._endPan=this._endPan.bind(this),(this.overlay=document.createElement("div")).className="grab-to-pan-grabbing"}var t;e.prototype={CSS_CLASS_GRAB:"grab-to-pan-grab",activate:function(){!this.active&&(this.active=!0,this.element.addEventListener("mousedown",this._onmousedown,!0),this.element.addEventListener("mousewheel",this._onmousewheel),this.element.addEventListener("wheel",this._onmousewheel),this.element.addEventListener("DOMMouseScroll",this._onmousewheel),this.element.classList.add(this.CSS_CLASS_GRAB),this.onActiveChanged)&&this.onActiveChanged(!0)},deactivate:function(){this.active&&(this.active=!1,this.element.removeEventListener("mousedown",this._onmousedown,!0),this._endPan(),this.element.classList.remove(this.CSS_CLASS_GRAB),this.onActiveChanged)&&this.onActiveChanged(!1)},toggle:function(){this.active?this.deactivate():this.activate()},ignoreTarget:function(e){return e[t]("a[href], a[href] *, input, textarea, button, button *, select, option")},_onmousedown:function(e){if(0===e.button&&!this.ignoreTarget(e.target)){this.scrollLeftStart=this.element.scrollLeft,this.scrollTopStart=this.element.scrollTop,this.clientXStart=e.clientX,this.clientYStart=e.clientY,this.document.addEventListener("mousemove",this._onmousemove,!0),this.document.addEventListener("mouseup",this._endPan,!0),this.element.addEventListener("scroll",this._endPan,!0),e.preventDefault(),e.stopPropagation(),this.document.documentElement.classList.add(this.CSS_CLASS_GRABBING);var t=document.activeElement;t&&!t.contains(e.target)&&t.blur()}},_onmousemove:function(e){var t;this.element.removeEventListener("scroll",this._endPan,!0),(t="buttons"in e&&n?!(1|e.buttons):i||o?0===e.which:void 0)?this._endPan():(t=e.clientX-this.clientXStart,this.element.scrollTop=this.scrollTopStart-(e.clientY-this.clientYStart),this.element.scrollLeft=this.scrollLeftStart-t,this.overlay.parentNode||document.body.appendChild(this.overlay))},_onmousewheel:function(e){this.element.removeEventListener("scroll",this._endPan,!0);var t=.5;e.deltaMode&&(1==e.deltaMode&&(t=10),2==e.deltaMode&&(t=1e3));var n=e.deltaY?-e.deltaY:e.wheelDelta?e.wheelDelta:-e.detail;if(this.scrollLeftStart=this.element.scrollLeft,this.scrollTopStart=this.element.scrollTop,t*=n,this.element.scrollTop=this.scrollTopStart-t,this.overlay.parentNode||document.body.appendChild(this.overlay),this.element.scrollTop!=this.scrollTopStart||0==t)return e.preventDefault(),!1},_endPan:function(){this.element.removeEventListener("scroll",this._endPan,!0),this.document.removeEventListener("mousemove",this._onmousemove,!0),this.document.removeEventListener("mouseup",this._endPan,!0),this.overlay.parentNode&&this.overlay.parentNode.removeChild(this.overlay)}},["webkitM","mozM","msM","oM","m"].some(function(e){return(e+="atches")in document.documentElement&&(t=e),(e+="Selector")in document.documentElement&&(t=e),t});var n=!document.documentMode||9<document.documentMode,a=window.chrome,i=a&&(a.webstore||a.app),o=/Apple/.test(navigator.vendor)&&/Version\/([6-9]\d*|[1-5]\d+)/.test(navigator.userAgent);return e}(),PDFEMB_NS={};jQuery(document).ready(function(e){var t,n=(t=document.createElement("canvas").getContext("2d"),(window.devicePixelRatio||1)/(t.webkitBackingStorePixelRatio||t.mozBackingStorePixelRatio||t.msBackingStorePixelRatio||t.oBackingStorePixelRatio||t.backingStorePixelRatio||1));PDFEMB_NS.PIXEL_RATIO=n,createHiDPICanvas=function(e,t,a){a||(a=n);var i=document.createElement("canvas");return i.width=e*a,i.height=t*a,i.style.width=e+"px",i.style.height=t+"px",i.getContext("2d").setTransform(a,0,0,a,0,0),i};var a=0,i=0;!function(){var e=document.createElement("div");e.style.width="100px",e.style.height="100px",e.style.overflow="scroll",e.style.position="absolute",e.style.top="-9999px",document.body.appendChild(e),a=e.offsetWidth-e.clientWidth,i=e.offsetHeight-e.clientHeight,document.body.removeChild(e)}(),PDFEMB_NS.vscrollbarwidth=a,PDFEMB_NS.hscrollbarheight=i;var o=function(e,t,n){this.pdfDoc=e,this.divContainer=t,this.showIsSecure=n,this.initialResize=!1,this.firstPageHeight=this.firstPageWidth=0,this.invalidationRound=1,this.currentPageNum=0,this.zoom=100,this.toZoom=this.fromZoom=0};o.prototype.setup=function(){var t=this,n=this.divContainer,a=this.pdfDoc,i=this.showIsSecure;this.numPages=a.numPages;var o=n.data("scrollbar");this.vscrollbar="both"==o||"vertical"==o,this.hscrollbar="both"==o||"horizontal"==o,o="overflow-y: "+(this.vscrollbar?"scroll":"hidden")+"; ",o+="overflow-x: "+(this.hscrollbar?"scroll":"hidden")+"; ",n.empty().append(e("<div></div>",{class:"pdfemb-pagescontainer",style:o})),n.data("pdfDoc",a),"top"!=(o=n.data("toolbar"))&&"both"!=o||this.addToolbar(!0,"on"==n.data("toolbar-fixed"),i),"bottom"!=o&&"both"!=o||this.addToolbar(!1,"on"==n.data("toolbar-fixed"),i),t.annotationsLayerFactory=void 0!==PDFEMB_NS.pdfembPremiumAnnotationsLayerFactory?new PDFEMB_NS.pdfembPremiumAnnotationsLayerFactory:{createAnnotationsLayerBuilder:function(e,t){return null}},t.annotationLayerFactories=[],n.on("pdfembGotopage",function(e,n){n>this.numPages||0>=n||(t.gotoPage(n),t.jumpToTop())}),n.on("pdfembGotoHash",function(e,n){var a;n.dest&&(dest=n.dest,"string"==typeof dest?(destString=dest,a=t.pdfDoc.getDestination(dest)):a=Promise.resolve(dest),a.then(function(e){e instanceof Array&&!(1>e.length)&&t.pdfDoc.getPageIndex(e[0]).then(function(e){(e+=1)>t.numPages||0>=e||t.currentPageNum==e||(t.gotoPage(e),t.jumpToTop())})}))}),n.on("pdfembGotoAction",function(e,n){var a=t.currentPageNum,i=a;switch(n){case"GoBack":--i;break;case"GoForward":case"NextPage":++i;break;case"PrevPage":--i;break;case"LastPage":i=t.pageCount;break;case"FirstPage":i=1}i==a||i>t.pageCount||0>=i||t.gotoPage(i)}),n.on("pdfembMagnify",function(e){t.magnifyEvent(e)}),n.on("pdfembChangeZoom",function(e,n){t.changeZoom(n)}),this.pageCount=a.numPages,(!n.data("pagenum")||1>n.data("pagenum")||n.data("pagenum")>this.pageCount)&&n.data("pagenum",1),n.data("showIsSecure",this.showIsSecure),n.data("pageNumPending",null),a="on"==n.data("fullScreen")?parseInt(n.data("startfpzoom")):parseInt(n.data("startzoom")),(isNaN(a)||20>a||500<a)&&(a=100),this.zoom=a,100!=a&&n.find("span.pdfemb-zoom").text(a+"%"),n.find("span.pdfemb-page-count").text(this.pageCount),this.gotoPage(n.data("pagenum"))},o.prototype.checkForResize=function(){var t=this,n=t.divContainer,a=e(window).height(),i=e(window).width(),o=n.data("checked-window-height"),s=n.data("checked-window-width");o&&s||(n.data("checked-window-height",a),n.data("checked-window-width",i)),o==a&&s==i||(t.resizeViewer(),t.resizeInnerDivs(),t.invalidateAllPages(),t.renderPage(this.currentPageNum),t.prerenderNearbyPages(this.currentPageNum),t.pdfembMakeMobile(),n.data("checked-window-height",a),n.data("checked-window-width",i)),"true"!=n.data("fullScreenClosed")&&setTimeout(function(){t.checkForResize()},100)},o.prototype.setSizesBasedOnPage=function(e){e=e.getViewport(1),this.pageWidth=e.width,this.pageHeight=e.height,(0>=this.pageWidth||0>=this.pageHeight)&&this.divContainer.empty().append(document.createTextNode(pdfemb_trans.objectL10n.widthheightinvalid))},o.prototype.createPageInnerDivs=function(){for(var t=this.divContainer.find(".pdfemb-pagescontainer"),n=1;n<=this.pageCount;++n){var a=t.find(".pdfemb-inner-div.pdfemb-page"+n);0==a.length&&((a=e("<div></div>",{class:"pdfemb-inner-div pdfemb-page"+n})).data("pageNum",n),t.append(a))}this.resizeInnerDivs()},o.prototype.addGrabToPan=function(){var t=this,n=t.divContainer,a=n.find("div.pdfemb-pagescontainer"),i=new pdfembGrabToPan({element:a[0]});n.data("grabtopan",i),a.on("scroll",function(e){var n=t.getTopVisiblePageNum();n!=t.currentPageNum&&(t.currentPageNum=n,t.updatePageNumDisplay(n),t.renderPage(n,!1),t.prerenderNearbyPages(n),t.deallocateFarAwayPages(n)),e.stopPropagation()}),e(window).resize(function(){setTimeout(function(){t.checkForResize()},100)})},o.prototype.resizeInnerDivs=function(t){var n=this,a=n.wantCanvasWidth,i=n.wantCanvasHeight,o=n.wantHeight,s=this.divContainer.find(".pdfemb-pagescontainer").find(".pdfemb-inner-div");t&&(s=s.filter(".pdfemb-page"+t));var r=0;s.each(function(o,d){var h=e(d),p=h.data("widthfactor"),c=h.data("heightfactor");p||(p=1),c||(c=1),h.data("invalidation-round",this.invalidationRound-1),h.css("width",a*p);var m=i*c+(t==n.numPages||!t&&o==s.length-1?0:2);h.css("height",m),r+=m,(h=h.find(".pdfemb-the-canvas")).css("width",a*p),h.css("height",i*c)});var d=0;!t&&r<o&&(d=(o-r)/2),s.first().css("top",d)},o.prototype.invalidateAllPages=function(){++this.invalidationRound},o.prototype.prerenderNearbyPages=function(e){var t=3,n=2;for(100>this.zoom&&(t*=Math.min(Math.ceil(100/this.zoom),10),n*=Math.min(Math.ceil(100/this.zoom),10)),n=Math.max(1,e-n);n<=Math.min(e+t,this.numPages);++n)n!=e&&this.renderPage(n,!1)},o.prototype.deallocateFarAwayPages=function(e){var t=50,n=50;if(100>this.zoom)t=t+(i=Math.min(Math.ceil(100/this.zoom),50)),n=n+i;var a,i=function(e){var t=(e=o.find(".pdfemb-page"+e)).find(".pdfemb-the-canvas");t.length&&(t.remove(),e.data("invalidation-round",0))},o=this.divContainer.find("div.pdfemb-pagescontainer");for(a=3;a<e-n;++a)i(a);for(a=e+t;a<this.numPages;++a)i(a)},o.prototype.resizeViewer=function(){var e=this.pageWidth,t=this.pageHeight,o=this.divContainer,s=o.find("div.pdfemb-pagescontainer"),r=s[0].scrollLeft,d=s[0].scrollTop,h=o.parent().width(),p=e;"max"==o.data("width")?p=h:"auto"==o.data("width")?p=e:(p=parseInt(o.data("width"),10),(isNaN(p)||0>=p)&&(p=h)),0>=p&&(p=e),p>h&&0<h&&(p=h);t=t*p/e;var c=this.pdfembWantMobile(p,f);this.wantMobile=c;var m=o.find("div.pdfemb-toolbar-fixed"),l=c?0:m.length,f=parseInt(o.data("height"),10);(isNaN(f)||0>=f||f>t)&&(f="auto"==o.data("height")?o.parent().height()-l*m.height():t),this.userHeight=f;p=Math.floor(p),t=Math.floor(t),h=100;var u=p-(this.vscrollbar?a:0),g=t-(this.hscrollbar?i:0),v=1;c||16777e3<(u=u*(h=this.zoom)/100)*(g=g*h/100)*n*n&&(v=16777e3/(u*g*n*n)),p!=o.width()&&o.width(p),o.height()!=f&&o.height(f+l*m.height()),s.width(p),s.height(f),o=m.filter(".pdfemb-toolbar-top"),0<l&&s.css("top",o.height()),e=(p-(this.vscrollbar?a:0))/e,0!=this.fromZoom&&0!=this.toZoom&&(s[0].scrollLeft=this.toZoom/this.fromZoom*(r+this.pccentreLeft)-this.pccentreLeft,s[0].scrollTop=this.toZoom/this.fromZoom*(d+this.pccentreTop)-this.pccentreTop),this.toZoom=this.fromZoom=0,this.wantCanvasWidth=u,this.wantCanvasHeight=g,this.reducefactor=v,this.wantWidth=p,this.wantHeight=t,this.canvasscale=e,this.zoom=h},o.prototype.getTopVisiblePageNum=function(){var e=this.divContainer.find(".pdfemb-pagescontainer").find(".pdfemb-inner-div:visible");return 0<e.length?e.first().data("pageNum"):1},o.prototype.gotoPage=function(e){0>=e||e>this.pageCount||(this.renderPage(e,!0),this.currentPageNum=e,this.updatePageNumDisplay(e),this.prerenderNearbyPages(e),this.deallocateFarAwayPages(e))},o.prototype.updatePageNumDisplay=function(t){var n=this.divContainer;n.find("div.pdfemb-toolbar .pdfemb-page-num").each(function(n,a){var i=e(a);i.is("span")?i.text(t):i.val(t)}),t<this.pageCount?n.find(".pdfemb-next").removeAttr("disabled").removeClass("pdfemb-btndisabled"):n.find(".pdfemb-next").attr("disabled","disabled").addClass("pdfemb-btndisabled"),1<t?n.find(".pdfemb-prev").removeAttr("disabled").removeClass("pdfemb-btndisabled"):n.find(".pdfemb-prev").attr("disabled","disabled").addClass("pdfemb-btndisabled")},o.prototype.scrollPageIntoView=function(e){var t=this.divContainer.find(".pdfemb-pagescontainer"),n=t.find(".pdfemb-page"+e);t.find(".pdfemb-inner-div").not(".pdfemb-page"+e).hide(),n.show(),t[0].scrollTop=0},o.prototype.renderPage=function(t,a){var i=this,o=i.invalidationRound,s=this.divContainer,r=s.data("pdfDoc"),d=s.find(".pdfemb-pagescontainer"),h=d.find(".pdfemb-page"+t);if(h.length&&h.data("invalidation-round")>=o)a&&i.scrollPageIntoView(t);else{var p=h.data("pending-drawing-round");p>=o||(0<p&&p<o?h.data("pending-drawing-round",o):(h.data("pending-drawing-round",o),r.getPage(t).then(function(r){i.initialResize||(i.initialResize=!0,i.setSizesBasedOnPage(r),i.resizeViewer(),i.createPageInnerDivs(),i.addGrabToPan(),i.pdfembMakeMobile()),0==h.length&&(h=d.find(".pdfemb-page"+t));var c=h.data("widthfactor"),m=h.data("heightfactor");if(!c||!m){c=(g=r.getViewport(1)).width/i.pageWidth,m=g.height/i.pageHeight;h.data("widthfactor",c),h.data("heightfactor",m),1==c&&1==m||i.resizeInnerDivs(t)}var l=h.find(".pdfemb-the-canvas");0==l.length&&(l=e("<canvas></canvas>",{class:"pdfemb-the-canvas"}),h.append(l)),a&&i.scrollPageIntoView(t);var f=i.wantCanvasWidth,u=i.wantCanvasHeight,g=i.canvasscale,v=i.zoom;l.css("width",f*c),l.css("height",u*m),i.wantMobile?s.data("grabtopan").deactivate():s.data("grabtopan").activate();var b=r.getViewport(g*v/100),w=document.createElement("canvas");w.width=f*n*i.reducefactor*c,w.height=u*n*i.reducefactor*m;var P=w.getContext("2d"),y=function(){l[0].width=f*n*i.reducefactor*c,l[0].height=u*n*i.reducefactor*m,i.preRenderCanvas(P,t,v);var e=P.getImageData(0,0,w.width,w.height);l[0].getContext("2d").putImageData(e,0,0),e=null,void 0===i.annotationLayerFactories[t]?(e=i.annotationsLayerFactory.createAnnotationsLayerBuilder(h[0],r),i.annotationLayerFactories[t]=e):e=i.annotationLayerFactories[t],null!=e&&e.setupAnnotations(b,i.divContainer.data("newwindow")),h.data("invalidation-round",o),p=h.data("pending-drawing-round"),h.data("pending-drawing-round",""),p>o&&i.renderPage(t,!1)};r.render({canvasContext:P,viewport:b,transform:[n*i.reducefactor,0,0,n*i.reducefactor,0,0]}).promise.then(function(){"requestAnimationFrame"in window?window.requestAnimationFrame(y):setTimeout(y,1)})})))}},o.prototype.changeZoom=function(e){var t=this.divContainer,n=this.zoom;this.zoom=e=n+e,t.find("span.pdfemb-zoom").text(e+"%"),this.fromZoom=n,this.toZoom=e,t=t.find(".pdfemb-pagescontainer"),this.pccentreLeft=t.width()/2,this.pccentreTop=t.height()/2,this.resizeViewer(),this.resizeInnerDivs(),this.invalidateAllPages(),this.renderPage(this.currentPageNum),this.prerenderNearbyPages(this.currentPageNum)},o.prototype.queueRenderPage=function(e,t){this.renderPage(e,t)},o.prototype.addToolbar=function(t,n,a){var i=this.divContainer,o=this,s=e("<div></div>",{class:"pdfemb-toolbar pdfemb-toolbar"+(n?"-fixed":"-hover")+" "+(t?" pdfemb-toolbar-top":"pdfemb-toolbar-bottom")}),r=e('<button class="pdfemb-prev" title="'+pdfemb_trans.objectL10n.prev+'" type="button"></button>');s.append(r);var d=e('<button class="pdfemb-next" title="'+pdfemb_trans.objectL10n.next+'" type="button"></button>');s.append(d),s.append(e('<div class="pdfemb-page-area">'+pdfemb_trans.objectL10n.page+' <span class="pdfemb-page-num">0</span> / <span class="pdfemb-page-count"></span></div>'));var h=e('<button class="pdfemb-zoomout" title="'+pdfemb_trans.objectL10n.zoomout+'" type="button"></button>');s.append(h);var p=e('<button class="pdfemb-zoomin" title="'+pdfemb_trans.objectL10n.zoomin+'" type="button"></button>');s.append(p),s.append(e("<div>"+pdfemb_trans.objectL10n.zoom+' <span class="pdfemb-zoom">100%</span></div>')),a&&s.append(e("<div>"+pdfemb_trans.objectL10n.secure+"</div>")),t?i.prepend(s):i.append(s),r.on("click",function(e){1>=o.currentPageNum||(o.gotoPage(o.currentPageNum-1),o.jumpToTop())}),d.on("click",function(e){o.currentPageNum>=o.pageCount||0==o.currentPageNum||(o.gotoPage(o.currentPageNum+1),o.jumpToTop())}),p.on("click",function(e){500<=o.zoom||o.changeZoom(10)}),h.on("click",function(e){20>=o.zoom||o.changeZoom(-10)}),o.addMoreToolbar(s),n||(i.on("mouseenter",function(e){!0!==(e=i.find("div.pdfemb-toolbar-hover")).data("no-hover")&&e.show()}),i.on("mouseleave",function(e){i.find("div.pdfemb-toolbar-hover").hide()}),i.on("pdfembTouchTapped",function(e){if(e.stopPropagation(),e.preventDefault(),!o.locktaps){o.locktaps=!0;var t=(e=i.find("div.pdfemb-toolbar-hover")).is(":visible");1==e.data("no-hover")&&(t=!0),t?e.hide():e.show(),setTimeout(function(){o.locktaps=!1},250)}})),"on"==pdfemb_trans.poweredby&&s.append(e("<div class='poweredby'>Powered by </div>",{class:"pdfemb-poweredby"}).append(e('<a href="https://wp-pdf.com/?utm_source=Poweredby&utm_medium=freemium&utm_campaign=Freemium" target="_blank">wp-pdf.com</a>')))},o.prototype.magnifyEvent=function(e){var t=e.originalEvent.magnification;if(-1==t)this.resizeViewer(),this.resizeInnerDivs(),this.invalidateAllPages(),this.renderPage(this.getTopVisiblePageNum());else{var n=this.divContainer.find(".pdfemb-pagescontainer").offset();this.magnifyZoom(t,e.originalEvent.centreLeft-n.left,e.originalEvent.centreTop-n.top)}},o.prototype.magnifyZoom=function(e,t,n){var a=this.zoom;20>(e=Math.floor(a*e))&&(e=20),500<e&&(e=500),this.zoom=e,this.divContainer.find("span.pdfemb-zoom").text(e+"%"),this.fromZoom=a,this.toZoom=e,this.pccentreLeft=t,this.pccentreTop=n,this.resizeViewer(),this.resizeInnerDivs(),this.invalidateAllPages()},o.prototype.pdfembWantMobile=function(e,t){return!1},o.prototype.pdfembMakeMobile=function(){},o.prototype.addMoreToolbar=function(e){},o.prototype.jumpToTop=function(){},o.prototype.preRenderCanvas=function(e,t,n){},PDFEMB_NS.pdfembPagesViewer=o}),jQuery(document).ready(function(e){var t=PDFEMB_NS.pdfembPagesViewer;(e=function(){t.apply(this,arguments)}).prototype=new t,PDFEMB_NS.pdfembPagesViewerUsable=e}),PDFEMB_NS.pdfembGetPDF=function(e,t){t(e,!1)},jQuery(document).ready(function(e){e.fn.pdfEmbedder=function(){return this.each(function(t,n){var a,i=e(n);if(i.is("a")){var o=i.data();(a=e("<div></div>",{class:i.attr("class"),style:i.attr("style")})).data(e.extend({"pdf-url":i.attr("href")},o)),i.replaceWith(a)}else a=i;a.append(e("<div></div>",{class:"pdfemb-loadingmsg"}).append(document.createTextNode(pdfemb_trans.objectL10n.loading))),"on"==a.data("disablerightclick")&&a.bind("contextmenu",function(e){e.preventDefault()});var s=function(e,t){new PDFEMB_NS.pdfembPagesViewerUsable(e,a,t).setup()};if(a.data("pdfDoc"))s(a.data("pdfDoc"),a.data("showIsSecure"));else{var r=a.data("pdf-url");PDFEMB_NS.pdfembGetPDF(r,function(t,n){null!==t?pdfjsLib.getDocument(t).promise.then(function(e){s(e,n)},function(t){var n=document.createTextNode(t.message);"UnknownErrorException"==t.name&&"Failed to fetch"==t.message&&(n=e("<span></span>").append(document.createTextNode(t.message+" "+pdfemb_trans.objectL10n.domainerror+" ")).append(e('<a href="https://wp-pdf.com/kb/error-url-to-the-pdf-file-must-be-on-exactly-the-same-domain-as-the-current-web-page/" target="_blank">'+pdfemb_trans.objectL10n.clickhereinfo+"</a>"))),a.empty().append(e("<div></div>",{class:"pdfemb-errormsg"}).append(n))}):a.empty().append(e("<div></div>",{class:"pdfemb-errormsg"}).append(msgnode=e("<span></span>").append(document.createTextNode("Failed to load and decrypt PDF"))))})}}),this},e(".pdfemb-viewer").pdfEmbedder()}); |