From 6639f1c6e7f152a141bab078d020eaa09bb2d7e4 Mon Sep 17 00:00:00 2001 From: Mark Moser Date: Thu, 1 Sep 2016 10:49:49 -0500 Subject: [PATCH] text counter refactor --- app/assets/javascripts/textarea-limit.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/textarea-limit.js b/app/assets/javascripts/textarea-limit.js index cf48d74..b325c60 100644 --- a/app/assets/javascripts/textarea-limit.js +++ b/app/assets/javascripts/textarea-limit.js @@ -1,21 +1,22 @@ $.fn.extend({ - characterLimiter: function(limit, $label) { - $(this).on("keyup focus show", function() { - setCount(this, $label); + characterLimiter: function(limit, label) { + this.on("keyup focus show", function() { + setCount(this, label); }); - // TODO: append label container after $this, instead of hard codeing - function setCount(src, $label) { + // TODO: append label container after $this, instead of hard HTML + function setCount(src, label) { if(src !== undefined) { var chars = src.value.length; if (chars >= limit) { src.value = src.value.substr(0, limit); chars = limit; } - $label.html(limit - chars); + label.html(limit - chars); } } - setCount($(this)[0], $label); + + setCount(this[0], label); } });