jQuery(document).ready(function($) { var viewportWidth = window.innerWidth || document.documentElement.clientWidth; var viewportHeight = window.innerHeight || document.documentElement.clientHeight; // sort retailer list alphabeticallys var select2_alphabetical_sorter = function(data) { return data.sort(function(a,b){ a = a.text.toLowerCase(); b = b.text.toLowerCase(); if(a > b) { return 1; } else if (a < b) { return -1; } return 0; }); }; // faq section question / answer accordion toggle $('.questions_wrapper ul li .question').click(function (e) { e.preventDefault(); // $(this).closest('ul').find('li .answer').toggle(); $(this).closest('li').find('> .answer').slideToggle(300); }); // scroll to anchor link on click $('a.link_scrollto[href^="#"]').click(function(e){ e.preventDefault(); var link_anchor = $(this).attr('href'); // scroll to anchor link if section ID is visible and exists if($(''+link_anchor+':visible').length > 0) { $('html, body').animate({ scrollTop: $(''+link_anchor+'').offset().top + 0 }, 300); } // scroll to anchor link tab wrapper if hidden else { var current_tab = $(''+link_anchor+'').closest('.tab_wrapper'); // close all other tabs $('.tab_wrapper').removeClass('open'); $('.tab_wrapper .tab_content').slideUp(300); current_tab.addClass('open'); current_tab.find('.tab_content').slideDown(300); setTimeout(function() { $('html, body').animate({ scrollTop: current_tab.offset().top - 10 }, 300); }, 300); } }); // Devices without touch events $('html.no-touchevents .tile').hover(function() { $(this).addClass('hover'); }, function() { $(this).removeClass('hover'); } ); $('html.no-touchevents #product_before_after .photo_column .photo_column_inner').hover(function(e) { e.stopPropagation(); // e.preventDefault(); // $(this).toggleClass('hover'); if ($(this).hasClass('hover')) { $(this).removeClass('hover'); } else { $(this).addClass('hover'); } }); // Devices with touch events $('html.touchevents #product_before_after .photo_column .photo_column_inner').click(function(e) { e.stopPropagation(); // e.preventDefault(); // $(this).toggleClass('hover'); if ($(this).hasClass('hover')) { $(this).removeClass('hover'); } else { $(this).addClass('hover'); } }); $(window).on('load', function(){ var site_header_height = $('#site_header').height(); $('#page_product').css({'padding-top':''+site_header_height+'px'}); }); $(window).on('resize', function(){ var win = $(this); //this = window var site_header_height = $('#site_header').height(); $('#page_product').css({'padding-top':''+site_header_height+'px'}); // if (win.width() <= 767) { // start_product_carousel(); // } else { // stop_product_carousel(); // } }); // add detailed title to each logo link $('.tab_headline h3').each(function(){ var headline_copy = $(this).text(); $(this).closest('.tab_headline').attr('data-detailed-title', 'Tab - '+headline_copy+'') }); // add detailed title to each logo link $('.logo_column img').each(function(){ var logo_retailer_name = $(this).attr('alt'); $(this).closest('.logo_wrapper').attr('data-detailed-title', 'Shop - '+logo_retailer_name+'') }); // mobile accordion tabs $('.tab_wrapper .tab_headline').click(function (e) { e.preventDefault(); var current_tab = $(this).closest('.tab_wrapper'); if ($(this).closest('.tab_wrapper').hasClass('open')) { $(this).closest('.tab_wrapper').removeClass('open'); $(this).closest('.tab_wrapper').find('.tab_content').slideUp(300); } else { // close all other tabs $('.tab_wrapper').removeClass('open'); $('.tab_wrapper .tab_content').slideUp(300); $(this).closest('.tab_wrapper').addClass('open'); $(this).closest('.tab_wrapper').find('.tab_content').slideDown(300); setTimeout(function() { $('html, body').animate({ scrollTop: current_tab.offset().top - 10 }, 300); }, 300); } }) .keydown(function (e) { // Check if the pressed key is Enter (key code 13) if (e.which === 13 || e.key === 'Enter') { // Prevent default Enter key behavior e.preventDefault(); // Trigger the same functionality as the click event $(this).trigger('click'); } }); // $(window).on('resize', function(){ // var win = $(this); //this = window // if (win.width() <= 767) { // } else { // } // }); $('#toggle-discontinued-products').click(function(e){ let container = document.getElementById('discontinued-products'); container.classList.toggle('hide'); if (container.classList.contains('hide')) { this.innerHTML = 'Show all DIUREX products'; } else { this.innerHTML = 'Hide DIUREX products'; } }); // add classes to all shop links for tracking $('\ a.logo_wrapper, \ #site_header .col_buttons .btn, \ .sticky_shop_now, \ .retailer_form input[type="submit"], \ .link_scrollto, \ .tab_headline, \ .cta_wrapper .btn, \ .logo_column .logo_wrapper \ ').each(function () { $(this).addClass('tracking_shop_link'); }); });