From bbcf37a634659c9fb4bd36ca4fa82f78271b8e98 Mon Sep 17 00:00:00 2001 From: Norman Xu Date: Fri, 25 Jul 2014 16:09:11 +0100 Subject: [PATCH 1/2] use rawgit instead of rawgithub as rawgit is the new domain name --- cross-domain/example-base.html | 6 +++--- cross-domain/example.html | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cross-domain/example-base.html b/cross-domain/example-base.html index 50201d98..ba4dcc4f 100644 --- a/cross-domain/example-base.html +++ b/cross-domain/example-base.html @@ -5,12 +5,12 @@ Respond JS Test Page - - + + - + diff --git a/cross-domain/example.html b/cross-domain/example.html index 700224e7..38b7c43a 100644 --- a/cross-domain/example.html +++ b/cross-domain/example.html @@ -3,12 +3,12 @@ Respond JS Test Page - - + + - + From 69c31b5647917b5870b07a5f49089b7cb01cf0e6 Mon Sep 17 00:00:00 2001 From: Norman Xu Date: Fri, 25 Jul 2014 17:17:36 +0100 Subject: [PATCH 2/2] add support for multiple external domain --- cross-domain/respond.proxy.js | 45 +++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/cross-domain/respond.proxy.js b/cross-domain/respond.proxy.js index 9322a354..068da6cf 100644 --- a/cross-domain/respond.proxy.js +++ b/cross-domain/respond.proxy.js @@ -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. @@ -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; @@ -81,7 +115,7 @@ // IE6 & IE7 don't build out absolute urls in 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"); @@ -123,6 +157,7 @@ if( !respond.mediaQueriesSupported ){ checkRedirectURL(); + getProxyHostMap(); buildUrls(); }