Created
March 19, 2013 13:06
-
-
Save srobbin/5195948 to your computer and use it in GitHub Desktop.
jQuery Plugin Workshop
Adding in Options
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-symbol 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 (options) { | |
var settings = { | |
"@": " at ", | |
".": " dot " | |
}; | |
$.extend(settings, options); | |
return this.each(function () { | |
var $self = $(this); | |
// Get the text | |
var text = $self.text(); | |
// Replace "at" and "dot" | |
var email = text.replace(settings["@"], "@").replace(settings["."], "."); | |
// 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({"@": " at-symbol "}); |
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