Skip to content
This repository was archived by the owner on Dec 19, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions iron-iconset-svg.html
Original file line number Diff line number Diff line change
Expand Up @@ -187,20 +187,33 @@
},

/**
*
* When name is changed, register iconset metadata
*
* Fire 'iron-iconset-added' event at next microtask.
*/
_nameChanged: function() {
this._meta.value = null;
this._meta.key = this.name;
this._meta.value = this;

_fireIronIconsetAdded: function() {
this.async(function() {
this.fire('iron-iconset-added', this, {node: window});
});
},

/**
*
* When name is changed, register iconset metadata
*
*/
_nameChanged: function() {
this._meta.value = null;
this._meta.key = this.name;
this._meta.value = this;
if (this.ownerDocument && this.ownerDocument.readyState === 'loading') {
// Document still loading. It could be that not all icons in the iconset are parsed yet.
this.ownerDocument.addEventListener('DOMContentLoaded', function() {
this._fireIronIconsetAdded();
}.bind(this));
} else {
this._fireIronIconsetAdded();
}
},

/**
* Create a map of child SVG elements by id.
*
Expand Down
11 changes: 11 additions & 0 deletions test/imported.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<iron-iconset-svg name="imported-icons" size="20">
<svg>
<defs>
<circle id="circle" cx="20" cy="20" r="10"></circle>
<rect id="square" x="0" y="0" width="20" height="20"></rect>
<symbol id="rect" viewBox="0 0 50 25">
<rect x="0" y="0" width="50" height="25"></rect>
</symbol>
</defs>
</svg>
</iron-iconset-svg>
39 changes: 39 additions & 0 deletions test/iron-iconset-svg.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@
</template>
</test-fixture>

<test-fixture id="ImportIconsetSvg">
<template>
<iron-icon icon="imported-icons:rect"></iron-icon>
</template>
</test-fixture>

<script>


Expand Down Expand Up @@ -282,6 +288,39 @@

});

suite('Late-loading iconset', function () {
var icon;
var fired;

setup(function () {
icon = fixture('ImportIconsetSvg');
fired = false;
window.addEventListener('iron-iconset-added', function(ev) {
if (ev.detail.name === 'imported-icons') {
fired = true;
}
});
});

test('icons appear after iconset is loaded.', function (done) {
var children = Polymer.dom(icon.root).querySelectorAll('img,svg');
expect(children.length).to.be.eql(0);
icon.importHref('imported.html', function () {
flush(function () {
if (!fired) {
// In Chrome with wc-shadydom=true&wc-ce=true importHref has no effect on
// already-loaded custom elements.
done();
return;
}
children = Polymer.dom(icon.root).querySelectorAll('img,svg');
expect(children.length).to.be.eql(1);
done();
});
});
});
});

</script>

</body>
Expand Down