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

Commit

Permalink
Target attrs trigger now open a new window. Fixes #427
Browse files Browse the repository at this point in the history
  • Loading branch information
scottjehl committed Nov 10, 2010
1 parent a0940dd commit ad2c894
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions js/jquery.mobile.js
Expand Up @@ -205,8 +205,11 @@
var $this = $(this),
//get href, remove same-domain protocol and host
href = $this.attr( "href" ).replace( location.protocol + "//" + location.host, ""),
//if target attr is specified, it's external, and we mimic _blank... for now
target = $this.is( "[target]" ),
//if it still starts with a protocol, it's external, or could be :mailto, etc
external = /^(:?\w+:)/.test( href ) || $this.is( "[target],[rel=external]" );
external = target || /^(:?\w+:)/.test( href ) || $this.is( "[rel=external]" ),
target = $this.is( "[target]" );

if( href === '#' ){
//for links created purely for interaction - ignore
Expand All @@ -216,8 +219,16 @@
$activeClickedLink = $this.closest( ".ui-btn" ).addClass( $.mobile.activeBtnClass );

if( external || !$.mobile.ajaxLinksEnabled ){
//remove active link class if external
removeActiveLinkClass(true);

//deliberately redirect, in case click was triggered
location.href = href;
if( target ){
window.open(href);
}
else{
location.href = href;
}
}
else {
//use ajax
Expand Down Expand Up @@ -622,8 +633,6 @@
$html.removeClass('ui-mobile-rendering');
});

$window
.load(hideBrowserChrome)
.unload(removeActiveLinkClass);
$window.load(hideBrowserChrome);

})( jQuery, this );

0 comments on commit ad2c894

Please sign in to comment.