Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
improve theme handling code
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott J. Miles committed Sep 5, 2013
1 parent 78a7b95 commit 3083398
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions polymer-ui-icon/polymer-ui-icon.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

<!--
Copyright 2013 The Polymer Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
-->

<!--
/**
* Polymer UI Elements
Expand Down Expand Up @@ -31,6 +31,7 @@
* @class polymer-ui-icon
*/
-->

<link rel="import" href="../polymer-ui-theme-aware/polymer-ui-theme-aware.html">

<polymer-element name="polymer-ui-icon" extends="polymer-ui-theme-aware" attributes="src size index icon">
Expand Down Expand Up @@ -136,25 +137,20 @@
this.updateIcon();
},
themeChanged: function(old) {
this.super(arguments);
this.style.backgroundPosition = '';
this.classList.switch(old, this.theme);
this.bx = calcThemeOffset(this.theme, this);
this.asyncMethod('updateIcon');
this.updateIcon();
},
updateIcon: function() {
if (this.src) {
this.style.backgroundPosition = 'center';
} else {
// TODO(sorvell): FF cannot set Y only so we go to trouble
// to find the x offset and use it here.
this.style.backgroundPosition = (this.bx + 'px') + ' ' + (this.by + 'px');
//this.style.backgroundPositionY = this.by + 'px';
}
}
});

// memoize offset by theme name since getComputedStyle
// is $$
// memoize offset because getComputedStyle is expensive
var themes = {};
function calcThemeOffset(theme, node) {
if (themes[theme] === undefined) {
Expand Down

0 comments on commit 3083398

Please sign in to comment.