/** * AntiSpam mailto script * * * This JavaScript is part of Credox Framework [www.credox.org] * The script is freely distributable under the terms of an MIT-style license. * * * @author Hristo Drumev * @package framework * @copyright Hristo Drumev [www.hdrumev.com] * @version 0.4 / 31.08.2007 * * * @require Standard JS objects extensions [core.js] * @require object Event [object.event.js] * * * @usage: type mail links with '(at)' and '(dot)' instead of '@' and '.' * script automaticaly replace in mailto links '(at)' with '@' and '(dot)' with '.' * * is possible to define your custom replacements. add them as parameter of Credox.AntiSpam * possible types of search and replace are string and array * ex.: new Credox.AntiSpam( { search: 'to search', replace: 'to replace' } ); */ /** Credox.AntiSpam [class] */ Credox.AntiSpam = new Class(); // Standard settings Credox.AntiSpam.prototype.standardParams = { search : new Array( /\(at\)/i, /\(dot\)/i ), replace: new Array( '@', '.' ) } /** * Constructor * * @param Object params - Custom settings /see format from this.standardParams/ * @return void */ Credox.AntiSpam.prototype.create = function( params ) { for( var property in this.standardParams ) this[property] = this.standardParams[property]; if( typeof( this.search ) == 'string' ) { this.search = new Array( this.search ); this.replace = new Array( this.replace ); } if( !document.links ) // Safari document.links = document.getElementsByTagName( 'a' ); for( var i = document.links.length; i--; ) if( document.links[i].href && document.links[i].href.search( /mailto:/i ) == 0 ) { var link = document.links[i]; for( var j = this.search.length; j--; ) { link.href = link.href.replace( this.search[j], this.replace[j] ); if( link.title ) link.title = link.title.replace( this.search[j], this.replace[j] ); link.innerHTML = link.innerHTML.replace( this.search[j], this.replace[j] ); } } } // start script on DOM load Event.onDOMLoad( function() { new Credox.AntiSpam(); } );