PageSourceSearch

https://www.wealthysinglemommy.com/wp-content/themes/wealthy-single-mommy/js/twentytwenty.js?ver=1.1

js wealthysinglemommy.com collected 2026-10-03 21:41:52 UTC 29,287 bytes, 775 lines download raw bytes

1/*	-----------------------------------------------------------------------------------------------
2	Parent file: wp-content/themes/twentytwenty/assets/js/index.js
3	Removed makeFit: function
4--------------------------------------------------------------------------------------------------- */
5
6var twentytwenty = twentytwenty || {};
7
8// Set a default value for scrolled.
9twentytwenty.scrolled = 0;
10
11// polyfill closest
12// https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Polyfill
13if ( ! Element.prototype.closest ) {
14    Element.prototype.closest = function( s ) {
15        var el = this;
16
17        do {
18            if ( el.matches( s ) ) {
19                return el;
20            }
21
22            el = el.parentElement || el.parentNode;
23        } while ( el !== null && el.nodeType === 1 );
24
25        return null;
26    };
27}
28
29// polyfill forEach
30// https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach#Polyfill
31if ( window.NodeList && ! NodeList.prototype.forEach ) {
32    NodeList.prototype.forEach = function( callback, thisArg ) {
33        var i;
34        var len = this.length;
35
36        thisArg = thisArg || window;
37
38        for ( i = 0; i < len; i++ ) {
39            callback.call( thisArg, this[ i ], i, this );
40        }
41    };
42}
43
44// event "polyfill"
45twentytwenty.createEvent = function( eventName ) {
46    var event;
47    if ( typeof window.Event === 'function' ) {
48        event = new Event( eventName );
49    } else {
50        event = document.createEvent( 'Event' );
51        event.initEvent( eventName, true, false );
52    }
53    return event;
54};
55
56// matches "polyfill"
57// https://developer.mozilla.org/es/docs/Web/API/Element/matches
58if ( ! Element.prototype.matches ) {
59    Element.prototype.matches =
60        Element.prototype.matchesSelector ||
61        Element.prototype.mozMatchesSelector ||
62        Element.prototype.msMatchesSelector ||
63        Element.prototype.oMatchesSelector ||
64        Element.prototype.webkitMatchesSelector ||
65        function( s ) {
66            var matches = ( this.document || this.ownerDocument ).querySelectorAll( s ),
67                i = matches.length;
68            while ( --i >= 0 && matches.item( i ) !== this ) {}
69            return i > -1;
70        };
71}
72
73// Add a class to the body for when touch is enabled for browsers that don't support media queries
74// for interaction media features. Adapted from <https://codepen.io/Ferie/pen/vQOMmO>.
75twentytwenty.touchEnabled = {
76
77    init: function() {
78        var matchMedia = function() {
79            // Include the 'heartz' as a way to have a non-matching MQ to help terminate the join. See <https://git.io/vznFH>.
80            var prefixes = [ '-webkit-', '-moz-', '-o-', '-ms-' ];
81            var query = [ '(', prefixes.join( 'touch-enabled),(' ), 'heartz', ')' ].join( '' );
82            return window.matchMedia && window.matchMedia( query ).matches;
83        };
84
85        if ( ( 'ontouchstart' in window ) || ( window.DocumentTouch && document instanceof window.DocumentTouch ) || matchMedia() ) {
86            document.body.classList.add( 'touch-enabled' );
87        }
88    }
89}; // twentytwenty.touchEnabled
90
91/*	-----------------------------------------------------------------------------------------------
92	Cover Modals
93--------------------------------------------------------------------------------------------------- */
94
95twentytwenty.coverModals = {
96
97    init: function() {
98        if ( document.querySelector( '.cover-modal' ) ) {
99            // Handle cover modals when they're toggled.
100            this.onToggle();
101
102            // When toggled, untoggle if visitor clicks on the wrapping element of the modal.
103            this.outsideUntoggle();
104
105            // Close on escape key press.
106            this.closeOnEscape();
107
108            // Hide and show modals before and after their animations have played out.
109            this.hideAndShowModals();
110        }
111    },
112
113    // Handle cover modals when they're toggled.
114    onToggle: function() {
115        document.querySelectorAll( '.cover-modal' ).forEach( function( element ) {
116            element.addEventListener( 'toggled', function( event ) {
117                var modal = event.target,
118                    body = document.body;
119
120                if ( modal.classList.contains( 'active' ) ) {
121                    body.classList.add( 'showing-modal' );
122                } else {
123                    body.classList.remove( 'showing-modal' );
124                    body.classList.add( 'hiding-modal' );
125
126                    // Remove the hiding class after a delay, when animations have been run.
127                    setTimeout( function() {
128                        body.classList.remove( 'hiding-modal' );
129                    }, 500 );
130                }
131            } );
132        } );
133    },
134
135    // Close modal on outside click.
136    outsideUntoggle: function() {
137        document.addEventListener( 'click', function( event ) {
138            var target = event.target;
139            var modal = document.querySelector( '.cover-modal.active' );
140
141            // if target onclick is <a> with # within the href attribute
142            if ( event.target.tagName.toLowerCase() === 'a' && event.target.hash.includes( '#' ) && modal !== null ) {
143                // untoggle the modal
144                this.untoggleModal( modal );
145                // wait 550 and scroll to the anchor
146                setTimeout( function() {
147                    var anchor = document.getElementById( event.target.hash.slice( 1 ) );
148                    anchor.scrollIntoView();
149                }, 550 );
150            }
151
152            if ( target === modal ) {
153                this.untoggleModal( target );
154            }
155        }.bind( this ) );
156    },
157
158    // Close modal on escape key press.
159    closeOnEscape: function() {
160        document.addEventListener( 'keydown', function( event ) {
161            if ( event.keyCode === 27 ) {
162                event.preventDefault();
163                document.querySelectorAll( '.cover-modal.active' ).forEach( function( element ) {
164                    this.untoggleModal( element );
165                }.bind( this ) );
166            }
167        }.bind( this ) );
168    },
169
170    // Hide and show modals before and after their animations have played out.
171    hideAndShowModals: function() {
172        var _doc = document,
173            _win = window,
174            modals = _doc.querySelectorAll( '.cover-modal' ),
175            htmlStyle = _doc.documentElement.style,
176            adminBar = _doc.querySelector( '#wpadminbar' );
177
178        function getAdminBarHeight( negativeValue ) {
179            var height,
180                currentScroll = _win.pageYOffset;
181
182            if ( adminBar ) {
183                height = currentScroll + adminBar.getBoundingClientRect().height;
184
185                return negativeValue ? -height : height;
186            }
187
188            return currentScroll === 0 ? 0 : -currentScroll;
189        }
190
191        function htmlStyles() {
192            var overflow = _win.innerHeight > _doc.documentElement.getBoundingClientRect().height;
193
194            return {
195                'overflow-y': overflow ? 'hidden' : 'scroll',
196                position: 'fixed',
197                width: '100%',
198                top: getAdminBarHeight( true ) + 'px',
199                left: 0
200            };
201        }
202
203        // Show the modal.
204        modals.forEach( function( modal ) {
205            modal.addEventListener( 'toggle-target-before-inactive', function( event ) {
206                var styles = htmlStyles(),
207                    offsetY = _win.pageYOffset,
208                    paddingTop = ( Math.abs( getAdminBarHeight() ) - offsetY ) + 'px',
209                    mQuery = _win.matchMedia( '(max-width: 600px)' );
210
211                if ( event.target !== modal ) {
212                    return;
213                }
214
215                Object.keys( styles ).forEach( function( styleKey ) {
216                    htmlStyle.setProperty( styleKey, styles[ styleKey ] );
217                } );
218
219                _win.twentytwenty.scrolled = parseInt( styles.top, 10 );
220
221                if ( adminBar ) {
222                    _doc.body.style.setProperty( 'padding-top', paddingTop );
223
224                    if ( mQuery.matches ) {
225                        if ( offsetY >= getAdminBarHeight() ) {
226                            modal.style.setProperty( 'top', 0 );
227                        } else {
228                            modal.style.setProperty( 'top', ( getAdminBarHeight() - offsetY ) + 'px' );
229                        }
230                    }
231                }
232
233                modal.classList.add( 'show-modal' );
234            } );
235
236            // Hide the modal after a delay, so animations have time to play out.
237            modal.addEventListener( 'toggle-target-after-inactive', function( event ) {
238                if ( event.target !== modal ) {
239                    return;
240                }
241
242                setTimeout( function() {
243                    var clickedEl = twentytwenty.toggles.clickedEl;
244
245                    modal.classList.remove( 'show-modal' );
246
247                    Object.keys( htmlStyles() ).forEach( function( styleKey ) {
248                        htmlStyle.removeProperty( styleKey );
249                    } );
250
251                    if ( adminBar ) {
252                        _doc.body.style.removeProperty( 'padding-top' );
253                        modal.style.removeProperty( 'top' );
254                    }
255
256                    if ( clickedEl !== false ) {
257                        clickedEl.focus();
258                        clickedEl = false;
259                    }
260
261                    _win.scrollTo( 0, Math.abs( _win.twentytwenty.scrolled + getAdminBarHeight() ) );
262
263                    _win.twentytwenty.scrolled = 0;
264                }, 500 );
265            } );
266        } );
267    },
268
269    // Untoggle a modal.
270    untoggleModal: function( modal ) {
271        var modalTargetClass,
272            modalToggle = false;
273
274        // If the modal has specified the string (ID or class) used by toggles to target it, untoggle the toggles with that target string.
275        // The modal-target-string must match the string toggles use to target the modal.
276        if ( modal.dataset.modalTargetString ) {
277            modalTargetClass = modal.dataset.modalTargetString;
278
279            modalToggle = document.querySelector( '*[data-toggle-target="' + modalTargetClass + '"]' );
280        }
281
282        // If a modal toggle exists, trigger it so all of the toggle options are included.
283        if ( modalToggle ) {
284            modalToggle.click();
285
286            // If one doesn't exist, just hide the modal.
287        } else {
288            modal.classList.remove( 'active' );
289        }
290    }
291
292}; // twentytwenty.coverModals
293
294/*	-----------------------------------------------------------------------------------------------
295	Modal Menu
296--------------------------------------------------------------------------------------------------- */
297twentytwenty.modalMenu = {
298
299    init: function() {
300        // If the current menu item is in a sub level, expand all the levels higher up on load.
301        this.expandLevel();
302        this.keepFocusInModal();
303    },
304
305    expandLevel: function() {
306        var modalMenus = document.querySelectorAll( '.modal-menu' );
307
308        modalMenus.forEach( function( modalMenu ) {
309            var activeMenuItem = modalMenu.querySelector( '.current-menu-item' );
310
311            if ( activeMenuItem ) {
312                twentytwentyFindParents( activeMenuItem, 'li' ).forEach( function( element ) {
313                    var subMenuToggle = element.querySelector( '.sub-menu-toggle' );
314                    if ( subMenuToggle ) {
315                        twentytwenty.toggles.performToggle( subMenuToggle, true );
316                    }
317                } );
318            }
319        } );
320    },
321
322    keepFocusInModal: function() {
323        var _doc = document;
324
325        _doc.addEventListener( 'keydown', function( event ) {
326            var toggleTarget, modal, selectors, elements, menuType, bottomMenu, activeEl, lastEl, firstEl, tabKey, shift
326Key,
327                clickedEl = twentytwenty.toggles.clickedEl;
328
329            if ( clickedEl && _doc.body.classList.contains( 'showing-modal' ) ) {
330                toggleTarget = clickedEl.dataset.toggleTarget;
331                selectors = 'input, a, button';
332                modal = _doc.querySelector( toggleTarget );
333
334                elements = modal.querySelectorAll( selectors );
335                elements = Array.prototype.slice.call( elements );
336
337                if ( '.menu-modal' === toggleTarget ) {
338                    menuType = window.matchMedia( '(min-width: 1000px)' ).matches;
339                    menuType = menuType ? '.expanded-menu' : '.mobile-menu';
340
341                    elements = elements.filter( function( element ) {
342                        return null !== element.closest( menuType ) && null !== element.offsetParent;
343                    } );
344
345                    elements.unshift( _doc.querySelector( '.close-nav-toggle' ) );
346
347                    bottomMenu = _doc.querySelector( '.menu-bottom > nav' );
348
349                    if ( bottomMenu ) {
350                        bottomMenu.querySelectorAll( selectors ).forEach( function( element ) {
351                            elements.push( element );
352                        } );
353                    }
354                }
355
356                lastEl = elements[ elements.length - 1 ];
357                firstEl = elements[0];
358                activeEl = _doc.activeElement;
359                tabKey = event.keyCode === 9;
360                shiftKey = event.shiftKey;
361
362                if ( ! shiftKey && tabKey && lastEl === activeEl ) {
363                    event.preventDefault();
364                    firstEl.focus();
365                }
366
367                if ( shiftKey && tabKey && firstEl === activeEl ) {
368                    event.preventDefault();
369                    lastEl.focus();
370                }
371            }
372        } );
373    }
374}; // twentytwenty.modalMenu
375
376/*	-----------------------------------------------------------------------------------------------
377	Primary Menu
378--------------------------------------------------------------------------------------------------- */
379
380twentytwenty.primaryMenu = {
381
382    init: function() {
383        this.focusMenuWithChildren();
384    },
385
386    // The focusMenuWithChildren() function implements Keyboard Navigation in the Primary Menu
387    // by adding the '.focus' class to all 'li.menu-item-has-children' when the focus is on the 'a' element.
388    focusMenuWithChildren: function() {
389        // Get all the link elements within the primary menu.
390        var links, i, len,
391            menu = document.querySelector( '.primary-menu-wrapper' );
392
393        if ( ! menu ) {
394            return false;
395        }
396
397        links = menu.getElementsByTagName( 'a' );
398
399        // Each time a menu link is focused or blurred, toggle focus.
400        for ( i = 0, len = links.length; i < len; i++ ) {
401            links[i].addEventListener( 'focus', toggleFocus, true );
402            links[i].addEventListener( 'blur', toggleFocus, true );
403        }
404
405        //Sets or removes the .focus class on an element.
406        function toggleFocus() {
407            var self = this;
408
409            // Move up through the ancestors of the current link until we hit .primary-menu.
410            while ( -1 === self.className.indexOf( 'primary-menu' ) ) {
411                // On li elements toggle the class .focus.
412                if ( 'li' === self.tagName.toLowerCase() ) {
413                    if ( -1 !== self.className.indexOf( 'focus' ) ) {
414                        self.className = self.className.replace( ' focus', '' );
415                    } else {
416                        self.className += ' focus';
417                    }
418                }
419                self = self.parentElement;
420            }
421        }
422    }
423}; // twentytwenty.primaryMenu
424
425/*	-----------------------------------------------------------------------------------------------
426	Toggles
427--------------------------------------------------------------------------------------------------- */
428
429twentytwenty.toggles = {
430
431    clickedEl: false,
432
433    init: function() {
434        // Do the toggle.
435        this.toggle();
436
437        // Check for toggle/untoggle on resize.
438        this.resizeCheck();
439
440        // Check for untoggle on escape key press.
441        this.untoggleOnEscapeKeyPress();
442    },
443
444    performToggle: function( element, instantly ) {
445        var target, timeOutTime, classToToggle,
446            self = this,
447            _doc = document,
448            // Get our targets.
449            toggle = element,
450            targetString = toggle.dataset.toggleTarget,
451            activeClass = 'active';
452
453        // Elements to focus after modals are closed.
454        if ( ! _doc.querySelectorAll( '.show-modal' ).length ) {
455            self.clickedEl = _doc.activeElement;
456        }
457
458        if ( targetString === 'next' ) {
459            target = toggle.nextSibling;
460        } else {
461            target = _doc.querySelector( targetString );
462        }
463
464        // Trigger events on the toggle targets before they are toggled.
465        if ( target.classList.contains( activeClass ) ) {
466            target.dispatchEvent( twentytwenty.createEvent( 'toggle-target-before-active' ) );
467        } else {
468            target.dispatchEvent( twentytwenty.createEvent( 'toggle-target-before-inactive' ) );
469        }
470
471        // Get the class to toggle, if specified.
472        classToToggle = toggle.dataset.classToToggle ? toggle.dataset.classToToggle : activeClass;
473
474        // For cover modals, set a short timeout duration so the class animations have time to play out.
475        timeOutTime = 0;
476
477        if ( target.classList.contains( 'cover-modal' ) ) {
478            timeOutTime = 10;
479        }
480
481        setTimeout( function() {
482            var focusElement,
483                subMenued = target.classList.contains( 'sub-menu' ),
484                newTarget = subMenued ? toggle.closest( '.menu-item' ).querySelector( '.sub-menu' ) : target,
485                duration = toggle.dataset.toggleDuration;
486
487            // Toggle the target of the clicked toggle.
488            if ( toggle.dataset.toggleType === 'slidetoggle' && ! instantly && duration !== '0' ) {
489                twentytwentyMenuToggle( newTarget, duration );
490            } else {
491                newTarget.classList.toggle( classToToggle );
492            }
493
494            // If the toggle target is 'next', only give the clicked toggle the active class.
495            if ( targetString === 'next' ) {
496                toggle.classList.toggle( activeClass );
497            } else if ( target.classList.contains( 'sub-menu' ) ) {
498                toggle.classList.toggle( activeClass );
499            } else {
500                // If not, toggle all toggles with this toggle target.
501                _doc.querySelector( '*[data-toggle-target="' + targetString + '"]' ).classList.toggle( activeClass );
502            }
503
504            // Toggle aria-expanded on the toggle.
505            twentytwentyToggleAttribute( toggle, 'aria-expanded', 'true', 'false' );
506
507            if ( self.clickedEl && -1 !== toggle.getAttribute( 'class' ).indexOf( 'close-' ) ) {
508                twentytwentyToggleAttribute( self.clickedEl, 'aria-expanded', 'true', 'false' );
509            }
510
511            // Toggle body class.
512            if ( toggle.dataset.toggleBodyClass ) {
513                _doc.body.classList.toggle( toggle.dataset.toggleBodyClass );
514            }
515
516            // Check whether to set focus.
517            if ( toggle.dataset.setFocus ) {
518                focusElement = _doc.querySelector( toggle.dataset.setFocus );
519
520                if ( focusElement ) {
521                    if ( target.classList.contains( activeClass ) ) {
522                        focusElement.focus();
523                    } else {
524                        focusElement.blur();
525                    }
526                }
527            }
528
529            // Trigger the toggled event on the toggle target.
530            target.dispatchEvent( twentytwenty.createEvent( 'toggled' ) );
531
532            // Trigger events on the toggle targets after they are toggled.
533            if ( target.classList.contains( activeClass ) ) {
534                target.dispatchEvent( twentytwenty.createEvent( 'toggle-target-after-active' ) );
535            } else {
536                target.dispatchEvent( twentytwenty.createEvent( 'toggle-target-after-inactive' ) );
537            }
538        }, timeOutTime );
539    },
540
541    // Do the toggle.
542    toggle: function() {
543        var self = this;
544
545        document.querySelectorAll( '*[data-toggle-target]' ).forEach( function( element ) {
546            element.addEventListener( 'click', function( event ) {
547                event.preventDefault();
548                self.performToggle( element );
549            } );
550        } );
551    },
552
553    // Check for toggle/untoggle on screen resize.
554    resizeCheck: function() {
555        if ( document.querySelectorAll( '*[data-untoggle-above], *[data-untoggle-below], *[data-toggle-above], *[data-toggle-below]' ).length ) {
556            window.addEventListener( 'resize', function() {
557                var winWidth = window.innerWidth,
558                    toggles = document.querySelectorAll( '.toggle' );
559
560                toggles.forEach( function( toggle ) {
561                    var unToggleAbove = toggle.dataset.untoggleAbove,
562                        unToggleBelow = toggle.dataset.untoggleBelow,
563                        toggleAbove = toggle.dataset.toggleAbove,
564                        toggleBelow = toggle.dataset.toggleBelow;
565
566                    // If no width comparison is set, continue.
567                    if ( ! unToggleAbove && ! unToggleBelow && ! toggleAbove && ! toggleBelow ) {
568                        return;
569                    }
570
571                    // If the toggle width comparison is true, toggle the toggle.
572                    if (
573                        ( ( ( unToggleAbove && winWidth > unToggleAbove ) ||
574                            ( unToggleBelow && winWidth < unToggleBelow ) ) &&
575                            toggle.classList.contains( 'active' ) ) ||
576                        ( ( ( toggleAbove && winWidth > toggleAbove ) ||
577                            ( toggleBelow && winWidth < toggleBelow ) ) &&
578                            ! toggle.classList.contains( 'active' ) )
579                    ) {
580                        toggle.click();
581                    }
582                } );
583            } );
584        }
585    },
586
587    // Close toggle on escape key press.
588    untoggleOnEscapeKeyPress: function() {
589        document.addEventListener( 'keyup', function( event ) {
590            if ( event.key === 'Escape' ) {
591                document.querySelectorAll( '*[data-untoggle-on-escape].active' ).forEach( function( element ) {
592                    if ( element.classList.contains( 'active' ) ) {
593                        element.click();
594                    }
595                } );
596            }
597        } );
598    }
599
600}; // twentytwenty.toggles
601
602/**
603 * Is the DOM ready?
604 *
605 * This implementation is coming from https://gomakethings.com/a-native-javascript-equivalent-of-jquerys-ready-method/
606 *
607 * @param {Function} fn Callback function to run.
608 */
609function twentytwentyDomReady( fn ) {
610    if ( typeof fn !== 'function' ) {
611        return;
612    }
613
614    if ( document.readyState === 'interactive' || document.readyState === 'complete' ) {
615        return fn();
616    }
617
618    document.addEventListener( 'DOMContentLoaded', fn, false );
619}
620
621twentytwentyDomReady( function() {
622    twentytwenty.toggles.init();              // Handle toggles.
623    twentytwenty.coverModals.init();          // Handle cover modals.
624    twentytwenty.intrinsicRatioVideos.init(); // Retain aspect ratio of videos on window resize.
625    twentytwenty.modalMenu.init();            // Modal Menu.
626    twentytwenty.primaryMenu.init();          // Primary Menu.
627    twentytwenty.touchEnabled.init();         // Add class to body if device is touch-enabled.
628} );
629
630/*	-----------------------------------------------------------------------------------------------
631	Helper functions
632--------------------------------------------------------------------------------------------------- */
633
634/* Toggle an attribute ----------------------- */
635
636function twentytwentyToggleAttribute( element, attribute, trueVal, falseVal ) {
637    if ( trueVal === undefined ) {
638        trueVal = true;
639    }
640    if ( falseVal === undefined ) {
641        falseVal = false;
642    }
643    if ( element.getAttribute( attribute ) !== trueVal ) {
644        element.setAttribute( attribute, trueVal );
645    } else {
646        element.setAttribute( attribute, falseVal );
647    }
648}
649
650/**
651 * Toggle a menu item on or off.
652 *
653 * @param {HTMLElement} target
654 * @param {number} duration
655 */
656function twentytwentyMenuToggle( target, duration ) {
657    var initialParentHeight, finalParentHeight, menu, menuItems, transitionListener,
658        initialPositions = [],
659        finalPositions = [];
660
661    if ( ! target ) {
662        return;
663    }
664
665    menu = target.closest( '.menu-wrapper' );
666
667    // Step 1: look at the initial positions of every menu item.
668    menuItems = menu.querySelectorAll( '.menu-item' );
669
670    menuItems.forEach( function( menuItem, index ) {
671        initialPositions[ index ] = { x: menuItem.offsetLeft, y: menuItem.offsetTop };
672    } );
673    initialParentHeight = target.parentElement.offsetHeight;
674
675    target.classList.add( 'toggling-target' );
676
677    // Step 2: toggle target menu item and look at the final positions of every menu item.
678    target.classList.toggle( 'active' );
679
680    menuItems.forEach( function( menuItem, index ) {
681        finalPositions[ index ] = { x: menuItem.offsetLeft, y: menuItem.offsetTop };
682    } );
683    finalParentHeight = target.parentElement.offsetHeight;
684
685    // Step 3: close target menu item again.
686    // The whole process happens without giving the browser a chance to render, so it's invisible.
687    target.classList.toggle( 'active' );
688
689    /*
690     * Step 4: prepare animation.
691     * Position all the items with absolute offsets, at the same starting position.
692     * Shouldn't result in any visual changes if done right.
693     */
694    menu.classList.add( 'is-toggling' );
695    target.classList.toggle( 'active' );
696    menuItems.forEach( function( menuItem, index ) {
697        var initialPosition = initialPositions[ index ];
698        if ( initialPosition.y === 0 && menuItem.parentElement === target ) {
699            initialPosition.y = initialParentHeight;
700        }
701        menuItem.style.transform = 'translate(' + initialPosition.x + 'px, ' + initialPosition.y + 'px)';
702    } );
703
704    /*
705     * The double rAF is unfortunately needed, since we're toggling CSS classes, and
706     * the only way to ensure layout completion here across browsers is to wait twice.
707     * This just delays the start of the animation by 2 frames and is thus not an issue.
708     */
709    requestAnimationFrame( function() {
710        requestAnimationFrame( function() {
711            /*
712             * Step 5: start animation by moving everything to final position.
713             * All the layout work has already happened, while we were preparing for the animation.
714             * The animation now runs entirely in CSS, using cheap CSS properties (opacity and transform)
715             * that don't trigger the layout or paint stages.
716             */
717            menu.classList.add( 'is-animating' );
718            menuItems.forEach( function( menuItem, index ) {
719                var finalPosition = finalPositions[ index ];
720                if ( finalPosition.y === 0 && menuItem.parentElement === target ) {
721                    finalPosition.y = finalParentHeight;
722                }
723                if ( duration !== undefined ) {
724                    menuItem.style.transitionDuration = duration + 'ms';
725                }
726                menuItem.style.transform = 'translate(' + finalPosition.x + 'px, ' + finalPosition.y + 'px)';
727            } );
728            if ( duration !== undefined ) {
729                target.style.transitionDuration = duration + 'ms';
730            }
731        } );
732
733        // Step 6: finish toggling.
734        // Remove all transient classes when the animation ends.
735        transitionListener = function() {
736            menu.classList.remove( 'is-animating' );
737            menu.classList.remove( 'is-toggling' );
738            target.classList.remove( 'toggling-target' );
739            menuItems.forEach( function( menuItem ) {
740                menuItem.style.transform = '';
741                menuItem.style.transitionDuration = '';
742            } );
743            target.style.transitionDuration = '';
744            target.removeEventListener( 'transitionend', transitionListener );
745        };
746
747        target.addEventListener( 'transitionend', transitionListener );
748    } );
749}
750
751/**
752 * Traverses the DOM up to find elements matching the query.
753 *
754 * @param {HTMLElement} target
755 * @param {string} query
756 * @return {NodeList} parents matching query
757 */
758function twentytwentyFindParents( target, query ) {
759    var parents = [];
760
761    // Recursively go up the DOM adding matches to the parents array.
762    function traverse( item ) {
763        var parent = item.parentNode;
764        if ( parent instanceof HTMLElement ) {
765            if ( parent.matches( query ) ) {
766                parents.push( parent );
767            }
768            traverse( parent );
769        }
770    }
771
772    traverse( target );
773
774    return parents;
775}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.