twbs / mq4-hover-shim

A shim for the Media Queries Level 4 `hover` media feature
https://www.npmjs.com/package/mq4-hover-shim
MIT License
98 stars 18 forks source link

mq4-hover-shim

NPM version Build Status Development Status :: 4 - Beta MIT License Dependency Status devDependency Status

A shim for the Media Queries Level 4 hover @media feature.

The CSSWG's Media Queries Level 4 Working Draft defines a hover media feature that can be used in media queries. This can be used to determine whether the user-agent's primary pointing device truly supports hovering (like mice do) (the hover value), or emulates hovering (e.g. via a long tap, like most modern touch-based mobile devices) (the on-demand value), or does not support hovering at all (like some old mobile devices) (the none value). This matters because emulated hovering typically has some ugly quirks, such as :hover being "sticky" (i.e. a hovered element stays in the :hover state even after the user stops interacting with it and until the user hovers over a different element). It is often better to avoid :hover styles in browsers where hovering supports is emulated.

However, since it's from a relatively recent Working Draft, the hover media feature is not supported in all current modern browsers or in any legacy browsers. So, this library was created to shim support for the feature into browsers that lack native support for it.

NOTE: This shim only adds support for the hover value of the hover media feature. So you can only tell the difference between "truly supports hovering" (the hover value)" and "does not truly support hovering" (the none or on-demand values).

The shim consists of two parts:

Installation

Client-side dependencies

The browser-side portion of the shim depends on jQuery for firing events.

Pull requests to add support for other browser event libraries would be welcomed.

Browser compatibility

The following is a summary of the results of testing the library in various browsers. Try out the Live Testcase.

Legend:

Officially supported:

Unofficially supported:

API

Node.js module; CSS postprocessor

The npm module has the following properties:

Browser-side feature detector

The browser-side feature detector is available in the following module formats:

The module exports one public function:

The module has one public event:

Grunt, Gulp

Contributing

The project's coding style is laid out in the JSHint, ESLint, and JSCS configurations. Add unit tests when changing the CSS postprocessor. Lint and test your code using Grunt. Manually test any changes to the browser-side portion of the shim.

Also, please don't edit files in the dist subdirectory as they are generated via Grunt. You'll find source code in the src subdirectory!

Release History

See the GitHub Releases page for detailed changelogs.

License

Copyright (c) 2014-2015 Christopher Rebert. Licensed under the MIT License.