Skip to content

Commit 5cede90

Browse files
committed
Add content visibility change handler for video grid (#39)
* remove extra changes * Add content visibility change handlers for video grid
1 parent 8b4e3bb commit 5cede90

File tree

6 files changed

+22
-22
lines changed

6 files changed

+22
-22
lines changed

experimental/responsive-design/dist/app.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

experimental/responsive-design/dist/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
margin: 0;
1212
width: 100%;
1313
height: 100%;
14-
overflow: hidden;
14+
}
15+
body {
16+
overflow: auto;
1517
}
1618
</style>
1719
<!-- Preload links autogenerated by Rollup -->

experimental/responsive-design/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
margin: 0;
1212
width: 100%;
1313
height: 100%;
14-
overflow: hidden;
14+
}
15+
body {
16+
overflow: auto;
1517
}
1618
</style>
1719
</head>

experimental/responsive-design/src/lib/components/article-grid.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class ArticleGrid extends LightDOMLitElement {
88
static properties = {
99
articles: { type: Array },
1010
};
11+
1112
constructor() {
1213
super();
1314
this.articles = articles;

experimental/responsive-design/src/lib/components/video-grid.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ class VideoGrid extends LightDOMLitElement {
1414
this.videos = videos;
1515
}
1616

17+
async _onContentVisibilityChange(_) {
18+
await this.updateComplete;
19+
window.dispatchEvent(new CustomEvent("video-grid-content-visibility-complete"));
20+
}
21+
1722
_getVideoCardsTemplate() {
1823
return this.videos.map((video) => {
1924
return html`<video-card text="${video.text}" description="${video.description}"></video-card>`;
@@ -24,7 +29,7 @@ class VideoGrid extends LightDOMLitElement {
2429
return html`
2530
<div class="flex flex-col p-2">
2631
<section-heading title="Videos" subtitle="Watch and learn from our collection of cooking videos."></section-heading>
27-
<div class="content-auto grid grid-cols-1 gap-6 p-4 lg:grid-cols-2 xl:gap-7">${this._getVideoCardsTemplate()}</div>
32+
<div class="content-auto grid grid-cols-1 gap-6 p-4 lg:grid-cols-2 xl:gap-7" @contentvisibilityautostatechange=${this._onContentVisibilityChange}>${this._getVideoCardsTemplate()}</div>
2833
</div>
2934
`;
3035
}

resources/benchmark-runner.mjs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ class Page {
3030
return this._frame.contentWindow.localStorage;
3131
}
3232

33-
layout(target = null) {
34-
// If target is provided, it should be a body element to force layout on
35-
// Otherwise force layout on the current page's body
36-
const body = target || this._frame?.contentDocument?.body || document.body;
33+
layout() {
34+
const body = this._frame ? this._frame.contentDocument.body : document.body;
3735

3836
const value = forceLayout(body, params.layoutMode);
3937
body._leakedLayoutValue = value; // Prevent dead code elimination.
@@ -73,7 +71,7 @@ class Page {
7371

7472
if (element === null)
7573
return null;
76-
return this.wrapElement(element);
74+
return this._wrapElement(element);
7775
}
7876

7977
/**
@@ -95,15 +93,15 @@ class Page {
9593
const lookupStartNode = this._frame.contentDocument;
9694
const elements = Array.from(getParent(lookupStartNode, path).querySelectorAll(selector));
9795
for (let i = 0; i < elements.length; i++)
98-
elements[i] = this.wrapElement(elements[i]);
96+
elements[i] = this._wrapElement(elements[i]);
9997
return elements;
10098
}
10199

102100
getElementById(id) {
103101
const element = this._frame.contentDocument.getElementById(id);
104102
if (element === null)
105103
return null;
106-
return this.wrapElement(element);
104+
return this._wrapElement(element);
107105
}
108106

109107
call(functionName) {
@@ -118,14 +116,14 @@ class Page {
118116
}
119117

120118
callToGetElement(functionName) {
121-
return this.wrapElement(this._frame.contentWindow[functionName]());
119+
return this._wrapElement(this._frame.contentWindow[functionName]());
122120
}
123121

124122
setWidth(widthPx) {
125123
this._frame.style.width = `${widthPx}px`;
126124
}
127125

128-
wrapElement(element) {
126+
_wrapElement(element) {
129127
return new PageElement(element);
130128
}
131129

@@ -146,14 +144,6 @@ class PageElement {
146144
this.#node = node;
147145
}
148146

149-
getContentDocument() {
150-
if (this.#node.nodeName?.toLowerCase() !== "iframe")
151-
throw new Error("getContentDocument() called on non-iframe element");
152-
if (!this.#node.contentDocument)
153-
throw new Error("Iframe contentDocument is not available.");
154-
return this.#node.contentDocument;
155-
}
156-
157147
setValue(value) {
158148
this.#node.value = value;
159149
}

0 commit comments

Comments
 (0)