-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.html
80 lines (71 loc) · 1.96 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no'>
<meta http-equiv='X-UA-Compatible' content='IE=edge' >
<meta charset='utf-8'>
<meta name='author' content='Andrei Kashcha'>
<title>Application state in query string</title>
</head>
<style type="text/css" media="screen">
body {
padding: 0;
margin: 0;
overflow: hidden;
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 40px;
}
* {
box-sizing: border-box;
}
.docs {
margin-top: 20px;
}
h2, h3 {
font-weight: normal;
}
a {
color: #42b983;
text-decoration: none;
}
.sample, .sample input {
font-size: 18px;
}
</style>
<body>
<h2>Query State</h2>
<h3>Simple application state in query string</h3>
<p>
Enter text below, and see how query string changes:
</p>
<p class='sample'>
Hello <input type='text' id='name' placeholder='enter text here' autofocus></input>
</p>
<h2 class='docs'>
<a href='https://github.com/anvaka/query-state'>API</a>
</h2>
<script src='dist/query-state.js'></script>
<script type='text/javascript' charset='utf-8'>
var inputText = document.getElementById('name')
var qs = queryState();
// Initialize input box with current app state:
updateInputBox(qs.get())
// and listen to all events from query state:
qs.onChange(updateInputBox);
// When input changes, we update query state too!
inputText.addEventListener('keyup', updateQueryState);
inputText.addEventListener('blur', updateQueryState);
inputText.addEventListener('keydown', updateQueryState);
function updateQueryState(e) {
qs.set('name', inputText.value);
}
function updateInputBox(appState) {
inputText.value = appState.name || '';
}
</script>
</body>
</html>