/**************************************** * Add function to the jQuery * Calls the positionSliderArrows() funtion ****************************************/ $.fn.positionSliderArrows = function() { window.positionSliderArrows(); return; }; /**************************************** * jquery.wait - insert simple delays into your jquery method chains * @author Matthew Lee matt@madleedesign.com * https://github.com/madbook/jquery.wait ****************************************/ (function($) { function jQueryDummy($real, delay, _fncQueue) { // A Fake jQuery-like object that allows us to resolve the entire jQuery // method chain, pause, and resume execution later. var dummy = this; this._fncQueue = (typeof _fncQueue === 'undefined') ? [] : _fncQueue; this._delayCompleted = false; this._$real = $real; if (typeof delay === 'number' && delay >= 0 && delay < Infinity) this.timeoutKey = window.setTimeout(function() { dummy._performDummyQueueActions(); }, delay); else if (delay !== null && typeof delay === 'object' && typeof delay.promise === 'function') delay.then(function() { dummy._performDummyQueueActions(); }); else if (typeof delay === 'string') $real.one(delay, function() { dummy._performDummyQueueActions(); }); else return $real; } jQueryDummy.prototype._addToQueue = function(fnc, arg) { // When dummy functions are called, the name of the function and // arguments are put into a queue to execute later this._fncQueue.unshift({ fnc: fnc, arg: arg }); if (this._delayCompleted) return this._performDummyQueueActions(); else return this; }; jQueryDummy.prototype._performDummyQueueActions = function() { // Start executing queued actions. If another `wait` is encountered, // pass the remaining stack to a new jQueryDummy this._delayCompleted = true; var next; while (this._fncQueue.length > 0) { next = this._fncQueue.pop(); if (next.fnc === 'wait') { next.arg.push(this._fncQueue); return this._$real = this._$real[next.fnc].apply(this._$real, next.arg); } this._$real = this._$real[next.fnc].apply(this._$real, next.arg); } return this; }; $.fn.wait = function(delay, _queue) { // Creates dummy object that dequeues after a times delay OR promise return new jQueryDummy(this, delay, _queue); }; for (var fnc in $.fn) { // Add shadow methods for all jQuery methods in existence. Will not // shadow methods added to jQuery _after_ this! // skip non-function properties or properties of Object.prototype if (typeof $.fn[fnc] !== 'function' || !$.fn.hasOwnProperty(fnc)) continue; jQueryDummy.prototype[fnc] = (function(fnc) { return function() { var arg = Array.prototype.slice.call(arguments); return this._addToQueue(fnc, arg); }; })(fnc); } })(jQuery); /**************************************** Element Onscreen Visibility This is a jQuery plugin which allows us to quickly check if an element is within the browsers visual viewport, regardless of the scroll position. If a user can see this element, the function will return true. https://github.com/customd/jquery-visible ****************************************/ (function($){ /** * Copyright 2012, Digital Fusion * Licensed under the MIT license. * http://teamdf.com/jquery-plugins/license/ * * @author Sam Sehnert * @desc A small plugin that checks whether elements are within * the user visible viewport of a web browser. * can accounts for vertical position, horizontal, or both */ var $w=$(window); $.fn.visible = function(partial,hidden,direction,container){ if (this.length < 1) return; // Set direction default to 'both'. direction = direction || 'both'; var $t = this.length > 1 ? this.eq(0) : this, isContained = typeof container !== 'undefined' && container !== null, $c = isContained ? $(container) : $w, wPosition = isContained ? $c.position() : 0, t = $t.get(0), vpWidth = $c.outerWidth(), vpHeight = $c.outerHeight(), clientSize = hidden === true ? t.offsetWidth * t.offsetHeight : true; if (typeof t.getBoundingClientRect === 'function'){ // Use this native browser method, if available. var rec = t.getBoundingClientRect(), tViz = isContained ? rec.top - wPosition.top >= 0 && rec.top < vpHeight + wPosition.top : rec.top >= 0 && rec.top < vpHeight, bViz = isContained ? rec.bottom - wPosition.top > 0 && rec.bottom <= vpHeight + wPosition.top : rec.bottom > 0 && rec.bottom <= vpHeight, lViz = isContained ? rec.left - wPosition.left >= 0 && rec.left < vpWidth + wPosition.left : rec.left >= 0 && rec.left < vpWidth, rViz = isContained ? rec.right - wPosition.left > 0 && rec.right < vpWidth + wPosition.left : rec.right > 0 && rec.right <= vpWidth, vVisible = partial ? tViz || bViz : tViz && bViz, hVisible = partial ? lViz || rViz : lViz && rViz, vVisible = (rec.top < 0 && rec.bottom > vpHeight) ? true : vVisible, hVisible = (rec.left < 0 && rec.right > vpWidth) ? true : hVisible; if(direction === 'both') return clientSize && vVisible && hVisible; else if(direction === 'vertical') return clientSize && vVisible; else if(direction === 'horizontal') return clientSize && hVisible; } else { var viewTop = isContained ? 0 : wPosition, viewBottom = viewTop + vpHeight, viewLeft = $c.scrollLeft(), viewRight = viewLeft + vpWidth, position = $t.position(), _top = position.top, _bottom = _top + $t.height(), _left = position.left, _right = _left + $t.width(), compareTop = partial === true ? _bottom : _top, compareBottom = partial === true ? _top : _bottom, compareLeft = partial === true ? _right : _left, compareRight = partial === true ? _left : _right; if(direction === 'both') return !!clientSize && ((compareBottom <= viewBottom) && (compareTop >= viewTop)) && ((compareRight <= viewRight) && (compareLeft >= viewLeft)); else if(direction === 'vertical') return !!clientSize && ((compareBottom <= viewBottom) && (compareTop >= viewTop)); else if(direction === 'horizontal') return !!clientSize && ((compareRight <= viewRight) && (compareLeft >= viewLeft)); } }; })(jQuery); /**************************************** * Slider > ****************************************/ /* Slider objects array */ var sliderObjects = []; /* Slider plus divs */ function plusDivs(obj, n) { var parentDiv = $(obj).parent(); var matchedDiv; $.each(sliderObjects, function(i, item) { if ($(parentDiv[0]).attr('id') == $(item).attr('id')) { matchedDiv = item; return false; } }); matchedDiv.slideIndex = matchedDiv.slideIndex + n; showDivs(matchedDiv, matchedDiv.slideIndex); } /*Slider create sliders*/ function createSliderObjects() { var sliderDivs = $('.slider'); $.each(sliderDivs, function(i, item) { var obj = {}; obj.id = $(item).attr('id'); obj.divContent = item; obj.slideIndex = 1; obj.slideContents = $(item).find('.mySlides'); sliderObjects.push(obj); showDivs(obj, 1); }); } /*Slider showDivs*/ function showDivs(divObject, n) { var i; if (n > divObject.slideContents.length) { divObject.slideIndex = 1 } if (n < 1) { divObject.slideIndex = divObject.slideContents.length } for (i = 0; i < divObject.slideContents.length; i++) { $(divObject.slideContents[i]).css('display', 'none'); } // waits 100 miliseconds until call the positionSliderArrows() function $(divObject.slideContents[divObject.slideIndex - 1]).css('display', 'block').wait(100).positionSliderArrows(); // redundance function call positionSliderArrows(); } function positionSliderArrows() { $('.slider .mySlides img').each(function() { $(this).load(function() { positionSliderArrowsElements(); }); }); positionSliderArrowsElements(); } function positionSliderArrowsElements() { $.each($('.slider .mySlides'), function() { if ($(this).css('display') !== 'none') { $(this).parent().children('.button-display-left').css('top', ($('img', this).height() / 2) - ($(this).parent().children('.button-display-left').height() / 2) - (0) + 'px'); $(this).parent().children('.button-display-right').css('top', ($('img', this).height() / 2) - ($(this).parent().children('.button-display-right').height() / 2) - (0) + 'px'); } else {} }); } /* < Slider */ /**************************************** * creditsToggleFunction > ****************************************/ function creditsToggleFunction() { var x = document.getElementById("modal-box"); var credits = document.getElementById("creditsButton"); if (x.style.display === "block") { x.style.display = "none"; credits.style.color = "#808080"; } else { x.style.display = "block"; /*credits.style.color = "#FAA61A";*/ credits.style.color = ""; } } /* < creditsToggleFunction */ /**************************************** * toggleFunction > ****************************************/ function toggleFunction() { var x = document.getElementById("myMenuTwo"); var toggle = document.getElementById("toggleButton"); var y = document.getElementById("myBody"); /*console.log('CLASS NAME: '+x.className);*/ if (x.className.trim() === "menu-two") { x.className = x.className.trim() + " responsive"; y.className = y.className.trim() + " responsiveIsOpen"; toggle.style.color = "#ffcb07"; } else if (x.className.trim() === "menu-two responsive") { x.className = "menu-two"; y.className = "menu-two"; /*toggle.style.color = "#808080";*/ toggle.style.color = ""; } //mySet.clear(); } /* < toggleFunction */ /**************************************** Window on focusin or focus > - Quando a janela ou tab do browser ganha focus ****************************************/ $(window).on("focusin focus", function(){  playVideoOnViewportOnWindowFocus(); }); function playVideoOnViewportOnWindowFocus(){ console.log('Focus');  $("video").each(function(index, video){   if($(this).visible(true,true)){     //video.play();   } console.log(this);  }); } /* < Window on focusin or focus */ /**************************************** Window on focusout or blur > - Quando a janela ou tab do browser perde focus ****************************************/ $(window).on("focusout blur", function(){  pauseVideoOnViewportOnWindowBlur(); }); function pauseVideoOnViewportOnWindowBlur(){  $("video").each(function(index, video){   if($(this).visible(true,true)){    video.pause();   }  }); } /* < Window on focusout or blur */ /**************************************** Window OnScroll > ****************************************/ window.onscroll = function() { myFunction(); menuLinksSectionsOnScroll(); videosOnScroll(); audioOnScroll(); }; /* Change style of navbar on scroll: */ function myFunction() { var navbar = document.getElementById("myNavbar"); if (document.body.scrollTop > 100 || document.documentElement.scrollTop > 100) { navbar.className = "collapse-navbar" + " scroll-effects"; } else { navbar.className = navbar.className.replace("scroll-effects", ""); } } /* Altera o menu conforme a secção que estiver presente no viewport */ function menuLinksSectionsOnScroll(event) { $('#myMenuTwo > a').each(function () { var currLink = $(this); //console.log("currLink"); refElement = $($(this).attr('href')); //console.log("refElement"); if(refElement.attr('id') != 'undefined'){ //console.log(refElement.attr('id')); if(refElement.visible(true, true)){ $('#myMenuTwo > a').removeClass("active"); $('#myMenuTwo > a').removeClass("selected"); $(this).addClass("active"); }else{ $(this).removeClass("active"); } } }); } /* Pára os videos que não estiverem no viewport */ function videosOnScroll(){ $("video").each(function(index, video){ if(!$(this).visible(true,true)){ video.pause(); // don't forget to show play video button again $('#playVideo').show(); } }); } /* Pára os audios que não estiverem no viewport */ function audioOnScroll(){ $("audio").each(function(index, audio){ if(!$(this).visible(true,true)){ audio.pause(); // don't forget to show play video button again $('#playVideo').show(); } }); } /**************************************** * Videos > ****************************************/ function pauseAllVideos(el) { if (el) { $("video").not(el).each(function(index, video) { video.pause(); }); } else { $("video").each(function(index, video) { video.pause(); }); } } function pauseAllAudio(el) { if (el) { $("audio").not(el).each(function(index, audio) { audio.pause(); }); } else { $("audio").each(function(index, audio) { audio.pause(); }); } } /*VIDEO-OVERLAY*/ $(document).ready(function() { $.each($('.box-video'), function() { /*Click na div com o texto*/ $('.video-overlay', this).each(function() { $(this).on('click', function() { $(this).hide(); pauseAllVideos(); pauseAllAudio(); $(this).parent().children('video').first().trigger('play'); }); }); /*Click no video*/ $('video', this).each(function() { $(this).click(function() { if (this.paused) { pauseAllVideos(); pauseAllAudio(); $(this).parent().children('.playpause').hide(); this.pause(); } else { $(this).parent().children('.playpause').show(); this.pause(); $('#playVideo').show(); // show button after pause video } }); /*Click no play do video*/ $(this).onplay = function() { $(this).parent().children('.playpause').hide(); }; /*Click no pause do video*/ $(this).onpause = function() { $(this).parent().children('.playpause').show(); }; }); }); }); /* Esconde ou mostra o icon play: - Esconde: quando o utilizador clica para no icon - Mostra: quando o utilizador clica para parar o video */ jQuery(function(){ jQuery('.playpause').on('click', function(e){ var el = $(this); var video = $(this).prev().get(0); video.onplay = function () { el.fadeOut('fast', function(){}); }; video.onpause = function () { el.fadeIn('fast', function(){}); }; video.play(); }); }); /* < VIDEOS */ /**************************************** * Audio > ****************************************/ $(document).ready(function() { $("audio").each(function() { $(this).on("play", function() { var id = $(this).attr('id'); pauseAllVideos(); $("audio").not(this).each(function(index, audio) { audio.pause(); }); }); }); }); /* < Window OnScroll *> /* Quando o script é colocado no head e o script afecta elementos que só estão disponíveis depois do documento estar todo carregado é necessário colocar esta instrução para que o script seja executado apenas depois do documento carregar. */ $(document).ready(function() { VideoModule.init(); //VideoModule.setBehaviour(VideoModule.getOnHoverBehaviour()).init(); /**************************************** * Slider create slider objects ****************************************/ createSliderObjects(); /**************************************** * Add smooth scrolling to all links ****************************************/ $("a").on('click', function(event) { // Make sure this.hash has a value before overriding default behavior if (this.hash !== "") { // Prevent default anchor click behavior event.preventDefault(); // Store hash var hash = this.hash; // Using jQuery's animate() method to add smooth page scroll // The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area $('html, body').animate({ scrollTop: $(hash).offset().top }, 800, function() { // Add hash (#) to URL when done scrolling (default click behavior) window.location.hash = hash; }); } // End if }); /**************************************** * Changes the slass when clicking on a menu item * - Adds the "active" class to the clicked menu item ****************************************/ $("#myMenuTwo a").on("click", function() { // For all menu items $("#myMenuTwo a").removeClass("selected"); // For the clicked menu item $(this).addClass("selected"); }); }); /*jQuery(document).ready(function($) { var alterClass = function() { var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; if (width <= 768) { $('.destaque').removeClass('content-larger').addClass('content-center'); } else if (width > 768) { $('.destaque').removeClass('content-center').addClass('content-larger'); }; }; $(window).resize(function(){ alterClass(); }); //Fire it when the page first loads: alterClass(); });*/ /*window.addEventListener("hashchange", function () { window.scrollTo(window.scrollX, window.scrollY - 85); });*/ /********** var videoPlayButton, boxVideo = document.getElementsByClassName('box-video')[0], video = document.getElementsByTagName('video')[0], videoMethods = { renderVideoPlayButton: function() { if (boxVideo.contains(video)) { this.formatVideoPlayButton() video.classList.add('has-media-controls-hidden') videoPlayButton = document.getElementsByClassName('video-overlay-play-button')[0] videoPlayButton.addEventListener('click', this.hideVideoPlayButton) } }; formatVideoPlayButton: function() { boxVideo.insertAdjacentHTML('beforeend', '\ \ \ \ \ ') }; hideVideoPlayButton: function() { video.play(); videoPlayButton.classList.add('is-hidden'); video.classList.remove('has-media-controls-hidden'); video.setAttribute('controls', 'controls'); } } videoMethods.renderVideoPlayButton()*/ /**/ $('.video').parent().click(function () { if($(this).children(".video").get(0).paused){ $(this).children(".video").get(0).play(); $(this).children(".playpause").fadeOut(); }else{ $(this).children(".video").get(0).pause(); $(this).children(".playpause").fadeIn(); } }); /********/ /* Altera os href dos links aos 479 -1st-scrolldown mudaHrefDoLink = function () { var linkscrolldown = document.getElementById("1st-scrolldown"); var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; if (width <= 480) { linkscrolldown.href = "#introducao2"; } else if (width > 480) { linkscrolldown.href = "#introducao1"; } console.log('1st-scrolldown: ' + linkscrolldown.href); } window.addEventListener("load", mudaHrefDoLink); window.addEventListener("resize", mudaHrefDoLink);*/ /*Redes sociais sidebar*/ function openNav() { document.getElementById("mySidepanel").style.width = "46px"; document.getElementById("mySidepanel").style.display = "block"; } function closeNav() { document.getElementById("mySidepanel").style.width = "0"; }