udatinos.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. var $jq = jQuery.noConflict();
  2. var timeRef=Date.now();
  3. var state = 0;
  4. var oldJQueryEventTrigger = jQuery.event.trigger;
  5. function resetTimer(){
  6. timeRef=Date.now();
  7. }
  8. jQuery.event.trigger = function( event, data, elem, onlyHandlers ) {
  9. console.log("RESTTO TIMER");
  10. resetTimer();
  11. oldJQueryEventTrigger( event, data, elem, onlyHandlers );
  12. }
  13. function addPin(poi,i){
  14. if(!poi.isFixed()){
  15. do{
  16. // poi.x = 346;
  17. // poi.y = 332;
  18. poi.x=Math.floor(Math.random() * 1200);
  19. poi.y=Math.floor(Math.random() * 700);
  20. }while(!isFree(poi,i));
  21. }
  22. // 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;"/>');
  23. 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;"/>');
  24. img.click(function(){ // handle click
  25. var c = $jq("#container_" + poi.type);
  26. if(poi.type=='T'){ //contenuto testuale
  27. $jq.get("contents/"+poi.type+"_"+i+".html", function(html_string)
  28. {
  29. c.html('<div class="scrollable-content" id="sub_v">' + html_string + '</div>');
  30. },'html');
  31. }else if(poi.type=='V'){//contenuto video
  32. c.html('<source src="contents/'+poi.type+'_'+i+'.mp4" type="video/mp4" />');
  33. c.attr('currentTime',"0");
  34. c.trigger('load');
  35. c.trigger('play');
  36. }else{//è un'immagine
  37. c.html('<img src="contents/'+poi.type+'_'+i+'.jpg"/>');
  38. }
  39. c.modal();
  40. });
  41. // $jq('body').delay(Math.floor(Math.random() * 1001)).append( img );
  42. // $jq('body').append('').delay(2000).queue(function (next) {
  43. // $jq(this).append(img);
  44. // next();
  45. // });
  46. $jq('body').append( img );
  47. img.delay(500);
  48. img.animate({top: poi.y + 'px'},'fast');
  49. img.animate({left: poi.x + 'px'},'fast');
  50. }
  51. function toScsv(){
  52. state=0;
  53. $jq.get("asset/scsv.html", function(html_string){
  54. var body = $jq('body');
  55. body.html(html_string);
  56. $jq("#myVideo").on( "click", function(){toRiver();} )
  57. $jq(".mword").on( "click", function(){toRiver();} )
  58. },'html');
  59. }
  60. function toRiver(){
  61. state=1;
  62. $jq.get("asset/river.html", function(html_string){
  63. var body = $jq('body');
  64. body.html(html_string);
  65. $jq('.cat').on('click',function(e){
  66. if($jq(this).hasClass( "cat_OFF" )){
  67. //is going on
  68. $jq(this).removeClass( "cat_OFF" );
  69. for (let i=0; i<pois.length; i++) {
  70. var img = null;
  71. if(this.id == pois[i].cat){
  72. addPin(pois[i],i);
  73. }
  74. }
  75. }else{
  76. //is going off
  77. $jq(this).addClass( "cat_OFF" );
  78. for (let i=0; i<pois.length; i++) {
  79. if(this.id == pois[i].cat){
  80. $jq('#pin_'+i).remove();
  81. }
  82. }
  83. }
  84. });
  85. $jq('input').each(function(){
  86. var self = $jq(this),
  87. label = self.next(),
  88. label_text = label.text();
  89. label.remove();
  90. self.iCheck({
  91. checkboxClass: 'icheckbox_line-purple',
  92. radioClass: 'iradio_line-purple',
  93. insert: '<div class="icheck_line-icon"></div>' + label_text
  94. });
  95. });
  96. //fisso i bottoni ad una certa larghezza
  97. $jq( "div[class^='icheckbox_line']" ).css( "max-width", "200px" );
  98. // sposto i bottoni in alto a dx ma relativamente al loro container
  99. $jq('ul').css({
  100. position: "absolute",
  101. marginLeft: 0, marginTop: 0,
  102. top: 0, left: 0
  103. });
  104. //aggiungo l'on clicked alle checkbox
  105. $jq('input').on('ifChecked', function(event){
  106. for (let i=0; i<pois.length; i++) {
  107. var img = null;
  108. if(this.id == pois[i].cat){
  109. addPin(pois[i],i);
  110. }
  111. }
  112. //qui ci va un foreach suoi poi
  113. });
  114. $jq('input').on('ifUnchecked', function(event){
  115. //qui ci va un foreach suoi poi
  116. for (let i=0; i<pois.length; i++) {
  117. if(this.id == pois[i].cat){
  118. $jq('#pin_'+i).remove();
  119. }
  120. }
  121. });
  122. $jq( "[id^='container_']" ).on($jq.modal.AFTER_CLOSE, function(event, modal) {
  123. modal.$elm.html('');
  124. });
  125. for (let i=0; i<pois.length; i++) {
  126. if(!$jq('#' + pois[i].cat).hasClass("cat_OFF")) {
  127. addPin(pois[i],i);
  128. }
  129. }
  130. },'html');
  131. }
  132. function isFree(poi,j){
  133. for (let i=0; i<pois.length; i++) {
  134. if(i==j){
  135. continue;
  136. }
  137. if(pois[i].isOverlappedToPoi(poi)){
  138. return false;
  139. }
  140. }
  141. //[0,0,156,188] check if overlapped with checkboxes rectangle
  142. return !poi.isOverlapped([0,0,160,350]);
  143. }
  144. $jq( document ).ready(function() {
  145. console.log( "ready!" );
  146. var b = $jq("body");
  147. b.css("margin-top", "0px");
  148. b.css("margin-left", "0px");
  149. b.css("margin-right", "0px");
  150. b.css("margin-bottom", "0px");
  151. $jq(".modal").css("width","auto");
  152. //disable all
  153. // $jq('.river').hide();
  154. // toRiver();
  155. toScsv();
  156. $jq('body').mousemove(function(event){
  157. console.log("RESTTO TIMER");
  158. });
  159. // $jq('#container_T').on($jq.modal.AFTER_CLOSE, function(event, modal) {
  160. // modal.$elm.html('');
  161. // });
  162. });
  163. var intervalId = setInterval(function() {
  164. if(Date.now()-timeRef>=60000 && state==1){
  165. toScsv();
  166. }
  167. }, 5000);