Skip to content

Instantly share code, notes, and snippets.

@brandonkelly
Created January 21, 2010 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brandonkelly/283093 to your computer and use it in GitHub Desktop.
Save brandonkelly/283093 to your computer and use it in GitHub Desktop.
// 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