﻿/* LiteTest email encode
* Version 0.9
* Author Jonas Hagstedt
* URI: http://www.litetest.com/Resources.aspx/EmailEncode
* Released with the MIT License: http://www.opensource.org/licenses/mit-license.php
*/
(function ($) {
    $.fn.emailencode = function (options) {
        var settings = jQuery.extend({
            atsign: "*"
        }, options);

        return this.each(function () {

            var address = $.trim($(this).attr("href")).replace('/', ''); // The '/' replacement is due to TinyMCE apparently demanding there be a '/' at the beginning of a link
            var linkText = $.trim($(this).text());
            var formatedAddress = address.replace(settings.atsign, "@");
            $(this).attr("href", "mailto:" + formatedAddress);
            // check to see if the email address should be fixed in the link text as well
            if (address == linkText) {
                $(this).text(formatedAddress);
            }

        });
    };
})(jQuery);
