forked from ampproject/amphtml
/
ecommerce.amp.html
343 lines (317 loc) · 15.7 KB
/
ecommerce.amp.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<!doctype html>
<html ⚡>
<head>
<meta charset="utf-8">
<title>amp-bind: E-commerce</title>
<link rel="canonical" href="amps.html">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<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-carousel" src="https://cdn.ampproject.org/v0/amp-carousel-0.1.js"></script>
<script async custom-element="amp-selector" src="https://cdn.ampproject.org/v0/amp-selector-0.1.js"></script>
<style amp-custom>
/*** uncss> filename: https://code.getmdl.io/1.3.0/material.indigo-pink.min.css ***/
/**
* material-design-lite - Material Design Components in CSS, JS and HTML
* @version v1.3.0
* @license Apache-2.0
* @copyright 2015 Google, Inc.
* @link https://github.com/google/material-design-lite
*/
html{color:rgba(0,0,0,.87)}::-moz-selection{background:#b3d4fc;text-shadow:none}::selection{background:#b3d4fc;text-shadow:none}.hidden{display:none}@media print{*,*:before,*:after{background:transparent;color:#000;box-shadow:none}tr{page-break-inside:avoid}p{orphans:3;widows:3}}.mdl-button{-webkit-tap-highlight-color:transparent;-webkit-tap-highlight-color:rgba(255,255,255,0)}html{width:100%;height:100%;-ms-touch-action:manipulation;touch-action:manipulation}body{width:100%;min-height:100%}html,body{font-family:"Helvetica","Arial",sans-serif;font-size:14px;font-weight:400;line-height:20px}h5,h6,p{padding:0}h5{font-size:20px;font-weight:500;line-height:1;letter-spacing:.02em}h5,h6{font-family:"Roboto","Helvetica","Arial",sans-serif;margin:24px 0 16px}h6{font-size:16px;letter-spacing:.04em}h6,p{font-weight:400;line-height:24px}p{font-size:14px;letter-spacing:0;margin:0 0 16px}.mdl-color-text--red{color:#f44336 }.mdl-color-text--blue{color:#2196f3 }.mdl-color-text--grey{color:#9e9e9e }.mdl-color--black{background-color:#000 }.mdl-color-text--white{color:#fff }.mdl-button{background:0 0;border:none;border-radius:2px;color:#000;position:relative;height:36px;margin:0;min-width:64px;padding:0 16px;display:inline-block;font-family:"Roboto","Helvetica","Arial",sans-serif;font-size:14px;font-weight:500;text-transform:uppercase;letter-spacing:0;overflow:hidden;will-change:box-shadow;transition:box-shadow .2s cubic-bezier(.4,0,1,1),background-color .2s cubic-bezier(.4,0,.2,1),color .2s cubic-bezier(.4,0,.2,1);outline:none;cursor:pointer;text-decoration:none;text-align:center;line-height:36px;vertical-align:middle}.mdl-button::-moz-focus-inner{border:0}.mdl-button:hover{background-color:rgba(158,158,158,.2)}.mdl-button:focus:not(:active){background-color:rgba(0,0,0,.12)}.mdl-button:active{background-color:rgba(158,158,158,.4)}.mdl-button.mdl-button--colored:focus:not(:active){background-color:rgba(0,0,0,.12)}.mdl-button--raised{background:rgba(158,158,158,.2);box-shadow:0 2px 2px 0 rgba(0,0,0,.14),0 3px 1px -2px rgba(0,0,0,.2),0 1px 5px 0 rgba(0,0,0,.12)}.mdl-button--raised:active{box-shadow:0 4px 5px 0 rgba(0,0,0,.14),0 1px 10px 0 rgba(0,0,0,.12),0 2px 4px -1px rgba(0,0,0,.2);background-color:rgba(158,158,158,.4)}.mdl-button--raised:focus:not(:active){box-shadow:0 0 8px rgba(0,0,0,.18),0 8px 16px rgba(0,0,0,.36);background-color:rgba(158,158,158,.4)}.mdl-button--raised.mdl-button--colored:focus:not(:active){background-color:rgb(63,81,181)}.mdl-button--fab:focus:not(:active){box-shadow:0 0 8px rgba(0,0,0,.18),0 8px 16px rgba(0,0,0,.36);background-color:rgba(158,158,158,.4)}.mdl-button--fab.mdl-button--colored:focus:not(:active){background-color:rgb(255,64,129)}.mdl-button--accent.mdl-button--accent{color:rgb(255,64,129)}.mdl-button--accent.mdl-button--accent.mdl-button--raised{color:rgb(255,255,255);background-color:rgb(255,64,129)}.mdl-button[disabled][disabled]{color:rgba(0,0,0,.26);cursor:default;background-color:transparent}.mdl-button--raised[disabled][disabled]{background-color:rgba(0,0,0,.12);color:rgba(0,0,0,.26);box-shadow:none}@supports (-webkit-appearance:none){}@supports (pointer-events:auto){}.mdl-slider.is-upgraded:focus:not(:active)::-webkit-slider-thumb{box-shadow:0 0 0 10px rgba(63,81,181,.26)}.mdl-slider.is-upgraded:focus:not(:active)::-moz-range-thumb{box-shadow:0 0 0 10px rgba(63,81,181,.26)}.mdl-slider.is-upgraded:focus:not(:active)::-ms-thumb{background:radial-gradient(circle closest-side,rgb(63,81,181)0%,rgb(63,81,181)37.5%,rgba(63,81,181,.26)37.5%,rgba(63,81,181,.26)100%);transform:scale(1)}.mdl-slider.is-upgraded.is-lowest-value:focus:not(:active)::-webkit-slider-thumb{box-shadow:0 0 0 10px rgba(0,0,0,.12);background:rgba(0,0,0,.12)}.mdl-slider.is-upgraded.is-lowest-value:focus:not(:active)::-moz-range-thumb{box-shadow:0 0 0 10px rgba(0,0,0,.12);background:rgba(0,0,0,.12)}.mdl-slider.is-upgraded.is-lowest-value:focus:not(:active)::-ms-thumb{background:radial-gradient(circle closest-side,rgba(0,0,0,.12)0%,rgba(0,0,0,.12)25%,rgba(0,0,0,.26)25%,rgba(0,0,0,.26)37.5%,rgba(0,0,0,.12)37.5%,rgba(0,0,0,.12)100%);transform:scale(1)}body{margin:0}
/* custom css */
#header {
height: 24px;
padding: 16px;
margin: 0;
text-align: center;
text-transform: uppercase;
letter-spacing: 2px;
line-height: 24px;
}
.menu {
float: left;
}
.search {
float: right;
}
#container {
max-width: 500px;
padding: 32px 16px 64px 16px;
margin: auto;
}
.title {
text-align: center;
}
.rating {
margin-bottom: 0;
text-align: center;
}
#carousel {
margin: 16px;
}
.dots {
text-align: center;
}
.dots span {
display: inline-block;
background: #ccc;
border-radius: 6px;
width: 12px;
height: 12px;
margin: 4px;
}
.dots span.current {
background: #555;
}
.options {
margin: 16px 0;
}
.options h6 {
text-transform: uppercase;
margin: 0 0 4px 0;
}
.colors table {
margin: 0 -8px;
}
.colors amp-img {
border: solid 2px white;
display: block;
margin: auto;
}
.colors amp-img[selected] {
outline: solid 2px red;
}
.sizes div {
border: solid 1px black;
width: 40px;
height: 40px;
line-height: 40px;
font-weight: 800;
text-align: center;
}
.sizes div[selected] {
background-color: gray;
color: white;
outline: none;
}
.unavailable::before {
content: '';
position: absolute;
border-top: 1px solid black;
margin-left: 1px;
width: 57px;
transform: rotate(45deg);
transform-origin: 0% 0%;
}
.quantity select {
font-size: 16px;
border: solid 1px gray;
padding: 8px;
}
table {
width: 100%;
}
.hidden {
display: none;
}
</style>
</head>
<body>
<!--
Available shirts, maps unique identifier to {color, image}. Sizes are fetched remotely.
When a shirt color is selected, `selected.id` changes which causes this
<amp-state> to perform an XHR to the new [src] value. Upon completion,
the XHR response is merged into the state under its "id" attribute ("shirts").
This has the limitation that data returned by the XHR must have the same
hierarchical structure as the existing data.
For example, the XHR must return something like:
{
"3": {
"sizes": ["S", "L"]
}
}
By contrast, it must NOT return something like:
{
"sizes": ["S", "L"]
}
In order to support the latter, we'd need to:
- Add support for a new action event, AND
- Force quotation marks for literal keys, AND
- Reintroduce variables in object keys (removed in #7582)
<amp-state [src]="..." on="fetch:AMP.setState({"shirts": {selected: {id: event.response}}})"
Note that shirt with ID == "0" contains size data (but other IDs don't)
because it's the default shirt color at page load. Size data for other shirts
will be fetched via XHR when their corresponding colors are selected.
-->
<amp-state id="shirts" [src]="'/bind/ecommerce/sizes?shirt=' + selected.id">
<script type="application/json">
{
"0": {
"color": "black",
"image": "./shirts/black.jpg",
"sizes": {
"XS": 8.99,
"S": 9.99
}
},
"1": {
"color": "blue",
"image": "./shirts/blue.jpg"
},
"2": {
"color": "brown",
"image": "./shirts/brown.jpg"
},
"3": {
"color": "dark green",
"image": "./shirts/dark-green.jpg"
},
"4": {
"color": "gray",
"image": "./shirts/gray.jpg"
},
"5": {
"color": "light gray",
"image": "./shirts/light-gray.jpg"
},
"6": {
"color": "navy",
"image": "./shirts/navy.jpg"
},
"7": {
"color": "wine",
"image": "./shirts/wine.jpg"
}
}
</script>
</amp-state>
<amp-state id="selected">
<script type="application/json">
{
"id": 0,
"slide": 0
}
</script>
</amp-state>
<header id="header" class="mdl-color--black mdl-color-text--white">
<amp-img class="menu" src="./img/ic_menu_white_24dp_1x.png" width=24 height=24></amp-img>
<span class="mdl-color-text--blue">AMP</span>PAREL
<amp-img class="search" src="./img/ic_search_white_24dp_1x.png" width=24 height=24></amp-img>
</header>
<div id="container">
<h5 class="title">MEN'S COTTON CREW NECK<br>LONG SLEEVE T-SHIRT</h5>
<h6 class="rating"><span class="mdl-color-text--red">★★★★☆</span> <span class="mdl-color-text--grey">(14)</span></h6>
<amp-carousel type="slides" layout="fixed-height" height=250 id="carousel"
[slide]="selected.slide" on="slideChange:AMP.setState({selected: {slide: event.index}})">
<amp-img width=200 height=250 src="./shirts/black.jpg" [src]="shirts[selected.id].image"></amp-img>
<amp-img width=300 height=375 src="./shirts/black.jpg" [src]="shirts[selected.id].image"></amp-img>
<amp-img width=400 height=500 src="./shirts/black.jpg" [src]="shirts[selected.id].image"></amp-img>
</amp-carousel>
<p class="dots">
<span [class]="selected.slide == 0 ? 'current' : ''" class="current"
on="tap:AMP.setState({selected: {slide: 0}})"></span>
<span [class]="selected.slide == 1 ? 'current' : ''"
on="tap:AMP.setState({selected: {slide: 1}})"></span>
<span [class]="selected.slide == 2 ? 'current' : ''"
on="tap:AMP.setState({selected: {slide: 2}})"></span>
</p>
<div class="options colors">
<h6>COLOR : <span [text]="shirts[selected.id].color">black</span></h6>
<amp-selector on="select:AMP.setState({selected: {id: event.targetOption}})">
<table>
<tr>
<td><amp-img width=40 height=40 option=0 src="./shirts/swatch/black.jpg" selected></amp-img></td>
<td><amp-img width=40 height=40 option=1 src="./shirts/swatch/blue.jpg"></amp-img></td>
<td><amp-img width=40 height=40 option=2 src="./shirts/swatch/brown.jpg"></amp-img></td>
<td><amp-img width=40 height=40 option=3 src="./shirts/swatch/dark-green.jpg"></amp-img></td>
</tr>
<tr>
<td><amp-img width=40 height=40 option=4 src="./shirts/swatch/gray.jpg"></amp-img></td>
<td><amp-img width=40 height=40 option=5 src="./shirts/swatch/light-gray.jpg"></amp-img></td>
<td><amp-img width=40 height=40 option=6 src="./shirts/swatch/navy.jpg"></amp-img></td>
<td><amp-img width=40 height=40 option=7 src="./shirts/swatch/wine.jpg"></amp-img></td>
</tr>
</table>
</amp-selector>
</div>
<div class="options price">
<h6>PRICE : <span [text]="shirts[selected.id].sizes[selectedSize] || '---'">---</span></h6>
</div>
<div class="options sizes">
<h6>SIZE :</h6>
<amp-selector on="select:AMP.setState({selectedSize: event.targetOption})">
<table>
<tr>
<td [class]="!shirts[selected.id].sizes['XS'] ? 'unavailable' : ''">
<div option="XS">XS</div>
</td>
<td [class]="!shirts[selected.id].sizes['S'] ? 'unavailable' : ''">
<div option="S">S</div>
</td>
<td [class]="!shirts[selected.id].sizes['M'] ? 'unavailable' : ''"
class="unavailable">
<div option="M">M</div>
</td>
<td [class]="!shirts[selected.id].sizes['L'] ? 'unavailable' : ''"
class="unavailable">
<div option="L">L</div>
</td>
<td [class]="!shirts[selected.id].sizes['XL'] ? 'unavailable' : ''"
class="unavailable">
<div option="XL">XL</div>
</td>
</tr>
</table>
</amp-selector>
</div>
<div class="options quantity">
<h6>QUANTITY :</h6>
<select disabled [disabled]="!shirts[selected.id].sizes[selectedSize]">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</div>
<div class="options purchase">
<h5 [text]="(selectedSize && shirts[selected.id].sizes)
? (shirts[selected.id].sizes[selectedSize] ? 'In stock' : 'Out of stock')
: '---'"
[class]="(!selectedSize || shirts[selected.id].sizes[selectedSize])
? 'mdl-color-text--grey'
: 'mdl-color-text--red'"
class="mdl-color-text--grey">
---</h5>
<!--
TODO(choumx):
- A nice way to DRY expressions that's less powerful than allowing chained AMP.setState()?
- Would users assume that chaining <amp-variable> is possible? Probably...
<amp-variable
id="showAddToBag"
value="!selectedSize || !shirts[selected.id].sizes || shirts[selected.id].sizes[selectedSize]">
</amp-variable>
-->
<!--
Show the "ADD TO BAG" button when:
1. There is no selected size, OR
2. The sizes for the shirt color in the selected size has NOT been fetched yet, OR
3. The selected size for the selected color is available
Note that in cases (1) and (2) the button is visible but disabled. This replicates the behavior
in a certain e-commerce site I modeled this example off of. :)
-->
<button class="mdl-button mdl-button--raised mdl-button--accent"
[class]="'mdl-button mdl-button--raised mdl-button--accent ' +
((!selectedSize || !shirts[selected.id].sizes || shirts[selected.id].sizes[selectedSize]) ? '' : 'hidden')"
[disabled]="!selectedSize || !shirts[selected.id].sizes" disabled>
ADD TO BAG
</button>
<button class="mdl-button mdl-button--raised hidden"
[class]="'mdl-button mdl-button--raised ' +
((!selectedSize || !shirts[selected.id].sizes || shirts[selected.id].sizes[selectedSize]) ? 'hidden' : '')">
EMAIL ME WHEN IN STOCK
</button>
</div>
</div>
</body>
</html>