OLD | NEW |
1 <!-- | 1 <!-- |
2 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. | 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 | 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 | 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 | 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 | 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 | 7 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
8 --> | 8 --> |
9 | 9 |
10 <link rel="import" href="../polymer/polymer.html"> | 10 <link rel="import" href="../polymer/polymer.html"> |
(...skipping 30 matching lines...) Expand all Loading... |
41 readOnly: true, | 41 readOnly: true, |
42 notify: true | 42 notify: true |
43 }, | 43 }, |
44 | 44 |
45 /** | 45 /** |
46 * The CSS media query to evaluate. | 46 * The CSS media query to evaluate. |
47 */ | 47 */ |
48 query: { | 48 query: { |
49 type: String, | 49 type: String, |
50 observer: 'queryChanged' | 50 observer: 'queryChanged' |
| 51 }, |
| 52 |
| 53 /** |
| 54 * @type {function(MediaQueryList)} |
| 55 */ |
| 56 _boundMQHandler: { |
| 57 value: function() { |
| 58 return this.queryHandler.bind(this); |
| 59 } |
| 60 }, |
| 61 |
| 62 /** |
| 63 * @type {MediaQueryList} |
| 64 */ |
| 65 _mq: { |
| 66 value: null |
51 } | 67 } |
52 | |
53 }, | 68 }, |
54 | 69 |
55 created: function() { | 70 attached: function() { |
56 this._mqHandler = this.queryHandler.bind(this); | 71 this.queryChanged(); |
57 }, | 72 }, |
58 | 73 |
59 queryChanged: function(query) { | 74 detached: function() { |
| 75 this._remove(); |
| 76 }, |
| 77 |
| 78 _add: function() { |
60 if (this._mq) { | 79 if (this._mq) { |
61 this._mq.removeListener(this._mqHandler); | 80 this._mq.addListener(this._boundMQHandler); |
| 81 } |
| 82 }, |
| 83 |
| 84 _remove: function() { |
| 85 if (this._mq) { |
| 86 this._mq.removeListener(this._boundMQHandler); |
| 87 } |
| 88 this._mq = null; |
| 89 }, |
| 90 |
| 91 queryChanged: function() { |
| 92 this._remove(); |
| 93 var query = this.query; |
| 94 if (!query) { |
| 95 return; |
62 } | 96 } |
63 if (query[0] !== '(') { | 97 if (query[0] !== '(') { |
64 query = '(' + query + ')'; | 98 query = '(' + query + ')'; |
65 } | 99 } |
66 this._mq = window.matchMedia(query); | 100 this._mq = window.matchMedia(query); |
67 this._mq.addListener(this._mqHandler); | 101 this._add(); |
68 this.queryHandler(this._mq); | 102 this.queryHandler(this._mq); |
69 }, | 103 }, |
70 | 104 |
71 queryHandler: function(mq) { | 105 queryHandler: function(mq) { |
72 this._setQueryMatches(mq.matches); | 106 this._setQueryMatches(mq.matches); |
73 } | 107 } |
74 | 108 |
75 }); | 109 }); |
76 | 110 |
77 </script> | 111 </script> |
OLD | NEW |