1/******/ (() => { // webpackBootstrap 2/*!*********************!*\ 3 !*** ./src/view.js ***! 4 \*********************/ 5/** 6 * Use this file for JavaScript code that you want to run in the front-end 7 * on posts/pages that contain this block. 8 * 9 * When this file is defined as the value of the `viewScript` property 10 * in `block.json` it will be enqueued on the front end of the site. 11 * 12 * Example: 13 * 14 * ```js 15 * { 16 * "viewScript": "file:./view.js" 17 * } 18 * ``` 19 * 20 * If you're not making any changes to this file because your project doesn't need any 21 * JavaScript running in the front-end, then you should delete this file and remove 22 * the `viewScript` property from `block.json`. 23 * 24 * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/#view-script 25 */ 26 27const STORAGE_ATTR = 'data-storage-key'; 28const VISIBLE_CLASS = 'thin-popup--visible'; 29const DISMISSED_VALUE = 'dismissed'; 30const ensureDataLayer = () => { 31 if (typeof window === 'undefined') { 32 return; 33 } 34 if (!Array.isArray(window.dataLayer)) { 35 window.dataLayer = []; 36 } 37}; 38const pushEvent = (action, storageKey) => { 39 ensureDataLayer(); 40 if (!window.dataLayer) { 41 return; 42 } 43 window.dataLayer.push({ 44 event: 'thinPopup', 45 thinPopupAction: action, 46 thinPopupKey: storageKey 47 }); 48}; 49const setDismissed = storageKey => { 50 try { 51 window.localStorage.setItem(storageKey, DISMISSED_VALUE); 52 } catch (error) { 53 // Silently ignore storage errors (private browsing, quota, etc.). 54 } 55}; 56const hasDismissed = storageKey => { 57 try { 58 return window.localStorage.getItem(storageKey) === DISMISSED_VALUE; 59 } catch (error) { 60 return false; 61 } 62}; 63const dismissPopup = (popup, storageKey, revealTimeout, reason) => { 64 if (popup.dataset.thinPopupDismissed === '1') { 65 return; 66 } 67 popup.dataset.thinPopupDismissed = '1'; 68 if (revealTimeout) { 69 window.clearTimeout(revealTimeout); 70 } 71 popup.classList.remove(VISIBLE_CLASS); 72 popup.addEventListener('transitionend', () => { 73 popup.remove(); 74 }, { 75 once: true 76 }); 77 setDismissed(storageKey); 78 pushEvent(reason, storageKey); 79}; 80const initPopup = popup => { 81 const storageKey = popup.getAttribute(STORAGE_ATTR) || 'thinPopupDismissed'; 82 if (hasDismissed(storageKey)) { 83 popup.remove(); 84 return; 85 } 86 const closeButton = popup.querySelector('.thin-popup__close'); 87 const link = popup.querySelector('.thin-popup__link'); 88 const revealTimeout = window.setTimeout(() => { 89 requestAnimationFrame(() => { 90 popup.classList.add(VISIBLE_CLASS); 91 pushEvent('view', storageKey); 92 }); 93 }, 3000); 94 const handleDismiss = event => { 95 if (event) { 96 event.preventDefault(); 97 } 98 dismissPopup(popup, storageKey, revealTimeout, 'dismiss-button'); 99 }; 100 closeButton?.addEventListener('click', handleDismiss); 101 link?.addEventListener('click', () => { 102 dismissPopup(popup, storageKey, revealTimeout, 'link-click'); 103 }); 104 105 // Allow the Escape key to close the popup when it has focus. 106 popup.addEventListener('keyup', event => { 107 if (event.key === 'Escape') { 108 dismissPopup(popup, storageKey, revealTimeout, 'dismiss-escape'); 109 } 110 }); 111}; 112const bootstrap = () => { 113 const popups = document.querySelectorAll('.thin-popup'); 114 popups.forEach(initPopup); 115}; 116if (document.readyState === 'loading') { 117 document.addEventListener('DOMContentLoaded', bootstrap); 118} else { 119 bootstrap(); 120} 121/******/ })() 122; 123//# sourceMappingURL=view.js.map
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.