Untitled

 avatar
unknown
plain_text
2 years ago
12 kB
4
Indexable
(function () {
  try {
    var debug = 0;
    var variation_name = '';

    function waitForElement(selector, trigger) {
      var interval = setInterval(function () {
        if (document && document.querySelector(selector) && document.querySelectorAll(selector).length > 0) {
          clearInterval(interval);
          trigger();
        }
      }, 50);
      setTimeout(function () {
        clearInterval(interval);
      }, 10000);
    }

    var cabinData = {
      ultramarine: {
        'explorer triple': 'hair dryer, bathrobe, slippers, shampoo, conditioner, shower gel, complimentary water bottle.',
        'explorer suite': 'hair dryer, bathrobe, slippers, shampoo, conditioner, shower gel, complimentary water bottle.',
        'balcony suite': 'hair dryer, bathrobe, slippers, shampoo, conditioner, shower gel, complimentary water bottle.',
        'deluxe balcony suite': 'hair dryer, bathrobe, slippers, shampoo, conditioner, shower gel, complimentary water bottle.',
        'solo panorama': 'hair dryer, bathrobe, slippers, shampoo, conditioner, shower gel, complimentary water bottle.',
        'deluxe balcony suite': 'hair dryer, bathrobe, slippers, shampoo, conditioner, shower gel, complimentary water bottle.',
        'terrace suite': 'hair dryer, bathrobe, slippers, shampoo, conditioner, shower gel, complimentary water bottle.',
        "owner's suite": 'hair dryer, bathrobe, slippers, shampoo, conditioner, shower gel, complimentary water bottle.',
        'ultra suite': 'hair dryer, bathrobe, slippers, shampoo, conditioner, shower gel, complimentary water bottle.',
        'penthouse suite': 'hair dryer, bathrobe, slippers, shampoo, conditioner, shower gel, complimentary water bottle.',
      },
      'ocean adventurer': {
        'lower deck twin': '2 lower beds, bedside table, desk w/chair, safe, 21" TV, closets, bathroom w/shower, porthole',
        triple: '2 lower beds, 1 Pullman, bedside table, desk w/chair, safe, 21" TV, closets, bathroom w/shower, porthole',
        'main deck twin porthole': '2 lower beds, bedside table, desk w/chair, safe, 21" TV, closets, bathroom w/shower, porthole',
        'main deck twin window': '2 lower beds, bedside table, desk w/chair, safe, 21" TV, closets, bathroom w/shower, window',
        superior: '2 lower beds, bedside table, desk w/chair, safe, 21" TV, closets, bathroom w/shower, window',
        deluxe: '2 lower beds (convertible), bedside table, desk w/chair, safe, 32" TV, closets, bathroom w/shower, window, fridge, USB ports in bedside lamps',
        suite: '1 double bed (convertible), bedside table, desk w/chair, safe, 32" TV, closets, bathroom w/shower, window, USB ports in bedside lamps, separate sitting area with sofabed',
        "owner's suite": '1 double bed (convertible), bedside table, desk w/chair, safe, 32" TV, closets, bathroom w/shower, window, fridge, USB ports in bedside lamps, separate sitting area with sofabed',
      },
      'ocean diamond': {
        triple: 'A refrigerator, TV, and DVD player are included in each cabin',
        'single obstructed view': 'A refrigerator, TV, and DVD player are included in each cabin',
        'single porthole': 'A refrigerator, TV, and DVD player are included in each cabin',
        'twin obstructed view': 'A refrigerator, TV, and DVD player are included in each cabin',
        'twin window': 'A refrigerator, TV, and DVD player are included in each cabin',
        suite: 'A refrigerator, TV, and DVD player are included in each cabin',
        'balcony suite': 'A refrigerator, TV, and DVD player are included in each cabin',
      },
      'world explorer': {
        triple: 'A separate combo sitting area/bedroom with a sofa bed and additional closet is around the corner, and a refrigerator, TV, state of the art “infotainment” system, and private bathroom with shower is also featured in each cabin.',
        'infinity suite': 'A sitting area with sofa, refrigerator, TV, state of the art “infotainment” system, and private bathroom with shower is also featured in each cabin.',
        'veranda suite': 'sitting area with sofa, refrigerator, TV, state of the art “infotainment” system, and private bathroom with shower is also featured in each cabin.',
        'superior suite': 'sitting area with sofa, refrigerator, TV, state of the art “infotainment” system, and private bathroom with shower is also featured in each cabin.',
        'deluxe suite': 'sitting area with sofa, refrigerator, TV, state of the art “infotainment” system, and private bathroom with shower is also featured in each cabin.',
        "owner's suite": 'separate sitting area with sofa, refrigerator, TV, state of the art “infotainment” system, and private bathroom with shower, dual vanity, and bathtub is also featured in each cabin.',
      },
    };

    function init() {
      document.querySelectorAll('.departure-card-inner .departure-card__cabins-btn').forEach(function (item) {
        item.addEventListener('click', function () {
          if (this.getAttribute('aria-expanded') == 'false') {
            var self = this;
            var cabinContainer = self.closest('.departure-card-inner');
            var interval = setInterval(function () {
              if (self.closest('.departure-card-inner').querySelectorAll('.cabin-selector__slider .cabin-selector__cabin-slide').length > 0) {
                clearInterval(interval);
                self
                  .closest('.departure-card-inner')
                  .querySelectorAll('.departure-card__cabin-selector .cabin-selector__cabin-details[data-item]')
                  .forEach(function (el) {
                    el && el.remove();
                  });
                var count = 0;
                var rowEls = [];
                var waitInterval = setInterval(function () {
                  cabinContainer.querySelectorAll('.cabin-selector__slider .cabin-selector__cabin-slide')[count].click();
                  setTimeout(function () {
                    rowEls.push(cabinContainer.querySelector('.departure-card__cabins .cabin-selector__cabin-details').cloneNode(true));
                  }, 50);
                  count++;
                }, 100);
                setTimeout(function () {
                  clearInterval(waitInterval);
                  rowEls.forEach(function (item, index) {
                    item.setAttribute('data-item', index);
                    cabinContainer.querySelector('.departure-card-inner .cabin-selector').insertAdjacentElement('afterend', item);
                  });
                  addEvent(cabinContainer);
                }, cabinContainer.querySelectorAll('.cabin-selector__slider .cabin-selector__cabin-slide').length * 100);
              }
            }, 50);
            setTimeout(function () {
              clearInterval(interval);
            }, 8000);
          }
        });
      });
    }

    function addEvent(cabinContainer) {
      cabinContainer.querySelectorAll('.cabin-selector__form .cabin-selector__occupancy').forEach(function (item) {
        item.addEventListener('change', function () {
          if (this.value != -1) {
            this.parentNode.nextElementSibling.disabled = false;
          } else {
            this.parentNode.nextElementSibling.disabled = true;
          }
        });
      });

      cabinContainer.querySelectorAll('.departure-card__cabin-selector > .cabin-selector__cabin-details .cabin-selector__book-btn').forEach(function (item) {
        item.addEventListener('click', function (e) {
          e.preventDefault();
          var idx = this.closest('.cabin-selector__cabin-details').getAttribute('data-item');
          document.querySelectorAll('.cabin-selector__slider .cabin-selector__cabin-slide')[idx].click();
          var selectedValue = this.closest('.cabin-selector__cabin-details').querySelector('.cabin-selector__occupancy').value;
          var departure_id = this.closest('.departure-card__cabins').getAttribute('id').split('-').pop();
          var cabin_index = document.querySelectorAll('.cabin-selector__slider .cabin-selector__cabin-slide')[idx].classList[1].split('-').pop();
          window.location.href = 'https://www.quarkexpeditions.com/booking?expedition_id=9141&departure_id=' + departure_id + '&cabin=' + selectedValue + '&cabin_index=' + cabin_index;
        });
      });

      cabinContainer.querySelectorAll('.cabin-selector__cabin-details[data-item]').forEach(function (item) {
        var html = '';
        item.querySelectorAll('.cabin-selector__cabin-stat').forEach(function (stat) {
          html += stat.querySelector('.cabin-stat__value').innerHTML + '<span>|</span>';
        });
        item.querySelector('.cabin-selector__cabin-price-wrapper').insertAdjacentHTML('beforebegin', '<div class="qa-description">' + html + '</div>');
        if (item.querySelector('.sold-out')) {
          item.querySelector('.cabin-selector__cabin-name').insertAdjacentHTML('beforeend', '<span class="qa-badge">Sold Out</span>');
        }
        item.querySelectorAll('.cabin-selector__cabin-body > p').forEach(function (para) {
          if (para.querySelector('strong') && para.querySelector('strong').innerHTML.includes('Standard Amenities')) {
            para.style.display = 'none';
          }
        });
        var cabinName = item.querySelector('.cabin-selector__cabin-name').innerHTML.toLowerCase();
        var shipName = item.closest('.departure-card-inner').querySelector('.detail--field-ship .detail__value').innerHTML.toLowerCase();
        var amenitiesText = cabinData[shipName] && cabinData[shipName][cabinName];
        // console.log(amenitiesText, amenitiesText.length);
        if (amenitiesText) {
          item.querySelector('.cabin-selector__cabin-price-wrapper').insertAdjacentHTML('beforebegin', '<p><strong>Cabin Amenities</strong>: ' + amenitiesText + '</p>');
        }
        var viewCTA = document.createElement('button');
        viewCTA.classList.add('qa-view-cta');
        viewCTA.innerHTML = 'Book This Cabin';
        viewCTA.addEventListener('click', function () {
          item.classList.toggle('active');
          if (item.classList.contains('active')) {
            this.innerHTML = 'Hide All Details';
          } else {
            this.innerHTML = 'Book This Cabin';
          }
        });
        item.querySelector('.qa-view-cta') && item.querySelector('.qa-view-cta').remove();
         item.querySelector('.cabin-selector__cabin-stats').insertAdjacentElement('beforebegin', viewCTA);
      });
    }

    /* Initialise variation */
    waitForElement('.departure-card-inner .departure-card__cabins-btn', init);
  } catch (e) {
    if (debug) console.log(e, 'error in Test' + variation_name);
  }
})();


