Skip to content
This repository
Browse code

Merge pull request #104 from scottjehl/cross-domain

Resolves Issue #59: Cross domain CSS files with ? in URL won't load
  • Loading branch information...
commit b21c5785e8442cca651f532ce72e6e515817ad3d 2 parents ed8479c + f949305
authored March 16, 2012
60  cross-domain/respond-proxy.html
@@ -8,13 +8,41 @@
8 8
 <body>
9 9
 	<script>
10 10
 		(function () {
11  
-			var domain, css, url, match, file, ajax, xmlHttp;
12  
-			
  11
+			var domain, css, query, getQueryString, ajax, xmlHttp;
  12
+
  13
+			/*
  14
+				http://stackoverflow.com/questions/4963673/get-url-array-variables-in-javascript-jquery/4963817#4963817
  15
+			*/
  16
+			getQueryString = function() {
  17
+				var ret = {}, parts, i, p;
  18
+
  19
+				parts = (document.location.toString().split("?")[1]).split("&");
  20
+
  21
+				for (i = 0; i < parts.length; i++) {
  22
+
  23
+					p = parts[i].split("=");
  24
+					// so strings will be correctly parsed:
  25
+					p[1] = decodeURIComponent(p[1].replace(/\+/g, " "));
  26
+
  27
+					if (p[0].search(/\[\]/) >= 0) { // then it"s an array
  28
+						p[0] = p[0].replace("[]", "");
  29
+
  30
+						if (typeof ret[p[0]] != "object") {
  31
+							ret[p[0]] = [];
  32
+						}
  33
+						ret[p[0]].push(p[1]);
  34
+					} else {
  35
+						ret[p[0]] = p[1];
  36
+					}
  37
+				}
  38
+				return ret;
  39
+			};
  40
+
13 41
 			ajax = function( url, callback ) {
14 42
 				var req = xmlHttp();
15 43
 				if (!req){
16 44
 					return;
17  
-				}	
  45
+				}
18 46
 				req.open( "GET", url, true );
19 47
 				req.onreadystatechange = function () {
20 48
 					if ( req.readyState != 4 || req.status != 200 && req.status != 304 ){
@@ -27,7 +55,7 @@
27 55
 				}
28 56
 				req.send();
29 57
 			};
30  
-			
  58
+
31 59
 			//define ajax obj 
32 60
 			xmlHttp = (function() {
33 61
 				var xmlhttpmethod = false,
@@ -51,24 +79,12 @@
51 79
 					return xmlhttpmethod;
52 80
 				};
53 81
 			})();
54  
-			
55  
-			url = window.location.href;
56  
-			
57  
-			if (url) {
58  
-				match = (/css\=(.*\.css)$/).exec(url.slice(url.indexOf('?') + 1));
59  
-				
60  
-				if (match && match[1]) {
61  
-					css = match[1];
62  
-				}
63  
-				
64  
-				match = (/url\=([^&]+)/).exec(url);
65  
-				
66  
-				if (match && match[1]) {
67  
-					domain = match[1];
68  
-				}
69  
-			}
70  
-			
71  
-			if (css) {
  82
+
  83
+			query = getQueryString();
  84
+			css = query["css"];
  85
+			domain = query["url"];
  86
+
  87
+			if (css && domain) {
72 88
 				ajax(css, function (response) {
73 89
 					window.name = response;
74 90
 					window.location.href = domain;
6  cross-domain/respond.proxy.js
@@ -7,6 +7,10 @@
7 7
 		urls			= [],
8 8
 		refNode;
9 9
 
  10
+	function encode(url){
  11
+		return win.encodeURIComponent(url);
  12
+	}
  13
+
10 14
 	 function fakejax( url, callback ){
11 15
 
12 16
 		var iframe,
@@ -26,7 +30,7 @@
26 30
 			docElem.insertBefore(iframe, docElem.firstElementChild || docElem.firstChild );
27 31
 		}
28 32
 
29  
-		iframe.src = checkBaseURL(proxyURL) + "?url=" + redirectURL + "&css=" + checkBaseURL(url);
  33
+		iframe.src = checkBaseURL(proxyURL) + "?url=" + encode(redirectURL) + "&css=" + encode(checkBaseURL(url));
30 34
 		
31 35
 		function checkFrameName() {
32 36
 			var cssText;

0 notes on commit b21c578

Please sign in to comment.
Something went wrong with that request. Please try again.