3 Polymer('core-iconset-svg', {
7 * The size of an individual icon. Note that icons must be square.
25 iconById: function(id) {
26 return this._icons[id] || (this._icons[id] = this.querySelector('#' + id));
29 cloneIcon: function(id) {
30 var icon = this.iconById(id);
32 var content = icon.cloneNode(true);
33 content.removeAttribute('id');
34 var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
35 svg.setAttribute('viewBox', '0 0 ' + this.iconSize + ' ' +
37 // NOTE(dfreedm): work around https://crbug.com/370136
38 svg.style.pointerEvents = 'none';
39 svg.appendChild(content);
45 if (!this._iconNames) {
46 this._iconNames = this.findIconNames();
48 return this._iconNames;
51 findIconNames: function() {
52 var icons = this.querySelectorAll('[id]').array();
54 return icons.map(function(n){ return n.id });
59 * Applies an icon to the given element. The svg icon is added to the
60 * element's shadowRoot if one exists or directly to itself.
63 * @param {Element} element The element to which the icon is
65 * @param {String|Number} icon The name the icon to apply.
66 * @return {Element} The icon element
68 applyIcon: function(element, icon) {
71 var old = root.querySelector('svg');
76 var svg = this.cloneIcon(icon);
80 svg.setAttribute('height', '100%');
81 svg.setAttribute('width', '100%');
82 svg.setAttribute('preserveAspectRatio', 'xMidYMid meet');
83 svg.style.display = 'block';
84 root.insertBefore(svg, root.firstElementChild);
89 * Tell users of the iconset, that the set has loaded.
90 * This finds all elements matching the selector argument and calls
91 * the method argument on them.
93 * @param selector {string} css selector to identify iconset users,
94 * defaults to '[icon]'
95 * @param method {string} method to call on found elements,
96 * defaults to 'updateIcon'
98 updateIcons: function(selector, method) {
99 selector = selector || '[icon]';
100 method = method || 'updateIcon';
101 var deep = window.ShadowDOMPolyfill ? '' : 'html /deep/ ';
102 var i$ = document.querySelectorAll(deep + selector);
103 for (var i=0, e; e=i$[i]; i++) {