Skip to content

Instantly share code, notes, and snippets.

@medovob
Created February 12, 2011 12:56
Show Gist options
  • Save medovob/823744 to your computer and use it in GitHub Desktop.
Save medovob/823744 to your computer and use it in GitHub Desktop.
Enable SubPages from listview in jQuery Mobile
$('div').live('pagebeforecreate', function(event, ui) {
var subpageIndex = 0,
$page = $(this),
pageURL = $page.data("url"),
$body = $page.parent();
$page.find("ul[data-role='listview']>li>[data-role='subpage']").each(function() {
var $subcontent = $(this),
$li = $subcontent.parent(),
$ul = $li.parent(),
subpageURL = pageURL+"?subpage="+(subpageIndex++),
$subpage = $('<div data-role="pending-page"></div>').attr("data-url",subpageURL).appendTo($body),
$titleElement = $li.find("[data-role='subpagetitle']"),
title = $titleElement.length ? $titleElement.text() : $page.find("[data-role='header'] h1").text(),
$aTarget = $titleElement.length ? $titleElement.eq(0) : $li.children().eq(0),
$subpageHeader = $('<div data-role="header"></div>').append($('<h1/>').text(title)).appendTo($subpage);
$subcontent.attr("data-role","content").appendTo($subpage);
$aTarget.wrapInner('<a></a>');
$a = $li.find("a:eq(0)").attr("href",subpageURL);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment