PageSourceSearch

https://visitayas.it/themes/custom/turismo/js/custom.js?th17ko

js visitayas.it collected 2026-10-06 00:19:05 UTC 11,636 bytes, 364 lines download raw bytes

1var scroll_margin_top = 45;
2var show_map = false; // switch mappa aggregatori
3(function ($, Drupal) {
4  'use strict';
5  // *** aggiungere qui codice che non deve usare i behaviors di Drupal
6  if (typeof (IAT) != 'undefined') {
7    IAT.SLIDER.init();
8
9    $(".section-swiper-accordion .section__content-title").on("click", function() { 
10      IAT.SLIDER.init(); 	
11    });
12  }
13
14  var anchor_click = function(e) {
15    e.preventDefault();
16    $( 'html,body' ).animate({
17      scrollTop: $($.attr(this, 'href')).offset().top - scroll_margin_top
18    }, 500 );
19  }
20
21  function msieversion() {
22    var ua = window.navigator.userAgent;
23    var msie = ua.indexOf("MSIE ");
24
25    if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./))  // If Internet Explorer, return version number
26    {
27        return true;
28    }
29
30    return false;
31  }
32
33  // Set a Cookie
34  function setCookie(cName, cValue, expHours) {
35    var date = new Date();
36    date.setTime(date.getTime() + (expHours * 60 * 60 * 1000));
37    var expires = "expires=" + date.toUTCString();
38    document.cookie = cName + "=" + cValue + "; " + expires + "; path=/";
39  }
40
41  // toogle modalità mappa negli aggregatori
42  function toggle_view_map() {
43    if (show_map && drupalSettings.leaflet !== undefined) {     
44      setTimeout(function(){
45        var map_item_ids = Object.keys(drupalSettings.leaflet);
46        var map_item_id = null;
47        for (let i = (map_item_ids.length-1); i >= 0; i--) {
48          map_item_id = map_item_ids[i];
49          if (document.getElementById(map_item_id)) {
50            break;
51          }
52        }
53        var map_item = drupalSettings.leaflet[map_item_id];
54        map_item.lMap.invalidateSize(false);
55        if (map_item.features.length) {
56          map_item.lMap.fitBounds(map_item.features);  
57        }
58        window.dispatchEvent(new Event('resize'));
59      }, 50);
60    }   
61  }
62
63  $(function () {
64
65    // inizializzazione menù //
66    // if ($('#menu .main-nav__list').length) {
67    //   $('#menu .main-nav__list').menuTop(); 
68    // }
69    
70    // inizializzazione tabmenù //
71    $(".header__menus").tabs({
72      active: false,
73      collapsible: true,
74    });
75
76    // inizializzazione tabs vicinanze
77    if ($("#js-slider-tabbed__list").length) {
78      $("#js-slider-tabbed__list").tabs({
79        activate: function(event, ui) {
80          var swiper=ui.newPanel.find('.swiper-container').get(0).swiper;
81          if (swiper) {
82            swiper.update();
83            swiper.slideTo(0);
84            //swiper.autoplay.paused=false;
85            //swiper.autoplay.start();
86          }
87        },
88        beforeActivate: function(event, ui){
89          var ok = (ui.newPanel.find('.swiper-container').length > 0);
90          if (!ok) event.preventDefault();
91        }
92      });
93    }
94
95    // gestione object-fit su IE
96    if ( msieversion() ) {
97      $.getScript( "//cdnjs.cloudflare.com/ajax/libs/object-fit-images/3.2.4/ofi.min.js", function( data, textStatus, jqxhr ) {
98        if (jqxhr.status === 200) {
99          objectFitImages('img.obj-fit');
100        }
101      });
102    }
103
104    // js-section-map
105    $('.js-section-map .toggle').click(function () {
106      if ($(this).hasClass('active')) {
107        // setTimeout(function(){ map.invalidateSize()}, 400);
108        window.dispatchEvent(new Event('resize'));
109      }
110    });
111
112    // gestione tabs slider
113    var tabs_class = '#tab-list';
114    if ($(tabs_class).length) {
115      $("#tab-list").tabs({
116        activate: function(event, ui) {
117          var swiper=ui.newPanel.find('.swiper-container').get(0).swiper;
118          if (swiper) {
119            swiper.update();
120            swiper.slideTo(0);
121            // swiper.autoplay.paused=false;
122            // swiper.autoplay.start();
123          }
124        },
125        beforeActivate: function(event, ui){
126          var ok=(ui.newPanel.find('.swiper-container').length>0);
127          if (!ok) event.preventDefault();
128        }
129      });
130    }
131
132    // ANCHOR link
133    // $( '.anchor' ).on( 'click', anchor_click);
134    $(document).on('click', '.anchor', anchor_click);
135
136    // SEASON CHANGE
137    $(document).on('click', '.js-season-change', function(e) {
138      // e.preventDefault();
139      var season = $(this).data('season');
140      if (season) {
141        setCookie('edt_season', season, 8);
142      }
143    });
144    var season = $("body").data('set-season');
145    if (season) {
146      setCookie('edt_season', season, 8);
147    }
148
149    // applico il link alle email
150    $('.js-mailto').each(function() {
151      var mailto = $(this).html();
152      if(mailto) {
153        $(this).html('<a class="link--underline-animation" href="mailto:' + mailto + '">' + mailto + '</a>');
154      }
155    });
156    // applico il link ai numeri di telefono solo da mobile
157		if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
158			$('.js-tel').each(function() {
159				var tel = $(this).html();
160				if(tel) {
161					$(this).html("<a href='tel:"+tel+"'>"+tel+"</a>");
162				}
163      });
164		}
165
166    $(document).on('click', '.js-show-map', function(e) {
167      e.preventDefault();
168
169      $(this).toggleClass('active');
170
171      show_map = !show_map;
172      
173      if (show_map) {
174        $('.block-aggregatore').addClass('js-view-show-map');
175        toggle_view_map();
176      } else {
177        $('.block-aggregatore').removeClass('js-view-show-map');
178      }
179    });
180
181    // aggiungo timestamp ai links (usato per webcam)
182    $('img.js-timestamp').each(function() {
183      this.src = addTimestampToUrl(this.src);
184    });
185
186    function addTimestampToUrl(url) {
187      return url + (url.indexOf('?') >= 0 ? '&' : '?') + 'timestamp=' + new Date().getTime();
188    }
189    
190    /**
191     * Funzione per ottenere la data e l'ora corrente compreso il fuso orario
192     */
193    function getDateTime() {
194      var options = {
195        timeZone: 'Europe/Rome',
196        year: 'numeric',
197        month: '2-digit',
198        day: '2-digit',
199        hour: '2-digit',
200        minute: '2-digit',
201        hour12: false,
202        timeZoneName: 'short'
203      };
204      
205      var now = new Date();
206      var formatter = new Intl.DateTimeFormat(drupalSettings.path.currentLanguage, options);
207      var result = formatter.format(now);
208      
209      return result;
210    }
211    
212    // data realtime skirama
213    if ($('.js-realtime-skirama').length) {
214      $('.js-realtime-skirama').html(getDateTime());
215    }
216
217    // test load views
218    // $.ajax({
219    //   url: drupalSettings.path.baseUrl + 'views/ajax',
220    //   type: 'post',
221    //   data: {
222    //     view_name: 'aggregatore_eventi',
223    //     view_display_id: 'map', //your display id
224    //     // view_args: VIEW_ARGUMENT_HERE, // your views argument(s)
225    //   },
226    //   dataType: 'json',
227    //   success: function (response) {
228    //     console.log(response);
229    //     var views_dom_id = Object.keys(response[0].settings.views.ajaxViews)[0];
230    //     $('<div>', {
231    //         class: 'js-view-dom-id-' + views_dom_id,
232    //     }).appendTo('.block-aggregatore');
233    //     // if (response[1] !== undefined) {
234    //     //   console.log(response[1].data); // do something with the view
235    //     // }
236    //     var ajaxObject = Drupal.ajax({
237    //       url: '',
238    //       base: false,
239    //       element: false,
240    //       // Use the 'submit' key to pass data.
241    //       // Leave this key out if not passing any data.
242    //       submit: {},
243    //       progress: false
244    //     });
245    //     ajaxObject.success(response, "success");
246    //     Drupal.attachBehaviors();
247    //   }
248    // });
249  });
250
251  // *** da qui in poi solo behaviors di Drupal
252  if (typeof Drupal === 'undefined') {
253    return;
254  }
255  
256  function filterCheckboxTrigger(_this, chk_box_class_name, field_name) {
257    var new_val = [];
258    var current = $(_this);
259    var val = $(_this).val();
260
261    if (current.is(':checked') && val == 'all') {
262      $( "." + chk_box_class_name + ":not(.btn-all)" ).removeClass('on').prop('checked', false);
263    }
264
265    if (val != 'all') {
266      current.toggleClass('on');
267      if ($( "." + chk_box_class_name + ":checked:not(.btn-all)").length > 0) {
268        $( "." + chk_box_class_name + '.btn-all' ).removeClass('on').prop('checked', false);
269      } else {
270        $( "." + chk_box_class_name + '.btn-all' ).removeClass('on').prop('checked', true);
271      }
272
273      $( "." + chk_box_class_name + ":checked:not(.btn-all)").each(function(e) {
274        new_val.push($(this).val());
275      });
276    }
277
278    $( "select[name='" + field_name + "[]']" ).val(new_val);
279  }
280
281  Drupal.behaviors.search_api = {
282    attach: function (context, settings) {
283      // gestione pulsanti search
284      if ($('.view-search-api .js-form-item-type_btn').length > 0) {
285        $($(".view-search-api .btn-filter-type"), context).once('search_api').click(function(e) {
286          filterCheckboxTrigger(this, 'btn-filter-type', 'type');
287          return;
288        });
289        $($(".view-search-api .btn-filter-valle"), context).once('search_api').click(function(e) {
290          filterCheckboxTrigger(this, 'btn-filter-valle', 'field_area_turistica');
291          return;
292        });
293      } // end if div exists
294    } // end attach
295  };
296
297  // Filter ajax
298  Drupal.behaviors.edt_aggregatori = {
299    attach: function(context, settings) {
300      $(document).ajaxComplete(function(event, jqXHR, settings) {
301        if (settings.extraData && settings.extraData.view_display_id && settings.extraData.view_display_id.lastIndexOf('aggregatore_') === 0) {
302          // console.log([context, $(context).is('.view-with-filter')]);
303          if (!$(context).is('.view-with-filter')) {
304            return;
305          }
306          $('.js-view-results', context).once('edt_aggregatori_ajax_submit').each(function() {
307            // console.log('quii');
308            // set url after search
309            var formData = $( '.views-exposed-form', context ).serialize();
310            if(formData) {
311              var url = window.location.href;
312              url = url.replace(/\?.*/, '');
313              url = url + '?' + formData;
314              window.history.pushState({}, document.title, url);
315            }
316            var map_is_open = $('.block-aggregatore').hasClass('js-view-show-map');
317            if (map_is_open) {
318              $('.js-show-map').addClass('active');
319            }
320            // if the user uses the scrollbar while the animation is executing, it stops the animation.
321            $(window).on("mousewheel", function() {
322              $("html, body").stop();
323            });
324            $( 'html, body' ).animate({
325              scrollTop: $( '.js-view-results' ).parent().offset().top - scroll_margin_top
326            }, 500 );
327          });
328        }
329      });
330    }
331  }
332
333  $(function () {
334    if (Drupal.AjaxCommands) {
335      Drupal.AjaxCommands.prototype.shopping = function(ajax, response, status) {
336        if (response.result.err) {
337          // console.error(response.result.err);
338          alert('Si è verificato un errore: ' + response.result.err);
339          return;
340        }
341        if (response.result.count) {
342          // console.log(ajax.element);
343          // $(ajax.element).closest('tr').addClass('deshopped');
344          $(ajax.element).after('<span class="success">✔</span>').hide();
345          // location.reload();
346        }
347      } 
348    }
349  });
350
351})(jQuery, Drupal);
352
353// GLOBAL cookie
354
355function EDTgetCookie(cookie_name) {
356  return Cookies.get(cookie_name);
357}
358
359function EDTsetCookie(cookie_name, value, cookie_time) {
360  var t = new Date();
361  t.setSeconds(t.getSeconds() + cookie_time);
362  value = (typeof value == 'object') ? JSON.stringify(value) : value;
363  Cookies.set(cookie_name, value, {expires: t, path: '/'});
364}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.