google chrome fix
[svn42.git] / raspberry-kiosk / kiosk.js
index a4c31d6..edbef05 100644 (file)
@@ -1,6 +1,17 @@
+function min(a,b)
+{
+       if (a > b)
+               return b;
+       else
+               return a;
+}
+
 function writeGooglePlusEvents(data, elem)
 {
   var ghtml = "";
+  //var gplusimgwidth = parseInt($('<table class="gplusimg" />').css("width"));
+  var gplusimgwidth = 495;
+  var minimgwidth=78;
   for (var i=0; i< data.items.length; i++)
   {
     var item = data.items[i];
@@ -33,11 +44,33 @@ function writeGooglePlusEvents(data, elem)
     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 (noteimgs.length>0)
-    {
+    { 
+      var bigimglimit;
       ghtml += '<table class="gplusimg" cellspacing="0"><tr>';
-      for (var ni=0; ni<noteimgs.length; ni++)
+      if (noteimgs.length > 3)
       {
-        ghtml += '<td><img class="gplusimg" src="'+noteimgs[ni]+'"/></td>';
+              var gplusimgmaxwidth = gplusimgwidth - (minimgwidth * ((noteimgs.length -1) / 3));
+             bigimglimit = "max-height:"+(minimgwidth*3)+"px; max-width:"+gplusimgmaxwidth+"px;"
+             ghtml += '<td><img class="gplusimg" style="'+bigimglimit+'" src="'+noteimgs[0]+'"/></td>';
+             for (var ni=1; ni<noteimgs.length; ni+=3)
+             {
+                 ghtml += '<td>';
+                 var niimax = min(noteimgs.length, ni+3);
+                 for (var nii=ni; nii<niimax; nii++)
+                 {
+                       ghtml += '<img class="gplusimg" style="max-width:'+minimgwidth+'px; max-height:'+minimgwidth+'px;" src="'+noteimgs[nii]+'"/><br/>';
+                 }
+                 ghtml += '</td>';
+             }
+      }
+      else
+      {
+             var gplusimgmaxwidth = gplusimgwidth / noteimgs.length;
+            bigimglimit = "max-width:"+gplusimgmaxwidth+"px;"
+             for (var ni=0; ni<noteimgs.length; ni++)
+            {
+               ghtml += '<td><img class="gplusimg" style="'+bigimglimit+'" src="'+noteimgs[ni]+'"/></td>';
+            }
       }
       ghtml += '</tr></table>';
     }
@@ -57,6 +90,22 @@ function loadGooglePlusEvents()
   });
 }
 
+function weekday2str(dow)
+{
+    var weekday=new Array(7);
+    weekday[0]="So";
+    weekday[1]="Mo";
+    weekday[2]="Di";
+    weekday[3]="Mi";
+    weekday[4]="Do";
+    weekday[5]="Fr";
+    weekday[6]="Sa";
+    weekday[7]="So";
+    if (dow >=0 && dow <=7)
+        return weekday[dow];
+    else
+        return "";
+}
 
 function writeCalendar(data, elem)
 {
@@ -71,13 +120,20 @@ function writeCalendar(data, elem)
       }
       else
       {
+        var weekday = weekday2str((new Date(dt)).getDay());
         var stime = data[s].starttime;
+        var month = data[s].start.substring(5,7);
+        if (month[0] == '0')
+          month = month[1];
+        var dayofmonth = data[s].start.substring(8,10);
+          if (dayofmonth[0] == '0')
+          dayofmonth = dayofmonth[1];
         while (stime.substring(stime.length-3,stime.length) == ":00")
         {
           stime=stime.substring(0,stime.length-3);
         }
         if (stime.length <= 2) { stime+="h"; }
-        when = data[s].start.substring(8,10)+"."+data[s].start.substring(5,7) +", "+stime;
+        when = weekday + " " + dayofmonth+"."+month +", "+stime;
       }
       calhtml += '<li class="level1">'+when+' - <span class="r3red">'+data[s].title+'</span></li>'+"\n";
     }
@@ -148,7 +204,7 @@ $(document).ready(function()
   loadGooglePlusEvents();
   setInterval("updateAnwesenheitStatus()", 10*1000);
   setInterval("loadCalendar()", 123*1000);
-  setInterval("updateSensors()",125*1000);
+  setInterval("updateSensors()",145*1000);
   setInterval("loadGooglePlusEvents()", 1207*1000);
 });
 
@@ -212,16 +268,20 @@ function IsImageOk(img) {
     return true;
 }
 
-function reloadImg(element)
+var img_orig_src = {};
+function reloadImgAlt(element)
 {
-    //var image = document.getElementById("theText");
     if(element.complete)
     {
       var new_image = new Image();
       //set up the new image
       new_image.id = element.id;
       new_image.className = element.className;
-      new_image.src = element.src;
+      if (! img_orig_src[element.id])
+      {
+        img_orig_src[element.id] = element.src;
+      }
+      new_image.src = img_orig_src[element.id] + "?dt="+Math.floor(new Date().getTime() / 1000).toString();
       if (IsImageOk(new_image))
       {
         element.parentNode.insertBefore(new_image,element);
@@ -229,3 +289,11 @@ function reloadImg(element)
       }
     }
 }
+function reloadImg(element)
+{
+    if (! img_orig_src[element.id])
+    {
+      img_orig_src[element.id] = element.src;
+    }
+    element.src = img_orig_src[element.id] + "?dt="+Math.floor(new Date().getTime() / 1000).toString();
+}