-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
331 lines (314 loc) · 10.8 KB
/
Copy pathindex.html
File metadata and controls
331 lines (314 loc) · 10.8 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>podcast:location Tag Demo</title>
<script>
// IMPORTANT: This key should NEVER be exposed in production.
// It should be kept on the backend to avoid abuse and quota limits.
// This key is exposed here ONLY for demonstration purposes and uses a free account with rate limiting.
// Please do NOT abuse it — get your own key at locationiq.com and do not use this one.
const locationiqKey = "pk.941791e42cbab69fbaf845b29cfcef8c";
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.devbridge-autocomplete/1.4.11/jquery.autocomplete.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
:root {
font-size: 14px;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #f9f9f9;
margin: 0;
padding: 0;
line-height: 1.5;
}
.header {
width: 100%;
background: #ffffff;
border-bottom: 1px solid #eee;
padding: 25px 5vw;
box-sizing: border-box;
}
.header h2 {
font-size: 1.4rem;
margin: 0 0 10px 0;
}
.bottom-sticky h4 {
font-size: 0.8rem;
margin: 0;
padding: 0;
}
.header .intro {
font-size: 0.8rem;
color: #555;
max-width: 1000px;
}
.container {
display: flex;
flex-direction: column;
max-width: 1000px;
margin: auto;
padding: 20px 5vw 300px;
box-sizing: border-box;
gap: 20px;
}
.step {
margin-bottom: 20px;
padding: 20px;
background: #eaf4ff;
border-left: 5px solid #2196F3;
border-radius: 6px;
}
.step h3 {
margin-top: 0;
font-size: 1rem;
}
.radio-group label {
margin-right: 20px;
font-weight: 500;
font-size: 1rem;
display: inline-flex;
align-items: center;
}
input[type="text"], select {
width: 100%;
padding: 14px;
font-size: 1rem;
border: 1px solid #ccc;
border-radius: 6px;
box-sizing: border-box;
margin-top: 8px;
}
input[type="radio"] {
transform: scale(1.3);
margin-right: 8px;
}
.autocomplete-note {
font-size: 0.8rem;
color: #666;
margin-top: 10px;
}
.bottom-sticky {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
background: #fffefc;
border-top: 2px solid #eee;
padding: 10px 5vw;
font-size: 1rem;
box-sizing: border-box;
z-index: 999;
}
.json-toggle {
cursor: pointer;
font-weight: bold;
margin-top: 10px;
color: #0074d9;
user-select: none;
font-size: 0.8rem;
}
.json-toggle:hover {
text-decoration: underline;
}
.json-section {
display: none;
margin-top: 10px;
background: #f9f9f9;
border: 1px solid #ccc;
border-radius: 6px;
padding: 10px;
font-size: 0.5rem;
font-family: Consolas, Monaco, monospace;
white-space: pre-wrap;
word-wrap: break-word;
overflow-wrap: break-word;
word-break: break-word;
max-width: 100%;
}
.location-tag-preview {
margin-bottom: 10px;
background: #fff3e0;
border: 1px solid #ffc107;
border-radius: 6px;
padding: 5px 15px 5px 15px;
font-size: 0.8rem;
font-family: Consolas, Monaco, monospace;
white-space: pre-wrap;
word-break: break-word;
overflow-wrap: break-word;
box-shadow: 0 0 4px rgba(0,0,0,0.06);
overflow-x: hidden;
}
.location-tag-preview code {
white-space: inherit;
word-break: inherit;
padding: 0px 15px 0px 15px;
}
.autocomplete-suggestions {
border: 1px solid #ccc;
background: white;
overflow: auto;
border-radius: 6px;
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
z-index: 10000 !important;
}
.autocomplete-suggestion {
padding: 10px;
font-size: 1rem;
line-height: 1.5;
cursor: pointer;
border-bottom: 1px solid #eee;
}
.autocomplete-selected {
background-color: #eaf4ff;
}
</style>
</head>
<body>
<div class="header">
<h2>podcast:location Tag Demo</h2>
<div class="intro">
This implementation of the <strong>podcast:location</strong> tag follows the <a href="https://podcasting2.org/docs/podcast-namespace/tags/location" target="_blank">latest specifications and best practices</a>, including the use of OpenStreetMap (OSM). One of the main goals of this demo is to offer location autocompletion for a better user experience and more accurate data. For more details, visit the <a href="https://github.com/albertobeta/podcast-location-tag-demo/tree/main" target="_blank">Github repository</a>.
</div>
</div>
<div class="container">
<div class="step" id="step1">
<h3>Step 1: Choose location type</h3>
<div class="radio-group">
<label><input type="radio" name="rel" value="subject">Subject<small> (What this podcast is about)</small></label>
<label><input type="radio" name="rel" value="creator">Creator<small> (Where this podcast is made)</small></label>
</div>
</div>
<div class="step" id="step2" style="display:none;">
<h3>Step 2: Type a location</h3>
<input type="text" id="input-step1" placeholder="Start typing a place name...">
<div class="autocomplete-note">
This is not about precise geolocation or coordinates, but about meaningful place-based discoverability. For example, if a podcast creator is based in London, simply using “London” is fine unless a specific neighborhood adds useful context. The goal is not to pinpoint homes or exact addresses, but to help listeners find content by general place names.
</div>
</div>
<div class="step" id="step3" style="display:none;">
<h3 id="step3-heading">Optional: Add second location</h3>
<div class="radio-group">
<label><input type="radio" id="rel-second" disabled> <span id="second-label"></span></label>
</div>
<input type="text" id="input-step2" placeholder="Start typing second location...">
</div>
</div>
<div class="bottom-sticky">
<h4>Location Tag Preview</h4>
<div class="location-tag-preview" id="location-tag-box" style="display:none;">
<code id="location-tag-preview"></code>
</div>
<div class="json-section" id="json-box"><pre id="json-output"></pre></div>
<div class="json-toggle" id="toggle-json">▶ Show JSON Response</div>
</div>
<script>
const locations = { subject: null, creator: null };
let firstType = null;
let secondType = null;
function generateTag(rel, data) {
if (!data) return "";
const lat = data.lat;
const lon = data.lon;
const osmId = data.osm_id;
const osmType = data.osm_type;
const label = data.display_name.split(",")[0];
const country = data.address && data.address.country_code ? data.address.country_code.toUpperCase() : "XX";
const osmPrefix = { node: "N", way: "W", relation: "R" }[osmType.toLowerCase()] || "R";
const osm = osmPrefix + osmId;
return `<podcast:location rel="${rel}" geo="geo:${lat},${lon}" osm="${osm}" country="${country}">${label}</podcast:location>`;
}
function updatePreview() {
const tagSubject = locations.subject ? generateTag("subject", locations.subject) : "";
const tagCreator = locations.creator ? generateTag("creator", locations.creator) : "";
const combined = [tagSubject, tagCreator].filter(Boolean).join("\n\n");
$('#location-tag-preview').text(combined);
$('#location-tag-box').toggle(Boolean(combined));
}
function updateJSONBox() {
const merged = {
...(locations.subject && { subject: locations.subject }),
...(locations.creator && { creator: locations.creator })
};
$('#json-output').text(JSON.stringify(merged, null, 2));
}
function handleSelection(rel, data) {
locations[rel] = data;
updatePreview();
updateJSONBox();
if (rel === firstType && !locations[secondType]) {
$('#step3').show();
const label = secondType.charAt(0).toUpperCase() + secondType.slice(1);
$('#step3-heading').html(`Optional: Add location for <em>${label}</em>`);
$('#rel-second').prop('checked', true);
$('#second-label').text(
secondType.charAt(0).toUpperCase() + secondType.slice(1) +
(secondType === "creator" ? " (i.e. Where this podcast is made)" : " (i.e. What this podcast is about)")
);
const stickyHeight = document.querySelector(".bottom-sticky").offsetHeight;
const step3 = document.getElementById("step3");
const step3Top = step3.getBoundingClientRect().top + window.scrollY;
window.scrollTo({
top: step3Top - stickyHeight - 10,
behavior: "smooth"
});
}
}
function initAutocomplete(inputId, getRel) {
$(`#${inputId}`).autocomplete({
minChars: 3,
deferRequestBy: 300,
serviceUrl: 'https://api.locationiq.com/v1/autocomplete.php',
paramName: 'q',
params: {
key: locationiqKey,
format: "json",
limit: 10
},
ajaxSettings: {
dataType: 'json'
},
formatResult: function(suggestion) {
const typeRaw = suggestion.data.type || "";
const typeFormatted = typeRaw.replace(/_/g, ' ').replace(/\b\w/g, l => l.toUpperCase());
const label = typeFormatted ? `<strong>[${typeFormatted}]</strong> ` : "";
return `<div>${label}${suggestion.data.display_name}</div>`;
},
transformResult: function(response) {
return {
suggestions: $.map(response, function(item) {
return { value: item.display_name, data: item };
})
};
},
onSelect: function(suggestion) {
handleSelection(getRel(), suggestion.data);
}
});
}
$('input[name="rel"]').change(function () {
firstType = $(this).val();
secondType = firstType === "subject" ? "creator" : "subject";
locations.subject = null;
locations.creator = null;
$('#step2').show();
$('#step3').hide();
$('#input-step1').val('');
$('#input-step2').val('');
$('#location-tag-preview').text('');
$('#json-output').text('');
$('#location-tag-box').hide();
});
$('#toggle-json').click(function () {
$('#json-box').slideToggle();
const txt = $(this).text().includes("Show") ? "▼ Hide JSON Response" : "▶ Show JSON Response";
$(this).text(txt);
});
initAutocomplete("input-step1", () => firstType);
initAutocomplete("input-step2", () => secondType);
</script>
</body>
</html>