From 575391b27f0b5b86d876a3c24ff2ca886184c713 Mon Sep 17 00:00:00 2001 From: Chris Date: Sat, 21 Mar 2015 22:09:12 -0400 Subject: [PATCH 1/3] jQuery .bind changed to .on Line 54 - minor efficiency update, faster to declare all vars outside of your loops. bindEvents() - Updated from .bind to .on - it appears your supporting jQuery 1.7.2 and up, so this should be fine since its supported 1.7+ --- jquery.charactercounter.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jquery.charactercounter.js b/jquery.charactercounter.js index e32cc25..0546330 100644 --- a/jquery.charactercounter.js +++ b/jquery.charactercounter.js @@ -49,9 +49,9 @@ function customFields(params) { - var html=''; + var i, html=''; - for (var i in params) + for (i in params) { html += ' ' + i + '="' + params[i] + '"'; } @@ -118,10 +118,10 @@ function bindEvents(element) { $(element) - .bind("keyup", function () { + .on("keyup", function () { checkCount(element); }) - .bind("paste", function () { + .on("paste", function () { var self = this; setTimeout(function () { checkCount(self); }, 0); }); From 641f5124c7012098f99ce7f72907db7628078a3e Mon Sep 17 00:00:00 2001 From: Chris Date: Sat, 21 Mar 2015 23:53:06 -0400 Subject: [PATCH 2/3] Validation element insertion breaks counter (because plugin is looking for $elem.next()) Modifying the plugin to look for the counterCssClass among $elem siblings instead of $elem.next() - this way if validation inserts an extra label, span, etc. the plugin won't break. --- jquery.charactercounter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jquery.charactercounter.js b/jquery.charactercounter.js index 0546330..2c1c316 100644 --- a/jquery.charactercounter.js +++ b/jquery.charactercounter.js @@ -87,7 +87,7 @@ function checkCount(element) { var characterCount = $(element).val().length; - var counter = options.counterSelector ? $(options.counterSelector) : $(element).next("." + options.counterCssClass); + var counter = options.counterSelector ? $(options.counterSelector) : $(element).siblings("." + options.counterCssClass); var remaining = options.limit - characterCount; var condition = remaining < 0; From 87b8f377e63549aa9e44e14ab3c2f751456cf9b6 Mon Sep 17 00:00:00 2001 From: Chris Date: Sat, 21 Mar 2015 23:57:38 -0400 Subject: [PATCH 3/3] Using .siblings() instead of next() The plugin currently looks for $elem.next() - when validation (or any other scripts) insert a new element (such as an error label) next to the