udatinos.js 5.5 KB

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