Skip to content

Instantly share code, notes, and snippets.

@hyperking
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyperking/9177864 to your computer and use it in GitHub Desktop.
Save hyperking/9177864 to your computer and use it in GitHub Desktop.
updating body class with current page name for djax plugin
<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