@exadel/esl
Version:
Exadel Smart Library (ESL) is the lightweight custom elements library that provide a set of super-flexible components
33 lines (32 loc) • 858 B
JavaScript
/**
* Const media condition implementation
* @author Alexey Stsefanovich (ala'n)
*
* Ignores listeners always return the same result.
* Have only two instances: {@link ALL} and {@link NOT_ALL}
*/
class MediaQueryConstCondition {
constructor(_matches) {
this._matches = _matches;
}
get matches() {
return this._matches;
}
addEventListener() { }
removeEventListener() { }
dispatchEvent() {
return false;
}
optimize() {
return this;
}
toString() {
return this._matches ? 'all' : 'not all';
}
/** Compares const media condition with the passed query instance or string */
eq(val) {
return String(val).trim() === this.toString();
}
}
export const ALL = new MediaQueryConstCondition(true);
export const NOT_ALL = new MediaQueryConstCondition(false);