| Index: third_party/polymer/components-chromium/core-iconset-svg/core-iconset-svg-extracted.js
|
| diff --git a/third_party/polymer/components-chromium/core-iconset-svg/core-iconset-svg-extracted.js b/third_party/polymer/components-chromium/core-iconset-svg/core-iconset-svg-extracted.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a443ed2426c0afaf4d4d7cf5dfd46a762f92df4e
|
| --- /dev/null
|
| +++ b/third_party/polymer/components-chromium/core-iconset-svg/core-iconset-svg-extracted.js
|
| @@ -0,0 +1,113 @@
|
| +
|
| +
|
| + Polymer('core-iconset-svg', {
|
| +
|
| +
|
| + /**
|
| + * The size of an individual icon. Note that icons must be square.
|
| + *
|
| + * @attribute iconSize
|
| + * @type number
|
| + * @default 24
|
| + */
|
| + iconSize: 24,
|
| + type: 'iconset',
|
| +
|
| + created: function() {
|
| + this._icons = {};
|
| + },
|
| +
|
| + ready: function() {
|
| + this.super();
|
| + this.updateIcons();
|
| + },
|
| +
|
| + iconById: function(id) {
|
| + return this._icons[id] || (this._icons[id] = this.querySelector('#' + id));
|
| + },
|
| +
|
| + cloneIcon: function(id) {
|
| + var icon = this.iconById(id);
|
| + if (icon) {
|
| + var content = icon.cloneNode(true);
|
| + content.removeAttribute('id');
|
| + var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
| + svg.setAttribute('viewBox', '0 0 ' + this.iconSize + ' ' +
|
| + this.iconSize);
|
| + // NOTE(dfreedm): work around https://crbug.com/370136
|
| + svg.style.pointerEvents = 'none';
|
| + svg.appendChild(content);
|
| + return svg;
|
| + }
|
| + },
|
| +
|
| + get iconNames() {
|
| + if (!this._iconNames) {
|
| + this._iconNames = this.findIconNames();
|
| + }
|
| + return this._iconNames;
|
| + },
|
| +
|
| + findIconNames: function() {
|
| + var icons = this.querySelectorAll('[id]').array();
|
| + if (icons.length) {
|
| + return icons.map(function(n){ return n.id });
|
| + }
|
| + },
|
| +
|
| + /**
|
| + * Applies an icon to the given element. The svg icon is added to the
|
| + * element's shadowRoot if one exists or directly to itself.
|
| + *
|
| + * @method applyIcon
|
| + * @param {Element} element The element to which the icon is
|
| + * applied.
|
| + * @param {String|Number} icon The name the icon to apply.
|
| + * @return {Element} The icon element
|
| + */
|
| + applyIcon: function(element, icon) {
|
| + var root = element;
|
| + // remove old
|
| + var old = root.querySelector('svg');
|
| + if (old) {
|
| + old.remove();
|
| + }
|
| + // install new
|
| + var svg = this.cloneIcon(icon);
|
| + if (!svg) {
|
| + return;
|
| + }
|
| + svg.setAttribute('height', '100%');
|
| + svg.setAttribute('width', '100%');
|
| + svg.setAttribute('preserveAspectRatio', 'xMidYMid meet');
|
| + svg.style.display = 'block';
|
| + root.insertBefore(svg, root.firstElementChild);
|
| + return svg;
|
| + },
|
| +
|
| + /**
|
| + * Tell users of the iconset, that the set has loaded.
|
| + * This finds all elements matching the selector argument and calls
|
| + * the method argument on them.
|
| + * @method updateIcons
|
| + * @param selector {string} css selector to identify iconset users,
|
| + * defaults to '[icon]'
|
| + * @param method {string} method to call on found elements,
|
| + * defaults to 'updateIcon'
|
| + */
|
| + updateIcons: function(selector, method) {
|
| + selector = selector || '[icon]';
|
| + method = method || 'updateIcon';
|
| + var deep = window.ShadowDOMPolyfill ? '' : 'html /deep/ ';
|
| + var i$ = document.querySelectorAll(deep + selector);
|
| + for (var i=0, e; e=i$[i]; i++) {
|
| + if (e[method]) {
|
| + e[method].call(e);
|
| + }
|
| + }
|
| + }
|
| +
|
| +
|
| + });
|
| +
|
| +
|
|
|