forked from niklasvh/html2canvas
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
197 lines (139 loc) · 5.64 KB
/
index.html
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<header>
<img id="logo" src="logo.png">
</header>
<div class="container">
<h2 id="titulo">Gerador de Assinaturas</h2>
<br>
<form class="form-horizontal">
<div class="form-group">
<label for="nome" class="col-sm-2 control-label nome-form">Nome</label>
<div name="name" class="col-sm-10">
<input name="name" type="text" class="form-control" id="nome" placeholder="Seu nome" value="" autocomplete maxlength="50">
</div>
</div>
<div class="form-group">
<label for="cargo" class="col-sm-2 control-label nome-form">Cargo exercido</label>
<div class="col-sm-10">
<input name="cargo" type="text" class="form-control" id="cargo" placeholder="Seu cargo" value="" autocomplete maxlength="50">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="button" class="btn btn-default" onclick="gerar()"> Gerar Assinatura </button>
</div>
</div>
</form>
<div id="alertdiv" class="alert alert-dismissible hidden" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span>
</button> <span id="alerttext">Text</span>
</div>
<br>
<h4>Sua Assinatura</h2>
<div id="assinatura" class="well">
<div class="text-muted text-center small">
Clique no botão Gerar para criar uma assinatura
</div>
<script type="template/html" id="t2">
<footer id="teste">
<div style="font-family: Helvetica, Arial;" class="texto" id="texto-assinatura">
<p><h1 id="nome-p">{{this.nome}}</h1><br>
<h2 id="cargo-p">{{this.cargo}}</h2></p>
</div>
<div id="img-template">
<img src="template.png" alt="Rodapé: By Israel Rodrigues"/>
</div>
</footer>
</script>
</div>
</div>
<footer>
<div class="footer text-center text-muted small">By Israel Rodrigues</a> © 2016</div>
</footer>
<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script src="dist/html2canvas.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script type="text/javascript">
var template;
var dismiss;
window.onload = function() {
template = generateTemplate("#t2");
}
function gerar() {
var dados = {
nome: nome.value || "[Digite Nome]",
cargo: cargo.value || "[Digite Cargo]",
};
assinatura.innerHTML = template.apply(dados);
createSelection(assinatura);
html2canvas(document.querySelector("#teste"), {
onrendered: function(canvas) {
document.querySelector("#teste").appendChild(canvas);
},
width: 400
});
document.getElementById("img-template").style.display = 'none';
document.getElementById("texto-assinatura").style.display = 'none';
try {
var successful = document.execCommand('copy');
var msg = successful ? 'successful' : 'unsuccessful';
alerttext.innerHTML = ('Assinatura gerada com sucesso!');
alertdiv.classList.add("alert-success");
alertdiv.classList.remove("hidden");
} catch (err) {
alerttext.innerHTML = ('Aperte <code>CTRL+C</code> para copiar');
alertdiv.classList.add("alert-info");
alertdiv.classList.remove("hidden");
}
if (dismiss) clearTimeout(dismiss);
dismiss = setTimeout(function() {
alertdiv.classList.add("hidden");
}, 15000);
}
function createSelection(element) {
var selection = window.getSelection();
var range = document.createRange();
range.setStartBefore(element.firstChild);
range.setEndAfter(element.lastChild);
selection.removeAllRanges();
selection.addRange(range);
}
var compileTemplate = function(html) {
var re = /{{([^}]*(?:}[^}]+)*}*)}}/g,
reExp = /(^( )?(if|for|else|switch|case|break|{|}))(.*)?/g,
code = 'var r=[];\n',
cursor = 0,
match;
var add = function(line, js) {
js ? (code += line.match(reExp) ? line + '\n' : 'r.push(' + line + ');\n') : (code += line != '' ? 'r.push("' + line.replace(/"/g, '\\"') + '");\n' : '');
return add;
}
while (match = re.exec(html)) {
add(html.slice(cursor, match.index))(match[1], true);
cursor = match.index + match[0].length;
}
add(html.substr(cursor, html.length - cursor));
code += 'return r.join("");';
var template = new Function(code.replace(/[\r\t\n]/g, ''));
return template;
}
function generateTemplate(selector) {
var el = document.querySelector(selector);
if (el.type.toLowerCase() == "template/html") {
return compileTemplate(el.innerHTML);
} else throw Error("Type of '" + selector + "' is not a template/html");
}
</script>
</body>
</html>