I am using https://github.com/miguel-perez/smoothState.js and trying to create an if/else statement using the previous page's URL. I tried storing the pathname in a cookie, but I also need to use the current pathname and it was only logging the cookie for some reason.
I hope this explains what I'm trying to do:
(function($) {
'use strict';
var $page = $('#main'),
options = {
debug: true,
prefetch: true,
cacheLength: 0,
onBefore: function($currentTarget, $container) {
// Keep the current page's pathname. Specifically
// check if it's the sites index
},
onStart: {
duration: 1000,
render: function ($container) {
$('#tempWrapper').remove();
// Check if the new page is the site's index or not
// and run a specific function
if ( window.location.pathname == "/" ) {
smoothState.restartCSSAnimations();
} else {
$("html, body").animate({ scrollTop: "0px" });
$(".carousel").remove();
var $newContainer = $container.clone();
$newContainer.attr("id", "tempWrapper");
$newContainer.css({
position:'absolute',
top:$container.offset().top,
width:$container.css("width"),
maxHeight:"100vh",
overflow:"hidden"
});
// $container.empty();
$container.before($newContainer);
$('#inner-content').removeClass('entering');
var element = $('#inner-content', $newContainer);
setTimeout(callAnimation(element, true), 0);
}
}
},
onReady: {
duration: 1000,
render: function ($container, $newContent) {
$container.html($newContent);
// This is where it gets tricky: I need to check if
// the previous page was the site's index. If the
// previous page was a subpage, it does an animation.
if ( window.location.pathname == "/" ) {
// Index (home) page
} else {
// Do animations
var element = document.getElementById($container[0].id).getElementsByClassName('move')[0];
callAnimation(element);
}
}
}
},
smoothState = $page.smoothState(options).data('smoothState');
})(jQuery);
I've inlined my notes, any help is greatly appreciated. I've also tried using document.referrer but displays blank; I'm assuming it's because there's no click page refreshing.