PageSourceSearch

https://www.lavilletta.it/wp-content/plugins/wp-hotel-booking/incl…/assets/js/site.js?ver=1790424453

js lavilletta.it collected 2026-09-26 12:08:59 UTC 9,350 bytes, 221 lines download raw bytes

1(function ($) {
2
3    TPHB_Extra_Site = {
4
5        init: function () {
6            // toggle extra field optional
7            this.toggle_extra();
8            // toggle input number when checked checkbox and process price
9            // this.toggleCheckbox();
10            // remove package cart
11            this.removePackage();
12
13        },
14
15        parseJSON: function (data) {
16            if (!$.isPlainObject(data)) {
17                var m = data.match(/<!-- HB_AJAX_START -->(.*)<!-- HB_AJAX_END -->/);
18                try {
19                    if (m) {
20                        data = $.parseJSON(m[1]);
21                    } else {
22                        data = $.parseJSON(data);
23                    }
24                } catch (e) {
25                    console.log(e);
26                    data = {};
27                }
28            }
29            return data;
30        },
31
32        toggle_extra: function () {
33            $(document).on('change', '.number_room_select', function (e) {
34                e.preventDefault();
35
36                var _self = $(this),
37                    _form = _self.parents('.hb-search-room-results'),
38                    _exta_area = _form.find('.hb_addition_package_extra'),
39                    _toggle = _exta_area.find('.hb_addition_packages'),
40                    _val = _self.val();
41
42                if (_val !== '') {
43                    _form.parent().siblings().find('.hb_addition_packages').removeClass('active').slideUp();
44                    _toggle.removeAttr('style').addClass('active');
45                    _exta_area.removeAttr('style').slideDown();
46                }
47                else {
48                    _exta_area.slideUp();
49                    _val = 1;
50                }
51
52                _form.find('.hb_optional_quantity').val(_val);
53
54            });
55        },
56
57        optional_toggle: function (toggle) {
58            if (toggle.hasClass('active'))
59                toggle.slideDown();
60            else
61                toggle.slideUp();
62        },
63
64        toggleCheckbox: function () {
65            $(document).on('change', '.hb_optional_quantity_selected', function (e) {
66                e.preventDefault();
67                var _self = $(this),
68                    parent = _self.parents('li:first'),
69                    inputQuantity = parent.find('.hb_optional_quantity');
70
71                if (_self.is(':checked')) {
72                    inputQuantity.attr('readonly', true);
73                }
74                else {
75                    if (!inputQuantity.hasClass('tp_hb_readonly'))
76                        inputQuantity.removeAttr('readonly');
77                }
78            });
79        },
80
81        removePackage: function () {
82            $(document).on('click', '.hb_package_remove', function (e) {
83                e.preventDefault();
84                var _self = $(this),
85                    _cart_id = _self.attr('data-cart-id'),
86                    _parents = _self.parents('.hb_mini_cart_item:first'),
87                    _overlay = _self.parents('.hb_mini_cart_item:first, tr');
88
89                if (typeof _parents === 'undefined' || _parents.length === 0) {
90                    _parents = _self.parents('.hb_checkout_item.package:first');
91                }
92
93                $.ajax({
94                    url: hotel_settings.ajax,
95                    method: 'POST',
96                    data: {
97                        action : 'tp_hotel_booking_remove_package',
98                        cart_id: _cart_id,
99                        nonce  : hotel_settings.nonce
100                    },
101                    dataType: 'html',
102                    beforeSend: function () {
103                        // ajax start effect
104                        _overlay.hb_overlay_ajax_start();
105                    }
106                }).done(function (res) {
107                    res = TPHB_Extra_Site.parseJSON(res);
108                    if (typeof res.status !== 'undefined' && res.status === 'success') {
109                        TPHB_Extra_Site.hb_add_to_cart_callback(res, function () {
110                            var cart_table = $('#hotel-booking-payment, #hotel-booking-cart');
111
112                            for (var i = 0; i < cart_table.length; i++) {
113                                var _table = $(cart_table[i]);
114                                var tr = _table.find('table').find('.hb_checkout_item.package');
115                                for (var y = 0; y < tr.length; y++) {
116                                    var _tr = $(tr[y]),
117                                        _cart_id = _tr.attr('data-cart-id'),
118                                        _cart_parent_id = _tr.attr('data-parent-id');
119                                    if (_cart_id === res.package_id && _cart_parent_id === res.cart_id) {
120                                        var _packages = $('tr.hb_checkout_item.package[data-cart-id="' + _cart_id + '"][data-parent-id="' + _cart_parent_id + '"]'),
121                                            _additon_package = $('tr.hb_addition_services_title[data-cart-id="' + _cart_parent_id + '"]'),
122                                            _tr_room = $('.hb_checkout_item:not(.package)[data-cart-id="' + _cart_parent_id + '"]'),
123                                            _packages_length = $('tr.hb_checkout_item.package[data-parent-id="' + _cart_parent_id + '"]').length;
124
125                                        if (_packages_length === 1) {
126                                            _tr.remove();
127                                            _additon_package.remove();
128                                            _tr_room.find('td:first').removeAttr('rowspan');
129                                        }
130                                        else {
131                                            var _rowspan = _tr_room.find('td:first').attr('rowspan');
132                                            _tr.remove();
133                                            _tr_room.find('td:first').attr('rowspan', _rowspan - 1);
134                                        }
135
136                                        break;
137                                    }
138                                }
139
140                                if (typeof res.sub_total !== 'undefined')
141                                    _table.find('span.hb_sub_total_value').html(res.sub_total);
142
143                                if (typeof res.grand_total !== 'undefined')
144                                    _table.find('span.hb_grand_total_value').html(res.grand_total);
145
146                                if (typeof res.advance_payment !== 'undefined')
147                                    _table.find('span.hb_advance_payment_value').html(res.advance_payment);
148
149                            }
150                        });
151
152	                    $('body').trigger('hb_remove_extra_to_cart');
153                    }
154                    // ajax stop effect
155                    _overlay.hb_overlay_ajax_stop();
156                });
157            });
158        },
159        hb_add_to_cart_callback: function ( data, callback ) {
160            const mini_cart = $( '.hotel_booking_mini_cart' );
161            const length = mini_cart.length;
162            let template = wp.template( 'hb-minicart-item' );
163            template = template( data );
164
165            if ( length > 0 ) {
166                for ( let i = 0; i < length; i++ ) {
167                    let cart = $( mini_cart[ i ] ),
168                        cart_item = $( mini_cart[ i ] ).find( '.hb_mini_cart_item' ),
169                        insert = false,
170                        empty = cart.find( '.hb_mini_cart_empty' ),
171                        footer_ele = cart.find( '.hb_mini_cart_footer' ),
172                        items_length = cart_item.length;
173
174                    if ( items_length === 0 ) {
175                        const footer = wp.template( 'hb-minicart-footer' );
176                        const ele = footer_ele;
177                        if ( empty.length === 1 ) {
178                            empty.after( footer( {} ) );
179                            empty.before( template );
180                        } else {
181                            footer_ele.before( template );
182                        }
183                        insert = true;
184                        break;
185                    } else {
186                        for ( let y = 0; y < items_length; y++ ) {
187                            const item = $( cart_item[ y ] ),
188                                cart_id = item.attr( 'data-cart-id' );
189
190                            if ( data.cart_id === cart_id ) {
191                                item.replaceWith( template );
192                                insert = true;
193                                break;
194                            }
195                        }
196
197                        if ( insert === false ) {
198                            footer_ele.before( template );
199                        }
200                    }
201                }
202            }
203
204            $( '.hb_mini_cart_empty' ).remove();
205            var timeout = setTimeout( function() {
206                $( '.hb_mini_cart_item' ).removeClass( 'active' );
207                clearTimeout( timeout );
208            }, 3500 );
209
210            if ( typeof callback !== 'undefined' ) {
211                callback();
212            }
213        },
214
215    };
216
217    $(document).ready(function () {
218        TPHB_Extra_Site.init();
219    });
220
221})(jQuery);

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.