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

Patch for issue #1024 (Duplicate pages created in DOM) #1456

Closed
wants to merge 9 commits into from

Conversation

okoskimi
Copy link

#1024

This patch extends path.clean() in jquery.mobile.navigation.js to canonicalize URLs:

  • Relative urls (e.g. "../dir/file.html") are canonicalized to #dir/file.html format
  • Same for absolute urls (e.g. "/dir/file.html"), if above in directory hierarchy this will produce something like #../../../dir/file.html (keeping the hash always relative to current location.pathname). The "#../../..." style was used for consistency and URL legibility (remove the hash and you have a working URL) reasons.
  • Hashed urls (hash somewhere else than first character) can be used to load a page as external, e.g. ../dir/#file.html is resolved to a full URL (beginning with protocol), which again causes it to be interpreted as external by the isExternal() logic. This seemed to be the most intuitive semantic for hashed urls.
  • You can use #/ to refer to $.mobile.firstPage (and relative/absolute urls that point to the first page will work too). Also, urls like #/dir/file.html are interpreted logically related to this, so that the url is always relative to location.pathname (i.e. #/dir/file.html is interpreted the same as #dir/file.html).

The patch changes the semantics for a "hash-absolute" url of type "#/dir1/dir2/file.html". Before the patch, this referred to file /dir1/dir2/file.html. However, you get the same semantics also without the hash, i.e. "/dir1/dir2/file.html" means the same thing. The patch changes the semantics to be so that "#/" refers to $.mobile.firstPage (i.e. location.pathname), and anything after that is interpreted as being relative to location.pathname (i.e. "#/dir1/dir2/file.html" is interpreted the same as the "#dir1/dir2/file.html"). The idea is that the "hash-absolute" urls now let you refer to both $.mobile.firstPage and other files in a consistent way.

See path.clean() comments for more details.

Unit tests have been added for the new functionality. Tested on Chrome, Firefox and IE8. Unit tests pass where they pass for the original code (i.e. there are some tests that did not work for IE8 in the original code either).

BR,
--Oskari

@scottjehl
Copy link

Great work. We'll take a look at this and get back to you with some feedback soon!

@scottjehl
Copy link

This issue should be fixed in latest, as all URLs are now normalized to a full absolute path. I'm closing this one out, but please let us know if you find any issues with the current build.

Again, thanks so much for the ideas. They really helped!

@scottjehl scottjehl closed this Jun 17, 2011
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants