Skip to content
Open
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Simple usage:
Advanced usage:

$('#my_textarea').simplyCountable({
counter: '#counter',
counter: '#counter', //or $('#counter')
countType: 'characters',
maxCount: 140,
strictMax: false,
Expand All @@ -30,7 +30,7 @@ Advanced usage:

## Options

* `counter` - A jQuery selector to match the 'counter' element. Defaults to `#counter`.
* `counter` - A jQuery selector or jQuery object to match the 'counter' element. Defaults to `#counter`.
* `countType` - Select whether to count `characters` or `words`. Defaults to `characters`.
* `maxCount` - The maximum character (or word) count of the text input or textarea. Defaults to `140`.
* `strictMax` - Prevents the user from being able to exceed the `maxCount`. Defaults to `false`.
Expand Down
13 changes: 12 additions & 1 deletion jquery.simplyCountable.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,18 @@
return $(this).each(function(){

var countable = $(this);
var counter = $(options.counter);
var counter;

if (typeof(options.counter) == 'string'){
counter = $(options.counter);
}
else if (options.counter instanceof jQuery){
counter = options.counter;
}
else {
throw new Error("The counter option must be a jQuery selector or a jQuery object.");
}

if (!counter.length) { return false; }

var countCheck = function(){
Expand Down