Don't like ads? PRO users don't see any ads ;-)
Guest

Work-around for jQuery Mobile issue #4050

By: a guest on May 23rd, 2012  |  syntax: JavaScript  |  size: 1.65 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. $(document).on('pagebeforechange', function(event, data) {
  2.         // pagebeforechange fires both before and after the request; data.toPage is only a string before
  3.         if ($.mobile.ajaxEnabled && typeof data.toPage === 'string') {
  4.                 /* NOTE: $cur_page may be undefined if reloading a page w/ hash in browser w/o pushState support
  5.                          $initial_page may be undefined, empty, or reference an unenhanced page */
  6.                 var $cur_page = $.mobile.activePage,
  7.                         $initial_page = $cur_page && $cur_page.jqmData('external-page')
  8.                                 ? $cur_page.siblings(':jqmData(role="page")').not(':jqmData(external-page="true"))
  9.                                 : $cur_page,
  10.                         initial_page_data = $initial_page && $initial_page.jqmData('page'),
  11.                         root_url = window.location.protocol + '//' + window.location.host,
  12.                         nav_urls = {
  13.                                 dest: $.mobile.path.makeUrlAbsolute(data.toPage, root_url),
  14.                                 initial: $initial_page && $initial_page.length ? root_url + $initial_page.jqmData('url') : undefined
  15.                         };
  16.                 // for when initial pg data-url & return link disagree on trailing "/"...
  17.                 $.each(nav_urls, function(key, value) {
  18.                         nav_urls[key] = value && value.charAt(value.length - 1) === '/' ? value.slice(0, -1) : value;
  19.                 });
  20.                 if ($initial_page !== $cur_page
  21.                                 && nav_urls.dest === nav_urls.initial
  22.                                 && !(initial_page_data && initial_page_data.options.domCache)) {
  23.                         data.options.reloadPage = true;
  24.                         $(document).one('pageshow', function() {
  25.                                 // keep new version of the page around (is this necessary?)
  26.                                 $(event.target).removeAttr('data-' + $.mobile.ns + 'external-page').off('pagehide.remove');
  27.                                 // clean up dup DOM node from any trailing slash disagreement
  28.                                 $initial_page.remove();
  29.                         });
  30.                 }
  31.         }
  32. });