-
Notifications
You must be signed in to change notification settings - Fork 11
/
quest.orig.js
116 lines (85 loc) · 3.13 KB
/
quest.orig.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
112
113
114
115
116
console.log("quest.js loaded");
quest = function() {
//ini
};
quest.render = txt => {
var html = "";
var txt0 = txt;
// remove blocked out
txt = txt.replace(/\/\*[\s\S]+\*\//g, "");
txt = txt.replace(/\/\/.*\n/g, "");
// separate questions
txt = txt.split(/\n\n/).map(qq => {
qq = qq.split("\n");
if (qq.length > 1) {
html += `<div><b class="questionText">${qq[0]}</b>`;
qq.slice(1).forEach(q => {
html += `<p>${q}</p>`;
});
html += "</div>";
}
});
// ---- html elements ---- //
while (html.search(/\[[A-Z][A-Z0-9]+]/) != -1) {
let word = html.match(/\[[A-Z][A-Z0-9]+]/)[0];
html = html.replace("<div>", "<div id='" + word.substr(1, word.length - 2) + "' class='question'>");
html = html.replace(word, "")
}
while (html.search(/\[[a-z0-9][a-zA-Z0-9_]*]/) != -1) {
let term = html.match(/\[[a-z0-9][a-zA-Z0-9_]*]/)[0];
html = html.replace(term, "<input type='checkbox' value='" + term.substr(1, term.length - 2) + "'>")
html = html.replace(term, "")
}
while (html.search(/\([a-z0-9][a-zA-Z0-9]*\)/) != -1) {
let term = html.match(/\([a-z0-9][a-zA-Z0-9]*\)/)[0];
html = html.replace(term, "<input type='radio' value='" + term.substr(1, term.length - 2) + "'>")
html = html.replace(term, "")
}
html = html.replace(/\[DISPLAY \w*\]/g, "")
html = html.replace(/... GO TO /g, " -> ");
html = html.replace(/\* NO RESPONSE | NO RESPONSE/g, "");
// Create skip tags
const skips = html.match(/\* NO RESPONSE -> [A-Z0-9]+ | -> [A-Z0-9]+/g);
if (skips === null) {
null
} else {
for (i = 0; i < skips.length; i++) {
let word = skips[i];
html = html.replace(word, "<skip id='" + word.substr(4) + "'>");
}
}
// Check Box []
html = html.replace(/\*/g, "[]");
html = html.replace(/\[\]/g, '<input type="checkbox">');
// Radio Button ()
html = html.replace(/\(\)/g, '<input type="radio">');
// Year |__|__|__|__|
html = html.replace(/\|__\|__\|__\|__\|/g, "|_|");
// Age |__|__|
html = html.replace(/\|__\|__\|/g, "|_|");
// Integer |_|
html = html.replace(/\|_\|/g, "<input type='number'>");
// Regular input field |__|
html = html.replace(/\|__\|/g, "<input>");
// Text Area |___|
html = html.replace(/\[text box\]/g, "|___|");
html = html.replace(/\|___\|/g, "<textarea></textarea>");
// Phone Number |(###)-###-####|
html = html.replace(
/\|\(\###\)\-###-####\|/g,
"<input type='tel' id='phone' name='phone' pattern='(((d{3}) ?)|(d{3}-))?d{3}-d{4}'>"
);
// Social Security |###-##-####|
html = html.replace(
/\|###-##-####\|/g,
"<input type='tel' id='social' name='social' pattern='^(?!219099999|078051120)(?!666|000|9d{2})d{3}(?!00)d{2}(?!0{4})d{4}$'>"
);
return html + "<hr>"; //+txt0
};
quest.tout = function(fun, tt = 500) {
if (quest.tout.t) {
clearTimeout(quest.tout.t)
}
quest.tout.t = setTimeout(fun, tt)
}
class Questionnaire {}