/* * jQuery jopenweather plugin - v0.2 - 7/12/2010 * http://plugins.jquery.com/project/jopenweather/ * * Copyright (c) 2010 "WasserDragoon" Danny Trunk * Licensed under the GPL license. * http://www.gnu.org/licenses/gpl-3.0-standalone.html */ (function($) {$.fn.jopenweather=function(options) {var defaults={api_key:null,project:null,city_code:null,ajax:{}};var options=$.extend({},defaults,options);var checksum=$.md5(options.project+options.api_key+options.city_code);return $(this).each(function() {var $this=$(this);$.getJSON('http://api.wetter.com/forecast/weather/city/'+options.city_code+'/project/'+options.project+'/cs/'+checksum+'/output/json?jsoncallback=?',function(data) {var date=new Date(),day=date.getDate()<10?'0'+date.getDate():date.getDate(),month=date.getMonth()+1<10?'0'+(date.getMonth()+1):date.getMonth()+1,day_data=data.city.forecast[date.getFullYear()+'-'+month+'-'+day];data.city.forecast.current={};if(date.getHours()>=6&&date.getHours()<11) {data.city.forecast.current=day_data['06:00'];} else if(date.getHours()>=11&&date.getHours()<17) {data.city.forecast.current=day_data['11:00'];} else if(date.getHours()>=17&&date.getHours()<23) {data.city.forecast.current=day_data['17:00'];} else if(date.getHours()>=23) {data.city.forecast.current=day_data['23:00'];} else {$.each(day_data,function(key,value) {if(typeof(value)!=='object') {data.city.forecast.current[key]=value;}});} $.post(options.ajax.url,{data:data,user:options.ajax.data},function(html) {$this.html(html);});});});};})(jQuery);