Polymer elements added to third_party/polymer.
[chromium-blink-merge.git] / third_party / polymer / components / core-media-query / core-media-query.html
blob20cfd09ef304d1690ede4655040e070405ab526f
1 <!--
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
8 -->
9 <!--
10 /**
11 * @group Polymer Core Elements
12 * @element core-media-query
13 * @status beta
14 * @homepage github.io
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.
23 * Example:
25 * <core-media-query query="max-width: 640px" queryMatches="{{phoneScreen}}"></core-media-query>
29 /**
30 * Fired when the media query state changes
32 * @event core-media-change
34 -->
35 <link rel="import" href="../polymer/polymer.html">
37 <polymer-element name="core-media-query" attributes="query queryMatches">
38 <template>
39 <style>
40 :host {
41 display: none;
43 </style>
44 </template>
45 <script>
46 Polymer('core-media-query', {
48 /**
49 * The Boolean return value of the media query
51 * @attribute queryMatches
52 * @type Boolean
53 * @default false
55 queryMatches: false,
57 /**
58 * The CSS media query to evaulate
60 * @attribute query
61 * @type string
62 * @default ''
64 query: '',
65 ready: function() {
66 this._mqHandler = this.queryHandler.bind(this);
67 this._mq = null;
69 queryChanged: function() {
70 if (this._mq) {
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);
85 });
86 </script>
87 </polymer-element>