I ok with the JS thing, if I’am right. But i don’t know how to init the plugin on first load…
Hi there
Please go to wp-google-maps/js/wpgmaps.js and replace the line where the function InitMap(); is called with the following: setTimeout(function(){ InitMap(); }, 800);
Does this help at all?
Nope, because google maps api and the wpgmaps.js scripts are not loaded.
It does work when I load a page where is a google map as first, then the scripts and the whole plugin are loaded, then when I change a page via the ajax powered theme, I can call InitMap(); in my javascript and the map is ok.
But if I load a page where is no google map, the scripts are not loaded, and then when i go to the page where is a google map, there is a blank space.
The ajax powered theme can add and run scripts placed in the content, but not in header or footer.
So i probably need to load the scripts somehow via ajax with condition has_shortcode($content, 'wpgmza'), or at the first load of wordpress i guess even if there is no google map on the page. But there is also the localization o_O
I’m more into front-end, so I’m quite short how to deal with the back-end / plugin…
After digging in the code for a while i give it up 🙂
Tried solution like this:
First i checked if content has_shortcode($content, 'wpgmza'), then with regex search for the map id and called the plugin shortcode function wpgmaps_tag_basic($id); and then from global $wp_scripts added an run the scripts and the localization properties in the content.
It does partly worked, but for me it’s too much hairy solution 🙂 I guess the plugin is not much ajax friendly written, but maybe I’m doing it wrong as well….)
Hi @spongeboob
We’re going to look into this and see if we can come up with a stable solution around this.
What theme are you using? Just so that we can try and replicate/debug on this on our side?
Yeah, it would be great if the plugin could be more ajax friendly. It’s the best google maps plugin i’ve found.
I’m using theme with custom ajax controller, but it should be same as any other ajax powered theme. Basically it fetches new page via ajax and replace the content. Scripts are to be added an run in js like this:
var $scripts = $ajaxResponse.find('#content script');
$scripts.each(function() {
var scriptText = $(this).html();
if ('' !== scriptText) {
var script = document.createElement('script'),
textNode = document.createTextNode(scriptText);
script.appendChild(textNode);
contentNode.appendChild(script);
} else {
$.getScript($(this).attr('src'));
}
});
Solution for the plugin could be adding the scripts along with the map into the content, or have there an option checkbox in admin for ajax powered themes for that. I’ve seen it in some other plugin.
Hi @spongeboob
Thank you for your kind words.
I’ve added this to Github (https://github.com/CodeCabin/wp-google-maps/issues/175) for us to look further into this and see how we can work around this.