-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.html
127 lines (119 loc) · 6.11 KB
/
example.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Spotlight Search</title>
<link rel="stylesheet" href="spotlight.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css">
<style>
body {
font-family: 'Helvetica Neue', Arial, sans-serif;
margin: 0;
padding: 20px;
background: #f0f0f5;
height: 200vh;
}
h2 {
display: inline-block;
}
body > div {
display: inline-block;
margin-left: 10px;
}
@media (prefers-color-scheme: dark) {
body {
background: #121212;
color: #fffffe
}
}
</style>
</head>
<body>
<h2>Welcome to the Website</h2>
<div data-spotlight="true"></div>
<p>This is some sample content to help you visualize the search functionality on top of an existing page.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum interdum, nisi lorem egestas odio, vitae scelerisque enim ligula venenatis dolor.</p>
<p>Maecenas nisl est, ultrices nec congue eget, auctor vitae massa. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam ut sapien non nisi sodales feugiat. Curabitur lacinia tristique dolor, vitae maximus est vehicula in. Proin a erat vel dolor malesuada euismod.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
<p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<script type="module">
import spotlight from './spotlight.js';
document.addEventListener('DOMContentLoaded', () => {
spotlight.init({
"url": "https://your-api-url.com",
onItemClick: (sectionData, itemData) => {
alert(`You clicked on ${sectionData.name} : ${itemData.name} !`);
},
onFetch: function(url, options) {
return {
ok: true,
json: () => [
{
type: "books",
name: "Books",
items: [
{ name: "JavaScript: The Good Parts" },
{ name: "Eloquent JavaScript" },
{ name: "You Don't Know JS" },
{ name: "Clean Code" },
{ name: "The Pragmatic Programmer" }
]
},
{
type: "movies",
name: "Movies",
items: [
{ name: "Inception" },
{ name: "Interstellar" },
{ name: "The Matrix" },
{ name: "The Dark Knight" },
{ name: "Pulp Fiction" }
]
},
{
type: "music",
name: "Music",
items: [
{ name: "Bohemian Rhapsody" },
{ name: "Imagine" },
{ name: "Smells Like Teen Spirit" },
{ name: "Hotel California" },
{ name: "Hey Jude" }
]
},
{
type: "tv-shows",
name: "TV Shows",
items: [
{ name: "Breaking Bad" },
{ name: "Stranger Things" },
{ name: "Game of Thrones" },
{ name: "The Office" },
{ name: "Friends" }
]
},
{
type: "tech",
name: "Tech",
items: [
{ name: "React" },
{ name: "Vue.js" },
{ name: "Angular" },
{ name: "Node.js" },
{ name: "Python" }
]
}
]
}
},
onDataResponse: (query, data) => data.map(section => {
const { type, name, items = [] } = section;
const filteredItems = items.filter(item => item.name.toLowerCase().includes(query.toLowerCase()));
return { type, name, items: filteredItems };
}).filter(section => section.items.length > 0),
});
});
</script>
</body>
</html>