Meta search from external form

This commit is contained in:
Yuriy Bakhtin 2024-02-27 15:09:11 +01:00
parent 36365887c1
commit 783d791b49
4 changed files with 85 additions and 36 deletions

View File

@ -8,6 +8,7 @@
use humhub\assets\SearchAsset; use humhub\assets\SearchAsset;
use humhub\components\SearchProvider; use humhub\components\SearchProvider;
use humhub\libs\Html; use humhub\libs\Html;
use humhub\modules\ui\icon\widgets\Icon;
use humhub\widgets\Button; use humhub\widgets\Button;
use humhub\widgets\Link; use humhub\widgets\Link;
use humhub\widgets\SearchProviderWidget; use humhub\widgets\SearchProviderWidget;
@ -27,19 +28,20 @@ SearchAsset::register($this);
->options(['data-toggle' => 'dropdown']) ->options(['data-toggle' => 'dropdown'])
->cssClass('dropdown-toggle') ?> ->cssClass('dropdown-toggle') ?>
<div id="dropdown-search" class="dropdown-menu"> <div id="dropdown-search" class="dropdown-menu">
<ul class="dropdown-search-list"> <div class="dropdown-header">
<li class="dropdown-header">
<div class="arrow"></div> <div class="arrow"></div>
<?= Yii::t('base', 'Search') ?> <?= Yii::t('base', 'Search') ?>
</li> <?= Icon::get('close', ['id' => 'dropdown-search-close']) ?>
<li class="dropdown-search-form"> </div>
<div class="dropdown-search-form">
<?= Button::defaultType() <?= Button::defaultType()
->icon('search') ->icon('search')
->action('search') ->action('search')
->cssClass('dropdown-search-button') ->cssClass('dropdown-search-button')
->loader(false) ?> ->loader(false) ?>
<?= Html::input('text', 'keyword', '', ['class' => 'dropdown-search-keyword form-control']) ?> <?= Html::input('text', 'keyword', '', ['class' => 'dropdown-search-keyword form-control']) ?>
</li> </div>
<ul class="dropdown-search-list">
<?php foreach ($searchProviders as $searchProvider) : ?> <?php foreach ($searchProviders as $searchProvider) : ?>
<?= SearchProviderWidget::widget(['searchProvider' => $searchProvider]) ?> <?= SearchProviderWidget::widget(['searchProvider' => $searchProvider]) ?>
<?php endforeach; ?> <?php endforeach; ?>

View File

@ -11,6 +11,7 @@ humhub.module('ui.search', function(module, require, $) {
that.selectors = { that.selectors = {
toggler: '#search-menu[data-toggle=dropdown]', toggler: '#search-menu[data-toggle=dropdown]',
panel: '#dropdown-search', panel: '#dropdown-search',
close: '#dropdown-search-close',
list: '.dropdown-search-list', list: '.dropdown-search-list',
arrow: '.dropdown-header > .arrow', arrow: '.dropdown-header > .arrow',
form: '.dropdown-search-form', form: '.dropdown-search-form',
@ -30,6 +31,10 @@ humhub.module('ui.search', function(module, require, $) {
e.stopPropagation(); e.stopPropagation();
}); });
$(document).on('click', that.selectors.close, function () {
that.getMenuToggler().dropdown('toggle');
});
that.getInput().on('keypress', function (e) { that.getInput().on('keypress', function (e) {
if (e.which === 13) { if (e.which === 13) {
that.search(); that.search();
@ -50,6 +55,10 @@ humhub.module('ui.search', function(module, require, $) {
if (that.getBackdrop().length === 0) { if (that.getBackdrop().length === 0) {
that.$.append('<div class="' + that.selectors.backdrop.replace('.', '') + '">'); that.$.append('<div class="' + that.selectors.backdrop.replace('.', '') + '">');
} }
if (that.getList().is(':visible')) {
// refresh NiceScroll after reopen it with searched results
that.getList().hide().show();
}
}) })
that.initAdditionalToggle(); that.initAdditionalToggle();
@ -171,6 +180,8 @@ humhub.module('ui.search', function(module, require, $) {
return; return;
} }
this.getList().show();
this.getProviders().each(function () { this.getProviders().each(function () {
const provider = $(this); const provider = $(this);
provider.addClass('provider-searching').show() provider.addClass('provider-searching').show()

View File

@ -9,12 +9,12 @@
box-shadow: 0 0 8px #CCC; box-shadow: 0 0 8px #CCC;
top: 115%; top: 115%;
.dropdown-search-list { .dropdown-header {
list-style: none; font-weight: 600;
color: #000;
padding: 20px; padding: 20px;
height: 100%; margin: 0;
} flex: 0 0 auto;
.arrow { .arrow {
position: absolute; position: absolute;
display: block; display: block;
@ -26,23 +26,44 @@
right: 10px; right: 10px;
margin-left: -18px; margin-left: -18px;
border-top-width: 0; border-top-width: 0;
border-bottom-color: #fff; border-bottom-color: #CCC;
top: -8px; top: -8px;
z-index: 1035; z-index: 1035;
&:after {
position: absolute;
border-color: transparent;
border-style: solid;
border-width: 8px;
content: " ";
top: 1px;
margin-left: -8px;
border-top-width: 0;
border-bottom-color: #FFF;
z-index: 1035;
}
}
#dropdown-search-close {
float: right;
font-size: 18px;
cursor: pointer;
} }
.dropdown-header {
font-weight: 600;
color: #000;
padding: 0;
} }
.dropdown-search-form { .dropdown-search-form {
position: relative; position: relative;
padding: 0 20px 20px;
flex: 0 1 auto;
.dropdown-search-keyword { .dropdown-search-keyword {
background: #f8f8f8; background: #f8f8f8;
border-color: #f3f3f3; border-color: #f3f3f3;
padding-left: 32px; padding-left: 32px;
&:-webkit-autofill,
&:-webkit-autofill:hover,
&:-webkit-autofill:focus,
&:-webkit-autofill:active {
-webkit-text-fill-color: #777 !important;
-webkit-box-shadow: 0 0 0 30px #f8f8f8 inset !important;
}
} }
.dropdown-search-button { .dropdown-search-button {
position: absolute; position: absolute;
@ -57,6 +78,17 @@
} }
} }
.dropdown-search-list {
list-style: none;
padding: 0 20px 20px;
display: none;
flex: 0 1 auto;
> li:first-child {
margin-top: 0;
padding-top: 0;
}
}
.dropdown-search-provider { .dropdown-search-provider {
display: none; display: none;
padding-top: 20px; padding-top: 20px;
@ -129,6 +161,10 @@
} }
} }
.open > #dropdown-search.dropdown-menu {
display: flex;
flex-direction: column;
}
.dropdown.search-menu { .dropdown.search-menu {
.dropdown-backdrop { .dropdown-backdrop {

File diff suppressed because one or more lines are too long