- var counterBlackout = false;
-
- // count character on keyup
- function counter(event){
- if (maxLength <= 0) {
- return;
- }
- var currentLength = $("#notice_data-text").val().length;
- var remaining = maxLength - currentLength;
- var counter = $("#notice_text-count");
-
- if (remaining.toString() != counter.text()) {
- if (!counterBlackout || remaining == 0) {
- if (counter.text() != String(remaining)) {
- counter.text(remaining);
- }
-
- if (remaining < 0) {
- $("#form_notice").addClass("warning");
- } else {
- $("#form_notice").removeClass("warning");
- }
- // Skip updates for the next 500ms.
- // On slower hardware, updating on every keypress is unpleasant.
- if (!counterBlackout) {
- counterBlackout = true;
- window.setTimeout(clearCounterBlackout, 500);
- }
- }
- }
- }
-
- function clearCounterBlackout() {
- // Allow keyup events to poke the counter again
- counterBlackout = false;
- // Check if the string changed since we last looked
- counter(null);
- }
-
-
-
- // define maxLength if it wasn't defined already
-
- if (typeof(maxLength) == "undefined") {
- maxLength = 140;
- }
-
- if ($("#notice_data-text").length) {
- if (maxLength > 0) {
- $("#notice_data-text").bind("keyup", counter);
- // run once in case there's something in there
- counter();
- }