PageSourceSearch

https://autosmallorca.com/wp-content/plugins/renthub/js/search_form_shortcode.js?ver=v098

js autosmallorca.com collected 2026-10-09 22:25:24 UTC 32,131 bytes, 691 lines download raw bytes

1var searchFormAfterInit = [];
2(function ($) {
3
4    $(document).ready(function () {
5        var dateFormat = renthub_opening.locale.js_date_format.replace("yyyy", 'Y').replace("yy", 'y').replace("dd", "d").replace("mm", "m");
6        if ($("#rsf_type").length > 0) {
7            $(".renthub_search_category").click(function () {
8                var selected_category = $(this).data("category-id");
9                $("#rsf_type").val(selected_category);
10                $(".renthub_search_category").removeClass("active");
11                $(this).addClass("active");
12            });
13        }
14        if ($("#rsf_macro_type").length > 0) {
15            $(".renthub_search_macro_type").click(function () {
16                var selected_macro_type = $(this).data("macrotype-id");
17                $("#rsf_macro_type").val(selected_macro_type);
18                $(".renthub_search_macro_type").removeClass("active");
19                $(this).addClass("active");
20            });
21        }
22
23        $(window).on("load resize", function() {
24            if(($('.nrhsf-pickup-container').hasClass('rh_details_show_right') && $(window).width() > 991) || $(".rh_layout_version_light").length > 0) {
25                $("body").removeClass("renthub-search-form-small");
26                $("body").addClass("renthub-search-form-big");
27            }
28            else {
29                $("body").removeClass("renthub-search-form-big");
30                $("body").addClass("renthub-search-form-small");
31            }
32        });
33
34        if ($("#rsf_pickup").length > 0) {
35            
36            /** Pickup Variables */
37            var pickupContainer = ".nrhsf-pickup-container";
38            var pickupLocationResults = "#rh_location_results";
39            var pickupInput = "#rsf_pickup_input";
40
41            /** Drop off Variables */
42            var dropoffContainer = ".nrhsf-dropoff-container";
43            var dropoffLocationResults = "#dropoff_rh_location_results";
44            var dropoffInput = "#rsf_dropoff_input";
45
46            /** Location Details Variables */
47            var mobileDetail = ".rh_location-data";
48            var desktopDetail = ".rh_location_info";
49
50            function searchFormMobileLayout(element) {
51                if($(element).find(mobileDetail).hasClass('show')) {
52                    $(element).find(mobileDetail).removeClass('show');
53                    $(element).find(".rh_info_open").text('+');
54                }
55                else {
56                    $(mobileDetail).removeClass('show');
57                    $(".rh_info_open").text('+');
58
59                    $(element).find(mobileDetail).addClass('show');
60                    $(element).find(".rh_info_open").text('-');
61                }
62            }
63
64            $("#rsf_pickup").change(function () {
65                var pickup = $("#rsf_pickup").val();
66                if (pickup != '' && $("#rsf_dropoff option[value='" + pickup + "']").length > 0) {
67                    $("#rsf_dropoff").val(pickup);
68                }
69            });
70            $("#rsf_dropoff_date").click(function() {
71                if(($("#rsf_dropoff").length > 0 && !$("#rsf_dropoff").val())) {
72                    RenthubLoader.showError(renthub_js_trans.select_location_before_date);
73                }
74            });
75            $("#rsf_pickup_date").click(function() {
76                if(!$("#rsf_pickup").val()) {
77                    RenthubLoader.showError(renthub_js_trans.select_location_before_date);
78                }
79            });
80
81            $("#rsf_pickup_time").change(function () {
82                var pickup = $("#rsf_pickup_time").val();
83                if (pickup != '' && $("#rsf_dropoff_time option[value='" + pickup + "']").length > 0) {
84                    $("#rsf_dropoff_time").val(pickup);
85                }
86            });
87
88            var daysOfWeekDisabled = [];
89
90            for (var i = 1; i <= 7; i++) {
91                if (renthub_opening.opening.opening_time[i] == '') {
92                    daysOfWeekDisabled.push(i == 7 ? 0 : i);
93                }
94            }
95            var minDateToSetInPicker = new Date();
96            minDateToSetInPicker.setHours(0, 0, 0, 0);
97            $("#rsf_pickup_date").flatpickr({
98                'dateFormat': dateFormat,
99                'locale': renthub_opening.wp_locale,
100                'minDate': minDateToSetInPicker,
101                'disable': [function (date) {
102                    var timetable = getPickupTimetable();
103                    return !isOpenAtDate(timetable, date);
104                }],
105                "onChange": function (selectedDates, dateStr, instance) {
106                    if (selectedDates.length > 0) {
107                        var newDate = new Date(selectedDates[0]);
108                        newDate.setDate(newDate.getDate() + parseInt(renthub_opening.opening.min_days));
109                        var attempts = 0;
110                        var dropoff = document.querySelector("#rsf_dropoff_date")._flatpickr;
111                        if (dropoff.selectedDates.length == 0 || newDate > dropoff.selectedDates[0]) {
112                            var timetable = getDropoffTimetable();
113                            var opened = isOpenAtDate(timetable, newD
113ate)
114                            while (!opened && attempts <= 30) {
115                                attempts++;
116                                newDate.setDate(newDate.getDate() + 1);
117                                opened = isOpenAtDate(timetable, newDate)
118                            }
119                            dropoff.setDate(newDate);
120                        }
121                    }
122                    renthubCheckAndSetTime();
123                }
124            });
125
126            $("#rsf_dropoff_date").flatpickr({
127                'dateFormat': dateFormat,
128                'locale': renthub_opening.wp_locale,
129                'minDate': minDateToSetInPicker,
130                'disable': [function (date) {
131                    var timetable = getDropoffTimetable();
132                    return !isOpenAtDate(timetable, date);
133                }],
134                "onChange": function (selectedDates, dateStr, instance) {
135                    renthubCheckAndSetTime();
136                }
137            });
138
139            renthubCheckAndSetTime(function () {
140                if (renthub_opening.pickup_time != '') {
141                    $("#rsf_pickup_time").val(renthub_opening.pickup_time);
142                }
143                if (renthub_opening.dropoff_time != '') {
144                    $("#rsf_dropoff_time").val(renthub_opening.dropoff_time);
145                }
146                for(let i = 0; i < searchFormAfterInit.length; i++) {
147                    if(typeof searchFormAfterInit[i] == 'function') {
148                        searchFormAfterInit[i]();
149                    }
150                }
151            });
152
153            function isOpenAtDate(timetable, date, time) {
154                if (!timetable) {
155                    return false;
156                }
157                var formattedDate = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + ("0" + (date.getDate())).slice(-2);
158                var formattedMonthDay = ("0" + (date.getMonth() + 1)).slice(-2) + "-" + ("0" + (date.getDate())).slice(-2);
159                var weekDay = date.getDay() != 0 ? date.getDay() : 7;
160                for (var cdpyIndex = 0; cdpyIndex < timetable.closingDaysPerYear.length; cdpyIndex++) {
161                    var cdpy = timetable.closingDaysPerYear[cdpyIndex];
162                    if (formattedDate >= cdpy.from && formattedDate <= cdpy.to) {
163                        return false;
164                    }
165                }
166                for (var closingDayIndex = 0; closingDayIndex < timetable.closingDays.length; closingDayIndex++) {
167                    var closingDay = timetable.closingDays[closingDayIndex];
168                    if (closingDay == formattedMonthDay) {
169                        return false;
170                    }
171                }
172                for (var exceptionIndex = 0; exceptionIndex < timetable.weeklyScheduleException.length; exceptionIndex++) {
173                    var exception = timetable.weeklyScheduleException[exceptionIndex];
174                    if (formattedDate >= exception.range.from && formattedDate <= exception.range.to) {
175                        if (typeof exception.scheduled[weekDay] != 'undefined' && exception.scheduled[weekDay].length > 0) {
176                            if (!time) {
177                                return true;
178                            } else {
179                                for (var timeRangeExceptionIndex = 0; timeRangeExceptionIndex < exception.scheduled[weekDay].length; timeRangeExceptionIndex++) {
180                                    var timeRangeException = exception.scheduled[weekDay][timeRangeExceptionIndex];
181                                    if (time >= timeRangeException.from && time <= timeRangeException.to) {
182                                        return true;
183                                    }
184                                }
185                            }
186                        }
187                        return false;
188                    }
189                }
190                if (typeof timetable.weeklySchedule[weekDay] != 'undefined' && timetable.weeklySchedule[weekDay].length > 0) {
191                    if (!time) {
192                        return true;
193                    } else {
194                        for (var timeRangeIndex = 0; timeRangeIndex < timetable.weeklySchedule[weekDay].length; timeRangeIndex++) {
195                            var timeRange = timetable.weeklySchedule[weekDay][timeRangeIndex];
196                            if (time >= timeRange.from && time <= timeRange.to) {
197                                return true;
198                            }
199                        }
200                    }
201                }
202                return false;
203            }
204
205            function getPickupTimetable() {
206                var timetableId = $("#rsf_pickup option:selected").length > 0 ? $("#rsf_pickup option:selected").data("timetable") : false;
207                if (!timetableId) {
208                    return false;
209                }
210                var timetable = renthub_opening.complete_timetable[timetableId];
211                return timetable;
212            }
213
214            function getDropoffTimetable() {
215                var timetableId;
216                if ($("#rsf_dropoff").is("select")) {
217                    timetableId = $("#rsf_dropoff option:selected").length > 0 ? $("#rsf_dropoff option:selected").data("timetable") : false;
218                } else if ($("#rsf_dropoff").is('input[type="hidden"]') || $("#rsf_dropoff").length == 0) {
219                    /*è il caso in cui pickup e dropoff corrispondono sempre*/
220                    timetableId = $("#rsf_pickup option:selected").length > 0 ? $("#rsf_pickup option:selected").data("dropoff-timetable") : false;
221                    if (!timetableId) {
222                        return false;
223                    }
224                }
225
226                if (!timetableId) {
227                    return false;
228                }
229                var timetable = renthub_opening.complete_timetable[timetableId];
230                return timetable;
231            }
232
233            /* Pickup */
234            $("#rsf_pickup").change(function () {
235                document.querySelector("#rsf_pickup_date")._flatpickr.redraw();
236                //redraw pure dropoff_date perché cambiando località pickup si cambia località dropoff
237                document.querySelector("#rsf_dropoff_date")._flatpickr.redraw();
238            });
239
240            $(document).on("keyup",pickupContainer+" "+pickupInput,function () {
241                $(pickupContainer+" "+pickupLocationResults).addClass("show");
242                locationFilterFunction("rsf_pickup_input","rh_location_results");
243            });
244
245            if($(".rh_layout_version_light").length == 0) {
246                $(document).on("click",pickupContainer+" "+pickupLocationResults+" li .rh_loc-select ",function () {
247                    
248                    var curloc = $(this).parent('div').parent('div').parent('li');
249
250                    var curLocID = curloc.data('id');
251                    var curLocText = curloc.find(".rh_loc_label").text();
252                    $(pickupContainer+" "+pickupInput).val(curLocText);
253                    $(dropoffContainer+" "+dropoffInput).val(curLocText);
254
255                    $(pickupContainer+" "+pickupLocationResults).removeClass("show");
256                    document.getElementById("rsf_pickup").value = curLocID;
257                    $(pickupContainer+" #rsf_pickup").trigger('change');
258
259                    document.getElementById("rsf_dropoff").value = curLocID;
260                    $(dropoffContainer+" #rsf_dropoff").trigger('change');
261
262                    $(pickupContainer+" "+desktopDetail).html("");
263
264                    $(pickupContainer+" "+mobileDetail).removeClass("show");
265                });
266            }
267
268            $(document).on("click",pickupContainer+" "+pickupLocationResults+" li",function () {
269                if($("body").hasClass("renthub-search-form-big")) {
270                    var curLocID = $(this).data('id');
271                    var curLocText = $(this).find(".rh_loc_label").text();
272
273                    $(pickupContainer+" "+pickupInput).val(curLocText);
274                    $(dropoffContainer+" "+dropoffInput).val(curLocText);
275
276                    $(pickupContainer+" "+pickupLocationResults).removeClass("show");
277                    document.getElementById("rsf_pickup").value = curLocID;
278                    $(pickupContainer+" #rsf_pickup").trigger('change');
279
280                    document.getElementById("rsf_dropoff").value = curLocID;
281                    $(dropoffContainer+" #rsf_dropoff").trigger('change');
282
283                    $(pickupContainer+" "+desktopDetail).html("");
284                    
285                }
286                else {
287                    searchFormMobileLayout(this);
288                }
289            });
290
291            $(document).on("mouseenter",pickupContainer+" "+pickupLocationResults+" li",function () {
292                if($("body").hasClass("renthub-search-form-big")) {
293                    var curLocData = $(this).find(mobileDetail).html();
294                    $(pickupContainer+" "+desktopDetail).html(curLocData);
295                    $(pickupContainer+" "+desktopDetail).addClass('show');
296                }
297            });
298
299            /* End Pickup */
300
301            $(document).on('click', function(event) {
302                if(!$(event.target).closest(pickupLocationResults).length) {
303                    $(pickupLocationResults).removeClass("show");
304                    $(desktopDetail).removeClass("show");
305                }
306
307                if(!$(event.target).closest(dropoffLocationResults).length) {
308                    $(dropoffLocationResults).removeClass("show");
309                    $(desktopDetail).removeClass("show");
310                }
311            });
312
313            $(document).on("click",pickupInput,function () {
314                setTimeout(function(){
315                    hideList();
316                    $(pickupLocationResults).addClass("show");
317                },100);
318            });
319
320            $(document).on("click",dropoffInput,function () {
321                setTimeout(function(){
322                    hideList();
323                    $(dropoffLocationResults).addClass("show");
324                },100);
325            });
326
327            if($(".nrhsf-container").length > 0) {
328                $('body').addClass("rh-booking-search");
329                $(".nrhsf-container").closest(".vc_row[data-vc-full-width]").addClass("rh-booking-shortcode");
330            }
331
332            /* Drop-off */
333            $("#rsf_dropoff").change(function () {
334                document.querySelector("#rsf_dropoff_date")._flatpickr.redraw();
335            });
336
337            $(document).on("keyup",dropoffContainer+" "+dropoffInput,function () {
338                $(dropoffContainer+" "+dropoffLocationResults).addClass("show");
339                locationFilterFunction("rsf_dropoff_input","dropoff_rh_location_results");
340            });
341
342            if($(".rh_layout_version_light").length == 0) {
343                $(document).on("click",dropoffContainer+" "+dropoffLocationResults+" li .rh_loc-select ",function () {
344                    var curloc = $(this).parent('div').parent('div').parent('li');
345
346                    var curLocID = curloc.data('id');
347                    var curLocText = curloc.find(".rh_loc_label").text();
348                    $(dropoffContainer+" "+dropoffInput).val(curLocText);
349
350                    $(dropoffContainer+" "+dropoffLocationResults).removeClass("show");
351                    document.getElementById("rsf_dropoff").value = curLocID;
352                    $(dropoffContainer+" #rsf_dropoff").trigger('change');
353
354                    $(dropoffContainer+" "+desktopDetail).html("");
355
356                    $(dropoffContainer+" "+mobileDetail).removeClass("show");
357                });
358            }
359
360            $(document).on("click",dropoffContainer+" "+dropoffLocationResults+" li",function () {
361                if($("body").hasClass("renthub-search-form-big")) {
362                    var curLocID = $(this).data('id');
363                    var curLocText = $(this).find(".rh_loc_label").text();
364                    $(dropoffContainer+" "+dropoffInput).val(curLocText);
365
366                    $(dropoffContainer+" "+dropoffLocationResults).removeClass("show");
367                    document.getElementById("rsf_dropoff").value = curLocID;
368                    $(dropoffContainer+" #rsf_dropoff").trigger('change');
369
370                    $(dropoffContainer+" "+desktopDetail).html("");
371                }
372                else {
373                    searchFormMobileLayout(this);
374                }
375            });
376
377            $(document).on("mouseenter",dropoffContainer+" "+dropoffLocationResults+" li",function () {
378                if($("body").hasClass("renthub-search-form-big")) {
379                    var curLocData = $(this).find(mobileDetail).html();
380                    $(dropoffContainer+" "+desktopDetail).html(curLocData);
381                    $(dropoffContainer+" "+desktopDetail).addClass('show');
382                }
383            });
384
385            /* End Drop-off */
386
387            function renthubCheckAndSetTime(callback) {
388                var pickupTimetable = getPickupTimetable();
389                var dropoffTimetable = getDropoffTimetable();
390                if (pickupTimetable) {
391                    var pickup = document.querySelector("#rsf_pickup_date")._flatpickr;
392                    if (pickup.selectedDates.length > 0) {
393                        var pickupDate = new Date(pickup.selectedDates[0]);
394                        setTimeOptionsInSelect(pickupTimetable, $("#rsf_pickup_time"), pickupDate, 'from');
395                    }
396                }
397                if (dropoffTimetable) {
398                    var dropoff = document.querySelector("#rsf_dropoff_date")._flatpickr;
399                    if (dropoff.selectedDates.length > 0) {
400                        var dropoffDate = new Date(dropoff.selectedDates[0]);
401                        setTimeOptionsInSelect(dropoffTimetable, $("#rsf_dropoff_time"), dropoffDate, 'to');
402                    }
403                }
404                if(typeof callback == 'function') {
405                    callback();
406                }
407            }
408
409            $(".renthub-search-form select").change(function () {
410                setTimeout(renthubCheckAndSetTime, 20);
411            });
412
413            function setTimeOptionsInSelect(timetable, timeSelector, selectedDate, is) {
414                var oldTime = timeSelector.val();
415                timeSelector.find("option").remove();
416                if (isOpenAtDate(timetable, selectedDate)) {
417                    var tmpDate = new Date();
418                    tmpDate.setHours(0, 0, 0, 0);
419                    do {
420                        var timeStr = getTimeStrFormatted(tmpDate);
421                        if (isOpenAtDate(timetable, selectedDate, timeStr)) {
422                            timeSelector.append('<option value="' + timeStr + '">' + timeStr + '</option>')
423                        }
424                        tmpDate.setMinutes(tmpDate.getMinutes() + 30);
425                    } while (tmpDate.getHours() != 0 || tmpDate.getMinutes() != 0);
426                    if (oldTime && timeSelector.find('option[value="' + oldTime + '"]').length > 0) {
427                        timeSelector.val(oldTime);
428                    } else {
429                        if(is == 'from' && renthub_opening.suggested_start_time && timeSelector.find('option[value="' + renthub_opening.suggested_start_time + '"]').length > 0) {
430                            timeSelector.val(renthub_opening.suggested_start_time)
431                        }
432                        if(is == 'to') {
433                            if($("#rsf_pickup_time").val() == $("#rsf_dropoff_time").val()) {
434                                if(renthub_opening.suggested_end_time_same_day && timeSelector.find('option[value="' + renthub_opening.suggested_end_time_same_day + '"]').length > 0) {
435                                    timeSelector.val(renthub_opening.suggested_end_time_same_day);
436                                }
437                            } else {
438                                if(renthub_opening.suggested_end_time && timeSelector.find('option[value="' + renthub_opening.suggested_end_time + '"]').length > 0) {
439                                    timeSelector.val(renthub_opening.suggested_end_time);
440                                }
441                            }
442                        }
443                    }
444                }
445            }
446
447            function getTimeStr(date) {
448                var hours = date.getHours();
449                var minutes = date.getMinutes();
450                if (minutes < 10) {
451                    minutes = '0' + minutes.toString();
452                } else {
453                    minutes = minutes.toString();
454                }
455                if (hours < 10) {
456                    hours = '0' + hours.toString();
457                } else {
458                    hours = hours.toString();
459                }
460                return hours + ':' + minutes;
461            }
462            function getTimeStrFormatted(date) {
463                var hours = date.getHours();
464                var minutes = date.getMinutes();
465                let AM_PM = '';
466                if (minutes < 10) {
467                    minutes = '0' + minutes.toString();
468                } else {
469                    minutes = minutes.toString();
470                }
471
472                if(renthub_utils.twelve_hours) {
473                    if(hours <12) {
474                        AM_PM = 'AM';
475                    } else {
476                        AM_PM = 'PM';
477                        hours=hours-12;
478                    }
479                    if(hours===0) {
480                        hours = 12;
481                    }
482                }
483
484                if (hours < 10) {
485                    hours = '0' + hours.toString();
486                } else {
487                    hours = hours.toString();
488                }
489                return hours + ':' + minutes+AM_PM;
490            }
491            function locationFilterFunction(inputField,locationData) {
492                var input, filter, ul, li, a, i;
493                input = document.getElementById(inputField);
494                filter = input.value;
495                let txtValue;
496                let div = document.getElementById(locationData);
497                a = div.getElementsByTagName("li");
498                for (i = 0; i < a.length; i++) {
499                  txtValue = a[i].textContent || a[i].innerText;
500                  if (txtValue
501                      .normalize("NFD")
502                      .replace(/[\u0300-\u036f]/g, "")
503                      .toUpperCase()
504                      .indexOf(
505                          filter
506                              .normalize("NFD")
507                              .replace(/[\u0300-\u036f]/g, "")
508                              .toUpperCase()
509                      ) > -1) {
510                    a[i].style.display = "";
511                  } else {
512                    a[i].style.display = "none";
513                  }
514                }
515            }
516
517            function hideList() {
518                $(mobileDetail).removeClass('show');
519                $(".rh_info_open").text('+');
520            }
521        }
522
523        /** Auto select pickup/dropoff location if only one item in the dropdown */
524        if ($(pickupLocationResults+" li").length == 1) {
525            $(pickupContainer+" "+pickupLocationResults+" li span").trigger('click');
526        }
527
528        if ($(dropoffLocationResults+" li").length == 1) {
529            $(dropoffContainer+" "+dropoffLocationResults+" li span").trigger('click');
530        }
531        /** End Auto select from location dropdown */
532
533        if($("#rsf_brand").length > 0) {
534            let allModelOpts = $("#rsf_model").html();
535            $("#rsf_brand").change(function() {
536                let oldSelectedModel = $('#rsf_model').val();
537                $("#rsf_model").html(allModelOpts);
538                if($(this).val() != '') {
539                    $('#rsf_model option[data-brand="'+$(this).val()+'"]').addClass("preserve");
540                    $('#rsf_model option[value=""]').addClass("preserve");
541                    $("#rsf_model option:not(.preserve)").remove();
542
543                    if(oldSelectedModel != '' && $('#rsf_model option[value="'+oldSelectedModel+'"]').length <= 0) {
544                        $('#rsf_model').val("");
545                    }
546                }
547            });
548            if($("#rsf_brand").val()!=''){
549                $("#rsf_brand").trigger("change");
550            }
551        }
552
553        /** Coupon Code */
554        $(document).on("click","#rsf_add_coupon",function(){
555            let _self = this;
556            setTimeout(function() {
557                if ($(_self).is(':checked')) {
558                    $(_self).closest(".renthub-coupon-checkbox").find(".rsf_show_coupon").show();
559                    $(_self).closest(".rsf_coupon_checkbox_container").hide();
560                    $("#rbf_coupon").focus();
561                } else {
562                    $(_self).closest(".renthub-coupon-checkbox").find(".rsf_show_coupon").hide();
563                    $(_self).closest(".renthub-coupon-checkbox").find(".rsf_show_coupon").find("input").val("");
564                    $("#renthub_coupon_applied").hide();
565                }
566            }, 5);
567        });
568        
569      /*  $("#rbf_coupon").change(function () {
570
571            var params = [];
572            params.push("start_date=" + $("#rsf_pickup_date").val());
573            params.push("couponcode=" + encodeURIComponent($("#rbf_coupon").val()));
574
575            RenthubLoader.show();
576            
577            $.ajax({
578                type: 'GET',
579                url: renthub_utils.ajaxurl,
580                data: params.join("&") + '&action=renthub_coupon',
581                success: function (result) {
582                    console.log(result);
583                    $('.renthub_coupon_applied').hide();
584                    $('.renthub_coupon_not_valid').hide();
585                    if(result.result.valid) {
586                        $('.renthub_coupon_applied').show();
587                        if($(".renthub-search-form").valid()) {
588                            $(".renthub-search-form").submit();
589                        }
590                    }
591                    else {
592                        $("#rbf_coupon").val("");
593                        $('.renthub_coupon_not_valid').show();
594                    }
595                    
596                    RenthubLoader.hide();
597                },
598                error: function (response) {
599                    RenthubLoader.hide();
600                    RenthubLoader.showError($(".renthub_coupon_not_valid").text());
601                }
602            });
603        });*/
604
605        /** Show Drop off */
606        $(document).on("click",".show_dropoff input",function(){
607            if ($(this).is(':checked')) {
608                $(".nrhsf-dropoff-container").hide();
609                var pickup = $("#rsf_pickup").val();
610                if (pickup != '' && $("#rsf_dropoff option[value='" + pickup + "']").length > 0) {
611                    $("#rsf_dropoff").val(pickup);
612                    curLocText = $("#rsf_dropoff option[value='" + pickup + "']").text();
613                    $(dropoffContainer+" "+dropoffInput).val(curLocText);
614                }
615                $(".nrhsf-pickup-datetime-container").addClass("hide-dropoff");
616            } else {
617                $(".nrhsf-dropoff-container").show();
618                $(".nrhsf-dropoff-container").addClass("hide-dropoff");
619                $(".nrhsf-pickup-datetime-container").removeClass("hide-dropoff");
620            }
621        });
622
623        /** Keyboard navigation implementation start */
624        
625        const pickupResultSelector = document.querySelector('#rh_location_results');
626        const dropoffResultSelector = document.querySelector('#dropoff_rh_location_results');
627        const pickupLocations = document.querySelectorAll('.rh_pickup_locations li');
628        const dropoffLocations = document.querySelectorAll('.rh_dropoff_locations li');
629        let selectedIndex = -1;
630
631        /* Function to handle key events for both pickup and dropoff locations */
632        function handleKeyEvents(resultSelector, locations, e) {
633            if (resultSelector && resultSelector.children.length > 0) {
634                if (resultSelector.classList.contains('show')) {
635                    if (e.key === 'ArrowDown') {
636                        e.preventDefault();
637                        if (selectedIndex < locations.length - 1) {
638                            if (selectedIndex >= 0) {
639                                locations[selectedIndex].classList.remove('renthub-highlight');
640                            }
641                            selectedIndex++;
642                            locations[selectedIndex].classList.add('renthub-highlight');
643                            locations[selectedIndex].scrollIntoView({ block: 'nearest' });
644                        }
645                    } else if (e.key === 'ArrowUp') {
646                        e.preventDefault();
647                        if (selectedIndex > 0) {
648                            locations[selectedIndex].classList.remove('renthub-highlight');
649                            selectedIndex--;
650                            locations[selectedIndex].classList.add('renthub-highlight');
651                            locations[selectedIndex].scrollIntoView({ block: 'nearest' });
652                        }
653                    } else if (e.key === 'Enter') {
654                        e.preventDefault();
655                        if (selectedIndex >= 0) {
656                            const selectedItem = locations[selectedIndex];
657                            triggerSelect(selectedItem);
658                        }
659                    } else if (e.key === 'Escape') {
660                        e.preventDefault();
661                        resultSelector.classList.remove('show');
662                        document.activeElement.blur();
663                        locations.forEach(item => item.classList.remove('renthub-highlight'));
664                        selectedIndex = -1;
665                    }
666                }
667            }
668        }
669
670        /* Add event listener for keydown on the document */
671        document.addEventListener('keydown', function (e) {
672            handleKeyEvents(pickupResultSelector, pickupLocations, e);
673            handleKeyEvents(dropoffResultSelector, dropoffLocations, e);
674        });
675
676        /* Function to trigger select functionality */
677        function triggerSelect(selectedItem) {
678            const id = selectedItem.getAttribute('data-id');
679            const name = selectedItem.querySelector('.rh_loc_label').textContent;
680            selectedItem.click();
681            $("input").blur();
682        }
683
684        /** Keyboard navigation implementation end */
685        
686    });
687
688
689
690})(jQuery);
691

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.