PageSourceSearch

https://www.spyglassinn.com/site/templates/fields/content/booking_widget_element.js?2nct1v

js spyglassinn.com collected 2026-10-07 00:55:29 UTC 9,840 bytes, 285 lines download raw bytes

1document.addEventListener('alpine:init', () => {
2    let today = new Date();
3
4    function getStartDate(checkinStartDate) {
5        if (!checkinStartDate) return null;
6        var parts = checkinStartDate.split('-');
7        var d = new Date(parseInt(parts[0]), parseInt(parts[1]) - 1, parseInt(parts[2]));
8        return d > today ? d : null;
9    }
10
11    function getDefaultDates(checkinStartDate, stayNights) {
12        var nights = stayNights || 5;
13        var start = getStartDate(checkinStartDate);
14        if (start) {
15            var defaultStart = new Date(start);
16            defaultStart.setDate(start.getDate() + 1);
17            var defaultEnd = new Date(start);
18            defaultEnd.setDate(start.getDate() + 1 + nights);
19            return [defaultStart, defaultEnd];
20        }
21        var tomorrow = new Date(today);
22        tomorrow.setDate(today.getDate() + 1);
23        var endDate = new Date(today);
24        endDate.setDate(today.getDate() + 1 + nights);
25        return [tomorrow, endDate];
26    }
27
28    Alpine.data('tabItem', () => ({
29        _drop: null,
30        closeDrop() {
31            this._drop.hide(false)
32        },
33        init() {
34
35            this._drop = UIkit.dropdown(this.$refs['drop'])
36            let items = this.$el.querySelectorAll('.uk-nav > li > a');
37            items.forEach((item) => {
38                UIkit.util.on(item, 'click', () => {
39                    this.closeDrop();
40                })
41            });
42
43        }
44    }));
45    Alpine.data('bookingWidget', () => ({
46        value: [],
47        adults: 2,
48        child: 0,
49        build_url: false,
50        booking_data: null,
51        booking_groups: [],
52        flatpickr_instance: null,
53        selected_booking: null,
54        form_instance: null,
55        checkin_mobile_formatted: "",
56
57        checkout_mobile_formatted: "",
58        flatpickr_format: 'D, j M',
59        flatpickr_mobile_instance: null,
60        get children_enabled() {
61            return this.current.children_parameter_disable !== true;
62        },
63        get guests_text() {
64            let text = this.adults + ' ' + (this.adults === 1 ? 'Adult' : 'Adults');
65            if (this.children_enabled && this.child > 0) {
66                text += ', ' + this.child + ' ' + (this.child === 1 ? 'Child' : 'Children');
67            }
68            return text;
69        },
70        get extra_fields() {
71
72            return this.current.extra_fields
73        },
74
75        get checkin_parameter_name() {
76            return this.current.checkin_parameter_name
77        },
78        get checkout_parameter_name() {
79            return this.current.checkout_parameter_name
80        },
81
82        get children_parameter_name() {
83            return this.current.children_parameter_name
84        },
85
86        get adults_parameter_name() {
87            return this.current.adults_parameter_name
88        },
89
90        get checkout_format() {
91            return this.current.checkout_format
92        },
93
94        get checkin_format() {
95            return this.current.checkin_format
96        },
97        getParents(el, parentSelector) {
98            if (parentSelector === undefined) {
99                parentSelector = document;
100            }
101            var parents = [];
102            var p = el.parentNode;
103            while (p !== parentSelector) {
104                var o = p;
105                parents.push(o);
106                p = o.parentNode;
107            }
108            parents.push(parentSelector);
109            return parents;
110        },
111        getByGroup(group){
112            if(!group){
113                let found = this.booking_data.filter(function (item) {
114                    return !item.group;
115                });
116                return found;
117            }else {
118                let found = this.booking_data.filter(function (item) {
119                    return item.group == group;
120                });
121                return found;
122
123            }
124        },
125
126        init() {
127            this.form_instance = this.$refs.form_action;
128            this.booking_data = JSON.parse(this.$refs['form_action'].dataset.booking);
129            //console.log(this.booking_data);
130            let has_group =  this.booking_data.some(function(item){
131                return item.group != "";
132            });
133            if(has_group){
134                this.booking_groups = this.booking_data.reduce(function(acc, item){
135                    if(item.group){
136                        if(!acc.includes(item.group)) {
137                            acc.push(item.group);
138                        }
139                    }
140                    return acc;
141                }, []);
142            }
143
144            var initialStartDate = this.current.checkin_start_date || '';
145            var initialStayNights = this.current.default_stay_nights || 5;
146            var initialMinDate = getStartDate(initialStartDate) || "today";
147            var initialDefaults = getDefaultDates(initialStartDate, initialStayNights);
148            this.value = initialDefaults;
149
150            this.flatpickr_instance = flatpickr(this.$refs.picker, {
151                dateFormat: this.flatpickr_format,
152                defaultDate: this.value,
153                showMonths: 2,
154                minDate: initialMinDate,
155                dateFormat: this.flatpickr_format,
156                mode: "range",
157                onReady: (date, dateString, instance) => {
158                    instance.element.value = dateString.replace(' to ', ' - ');
159                    instance.element.size = instance.element.value.length + 2;
160                },
161                onChange: (date, dateString, instance) => {
162                    instance.element.value = dateString.replace(' to ', ' - ');
163                    instance.element.size = instance.element.value.length + 2;
164                    this.value[0] = date[0];
165                    if (date[1] !== undefined) {
166                        this.value[1] = date[1]
167                    }
168                }
169            })
170
171            this.flatpickr_mobile_instance = flatpickr(this.$refs.picker_mobile, {
172                disableMobile: true,
173                dateFormat: this.flatpickr_format,
174                defaultDate: this.value,
175                showMonths: 1,
176                inline: true,
177                position: "center",
178                minDate: initialMinDate,
179                mode: "range",
180                onChange: (date, dateStr, instance) => {
181                    this.value[0] = date[0];
182                    if (date[1] !== undefined) {
183                        this.value[1] = date[1]
184                    }
185                },
186
187            })
188
189            this.$watch('selected_booking', (val) => {
190                var booking = val ? this.booking_data[val] : this.booking_data[0];
191                if (!booking) return;
192                var startDateStr = booking.checkin_start_date || '';
193                var stayNights = booking.default_stay_nights || 5;
194                var newMinDate = getStartDate(startDateStr) || "today";
195                var newDefaults = getDefaultDates(startDateStr, stayNights);
196
197                this.flatpickr_instance.set('minDate', newMinDate);
198                this.flatpickr_mobile_instance.set('minDate', newMinDate);
199
200                this.value = newDefaults;
201                this.flatpickr_instance.setDate(newDefaults);
202                this.flatpickr_mobile_instance.setDate(newDefaults);
203            });
204        },
205
206        submitBooking(){
207            this.form_instance.submit();
208        },
209        scroll() {
210            UIkit.util.scrollIntoView(this.$el, {
211                offset: 30
212            })
213        },
214
215        get checkin_booking_formatted() {
216            return this.getBookingDateFormat(0, 'checkin_format')
217        },
218        get checkout_booking_formatted() {
219            return this.getBookingDateFormat(1, 'checkout_format')
220        },
221        get checkin_mobile_formatted() {
222            return this.getPublicDate(0)
223        },
224        get checkout_mobile_formatted() {
225            return this.getPublicDate(1)
226
227        },
228        get action() {
229            return this.current.action;
230        },
231        get current() {
232            if (this.booking_data !== undefined) {
233                if (this.selected_booking) {
234                    return this.booking_data[this.selected_booking];
235                } else {
236                    return this.booking_data[0];
237                }
238            }
239        },
240        getPublicDate(index) {
241            if (this.flatpickr_instance && this.value[index] !== undefined) {
242                return this.flatpickr_instance.formatDate(
243                    this.flatpickr_instance.parseDate(this.value[index]),
244                    this.flatpickr_format);
245            }
246        },
247        getBookingDateFormat(index, format) {
248            if (this.flatpickr_instance
249                && this.current !== undefined
250                && this.value[index] !== undefined) {
251
252                return this.flatpickr_instance.formatDate(
253                    this.flatpickr_instance.parseDate(this.value[index]),
254                    this.current[format]);
255            }
256        },
257        adultCountAction: function (action) {
258            switch (action) {
259                case 'up':
260                    this.adults++
261                    break;
262                case 'down':
263                    if (this.adults == 1) {
264                        return;
265                    }
266                    this.adults--;
267                    break;
268            }
269        },
270
271        childCountAction: function (action) {
272            switch (action) {
273                case 'up':
274                    this.child++
275                    break;
276                case 'down':
277                    if (this.child == 0) {
278                        return;
279                    }
280                    this.child--;
281                    break;
282            }
283        },
284    }))
285})

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.