Skip to content

Instantly share code, notes, and snippets.

@tomdrn
Created June 8, 2012 08:39
Show Gist options
  • Save tomdrn/2894502 to your computer and use it in GitHub Desktop.
Save tomdrn/2894502 to your computer and use it in GitHub Desktop.
var MAX_FACTFACT_CHAR = 40
$(".char-counter").html(MAX_FACTFACT_CHAR);
$("#fastfacts_list table input.fastfact-content").attr('maxlength', 40);
$("#fastfacts_list table:not(.hidden)").each(function(){
var counter = MAX_FACTFACT_CHAR - $(this).find('.fastfact-content').val().length;
$(this).find('.char-counter').html(counter);
});
$("#fastfacts_list table input.fastfact-content").on("focusin", function(){
$(this).parent().parent().find('.char-counter').show();
});
$("#fastfacts_list table input.fastfact-content").on("focusout", function(){
$(this).parent().parent().find('.char-counter').hide();
});
$("#fastfacts_list table input.fastfact-content").on("keypress", function(){
updateFastfactCharCounter($(this));
});
$("#fastfacts_list table input.fastfact-content").on("change", function(){
updateFastfactCharCounter($(this));
});
$("#fastfacts_list table input.fastfact-content").on("keyup", function(){
updateFastfactCharCounter($(this));
});
function updateFastfactCharCounter(item){
item.parent().parent().find('.char-counter').html(MAX_FACTFACT_CHAR - item.val().length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment