Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 30 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,32 +109,37 @@ Fires when counter is under min limit.
## Options

```javascript
type : "character", // "character" or "word"
min : 0, // minimum number of characters/words
max : 200, // maximum number of characters/words, -1 for unlimited, 'auto' to use maxlength attribute
countContainerElement : "div", // HTML element to wrap the text count in
countContainerClass : "text-count-wrapper", // class applied to the countContainerElement
textCountClass : "text-count", // class applied to the counter length
inputErrorClass : "error", // error class appended to the input element if error occurs
counterErrorClass : "error", // error class appended to the countContainerElement if error occurs
counterText : "Total Count: %d", // counter text, %d replaced with count value
errorTextElement : "div", // error text element
minimumErrorText : "Minimum not met", // error message for minimum not met,
maximumErrorText : "Maximum exceeded", // error message for maximum range exceeded,
displayErrorText : true, // display error text messages for minimum/maximum values
stopInputAtMaximum : true, // stop further text input if maximum reached
countSpaces : false, // count spaces as character (only for "character" type)
countDown : false, // if the counter should deduct from maximum characters/words rather than counting up
countDownText : "Remaining: %d", // count down text, %d replaced with remaining value
countExtendedCharacters : false, // count extended UTF-8 characters as 2 bytes (such as Chinese characters)
twoCharCarriageReturn : false, // count carriage returns/newlines as 2 characters
type : "character", // "character" or "word"
min : 0, // minimum number of characters/words
max : 200, // maximum number of characters/words, -1 for unlimited, 'auto' to use maxlength attribute, 'autocustom' to use a custom attribute for the length (must set "autoCustomAttr")
autoCustomAttr : "counterlimit", // custom attribute name with the counter limit if the max is 'autocustom'
countContainerElement : "div", // HTML element to wrap the text count in
countContainerClass : "text-count-wrapper", // class applied to the countContainerElement
textCountMessageClass : "text-count-message", // class applied to the counter message
textCountClass : "text-count", // class applied to the counter length (the count number)
inputErrorClass : "error", // error class appended to the input element if error occurs
counterErrorClass : "error", // error class appended to the countContainerElement if error occurs
counterText : "Total Count: %d", // counter text
errorTextElement : "div", // error text element
minimumErrorText : "Minimum not met", // error message for minimum not met,
maximumErrorText : "Maximum exceeded", // error message for maximum range exceeded,
displayErrorText : true, // display error text messages for minimum/maximum values
stopInputAtMaximum : true, // stop further text input if maximum reached
countSpaces : false, // count spaces as character (only for "character" type)
countDown : false, // if the counter should deduct from maximum characters/words rather than counting up
countDownText : "Remaining: %d", // count down text
countExtendedCharacters : false, // count extended UTF-8 characters as 2 bytes (such as Chinese characters)
twoCharCarriageReturn : false, // count carriage returns/newlines as 2 characters
countOverflow : false, // display text overflow element
countOverflowText : "Maximum %type exceeded by %d", // count overflow text
countOverflowContainerClass : "text-count-overflow-wrapper", // class applied to the count overflow wrapper

// Callback API
maxunder : function(el){}, // Callback: function(element) - Fires when counter is under max limit
minunder : function(el){}, // Callback: function(element) - Fires when counter is under min limit
maxcount : function(el){}, // Callback: function(element) - Fires when the counter hits the maximum word/character count
mincount : function(el){}, // Callback: function(element) - Fires when the counter hits the minimum word/character count
init : function(el){} // Callback: function(element) - Fires after the counter is initially setup
maxunder : function(el){}, // Callback: function(element) - Fires when counter is under max limit
minunder : function(el){}, // Callback: function(element) - Fires when counter is under min limit
maxcount : function(el){}, // Callback: function(element) - Fires when the counter hits the maximum word/character count
mincount : function(el){}, // Callback: function(element) - Fires when the counter hits the minimum word/character count
init : function(el){} // Callback: function(element) - Fires after the counter is initially setup
```

## Development
Expand All @@ -159,4 +164,4 @@ init : function(el){} // Callback: function(element
- [juliovedovatto](https://github.com/juliovedovatto) / [alvaro-canepa](https://github.com/alvaro-canepa) - multiple classes support for counter container
- [dtipson](https://github.com/dtipson) - multiple classes error fix
- [jmichalicek](https://github.com/jmichalicek) - count carriage returns/newlines as 2 characters
- [diptopol](https://github.com/diptopol) - `stopInputAtMaximum` with `twoCharCarriageReturn` count fix, trimmed newline calculation fix, maximum text reached condition fix, text count overflow notification
- [diptopol](https://github.com/diptopol) - `stopInputAtMaximum` with `twoCharCarriageReturn` count fix, trimmed newline calculation fix, maximum text reached condition fix, text count overflow notification
13 changes: 12 additions & 1 deletion textcounter.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@
base.$container.text('error: [maxlength] attribute not set');
}
}
else if (base.options.max == 'autocustom') {
var max = base.$el.attr(base.options.autoCustomAttr);

if (typeof max !== 'undefined' && max !== false) {
base.options.max = max;
}
else {
base.$container.text('error: [' + base.options.autoCustomAttr + '] attribute not set');
}
}

// if this is a countdown counter deduct from the max characters/words
textTotalCount = base.options.countDown ? base.options.max - textCount : textCount;
Expand Down Expand Up @@ -294,7 +304,8 @@
$.textcounter.defaultOptions = {
'type' : "character", // "character" or "word"
'min' : 0, // minimum number of characters/words
'max' : 200, // maximum number of characters/words, -1 for unlimited, 'auto' to use maxlength attribute
'max' : 200, // maximum number of characters/words, -1 for unlimited, 'auto' to use maxlength attribute, 'autocustom' to use a custom attribute for the length (must set "autoCustomAttr")
'autoCustomAttr' : "counterlimit", // custom attribute name with the counter limit if the max is 'autocustom'
'countContainerElement' : "div", // HTML element to wrap the text count in
'countContainerClass' : "text-count-wrapper", // class applied to the countContainerElement
'textCountMessageClass' : "text-count-message", // class applied to the counter message
Expand Down
2 changes: 1 addition & 1 deletion textcounter.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.