udatinos.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. var x=(poi.cat=='FL'||poi.cat=='FA')?Math.floor(Math.random() * 1200):poi.x;
  15. var y=(poi.cat=='FL'||poi.cat=='FA')?Math.floor(Math.random() * 700):poi.y;
  16. // 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;"/>');
  17. 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;"/>');
  18. img.click(function(){ // handle click
  19. var c = $jq("#container_" + poi.type);
  20. if(poi.type=='T'){ //contenuto testuale
  21. $jq.get("contents/"+poi.type+"_"+i+".html", function(html_string)
  22. {
  23. c.html('<div class="scrollable-content" id="sub_v">' + html_string + '</div>');
  24. },'html');
  25. }else if(poi.type=='V'){//contenuto video
  26. c.html('<source src="contents/'+poi.type+'_'+i+'.mp4" type="video/mp4" />');
  27. c.attr('currentTime',"0");
  28. c.trigger('load');
  29. c.trigger('play');
  30. }else{//è un'immagine
  31. c.html('<img src="contents/'+poi.type+'_'+i+'.jpg"/>');
  32. }
  33. c.modal();
  34. });
  35. // $jq('body').delay(Math.floor(Math.random() * 1001)).append( img );
  36. // $jq('body').append('').delay(2000).queue(function (next) {
  37. // $jq(this).append(img);
  38. // next();
  39. // });
  40. $jq('body').append( img );
  41. img.delay(500);
  42. img.animate({top: y + 'px'},'fast');
  43. img.animate({left: x + 'px'},'fast');
  44. }
  45. function toScsv(){
  46. state=0;
  47. $jq.get("asset/scsv.html", function(html_string){
  48. var body = $jq('body');
  49. body.html(html_string);
  50. $jq("#myVideo").on( "click", function(){toRiver();} )
  51. },'html');
  52. }
  53. function toRiver(){
  54. state=1;
  55. $jq.get("asset/river.html", function(html_string){
  56. var body = $jq('body');
  57. body.html(html_string);
  58. $jq('input').each(function(){
  59. var self = $jq(this),
  60. label = self.next(),
  61. label_text = label.text();
  62. label.remove();
  63. self.iCheck({
  64. checkboxClass: 'icheckbox_line-purple',
  65. radioClass: 'iradio_line-purple',
  66. insert: '<div class="icheck_line-icon"></div>' + label_text
  67. });
  68. });
  69. //fisso i bottoni ad una certa larghezza
  70. $jq( "div[class^='icheckbox_line']" ).css( "max-width", "200px" );
  71. // sposto i bottoni in alto a dx ma relativamente al loro container
  72. $jq('ul').css({
  73. position: "absolute",
  74. marginLeft: 0, marginTop: 0,
  75. top: 0, left: 0
  76. });
  77. //aggiungo l'on clicked alle checkbox
  78. $jq('input').on('ifChecked', function(event){
  79. for (let i=0; i<pois.length; i++) {
  80. var img = null;
  81. if(this.id == pois[i].cat){
  82. addPin(pois[i],i);
  83. }
  84. }
  85. //qui ci va un foreach suoi poi
  86. });
  87. $jq('input').on('ifUnchecked', function(event){
  88. //qui ci va un foreach suoi poi
  89. for (let i=0; i<pois.length; i++) {
  90. if(this.id == pois[i].cat){
  91. $jq('#pin_'+i).remove();
  92. }
  93. }
  94. });
  95. $jq( "[id^='container_']" ).on($jq.modal.AFTER_CLOSE, function(event, modal) {
  96. modal.$elm.html('');
  97. });
  98. for (let i=0; i<pois.length; i++) {
  99. if($jq('#' + pois[i].cat).is(":checked")) {
  100. addPin(pois[i],i);
  101. }
  102. }
  103. },'html');
  104. }
  105. $jq( document ).ready(function() {
  106. console.log( "ready!" );
  107. var b = $jq("body");
  108. b.css("margin-top", "0px");
  109. b.css("margin-left", "0px");
  110. b.css("margin-right", "0px");
  111. b.css("margin-bottom", "0px");
  112. $jq(".modal").css("width","auto");
  113. //disable all
  114. // $jq('.river').hide();
  115. // toRiver();
  116. toScsv();
  117. $jq('body').mousemove(function(event){
  118. console.log("RESTTO TIMER");
  119. });
  120. // $jq('#container_T').on($jq.modal.AFTER_CLOSE, function(event, modal) {
  121. // modal.$elm.html('');
  122. // });
  123. });
  124. var intervalId = setInterval(function() {
  125. if(Date.now()-timeRef>=30000 && state==1){
  126. toScsv();
  127. }
  128. }, 5000);