Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e8fd218c74 | |||
| 5f652530ed |
@@ -37,16 +37,6 @@
|
|||||||
<p id="eventfilter-status" class="visually-hidden" aria-live="polite"></p>
|
<p id="eventfilter-status" class="visually-hidden" aria-live="polite"></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
|
||||||
@media (prefers-reduced-motion: no-preference) {
|
|
||||||
::view-transition-old(root),
|
|
||||||
::view-transition-new(root) {
|
|
||||||
animation-duration: 240ms;
|
|
||||||
animation-timing-function: ease;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<script type="module">
|
<script type="module">
|
||||||
const filters = document.getElementById('eventfilters');
|
const filters = document.getElementById('eventfilters');
|
||||||
|
|
||||||
@@ -124,63 +114,9 @@
|
|||||||
const stateStorageKey = 'event-filter-state';
|
const stateStorageKey = 'event-filter-state';
|
||||||
const stateQueryKey = 'event_filter';
|
const stateQueryKey = 'event_filter';
|
||||||
|
|
||||||
const animationMs = 220;
|
|
||||||
let hideTimers = new WeakMap();
|
|
||||||
const supportsViewTransitions = typeof document.startViewTransition === 'function';
|
|
||||||
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
||||||
let activeViewTransition = null;
|
|
||||||
let isViewTransitionMutation = false;
|
|
||||||
let currentFilter = { type: 'all', value: '' };
|
let currentFilter = { type: 'all', value: '' };
|
||||||
let suppressedChangeEvents = 0;
|
let suppressedChangeEvents = 0;
|
||||||
|
|
||||||
const runWithLayoutTransition = (mutation) => {
|
|
||||||
if (!supportsViewTransitions || prefersReducedMotion) {
|
|
||||||
mutation();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (activeViewTransition) {
|
|
||||||
mutation();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const transition = document.startViewTransition(() => {
|
|
||||||
isViewTransitionMutation = true;
|
|
||||||
|
|
||||||
try {
|
|
||||||
mutation();
|
|
||||||
} finally {
|
|
||||||
isViewTransitionMutation = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
activeViewTransition = transition;
|
|
||||||
|
|
||||||
transition.ready.catch(() => {
|
|
||||||
// Can reject when the transition is skipped.
|
|
||||||
});
|
|
||||||
|
|
||||||
transition.updateCallbackDone.catch(() => {
|
|
||||||
// Keep skipped/aborted update callbacks from surfacing as uncaught.
|
|
||||||
});
|
|
||||||
|
|
||||||
transition.finished
|
|
||||||
.catch(() => {
|
|
||||||
// Browsers can skip overlapping transitions; ignore these rejections.
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
if (activeViewTransition === transition) {
|
|
||||||
activeViewTransition = null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
mutation();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const shouldMutateVisibilityImmediately = () => supportsViewTransitions && !prefersReducedMotion;
|
|
||||||
|
|
||||||
const hasOptionValue = (selectElement, value) => {
|
const hasOptionValue = (selectElement, value) => {
|
||||||
if (!selectElement) {
|
if (!selectElement) {
|
||||||
return false;
|
return false;
|
||||||
@@ -304,51 +240,12 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const clearHideTimer = (eventItem) => {
|
const showEvent = (eventItem) => {
|
||||||
const timer = hideTimers.get(eventItem);
|
eventItem.hidden = false;
|
||||||
|
|
||||||
if (timer) {
|
|
||||||
window.clearTimeout(timer);
|
|
||||||
hideTimers.delete(eventItem);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const showEvent = (eventItem, { immediateVisibility = false } = {}) => {
|
const hideEvent = (eventItem) => {
|
||||||
clearHideTimer(eventItem);
|
|
||||||
|
|
||||||
if (immediateVisibility) {
|
|
||||||
eventItem.hidden = false;
|
|
||||||
eventItem.classList.remove('is-filtered-out');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (eventItem.hidden) {
|
|
||||||
eventItem.hidden = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
requestAnimationFrame(() => {
|
|
||||||
eventItem.classList.remove('is-filtered-out');
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const hideEvent = (eventItem, { immediateVisibility = false } = {}) => {
|
|
||||||
clearHideTimer(eventItem);
|
|
||||||
|
|
||||||
if (immediateVisibility) {
|
|
||||||
eventItem.classList.add('is-filtered-out');
|
|
||||||
eventItem.hidden = true;
|
eventItem.hidden = true;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
eventItem.classList.add('is-filtered-out');
|
|
||||||
|
|
||||||
const timer = window.setTimeout(() => {
|
|
||||||
eventItem.hidden = true;
|
|
||||||
|
|
||||||
hideTimers.delete(eventItem);
|
|
||||||
}, animationMs);
|
|
||||||
|
|
||||||
hideTimers.set(eventItem, timer);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const setActiveControl = ({ type, value }) => {
|
const setActiveControl = ({ type, value }) => {
|
||||||
@@ -436,17 +333,13 @@
|
|||||||
currentFilter = filterState;
|
currentFilter = filterState;
|
||||||
setActiveControl(filterState);
|
setActiveControl(filterState);
|
||||||
|
|
||||||
const immediateVisibility = shouldMutateVisibilityImmediately();
|
|
||||||
|
|
||||||
runWithLayoutTransition(() => {
|
|
||||||
events.forEach((eventItem) => {
|
events.forEach((eventItem) => {
|
||||||
if (matches(eventItem, filterState)) {
|
if (matches(eventItem, filterState)) {
|
||||||
showEvent(eventItem, { immediateVisibility });
|
showEvent(eventItem);
|
||||||
} else {
|
} else {
|
||||||
hideEvent(eventItem, { immediateVisibility });
|
hideEvent(eventItem);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
updateStatus(filterState);
|
updateStatus(filterState);
|
||||||
syncState(filterState);
|
syncState(filterState);
|
||||||
|
|||||||
Reference in New Issue
Block a user