udatinos.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. },'html');
  58. }
  59. function toRiver(){
  60. state=1;
  61. $jq.get("asset/river.html", function(html_string){
  62. var body = $jq('body');
  63. body.html(html_string);
  64. $jq('input').each(function(){
  65. var self = $jq(this),
  66. label = self.next(),
  67. label_text = label.text();
  68. label.remove();
  69. self.iCheck({
  70. checkboxClass: 'icheckbox_line-purple',
  71. radioClass: 'iradio_line-purple',
  72. insert: '<div class="icheck_line-icon"></div>' + label_text
  73. });
  74. });
  75. //fisso i bottoni ad una certa larghezza
  76. $jq( "div[class^='icheckbox_line']" ).css( "max-width", "200px" );
  77. // sposto i bottoni in alto a dx ma relativamente al loro container
  78. $jq('ul').css({
  79. position: "absolute",
  80. marginLeft: 0, marginTop: 0,
  81. top: 0, left: 0
  82. });
  83. //aggiungo l'on clicked alle checkbox
  84. $jq('input').on('ifChecked', function(event){
  85. for (let i=0; i<pois.length; i++) {
  86. var img = null;
  87. if(this.id == pois[i].cat){
  88. addPin(pois[i],i);
  89. }
  90. }
  91. //qui ci va un foreach suoi poi
  92. });
  93. $jq('input').on('ifUnchecked', function(event){
  94. //qui ci va un foreach suoi poi
  95. for (let i=0; i<pois.length; i++) {
  96. if(this.id == pois[i].cat){
  97. $jq('#pin_'+i).remove();
  98. }
  99. }
  100. });
  101. $jq( "[id^='container_']" ).on($jq.modal.AFTER_CLOSE, function(event, modal) {
  102. modal.$elm.html('');
  103. });
  104. for (let i=0; i<pois.length; i++) {
  105. if($jq('#' + pois[i].cat).is(":checked")) {
  106. addPin(pois[i],i);
  107. }
  108. }
  109. },'html');
  110. }
  111. function isFree(poi,j){
  112. for (let i=0; i<pois.length; i++) {
  113. if(i==j){
  114. continue;
  115. }
  116. if(pois[i].isOverlappedToPoi(poi)){
  117. return false;
  118. }
  119. }
  120. //[0,0,156,188] check if overlapped with checkboxes rectangle
  121. return !poi.isOverlapped([0,0,156,188]);
  122. }
  123. $jq( document ).ready(function() {
  124. console.log( "ready!" );
  125. var b = $jq("body");
  126. b.css("margin-top", "0px");
  127. b.css("margin-left", "0px");
  128. b.css("margin-right", "0px");
  129. b.css("margin-bottom", "0px");
  130. $jq(".modal").css("width","auto");
  131. //disable all
  132. // $jq('.river').hide();
  133. // toRiver();
  134. toScsv();
  135. $jq('body').mousemove(function(event){
  136. console.log("RESTTO TIMER");
  137. });
  138. // $jq('#container_T').on($jq.modal.AFTER_CLOSE, function(event, modal) {
  139. // modal.$elm.html('');
  140. // });
  141. });
  142. var intervalId = setInterval(function() {
  143. if(Date.now()-timeRef>=30000 && state==1){
  144. toScsv();
  145. }
  146. }, 5000);