forked from scottjehl/Respond
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Respond.js proxy. The iframe URL is constructed as follows:
http://cdnexample.com/respond-proxy.html?url=http://originalurl.com/x-domain-end-point.html&css=http://cdnexample.com/example.css The URL is parsed, CSS file is extracted and stored in window.name. The file then redirects to the correct URL for MQ parsing.
- Loading branch information
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Respond JS Proxy</title> | ||
</head> | ||
<body> | ||
<script> | ||
(function () { | ||
var domain, css, url, match, file, ajax, xmlHttp; | ||
|
||
ajax = function( url, callback ) { | ||
var req = xmlHttp(); | ||
if (!req){ | ||
return; | ||
} | ||
req.open( "GET", url, true ); | ||
req.onreadystatechange = function () { | ||
if ( req.readyState != 4 || req.status != 200 && req.status != 304 ){ | ||
return; | ||
} | ||
callback( req.responseText ); | ||
} | ||
if ( req.readyState == 4 ){ | ||
return; | ||
} | ||
req.send(); | ||
}; | ||
|
||
//define ajax obj | ||
xmlHttp = (function() { | ||
var xmlhttpmethod = false, | ||
attempts = [ | ||
function(){ return new ActiveXObject("Microsoft.XMLHTTP") }, | ||
function(){ return new XMLHttpRequest() } | ||
], | ||
al = attempts.length; | ||
|
||
while( al-- ){ | ||
try { | ||
xmlhttpmethod = attempts[ al ](); | ||
} | ||
catch(e) { | ||
continue; | ||
} | ||
break; | ||
} | ||
return function(){ | ||
return xmlhttpmethod; | ||
}; | ||
})(); | ||
|
||
url = window.location.href; | ||
|
||
if (url) { | ||
match = (/css\=(.*\.css)$/).exec(url.slice(url.indexOf('?') + 1)); | ||
|
||
if (match && match[1]) { | ||
css = match[1]; | ||
} | ||
|
||
match = (/url\=([^&]+)/).exec(url); | ||
|
||
if (match && match[1]) { | ||
domain = match[1]; | ||
} | ||
} | ||
|
||
if (css) { | ||
ajax(css, function (response) { | ||
var encodedText = window.encodeURIComponent(response); | ||
|
||
window.name = encodedText; | ||
window.location.href = domain; | ||
}); | ||
} | ||
}()); | ||
</script> | ||
</body> | ||
</html> |