@@ -10,23 +10,34 @@ Util.History = u.h = new function() {
1010 // create central navigate function
1111 // update hash/url
1212 this . navigate = function ( url , node , silent ) {
13- // u.bug("u.h.navigate:" + url + ", " + ( node ? u.nodeId(node) : "no node"))
13+ // u.bug("u.h.navigate:" + url, node);
1414
1515 silent = silent || false ;
1616
17- // popstate handling
18- if ( this . popstate ) {
19- history . pushState ( { } , url , url ) ;
20- if ( ! silent ) {
21- this . callback ( url ) ;
17+ // Don't navigate external links
18+ if ( ( ! url . match ( / ^ h t t p [ s ] ? \: \/ \/ / ) || url . match ( document . domain ) ) && ( ! node || ! node . _a || ! node . _a . target ) ) {
19+ // popstate handling
20+ if ( this . popstate ) {
21+ history . pushState ( { } , url , url ) ;
22+ if ( ! silent ) {
23+ this . callback ( url ) ;
24+ }
25+ }
26+ // hash handling
27+ else {
28+ if ( silent ) {
29+ this . next_hash_is_silent = true ;
30+ }
31+ location . hash = u . h . getCleanUrl ( url ) ;
2232 }
2333 }
24- // hash handling
2534 else {
26- if ( silent ) {
27- this . next_hash_is_silent = true ;
35+ if ( ! node || ! node . _a || ! node . _a . target ) {
36+ location . href = url ;
37+ }
38+ else {
39+ window . open ( this . url ) ;
2840 }
29- location . hash = u . h . getCleanUrl ( url ) ;
3041 }
3142
3243 }
@@ -205,7 +216,7 @@ Util.History = u.h = new function() {
205216// u.bug("getCleanUrl:" + string + " = " + (string ? string.replace(location.protocol+"//"+document.domain, "").match(/[^#$]+/) : "#error#"));
206217
207218 // remove hash and domain from string before
208- string = string . replace ( location . protocol + "//" + document . domain , "" ) . match ( / [ ^ # $ ] + / ) [ 0 ] ;
219+ string = string . replace ( location . protocol + "//" + document . domain , "" ) ? string . replace ( location . protocol + "//" + document . domain , "" ) . match ( / [ ^ # $ ] + / ) [ 0 ] : "/" ;
209220
210221 if ( ! levels ) {
211222 return string ;
0 commit comments