Created
April 16, 2012 14:32
-
-
Save lexander/2399151 to your computer and use it in GitHub Desktop.
.noDescription click handler fix
This file contains 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
$('.noDescription').live('click', function() { | |
var form = $('<div class="Form" id="editDescription"></div>'); | |
var textarea = $('<textarea></textarea>'); | |
var charCount = $('<div class="CharacterCount"></div>'); | |
var button = $('<a class="Button11 Button RedButton editDescription" href="#"><strong>Save Description</strong><span></span></a>'); | |
trackGAEvent('about_field', 'expanded', 'profile'); | |
form.append(textarea).append(button).append(charCount); | |
$('.noDescription').replaceWith(form); | |
collapseEditWebsite(); | |
collapseEditLocation(); | |
// Character count | |
CharacterCount.truncateData("#editDescription textarea", 200); | |
CharacterCount.setup('#editDescription textarea', '#editDescription .CharacterCount', '#editDescription .Button', 200); | |
textarea.focus(); | |
button.click(function() { | |
if (!button.hasClass('disabled')) { | |
var about = $('#editDescription textarea').val(); | |
trackGAEvent('about_field', 'clicked', 'profile'); | |
$.post('/settings/about/', | |
{ about : about }, | |
function(data) { | |
if (data.status == 'ok') { | |
trackGAEvent('about_field', 'success', 'profile'); | |
// create a 'p' tag & use text() to html-encode the | |
// string before redisplaying it to the user | |
$('#editDescription').replaceWith($("<p class='colormuted' />").text(about)); | |
// live version of the code below | |
//$('#editDescription').replaceWith('<p class="colormuted">' + about + '</p>'); | |
} | |
} | |
); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Small change to Pinterest's click handler for a user's description that properly encodes input to prevent malicious injections.