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.
@ -198,7 +198,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
});
},
/**
* Dispatches a custom event with an optional detail value.
*
@ -234,13 +234,13 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
__eventCache: {},
// NOTE: We optionally cache event objects for efficiency during high
// freq. opts. This option cannot be used for events which may have
// freq. opts. This option cannot be used for events which may have
// `stopPropagation` called on them. On Chrome and Safari (but not FF)
// if `stopPropagation` is called, the event cannot be reused. It does not
// if `stopPropagation` is called, the event cannot be reused. It does not
// dispatch again.
_getEvent: function(type, bubbles, cancelable, useCache) {
var event = useCache && this.__eventCache[type];
if (!event || ((event.bubbles != bubbles) ||
if (!event || ((event.bubbles != bubbles) ||
(event.cancelable != cancelable))) {
event = new Event(type, {
bubbles: Boolean(bubbles),
@ -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

@ -20,7 +20,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
<dynamic-element></dynamic-element>
<script>
suite('dynamic imports', function() {
test('use importHref to load and create an element', function(done) {
@ -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>

View File

@ -12,12 +12,12 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
<dom-module id="dynamic-element">
<template>
<span id="content">dynamic-element</span> :
<span id="content">dynamic-element</span> :
</template>
</dom-module>
<script>
Polymer({
is: 'dynamic-element',
ready: function() {
@ -42,4 +42,4 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
}
});
</script>
</script>