[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/blocks/file/ -> view.js (source)

   1  /******/ (function() { // webpackBootstrap
   2  /******/     "use strict";
   3  var __webpack_exports__ = {};
   4  
   5  ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-library/build-module/file/utils.js
   6  /**
   7   * Uses a combination of user agent matching and feature detection to determine whether
   8   * the current browser supports rendering PDFs inline.
   9   *
  10   * @return {boolean} Whether or not the browser supports inline PDFs.
  11   */
  12  const browserSupportsPdfs = () => {
  13    // Most mobile devices include "Mobi" in their UA.
  14    if (window.navigator.userAgent.indexOf('Mobi') > -1) {
  15      return false;
  16    } // Android tablets are the noteable exception.
  17  
  18  
  19    if (window.navigator.userAgent.indexOf('Android') > -1) {
  20      return false;
  21    } // iPad pretends to be a Mac.
  22  
  23  
  24    if (window.navigator.userAgent.indexOf('Macintosh') > -1 && window.navigator.maxTouchPoints && window.navigator.maxTouchPoints > 2) {
  25      return false;
  26    } // IE only supports PDFs when there's an ActiveX object available for it.
  27  
  28  
  29    if (!!(window.ActiveXObject || 'ActiveXObject' in window) && !(createActiveXObject('AcroPDF.PDF') || createActiveXObject('PDF.PdfCtrl'))) {
  30      return false;
  31    }
  32  
  33    return true;
  34  };
  35  /**
  36   * Helper function for creating ActiveX objects, catching any errors that are thrown
  37   * when it's generated.
  38   *
  39   * @param {string} type The name of the ActiveX object to create.
  40   * @return {window.ActiveXObject|undefined} The generated ActiveXObject, or null if it failed.
  41   */
  42  
  43  const createActiveXObject = type => {
  44    let ax;
  45  
  46    try {
  47      ax = new window.ActiveXObject(type);
  48    } catch (e) {
  49      ax = undefined;
  50    }
  51  
  52    return ax;
  53  };
  54  /**
  55   * Hides all .wp-block-file__embed elements on the document. This function is only intended
  56   * to be run on the front-end, it may have weird side effects running in the block editor.
  57   */
  58  
  59  
  60  const hidePdfEmbedsOnUnsupportedBrowsers = () => {
  61    if (!browserSupportsPdfs()) {
  62      const embeds = document.getElementsByClassName('wp-block-file__embed');
  63      Array.from(embeds).forEach(embed => {
  64        embed.style.display = 'none';
  65      });
  66    }
  67  };
  68  
  69  ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-library/build-module/file/view.js
  70  /**
  71   * Internal dependencies
  72   */
  73  
  74  hidePdfEmbedsOnUnsupportedBrowsers();
  75  
  76  /******/ })()
  77  ;


Generated: Fri Mar 29 01:00:02 2024 Cross-referenced by PHPXref 0.7.1