-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
45 lines (44 loc) · 1.09 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>URL Shortener Prototype</title>
</head>
<body>
<h1>URL Shortener</h1>
<form id="form" method="PUT">
<input type="url" id="url" placeholder="Type url here...">
<input type="submit">
</form>
<dl id="results">
<script type="text/mustache-tempalte" id="result-row">
<dt>http://{{{ host }}}/{{{id}}}</dt>
<dd>{{{url}}}</dd>
</script>
</dl>
<script type="text/javascript" src="//code.jquery.com/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/mustache.js/0.8.1/mustache.min.js"></script>
<script type="text/javascript">
$.ajaxSetup({
url: "/"
});
var template = $("#result-row").html();
Mustache.parse(template); //speed up
$("#form").submit(function(event) {
event.preventDefault();
var url = $("#url").val();
$.ajax({
type: "PUT",
data: url,
success: function(result) {
$("#results").prepend(Mustache.render(template, {
host: location.host,
url: url,
id: result
}));
}
});
});
</script>
</body>
</html>