feat(frontend): restore Zibll-like global search panel
Render full search overlay with types/history/suggestions for tabbar and desktop header toggle. Open panel on all viewports (not mobile-only) and wire data-toggle-class/.navbar-search compatibility hooks.
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
/**
|
||||
* Global search panel (desktop + mobile).
|
||||
*
|
||||
* DOM contracts for assets/js/core/search.js and footer-tabbar search tab:
|
||||
* - #tabbar-search-overlay (also #nav-search-panel for shell config)
|
||||
* - #tabbar-search-input / #tabbar-search-close / #tabbar-search-type
|
||||
* - #tabbar-search-types [data-search-type]
|
||||
* - history / suggestions sections
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
if (class_exists('AKSRT_Settings')) {
|
||||
$header_nav = AKSRT_Settings::get_header_nav_settings();
|
||||
if (empty($header_nav['search_enabled'])) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$search_state = function_exists('aksrt_get_search_form_state')
|
||||
? aksrt_get_search_form_state()
|
||||
: [
|
||||
'type' => 'post',
|
||||
'types' => ['post' => __('文章', 'aksrt')],
|
||||
'category_id' => 0,
|
||||
'category_enabled' => false,
|
||||
'categories' => [],
|
||||
];
|
||||
|
||||
$search_type = (string) ($search_state['type'] ?? 'post');
|
||||
$search_type_options = is_array($search_state['types'] ?? null) ? $search_state['types'] : ['post' => __('文章', 'aksrt')];
|
||||
$search_category_enabled = !empty($search_state['category_enabled']);
|
||||
$search_category_id = (int) ($search_state['category_id'] ?? 0);
|
||||
$search_categories = is_array($search_state['categories'] ?? null) ? $search_state['categories'] : [];
|
||||
$search_placeholder = function_exists('aksrt_get_search_placeholder') ? aksrt_get_search_placeholder() : __('开启精彩搜索', 'aksrt');
|
||||
$search_hot_keywords = function_exists('aksrt_get_search_hot_keywords') ? aksrt_get_search_hot_keywords() : [];
|
||||
$history_enabled = function_exists('aksrt_search_history_enabled') ? aksrt_search_history_enabled() : true;
|
||||
$suggestions_enabled = function_exists('aksrt_search_suggestions_enabled') ? aksrt_search_suggestions_enabled() : false;
|
||||
$popular_title = class_exists('AKSRT_Settings') ? AKSRT_Settings::search_popular_title() : __('热门搜索', 'aksrt');
|
||||
?>
|
||||
<div
|
||||
id="tabbar-search-overlay"
|
||||
class="tabbar-search-overlay main-search navbar-search nav-search-panel"
|
||||
data-aksrt-shell="search-panel"
|
||||
data-nav-search-panel="nav-search-panel"
|
||||
hidden
|
||||
aria-hidden="true"
|
||||
>
|
||||
<div class="tabbar-search-overlay__dialog" role="dialog" aria-modal="true" aria-labelledby="tabbar-search-title">
|
||||
<div class="tabbar-search-overlay__head">
|
||||
<strong id="tabbar-search-title"><?php esc_html_e('搜索', 'aksrt'); ?></strong>
|
||||
<button type="button" class="tabbar-search-overlay__close" id="tabbar-search-close" aria-label="<?php esc_attr_e('关闭搜索', 'aksrt'); ?>">
|
||||
<i class="fas fa-times" aria-hidden="true"></i>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<form
|
||||
role="search"
|
||||
method="get"
|
||||
class="tabbar-search-overlay__form search-form"
|
||||
action="<?php echo esc_url(home_url('/')); ?>"
|
||||
data-aksrt-search-form="panel"
|
||||
data-default-search-type="<?php echo esc_attr($search_type); ?>"
|
||||
data-default-category="<?php echo esc_attr((string) $search_category_id); ?>"
|
||||
>
|
||||
<input type="hidden" name="aksrt_search_type" id="tabbar-search-type" value="<?php echo esc_attr($search_type); ?>">
|
||||
<?php if ($search_category_enabled) : ?>
|
||||
<input type="hidden" name="aksrt_category" value="<?php echo esc_attr((string) $search_category_id); ?>">
|
||||
<?php endif; ?>
|
||||
<span class="tabbar-search-overlay__icon" aria-hidden="true"><i class="fas fa-search"></i></span>
|
||||
<label class="screen-reader-text" for="tabbar-search-input"><?php esc_html_e('搜索关键词', 'aksrt'); ?></label>
|
||||
<input
|
||||
id="tabbar-search-input"
|
||||
class="search-input"
|
||||
type="search"
|
||||
name="s"
|
||||
value="<?php echo esc_attr(get_search_query()); ?>"
|
||||
placeholder="<?php echo esc_attr($search_placeholder); ?>"
|
||||
autocomplete="off"
|
||||
enterkeyhint="search"
|
||||
>
|
||||
<button type="submit" class="tabbar-search-overlay__submit"><?php esc_html_e('搜索', 'aksrt'); ?></button>
|
||||
</form>
|
||||
|
||||
<?php if (!empty($search_type_options)) : ?>
|
||||
<div class="tabbar-search-overlay__types" id="tabbar-search-types" aria-label="<?php esc_attr_e('搜索类型', 'aksrt'); ?>">
|
||||
<?php foreach ($search_type_options as $type_key => $type_label) : ?>
|
||||
<button
|
||||
type="button"
|
||||
class="tabbar-search-overlay__type<?php echo $search_type === $type_key ? ' is-active' : ''; ?>"
|
||||
data-search-type="<?php echo esc_attr((string) $type_key); ?>"
|
||||
><?php echo esc_html((string) $type_label); ?></button>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($search_category_enabled && !empty($search_categories)) : ?>
|
||||
<div class="tabbar-search-overlay__section">
|
||||
<label class="tabbar-search-overlay__label" for="tabbar-search-category"><?php esc_html_e('分类', 'aksrt'); ?></label>
|
||||
<select class="nav-searchbox__category" id="tabbar-search-category" data-search-category-select>
|
||||
<option value="0"><?php esc_html_e('全部分类', 'aksrt'); ?></option>
|
||||
<?php foreach ($search_categories as $search_category) : ?>
|
||||
<option value="<?php echo esc_attr((string) $search_category->term_id); ?>"<?php selected($search_category_id, (int) $search_category->term_id); ?>>
|
||||
<?php echo esc_html($search_category->name); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($search_hot_keywords)) : ?>
|
||||
<div class="tabbar-search-overlay__section">
|
||||
<div class="tabbar-search-overlay__section-head">
|
||||
<span class="tabbar-search-overlay__label"><?php echo esc_html($popular_title); ?></span>
|
||||
</div>
|
||||
<?php aksrt_render_search_hot_keywords($search_hot_keywords, 'aksrt-search-hot-keywords'); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($history_enabled) : ?>
|
||||
<div class="tabbar-search-overlay__section" id="tabbar-search-history-section">
|
||||
<div class="tabbar-search-overlay__section-head">
|
||||
<span class="tabbar-search-overlay__label"><?php esc_html_e('历史搜索', 'aksrt'); ?></span>
|
||||
<button type="button" class="tabbar-search-overlay__clear" id="tabbar-search-history-clear" style="display:none;">
|
||||
<?php esc_html_e('清空', 'aksrt'); ?>
|
||||
</button>
|
||||
</div>
|
||||
<div class="tabbar-search-overlay__history" id="tabbar-search-history"></div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($suggestions_enabled) : ?>
|
||||
<div class="tabbar-search-overlay__section" id="tabbar-search-suggestions-section" hidden>
|
||||
<div class="tabbar-search-overlay__section-head">
|
||||
<span class="tabbar-search-overlay__label"><?php esc_html_e('搜索建议', 'aksrt'); ?></span>
|
||||
</div>
|
||||
<div class="tabbar-search-overlay__suggestions" id="tabbar-search-suggestions"></div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user