/* 01. Fullpage Slider 02. Page Transitioan 03. Masonry plugin 04. Parallax 05. Mobile Menu Navigation 06. Back To Top Buttone 07. PhotoSwipe Gallery 08. Validate form */ jQuery(function () { 'use strict'; var $ = jQuery; var _ismobile = navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPod/i); if (typeof pageCalculations !== 'function') { var winW, winH,winS, pageCalculations; pageCalculations = function (func){ winW = $(window).width(); winH = $(window).height(); winS = $(window).scrollTop(); if (func) { $(window) .on('load',function(){ func(); }) .on('resize',function(){ func(); }); window.addEventListener("orientationchange", function() { func(); }, false); } } pageCalculations(function(){ pageCalculations(); }); } Pace.on('done',function() { $('.preloader').css('display', 'none'); }); $('body, .contact_form, .contact-info, .btn').addClass('fadeIn animated'); /*Create 'exist' selector*/ jQuery.exists = function(selector) { return ($(selector).length > 0); } /*==============================*/ /* 01 - Fullpage Slider */ /*==============================*/ if ($.exists('.fullpage')) { /* Custom scrolling enabled */ $('.jsScrollOn').fullpage({ menu: '#menu', autoScrolling: true, // + lockAnchors: false, fitToSection: true, // + scrollBar: true, scrollingSpeed: 500, navigation: true, loopBottom: true, loopTop: true, fadingEffect: true, animateAnchor: true, afterRender: function() { upFullWidthVideo(); $(this).fitVids(); }, afterSlideLoad: function() { upFullWidthVideo(); //$("iframe").fitVids(); }, }); } $(window).on("resize", function() { hidePagination(); countPagination(); widthNavMenu(); toggleIcon(); }); /*==============================*/ /* 02 - Page Transitioan */ /*==============================*/ // $('.transition a').on('click', function(e) { // e.preventDefault(); // var url = $(this).attr('href'); // if (url != '#' && url != '') { // $('body').addClass('fadeOut animated'); // setTimeout(function() { // window.location.href = url; // }, 500); // } // }); /*==============================*/ /* 03 - Masonry plugin */ /*==============================*/ if ($.exists('.masonry')) { var $container = $('.masonry'); $container.imagesLoaded( function() { $container.masonry({ itemSelector: '.grid-item, .proof-photo, .blog-item, .timeline, .almub-item', normalScrollElements: '.mobile-menu-overlay', percentPosition: true }); }); } function animate() { $('.row:not(.no-animation) img, .post-info, .image_thumbnail, .item-albums').each(function(i) { if($(window).scrollTop() >= $(this).offset().top-$(window).height()*0.9 ) { (function(self, j) { setTimeout(function() { $(self).addClass('fadeInUp animated'); }, (j * 60) ); })(this, i); } }); } animate(); $(window).on("scroll", function() { animate(); }); function animateAlbums() { $('.item-albums').each(function(i) { (function(self, j) { setTimeout(function() { $(self).addClass('fadeInUp animated'); }, (j * 150) + 150); })(this, i); }); } animateAlbums(); $(window).on("scroll", function() { setTimeout(function() { animateAlbums(); }, 1000) }); /*==============================*/ /* 04 - Parallax */ /*==============================*/ if ($.exists('.parallax')) { $(window).scroll(function(){ marseille_parallax(); }); } function marseille_parallax(){ var scrolled = $(window).scrollTop(); $('.item-category').css('padding-top', '0'+(scrolled*.02)+'rem'); if (! $('.admin-bar').length ) { $('.parallax').css('top', '0'-(scrolled*.04)+'rem'); } $('.item-category h1, .item-category p, .item-category .wpc-divider ').css('opacity', '1'-(scrolled*.003)); } /*==============================*/ /* 05 - Mobile Menu Navigation */ /*==============================*/ $('.mobile-menu .menu-toggle').on('click', function(){ $('.mobile-menu-overlay').toggleClass('visible'); $(".mobile-menu-overlay").addClass('active'); $("body, html").css("overflow", "hidden"); }); $(".menu-close").on("click", function() { $('.mobile-menu-overlay').removeClass("visible"); $('.mobile-menu .menu-toggle').removeClass("active"); $("body, html").css("overflow", "visible"); $(".mobile-menu-overlay").removeClass('active'); }); $('.mobile-menu-content .menu-item-has-children > a').on('click', function(){ $(this).next().slideToggle('fast'); //Hide the other panels // $(".sub-menu").not($(this).next()).slideUp('fast'); }); /*==============================*/ /* 06 - Back To Top Button */ /*==============================*/ var offset = 300, offset_opacity = 1200, scroll_top_duration = 1000, $back_to_top = $('.back-top'); //hide or show the "back to top" link $(window).scroll(function() { ($(this).scrollTop() > offset) ? $back_to_top.addClass('back-top-is-visible'): $back_to_top.removeClass('back-top-is-visible back-top-fade-out'); if ($(this).scrollTop() > offset_opacity) { $back_to_top.addClass('back-top-fade-out'); } }); //smooth scroll to top $back_to_top.on('click', function(event) { event.preventDefault(); $('body,html').animate({ scrollTop: 0, }, scroll_top_duration); }); /*==============================*/ /* 07 - PhotoSwipe Gallery */ /*==============================*/ if ($.exists('.gallery')) { var initPhotoSwipeFromDOM = function(gallerySelector) { // parse slide data (url, title, size ...) from DOM elements // (children of gallerySelector) var parseThumbnailElements = function(el) { console.log('inited'); var thumbElements = el.childNodes, numNodes = thumbElements.length, items = [], figureEl, linkEl, size, item; for (var i = 0; i < numNodes; i++) { figureEl = thumbElements[i]; //
element // include only element nodes if (figureEl.nodeType !== 1) { continue; } linkEl = figureEl.children[0]; // element size = linkEl.getAttribute('data-size').split('x'); // create slide object item = { src: linkEl.getAttribute('href'), w: parseInt(size[0], 10), h: parseInt(size[1], 10) }; if (figureEl.children.length > 1) { //
content item.title = figureEl.children[1].innerHTML; } if (linkEl.children.length > 0) { // thumbnail element, retrieving thumbnail url item.msrc = linkEl.children[0].getAttribute('src'); } item.el = figureEl; // save link to element for getThumbBoundsFn items.push(item); } return items; }; // find nearest parent element var closest = function closest(el, fn) { return el && (fn(el) ? el : closest(el.parentNode, fn)); }; // triggers when user clicks on thumbnail var onThumbnailsClick = function(e) { e = e || window.event; e.preventDefault ? e.preventDefault() : e.returnValue = false; var eTarget = e.target || e.srcElement; // find root element of slide console.log(eTarget) var clickedListItem = closest(eTarget, function(el) { // console.log((el.tagName && el.tagName.toUpperCase() === 'FIGURE')) return (el.tagName && el.tagName.toUpperCase() === 'FIGURE'); }); if (!clickedListItem) { return; } console.log('enter') // find index of clicked item by looping through all child nodes // alternatively, you may define index via data- attribute var clickedGallery = clickedListItem.parentNode, childNodes = clickedListItem.parentNode.childNodes, numChildNodes = childNodes.length, nodeIndex = 0, index; for (var i = 0; i < numChildNodes; i++) { if (childNodes[i].nodeType !== 1) { continue; } if (childNodes[i] === clickedListItem) { index = nodeIndex; break; } nodeIndex++; } console.log('index', index) if (index >= 0) { // open PhotoSwipe if valid index found openPhotoSwipe(index, clickedGallery); } // jQuery(".pswp__iframe").fitVids(); return false; }; // parse picture index and gallery index from URL (#&pid=1&gid=2) var photoswipeParseHash = function() { var hash = window.location.hash.substring(1), params = {}; if (hash.length < 5) { return params; } var vars = hash.split('&'); for (var i = 0; i < vars.length; i++) { if (!vars[i]) { continue; } var pair = vars[i].split('='); if (pair.length < 2) { continue; } params[pair[0]] = pair[1]; } if (params.gid) { params.gid = parseInt(params.gid, 10); } return params; }; var openPhotoSwipe = function(index, galleryElement, disableAnimation, fromURL) { var pswpElement = document.querySelectorAll('.pswp')[0], gallery, options, items; items = parseThumbnailElements(galleryElement); // define options (if needed) options = { isClickableElement: function(el) { return (el.tagName === 'SELECT' || el.tagName === 'A'); }, // define gallery index (for URL) galleryUID: galleryElement.getAttribute('data-pswp-uid'), getThumbBoundsFn: function(index) { // See Options -> getThumbBoundsFn section of documentation for more info var thumbnail = items[index].el.getElementsByTagName('img')[0], // find thumbnail pageYScroll = window.pageYOffset || document.documentElement.scrollTop, rect = thumbnail.getBoundingClientRect(); return { x: rect.left, y: rect.top + pageYScroll, w: rect.width }; } }; // PhotoSwipe opened from URL if (fromURL) { if (options.galleryPIDs) { // parse real index when custom PIDs are used // http://photoswipe.com/documentation/faq.html#custom-pid-in-url for (var j = 0; j < items.length; j++) { if (items[j].pid == index) { options.index = j; break; } } } else { // in URL indexes start from 1 options.index = parseInt(index, 10) - 1; } } else { options.index = parseInt(index, 10); } for (var j = items.length - 1; j >= 0; j--) { if ( items[j].el.children[0].getAttribute('data-iframe') ) { items[j].html = '