-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.js
90 lines (90 loc) · 3.09 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//search begin
function srch(txt, ob) {
// Retrieve the input field text and reset the count to zero
var filter = $("#filter").val(),
count = 0;
if (!filter) {
ob.show();
return;
}
var regex = new RegExp(filter, "i");
// Loop through the comment list
ob.each(function() {
var ths = $(this);
var ftd = ths.find(txt).text();
if (ftd.search(regex) < 0) {
ths.hide();
// Show the list item if the phrase matches and increase the count by 1
} else {
ths.show();
}
});
// Update the count
var numberItems = count;
$("#filter-count").text("Number of Comments = " + count);
};
function srchHilight(txt, ob) {
var filter = $("#filter").val(),
count = 0;
if (!filter) {
ob.show();
element = ob; //convert string to JQuery element
element.each(function(index) {
var text = $(this).find(txt).html() //get span content
text = text.replace('<span class="highlight">', '');
//text = text.replace('<span class="highlight fcty">','');
text = text.replace('</span>', '');
$(this).find(txt).html(text); //replace all span with just content
})
return;
}
var regex = new RegExp(filter, "i");
// Loop through the comment list
ob.each(function() {
var ths = $(this);
var ftd = ths.find(txt).text();
//var ftd = ths.find(txt).text().replace("Ù€","");;
if (ftd.search(regex) < 0) {
ths.hide();
// Show the list item if the phrase matches and increase the count by 1
} else {
ths.show();
ftd = ftd.replace(regex, '<span class="highlight">' + regex + "</span>");
// ftd = ftd.replace(regex, '<span class="highlight fcty">' + regex +"Ù€"+ "</span>");
ftd = ftd.replace(">/", ">");
ftd = ftd.replace("/<", "<");
ftd = ftd.replace("/i", "");
// ftd = ftd.replace("Ù€</span> ","</span> ");
ths.find(txt).html(ftd);
}
});
// Update the count
var numberItems = count;
$("#filter-count").text("Number of Comments = " + count);
};
//search end
//hilight function
function hilight(txt, ob) {
var filter = $("#filter").val(),
count = 0;
var regex = new RegExp(filter, "i");
ob.each(function() {
var ths = $(this);
var ftd = ths.find(txt).text();
ftd = ftd.replace(regex, '<span class="highlight">' + regex + '</span>');
ftd = ftd.replace(">/", ">");
ftd = ftd.replace("/<", "<");
ftd = ftd.replace("/i", "");
ths.find(txt).html(ftd);
});
};
//remove hilight function
function removeHilight(txt, ob) {
element = ob; //convert string to JQuery element
element.each(function(index) {
var text = $(this).find(txt).html() //get span content
text = text.replace('<span class="highlight">', '');
text = text.replace('</span>', '');
$(this).find(txt).html(text); //replace all span with just content
})
};