Created
September 21, 2011 09:35
-
-
Save maxcal/1231659 to your computer and use it in GitHub Desktop.
PDF test regex
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.ready(function($){ | |
// Check for PDF links | |
$('a').each(function(){ | |
var pdfExt = /\.pdf$/i; | |
var href = $(this).attr('href'); | |
if ( pdfExt.test(href)) { | |
$(this).addClass('pdf'); | |
} | |
}); | |
// Google track PDFs | |
$('a.pdf').live('click', function($){ | |
var base_url, absolute_url; | |
// test for P3 env variable resources.baseurl | |
base_url = resources.baseurl || "http://www.greenpeace.org/international/"; | |
// Self-Invoking Function - returns abs | |
absolute_url = (function(url, base_url){ | |
if (url.charAt(0) === '/') { | |
url = base_url + url.substr(1); | |
} | |
return url; | |
}( $(this).attr('href'), base_url)); | |
// Push it too ye old google | |
_gaq.push(['_trackPageview', absolute_url]); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated with hook to auto register urls ending with PDF