Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Maps block doesn't work in blocks.wp-a2z.org #188

Closed
bobbingwide opened this issue Dec 29, 2021 · 4 comments
Closed

Google Maps block doesn't work in blocks.wp-a2z.org #188

bobbingwide opened this issue Dec 29, 2021 · 4 comments

Comments

@bobbingwide
Copy link
Owner

bobbingwide commented Dec 29, 2021

While investigating a problem with Yoast's Google Map block I noticed that the Google Maps block doesn't appear to work in blocks.wp-a2z.org. There's just an empty space where the map should appear. It works fine in other sites.
It would appear that the inline Javascript is not being run. I don't know why not.

Reading https://stackoverflow.com/questions/5156388/how-to-set-breakpoints-in-inline-javascript-in-google-chrome/39156149#39156149 helped a bit but...

@bobbingwide
Copy link
Owner Author

I can set a breakpoint on the window.onload=initialize0; line but nothing seems to happen.

<div>
                <h3>Map</h3>
                <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?&amp;region=GB&amp;key=AIzaSyBU6GyrIrVZZ0auvDzz_x0Xl1TzbcYrPJU"></script>
                <script type="text/javascript">
                    function initialize0() {
                        var latlng = new google.maps.LatLng(50.8879011,-0.9652489);
                        var myOptions = {
                            zoom: 12,
                            center: latlng,
                            mapTypeId: google.maps.MapTypeId.ROADMAP
                        };
                        var map = new google.maps.Map(document.getElementById("bw_map_canvas0"),myOptions);
                        var marker = new google.maps.Marker({
                            position: latlng,
                            title: "PO6&nbsp;6DE"
                        });
                        marker.setMap(map);
                        var contentString = 'WordPress Blocks Reference PO6&nbsp;6DE';
                        var infowindow = new google.maps.InfoWindow({
                            content: contentString
                        });
                        infowindow.open(map, marker);
                    }
                    window.onload = initialize0;
                </script>
                <div class="bw_map_canvas" id="bw_map_canvas0" style="min-height: 200px; width:100%; height:400px;"></div>
            </div>

@bobbingwide
Copy link
Owner Author

bobbingwide commented Dec 29, 2021

Hmm. this appears to be a problem with two bits of JavaScript both setting window.onload to a function and the second one overriding the first.

The second function is in view.min.js

  • loaded from Gutenberg in 12.1.0 and WordPress 5.8 on blocks.wp-a2z.org;
    ie wp-content/plugins/gutenberg/build/block-library/blocks/navigation/view.min.js

  • loaded from WordPress in 5.9.beta2 and beta3; ie wp-includes/blocks/navigation/view.min.js

So why's it working on my local development environment?

@bobbingwide
Copy link
Owner Author

bobbingwide commented Dec 29, 2021

Updating the production site to Gutenberg 12.2.0 resolved the issue.
There was a fix in Gutenberg to replace window.onload with window.addEventListener( 'load', function )

For the fix see WordPress/gutenberg#37135
For the problem report see WordPress/gutenberg#35768

It would make sense to update oik to also use window.addEventListener()

@bobbingwide bobbingwide self-assigned this Dec 29, 2021
@bobbingwide
Copy link
Owner Author

I made the change and tested locally. The code still works. Not a complete test since I wasn't able to reproduce the problem locally.

I did notice one other anomaly. When oik-user is activated then the marker is not shown. This is because the postcode is not set for the current user.

Questions:

  • Does the block support an alt=0 setting?
  • Should the shortcode be [bw_show_googlemap alt=0]?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant