Last active
August 29, 2015 13:56
-
-
Save hyperking/9177864 to your computer and use it in GitHub Desktop.
updating body class with current page name for djax plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
var transition = function($newEl) { | |
// the pageTitle var assumes your title tag is formatted as " Site Name|Page Name " | |
// i perfer to use this method, otherwise landing page body class will show empty | |
var pageTitle = document.title.split('|')[1].toLowerCase().replace(/ /g,"-"); | |
function updateBodyClass(){ | |
$('body').removeClass().addClass(pageTitle); | |
} | |
var $oldEl = this; // reference to the DOM element that is about to be replaced | |
$newEl.hide(); // hide the new content before it comes in | |
$oldEl.fadeOut("fast", function() { | |
$oldEl.replaceWith($newEl); | |
updateBodyClass(function(){pageTitle = pageTitle}); | |
$newEl.show(); | |
$newEl.fadeIn("fast"); | |
}); | |
} | |
jQuery(document).ready(function($) { | |
$('body').djax('.djaxable', [], transition); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment