(mq)
| 133 | } |
| 134 | } |
| 135 | _registerMediaQuery(mq) { |
| 136 | if (!this._changeHandler) { |
| 137 | this._changeHandler = () => { |
| 138 | this._onRemove(); |
| 139 | if (this._mql.matches) { |
| 140 | this._onAdd(); |
| 141 | } |
| 142 | // set the disabled 'read-only' attribute indirectly, via _validateDisabled |
| 143 | this._validateDisabled(); |
| 144 | }; |
| 145 | } |
| 146 | |
| 147 | if (mq) { |
| 148 | // a new media query is being established |
| 149 | let map = this.getMapEl(); |
| 150 | if (!map) return; |
| 151 | |
| 152 | // Remove listener from the old media query (if it exists) |
| 153 | if (this._mql) { |
| 154 | this._mql.removeEventListener('change', this._changeHandler); |
| 155 | } |
| 156 | |
| 157 | this._mql = map.matchMedia(mq); |
| 158 | this._changeHandler(); |
| 159 | this._mql.addEventListener('change', this._changeHandler); |
| 160 | } else if (this._mql) { |
| 161 | // the media attribute removed or query set to '' |
| 162 | this._mql.removeEventListener('change', this._changeHandler); |
| 163 | delete this._mql; |
| 164 | // effectively, no / empty media attribute matches, do what changeHandler does |
| 165 | this._onRemove(); |
| 166 | this._onAdd(); |
| 167 | this._validateDisabled(); |
| 168 | } |
| 169 | } |
| 170 | getMapEl() { |
| 171 | return Util.getClosest(this, 'mapml-viewer,map[is=web-map]'); |
| 172 | } |
no test coverage detected