Skip to content

Instantly share code, notes, and snippets.

@jmuspratt
Created October 2, 2015 17:06
Show Gist options
  • Save jmuspratt/63dc2a0793002427e77e to your computer and use it in GitHub Desktop.
Save jmuspratt/63dc2a0793002427e77e to your computer and use it in GitHub Desktop.
// from http://commandogroup.no/wp-content/themes/Commando/js/app.js
function ajaxNav() {
$('a.home, a.project-title, a.thumbnail-title').click(function(e) {
var _gaq = _gaq || [];
var data = {
scrollTop: document.body.scrollTop
};
var path = $(this).attr('href');
var title = $(this).attr('title');
History.pushState(data, title, path);
_gaq.push(['_setAccount', 'UA-5672795-1']);
_gaq.push(['_trackEvent', 'AjaxLink', 'clicked']);
e.preventDefault();
//return false;
});
}
History.Adapter.bind(window, 'statechange', function() {
var State = History.getState();
var data = State.data;
var main = $('main');
var loading = $('#loading');
window.stop();
loading.css('display', 'block').velocity({
opacity: 1
}, 400);
main.velocity({
opacity: 0
}, 600, function() {
$(this).load(State.url + ' #content', data, function() {
$(this).waitForImages(function() {
//console.log('Images loaded.');
scrolltothetop();
loading.velocity({
opacity: 0
}, {
duration: 400,
display: 'none'
});
$(this).velocity({
opacity: 1
}, 600);
commando();
});
});
});
});
}) ( jQuery );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment