Skip to content

Instantly share code, notes, and snippets.

@tatsuyaueda
Last active December 17, 2015 09:49
Show Gist options
  • Save tatsuyaueda/5590181 to your computer and use it in GitHub Desktop.
Save tatsuyaueda/5590181 to your computer and use it in GitHub Desktop.
jQueryMobile Dynamic Content Rewrite(1)
$(document).bind("pagebeforechange", function(e, data) {
if(typeof data.toPage === "string") {
var u = $.mobile.path.parseUrl(data.toPage);
var re = /^#pageID/;
if (u.hash.search(re) !== -1) {
$.get("/foo/path", function(data) {
var $page = $("#pageID");
var $content = $page.children( ":jqmData(role=content)" );
$content.html($("<div>" + data + "</div>").children("#pageID").children( ":jqmData(role=content)" ).children()).trigger( "create" );
$content.find( ":jqmData(role=listview)" ).listview();
//$page.page();
$.mobile.changePage($page, data.options);
e.preventDefault();
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment