PageSourceSearch

https://www.centarahotelsresorts.com/themes/custom/centara_core/src/js/select.js?v=10.6.17

js centarahotelsresorts.com collected 2026-09-24 17:47:26 UTC 6,221 bytes, 139 lines download raw bytes

1/**
2 * @file
3 * Enable Select2 on all select elements.
4 */
5
6(function select($) {
7  var formId = 'views-exposed-form-properties-block-participating-hotels';
8  var excludeSelector = '#' + formId + ' .select2-search__field:not(.excluded)';
9  var addedExcludeSubmit = false;
10  // reset list
11  $('.offer-detail-filter-block [name="country"]').val($('.offer-detail-filter-block [name="country"] option:first-child').attr('value'));
12  $('.offer-detail-filter-block [name="hotel"]').val($('.offer-detail-filter-block [name="hotel"] option:first-child').attr('value'));
13  $('.offer-detail-filter-block [name="city"]').val($('.offer-detail-filter-block [name="city"] option:first-child').attr('value'));
14
15  $('.offer-detail-filter-block [name="hotel"] option:not(:first-child)').detach();
16  $('.offer-detail-filter-block [name="city"] option:not(:first-child)').detach();
17
18
19  Drupal.behaviors.select = {
20    attach: () => {
21      const filterDropdowns = $(".filter-dropdown");
22      filterDropdowns.once().each((_idx, fd) => {
23        const $fd = $(fd);
24        const selects = $fd.find("select");
25        const toggleBtn = $fd.find(".filter-dropdown__toggle");
26        const closeBtn = $fd.find(".filter-dropdown__close");
27
28        function toggleFilter(e) {
29          e.preventDefault();
30          $fd.toggleClass("enabled");
31        }
32
33        toggleBtn.click(toggleFilter);
34        closeBtn.click(toggleFilter);
35
36        selects.once().each((_, elem) => {
37          $(elem).select2({
38            minimumResultsForSearch: -1,
39            width: "100%",
40            dropdownParent: $(elem).parent()
41          });
42        });
43      });
44
45      // $('.select2-search input').prop('readonly', true);
46
47      $('.offer-detail-filter-block').once().each(function(index, item){
48        const $item = $(item);
49        const selects = $item.find("select");
50        selects.once().each(function(index, elem){
51          $(elem).select2({
52            width: "100%",
53            dropdownParent: $(elem).parent(),
54            dropdownCssClass: 'filter-select-dropdown'
55          });
56          $(elem).one('select2:open', function(){
57            $('input.select2-search__field').prop('placeholder', 'Search');
58          })
59        })
60      })
61      var $countryList = drupalSettings.participating_hotels;
62      $('.offer-detail-filter-block [name="country"]').on('change', function(){
63        $('.offer-detail-filter-block [name="hotel"] option:not(:first-child)').detach();
64        $('.offer-detail-filter-block [name="city"] option:not(:first-child)').detach();
65        var $currentCountry = $(this).val();
66        var $city = $countryList[$currentCountry];
67        if ($city) {
68          Object.keys($city).forEach(function(item){
69            var newOption = new Option($city[item].city, item, false, false);
70            $('.offer-detail-filter-block [name="city"]').append(newOption);
71          });
72          $('.offer-detail-filter-block [name="city"]').trigger('change');
73        }
74      })
75      $('.offer-detail-filter-block [name="city"]').on('change', function(){
76        $('.offer-detail-filter-block [name="hotel"] option:not(:first-child)').detach();
77        var $currentCity = $(this).val();
78        var $currentCountry = $('.offer-detail-filter-block [name="country"]').val();
79        var $hotels = $countryList[$currentCountry] ? $countryList[$currentCountry][$currentCity]?.hotels : null;
80        if ($hotels) {
81          $hotels.map(function(item){
82            var $id = Object.keys(item)[0];
83            var newOption = new Option(item[$id], $id, false, false);
84            $('.offer-detail-filter-block [name="hotel"]').append(newOption);
85          });
86          $('.offer-detail-filter-block [name="hotel"]').trigger('change');
87        }
88      })
89
90      $(document).on('change', '.hotel-card__currency select', function() {
91        var $text = $(this).find('option:selected').data('price');
92        $(this).parent().next('.hotel-card__currency__text').html($text);
93        var $currentCurrency = window.Cookies.get("currency_code");
94        window.Cookies.set("currency_code", $(this).val(), { path: '/' });
95        $('header .view--currency').html($(this).val());
96        var $current = $(this);
97        $('.view-properties .hotel-card__currency .form-item select').each(function(index, item){
98          $(item).val($current.val());
99          var $textItem = $(item).find('option:selected').data('price');
100          $(item).parent().next('.hotel-card__currency__text').html($textItem);
101        });
102        jQuery('[name="currency"]').val($current.val()).trigger('change');
103        // change currency booking url
104        $('.view-properties .hotel-card__buttons .book-this-room').each(function(index, item){
105          var $url = $(item).attr('href');
106          var $newUrl = $url.replace('currency%3D'+$currentCurrency, 'currency%3D'+$current.val());
107          $(item).attr('href', $newUrl);
108        })
109      })
110      
111      // check currency page loaded
112      $(window).bind('load', function(){
113        var currency_code = window.Cookies.get("currency_code");
114        $('.hotel-card__currency .form-item select option[value="'+ currency_code +'"]').prop('selected', true);
115        $('.hotel-card__currency .form-item select').each(function(index, item){
116          var $textItem = $(item).find('option:selected').data('price');
117          $(item).parent().next('.hotel-card__currency__text').html($textItem);
118        })
119      })
120      $(document).ajaxComplete(function(){
121        var currency_code = window.Cookies.get("currency_code");
122        $('.hotel-card__currency .form-item select option[value="'+ currency_code +'"]').prop('selected', true);
123        $('.hotel-card__currency .form-item select').each(function(index, item){
124          var $textItem = $(item).find('option:selected').data('price');
125          $(item).parent().next('.hotel-card__currency__text').html($textItem);
126        })
127      })
128
129      if (!addedExcludeSubmit && document.getElementById(formId)) {
130        addedExcludeSubmit = true;
131
132        $(document).on('focus', excludeSelector, function(e) {
133          this.classList.add('excluded');
134          this.setAttribute('data-bef-auto-submit-exclude', true);
135        });
136      }
137    }
138  };
139})(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.