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,EAAMiC,QACNzB,EAAYE,YAAc,OAC1BV,EAAME,aAAa,aAAc,UAEjC,IAAMS,EAAoBd,SAASe,cAAc,uBAE7CD,GACFA,EAAkBuB,QAEtB,CACF,M,oEAAC5C,CAAA,CAzEa,GA4EhB,W","sources":["webpack://cornell-engineering/./static/js/components/video-pause.js"],"sourcesContent":["/**\n * VideoPause\n *\n * To enable a user to pause or restart an autoplaying video\n */\n\nclass VideoPause {\n  constructor() {\n    this.initialize();\n  }\n\n  initialize() {\n    const videos = document.querySelectorAll('.wp-block-video video');\n\n    videos.forEach(video => {\n      const autoplay = video.hasAttribute('autoplay');\n\n      // If the video has autoplay attribute, add a play/pause button\n      if (autoplay) {\n        video.setAttribute('data-state', 'playing');\n        const videoID = video.getAttribute('id') || `video-${crypto.randomUUID()}`;\n        const pauseButton = document.createElement('button');\n        pauseButton.textContent = 'Pause';\n        pauseButton.setAttribute('aria-controls', videoID);\n        video.setAttribute('id', videoID);\n\n        let hiddenPauseButton = document.querySelector('.video-pause-button');\n\n        if (!hiddenPauseButton) {\n          hiddenPauseButton = pauseButton.cloneNode(true);\n          hiddenPauseButton.classList.add('video-pause-button');\n          hiddenPauseButton.classList.add('skip-to-content');\n          hiddenPauseButton.textContent = 'Pause Video';\n          // Insert as the first child of the body element.\n          document.body.insertBefore(hiddenPauseButton, document.body.firstChild);\n        } else {\n          const hiddenAriaControls = hiddenPauseButton.getAttribute('aria-controls');\n          hiddenPauseButton.setAttribute('aria-controls', `${hiddenAriaControls} ${videoID}`);\n        }\n\n        // Add click event listener to the button\n        pauseButton.addEventListener('click', () => this.togglePlayPause(video, pauseButton));\n        hiddenPauseButton.addEventListener('click', () => this.togglePlayPause(video, pauseButton));\n\n        // Append the button inside the figure element\n        const figure = video.closest('.wp-block-video');\n        if (figure) {\n          figure.appendChild(pauseButton);\n        }\n\n        // Set tabIndex=\"-1\" to make the video unfocusable via keyboard tabbing\n        video.tabIndex = -1;\n\n        // If prefers reduced motion is set, pause the video.\n        if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {\n          pauseButton.click();\n        }\n      }\n    });\n  }\n\n  // Function to toggle play/pause and update button text\n  togglePlayPause(video, pauseButton) {\n    pauseButton.blur();\n    if (video.paused) {\n      video.play();\n      pauseButton.textContent = 'Pause';\n      video.setAttribute('data-state', 'playing');\n    } else {\n      video.pause();\n      pauseButton.textContent = 'Play';\n      video.setAttribute('data-state', 'paused');\n\n      const hiddenPauseButton = document.querySelector('.video-pause-button');\n\n      if (hiddenPauseButton) {\n        hiddenPauseButton.remove();\n      }\n    }\n  }\n}\n\nexport default VideoPause;\n"],"names":["VideoPause","_classCallCheck","this","initialize","key","value","_this","document","querySelectorAll","forEach","video","hasAttribute","setAttribute","videoID","getAttribute","concat","crypto","randomUUID","pauseButton","createElement","textContent","hiddenPauseButton","querySelector","hiddenAriaControls","cloneNode","classList","add","body","insertBefore","firstChild","addEventListener","togglePlayPause","figure","closest","appendChild","tabIndex","window","matchMedia","matches","click","blur","paused","play","pause","remove"],"sourceRoot":""}