1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2024-09-24 19:38:27 +02: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 %}
</div>
{% 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>
{% for path in extra_javascript %}
<script src="{{ path }}"></script>

View File

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

View File

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