PageSourceSearch

https://blunavytraghetti.com/wp-content/themes/cosmo/assets/js/orari.js?ver=1775745451

js blunavytraghetti.com collected 2026-09-24 12:35:21 UTC 7,726 bytes, 249 lines download raw bytes

1jQuery(document).ready(function ($) {
2  if ($('.orari').length) {
3    let periodi = null
4    let partenze = {}
5
6    function changeOptionsPeriodo () {
7      var valuesPartenza = partenza.getSelected()
8      $('#single-periodi option').each(function () {
9        $(this).addClass('d-none')
10        if ($(this).data('destination') == valuesPartenza[0].toLowerCase()) {
11          $(this).removeClass('d-none')
12        }
13      })
14    }
15
16    $('.prossima-partenza span').each(function () {
17      let partenza = $(this).data('destination')
18      let titolo = $(this).data('titolo')
19      partenze[partenza] = {
20        titolo: titolo,
21        ore: Infinity,
22        minuti: Infinity,
23        domani: false,
24      }
25      console.log(partenze)
26    })
27
28    const handleProssimaPartenza = () => {
29      $('.prossima-partenza span').each(function () {
30        const destinazione = partenza.getSelected()
31        if ($(this).data('destination') == destinazione) {
32          $(this).removeClass('d-none')
33        } else {
34          $(this).addClass('d-none')
35        }
36      })
37    }
38
39    const eventHandlerPartenza = (val) => {
40      $('#single-periodi option').each(function () {
41        $(this).addClass('d-none')
42        if ($(this).data('destination') == val.value.toLowerCase()) {
43          $(this).removeClass('d-none')
44        }
45      })
46
47      selectCurrentPeriodo()
48
49      // setTimeout(() => {
50      //   periodi.setSelected($('#single-periodi option:not(.d-none)').val())
51      // }, 200)
52    }
53
54    const partenza = new SlimSelect({
55      select: '#single-partenza',
56      settings: {
57        showSearch: false,
58        hideSelected: true,
59      },
60      events: {
61        afterChange: (newVal) => {
62          eventHandlerPartenza(newVal[0])
63          eventHandlerPartenza(newVal[0])
64          const dataPeriodi = periodi.getData()
65          eventHandlerPeriodi(dataPeriodi[0])
66          handleProssimaPartenza()
67          changeOptionsPeriodo()
68        },
69      },
70    })
71
72    handleProssimaPartenza()
73
74    const eventHandlerPeriodi = (val) => {
75      $('.week').each(function () {
76        $(this).addClass('d-none')
77        const destinazione = partenza.getSelected()
78        if ($(this).data('periodo') == val.value && $(this).data('destinazione') == destinazione) {
79          $(this).removeClass('d-none')
80        }
81      })
82
83      periodi.setSelected(val.value)
84    }
85
86    periodi = new SlimSelect({
87      select: '#single-periodi',
88      settings: {
89        showSearch: false,
90        hideSelected: false,
91      },
92      events: {
93        afterChange: (newVal) => {
94          eventHandlerPeriodi(newVal[0])
95        },
96      },
97    })
98
99    const selectCurrentPeriodo = () => {
100      $('.week').each(function () {
101        const destinazione = partenza.getSelected()
102        if ($(this).data('destinazione') == destinazione) {
103          const periodo = $(this).data('periodo').split('_')
104          const inizioPeriodo = periodo[0].split('-')
105          const finePeriodo = periodo[1].split('-')
106
107          let time_start = new Date()
108          let today = new Date()
109          let time_end = new Date()
110
111          time_start.setMonth(inizioPeriodo[1] - 1)
112          time_start.setDate(inizioPeriodo[0])
113
114          time_end.setMonth(finePeriodo[1] - 1)
115          time_end.setDate(finePeriodo[0])
116
117          if (time_start <= today && today <= time_end) {
118            periodi.setSelected($(this).data('periodo'))
119          }
120        }
121      })
122    }
123
124    selectCurrentPeriodo()
125
126    // Uno di questi due triggera l'eventhandleperiodi, non so qual dei due, ma funziona, non toccare
127    const dataPeriodi = periodi.getData()
128    var valuesPeriodo = periodi.getSelected()
129
130    $('.week').each(function () {
131      $(this).addClass('d-none')
132      const destinazione = partenza.getSelected()
133      if ($(this).data('periodo') == valuesPeriodo && $(this).data('destinazione') == destinazione) {
134        $(this).removeClass('d-none')
135      }
136    })
137
138
139    function updateNextDeparture() {
140      const date = new Date()
141      const hour = date.getHours()
142      const minute = date.getMinutes()
143
144
145      console.log('dates', WPURLS.daily_departures.date)
146
147      Object.keys(WPURLS.daily_departures.date[0].destinazioni).forEac
147h((val) => {
148        partenze[val]['ore'] = Infinity
149        partenze[val]['minuti'] = Infinity
150        partenze[val]['domani'] = false
151
152        WPURLS.daily_departures.date[0].destinazioni[val].map((orari, index) => {
153          const ora = orari.split(':')[0]
154          const minuti = orari.split(':')[1]
155
156          var time_start = new Date()
157          var time_end = new Date()
158
159          time_start.setHours(hour, minute, 0, 0)
160          time_end.setHours(ora, minuti, 0, 0)
161
162          time_end - time_start // millisecond
163
164          let hours_end = parseInt((time_end - time_start) / 1000 / 60 / 60)
165          let minute_end = ((time_end - time_start) / 1000 / 60) % 60
166
167          
168          if (hours_end > 0 && hours_end <= partenze[val]['ore'] && minute_end > 0 && minute_end <= partenze[val]['minuti']) {
169            partenze[val]['ore'] = hours_end
170            partenze[val]['minuti'] = minute_end
171          }
172        })
173      })
174
175      Object.keys(WPURLS.daily_departures.date[1].destinazioni).forEach((val) => {
176        if (partenze[val]['ore'] == Infinity || partenze[val]['minuti'] == Infinity) {
177          WPURLS.daily_departures.date[1].destinazioni[val].map((orari) => {
178            const ora = orari.split(':')[0]
179            const minuti = orari.split(':')[1]
180
181            var time_start = new Date()
182            var time_end = new Date(time_start)
183
184            time_end.setDate(time_end.getDate() + 1)
185
186            
187            time_start.setHours(hour, minute, 0, 0)
188            time_end.setHours(ora, minuti, 0, 0)
189            
190
191            time_end - time_start // millisecond
192
193            let hours_end = parseInt((time_end - time_start) / 1000 / 60 / 60)
194            let minute_end = ((time_end - time_start) / 1000 / 60) % 60
195
196            if (hours_end > 0 && hours_end <= partenze[val]['ore'] && minute_end > 0 && minute_end <= partenze[val]['minuti']) {
197              partenze[val]['ore'] = hours_end
198              partenze[val]['minuti'] = minute_end
199              partenze[val]['domani'] = true
200            }
201          })
202        }
203      })
204
205      $('.prossima-partenza span').each(function () {
206        Object.keys(partenze).forEach((val) => {
207          if (val == $(this).data('destination')) {
208            let stringPartenza = ''
209
210            stringPartenza = WPURLS.string.prossimaPartenzaIn
211
212            stringPartenza += ' <b>' + partenze[val]['titolo'] + '</b> '
213
214            if (partenze[val]['domani']) {
215              stringPartenza += WPURLS.string.previstroDomaniTra
216            } else {
217              stringPartenza += WPURLS.string.previstroTra
218            }
219
220            if (partenze[val]['ore'] == 1) {
221              stringPartenza += '<b> 1 ' + WPURLS.string.ora + '</b> ' + WPURLS.string.e
222            } else if (partenze[val]['ore'] > 1) {
223              stringPartenza += '<b> ' + partenze[val]['ore'] + ' ' + WPURLS.string.ore + '</b> ' + WPURLS.string.e
224            }
225
226            if (partenze[val]['minuti'] == 1) {
227              stringPartenza += '<b> 1 ' + WPURLS.string.minuto + '</b>'
228            } else if (partenze[val]['minuti'] > 1) {
229              stringPartenza += '<b> ' + partenze[val]['minuti'] + ' ' + WPURLS.string.minuti + '</b>'
230            }
231
232            $(this).empty()
233            $(this).append(stringPartenza)
234          }
235        })
236      })
237
238      setTimeout(function () {
239        updateNextDeparture()
240      }, 60000)
241    }
242
243    updateNextDeparture()
244	  
245	changeOptionsPeriodo()
246
247    // richiamare al change della destinazione
248  }
249})

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.