Skip to content

Commit

Permalink
Merge pull request LeaVerou#61 from vincentbernat/fix/xdomainrequest
Browse files Browse the repository at this point in the history
IE9: Fallback to XDomainRequest if available.
  • Loading branch information
LeaVerou committed Apr 16, 2012
2 parents 7031ff1 + 1fcb5f5 commit a61a1e7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
27 changes: 21 additions & 6 deletions prefixfree.js
Expand Up @@ -25,12 +25,16 @@ var self = window.StyleFix = {
var url = link.href || link.getAttribute('data-href'),
base = url.replace(/[^\/]+$/, ''),
parent = link.parentNode,
xhr = new XMLHttpRequest();
xhr = new XMLHttpRequest(),
process;

xhr.open('GET', url);

xhr.onreadystatechange = function() {
if(xhr.readyState === 4) {
process();
}
}

process = function() {
var css = xhr.responseText;

if(css && link.parentNode) {
Expand Down Expand Up @@ -60,10 +64,21 @@ var self = window.StyleFix = {
parent.insertBefore(style, link);
parent.removeChild(link);
}
}
};

xhr.send(null);

try {
xhr.open('GET', url);
xhr.send(null);
} catch (e) {
// Fallback to XDomainRequest if available
if (typeof XDomainRequest != "undefined") {
xhr = new XDomainRequest();
xhr.onerror = xhr.onprogress = function() {};
xhr.onload = process;
xhr.open("GET", url);
xhr.send(null);
}
}

link.setAttribute('data-inprogress', '');
},
Expand Down
16 changes: 5 additions & 11 deletions prefixfree.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a61a1e7

Please sign in to comment.