diff options
author | Darius Jahandarie <djahandarie@gmail.com> | 2023-12-06 03:53:16 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-06 03:53:16 +0000 |
commit | bd5bc1a5db29903bc098995cd9262c4576bf76af (patch) | |
tree | c9214189e0214480fcf6539ad1c6327aef6cbd1c /test/data/html | |
parent | fd6bba8a2a869eaf2b2c1fa49001f933fce3c618 (diff) | |
parent | 23e6fb76319c9ed7c9bcdc3efba39bc5dd38f288 (diff) |
Merge pull request #339 from toasted-nutbread/type-annotations
Type annotations
Diffstat (limited to 'test/data/html')
-rw-r--r-- | test/data/html/test-document2-script.js | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/test/data/html/test-document2-script.js b/test/data/html/test-document2-script.js index 8a183019..f6082802 100644 --- a/test/data/html/test-document2-script.js +++ b/test/data/html/test-document2-script.js @@ -16,40 +16,65 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ +/** + * @param {Element} element + */ function requestFullscreen(element) { if (element.requestFullscreen) { element.requestFullscreen(); + // @ts-expect-error - Browser compatibility } else if (element.mozRequestFullScreen) { + // @ts-expect-error - Browser compatibility element.mozRequestFullScreen(); + // @ts-expect-error - Browser compatibility } else if (element.webkitRequestFullscreen) { + // @ts-expect-error - Browser compatibility element.webkitRequestFullscreen(); + // @ts-expect-error - Browser compatibility } else if (element.msRequestFullscreen) { + // @ts-expect-error - Browser compatibility element.msRequestFullscreen(); } } +/** */ function exitFullscreen() { if (document.exitFullscreen) { document.exitFullscreen(); + // @ts-expect-error - Browser compatibility } else if (document.mozCancelFullScreen) { + // @ts-expect-error - Browser compatibility document.mozCancelFullScreen(); + // @ts-expect-error - Browser compatibility } else if (document.webkitExitFullscreen) { + // @ts-expect-error - Browser compatibility document.webkitExitFullscreen(); + // @ts-expect-error - Browser compatibility } else if (document.msExitFullscreen) { + // @ts-expect-error - Browser compatibility document.msExitFullscreen(); } } +/** + * @returns {?Element} + */ function getFullscreenElement() { return ( document.fullscreenElement || + // @ts-expect-error - Browser compatibility document.msFullscreenElement || + // @ts-expect-error - Browser compatibility document.mozFullScreenElement || + // @ts-expect-error - Browser compatibility document.webkitFullscreenElement || null ); } +/** + * @param {Element} element + */ function toggleFullscreen(element) { if (getFullscreenElement()) { exitFullscreen(); @@ -58,6 +83,10 @@ function toggleFullscreen(element) { } } +/** + * @param {HTMLElement|DocumentFragment} container + * @param {?Element} [fullscreenElement] + */ function setup(container, fullscreenElement=null) { const fullscreenLink = container.querySelector('.fullscreen-link'); if (fullscreenLink !== null) { @@ -65,6 +94,7 @@ function setup(container, fullscreenElement=null) { fullscreenElement = container.querySelector('.fullscreen-element'); } fullscreenLink.addEventListener('click', (e) => { + if (fullscreenElement === null) { return; } toggleFullscreen(fullscreenElement); e.preventDefault(); return false; @@ -74,11 +104,15 @@ function setup(container, fullscreenElement=null) { const template = container.querySelector('template'); const templateContentContainer = container.querySelector('.template-content-container'); if (template !== null && templateContentContainer !== null) { - const mode = container.dataset.shadowMode; - const shadow = templateContentContainer.attachShadow({mode}); + const mode = (container instanceof HTMLElement ? container.dataset.shadowMode : void 0); + const shadow = templateContentContainer.attachShadow({ + mode: (mode === 'open' || mode === 'closed' ? mode : 'open') + }); const containerStyles = document.querySelector('#container-styles'); - shadow.appendChild(containerStyles.cloneNode(true)); + if (containerStyles !== null) { + shadow.appendChild(containerStyles.cloneNode(true)); + } const content = document.importNode(template.content, true); setup(content); |