| 1 |
var entityMap = { |
| 2 |
'&': '&', |
| 3 |
'<': '<', |
| 4 |
'>': '>', |
| 5 |
'"': '"', |
| 6 |
"'": ''', |
| 7 |
'/': '/', |
| 8 |
'`': '`', |
| 9 |
'=': '=' |
| 10 |
}; |
| 11 |
|
| 12 |
function escapeHtml (string) { |
| 13 |
return String(string).replace(/[&<>"'`=\/]/g, function (s) { |
| 14 |
return entityMap[s]; |
| 15 |
}); |
| 16 |
} |
| 17 |
|
| 18 |
function GetURLParameter(sParam) |
| 19 |
{ |
| 20 |
var sPageURL = window.location.search.substring(1); |
| 21 |
|
| 22 |
var sURLVariables = sPageURL.split('&'); |
| 23 |
for (var i = 0; i < sURLVariables.length; i++) { |
| 24 |
var sParameterName = sURLVariables[i].split('='); |
| 25 |
if (sParameterName[0] == sParam) { |
| 26 |
return escapeHtml(decodeURIComponent(sParameterName[1])); |
| 27 |
} |
| 28 |
} |
| 29 |
return "" |
| 30 |
} |
| 31 |
|
| 32 |
async function render_search(type) |
| 33 |
{ |
| 34 |
var query = GetURLParameter("query"); |
| 35 |
if (query == "") { |
| 36 |
$( '.loader' ).remove() |
| 37 |
$( "#search-title" ).html("<i>...If you don't tell what to search, I can't find anything...</i>"); |
| 38 |
return |
| 39 |
} |
| 40 |
$( "#search-input" ).val(query); |
| 41 |
$( "#search-title" ).append(" <i>" + query + "</i>"); |
| 42 |
var json_path = "searchdata.json"; |
| 43 |
|
| 44 |
await do_search(json_path, query, type); |
| 45 |
} |
| 46 |
|
| 47 |
function do_search(json_path, query, type) |
| 48 |
{ |
| 49 |
var results = [] |
| 50 |
$.ajax({ |
| 51 |
url: json_path, |
| 52 |
dataType: 'json', |
| 53 |
error: function(data, status, err) { |
| 54 |
console.log(err) |
| 55 |
}, |
| 56 |
success: function (json) { |
| 57 |
search_json(type, json, query) |
| 58 |
} |
| 59 |
}); |
| 60 |
} |
| 61 |
|
| 62 |
function search_json(type, json, query) |
| 63 |
{ |
| 64 |
result_html = "" |
| 65 |
if (type == 'library') { |
| 66 |
results_html = search_json_library(json, query) |
| 67 |
} else if (type == 'group') { |
| 68 |
results_html = search_json_group(json, query) |
| 69 |
} else if (type == 'global') { |
| 70 |
results_html = search_json_global(json, query) |
| 71 |
} |
| 72 |
|
| 73 |
$( '.loader' ).remove() |
| 74 |
$( '#results' ).append(results_html) |
| 75 |
|
| 76 |
document.querySelectorAll('h1, .dynheader, el, #results li a').forEach(h => { |
| 77 |
h.innerText = h.innerText.replace('org::kde::kirigami::templates::', 'Kirigami.Templates.'); |
| 78 |
h.innerText = h.innerText.replace('org::kde::kirigami::', 'Kirigami.'); |
| 79 |
}); |
| 80 |
|
| 81 |
} |
| 82 |
|
| 83 |
function search_json_library(json, query) |
| 84 |
{ |
| 85 |
var results_name = [] |
| 86 |
var results_text = [] |
| 87 |
$.each(json.docfields, function(key, val) { |
| 88 |
if ('name' in val) { |
| 89 |
if (val.name.search(new RegExp(query, "i")) != -1) { |
| 90 |
results_name.push(val) |
| 91 |
} |
| 92 |
} |
| 93 |
if ('text' in val) { |
| 94 |
if (val.text.search(new RegExp(query, "i")) != -1) { |
| 95 |
results_text.push(val) |
| 96 |
} |
| 97 |
} |
| 98 |
}); |
| 99 |
|
| 100 |
var html_results = "" |
| 101 |
html_results += "<h3>Matches in names</h3>\n" |
| 102 |
html_results += "<ul>\n" |
| 103 |
$.each(results_name, function(key, result) { |
| 104 |
html_results += "\t<li><a href=\"" + result.url + "\">"+ result.name + "</a>\n" |
| 105 |
}); |
| 106 |
html_results += "</ul>\n" |
| 107 |
|
| 108 |
html_results += "<h3>Matches in text</h3>\n" |
| 109 |
html_results += "<ul>\n" |
| 110 |
$.each(results_text, function(key, result) { |
| 111 |
html_results += "\t<li><a href=\"" + result.url + "\">"+ result.name + "</a>: " + result.text +"\n" |
| 112 |
}); |
| 113 |
html_results += "</ul>\n" |
| 114 |
|
| 115 |
return html_results |
| 116 |
} |
| 117 |
|
| 118 |
function search_json_group(json, query) |
| 119 |
{ |
| 120 |
var results_name = [] |
| 121 |
var results_text = [] |
| 122 |
|
| 123 |
$.each(json.libraries, function(k, libval) { |
| 124 |
if ('fancyname' in libval) { |
| 125 |
libname = libval.fancyname |
| 126 |
} |
| 127 |
|
| 128 |
$.each(libval.docfields, function(key, val) { |
| 129 |
if ('name' in val) { |
| 130 |
if (val.name.search(new RegExp(query, "i")) != -1) { |
| 131 |
val['libname'] = libname |
| 132 |
results_name.push(val) |
| 133 |
} |
| 134 |
} |
| 135 |
if ('text' in val) { |
| 136 |
if (val.text.search(new RegExp(query, "i")) != -1) { |
| 137 |
val['libname'] = libname |
| 138 |
results_text.push(val) |
| 139 |
} |
| 140 |
} |
| 141 |
}); |
| 142 |
}); |
| 143 |
|
| 144 |
var html_results = "" |
| 145 |
html_results += "<h3>Matches in names</h3>\n" |
| 146 |
html_results += "<ul>\n" |
| 147 |
$.each(results_name, function(key, result) { |
| 148 |
html_results += "\t<li><a href=\"" + result.url + "\">"+ result.name + "</a> in <i>" + result.libname +"</i>\n" |
| 149 |
}); |
| 150 |
html_results += "</ul>\n" |
| 151 |
|
| 152 |
html_results += "<h3>Matches in text</h3>\n" |
| 153 |
html_results += "<ul>\n" |
| 154 |
$.each(results_text, function(key, result) { |
| 155 |
html_results += "\t<li><a href=\"" + result.url + "\">"+ result.name + "</a> in <i>" + result.libname +"</i><br />" + result.text +"\n" |
| 156 |
}); |
| 157 |
html_results += "</ul>\n" |
| 158 |
|
| 159 |
return html_results |
| 160 |
} |
| 161 |
|
| 162 |
function search_json_global(json, query) |
| 163 |
{ |
| 164 |
var results_name = [] |
| 165 |
var results_text = [] |
| 166 |
|
| 167 |
$.each(json.all, function(k, productval) { |
| 168 |
if ('fancyname' in productval) { |
| 169 |
productname = productval.fancyname |
| 170 |
} |
| 171 |
|
| 172 |
$.each(productval.libraries, function(k, libval) { |
| 173 |
if ('fancyname' in libval) { |
| 174 |
libname = libval.fancyname |
| 175 |
} |
| 176 |
|
| 177 |
$.each(libval.docfields, function(key, val) { |
| 178 |
if ('name' in val) { |
| 179 |
if (val.name.search(new RegExp(query, "i")) != -1) { |
| 180 |
val['libname'] = libname |
| 181 |
val['productname'] = productname |
| 182 |
results_name.push(val) |
| 183 |
} |
| 184 |
} |
| 185 |
if ('text' in val) { |
| 186 |
if (val.text.search(new RegExp(query, "i")) != -1) { |
| 187 |
val['libname'] = libname |
| 188 |
val['productname'] = productname |
| 189 |
results_text.push(val) |
| 190 |
} |
| 191 |
} |
| 192 |
}); |
| 193 |
}); |
| 194 |
}); |
| 195 |
|
| 196 |
var html_results = "" |
| 197 |
html_results += "<h3>Matches in names</h3>\n" |
| 198 |
html_results += "<ul>\n" |
| 199 |
$.each(results_name, function(key, result) { |
| 200 |
html_results += "\t<li><a href=\"" + result.url + "\">"+ result.name + |
| 201 |
"</a> in <i>" + result.libname +"</i> from product <i>" + |
| 202 |
result.productname + "</i>\n" |
| 203 |
}); |
| 204 |
html_results += "</ul>\n" |
| 205 |
|
| 206 |
html_results += "<h3>Matches in text</h3>\n" |
| 207 |
html_results += "<ul>\n" |
| 208 |
$.each(results_text, function(key, result) { |
| 209 |
html_results += "\t<li><a href=\"" + result.url + "\">"+ result.name + |
| 210 |
"</a> in <i>" + result.libname +"</i> from product <i>" + |
| 211 |
result.productname + "</i><br />" + result.text +"\n" |
| 212 |
}); |
| 213 |
html_results += "</ul>\n" |
| 214 |
|
| 215 |
return html_results |
| 216 |
} |