Skip to content

Instantly share code, notes, and snippets.

@maxcal
Created January 16, 2012 10:08
Show Gist options
  • Select an option

  • Save maxcal/1620108 to your computer and use it in GitHub Desktop.

Select an option

Save maxcal/1620108 to your computer and use it in GitHub Desktop.
Rot13 email
/**
* @name Newletter transfer
* @package P3 / Main
* @author Max Calabrese <max.calabrese@greenpeace.org>
* @copyright Greenpeace Nordic
*/
/**
* Used for transfering an email address via the url hash
*/
/**
* @return void
*/
Main.getEmailFromHash = function(){
var hash = window.location.hash,
$emailInput = $("input[id*='txtEmail']");
/**
* Decodes a rot13 encoded string
* @param string str
*/
function rot13decode(str) {
return str.replace(/[a-zA-Z]/g, function(c) {
return String.fromCharCode((c <= 'Z' ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26);
});
}
// Insert email into text field
if (hash && $emailInput.length > 0 && !$emailInput.val().length){
hash = hash.replace('#', '');
$emailInput.val( unescape( rot13decode(hash) ) );
}
// Show flash message?
$('#language-notice').delay(800).show('fast');
}
jQuery(document).ready(function($) {
Main.getEmailFromHash();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment