2 Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
3 This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
5 The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
6 Code distributed by Google as part of the polymer project is also
7 subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
11 * @group Polymer Core Elements
12 * @element core-media-query
16 * core-media-query can be used to data bind to a CSS media query.
17 * The "query" property is a bare CSS media query.
18 * The "queryMatches" property will be a boolean representing if the page matches that media query.
20 * core-media-query uses media query listeners to dynamically update the "queryMatches" property.
21 * A "core-media-change" event also fires when queryMatches changes.
25 * <core-media-query query="max-width: 640px" queryMatches="{{phoneScreen}}"></core-media-query>
30 * Fired when the media query state changes
32 * @event core-media-change
35 <link rel=
"import" href=
"../polymer/polymer.html">
37 <polymer-element name=
"core-media-query" attributes=
"query queryMatches">
46 Polymer('core-media-query', {
49 * The Boolean return value of the media query
51 * @attribute queryMatches
58 * The CSS media query to evaulate
66 this._mqHandler
= this.queryHandler
.bind(this);
69 queryChanged: function() {
71 this._mq
.removeListener(this._mqHandler
);
73 var query
= this.query
;
74 if (query
[0] !== '(') {
75 query
= '(' + this.query
+ ')';
77 this._mq
= window
.matchMedia(query
);
78 this._mq
.addListener(this._mqHandler
);
79 this.queryHandler(this._mq
);
81 queryHandler: function(mq
) {
82 this.queryMatches
= mq
.matches
;
83 this.asyncFire('core-media-change', mq
);