You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 3 години
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # [enquire.js](http://wickynilliams.github.com/enquire.js/) - Awesome Media Queries in JavaScript
  2. [![Build Status](https://travis-ci.org/WickyNilliams/enquire.js.svg)](https://travis-ci.org/WickyNilliams/enquire.js)
  3. `enquire.js` is a lightweight, pure javascript library (with **no dependencies**) for programmatically responding to media queries.
  4. ## Getting enquire.js
  5. ### Download
  6. Get the latest build, ready to go:
  7. * [Development](https://github.com/WickyNilliams/enquire.js/raw/master/dist/enquire.js) - unminified
  8. * [Production](https://github.com/WickyNilliams/enquire.js/raw/master/dist/enquire.min.js) - minified
  9. ### Install via Bower
  10. To install via bower, enter the following at the command line:
  11. bower install enquire
  12. ### Install via npm
  13. To install via npm, enter the following at the command line:
  14. npm install enquire.js
  15. ### Build From Source
  16. If you want build from source (and run all unit tests etc):
  17. git clone git://github.com/WickyNilliams/enquire.js.git
  18. cd enquire.js
  19. npm install
  20. grunt
  21. Booya!
  22. ## Quick Start
  23. The main method you will be dealing with is `register`. It's basic signature is as follows:
  24. ```javascript
  25. enquire.register(query /* string */, handler /* object || array || function */);
  26. ```
  27. `query` is the CSS media query you wish to respond to, and `handler` is an object containing any logic to handle the query. An example of usage is as follows:
  28. ```javascript
  29. enquire.register("screen and (max-width:1000px)", {
  30. match : function() {}, // OPTIONAL
  31. // If supplied, triggered when the media query transitions
  32. // *from an unmatched to a matched state*
  33. unmatch : function() {}, // OPTIONAL
  34. // If supplied, triggered when the media query transitions
  35. // *from a matched state to an unmatched state*.
  36. // Also may be called when handler is unregistered (if destroy is not available)
  37. setup : function() {}, // OPTIONAL
  38. // If supplied, triggered once immediately upon registration of the handler
  39. destroy : function() {}, // OPTIONAL
  40. // If supplied, triggered when handler is unregistered. Place cleanup code here
  41. deferSetup : true // OPTIONAL, defaults to false
  42. // If set to true, defers execution the setup function
  43. // until the media query is first matched. still triggered just once
  44. });
  45. ```
  46. This should be enough to get you going, but **please read the full [enquire.js documentation](http://wickynilliams.github.com/enquire.js/)** if you wish to learn about the other cool features.
  47. ## Contributing
  48. * Got an awesome idea?
  49. * Found a *not-so*-awesome bug?
  50. * Wish to get my attention through an inappropriate communication channel?!
  51. Then please don't hesitate to raise an issue, they will *all* be looked at and tended to.
  52. And for all the cool cats who are prepared to give their time to contribute code, feel free to open a pull request. If you could write unit tests to accompany your pull request that would be pretty sweet, but no worries if not - if it's good enough to be merged in, it's good enough for me to spend a little time to write tests on your behalf :-)
  53. ## License
  54. License: MIT (http://www.opensource.org/licenses/mit-license.php)