@wordpress/block-library
Version:
Block library for the WordPress editor.
39 lines (38 loc) • 1.44 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
// packages/block-library/src/file/utils/index.js
/**
* Uses a combination of user agent matching and feature detection to determine whether
* the current browser supports rendering PDFs inline.
*
* @return {boolean} Whether or not the browser supports inline PDFs.
*/
const browserSupportsPdfs = () => {
if (window.navigator.pdfViewerEnabled) return true;
if (window.navigator.userAgent.indexOf("Mobi") > -1) return false;
if (window.navigator.userAgent.indexOf("Android") > -1) return false;
if (window.navigator.userAgent.indexOf("Macintosh") > -1 && window.navigator.maxTouchPoints && window.navigator.maxTouchPoints > 2) return false;
if (!!(window.ActiveXObject || "ActiveXObject" in window) && !(createActiveXObject("AcroPDF.PDF") || createActiveXObject("PDF.PdfCtrl"))) return false;
return true;
};
/**
* Helper function for creating ActiveX objects, catching any errors that are thrown
* when it's generated.
*
* @param {string} type The name of the ActiveX object to create.
* @return {window.ActiveXObject|undefined} The generated ActiveXObject, or null if it failed.
*/
const createActiveXObject = (type) => {
let ax;
try {
ax = new window.ActiveXObject(type);
} catch {
ax = void 0;
}
return ax;
};
exports.browserSupportsPdfs = browserSupportsPdfs;
//# sourceMappingURL=index.cjs.map