Skip to content

Instantly share code, notes, and snippets.

@jdittrich
Last active December 29, 2015 19:59
Show Gist options
  • Save jdittrich/7720927 to your computer and use it in GitHub Desktop.
Save jdittrich/7720927 to your computer and use it in GitHub Desktop.
/*
For injecting additional pages in an existing jqueryMobile-Page
*/
$(function(){
(function(){
var data = $.parseJSON( $("#template-data").html());//gets the string and turns it into a JSON
var template = $("#template").html(); //gets the mustache template;
var compiledTemplate = Handlebars.compile(template); //precompilation of the template
//replaceWith() is used because I dont get DOMFragements to work and I dont want to replace the whole content.
//renders the template and returns a HTML-String
$("#placeholder").replaceWith(compiledTemplate(data));
$("#container").trigger("create"); //triggers the enhancement of inserted HTML
}())
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment