const hiddenCategories = ['hidden']
const categoriesToHide = ['Live Events - Premium', 'Video on Demand - Premium', 'My Library', 'Continue Watching', 'Coming Up Next', 'Now Premiering on A+']
hideCategory(categoriesToHide)
function hideCategory(titlesArray) {
let categorySliders = document.querySelectorAll('.category-group:not(.touched)')
if (categorySliders.length) {
categorySliders.forEach(category =>{
if (category.querySelector('.category-title')) {
category.classList.add('touched')
if (hiddenCategories.includes(category.querySelector('.category-title').innerText.trim())) {
category.classList.add('hidden')
}
if (titlesArray.includes(category.querySelector('.category-title').innerText.trim())) {
category.classList.add('marked-category')
if (category.querySelector('.category-title').innerText.trim() === 'Video on Demand - Premium') {
category.classList.add('banner-category')
}
console.log(category.querySelector('.category-title').innerText.trim())
if (category.querySelector('.category-title').innerText.trim().includes('Premium')) {
let name = category.querySelector('.category-title').innerText.split('-')[0]
category.querySelector('.category-title').innerHTML = name + ' - PREMIUM'
}
}
}
})
}
let programTags = document.querySelectorAll('.cbt-tabs--categories button:not(.touched)')
if (programTags.length) {
programTags.forEach(button =>{
button.classList.add('touched')
if (hiddenCategories.includes(button.innerText)) {
button.classList.add('hidden')
}
})
}
let authorCustomSelect = document.querySelector('.s-author-area + div .secondary-filters .with-bottom-margin:nth-of-type(1) .multiselect');
if (authorCustomSelect) {
if (authorCustomSelect.querySelectorAll('.multiselect__element').length && !authorCustomSelect.classList.value.includes('touched')) {
let customSelectOptions = authorCustomSelect.querySelectorAll('.multiselect__element')
customSelectOptions.forEach(option => {
if (hiddenCategories.includes(option.innerText.trim())) {
option.classList.add('hidden')
}
})
authorCustomSelect.classList.add('touched')
}
}
let customSelect = document.querySelector('.catalog-area .secondary-filters .with-bottom-margin:nth-of-type(1) .multiselect');
if (customSelect) {
if (customSelect.querySelectorAll('.multiselect__element').length && !customSelect.classList.value.includes('touched')) {
let customSelectOptions = customSelect.querySelectorAll('.multiselect__element')
customSelectOptions.forEach(option => {
if (hiddenCategories.includes(option.innerText.trim())) {
option.classList.add('hidden')
}
})
customSelect.classList.add('touched')
}
}
setTimeout(() => hideCategory(titlesArray), 500)
}
let showOnlyAccessableBanners = () => {
axios.get('/api/sessions').then(response=> {
let AUS_NZ = ['AU', 'NZ']
let UK_IRELAND = ['UK', 'IE']
let USA = ['USA']
let EUROPE = ['BE', 'BG', 'CZ', 'DK', 'DE', 'EE', 'IE', 'EL', 'ES', 'FR', 'HR', 'IT', 'CY', 'LV', 'LT', 'LU', 'HU', 'MT', 'NL', 'AT', 'PL', 'PT', 'RO', 'SI', 'SK', 'FI', 'SE']
let SOUTH_AMERICA = ['AR', 'BO', 'BR', 'CL', 'CO', 'EC', 'FK', 'GF', 'GY', 'PY', 'PE', 'SR', 'UY', 'VE']
let session = response.data
if (session.country) {
let country = session.country;
console.log(country)
switch (true) {
case AUS_NZ.includes(country):
document.querySelectorAll('.AUS_NZ').forEach(banner => banner.classList.remove('hidden'))
console.log('AUS_NZ')
break;
case UK_IRELAND.includes(country):
document.querySelectorAll('.UK_IRELAND').forEach(banner => banner.classList.remove('hidden'))
console.log('UK_IRELAND')
break;
case USA.includes(country):
document.querySelectorAll('.USA').forEach(banner => banner.classList.remove('hidden'))
console.log('USA')
break;
case EUROPE.includes(country):
document.querySelectorAll('.EUROPE').forEach(banner => banner.classList.remove('hidden'))
console.log('EUROPE')
break;
case SOUTH_AMERICA.includes(country):
document.querySelectorAll('.SOUTH_AMERICA').forEach(banner => banner.classList.remove('hidden'))
console.log('SOUTH_AMERICA')
break;
default:
document.querySelectorAll('.EVERYWHERE_ELSE').forEach(banner => banner.classList.remove('hidden'))
console.log('EVERYWHERE_ELSE')
}
}
})
}
let detectCatalogPage = () => {
if (location.href.includes('/catalog')) {
let bannerCategory = document.querySelector('.banner-category')
if (bannerCategory) {
if (!bannerCategory.classList.value.includes('render-banner')) {
let banner1 = document.querySelector('.banner-1')
let markup = banner1.innerHTML
bannerCategory.insertAdjacentHTML('afterEnd', markup)
bannerCategory.classList.add('render-banner')
showOnlyAccessableBanners()
}
}
let bannerContainer = document.querySelector('.container.catalog')
if (bannerContainer) {
if (!bannerContainer.classList.value.includes('render-banner')) {
let banner2 = document.querySelector('.banner-2')
let markup = banner2.innerHTML
bannerContainer.insertAdjacentHTML('beforeEnd', markup)
bannerContainer.classList.add('render-banner')
showOnlyAccessableBanners()
}
}
let filters = document.querySelector('.ui-filters')
if (filters) {
if (!filters.classList.value.includes('touched')) {
let axiosHeaders = {
headers: {
'X-Fastly-Origin': 'adventureplus'
}
}
axios.get(`https://api-u-alpha.global.ssl.fastly.net/api/categories`, axiosHeaders).then(function (response) {
let categories = response.data
let markup = ''
categories.forEach(category => {
markup += ``
})
let htmlMarkup = ``
tabsContainer.insertAdjacentHTML('afterBegin', markup)
}
console.log(program)
})
tabsContainer.classList.add('touched')
}
}
}
setTimeout(() => detectProgramPage(), 500)
}
let detectOceanCategoryPage = () => {
if (location.href.includes('/categories/Ocean-Movies-presented-by-Blancpain')) {
let customWatch = document.querySelector('.custom-watch')
if (customWatch) {
if (customWatch.classList.value.includes('hidden')) {
customWatch.classList.remove('hidden')
}
}
let tabsContainer = document.querySelector('.s-category-area .container')
if (tabsContainer) {
if (!tabsContainer.classList.value.includes('touched')) {
let markup = `
`;
tabsContainer.insertAdjacentHTML('beforeend', markup)
var dureeAnimation = 5;
window.init_Blancpain_Watch();
tabsContainer.classList.add('touched')
}
}
} else {
let customWatch = document.querySelector('.custom-watch')
if (customWatch) {
if (!customWatch.classList.value.includes('hidden')) {
customWatch.classList.add('hidden')
}
}
}
setTimeout(() => detectOceanCategoryPage(), 500)
}
detectOceanCategoryPage()
detectProgramPage()
detectCatalogPage()
`
filters.insertAdjacentHTML('beforeBegin', htmlMarkup)
$('.custom-category-navigation button').on('click', function(){
let categorySlider = $(`.category-title[href="/categories/${$(this).data('target')}"]`)
if (categorySlider.length) {
$('html, body').animate({
scrollTop: categorySlider.offset().top - 140
}, 300);
} else {
$('html, body').animate({
scrollTop: document.body.scrollHeight
}, 300);
}
})
})
filters.classList.add('touched')
}
}
}
setTimeout(() => detectCatalogPage(), 500)
}
let detectProgramPage = () => {
let getPermalinkFromURL = (url) => {
return url.substring(url.indexOf('/programs/') + 10).split('?')[0]
}
let axiosHeaders = {
headers: {
'X-Fastly-Origin': 'adventureplus'
}
}
if (location.href.includes('/programs/')) {
let getAccessNow = document.querySelector('a[data-test="button-access"]')
if (getAccessNow) {
if (!getAccessNow.classList.value.includes('touched')) {
let customLink = getAccessNow.href;
if (GLOBAL_GET_ACCESS_NOW) {
customLink = GLOBAL_GET_ACCESS_NOW;
}
let programUrl = getPermalinkFromURL(location.href);
axios.get(`https://api-u-alpha.global.ssl.fastly.net/api/contents/${programUrl}`, axiosHeaders).then(function (response) {
let program = response.data
if (program.tags.length) {
program.tags.forEach(tag => {
if (tag.split('|')[0].trim().toLowerCase() === 'get_access_now') {
customLink = tag.split('|')[1].trim()
}
})
}
getAccessNow.href = customLink
})
getAccessNow.classList.add('touched')
}
}
let tabsContainer = document.querySelector('.container.cbt-program')
if (tabsContainer) {
if (!tabsContainer.classList.value.includes('touched')) {
let programUrl = getPermalinkFromURL(location.href);
axios.get(`https://api-u-alpha.global.ssl.fastly.net/api/contents/${programUrl}`, axiosHeaders).then(function (response) {
let program = response.data
let bannerImage = ''
let bannerUrl = ''
if (program.tags.length) {
program.tags.forEach(tag => {
if (tag.split('|')[0].trim().toLowerCase() === 'banner_image') {
bannerImage = tag.split('|')[1].trim()
}
if (tag.split('|')[0].trim().toLowerCase() === 'banner_url') {
bannerUrl = tag.split('|')[1].trim()
}
})
let markup = `