| @@ -1,79 +1,77 @@ | ||
| 1 | -/* | |
| 2 | - | |
| 3 | -javascript for ajax like request to update the weather location | |
| 4 | -and corresponding data on the fly | |
| 5 | - | |
| 1 | +/** | |
| 2 | + * Javascript for ajax like request to update the weather location | |
| 3 | + * and corresponding data on the fly | |
| 4 | + * | |
| 5 | + * @package wp-forecast | |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | /* load widget for the first time on this page */ |
| 9 | -function wpf_load() | |
| 10 | -{ | |
| 11 | - // get cookie | |
| 12 | - if(document.cookie){ | |
| 13 | - a = document.cookie; | |
| 14 | - cookiename = a.substring(0,a.indexOf('=')); | |
| 15 | - if(a.indexOf(';') != -1){ | |
| 16 | - cookiewert = a.substring(a.indexOf('=')+1,a.indexOf(';')); | |
| 17 | - } else { | |
| 18 | - cookiewert = a.substr(a.indexOf('=')+1,a.length); | |
| 9 | +function wpf_load() { | |
| 10 | + // get cookie. | |
| 11 | + if (document.cookie) { | |
| 12 | + a = document.cookie; | |
| 13 | + cookiename = a.substring( 0, a.indexOf( '=' ) ); | |
| 14 | + if (a.indexOf( ';' ) != -1) { | |
| 15 | + cookiewert = a.substring( a.indexOf( '=' ) + 1, a.indexOf( ';' ) ); | |
| 16 | + } else { | |
| 17 | + cookiewert = a.substr( a.indexOf( '=' ) + 1, a.length ); | |
| 18 | + } | |
| 19 | + // set selected location. | |
| 20 | + if (cookiename == 'location') { | |
| 21 | + document.getElementById( "wpf_selector" ).value = cookiewert; | |
| 22 | + } | |
| 19 | 23 | } |
| 20 | - // set selected location | |
| 21 | - if (cookiename == 'location') | |
| 22 | - document.getElementById("wpf_selector").value = cookiewert; | |
| 23 | - } | |
| 24 | - // update widget | |
| 25 | - wpf_update(); | |
| 24 | + // update widget. | |
| 25 | + wpf_update(); | |
| 26 | 26 | } |
| 27 | 27 | /* get the data for the new location */ |
| 28 | -function wpf_update() | |
| 29 | -{ | |
| 30 | - var newloc = document.getElementById("wpf_selector").value; | |
| 31 | - var siteuri = document.getElementById("wpf_selector_site").value; | |
| 32 | - var language = document.getElementById("wpf_language").value; | |
| 28 | +function wpf_update() { | |
| 29 | + var newloc = document.getElementById( "wpf_selector" ).value; | |
| 30 | + var siteuri = document.getElementById( "wpf_selector_site" ).value; | |
| 31 | + var language = document.getElementById( "wpf_language" ).value; | |
| 33 | 32 | |
| 34 | - // set cookie with newloc | |
| 35 | - var expire = new Date(); | |
| 36 | - expire = new Date(expire.getTime() +1000*60*60*24*365); | |
| 37 | - document.cookie = escape("location=" + newloc) + | |
| 38 | - '; expires='+expire.toGMTString()+';'; | |
| 33 | + // set cookie with newloc. | |
| 34 | + var expire = new Date(); | |
| 35 | + expire = new Date( expire.getTime() + 1000 * 60 * 60 * 24 * 365 ); | |
| 36 | + document.cookie = escape( "location=" + newloc ) + '; expires=' + expire.toGMTString() + ';'; | |
| 39 | 37 | |
| 40 | - jQuery.get(siteuri + "/wp-forecast-show.php", | |
| 41 | - { wpfcid: newloc, header: "0" , selector: "1" , language_override: language }, | |
| 42 | - function(data){ | |
| 43 | - /* | |
| 44 | - var b = data.indexOf(">"); | |
| 45 | - var e = data.lastIndexOf("<"); | |
| 46 | - data = data.substring(b + 1, e - 1); | |
| 47 | - */ | |
| 48 | - jQuery("div#wp-forecastA").html(data); | |
| 49 | - }); | |
| 38 | + jQuery.get( | |
| 39 | + siteuri + "/wp-forecast-direct", | |
| 40 | + { | |
| 41 | + wpfcid: newloc, | |
| 42 | + header: "0", | |
| 43 | + selector: "1", | |
| 44 | + language_override: language | |
| 45 | + }, | |
| 46 | + function(data) { | |
| 47 | + jQuery( "div#wp-forecastA" ).html( data ); | |
| 48 | + } | |
| 49 | + ); | |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | -/* javascript to rebuild the onLoad event for triggering | |
| 52 | +/* javascript to rebuild the onLoad event for triggering | |
| 53 | 53 | the first wpf_update call */ |
| 54 | 54 | |
| 55 | -//create onDomReady Event | |
| 55 | +// create onDomReady Event. | |
| 56 | 56 | window.onDomReady = initReady; |
| 57 | 57 | |
| 58 | -// Initialize event depending on browser | |
| 59 | -function initReady(fn) | |
| 60 | -{ | |
| 61 | - //W3C-compliant browser | |
| 62 | - if(document.addEventListener) { | |
| 63 | - document.addEventListener("DOMContentLoaded", fn, false); | |
| 64 | - } | |
| 65 | - //IE | |
| 66 | - else { | |
| 67 | - document.onreadystatechange = function(){readyState(fn)} | |
| 68 | - } | |
| 69 | - } | |
| 58 | +// Initialize event depending on browser. | |
| 59 | +function initReady(fn) { | |
| 60 | + // W3C-compliant browser. | |
| 61 | + if (document.addEventListener) { | |
| 62 | + document.addEventListener( "DOMContentLoaded", fn, false ); | |
| 63 | + } else { | |
| 64 | + // IE. | |
| 65 | + document.onreadystatechange = function() { | |
| 66 | + readyState( fn ); | |
| 67 | + }; | |
| 68 | + } | |
| 69 | +} | |
| 70 | 70 | |
| 71 | -//IE execute function | |
| 72 | -function readyState(func) | |
| 73 | -{ | |
| 74 | - // DOM is ready | |
| 75 | - if(document.readyState == "interactive" || document.readyState == "complete") | |
| 76 | - { | |
| 77 | - func(); | |
| 78 | - } | |
| 79 | -} | |
| 71 | +// IE execute function. | |
| 72 | +function readyState(func) { | |
| 73 | + // DOM is ready. | |
| 74 | + if (document.readyState == "interactive" || document.readyState == "complete") { | |
| 75 | + func(); | |
| 76 | + } | |
| 77 | +} | |