-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.js
155 lines (140 loc) · 3.7 KB
/
lib.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
Name: html-boilerplate-generator
Author: Alek Mugnozzo ([email protected])
Version: 1.1.1
File: lib.js (main JavaScript library)
License: GPLv3 (see "LICENSE" file)
Hosted at: https://github.com/mugnozzo/html-boilerplate-generator
*/
document.addEventListener("DOMContentLoaded", function(event) {
reload_result();
});
var t=document.getElementById.bind(document);
function reload_result(){
var title=t("title");
var description=t("description");
var charset=t("charset");
var css=t("css");
var css_dir=t("css-dir");
var js=t("js");
var js_dir=t("js-dir");
var favicon=t("favicon");
var bootstrap_css=t("bootstrap-css");
var bootstrap_js=t("bootstrap-js");
var bootstrap_columns=t("bootstrap-columns");
// Check checkbox dependencies
if(!css.checked){
css_dir.checked=false;
css_dir.disabled=true;
}
else{
css_dir.disabled=false;
}
if(!js.checked){
js_dir.checked=false;
js_dir.disabled=true;
}
else{
js_dir.disabled=false;
}
if(!bootstrap_css.checked){
bootstrap_js.checked=false;
bootstrap_js.disabled=true;
bootstrap_columns.disabled=true;
}
else{
bootstrap_js.disabled=false;
bootstrap_columns.disabled=false;
}
boilerplate='\
<!DOCTYPE html>\n\
<html>\n\
<head>\n\
<title>'+title.value+'</title>\n\
<meta charset="'+charset.value+'"/>\n\
<meta name="viewport" content="width=device-width,initial-scale=1" />\n\
<meta name="description" content="'+description.value+'"/>\n';
if(css.checked){
if(css_dir.checked){
boilerplate+=' <link rel="stylesheet" type="text/css" href="./css/style.css"/>\n';
}
else{
boilerplate+=' <link rel="stylesheet" type="text/css" href="./style.css"/>\n';
}
}
if(js.checked){
if(js_dir.checked){
boilerplate+=' <script src="./js/lib.js"></script>\n';
}
else{
boilerplate+=' <script src="./lib.js"></script>\n';
}
}
if(favicon.checked){
boilerplate+=' <link rel="icon" href="./favicon.png"/>\n';
}
if(bootstrap_css.checked){
boilerplate+='\
<link\n\
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"\n\
rel="stylesheet"\n\
integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65"\n\
crossorigin="anonymous"/>\n';
}
if(bootstrap_js.checked){
boilerplate+='\
<script\n\
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"\n\
integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4"\n\
crossorigin="anonymous"></script>\n';
}
boilerplate+='\
</head>\n\
<body>\n\
<div class="main-content">\n\
<h1>'+title.value+'</h1>\n';
var cols=bootstrap_columns.value;
if(bootstrap_columns.disabled==false && cols!=0){
boilerplate+='\
<div class="row">\n';
for(i=1;i<=cols;i++){
boilerplate+='\
<div class="col">\n\
Column '+i+'\n\
</div>\n';
}
boilerplate+='\
</div>\n';
}
boilerplate+='\
</div>\n\
</body>\n\
</html>';
boilerplate=escapeHtmlEntities(boilerplate);
boilerplate="<pre>"+boilerplate+"</pre>";
document.getElementById("result").innerHTML=boilerplate;
}
function escapeHtmlEntities(str){
return str
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
}
function copyResult(){
const divToCopy=document.getElementById("result");
const range=document.createRange();
range.selectNode(divToCopy);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
document.execCommand("copy");
window.getSelection().removeAllRanges();
showPopup();
}
function showPopup(){
document.getElementById("popup-container").classList.remove("hidden");
}
function hidePopup(){
document.getElementById("popup-container").classList.add("hidden");
}