Repository navigation
Expand file tree
/
Copy pathlive.js
More file actions
52 lines (50 loc) · 1.77 KB
/
Copy pathlive.js
File metadata and controls
52 lines (50 loc) · 1.77 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
$(document).ready(function(){
$('#search').on("keyup", function(){
/* Get input value on change */
var inputVal = $(this).val();
var resultDropdown = $(this).siblings(".result");
if(inputVal.length){
$.get("search.php", {term: inputVal}).done(function(data){
// Display the returned data in browser
resultDropdown.html(data);
});
} else{
resultDropdown.empty();
}
});
// Set search input value on click of result item
$(document).on("click", ".result p", function(){
$(this).parents(".search-box").find('input[type="search"]').val($(this).text());
$(this).parent(".result").empty();
});
//mobile search
$('#mobileSearch').on("keyup", function(){
/* Get input value on change */
var inputVal = $(this).val();
var resultDropdown = $(this).siblings(".mobileResult");
if(inputVal.length){
$.get("search.php", {term: inputVal}).done(function(data){
// Display the returned data in browser
resultDropdown.html(data);
});
} else{
resultDropdown.empty();
}
});
// Set search input value on click of result item
$(document).on("click", ".mobileResult p", function(){
$(this).parents(".search-box").find('input[type="search"]').val($(this).text());
$(this).parent(".mobileResult").empty();
});
//submit the form
$(".result").on("click", function(){
setTimeout( () => {
$(".desktopForm").submit();
}, 300)
});
$(".mobileResult").on("click", () => {
setTimeout( function() {
$(".mobileForm").submit();
}, 300)
});
});