Created
June 22, 2012 16:19
-
-
Save cianclarke/2973802 to your computer and use it in GitHub Desktop.
fh-studio single page navigation example
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
// attach an event handler to all links with the singlepage class, that is all links we want to not do a full page nav | |
// where possible | |
$('a.singlepage').click(function(e){ | |
e.preventDefault(); | |
var url = $(this).attr('href'), | |
// Continue as normal for cmd clicks etc | |
if ( event.which == 2 || event.metaKey || url==="#" || !url ) { return true; } | |
// Now do a call to our JSON API made by Express. | |
// Because the resource type is JSON, we get JSON back! | |
$.get(self.url + ".json", function(res){ | |
// Res contains the template we need to look up, and the data to apply to it. | |
var tpl = res.tpl, // a string representing the template name we need for this view | |
data = res.data; // the data to apply to the template | |
dust.render(tpl, data, function(err, out){ | |
// DustJS has rendered our HTML. Use JQuery to append it. | |
$('body').html(out); | |
}); | |
}).error(function(){ | |
alert("Error Changing Page"); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment