Highlight content after open a page from search results (#7157)

This commit is contained in:
Yuriy Bakhtin 2024-08-07 22:33:40 +03:00 committed by GitHub
parent de2027b913
commit 589d12cbee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 36 additions and 7 deletions

View File

@ -15,6 +15,7 @@ HumHub Changelog
- Fix #7141: Fix meta searching twice for the same keyword
- Fix #7150: Remove js statement `with` to avoid error on build assets by grunt uglify
- Fix #7156: Fix duplicated following spaces in the chooser widget
- Enh #7157: Highlight content after open a page from search results
1.16.1 (July 1, 2024)
---------------------

View File

@ -32,12 +32,36 @@ class ContentHighlightAsset extends AssetBundle
{
parent::init();
if (Yii::$app instanceof Application && Yii::$app->isInstalled()) {
$highlight = Yii::$app->session->get('contentHighlight');
if ($highlight !== null && $highlight !== '') {
Yii::$app->session->remove('contentHighlight');
Yii::$app->view->registerJsConfig('content.highlight', ['keyword' => $highlight]);
}
$keyword = $this->getKeyword();
if ($keyword !== null) {
Yii::$app->view->registerJsConfig('content.highlight', ['keyword' => $keyword]);
}
}
private function getKeyword(): ?string
{
if (!(Yii::$app instanceof Application && Yii::$app->isInstalled())) {
return null;
}
$keyword = Yii::$app->session->get('contentHighlight');
if ($keyword !== null && $keyword !== '') {
Yii::$app->session->remove('contentHighlight');
return $keyword;
}
$keyword = Yii::$app->request->get('highlight');
if ($keyword !== null && $keyword !== '') {
return $keyword;
}
if (isset(Yii::$app->request->referrer)) {
$url = parse_url(Yii::$app->request->referrer);
if (isset($url['query']) && preg_match('/(^|&|\?)keyword=(.+?)(&|$)/i', $url['query'], $m)) {
return urldecode($m[2]);
}
}
return null;
}
}

View File

@ -3,9 +3,13 @@ humhub.module('content.highlight', function (module, require, $) {
const event = require('event');
const highlightWords = require('ui.additions').highlightWords;
const layout = $('.layout-content-container');
const layout = $('.layout-content-container').length
? $('.layout-content-container')
: $('#layout-content');
const init = function () {
$(document).ready(() => highlight());
event.on('humhub:modules:content:highlight:afterInit', () => highlight());
layout.find('[data-ui-widget="ui.richtext.prosemirror.RichText"]')
.on('afterRender', (obj) => highlight(obj.target));