OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. |
| 3 This code may only be used under the BSD style license found at http://polymer.g
ithub.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/CONTRI
BUTORS.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/PATEN
TS.txt |
| 8 --> |
| 9 |
| 10 <link rel="import" href="../polymer/polymer.html"> |
| 11 |
| 12 <!-- |
| 13 `iron-media-query` can be used to data bind to a CSS media query. |
| 14 The `query` property is a bare CSS media query. |
| 15 The `queryMatches` property is a boolean representing if the page matches that m
edia query. |
| 16 |
| 17 Example: |
| 18 |
| 19 <iron-media-query query="(min-width: 600px)" queryMatches="{{queryMatches}}"
></iron-media-query> |
| 20 |
| 21 @group Polymer Core Elements |
| 22 @element iron-media-query |
| 23 --> |
| 24 |
| 25 <script> |
| 26 |
| 27 Polymer({ |
| 28 |
| 29 is: 'iron-media-query', |
| 30 |
| 31 properties: { |
| 32 |
| 33 /** |
| 34 * The Boolean return value of the media query. |
| 35 * |
| 36 * @attribute queryMatches |
| 37 * @type Boolean |
| 38 * @default false |
| 39 */ |
| 40 queryMatches: { |
| 41 type: Boolean, |
| 42 value: false, |
| 43 readOnly: true, |
| 44 notify: true |
| 45 }, |
| 46 |
| 47 /** |
| 48 * The CSS media query to evaluate. |
| 49 * |
| 50 * @attribute query |
| 51 * @type String |
| 52 */ |
| 53 query: { |
| 54 type: String, |
| 55 observer: 'queryChanged' |
| 56 } |
| 57 |
| 58 }, |
| 59 |
| 60 created: function() { |
| 61 this._mqHandler = this.queryHandler.bind(this); |
| 62 }, |
| 63 |
| 64 queryChanged: function(query) { |
| 65 if (this._mq) { |
| 66 this._mq.removeListener(this._mqHandler); |
| 67 } |
| 68 if (query[0] !== '(') { |
| 69 query = '(' + query + ')'; |
| 70 } |
| 71 this._mq = window.matchMedia(query); |
| 72 this._mq.addListener(this._mqHandler); |
| 73 this.queryHandler(this._mq); |
| 74 }, |
| 75 |
| 76 queryHandler: function(mq) { |
| 77 this._setQueryMatches(mq.matches); |
| 78 } |
| 79 |
| 80 }); |
| 81 |
| 82 </script> |
OLD | NEW |