Hodges |
|
---|---|
Hey,
I've got a google map on a page set to html mode. To make it work I require this in the header: <script type="text/javascript">
function initialize() {
var myLatlng = new google.maps.LatLng(53.381883, -1.477755);
var myOptions = {
zoom: 15,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title:"Sir Robert Hadfield Building"
});
}
</script> And this in the body tag: <body onLoad="initialize()"> Thing is, I don't won't this code including anywhere else on the site. How would you guys solve this elegantly? Cheers. |
pieter |
|
---|---|
you can give the page:
OR specific header: that page in another category and use header.CAT.tpl OR maybe give your page an alias and add following in the standard header: <!-- IF {PHP.al} == 'your_pagealias' --> YOUR_CODE <!-- ENDIF --> ... can we help you ...
|
GHengeveld |
|
---|---|
Don't use body onload, its very dirty. Also you normally shouldn't put javascript in the header, but in the footer (just before </body>). If you use html parsing in pages you can just as well put it directly in the page body, right where you want the map to be displayed. It's not the best solution, but OK if it's just one page using it. Otherwise put it in page.tpl and try this:
<!-- IF {PAGE_ID} == xx --> JS code <!-- ENDIF --> Replace xx with the ID of the page you want the map to display on. You can also try pieters suggestion but that requires the page to have an alias. His code will work in footer.tpl as well (probably an even better solution). Try this: <script type="text/javascript">
function initialize() {
var myLatlng = new google.maps.LatLng(53.381883, -1.477755);
var myOptions = {
zoom: 15,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title:"Sir Robert Hadfield Building"
});
}
jQuery(document).ready(function(){ initialize(); });
</script> Don't forget to remove the onload="initialize()" |
pieter |
|
---|---|
@Koradhil
Suggestion for documentation: List of most used tags {PAGE_ID} {PHP.al} .... There are so many that nobody knows them all. Execpt programmers. ... can we help you ...
|
ez |
|
---|---|
It is not required to put JS in the header.... It is cleaner, but you can use it anywhere.
So just put your js in your page ! @Pieter: The tags are pretty easy to find in the php files, but you are right a list should be nice.. There are some here: http://www.cotonti.com/plug.php?e=tpltags ==- I say: Keep it EZ -==
|
pieter |
|
---|---|
# ez : The tags are pretty easy to find in the php files, but you are right a list should be nice.. Some explanation next to it, would be nice ... can we help you ...
|
Hodges |
|
---|---|
Cheers everyone.
In the end I went with Koradhil's code in the page body. Works a treat. Damn I really should learn how to use jquery now ![]() |
Kingsley |
|
---|---|
# Koradhil : Also you normally shouldn't put javascript in the header, but in the footer (just before </body>). why is that? |
Hodges |
|
---|---|
Look here for a good answer: http://stackoverflow.com/questions/196702/where-to-place-javascript-in-a-html-file
Specifically:
|
Kingsley |
|
---|---|
thx for the explanation hodges
|
foxhound |
|
---|---|
Well, that means you just have to look into the php files to find a variable, right?
You could even use variables which are introduced with plugins. So, if you need something open the php files and have a look at it. I guess even a noob like me can do that ;-) Argh, it redirected me to the wrong topic after login. Sorry. <img src="http://www.armaholic.com/datas/thumbs/green-sea-battalion-uniforms-version-03-preview_4.jpg" alt="green-sea-battalion-uniforms-version-03-" />
|