2014-02-19 16:45:36 +01:00
|
|
|
jQuery.fn.updateWithText = function(text, speed)
|
|
|
|
{
|
|
|
|
var dummy = $('<div/>').html(text);
|
|
|
|
|
|
|
|
if ($(this).html() != dummy.html())
|
|
|
|
{
|
|
|
|
$(this).fadeOut(speed/2, function() {
|
|
|
|
$(this).html(text);
|
|
|
|
$(this).fadeIn(speed/2, function() {
|
|
|
|
//done
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
jQuery.fn.outerHTML = function(s) {
|
|
|
|
return s
|
|
|
|
? this.before(s).remove()
|
|
|
|
: jQuery("<p>").append(this.eq(0).clone()).html();
|
|
|
|
};
|
|
|
|
|
2014-02-25 16:34:20 +01:00
|
|
|
function roundVal(temp)
|
2014-02-24 16:35:48 +01:00
|
|
|
{
|
|
|
|
return Math.round(temp * 10) / 10;
|
|
|
|
}
|
|
|
|
|
2014-02-25 16:34:20 +01:00
|
|
|
function kmh2beaufort(kmh)
|
|
|
|
{
|
|
|
|
var speeds = [1, 5, 11, 19, 28, 38, 49, 61, 74, 88, 102, 117, 1000];
|
|
|
|
for (var beaufort in speeds) {
|
|
|
|
var speed = speeds[beaufort];
|
|
|
|
if (speed > kmh) {
|
|
|
|
return beaufort;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 12;
|
|
|
|
}
|
|
|
|
|
2014-02-19 16:45:36 +01:00
|
|
|
jQuery(document).ready(function($) {
|
|
|
|
|
|
|
|
var news = [];
|
|
|
|
var newsIndex = 0;
|
2014-02-19 17:19:54 +01:00
|
|
|
|
2014-02-26 14:14:29 +01:00
|
|
|
var eventList = [];
|
|
|
|
|
2014-02-19 17:19:54 +01:00
|
|
|
var lastCompliment;
|
|
|
|
var compliment;
|
2014-02-24 16:35:48 +01:00
|
|
|
|
2014-05-01 09:08:19 +02:00
|
|
|
// multi-langugage support according to browser-lang
|
|
|
|
var lang = window.navigator.language;
|
|
|
|
switch (lang)
|
|
|
|
{
|
|
|
|
case 'de':
|
|
|
|
var days = ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'];
|
|
|
|
var months = ['Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'];
|
|
|
|
var dayAbbr = ['So','Mo','Di','Mi','Do','Fr','Sa'];
|
2014-05-02 13:26:28 +02:00
|
|
|
var today = 'heute';
|
2014-05-01 09:08:19 +02:00
|
|
|
var tomorrow = 'morgen';
|
2014-05-01 09:37:19 +02:00
|
|
|
var in_days = 'Tage';
|
2014-05-01 09:08:19 +02:00
|
|
|
break;
|
|
|
|
case 'nl':
|
|
|
|
var days = ['zondag','maandag','dinsdag','woensdag','donderdag','vrijdag','zaterdag'];
|
|
|
|
var months = ['januari','februari','maart','april','mei','juni','juli','augustus','september','oktober','november','december'];
|
|
|
|
var dayAbbr = ['zo','ma','di','wo','do','vr','za'];
|
2014-05-02 13:26:28 +02:00
|
|
|
var today = 'vandaag';
|
2014-05-01 09:08:19 +02:00
|
|
|
var tomorrow = 'morgen';
|
|
|
|
var in_days = 'dagen';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
var days = ['sunday','monday','tuesday','wednesday','thursday','friday','saturday'];
|
|
|
|
var months = ['january','february','march','april','may','june','july','august','september','oktober','november','december'];
|
|
|
|
var dayAbbr = ['su','mo','tu','we','th','fr','sa'];
|
2014-05-02 13:26:28 +02:00
|
|
|
var today = 'today';
|
2014-05-01 09:08:19 +02:00
|
|
|
var tomorrow = 'tomorrow';
|
|
|
|
var in_days = 'days';
|
|
|
|
}
|
2014-02-24 16:35:48 +01:00
|
|
|
|
2014-04-21 17:15:08 +02:00
|
|
|
//connect do Xbee monitor
|
2014-04-21 16:51:21 +02:00
|
|
|
var socket = io.connect('http://rpi-development.local:8080');
|
|
|
|
socket.on('dishwasher', function (dishwasherReady) {
|
|
|
|
if (dishwasherReady) {
|
2014-04-21 17:03:03 +02:00
|
|
|
$('.dishwasher').fadeIn(2000);
|
|
|
|
$('.lower-third').fadeOut(2000);
|
2014-04-21 16:51:21 +02:00
|
|
|
} else {
|
2014-04-21 17:03:03 +02:00
|
|
|
$('.dishwasher').fadeOut(2000);
|
|
|
|
$('.lower-third').fadeIn(2000);
|
2014-04-21 16:51:21 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-02-24 16:35:48 +01:00
|
|
|
|
|
|
|
var weatherParams = {
|
|
|
|
'q':'Baarn,Netherlands',
|
|
|
|
'units':'metric',
|
2014-05-01 09:37:19 +02:00
|
|
|
'lang':lang
|
2014-02-24 16:35:48 +01:00
|
|
|
};
|
2014-02-19 16:45:36 +01:00
|
|
|
|
2014-02-19 17:02:17 +01:00
|
|
|
(function checkVersion()
|
|
|
|
{
|
|
|
|
$.getJSON('githash.php', {}, function(json, textStatus) {
|
|
|
|
if (json) {
|
|
|
|
if (json.gitHash != gitHash) {
|
2014-02-19 17:23:54 +01:00
|
|
|
window.location.reload();
|
|
|
|
window.location.href=window.location.href;
|
2014-02-19 17:02:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
setTimeout(function() {
|
|
|
|
checkVersion();
|
|
|
|
}, 3000);
|
|
|
|
})();
|
|
|
|
|
2014-02-19 16:45:36 +01:00
|
|
|
(function updateTime()
|
|
|
|
{
|
|
|
|
var now = new Date();
|
|
|
|
|
2014-02-24 16:35:48 +01:00
|
|
|
var day = now.getDay();
|
|
|
|
var date = now.getDate();
|
2014-02-24 11:19:51 +01:00
|
|
|
var month = now.getMonth();
|
|
|
|
var year = now.getFullYear();
|
|
|
|
|
2014-02-24 16:35:48 +01:00
|
|
|
var date = days[day] + ', ' + date+' ' + months[month] + ' ' + year;
|
2014-02-19 16:45:36 +01:00
|
|
|
|
|
|
|
|
2014-02-24 11:19:51 +01:00
|
|
|
$('.date').html(date);
|
2014-02-27 13:51:18 +01:00
|
|
|
$('.time').html(now.toTimeString().substring(0,5) + '<span class="sec">'+now.toTimeString().substring(6,8)+'</span>');
|
2014-02-19 16:45:36 +01:00
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
updateTime();
|
|
|
|
}, 1000);
|
|
|
|
})();
|
2014-02-24 11:19:51 +01:00
|
|
|
|
2014-02-26 14:14:29 +01:00
|
|
|
(function updateCalendarData()
|
|
|
|
{
|
|
|
|
new ical_parser("calendar.php", function(cal){
|
|
|
|
events = cal.getEvents();
|
|
|
|
eventList = [];
|
|
|
|
|
|
|
|
for (var i in events) {
|
|
|
|
var e = events[i];
|
|
|
|
for (var key in e) {
|
|
|
|
var value = e[key];
|
|
|
|
var seperator = key.search(';');
|
|
|
|
if (seperator >= 0) {
|
|
|
|
var mainKey = key.substring(0,seperator);
|
|
|
|
var subKey = key.substring(seperator+1);
|
|
|
|
|
|
|
|
var dt;
|
|
|
|
if (subKey == 'VALUE=DATE') {
|
|
|
|
//date
|
|
|
|
dt = new Date(value.substring(0,4), value.substring(4,6) - 1, value.substring(6,8));
|
|
|
|
} else {
|
|
|
|
//time
|
|
|
|
dt = new Date(value.substring(0,4), value.substring(4,6) - 1, value.substring(6,8), value.substring(9,11), value.substring(11,13), value.substring(13,15));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mainKey == 'DTSTART') e.startDate = dt;
|
|
|
|
if (mainKey == 'DTEND') e.endDate = dt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-28 11:13:15 +01:00
|
|
|
|
|
|
|
var now = new Date();
|
|
|
|
var today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
|
|
|
var days = moment(e.startDate).diff(moment(today), 'days');
|
2014-02-26 14:14:29 +01:00
|
|
|
|
2014-02-28 15:14:57 +01:00
|
|
|
//only add fututre events
|
|
|
|
if (days >= 0) {
|
|
|
|
eventList.push({'description':e.SUMMARY,'days':days});
|
|
|
|
}
|
2014-02-26 14:14:29 +01:00
|
|
|
};
|
|
|
|
eventList.sort(function(a,b){return a.days-b.days});
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
updateCalendarData();
|
|
|
|
}, 60000);
|
|
|
|
});
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function updateCalendar()
|
|
|
|
{
|
|
|
|
table = $('<table/>').addClass('xsmall').addClass('calendar-table');
|
2014-02-27 13:51:18 +01:00
|
|
|
opacity = 1;
|
|
|
|
|
2014-02-26 14:14:29 +01:00
|
|
|
|
|
|
|
for (var i in eventList) {
|
|
|
|
var e = eventList[i];
|
|
|
|
var days = e.days;
|
|
|
|
|
2014-05-01 09:08:19 +02:00
|
|
|
var daysString = (days == 1) ? tomorrow : days + ' ' + in_days;
|
2014-02-26 14:14:29 +01:00
|
|
|
if (days == 0) {
|
2014-05-02 13:26:28 +02:00
|
|
|
daysString = today;
|
2014-02-26 14:14:29 +01:00
|
|
|
}
|
|
|
|
|
2014-02-27 13:51:18 +01:00
|
|
|
var row = $('<tr/>').css('opacity',opacity);
|
2014-02-26 14:16:11 +01:00
|
|
|
row.append($('<td/>').html(e.description).addClass('description'));
|
2014-02-26 14:14:29 +01:00
|
|
|
row.append($('<td/>').html(daysString).addClass('days dimmed'));
|
|
|
|
table.append(row);
|
2014-02-27 13:51:18 +01:00
|
|
|
|
|
|
|
opacity -= 1 / eventList.length;
|
2014-02-26 14:14:29 +01:00
|
|
|
}
|
|
|
|
|
2014-02-26 14:19:12 +01:00
|
|
|
$('.calendar').updateWithText(table,1000);
|
2014-02-26 14:14:29 +01:00
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
updateCalendar();
|
2014-02-28 11:13:15 +01:00
|
|
|
}, 1000);
|
2014-02-26 14:14:29 +01:00
|
|
|
})();
|
|
|
|
|
2014-02-19 16:45:36 +01:00
|
|
|
(function updateCompliment()
|
|
|
|
{
|
2014-04-21 17:03:03 +02:00
|
|
|
|
2014-02-25 16:34:20 +01:00
|
|
|
var compliments = [
|
|
|
|
'Hey, handsome!',
|
|
|
|
'Hi, sexy!',
|
|
|
|
'Hello, beauty!',
|
|
|
|
'You look sexy!',
|
|
|
|
'Wow, you look hot!',
|
|
|
|
'Looking good today!',
|
|
|
|
'You look nice!',
|
|
|
|
'Enjoy your day!'
|
|
|
|
];
|
2014-02-19 17:19:54 +01:00
|
|
|
|
|
|
|
while (compliment == lastCompliment) {
|
|
|
|
compliment = Math.floor(Math.random()*compliments.length);
|
|
|
|
}
|
2014-04-21 17:03:03 +02:00
|
|
|
|
2014-02-19 17:19:54 +01:00
|
|
|
$('.compliment').updateWithText(compliments[compliment], 4000);
|
|
|
|
|
|
|
|
lastCompliment = compliment;
|
2014-02-19 16:45:36 +01:00
|
|
|
|
|
|
|
setTimeout(function() {
|
2014-04-21 17:03:03 +02:00
|
|
|
updateCompliment(true);
|
2014-02-25 16:34:20 +01:00
|
|
|
}, 30000);
|
2014-04-21 17:03:03 +02:00
|
|
|
|
2014-02-19 16:45:36 +01:00
|
|
|
})();
|
|
|
|
|
2014-02-24 16:35:48 +01:00
|
|
|
(function updateCurrentWeather()
|
2014-02-19 16:45:36 +01:00
|
|
|
{
|
|
|
|
var iconTable = {
|
|
|
|
'01d':'wi-day-sunny',
|
|
|
|
'02d':'wi-day-cloudy',
|
|
|
|
'03d':'wi-cloudy',
|
|
|
|
'04d':'wi-cloudy-windy',
|
|
|
|
'09d':'wi-showers',
|
|
|
|
'10d':'wi-rain',
|
|
|
|
'11d':'wi-thunderstorm',
|
|
|
|
'13d':'wi-snow',
|
|
|
|
'50d':'wi-fog',
|
|
|
|
'01n':'wi-night-clear',
|
|
|
|
'02n':'wi-night-cloudy',
|
|
|
|
'03n':'wi-night-cloudy',
|
|
|
|
'04n':'wi-night-cloudy',
|
|
|
|
'09n':'wi-night-showers',
|
|
|
|
'10n':'wi-night-rain',
|
|
|
|
'11n':'wi-night-thunderstorm',
|
|
|
|
'13n':'wi-night-snow',
|
|
|
|
'50n':'wi-night-alt-cloudy-windy'
|
|
|
|
}
|
2014-02-24 16:35:48 +01:00
|
|
|
|
2014-02-19 16:45:36 +01:00
|
|
|
|
2014-02-24 16:35:48 +01:00
|
|
|
$.getJSON('http://api.openweathermap.org/data/2.5/weather', weatherParams, function(json, textStatus) {
|
2014-02-25 16:34:20 +01:00
|
|
|
|
|
|
|
var temp = roundVal(json.main.temp);
|
|
|
|
var temp_min = roundVal(json.main.temp_min);
|
|
|
|
var temp_max = roundVal(json.main.temp_max);
|
|
|
|
|
|
|
|
var wind = roundVal(json.wind.speed);
|
|
|
|
|
2014-02-19 16:45:36 +01:00
|
|
|
var iconClass = iconTable[json.weather[0].icon];
|
2014-02-26 14:14:29 +01:00
|
|
|
var icon = $('<span/>').addClass('icon').addClass('dimmed').addClass('wi').addClass(iconClass);
|
2014-02-19 16:45:36 +01:00
|
|
|
$('.temp').updateWithText(icon.outerHTML()+temp+'°', 1000);
|
2014-02-24 11:19:51 +01:00
|
|
|
|
2014-02-24 16:35:48 +01:00
|
|
|
// var forecast = 'Min: '+temp_min+'°, Max: '+temp_max+'°';
|
|
|
|
// $('.forecast').updateWithText(forecast, 1000);
|
|
|
|
|
2014-02-25 16:34:20 +01:00
|
|
|
var now = new Date();
|
2014-02-24 16:35:48 +01:00
|
|
|
var sunrise = new Date(json.sys.sunrise*1000).toTimeString().substring(0,5);
|
|
|
|
var sunset = new Date(json.sys.sunset*1000).toTimeString().substring(0,5);
|
|
|
|
|
2014-02-26 14:14:29 +01:00
|
|
|
var windString = '<span class="wi wi-strong-wind xdimmed"></span> ' + kmh2beaufort(wind) ;
|
|
|
|
var sunString = '<span class="wi wi-sunrise xdimmed"></span> ' + sunrise;
|
2014-02-27 13:51:18 +01:00
|
|
|
if (json.sys.sunrise*1000 < now && json.sys.sunset*1000 > now) {
|
2014-02-26 14:14:29 +01:00
|
|
|
sunString = '<span class="wi wi-sunset xdimmed"></span> ' + sunset;
|
2014-02-25 18:55:58 +01:00
|
|
|
}
|
2014-02-24 16:35:48 +01:00
|
|
|
|
2014-02-27 13:51:18 +01:00
|
|
|
$('.windsun').updateWithText(windString+' '+sunString, 1000);
|
2014-02-24 16:35:48 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
updateCurrentWeather();
|
|
|
|
}, 60000);
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function updateWeatherForecast()
|
|
|
|
{
|
|
|
|
$.getJSON('http://api.openweathermap.org/data/2.5/forecast', weatherParams, function(json, textStatus) {
|
|
|
|
|
|
|
|
var forecastData = {};
|
|
|
|
|
|
|
|
for (var i in json.list) {
|
|
|
|
var forecast = json.list[i];
|
|
|
|
var dateKey = forecast.dt_txt.substring(0, 10);
|
|
|
|
|
|
|
|
if (forecastData[dateKey] == undefined) {
|
|
|
|
forecastData[dateKey] = {
|
|
|
|
'timestamp':forecast.dt * 1000,
|
|
|
|
'temp_min':forecast.main.temp,
|
|
|
|
'temp_max':forecast.main.temp
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
forecastData[dateKey]['temp_min'] = (forecast.main.temp < forecastData[dateKey]['temp_min']) ? forecast.main.temp : forecastData[dateKey]['temp_min'];
|
|
|
|
forecastData[dateKey]['temp_max'] = (forecast.main.temp > forecastData[dateKey]['temp_max']) ? forecast.main.temp : forecastData[dateKey]['temp_max'];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var forecastTable = $('<table />').addClass('forecast-table');
|
2014-02-27 13:51:18 +01:00
|
|
|
var opacity = 1;
|
2014-02-24 16:35:48 +01:00
|
|
|
for (var i in forecastData) {
|
|
|
|
var forecast = forecastData[i];
|
|
|
|
var dt = new Date(forecast.timestamp);
|
2014-02-27 13:51:18 +01:00
|
|
|
var row = $('<tr />').css('opacity', opacity);
|
2014-02-24 16:35:48 +01:00
|
|
|
|
|
|
|
row.append($('<td/>').addClass('day').html(dayAbbr[dt.getDay()]));
|
2014-02-25 16:34:20 +01:00
|
|
|
row.append($('<td/>').addClass('temp-max').html(roundVal(forecast.temp_max)));
|
|
|
|
row.append($('<td/>').addClass('temp-min').html(roundVal(forecast.temp_min)));
|
2014-02-24 16:35:48 +01:00
|
|
|
|
|
|
|
forecastTable.append(row);
|
2014-02-27 13:51:18 +01:00
|
|
|
opacity -= 0.155;
|
2014-02-24 16:35:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$('.forecast').updateWithText(forecastTable, 1000);
|
2014-02-19 16:45:36 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(function() {
|
2014-02-24 16:35:48 +01:00
|
|
|
updateWeatherForecast();
|
2014-02-19 16:45:36 +01:00
|
|
|
}, 60000);
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function fetchNews() {
|
|
|
|
$.feedToJson({
|
|
|
|
feed:'http://feeds.nos.nl/nosjournaal?format=rss',
|
|
|
|
//feed:'http://www.nu.nl/feeds/rss/achterklap.rss',
|
|
|
|
//feed:'http://www.nu.nl/feeds/rss/opmerkelijk.rss',
|
|
|
|
success: function(data){
|
|
|
|
news = [];
|
|
|
|
for (var i in data.item) {
|
|
|
|
var item = data.item[i];
|
|
|
|
news.push(item.title);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
setTimeout(function() {
|
|
|
|
fetchNews();
|
|
|
|
}, 60000);
|
|
|
|
})();
|
|
|
|
|
2014-02-25 15:19:05 +01:00
|
|
|
(function showNews() {
|
2014-02-19 16:45:36 +01:00
|
|
|
var newsItem = news[newsIndex];
|
2014-02-24 11:19:51 +01:00
|
|
|
$('.news').updateWithText(newsItem,2000);
|
2014-02-19 16:45:36 +01:00
|
|
|
|
|
|
|
newsIndex--;
|
|
|
|
if (newsIndex < 0) newsIndex = news.length - 1;
|
|
|
|
setTimeout(function() {
|
|
|
|
showNews();
|
2014-02-19 17:27:51 +01:00
|
|
|
}, 5500);
|
2014-02-25 15:19:05 +01:00
|
|
|
})();
|
2014-02-19 16:45:36 +01:00
|
|
|
|
2014-02-20 19:23:59 +01:00
|
|
|
});
|