Merge pull request #3114 from Polymer/3113

importHref loads imports, async. Fixes #3113
This commit is contained in:
Daniel Freedman 2015-12-09 18:26:42 -08:00
commit 9066a48a63
3 changed files with 40 additions and 11 deletions

View File

@ -164,7 +164,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
/**
* Returns a list of nodes distributed to this element's `<content>`.
*
* If this element contans more than one `<content>` in its local DOM,
* If this element contains more than one `<content>` in its local DOM,
* an optional selector may be passed to choose the desired content.
*
* @method getContentChildNodes
@ -181,7 +181,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
* Returns a list of element children distributed to this element's
* `<content>`.
*
* If this element contans more than one `<content>` in its
* If this element contains more than one `<content>` in its
* local DOM, an optional selector may be passed to choose the desired
* content. This method differs from `getContentChildNodes` in that only
* elements are returned.
@ -358,12 +358,20 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
* loaded.
* @param {Function} onerror Callback to notify when an import
* unsuccessfully loaded.
* @param {boolean} optAsync True if the import should be loaded `async`.
* Defaults to `false`.
* @return {HTMLLinkElement} The link element for the URL to be loaded.
*/
importHref: function(href, onload, onerror) {
importHref: function(href, onload, onerror, optAsync) {
var l = document.createElement('link');
l.rel = 'import';
l.href = href;
optAsync = Boolean(optAsync);
if (optAsync) {
l.setAttribute('async', '');
}
var self = this;
if (onload) {
l.onload = function(e) {

View File

@ -36,6 +36,27 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
});
});
suite('async/sync loading', function() {
var url = 'dynamic-imports/dynamic-element.html';
test('importHref sync loads by default', function(done) {
Polymer.Base.importHref(url, function(e) {
assert.isFalse(e.target.hasAttribute('async'),
'sync load is default');
done();
});
});
test('importHref sync loading', function(done) {
Polymer.Base.importHref(url, function(e) {
assert.isTrue(e.target.hasAttribute('async'), 'async load');
done();
}, null, true);
});
});
});
</script>