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

juggler-js

v2.0.1

Published

Juggler is a simple tool that allows to move (not copy!) the element nodes from one place to another in the DOM when they match the provided media query.

Downloads

3

Readme

Juggler.js

Juggler is a simple tool that allows to move (not copy!) the element nodes from one place to another in the DOM when they match the provided media query.

Why?

During the design implementation it can happen that some elements must be moved around as not everything can be achieved with pure CSS. Consider the following HTML structure:

<div class="header">
    <div class="logo">...</div>
    <div class="navigation">...</div>
    <div class="mobile-box-trigger">...</div>
    <div class="mobile-box">
        <!-- we want to display .navigation here but only on mobile -->
    </div>
</div>

What if you had to move the .navigation div into the .mobile-box but only on the small devices? That's where the Juggle.js comes in handy and solves the problem with ease:

<div class="header">
    <div class="logo">...</div>
    <div class="navigation" data-juggler-source="navigation">...</div>
    <div class="mobile-box-trigger">...</div>
    <div class="mobile-box">
        <!-- the .navigation will be displayed here on mobile -->
        <div data-juggler-target="navigation" data-juggler-media-query="(max-width: 767px)"></div>
    </div>
</div>

How it works?

When the document is ready (e.g. DOMContentLoaded event is triggered) the script gathers all Juggler elements and puts them in an internal registry. To preserve the location of the source and target elements for further reference the HTML comments are added before the source element and as a replacement of the target element. This way the temporary placeholders do not interfere with other elements and do not break CSS nor JS.

Installation

Download the package and include the file on your page:

<script src="assets/js/juggler.min.js"></script>

Then intiialize the script once DOM is ready:

document.addEventListener('DOMContentLoaded', Juggler.init());

// or

document.addEventListener('DOMContentLoaded', function () {
    Juggler.init();
});

Configuration

There are basically two things you have to configure:

  1. Source element

The original element you would like to juggle. It must have a unique ID specified the attribute:

<div data-juggler-source="my_unique_id">...</div>
  1. Target element

The element that will be replaced by the source element when necessary. It must refer to the existing source element and contain a valid CSS media query:

<div data-juggler-target="my_unique_id" data-juggler-media-query="(max-width: 767px)"></div>

Using boolean flags instead of media queries

You can also use the boolean flags instead of media queries, see the demo files for example.

<div data-juggler-source="my_unique_id">...</div>
<div data-juggler-target="my_unique_id" data-juggler-flag="foobar"></div>

<script>
Juggler.setFlag('foobar', true);
Juggler.setFlag('foobar', false);
</script>

Known issues

  1. When you clone an element that is a Juggler source, make sure to remove the data attribute or you will get an error of duplicate source items.

Copyright

This project has been created and is maintained by Codefog.