npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rwt-sitenav

v1.0.35

Published

Popout site navigation panel, a standards-based DOM Component

Downloads

1

Readme

Open Source DOM Component

Sitenav

Website pull-out navigation

Motivation

Sometimes you need to provide your website visitors with quick access to a large quantity of pages without cluttering the main reading area of the page.

The rwt-sitenav DOM component does this by keeping the menu off the left-hand side of the page until the user needs it. The menu is activated, sliding over the page content, when the user clicks on the hamburger menu button. Activation may also be initiated through the component's toggleMenu method or through its event interface.

The component has these features:

  • The hamburger menu button is subtly displayed along the left-hand margin, appearing brighter on hover.
  • The first few times that a visitor interacts with your website, the menu button pulses to draw attention to itself.
  • The menu scrolls vertically, accommodating any number of menu items.
  • Menu items may be kept separate from the DOM component, allowing the webmaster to change its contents in a single centralized place. Alternatively, menu items may be slotted directly between the component's opening and closing tags.
  • The menu item corresponding to the current page is highlighted and scrolled into view when the page is first loaded.
  • The menu has an event interface for showing and hiding itself.
  • The menu emits a custom event to close sibling menus and dialog boxes.
  • A keyboard listener is provided to allow a shortcut key to open/close the menu.

In the wild

To see an example of this component in use, visit the BLUEFIDDLE website and press F1 "Menu". 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-sitenav 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 two things to your HTML page to make use of it.

  • Add a script tag to load the component's rwt-sitenav.js file:
<script src='/node_modules/rwt-sitenav/rwt-sitenav.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 an HTML file containing the menu's text and any CSS it needs.
    • Optionally, apply a shortcut attribute with something like F9, F10, etc. for hotkey access.
    • For WAI-ARIA accessibility apply a role=navigation attribute.
    • For simple menus, the sourceref may be omitted and the menu hyperlinks may be slotted into the DOM component. Simply place the hyperlinks directly between the <rwt-sitenav> and </rwt-sitenav> tags.
<rwt-sitenav id=sitenav sourceref='/menu.html' shortcut=F9 role=navigation></rwt-sitenav>

Menu template

The content and format of the menu is not prescribed. You may add hyperlinks with formatting that matches your website. Still, one important guideline to keep in mind is that the text of each menu item should be short so that it doesn't wrap into multiple lines. If necessary, the width of the panel can be adjusted using the component's --width CSS variable.

The easiest way to start building your menu is to follow this pattern, which uses list items li for individual pages, and headings h2 for grouping similar pages.

<h2><a href='/products.html' >Products</a></h2>
<ul>
    <li><a href='/products/grappling-hooks.html'>Grappling hooks</a></li>
    <li><a href='/products/ropes.html'>Ropes</a></li>
    <li><a href='/products/carabiners.html'>Carabiners</a></li>
</ul>
<h2><a href='/services.html' >Services</a></h2>
<ul>
    <li><a href='/services/training.html'>Training</a></li>
    <li><a href='/services/certification.html'>Certification</a></li>
</ul>

Self identification

The menu item corresponding to the current page can be highlighted when it identifies itself to the menu. This is accomplished by adding a meta tag to the page that contains the short-form URL of the page itself. For example, if the page's full URL is https://example.com:443/services.html the shortform URL would be /services.html.

The short-form URL may be added to any of three special-purpose meta tags, like this:

<meta name=sitenav:level1 content='/services.html' />
<meta name=sitenav:level2 content='/services/certification.html' />
<meta name=sitenav:level3 content='/services/certification/instructor.html' />

The three items correspond to the artificial hierarchical depth of the menu items. When the page is first loaded, the DOM component uses the content attribute of these meta tags as search terms, looking for the menu item with a matching anchor href. When found, that menu item is highlighted and scrolled into view.

The search for a corresponding href is conducted starting with the deepest level, going from sitenav:level3 to sitenav:level2 to sitenav:level1.

Continuing with the previous example, if the current page is https://example.com:443/services.html , then this menu item will be highlighted:

<h2><a href='/services.html' >Services</a></h2>

Customization

Menu size and position

When visible, the menu is absolutely positioned along the left-hand side of the viewport. Its position and size may be overridden using CSS by defining new values for the top, bottom, and width variables.

rwt-sitenav {
    --top: 0;
    --bottom: 0;
    --width: 15.5rem;
    --z-index: 1;
}

Menu color scheme

The default color palette for the menu uses a dark mode theme. You can use CSS to override the variables' defaults:

rwt-sitenav {
    --background: var(--nav-black);
    --level1-color: var(--title-blue);
    --level2-color: var(--pure-white);
    --accent-color: var(--yellow);
    --accent-background: var(--pure-black);
}

Life-cycle events

The component issues life-cycle events.

Event controllers

The menu can be controlled with its event interface.


Reference

License

The rwt-sitenav DOM component is licensed under the MIT License.