1/*global ActiveXObject, window, console, define, module, jQuery */ 2//jshint unused:false, strict: false 3 4/* 5 PDFObject v2.1.1 6 https://github.com/pipwerks/PDFObject 7 Copyright (c) 2008-2018 Philip Hutchison 8 MIT-style license: http://pipwerks.mit-license.org/ 9 UMD module pattern from https://github.com/umdjs/umd/blob/master/templates/returnExports.js 10*/ 11 12(function (root, factory) { 13 if (typeof define === 'function' && define.amd) { 14 // AMD. Register as an anonymous module. 15 define([], factory); 16 } else if (typeof module === 'object' && module.exports) { 17 // Node. Does not work with strict CommonJS, but 18 // only CommonJS-like environments that support module.exports, 19 // like Node. 20 module.exports = factory(); 21 } else { 22 // Browser globals (root is window) 23 root.PDFObject = factory(); 24 } 25}(this, function () { 26 27 "use strict"; 28 //jshint unused:true 29 30 //PDFObject is designed for client-side (browsers), not server-side (node) 31 //Will choke on undefined navigator and window vars when run on server 32 //Return boolean false and exit function when running server-side 33 34 if(typeof window === "undefined" || typeof navigator === "undefined"){ return false; } 35 36 var pdfobjectversion = "2.1.1", 37 ua = window.navigator.userAgent, 38 39 //declare booleans 40 supportsPDFs, 41 isIE, 42 supportsPdfMimeType = (typeof navigator.mimeTypes['application/pdf'] !== "undefined"), 43 supportsPdfActiveX, 44 isModernBrowser = (function (){ return (typeof window.Promise !== "undefined"); })(), 45 isFirefox = (function (){ return (ua.indexOf("irefox") !== -1); } )(), 46 isFirefoxWithPDFJS = (function (){ 47 //Firefox started shipping PDF.js in Firefox 19. 48 //If this is Firefox 19 or greater, assume PDF.js is available 49 if(!isFirefox){ return false; } 50 //parse userAgent string to get release version ("rv") 51 //ex: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:57.0) Gecko/20100101 Firefox/57.0 52 return (parseInt(ua.split("rv:")[1].split(".")[0], 10) > 18); 53 })(), 54 isIOS = (function (){ return (/iphone|ipad|ipod/i.test(ua.toLowerCase())); })(), 55 56 //declare functions 57 createAXO, 58 buildFragmentString, 59 log, 60 embedError, 61 embed, 62 getTargetElement, 63 generatePDFJSiframe, 64 generateEmbedElement; 65 66 67 /* ---------------------------------------------------- 68 Supporting functions 69 ---------------------------------------------------- */ 70 71 createAXO = function (type){ 72 var ax; 73 try { 74 ax = new ActiveXObject(type); 75 } catch (e) { 76 ax = null; //ensure ax remains null 77 } 78 return ax; 79 }; 80 81 //IE11 still uses ActiveX for Adobe Reader, but IE 11 doesn't expose 82 //window.ActiveXObject the same way previous versions of IE did 83 //window.ActiveXObject will evaluate to false in IE 11, but "ActiveXObject" in window evaluates to true 84 //so check the first one for older IE, and the second for IE11 85 //FWIW, MS Edge (replacing IE11) does not support ActiveX at all, both will evaluate false 86 //Constructed as a method (not a prop) to avoid unneccesarry overhead -- will only be evaluated if needed 87 isIE = function (){ return !!(window.ActiveXObject || "ActiveXObject" in window); }; 88 89 //If either ActiveX support for "AcroPDF.PDF" or "PDF.PdfCtrl" are found, return true 90 //Constructed as a method (not a prop) to avoid unneccesarry overhead -- will only be evaluated if needed 91 supportsPdfActiveX = function (){ return !!(createAXO("AcroPDF.PDF") || createAXO("PDF.PdfCtrl")); }; 92 93 //Determines whether PDF support is available 94 supportsPDFs = ( 95 //as of iOS 12, inline PDF rendering is still not supported in Safari or native webview 96 //3rd-party browsers (eg Chrome, Firefox) use Apple's webview for rendering, and thus the same result as Safari 97 //Therefore if iOS, we shall assume that PDF support is not available 98 !isIOS && ( 99 //Modern versions of Firefox come bundled with PDFJS 100 isFirefoxWithPDFJS || 101 //Browsers that still support the original MIME type check 102 supportsPdfMimeType || ( 103 //Pity the poor souls still using IE 104 isIE() && supportsPdfActiveX() 105 ) 106 ) 107 ); 108 109 //Create a fragment identifier for using PDF Open parameters when embedding PDF
110 buildFragmentString = function(pdfParams){ 111 112 var string = "", 113 prop; 114 115 if(pdfParams){ 116 117 for (prop in pdfParams) { 118 if (pdfParams.hasOwnProperty(prop)) { 119 string += encodeURIComponent(prop) + "=" + encodeURIComponent(pdfParams[prop]) + "&"; 120 } 121 } 122 123 //The string will be empty if no PDF Params found 124 if(string){ 125 126 string = "#" + string; 127 128 //Remove last ampersand 129 string = string.slice(0, string.length - 1); 130 131 } 132 133 } 134 135 return string; 136 137 }; 138 139 log = function (msg){ 140 if(typeof console !== "undefined" && console.log){ 141 console.log("[PDFObject] " + msg); 142 } 143 }; 144 145 embedError = function (msg){ 146 log(msg); 147 return false; 148 }; 149 150 getTargetElement = function (targetSelector){ 151 152 //Default to body for full-browser PDF 153 var targetNode = document.body; 154 155 //If a targetSelector is specified, check to see whether 156 //it's passing a selector, jQuery object, or an HTML element 157 158 if(typeof targetSelector === "string"){ 159 160 //Is CSS selector 161 targetNode = document.querySelector(targetSelector); 162 163 } else if (typeof jQuery !== "undefined" && targetSelector instanceof jQuery && targetSelector.length) { 164 165 //Is jQuery element. Extract HTML node 166 targetNode = targetSelector.get(0); 167 168 } else if (typeof targetSelector.nodeType !== "undefined" && targetSelector.nodeType === 1){ 169 170 //Is HTML element 171 targetNode = targetSelector; 172 173 } 174 175 return targetNode; 176 177 }; 178 179 generatePDFJSiframe = function (targetNode, url, pdfOpenFragment, PDFJS_URL, id){ 180 181 var fullURL = PDFJS_URL + "?file=" + encodeURIComponent(url) + pdfOpenFragment; 182 var scrollfix = (isIOS) ? "-webkit-overflow-scrolling: touch; overflow-y: scroll; " : "overflow: hidden; "; 183 var iframe = "<div style='" + scrollfix + "position: absolute; top: 0; right: 0; bottom: 0; left: 0;'><iframe " + id + " src='" + fullURL + "' style='border: none; width: 100%; height: 100%;' frameborder='0'></iframe></div>"; 184 targetNode.className += " pdfobject-container"; 185 targetNode.style.position = "relative"; 186 targetNode.style.overflow = "auto"; 187 targetNode.innerHTML = iframe; 188 return targetNode.getElementsByTagName("iframe")[0]; 189 190 }; 191 192 generateEmbedElement = function (targetNode, targetSelector, url, pdfOpenFragment, width, height, id){ 193 194 var style = ""; 195 196 if(targetSelector && targetSelector !== document.body){ 197 style = "width: " + width + "; height: " + height + ";"; 198 } else { 199 style = "position: absolute; top: 0; right: 0; bottom: 0; left: 0; width: 100%; height: 100%;"; 200 } 201 202 targetNode.className += " pdfobject-container"; 203 targetNode.innerHTML = "<iframe " + id + " id='pdfFrame' class='pdfobject' src='" + url + pdfOpenFragment + "#view=FitH&toolbar=0' frameborder='0' scrolling='no' seamless='' allowfullscreen='allowfullscreen' style='overflow: auto; " + style + "'/></iframe>"; 204 return targetNode.getElementsByTagName("embed")[0]; 205 206 }; 207 208 embed = function(url, targetSelector, BASE_URL,options){ 209 210 //Ensure URL is available. If not, exit now. 211 if(typeof url !== "string"){ return embedError("URL is not valid"); } 212 213 //If targetSelector is not defined, convert to boolean 214 targetSelector = (typeof targetSelector !== "undefined") ? targetSelector : false; 215 216 //Ensure options object is not undefined -- enables easier error checking below 217 options = (typeof options !== "undefined") ? options : {}; 218 219 //Get passed options, or set reasonable defaults 220 var id = (options.id && typeof options.id === "string") ? "id='" + options.id + "'" : "", 221 page = (options.page) ? options.page : false, 222 pdfOpenParams = (options.pdfOpenParams) ? options.pdfOpenParams : {}, 223 fallbackLink = (typeof options.fallbackLink !== "undefined") ? options.fallbackLink : true, 224 width = (options.width) ? options.width : "100%", 225 height = (options.height) ? options.height : "100%", 226 assumptionMode = (typeof options.assumptionMode === "boolean") ? options.assumptionMode : true, 227 forcePDFJS = (typeof options.forcePDFJS === "boolean") ? options.forcePDFJS : false, 228 PDFJS_URL = (options.PDFJS_URL) ? options.PDFJS_URL : false,
229 targetNode = getTargetElement(targetSelector), 230 fallbackHTML = "", 231 pdfOpenFragment = "", 232 filename = url.split('/').pop(), 233 fallbackHTML_default = "<div style='margin-top:20%;text-align:center;'><img src='"+BASE_URL+"media/image/algo_pdf_black.png' alt='pdf'><br/><p style='padding: 12px 32px 16px 32px; text-align: center; display: inline-block; font-size: 16px;'></p><br/><a type='button' style='background-color: #4073e9; border: none; color: white;padding: 12px 32px 16px 32px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px;' target='_blank' href='[url]'>Open</a></div>"; 234 235 //If target element is specified but is not valid, exit without doing anything 236 if(!targetNode){ return embedError("Target element cannot be determined"); } 237 238 239 //page option overrides pdfOpenParams, if found 240 if(page){ 241 pdfOpenParams.page = page; 242 } 243 244 //Stringify optional Adobe params for opening document (as fragment identifier) 245 pdfOpenFragment = buildFragmentString(pdfOpenParams); 246 247 //Do the dance 248 249 //If the forcePDFJS option is invoked, skip everything else and embed as directed 250 if(forcePDFJS && PDFJS_URL){ 251 252 return generatePDFJSiframe(targetNode, url, pdfOpenFragment, PDFJS_URL, id); 253 254 //If traditional support is provided, or if this is a modern browser and not iOS (see comment for supportsPDFs declaration) 255 } else if(supportsPDFs || (assumptionMode && isModernBrowser && !isIOS)){ 256 257 return generateEmbedElement(targetNode, targetSelector, url, pdfOpenFragment, width, height, id); 258 259 //If everything else has failed and a PDFJS fallback is provided, try to use it 260 } else if(PDFJS_URL){ 261 262 return generatePDFJSiframe(targetNode, url, pdfOpenFragment, PDFJS_URL, id); 263 264 } else { 265 266 //Display the fallback link if available 267 if(fallbackLink){ 268 269 fallbackHTML = (typeof fallbackLink === "string") ? fallbackLink : fallbackHTML_default; 270 targetNode.innerHTML = fallbackHTML.replace(/\[url\]/g, url); 271 272 } 273 274 return embedError("This browser does not support embedded PDFs"); 275 276 } 277 278 }; 279 280 return { 281 embed: function (a,b,c){ return embed(a,b,c); }, 282 pdfobjectversion: (function () { return pdfobjectversion; })(), 283 supportsPDFs: (function (){ return supportsPDFs; })() 284 }; 285 286}));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.