OLD | NEW |
| (Empty) |
1 | |
2 | |
3 Polymer({ | |
4 | |
5 is: 'iron-icon', | |
6 | |
7 properties: { | |
8 | |
9 /** | |
10 * The name of the icon to use. The name should be of the form: | |
11 * `iconset_name:icon_name`. | |
12 */ | |
13 icon: { | |
14 type: String, | |
15 observer: '_iconChanged' | |
16 }, | |
17 | |
18 /** | |
19 * The name of the theme to used, if one is specified by the | |
20 * iconset. | |
21 */ | |
22 theme: { | |
23 type: String, | |
24 observer: '_updateIcon' | |
25 }, | |
26 | |
27 /** | |
28 * If using iron-icon without an iconset, you can set the src to be | |
29 * the URL of an individual icon image file. Note that this will take | |
30 * precedence over a given icon attribute. | |
31 */ | |
32 src: { | |
33 type: String, | |
34 observer: '_srcChanged' | |
35 } | |
36 }, | |
37 | |
38 _DEFAULT_ICONSET: 'icons', | |
39 | |
40 _iconChanged: function(icon) { | |
41 var parts = (icon || '').split(':'); | |
42 this._iconName = parts.pop(); | |
43 this._iconsetName = parts.pop() || this._DEFAULT_ICONSET; | |
44 this._updateIcon(); | |
45 }, | |
46 | |
47 _srcChanged: function(src) { | |
48 this._updateIcon(); | |
49 }, | |
50 | |
51 _usesIconset: function() { | |
52 return this.icon || !this.src; | |
53 }, | |
54 | |
55 _updateIcon: function() { | |
56 if (this._usesIconset()) { | |
57 if (this._iconsetName) { | |
58 this._iconset = this.$.meta.byKey(this._iconsetName); | |
59 if (this._iconset) { | |
60 this._iconset.applyIcon(this, this._iconName, this.theme); | |
61 } else { | |
62 this._warn(this._logf('_updateIcon', 'could not find iconset `' | |
63 + this._iconsetName + '`, did you import the iconset?')); | |
64 } | |
65 } | |
66 } else { | |
67 if (!this._img) { | |
68 this._img = document.createElement('img'); | |
69 this._img.style.width = '100%'; | |
70 this._img.style.height = '100%'; | |
71 } | |
72 this._img.src = this.src; | |
73 Polymer.dom(this.root).appendChild(this._img); | |
74 } | |
75 } | |
76 | |
77 }); | |
78 | |
79 | |
OLD | NEW |