/* * jDigiClock plugin 2.1 * * http://www.radoslavdimov.com/jquery-plugins/jquery-plugin-digiclock/ * * Copyright (c) 2009 Radoslav Dimov * * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * */ (function(jQuery) { jQuery.fn.extend({ jdigiclock: function(options) { var defaults = { weatherImagesPath: 'media/weather/', lang: 'en', am_pm: true, weatherLocationCode: 'NAM|US|IN|SOUTH BEND', weatherMetric: 'F', weatherUpdate: 0, proxyType: 'php' }; var regional = []; regional['en'] = { monthNames: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] } var options = jQuery.extend(defaults, options); return this.each(function() { var $this = $(this); var o = options; $this.clockImagesPath = o.clockImagesPath; $this.weatherImagesPath = o.weatherImagesPath; $this.lang = regional[o.lang] == undefined ? regional['en'] : regional[o.lang]; $this.am_pm = o.am_pm; $this.weatherLocationCode = o.weatherLocationCode; $this.weatherMetric = o.weatherMetric == 'C' ? 1 : 0; $this.weatherUpdate = o.weatherUpdate; $this.proxyType = o.proxyType; $this.currDate = ''; $this.timeUpdate = ''; var html = '
'; $this.html(html); $this.displayWeather($this); }); } }); jQuery.fn.displayWeather = function(el) { jQuery.fn.getWeather(el); if (el.weatherUpdate > 0) { setTimeout(function() {jQuery.fn.displayWeather(el)}, (el.weatherUpdate * 60 * 1000)); } } jQuery.fn.delay = function() { var now = new Date(); var delay = (60 - now.getSeconds()) * 1000; return delay; } jQuery.fn.getWeather = function(el) { el.find('#weather').html('

Update Weather ...

'); el.find('#forecast_container').html('

Update Weather ...

'); var metric = el.weatherMetric == 1 ? 'C' : 'F'; var proxy = ''; switch (el.proxyType) { case 'php': proxy = 'common/weather_proxy.php'; break; case 'asp': proxy = 'asp/WeatherProxy.aspx'; break; } jQuery.getJSON(proxy + '?location=' + el.weatherLocationCode + '&metric=' + el.weatherMetric, function(data) { el.find('#weather .loading, #forecast_container .loading').hide(); var curr_temp = '

' + data.curr_temp + '°' + metric + '

'; el.find('#weather').css('background','url(' + el.weatherImagesPath + data.curr_icon + '.png) 50% 100% no-repeat'); var weather = '

' + data.city + '

' + data.curr_text + '

'; weather += '

' + el.currDate + '

' + curr_temp + '
'; el.find('#weather').html(weather); // forecast var curr_for = curr_temp + '

' + data.forecast[0].day_htemp + '° / ' + data.forecast[0].day_ltemp + '°

'; el.find('#forecast_container').append(''); //data.forecast.shift(); for (var i in data.forecast) { if (i <= 2) { var d_date = new Date(data.forecast[i].day_date); var day_name = el.lang.dayNames[d_date.getDay()]; var forecast = '
  • '; if (i == 0) { forecast += '

    Today

    '; } else { forecast += '

    ' + data.forecast[i].day_text + '

    '; } forecast += '' + data.forecast[i].day_text + ''; forecast += '

    ' + data.forecast[i].day_htemp + '° / ' + data.forecast[i].day_ltemp + '°

    '; forecast += '
  • '; el.find('#forecast').append(forecast); } } /* $('#reload').click(function() { el.find('#weather').html(''); el.find('#forecast_container').html(''); jQuery.fn.getWeather(el); }); */ }); } })(jQuery);