Skip to content
This repository was archived by the owner on Mar 13, 2018. It is now read-only.

Commit 38c3371

Browse files
author
Steve Orvell
committed
Merge pull request #47 from Polymer/dynamic-ie
Fixes for IE
2 parents d2a0fa6 + dec1f87 commit 38c3371

File tree

6 files changed

+47
-6
lines changed

6 files changed

+47
-6
lines changed

build.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[
2+
"../MutationObservers/build.json",
23
"src/scope.js",
34
"src/Loader.js",
45
"src/Parser.js",

conf/karma.conf.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ module.exports = function(karma) {
1313
'HTMLImports/html-imports.js',
1414
{pattern: 'tools/**/*.js', included: false},
1515
{pattern: 'HTMLImports/src/*', included: false},
16-
{pattern: 'HTMLImports/test/**/*', included: false}
16+
{pattern: 'HTMLImports/test/**/*', included: false},
17+
{pattern: 'MutationObservers/*.js', included: false},
18+
{pattern: 'WeakMap/*.js', included: false}
1719
],
1820
}));
1921
};

html-imports.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
var thisFile = 'html-imports.js';
1010
var scopeName = 'HTMLImports';
1111
var modules = [
12+
'../MutationObservers/mutation-observers.js',
1213
'src/scope.js',
1314
'src/Loader.js',
1415
'src/Parser.js',

src/HTMLImports.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,23 @@ var currentScriptDescriptor = {
164164
get: function() {
165165
return HTMLImports.currentScript || document.currentScript;
166166
},
167-
writeable: true,
168167
configurable: true
169-
}
168+
};
170169

171170
Object.defineProperty(document, '_currentScript', currentScriptDescriptor);
172171
Object.defineProperty(mainDoc, '_currentScript', currentScriptDescriptor);
173172

173+
// Polyfill document.baseURI for browsers without it.
174+
// ShadowDOM Polyfill wrapper should handle this automatically.
175+
if (!document.baseURI) {
176+
Object.defineProperty(document, 'baseURI', {
177+
get: function() {
178+
return window.location.href;
179+
},
180+
configurable: true
181+
});
182+
}
183+
174184
// TODO(sorvell): multiple calls will install multiple event listeners
175185
// which may not be desireable; calls should resolve in the correct order,
176186
// however.

src/Observer.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ var importSelector = 'link[rel=' + IMPORT_LINK_TYPE + ']';
1212
var matches = HTMLElement.prototype.matches ||
1313
HTMLElement.prototype.matchesSelector ||
1414
HTMLElement.prototype.webkitMatchesSelector ||
15-
HTMLElement.prototype.mozMatchesSelector;
15+
HTMLElement.prototype.mozMatchesSelector ||
16+
HTMLElement.prototype.msMatchesSelector;
1617

1718
var importer = scope.importer;
1819

@@ -22,7 +23,7 @@ function handler(mutations) {
2223
addedNodes(m.addedNodes);
2324
}
2425
}
25-
};
26+
}
2627

2728
function addedNodes(nodes) {
2829
for (var i=0, l=nodes.length, n; (i<l) && (n=nodes[i]); i++) {

src/Parser.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,32 @@ var importParser = {
109109
};
110110
elt.addEventListener('load', done);
111111
elt.addEventListener('error', done);
112+
113+
// NOTE: IE does not fire "load" event for styles that have already loaded
114+
// This is in violation of the spec, so we try our hardest to work around it
115+
if (isIe && elt.localName === 'style') {
116+
var fakeLoad = false;
117+
// If there's not @import in the textContent, assume it has loaded
118+
if (elt.textContent.indexOf('@import') == -1) {
119+
fakeLoad = true;
120+
// if we have a sheet, we have been parsed
121+
} else if (elt.sheet) {
122+
fakeLoad = true;
123+
var csr = elt.sheet.cssRules;
124+
var len = csr ? csr.length : 0;
125+
// search the rules for @import's
126+
for (var i = 0, r; (i < len) && (r = csr[i]); i++) {
127+
if (r.type === CSSRule.IMPORT_RULE) {
128+
// if every @import has resolved, fake the load
129+
fakeLoad = fakeLoad && Boolean(r.styleSheet);
130+
}
131+
}
132+
}
133+
// dispatch a fake load event and continue parsing
134+
if (fakeLoad) {
135+
elt.dispatchEvent(new CustomEvent('load', {bubbles: false}));
136+
}
137+
}
112138
},
113139
parseScript: function(scriptElt) {
114140
// acquire code to execute
@@ -216,4 +242,4 @@ scope.parser = importParser;
216242
scope.path = path;
217243
scope.isIE = isIe;
218244

219-
})(HTMLImports);
245+
})(HTMLImports);

0 commit comments

Comments
 (0)