-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtmlUseful.js
More file actions
80 lines (68 loc) · 1.86 KB
/
htmlUseful.js
File metadata and controls
80 lines (68 loc) · 1.86 KB
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
export function create(type, classes, ...attributes){
return make(type, classes, attributes);
}
function make(type, classes, attributes){
const div = document.createElement(type);
if(classes != null) div.classList.add(classes);
for(let i = 0; i < attributes.length; i++){
if(attributes[i][0] === "BODY"){
div.body = attributes[i][1];
} else if(attributes[i][0] === "TEXT"){
div.appendChild(document.createTextNode(attributes[i][1]));
}
else if(attributes[i][0] === "CLASS") {
for(let c of attributes[i][1]){
div.classList.add(c);
}
}
else div.setAttribute(attributes[i][0], attributes[i][1]);
}
return div;
}
export function div(classes, ...attributes){
return make("div", classes, attributes);
}
export function strong(classes, body2){
return make("strong", classes, body(body2));
}
export function small(body2){
return make("small", null, body(body2));
}
export function btn(classes, ...attributes){
return make("input", classes, attributes);
}
export function button(classes, ...attributes){
return make("button", classes, attributes);
}
export function toast(...attributes){
return div("toast", attributes);
}
export function type(s){
return tag("type", s);
}
export function id(s){
return tag("id", s);
}
export function value(s){
return tag("value", s);
}
export function drag(s){
return tag("draggable", s);
}
export function body(s){
return tag("BODY", s);
}
export function extraClass(...s){
return ["CLASS", s];
}
function tag(tag, s){
return [tag, s];
}
export function text(s){
return tag("TEXT", s);
}
String.prototype.replaceAt = function (index, char) {
let a = this.split("");
a[index] = char;
return a.join("");
}