jQuery.noConflict(); // START JQUERY WRAPPER (function( $ ) { /* -------------------------------------------------------------- [] global variables -------------------------------------------------------------- */ var windowWidth, windowHeight; /* -------------------------------------------------------------- [] Mobile Detection -------------------------------------------------------------- */ var isMobile = false; //initiate as false // device detection if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|ipad|iris|kindle|Android|Silk|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(navigator.userAgent.substr(0,4))) isMobile = true; /* -------------------------------------------------------------- [] Ajax cache -------------------------------------------------------------- */ $.ajaxSetup({ cache: true }); /* -------------------------------------------------------------- [] document ready -------------------------------------------------------------- */ $(document).ready(function() { /* -------------------------------------------------------------- [1.1] Initialise -------------------------------------------------------------- */ jQuery.fn.reverse = [].reverse; /* Dartmoor Story Filter (Homepage) */ $('.dartmoor-attraction-filter li a').on('click', function(e) { e.preventDefault(); var removeActive = $(this).parent().siblings('li').children('a').removeClass('active'); $(this).addClass('active'); var filterSelector = $(this).data('dartmoorselector'); $('.filterResult').each(function() { $(this).hide().addClass('hidden'); var filterResult = $(this).data('dartmoorfilterresult'); var popularResult = $(this).data('dartmoorpopular'); if ( (filterSelector == filterResult) || (filterSelector == popularResult) ) { $(this).show().removeClass('hidden'); } }) }) /* Window print */ $('.printer').on('click', function() { window.print(); }) /* Leafleft Initilisation */ if ( $('#map').length > 0 ) { var map = new L.Map('map', {maxZoom:15, minZoom:10, center: new L.LatLng(50.572, -3.921) }); //Add the basemap - to change this source go to http://leaflet-extras.github.io/leaflet-providers/preview/ select a basemap and copy and the accompanying js to use above. var MapQuestOpen_OSM = L.tileLayer('http://otile{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpeg', { attribution: 'Tiles Courtesy of MapQuest — Map data © OpenStreetMap contributors, CC-BY-SA', subdomains: '1234' }).addTo(map); var owsrootUrl = 'http://maps.nationalparks.gov.uk/geoserver/ows'; var defaultParameters = { service : 'WFS', version : '1.0.0', request : 'GetFeature', typeName : 'dartmoor:neighbourhood_plans', outputFormat : 'text/javascript', format_options : 'callback:getJson', SrsName : 'EPSG:4326' }; var parameters = L.Util.extend(defaultParameters); var URL = owsrootUrl + L.Util.getParamString(parameters); var ajax = $.ajax({ url : URL, dataType : 'jsonp', jsonpCallback : 'getJson', contentType: 'application/json', success : function (data) { WFSLayer = L.geoJson(data, { style: function (feature) { return { weight: 2, fillColor: 'blue', fillOpacity: 0.2 }; }, onEachFeature: function (feature, layer) { popupOptions = {maxWidth: 200}; layer.bindPopup(''+feature.properties.name+'' ,popupOptions); } }); map.addLayer(WFSLayer); map.fitBounds(WFSLayer.getBounds()); } }); } /* -------------------------------------------------------------- [] Nav -------------------------------------------------------------- */ $('.menu-icon').click(function(e) { e.preventDefault(); if ( !$(this).hasClass('active') ) { $(this).addClass('active'); hideSearch(); showMenu(); } else { hideMenu(); } }) $('.search-icon').click(function() { if ( !$(this).hasClass('active') ) { $(this).addClass('active'); hideMenu() showSearch(); } else { hideSearch(); } }) function showMenu() { $('#main-menu .has-children').each(function() { if ($(this).children('.subnav-contents').length === 0) { $(this).removeClass('has-children'); } }); //show menu before it's allowed to animate $('.primary-nav-container').addClass('show') //delay animation for DOM update to show menu setTimeout(function() { $('.primary-nav-container').addClass('active'); // bind mobile nav behviours and set required styles if ($(window).width() < 1180) { if (!$('#main-menu').hasClass('mobile-nav-bound')) { $('#main-menu .has-children > .nav-name > a').click(function(e){ e.preventDefault(); }); // on click set behaviours for sub menus $('#main-menu .has-children').on('click', '> .nav-name', function(e){ displayMenu($(this)); }); $('#main-menu').addClass('mobile-nav-bound'); } // open menu panels relative to the current page setTimeout(function(){ openCurrent(); }, 30); } else { if($('#main-menu').hasClass('mobile-nav-bound')){ $('#main-menu').removeAttr('style'); $('#main-menu *').each(function(){ $(this).removeAttr('style'); }); $('#main-menu .has-children > .nav-name > a').unbind('click').bind('click'); } $('#main-menu').removeClass('mobile-nav-bound'); } },30); } function hideMenu() { $('.menu-icon').removeClass('active') $('.primary-nav-container').removeClass('active'); $('.active', $('#main-menu')).removeClass('active'); $('.menu-expanded', $('#main-menu')).removeClass('menu-expanded'); //When the menu closes, hide it, so TAB can't activate it setTimeout(function() { $('.primary-nav-container').removeClass('show'); },300 ) } function showSearch() { $('.searchbox-container').addClass('active'); } function hideSearch() { $('.search-icon').removeClass('active'); $('.searchbox-container').removeClass('active'); } // menu closes when there is a click outside of it $(document).click(function(event) { if(!$(event.target).closest('.width-page.clearfix,.top-level-background, .top-level-background-triangle, .bottom-level-background, .bottom-level-background-triangle, .keep-in-touch-container, .logo-tools, .primary-nav').length && !$(event.target).is('.width-page.clearfix,.top-level-background, .top-level-background-triangle, .bottom-level-background, .bottom-level-background-triangle, .keep-in-touch-container, .logo-tools, .primary-nav')) { hideMenu(); } }) // Close menu on resize for desktop or mobile window.addEventListener("resize", function() { // wrapped in width check to prevent menu hiding when scrolling menu // because scroll bar is added dynamically on mobile browsers if($(window).width() != windowWidth){ hideMenu(); } }, false); /* -------------------------------------------------------------- [] Nav Off-canvas -------------------------------------------------------------- */ var displayMenu = function(hasChildren){ var onlyOnePanel = true, //only allows one child to be seen at a time $siblings = $(hasChildren).parent('.has-children').siblings(), $siblingsChild = $siblings.children('.subnav-contents'), $parent = $(hasChildren).parent('.has-children'), // get first parent with has-children class $child = $parent.children('.subnav-contents'), $mainMenu = $('#main-menu'), $mainMenuHeight = $mainMenu.height(); if ($parent.hasClass('active')) { $parent.removeClass('active'); $child.removeClass('active menu-expanded'); $('.menu-expanded', $child).removeClass('menu-expanded'); $('.active', $child).removeClass('active'); } else { if (onlyOnePanel) { $siblings.removeClass('active'); $siblingsChild.removeClass('active menu-expanded'); $('.menu-expanded', $siblingsChild).removeClass('menu-expanded'); $('.active', $siblingsChild).removeClass('active'); } $parent.addClass('active'); $('.menu-current-open').removeClass('menu-current-open'); $child.addClass('active menu-expanded menu-current-open'); // Generate parent page link if(!$('> .menu-parent-link', $child).length > 0){ var $menuParentLink = $('> .nav-name > a', $parent), $newParentLink = $(''), $li = $('
').addClass('menu-parent-link'); if ($('> .nav-name', $parent).hasClass('current')){ $('> .nav-name', $parent).removeClass('current'); $li.addClass('current'); } $newParentLink.attr('href', $menuParentLink.attr('href')) .html($menuParentLink.text()); $li.append($newParentLink).prependTo($child); } // Generate links and click behaviour for menu back links if(!$('> .menu-back', $child).length > 0){ var backLink = $('').html('Back').addClass('menu-back back-link'), backBar = $('').addClass('menu-back back-bar'); $child.prepend(backLink).append(backBar); $child.css('margin-top', $mainMenu.offset().top - $child.offset().top); $child.attr('data-height', $child.height()); $('.menu-back', $child).on('click', function(e){ $child.removeClass('active menu-expanded'); $('.menu-expanded', $child).removeClass('menu-expanded'); $('.active', $child).removeClass('active'); $parent.removeClass('active'); $('.menu-current-open').removeClass('menu-current-open'); setMenuHeight($parent.closest('.subnav-contents')); }); } // Set new menu height when navigating through menu var setMenuHeight = function(matchElem){ if (matchElem.attr('data-height') > $mainMenuHeight) { $mainMenu.height(matchElem.attr('data-height')); } else { $mainMenu.height($mainMenuHeight); matchElem.height($mainMenuHeight); } }; setMenuHeight($parent.closest('.subnav-contents')); // Set menu height setMenuHeight($child); $child.parents('.subnav-contents').height($('.menu-current-open').height()); } return; }; var openCurrent = function(){ if($('#main-menu .current').length > 0){ var $current = $('#main-menu .current'), $parents = $current.parents('.has-children'); $parents.reverse().each(function(index){ var $_this = $('> .nav-name', $(this)); displayMenu($_this); }); } return; }; /* -------------------------------------------------------------- [] Left nav accordions -------------------------------------------------------------- */ $('#left-menu .has-children').each(function() { if ($(this).children('.subnav-contents').length === 0) { $(this).removeClass('has-children'); } }); $('#left-menu .has-children a').click(function(e) { e.stopImmediatePropagation(); }) $('#left-menu .has-children').on('click', '> .nav-name', function(e){ var onlyOnePanel = true, //only allows one child to be seen at a time $siblings = $(this).parent('.has-children').siblings(), $siblingsChild = $siblings.children('.subnav-contents'), $parent = $(this).parent('.has-children'), // get first parent with has-children class $child = $parent.children('.subnav-contents'); if ($parent.hasClass('active')) { $parent.removeClass('active'); $child.removeClass('active').slideUp(); } else { if (onlyOnePanel) { $siblings.removeClass('active'); $siblingsChild.removeClass('active').slideUp(); } $parent.addClass('active'); $child.addClass('active').slideDown(); } }); //Auto expand sidebar nav on active page var sideBarAnimateTimer = setInterval(function() { if ($('.sidenav').length > 0 ) { clearInterval(sideBarAnimateTimer) setTimeout(function() { $('.sidenav .nav-name').each(function() { if ($(this).hasClass('active')) { $(this).parent().addClass('active') $(this).siblings().slideDown(); } }) },2000) } },300) $('a.scrollTo').each(function() { $(this).click(function(e) { e.preventDefault(); var selector = $(this).attr('href'); var scrollSpeed = $(this).attr('data-speed'); var verticalOffset = $(this).attr('data-offset'); scrollSpeed = typeof(scrollSpeed) != 'undefined' ? parseInt(scrollSpeed) : 1000; //change the values into Int's verticalOffset = typeof(verticalOffset) != 'undefined' ? parseInt(verticalOffset) : 0; scrollToElement(selector, scrollSpeed, verticalOffset); }); }) //Can also call the scroll function from anything other than an A tag //e.g. //Selector - scrollToElement('#someSelector') //Selector and time - scrollToElement('#someSelector', 1000) //Selector, time and offset - scrollToElement('#someSelector', 1000, 150) function scrollToElement(selector, time, verticalOffset) { //check the values in case function was called from anything other than an A tag time = typeof(time) != 'undefined' ? time : 1000; verticalOffset = typeof(verticalOffset) != 'undefined' ? verticalOffset : 0; //get the height from the top of the selector we are interested in //add any offset we wish to put on top of the height offset = $(selector).offset(); offsetTop = offset.top + verticalOffset; $('html, body').animate({scrollTop: offsetTop}, time); } /* -------------------------------------------------------------- [] backtotop -------------------------------------------------------------- */ $('.backtotop').click(function(e){ e.preventDefault(); scrollToPoint(0, 1000, 0); return false; }); }); // END document.ready(); /* -------------------------------------------------------------- [] Window load -------------------------------------------------------------- */ $(window).load(function () { getWindowDimensions(); equaliseHeight(); $.fn.matchHeight._afterUpdate = function(event, groups) { equaliseHeight(); } }) /* -------------------------------------------------------------- [] END Window load -------------------------------------------------------------- */ /* -------------------------------------------------------------- [] window resize -------------------------------------------------------------- */ var windowResize = function() { //unbinds itself every time it fires $(window).one("resize orientationchange",function() { setTimeout(windowResize,100); //rebinds itself after 100ms getWindowDimensions(); equaliseHeight(); }); } windowResize(); // END window.resize(); /* -------------------------------------------------------------- [] window scroll -------------------------------------------------------------- */ var windowScroll = function() { //unbinds itself every time it fires $(window).one("scroll",function() { setTimeout(windowScroll,100); //rebinds itself after 100ms }); } windowScroll(); /* -------------------------------------------------------------- [] functions -------------------------------------------------------------- */ /* -------------------------------------------------------------- [] Body Widths -------------------------------------------------------------- */ function getWindowDimensions() { windowWidth = viewportSize.getWidth(); //get the true viewport width windowHeight = viewportSize.getHeight(); //get the true viewport width return {'windowWidth':windowWidth, 'windowHeight':windowHeight} } function equaliseHeight() { if ( windowWidth >= 600 ) { $('.js-equaliseHeight').matchHeight({ byRow: true }); $('.js-equaliseHeightsBottom').matchHeight({ byRow: true }); } else { $('.js-equaliseHeight').matchHeight('remove'); $('.js-equaliseHeightsBottom').matchHeight('remove'); } } })(jQuery); // FINISH JQUERY WRAPPER // slider function trackLocation(e) { var rect = videoContainer.getBoundingClientRect(), position = ((e.pageX - rect.left) / videoContainer.offsetWidth)*100; if (position <= 100) { videoClipper.style.width = position+"%"; clippedVideo.style.width = ((100/position)*100)+"%"; clippedVideo.style.zIndex = 3; } } var videoContainer = document.getElementById("video-compare-container"), videoClipper = document.getElementById("video-clipper"); if(videoClipper){ clippedVideo = videoClipper.getElementsByTagName("video")[0]; } if(videoContainer){ videoContainer.addEventListener( "mousemove", trackLocation, false); videoContainer.addEventListener("touchstart",trackLocation,false); videoContainer.addEventListener("touchmove",trackLocation,false); }