view.js 2.2 KB

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