Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/18F/glossary
A glossary panel for your site to help readers understand jargon
https://github.com/18F/glossary
Last synced: 4 months ago
JSON representation
A glossary panel for your site to help readers understand jargon
- Host: GitHub
- URL: https://github.com/18F/glossary
- Owner: 18F
- License: other
- Archived: true
- Created: 2015-10-20T21:20:06.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2021-08-30T17:56:28.000Z (over 3 years ago)
- Last Synced: 2024-08-19T10:48:37.242Z (4 months ago)
- Language: JavaScript
- Homepage:
- Size: 666 KB
- Stars: 47
- Watchers: 112
- Forks: 26
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Glossary panel
[![CircleCI](https://circleci.com/gh/18F/glossary.svg?style=svg)](https://circleci.com/gh/18F/glossary)
[![Test Coverage](https://img.shields.io/codecov/c/github/18F/glossary/master.svg)](https://codecov.io/github/18F/glossary)# About
Add a simple glossary panel to your site to help your users understand jargon-y terms. As seen on [FEC.gov](https://www.fec.gov) and DOI's [Natural Resources Revenue Data](https://revenuedata.doi.gov/).For example:
* https://www.fec.gov/data/ - click on the `Glossary` book icon in the header
* https://www.fec.gov/help-candidates-and-committees/registering-candidate/ - click on `contributions`
* https://revenuedata.doi.gov/ - click on `royalties`# Getting started
To run the example locally:
```sh
npm install -g parcel-bundler
npm start
open http://localhost:1234
```Note: if you are a contributor, please see [CONTRIBUTING for additional help](CONTRIBUTING.md).
## Download
### Via npm
```
npm install glossary-panel
```## Set up your HTML
The following is the bare minimum HTML needed in your document:```html
Glossary
Hide glossary
Glossary
Filter glossary terms
```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 `
- ` for the terms.
- ` that contains the term and definition. _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 `` 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 definitions 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 domainThis project is in the worldwide [public domain](LICENSE.md). As stated in [CONTRIBUTING](CONTRIBUTING.md):
> 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](https://creativecommons.org/publicdomain/zero/1.0/).
>
> 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.
Then, to add glossary terms to the body of the page, add a `data-term` attribute to the terms. For example:
```html
A committee 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:
```js
var Glossary = require('glossary-panel');
// JSON file of terms and definitions
var terms = require('./terms');
// Optional configuration objects
var selectors = { ... };
var classes = { ... };
new Glossary(terms, selectors, classes);
```
# Configuration
The constructor expects an array of objects (`terms`) that follows this pattern:
```json
[
{
"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 `
- ` that will be populated with terms. _Default_: `.js-glossary-list`
- `searchClass`: Class of the `` 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 `
- `glossaryItemClass`: Single class applied to the `