Skip to content

Commit 032ef80

Browse files
committed
2 parents 951ac5f + 81807ce commit 032ef80

File tree

12 files changed

+106
-194
lines changed

12 files changed

+106
-194
lines changed

infinite-scroller/index.html

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@
172172
if(!node.children || node.children.length == 0)
173173
return 0;
174174
var childrenCount = Array.from(node.children).map(numDomNodes);
175-
return node.children.length + childrenCount.reduce((p, c) => p + c, 0);
175+
return node.children.length + childrenCount.reduce(function(p, c){ return p + c; }, 0);
176176
}
177177

178178
document.addEventListener('DOMContentLoaded', function() {
@@ -187,9 +187,15 @@
187187
stats.addPanel(domPanel);
188188
stats.showPanel(3);
189189
document.body.appendChild(stats.dom);
190-
setInterval(function() {
191-
domPanel.update(numDomNodes(document.body), 1500);
192-
}, 100);
190+
var TIMEOUT = 100;
191+
setTimeout(function timeoutFunc() {
192+
// Only update DOM node graph when we have time to spare to call
193+
// numDomNodes(), which is a fairly expensive function.
194+
requestIdleCallback(function() {
195+
domPanel.update(numDomNodes(document.body), 1500);
196+
setTimeout(timeoutFunc, TIMEOUT);
197+
});
198+
}, TIMEOUT);
193199

194200

195201
});

infinite-scroller/styles/messages.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
height: 100%;
99
position: absolute;
1010
box-sizing: border-box;
11-
containment: layout;
11+
contain: layout;
1212
}
1313

1414
.chat-item {
1515
display: flex;
1616
padding: 10px 0;
1717
width: 100%;
18-
containment: layout;
18+
contain: layout;
1919
}
2020

2121
.avatar {

router-advanced/about/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
<meta name="theme-color" content="#FF00FF">
2020
<title>Router</title>
2121
<link rel="stylesheet" href="/static/superstyles.css">
22+
<link rel="preload" href="/">
23+
<link rel="preload" href="/about/">
24+
<link rel="preload" href="/contact/">
25+
<!--<link rel="preload" href="/misc/">-->
2226
</head>
2327
<body>
2428
<nav>

router-advanced/contact/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
<meta name="theme-color" content="#FF00FF">
2020
<title>Router</title>
2121
<link rel="stylesheet" href="/static/superstyles.css">
22+
<link rel="preload" href="/">
23+
<link rel="preload" href="/about/">
24+
<!--<link rel="preload" href="/contact/">-->
25+
<link rel="preload" href="/misc/">
2226
</head>
2327
<body>
2428
<nav>

router-advanced/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
<meta name="theme-color" content="#FF00FF">
2020
<title>Router</title>
2121
<link rel="stylesheet" href="/static/superstyles.css">
22+
<!--<link rel="preload" href="/">-->
23+
<link rel="preload" href="/about/">
24+
<link rel="preload" href="/contact/">
25+
<link rel="preload" href="/misc/">
2226
</head>
2327
<body>
2428
<nav>

router-advanced/misc/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
<meta name="theme-color" content="#FF00FF">
2020
<title>Router</title>
2121
<link rel="stylesheet" href="/static/superstyles.css">
22+
<link rel="preload" href="/">
23+
<link rel="preload" href="/about/">
24+
<link rel="preload" href="/contact/">
25+
<!--<link rel="preload" href="/misc/">-->
2226
</head>
2327
<body>
2428
<nav>

router-advanced/static/sc-view.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ class SCView extends HTMLElement {
3838
}
3939

4040
_loadView (data) {
41-
// Create an artifical delay for testing.
42-
const delay = 1000 + Math.floor(Math.random() * 5000);
43-
4441
// Wait for half a second then show the spinner.
4542
const spinnerTimeout = setTimeout(_ => this._showSpinner(), 500);
4643

@@ -64,7 +61,7 @@ class SCView extends HTMLElement {
6461
this._hideSpinner();
6562
};
6663
xhr.responseType = 'document';
67-
xhr.open('GET', `${data[0]}?delay=${delay}`);
64+
xhr.open('GET', `${data[0]}`);
6865
xhr.send();
6966
}
7067

side-nav/detabinator.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
*
3+
* Copyright 2016 Google Inc. All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
19+
/**
20+
* Usage:
21+
* const detabinator = new Detabinator(element);
22+
* detabinator.inert = true; // Sets all focusable children of element to tabindex=-1
23+
* detabinator.inert = false; // Restores all focusable children of element
24+
* Limitations: Doesn't support Shadow DOM v0 :P
25+
*/
26+
27+
class Detabinator {
28+
constructor(element) {
29+
if (!element) {
30+
throw new Error('Missing required argument. new Detabinator needs an element reference');
31+
}
32+
this._inert = false;
33+
this._focusableElementsString = 'a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, [tabindex], [contenteditable]';
34+
this._focusableElements = Array.from(
35+
element.querySelectorAll(this._focusableElementsString)
36+
);
37+
}
38+
39+
get inert() {
40+
return this._inert;
41+
}
42+
43+
set inert(isInert) {
44+
if (this._inert === isInert) {
45+
return;
46+
}
47+
48+
this._inert = isInert;
49+
50+
this._focusableElements.forEach((child) => {
51+
if (isInert) {
52+
// If the child has an explict tabindex save it
53+
if (child.hasAttribute('tabindex')) {
54+
child.__savedTabindex = child.tabIndex;
55+
}
56+
// Set ALL focusable children to tabindex -1
57+
child.setAttribute('tabindex', -1);
58+
} else {
59+
// If the child has a saved tabindex, restore it
60+
// Because the value could be 0, explicitly check that it's not false
61+
if (child.__savedTabindex === 0 || child.__savedTabindex) {
62+
return child.setAttribute('tabindex', child.__savedTabindex);
63+
} else {
64+
// Remove tabindex from ANY REMAINING children
65+
child.removeAttribute('tabindex');
66+
}
67+
}
68+
});
69+
}
70+
}

side-nav/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
</ul>
4141
</nav>
4242
</aside>
43+
<script src='./detabinator.js'></script>
4344
<script src='./side-nav.js'></script>
4445
</body>
4546
</html>

side-nav/side-nav.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ class SideNav {
2323
this.hideButtonEl = document.querySelector('.js-menu-hide');
2424
this.sideNavEl = document.querySelector('.js-side-nav');
2525
this.sideNavContainerEl = document.querySelector('.js-side-nav-container');
26+
// Control whether the container's children can be focused
27+
// Set initial state to inert since the drawer is offscreen
28+
this.detabinator = new Detabinator(this.sideNavContainerEl);
29+
this.detabinator.inert = true;
2630

2731
this.showSideNav = this.showSideNav.bind(this);
2832
this.hideSideNav = this.hideSideNav.bind(this);
@@ -127,12 +131,14 @@ class SideNav {
127131
showSideNav () {
128132
this.sideNavEl.classList.add('side-nav--animatable');
129133
this.sideNavEl.classList.add('side-nav--visible');
134+
this.detabinator.inert = false;
130135
this.sideNavEl.addEventListener('transitionend', this.onTransitionEnd);
131136
}
132137

133138
hideSideNav () {
134139
this.sideNavEl.classList.add('side-nav--animatable');
135140
this.sideNavEl.classList.remove('side-nav--visible');
141+
this.detabinator.inert = true;
136142
this.sideNavEl.addEventListener('transitionend', this.onTransitionEnd);
137143
}
138144
}

0 commit comments

Comments
 (0)