Abstract |
---|
The rwt-favorites DOM component uses the browser's local-storage facility to hold a website-specific list of favorite pages. Visitors can add or remove pages from the list using a popup dialog box. |
When browsing for information, it's common to glance over page after page of "not quite what I'm looking for" stuff. When you finally discover the gem you're looking for, you naturally don't want to lose it.
Saving that page to your browser's list of favorites is a common way to keep track of important URLs. Unfortunately, the browser's list of favorites tends to get so cluttered over time that it's no longer useful.
This rwt-favorites DOM component is a way to give a similar functionality to your visitors, but on a local website basis. Users can save pages for later in-depth reading, or for follow-up work, or for ready reference. It is most useful on large websites.
To see an example of this component in use, visit the BLUEPHRASE website and press F8 "Favorites". 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.
The rwt-favorites 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 NPM
OPTION 1: Familiar with Node.js and the package.json
file?
Great. Install the component with this command:
npm install rwt-favorites
OPTION 2: No prior experience using NPM?
Just follow these general steps:
- Install Node.js/NPM on your development computer.
- Create a
package.json
file in the root of your web project using the command: - Download and install the DOM component using the command:
npm init
npm install rwt-favorites
Important note: This DOM component uses Node.js and NPM and package.json
as a convenient distribution and installation mechanism. The DOM component itself does not need them.
Download using Github
If you prefer using Github directly, simply follow these steps:
- Create a
node_modules
directory in the root of your web project. - Clone the rwt-favorites DOM component into it using the command:
git clone https://github.com/readwritetools/rwt-favorites.git
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-favorites.js
file:
<script src='/node_modules/rwt-favorites/rwt-favorites.js' type=module></script>
-
Add the component tag somewhere on the page.
- For scripting purposes, apply an
id
attribute. - Optionally, apply a
sourceref
attribute with a reference to a JSON file containing initial favorites. - And for WAI-ARIA accessibility apply a
role=search
attribute.
- For scripting purposes, apply an
<rwt-favorites id=favorites sourceref='/initial-favorites.json' role=search></rwt-favorites>
- Add a button for the visitor to click to show the dialog:
<a id=favorite-button title='Favorites (F7)'>★</a>
- Add a listener to respond to the click event:
<script type=module>
document.getElementById('favorite-button').addEventListener('click', (e) => {
document.getElementById('favorites').toggleDialog(e);
});
</script>
The JSON file referenced by the sourceref
attribute is used to initialize the
local-storage area with "favorites" that you think are appropriate for
first-time visitors. It is only used the first time a visitor encounters this
component on any page in your website. It is ignored from then on.
The format for this JSON file follows this pattern:
[
{
"filePath": "/page1.html",
"title": "Page 1",
"description": "The most important feature of this website",
"star": true
},
{
"filePath": "...",
"title": "...",
"description": "...",
"star": true
}
]
The dialog is absolutely positioned towards the bottom right of the viewport.
Its size may be overridden using CSS by defining new values for --width
and --height
.
rwt-favorites {
--width: 70vw;
--height: 50vh;
--bottom: 1rem;
--right: 1rem;
}
The default color palette for the dialog uses a dark mode theme. You can use CSS to override the variables' defaults:
rwt-favorites {
--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);
}
The visitor's favorites are stored in local-storage under the key favorite-data
.
The component issues life-cycle events.
component-loaded
- Sent when the component is fully loaded and ready to be used. As a convenience you can use the
waitOnLoading()
method which returns a promise that resolves when thecomponent-loaded
event is received. Call this asynchronously withawait
.
![]() | Documentation | READ WRITE HUB |
![]() | Source code | github |
![]() | Component catalog | DOM COMPONENTS |
![]() | Package installation | npm |
![]() | Publication venue | READ WRITE STACK |
The rwt-favorites 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 .
Favorites Software License Agreement
- This Software License Agreement ("Agreement") is a legal contract between you and Read Write Tools ("RWT"). The "Materials" subject to this Agreement include the "Favorites" software and associated documentation.
- By using these Materials, you agree to abide by the terms and conditions of this Agreement.
- The Materials are protected by United States copyright law, and international treaties on intellectual property rights. The Materials are licensed, not sold to you, and can only be used in accordance with the terms of this Agreement. RWT is and remains the owner of all titles, rights and interests in the Materials, and RWT reserves all rights not specifically granted under this Agreement.
- Subject to the terms of this Agreement, RWT hereby grants to you a limited, non-exclusive license to use the Materials subject to the following conditions:
- You may not distribute, publish, sub-license, sell, rent, or lease the Materials.
- You may not decompile or reverse engineer any source code included in the software.
- You may not modify or extend any source code included in the software.
- Your license to use the software is limited to the purpose for which it was originally intended, and does not include permission to extract, link to, or use parts on a separate basis.
- Each paid license allows use of the Materials under one "Fair Use Setting". Separate usage requires the purchase of a separate license. Fair Use Settings include, but are not limited to: eBooks, mobile apps, desktop applications and websites. The determination of a Fair Use Setting is made at the sole discretion of RWT. For example, and not by way of limitation, a Fair Use Setting may be one of these:
- An eBook published under a single title and author.
- A mobile app for distribution under a single app name.
- A desktop application published under a single application name.
- A website published under a single domain name. For this purpose, and by way of example, the domain names "alpha.example.com" and "beta.example.com" are considered to be separate websites.
- A load-balanced collection of web servers, used to provide access to a single website under a single domain name.
- THE MATERIALS ARE PROVIDED BY READ WRITE TOOLS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL READ WRITE TOOLS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- This license is effective for a one year period from the date of purchase or until terminated by you or Read Write Tools. Continued use, publication, or distribution of the Materials after the one year period, under any of this Agreement's Fair Use Settings, is subject to the renewal of this license.
- Products or services that you sell to third parties, during the valid license period of this Agreement and in compliance with the Fair Use Settings provision, may continue to be used by third parties after the effective period of your license.
- If you decide not to renew this license, you must remove the software from any eBook, mobile app, desktop application, web page or other product or service where it is being used.
- Without prejudice to any other rights, RWT may terminate your right to use the Materials if you fail to comply with the terms of this Agreement. In such event, you shall uninstall and delete all copies of the Materials.
- This Agreement is governed by and interpreted in accordance with the laws of the State of California. If for any reason a court of competent jurisdiction finds any provision of the Agreement to be unenforceable, that provision will be enforced to the maximum extent possible to effectuate the intent of the parties and the remainder of the Agreement shall continue in full force and effect.
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:
export default [{ "product-key": "rwt-favorites", "registration": "example.com", "customer-number": "CN-xxx-yyyyy", "access-key": "AK-xxx-yyyyy" }]