lucaconte 3 years ago
parent
commit
da5617fe0b
2 changed files with 71 additions and 48 deletions
  1. 54 35
      asset/pois.js
  2. 17 13
      asset/udatinos.js

+ 54 - 35
asset/pois.js

@@ -7,7 +7,8 @@ var poiAlpha = {
   pin: function(){
   },
   isFixed: function(){
-    return (this.cat=='FI'||this.cat=='UD');
+    // return (this.cat=='FI'||this.cat=='UD');
+    return (this.x>0 && this.y >0);
   },
   isOverlappedToPoi: function(poi){
     var rec1 = [poi.x,poi.y,poi.x+this.pin_width,poi.y+this.pin_width];
@@ -39,14 +40,32 @@ var pois=[];
 //  - "V": Video
 
 //Cat(egories):
-// - "FI": FIume (Position Fixed)
+// - "FI": FIume 
 // - "FL": FLora
 // - "FI": FAuna
-// - "UD": UDatinos (Position Fixed)
+// - "UD": UDatinos 
 
+//Tutto ciò che a coordinate x,y maggiori di zero (entrambe) è posizionato fisso
+//Altrimenti è posizionato randomicamente
 
+//Se, ad esempio, un "poi"  ha "id" uguale a "0" allora il corrispettivo contenuto cercato sarà
+//"asset/I_0.jpg" se Immagine
+//"asset/T_0.html" se (iper)Testo
+//"asset/V_0.mp4" se Video
+//
+//Recola generale: <poi.type>_<poi.id>.jpg|html|mp4
 
-var poi=Object.create(poiAlpha);
+//Qui sotto la definizione di timeout in millisecondi per lo switch allo screensaver
+//Il timeout scatta se l'utente non muove il mouse e non clicca da qualche parte cliccabile
+//quindi es: 60000 sono 60 secondi 
+var screensaver_timeout = 60000;
+
+
+
+
+function resetAllPins(){
+  pois=[]; 
+  var poi=Object.create(poiAlpha);
 //-----------
 // FIUME
 //-----------
@@ -54,7 +73,7 @@ var poi=Object.create(poiAlpha);
     //0
     poi.x = 346;
     poi.y = 332;
-    poi.id = "First One";
+    poi.id = "0";
     poi.type = 'I'; //looking for "asset/I_0.jpg"
     poi.cat = 'FI'
     pois.push(poi);
@@ -63,7 +82,7 @@ var poi=Object.create(poiAlpha);
     poi=Object.create(poiAlpha);
     poi.x= 746;
     poi.y= 432;
-    poi.id="Two";
+    poi.id="1";
     poi.type = 'V'; //looking for "asset/V_1.mp4"
     poi.cat = 'FI'
     pois.push(poi);
@@ -72,7 +91,7 @@ var poi=Object.create(poiAlpha);
     poi=Object.create(poiAlpha);
     poi.x= 700;
     poi.y= 402;
-    poi.id="Two";
+    poi.id="2";
     poi.type = 'T'; //looking for "asset/T_2.html"
     poi.cat = 'FI'
     pois.push(poi);
@@ -187,7 +206,7 @@ var poi=Object.create(poiAlpha);
     poi=Object.create(poiAlpha);
     poi.x = -1;
     poi.y = -1;
-    poi.id = "5";
+    poi.id = "15";
     poi.type = 'I'; 
     poi.cat = 'FA'
     pois.push(poi);
@@ -195,7 +214,7 @@ var poi=Object.create(poiAlpha);
     poi=Object.create(poiAlpha);
     poi.x = -1;
     poi.y = -1;
-    poi.id = "6";
+    poi.id = "16";
     poi.type = 'I'; 
     poi.cat = 'FA'
     pois.push(poi);
@@ -203,7 +222,7 @@ var poi=Object.create(poiAlpha);
     poi=Object.create(poiAlpha);
     poi.x = -1;
     poi.y = -1;
-    poi.id = "7";
+    poi.id = "17";
     poi.type = 'I'; 
     poi.cat = 'FA'
     pois.push(poi);
@@ -211,7 +230,7 @@ var poi=Object.create(poiAlpha);
     poi=Object.create(poiAlpha);
     poi.x = -1;
     poi.y = -1;
-    poi.id = "8";
+    poi.id = "18";
     poi.type = 'I'; 
     poi.cat = 'FA'
     pois.push(poi);
@@ -219,7 +238,7 @@ var poi=Object.create(poiAlpha);
     poi=Object.create(poiAlpha);
     poi.x = -1;
     poi.y = -1;
-    poi.id = "9";
+    poi.id = "19";
     poi.type = 'I'; 
     poi.cat = 'FA'
     pois.push(poi);
@@ -227,7 +246,7 @@ var poi=Object.create(poiAlpha);
     poi=Object.create(poiAlpha);
     poi.x = -1;
     poi.y = -1;
-    poi.id = "10";
+    poi.id = "20";
     poi.type = 'V'; 
     poi.cat = 'FA'
     pois.push(poi);
@@ -235,7 +254,7 @@ var poi=Object.create(poiAlpha);
     poi=Object.create(poiAlpha);
     poi.x = -1;
     poi.y = -1;
-    poi.id = "11";
+    poi.id = "21";
     poi.type = 'V'; 
     poi.cat = 'FA'
     pois.push(poi);
@@ -243,7 +262,7 @@ var poi=Object.create(poiAlpha);
     poi=Object.create(poiAlpha);
     poi.x = -1;
     poi.y = -1;
-    poi.id = "12";
+    poi.id = "22";
     poi.type = 'I'; 
     poi.cat = 'FA'
     pois.push(poi);
@@ -251,7 +270,7 @@ var poi=Object.create(poiAlpha);
     poi=Object.create(poiAlpha);
     poi.x = -1;
     poi.y = -1;
-    poi.id = "13";
+    poi.id = "23";
     poi.type = 'V'; 
     poi.cat = 'FA'
     pois.push(poi);
@@ -259,7 +278,7 @@ var poi=Object.create(poiAlpha);
     poi=Object.create(poiAlpha);
     poi.x = -1;
     poi.y = -1;
-    poi.id = "14";
+    poi.id = "24";
     poi.type = 'T'; 
     poi.cat = 'FA'
     pois.push(poi);
@@ -272,8 +291,8 @@ var poi=Object.create(poiAlpha);
     poi=Object.create(poiAlpha);
     poi.x = 1146;
     poi.y = 543;
-    poi.id = "First One";
-    poi.type = 'I'; //looking for "asset/I_0.jpg"
+    poi.id = "25";
+    poi.type = 'I'; 
     poi.cat = 'UD'
     pois.push(poi);
 
@@ -281,8 +300,8 @@ var poi=Object.create(poiAlpha);
     poi=Object.create(poiAlpha);
     poi.x= 789;
     poi.y= 100;
-    poi.id="Two";
-    poi.type = 'V'; //looking for "asset/V_1.mp4"
+    poi.id="26";
+    poi.type = 'V';
     poi.cat = 'UD'
     pois.push(poi);
 
@@ -290,8 +309,8 @@ var poi=Object.create(poiAlpha);
     poi=Object.create(poiAlpha);
     poi.x= 1053;
     poi.y= 438;
-    poi.id="Two";
-    poi.type = 'T'; //looking for "asset/T_2.html"
+    poi.id="27";
+    poi.type = 'T';
     poi.cat = 'UD'
     pois.push(poi);
     
@@ -299,7 +318,7 @@ var poi=Object.create(poiAlpha);
     poi=Object.create(poiAlpha);
     poi.x = 26;
     poi.y = 411;
-    poi.id = "3";
+    poi.id = "28";
     poi.type = 'I'; 
     poi.cat = 'UD'
     pois.push(poi);
@@ -308,7 +327,7 @@ var poi=Object.create(poiAlpha);
     poi=Object.create(poiAlpha);
     poi.x =180;
     poi.y = 701;
-    poi.id = "4";
+    poi.id = "29";
     poi.type = 'I'; 
     poi.cat = 'UD'
     pois.push(poi);
@@ -316,8 +335,8 @@ var poi=Object.create(poiAlpha);
     //30
     poi.x = 316;
     poi.y = 532;
-    poi.id = "First One";
-    poi.type = 'I'; //looking for "asset/I_0.jpg"
+    poi.id = "30";
+    poi.type = 'I';
     poi.cat = 'UD'
     pois.push(poi);
 
@@ -325,8 +344,8 @@ var poi=Object.create(poiAlpha);
     poi=Object.create(poiAlpha);
     poi.x= 710;
     poi.y= 236;
-    poi.id="Two";
-    poi.type = 'V'; //looking for "asset/V_1.mp4"
+    poi.id="31";
+    poi.type = 'V';
     poi.cat = 'UD'
     pois.push(poi);
 
@@ -334,8 +353,8 @@ var poi=Object.create(poiAlpha);
     poi=Object.create(poiAlpha);
     poi.x= 301;
     poi.y= 323;
-    poi.id="Two";
-    poi.type = 'T'; //looking for "asset/T_2.html"
+    poi.id="32";
+    poi.type = 'T';
     poi.cat = 'UD'
     pois.push(poi);
     
@@ -343,7 +362,7 @@ var poi=Object.create(poiAlpha);
     poi=Object.create(poiAlpha);
     poi.x = 506;
     poi.y = 562;
-    poi.id = "3";
+    poi.id = "33";
     poi.type = 'I'; 
     poi.cat = 'UD'
     pois.push(poi);
@@ -352,9 +371,9 @@ var poi=Object.create(poiAlpha);
     poi=Object.create(poiAlpha);
     poi.x = 616;
     poi.y = 232;
-    poi.id = "4";
+    poi.id = "34";
     poi.type = 'I'; 
     poi.cat = 'UD'
     pois.push(poi);
-
-
+}
+resetAllPins();

+ 17 - 13
asset/udatinos.js

@@ -14,32 +14,33 @@ jQuery.event.trigger = function( event, data, elem, onlyHandlers ) {
   oldJQueryEventTrigger( event, data, elem, onlyHandlers ); 
 }
 
-function addPin(poi,i){
+function addPin(poi){
   if(!poi.isFixed()){
      do{
       // poi.x = 346;
       // poi.y = 332;
        poi.x=Math.floor(Math.random() * 1200);
       poi.y=Math.floor(Math.random() * 700);
-    }while(!isFree(poi,i));
+    }while(!isFree(poi));
   }
  // var img = $jq('<img id="pin_'+i+'" src="asset/i_'+poi.cat+'_48.png" style="position:absolute;left:'+Math.floor(Math.random() * 1200)+'px;top:'+Math.floor(Math.random() * 700)+'px; display: block;visibility: visible;"/>');
-  var img = $jq('<img id="pin_'+i+'" src="asset/i_'+poi.cat+'_48.png" class="river" style="position:absolute;left:'+Math.floor($jq(window).width()/2)+'px;top:'+Math.floor($jq(window).height()/2)+'px; display: block;visibility: visible;"/>'); 
+  var img = $jq('<img id="pin_'+poi.id+'" src="asset/i_'+poi.cat+'_48.png" class="river" style="position:absolute;left:'+Math.floor($jq(window).width()/2)+'px;top:'+Math.floor($jq(window).height()/2)+'px; display: block;visibility: visible;"/>'); 
   img.click(function(){ // handle click
+    resetTimer();
     var c = $jq("#container_" + poi.type);
 
     if(poi.type=='T'){ //contenuto testuale
-      $jq.get("contents/"+poi.type+"_"+i+".html", function(html_string)
+      $jq.get("contents/"+poi.type+"_"+poi.id+".html", function(html_string)
          {
             c.html('<div class="scrollable-content" id="sub_v">' + html_string + '</div>'); 
          },'html');
     }else if(poi.type=='V'){//contenuto video 
-      c.html('<source src="contents/'+poi.type+'_'+i+'.mp4" type="video/mp4" />');  
+      c.html('<source src="contents/'+poi.type+'_'+poi.id+'.mp4" type="video/mp4" />');  
       c.attr('currentTime',"0");
       c.trigger('load');
       c.trigger('play');
     }else{//è un'immagine
-      c.html('<img src="contents/'+poi.type+'_'+i+'.jpg"/>');  
+      c.html('<img src="contents/'+poi.type+'_'+poi.id+'.jpg"/>');  
     }
     c.modal();
   }); 
@@ -70,11 +71,13 @@ function toScsv(){
     },'html');
 }
 function toRiver(){
+    resetAllPins();
     state=1;
     $jq.get("asset/river.html", function(html_string){
             var body = $jq('body');
             body.html(html_string);
             $jq('.cat').on('click',function(e){
+            resetTimer();
                if($jq(this).hasClass( "cat_OFF" )){
                  //is going on
                   $jq(this).removeClass( "cat_OFF" );   
@@ -82,7 +85,7 @@ function toRiver(){
 
                     var img = null;
                     if(this.id == pois[i].cat){
-                      addPin(pois[i],i);
+                      addPin(pois[i]);
                     }
                   }
               }else{
@@ -90,7 +93,7 @@ function toRiver(){
                   $jq(this).addClass( "cat_OFF" );   
                    for (let i=0; i<pois.length; i++) {
                     if(this.id == pois[i].cat){
-                      $jq('#pin_'+i).remove();
+                      $jq('#pin_'+pois[i].id).remove();
                     }
                   }
                 }
@@ -103,17 +106,17 @@ function toRiver(){
             });
              for (let i=0; i<pois.length; i++) {
                if(!$jq('#' + pois[i].cat).hasClass("cat_OFF")) {
-                addPin(pois[i],i);
+                addPin(pois[i]);
                }
              }
 
          },'html');
  }
 
-function isFree(poi,j){
+function isFree(poi){
   
    for (let i=0; i<pois.length; i++) {
-     if(i==j){
+     if(poi.id==pois[i].id){
       continue;
      }
 
@@ -121,7 +124,7 @@ function isFree(poi,j){
       return false;
     }
    }
-  //[0,0,156,188] check if overlapped with checkboxes rectangle
+  //[0,0,160,350] check if overlapped with checkboxes rectangle
   return !poi.isOverlapped([0,0,160,350]);
 }
 
@@ -139,6 +142,7 @@ $jq( document ).ready(function() {
     toScsv();
     $jq('body').mousemove(function(event){
       console.log("RESTTO TIMER"); 
+      resetTimer();
     });
    // $jq('#container_T').on($jq.modal.AFTER_CLOSE, function(event, modal) {
       // modal.$elm.html('');
@@ -146,7 +150,7 @@ $jq( document ).ready(function() {
 });
 
 var intervalId = setInterval(function() {
-  if(Date.now()-timeRef>=60000 && state==1){
+  if(Date.now()-timeRef>=screensaver_timeout && state==1){
     toScsv();
   }
 }, 5000);