Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
123 lines (100 sloc) 2.93 KB
<html>
<head>
<script data-joshfire-bootstrap src="http://localhost:40021/bootstrap/4f2c1f3e69f4ae0000000142/4f2c1fd169f4ae0000000373/phone/"></script>
<script>
var toDate = function (string) {
var regexp = "([0-9]{4})(-([0-9]{2})(-([0-9]{2})" +
"(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?" +
"(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?";
var d = string.match(new RegExp(regexp));
var offset = 0;
var date = new Date(d[1], 0, 1);
if (d[3]) { date.setMonth(d[3] - 1); }
if (d[5]) { date.setDate(d[5]); }
if (d[7]) { date.setHours(d[7]); }
if (d[8]) { date.setMinutes(d[8]); }
if (d[10]) { date.setSeconds(d[10]); }
if (d[12]) { date.setMilliseconds(Number("0." + d[12]) * 1000); }
if (d[14]) {
offset = (Number(d[16]) * 60) + Number(d[17]);
offset *= ((d[15] == '-') ? 1 : -1);
}
offset -= date.getTimezoneOffset();
time = (Number(date) + (offset * 60 * 1000));
return new Date(Number(time));
};
var switchToUrl = function(src) {
var iframeElt = document.getElementById("iframe");
if (iframeElt.src!=src) {
iframeElt.src = src;
}
};
var processEntry = function(foundInterval) {
//Blank screen ?
if (!foundInterval) {
switchToUrl("");
} else {
//Find an url in the title or description
var urlRegexp = /\b(?:(?:https?|ftp|file):\/\/|www\.|ftp\.)[-A-Z0-9+&@#\/%=~_|$?!:,.]*[A-Z0-9+&@#\/%=~_|$]/i;
var nameMatch = foundInterval.name.match(urlRegexp);
if (nameMatch) {
switchToUrl(nameMatch[0]);
} else {
var descMatch = foundInterval.description.match(urlRegexp);
if (descMatch) {
switchToUrl(descMatch[0]);
} else {
//no url found!
switchToUrl("");
}
}
}
}
var refresh = function() {
Joshfire.factory.getDataSource("calendar").find({},function(err,data) {
if (err) {
setTimeout(function() {
refresh();
},10*3600);
return;
}
// Find the first item we're in
var currentDate = +new Date();
var foundInterval = false;
var entry,startDate,endDate;
for (var i=0;i<data.entries.length && !foundInterval;i++) {
entry = data.entries[i];
startDate = +toDate(entry.startDate);
endDate = +toDate(entry.endDate);
if (startDate<=currentDate && currentDate<endDate) {
foundInterval = entry;
//Schedule a refresh after the event end date.
var endDateCountdown = endDate-currentDate;
setTimeout(function() {
refresh();
},endDateCountdown);
}
}
processEntry(foundInterval);
});
};
window.onload=function() {
refresh();
//Force refresh every 6 hours
setInterval(function() {
refresh();
},6*60*3600);
};
</script>
<style>
html,body,iframe {
margin:0;
padding:0;
border:0;
}
</style>
</head>
<body>
<iframe style="width:100%;height:100%;border:0;" id="iframe"></iframe>
</body>
</html>