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

modern-dropdown

v1.1.0

Published

Utility javascript that handles all modern usecases for dropdown menus

Downloads

7

Readme

Modern Dropdown

Modern Dropdown is a utility javascript with no dependencies that covers all the bases for modern dropdown menus.

It handles:

  • W3C Touch Events
  • Pointer Events
  • Mouse Events
  • Hover Intent
  • Focus Events

If a menu has a top level link and is opened with touch, the menu is opened and the link is not followed. Then if it is touched again while the menu is open, the link followed. This behavior is similar to aria-haspopup.

To use pass the node reference or query selector of the container that contains the menu to the constructor. This is where the open class will be added along with the event listeners.

Note: All styling including display is left to css. This script only adds the class at the appropriate time. You must add display:block or similar with the open class.

new Dropdown('#node', options);
jQuery('#node').dropdown(options);

Options

{
    delay: 250, // delay in milliseconds for hover intent
    openClass: 'dropdown--open', // class that is added to node when dropdown is open
    menu : '> ul', // selector for submenu, events will not be added if menu is not found
    spa  : false, // set to true for single page application mode - the links will not be followed in the menu but will close the menu on click
    beforeOpen: function() {}, // is called as the class is about to be added, return false to cancel the rest of the open event, 'this' refers to dropdown object
    afterOpen: function() {}, // is called after the open class has been added, useful in case measurements need to be made, 'this' refers to dropdown object
    beforeClose: function() {}, // is called before the open class is about to be removed, return false to cancel the rest of the close event, 'this' refers to dropdown object
    afterClose: function() {} // is called after the open class has been removed, 'this' refers to dropdown object
}

Browser Support

  • Firefox
  • Chrome
  • Safari
  • Mobile Safari
  • Android 4+ (haven't tested with 2.3)
  • Edge
  • IE8+

Develop Notes

Use uglifyjs to create minified version: uglifyjs dropdown.js -o dropdown.min.js --mangle --compress