Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

web mechanics cleaned up a little

  • Loading branch information...
commit 049bba7f4827b3fe4ed06449e28357c97072fa28 1 parent 8b7a8db
@dimsmol authored
View
1  TODO.md
@@ -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
View
5 lib/mechanics/web/cross_domain_workaround/jsonp_mechanics.js
@@ -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);
};
View
8 lib/mechanics/web/cross_domain_workaround/mechanics_base.js
@@ -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;
View
25 lib/mechanics/web/mechanics.js
@@ -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;
Please sign in to comment.
Something went wrong with that request. Please try again.