Permalink
Browse files

Navigation: Click handler correctly handles absolute URL with hash

(cherry picked from commit bdfe15d)

Closes gh-7632
Fixes gh-5759
  • Loading branch information...
1 parent 6c9b996 commit 4813c3378b5316b3d34896765d6219b9810854ff @gabrielschulhof gabrielschulhof committed Aug 20, 2014
@@ -364,9 +364,10 @@ define( [
// lists and select dialogs, just write a hash in the link they
// create. This means the actual URL path is based on whatever
// the current value of the base tag is at the time this code
- // is called. For now we are just assuming that any url with a
- // hash in it is an application page reference.
- if ( href.search( "#" ) !== -1 ) {
+ // is called.
+ if ( href.search( "#" ) !== -1 &&
+ !( $.mobile.path.isExternal( href ) && $.mobile.path.isAbsoluteUrl( href ) ) ) {
+
href = href.replace( /[^#]*#/, "" );
if ( !href ) {
//link was an empty hash meant purely
@@ -30,6 +30,7 @@
<div id="qunit"></div>
<div id="harmless-default-page" data-nstest-role="page" class="first-page">
+ <a id="goToGoogle" href="http://www.google.com/#abc">Go to Google</a>
</div>
<div id="foo" data-nstest-role="page" class="foo-class">
@@ -16,6 +16,26 @@ $.testHelper.delayStart();
$.testHelper.openPage( "#" + location.pathname + location.search );
};
+ test( "Absolute link with hash works", function() {
+ var defaultIsPrevented,
+ theLink = $( "#goToGoogle" ),
+ theClickHandler = function( event ) {
+ defaultIsPrevented = !!event.isDefaultPrevented();
+ if ( event.target === theLink[ 0 ] ) {
+ event.preventDefault();
+ }
+ };
+
+ $.mobile.document.one( "click", theClickHandler );
+
+ $( "#goToGoogle" ).click();
+
+ $.mobile.document.off( "click", theClickHandler );
+
+ deepEqual( defaultIsPrevented, false,
+ "Default is not prevented when clicking on external link with hash" );
+ });
+
module('jquery.mobile.navigation.js', {
setup: function() {
$.mobile.navigate.history.stack = [];

0 comments on commit 4813c33

Please sign in to comment.