Created
January 21, 2010 19:14
-
-
Save brandonkelly/283093 to your computer and use it in GitHub Desktop.
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
// P&T link automations | |
var ee_affiliate_name = 'brandonkelly', | |
external_re = new RegExp('^https?://(?!'+document.location.hostname+')'), | |
external_ee_re = new RegExp('^(https?://(secure\\.)?expressionengine.com\\/)([^#]*)(#(\\w+))?$'), | |
ee_affiliate_re = new RegExp('^index\\.php\\?affiliate='+ee_affiliate_name); | |
$('a').each(function(){ | |
// is this an external link? | |
if (this.href.match(external_re)) { | |
// enforce target="_blank" (take that Boyink!) | |
this.target = '_blank'; | |
$(this).addClass('external'); | |
// if this is a link to expressionengine.com | |
// but not already an affiliate link, convert it one | |
var href = this.href, | |
match = href.match(external_ee_re); | |
if (match && ! match[3].match(ee_affiliate_re)) { | |
this.href = match[1]+'index.php?affiliate='+ee_affiliate_name | |
+ (match[3] ? '&page=/'+match[3] : '') | |
+ (match[5] ? '&anchor='+match[5] : ''); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment