Skip to content

Commit 4dac259

Browse files
committed
Merge pull request #36, minor adjustments
1 parent 3893371 commit 4dac259

File tree

6 files changed

+49
-50
lines changed

6 files changed

+49
-50
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,4 @@ init : function(el){} // Callback: function(element
159159
- [juliovedovatto](https://github.com/juliovedovatto) / [alvaro-canepa](https://github.com/alvaro-canepa) - multiple classes support for counter container
160160
- [dtipson](https://github.com/dtipson) - multiple classes error fix
161161
- [jmichalicek](https://github.com/jmichalicek) - count carriage returns/newlines as 2 characters
162-
- [diptopol](https://github.com/diptopol) - `stopInputAtMaximum` with `twoCharCarriageReturn` count fix, trimmed newline calculation fix, maximum text reached condition fix
162+
- [diptopol](https://github.com/diptopol) - `stopInputAtMaximum` with `twoCharCarriageReturn` count fix, trimmed newline calculation fix, maximum text reached condition fix, text count overflow notification

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jquery-text-counter",
3-
"version": "0.6.4",
3+
"version": "0.7.0",
44
"main": "textcounter.js",
55
"license": "MIT",
66
"ignore": [

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"minimum",
1212
"maximum"
1313
],
14-
"version": "0.6.4",
14+
"version": "0.7.0",
1515
"author": {
1616
"name": "ractoon",
1717
"url": "http://www.ractoon.com"

textcounter.jquery.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"minimum",
1010
"maximum"
1111
],
12-
"version": "0.6.4",
12+
"version": "0.7.0",
1313
"author": {
1414
"name": "ractoon",
1515
"url": "http://www.ractoon.com"

textcounter.js

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* jQuery Text Counter Plugin v0.6.4
2+
* jQuery Text Counter Plugin v0.7.0
33
* https://github.com/ractoon/jQuery-Text-Counter
44
*
55
* Copyright 2014 ractoon
@@ -24,9 +24,9 @@
2424
// append the count element
2525
var counterText = base.options.countDown ? base.options.countDownText : base.options.counterText,
2626
counterNum = base.options.countDown ? base.options.max : 0,
27-
$formatted_counter_text = $('<div/>').addClass('text-counter-div')
27+
$formatted_counter_text = $('<div/>').addClass(base.options.textCountMessage)
2828
.html(counterText.replace('%d', '<span class="' + base.options.textCountClass + '">' + counterNum + '</span>')),
29-
$count_overflow_text = $('<div/>').addClass(base.options.countOverflowTextCss);
29+
$count_overflow_text = $('<div/>').addClass(base.options.countOverflowContainerClass);
3030

3131
base.hideMessage($count_overflow_text);
3232

@@ -229,16 +229,16 @@
229229

230230
switch(type) {
231231
case 'min':
232-
errorText = base.options.minimumErrorText;
233-
break;
232+
errorText = base.options.minimumErrorText;
233+
break;
234234
case 'max':
235-
errorText = base.options.maximumErrorText;
235+
errorText = base.options.maximumErrorText;
236236

237-
if (base.options.countOverflow) {
238-
base.setOverflowMessage();
239-
}
237+
if (base.options.countOverflow) {
238+
base.setOverflowMessage();
239+
}
240240

241-
break;
241+
break;
242242
}
243243

244244
if (base.options.displayErrorText) {
@@ -249,21 +249,20 @@
249249
};
250250

251251
base.setOverflowMessage = function () {
252-
base.hideMessage(base.$container.find('.text-counter-div'));
252+
base.hideMessage(base.$container.find('.' + base.options.textCountMessage));
253253

254254
base.removeOverflowMessage();
255255

256256
var overflowText = base.options.countOverflowText
257257
.replace('%d', base.textCount(base.$el.val()) - base.options.max)
258-
.replace('%type', base.options.type);
258+
.replace('%type', base.options.type + 's');
259259

260-
261-
var overflowDiv = base.$container.find('.' + base.options.countOverflowTextCss).append(overflowText);
260+
var overflowDiv = base.$container.find('.' + base.options.countOverflowContainerClass).append(overflowText);
262261
base.showMessage(overflowDiv);
263262
},
264263

265264
base.removeOverflowMessage = function () {
266-
base.$container.find('.' + base.options.countOverflowTextCss).empty();
265+
base.$container.find('.' + base.options.countOverflowContainerClass).empty();
267266
},
268267

269268
base.showMessage = function ($selector) {
@@ -274,7 +273,6 @@
274273
$selector.css('display', 'none');
275274
},
276275

277-
278276
base.clearErrors = function(type) {
279277
var $this = base.$el,
280278
$countEl = base.$container;
@@ -283,7 +281,7 @@
283281

284282
if ($countEl.children('.error-text').length == 0) {
285283
base.removeOverflowMessage();
286-
base.showMessage(base.$container.find('.text-counter-div'));
284+
base.showMessage(base.$container.find('.' + base.options.textCountMessage));
287285
$this.removeClass(base.options.inputErrorClass);
288286
$countEl.removeClass(base.options.counterErrorClass);
289287
}
@@ -294,35 +292,36 @@
294292
};
295293

296294
$.textcounter.defaultOptions = {
297-
'type' : "character", // "character" or "word"
298-
'min' : 0, // minimum number of characters/words
299-
'max' : 200, // maximum number of characters/words, -1 for unlimited, 'auto' to use maxlength attribute
300-
'countContainerElement' : "div", // HTML element to wrap the text count in
301-
'countContainerClass' : "text-count-wrapper", // class applied to the countContainerElement
302-
'textCountClass' : "text-count", // class applied to the counter length
303-
'inputErrorClass' : "error", // error class appended to the input element if error occurs
304-
'counterErrorClass' : "error", // error class appended to the countContainerElement if error occurs
305-
'counterText' : "Total Count: %d", // counter text
306-
'errorTextElement' : "div", // error text element
307-
'minimumErrorText' : "Minimum not met", // error message for minimum not met,
308-
'maximumErrorText' : "Maximum exceeded", // error message for maximum range exceeded,
309-
'displayErrorText' : true, // display error text messages for minimum/maximum values
310-
'stopInputAtMaximum' : true, // stop further text input if maximum reached
311-
'countSpaces' : false, // count spaces as character (only for "character" type)
312-
'countDown' : false, // if the counter should deduct from maximum characters/words rather than counting up
313-
'countDownText' : "Remaining: %d", // count down text
314-
'countExtendedCharacters' : false, // count extended UTF-8 characters as 2 bytes (such as Chinese characters)
315-
'twoCharCarriageReturn' : false, // count carriage returns/newlines as 2 characters
316-
'countOverflow' : false, // count text overflow
317-
'countOverflowText' : "About %d extra %type(s) have been entered", // text message for count overflow
318-
'countOverflowTextCss' : "text-overflow-div", // css for overflow text count
295+
'type' : "character", // "character" or "word"
296+
'min' : 0, // minimum number of characters/words
297+
'max' : 200, // maximum number of characters/words, -1 for unlimited, 'auto' to use maxlength attribute
298+
'countContainerElement' : "div", // HTML element to wrap the text count in
299+
'countContainerClass' : "text-count-wrapper", // class applied to the countContainerElement
300+
'textCountMessage' : "text-count-message", // class applied to the counter message
301+
'textCountClass' : "text-count", // class applied to the counter length (the count number)
302+
'inputErrorClass' : "error", // error class appended to the input element if error occurs
303+
'counterErrorClass' : "error", // error class appended to the countContainerElement if error occurs
304+
'counterText' : "Total Count: %d", // counter text
305+
'errorTextElement' : "div", // error text element
306+
'minimumErrorText' : "Minimum not met", // error message for minimum not met,
307+
'maximumErrorText' : "Maximum exceeded", // error message for maximum range exceeded,
308+
'displayErrorText' : true, // display error text messages for minimum/maximum values
309+
'stopInputAtMaximum' : true, // stop further text input if maximum reached
310+
'countSpaces' : false, // count spaces as character (only for "character" type)
311+
'countDown' : false, // if the counter should deduct from maximum characters/words rather than counting up
312+
'countDownText' : "Remaining: %d", // count down text
313+
'countExtendedCharacters' : false, // count extended UTF-8 characters as 2 bytes (such as Chinese characters)
314+
'twoCharCarriageReturn' : false, // count carriage returns/newlines as 2 characters
315+
'countOverflow' : false, // display text overflow element
316+
'countOverflowText' : "Maximum %type exceeded by %d", // count overflow text
317+
'countOverflowContainerClass' : "text-count-overflow-wrapper", // class applied to the count overflow wrapper
319318

320319
// Callback API
321-
'maxunder' : function(el){}, // Callback: function(element) - Fires when counter under max limit
322-
'minunder' : function(el){}, // Callback: function(element) - Fires when counter under min limit
323-
'maxcount' : function(el){}, // Callback: function(element) - Fires when the counter hits the maximum word/character count
324-
'mincount' : function(el){}, // Callback: function(element) - Fires when the counter hits the minimum word/character count
325-
'init' : function(el){} // Callback: function(element) - Fires after the counter is initially setup
320+
'maxunder' : function(el){}, // Callback: function(element) - Fires when counter under max limit
321+
'minunder' : function(el){}, // Callback: function(element) - Fires when counter under min limit
322+
'maxcount' : function(el){}, // Callback: function(element) - Fires when the counter hits the maximum word/character count
323+
'mincount' : function(el){}, // Callback: function(element) - Fires when the counter hits the minimum word/character count
324+
'init' : function(el){} // Callback: function(element) - Fires after the counter is initially setup
326325
};
327326

328327
$.fn.textcounter = function(options) {

0 commit comments

Comments
 (0)