holmes

holmes

holmes

new holmes()

search for dom elements on your page For legacy reasons, this class is a function, and thus doesn't have a capital You can fix this by using var Holmes = holmes before doing new Holmes.
Parameters:
Name Type Attributes Default Description
options.input string optional
'input[type=search]' A querySelector to find the input
options.find string A querySelectorAll rule to find each of the find terms
options.placeholder string optional
Text to show when there are no results (innerHTML)
options.mark bool optional
false Whether to <mark></mark> the matching text Text to show when there are no results (innerHTML)
options.class.visible string optional
false class to add to matched items
options.class.hidden string optional
'hidden' class to add to non-matched items
options.dynamic boolean optional
false Whether to query for the content of the elements on every input. If this is false, then only when initializing the script will fetch the content of the elements to search in. If this is true then it will refresh on every input event.
options.contenteditable boolean optional
false DEPRECATED (now handled automatically) whether the input is a contenteditable or not. By default it's assumed that it's <input>, true here will use <div contenteditable>
options.instant boolean optional
false DEPRECATED!!, after v1.13.3 use holmes({}).start(); instead By default Holmes waits for the DOMContentLoaded event to fire before listening. This is to make sure that all content is available. However if you exactly know when all your content is available (ajax, your own event or other situations), you can put this option on true.
options.minCharacters number optional
0 The minimum amount of characters to be typed before Holmes starts searching. Beware that this also counts when backspacing.
options.hiddenAttr boolean optional
true Adds hidden="true" to hidden elements. interesting link explaining its use.
options.onHidden onChange optional
Callback for when an item is hidden.
options.onVisible onChange optional
Callback for when an item is visible again.
options.onEmpty onChange optional
Callback for when no items were found.
options.onFound onChange optional
Callback for when items are found after being empty.
options.onInput onInput optional
Callback for every input.

Members

elements

(static) elements :NodeList

All of the elements that are searched
Type:
  • NodeList

elementsArray

(static) elementsArray :Array

all of the elements that are searched as an array
Type:

elementsLength

(static) elementsLength :Number

amount of elements to search
Type:

input

(static) input :NodeList

The input element
Type:
  • NodeList

placeholderNode

(static) placeholderNode :Element

Placeholder element
Type:
  • Element

searchString

(static) searchString :string

Lowercase string holmes searces for
Type:

Methods

clear

(static) clear()

empty the search string programmatically. This avoids having to send a new `input` event

count

(static) count() → {object}

Show the amount of elements, and those hidden and visible
Returns:
all matching elements, the amount of hidden and the amount of visible elements
Type
object

inputString

(static) inputString() → {String}

The current search input in lower case
Throws:
If The current input is no <input> or contenteditable
Type
Error
Returns:
the input as a string
Type
String

setInput

(static) setInput(value)

Sets an input string
Parameters:
Name Type Description
value string the string to set
Throws:
If The current input is no <input> or contenteditable
Type
Error

start

(static) start()

Start an event listener with the specified options
Throws:
  • If a there was no options.find
    Type
    Error
  • If the placeholder couldn't be inserted
    Type
    Error
  • If the .input isn't valid
    Type
    Error

stop

(static) stop() → {Promise}

remove the current event listener
See:
  • this.start
Throws:
If the placeholder couldn't be removed because it has no parent
Type
Error
Returns:
resolves when the event is removed
Type
Promise

Type Definitions

onChange

onChange(HTMLElementopt)

Callback used for changes in item en list states.
Parameters:
Name Type Attributes Description
HTMLElement object optional
Element affected by the event. This is the item found by onVisible and onHidden and the placeholder (or undefined) for onEmpty and onFound.

onInput

onInput(input)

Callback used for changes in input value
Parameters:
Name Type Description
input string The value that is currently in the search field