Skip to content

Commit

Permalink
Opera 11 doesn't have the XDomainRequest, but Opera 12 (beta) does. This
Browse files Browse the repository at this point in the history
is a workaround using jsonp.

fixes #6
  • Loading branch information
jfly committed Jun 12, 2012
1 parent 0de5d6e commit d3368ab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ protected void wrappedHandle(HttpExchange t, String[] path, LinkedHashMap<String
} else {
Date generationDate = new Date();

// TODO - this means you can't have a round named "seed" or "showIndices"!
// TODO - this means you can't have a round named "seed" or "showIndices" or "callback"!
String seed = query.remove("seed");
boolean showIndices = query.remove("showIndices") != null;
String callback = query.remove("callback");

String globalTitle, ext;
int lastDot = path[0].lastIndexOf(".");
Expand Down Expand Up @@ -66,7 +67,7 @@ protected void wrappedHandle(HttpExchange t, String[] path, LinkedHashMap<String
sendText(t, sb.toString());
} else if(ext.equals("json")) {
ScrambleRequest[] scrambleRequests = ScrambleRequest.parseScrambleRequests(query, seed);
sendJSON(t, GSON.toJson(scrambleRequests), query.get("callback"));
sendJSON(t, GSON.toJson(scrambleRequests), callback);
} else if(ext.equals("pdf")) {
ScrambleRequest[] scrambleRequests = ScrambleRequest.parseScrambleRequests(query, seed);
ByteArrayOutputStream totalPdfOutput = ScrambleRequest.requestsToPdf(globalTitle, generationDate, scrambleRequests);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ tnoodle.ajax = function(callback, url, data) {
}
}
if(xhr === null) {
// freaking opera & ie, man
// we'll make an attempt to use jsonp here
// Opera 11 doesn't have XDomainRequest, so
// we'll make an attempt to use jsonp here.
tnoodle.jsonp(callback, url, data);
return null;
}
Expand Down Expand Up @@ -294,32 +294,28 @@ tnoodle.retryAjax = function(callback, url, data, nthTry) {
}
return { abort: abort };
};
tnoodle.jsonpcount = 0;
tnoodle.jsonp = function(callback, url, data) {
// TODO - we don't have access to mootools anymore...
var request = new Request.JSONP({
url: url,
callbackKey: "callback",
data: data,
onComplete: callback
});
request.send();
/*
var callbackname = "tnoodle.jsonp.callback" + this.jsonpcount++;
eval(callbackname + "=callback");
var callbackname = "tnoodle.jsonp.callback" + tnoodle.jsonpcount++;
var JSLINT_HAPPY_EVAL = eval; // I *totally* know what I'm doing, yep
JSLINT_HAPPY_EVAL(callbackname + "=callback");
if (url.indexOf("?") > -1) {
url += "&callback=";
} else {
url += "?callback=";
}

url += callbackname + "&" + tnoodle.toQueryString(data);
url += "&" + new Date().getTime().toString(); // prevent caching

// TODO - is this needed? We can't do it now, because of the super
// strict parsing of url parameters. See
// https://github.com/jfly/tnoodle/issues/22
//url += "&" + new Date().getTime().toString(); // prevent caching

var script = document.createElement("script");
script.setAttribute("src",url);
script.setAttribute("type","text/javascript");
script.setAttribute("src", url);
script.setAttribute("type", "text/javascript");
document.body.appendChild(script); //TODO - doesn't work until body is loaded
*/
};
tnoodle.toQueryString = function(data) {
var url = "";
Expand Down

0 comments on commit d3368ab

Please sign in to comment.