forked from ampproject/amphtml
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautosuggest.amp.html
More file actions
138 lines (138 loc) · 4.71 KB
/
autosuggest.amp.html
File metadata and controls
138 lines (138 loc) · 4.71 KB
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
<!doctype html>
<html ⚡>
<head>
<meta charset="utf-8">
<title>AMP autosuggest Demo</title>
<link rel="canonical" href="amps.html">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Questrial" rel="stylesheet" type="text/css">
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-bind" src="https://cdn.ampproject.org/v0/amp-bind-0.1.js"></script>
<script async custom-element="amp-form" src="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script>
<script async custom-element="amp-list" src="https://cdn.ampproject.org/v0/amp-list-0.1.js"></script>
<script async custom-element="amp-selector" src="https://cdn.ampproject.org/v0/amp-selector-0.1.js"></script>
<script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-latest.js"></script>
<style amp-custom>
body {
padding: 10px;
}
.search-container {
display: flex;
flex-flow: row nowrap;
}
.search-box, .search-submit, .select-option {
font-size: 1.25em;
}
.autosuggest-box {
box-shadow: 0px 2px 6px rgba(0,0,0,.3);
}
.search-box {
flex: 4 0 0;
padding: 5px;
border-radius: 4px 0 0 4px;
border: 2px solid lightgray;
border-right: 0;
}
.search-submit {
flex: 1 0 0;
padding: 5px;
border-radius: 0 4px 4px 0;
border: 2px solid #4b68ff;
background: #4b68ff;
color: #fff;
}
.select-option {
display: block;
box-sizing: border-box;
height: 30px;
line-height: 30px;
padding-left: 10px;
background: #ddd;
}
amp-selector .select-option.no-outline.no-outline[option] {
outline: none;
}
.select-option:focus {
box-shadow: inset rgb(94, 158, 215) 0px 0px 45px;
}
.select-option:focus {
background: #fff;
}
.select-option:nth-child(2n) {
background: #eee;
}
</style>
</head>
<body>
<h1>Programming language search</h1>
<form
method="post"
action-xhr="/form/autosuggest/search"
target="_blank"
id="search-form"
on="submit:autosuggest-list.hide;submit-success:results.show"
autocomplete="off"
>
<div class="search-container">
<input
id="query"
name="query"
type="text"
class="search-box"
on="input-debounced:AMP.setState({
query: event.value,
autosuggest: event.value
}),
autosuggest-list.show,
results.hide"
[value]="query || ''"
/>
<button class="search-submit" type="submit">Search</button>
</div>
<amp-list
class="autosuggest-box"
layout="fixed-height"
height="120"
src="/form/autosuggest/query"
[src]="'/form/autosuggest/query?q=' + (autosuggest || '')"
id="autosuggest-list"
hidden
>
<template type="amp-mustache">
<amp-selector
keyboard-select-mode="focus"
layout="container"
on="select:AMP.setState({
query: event.targetOption
}),
autosuggest-list.hide,
results.hide"
>
{{#results}}
<div
class="select-option no-outline"
role="option"
tabindex="0"
on="tap:autosuggest-list.hide"
option="{{.}}"
>{{.}}</div>
{{/results}}
{{^results.3}}<div class="select-option"></div>{{/results.3}}
{{^results.2}}<div class="select-option"></div>{{/results.2}}
{{^results.1}}<div class="select-option"></div>{{/results.1}}
{{^results.0}}<div class="select-option"></div>{{/results.0}}
</amp-selector>
</template>
</amp-list>
<div submit-success id="results">
<template type="amp-mustache">
<p>Here are the results for the search "{{query}}":</p>
<ul>
{{#results}}<li>{{title}}</li>{{/results}}
</ul>
</template>
</div>
</form>
</body>
</html>