Permalink
Browse files

Added: jquery.protectEmail.js, mit license

  • Loading branch information...
1 parent 7db6d88 commit b9f8dd45565a69aa0d3e957b007cad6ff261b0d9 @vokiel committed Jan 11, 2012
Showing with 78 additions and 2 deletions.
  1. +20 −0 MIT-LICENSE.txt
  2. +11 −2 README.md
  3. +47 −0 jquery.protectEmails.js
View
@@ -0,0 +1,20 @@
+Copyright (c) 2012 Robert Mikołajuk, http://vokiel.com/
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
View
@@ -1,12 +1,21 @@
protectEmails jQuery plugin
===========================
-This simple plugin protects emails on the page from being stollen by spam bots.
+This simple plugin protects emails on the page from being stollen by spam bots.
+Mostly every plugin uses `user [at] domain [dot] com` schema.
+This one is based on html5 data attribute with css content styling.
License: MIT
Usage
-----
-
+Add css rule (or leave this for plugin to do so)
+
+ <style type="text/css">
+ .email-protect:after {
+ content: attr(data-user) '@' attr(data-domain);
+ }
+ </style>
+
Create html element ( `span`, `p`, `strong` etc ) with data attributes:
<span data-user="admin" data-domain="example.com" class="protect-emails" />
@@ -0,0 +1,47 @@
+/*
+ * jQuery protectEmails plugin
+ * @requires jQuery v1.7 or later
+ * Version: 1.0
+ * Date: 2012 January
+ *
+ * Author Robert Mikołajuk
+ * Copyright (c) 2012, Robert Mikołajuk
+ * The MIT License
+ * Description and Demo: http://blog.vokiel.com/jquery-protectEmails-plugin
+ *
+ *
+ *
+ * HTML: <span data-user="admin" data-domain="example.com" class="protect-emails" />
+ * CSS: .email-protect:after { content: attr(data-user) '@' attr(data-domain); }
+ * JavaScript: $('span').filter('.protect-emails').protectEmails();
+ *
+ */
+;(function($){
+ /**
+ * Main function
+ */
+ $.fn.protectEmails = function( customOptions ) {
+
+ var options = $.extend({}, $.fn.protectEmails.defaultOptions, customOptions);
+
+ return this.on(options.action,function(){
+ var $this = $(this);
+ var data = $this.data();
+ if ( data && data.user && data.domain){
+ var email = data.user + '@' + data.domain;
+ var aclass = (data.aclass)? ' class="'+data.aclass+'"' : '';
+ var link = '<a href="mailto:' + email +'" title="' + email + '"'+ aclass +'>' + email + '</a>';
+ $this.replaceWith(link);
+ }
+ });
+ };
+
+ /**
+ * Default options
+ */
+ $.fn.protectEmails.defaultOptions = {
+ appendCss : true,
+ action : 'hover'
+ };
+
+})(jQuery);

0 comments on commit b9f8dd4

Please sign in to comment.