Simplify shadow test and add an open shadow DOM test (#533)
This commit is contained in:
parent
c38cd70e91
commit
f85508a25e
@ -33,10 +33,8 @@ a, a:visited {
|
|||||||
ありがとう
|
ありがとう
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<a href="#" id="fullscreen-link">Toggle fullscreen</a>
|
<a href="#" class="fullscreen-link">Toggle fullscreen</a>
|
||||||
<script>
|
<script>setup(document.body, document.body);</script>
|
||||||
document.querySelector('#fullscreen-link').addEventListener('click', () => toggleFullscreen(document.body), false);
|
|
||||||
</script>
|
|
||||||
</div>
|
</div>
|
||||||
</div></body>
|
</div></body>
|
||||||
</html>
|
</html>
|
@ -39,3 +39,27 @@ function toggleFullscreen(element) {
|
|||||||
requestFullscreen(element);
|
requestFullscreen(element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setup(container, fullscreenElement=null) {
|
||||||
|
const fullscreenLink = container.querySelector('.fullscreen-link');
|
||||||
|
if (fullscreenLink !== null) {
|
||||||
|
if (fullscreenElement === null) {
|
||||||
|
fullscreenElement = container.querySelector('.fullscreen-element');
|
||||||
|
}
|
||||||
|
fullscreenLink.addEventListener('click', (e) => {
|
||||||
|
toggleFullscreen(fullscreenElement);
|
||||||
|
e.preventDefault();
|
||||||
|
return false;
|
||||||
|
}, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 content = document.importNode(template.content, true);
|
||||||
|
setup(content);
|
||||||
|
shadow.appendChild(content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -11,88 +11,78 @@
|
|||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>Yomichan Manual Tests</h1>
|
<h1>Yomichan Manual Tests</h1>
|
||||||
<p class="description">Manual tests involving fullscreen elements, <iframe>s, and shadow DOMs.</p>
|
<y-description>Manual tests involving fullscreen elements, <iframe>s, and shadow DOMs.</y-description>
|
||||||
|
|
||||||
<div class="test">
|
<y-test>
|
||||||
<div class="description">Standard content.</div>
|
<y-description>Standard content.</y-description>
|
||||||
<div id="fullscreen-element1" style="width: 100%; height: 200px; border: 1px solid #d8d8d8; position: relative;"><div style="background-color: #f8f8f8; padding: 0.5em; position: absolute; left: 0; top: 0; bottom: 0; right: 0;">
|
<div class="fullscreen-element" style="width: 100%; height: 200px; border: 1px solid #d8d8d8; position: relative;"><div style="background-color: #f8f8f8; padding: 0.5em; position: absolute; left: 0; top: 0; bottom: 0; right: 0;">
|
||||||
<div>
|
<div>
|
||||||
ありがとう
|
ありがとう
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<a href="#" id="fullscreen-link1">Toggle fullscreen</a>
|
<a href="#" class="fullscreen-link">Toggle fullscreen</a>
|
||||||
</div>
|
</div>
|
||||||
</div></div>
|
</div></div>
|
||||||
<script>
|
</y-test>
|
||||||
document.querySelector('#fullscreen-link1').addEventListener('click', () => toggleFullscreen(document.querySelector('#fullscreen-element1')), false);
|
|
||||||
</script>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="test">
|
<y-test data-shadow-mode="open">
|
||||||
<div class="description">Content inside of a shadow DOM.</div>
|
<y-description>Content inside of an open shadow DOM.</y-description>
|
||||||
<div id="shadow-content-container"></div>
|
<div class="template-content-container"></div>
|
||||||
<template id="shadow-content-container-content-template">
|
<template>
|
||||||
<link rel="stylesheet" href="test-stylesheet.css" />
|
<link rel="stylesheet" href="test-stylesheet.css" />
|
||||||
<div id="fullscreen-element2" style="width: 100%; height: 200px; border: 1px solid #d8d8d8; position: relative;"><div style="background-color: #f8f8f8; padding: 0.5em; position: absolute; left: 0; top: 0; bottom: 0; right: 0;">
|
<div class="fullscreen-element" style="width: 100%; height: 200px; border: 1px solid #d8d8d8; position: relative;"><div style="background-color: #f8f8f8; padding: 0.5em; position: absolute; left: 0; top: 0; bottom: 0; right: 0;">
|
||||||
<div>
|
<div>
|
||||||
ありがとう
|
ありがとう
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<a href="#" id="fullscreen-link2">Toggle fullscreen</a>
|
<a href="#" class="fullscreen-link">Toggle fullscreen</a>
|
||||||
</div>
|
</div>
|
||||||
</div></div>
|
</div></div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
</y-test>
|
||||||
(() => {
|
|
||||||
const shadowIframeContainer = document.querySelector('#shadow-content-container');
|
|
||||||
const shadow = shadowIframeContainer.attachShadow({mode: 'closed'});
|
|
||||||
const template = document.querySelector('#shadow-content-container-content-template').content;
|
|
||||||
const content = document.importNode(template, true);
|
|
||||||
const fullscreenElement = content.querySelector('#fullscreen-element2');
|
|
||||||
content.querySelector('#fullscreen-link2').addEventListener('click', () => toggleFullscreen(fullscreenElement), false);
|
|
||||||
shadow.appendChild(content);
|
|
||||||
})();
|
|
||||||
</script>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="test">
|
<y-test data-shadow-mode="closed">
|
||||||
<div class="description"><iframe> element.</div>
|
<y-description>Content inside of a closed shadow DOM.</y-description>
|
||||||
|
<div class="template-content-container"></div>
|
||||||
|
<template>
|
||||||
|
<link rel="stylesheet" href="test-stylesheet.css" />
|
||||||
|
<div class="fullscreen-element" style="width: 100%; height: 200px; border: 1px solid #d8d8d8; position: relative;"><div style="background-color: #f8f8f8; padding: 0.5em; position: absolute; left: 0; top: 0; bottom: 0; right: 0;">
|
||||||
|
<div>
|
||||||
|
ありがとう
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<a href="#" class="fullscreen-link">Toggle fullscreen</a>
|
||||||
|
</div>
|
||||||
|
</div></div>
|
||||||
|
</template>
|
||||||
|
</y-test>
|
||||||
|
|
||||||
|
<y-test>
|
||||||
|
<y-description><iframe> element.</y-description>
|
||||||
<iframe src="test-document2-frame1.html" allowfullscreen="true" style="width: 100%; height: 200px; border: 1px solid #d8d8d8;"></iframe>
|
<iframe src="test-document2-frame1.html" allowfullscreen="true" style="width: 100%; height: 200px; border: 1px solid #d8d8d8;"></iframe>
|
||||||
</div>
|
</y-test>
|
||||||
|
|
||||||
<div class="test">
|
<y-test data-shadow-mode="open">
|
||||||
<div class="description"><iframe> element inside of a shadow DOM.</div>
|
<y-description><iframe> element inside of an open shadow DOM.</y-description>
|
||||||
<div id="shadow-iframe-container"></div>
|
<div class="template-content-container"></div>
|
||||||
<template id="shadow-iframe-container-content-template">
|
<template>
|
||||||
<iframe src="test-document2-frame1.html" allowfullscreen="true" style="width: 100%; height: 200px; border: 1px solid #d8d8d8;"></iframe>
|
<iframe src="test-document2-frame1.html" allowfullscreen="true" style="width: 100%; height: 200px; border: 1px solid #d8d8d8;"></iframe>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
</y-test>
|
||||||
(() => {
|
|
||||||
const shadowIframeContainer = document.querySelector('#shadow-iframe-container');
|
|
||||||
const shadow = shadowIframeContainer.attachShadow({mode: 'closed'});
|
|
||||||
const template = document.querySelector('#shadow-iframe-container-content-template').content;
|
|
||||||
const content = document.importNode(template, true);
|
|
||||||
shadow.appendChild(content);
|
|
||||||
})();
|
|
||||||
</script>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="test">
|
<y-test data-shadow-mode="closed">
|
||||||
<div class="description"><iframe> element inside of an open shadow DOM.</div>
|
<y-description><iframe> element inside of a closed shadow DOM.</y-description>
|
||||||
<div id="shadow-iframe-container-open"></div>
|
<div class="template-content-container"></div>
|
||||||
<template id="shadow-iframe-container-open-content-template">
|
<template>
|
||||||
<iframe src="test-document2-frame1.html" allowfullscreen="true" style="width: 100%; height: 200px; border: 1px solid #d8d8d8;"></iframe>
|
<iframe src="test-document2-frame1.html" allowfullscreen="true" style="width: 100%; height: 200px; border: 1px solid #d8d8d8;"></iframe>
|
||||||
</template>
|
</template>
|
||||||
|
</y-test>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
(() => {
|
for (const element of document.querySelectorAll('y-test')) {
|
||||||
const shadowIframeContainer = document.querySelector('#shadow-iframe-container-open');
|
setup(element);
|
||||||
const shadow = shadowIframeContainer.attachShadow({mode: 'open'});
|
}
|
||||||
const template = document.querySelector('#shadow-iframe-container-open-content-template').content;
|
|
||||||
const content = document.importNode(template, true);
|
|
||||||
shadow.appendChild(content);
|
|
||||||
})();
|
|
||||||
</script>
|
</script>
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -19,7 +19,8 @@ p {
|
|||||||
margin: 0.33em 0;
|
margin: 0.33em 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1+p {
|
h1+p,
|
||||||
|
h1+y-description {
|
||||||
margin-top: -0.67em;
|
margin-top: -0.67em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user