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

jquery-visibility

v1.0.11

Published

Page visibility shim for jQuery.

Downloads

82

Readme

Page Visibility shim for jQuery

This plugin gives you a very simple API that allows you to execute callbacks when the page’s visibility state changes.

It does so by using the Page Visibility API where it’s supported, and falling back to good old focus and blur in older browsers.

Demo

http://mathiasbynens.be/demo/jquery-visibility

When to use?

Typical use cases include but are not limited to pausing/resuming slideshows, video, and/or embedded audio clips.

Example usage

This plugin simply provides two custom document events for you to use: show and hide. When the page visibility state changes, the appropriate event will be triggered.

You can use them separately:

$(document).on('show', function() {
  // the page gained visibility
});
$(document).on('hide', function() {
  // the page was hidden
});

For most applications you'll need both events, so the most convenient option is to use an events map. This way, you can bind both event handlers in one go:

$(document).on({
  'show': function() {
    console.log('The page gained visibility; the `show` event was triggered.');
  },
  'hide': function() {
    console.log('The page lost visibility; the `hide` event was triggered.');
  }
});

Or bind both to the same callback and distinguish using the event variable.

$(document).on('show hide', function (e) {
	console.log('The page is now', e.type === 'show' ? 'visible' : 'hidden');
});

The plugin will detect if the Page Visibility API is natively supported in the browser or not, and expose this information as a boolean (true/false) in $.support.pageVisibility.
Warning: $.support was marked deprecated in jQuery version 1.9, so it is likely to be removed in the future.

if ($.support.pageVisibility) {
  // Page Visibility is natively supported in this browser
}

If the Page Visibility API is supported the plugin will also store the current visibility state in document.hidden.

if (!document.hidden) {
  // Page is currently visible
}

Notes

This plugin is not a Page Visibility polyfill, as it doesn’t aim to mimic the standard API. It merely provides a simple way to use this functionality (or a fallback) in your jQuery code.

License

This plugin is available under the MIT license.

Author

Mathias Bynens

Contributors

Jan Paepke, John-David Dalton