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

break

v1.0.2

Published

Fire events when certain media queries are entered and exited due to a window resize

Downloads

367

Readme

Break

Know when breakpoints are entered/exited due to a window resize.

Installation

If you are sane and use npm:

npm install break

If you are not sane, grab the bundled standalone version at standalone/break.min.js. Including this on your page will assign window.createBreakpointManager.

Usage

var createBreakpointManager = require('break')

var bm = createBreakpointManager()

bm.add('portable', '(max-width: 800px)')

bm.on('enter:portable', function () {
  // Set up functionality relating to small screens e.g…
  createTouchSlider()
})

bm.on('exit:portable', function () {
  // Tear down functionality relating to small screens e.g…
  removeTouchSlider()
})

API

var bm = createBreakpointManager()

Create a breakpoint manager. bm inherits from the node event emitter so it has the same API in addition to the methods below.

The following events are emitted by this module:

  • enter:[breakpoint] - when a breakpoint is entered, e.g enter:portable
  • exit:[breakpoint] - when a breakpoint is exited, e.g exit:wide

bm.add(name, mq)

Add a breakpoint with a name and a media query. On every window resize event, the media query will be tested. If the result changes to mq being satisfied, the event enter:[name] will be emitted. If the result changes such that mq is no longer satisfied, the event exit:[name] will be emitted. If no change occurs, no events are emitted (as this would be chaos on every window resize event!).

The media query is also tested once when it is added, as it is often helpful to know whether the mq is satsfied at this point. This check happens on process.nextTick() so that it does not matter whether you add the listeners (with .on()) before or after you add the breakpoints (with .add()).

bm.on(event, name, isFallback)

This function delegates the first two arguments to the event emitter .on(). The third argument is a flag as to whether this function should run once if media queries are not supported.

bm.fallback(fn)

Runs the function fn if media queries are not supported.

Development

This is quite a simple module, however it's annoyingly tricky to test. However, this has been acheived by having two browser test suites – modern and legacy. The caveat is that these tests have to run in a browser by hand.

All bug fixes and features require that (if possible) test is added which fails before the implementation of the new code, and passes afterwards.

Check out a development version

git clone [email protected]:bengourley/break.git
cd break
npm install

Running the tests

npm test

Then use the links presented in the terminal to run the tests in various browsers. You will be prompted to resize your browser at points during the test.

The modern tests should pass in IE9+, Firefox, Safari and Chrome. The legacy tests should pass in IE6,7,8.

Note: you may need to replace a portion of the links if using a VM. I am using VirtualBox, so the route to my development localhost is 10.0.2.2. Therefore the url I use to run the legacy tests on IE6 inside my VM is: http://10.0.2.2:4567/test/legacy/index.html.

Building the standalone version

npm run standalone

This needs to happen before every release.

License

BSD. Bundled in with this module is an IE9 matchMedia polyfill by Scott Jehl et al. with a BSD/MIT license.

Authors / Contributors

Ben Gourley, Nick Price.