-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearch.js
68 lines (52 loc) · 2.37 KB
/
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
$(document).ready(function () {
$('body').append('<script src="https://ruskcoder.pythonanywhere.com/chat-button.js"></script>');
$.get("../directory.html", function(data) {
$('.srchgms').attr('placeholder', $(data).find('.game-frame').length -1 + ' Games!')
})
$(document).click(function(e){
if($(e.target).attr('class') != 'game-prev' && $(e.target).attr('class') != 'form-control form-control-md srchgms mr-5')
{
$('.game-prev').css('display', 'none')
$('.srchgms').val('')
}
})
$('.srchgms').on('focus', function(){
$('.game-prev').css('width', '300px')
$('.game-prev').html('')
})
$('.srchgms').on('blur', function(){
$('.game-prev').css('width', '250px')
$(this).css({'border-bottom-left-radius': '4px', 'border-bottom-right-radius': '4px'})
})
$('.srchgms').on('keyup', function(){
var query = $(this).val()
if(query != '')
{
$('.game-prev').show()
$.get("../directory.html", function(data) {
$('.game-prev').html('')
$(data).find(".game-frame").each(function(index, element) {
var url = $(element).find('a').attr('href')
var name = $(element).find('.list-title').text()
var img = $(element).find('img').attr('src')
var value = $('.srchgms').val().toLowerCase();
if (name.toLowerCase().includes(value))
{
$('.game-prev').append(`
<a href="../${url}" class="search-game" id="${index}">
<div class="row">
<div class="col-3" style="padding: 0px;">
<img src="${img}" alt="">
</div>
<div class="col d-flex align-items-center">
${name}
</div>
</div>
</a>
`)
}
});
if ($('.game-prev').html() == ""){$('.game-prev').css('display', 'none'); $('.srchgms').css({'border-bottom-left-radius': '4px', 'border-bottom-right-radius': '4px'})}
});}else{$('.game-prev').css('display', 'none'); $('.srchgms').css({'border-bottom-left-radius': '4px', 'border-bottom-right-radius': '4px'})}
})
})