1;(function (window, document) { 2 'use strict' 3 4 const buttonClass = 'rgive-button', 5 frames = new Map() 6 7 function openOverlay(url) { 8 let frame = frames.get(url) 9 if (frame) { 10 toggleOverlay(frame, true) 11 toggleBackScrolling(true) 12 frame.focus() 13 } else { 14 frame = document.createElement('iframe') 15 toggleBackScrolling(true) 16 frame.id = 'rgive-overlay-' + (frames.size + 1) 17 frame.setAttribute('data-src', url) 18 // see https://developer.mozilla.org/en-US/docs/Web/API/Payment_Request_API 19 frame.setAttribute('allowpaymentrequest', 'true') 20 frame.setAttribute('allow', 'payment *; sync-xhr *') 21 frame.setAttribute('scrolling', 'yes') 22 // Inject overlay "parameter" 23 const href = new URL(url) 24 href.pathname += 'overlay/' 25 frame.src = href.toString() 26 // Prevent as much CSS bleeding from source as possible 27 frame.style.position = 'fixed' 28 frame.style.display = 'block' 29 frame.style.left = '0' 30 frame.style.top = '0' 31 frame.style.width = '100%' 32 frame.style.height = '100%' 33 frame.style.margin = '0' 34 frame.style.padding = '0' 35 frame.style.border = 'none' 36 frame.style.overflowX = 'hidden' 37 frame.style.overflowY = 'auto' 38 frame.style.visibility = 'visible' 39 frame.style.backgroundColor = 'transparent' 40 frame.style.zIndex = '2147483647' 41 document.body.appendChild(frame) 42 frame.focus() 43 frames.set(url, frame) 44 45 window.addEventListener('message', function (event) { 46 if ( 47 event.origin !== window.location.origin && 48 !['rgive-form-loaded', 'close-rgive-overlay'].includes(event.data) 49 ) { 50 return 51 } 52 53 if (event.data === 'rgive-form-loaded') { 54 frame.contentWindow.postMessage({ parentUrl: window.location.href }, event.origin) 55 } else if (event.data === 'close-rgive-overlay') { 56 toggleBackScrolling(false) 57 toggleOverlay(frame, false) 58 } 59 }) 60 } 61 return false 62 } 63 64 const initialBackScrolling = document.documentElement.style.overflow 65 66 function toggleBackScrolling(disable) { 67 document.documentElement.style.overflow = disable ? 'hidden' : initialBackScrolling 68 } 69 70 function toggleOverlay(frame, stateOpen) { 71 frame.style.display = stateOpen ? '' : 'none' 72 } 73 74 function enrichUrl(href) { 75 // Transfer query parameters from the parent page to the capsule url 76 const pageUrl = new URL(window.location) 77 const embedUrl = new URL(href) 78 pageUrl.searchParams.forEach((value, param) => { 79 embedUrl.searchParams.append(param, value) 80 }) 81 82 return embedUrl.toString() 83 } 84 85 // Install behavior on links 86 const installBehavior = function () { 87 const buttons = document.getElementsByClassName(buttonClass) 88 for (let i = 0; i < buttons.length; i++) { 89 buttons[i].setAttribute('href', enrichUrl(buttons[i].getAttribute('href'))) 90 91 buttons[i].addEventListener('click', (e) => { 92 e.preventDefault() 93 e.stopPropagation() 94 openOverlay(e.currentTarget.href) 95 }) 96 } 97 } 98 99 if (document.readyState === 'loading') { 100 // Loading hasn't finished yet 101 document.addEventListener('DOMContentLoaded', installBehavior) 102 } else { 103 // `DOMContentLoaded` has already fired 104 installBehavior() 105 } 106 107 // Inspect url to open automatically 108 const slug = new URLSearchParams(window.location.search).get('capsule') 109 if (slug) { 110 const scriptUrl = new URL(document.currentScript.src) 111 openOverlay(`${scriptUrl.protocol}//${scriptUrl.host}/${slug}/${window.location.search}`) 112 } 113})(window, document)
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.