mirror of
https://github.com/humhub/humhub.git
synced 2025-01-17 06:08:21 +01:00
Highlight content after open a page from search results (#7157)
This commit is contained in:
parent
de2027b913
commit
589d12cbee
@ -15,6 +15,7 @@ HumHub Changelog
|
|||||||
- Fix #7141: Fix meta searching twice for the same keyword
|
- 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 #7150: Remove js statement `with` to avoid error on build assets by grunt uglify
|
||||||
- Fix #7156: Fix duplicated following spaces in the chooser widget
|
- 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)
|
1.16.1 (July 1, 2024)
|
||||||
---------------------
|
---------------------
|
||||||
|
@ -32,12 +32,36 @@ class ContentHighlightAsset extends AssetBundle
|
|||||||
{
|
{
|
||||||
parent::init();
|
parent::init();
|
||||||
|
|
||||||
if (Yii::$app instanceof Application && Yii::$app->isInstalled()) {
|
$keyword = $this->getKeyword();
|
||||||
$highlight = Yii::$app->session->get('contentHighlight');
|
if ($keyword !== null) {
|
||||||
if ($highlight !== null && $highlight !== '') {
|
Yii::$app->view->registerJsConfig('content.highlight', ['keyword' => $keyword]);
|
||||||
Yii::$app->session->remove('contentHighlight');
|
|
||||||
Yii::$app->view->registerJsConfig('content.highlight', ['keyword' => $highlight]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,13 @@ humhub.module('content.highlight', function (module, require, $) {
|
|||||||
const event = require('event');
|
const event = require('event');
|
||||||
const highlightWords = require('ui.additions').highlightWords;
|
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 () {
|
const init = function () {
|
||||||
|
$(document).ready(() => highlight());
|
||||||
|
|
||||||
event.on('humhub:modules:content:highlight:afterInit', () => highlight());
|
event.on('humhub:modules:content:highlight:afterInit', () => highlight());
|
||||||
layout.find('[data-ui-widget="ui.richtext.prosemirror.RichText"]')
|
layout.find('[data-ui-widget="ui.richtext.prosemirror.RichText"]')
|
||||||
.on('afterRender', (obj) => highlight(obj.target));
|
.on('afterRender', (obj) => highlight(obj.target));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user