Created
January 16, 2012 10:08
-
-
Save maxcal/1620108 to your computer and use it in GitHub Desktop.
Rot13 email
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @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