/** * File skip-link-focus-fix.js. * * Helps with accessibility for keyboard only users. * * Learn more: https://git.io/vWdr2 */ ( function() { var isWebkit = navigator.userAgent.toLowerCase().indexOf( 'webkit' ) > -1, isOpera = navigator.userAgent.toLowerCase().indexOf( 'opera' ) > -1, isIe = navigator.userAgent.toLowerCase().indexOf( 'msie' ) > -1; if ( ( isWebkit || isOpera || isIe ) && document.getElementById && window.addEventListener ) { window.addEventListener( 'hashchange', function() { var id = location.hash.substring( 1 ), element; if ( ! ( /^[A-z0-9_-]+$/.test( id ) ) ) { return; } element = document.getElementById( id ); if ( element ) { if ( ! ( /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) ) ) { element.tabIndex = -1; } element.focus(); } }, false ); } })(); ( function ( $ ) { // Defs var bgColor = $('body').css('background-color'); /** * Get Viewport Dimensions * returns object with viewport dimensions to match css in width and height properties * ( source: http://andylangton.co.uk/blog/development/get-viewport-size-width-and-height-javascript ) */ function updateViewportDimensions() { var w=window,d=document,e=d.documentElement,g=d.getElementsByTagName('body')[0],x=w.innerWidth||e.clientWidth||g.clientWidth,y=w.innerHeight||e.clientHeight||g.clientHeight; return { width:x,height:y }; } var viewport = updateViewportDimensions(); /** * Throttle Resize-triggered Events * Wrap your actions in this function to throttle the frequency of firing them off, for better performance, esp. on mobile. * ( source: http://stackoverflow.com/questions/2854407/javascript-jquery-window-resize-how-to-fire-after-the-resize-is-completed ) */ var waitForFinalEvent = (function () { var timers = {}; return function (callback, ms, uniqueId) { if (!uniqueId) { uniqueId = "Don't call this twice without a uniqueId"; } if (timers[uniqueId]) { clearTimeout (timers[uniqueId]); } timers[uniqueId] = setTimeout(callback, ms); }; })(); var timeToWaitForLast = 100; /** * Resize the video proportionally to fit the screen while remaining centered */ function wallpapers_videoRatio() { if( typeof videoDefs !== 'undefined' ) { var ratio = videoDefs.aspectRatio, dimension = ratio.split('-'), dw = dimension[0], dh = dimension[1], svar = dw / dh, $fsvideo = $('.wp-video'), $window = $(window); if ($window.width() / $window.height() >= svar) { $fsvideo.css({ 'height': $window.width() / svar, 'width': $window.width(), 'margin-left': '0', 'margin-top': (($window.height() - $fsvideo.height()) / 2) }); } else { $fsvideo.css({ 'height': $window.height(), 'width': $window.height() * svar, 'margin-top': '0', 'margin-left': (($window.width() - $fsvideo.width()) / 2) }); } } } /** * Setup the Gallery slider */ function wallpapers_exhibitions_archive_gallery() { $('[data-toggle="gallery"]').on('click', function(e) { e.preventDefault(); var closer = $(''), $this = $(this), items = $this.data('gallery'), flickityOptions = { cellSelector: '.flickity-item', cellAlign: 'left', contain: true, imagesLoaded: true, pageDots: false, setGallerySize: false }; $('
').appendTo('body'); $.each(items, function() { $.each(this, function(gallery, image) { var html = ''; $('.flickity-gallery-carousel').append(html); }); }); $('.flickity-gallery-carousel').flickity(flickityOptions).focus().append(closer).css('background', bgColor); // Fade In $('.flickity-item').hide().fadeIn(); // Prevent Scroll $('body').css('overflow', 'hidden'); // Animatie the close icon closer.addClass('is-active'); }); $('body').on('click', '[data-dismiss="gallery"]', function(e) { e.preventDefault(); $('.flickity-gallery-carousel').remove(); $('body').css('overflow', ''); }); } // Toggle Collapse function wallpapers_toggleCollapse() { $('[data-toggle="collapse"]').click( function(e) { e.preventDefault(); var $this = $(this), href = $this.attr('href'), $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))); // strip for ie7 $this.toggleClass("is-active").attr('aria-expanded', function (i, attr) { return attr === 'true' ? 'false' : 'true'; }); $target.toggleClass('hidden visible').attr('aria-expanded', function (i, attr) { return attr === 'true' ? 'false' : 'true'; }); $('body').attr('style', function (i, attr) { return attr === 'overflow: hidden' ? 'overflow: auto' : 'overflow: hidden'; }); }); } // Layout Hacks function wallpapers_layout_hacks() { $('.single-exhibitions .nav-links div').hover( function(){ $(this).siblings().toggleClass('dim-opacity'); } ); // Set the background color of the menu overlay $('.overlay-navigation').css('background', bgColor); // Set the background color of the hover overlay var bgFade = bgColor.replace('rgb', 'rgba').replace(')', ',.5)'); $('.hover-cover').css('background-image', 'linear-gradient(to bottom, '+ bgFade +' 0%,' + bgColor + '66.666%)'); } // Sticky Headers function wallpapers_stickyTitles(stickies) { this.load = function() { stickies.each(function(){ var thisSticky = $(this).wrap(''); thisSticky.parent().height(thisSticky.outerHeight()); $.data(thisSticky[0], 'pos', thisSticky.offset().top); }); }; this.scroll = function() { stickies.each(function(i){ var thisSticky = $(this), nextSticky = stickies.eq(i+1), prevSticky = stickies.eq(i-1), pos = $.data(thisSticky[0], 'pos'), offsetTop = 20; if (pos <= $(window).scrollTop() + offsetTop) { //offset thisSticky.addClass("fixed"); if ( nextSticky.length > 0 && thisSticky.offset().top >= $.data(nextSticky[0], 'pos') - thisSticky.outerHeight() ) { thisSticky.addClass("absolute").css("top", $.data(nextSticky[0], 'pos') - thisSticky.outerHeight()); } } else { thisSticky.removeClass("fixed"); if ( prevSticky.length > 0 && $(window).scrollTop() <= $.data(thisSticky[0], 'pos') - prevSticky.outerHeight() - offsetTop ) { //offset prevSticky.removeClass("absolute").removeAttr("style"); } } }); }; } function wallapers_do_stickies() { viewport = updateViewportDimensions(); if ( viewport.width < 768 ) { return; } else { var newStickies = new wallpapers_stickyTitles($(".entry-header-sticky")); newStickies.load(); $(window).on("scroll", function() { newStickies.scroll(); }); } } /** * Prepare for launch! */ function wallpapers_resize() { wallpapers_videoRatio(); //wallapers_do_stickies(); } function wallpapers_launch() { $(window).resize(wallpapers_videoRatio).trigger('resize'); wallpapers_videoRatio(); wallpapers_toggleCollapse(); wallpapers_layout_hacks(); wallpapers_exhibitions_archive_gallery(); //wallapers_do_stickies(); } $(document).ready(function() { wallpapers_launch(); $(window).resize(function () { waitForFinalEvent(function () { wallpapers_resize(); }, timeToWaitForLast, "screen resize"); }); // if Infinite Scroll, fire again when new posts are loaded $( document.body ).on( 'post-load', function() { wallpapers_layout_hacks(); } ); }); })( jQuery );