From ad7da9afa0a97218f9f1839004364b3836d2ad71 Mon Sep 17 00:00:00 2001 From: Jonathan Vogt Date: Tue, 26 Jan 2016 00:27:57 +0100 Subject: [PATCH 1/2] Improve Weather * Add spans for CSS placement * Add option to flip weather forecast * Add additional forecast day --- js/weather/weather.js | 56 ++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/js/weather/weather.js b/js/weather/weather.js index 6db8ea96..0343d639 100644 --- a/js/weather/weather.js +++ b/js/weather/weather.js @@ -31,7 +31,8 @@ var weather = { forecastEndpoint: 'forecast/daily', updateInterval: config.weather.interval || 6000, fadeInterval: config.weather.fadeInterval || 1000, - intervalId: null + intervalId: null, + orientation: 'vertical', } /** @@ -89,14 +90,14 @@ weather.updateCurrentWeather = function () { _sunrise = moment(data.sys.sunrise*1000).format('HH:mm'), _sunset = moment(data.sys.sunset*1000).format('HH:mm'); - var _newWindHtml = ' ' + this.ms2Beaufort(_wind), - _newSunHtml = ' ' + _sunrise; + var _newWindHtml = ' ' + this.ms2Beaufort(_wind) + '', + _newSunHtml = ' ' + _sunrise + ''; if (_sunrise < _now && _sunset > _now) { - _newSunHtml = ' ' + _sunset; + _newSunHtml = ' ' + _sunset + ''; } - $(this.windSunLocation).updateWithText(_newWindHtml + ' ' + _newSunHtml, this.fadeInterval); + $(this.windSunLocation).updateWithText(_newWindHtml + ' ' + _newSunHtml,this.fadeInterval); }.bind(this), error: function () { @@ -118,28 +119,44 @@ weather.updateWeatherForecast = function () { success: function (data) { var _opacity = 1, - _forecastHtml = ''; + _forecastHtml = '', + _forecastHtml2 = '', + _forecastHtml3 = '', + _forecastHtml4 = ''; - _forecastHtml += ''; + _forecastHtml = '
'; for (var i = 0, count = data.list.length; i < count; i++) { var _forecast = data.list[i]; + + if (this.orientation == 'vertical') { + _forecastHtml2 = ''; + _forecastHtml3 = ''; + _forecastHtml4 = ''; + } - _forecastHtml += ''; - - _forecastHtml += ''; - _forecastHtml += ''; - _forecastHtml += ''; - _forecastHtml += ''; - - _forecastHtml += ''; + _forecastHtml += ''; + _forecastHtml2 += ''; + _forecastHtml3 += ''; + _forecastHtml4 += ''; _opacity -= 0.155; + if (this.orientation == 'vertical') { + _forecastHtml += _forecastHtml2 + _forecastHtml3 + _forecastHtml4 + ''; + } + } + _forecastHtml += '', + _forecastHtml2 += '', + _forecastHtml3 += '', + _forecastHtml4 += ''; + + if (this.orientation == 'vertical') { + _forecastHtml += '
' + moment(_forecast.dt, 'X').format('ddd') + '' + this.roundValue(_forecast.temp.max) + '' + this.roundValue(_forecast.temp.min) + '
' + moment(_forecast.dt, 'X').format('ddd') + '' + this.roundValue(_forecast.temp.max) + '' + this.roundValue(_forecast.temp.min) + '
'; + } else { + _forecastHtml += _forecastHtml2 + _forecastHtml3 + _forecastHtml4 +''; } - - _forecastHtml += ''; $(this.forecastLocation).updateWithText(_forecastHtml, this.fadeInterval); @@ -158,12 +175,13 @@ weather.init = function () { } if (this.params.cnt === undefined) { - this.params.cnt = 5; + this.params.cnt = 6; } this.intervalId = setInterval(function () { this.updateCurrentWeather(); this.updateWeatherForecast(); }.bind(this), this.updateInterval); - + this.updateCurrentWeather(); + this.updateWeatherForecast(); } From 523103ce30fcd2002166dde0eadaa54806671b6d Mon Sep 17 00:00:00 2001 From: Jonathan Vogt Date: Tue, 26 Jan 2016 00:47:33 +0100 Subject: [PATCH 2/2] Make Orientation configurable --- js/weather/weather.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/weather/weather.js b/js/weather/weather.js index 0343d639..8147be6f 100644 --- a/js/weather/weather.js +++ b/js/weather/weather.js @@ -32,7 +32,7 @@ var weather = { updateInterval: config.weather.interval || 6000, fadeInterval: config.weather.fadeInterval || 1000, intervalId: null, - orientation: 'vertical', + orientation: config.weather.orientation || 'vertical', } /**