25
25
var counterText = base . options . countDown ? base . options . countDownText : base . options . counterText ,
26
26
counterNum = base . options . countDown ? base . options . max : 0 ;
27
27
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 ) ;
29
31
30
32
// bind input events
31
33
base . $el . bind ( 'keyup.textcounter click.textcounter blur.textcounter focus.textcounter change.textcounter paste.textcounter' , base . checkLimits ) . trigger ( 'click.textcounter' ) ;
36
38
37
39
base . checkLimits = function ( e ) {
38
40
var $this = base . $el ,
39
- $countEl = $this . nextAll ( '.' + base . options . countContainerClass ) ,
41
+ $countEl = base . $container ,
40
42
$text = $this . val ( ) ,
41
43
textCount = 0 ,
42
44
textTotalCount = 0 ,
74
76
base . options . max = max ;
75
77
}
76
78
else {
77
- base . $el . nextAll ( '.' + base . options . countContainerClass ) . text ( 'error: [maxlength] attribute not set' ) ;
79
+ base . $container . text ( 'error: [maxlength] attribute not set' ) ;
78
80
}
79
81
}
80
82
157
159
} ;
158
160
159
161
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 ) ;
164
163
} ;
165
164
166
165
base . setErrors = function ( type ) {
167
166
var $this = base . $el ,
168
- $countEl = $this . nextAll ( '.' + base . options . countContainerClass ) ;
167
+ $countEl = $base . $container ;
169
168
170
169
$this . addClass ( base . options . inputErrorClass ) ;
171
170
$countEl . addClass ( base . options . counterErrorClass ) ;
188
187
189
188
base . clearErrors = function ( type ) {
190
189
var $this = base . $el ,
191
- $countEl = $this . nextAll ( '.' + base . options . countContainerClass ) ;
190
+ $countEl = base . $container ;
192
191
193
192
$countEl . children ( '.error-text-' + type ) . remove ( ) ;
194
193
236
235
} ) ;
237
236
} ;
238
237
239
- } ) ( jQuery ) ;
238
+ } ) ( jQuery ) ;
0 commit comments