// Global const path = document.location.origin + '/fr/paris/'; // Layout function layoutElement(tag, css_class, parent) { var element = document.createElement(tag); if(css_class !== null) element.className = css_class; parent.appendChild(element); return element; } function layoutImage(img_array, css_class, parent) { if(img_array === null) return; var img = document.createElement('img'); if(css_class !== null) img.className = css_class; img.src = img_array['url']; img.alt = img_array['alt']; parent.appendChild(img); return img; } function layoutHeading(heading, title, css_class, parent) { if(title === null) return; var heading = document.createElement(heading); heading.innerHTML = title; if(css_class !== null) heading.className = css_class; parent.appendChild(heading); return heading; } function layoutTitle(heading, title, icon, css_class, parent) { if(title === null && icon !== null) return layoutImage(icon, css_class, parent); if(title !== null && icon === null) return layoutHeading(heading, title, css_class, parent); if(title === null && icon === null) return; var div = document.createElement('div'); if(css_class !== null) div.className = css_class; layoutHeading(heading, title, '', div); layoutImage(icon, '', div); parent.appendChild(div); return div; } function layoutButton(link, heading, title, icon, css_class, parent, target = null, rel = null) { if(link === null) return layoutTitle(heading, title, icon, css_class, parent); var a = document.createElement('a'); if(css_class !== null) a.className = css_class; a.href= link['url']; a.title = link['title']; if(target !== null) a.target = target; if(rel !== null) a.rel = rel; if(title !== null) layoutHeading(heading, title, '', a); if(icon !== null) layoutImage(icon, '', a); parent.appendChild(a); return a; } function layoutScript(url, parent) { var script = document.createElement('script'); script.src = url; parent.appendChild(script); } function layoutAdvertiserGeographicalAreaButton(link, heading, title, icon, css_class, parent, target = null, rel = null, placement = null, link_type = null, section = null, rank = null, advertiser_geographical_area_identifier = null, marketing_source_identifier = null) { if(link === null) return layoutTitle(heading, title, icon, css_class, parent); var a = document.createElement('a'); a.className = 'os-ms'; if(css_class !== null) a.addClass(css_class); a.href= link['url']; a.title = link['title']; if(target !== null) a.target = target; if(rel !== null) a.rel = rel; a.setAttribute("data-os_aga", link['title']); if(placement !== null) a.setAttribute("data-os_dlp", placement); if(link_type !== null) a.setAttribute("data-os_dlt", link_type); if(section !== null) a.setAttribute("data-os_element", section); if(advertiser_geographical_area_identifier !== null) a.setAttribute("data-os_adv_id", advertiser_geographical_area_identifier); if(rank !== null) a.setAttribute("data-os_r", rank); if(marketing_source_identifier !== null) a.setAttribute("data-os_ms", marketing_source_identifier); if(title !== null) layoutHeading(heading, title, '', a); if(icon !== null) layoutImage(icon, '', a); parent.appendChild(a); return a; } https:// Global variables function setGlobalVariables() { const url = path + 'wp-content/themes/odds-scanner-main/ajax/update-wp-global-variables.php'; jQuery.ajax({ url: url, data: { wp_site_id: wp_site_id, wp_post_id: wp_post_id, }, success: function(data) { wp_site = data.wp_site wp_post = data.wp_post }, dataType: 'json' }); } https:// Cookies function setCookie(cname, cvalue, seconds) { if(seconds) { var d = new Date(); d.setTime(d.getTime() + (seconds * 1000)); var expires = 'expires=' + d.toUTCString(); document.cookie = cname + '=' + cvalue + ';' + expires + ';path=/'; } else document.cookie = cname + '=' + cvalue + ';path=/'; } https://Hack function setCoookie(cname, cvalue, seconds) { if(seconds) { var d = new Date(); d.setTime(d.getTime() + (seconds * 1000)); var expires = 'expires=' + d.toUTCString(); document.cookie = cname + '=' + cvalue + ';' + expires + ';path=/'; } else document.cookie = cname + '=' + cvalue + ';path=/'; } function getCookie(cname) { var name = cname + '='; var ca = document.cookie.split(';'); for(var i = 0; i < ca.length; i++) { var c = ca[i]; while(c.charAt(0) == ' ') c = c.substring(1); if(c.indexOf(name) == 0) return c.substring(name.length, c.length); } return ''; } function checkCookie(new_identifier, time) { var identifier = getCookie(new_identifier); if(identifier != '') return false; else if(new_identifier != '' && new_identifier != null) { setCookie(new_identifier, new_identifier, time); return true; } } https:// Auxiliar Functions function leftPad(num, size) { num = num.toString(); while(num.length < size) num = '0' + num; return num; } https:// Account function accountSignOut() { var url = path + 'wp-content/themes/odds-scanner-main/ajax/sign-out.php'; jQuery.ajax({ url: url, data: { wp_site_id: wp_site_id }, success: function(data) { if(data.status == 'success') location.replace(data.redirect.url); }, dataType: 'json' }); } function accountSignUp(form_id) { var fields = {}; var fields_el = jQuery('#' + form_id + ' .field input, #' + form_id + ' .field textarea, #' + form_id + ' .field select'); for(var i = 0; i < fields_el.length; i++) if(fields_el[i].name) { var errors = jQuery(jQuery(fields_el[i]).parent().find('.error')[0]).children(); for(var j = 0; j < errors.length; j++) errors[j].remove(); fields[fields_el[i].name] = {name: fields_el[i].name, type: fields_el[i].type, required: fields_el[i].required, value: fields_el[i].value, checked: fields_el[i].checked}; } var url = path + 'wp-content/themes/odds-scanner-main/ajax/sign-up.php'; jQuery.ajax({ url: url, data: { wp_site_id: wp_site_id, wp_post_id: wp_post_id, form_identifier: form_id, fields: fields }, success: function(data) { for(var i = 0; i < fields_el.length; i++) if(fields_el[i].name) if(data.errors[fields_el[i].name] != true) { var error_el = jQuery(fields_el[i]).parent().find('.error')[0]; for(var j = 0; j < data.errors[fields_el[i].name].length; j++) layoutHeading('span', data.errors[fields_el[i].name][j], null, error_el); } if(data.success == true) { if(data.reload) location.reload(); else location.replace(data.redirect.url); } }, dataType: 'json' }); } function accountSignIn(form_id) { var fields = {}; var fields_el = jQuery('#' + form_id + ' .field input, #' + form_id + ' .field textarea, #' + form_id + ' .field select'); for(var i = 0; i < fields_el.length; i++) if(fields_el[i].name) { var errors = jQuery(jQuery(fields_el[i]).parent().find('.error')[0]).children(); for(var j = 0; j < errors.length; j++) errors[j].remove(); fields[fields_el[i].name] = {name: fields_el[i].name, type: fields_el[i].type, required: fields_el[i].required, value: fields_el[i].value, checked: fields_el[i].checked}; } var url = path + 'wp-content/themes/odds-scanner-main/ajax/sign-in.php'; jQuery.ajax({ url: url, data: { wp_site_id: wp_site_id, wp_post_id: wp_post_id, form_identifier: form_id, fields: fields }, success: function(data) { for(var i = 0; i < fields_el.length; i++) if(fields_el[i].name) if(data.errors[fields_el[i].name] != true) { var error_el = jQuery(fields_el[i]).parent().find('.error')[0]; for(var j = 0; j < data.errors[fields_el[i].name].length; j++) layoutHeading('span', data.errors[fields_el[i].name][j], null, error_el); } if(data.success == true) { if(data.reload) location.reload(); else location.replace(data.redirect.url); } }, dataType: 'json' }); } function accountRecoverPassword(form_id) { var fields = {}; var fields_el = jQuery('#' + form_id + ' .field input, #' + form_id + ' .field textarea, #' + form_id + ' .field select'); for(var i = 0; i < fields_el.length; i++) if(fields_el[i].name) { var errors = jQuery(jQuery(fields_el[i]).parent().find('.error')[0]).children(); for(var j = 0; j < errors.length; j++) errors[j].remove(); fields[fields_el[i].name] = {name: fields_el[i].name, type: fields_el[i].type, required: fields_el[i].required, value: fields_el[i].value, checked: fields_el[i].checked}; } var url = path + 'wp-content/themes/odds-scanner-main/ajax/recover-password.php'; jQuery.ajax({ url: url, data: { wp_site_id: wp_site_id, form_identifier: form_id, fields: fields }, success: function(data) { for(var i = 0; i < fields_el.length; i++) if(fields_el[i].name) if(data.errors[fields_el[i].name] != true) { var error_el = jQuery(fields_el[i]).parent().find('.error')[0]; for(var j = 0; j < data.errors[fields_el[i].name].length; j++) layoutHeading('span', data.errors[fields_el[i].name][j], null, error_el); } if(data.success == true) { var success_message = jQuery('#' + form_id + ' > form > .success')[0]; var success_messages = jQuery(success_message).children(); for(var j = 0; j < success_messages.length; j++) success_messages[j].remove(); layoutHeading('span', data.success_message, null, success_message); } }, dataType: 'json' }); } function accountChangePassword(form_id) { var fields = {}; var fields_el = jQuery('#' + form_id + ' .field input, #' + form_id + ' .field textarea, #' + form_id + ' .field select'); for(var i = 0; i < fields_el.length; i++) if(fields_el[i].name) { var errors = jQuery(jQuery(fields_el[i]).parent().find('.error')[0]).children(); for(var j = 0; j < errors.length; j++) errors[j].remove(); fields[fields_el[i].name] = {name: fields_el[i].name, type: fields_el[i].type, required: fields_el[i].required, value: fields_el[i].value, checked: fields_el[i].checked}; } var url = path + 'wp-content/themes/odds-scanner-main/ajax/change-password.php'; jQuery.ajax({ url: url, data: { wp_site_id: wp_site_id, wp_post_id: wp_post_id, form_identifier: form_id, fields: fields }, success: function(data) { for(var i = 0; i < fields_el.length; i++) if(fields_el[i].name) if(data.errors[fields_el[i].name] != true) { var error_el = jQuery(fields_el[i]).parent().find('.error')[0]; for(var j = 0; j < data.errors[fields_el[i].name].length; j++) layoutHeading('span', data.errors[fields_el[i].name][j], null, error_el); } if(data.success == true) { var success_message = jQuery('#' + form_id + ' > form > .success')[0]; var success_messages = jQuery(success_message).children(); for(var j = 0; j < success_messages.length; j++) success_messages[j].remove(); layoutHeading('span', data.success_message, null, success_message); } }, dataType: 'json' }); } // Statistics function wpPostsViews(wp_post_id) { if(checkCookie('wp-posts-views-' + wp_post_id)) { var url = path + 'wp-content/themes/odds-scanner-main/ajax/wp-posts-views.php'; jQuery.ajax({ url: url, data: { wp_post_id: wp_post_id }, success: function(data) { }, dataType: 'json' }); } } // Effects function setCowntdown() { setInterval(function() { jQuery('.countdown').each(function() { var seconds = jQuery(this).find('.seconds > span'); if(seconds[0].innerHTML == 0) { seconds[0].innerHTML = 59; var minutes = jQuery(this).find('.minutes > span'); if(minutes[0].innerHTML == 0) { minutes[0].innerHTML = 59; var hours = jQuery(this).find('.hours > span'); if(hours[0].innerHTML == 0) { hours[0].innerHTML = 23; var days = jQuery(this).find('.days > span'); days[0].innerHTML = leftPad(days[0].innerHTML - 1, 2); } else hours[0].innerHTML = leftPad(hours[0].innerHTML - 1, 2); } else minutes[0].innerHTML = leftPad(minutes[0].innerHTML - 1, 2); } else seconds[0].innerHTML = leftPad(seconds[0].innerHTML - 1, 2); }); }, 1000); } function smoothHref() { jQuery('[href*="#"]').click(function(e) { e.preventDefault(); var url = this.href; var url_array = url.split('#'); if(url_array[1] != '') { var fixed_header = jQuery('header'); var fixed_header_height = fixed_header.length > 0 ? fixed_header[0].offsetHeight : 0; var widget_navigation = window.innerWidth <= 1199 ? jQuery('.widget-navigation ul')[0].offsetHeight : 0; jQuery('html, body').animate({ scrollTop: jQuery(jQuery('#' + url_array[url_array.length - 1]).offset().top)[0] - fixed_header_height - widget_navigation - 5 }, 500); } }); } // Display/Hide function responsivenessDisplayNavigationWidget() { if (window.innerWidth <= 1199) { jQuery(window).scroll(function () { var scroll = jQuery(window).scrollTop(); if (scroll > 320) jQuery('.widget-navigation').addClass('show'); else jQuery('.widget-navigation').removeClass('show'); }); } } function toggleFaq(element) { var current_faq_card = jQuery(element).parent(); var content_block = current_faq_card.parent(); var faq_cards = content_block[0].children; for(var i = 0; i < faq_cards.length; i++) { if(faq_cards[i] == current_faq_card[0]) { current_faq_card.toggleClass('open'); current_faq_card.toggleClass('close'); } else { jQuery(faq_cards[i]).removeClass('open'); jQuery(faq_cards[i]).addClass('close'); } } } function showAll(element) { var cards = jQuery(element).parent()[0].children; for(var i = 0; i < cards.length; i++) jQuery(cards[i]).removeClass('hide'); element.remove(); } function showMoreLessContent(element, strings) { var title = jQuery(element).find('span'); var more_content = jQuery(element).parent().find('.more-content'); if(element.className.includes('less')) { jQuery(element).removeClass('less'); more_content.removeClass('less'); title[0].innerHTML = strings['less']['title']; } else { jQuery(element).addClass('less'); more_content.addClass('less'); title[0].innerHTML = strings['more']['title']; } } function showMoreLessAdvertisersGeographicalAreasInfo(element, strings) { var title = jQuery(element).find('span'); var more_content = jQuery(element).parent().parent().parent().find('.more-content'); if(element.className.includes('less')) { jQuery(element).removeClass('less'); more_content.removeClass('less'); title[0].innerHTML = strings['less']['title']; } else { jQuery(element).addClass('less'); more_content.addClass('less'); title[0].innerHTML = strings['more']['title']; } } // Menu function openSubmenu(element) { jQuery(element).parent().parent().toggleClass('opened'); } // Geo Target function changeGeoTarget(geographical_area_id) { var url = path + 'wp-content/themes/odds-scanner-main/ajax/geo-target-change.php'; jQuery.ajax({ url: url, data: { wp_site_id: wp_site_id, wp_user_id: wp_user_id, geographical_area_id: geographical_area_id }, success: function(data) { location.reload(); }, dataType: 'json' }); } window.addEventListener('load', () => onLoad()); function onLoad() { wpPostsViews(wp_post_id); setCowntdown(); smoothHref(); bannerManager(); handleFixedWidgets(); responsivenessDisplayNavigationWidget(); last_width = window.innerWidth; if(age_restriction_active) ageRestrictionPopUp(); dropCookie(); } // Age Restriction Pop Up function ageRestrictionPopUp() { if(getCookie('age-restriction')) return; const identifier = 'age-restriction-pop-up'; closePopUp(identifier); const url = path + 'wp-content/themes/os-sportsbook-child/ajax/pop-ups.php'; jQuery.ajax({ url: url, data: { wp_site_id: wp_site_id, wp_post_id: wp_post_id, type: 'age_restriction' }, success: function(data) { const body = jQuery('body'); body.addClass(`pop-up ${identifier}`); const siteContainerDiv = jQuery(body).find('.site-container'); const popUpDiv = layoutElement('div', `pop-up ${identifier}`, siteContainerDiv[0]); popUpDiv.id = identifier; const popUpContainerDiv = layoutElement('div', 'pop-up-container', popUpDiv); const popUpContainerTopDiv = layoutElement('div', 'top', popUpContainerDiv); const iconDiv = layoutElement('div', 'icon', popUpContainerTopDiv); layoutImage(data['style_icons']['age'], null, iconDiv); const popUpContainerMiddleDiv = layoutElement('div', 'middle', popUpContainerDiv); const titleDiv = layoutElement('div', 'title', popUpContainerMiddleDiv); layoutHeading(data['introduction_title']['heading'], data['introduction_title']['title'], null, titleDiv); const contentDiv = layoutElement('div', 'content', popUpContainerMiddleDiv); contentDiv.innerHTML = data['introduction_content']; const popUpContainerBottomDiv = layoutElement('div', 'bottom', popUpContainerDiv); const popUpContainerButtonsDiv = layoutElement('div', 'buttons', popUpContainerBottomDiv); const confirmDiv = layoutElement('div', 'confirm', popUpContainerButtonsDiv); layoutTitle('span', data['buttons_confirm']['title'], null, null, confirmDiv); confirmDiv.addEventListener('click', () => { setCoookie('age-restriction', 'age-restriction', null); closePopUp(identifier); }) const denyDiv = layoutElement('div', 'deny', popUpContainerButtonsDiv); layoutButton(data['buttons_deny']['link'], 'span', data['buttons_deny']['title'], null, null, denyDiv); }, dataType: 'json', }) } // Close Pop Up function closePopUp(id) { const bodyDiv = jQuery(document.body); const popUpDiv = bodyDiv.find(`.${id}`); if(!popUpDiv.length) return; popUpDiv.remove(); bodyDiv.removeClass(`pop-up ${id}`); } // Search function handleSearchOnClick(element) { const currentElement = jQuery(element); const searchBarElement = currentElement.closest('.search'); const inputElement = searchBarElement.find('input'); handleSearch(inputElement); } function handleSearchBarInputOnKeyDown(element, event) { if(event.key == 'Enter') handleSearch(jQuery(element)); } function handleSearch(inputElement) { var url = path + 'wp-content/themes/os-sportsbook-child/ajax/search.php'; jQuery.ajax({ url: url, data: { wp_site_id: wp_site_id, }, success: function (data) { if(inputElement.val()) location.href= `${data.link.url}?search=${inputElement.val()}`; }, dataType: 'json' }); } https:// Not Recommended Pop Up function handleNotRecommendedPopUpCloseOnClick(e = null) { var notRecommendedPopUp = jQuery('.not-recommended-pop-up'); if((e == null) || ((e != null) && (e.target == e.currentTarget))) { $(notRecommendedPopUp).remove(); } } https:// Footer function handleFooterCTACloseOnClick(element) { const currentElement = jQuery(element); currentElement.closest('.bottom-cta').remove(); } https:// Show More function handleShowMoreCardsOnClick(element) { const currentElement = jQuery(element); const cardsContainerElement = currentElement.parent(); cardsContainerElement.children().each(function () { if($(this).hasClass('hide')) $(this).removeClass('hide'); }); currentElement.remove(); } https:// Header Menu Responsiveness function handleMobileMenuStructure() { const topBarCenter = jQuery('header .top .center'); const topBarCenterElement = topBarCenter[0]; const topBarRight = jQuery('header .top .right'); const topBarRightElement = topBarRight[0]; const bottomBarMenus = jQuery('header .bottom .center'); const bottomBarMenusElement = bottomBarMenus[0]; const bottomBawrapper = jQuery('header .bottom .wrapper'); const bottomBawrapperElement = bottomBawrapper[0]; const mobileMenu = jQuery('.mobile-menu'); const mobileMenuElement = mobileMenu[0]; const search = jQuery('.search'); const searchElement = search[0]; const primaryMenu = jQuery('.primary-menu'); const primaryMenuElement = primaryMenu[0]; const languageSwitcher = jQuery('.language-switcher'); const languageSwitcherElement = languageSwitcher[0]; const sambaGold = jQuery('.samba-gold'); const sambaGoldElement = sambaGold[0]; if(window.innerWidth<1200) { if(searchElement) mobileMenuElement.appendChild(searchElement); if(primaryMenuElement) mobileMenuElement.appendChild(primaryMenuElement); if(languageSwitcherElement) mobileMenuElement.appendChild(languageSwitcherElement); if(sambaGoldElement) mobileMenuElement.appendChild(sambaGoldElement); } else { if(searchElement) topBarCenterElement.appendChild(searchElement); if(primaryMenuElement) bottomBarMenusElement.appendChild(primaryMenuElement); if(languageSwitcherElement) bottomBawrapperElement.appendChild(languageSwitcherElement); if(sambaGoldElement) topBarRightElement.appendChild(sambaGoldElement); } } function handleMobileMenuOpenCloseOnClick() { handleMobileMenuStructure(); const mobileMenuNavigation = jQuery('.mobile-menu-navigation'); const mobileMenuNavigationElement = mobileMenuNavigation[0]; const resposiveness = jQuery('header .resposiveness'); const mobileMenu = jQuery('.mobile-menu'); mobileMenuNavigation.children().each(function () { if($(this).hasClass('hide')) $(this).removeClass('hide'); else $(this).addClass('hide'); }); if(mobileMenuNavigationElement.className.includes('closed')) { mobileMenuNavigation.toggleClass('closed'); mobileMenu.toggleClass('closed'); resposiveness.toggleClass('closed'); } else { mobileMenuNavigation.toggleClass('closed'); mobileMenu.toggleClass('closed'); resposiveness.toggleClass('closed'); } } https:// Sportsbook Review function handleSportsbookTablesActiveOnClick(element) { const headElement = jQuery(element).parent(); let headElements; if(headElement) headElements = headElement.children(); const bodyElement = jQuery(element).parent().parent().find('.body'); let bodyElements; if(bodyElement) bodyElements = bodyElement.children(); for(var i=0;i Object.keys(bannerObject['wp_fields']['banners_banners']).length - 1) banners_map[dataId] = 0; setCookie('banner_index_' + dataId, banners_map[dataId]); return; } }; }, dataType: 'json' }); }); } function handleCloseBannerOnClick(element) { const currentElement = jQuery(element); const bannerManager = currentElement.closest('.banner-manager'); const bannerElement = currentElement.closest('.banner'); setCookie('banner_close_' + bannerManager.attr('data-id'), '1'); bannerElement.remove(); } // Event listeners let last_width = 0; window.addEventListener('resize', () => { if(window.innerWidth < 1200 && last_width > 1200) handleMobileMenuStructure(); else if(window.innerWidth >= 1200 && last_width <= 1200) handleMobileMenuStructure(); last_width = window.innerWidth; }); // Gallery Pop Up jQuery(document).ready(function(e) { let gallery = jQuery('.gallery .gallery-item'); gallery.on('click', function(event) { event.stopPropagation(); event.bubbles = false; createGalleryPopUp($(this)); }); }); function createGalleryPopUp(element) { let body = jQuery('body'); body.addClass('gallery-pop-up-opened'); let galleryPopUp = jQuery('.gallery-pop-up'); $(galleryPopUp).addClass('opened'); let imageData = jQuery('.gallery-pop-up .image'); $(imageData).attr('data-i', $(element).attr('data-i')); $(imageData).css('background-image', 'url(' + $(element).children().attr('src') + ')'); } function handleGalleryPopUpNavigation(element, direction) { let gallery = jQuery('.gallery .gallery-item'); let total_images = gallery.length; let currentImage = jQuery(element).parent().parent().find('.image'); let currentId = $(currentImage).attr('data-i'); if((direction == '-1') && (currentId != 0)) currentId--; else if((direction == '1') && (currentId != total_images - 1)) currentId++; image = $(gallery[currentId]).children(); $(currentImage).attr('data-i', currentId); $(currentImage).css('background-image', 'url(' + $(image).attr('src') + ')'); } function closeGalleryPopUp(e = null) { var galleryPopUp = jQuery('.gallery-pop-up'); if((e == null) || ((e != null) && (e.target == e.currentTarget))) { if(galleryPopUp.hasClass('opened')) { jQuery(galleryPopUp[0]).removeClass('opened'); var body = jQuery('body'); jQuery(body[0]).removeClass('gallery-pop-up-opened'); } } } // Fixed Widgets function handleFixedWidgets() { let header = jQuery('header'); let sidebar = jQuery('.right-sidebar'); if(sidebar.length === 0) sidebar = jQuery('.advertisers-sidebar'); let site_main_padding = 60; let advertiser = jQuery(sidebar).find('.advertisers-geographical-areas.vertical.medium-cards').parent(); let navigation = jQuery(sidebar).find('.widget-navigation'); if (window.innerWidth >= 1200) { jQuery(window).scroll(function() { let scroll = jQuery(window).scrollTop(); let header_height = header.length > 0 ? header[0].offsetHeight : 0; let sidebar_height = sidebar.length > 0 ? jQuery(sidebar[0]).outerHeight(true) : 0; let fixed_widgets = []; let fixed_widgets_height = 0; if((advertiser.length > 0) && (advertiser.children().length > 0)) fixed_widgets.push(advertiser); if((navigation.length > 0) && (navigation.children().length > 0)) fixed_widgets.push(navigation); if(fixed_widgets.length > 0) for (let i = 0; i < fixed_widgets.length; i++) fixed_widgets_height += jQuery(fixed_widgets[i]).outerHeight(true); let widgets = sidebar.find('.widget'); let widgets_height = 0; if(widgets.length > 0) { for (let i = 0; i < widgets.length; i++) widgets_height += jQuery(widgets[i]).outerHeight(true); widgets_height -= fixed_widgets_height; } if (fixed_widgets.length > 0) { if (scroll > site_main_padding + widgets_height) { if (scroll + header_height + jQuery(fixed_widgets[fixed_widgets.length - 1]).outerHeight(true) > sidebar_height + header_height + site_main_padding) { for (var i = 0; i < fixed_widgets.length; i++) { if (!jQuery(fixed_widgets[i]).hasClass('fixed-bottom')) { fixed_widgets[i].css('top', `${sidebar_height - jQuery(fixed_widgets[fixed_widgets.length - 1]).outerHeight(true)}px`); jQuery(fixed_widgets[i]).addClass('fixed-bottom'); } } } else { for (var i = 0; i < fixed_widgets.length; i++) { jQuery(fixed_widgets[i]).addClass('fixed'); jQuery(fixed_widgets[i]).removeClass('fixed-bottom'); fixed_widgets[i].css('top', `${header_height}px`); } if (fixed_widgets.length > 1) fixed_widgets[fixed_widgets.length - 1].css('marginTop', `${jQuery(fixed_widgets[0]).outerHeight(true) + 20}px`); } } else { for (var i = 0; i < fixed_widgets.length; i++) { jQuery(fixed_widgets[i]).removeClass('fixed'); fixed_widgets[i].css('top', '0px'); } if (fixed_widgets.length > 1) fixed_widgets[fixed_widgets.length - 1].css('marginTop', `20px`); } } }); } } // Article Navigation function articleSliderNavigation(element) { let articles_navigation = jQuery('.featured-articles .navigation-element'); for(let i = 0; i < articles_navigation.length; i++) { if($(articles_navigation[i]).attr('data-post_id') == $(element).attr('data-post_id')) { if(!($(articles_navigation[i]).hasClass('active'))) $(articles_navigation[i]).addClass('active'); } else $(articles_navigation[i]).removeClass('active'); } let featured_article = jQuery('.featured-articles .wp-post.large-card.featured')[0]; $(featured_article).css('background-image', $(element).children().find('.left').css('background-image')); $(featured_article).find('.area-link').replaceWith($(element).children().find('.area-link').clone()); $(featured_article).find('.title').replaceWith($(element).children().find('.title').clone()); $(featured_article).find('.meta').replaceWith($(element).children().find('.meta').clone()); } // Betting Tips Navigation function requestBettingTipsNavigation() { const url = path + 'wp-content/themes/os-sportsbook-child/ajax/betting-tips-navigation.php'; jQuery.ajax({ url: url, data: { wp_site_id: wp_site_id, wp_post_id: wp_post_id, data: filters }, success: function (betting_tips_wp_posts) { layoutBettingTipsNavigation(betting_tips_wp_posts); }, dataType: 'json' }); } function layoutBettingTipsNavigation(betting_tips_wp_posts) { const betting_tips_body = jQuery('.tips.grid'); betting_tips_body.empty(); var counter = 0; if(betting_tips_wp_posts['betting_tips_wp_posts']) for(const [key, betting_tip_wp_post] of Object.entries(betting_tips_wp_posts['betting_tips_wp_posts'])) { if(counter >= filters['pagination']['page'] && counter <= (filters['pagination']['page'] + filters['pagination']['offset'] - 1)) layoutBettingTipsNavigationRow(betting_tip_wp_post); counter++; } let total_pages; if(parseInt(counter) > filters['pagination']['offset']) total_pages = Math.ceil(parseInt(counter) / filters['pagination']['offset']); else total_pages = 1; const current_page = Math.ceil(filters['pagination']['page'] / filters['pagination']['offset']) + 1; const paginationDiv = jQuery('.pagination'); const paginationDivElement = paginationDiv[0]; const navigationIconImg = betting_tips_wp_posts['navigation_icon']; paginationDiv.empty(); layoutDatabasePagination(total_pages, current_page, navigationIconImg, paginationDivElement); } function layoutBettingTipsNavigationRow(betting_tip_wp_post) { const betting_tips_body = jQuery('.tips.grid'); const betting_tips_bodyElement = betting_tips_body[0]; const betting_tips_row = layoutElement('div', 'betting-tip vertical large-card', betting_tips_bodyElement); betting_tips_row.setAttribute("data-os_element", 'Odds'); if(betting_tip_wp_post['wp_fields']['advertiser_geographical_area']['identifier'] !== null) betting_tips_row.setAttribute('data-os_adv_id', betting_tip_wp_post['wp_fields']['advertiser_geographical_area']['identifier']); if(betting_tip_wp_post['wp_fields']['advertiser_geographical_area']['marketing_source_identifier'] !== null) betting_tips_row.setAttribute('data-os_ms', betting_tip_wp_post['wp_fields']['advertiser_geographical_area']['marketing_source_identifier']); if(betting_tip_wp_post['url']) layoutButton({url: betting_tip_wp_post['url'], title: betting_tip_wp_post['name']}, null, null, null, 'area-link', betting_tips_row); const top_data = layoutElement('div', 'top', betting_tips_row); const top_div_top = layoutElement('div', 'top', top_data); const assets = layoutElement('div', 'assets', top_div_top); const assets_left = layoutElement('div', 'left', assets); const assets_teams = layoutElement('div', 'teams', assets_left); const assets_home_team = layoutElement('div', 'home-team', assets_teams); layoutImage(betting_tip_wp_post['wp_fields']['football_fixture']['home_team']['assets']['small'], null, assets_home_team); const assets_away_team = layoutElement('div', 'away-team', assets_teams); layoutImage(betting_tip_wp_post['wp_fields']['football_fixture']['away_team']['assets']['small'], null, assets_away_team) const assets_right = layoutElement('div', 'right', assets); const assets_competitions = layoutElement('div', 'competitions', assets_right); layoutImage(betting_tip_wp_post['wp_fields']['football_fixture']['competition']['assets']['medium'], null, assets_competitions); const fixture = layoutElement('div', 'fixture', top_div_top); const fixture_left = layoutElement('div', 'left', fixture); const fixture_datetime = layoutElement('div', 'datetime', fixture_left); layoutHeading('span', betting_tip_wp_post['wp_fields']['football_fixture']['datetime'], null, fixture_datetime) const fixture_teams = layoutElement('div', 'teams', fixture_left); let home_win = betting_tip_wp_post['wp_fields']['football_fixture']['home_total_goals'] > betting_tip_wp_post['wp_fields']['football_fixture']['away_total_goals'] ? ' win' : ''; let away_win = betting_tip_wp_post['wp_fields']['football_fixture']['away_total_goals'] > betting_tip_wp_post['wp_fields']['football_fixture']['home_total_goals'] ? ' win' : ''; const fixture_home_team = layoutElement('div', 'team home' + home_win, fixture_teams); layoutHeading('span', betting_tip_wp_post['wp_fields']['football_fixture']['home_team']['name'], null, fixture_home_team); const fixture_away_team = layoutElement('div', 'team away' + away_win, fixture_teams); layoutHeading('span', betting_tip_wp_post['wp_fields']['football_fixture']['away_team']['name'], null, fixture_away_team); const fixture_right = layoutElement('div', 'right', fixture); const fixture_results = layoutElement('div', 'results', fixture_right); const results_home_team = layoutElement('div', 'team home' + home_win, fixture_results); layoutHeading('span', betting_tip_wp_post['wp_fields']['football_fixture']['home_total_goals'], null, results_home_team); const results_away_team = layoutElement('div', 'team away' + away_win, fixture_results); layoutHeading('span', betting_tip_wp_post['wp_fields']['football_fixture']['away_total_goals'], null, results_away_team); const top_div_bottom = layoutElement('div', 'bottom', top_data); layoutHeading('span', betting_tip_wp_post['strings_label'], 'label', top_div_bottom); if(betting_tip_wp_post.length > 0) layoutHeading('span', betting_tip_wp_post['wp_fields']['settings']['betting_tip_tip'], 'bold', top_div_bottom); const bottom_data = layoutElement('div', 'bottom', betting_tips_row); $(bottom_data).css('background-image', `linear-gradient(to right, ${betting_tip_wp_post['wp_fields']['advertiser_geographical_area']['primary_color']}, ${betting_tip_wp_post['wp_fields']['advertiser_geographical_area']['secondary_color']})`); const bottom_left = layoutElement('div', 'left', bottom_data); const odd = layoutElement('div', 'odd', bottom_left); layoutHeading('span', betting_tip_wp_post['strings_odd'], null, odd); layoutHeading('span', Number(betting_tip_wp_post['wp_fields']['fixture_market_odd']['odd']).toFixed(2), null, odd); const bottom_right = layoutElement('div', 'right', bottom_data); const advertiser = layoutElement('div', 'advertiser', bottom_right); layoutAdvertiserGeographicalAreaButton(betting_tip_wp_post['wp_fields']['advertiser_geographical_area']['donation_link'], null, null, betting_tip_wp_post['wp_fields']['advertiser_geographical_area']['assets']['sportsbook_logo_background'], null, advertiser, '_blank', 'nofollow', 'All', 'Card'); // HACK - to fix } // Wp Posts Navigation function requestWpPostsNavigation() { const url = path + 'wp-content/themes/os-sportsbook-child/ajax/wp-posts-navigation.php'; jQuery.ajax({ url: url, data: { wp_site_id: wp_site_id, wp_post_id: wp_post_id, data: filters }, success: function (articles_wp_posts) { layoutWpPostsNavigation(articles_wp_posts); }, dataType: 'json' }); } function layoutWpPostsNavigation(articles_wp_posts) { const articlesBody = jQuery('.articles.grid'); articlesBody.empty(); var counter = 0; if(articles_wp_posts['articles_wp_posts']) for(const [key, article_wp_post] of Object.entries(articles_wp_posts['articles_wp_posts'])) { if(counter >= filters['pagination']['page'] && counter <= (filters['pagination']['page'] + filters['pagination']['offset'] - 1)) layoutWpPostsNavigationRow(article_wp_post); counter++; } let total_pages; if(parseInt(counter) > filters['pagination']['offset']) total_pages = Math.ceil(parseInt(counter) / filters['pagination']['offset']); else total_pages = 1; const current_page = Math.ceil(filters['pagination']['page'] / filters['pagination']['offset']) + 1; const paginationDiv = jQuery('.pagination'); const paginationDivElement = paginationDiv[0]; const navigationIconImg = articles_wp_posts['navigation_icon']; paginationDiv.empty(); layoutDatabasePagination(total_pages, current_page, navigationIconImg, paginationDivElement); } function layoutWpPostsNavigationRow(article_wp_post) { const articlesBody = jQuery('.articles.grid'); const articlesBodyElement = articlesBody[0]; const articlesRow = layoutElement('div', 'wp-post vertical medium-card', articlesBodyElement); if(article_wp_post['url']) layoutButton({url: article_wp_post['url'], title: article_wp_post['name']}, null, null, null, 'area-link', articlesRow); const top_data = layoutElement('div', 'top', articlesRow); const featuredImageData = layoutElement('div', 'featured-image', top_data); $(featuredImageData).css('background-image', `url(${article_wp_post['featured_image']['url']})`); const bottomData = layoutElement('div', 'bottom', articlesRow); const titleData = layoutElement('div', 'title', bottomData); layoutButton({url: article_wp_post['url'], title: article_wp_post['name']}, 'span', article_wp_post['name'], null, null, titleData); const metaData = layoutElement('div', 'meta', bottomData); const authorData = layoutElement('div', 'author', metaData); const authorNameData = layoutElement('div', 'name', authorData); const authorPrefix = layoutHeading('span', article_wp_post['author_meta_prefix'], 'prefix', authorNameData); if(article_wp_post['wp_author']['review']) layoutButton({url: article_wp_post['wp_author']['review']['url'], title: article_wp_post['wp_author']['review']['name']}, 'span', article_wp_post['wp_author']['review']['name'], null, null, authorPrefix); else layoutHeading('span', article_wp_post['wp_author']['display_name'], 'name', authorNameData); const publishedDateData = layoutElement('div', 'published-date', metaData); const dateDivDate = layoutElement('div', null, publishedDateData); layoutHeading('span', article_wp_post['published_date'], null, dateDivDate); layoutImage(article_wp_post['published_date_icon'], null, dateDivDate) } // Pagination function handleDatabasePaginationNavigation(element) { const navigation = jQuery(element); const direction = navigation.attr('data-navigation'); const current_page = Math.ceil(filters['pagination']['page'] / filters['pagination']['offset']) + 1; if(direction == '1') filters['pagination']['page'] = current_page * filters['pagination']['offset']; else if(direction == '-1') filters['pagination']['page'] = ((current_page - 2) >= 0 ? current_page - 2 : 0) * filters['pagination']['offset']; const body = jQuery('body'); if(body.hasClass('bettingtip')) requestBettingTipsNavigation(); else requestWpPostsNavigation(); } function handleDatabasePaginationPage(element) { const pageNumberElement = jQuery(element); const pageNumber = pageNumberElement.attr('data-page'); filters['pagination']['page'] = (parseInt(pageNumber) - 1) * filters['pagination']['offset']; const body = jQuery('body'); if(body.hasClass('bettingtip')) requestBettingTipsNavigation(); else requestWpPostsNavigation(); } function layoutDatabasePagination(total_pages, current_page, icon, parent) { if(current_page === null) return; if(current_page > 1) { const navigationLeft = layoutElement('div', 'arrow left', parent); layoutImage(icon, null, navigationLeft); const navigationLeftElement = jQuery(navigationLeft); navigationLeftElement.attr('data-navigation', '-1'); navigationLeftElement.on('click', function(event) { event.stopPropagation(); event.bubbles = false; handleDatabasePaginationNavigation($(this)); }); } if(current_page > 1) { const pageNumber = layoutElement('div', 'page-number', parent); layoutHeading('span', '1', null, pageNumber); const pageNumberElement = jQuery(pageNumber); pageNumberElement.attr('data-page', '1'); pageNumberElement.on('click', function(event) { event.stopPropagation(); event.bubbles = false; handleDatabasePaginationPage($(this)); }); } if(current_page - 2 > 2) { const pageDots = layoutElement('div', 'separator', parent); layoutHeading('span', '...', null, pageDots); } if(current_page - 2 > 1) { const pageNumber = layoutElement('div', 'page-number', parent); layoutHeading('span', current_page - 2, null, pageNumber); const pageNumberElement = jQuery(pageNumber); pageNumberElement.attr('data-page', current_page - 2); pageNumberElement.on('click', function(event) { event.stopPropagation(); event.bubbles = false; handleDatabasePaginationPage($(this)); }); } if(current_page - 1 > 1) { const pageNumber = layoutElement('div', 'page-number', parent); layoutHeading('span', current_page - 1, null, pageNumber); const pageNumberElement = jQuery(pageNumber); pageNumberElement.attr('data-page', current_page - 1); pageNumberElement.on('click', function(event) { event.stopPropagation(); event.bubbles = false; handleDatabasePaginationPage($(this)); }); } const pageNumberCurrent = layoutElement('div', 'page-number current', parent); layoutHeading('span', current_page, null, pageNumberCurrent); const pageNumberCurrentElement = jQuery(pageNumberCurrent); pageNumberCurrentElement.attr('data-page', current_page); pageNumberCurrentElement.on('click', function(event) { event.stopPropagation(); event.bubbles = false; handleDatabasePaginationPage($(this)); }); if(current_page + 1 < total_pages) { const pageNumber = layoutElement('div', 'page-number', parent); layoutHeading('span', current_page + 1, null, pageNumber); const pageNumberElement = jQuery(pageNumber); pageNumberElement.attr('data-page', current_page + 1); pageNumberElement.on('click', function(event) { event.stopPropagation(); event.bubbles = false; handleDatabasePaginationPage($(this)); }); } if(current_page + 2 < total_pages) { const pageNumber = layoutElement('div', 'page-number', parent); layoutHeading('span', current_page + 2, null, pageNumber); const pageNumberElement = jQuery(pageNumber); pageNumberElement.attr('data-page', current_page + 2); pageNumberElement.on('click', function(event) { event.stopPropagation(); event.bubbles = false; handleDatabasePaginationPage($(this)); }); } if(current_page + 2 < total_pages - 1) { const pageDots = layoutElement('div', 'separator', parent); layoutHeading('span', '...', null, pageDots); } if(current_page < total_pages) { const pageNumber = layoutElement('div', 'page-number', parent); layoutHeading('span', total_pages, null, pageNumber); const pageNumberElement = jQuery(pageNumber); pageNumberElement.attr('data-page', total_pages); pageNumberElement.on('click', function(event) { event.stopPropagation(); event.bubbles = false; handleDatabasePaginationPage($(this)); }); const navigationRight = layoutElement('div', 'arrow right', parent); layoutImage(icon, null, navigationRight); const navigationRightElement = jQuery(navigationRight); navigationRightElement.attr('data-navigation', '1') navigationRightElement.on('click', function(event) { event.stopPropagation(); event.bubbles = false; handleDatabasePaginationNavigation($(this)); }); } } // Drop Cookie function dropCookie() { const url = path + 'wp-content/themes/os-sportsbook-child/ajax/drop-cookie.php'; jQuery.ajax({ url: url, data: { wp_site_id: wp_site_id, wp_post_id: wp_post_id }, success: function (data) { if(data.advertisers_geographical_areas) { data.advertisers_geographical_areas.forEach(advertiserGeographicalArea => { const bodyDiv = jQuery(document.body)[0]; const iframe = layoutElement('iframe', null, bodyDiv); iframe.src = advertiserGeographicalArea.donation_link.url; iframe.style.display = 'none'; jQuery(iframe).addClass('os-ms'); iframe.setAttribute("data-os_element", 'Main'); if(advertiserGeographicalArea.identifier !== null) iframe.setAttribute("data-os_adv_id", advertiserGeographicalArea.identifier); if(advertiserGeographicalArea.marketing_source_identifier !== null) iframe.setAttribute("data-os_ms", advertiserGeographicalArea.marketing_source_identifier); }) } }, dataType: 'json' }); } // Copy To Clipboard function copyToClipboard(element, copyURL) { const currentElement = jQuery(element); currentElement.parent().children().each(function() { jQuery(this).toggleClass('active'); }); if(!copyURL) navigator.clipboard.writeText(window.location.href); else { navigator.clipboard.writeText(copyURL); setTimeout(() => { currentElement.parent().children().each(function() { jQuery(this).toggleClass('active'); }); }, 2 * 1000); } }