Skip to content

Instantly share code, notes, and snippets.

@cianclarke
Created June 22, 2012 16:19
Show Gist options
  • Save cianclarke/2973802 to your computer and use it in GitHub Desktop.
Save cianclarke/2973802 to your computer and use it in GitHub Desktop.
fh-studio single page navigation example
// 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