|
// Listen for any attempts to call changePage(). |
|
$(document).bind( "pagebeforechange", function(e, data) { |
|
// We only want to handle changePage() calls where the caller is |
|
// asking us to load a page by URL. |
|
if (typeof data.toPage === "string") { |
|
// We only want to handle a subset of URLs. |
|
var u = $.mobile.path.parseUrl(data.toPage); |
|
var home = /^#home/; |
|
var qrcode = /^#qrcode/; |
|
var delurl = /^#delurl/; |
|
if (u.hash.search(home) !== -1) { |
|
// Display a list of URLs. |
|
showUrlList(u, data.options); |
|
e.preventDefault(); |
|
} |
|
else if (u.hash.search(qrcode) !== -1) { |
|
// Display QR code for the selected URL. |
|
showQRCode(u, data.options); |
|
e.preventDefault(); |
|
} |
|
else if (u.hash.search(delurl) !== -1) { |
|
// Display URL delete confirmation dialog box. |
|
showDelUrl(u, data.options); |
|
e.preventDefault(); |
|
} |
|
} |
|
}); |
|
|
|
// Display Delete URL confirmation dialog for a specific url passed in as a parameter. |
|
function showDelUrl(urlObj, options) { |
|
// Get the url parameter |
|
var url = decodeURIComponent(urlObj.hash.replace(/.*url=/, "")); |
|
|
|
// The pages we use to display our content are already in |
|
// the DOM. The id of the page we are going to write our |
|
// content into is specified in the hash before the '?'. |
|
var pageSelector = urlObj.hash.replace(/\?.*$/, ""); |
|
|
|
// Get the page we are going to write our content into. |
|
var $page = $(pageSelector); |
|
|
|
// Get the content area element for the page. |
|
var $content = $page.children(":jqmData(role=content)"); |
|
|
|
// Set url elements of the page. |
|
$content.find("#url_value").val(url); |
|
$content.find("#url_prompt").html(getHostname(url)); |
|
|
|
// Pages are lazily enhanced. We call page() on the page |
|
// element to make sure it is always enhanced. |
|
$page.page(); |
|
|
|
// Now call changePage() and tell it to switch to the page we just modified. |
|
$.mobile.changePage($page, options); |
|
} |