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

moodlejs

v1.0.6

Published

An accessible modal that follow the WebAim standards.

Downloads

3

Readme

Travis Build Status

MoodleJS

An accessible modal that follows the WebAim standards.

Features

  • Uses a keyboard trap when user has selected open modal
  • When you get to the last focusable element it will go back to the first
  • When you shift + tab and you're on the first focusable element you will go to the last
  • Uses aria-labelledby & aria-describedby for title and text fields.
  • Sets focus on first focuable element when opened.
  • Resets focus on the previous element when closing the modal.

Usage

This is the basic example for having multiple products working with one modal.

<!doctype html>
<html>
	<head>
		<title>Hello World</title>
	</head>
	<body>
		<h1>Hello World Heading.</h1>
		<a href="" data-product data-modal-button="">
			<h2 data-product-heading>Product One</h2>
			<p data-product-detail>Product one detail</p>
		</a>
		<a href="" data-product data-modal-button="">
			<h2 data-product-heading>Product Two</h2>
			<p data-product-detail>Product Two detail</p>
		</a>

		<div class="modal" data-modal="" aria-labelledby="modalTitle" aria-describedby="modalText" role="dialog" tabindex="-1">
			<h2 id="modalTitle" data-modal-title=""></h2>
			<p id="modalText" data-modal-intro=""></p>
			<div data-modal-body=""></div>
			<button data-modal-close="">Close</button>
		</div>
		<div class="modal__overlay" data-modal-overlay></div>
	</body>
</html>

CSS

Here is just the baseline to having the modal sit infront of the content & the overlay to sit behind.

.modal__overlay {
	background: rgba(0, 0, 0, 0.5);
	display: none;
	height: 100%;
	left: 0;
	position: fixed;
	top: 0;
	z-index: 2;
	width: 100%;
}

.modal--open .modal,
.modal--open .modal__overlay {
	display: block;
}

.modal {
	background: white;
	border-radius: 5px;
	display: none;
	left: 50%;
	padding: 20px;
	position: fixed;
	top: 50%;
	transform: translate(-50%, -50%);
	-webkit-transform: translate(-50%, -50%);
	-moz-transform: translate(-50%, -50%);
	z-index: 3;
}

JS

To create the modal all the have to do is use the new Moodle(); and the modal will handle the rest. For example:

(function() {
	var modal = new Moodle();
	var buttons = document.querySelectorAll('[data-modal-button]');

	function showProductModal(event) {
		event.preventDefault();
		var currentElement = event.currentTarget;
		var heading = currentElement.querySelectorAll('[data-product-heading]')[0].textContent;
		var detail = currentElement.querySelectorAll('[data-product-detail]')[0].textContent;
		var html = '';

		modal.show(heading, detail, html);
	}

	buttons[1].addEventListener('click', showProductModal, false);
	buttons[2].addEventListener('click', showProductModal, false);
}());

Using with webpack

If you are using the module with webpack or some other bundler then you can do the following:

npm i moodlejs --save

Then in your js file you will have to require the module.

(function() {

var modal = require('moodlejs');

// Products example

var buttons = document.querySelectorAll('[data-modal-button]');

function showProductModal(event) {
	event.preventDefault();
	var currentElement = event.currentTarget;
	var heading = currentElement.querySelectorAll('[data-product-heading]')[0].textContent;
	var detail = currentElement.querySelectorAll('[data-product-detail]')[0].textContent;
	var html = '';

	modal.show(heading, detail, html);
}

buttons[1].addEventListener('click', showProductModal, false);
buttons[2].addEventListener('click', showProductModal, false);
}());

Contributing

Feel free to suggest any ideas or improvments to the plugin. If you have any issues using it feel free to submit an issue.