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

glossary-panel

v1.0.0

Published

18F Site Glossary Panel

Downloads

143

Readme

Glossary panel

Build Status Test Coverage

About

Add a simple glossary panel to your site to help your users understand jargon-y terms. As seen on betaFEC and EITI.

For example:

  • https://beta.fec.gov/data/ - click on the book icon in the header
  • https://useiti.doi.gov/how-it-works/production/ - click on "fossil fuel"

Getting started

Note: if you are a contributor, please see CONTRIBUTING for additional help.

Download

Via npm

npm install glossary-panel

Set up your HTML

The following is the bare minimum HTML needed in your document:

	<button class="js-glossary-toggle">Glossary</button>
	<div id="glossary" aria-describedby="glossary-title" aria-hidden="true">
	  <button title="Close glossary" class="js-glossary-close">Hide glossary</button>
	  <h2 id="glossary-title">Glossary</h2>
	  <label for="glossary-search">Filter glossary terms</label>
	  <input id="glossary-search" class="js-glossary-search" type="search" placeholder="e.g. Committee">
	  <ul class="js-glossary-list"></ul>
	</div>

It includes a toggle button, a div for the glossary, a close button inside the glossary, a title, a search input and label, and a <ul> for the terms.

Then, to add glossary terms to the body of the page, add a data-term attribute to the terms. For example:

A <span data-term="committee">committee</span> is a thing.

The data attribute must match the text of the term in your JSON file exactly, but it is not case-sensitive.

Initialize

In whichever file you initialize your JavaScript components, initialize the glossary like so:

	var Glossary = require('@18f/glossary');

	// JSON file of terms and definitions
	var terms = require('terms');

	// Optional configurion objects
	var selectors = { ... };
	var classes = { ... };

	new Glossary(terms, selectors, classes);

Configuration

The constructor expects an array of objects (terms) that follows this pattern:

[
  {
    "term": "Glossary",
    "definition": "A useful tool for finding the definitions of terms"
  }
]

The constructor also accepts an optional hash of selectors as its second parameter:

  • glossaryID: ID of the glossary panel that will be shown and hidden. Default: #glossary
  • close: ID or class of the close button inside the glossary panel. Default: .js-glossary-close
  • listClass: Class of the <ul> that will be populated with terms. Default: .js-glossary-list
  • searchClass: Class of the <input> that will be used to filter the list. Default: .js-glossary-search
  • toggle: ID or class of the element that will be used to open and close the glossary in the main body of the document. Default: .js-glossary-toggle

And you can pass an optional hash of classes to be applied to to the DOM:

  • definitionClass: Single class applied to the <div> that contains the term's definition. Default: glossary__definition
  • glossaryItemClass: Single class applied to the <li> that contains the term and deffinition. Default: glossary__item
  • highlightedTerm: Single class applied to terms in the body when they are highlighted. Default: term--higlight
  • termClass: Single class applied to the <button> element that opens the definition. Default: glossary__term

Methods

  • Glossary.show(): Show the glossary
  • Glossary.hide(): Hide the glossary
  • Glossary.toggle(): Toggle the glossary open or closed
  • Glossary.destroy(): Completely remove the glossary from the DOM
  • Glossary.findTerm(term): If the glossary is opens, filters the list down to the term called, expands the term, and highlights the associated term in the DOM

Styling

To style the glossary terms and defintions in the accordion list, either use the default classes or whichever ones you passed in. To change the style of the buttons when the accordion elements are expanded, you can select for [aria-expanded="true"].

You will need to add styles for [aria-hidden="true"] in order to hide the glossary panel and the glossary definitions.

License

Public domain

This project is in the worldwide public domain. As stated in CONTRIBUTING:

This project is in the public domain within the United States, and copyright and related rights in the work worldwide are waived through the CC0 1.0 Universal public domain dedication.

All contributions to this project will be released under the CC0 dedication. By submitting a pull request, you are agreeing to comply with this waiver of copyright interest.