Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(665)

Unified Diff: lib/src/iron-media-query/iron-media-query.html

Issue 1418513006: update elements and fix some bugs (Closed) Base URL: git@github.com:dart-lang/polymer_elements.git@master
Patch Set: code review updates Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/iron-list/test/x-list.html ('k') | lib/src/iron-media-query/test/basic.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/iron-media-query/iron-media-query.html
diff --git a/lib/src/iron-media-query/iron-media-query.html b/lib/src/iron-media-query/iron-media-query.html
index 8325eb2f7f2851cb66c4212e7042246e88e3fe90..8ddccdb1c9ac3fe9c68533498648658e1c9abe3a 100644
--- a/lib/src/iron-media-query/iron-media-query.html
+++ b/lib/src/iron-media-query/iron-media-query.html
@@ -48,23 +48,57 @@ Example:
query: {
type: String,
observer: 'queryChanged'
+ },
+
+ /**
+ * @type {function(MediaQueryList)}
+ */
+ _boundMQHandler: {
+ value: function() {
+ return this.queryHandler.bind(this);
+ }
+ },
+
+ /**
+ * @type {MediaQueryList}
+ */
+ _mq: {
+ value: null
}
+ },
+
+ attached: function() {
+ this.queryChanged();
+ },
+ detached: function() {
+ this._remove();
},
- created: function() {
- this._mqHandler = this.queryHandler.bind(this);
+ _add: function() {
+ if (this._mq) {
+ this._mq.addListener(this._boundMQHandler);
+ }
},
- queryChanged: function(query) {
+ _remove: function() {
if (this._mq) {
- this._mq.removeListener(this._mqHandler);
+ this._mq.removeListener(this._boundMQHandler);
+ }
+ this._mq = null;
+ },
+
+ queryChanged: function() {
+ this._remove();
+ var query = this.query;
+ if (!query) {
+ return;
}
if (query[0] !== '(') {
query = '(' + query + ')';
}
this._mq = window.matchMedia(query);
- this._mq.addListener(this._mqHandler);
+ this._add();
this.queryHandler(this._mq);
},
« no previous file with comments | « lib/src/iron-list/test/x-list.html ('k') | lib/src/iron-media-query/test/basic.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698