diff --git a/bower.json b/bower.json index dacfc29..d44ba0c 100644 --- a/bower.json +++ b/bower.json @@ -3,6 +3,7 @@ "private": true, "dependencies": { "polymer": "Polymer/polymer#master", - "core-meta": "Polymer/core-meta#master" + "core-meta": "Polymer/core-meta#master", + "core-icon": "Polymer/core-icon#master" } } diff --git a/core-iconset.html b/core-iconset.html index 193daf1..a35d7da 100644 --- a/core-iconset.html +++ b/core-iconset.html @@ -215,18 +215,24 @@ * @param {String} theme (optional) The name of the theme for the icon. * @param {Number} scale (optional, defaults to 1) A scaling factor * with which the icon can be magnified. + * @return {Element} The icon element. */ applyIcon: function(element, icon, scale) { - var offset = this.getOffset(icon); - scale = scale || 1; - if (element && offset) { - var style = element.style; - style.backgroundImage = 'url(' + this.src + ')'; - style.backgroundPosition = (-offset.offsetX * scale + 'px') + - ' ' + (-offset.offsetY * scale + 'px'); - style.backgroundSize = scale === 1 ? 'auto' : - this.width * scale + 'px'; - } + var offset = this.getOffset(icon); + scale = scale || 1; + if (element && offset) { + var icon = element._icon || document.createElement('div'); + var style = icon.style; + style.backgroundImage = 'url(' + this.src + ')'; + style.backgroundPosition = (-offset.offsetX * scale + 'px') + + ' ' + (-offset.offsetY * scale + 'px'); + style.backgroundSize = scale === 1 ? 'auto' : + this.width * scale + 'px'; + if (icon.parentNode !== element) { + element.appendChild(icon); + } + return icon; + } } }); diff --git a/demo.html b/demo.html index 32d63d0..82ea67a 100644 --- a/demo.html +++ b/demo.html @@ -15,6 +15,7 @@ +
@@ -24,72 +25,38 @@ icons="location place starta stopb bus car train walk"> - -