Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
[init] When the hash portion of the initial URL is exactly equal to t…
Browse files Browse the repository at this point in the history
…he dialog hash key, we must trigger a hashchange -- Fixes #5021
  • Loading branch information
Gabriel Schulhof committed Sep 18, 2012
1 parent 919a15d commit 6ef910d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion js/jquery.mobile.init.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ define( [ "jquery", "./jquery.mobile.core", "./jquery.mobile.support", "./jquery
if ( ! ( $.mobile.hashListeningEnabled &&
$.mobile.path.isHashValid( location.hash ) &&
( $( hashPage ).is( ':jqmData(role="page")' ) ||
$.mobile.path.isPath( hash ) ) ) ) {
$.mobile.path.isPath( hash ) ||
hash === $.mobile.dialogHashKey ) ) ) {

// Store the initial destination
if ( $.mobile.path.isHashValid( location.hash ) ) {
Expand Down

2 comments on commit 6ef910d

@johnbender
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gabrielschulhof

Why does the framework need to trigger a hashchange here? Don't we want to load the first page when the initial hash is the dialog hash key?

@gabrielschulhof
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs to trigger a hashchange so popstate information can be recorded for this case. The reason for that is that when you navigate to a dialog from a page with an initial URL that has a dialog hash key, when you go back from the dialog, a popstate event occurs, but no hashchange event occurs, because the cosmetically corrected URL for the dialog is the same as the initial URL. However, onPopState will call _handleHashChange manually so we can still handle this case as a normal hashchange. This is one of the reasons we came up with the "navigate" event. In brief:

  1. Go to http://jquerymobile.com/test/docs/pages/dialog/index.html#&ui-state=dialog
  2. Click on Open Dialog.
    This results in a URL of

http://jquerymobile.com/test/docs/pages/dialog/index.html#/test/docs/pages/dialog/index.html&ui-state=dialog

which is corrected in the pushstate plugin to

http://jquerymobile.com/test/docs/pages/dialog/index.html#&ui-state=dialog

Now, the dialog's history entry is identical to the initial URL's history entry.

So, when you close the dialog by going back you don't get a hashchange. Nevertheless, you get a popstate event. However, the popstate event only calls _handleHashChange if you've earlier saved some state[1]. Thus, we must make sure that an earlier state is saved. We do that in onHashChange, so we must ensure that onHashChange happens for the first page. Thus, we emit hashchange.

Please sign in to comment.