Created
March 19, 2013 12:50
-
-
Save srobbin/5195840 to your computer and use it in GitHub Desktop.
jQuery Plugin Workshop
Antispam: Basic Plugin
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
<h2>Antispam</h2> | |
<p>Email me at <span class="antispam">scott at robbin dot co</span></p> |
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
// Clear the console | |
console.clear(); | |
// Plugin | |
(function ($) { | |
$.fn.antispam = function () { | |
return this.each(function () { | |
var $self = $(this); | |
// Get the text | |
var text = $self.text(); | |
// Replace "at" and "dot" | |
var email = text.replace(" at ", "@").replace(" dot ", "."); | |
// Create a link | |
var $link = $("<a></a>"); | |
$link.attr("href", "mailto:" + email); | |
$link.text(email); | |
// Replace the span with the link | |
$self.html( $link ); | |
}); | |
}; | |
})(jQuery); | |
$(".antispam").antispam(); |
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
@import "compass"; | |
body { padding: 10px; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment