Guest User

Untitled

a guest
Dec 10th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. // Listen for any attempts to call changePage().
  2. $(document).bind( "pagebeforechange", function(e, data) {
  3. // We only want to handle changePage() calls where the caller is
  4. // asking us to load a page by URL.
  5. if (typeof data.toPage === "string") {
  6. // We only want to handle a subset of URLs.
  7. var u = $.mobile.path.parseUrl(data.toPage);
  8. var home = /^#home/;
  9. var qrcode = /^#qrcode/;
  10. var delurl = /^#delurl/;
  11. if (u.hash.search(home) !== -1) {
  12. // Display a list of URLs.
  13. showUrlList(u, data.options);
  14. e.preventDefault();
  15. }
  16. else if (u.hash.search(qrcode) !== -1) {
  17. // Display QR code for the selected URL.
  18. showQRCode(u, data.options);
  19. e.preventDefault();
  20. }
  21. else if (u.hash.search(delurl) !== -1) {
  22. // Display URL delete confirmation dialog box.
  23. showDelUrl(u, data.options);
  24. e.preventDefault();
  25. }
  26. }
  27. });
  28.  
  29. // Display Delete URL confirmation dialog for a specific url passed in as a parameter.
  30. function showDelUrl(urlObj, options) {
  31. // Get the url parameter
  32. var url = decodeURIComponent(urlObj.hash.replace(/.*url=/, ""));
  33.  
  34. // The pages we use to display our content are already in
  35. // the DOM. The id of the page we are going to write our
  36. // content into is specified in the hash before the '?'.
  37. var pageSelector = urlObj.hash.replace(/\?.*$/, "");
  38.  
  39. // Get the page we are going to write our content into.
  40. var $page = $(pageSelector);
  41.  
  42. // Get the content area element for the page.
  43. var $content = $page.children(":jqmData(role=content)");
  44.  
  45. // Set url elements of the page.
  46. $content.find("#url_value").val(url);
  47. $content.find("#url_prompt").html(getHostname(url));
  48.  
  49. // Pages are lazily enhanced. We call page() on the page
  50. // element to make sure it is always enhanced.
  51. $page.page();
  52.  
  53. // Now call changePage() and tell it to switch to the page we just modified.
  54. $.mobile.changePage($page, options);
  55. }
Add Comment
Please, Sign In to add comment