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

kist-dochopper

v0.3.2

Published

Move elements on page depending on media query.

Downloads

2

Readme

kist-dochopper

Move elements on page depending on media query.

Installation

npm install kist-dochopper --save

bower install kist-dochopper --save

API

$(Element).dochopper([options])

Returns: jQuery

options

Type: Object|String

Options defined as Object
conditions

Type: Array

Contains objects which define conditions where and when should specific element be moved when media query is matched or unmatched.

Arguments:

| Name | Type | Description | | --- | --- | --- | | into | String|Function|jQuery | To which element should content hop to. | | condition | String | Media query condition on which upon content should hop. |

Additionaly, into can be:

  • String - value of [data-hop-from] attribute
  • Function - return value which can be String or jQuery (has one argument - original element on which Dochopper is activated)
  • jQuery - jQuery element found inside document
hop

Type: Function
Provides: Array|jQuery, Array|Object
Event: dochopperhop

Callback for when context switching is complete, either when entering or exiting media query.

Array for first and second argument will be returned on plugin initialization. Every array contains list of currently active conditions, first argument containing elements which had their content filled with initial content, and second argument containing list of media query objects which are currently activate and correspond to list of containing elements in first argument.

Every next condition matching or unmatching will return active jQuery element and media query object.

hopConditionsDataProp

Type: String
Default: hop-conditions

data property which will be used to for optional setting of conditions (see options → conditions). If you provide data through this property, value should be valid JSON object.

hopFromDataProp

Type: String
Default: hop-from

data property which will be used as name of the element in which will the content hop to.

Options defined as String
destroy

Destroy plugin instance.

rehop

Retrigger hopping for current instance. Useful if hop-from element depends on some external conditions.

Examples

Set proper HTML markup.

<div class="hopper hopper-a">
	<b>Content A</b>
</div>

<div class="hopper hopper-b" data-hop-conditions='[{"into":"hop3","media":"screen and (min-width:900px)"},{"into":"hop4","media":"screen and (min-width:1400px)"}]'>
	<b>Content B</b>
</div>

<div data-hop-from="hop1"></div>
<div data-hop-from="hop2"></div>
<div data-hop-from="hop3"></div>
<div data-hop-from="hop4"></div>

Initialize plugin.

$('.hopper-a').dochopper({
	conditions: [
		{
			into: 'hop1',
			media: 'screen and (min-width:1000px)'
		},
		{
			into: $('.hop2'),
			media: 'screen and (min-width:1200px)'
		},
		{
			into: function ( el ) {
				if ( $('body').hasClass('foo') ) {
					return 'hop3';
				} else {
					return 'hop4';
				}
			},
			media: 'screen and (min-width:1200px)'
		}
	],
	hop: function ( element, media ) {
		// Hop!
	}
});

$('.hopper-b').dochopper();

$('.hopper-a, .hopper-b').on('dochopperhop', function ( e, element, media ) {
	// Hop!
});

Retrigger instance.

$('.hopper').dochopper('rehop');

Destroy plugin instance.

$('.hopper').dochopper('destroy');

Caveats

FOUC

It’s not unusual to experience FOUC (Flash Of Unmoved Content) because browser is waiting to render some other part of document and your hopping portion becomes blank and takes space where it shouldn’t be taking it.

To prevent this type of problems, you can use some simple CSS trickery to visually hide elements until they are ready. You have classes like .kist-Dochopper.is-ready applied when elements are switched to their correct places for current context and are ready to be displayed.

.hopper {
	height:1px;
	visibility:hidden;
}
.hopper.kist-Dochopper.is-ready {
	height:auto;
	visibility:visible;
}

Delegated events

If you have delegated events on some elements which will at some point be switched to another place, those events won’t work as intended since now those elements are in the new place.

Combination of min- and max- media queries

If you use combination of min- and max- media queries (e.g. screen and (min-width:100px) and (max-width:299px)), those media queries won’t be shown in inital list of media queries which where activated if the current viewport is larger than that media query condition. This is normal media query listener behavior.

Also, exiting that media query will trigger next matching query and the last ones which also match current viewport.

Browser support

Tested in IE8+ and all modern browsers.

License

MIT © Ivan Nikolić