Skip to content

Commit

Permalink
Highlight a content searching keyword on show more comments (#6974)
Browse files Browse the repository at this point in the history
  • Loading branch information
yurabakhtin committed Apr 29, 2024
1 parent 76a30f9 commit f595527
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-DEV.md
Expand Up @@ -15,6 +15,7 @@ HumHub Changelog
- Fix #6967: Use same order for meta searching that is used for content page searching by default
- Enh #6968: Meta search: open external links in new window
- Fix #6970: MultiSelect loads wrong options (since #6768 in 1.16.0-beta.1)
- Enh #6974: Highlight a content searching keyword on show more comments

1.16.0-beta.2 (April 9, 2024)
-----------------------------
Expand Down
Expand Up @@ -251,6 +251,12 @@ humhub.module('comment', function (module, require, $) {
: $container.append($html);
evt.$trigger.closest('.showMore').remove();
additions.applyTo($html);

// Highlight currently searching keywords in the loaded comments
const contentSearchKeyword = $('.container-contents .form-search input[name=keyword]');
if (contentSearchKeyword.length && contentSearchKeyword.val().length) {
contentSearchKeyword.val().split(' ').forEach((keyword) => $html.highlight(keyword))
}
}).catch(function (err) {
module.log.error(err, true);
loader.unset(evt.$trigger);
Expand Down
10 changes: 10 additions & 0 deletions protected/humhub/modules/comment/widgets/ShowMore.php
Expand Up @@ -4,6 +4,7 @@

use humhub\components\behaviors\PolymorphicRelation;
use humhub\modules\comment\models\Comment;
use humhub\modules\content\controllers\SearchController;
use Yii;
use yii\base\Widget;
use yii\helpers\Url;
Expand Down Expand Up @@ -65,6 +66,7 @@ public function run()
'type' => $this->type,
]),
'type' => $this->type,
'linkStyleClass' => $this->getLinkStyleClass(),
]);
}

Expand All @@ -84,4 +86,12 @@ public function getCount(): int
return $this->_count;
}

protected function getLinkStyleClass(): ?string
{
// Highlight it on Content Search page
return Yii::$app->controller instanceof SearchController && Yii::$app->controller->action->id === 'results'
? 'highlight'
: null;
}

}
3 changes: 2 additions & 1 deletion protected/humhub/modules/comment/widgets/views/showMore.php
Expand Up @@ -6,10 +6,11 @@
/* @var $text string */
/* @var $showMoreUrl string */
/* @var $type string */
/* @var $linkStyleClass string */
?>
<div class="showMore">
<?php if ($type == ShowMore::TYPE_NEXT) : ?>
<hr class="comment-separator">
<?php endif; ?>
<?= Link::withAction($text, 'comment.showMore', $showMoreUrl)->options(['data-type' => $type]) ?>
<?= Link::withAction($text, 'comment.showMore', $showMoreUrl)->options(['data-type' => $type])->cssClass($linkStyleClass) ?>
</div>
2 changes: 1 addition & 1 deletion protected/humhub/modules/content/views/search/_layout.php
Expand Up @@ -4,6 +4,6 @@

/* @var $content string */
?>
<div class="<?php if (ThemeHelper::isFluid()): ?>container-fluid<?php else: ?>container<?php endif; ?> container-cards container-spaces">
<div class="<?php if (ThemeHelper::isFluid()): ?>container-fluid<?php else: ?>container<?php endif; ?> container-cards container-contents">
<?= $content; ?>
</div>

0 comments on commit f595527

Please sign in to comment.