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.
24 lines
666 B
24 lines
666 B
var Emitter = require('./Emitter');
|
|
exports = Emitter.extend({
|
|
className: 'MediaQuery',
|
|
initialize: function(query) {
|
|
var _this = this;
|
|
this.callSuper(Emitter, 'initialize');
|
|
this._listener = function() {
|
|
_this.emit(_this.isMatch() ? 'match' : 'unmatch');
|
|
};
|
|
this.setQuery(query);
|
|
},
|
|
setQuery: function(query) {
|
|
if (this._mql) {
|
|
this._mql.removeListener(this._listener);
|
|
}
|
|
this._mql = window.matchMedia(query);
|
|
this._mql.addListener(this._listener);
|
|
},
|
|
isMatch: function() {
|
|
return this._mql.matches;
|
|
}
|
|
});
|
|
|
|
module.exports = exports;
|
|
|