updated clock to only refresh time on the minute boundry
This commit is contained in:
parent
bce7f56b31
commit
d4ad4ec3bb
189
app/js/clock.js
189
app/js/clock.js
@ -3,112 +3,117 @@
|
||||
*/
|
||||
|
||||
|
||||
(function () {
|
||||
(function() {
|
||||
|
||||
var storedData;
|
||||
var self = this;
|
||||
var weatherCount = 0;
|
||||
var skycons = new Skycons({"color": "white"});
|
||||
var storedData;
|
||||
var self = this;
|
||||
var weatherCount = 0;
|
||||
var skycons = new Skycons({"color": "white"});
|
||||
|
||||
MicroEvent.mixin(this);
|
||||
MicroEvent.mixin(this);
|
||||
|
||||
function getData() {
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: '/today/data',
|
||||
data: '',
|
||||
dataType: 'json',
|
||||
timeout: 10000,
|
||||
context: $('body'),
|
||||
contentType: ('application/json'),
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type'
|
||||
},
|
||||
success: function (data) {
|
||||
console.log(data);
|
||||
storedData = data;
|
||||
startWeather();
|
||||
},
|
||||
error: function (xhr, type) {
|
||||
console.log("ajax error");
|
||||
console.log(xhr);
|
||||
console.log(type);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function updateWeather() {
|
||||
$('#wCtext').empty().html(storedData.data.weather.currently);
|
||||
$('#wLtext').empty().html(storedData.data.weather.later);
|
||||
$('#wTtext').empty().html(storedData.data.weather.today);
|
||||
// $('#wDaily').empty();
|
||||
|
||||
for (var t = 0; t < storedData.data.weather.data.daily.data.length; t++) {
|
||||
var m = 'icon' + (t + 1).toString();
|
||||
var d = '#d' + (t + 1).toString();
|
||||
var ts = parseInt(storedData.data.weather.data.daily.data[t].time) * 1000;
|
||||
var n = Date.create(ts).format('{weekday}');
|
||||
|
||||
skycons.add(m, storedData.data.weather.data.daily.data[t].icon);
|
||||
$(d).empty().html(n);
|
||||
}
|
||||
skycons.play();
|
||||
|
||||
$('#wLater').hide();
|
||||
$('#wToday').hide();
|
||||
$('#wDaily').hide();
|
||||
}
|
||||
|
||||
function switchWeather() {
|
||||
|
||||
weatherCount++;
|
||||
weatherCount = weatherCount < 4 ? weatherCount : 0;
|
||||
|
||||
$('#wCurrent').toggle(weatherCount == 0);
|
||||
$('#wLater').toggle(weatherCount == 1);
|
||||
$('#wToday').toggle(weatherCount == 2);
|
||||
$('#wDaily').toggle(weatherCount == 3);
|
||||
|
||||
}
|
||||
|
||||
// event bus
|
||||
|
||||
this.bind('switchWeather', function () {
|
||||
switchWeather();
|
||||
function getData() {
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: '/today/data',
|
||||
data: '',
|
||||
dataType: 'json',
|
||||
timeout: 10000,
|
||||
context: $('body'),
|
||||
contentType: ('application/json'),
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type'
|
||||
},
|
||||
success: function(data) {
|
||||
console.log(data);
|
||||
storedData = data;
|
||||
startWeather();
|
||||
},
|
||||
error: function(xhr, type) {
|
||||
console.log("ajax error");
|
||||
console.log(xhr);
|
||||
console.log(type);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// timers
|
||||
function startWeather() {
|
||||
function updateWeather() {
|
||||
$('#wCtext').empty().html(storedData.data.weather.currently);
|
||||
$('#wLtext').empty().html(storedData.data.weather.later);
|
||||
$('#wTtext').empty().html(storedData.data.weather.today);
|
||||
// $('#wDaily').empty();
|
||||
|
||||
updateWeather();
|
||||
setInterval(function () {
|
||||
self.trigger('switchWeather');
|
||||
for (var t = 0; t < storedData.data.weather.data.daily.data.length; t++) {
|
||||
var m = 'icon' + (t + 1).toString();
|
||||
var d = '#d' + (t + 1).toString();
|
||||
var ts = parseInt(storedData.data.weather.data.daily.data[t].time) * 1000;
|
||||
var n = Date.create(ts).format('{weekday}');
|
||||
|
||||
}, 10000);
|
||||
skycons.add(m, storedData.data.weather.data.daily.data[t].icon);
|
||||
$(d).empty().html(n);
|
||||
}
|
||||
skycons.play();
|
||||
|
||||
function startClock() {
|
||||
setInterval(function () {
|
||||
var n = Date.create(new Date()).format('{hh}:{mm}:{ss}');
|
||||
$('#clockDisplay').html(n);
|
||||
$('#wLater').hide();
|
||||
$('#wToday').hide();
|
||||
$('#wDaily').hide();
|
||||
}
|
||||
|
||||
}, 1000);
|
||||
}
|
||||
function switchWeather() {
|
||||
|
||||
function refresh() {
|
||||
setInterval(function () {
|
||||
getData()
|
||||
}, 900000);
|
||||
}
|
||||
weatherCount++;
|
||||
weatherCount = weatherCount < 4 ? weatherCount : 0;
|
||||
|
||||
startClock();
|
||||
getData();
|
||||
refresh();
|
||||
$('#misc').html($( window ).width());
|
||||
$('#wCurrent').toggle(weatherCount == 0);
|
||||
$('#wLater').toggle(weatherCount == 1);
|
||||
$('#wToday').toggle(weatherCount == 2);
|
||||
$('#wDaily').toggle(weatherCount == 3);
|
||||
|
||||
}
|
||||
|
||||
// event bus
|
||||
|
||||
this.bind('switchWeather', function() {
|
||||
switchWeather();
|
||||
});
|
||||
|
||||
// timers
|
||||
function startWeather() {
|
||||
|
||||
updateWeather();
|
||||
setInterval(function() {
|
||||
self.trigger('switchWeather');
|
||||
|
||||
}, 10000);
|
||||
}
|
||||
|
||||
function updateClock() {
|
||||
var n = Date.create(new Date()).format('{hh}:{mm}');
|
||||
$('#clockDisplay').html(n);
|
||||
}
|
||||
|
||||
function clock() {
|
||||
'use strict';
|
||||
updateClock();
|
||||
var now = new Date;
|
||||
var mod = 60000 - (now.getTime() % 60000);
|
||||
|
||||
setTimeout(function() {clock();}, mod + 10);
|
||||
|
||||
}
|
||||
|
||||
function refresh() {
|
||||
setInterval(function() {
|
||||
getData()
|
||||
}, 900000);
|
||||
}
|
||||
|
||||
clock();
|
||||
getData();
|
||||
refresh();
|
||||
$('#misc').html($(window).width());
|
||||
|
||||
})();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user