Skip to content

Commit 83e1312

Browse files
committed
Highlight keyword search words
1 parent fa8144c commit 83e1312

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

plg_articles_good_search.zip

312 Bytes
Binary file not shown.

plg_articles_good_search/template/com_content/gsearch_blog.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,31 @@
3131
JHtml::_('bootstrap.framework');
3232
$document->addStyleSheet(JURI::root(true) . '/media/jui/css/icomoon.css');
3333

34+
?>
35+
36+
<script>
37+
jQuery(document).ready(function() {
38+
jQuery.fn.highlight = function (str, className) {
39+
var regex = new RegExp(str, "gi");
40+
return this.each(function () {
41+
jQuery(this).contents().filter(function() {
42+
return this.nodeType == 3 && regex.test(this.nodeValue);
43+
}).replaceWith(function() {
44+
return (this.nodeValue || "").replace(regex, function(match) {
45+
return "<span style='background-color: #ffff00; font-weight: bold; padding: 2px 5px;' class=\"" + className + "\">" + match + "</span>";
46+
});
47+
});
48+
});
49+
};
50+
<?php if(JRequest::getVar("keyword", "") != "") : ?>
51+
jQuery(".blog-gsearch *").highlight("<?php echo JRequest::getVar("keyword", ""); ?>", "highlight");
52+
<?php endif; ?>
53+
});
54+
55+
</script>
56+
57+
<?php
58+
3459
// switch to table template
3560
if(JRequest::getVar("search_layout", $model->module_params->results_template) == "table") {
3661
require_once(__DIR__ . '/gsearch_table.php');

0 commit comments

Comments
 (0)