-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjquery.pineput.js
executable file
·57 lines (47 loc) · 1.61 KB
/
jquery.pineput.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
(function($) {
$.fn.pineput = function() {
var $this = $(this);
for (var i = 0; i < $this.length; i++) {
var $input_fields = $($this[i]).find('.input-field input:not([type="submit"]), .input-field textarea, .input-field select');
// TODO: custom selector for input fields property
// TODO: other form items like checkbox, radio button etc...
$input_fields.on('focus', function(e){
var $field = $(this).closest('.input-field');
$field.addClass('focus');
}).on('blur', function(e){
var $this = $(this);
var $field = $this.closest('.input-field');
$field.removeClass('focus');
var val = $this.val().trim();
if (val === '') {
$field.removeClass('active');
} else {
$field.addClass('active');
}
}).on('change', function(e){
var $this = $(this);
var $field = $this.closest('.input-field');
var val = $this.val().trim();
if (val === '') {
$field.removeClass('active');
if ($this.is('select')) {
$this.trigger('blur');
}
} else {
$field.addClass('active');
}
});
for (var j = 0; j < $input_fields.length; j++) {
var $input_field = $($input_fields[j]);
var $field = $input_field.closest('.input-field');
var val = $input_field.val().trim();
if (val === '') {
$field.removeClass('active');
} else {
$field.addClass('active');
}
}
$this.find('textarea').closest('.input-field').addClass('textarea');
}
}
})(jQuery);