Created
January 28, 2011 16:43
-
-
Save devi/800524 to your computer and use it in GitHub Desktop.
hashbang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jquery hashbang(#!) | |
function hasbang(){ | |
$('a').each(function(){ | |
var o = $(this), url = o.attr('href'), p = url.match('^https?://'); | |
var h1 = location.hostname, h2 = h1.replace(/^www\./i,''); | |
if (url == '#') { | |
o.attr('href','javascript:void(0);'); | |
return; | |
} | |
if (url.match('^#!') || url.match('^javascript:')) | |
return; | |
if (!p || url.match(h1) || url.match(h2)){ | |
if (p){ | |
url = url.substr(p[0].length); | |
if(url.indexOf('/') != -1) | |
url = url.substr(url.indexOf('/')); | |
else | |
url = ''; | |
} | |
if (url.charAt(0) == '#') | |
return; | |
if (url.charAt(0) == '/') | |
url = url.substr(1); | |
if (!url){ | |
o.attr('href',location.protocol + '//'+ h1); | |
return; | |
} | |
url = '#!'+url.replace(/\#\!/g,''); | |
o.attr('href',url); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment