1.0.24 ā€¢ Published 3 years ago

rwt-favorites v1.0.24

Weekly downloads
81
License
see license.html
Repository
github
Last release
3 years ago
Premium DOM Component

Favorites

Site-specific favorites dialog

Motivation

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.

In the wild

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.

Installation

Prerequisites

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 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's rwt-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.
<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>

Customization

Preset favorites

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
    }
]

Dialog size and position

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;
}

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-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);
}

Internals

The visitor's favorites are stored in local-storage under the key favorite-data.

Life-cycle events

The component issues life-cycle events.


Reference

License

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 .

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:

1.0.24

3 years ago

1.0.23

3 years ago

1.0.22

3 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago