Created
January 16, 2009 17:41
-
-
Save aron/48026 to your computer and use it in GitHub Desktop.
Simple jQuery plugin to fill in mailto links.
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
$(document).ready(function(){ | |
$("a[href^=mailto]").emailSwitcher(); | |
}); | |
// Switches emails in the form <a href="mailto:">bill at ben dot com</a> | |
// to <a href="mailto:[email protected]">[email protected]</a>. | |
$.fn.emailSwitcher = function () { | |
var regex = /^([^\s]+)\s+at\s+([^\s]+)\s+dot\s+([^\s]+)$/gi; | |
this.each(function () { | |
var $this = $(this), | |
email; | |
if ($this.text().match(regex)) { | |
email = $(this).text().replace(regex, '$1@$2.$3'); | |
$this.attr('href', 'mailto:' + email).text(email); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment