File: D:/HostingSpaces/SBogers10/honger7.komma.pro/resources/assets/js/site/barba/barbaHandler.js
/* ==========================================================================
Initialize BarbaJS when DomContentLoaded
========================================================================== */
document.addEventListener("DOMContentLoaded", function() {
var lastElementClicked;
// Refine wrapper
Barba.Pjax.Dom.wrapperId = 'hungry-wrapper';
Barba.Pjax.Dom.containerClass = 'hungry-container';
// Initialize Pjax
Barba.Pjax.init();
// Update lastElementClicked on click
Barba.Dispatcher.on('linkClicked', function(el) {
lastElementClicked = el;
});
// Since there is no transition on page reload, trigger the updatePage
Barba.Dispatcher.trigger('updatePage');
/* Setup transition
========================================================================== */
Barba.Pjax.getTransition = function()
{
// Switch name
switch(lastElementClicked.dataset.name)
{
// Optional: custom animations for specific pages
// case 'case':
// // Custom animation
// return FadeTransition;
// break;
default:
return DT;
}
};
});
/* Setup Event listeners
========================================================================== */
// When a new page is ready
Barba.Dispatcher.on('newPageReady', function(currentStatus, oldStatus, container) {
// Fade in all images when loaded
ImagePreloader.init();
// Reset navigation open
$('body').removeClass("navigation-is-open");
});
// When the old page is no longer visible
// You can only update elements outside the hungry container here
Barba.Dispatcher.on('updatePage',function(){
// Define previous and current status
var currentStatus = Barba.HistoryManager.currentStatus();
var prevStatus = Barba.HistoryManager.prevStatus();
// Make sure the body always has a class with the name of the page
var $body = $('body');
// Remove previous state from body class
if( isset(prevStatus)) $body.removeClass(prevStatus.namespace);
// Add current state to body class
$body.addClass(currentStatus.namespace);
// Update Google Analytics
// Edit: this is done in tag manager
// if (typeof ga === 'function') ga('send', 'pageview', location.pathname);
// Update Komma Leads
// if( window._gaq ) _gaq.push(['_trackPageview', window.location.href]);
});
// After a page transition is completed:
// All actions that have affect on elements inside the hungry-container should go here.
Barba.Dispatcher.on('transitionCompleted', function(currentStatus,prevStatus) {
// Initialize handler for every page
AnimationHandler.init();
BrowserHandler.init();
Navigation.init();
ScrollHandler.init();
ViewportHandler.init();
FeaturedCaseHandler.init();
// Paint the navigation drip
if(currentStatus.namespace == 'cases') NavigationDripPainter.init();
if(currentStatus.namespace.substr(0,5) == 'case ') CaseProgress.init();
if(currentStatus.namespace == 'process') ProcessHandler.init();
if(currentStatus.namespace == 'testimonials') TestimonialHandler.init();
if(currentStatus.namespace == 'home') YoutubeHandler.init();
if(currentStatus.namespace == 'contact') MapsHandler.init();
});