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 #59: Cross domain CSS files with ? in URL won't load #104

Merged
merged 2 commits into from
Mar 16, 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
60 changes: 38 additions & 22 deletions cross-domain/respond-proxy.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,41 @@
<body>
<script>
(function () {
var domain, css, url, match, file, ajax, xmlHttp;

var domain, css, query, getQueryString, ajax, xmlHttp;

/*
http://stackoverflow.com/questions/4963673/get-url-array-variables-in-javascript-jquery/4963817#4963817
*/
getQueryString = function() {
var ret = {}, parts, i, p;

parts = (document.location.toString().split("?")[1]).split("&");

for (i = 0; i < parts.length; i++) {

p = parts[i].split("=");
// so strings will be correctly parsed:
p[1] = decodeURIComponent(p[1].replace(/\+/g, " "));

if (p[0].search(/\[\]/) >= 0) { // then it"s an array
p[0] = p[0].replace("[]", "");

if (typeof ret[p[0]] != "object") {
ret[p[0]] = [];
}
ret[p[0]].push(p[1]);
} else {
ret[p[0]] = p[1];
}
}
return ret;
};

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 ){
Expand All @@ -27,7 +55,7 @@
}
req.send();
};

//define ajax obj
xmlHttp = (function() {
var xmlhttpmethod = false,
Expand All @@ -51,24 +79,12 @@
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) {

query = getQueryString();
css = query["css"];
domain = query["url"];

if (css && domain) {
ajax(css, function (response) {
window.name = response;
window.location.href = domain;
Expand Down
6 changes: 5 additions & 1 deletion cross-domain/respond.proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
urls = [],
refNode;

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

function fakejax( url, callback ){

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

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

function checkFrameName() {
var cssText;
Expand Down