Skip to content

Commit

Permalink
Fixes #3113
Browse files Browse the repository at this point in the history
  • Loading branch information
ebidel committed Dec 10, 2015
1 parent 06898da commit fadd455
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
22 changes: 15 additions & 7 deletions src/standard/utils.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
/**
* 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
Expand All @@ -181,7 +181,7 @@
* 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.
Expand All @@ -198,7 +198,7 @@
});
},


/**
* Dispatches a custom event with an optional detail value.
*
Expand Down Expand Up @@ -234,13 +234,13 @@
__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),
Expand Down Expand Up @@ -358,12 +358,20 @@
* 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) {
Expand Down
23 changes: 22 additions & 1 deletion test/unit/dynamic-import.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<dynamic-element></dynamic-element>

<script>

suite('dynamic imports', function() {

test('use importHref to load and create an element', function(done) {
Expand All @@ -36,6 +36,27 @@
});
});

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>
Expand Down
6 changes: 3 additions & 3 deletions test/unit/dynamic-imports/dynamic-element.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

<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() {
Expand All @@ -42,4 +42,4 @@
}

});
</script>
</script>

0 comments on commit fadd455

Please sign in to comment.