Skip to content

Commit a09b2c5

Browse files
LightLight
authored andcommitted
feat: 支持在搜索框内显示清空按钮
1 parent fc5ac29 commit a09b2c5

4 files changed

Lines changed: 43 additions & 5 deletions

File tree

src/css/nav.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
border: 1px solid #e6e6e6;
4949
border-radius: 10px;
5050
}
51+
.search-input.can-clean {
52+
padding: 0 70px 0 45px;
53+
}
5154
.search-input:focus {
5255
outline: none;
5356
border: 1px solid #2188ff;
@@ -59,6 +62,18 @@ input::-webkit-input-placeholder {
5962
letter-spacing: 1px;
6063
color: #ccc;
6164
}
65+
.search-clean {
66+
position: absolute;
67+
right: 45px;
68+
top: 25%;
69+
background: transparent;
70+
border: none;
71+
color: #ddd;
72+
font-size: 18px;
73+
}
74+
.search-clean:hover {
75+
color: #8e262a;
76+
}
6277
.search-btn {
6378
position: absolute;
6479
right: 0;

src/footer.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,22 @@ function darkHandler(darkMode, mode, write = false) {
178178
})
179179
})();
180180
</script>
181+
<?php if($this->options->isSearchClean == '1'): ?>
182+
<script type="text/javascript">
183+
(function () {
184+
const searchCleanBtn = document.getElementById('search-clean');
185+
searchCleanBtn && searchCleanBtn.addEventListener('click', e => {
186+
e.stopPropagation();
187+
const txtInput = document.getElementById('txt');
188+
if (txtInput) {
189+
txtInput.value = '';
190+
txtInput.focus();
191+
}
192+
})
193+
})();
194+
</script>
195+
<?php endif; ?>
196+
181197

182198
<style>
183199
<?php if ($this->options->isSearchTop == '1') : ?>

src/functions.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ function themeConfig($form)
260260
$form->addInput($isSearch);
261261
$isSearchTop = new Typecho_Widget_Helper_Form_Element_Radio('isSearchTop', array('0' => _t('禁用'), '1' => _t('启用')), '0', _t('搜索框置顶'), _t('始终将搜索框置顶,即不受页面滚动影响'));
262262
$form->addInput($isSearchTop);
263+
// 搜索框内的清空按钮
264+
$isSearchClean = new Typecho_Widget_Helper_Form_Element_Radio('isSearchClean', array('0' => _t('禁用'), '1' => _t('启用')), '0', _t('搜索框内容清空按钮'), _t('在搜索框内一个显示清空内容的按钮'));
265+
$form->addInput($isSearchClean);
263266
// 右侧浮动窗
264267
$fk_zmki = new Typecho_Widget_Helper_Form_Element_Radio('fk_zmki', array('0' => _t('禁用'), '1' => _t('启用')), '1', _t('右侧浮动窗'), _t("是否显示右侧浮动窗,包含返回顶部按钮以及手机端的侧栏切换"));
265268
$form->addInput($fk_zmki);

src/search.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
<section class="sousuo">
22
<div class="search">
33
<div class="search-box">
4-
<span class="search-icon" style="background: url(<?php echo THEME_URL ?>/fonts/baidu.svg) 0px 0px; opacity: 1;"></span>
5-
<input type="text" id="txt" class="search-input" autocomplete="off" placeholder="输入关键字,按下回车搜索">
4+
<span class="search-icon"
5+
style="background: url(<?php echo THEME_URL ?>/fonts/baidu.svg) 0px 0px; opacity: 1;"></span>
6+
<input type="text" id="txt" class="search-input <?php echo $this->options->isSearchClean == '1' ? 'can-clean' : ''; ?>" autocomplete="off" placeholder="输入关键字,按下回车搜索">
7+
<?php if($this->options->isSearchClean == '1'): ?>
8+
<button class="search-clean" id="search-clean" title="清空内容"><i class="fa fa-close"></i></button>
9+
<?php endif; ?>
610
<button class="search-btn" id="search-btn"><i class="fa fa-search"></i></button>
711
</div>
812
<!-- 搜索索引 -->
@@ -15,8 +19,8 @@
1519
<strong class="search-engine-tit">选择您的默认搜索引擎:</strong>
1620
<div class="search-engine-tool">检索已有网址: <span id="hot-btn"></span></div>
1721
</div>
18-
<ul class="search-engine-list search-engine-list_zmki_ul">
22+
<ul class="search-engine-list search-engine-list_zmki_ul">
1923
</ul>
2024
</div>
21-
</div>
22-
</section>
25+
</div>
26+
</section>

0 commit comments

Comments
 (0)