Skip to content

Commit

Permalink
Severus.ajax now supports cross domain thingsw
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Nov 14, 2010
1 parent 31bcf30 commit e2398b5
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 42 deletions.
Binary file modified lib/.app.coffee.swp
Binary file not shown.
32 changes: 32 additions & 0 deletions log.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,35 @@ Sun Nov 14 01:50:04 UTC 2010
Sun Nov 14 01:50:05 UTC 2010
Sun Nov 14 01:50:11 UTC 2010
Sun Nov 14 01:50:11 UTC 2010
Sun Nov 14 06:03:03 UTC 2010
Sun Nov 14 06:03:03 UTC 2010
Sun Nov 14 06:03:03 UTC 2010
Sun Nov 14 06:33:53 UTC 2010
Sun Nov 14 06:34:17 UTC 2010
Sun Nov 14 06:34:30 UTC 2010
Sun Nov 14 06:54:45 UTC 2010
Sun Nov 14 06:54:45 UTC 2010
Sun Nov 14 06:55:59 UTC 2010
Sun Nov 14 06:55:59 UTC 2010
Sun Nov 14 06:57:15 UTC 2010
Sun Nov 14 06:57:15 UTC 2010
Sun Nov 14 06:57:43 UTC 2010
Sun Nov 14 06:57:44 UTC 2010
Sun Nov 14 07:04:54 UTC 2010
Sun Nov 14 07:04:54 UTC 2010
Sun Nov 14 07:05:43 UTC 2010
Sun Nov 14 07:05:43 UTC 2010
Sun Nov 14 07:06:38 UTC 2010
Sun Nov 14 07:06:38 UTC 2010
Sun Nov 14 07:07:01 UTC 2010
Sun Nov 14 07:07:01 UTC 2010
Sun Nov 14 07:07:49 UTC 2010
Sun Nov 14 07:07:49 UTC 2010
Sun Nov 14 07:08:07 UTC 2010
Sun Nov 14 07:08:07 UTC 2010
Sun Nov 14 07:10:19 UTC 2010
Sun Nov 14 07:10:19 UTC 2010
Sun Nov 14 07:10:51 UTC 2010
Sun Nov 14 07:10:51 UTC 2010
Sun Nov 14 07:11:14 UTC 2010
Sun Nov 14 07:11:14 UTC 2010
2 changes: 1 addition & 1 deletion pid.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
28291
28755
Binary file modified public/.severus.coffee.swp
Binary file not shown.
55 changes: 36 additions & 19 deletions public/severus.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,7 @@ Severus.acceptMessages = (whitelist) ->
args = message.args
id = message.id
if message.type is "ajax" #do an ajax request
posted =
id: id
type: "success"
dataType: args.dataType
if args.success?
args.success = (data) ->
posted.data = data
parent.postMessage JSON.stringify(posted), "*"
if args.error?
args.error = (data) ->
posted.type = "error"
posted.data = data
parent.postMessage JSON.stringify(posted), "*"


console.log args
delete args.contentType
#delete args.processData
Expand All @@ -146,16 +133,46 @@ Severus.acceptMessages = (whitelist) ->
url = url.split("/")[0]
if (_(args.url).startsWith("http://") or _(args.url).startsWith("https://")) and \
not(_(args.url).startsWith(protocol + url))
console.log "youre here!!"
old_args = _.clone(args)
args.url = "/ajax"
args.url = "/method/ajax"
args.type = "POST"
args.data =
new_data =
url: old_args.url
data: old_args.data
args.data =
q: JSON.stringify new_data
#contenttype?


posted =
id: id
type: "success"
if args.success? #should be set to 1 or something if there was a success
args.success = (data) ->
if not data.error
posted.data = data.result
parent.postMessage JSON.stringify(posted), "*"
else
posted.data = data.error
posted.type = "errror"
parent.postMessage JSON.stringify(posted), "*"
if args.error?
args.error = (data) ->
posted.type = "error"
posted.data = data
parent.postMessage JSON.stringify(posted), "*"
else #if not an ajax wrapper
posted =
id: id
type: "success"
dataType: args.dataType
if args.success?
args.success = (data) ->
posted.data = data
parent.postMessage JSON.stringify(posted), "*"
if args.error?
args.error = (data) ->
posted.type = "error"
posted.data = data
parent.postMessage JSON.stringify(posted), "*"
$.ajax args
else if message.type is "login_facebook" #authenticate with facebook.
url = "https://graph.facebook.com/oauth/authorize"
Expand Down
70 changes: 48 additions & 22 deletions public/severus.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,45 +142,71 @@
whitelist = whitelist || [];
sev = this;
return window.addEventListener("message", function(e) {
var _a, _b, args, id, message, old_args, post, posted, protocol, redirect_uri, url;
var _a, _b, _c, _d, args, id, message, new_data, old_args, post, posted, protocol, redirect_uri, url;
if (whitelist.length === 0 || _.indexOf(whitelist, e.origin) !== -1) {
message = JSON.parse(e.data);
args = message.args;
id = message.id;
if (message.type === "ajax") {
posted = {
id: id,
type: "success",
dataType: args.dataType
};
if (typeof (_a = args.success) !== "undefined" && _a !== null) {
args.success = function(data) {
posted.data = data;
return parent.postMessage(JSON.stringify(posted), "*");
};
}
if (typeof (_b = args.error) !== "undefined" && _b !== null) {
args.error = function(data) {
posted.type = "error";
posted.data = data;
return parent.postMessage(JSON.stringify(posted), "*");
};
}
console.log(args);
delete args.contentType;
console.log(Severus.url);
protocol = _.s(Severus.url, 0, Severus.url.indexOf("//") + 2);
url = _.s(Severus.url, Severus.url.indexOf("//") + 2);
url = url.split("/")[0];
if ((_(args.url).startsWith("http://") || _(args.url).startsWith("https://")) && !(_(args.url).startsWith(protocol + url))) {
console.log("youre here!!");
old_args = _.clone(args);
args.url = "/ajax";
args.url = "/method/ajax";
args.type = "POST";
args.data = {
new_data = {
url: old_args.url,
data: old_args.data
};
args.data = {
q: JSON.stringify(new_data)
};
posted = {
id: id,
type: "success"
};
if (typeof (_a = args.success) !== "undefined" && _a !== null) {
args.success = function(data) {
if (!data.error) {
posted.data = data.result;
return parent.postMessage(JSON.stringify(posted), "*");
} else {
posted.data = data.error;
posted.type = "errror";
return parent.postMessage(JSON.stringify(posted), "*");
}
};
}
if (typeof (_b = args.error) !== "undefined" && _b !== null) {
args.error = function(data) {
posted.type = "error";
posted.data = data;
return parent.postMessage(JSON.stringify(posted), "*");
};
}
} else {
posted = {
id: id,
type: "success",
dataType: args.dataType
};
if (typeof (_c = args.success) !== "undefined" && _c !== null) {
args.success = function(data) {
posted.data = data;
return parent.postMessage(JSON.stringify(posted), "*");
};
}
if (typeof (_d = args.error) !== "undefined" && _d !== null) {
args.error = function(data) {
posted.type = "error";
posted.data = data;
return parent.postMessage(JSON.stringify(posted), "*");
};
}
}
return $.ajax(args);
} else if (message.type === "login_facebook") {
Expand Down

0 comments on commit e2398b5

Please sign in to comment.