rwt-search
v1.0.42
Published
Full text search across a website, a standards-based DOM Component
Downloads
40
Maintainers
Readme
Premium DOM Component
Site Search
Full text search with look-ahead autofill
Motivation
The SEMWORDS and SITEWORDS tools (see Site Search ) produce an index of all the words used in a given website. That index is used by this DOM component to provide full text searching on a local basis, without relying on AJAX or direct server interaction.
This DOM component handles the initial fetch of the site index, caching it to the user's local-storage for ready use across all of the website's documents.
Internally, the DOM component uses a ternary search trie to provide partial word lookups as the user types, guiding the user towards better results.
In the wild
To see an example of this component in use, visit the READ WRITE STACK website and press F7 "Search". To understand what's going on under the hood, use the browser's inspector to view the HTML source code and network activity, and follow along as you read this documentation.
Installation
Prerequisites
The rwt-search DOM component works in any browser that supports modern W3C standards. Templates are written using BLUE PHRASE notation, which can be compiled into HTML using the free Read Write View desktop app. It has no other prerequisites. Distribution and installation are done with either NPM or via Github.
Download
Using the DOM component
After installation, you need to add four things to your HTML page to make use of it.
- Add a
script
tag to load the component'srwt-search.js
file:
<script src='/node_modules/rwt-search/rwt-search.js' type=module></script>
Add the component tag somewhere on the page.
- For scripting purposes, apply an
id
attribute. - Apply a
sourceref
attribute with a reference to the full-text word index file created by the SITEWORDS utility. - Optionally, apply a shortcut attribute with something like F2, F4, etc. for hotkey access.
- And for WAI-ARIA accessibility apply a
role=search
attribute.
- For scripting purposes, apply an
<rwt-search id=search sourceref='/data/sitewords' shortcut=F4 role=search></rwt-search>
- Add a button for the visitor to click to show the dialog:
<a id=search-button title='Search (F4)'>
🔎
</a>
- Add a listener to respond to the click event:
<script type=module>
document.getElementById('search-button').addEventListener('click', (e) => {
document.getElementById('search').toggleDialog(e);
});
</script>
Customization
Dialog size and position
The dialog is absolutely positioned towards the bottom right of the viewport. Its position and size may be overridden using CSS by defining new values for the variables:
rwt-search {
--width: 70vw;
--height: 75vh;
--bottom: 1rem;
--right: 1rem;
}
Dialog color scheme
The default color palette for the dialog uses a dark mode theme. You can use CSS to override the variables' defaults:
rwt-search {
--color: var(--white);
--accent-color1: var(--pure-white);
--accent-color2: var(--yellow);
--accent-color3: var(--js-blue);
--background: var(--black);
--accent-background1: var(--medium-black);
--accent-background2: var(--pure-black);
--accent-background3: var(--nav-black);
--accent-background4: var(--black);
}
Internals
The browser's local-storage area is used to cache the sitewords file and the user's most recent search terms. These keys are set by the DOM component:
Life-cycle events
The component issues life-cycle events.
Reference
License
The rwt-search DOM component is not freeware. After evaluating it and before using it in a public-facing website, eBook, mobile app, or desktop application, you must obtain a license from Read Write Tools .
Activation
To activate your license, copy the rwt-registration-keys.js
file to the root
directory of your website, providing the customer-number
and access-key
sent to
your email address, and replacing example.com
with your website's hostname.
Follow this example: