-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathgeneric_form_creation.js
More file actions
136 lines (112 loc) · 4.86 KB
/
Copy pathgeneric_form_creation.js
File metadata and controls
136 lines (112 loc) · 4.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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
var reg = (o, n) => o ? o[n] : '';
var cn = (o, s) => o ? o.getElementsByClassName(s) : [];
var tn = (o, s) => o ? o.getElementsByTagName(s) : [];
var gi = (o, s) => o ? o.getElementById(s) : null;
var ele = (t) => document.createElement(t);
var attr = (o, k, v) => o.setAttribute(k, v);
var a = (l, r) => r.forEach(a => attr(l, a[0], a[1]));
function dragElement() {
var el = this.parentElement;
var pos1 = 0,
pos2 = 0,
pos3 = 0,
pos4 = 0;
if (document.getElementById(this.id)) document.getElementById(this.id).onmousedown = dragMouseDown;
else this.onmousedown = dragMouseDown;
function dragMouseDown(e) {
pos3 = e.clientX;
pos4 = e.clientY;
document.onmouseup = closeDragElement;
document.onmousemove = elementDrag;
}
function elementDrag(e) {
pos1 = pos3 - e.clientX;
pos2 = pos4 - e.clientY;
pos3 = e.clientX;
pos4 = e.clientY;
el.style.top = (el.offsetTop - pos2) + "px";
el.style.left = (el.offsetLeft - pos1) + "px";
el.style.opacity = "0.85";
el.style.transition = "opacity 700ms";
}
function closeDragElement() {
document.onmouseup = null;
document.onmousemove = null;
el.style.opacity = "1";
}
}
function aninCloseBtn() {
var l1 = tn(this, 'path')[0];
var l2 = tn(this, 'path')[1];
l1.style.transform = "translate(49px, 50px) rotate(45deg) translate(-49px, -50px)";
l1.style.transition = "all 233ms";
l2.style.transform = "translate(49px, 50px) rotate(135deg) translate(-49px, -50px)";
l2.style.transition = "all 233ms";
}
function anoutCloseBtn() {
var l1 = tn(this, 'path')[0];
var l2 = tn(this, 'path')[1];
l1.style.transform = "translate(49px, 50px) rotate(225deg) translate(-49px, -50px)";
l1.style.transition = "all 233ms";
l2.style.transform = "translate(49px, 50px) rotate(225deg) translate(-49px, -50px)";
l2.style.transition = "all 233ms";
}
var svgs = {
close: `<svg x="0px" y="0px" viewBox="0 0 100 100"><g style="transform: scale(0.85, 0.85)" stroke-width="1" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"><g transform="translate(2, 2)" stroke="#e21212" stroke-width="8"><path d="M47.806834,19.6743435 L47.806834,77.2743435" transform="translate(49, 50) rotate(225) translate(-49, -50) "/><path d="M76.6237986,48.48 L19.0237986,48.48" transform="translate(49, 50) rotate(225) translate(-49, -50) "/></g></g></svg>`,
};
function createHTMLBox(){
if(gi(document,'test_box_container')) gi(document,'test_box_container').outerHTML = '';
var cont = ele('div');
document.body.appendChild(cont);
a(cont, [['id','test_box_container'],['style',`position: fixed; top: 10px; left: 10px; z-index: ${new Date().getTime()}; width: 400px; height: 300px;`]]);
var head = ele('div');
cont.appendChild(head);
a(head,[['style',`display: grid; grid-template-columns: 1fr 32px; grid-gap: 5px; background-color: #1c1c1c; color: #fff; cursor: move; border-top-left-radius: 0.4em; border-top-right-radius: 0.4em; `]]);
head.onmouseenter = dragElement;
var txt = ele('div');
head.appendChild(txt);
a(txt,[['style', 'padding: 8px;']]);
txt.innerText = 'Test Container';
var cls = ele('div');
head.appendChild(cls);
a(cls, [['style',`cursor: pointer;`]]);
cls.innerHTML = svgs.close;
cls.onclick = ()=> {cont.outerHTML = ''};
cls.onmouseenter = aninCloseBtn;
cls.onmouseleave = anoutCloseBtn;
var cbod = ele('div');
cont.appendChild(cbod);
a(cbod, [['style',`display: grid; grid-templete-rows: auto; grid-gap: 4px; background-color: #7c7c7c; padding: 8px;`]]);
addHTMLinputFields(cbod);
var send = ele('div');
a(send,[['style',`background-color: #004471; color: #fff; padding: 8px; text-align: center; border-radius: 0.4em; width: 100px; transform: translate(${(((400-16)-100) *0.5)}px, 0px); cursor: pointer;`]]);
cbod.appendChild(send);
send.innerText = 'Send Form';
send.onclick = sendFormData;
}
createHTMLBox()
function addHTMLinputFields(ref){
var inputs = ['First Name', 'Last Name', 'Phone Number', 'Email'];
inputs.forEach(i=> {
var inp = ele('input');
ref.appendChild(inp);
a(inp, [['class','form_inputs'],['placeholder',i],['style',`width: 100%; display: grid; grid-templete-rows: auto; grid-gap: 4px; border: 1px solid #7c7c7c; border-radius: 0.4em; padding: 8px;`]]);
});
}
function sendFormData(){
var inputs = Array.from(cn(document,'form_inputs')).map(v=> {return [v.getAttribute('placeholder'), v.value]});
var phone = inputs.filter(r=> r[0] == 'Phone Number')[0];
var email = inputs.filter(r=> r[0] == 'Email')[0];
var px = /\b[2-9]\d{2}\){0,1}\W{0,1}\d{3}\W{0,1}\d{4}\b/;
var ex = /\b[\w\.\-\+]+@[\w\-]+\.[a-zA-Z]{2,13}(\.[a-zA-Z]{2,13}|\b)/;
if(px.test(phone[1])){
console.log('saving phone');
}else{
alert('yo dawg. please enter a valid phone number.')
}
if(ex.test(email[1])){
console.log('saving email');
}else{
alert('yo dawg. please enter a valid email.')
}
}