Skip to content

Instantly share code, notes, and snippets.

@srobbin
Created March 19, 2013 13:06
Show Gist options
  • Save srobbin/5195948 to your computer and use it in GitHub Desktop.
Save srobbin/5195948 to your computer and use it in GitHub Desktop.
jQuery Plugin Workshop Adding in Options
<h2>Antispam</h2>
<p>Email me at <span class="antispam">scott at-symbol robbin dot co</span></p>
// 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 "});
@import "compass";
body { padding: 10px; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment