ProjectSidewalk / SidewalkWebpage

Project Sidewalk web page
http://projectsidewalk.org
MIT License
84 stars 25 forks source link

'DOMNodeInserted' is deprecated and does not work in Gallery Modal. #3616

Closed jsomeara closed 3 months ago

jsomeara commented 3 months ago
Brief description of problem/feature

I noticed this issue when I was adding keyboard shortcuts to the gallery expanded view.

Opening the gallery in Chrome, I get the following error:

jquery-1.12.2.min.js:3 [Deprecation] Listener added for a 'DOMNodeInserted' mutation event. Support for this event type has been removed, and this event will no longer be fired. See https://chromestatus.com/feature/5083947249172480 for more information.

This occurs because of the following lines in Modal.js:

        // Google Street View loads inside 'actual-pano' but there is no event triggered after it loads all the components.
        // So we need to detect it by brute-force.
        $('.actual-pano').bind('DOMNodeInserted', function(e) {
            if (e.target && e.target.className && typeof e.target.className === 'string' && e.target.className.indexOf('widget-scene-canvas') > -1) {
                $('.widget-scene-canvas').bind('mousedown', handlerViewControlLayerMouseDown).bind('mouseup', handlerViewControlLayerMouseUp);
            }
        });
Expected behavior

No error should occur, and it should properly detect the DOM changes.

Current behavior (add screenshots if applicable; check terminal & browser console for errors)

image

Steps to reproduce

Open the gallery page while the developer tools console is open.

Potential solution(s)

Use mutation observer instead of the deprecated DOMNodeInserted event.

jsomeara commented 3 months ago

Made a PR: #3617