function filterMonths(el, url) { jQuery('#trip-cards .no-results').remove(); jQuery('#trip-cards').removeClass('no-results'); var $productCards = jQuery('.product-card.col-12'); $productCards.css('display', 'block'); $productCards.css('opacity', 0); $this = jQuery(el).find('label'); $parent = jQuery(el); if($parent.hasClass('checked') && url != 'yes') { $parent.removeClass('checked'); } else { $parent.addClass('checked'); if(url) { var clickedMonth = url; } else { var clickedMonth = $parent.data('month'); jQuery('.month-filter').each(function() { if(jQuery(this).data('month') != clickedMonth) { jQuery(this).removeClass('checked'); jQuery(this).find('.filter-option').prop('checked', false); } }); } $productCards.each(function() { var $this = jQuery(this); var thisMonths = $this.data('month').split(','); var thisCard = $this; if(jQuery.inArray(clickedMonth, thisMonths) == -1) { $this.css('display', 'none'); } }); } filterTrips(); setTimeout(function() { $productCards.css('opacity', 1); if (jQuery('.product-card.col-12:visible').length === 0 && !(jQuery('#trip-cards').hasClass('no-results'))) { jQuery('#trip-cards').append('
The trail doesn’t end here. Try different search filters.
'); jQuery('#trip-cards').addClass('no-results'); } }, 250); } function filterTrips(el) { jQuery('#trip-cards .no-results').remove(); jQuery('#trip-cards').removeClass('no-results'); var $productCards = jQuery('.product-card.col-12'); $productCards.css('display', 'block'); $productCards.css('opacity', 0); var clickedMonth = jQuery(el).data('month'); var placesArr = []; jQuery('.product-card.col-12').each(function() { var country = jQuery(this).data('destination').split(','); jQuery.each(country, function(index, value) { if(value.length > 0 && !placesArr.includes(value)) { placesArr.push(value); } }); }); var placesLength = placesArr.length var typeArr = ['climbing','culture','cycling','hiking','mountaineering','ski_touring','trekking','yoga','all']; var levelArr = ['advanced','beginner','fun','intermediate','pro','all']; var durationArr = [1, 7, 12, 20, 21]; var pricesArr = ['cheapest', 'cheap', 'midRange', 'expensive', 'moneybags']; var monthsArr = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; var deal = false; var months = 0; $this = jQuery(el).find('label'); $parent = jQuery(el); $parent.toggleClass('checked'); var $containers = jQuery('.filter-option-container'); $containers.each(function() { $this = jQuery(this); if($this.hasClass('checked')) { if($this.data('month')) { months = 1; clickedMonth = $this.data('month'); } if($this.data('price')) { if($this.data('price') == 'deal') { deal = true; } price = $this.data('price'); if(price == 2000) { pricesArr = jQuery.grep(pricesArr, function(value) { return value !='cheapest'; }); } if(price == 3000) { pricesArr = jQuery.grep(pricesArr, function(value) { return value != 'cheap'; }); } if(price == 4000) { pricesArr = jQuery.grep(pricesArr, function(value) { return value != 'midRange'; }); } if(price == 5000) { pricesArr = jQuery.grep(pricesArr, function(value) { return value != 'expensive'; }); } if(price == 6000) { pricesArr = jQuery.grep(pricesArr, function(value) { return value != 'moneybags'; }); } } if($this.data('destination')) { place = $this.data('destination'); placesArr = jQuery.grep(placesArr, function(value) { return value != place; }) } if($this.data('type')) { type = $this.data('type'); typeArr = jQuery.grep(typeArr, function(value) { return value != type; }) } if($this.data('level')) { level = $this.data('level'); levelArr = jQuery.grep(levelArr, function(value) { return value != level; }) } if($this.data('duration')) { duration = $this.data('duration'); durationArr = jQuery.grep(durationArr, function(value) { return value != duration; }) } } }); if(deal == true) { $productCards.each(function() { $this = jQuery(this); if(!$this.data('deal')) { $this.css('display', 'none'); } }) } if(months == 1) { jQuery('.month-filter').each(function() { if(jQuery(this).data('month') != clickedMonth) { jQuery(this).removeClass('checked'); jQuery(this).find('.filter-option').prop('checked', false); } }); $productCards.each(function() { var $this = jQuery(this); var thisMonths = $this.data('month').split(','); var thisCard = $this; if(jQuery.inArray(clickedMonth, thisMonths) == -1) { $this.css('display', 'none'); } }); } if(pricesArr.length < 5) { $productCards.each(function() { $this = jQuery(this); price = parseInt($this.data('price')); if(price < 2001) { price = 'cheapest'; } else if(price < 3001 && price > 2000) { price = 'cheap'; } else if(price < 4001 && price > 3000) { price = 'midRange'; } else if(price < 5001 && price > 4000) { price = 'expensive'; } else { price = 'moneybags'; } if(jQuery.inArray(price, pricesArr) != -1) { $this.css('display', 'none'); } }) } if(placesArr.length < placesLength) { $productCards.each(function() { $this = jQuery(this); var destination = $this.data('destination').split(','); var hitCount = 0; jQuery.each(destination, function(index, value) { if(jQuery.inArray(value, placesArr) == -1) { hitCount++; } }); if(hitCount == 0) { $this.css('display', 'none'); } }) } if(typeArr.length < 9) { $productCards.each(function() { $this = jQuery(this); var type = $this.data('type').split(','); var hitCount = 0; jQuery.each(type, function(index, value) { if(jQuery.inArray(value, typeArr) == -1) { hitCount++; } }); if(hitCount == 0) { $this.css('display', 'none'); } }) } if(levelArr.length < 6) { $productCards.each(function() { $this = jQuery(this); if(jQuery.inArray($this.data('level'), levelArr) != -1) { $this.css('display', 'none'); } }) } if(durationArr.length < 5) { $productCards.each(function() { $this = jQuery(this); thisDuration = $this.data('duration'); if(thisDuration < 2) { thisDuration = 1; } else if(thisDuration < 8) { thisDuration = 7; } else if(thisDuration <12) { thisDuration = 11; } else if(thisDuration <21) { thisDuration = 20; } else { thisDuration = 21; } if(jQuery.inArray(thisDuration, durationArr) != -1) { $this.css('display', 'none'); } }) } if(deal == false) { if(placesArr.length == placesLength && typeArr.length == 10 && levelArr.length == 4 && durationArr.length == 4 && pricesArr.length == 5 && months == 0) { $productCards.fadeIn(); } } setTimeout(function() { $productCards.css('opacity', 1); if (jQuery('.product-card.col-12:visible').length === 0 && !(jQuery('#trip-cards').hasClass('no-results'))) { jQuery('#trip-cards').append('The trail doesn’t end here. Try different search filters.
'); jQuery('#trip-cards').addClass('no-results'); } }, 250); } /* function toggleFilters() { var toggleBtn = jQuery('#mob-filter-toggle'); if(toggleBtn.html() == "SHOW FILTERS") { jQuery('.filter-cat').fadeIn(); toggleBtn.html('HIDE FILTERS'); } else { jQuery('.filter-cat').fadeOut(); toggleBtn.html('SHOW FILTERS'); } } function currencySwitch(cur) { var currency = cur; var rate = 0; var currencySymbol = '£'; if(currency == 'USD') { currencySymbol = '$' } if(currency == 'EUR') { currencySymbol = '€' } if(currency == 'AED') { currencySymbol = 'د.إ' } if(currency == 'KWD') { currencySymbol = 'د.ك' } if(currency == 'SGD') { currencySymbol = 'S$' } if(currency == 'CAD') { currencySymbol = '$' } if(currency == 'AUD') { currencySymbol = 'A$' } if(currency == 'SAR') { currencySymbol = 'ر.س' } setCookie('currency', currency); readTextFile('https://lifehappensoutdoors.com/currency.json', function(text) { var data = JSON.parse(text); rate = data.rates[currency]; jQuery('.product-card.col-12').each(function() { var cost = jQuery(this).data('price'); var sale = jQuery(this).data('sale'); var localCost = Math.round(cost * rate); var localSaleCost = Math.round(sale * rate); if(currency == 'GBP') { localCost = cost; localSaleCost = sale; jQuery(this).find('.price').html(localCost); jQuery('.pound').html('£'); } else { jQuery(this).find('.price').html(localCost); jQuery('.pound').html(currencySymbol); } if(sale) { jQuery(this).find('.sale-price').html(localSaleCost); } }) }); } */ jQuery(document).ready(function() { jQuery('.tab').on('click', function() { jQuery('.tab, .tab-content').removeClass('active'); jQuery(this).addClass('active'); clickedTab = jQuery(this).data('id'); if(clickedTab == 'calendar') { jQuery('.filter-cat[data-filter="departure"]').fadeOut(); } else { jQuery('.filter-cat[data-filter="departure"]').fadeIn(); } jQuery('.tab-content').each(function() { if(jQuery(this).data('id') == clickedTab) { jQuery(this).addClass('active') } }); }); //jQuery('#currency-choice').on('change', function() { //cur = jQuery(this).val(); //currencySwitch(cur); //}); /*if(getCookie('currency')) { var cur = getCookie('currency'); jQuery('#currency-choice').val(cur); currencySwitch(cur); }*/ }); var getUrlParameter = function getUrlParameter(sParam) { var sPageURL = window.location.search.substring(1), sURLVariables = sPageURL.split('&'), sParameterName, i; for (i = 0; i < sURLVariables.length; i++) { sParameterName = sURLVariables[i].split('='); if (sParameterName[0] === sParam) { return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]); } } return false; }; var urlPrice = getUrlParameter('price'); var urlMonth = getUrlParameter('month'); var urlDestination = getUrlParameter('destination'); var urlType = getUrlParameter('type'); var urlLevel = getUrlParameter('level'); var urlDuration = getUrlParameter('duration'); var levelOrder = 0; var durationOrder = 1; var dateOrder = 0; function sortTrips(sortBy, clicked) { var $cards = jQuery('.product-card'); jQuery('.trip-sort').removeClass('active'); jQuery(clicked).addClass('active'); $cards.css('order', 1000); switch(sortBy) { case 'date': if(dateOrder == 0) { $cards.each(function() { $this = jQuery(this); date = $this.data('date'); parsedDate = new Date(date); timestamp = parsedDate.getTime() / 100000; if(timestamp > 20000000) { timestamp = 30000000; } $this.css('order', timestamp); }) dateOrder = 1; } else { $cards.each(function() { $this = jQuery(this); date = $this.data('date'); parsedDate = new Date(date); timestamp = parsedDate.getTime() / 100000; if(timestamp > 20000000) { timestamp = 1; } $this.css('order', -timestamp); }) dateOrder = 0; } break; case 'duration': dateOrder = 0; if(durationOrder == 0) { $cards.each(function() { $this = jQuery(this); duration = 1000 - $this.data('duration'); $this.css('order', duration) }) durationOrder = 1; } else { $cards.each(function() { $this = jQuery(this); duration = $this.data('duration'); $this.css('order', duration) }) durationOrder = 0; } break; case 'low': dateOrder = 0; $cards.each(function() { $this = jQuery(this); price = $this.data('price'); $this.css('order', (price - 10000)); }); break; case 'high': $cards.each(function() { $this = jQuery(this); price = $this.data('price'); $this.css('order', (10000 - price)); }); break; case 'activity': dateOrder = 0; if(levelOrder == 0) { $cards.each(function() { $this = jQuery(this); level = $this.data('level'); if(level == 'chilled out') { $this.css('order', 1); } else if(level == 'moderate') { $this.css('order', 2); } else if(level == 'challenging') { $this.css('order', 3); } else if(level == 'strenuous') { $this.css('order', 4); } else if(level == 'outrageous') { $this.css('order', 5); } }); levelOrder = 1; } else { $cards.each(function() { $this = jQuery(this); level = $this.data('level'); if(level == 'chilled out') { $this.css('order', 5); } else if(level == 'moderate') { $this.css('order', 4); } else if(level == 'challenging') { $this.css('order', 3); } else if(level == 'strenuous') { $this.css('order', 2); } else if(level == 'outrageous') { $this.css('order', 1); } }); levelOrder = 0; } break; case 'deals': dateOrder = 0; $cards.each(function() { if(jQuery(this).data('deal')) { jQuery(this).css('order', 1); } }) break } } function countExp() { var seven = 0; var ten = 0; var fifteen = 0; var twentyone = 0; var more = 0; var chilled = 0; var moderate = 0; var challenging = 0; var strenuous = 0; var outrageous = 0; var trekking = 0; var multiadventure = 0; var rockclimbing = 0; var deals = 0; var cheapest = 0; var cheap = 0; var midRange = 0; var expensive = 0; var moneybags = 0; jQuery.each(countries, function(index, value) { count = 0; jQuery('.product-card.col-12').each(function() { var cardDestinations = jQuery(this).data('destination').split(','); jQuery.each(cardDestinations, function(index, destination) { if(destination == value) { count++ } }) }); jQuery('.destination-filter .filter-option-container').each(function() { if(jQuery(this).data('destination') == value) { jQuery(this).find('label').append(' ('+count+')'); } }); }) jQuery('.product-card.col-12').each(function() { $this = jQuery(this); var level = $this.data('level'); var duration = $this.data('duration'); var type = $this.data('type').split(','); var price = parseInt($this.data('price')); if($this.data('deal')) { deals++; } if(price < 2001) { cheapest++ } else if(price < 3001) { cheap++ } else if(price < 4001) { midRange++ } else if(price < 5001) { expensive++ } else if(price >= 5000) { moneybags++ } jQuery.each(type, function(index, value) { if(value == 'trekking') { trekking++ } if(value == 'multi-adventure') { multiadventure++ } if(value == 'climbing-and-mountaineering') { rockclimbing++ } }) if(level == 'chilled out') { chilled++ } if(level == 'challenging') { challenging++ } if(level == 'strenuous') { strenuous++ } if(level == 'outrageous') { outrageous++ } if(duration < 1) { seven++; } else if(duration < 7) { ten++; } else if(duration < 12) { fifteen++; } else if(duration < 20) { twentyone++; } else { more++ } }); jQuery('.filter-cat[data-filter="prices"] .filter-option-container').each(function(index) { var $this = jQuery(this); if($this.data('price') == 'deal') { if(deals == 0) { $this.css('display', 'none'); jQuery('#deal-sort').css('display', 'none'); } else { $this.find('label').append(' (' +deals+ ')'); } } if($this.data('price') == 2000) { if(cheapest == 0) { $this.css('display', 'none') } else { $this.find('label').append(' (' +cheapest+ ')') } } if($this.data('price') == 3000) { if(cheap == 0) { $this.css('display', 'none') } else { $this.find('label').append(' (' +cheap+ ')') } } if($this.data('price') == 4000) { if(midRange == 0) { $this.css('display', 'none') } else { $this.find('label').append(' (' +midRange+ ')') } } if($this.data('price') == 5000) { if(expensive == 0) { $this.css('display', 'none') } else { $this.find('label').append(' (' +expensive+ ')') } } if($this.data('price') == 6000) { if(moneybags == 0) { $this.css('display', 'none') } else { $this.find('label').append(' (' +moneybags+ ')') } } }); jQuery('.filter-cat[data-filter="type"] .filter-option-container').each(function(index) { var $this = jQuery(this); if($this.data('type') == 'trekking') { if(trekking == 0) { $this.css('display', 'none'); } else { $this.find('label').append(' (' +trekking+ ')'); } } if($this.data('type') == 'multi-adventure') { if(multiadventure == 0) { $this.css('display', 'none'); } else { $this.find('label').append(' (' +multiadventure+ ')'); } } if($this.data('type') == 'climbing-and-mountaineering') { if(rockclimbing == 0) { $this.css('display', 'none'); } else { $this.find('label').append(' (' +rockclimbing+ ')'); } } }); jQuery('.filter-cat[data-filter="duration"] .filter-option-container').each(function(index) { var $this = jQuery(this); if(index == 0) { if(seven == 0) { $this.css*('display', 'none'); } else { $this.find('label').append(' (' +seven+ ')'); } } if(index == 1) { if(ten == 0) { $this.css('display', 'none'); } else { $this.find('label').append(' (' +ten+ ')'); } } if(index == 2) { if(fifteen == 0) { $this.css('display', 'none'); } else { $this.find('label').append(' (' +fifteen+ ')'); } } if(index == 3) { if(twentyone == 0) { $this.css('display', 'none'); } else { $this.find('label').append(' (' +twentyone+ ')'); } } if(index == 4) { if(more == 0) { $this.css('display', 'none'); } else { $this.find('label').append(' (' +more+ ')'); } } }); jQuery('.filter-cat[data-filter="level"] .filter-option-container').each(function(index) { var $this = jQuery(this); if(index == 0) { if(chilled == 0) { $this.css('display', 'none'); } else { $this.find('label').append(' (' +chilled+ ')'); } } if(index == 1) { if(challenging == 0) { $this.css('display', 'none'); } else { $this.find('label').append(' (' +challenging+ ')'); } } if(index == 2) { if(strenuous == 0) { $this.css('display', 'none'); } else { $this.find('label').append(' (' +strenuous+ ')'); } } if(index == 3) { if(outrageous == 0) { $this.css('display', 'none'); } else { $this.find('label').append(' (' +outrageous+ ')'); } } }); } var countries = []; counter = 0; window.addEventListener('DOMContentLoaded', (event) => { // Get List of Countries jQuery('.product-card.col-12').each(function() { var countryArray = jQuery(this).data('destination').split(','); jQuery.each(countryArray, function(index, value) { var country = value; if(country.length > 0 && !countries.includes(country)) { countries.push(country); } }) }); countries = countries.sort(); // Populate Country Filter while(counter < countries.length) { jQuery('.destination-filter .filter-form').append(''); counter++; } if(window.innerWidth <= 900) { jQuery('.unfold').removeClass('open'); } countExp(); jQuery('.product-card.col-12').each(function() { $this = jQuery(this); date = $this.data('date'); parsedDate = new Date(date); timestamp = parsedDate.getTime() / 100000; $this.css('order', timestamp); }); if(urlPrice || urlMonth || urlDestination || urlType || urlLevel || urlDuration) { var $containers = jQuery('.filter-option-container'); if(urlPrice) { jQuery('.filter-cat[data-filter="prices"] .filter-option-container').each(function(index) { var $this = jQuery(this); if($this.data('price') == urlPrice) { $this.toggleClass('checked'); } }); } if(urlMonth) { jQuery('.filter-cat[data-filter="departure"] .filter-option-container').each(function(index) { var $this = jQuery(this); if($this.data('month').toLowerCase() == urlMonth) { $this.toggleClass('checked'); } }); } if(urlType) { jQuery('.filter-cat[data-filter="type"] .filter-option-container').each(function(index) { var $this = jQuery(this); if($this.data('type') == urlType) { $this.toggleClass('checked'); } }); jQuery('.filter-cat[data-filter="type"] .unfold').addClass('open'); } if(urlLevel) { jQuery('.filter-cat[data-filter="level"] .filter-option-container').each(function(index) { var $this = jQuery(this); if($this.data('level').replace(' ', '-') == urlLevel) { $this.toggleClass('checked'); } }); jQuery('.filter-cat[data-filter="level"] .unfold').addClass('open'); } if(urlDuration) { jQuery('.filter-cat[data-filter="duration"] .filter-option-container').each(function(index) { var $this = jQuery(this); if($this.data('duration') == urlDuration) { $this.toggleClass('checked'); } }); jQuery('.filter-cat[data-filter="duration"] .unfold').addClass('open'); } if(urlDestination) { jQuery('.destination-filter .filter-option-container').each(function() { var $this = jQuery(this); if($this.data('destination') == urlDestination) { $this.toggleClass('checked'); } }) jQuery('.destination-filter .unfold').addClass('open'); } if(urlMonth) { filterMonths('', urlMonth); } else { filterTrips(); } } });