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

easy-toggler

v2.2.7

Published

Simple class switcher on web elements. JavaScript only.

Downloads

26

Readme

EasyToggler.js 🔗🚀

YouTube Channel Subscribers GitHub GitHub all releases GitHub issues GitHub package.json version (subfolder of monorepo)

Simple class switcher on web elements. JavaScript only.

Use a plugin instead of JavaScript

<!-- js: menu.classList.toggle('active') -->
<button easy-toggle="#target" easy-class="active">Toggle class</button>

<!-- js: menu.classList.add('active') -->
<button easy-add="#target" easy-class="active">Add class</button>

<!-- js: menu.classList.remove('active') -->
<button easy-remove="#target" easy-class="active">Remove class</button>

<!-- js: menu.classList.toggle('active') + work with e.closest() -->
<button easy-toggle="#target" easy-class="active" easy-rcoe>Removing a class if we click on an empty space</button>

Import EasyToggler

ES

<script type="module">
  import easySetup from "easy-toggler";

  easySetup({
    // html attrs
    toggle: 'easy-toggle',
    add: 'easy-add',
    remove: 'easy-remove',
    class: 'easy-class',
    rcoe: 'easy-rcoe',
    parallel: 'easy-parallel',
    self: 'easy-self',
    selfRcoe: 'easy-self-rcoe',

    // Hooks
    onToggle($el){},
    onAdd($el){},
    onRemove($el){},
    onRcoe($el){},
  });
</script>

or easier:

<script type="module">
  import easySetup from "easy-toggler";
  easySetup();
</script>

CDN jsDelivr

<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>

CJS

<script type="module">
  const easySetup = require("easy-toggler");

  easySetup({
    // html attrs
    toggle: 'easy-toggle',
    add: 'easy-add',
    remove: 'easy-remove',
    class: 'easy-class',
    rcoe: 'easy-rcoe',
    parallel: 'easy-parallel',
    self: 'easy-self',
    selfRcoe: 'easy-self-rcoe',

    // Hooks
    onToggle($el){},
    onAdd($el){},
    onRemove($el){},
    onRcoe($el){},
  });
</script>

or easier:

<script type="module">
  const easySetup = require("easy-toggler");
  easySetup();
</script>

Demo

Visit demo page: rah-emil.ru/easy-toggler

Example №1

When you click the button, the class show will be added to <nav id="main_menu">

<button easy-toggle="#main_menu" easy-class="show">Menu</button>

<nav id="main_menu">
    <ul>
        <li><a>Home</a></li>
        <li><a>About us</a></li>
        <li><a>Services</a></li>
        <li><a>Portfolio</a></li>
        <li><a>Contact us</a></li>
    </ul>
</nav>

Example №2

When you click the button, the class open will be added to <div id="categories" class="dropdown-menu">. When clicking outside the element area, class open will be deleted from <div id="categories" class="dropdown-menu">, since we specified the easy-rcoe attribute for the link.

<div class="dropdown">
    <a href="#" easy-toggle="#categories" easy-class="open" easy-rcoe>Categories</a>

    <div id="categories" class="dropdown-menu">
        <a href="#">HTML</a>
        <a href="#">CSS</a>
        <a href="#">JavaScript</a>
        <a href="#">Vue.js</a>
        <a href="#">Laravel</a>
    </div>
</div>

EasyToggler.js only allows you to conveniently manage the element classes. CSS styles (behavior of elements with certain classes) must be specified independently.

Attributes

  • easy-toggle - toggle class for target element
  • easy-add - add class for target element
  • easy-remove - remove class for target element
  • easy-class - specifying the class for the target element
  • easy-rcoe - indicate whether it is necessary to delete the class if another is pressed
  • easy-parallel - so that elements can open parallel to each other
  • easy-self - add a class to the clicked button
  • easy-self-rcoe - indicate whether it is necessary to delete the class if another is pressed (for self elements)

Hooks

  • onToggle($el) - hook after action toggle
  • onAdd($el) - hook after action add
  • onRemove($el) - hook after action remove
  • onRcoe($el) - hook after action rcoe