.departure-card__cabin-selector .cabin-details__close {
  display: none;
}
.departure-card-inner .cabin-selector {
  display: none;
}
.departure-card-inner .departure-card__cabins {
  padding-left: 0px;
  padding-right: 0px;
}
.qa-description {
  margin: 10px 0px;
  font-size: 14px;
}
.qa-description > span {
  margin: 0 10px;
}
.qa-description > span:last-child {
  display: none;
}
.cabin-selector__cabin-details .cabin-selector__cabin-stats {
  display: none;
}
span.qa-badge {
  font-size: 16px;
  text-transform: uppercase;
  padding: 10px;
  background: #b4b6bd;
  color: #fff;
  margin-left: 20px;
  font-family: system-ui;
}

.cabin-selector__cabin-details .cabin-selector__cabin-offers,
.cabin-selector__cabin-details .cabin-selector__occupancy-prices,
.cabin-selector__cabin-details .cabin-selector__cabin-body,
.cabin-selector__cabin-details .cabin-selector__cabin-footer {
  display: none;
}

.cabin-selector__cabin-details.active .cabin-selector__cabin-offers,
.cabin-selector__cabin-details.active .cabin-selector__occupancy-prices,
.cabin-selector__cabin-details.active .cabin-selector__cabin-body,
.cabin-selector__cabin-details.active .cabin-selector__cabin-footer {
  display: block;
}

.cabin-selector__cabin-details__right > img {
  margin-bottom: 0px;
}
button.qa-view-cta {
  border: none;
    background: #f2a900;
    font-size: 0.75rem;
    font-weight: 700;
    height: 2.5rem;
    line-height:0.625rem;
    margin-top: 10px;
    font-family: Nunito Sans,sans-serif;
    padding: 7px 12px 7px 12px;
    text-align: left;
    border-radius: 2px;
    text-transform: uppercase;
}
button.qa-view-cta + * {
  clear: both;
}
Editor is loading...