Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;(function($, window, document, undefined) {
- var $win = $(window);
- var $doc = $(document);
- var $slider;
- var tag = document.createElement('script');
- var lastScrollTop = 0;
- var delta = 5;
- var CurrentSection = 0;
- var _timerSection = null;
- tag.src = "https://www.youtube.com/iframe_api";
- var firstScriptTag = document.getElementsByTagName('script')[0];
- firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
- var ytPlayers = {};
- var vPlayers = {};
- var youtubeSettings = '?controls=0&showinfo=0&rel=0&autohide=0&autoplay=1&loop=1&modestbranding=1&showinfo=0&enablejsapi=1'
- var isMobile = {
- Android: function() {
- return navigator.userAgent.match(/Android/i);
- },
- BlackBerry: function() {
- return navigator.userAgent.match(/BlackBerry/i);
- },
- iOS: function() {
- return navigator.userAgent.match(/iPhone|iPad|iPod/i);
- },
- Opera: function() {
- return navigator.userAgent.match(/Opera Mini/i);
- },
- Windows: function() {
- return navigator.userAgent.match(/IEMobile/i);
- },
- any: function() {
- return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
- }
- };
- var isDesktop = true;
- $doc.ready(function() {
- if (isMobile.any()){
- $('body').addClass('mobile');
- isDesktop = false;
- };
- if (isDesktop) {
- $('.video, .slide-video').responsiveVideo();
- };
- $slider = $('.slider .owl-carousel');
- jPlayerInit();
- $('.popup-youtube').magnificPopup({
- type: 'iframe'
- });
- $('.popup-video').magnificPopup({
- type: 'inline'
- });
- $('.header-trigger').on('click', function (e) {
- e.preventDefault();
- $(this).toggleClass('active');
- $('body').toggleClass('header-active');
- });
- // Nav Service
- $('.nav-services a').on('click', function(e) {
- e.preventDefault();
- var target = $(this).attr('href');
- var headerHeight = $('.header').outerHeight();
- var targetPosition = $(target).offset().top;
- $('html, body').animate({
- scrollTop: targetPosition - headerHeight
- })
- })
- // Chosen
- $('select').chosen({
- disable_search_threshold: 999,
- });
- });
- var fullPageLoaded = false;
- $win.on('load resize', function() {
- if ($('#fullpage').length) {
- if (fullPageLoaded && $win.width() <= 1024) {
- fullPageLoaded = false;
- $.fn.fullpage.destroy('all');
- }
- if (!fullPageLoaded && $win.width() > 1024) {
- fullPageLoaded = true;
- fullPageInit();
- }
- };
- });
- $win.on('load', function() {
- isotope();
- initProjectVideoYoutube();
- initProjectVideoVimeo();
- // Slider Logo
- setTimeout(function() { $('.slider .slide-image').fadeOut(1999) }, 1000);
- // YT players
- if (isDesktop) {
- $('.yt-player').each(function() {
- var $ytPlayer = $(this);
- var identifier = $(this).attr('id');
- var src = $(this).data('video');
- var player = new YT.Player(identifier, {
- playerVars: {
- 'loop': 1,
- 'playlist': src,
- 'controls': 1,
- 'rel': 0
- },
- videoId: src,
- events: {
- 'onReady': function(event) {
- player.mute();
- ytPlayers[ identifier ] = player;
- }
- }
- });
- });
- };
- $('video').each(function(){
- var $this = $(this);
- var _id = $this.attr('id');
- vPlayers[_id] = document.getElementById(_id);
- });
- // Sliders
- $slider.owlCarousel({
- items: 1,
- mouseDrag: false,
- touchDrag: false,
- animateOut: 'fadeOut',
- autoplay: true,
- loop: true,
- onChange : function(){
- $('body').InitPauseVideos();
- clearTimeout(_timerSection);
- _timerSection = setTimeout(function() {
- var $active = $('.main > section').eq(CurrentSection).find('.owl-item.active');
- $active.InitPlayVideo();
- $('.video, .slide-video').responsiveVideo();
- }, 500);
- }
- });
- $('.slider-testimonials .owl-carousel').owlCarousel({
- items: 1,
- nav: true
- });
- $('.slider-project .owl-carousel').owlCarousel({
- items: 1,
- nav: true
- });
- $('body').on('change', '.gfield-fileupload input', function() {
- $('.file-name').remove();
- $('<span class="file-name">' + this.value + '</span>').insertAfter(this);
- })
- });
- function jPlayerInit() {
- $(".jp-jplayer").each( function(){
- $(this).jPlayer({
- ready: function () {
- var video_url = $(this).data('video-url');
- var video_poster = $(this).data('poster');
- $(this).jPlayer("setMedia", {
- m4v: video_url,
- ogv: video_url,
- poster: video_poster
- });
- jplayerScroll();
- },
- swfPath: "/js",
- supplied: "m4v, ogv",
- useStateClassSkin: true,
- autoBlur: false,
- smoothPlayBar: true,
- keyEnabled: true,
- remainingDuration: true,
- toggleDuration: true,
- });
- });
- };
- var projectYoutube;
- function initProjectVideoYoutube() {
- var $video = $('.project-video');
- var identifier = $('.youtube').attr('id');
- var src = $video.find('.youtube').data('src');
- projectYoutube = new YT.Player(identifier, {
- playerVars: {
- 'loop': 1,
- 'playlist': src,
- 'controls': 1
- },
- videoId: src,
- events: {
- 'onReady': function() {
- projectYoutube.mute();
- youtubeScroll();
- }
- }
- });
- };
- var projectVimeo;
- var vimeoIframe;
- function initProjectVideoVimeo() {
- var $video = $('.project-video');
- var playerId = 'vimeo';
- var src = $video.find('.vimeo').data('src');
- $video.find('.vimeo').html('<iframe id="' + playerId + '" src="http://player.vimeo.com/video/'+ src +'?api=1&player_id= ' + playerId +'" width="500" height="281" frameborder="0"></iframe>');
- vimeoIframe = $('#vimeo')[0];
- projectVimeo = $f(vimeoIframe);
- var status = $('.status');
- projectVimeo.addEvent('ready', function() {
- projectVimeo.api('setVolume', 0);
- vimeoScroll();
- });
- };
- function jplayerScroll() {
- var $video = $('.project-video');
- var videoId = $video.find('.jp-jplayer.autoplay').attr('id');
- if (isDesktop) {
- $('#' + videoId).jPlayer( "mute");
- startStopVideo();
- $win.on('scroll', function() {
- startStopVideo();
- });
- };
- function startStopVideo() {
- isVisible($video) ? $('#' + videoId).jPlayer( "play") : $('#' + videoId).jPlayer( "pause");
- };
- };
- function youtubeScroll() {
- var $video = $('.project-video');
- var autoplay = $video.find('.youtube').is('.autoplay')
- if (autoplay) {
- if (isDesktop) {
- startStopVideo();
- $win.on('scroll', function() {
- startStopVideo();
- });
- };
- };
- function startStopVideo() {
- isVisible($video) ? projectYoutube.playVideo() : projectYoutube.pauseVideo();
- };
- };
- function vimeoScroll() {
- var $video = $('.project-video');
- var autoplay = $video.find('.vimeo').is('.autoplay');
- if (autoplay) {
- if (isDesktop) {
- startStopVideo();
- $win.on('scroll', function() {
- startStopVideo();
- });
- };
- };
- function startStopVideo() {
- isVisible($video) ? projectVimeo.api('play') : projectVimeo.api('pause');
- };
- };
- function isVisible($video) {
- var videoOffsetTop = $video.offset().top;
- var videoOffsetBottom = $video.offset().top + $video.outerHeight();
- return ($win.scrollTop() + $win.height()) > videoOffsetTop && $win.scrollTop() < videoOffsetBottom;
- };
- $.fn.InitPauseVideos = function(){
- var $container = $('.main');
- $.each(vPlayers, function(index, value){
- value.pause();
- });
- $.each(ytPlayers, function(index, value){
- value.pauseVideo();
- });
- };
- $.fn.InitPlayVideo = function(){
- var currentSection = $(this);
- // Section Videos
- $('.video iframe').attr('src', '');
- if (currentSection.find('.section-video.youtube-video').length) {
- currentSection.find('.section-video iframe').attr('src', currentSection.find('.video').data('src') + youtubeSettings )
- };
- if (currentSection.find('.section-video.embed-video').length) {
- currentSection.find('.section-video video')[0].play();
- };
- $doc.on('player-loaded', function (event, data) {
- if ( currentSection.find('.slide-video .yt-player[id="' + data.identifier + '"]') ) {
- data.player.playVideo();
- }
- });
- // Intitial Youtube Load
- var $currentSectionVideos = currentSection.find('.slide-video .yt-player');
- if ( $currentSectionVideos.length ) {
- $currentSectionVideos.each(function () {
- var $video = $(this);
- var videoId = $video.attr('id');
- if ( videoId in ytPlayers ) {
- ytPlayers[videoId].playVideo();
- }
- });
- };
- var $embedVideo = currentSection.find('.slide-video video');
- $embedVideo.each(function(){
- var currentVideo = $(this);
- if (currentVideo[0].readyState === 4) {
- currentVideo[0].play();
- }
- currentVideo.on('loadeddata', function() {
- currentVideo[0].play();
- });
- });
- }
- function fullPageInit() {
- $('#fullpage').fullpage({
- sectionSelector: '.fullpage-section',
- slideSelector: '.fullpage-slide',
- navigation:true,
- afterLoad: function(anchorLink, index) {
- var $this = $(this);
- clearTimeout(_timerSection);
- CurrentSection = $this.index();
- $('body').InitPauseVideos();
- if(!$this.find('.slider').length){
- _timerSection = setTimeout(function() {
- $this.InitPlayVideo();
- }, 500);
- }else{
- _timerSection = setTimeout(function() {
- var $active = $('.main > section').eq(CurrentSection).find('.owl-item.active');
- $active.InitPlayVideo();
- }, 500);
- }
- // Footer
- if(index === $('#fullpage .fullpage-section').length){
- $('body').toggleClass('footer-active', true)
- } else {
- $('body').toggleClass('footer-active', false)
- };
- }
- });
- };
- function isotope () {
- //Isotope
- var $wallOuter = $('.team-members-outer');
- var $container = $wallOuter.find('.team-members');
- $win.on('load resize', resizeContainer);
- function resizeContainer() {
- $wallOuter.width('auto');
- };
- resizeContainer();
- $container.isotope({
- itemSelector: '.team-members .team-member',
- percentPosition: true,
- masonry: {
- // use outer width of grid-sizer for columnWidth
- columnWidth: '.team-members .team-member'
- }
- });
- };
- $.fn.responsiveVideo = function (options) {
- var resize_repsonsive_video = function() {
- var $player = $(this);
- var win_width = $player.parent().width(),
- win_height = $player.parent().height();
- var video_width = parseInt($player.data('video-width'));
- var video_height = parseInt($player.data('video-height'));
- var video_offset = parseInt($player.data('video-offset'));
- var img_dimensions_ratio = video_height / video_width;
- var offset = video_offset / video_height;
- offsetWidth = win_width * offset;
- offsetHeight = win_height * offset;
- if ( win_height / win_width > img_dimensions_ratio ) {
- var player_width = win_height / img_dimensions_ratio,
- player_height = win_height;
- player_width += (player_width * offset);
- player_height += ( player_height * offset)
- $player.height(player_height).width(player_width);
- } else {
- var player_width = win_width,
- player_height = win_width * img_dimensions_ratio;
- player_width += (player_width * offset);
- player_height += (player_height * offset);
- $player.width(player_width).height(player_height);
- }
- $player.css({
- 'left': (win_width - $player.width()) / 2,
- 'top': (win_height - $player.height() ) /2
- });
- }
- var videos = this;
- $(window).on('load resize', function () {
- setTimeout(function() {
- videos.each(resize_repsonsive_video);
- }, 500);
- });
- return videos.each(resize_repsonsive_video);
- };
- })(jQuery, window, document);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement