Created
June 8, 2012 08:39
-
-
Save tomdrn/2894502 to your computer and use it in GitHub Desktop.
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
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