-
Notifications
You must be signed in to change notification settings - Fork 1
/
search.html
60 lines (56 loc) · 2.4 KB
/
search.html
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
---
layout: page
title: Search Results
---
<div id="searchResultsDiv"></div>
<script type="text/javascript">
var whenDocumentReady = whenDocumentReady || function() {};
var whenSearchTermsReady = function() {
var searchText = decodeURIComponent(QueryString["txtSearch"] || "").split("+").join(" ");
if(searchText) {
$("#txtSearch").val(searchText);
$.each(typeaheadHandler.getData(searchText), function(index, post) {
var regex = new RegExp(searchText, "gi");
var div = $("<div/>");
var header = null;
var excerpt = null;
var tags = null;
if(post.title) {
var title = $("<div/>").html(post.title).text();
header = $("<h3/>")
.css("font-weight", "bold")
.html(title.replace(regex, "<span class='searchHit'>$&</span>"));
} else {
header = $("<h3/>")
.css("font-weight", "bold")
.text("{Title Unknown}");
}
var date = $("<span/>");
if(post.date) {
date = $("<p/>")
.css("font-weight","bold")
.text(new Date(post.date.substr(0,10)).toString().substr(0,15));
}
if(post.excerpt) {
excerpt = $("<p/>")
.html(post.excerpt.replace(regex, "<span class='searchHit'>$&</span>"));
}
if(post.tags) {
var tagsText = post.tags.split(",").sort().join(", ");
tags = $("<p/>")
.html("<b>Tags:</b> " + tagsText.replace(regex, "<span class='searchHit'>$&</span>"));
}
var link = $("<p/>").html("<a href='" + post.url + "'>View " +
(post.isPost ? "Post" : "Page") +
" »</a>");
$("#searchResultsDiv").append($("<div/>")
.append(header || $("<span/>"))
.append(date || $("<span/>"))
.append(excerpt || $("<span/>"))
.append(tags || $("<span/>"))
.append(link)
);
});
}
}
</script>