|
1 | 1 | /*! |
2 | | -* jQuery Text Counter Plugin v0.4.1 |
3 | 2 | * https://github.com/ractoon/jQuery-Text-Counter |
4 | 3 | * |
5 | 4 | * Copyright 2014 ractoon |
|
23 | 22 |
|
24 | 23 | // append the count element |
25 | 24 | var counterText = base.options.countDown ? base.options.countDownText : base.options.counterText, |
26 | | - counterNum = base.options.countDown ? base.options.max : 0; |
| 25 | + counterNum = base.options.countDown ? base.options.max : 0, |
| 26 | + $formatted_counter_text = $('<div/>').html(counterText.replace('%d', '<span class="' + base.options.textCountClass + '">' + counterNum + '</span>')).contents(); |
27 | 27 |
|
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); |
| 28 | + base.$container = $('<' + base.options.countContainerElement + '/>').addClass(base.options.countContainerClass).append($formatted_counter_text); |
| 29 | + base.$text_counter = base.$container.find('span'); |
30 | 30 | base.$el.after(base.$container); |
31 | 31 |
|
32 | 32 | // bind input events |
|
86 | 86 | // set the current text count |
87 | 87 | base.setCount(textTotalCount); |
88 | 88 |
|
89 | | - |
90 | 89 | if (base.options.min > 0 && eventTriggered) { // if a minimum value has been set |
91 | 90 | if (textCount < base.options.min) { |
92 | 91 | base.setErrors('min'); |
|
211 | 210 | 'textCountClass' : "text-count", // class applied to the counter length |
212 | 211 | 'inputErrorClass' : "error", // error class appended to the input element if error occurs |
213 | 212 | 'counterErrorClass' : "error", // error class appended to the countContainerElement if error occurs |
214 | | - 'counterText' : "Total Count: ", // counter text |
| 213 | + 'counterText' : "Total Count: %d", // counter text |
215 | 214 | 'errorTextElement' : "div", // error text element |
216 | 215 | 'minimumErrorText' : "Minimum not met", // error message for minimum not met, |
217 | 216 | 'maximumErrorText' : "Maximum exceeded", // error message for maximum range exceeded, |
218 | 217 | 'displayErrorText' : true, // display error text messages for minimum/maximum values |
219 | 218 | 'stopInputAtMaximum' : true, // stop further text input if maximum reached |
220 | 219 | 'countSpaces' : false, // count spaces as character (only for "character" type) |
221 | 220 | 'countDown' : false, // if the counter should deduct from maximum characters/words rather than counting up |
222 | | - 'countDownText' : "Remaining: ", // count down text |
| 221 | + 'countDownText' : "Remaining: %d", // count down text |
223 | 222 | 'countExtendedCharacters' : false, // count extended UTF-8 characters as 2 bytes (such as Chinese characters) |
224 | 223 |
|
225 | 224 | // Callback API |
|
0 commit comments