forked from Hube2/acf-input-counter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
acf-input-counter.js
43 lines (34 loc) · 880 Bytes
/
acf-input-counter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
(function($) {
acf.fields.text_counter = acf.field.extend({
type: 'text',
events: {
'input input': 'change_count',
},
change_count: function(e){
var $max = e.$el.attr('maxlength');
if (typeof($max) == 'undefined' || e.$el.closest('.acf-input').find('.count').length == 0) {
return;
}
var $value = e.$el.val();
var $length = $value.length;
e.$el.closest('.acf-input').find('.count').text($length);
},
});
})(jQuery);
(function($) {
acf.fields.textarea_counter = acf.field.extend({
type: 'textarea',
events: {
'input textarea': 'change_count',
},
change_count: function(e){
var $max = e.$el.attr('maxlength');
if (typeof($max) == 'undefined') {
return;
}
var $value = e.$el.val();
var $length = $value.length;
e.$el.closest('.acf-input').find('.count').text($length);
},
});
})(jQuery);