deno.land / x / mongoose@6.7.5 / docs / js / search.js

نووسراو ببینە
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
var root = 'https://mongoosejs.azurewebsites.net/api';var pairs = window.location.search.replace(/^\?/, '').split('&');
var q = null;for (var i = 0; i < pairs.length; ++i) { var _pair = pairs[i].split('='); if (_pair[0] === 'q') { q = _pair[1]; }}
if (q != null) { document.getElementById('search-input').value = decodeURIComponent(q); fetch(root + '/search?search=' + q). then(function(res) { return res.json(); }). then( function(result) { if (result.results.length === 0) { document.getElementById('results').innerHTML = '<h1>No Results</h1>'; return; } var html = ''; for (var i = 0; i < result.results.length; ++i) { var res = result.results[i]; var url = res.url.replace(/^\//, ''); html += '<li>' + '<a class="title" href="' + url + '">' + res.title + '</a>' + '<div class="url"><a href="' + url + '">' + url + '</a></div>' + '<p>' + res.body + '</p>' + '</li>'; }
document.getElementById('results').innerHTML = '<ul>' + html + '</ul>'; }, function(error) { document.getElementById('results').innerHTML = '<h3>An error occurred: ' + error.message + '</h3>'; } );}
document.getElementById('search-button').onclick = function() { var q = document.getElementById('search-input').value; window.location.href = 'search.html?q=' + encodeURIComponent(q);};
var q = document.getElementById('search-input').onkeyup = function(ev) { if (ev.keyCode === 13) { var q = document.getElementById('search-input').value; window.location.href = 'search.html?q=' + encodeURIComponent(q); }};
mongoose

Version Info

Tagged at
a year ago