Skip to content

Commit

Permalink
Highlight keyword search words
Browse files Browse the repository at this point in the history
  • Loading branch information
molotow11 committed May 31, 2023
1 parent fa8144c commit 83e1312
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Binary file modified plg_articles_good_search.zip
Binary file not shown.
25 changes: 25 additions & 0 deletions plg_articles_good_search/template/com_content/gsearch_blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,31 @@
JHtml::_('bootstrap.framework');
$document->addStyleSheet(JURI::root(true) . '/media/jui/css/icomoon.css');

?>

<script>
jQuery(document).ready(function() {
jQuery.fn.highlight = function (str, className) {
var regex = new RegExp(str, "gi");
return this.each(function () {
jQuery(this).contents().filter(function() {
return this.nodeType == 3 && regex.test(this.nodeValue);
}).replaceWith(function() {
return (this.nodeValue || "").replace(regex, function(match) {
return "<span style='background-color: #ffff00; font-weight: bold; padding: 2px 5px;' class=\"" + className + "\">" + match + "</span>";
});
});
});
};
<?php if(JRequest::getVar("keyword", "") != "") : ?>
jQuery(".blog-gsearch *").highlight("<?php echo JRequest::getVar("keyword", ""); ?>", "highlight");
<?php endif; ?>
});

</script>

<?php

// switch to table template
if(JRequest::getVar("search_layout", $model->module_params->results_template) == "table") {
require_once(__DIR__ . '/gsearch_table.php');
Expand Down

0 comments on commit 83e1312

Please sign in to comment.