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

Add support for multiple domain #294

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions cross-domain/example-base.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<base href="http://localhost/Respond/cross-domain/"><!--[if lte IE 6]></base><![endif]-->
<meta charset="utf-8" />
<title>Respond JS Test Page</title>
<link href="https://rawgithub.com/scottjehl/Respond/master/test/test.css" rel="stylesheet"/>
<link href="https://rawgithub.com/scottjehl/Respond/master/test/test2.css" media="screen and (min-width: 600px)" rel="stylesheet"/>
<link href="https://rawgit.com/scottjehl/Respond/master/test/test.css" rel="stylesheet"/>
<link href="https://rawgit.com/scottjehl/Respond/master/test/test2.css" media="screen and (min-width: 600px)" rel="stylesheet"/>
<script src="../dest/respond.src.js"></script>

<!-- Respond.js proxy on external server -->
<link href="https://rawgithub.com/scottjehl/Respond/master/cross-domain/respond-proxy.html" id="respond-proxy" rel="respond-proxy" />
<link href="https://rawgit.com/scottjehl/Respond/master/cross-domain/respond-proxy.html" id="respond-proxy" rel="respond-proxy" />
<link href="respond.proxy.gif" id="respond-redirect" rel="respond-redirect" />
<script src="respond.proxy.js"></script>
</head>
Expand Down
6 changes: 3 additions & 3 deletions cross-domain/example.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<head>
<meta charset="utf-8" />
<title>Respond JS Test Page</title>
<link href="https://rawgithub.com/scottjehl/Respond/master/test/test.css" rel="stylesheet"/>
<link href="https://rawgithub.com/scottjehl/Respond/master/test/test2.css" media="screen and (min-width: 600px)" rel="stylesheet"/>
<link href="https://rawgit.com/scottjehl/Respond/master/test/test.css" rel="stylesheet"/>
<link href="https://rawgit.com/scottjehl/Respond/master/test/test2.css" media="screen and (min-width: 600px)" rel="stylesheet"/>
<script src="../dest/respond.src.js"></script>

<!-- Respond.js proxy on external server -->
<link href="https://rawgithub.com/scottjehl/Respond/master/cross-domain/respond-proxy.html" id="respond-proxy" rel="respond-proxy" />
<link href="https://rawgit.com/scottjehl/Respond/master/cross-domain/respond-proxy.html" id="respond-proxy" rel="respond-proxy" />
<link href="respond.proxy.gif" id="respond-redirect" rel="respond-redirect" />
<script src="respond.proxy.js"></script>
</head>
Expand Down
45 changes: 40 additions & 5 deletions cross-domain/respond.proxy.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,54 @@
/*! Respond.js: min/max-width media query polyfill. Remote proxy (c) Scott Jehl. MIT/GPLv2 Lic. j.mp/respondjs */
(function(win, doc, undefined){
var docElem = doc.documentElement,
proxyURL = doc.getElementById("respond-proxy").href,
redirectURL = (doc.getElementById("respond-redirect") || location).href,
baseElem = doc.getElementsByTagName("base")[0],
urls = [],
proxyHostMap = {},
refNode;

function getProxyHostMap() {
var links = doc.getElementsByTagName("link"),
parser,
link;

for( var l = links.length; l--; ) {
link = links[l];
if ( link.rel != "respond-proxy" || link.href == null ) {
continue;
}
parser = getURLParser(link.href);
proxyHostMap[parser.host] = parser.href;
}
}

function getURLParser(url) {
var a = doc.createElement('a');
a.href = url;
return a;
}

function getProxyURL(url) {
var parser = getURLParser(url);
return proxyHostMap[parser.host];
}

function encode(url){
return win.encodeURIComponent(url);
}

function fakejax( url, callback ){
function fakejax( url, callback ){

var iframe,
AXO;
AXO,
proxyURL;

url = checkBaseURL(url);
proxyURL = getProxyURL(url);

if ( proxyURL == null ) {
return;
}

// All hail Google http://j.mp/iKMI19
// Behold, an iframe proxy without annoying clicky noises.
Expand All @@ -30,7 +64,7 @@
docElem.insertBefore(iframe, docElem.firstElementChild || docElem.firstChild );
}

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

function checkFrameName() {
var cssText;
Expand Down Expand Up @@ -81,7 +115,7 @@
// 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.
// This trickery resolves that issue.
if (~ !redirectURL.indexOf(location.host)) {
if (!~redirectURL.indexOf(location.host)) {

var fakeLink = doc.createElement("div");

Expand Down Expand Up @@ -123,6 +157,7 @@

if( !respond.mediaQueriesSupported ){
checkRedirectURL();
getProxyHostMap();
buildUrls();
}

Expand Down