// THROTTLE function throttle(fn, threshhold, scope) { threshhold || (threshhold = 250); var last, deferTimer; return function () { var context = scope || this; var now = +new Date, args = arguments; if (last && now < last + threshhold) { // hold on to it clearTimeout(deferTimer); deferTimer = setTimeout(function () { last = now; fn.apply(context, args); }, threshhold); } else { last = now; fn.apply(context, args); } }; } // SECTIONS MANIPULATION $(document).ready(function() { var sections = $('section.container'); $(window).scroll(throttle(function() { var currentPosition = $(this).scrollTop(); sections.each(function() { var $el = $(this); var offset = $el.offset(), height = $el.height(); var top = offset.top, bottom = top + height; $el.toggleClass('selected', (currentPosition >= top && currentPosition < bottom)); }); },60)); }); // MANIPULATE MENU, CREDITS AND SHARE BUTTONS $( document ).ready(function() { $(".menuToggleButton").click(function() { $("body").toggleClass("mobileMenuExpanded"); }); $(".creditsToggleButton").click(function() { $("body").toggleClass("creditsExpanded"); }); $(".socialLinks li span").click(function() { $(this).toggleClass("showThisShare"); }); }); // AUTOPLAY VIDEOS function isReadyToPlay(elem) { var docViewTop = $(window).scrollTop(); var docViewBottom = docViewTop + $(window).height(); var elemTop = $(elem).offset().top; var elemBottom = elemTop + $(elem).height(); var topFraction = 10; var bottomFraction = 250; elemTop = elemTop - topFraction; elemBottom = elemBottom - bottomFraction; //return ( (elemBottom <= docViewBottom) && (elemTop >= docViewTop) ); return ( elemBottom > docViewTop && elemTop < docViewTop ) || ( elemTop < docViewBottom && elemBottom > docViewBottom ) || ( elemTop > docViewTop && elemBottom < docViewBottom ); } $(window).scroll(throttle(function() { $('.modernizr_no-touch .jsPlay video').each(function() { var $el = $(this).attr('data-i-target'); if ($el) { $el = $($el); } else { $el = this; } if(isReadyToPlay($el)) { this.play(); } else { this.pause(); } }); },60)); $('.modernizr_no-touch .jsPlay video').on('play', function () { $('.modernizr_no-touch .jsPlay video').not($(this).get(0)).each(function () { $(this).get(0).pause(); }); }); //REQUIRE JS requirejs.config({ baseUrl: '../common/js', paths: { 'videojs': 'plugins/video-js' } }); require(['videojs'], function (videojs) { videojs.options.flash.swf = "../common/js/plugins/video-js.swf"; }); requirejs(["analytics"], function(Analytics) { var netscopeParameter = document.location.pathname; if(netscopeParameter === '/') { netscopeParameter = 'Homepage_do_site'; } var analytics = new Analytics({ googleanalytics: { id: 'UA-4263503-16', configObject: { 'cookieDomain' : 'sapo.pt' } }, sapoanalytics: { swakt: "24b385df-4bb8-4e29-a51f-defae04777fd", swasection : document.location.pathname, swasubsection : document.location.pathname, swasectiongrp : 'Impresa Publishing', swasubsectiongrp : 317344, swacontent : '', swachannel : document.title }, netscope: { id: 'pzObuT8RwBPt9Har2hEswLb.LSnwzSdM1eV554gHvI7.Q7', extraparameters: netscopeParameter } }); analytics.init(); analytics.trackPage( document.location.pathname, document.title ); }); // NEXT PAGE function nextPage() { var data, scroll, viewport, value = 0; scroll = $(window).scrollTop(); viewport = document.documentElement && document.documentElement.clientHeight || window.innerHeight; data = $('.anchorTarget').map(function(idx, el) { var $el = $(el); return { "$el": el, offset: $el.offset().top - scroll }; }).filter(function(idx, data) { return data.offset > viewport / 2; }).toArray(); data = data && data[0]; if (data && (data.offset < viewport || $(data.$el).hasClass('anchorForce'))) { value = scroll + data.offset; } else { value = scroll + (viewport * 0.9 | 0); } $("html, body").animate({ scrollTop: (value - 33) }, 'slow', 'swing'); return value; } // FIX VH AND VW FOR IOS 7 $(function() { var iOS = navigator.userAgent.match(/(iPod|iPhone|iPad)/); if(iOS){ function iosVhHeightBug() { var height = $(window).height(); setHeight100vh = $(".solidColorWrapper, .pinnedMedia .fullWidth .pictureWrapper, .pinnedMedia .fullWidth .videoWrapper, .scrollableContent .slide"); setMinHeight50vh = $(".scrollableContent"); setMinHeight100vh = $(".container .inner.viewportHeight"); setPaddingTop15vh = $(".layoutVersion_lt1024 .scrollableContent.contentInLine .listContainer"); setPaddingBottom50vh = $(".scrollableContent .listContainer"); $(setHeight100vh).css('height', height); $(setMinHeight50vh).css('min-height', (height * 0.5)); $(setMinHeight100vh).css('min-height', height); $(setPaddingTop15vh).css('padding-top', height * 0.15); $(setPaddingBottom50vh).css('padding-bottom', height * 0.5); } iosVhHeightBug(); $(window).bind('resize', iosVhHeightBug); } });