PageSourceSearch

https://www.sportwalter.it/js/booking.js

js sportwalter.it collected 2026-10-06 13:13:32 UTC 9,549 bytes, 283 lines download raw bytes

1//-------------------------------------------------
2//variable initialization
3//-------------------------------------------------
4var id= null;
5var elem = null;
6var y = null;
7var visiblePersons = 0;  
8var totalPrice = 0;
9
10
11//-------------------------------------------------
12//return json literal by name
13//-------------------------------------------------
14function getObjects(obj, key, val) {
15    var objects = [];
16    for (var i in obj) {
17        if (!obj.hasOwnProperty(i)) continue;
18        if (typeof obj[i] == 'object') {
19            objects = objects.concat(getObjects(obj[i], key, val));
20        } else if (i == key && obj[key] == val) {
21            objects.push(obj);
22        }
23    }
24    return objects;
25}
26
27//---------------------------------------------------------------
28//calculate price for every person
29//---------------------------------------------------------------
30function setPrice(id, elem){
31
32    //get days
33    var days = $('#days').val();  
34    
35    //get price object for the selected ski id
36    var priceObj = getObjects(prices, 'id', id);
37    
38    //if boots are not clicked, set default price
39    if(!$(elem).closest('.person').find("#boots").is(':checked'))
40    {
41        $(elem).closest('.person').find("#op_price").text(priceObj['0']['ppd_'+days]);
42    }
43    //otherwise set boots price
44    else
45    {
46        $(elem).closest('.person').find("#op_price").text(priceObj['0']['ppd_2_'+days]);
47    }
48    
49    //if helmet is clicked, add helmet price
50    if($(elem).closest('.person').find("#helmet").is(':checked'))
51    {
52        helmetPrice = parseInt(helmet['0']['ppd_'+days], 10);
53        $(elem).closest('.person').find("#op_price").text(parseInt($(elem).closest('.person').find("#op_price").text()) + (helmetPrice*1));
54    }
55    
56    
57    //set duration
58    $(elem).closest('.person').find("#op_days").text(days);
59    
60    //set discounted price
61    discountedPrice = parseInt($(elem).closest('.person').find("#op_price").text()) - (parseInt($(elem).closest('.person').find("#op_price").text()) * 0.10);
62    $(elem).closest('.person').find("#discounted-price").text(discountedPrice);
63    $(elem).closest('.person').find("#price").val(discountedPrice);    
64    
65    
66    //hide boots if no boot price is defined in the backend
67    if(priceObj['0']['ppd_2_1'] == "0")
68    {
69        $(elem).closest('.person').find("#boots").closest(".form-element").hide();
70    }
71    //else show helmet
72    else
73    {
74        $(elem).closest('.person').find("#boots").closest(".form-element").show();
75        
76    }   
77         
78}
79
80//-------------------------------------------------
81//quickfix: set prices to null if they are NaN
82//-------------------------------------------------
83function setNull(){
84    if($(".form-block:not(.template) #op_price").text() == "")
85    {
86        $(".form-block:not(.template) #op_price").text("0");
87        $(".form-block:not(.template) #summary-price").text("0");
88        $(".form-block:not(.template) #discounted-price").text("0");
89        $("#summary-price").text("0");   
90    }
91}
92
93function updateSummary()
94{
95    var totalPrice = 0;
96    
97    $(".person").each(function() {
98        totalPrice += parseInt($(this).find("#op_price").text());
99    });
100    
101    $("#booking-summary #summary-persons").text($("#persons").val());
102    $("#booking-summary #summary-days").text($("#days").val());
103    $("#booking-summary #summary-price").text(totalPrice - (totalPrice * 0.10));
104    $("#total-price").val(totalPrice - (totalPrice * 0.10));      
105    
106}
107
108
109
110$(function() { 
111
112    //datepicker
113    $( ".datepicker" ).datepicker();    
114    
115    //persons onChange event: clone div
116    $('#persons').change(function() {
117        
118        //if clicked persons is greater than visible persons
119        if(jQuery(this).val() > visiblePersons)
120        {
121            
122            for ( var i = visiblePersons; i < jQuery(this).val(); i++ ) {
123                
124                //clone the "template" person
125                jqEl = $(".form-template").clone();
126                
127                //make cloned element visible and remove template class
128                $(jqEl).removeClass("hidden");
129                $(jqEl).removeClass("form-template");
130                
131                //add incrementing person counter
132                $(jqEl).contents().find( ".person-counter" ).text(i*1+1);
133                                
134                //update id's with correct progressing number
135                $(jqEl).find("#select-ski").attr("name", "select-ski_" + (i*1+1));
136                $(jqEl).find("#boots").attr("name", "boots_" + (i*1+1));
137                $(jqEl).find("#helmet").attr("name", "helmet_" + (i*1+1));
138                $(jqEl).find("#hidsel").attr("name", "hidsel_" + (i*1+1));
139                $(jqEl).find("#category").attr("name", "category_" + (i*1+1));
140                $(jqEl).find("#price").attr("name", "price_" + (i*1+1));
141                
142                //add id and class attribute
143                $(jqEl).attr('id', (i*1+1));
144                $(jqEl).addClass('person');
145                
146                //get language
147                var pathname = window.location.pathname.split("/");
148                var lang = pathname[pathname.length-2];
149                
150                if(lang == "it")
151                    var selDesc = "Scegli l´attrezzatura";
152                if(lang == "de")
153                    var selDesc = "Ski- und Wintersportausrüstung auswhälen";
154                if(lang == "en")
155                    var selDesc = "Choose your ski and winter sports equipment";                                        
156                
157                
158
159                
160                //make it slick
161                $(jqEl).find("select").ddslick({
162                    width: '100%',
163                    showSelectedHTML: true,
164                    selectText: selDesc,
165                    onSelected: function(data){
166                    
167                        //get the clicked id and item
168                        id = data.selectedData.value;
169                        elem = data.selectedItem;
170                        category = data.selectedData.text;
171                        
172                        //set hidden input to selected value for convenience
173                        $(elem).closest('.person').find("#hidsel").val(id);
174                        $(elem).closest('.person').find("#category").val(category);
175                        
176                        //... and set price
177                        setPrice(id, elem);
178                        
179                        //update summary
180                        updateSummary();                        
181                        
182                    }           
183                });
184                
185                //and finally append to form
186                $("#persons-container").append(jqEl);
187                
188                //and update summary
189                updateSummary();
190                  
191            }        
192        }
193        //...otherwise remove persons
194        
195        else
196        {
197            for ( var i = visiblePersons; i > jQuery(this).val(); i-- ) {
198                $('#' + i).remove();
199            } 
200            
201            //and update summary
202            updateSummary();            
203                      
204        }
205        
206        visiblePersons = jQuery(this).val();
207
208    });
209    //immediately fire person change event
210    $("#persons").change();  
211    
212    //days onChange event
213    $('#days').change(function() {
214        $( ".person" ).each(function( index ) {
215        
216            var id = $(this).find("#hidsel").val()
217            //set price only if id is set (if user has already chosen a ski)
218            if(id)
219                setPrice(id, $(this));
220            
221        });
222        
223        //update summary
224        updateSummary();        
225        
226    }); 
227    
228    //boots onChange event
229    $( "body" ).on( "click", "input#boots", function() {
230        var id = $(this).closest('.person').find("#hidsel").val()
231        setPrice(id, $(this));
232        //update summary
233        updateSummary();        
234    });
235    
236    //helmet onChange event
237    $( "body" ).on( "click", "input#helmet", function() {
238        var id = $(this).closest('.person').find("#hidsel").val()
239        setPrice(id, $(this));
240        //update summary
241        updateSummary(); 
242    }); 
243    
244    //check checkbox if helmet or boots image is clicked
245    //$( "body" ).on( "click", ".checkbox", function() {
246        //$(this).find('input').prop('checked', !$(this).find('input').prop("checked"));
247        
248    //}); 
249    
250    $( "body" ).on( "click", "input[type=\"submit\"]", function() {
251        $("form#booking").submit();
252    });    
253    
254    //sticky warenkorb
255    
256    if( !/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
257    
258        if ($("#booking-summary").length > 0){
259            $("#booking-summary").sticky({topSpacing:30});
260        }
261    
262    }
263    
264    //validation
265    if ($("form#booking").length > 0){
266        $("form#booking").validate();
267    }    
268    
269    //set values to "0" if they are "NaN"
270    setNull();  
271   
272
273    //tooltip
274    //$("span.no-boots, span.with-boots").tooltip({ tooltipClass: "tooltip" });
275    
276    //hide honeypot
277    $(".hp").hide();
278    
279    
280
281});
282
283

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.