Skip to content
Snippets Groups Projects
Unverified Commit 4eab6f7c authored by Michael Große's avatar Michael Große
Browse files

feat(search): trigger event for each result

Add events around each search result, both for the pagename results
and the fullpage results.

The fullpage results are wrapped in a div for better separation and
styling.
( see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dl )

These events are intended to provide plugin authors with the ability
to hydrate the search results with more information.
parent bb8ef867
No related branches found
No related tags found
No related merge requests found
...@@ -280,19 +280,13 @@ class Search extends Ui ...@@ -280,19 +280,13 @@ class Search extends Ui
$html .= '<h3>' . $lang['quickhits'] . ':</h3>'; $html .= '<h3>' . $lang['quickhits'] . ':</h3>';
$html .= '<ul class="search_quickhits">'; $html .= '<ul class="search_quickhits">';
foreach ($data as $id => $title) { foreach ($data as $id => $title) {
$html .= '<li> '; $link = html_wikilink(':' . $id);
if (useHeading('navigation')) { $eventData = [
$name = $title; 'listItemContent' => [$link],
} else { 'page' => $id,
$ns = getNS($id); ];
if ($ns) { trigger_event('SEARCH_RESULT_PAGELOOKUP', $eventData);
$name = shorten(noNS($id), ' (' . $ns . ')', 30); $html .= '<li>' . implode('', $eventData['listItemContent']) . '</li>';
} else {
$name = $id;
}
}
$html .= html_wikilink(':' . $id, $name);
$html .= '</li> ';
} }
$html .= '</ul> '; $html .= '</ul> ';
//clear float (see http://www.complexspiral.com/publications/containing-floats/) //clear float (see http://www.complexspiral.com/publications/containing-floats/)
...@@ -322,18 +316,27 @@ class Search extends Ui ...@@ -322,18 +316,27 @@ class Search extends Ui
$html .= '<dl class="search_results">'; $html .= '<dl class="search_results">';
$num = 1; $num = 1;
foreach ($data as $id => $cnt) { foreach ($data as $id => $cnt) {
$html .= '<dt>'; $resultLink = html_wikilink(':' . $id, null, $highlight);
$html .= html_wikilink(':' . $id, useHeading('navigation') ? null : $id, $highlight); $hits = '';
if ($cnt !== 0) { $snippet = '';
$html .= ': ' . $cnt . ' ' . $lang['hits'] . '';
}
$html .= '</dt>';
if ($cnt !== 0) { if ($cnt !== 0) {
$hits = $cnt . ' ' . $lang['hits'];
if ($num < FT_SNIPPET_NUMBER) { // create snippets for the first number of matches only if ($num < FT_SNIPPET_NUMBER) { // create snippets for the first number of matches only
$html .= '<dd>' . ft_snippet($id, $highlight) . '</dd>'; $snippet = '<dd>' . ft_snippet($id, $highlight) . '</dd>';
} }
$num++; $num++;
} }
$eventData = [
'resultHeader' => [$resultLink, $hits],
'resultBody' => [$snippet],
'page' => $id,
];
trigger_event('SEARCH_RESULT_FULLPAGE', $eventData);
$html .= '<div class="search_fullpage_result">';
$html .= '<dt>' . implode(' ', $eventData['resultHeader']) . '</dt>';
$html .= implode('', $eventData['resultBody']);
$html .= '</div>';
} }
$html .= '</dl>'; $html .= '</dl>';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment