-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathfancyProps.js
executable file
·111 lines (97 loc) · 2.97 KB
/
fancyProps.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
var setify = require('setify'),
classist = require('classist');
function updateTextProperty(generic, element, value){
if(arguments.length === 2){
return element.textContent;
}
element.textContent = (value == null ? '' : value);
}
module.exports = {
class: function(generic, element, value){
if(!generic._classist){
generic._classist = classist(element);
}
if(arguments.length < 3){
return generic._classist();
}
generic._classist(value);
},
display: function(generic, element, value){
if(arguments.length === 2){
return element.style.display !== 'none';
}
element.style.display = value ? null : 'none';
},
disabled: function(generic, element, value){
if(arguments.length === 2){
return element.hasAttribute('disabled');
}
if(value){
element.setAttribute('disabled', 'disabled');
}else{
element.removeAttribute('disabled');
}
},
innerHTML: function(generic, element, value){
if(arguments.length === 2){
return element.innerHTML;
}
element.innerHTML = (value == null ? '' : value);
},
value: function(generic, element, value){
var inputType = element.type;
if(element.nodeName === 'INPUT' && inputType === 'date'){
if(arguments.length === 2){
return element.value ? new Date(element.value.replace(/-/g,'/').replace('T',' ')) : null;
}
value = value != null ? new Date(value) : null;
if(!value || isNaN(value)){
element.value = null;
}else{
element.value = [
value.getFullYear(),
('0' + (value.getMonth() + 1)).slice(-2),
('0' + value.getDate()).slice(-2)
].join('-');
}
return;
}
if(arguments.length === 2){
return element.value;
}
if(value === undefined){
value = null;
}
if(element.nodeName === 'PROGRESS'){
value = parseFloat(value) || 0;
}
setify(element, value);
},
max: function(generic, element, value) {
if(arguments.length === 2){
return element.value;
}
if(element.nodeName === 'PROGRESS'){
value = parseFloat(value) || 0;
}
element.max = value;
},
style: function(generic, element, value){
if(arguments.length === 2){
return element.style;
}
if(typeof value === 'string'){
element.style = value;
return;
}
for(var key in value){
element.style[key] = value[key];
}
},
type: function(generic, element, value){
if(arguments.length === 2){
return element.type;
}
element.setAttribute('type', value);
}
};