Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added: jquery.protectEmail.js, mit license

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

0 notes on commit b9f8dd4

Please sign in to comment.
Something went wrong with that request. Please try again.