WickyNilliams / enquire.js

Awesome Media Queries in JavaScript
http://wicky.nillia.ms/enquire.js/
MIT License
3.62k stars 269 forks source link

Why media query? #134

Closed iazel closed 9 years ago

iazel commented 9 years ago

I like the project's idea, but I was wondering, why media query instead of a more native approach using an object?

Something like this:

enquire.register({min: 600}, handler)

This would completely remove the need for polyfills and should be quite straightforward to code.
I think the first object should have three mode, namely min, max or in; the latter is more a sugar and could be dropped out in favor of {min: x, max: y}

WickyNilliams commented 9 years ago

How is it not "native"? The lib relies on the matchMedia API which has very broad support these days. Polyfills are only required for IE 9 and below. Also it is far more flexible and future-propf than your proposed API eg. How would you handle pixel density, or height, or AND or OR queries or any other type of query that may arise in future (eg touch or brightness)?

iazel commented 9 years ago

You could simply add more keys in the first object, but thinking about it, you're right: that would be a waste of time, reinventing the wheel.