| 1 |
/* |
| 2 |
|
| 3 |
javascript for ajax like request to update the weather location |
| 4 |
and corresponding data on the fly |
| 5 |
|
| 6 |
*/ |
| 7 |
|
| 8 |
|
| 9 |
/* get the data for the new location */ |
| 10 |
function wpf_update() |
| 11 |
{ |
| 12 |
var newloc = document.getElementById("wpf_selector").value; |
| 13 |
var siteuri = document.getElementById("wpf_selector_site").value; |
| 14 |
|
| 15 |
jQuery.get(siteuri + "/wp-forecast-show.php", |
| 16 |
{ wpfcid: newloc, header: "0" , selector: "1" }, |
| 17 |
function(data){ |
| 18 |
var b = data.indexOf(">"); |
| 19 |
var e = data.lastIndexOf("<"); |
| 20 |
data = data.substring(b + 1, e - 1); |
| 21 |
jQuery("div#wp-forecastA").html(data); |
| 22 |
}); |
| 23 |
} |
| 24 |
|
| 25 |
/* javascript to rebuild the onLoad event for triggering |
| 26 |
the first wpf_update call */ |
| 27 |
|
| 28 |
//create onDomReady Event |
| 29 |
window.onDomReady = initReady; |
| 30 |
|
| 31 |
// Initialize event depending on browser |
| 32 |
function initReady(fn) |
| 33 |
{ |
| 34 |
//W3C-compliant browser |
| 35 |
if(document.addEventListener) { |
| 36 |
document.addEventListener("DOMContentLoaded", fn, false); |
| 37 |
} |
| 38 |
//IE |
| 39 |
else { |
| 40 |
document.onreadystatechange = function(){readyState(fn)} |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
//IE execute function |
| 45 |
function readyState(func) |
| 46 |
{ |
| 47 |
// DOM is ready |
| 48 |
if(document.readyState == "interactive" || document.readyState == "complete") |
| 49 |
{ |
| 50 |
func(); |
| 51 |
} |
| 52 |
} |