1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2024-12-01 02:27:17 +01:00

Reset meta text to placeholder if input is cleared

This commit is contained in:
squidfunk 2017-03-23 23:39:19 +01:00 committed by Martin Donath
parent 931465af9f
commit c732082a1c
5 changed files with 16 additions and 8 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -151,7 +151,7 @@
{% endblock %} {% endblock %}
</div> </div>
{% block scripts %} {% block scripts %}
<script src="{{ base_url }}/assets/javascripts/application-3e4827aebb.js"></script> <script src="{{ base_url }}/assets/javascripts/application-cc8bbd29c0.js"></script>
<script>app.initialize({url:{base:"{{ base_url }}"}})</script> <script>app.initialize({url:{base:"{{ base_url }}"}})</script>
{% for path in extra_javascript %} {% for path in extra_javascript %}
<script src="{{ path }}"></script> <script src="{{ path }}"></script>

View File

@ -232,8 +232,13 @@ function initialize(config) { // eslint-disable-line func-style
/* Search is open */ /* Search is open */
if (toggle.checked) { if (toggle.checked) {
/* Enter: prevent form submission */
if (ev.key === "Enter") {
if (query === document.activeElement)
ev.preventDefault()
/* Escape: close search */ /* Escape: close search */
if (ev.key === "Escape") { } else if (ev.key === "Escape") {
toggle.checked = false toggle.checked = false
toggle.dispatchEvent(new CustomEvent("change")) toggle.dispatchEvent(new CustomEvent("change"))
query.blur() query.blur()

View File

@ -63,6 +63,7 @@ export default class Result {
/* Load messages for metadata display */ /* Load messages for metadata display */
this.message_ = { this.message_ = {
placeholder: this.meta_.textContent,
none: this.meta_.dataset.mdLangResultNone, none: this.meta_.dataset.mdLangResultNone,
one: this.meta_.dataset.mdLangResultOne, one: this.meta_.dataset.mdLangResultOne,
other: this.meta_.dataset.mdLangResultOther other: this.meta_.dataset.mdLangResultOther
@ -154,8 +155,8 @@ export default class Result {
if (!(target instanceof HTMLInputElement)) if (!(target instanceof HTMLInputElement))
throw new ReferenceError throw new ReferenceError
/* Abort early, if input hasn't changed */ /* Abort early, if index is not build or input hasn't changed */
if (target.value === this.value_) if (!this.index_ || target.value === this.value_)
return return
/* Clear current list */ /* Clear current list */
@ -164,8 +165,10 @@ export default class Result {
/* Abort early, if search input is empty */ /* Abort early, if search input is empty */
this.value_ = target.value this.value_ = target.value
if (this.value_.length === 0) if (this.value_.length === 0) {
this.meta_.textContent = this.message_.placeholder
return return
}
/* Perform search on index and group sections by document */ /* Perform search on index and group sections by document */
const result = this.index_ const result = this.index_