This repository has been archived by the owner on Oct 8, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[init] When the hash portion of the initial URL is exactly equal to t…
…he dialog hash key, we must trigger a hashchange -- Fixes #5021
- Loading branch information
6ef910d
There was a problem hiding this comment.
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?
6ef910d
There was a problem hiding this comment.
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:
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.