1class PriceSimulator { 2 3 constructor() { 4 this.resultDiv = $('#result'); 5 this.giorniTotali = 0; 6 this.prezzoFinale = 0; 7 this.bottoneForm = $('.popup-form-simulator-trigger'); 8 this.form = $('.form-prenotazione-simulator'); 9 this.events(); 10 } 11 12 events() { 13 $('.rect.mese').on('click', this.appearButtons.bind(this)); 14 $('.price-sel').on('click', this.getResults.bind(this)); 15 $('.simulator-button').on('click', this.appearSection.bind(this)); 16 $(this.bottoneForm).on('click', this.trasferimentoDati.bind(this)); 17 } 18 19 // Methods 20 21 trasferimentoDati() { 22 23 // Tipologia 24 if ($('.simulator-button.active').attr('data-filter') == 'villa-piscina') { 25 $(this.form).find('#form-cont-tipologia').val('Villa con piscina'); 26 } else if ($('.simulator-button.active').attr('data-filter') == 'villa') { 27 $(this.form).find('#form-cont-tipologia').val('Villa'); 28 } else if ($('.simulator-button.active').attr('data-filter') == 'cottage') { 29 $(this.form).find('#form-cont-tipologia').val('Cottage'); 30 } else if ($('.simulator-button.active').attr('data-filter') == 'piccolo-cottage') { 31 $(this.form).find('#form-cont-tipologia').val('Piccolo cottage'); 32 } 33 34 // Selezione 35 36 var bottoniSelezionati = ''; 37 38 if ($('.button.price-sel.selected').length) { 39 40 var mesiSelezionati = $('.rect.mese.selected'); 41 42 for (var i = 0; i < mesiSelezionati.length; i++) { 43 44 var mese = $(mesiSelezionati[i]).find('p').html(); 45 var durata = $(mesiSelezionati[i]).siblings('.piccoli-rect').find('.button.price-sel.selected p').html(); 46 47 bottoniSelezionati = bottoniSelezionati + mese + ': ' + durata + ', '; 48 49 } 50 51 $(this.form).find('input#selezione').val(bottoniSelezionati); 52 53 } else if ($('.rect.price-sel.pacchetto.selected').length) { 54 55 bottoniSelezionati = $('.rect.price-sel.pacchetto.selected p').html(); 56 57 $(this.form).find('input#selezione').val(bottoniSelezionati); 58 59 } 60 61 // Prezzo 62 if (this.giorniTotali == 60) { 63 $(this.form).find('input#prezzo').val(new Intl.NumberFormat().format(this.prezzoFinale * .9) + ',00.'); 64 } else if (this.giorniTotali > 60) { 65 $(this.form).find('input#prezzo').val(new Intl.NumberFormat().format(this.prezzoFinale * .8) + ',00.'); 66 } else { 67 $(this.form).find('input#prezzo').val(new Intl.NumberFormat().format(this.prezzoFinale) + ',00.'); 68 } 69 70 } 71 72 appearSection(e) { 73 74 // Riporta i valori a 0 75 this.prezzoFinale = 0; 76 this.giorniTotali = 0; 77 $(this.resultDiv).addClass('hidden'); 78 79 // Disattiva i bottoni 80 $('.bottoni-per-tipologia .piccoli-rect').addClass('hidden').find('.button.selected'); 81 $('.price-sel').attr("data-selected", 'no'); 82 $('.bottoni-per-tipologia .selected').removeClass('selected'); 83 84 // Seleziona la tipologia di casa cliccata 85 var tipologia = $(e.target).attr('data-filter'); 86 // Seleziona la sezione con la tipologia di classe cliccata 87 var sezioneTipologia = $('.bottoni-per-tipologia.' + tipologia); 88 89 // Se è nascosta 90 if ($(sezioneTipologia).hasClass('hidden')) { 91 92 // Nasconde le altre sezioni 93 $(sezioneTipologia).siblings('.bottoni-per-tipologia').addClass('hidden'); 94 // Mostra la sezione cliccata 95 $(sezioneTipologia).removeClass('hidden'); 96 97 // Disattiva tutti gli altri bottoni 98 $(e.target).siblings('.simulator-button').removeClass('active'); 99 // Attiva il bottone cliccato 100 $(e.target).addClass('active'); 101 102 } else { // Se è già visibile 103 104 // Nasconde la sezione cliccata 105 $(sezioneTipologia).addClass('hidden'); 106 // Disattiva il bottone cliccato 107 $(e.target).removeClass('active'); 108 109 } 110 111 } 112 113 appearButtons(e) { 114 115 // Se il mese è selezionato 116 if ($(e.target).hasClass('selected')) { 117 118 // Disattiva i bottoni sottostanti 119 $(e.target).siblings('.piccoli-rect').find('.button.selected').attr("data-selected", 'no'); 120 121 var dataPrice = parseInt($(e.target).siblings('.piccoli-rect').find('.button.selected').attr("data-price")); 122 var dataDays = parseInt($(e.target).siblings('.piccoli-rect').find('.button.selected').attr("data-value")); 123 124 // Sottrae il valore dei bottoni 125 if (!isNaN(dataPrice)) { 126 127 this.prezzoFinale = (parseInt(this.prezzoFinale) - dataPrice); 128 this.giorniTotali = (parseInt(this.giorniTotali) - dataDays); 129 130 // Nasconde il box se prezzo è 0 131 if (this.prezzoFinale == 0) { 132 $(this.resultDiv).addClass('hidden'); 133 } else { 134 135 if (this.giorniTotali == 60) { 136 $(this.resultDiv).removeClass('hidden').find('#result-value').html(new Intl.NumberFormat().format(this.prezzoFinale * .9) + ',00.'); 137 } else if (this.giorniTotali > 60) { 138 $(this.resultDiv).removeClass('hidden').find('#result-value').html(new Intl.NumberFormat().format(this.prezzoFinale * .8) + ',00.'); 139 } else { 140 $(this.resultDiv).removeClass('hidden').find('#result-value').html(new Intl.NumberFormat().format(this.prezzoFinale) + ',00.'); 141 } 142 143 } 144 145 } 146 147 // Nasconde i bottoni 148 $(e.target).removeClass('selected'); 149 $(e.target).siblings('.piccoli-rect').addClass('hidden'); 150 $(e.target).siblings('.piccoli-rect').find('.button.selected').removeClass('selected'); 151 152 } else { // Se il mese non è selezionato 153 154 // Attiva il mese e mostra i bottoni 155 $(e.target).addClass('selected'); 156 $(e.target).siblings('.piccoli-rect').removeClass('hidden'); 157 158 } 159 160 } 161 162 getResults(e) { 163 164 // Dato: selezionato o no 165 var selected = $(e.target).attr("data-selected"); 166 // Dato: prezzo 167 var dataPrice = parseInt($(e.target).attr("data-price")); 168 // Dato: giorni 169 var dataDays = parseInt($(e.target).attr("data-value")); 170 171 // Se il bottone non è selezionato 172 if (selected == 'no') { 173 174 // Se il bottone è un pacchetto 175 if ($(e.target).hasClass('pacchetto')) { 176 177 // Se ci sono bottoni mese selezionati 178 if ($('.rect.mese.selected').length) { 179 180 // Resetta i valori 181 this.prezzoFinale = 0; 182 this.giorniTotali = 0; 183 184 // Disattiva bottoni mese già cliccati 185 $('.rect.mese.selected').removeClass('selected').siblings('.piccoli-rect').addClass('hidden').find('.button.selected').removeClass('selected').attr("data-selected", 'no'); 186 187 } 188 189 } else if ($(e.target).hasClass('price-sel')) { // Se il bottone è un mese 190 191 // Se ci sono bottoni pacchetto selezionati 192 if ($('.pacchetto.selected').length) { 193 194 // Sottrae il valore del pacchetto selezionato 195 this.prezzoFinale = (parseInt(this.prezzoFinale) - parseInt($('.pacchetto.selected').attr('data-price'))); 196 197 // Disattiva bottone pacchetto 198 $('.pacchetto.selected').removeClass('selected').attr('data-selected', 'no'); 199 200 } 201 202 } 203 204 // Elimina altri bottoni dello stesso mese 205 var otherSelected = $(e.target).siblings('*[data-selected="yes"]'); 206 var otherSelectedPrice = parseInt($(otherSelected).attr("data-price")); 207 var otherSelectedDays = parseInt($(otherSelected).attr("data-value")); 208 209 $(otherSelected).removeClass('selected').attr("data-selected", 'no'); 210 211 if (!isNaN(otherSelectedPrice)) { 212 this.prezzoFinale = (parseInt(this.prezzoFinale) - otherSelectedPrice); 213 this.giorniTotali = (parseInt(this.giorniTotali) - otherSelectedDays); 214 } 215 216 // Attiva il bottone selezionato 217 $(e.target).addClass('selected'); 218 this.prezzoFinale = (parseInt(this.prezzoFinale) + dataPrice); 219 this.giorniTotali = (parseInt(this.giorniTotali) + dataDays); 220 221 $(e.target).attr("data-selected", "yes"); 222 223 } else { // Se il bottone è slezionato 224 225 // Elimina il bottone schiacciato 226 $(e.target).removeClass('selected'); 227 this.prezzoFinale = (parseInt(this.prezzoFinale) - dataPrice); 228 this.giorniTotali = (parseInt(this.giorniTotali) - dataDays); 229 230 $(e.target).attr("data-selected", "no"); 231 232 } 233 234 // Se il prezzo finale è 0, elimina il box del risultato 235 if (this.prezzoFinale == 0) { 236 $(this.resultDiv).addClass('hidden'); 237 } else { 238 239 if (this.giorniTotali == 60) { 240 $(this.resultDiv).removeClass('hidden').find('#result-value').html(new Intl.NumberFormat().format(this.prezzoFinale * .9) + ',00.'); 241 } else if (this.giorniTotali > 60) { 242 $(this.resultDiv).removeClass('hidden').find('#result-value').html(new Intl.NumberFormat().format(this.prezzoFinale * .8) + ',00.'); 243 } else { 244 $(this.resultDiv).removeClass('hidden').find('#result-value').html(new Intl.NumberFormat().format(this.prezzoFinale) + ',00.'); 245 } 246 247 } 248 249 } 250 251} 252 253var priceSimulator = new PriceSimulator; 254 255class ShowContent { 256 257 constructor() { 258 this.button = $('button[name="show-content-button"]'); 259 this.contentToShow = $(document).find('.content-to-show')[0]; 260 this.events(); 261 } 262 263 events() { 264 $(this.button).on('click', () => { 265 if (this.button.attr('data-clicked') == 'no') { 266 this.showContent(); 267 } else { 268 this.hideContent(); 269 } 270 }); 271 } 272 273 showContent() { 274 $(this.contentToShow).removeClass('no').addClass('yes'); 275 $(this.button).attr('data-clicked', 'yes').find('img').css('transform', 'rotate(0deg)'); 276 } 277 278 hideContent() { 279 $(this.contentToShow).removeClass('yes').addClass('no'); 280 $(this.button).attr('data-clicked', 'no').find('img').css('transform', 'rotate(180deg)'); 281 } 282 283} 284 285var showContent = new ShowContent;
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.