summaryrefslogtreecommitdiff
path: root/test/data/html
diff options
context:
space:
mode:
Diffstat (limited to 'test/data/html')
-rw-r--r--test/data/html/test-document2-script.js40
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);