JAVASCRIPT   43

pdfobject.js

Guest on 31st August 2021 10:05:14 AM

  1. /*
  2.         PDFObject, copyright (C) Philip Hutchison (pipwerks.com)
  3.         Documentation and examples are at www.pdfobject.com
  4.         Version 1.0, September
  5.         MIT style license
  6. */
  7.  
  8. var pipwerks=pipwerks||{};
  9. pipwerks.pdfUTILS={termFound:function(a,b){return(a.indexOf(b)!==-1)},detect:{hasReaderActiveX:function(){var a=null;
  10. if(window.ActiveXObject){a=new ActiveXObject("AcroPDF.PDF");
  11. if(!a){a=new ActiveXObject("PDF.PdfCtrl")}if(a!==null){return true}}return false},hasReader:function(){var a=pipwerks.pdfUTILS.termFound;var n=navigator.plugins;
  12. for(var i=0;i<n.length;i++){var b=n[i].name;if(a(b,"Adobe Reader")||a(b,"Adobe PDF")||a(b,"Acrobat")){return true}}return false},hasGeneric:function(){var a=navigator.mimeTypes["application/pdf"];
  13. return(a&&a.enabledPlugin)},pluginFound:function(){var a=null;var b=pipwerks.pdfUTILS.detect;if(b.hasReader()||b.hasReaderActiveX()){a="Adobe"}else if(b.hasGeneric()){a="generic"}return a}},setCssForFullWindowPdf:function(){if(!document.getElementsByTagName){return false}var a=document.getElementsByTagName("html");
  14. if(!a){return false}var c=a[0];
  15. c.style.height="100%";c.style.overflow="hidden";var b=document.body;b.style.margin="0";b.style.padding="0";b.style.height="100%";
  16. b.style.overflow="hidden"},buildQueryString:function(a){var b="";
  17. if(!a){return b}for(var c in a){if(a.hasOwnProperty(c)){b+=c+"=";
  18. if(c==="search"){b+=encodeURI(a[c])}else{b+=a[c]}b+="&"}}return b.slice(0,b.length-1)}};
  19. pipwerks.pdfObject=function(a){if(!document.getElementById||!a.url){return false}this.url=encodeURI(a.url)+"#";
  20. this.id=a.id||false;this.width=a.width||"100%";
  21. this.height=a.height||"100%";
  22. this.pdfOpenParams=a.pdfOpenParams;this.url+=pipwerks.pdfUTILS.buildQueryString(this.pdfOpenParams);
  23. this.pluginTypeFound=pipwerks.pdfUTILS.detect.pluginFound();this.pdfobjectversion="1.0";return this};
  24. pipwerks.pdfObject.prototype.get=function(a){var b=null;switch(a){case"url":b=this.url;break;
  25. case"id":b=this.id;break;case"width":b=this.width;break;
  26. case"height":b=this.height;break;
  27. case"pdfOpenParams":b=this.pdfOpenParams;break;
  28. case"pluginTypeFound":b=this.pluginTypeFound;
  29. break;case"pdfobjectversion":b=this.pdfobjectversion;
  30. break}return b};
  31. pipwerks.pdfObject.prototype.embed=function(a){if(!this.pluginTypeFound){return false}if(!document.createElement||!document.getElementById){return false}var b=/*@cc_on!@*/false;
  32. var c=null;if(a){c=document.getElementById(a);if(!c){return false}}else{c=document.body;pipwerks.pdfUTILS.setCssForFullWindowPdf();
  33. this.width="100%";this.height="100%"}var d;if(b){d=document.createElement("<object classid='CLSID:CA8A9780-280D-11CF-A24D-444553540000'>")}else{d=document.createElement("object")}d.setAttribute("type","application/pdf");
  34. d.setAttribute("data",this.url);
  35. d.setAttribute("width",this.width);
  36. d.setAttribute("height",this.height);
  37. if(this.id){d.setAttribute("id",this.id)}if(c.hasChildNodes){while(c.childNodes.length>0){c.removeChild(c.firstChild)}}c.appendChild(d);return d};var PDFObject=pipwerks.pdfObject;

Raw Paste


Login or Register to edit or fork this paste. It's free.