-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathaudioSearchApi.html
363 lines (351 loc) · 12.1 KB
/
audioSearchApi.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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<meta name="theme-color" content="#212529" />
<title>Audio Search API plugin</title>
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
/>
<link href="css/all.min.css" rel="stylesheet" />
<style>
.form-control-borderless {
border: none;
}
.form-control-borderless:hover,
.form-control-borderless:active,
.form-control-borderless:focus {
border: none;
outline: none;
box-shadow: none;
}
.list-group-ite-m {
border: none;
}
.amplitude-paused:before {
content: "\f04b";
}
.amplitude-playing:before {
content: "\f04c";
}
.list-group-item-action:hover:not(.active),
.list-group-item-action:visited:not(.active) {
color: #495057;
background-color: white;
}
.active-animate {
animation: flash-animation 1000ms 1;
}
@keyframes flash-animation {
0% {
background-color: white;
border-color: white;
}
50% {
background-color: #a3c4ff;
border-color: #b3d4ff;
}
100% {
background-color: white;
border-color: white;
}
}
</style>
</head>
<body>
<template id="content_template">
<a
data-index="{{index}}"
href="#"
class="mt-3 list-group-item list-group-item-action"
>
<div class="row">
<div class="col-3">
<img src="{{cover_art_url}}" class="img-thumbnail" />
</div>
<div class="col-9">
<div class="d-flex w-100 justify-content-between">
<h4>{{album}}</h4>
<small>
Date: {{date}}
</small>
</div>
<p>{{name}}</p>
<span>
<i
class="fas amplitude-play-pause"
data-amplitude-song-index="{{index}}"
style="width: 1.2em;"></i>
<small class="text-muted w-50">length: {{length}}</small>
</span>
</div>
</div>
</a>
</template>
<main role="main">
<div class="container-fluid">
<div class="row my-5">
<div class="col-4">
<form>
<div class="form-group">
<label for="releaseDaste" class="col-form-label-sm"
>Release Date</label
>
<div class="input-group input-group-sm">
<input
type="date"
class="form-control form-control-sm"
id="releaseDaste"
/>
<div class="input-group-append">
<div class="input-group-text">
<i class="far fa-calendar-alt"></i>
</div>
</div>
</div>
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="col-form-label-sm"
>Audio Program</label
>
<select
class="form-control form-control-sm"
id="exampleFormControlSelect1"
>
<option>All</option>
<option>Post Reports</option>
<option>Cape Up with Jonathan Capehart</option>
<option>The Daily 202's Big Idea</option>
<option>Retropod</option>
</select>
</div>
<div class="form-check mt-5">
<input
class="form-check-input"
type="checkbox"
checked
value=""
id="defaultCheck1"
/>
<label class="form-check-label" for="defaultCheck1">
published
</label>
</div>
<div class="form-check">
<input
class="form-check-input"
type="checkbox"
checked
value=""
id="defaultCheck4"
/>
<label class="form-check-label" for="defaultCheck4">
not published
</label>
</div>
<div class="form-check">
<input
class="form-check-input"
type="checkbox"
checked
value=""
id="defaultCheck2"
/>
<label class="form-check-label" for="defaultCheck2">
ads enabled
</label>
</div>
<div class="form-check">
<input
class="form-check-input"
type="checkbox"
checked
value=""
id="defaultCheck3"
/>
<label class="form-check-label" for="defaultCheck3">
ads disabled
</label>
</div>
</form>
</div>
<div class="col-8">
<div class="row my-4 justify-content-left">
<div class="col-12 col-md-12 col-lg-12">
<form class="card card-sm">
<div class="card-body row no-gutters align-items-center p-2">
<div class="col-auto">
<i class="fas fa-search text-body"></i>
</div>
<!--end of col-->
<div class="col">
<input
class="form-control form-control-sm form-control-borderless"
type="search"
placeholder="Search for audio"
/>
</div>
<!--end of col-->
<div class="col-auto">
<button class="btn btn-sm btn-success" type="submit">
Search
</button>
</div>
<!--end of col-->
</div>
</form>
</div>
<!--end of col-->
</div>
<div class="mt-3">
<div class="bs-example">
<div class="list-group" id="search_content" />
</div>
</div>
</div>
</div>
</div>
</main>
<script
src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
crossorigin="anonymous"
></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
crossorigin="anonymous"
></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
crossorigin="anonymous"
></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/[email protected]/dist/amplitude.js"></script>
<script>
const sendMessage = function(action, data) {
const messagePayload = {
source: 'custom_embed',
action,
data,
key: parseQueryString()['k']
}
if (action === 'ready') {
messagePayload.isAnsRequired = true
}
window.parent.postMessage(JSON.stringify(messagePayload), '*')
}
const parseQueryString = function() {
const params = location.search.split('?')[1] || ''
const kv = params.split('&')
return kv.reduce((result, item) => {
const [key, value] = item.split('=')
return Object.assign(result, {
[key]: value
})
}, {})
}
const songs = [
{
name: 'A T. rex exhibit 66 million years in the making',
description: 'Steve Hendrix and Peggy McGlone track the journey of a T. rex fossil to the newly reopened fossil hall at the Smithsonian National Museum of Natural History. Peter Holley shares how content about prison is making a space for former inmates on YouTube.',
album: 'Post Reports',
length: '25:17',
date: '06/07/19',
url: 'audio/audio0.mp3',
cover_art_url: "audio/cover0.png"
},
{
name: 'How Derek Black went from being the golden boy of white nationalism to its outspoken critic',
description: 'Derek Black was the golden boy of white nationalism. His godfather is David Duke. After enrolling in college, he began to change. Eli Saslow chronicles Black\'s transformation in his new book "Rising Out of Hatred."',
album: 'Cape Up with Jonathan Capehart',
length: '49:33',
date: '12/04/18',
url: 'audio/audio1.mp3',
cover_art_url: "audio/cover1.jpg"
},
{
name: 'Walmart robots make human workers feel like machines',
description: 'To Walmart executives, the self-driving floor scrubber is the future of retail automation. They have made a multimillion-dollar bet that advanced robots will optimize operations, cut costs and revolutionize the American superstore.',
album: 'The Daily 202\'s Big Idea',
length: '10:43',
date: '06/07/2019',
url: 'audio/audio2.mp3',
cover_art_url: "audio/cover2.jpg"
},
{
name: 'The painter who became the CIA’s master of disguise',
description: 'The spy business is all about masking the truth. One CIA agent’s deceptions and sham identities were so enterprising that he earned the nickname “Master of Disguise.”',
album: 'Retropod',
length: '10:11',
date: '06/07/2019',
url: 'audio/audio3.mp3',
cover_art_url: "audio/cover3.jpg"
}
]
const handleClick = event => {
event.preventDefault();
if (event.target.classList.contains('amplitude-play-pause')) {
return
}
const listGroupItem = event.target.closest('a')
const index = Number(listGroupItem.dataset.index)
if (Number.isNaN(index)) {
return
}
listGroupItem.classList.add('active-animate')
setTimeout(() => {
sendMessage('data', {
id: `aud-${index}`,
url: songs[index].url,
config: songs[index]
})
}, 800)
}
const get = (data, path) => path.split('.').reduce((r, k) => r ? r[k] : null, data)
const render = () => {
const template = document.getElementById('content_template').innerHTML
var rx = /{{([^}]*)}}/g
for (i = 0; i < songs.length; i++) {
let match
let html = template
while (match = rx.exec(template)) {
const path = match[1]
const value = get({...songs[i], index: i}, path)
html = html.replace(new RegExp(match[0], 'g'), value)
}
const element = document.createElement('div')
document.getElementById('search_content').appendChild(element)
element.outerHTML = html
}
document
.getElementById('search_content')
.addEventListener('click', handleClick)
}
window.onload = function() {
const parameters = Object.assign(
{
wait: 0
},
parseQueryString()
)
// Emulate wait time
setTimeout(function() {
sendMessage('ready', {
height: document.documentElement.scrollHeight
})
}, Number.parseInt(parameters.wait) + 100)
render()
Amplitude.init({ songs })
}
window.addEventListener('message', (e) => {
console.log(e)
}, false)
</script>
</body>
</html>