
/**
* Converts obfuscated email addresses into normal, working email addresses.
*
* @name defuscate
* @param Boolean link If true, all defuscated email addresses will be turned into links, defaults to true (optional)
* @descr Converts obfuscated email addresses into normal email addresses

This is a very simple plugin that allows you to hide email addresses from spambots while still being accessible. Visitors with JavaScript enabled browsers will see the email addresses correctly, while those without JavaScript will be provided with instructions for retrieving your email address. Spambots will see this same information, but won't know that it's an email address.

Obfuscate
For this plugin to defuscate email addresses, you first have to obfuscate them. This is very easy. Instead of writing name@example.com, you write:
name(put the 'at' sign here)example.com
What goes into the paranthese is up to you. You can even do:
name(replace this paranthese with the 'at' sign to get my email address)example.com

The Defuscator will recognize the obfuscated email address and defuscate it. This also works on mailto links

Example:

$('a').defuscate();

<a href="mailto:login##tutaj można wstawić cokolwiek##przyklad.com">login##tutaj można wstawić cokolwiek##przyklad.com</a>
*/

jQuery.fn.defuscate = function(settings)
{
	settings = jQuery.extend({ link: true }, settings);

	var regex = /\b([A-Z0-9._%-]+)##[^#]+##((?:[A-Z0-9-]+\.)+[A-Z]{2,6})\b/gi;

	return this.each(function()
	{
		if ($(this).is('a[@href]'))
		{
			// If it's an <a> element, defuscate the href attribute
			$(this).attr('href', $(this).attr('href').replace(regex, '$1@$2'));
			// Make sure that the element's contents is not made into a link
			var is_link = true;
			//alert($(this).attr('href'));
		}

		// Defuscate the element's contents
		$(this).html($(this).html().replace(regex, (settings.link && !is_link ? '<a href="mailto:$1@$2">$1@$2</a>' : '$1@$2')));
	});
};


