|
a |
|
b/archives/RadETL/docs/docsearch.js |
|
|
1 |
$(function() { |
|
|
2 |
|
|
|
3 |
// register a handler to move the focus to the search bar |
|
|
4 |
// upon pressing shift + "/" (i.e. "?") |
|
|
5 |
$(document).on('keydown', function(e) { |
|
|
6 |
if (e.shiftKey && e.keyCode == 191) { |
|
|
7 |
e.preventDefault(); |
|
|
8 |
$("#search-input").focus(); |
|
|
9 |
} |
|
|
10 |
}); |
|
|
11 |
|
|
|
12 |
$(document).ready(function() { |
|
|
13 |
// do keyword highlighting |
|
|
14 |
/* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ |
|
|
15 |
var mark = function() { |
|
|
16 |
|
|
|
17 |
var referrer = document.URL ; |
|
|
18 |
var paramKey = "q" ; |
|
|
19 |
|
|
|
20 |
if (referrer.indexOf("?") !== -1) { |
|
|
21 |
var qs = referrer.substr(referrer.indexOf('?') + 1); |
|
|
22 |
var qs_noanchor = qs.split('#')[0]; |
|
|
23 |
var qsa = qs_noanchor.split('&'); |
|
|
24 |
var keyword = ""; |
|
|
25 |
|
|
|
26 |
for (var i = 0; i < qsa.length; i++) { |
|
|
27 |
var currentParam = qsa[i].split('='); |
|
|
28 |
|
|
|
29 |
if (currentParam.length !== 2) { |
|
|
30 |
continue; |
|
|
31 |
} |
|
|
32 |
|
|
|
33 |
if (currentParam[0] == paramKey) { |
|
|
34 |
keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); |
|
|
35 |
} |
|
|
36 |
} |
|
|
37 |
|
|
|
38 |
if (keyword !== "") { |
|
|
39 |
$(".contents").unmark({ |
|
|
40 |
done: function() { |
|
|
41 |
$(".contents").mark(keyword); |
|
|
42 |
} |
|
|
43 |
}); |
|
|
44 |
} |
|
|
45 |
} |
|
|
46 |
}; |
|
|
47 |
|
|
|
48 |
mark(); |
|
|
49 |
}); |
|
|
50 |
}); |
|
|
51 |
|
|
|
52 |
/* Search term highlighting ------------------------------*/ |
|
|
53 |
|
|
|
54 |
function matchedWords(hit) { |
|
|
55 |
var words = []; |
|
|
56 |
|
|
|
57 |
var hierarchy = hit._highlightResult.hierarchy; |
|
|
58 |
// loop to fetch from lvl0, lvl1, etc. |
|
|
59 |
for (var idx in hierarchy) { |
|
|
60 |
words = words.concat(hierarchy[idx].matchedWords); |
|
|
61 |
} |
|
|
62 |
|
|
|
63 |
var content = hit._highlightResult.content; |
|
|
64 |
if (content) { |
|
|
65 |
words = words.concat(content.matchedWords); |
|
|
66 |
} |
|
|
67 |
|
|
|
68 |
// return unique words |
|
|
69 |
var words_uniq = [...new Set(words)]; |
|
|
70 |
return words_uniq; |
|
|
71 |
} |
|
|
72 |
|
|
|
73 |
function updateHitURL(hit) { |
|
|
74 |
|
|
|
75 |
var words = matchedWords(hit); |
|
|
76 |
var url = ""; |
|
|
77 |
|
|
|
78 |
if (hit.anchor) { |
|
|
79 |
url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; |
|
|
80 |
} else { |
|
|
81 |
url = hit.url + '?q=' + escape(words.join(" ")); |
|
|
82 |
} |
|
|
83 |
|
|
|
84 |
return url; |
|
|
85 |
} |