18
« il: 23 Giu 2011, 11:28:43 »
e ha ragione..... al dom ready ha già eseguito la header...
togli il codice che abbiamo messo e spostiamolo nella header, così:
$documento =& JFactory::getDocument();
$documento->addScript('http://code.google.com/apis/gears/gears_init.js');
$javascript ="
var coordinate = null;
function getLocale(){
if ( navigator ) {
if ( navigator.userLanguage ) {
return navigator.userLanguage.toLowerCase();
}
else if ( navigator.language ) {
return navigator.language.toLowerCase();
}
else if ( navigator.browserLanguage ) {
return navigator.browserLanguage.toLowerCase();
}
else if ( navigator.systemLanguage ) {
return navigator.systemLanguage.toLowerCase();
}
}
return \"unknown\";
}
var locales = new Object();
locales[\"en-gb\"] = {lat:54.559322587438636, lng:-4.1748046875, location:\"United Kingdom\"};
locales[\"en-us\"] = {lat:38.41055825094609, lng:-100.37109375, location:\"USA\"};
// TODO - more locales
function TryGoogleLoader(){
if (google.loader.ClientLocation != null) {
var address = google.loader.ClientLocation.address;
var yourLocation = address.city + \", \" + address.region + \", \" + address.country;
document.getElementById(\"location\").innerHTML = \"Your location (using Google loader) is \" + yourLocation;
var latLong = new google.maps.LatLng(google.loader.ClientLocation.latitude,
google.loader.ClientLocation.longitude);
//showMap(latLong, 12);
coordinate = latLong;
}
else {
// map locale to location
var locale = getLocale();
if (locales[locale] != null) {
var latLong = new google.maps.LatLng(locales[locale].lat, locales[locale].lng);
document.getElementById(\"location\").innerHTML =
\"Guessing your location based on your locale - \" + locales[locale].location;
//showMap(latLong, 5);
coordinate = latLong;
}
else {
document.getElementById(\"location\").innerHTML = \"Your location can not be found - locale is \" + locale;
}
}
}
function TryGoogleGears(){
if (google.gears) {
// Try Google Gears Geolocation
var geo = google.gears.factory.create('beta.geolocation');
geo.getCurrentPosition(function(position) {
var latLong = new google.maps.LatLng(position.latitude, position.longitude);
document.getElementById(\"location\").innerHTML = \"Found location via Google Gears\";
//showMap(latLong, 15);
coordinate = latLong;
}, function() {
TryGoogleLoader();
});
}
else
TryGoogleLoader();
}
";
$documento->addScriptDeclaration($javascript);
ovviamente in una zona php (ovunque nel file).... dovrebbe funzionare anche per i moduli.... per plugin e componenti funziona, speriamo.....