show multiple image if album
[svn42.git] / raspberry-kiosk / kiosk.js
index 512a337..338f8da 100644 (file)
@@ -7,14 +7,21 @@ function writeGooglePlusEvents(data, elem)
     var noteobj = item.object;
     var attach = noteobj.attachments;
     var notetxt = noteobj.content;
-    var noteimg = false;
+    var noteimgs = new Array();
     if (attach)
     {
       for (var a=0; a<attach.length; a++)
       {
-        if ( attach[a].objectType == "photo")
+        if ( attach[a].objectType == "album")
         {
-          noteimg = attach[a].image.url;
+          for (var t=0; t<attach[a].thumbnails.length; t++)
+          {
+            noteimgs.push(attach[a].thumbnails[t].image.url);
+          }
+        }
+        else if ( attach[a].objectType == "photo")
+        {
+          noteimgs.push(attach[a].image.url);
         }
         else if (attach[a].objectType == "event")
         {
@@ -23,11 +30,16 @@ function writeGooglePlusEvents(data, elem)
       }
     }
     ghtml += '<div class="gpluspost">'
-    ghtml += '<img class="gplusactor" src="'+item.actor.image.url+'"/><p class="gplustimestamp">'+item.updated+'</p>';
+    ghtml += '<img class="gplusactor" src="'+item.actor.image.url+'"/><p class="gplustimestamp">'+item.updated.substring(0,16).replace("T"," ")+'</p>';
     ghtml += '<p class="gplustxt">'+notetxt+'</p>';
-    if (noteimg)
+    if (noteimgs.length>0)
     {
-      ghtml += '<p class="gplusimg"><img class="gplusimg" src="'+noteimg+'"/></p>';
+      ghtml += '<table class="gplusimg" cellspacing="0"><tr>';
+      for (var ni=0; ni<noteimgs.length; ni++)
+      {
+        ghtml += '<td><img class="gplusimg" src="'+noteimgs[ni]+'"/></td>';
+      }
+      ghtml += '</tr></table>';
     }
     ghtml += '</div>';
   }
@@ -40,7 +52,6 @@ function loadGooglePlusEvents()
   var gpak = "AIzaSyD9xBFM-KWwSYBgZ8VzftJ5wYYvurOxEHg";
   var gplusuri = "https://www.googleapis.com/plus/v1/people/113737596421797426873/activities/public?maxResults=4&key="+gpak;
   var gpluscontainer=document.getElementById("gplusevents");
-  gpluscontainer.innerHTML="Plus loading ...";
   $.getJSON(gplusuri, function(data){
     writeGooglePlusEvents(data, gpluscontainer);
   });
@@ -76,7 +87,6 @@ function loadCalendar()
 {
   //old URI: //grical.realraum.at/s/?query=!realraum&limit=9&view=json
   var calcontainer=document.getElementById("grical_upcoming");
-  calcontainer.innerHTML="Calendar loading ...<br/>please wait a second or two";
   $.getJSON('/shmcache/grical_realraum.json', function(data){
     writeCalendar(data, calcontainer);
   });
@@ -106,7 +116,7 @@ function writeAnwesenheitStatus(data)
     {
       $.each( data.sensors[s], function(stype, std){
         $.each( std, function(swhere, svalue){
-           sensorstd+='<td style="background-color:white; height:42px; text-align:center; vertical-align:middle; display:table-cell;"><b>'+stype+'</b><br/>'+swhere+': '+svalue+'</td>';
+           sensorstd+='<td class="sensorstatus"><b>'+stype+'</b><br/>'+swhere+': '+svalue+'</td>';
         });
       });
     }
@@ -149,9 +159,9 @@ $(document).ready(function()
   loadCalendar();
   loadGooglePlusEvents();
   setInterval("updateAnwesenheitStatus()", 10000);
-  setInterval("loadCalendar()", 100000);
-  setInterval("updateSensors()", 50000);
-  setInterval("loadGooglePlusEvents()", 3600*1000);
+  setInterval("loadCalendar()", 123*1000);
+  setInterval("updateSensors()",125*1000);
+  setInterval("loadGooglePlusEvents()", 1207*1000);
 });
 
 function updateDateClock(now)
@@ -200,6 +210,16 @@ function showError(XMLHttpRequest, textStatus, errorThrown)
   alert("Error: " + textStatus);
 }
 
+function IsImageOk(img) {
+    if (!img.complete) {
+        return false;
+    }
+    if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
+        return false;
+    }
+    return true;
+}
+
 function reloadImg(element)
 {
     //var image = document.getElementById("theText");
@@ -209,7 +229,10 @@ function reloadImg(element)
         new_image.id = element.id;
         new_image.className = element.className;
         new_image.src = element.src;
-        element.parentNode.insertBefore(new_image,element);
-        element.parentNode.removeChild(element);
+       if (IsImageOk(new_image))
+       {
+               element.parentNode.insertBefore(new_image,element);
+               element.parentNode.removeChild(element);
+       }
     }
 }