rwt-reading-summary
v1.0.15
Published
Display reader's experience points and reading history, a standards-based DOM Component
Downloads
4
Maintainers
Readme
Open Source DOM Component
Reading Summary
Display a visitor's reading history
Motivation
As the user moves from page to page within a website, the rwt-reading-points component tracks which pages have been visited, what percentage has been read, and how much time was spent reading each page. This information is kept in the user's local storage.
The rwt-reading-summary DOM component displays the information in summary form.
In the wild
To see an example of this component in use, visit the READ WRITE SERVE website and press F4 "Reading Summary". 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-reading-summary DOM component works in any browser that supports modern W3C standards. Templates are written using BLUEPHRASE 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 several things to your HTML page to make use of it.
- Add a
script
tag to load the component'srwt-reading-summary.js
file:
<script src='/node_modules/rwt-reading-summary/rwt-reading-summary.js' type=module></script>
Add the component tag somewhere on the page.
- For scripting purposes, apply an
id
attribute. - Optionally, apply a
shortcut
attribute with something likeF1
,F2
, etc. for hotkey access. - And for WAI-ARIA accessibility apply a
role=contentinfo
attribute.
- For scripting purposes, apply an
<rwt-reading-summary id=reading-summary role=contentinfo shortcut=F4></rwt-reading-summary>
- Add a button to allow the visitor to show the dialog. Here the button contains
the number '0' as its text. This will be replaced with the user's experience
points when the
rwt-reading-summary-data
event is received.
<a id='reading-summary-button' aria-haspopup='true' aria-controls='reading-summary'>0</a>
- Add a listener to respond to the click event:
<script type=module>
document.getElementById('reading-summary-button').addEventListener('click', (e) => {
document.getElementById('reading-summary').toggleDialog(e);
});
</script>
- Add a listener to capture the
rwt-reading-summary-data
event and show the experience points on the summary button:
<script type=module>
document.addEventListener('rwt-reading-summary-data', (e) => {
var el = document.getElementById('reading-summary-button');
el.innerHTML = e.detail.pointsObtained;
el.title = `Reading Summary: ${e.detail.pagesRead} pages / ${e.detail.readingTime} / ${e.detail.pointsObtained} points / (${e.detail.shortcutKey}) for details`;
});
</script>
Customization
Dialog size and position
The dialog is absolutely positioned towards the bottom left of the viewport. Its size may be overridden using CSS by defining new values for the size and position variables.
rwt-reading-summary {
--width: 70vw;
--height: 50vh;
--bottom: 1rem;
--left: 1rem;
--caption-bar-height: 1.5rem;
--message-height: 1.5rem;
}
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-reading-summary {
--color: var(--white);
--accent-color1: var(--yellow);
--accent-color2: 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);
}
Life-cycle events
The component issues life-cycle events.
Event controllers
The dialog box can be controlled with its event interface.
Reference
License
The rwt-reading-summary DOM component is licensed under the MIT License.