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

@jwrunge/deepnav

v1.1.4

Published

Multilevel navigation utility written in vanilla JS.

Downloads

2

Readme

DeepNav

The purpose of DeepNav is to provide a flexible, multilevel, drop-in navigation system that requires minimal in-HTML markup. DeepNav supports as many levels of navigation as good taste will allow, and then some. You need only set up a couple of divs and anchors, initialize DeepNav, and you're good to go!

Features:

  • As many nested levels of navigation as you dare
  • Options for click-to-open menus, hover-only menus, or top-level hovering with clickable submenus
  • Easy-to-implement responsivity
  • Easily stylable and highly customizable

Check out the CodePen example to play around with settings and styling.

Contents

  1. Development
  2. Installation
  3. Implementation
  4. Styling

Development

Author: Jacob Runge

Support the developer!

This code is provided under the MIT license, and is completely free to use and modify in any personal or commercial projects--just because I like you! If you are using this code in an application that is making you money, or even if you just think it's super neat and want to support me as a developer, consider a small tip at the "Buy me a coffee!" link below. It's much appreciated! :-)

Installation

Via NPM

Install via NPM: npm install @jwrunge/deepnav

Or download a local copy of the code here.

Implementation

The JavaScript

There are two ways to implement DeepNav:

  • Including as a script tag
  • Including as a module

Importing via script tag is easy-peasy:

<script src="path/to/deepnav.js">
<script>
    new deepnav("myNav", {options})
</script>

If importing via NPM or in a module:

<script type="module">
    import deepnav from '@jwrunge/deepnav'
    new deepnav("myNav", {options})
</script>

The first argument to deepnav() should be the ID of the navigation structure you want to convert to a DeepNav navigation system. The second argument is a JavaScript dictionary, where you can pass various customization options to deepnav (detailed in "Customization" below).

The HTML

The HTML markup of your navigation structure should consist of a root div with an ID that you pass to the new deepnav() constructor. To create a sub-list of links, nest an <a> tag with the class deepnav-link, followed by a div with the class .sublinks. An example:

<div id='myNav'>
    <a href="some/cool/place">Leve 1 terminal link</a>

    <a class='deepnav-link'>Level 1 submenu link</a>
    <div class='sublinks'>
        <a href="another/cool/place">Level 2 terminal link</a>

        <a class='deepnav-link'>Level 2 submenu link</a>
        <div class='sublinks'>
            <a href="a/third/cool/place">Level 3 terminal link</a>
        </div>
    </div>
</div>

In the above example, DeepNav would create a menu system with two root-level links, one terminal link and one that opens a submenu. The submenu then would contain two links, one terminal link and one that opens a submenu. That submenu would then open a third-level terminal link.

Customization

The following is a list of customization options, which you can pass in a JavaScript dictionary to the second parameter of the deepnav() constructor.

You can change any of these preferences on the fly if you set up a reference to your DeepNav instance (var myNav = new deepnav('coolId')) by altering myNav.settings.settingIWantToChange.

|prop |default |description | |--- |--- |--- | |hoverMode |"" |Possible values include 'all', 'top_only', or any falsey value. This determines whether or not your anchors will open submenus on hover (they always respond to 'click'). 'all' signifies that all anchors will open submenus on hover (this is really a nightmare with a stacked menu); 'top_only' means that only your top-level anchors will respond to hover (you have to click on submenu anchors); false means users have to click.| |alignSubmenus |"center" |Possible values include 'right', 'left', and 'center'. This affects how dropdown menus are displayed relative to the anchor when DeepNav is not in 'stacked' mode (i.e. a horizontal rather than a vertical menu). No worries--DeepNav will do its best not to let your menu go off-screen; if a menu is aligned 'left' and goes off-screen to the right, DeepNav will automatically change alignment to 'right' for that menu.| |showContentArrows |true |Possible values include boolean true or false. This determines whether or not DeepNav adds open/close arrows to submenus. You MUST encode your HTML with UTF-8 (meta charset='utf-8' in the document head) for this to work anywhere outside of Chrome.| |showDefaultAnimations |true |Possible values include boolean true or false. This determines whether or not DeepNav is allowed to animate the opening and closing of your submenus. For the most part, I think the animations are sufficient for most designs.| |showAestheticStyling |true |Possible values include boolean true or false. You may want to set this one to false to give you full control over the aesthetic styling, although it is simple to override these styles if you wish to include them as a jumping off point.| |displayMode |"responsive" |Possible values include 'reponsive', 'horizontal', and 'stacked'. 'horizontal' will leave the menu in horizontal mode (best for wide screens); 'stacked' will leave the menu in 'stacked'/vertical mode (best for mobile devices in, say, a hamburger menu). 'responsive' will adapt itself between 'stacked' and 'horizontal' based on a breakpoint. 'responsive' also plays with the navigation style when your menu is in Hover Mode, removing hover functionality while the menu is stacked.| |breakpoint |500 |A number value. This defines the pixel width at which your menu changes from horizontal to stacked while in the responsive Display Mode.|

Styling

DeepNav programmatically sets some initial styles for each instance of DeepNav that you invoke. These styles are placed at the beginning of your document head so that they can be overridden easily, but if you need to make changes that the aesthetic styles are disallowing, you can disable them via the customization options listed above. You will need to do a bit more work to get your navigation system looking good, however!

Important styling classes: I have included the most important classes for custom CSS styling below. This is not an exhaustive list, but your browser's inspector will likely give you the best idea of what to style for your specific use case.

|class |description | |--- |--- | |.sublinks |A div containing anchor links and possibly other .sublinks.| |.deepnav-link |A link that opens a .sublinks container.| |.nav-list-open |Applied to a .deepnav-link to indicate that the submenu is open.| |.stacked |Applied to the root DeepNav div when it is displayed in stacked mode.|