Skip to content

Commit 8dabc10

Browse files
authored
Merge pull request #20 from Konnng/master
Added support for multiple classes for container and text counter container
2 parents 8373ea6 + edd76b9 commit 8dabc10

File tree

2 files changed

+13
-24
lines changed

2 files changed

+13
-24
lines changed

textcounter.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
var counterText = base.options.countDown ? base.options.countDownText : base.options.counterText,
2626
counterNum = base.options.countDown ? base.options.max : 0;
2727

28-
base.$el.after('<' + base.options.countContainerElement + ' class="' + base.options.countContainerClass + '">' + counterText + '<span class="' + base.options.textCountClass + '">' + counterNum + '</span></' + base.options.countContainerElement + '>');
28+
base.$text_counter = $('<span />').addClass(base.options.textCountClass).text(counterNum);
29+
base.$container = $('<' + base.options.countContainerElement + '/>').addClass(base.options.countContainerClass).text(counterText).append(base.$text_counter);
30+
base.$el.after(base.$container);
2931

3032
// bind input events
3133
base.$el.bind('keyup.textcounter click.textcounter blur.textcounter focus.textcounter change.textcounter paste.textcounter', base.checkLimits).trigger('click.textcounter');
@@ -36,7 +38,7 @@
3638

3739
base.checkLimits = function(e) {
3840
var $this = base.$el,
39-
$countEl = $this.nextAll('.' + base.options.countContainerClass),
41+
$countEl = base.$container,
4042
$text = $this.val(),
4143
textCount = 0,
4244
textTotalCount = 0,
@@ -74,7 +76,7 @@
7476
base.options.max = max;
7577
}
7678
else {
77-
base.$el.nextAll('.' + base.options.countContainerClass).text('error: [maxlength] attribute not set');
79+
base.$container.text('error: [maxlength] attribute not set');
7880
}
7981
}
8082

@@ -157,15 +159,12 @@
157159
};
158160

159161
base.setCount = function(count) {
160-
var $this = base.$el,
161-
$countEl = $this.nextAll('.' + base.options.countContainerClass);
162-
163-
$countEl.children('.' + base.options.textCountClass).text(count);
162+
base.$text_counter.text(count);
164163
};
165164

166165
base.setErrors = function(type) {
167166
var $this = base.$el,
168-
$countEl = $this.nextAll('.' + base.options.countContainerClass);
167+
$countEl = $base.$container;
169168

170169
$this.addClass(base.options.inputErrorClass);
171170
$countEl.addClass(base.options.counterErrorClass);
@@ -188,7 +187,7 @@
188187

189188
base.clearErrors = function(type) {
190189
var $this = base.$el,
191-
$countEl = $this.nextAll('.' + base.options.countContainerClass);
190+
$countEl = base.$container;
192191

193192
$countEl.children('.error-text-' + type).remove();
194193

@@ -236,4 +235,4 @@
236235
});
237236
};
238237

239-
})(jQuery);
238+
})(jQuery);

textcounter.min.js

Lines changed: 4 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)