Skip to content

Instantly share code, notes, and snippets.

@thomasbennett
Created March 21, 2013 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasbennett/5216570 to your computer and use it in GitHub Desktop.
Save thomasbennett/5216570 to your computer and use it in GitHub Desktop.
var editInPlace = $('a.edit');
editInPlace.on('focus', 'input, textarea', function(){
t.parents('a.edit').toggleClass('edited');
}).on('blur', 'input, textarea', function() {
var t = $(this);
if ( t.val() != '' || t.text() != '' ) {
t.parents('a.edit').addClass('edited');
} else {
t.parents('a.edit').removeClass('edited');
}
});
editInPlace.each(function(){
t = $(this);
if ( t.find('input, textarea').val() != '' ) {
t.addClass('edited');
}
});
editInPlace.on('keypress', 'input, textarea', function() {
this.style.width = ((this.value.length + 1) * 8) + 'px';
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment