var DirectMail = DirectMail || {}; DirectMail.parseQueryString = function() { var result = {}; var vars = window.location.search.substring(1).split("&"); for ( var i = 0; i < vars.length; i++ ) { var pair = vars[i].split("="); result[pair[0]] = unescape( pair[1] ); } return result; }; DirectMail.urlIsTrackable = function ( url ) { var a = document.createElement('a'); a.href = url; return ( a.protocol == 'http:' || a.protocol == 'https:' ); }; $(document).ready(function() { var pathComponents = window.location.pathname.split('/'); var params = DirectMail.parseQueryString(); var email = params['e']; var deliveryID = pathComponents[2]; var addressHistoryID = params['a'] || ''; var formID = params['f'] || ''; var shouldTrack = ( params['t'] == 1 ); var hostname = 'ethreemail.com'; var wasForwarded = ( params['fwd'] == 1 ); $("a[href='#web-version-url']").click(function() { var cleanURL = window.location.href.split('?')[0]; alert( "You are currently viewing the web version of this email.\n\nTo share, copy the following URL: " + cleanURL ); return false; }); if ( email && deliveryID ) { var $unsubscribeLinks = $("a[href='#unsubscribe-url']"); var $updateEmailAddressLinks = $("a[href='#update-email-address-url']"); $unsubscribeLinks.data( 'dm-intended-href', 'https://' + hostname + '/delivery-unsubscribe?d=' + deliveryID + '&e=' + email + '&a=' + addressHistoryID + '&f=' + formID ); $updateEmailAddressLinks.data( 'dm-intended-href', 'https://' + hostname + '/delivery-update-email?d=' + deliveryID + '&e=' + email + '&a=' + addressHistoryID + '&f=' + formID ); $("a[href='#forward-to-a-friend-url']").data( 'dm-intended-href', 'https://' + hostname + '/forward?d=' + deliveryID + '&e=' + email + '&f=' + formID ); if ( wasForwarded ) { $unsubscribeLinks.click(function(e) { alert( "Don't worry, you have not been subscribed to this mailing list. This email was forwarded to you by a friend." ); e.stopImmediatePropagation(); return false; }); $updateEmailAddressLinks.click(function(e) { alert( "You're not currently a member of this mailing list, so you can't update your email address. This email was forwarded to you by a friend." ); e.stopImmediatePropagation(); return false; }); } $("a[href]").click(function() { var intendedHREF = $(this).data( 'dm-intended-href' ); if ( !intendedHREF ) { intendedHREF = $(this).attr( 'href' ); } var redirect = intendedHREF; var linkID = $(this).data( 'dm-link-id' ); if ( shouldTrack && linkID && DirectMail.urlIsTrackable( redirect ) ) { redirect = 'https://' + hostname + '/click?u=' + encodeURIComponent( intendedHREF ) + '&i=' + linkID + '&d=' + deliveryID + '&e=' + email + '&a=' + addressHistoryID + '&f=' + formID; } window.location.href = redirect; return false; }); } });