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

Commit

Permalink
Navigation: Click handler correctly handles absolute URL with hash
Browse files Browse the repository at this point in the history
Closes gh-7632
Fixes gh-5759
  • Loading branch information
Gabriel Schulhof committed Aug 21, 2014
1 parent 529d3ca commit bdfe15d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
7 changes: 4 additions & 3 deletions js/navigation.js
Expand Up @@ -363,9 +363,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
Expand Down
1 change: 1 addition & 0 deletions tests/integration/navigation/index.html
Expand Up @@ -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">
Expand Down
20 changes: 20 additions & 0 deletions tests/integration/navigation/navigation_core.js
Expand Up @@ -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 = [];
Expand Down

0 comments on commit bdfe15d

Please sign in to comment.