(function ($) { 'use strict'; $(document).foundation(); var windowWidth = $(window).width(); // debulked onresize handler function on_resize(c, t) { window.onresize = function () { clearTimeout(t); t = setTimeout(c, 100); }; return c; } on_resize(function () { windowWidth = $(window).width(); }); /** * Resize elements to full browser height */ var $singleGalleryEl = $('.hero--gallery'), $vidWrapper = $('.hero__video-wrapper'), $vidFrameEl = $vidWrapper.find('iframe'), $headerEl; function cn_resize_el_height() { $headerEl = $('header.header'); var windowHeight = $(window).height(), headerElHeight = $headerEl.height(); // Force the gallery to 90% of the visible height so that the row of buttons beneath can be seen $singleGalleryEl.each(function () { $(this).height(( windowHeight / 10 ) * 9 - headerElHeight); }); if($vidWrapper.length>0) { var w = $vidWrapper.width(), h = $vidWrapper.height(), r1 = (w/h), r2 = (16/9), nW = '100%', nH = '100%'; // r2==1.7777 if(r1>r2) // low height, wide width { nW = '100%'; nH = h * r2; } else { nW = h * r2; nH = '100%'; } $vidFrameEl.css({minWidth:nW,minHeight:nH}); } } cn_resize_el_height(); /** * Homepage video backgrounds */ var $heroVideo = $('.hero--video'), $videoShort = $heroVideo.find('.hero__video--short'); if ($videoShort.length > 0) { // this uses very old vimeo frogaloop.js var $player = $f($videoShort.find('iframe')[0]); $player.api('setVolume', '0'); //console.log($player); }; /** * Col gallery fullscreen toggle * Also loads in the larger background images */ var $colDoubleGallery = $('.column-double__gallery'); $colDoubleGallery.find('button.gallery__fullscreen').on('click', function () { var $this = $(this), $parent = $this.parent(); if ($parent.hasClass('is-fullscreen')) { $parent.removeClass('is-fullscreen'); } else { $parent.addClass('is-fullscreen'); $parent.find('.gallery-cell').each(function () { var $thisCell = $(this); // Switch in larger background image $thisCell.css('background-image', "url('" + $thisCell.data('fullscreen') + "')"); $thisCell.removeAttr('data-fullscreen'); // Remove the old redundant low quality image $thisCell.children('.gallery-img').remove(); }); } }); /** * Accordion */ var $accordion = $('.accordion'); $accordion.on('click', '.accordion__title__toggle', function (e) { e.preventDefault(); var $this = $(this), $parent = $this.closest('.accordion__row'); $parent.toggleClass('is-active'); }); /** * Scroll to element */ jQuery.fn.extend({ scrollToMe: function () { var x = jQuery(this).offset().top - 100; jQuery('html,body').animate({scrollTop: x}, 500); } }); var $scrollElement = $('.scroll-to, a.hero__button[href="#body-content"]'); $scrollElement.on('click', function (e) { e.preventDefault(); $($(this).attr('href')).scrollToMe(); }); /** * Offcanvas nav functions */ var $body = $('body'), $offcanvas = $('#offcanvas'), $offcanvasOpen = $('#toggle-nav'), $offcanvasClose = $('#offcanvas-close'); $offcanvasOpen.on('click', function () { $body.addClass('offcanvas-is-visible'); $offcanvas.addClass('is-active'); }); $offcanvasClose.on('click', function () { $body.removeClass('offcanvas-is-visible'); $offcanvas.removeClass('is-active'); }); /** * Language switcher additions */ var $languageSwitcher = $('.language-switcher'); $languageSwitcher.hover( function () { $(this).removeClass('not-active'); }, function () { $(this).addClass('not-active'); } ); /** * Taxonomy switching for post list templates */ var $taxonomySwitcher = $('#post-taxonomy-select'); $taxonomySwitcher.on('change', '#post-taxonomy', function () { $taxonomySwitcher.submit(); }); /** * People listing template, * Show all people on page * * TODO - use AJAX for this */ var $showPeopleToggle = $('#people-toggle'), $boxLinksHidden = $('.box-links__box.not-active'); $showPeopleToggle.on('click', function () { $(this).remove(); $boxLinksHidden.removeClass('not-active'); }); /** * Create a fake back button that just mirrors the browser back button... */ var $historyBackBtn = $('a.history-back'); $historyBackBtn.on('click', function (e) { e.preventDefault(); history.go(-1); }); /** * Trigger header search form */ var $headerLogo = $('#logo'), $headerSearchForm = $('.header__searchform'), $headerSearchTrigger = $headerSearchForm.find('.searchform__overlay'); $headerLogo.on('click', function () { $body.removeClass('header-searchform--active'); }); $headerSearchTrigger.on('click', function () { $body.addClass('header-searchform--active'); }); /** * Booking bar, datepicker setup */ var bookingbarDate = $('.booking-bar .datepicker'); bookingbarDate.pickadate({ min: true, formatSubmit: 'yyyy-mm-dd', hiddenName: true }); if (bookingbarDate.length) { bookingbarDate.pickadate('picker').set('select', bookingbarDate.data('date')); } /** * Single post share box toggle */ var $shareToggle = $('#share-btn'), $shareBox = $('.share-box'); $shareToggle.on('click', function () { $(this).toggleClass('is-active'); $shareBox.toggleClass('hide'); }); var $mainNavHasChildren = $('li.menu__item--has-children'); /** * Setup doubletaptogo on main navigation * Only target li's with children */ $mainNavHasChildren.doubleTapToGo(); /** * Setup hoverIntent on main navigation */ function mainNavAddClass() { $(this).addClass('is-active'); } function mainNavRemoveClass() { $(this).removeClass('is-active'); } $mainNavHasChildren.hoverIntent({over: mainNavAddClass, out: mainNavRemoveClass, timeout: 150 }); // De-bounce on resize on_resize(function () { cn_resize_el_height(); }); /** * Search and replace the body of the document for a specific string (in this case the phone number) and replace * @param {object} json jSON object from 3rd party or cookie */ function cn_searchreplace_body_phone(json) { if (json !== 'undefined' && json !== 'United Kingdom') { $body.find('.tel-replace').each(function () { $(this).html($(this).html().replace(/\(?01225\)? 742777/g, '+44 (0) 1225 742 777')); }); } } $(window).load(function () { /** * If the browser is IE8 * Hide the WoW animations */ if ($('html').hasClass('ie8')) { $('.wow').removeClass('wow'); $('.fadeIn').removeClass('fadeIn'); $('.fadeInUp').removeClass('fadeInUp'); } /** * Check for a cookie for the location of the user * * If we can't find one, query Telize for new location information, * otherwise use the information in the cookie */ var cookieLocation = localStorage['telize-location']; if (cookieLocation !== 'undefined' && cookieLocation !== 'United Kingdom') { cn_searchreplace_body_phone(cookieLocation); } else { /** * Ajax function * * Get the current Users country information * If they are not within the UK - replace start of phone numbers with +44 */ $.getJSON("https://www.telize.com/geoip?callback=?", function (json) { cn_searchreplace_body_phone(json.country); localStorage['telize-location'] = json.country; } ); } /** * Set custom lazyloading on images * These will be set after the page has loaded * * Used for gallery */ var $cnLazyLoad = $('img.cn-lazyload'); $cnLazyLoad.each(function () { var $this = $(this); $this.attr('src', $this.data('src')); $this.removeAttr('data-src'); }); /** * Set custom background lazyloading on elements */ var $cnBGLazyLoad = $('[data-lazy-bg]'); $cnBGLazyLoad.each(function () { var $this = $(this), img = $this.data('lazy-bg'), el = $(''); el.load(function(){ $this.css('background-image', "url('" + img + "')"); $this.removeAttr('data-lazy-bg'); $this.removeClass('lazyload').addClass('lazyloaded'); }).attr('src',img); }); /** * Show the homepage autoplay video after the page has finished loading. Should give enough time to setup the video in the background * Now replaced by listening for playback */ //if($videoShort.closest('.hero--video-notmob').length==1) $videoShort.addClass('is-active'); var $heroGalleryData; /** * Show the hero slider 2 secs after we set the video to play. Hoping this is enough time for some of the video to load and hide the gallery */ // setTimeout(function () { // $heroVideo.addClass('video--has-loaded'); // $heroGalleryData = Flickity.data($heroVideo.find('.js-flickity')[0]); // $heroGalleryData.deactivatePlayer(); // }, 2000); /** * Hide the player after 16.5secs - video is 18secs long * There is a variance of time depending on the connection though... */ // setTimeout(function(){ // $videoShort.addClass('has-ended'); // // $heroGalleryData.activatePlayer(); // }, 16500); }); var elements = $('.sticky'); // sticky polyfill, currently only for booking bar Stickyfill.add(elements); // Select all links with hashes $('a[href*="#"]') // Remove links that don't actually link to anything .not('[href="#"]') .not('[href="#0"]') .click(function(event) { // On-page links if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) { if($(this).hasClass('noslow')) return true; // Figure out element to scroll to var target = $(this.hash); target = target.length ? target : $('[name=' + this.hash.slice(1) + ']'); // Does a scroll target exist? if (target.length) { // Only prevent default if animation is actually gonna happen event.preventDefault(); $('html, body').animate({ scrollTop: target.offset().top }, 1000, function() { // Callback after animation Must change focus! var $target = $(target); $target.focus(); if ($target.is(":focus")) { // Checking if the target was focused return false; } else { $target.attr('tabindex','-1'); // Adding tabindex for elements not focusable $target.focus(); // Set focus again } }); } } }); $('section.tabs').each(function() { var tabLinks = $(this).find('.tabs__nav__link'), tabBodies = $(this).find('.tabs__body__blocks'); tabLinks.on('click', function() { tabLinks.removeClass('tabs__nav__link--active'); tabBodies.removeClass('tabs__body__blocks--active'); var link = $(this), target = link.attr('href'); link.addClass('tabs__nav__link--active'); window.console.log('Tab block link'); if(tabBodies.length>0) tabBodies.filter(target).addClass('tabs__body__blocks--active'); return false; }); }); $('.galleryb').each(function(gallId) { var galleryBModal = null, galleryBValid = false, galleryBFlick = false; $(this).find('.galleryb__cont .explorelink').each(function(i,el){$(el).data('index',i); }); // Used for both the Tabs block, and the GalleryB block var tabLinks = $(this).find('.tabs__nav__link'), tabBodies = $(this).find('.tabs__body__blocks'); tabLinks.on('click', function() { tabLinks.removeClass('tabs__nav__link--active'); tabBodies.removeClass('tabs__body__blocks--active'); var link = $(this), target = link.attr('href'); link.addClass('tabs__nav__link--active'); window.console.log('Tab gallery link'); if(tabBodies.length>0) tabBodies.filter(target).addClass('tabs__body__blocks--active'); var galB = link.closest('.galleryb'); if(galB.length>0) { var galBImgs = galB.find('.galleryb__cont .explorelink'), sect = link.data().sect; galBImgs.removeClass('hidden'); galleryBValid = false; // trigger rebuild if(sect!=='*') { var hiding = galBImgs.not('.'+sect); if(sect==="video") hiding = galBImgs.not(':has(>.carousel-cell-video--main)'); hiding.addClass('hidden'); } galBImgs.not('.hidden').each(function(i,el){$(el).data('index',i);}); } return false; }); tabLinks.filter('.tabs__nav__link--active').trigger('click'); $(this).find('.galleryb__cont .explorelink').click(function() { var didFlick = false, link = $(this), index = link.data().index; if(!galleryBModal) { galleryBModal = '
'; $(document.body).append(galleryBModal); galleryBModal = $('#GalleryBModal.galleryBModal_'+gallId); galleryBModal.find('.galleryB--close').click(function(){galleryBModal.fadeOut().hide(); return false; }); }; if(!galleryBValid) { var gInner = galleryBModal.find('.main-carousel'); if(galleryBFlick) gInner.flickity('destroy'); var galBImgs = $(this).closest('.galleryb').find('.galleryb__cont .explorelink').not('.hidden'); gInner.html(''); galBImgs.each(function(){gInner.append($(this).children().eq(0).clone());}); gInner.children().wrap(''); gInner.flickity({contain:false, imagesLoaded:true, cellAlign:'center', cellSelector: '.carousel-cell', setGallerySize: false, percentPosition:false, initialIndex:index }); galleryBValid = true; galleryBFlick = true; didFlick = true; }; galleryBModal.fadeIn().show(); var flick = galleryBModal.find('.main-carousel') if(!didFlick) flick.flickity('select',index,true,true); flick.flickity('resize'); return false; }) }); // Add parallax to quote slider var qSlider = $('.quoteslide__slides'); if(qSlider.length) { var $qFlick = qSlider.flickity( {"wrapAround":true, "pageDots":false, "autoPlay":5000, "prevNextButtons":false, "draggable":false, "selectedAttraction":0.0182, }); }; //window.setInterval(function(){ // $('.telLink a').text($('.hero__video').css('max-height')); // var ifr = $('.hero__video iframe'), c = ifr.css; // $('.bookLink a').text('h='+ifr.css('min-height')+',w='+ifr.css('min-width')); // },200); window.console.log('Opening'); })(jQuery);