/* * LeaveNotice - plug in to notify users of leaving your site * Examples and documentation at: http://rewdy.com/tools/leavenotice-jquery-plugin * Version: 1.1.1 (09/27/2010) * Copyright (c) 2010 Andrew Meyer * Licensed under the MIT License: http://en.wikipedia.org/wiki/MIT_License * Requires: jQuery v1.4+ */ (function(jQuery){jQuery.fn.leaveNotice=function(opt){var defaults={siteName:window.location.href,exitMessage:"

You have requested a website outside of {SITENAME}.

Thank you for visiting.

",preLinkMessage:"

You will now be directed to:
{URL}

",linkString:"",timeOut:4000,overlayId:"ln-blackout",messageBoxId:"ln-messageBox",messageHolderId:"ln-messageHolder",displayUrlLength:50,overlayAlpha:0.3};var options=jQuery.extend(defaults,opt);return this.each(function(){el=jQuery(this);var url=el.attr('href');var ulen=options.displayUrlLength;if(url.length>=ulen){var suffix="..."}else{var suffix=""}var shortUrl=url.substr(0,ulen)+suffix;var title=el.attr('title');if(title!=""){var linkText=title}else if(title==""){var linkText=shortUrl}el.click(function(){jQuery('body').append('
');jQuery('body').append('
');if(options.overlayAlpha!==false){jQuery('#'+options.overlayId).css('opacity',options.overlayAlpha)}preFilteredContent=options.exitMessage+options.preLinkMessage;msgContent=preFilteredContent.replace(/\{URL\}/g,''+linkText+'');msgContent=msgContent.replace(/\{SITENAME\}/g,options.siteName);if(options.timeOut>0){msgContent+='

Cancel or press the ESC key.

'}else{msgContent+='

Click the link above to continue or Cancel

'}jQuery('#'+options.messageBoxId).append(msgContent);if(options.timeOut>0){leaveIn=setTimeout(function(){jQuery('#ln-cancelMessage').html('Loading...');window.location.href=url},options.timeOut)}else{leaveIn=false}jQuery('#ln-cancelLink').click(function(){closeDialog(options,leaveIn);return false});jQuery(document).bind('keyup',function(e){if(e.which==27){closeDialog(options,leaveIn)}});$(window).unload(function(){closeDialog(options,leaveIn)});return false})})};function closeDialog(options,timer){if(options.timeOut>0){clearTimeout(timer)}jQuery('#'+options.overlayId+', #'+options.messageHolderId).fadeOut('fast',function(){jQuery('#'+options.overlayId+', #'+options.messageHolderId).remove()});jQuery(document).unbind('keyup')}})(jQuery);