@@ -15,9 +15,9 @@ const md = new MarkdownIt({
15
15
} </div>`
16
16
} ) ;
17
17
18
- const renderMethod = ( method : Method ) => `<div class="mb-5"><a name="${
19
- method . slug
20
- } " />
18
+ const renderMethod = ( method : Method ) => `<div class="mb-5" data-method- name="${
19
+ method . name
20
+ } "><a name=" ${ method . slug } " />
21
21
22
22
<h2 class="method-name">
23
23
<a href="#${
@@ -72,7 +72,9 @@ const renderFileNav = (file: File) => `<p><a href="#${
72
72
${ file . methods
73
73
. map (
74
74
method =>
75
- `<li class="method-name"><a href="#${ method . slug } " class="${
75
+ `<li class="method-name" data-method-name="${
76
+ method . name
77
+ } "><a href="#${ method . slug } " class="${
76
78
method . private ? 'text-muted' : ''
77
79
} ">${ method . name } </a></li>`
78
80
)
@@ -140,6 +142,10 @@ export default async (doc: Doc): Promise<string> => `<!DOCTYPE html>
140
142
color: #eee;
141
143
text-decoration: none;
142
144
}
145
+
146
+ .hidden {
147
+ display: none;
148
+ }
143
149
</style>
144
150
</head>
145
151
<body>
@@ -162,6 +168,13 @@ export default async (doc: Doc): Promise<string> => `<!DOCTYPE html>
162
168
<div class="container">
163
169
<div class="row">
164
170
<nav class="p-5 col-md-3">
171
+ <form>
172
+ <div class="form-group mb-3">
173
+ <input type="search" class="form-control" id="filter-methods" name="q" placeholder="Filter methods..."
174
+ autocomplete="off">
175
+ </div>
176
+ </form>
177
+
165
178
${ doc . files
166
179
. filter ( file => file . methods . length )
167
180
. map ( file => renderFileNav ( file ) )
@@ -189,6 +202,32 @@ export default async (doc: Doc): Promise<string> => `<!DOCTYPE html>
189
202
</p>
190
203
</div>
191
204
</footer>
205
+ <script>
206
+ const params = new URLSearchParams(window.location.search);
207
+
208
+ const q = params.get('q');
209
+
210
+ const filterInput = document.querySelector('#filter-methods');
211
+
212
+ const methods = Array.from(document.querySelectorAll('[data-method-name]'));
213
+
214
+ const filterMethods = keyword => {
215
+ const keywordsPattern = RegExp(keyword.trim().split(/[^A-Za-z]+/).join('|'), 'i')
216
+
217
+ const matched = methods.filter(method => method.dataset.methodName.match(keywordsPattern));
218
+ const notMatched = methods.filter(method => !method.dataset.methodName.match(keywordsPattern));
219
+
220
+ matched.map(match => match.classList.remove('hidden'));
221
+ notMatched.map(match => match.classList.add('hidden'));
222
+ }
223
+
224
+ filterInput.addEventListener('keyup', e => filterMethods(e.target.value));
225
+ filterInput.addEventListener('search', e => filterMethods(e.target.value));
226
+
227
+ filterInput.value = q;
228
+
229
+ filterMethods(q);
230
+ </script>
192
231
</body>
193
232
</html>
194
233
` ;
0 commit comments