Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolves issue #100: CDN/x-domain setup fails in IE7 and IE6 when <base>... #101

Merged
merged 1 commit into from
Feb 2, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions cross-domain/respond.proxy.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var docElem = doc.documentElement, var docElem = doc.documentElement,
proxyURL = doc.getElementById("respond-proxy").href, proxyURL = doc.getElementById("respond-proxy").href,
redirectURL = (doc.getElementById("respond-redirect") || location).href, redirectURL = (doc.getElementById("respond-redirect") || location).href,
baseElem = doc.getElementsByTagName("base")[0],
urls = [], urls = [],
refNode; refNode;


Expand All @@ -25,7 +26,7 @@
docElem.insertBefore(iframe, docElem.firstElementChild || docElem.firstChild ); docElem.insertBefore(iframe, docElem.firstElementChild || docElem.firstChild );
} }


iframe.src = proxyURL + "?url=" + redirectURL + "&css=" + url; iframe.src = checkBaseURL(proxyURL) + "?url=" + redirectURL + "&css=" + checkBaseURL(url);


function checkFrameName() { function checkFrameName() {
var cssText; var cssText;
Expand Down Expand Up @@ -60,14 +61,22 @@


win.setTimeout(checkFrameName, 500); win.setTimeout(checkFrameName, 500);
} }

function checkBaseURL(href) {
if (baseElem && href.indexOf(baseElem.href) === -1) {
bref = (/\/$/).test(baseElem.href) ? baseElem.href : (baseElem.href + "/");
href = bref + href;
}

return href;
}


function checkRedirectURL() { function checkRedirectURL() {
// IE6 & IE7 don't build out absolute urls in <link /> attributes. // IE6 & IE7 don't build out absolute urls in <link /> attributes.
// So respond.proxy.gif remains relative instead of http://example.com/respond.proxy.gif. // So respond.proxy.gif remains relative instead of http://example.com/respond.proxy.gif.
// This trickery resolves that issue. // This trickery resolves that issue.
if (~ !redirectURL.indexOf(location.host)) { if (~ !redirectURL.indexOf(location.host)) {


// Inject an <a> attribute, with the redirectURL
var fakeLink = doc.createElement("div"); var fakeLink = doc.createElement("div");


fakeLink.innerHTML = '<a href="' + redirectURL + '"></a>'; fakeLink.innerHTML = '<a href="' + redirectURL + '"></a>';
Expand All @@ -89,10 +98,11 @@


var thislink = links[i], var thislink = links[i],
href = links[i].href, href = links[i].href,
ext = /^([a-zA-Z]+?:(\/\/)?(www\.)?)/; extreg = (/^([a-zA-Z]+?:(\/\/)?(www\.)?)/).test( href ),
ext = (baseElem && !extreg) || extreg;


//make sure it's an external stylesheet //make sure it's an external stylesheet
if( thislink.rel.indexOf( "stylesheet" ) >= 0 && ext.test( href ) ){ if( thislink.rel.indexOf( "stylesheet" ) >= 0 && ext ){
(function( link ){ (function( link ){
fakejax( href, function( css ){ fakejax( href, function( css ){
link.styleSheet.rawCssText = css; link.styleSheet.rawCssText = css;
Expand Down
3 changes: 2 additions & 1 deletion respond.src.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ window.matchMedia = window.matchMedia || (function(doc, undefined){
parsedSheets = {}, parsedSheets = {},
resizeThrottle = 30, resizeThrottle = 30,
head = doc.getElementsByTagName( "head" )[0] || docElem, head = doc.getElementsByTagName( "head" )[0] || docElem,
base = doc.getElementsByTagName( "base" )[0],
links = head.getElementsByTagName( "link" ), links = head.getElementsByTagName( "link" ),
requestQueue = [], requestQueue = [],


Expand All @@ -76,7 +77,7 @@ window.matchMedia = window.matchMedia || (function(doc, undefined){
translate( sheet.styleSheet.rawCssText, href, media ); translate( sheet.styleSheet.rawCssText, href, media );
parsedSheets[ href ] = true; parsedSheets[ href ] = true;
} else { } else {
if( !/^([a-zA-Z:]*\/\/)/.test( href ) if( (!base && !/^([a-zA-Z:]*\/\/)/.test( href ))
|| href.replace( RegExp.$1, "" ).split( "/" )[0] === win.location.host ){ || href.replace( RegExp.$1, "" ).split( "/" )[0] === win.location.host ){
requestQueue.push( { requestQueue.push( {
href: href, href: href,
Expand Down