Is it possible for a module to insert custom values into the body tag of a dynamic view page? I'm trying to write my own version of a google maps module, and I need to insert onload="initialize()" into the body tag to make the map load automatically (right now I've got a "click here to load the map" link instead). Is there a way to do that?
Posts: 16504
I don't know how, but it looks like that stuff is inserted into the theme:
See /themes/default/views/page.html.php
<body <?= $theme->body_attributes() ?>>That function is defined in /modules/gallery/libraries/MY_View.php
And right now it looks like it's not doing anything other than checking if you have a right-to-left language and if so, sets a class for that.
I don't know how to extend that, but you're the plugin machine so maybe you can't figure that out. And share it with me
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here
Posts: 722
I saw that function call too, but it doesn't take any variables
Oh well, it works well enough with the "Load Map" button. If I can't figure something out before I finish the rest of the code maybe I'll load the map inside of an iframe or something.
Posts: 27300
You can call initialize from within the code, you don't need to do it from the onLoad() in the body tag.
See if this works:
<script src="http://www.google.com/jsapi?key=xxxxxxxxxxxxxxxxxxxxx" type="text/javascript"></script> <script type="text/javascript"> google.load("maps", "2"); // Call this function when the page has been loaded function initialize() { var map = new google.maps.Map2(document.getElementById("map")); map.addControl(new GSmallMapControl()); map.setCenter(new google.maps.LatLng(33.214635, -87.545199), 14); var point = new GLatLng(33.214761, -87.545156); var marker = new GMarker(point); GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml("<a href='http://maps.google.com/maps?f=d&hl=en&geocode=&saddr=7th+St+%4033.214761,+-87.545156&daddr=&sll=33.213199,-87.544899&sspn=0.024164,0.040169&ie=UTF8&ll=33.215838,-87.545285&spn=0.024163,0.040169&z=15&om=1'>The Career Center</a><br/>330 Ferguson Center<br/>Tuscaloosa, AL<br/>35487"); } ); map.addOverlay(marker); } google.setOnLoadCallback(initialize); </script>Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team
Posts: 722
Yes that works, thanks
Posts: 7994
Just in case, I just tweaked the code to allow modules to add their own hooks in your xxx_theme helper so that you can override body_attributes.
---
Problems? Check gallery3/var/logs
bugs/feature req's | upgrade to the latest code | use git | help! vote!