Permalink
Browse files

web mechanics cleaned up a little

  • Loading branch information...
1 parent 8b7a8db commit 049bba7f4827b3fe4ed06449e28357c97072fa28 @dimsmol committed Feb 18, 2013
View
@@ -5,7 +5,6 @@
* fix *EventListener issues
* think about combining all apis headers into single http header - be careful, can have single row length issues
-* cleanup http mechanics
* make event names camelCase ? (check guidelines)
* make Loader command set easier to extend
@@ -10,7 +10,10 @@ inherits(JsonpMechanics, MechanicsBase);
JsonpMechanics.prototype.isJsonp = true;
JsonpMechanics.prototype.sendResponseResult = function (ctx, responseResult) {
- this.ctx.mechanics.sendJsonpResult(this.ctx, responseResult, this.callback);
+ var body = [
+ this.callback, '(', JSON.stringify(responseResult), ');'
+ ].join('');
+ this.sendResponse(this.ctx, 'text/javascript', body);
};
@@ -83,5 +83,13 @@ Mechanics.prototype.sendResponseResult = function (ctx, responseResult) {
throw new Error('Not Implemented');
};
+Mechanics.prototype.sendResponse = function (ctx, contentType, body) {
+ this.ctx.mechanics.onBeforeResponse(ctx);
+ var res = ctx.res;
+ res.statusCode = 200;
+ res.setHeader('Content-Type', contentType);
+ res.send(body);
+};
+
module.exports = Mechanics;
@@ -361,30 +361,5 @@ Mechanics.prototype.sendJsonResult = function (ctx, result) {
res.send(body);
};
-Mechanics.prototype.sendCrossDomainWorkaroundResult = function (ctx, contentType, body) {
- this.onBeforeResponse(ctx);
- var res = ctx.res;
- res.statusCode = 200;
- res.setHeader('Content-Type', contentType);
- res.send(body);
-};
-
-Mechanics.prototype.sendJsonpResult = function (ctx, result, callback) {
- var body = [
- callback, '(', JSON.stringify(result), ');'
- ].join('');
- this.sendCrossDomainWorkaroundResult(ctx, 'text/javascript', body);
-};
-
-Mechanics.prototype.sendFrameResult = function (ctx, result) {
- // NOTE IE (at least 8) can handle strings only with postMessage()
- var body = [
- '<html><script>(function(){window.parent.postMessage(JSON.stringify(',
- JSON.stringify(result),
- '), \'*\');})();</script><body></body></html>'
- ].join('');
- this.sendCrossDomainWorkaroundResult(ctx, 'text/html', body);
-};
-
module.exports = Mechanics;

0 comments on commit 049bba7

Please sign in to comment.