Commit 48b8c894 authored by Romain Courteaud's avatar Romain Courteaud

Wrap postmessage inside ajax call.

parent 04733133
...@@ -41,8 +41,20 @@ ...@@ -41,8 +41,20 @@
$(this).append("<li><button id='" + i + "'>" + $(this).append("<li><button id='" + i + "'>" +
value._links.contents[i].href + "</button></li>"); value._links.contents[i].href + "</button></li>");
$(this).find("#" + i.toString()).on('click', function(e, target) { $(this).find("#" + i.toString()).on('click', function(e, target) {
// XXX What to do with the url info? $.ajax({
console.log($(this).text()); // XXX Hardcoded post and url
// Why using postMessage?
method: "POST",
url: "browser://plumb/topwindow/",
context: $(this),
data: $(this).text(),
error: function (jqXHR, textStatus, errorThrown) {
console.log("Plumbing failed: " + errorThrown);
},
// success: function (value, textStatus, jqXHR) {
// console.log(value);
// },
});
}); });
} }
$(this).append("</ul>"); $(this).append("</ul>");
...@@ -61,7 +73,6 @@ ...@@ -61,7 +73,6 @@
$(document).ready(function () { $(document).ready(function () {
mapUrl(window.location); mapUrl(window.location);
window.top.postMessage({"type":"foo", "bar":"hello"}, window.location);
}); });
}(document, jQuery)); }(document, jQuery));
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
}; };
var handler = function (event) { var handler = function (event) {
console.log(event.origin);
console.log("hello inside handler"); console.log("hello inside handler");
console.log(event); console.log(event);
}; };
......
...@@ -1057,9 +1057,10 @@ ...@@ -1057,9 +1057,10 @@
dispatch = function () { dispatch = function () {
// XXX Local hack // XXX Local hack
var ls_regexp = /browser:\/\/localstorage\/([\w\W]+)/, var ls_regexp = /^browser:\/\/localstorage\/([\w\W]+)/,
browse_file_regexp = /browser:\/\/browse\/ls\/([\w\W]+)/, browse_file_regexp = /^browser:\/\/browse\/ls\/([\w\W]+)/,
browse_directory_regexp = /browser:\/\/browse\/ls\//, browse_directory_regexp = /^browser:\/\/browse\/ls\//,
plumb_regexp = /^browser:\/\/plumb\/([\w\W]+)\//,
key; key;
if (ls_regexp.test(this.url)) { if (ls_regexp.test(this.url)) {
key = ls_regexp.exec(this.url)[1]; key = ls_regexp.exec(this.url)[1];
...@@ -1101,6 +1102,19 @@ ...@@ -1101,6 +1102,19 @@
this.respond(200, { this.respond(200, {
'Content-Type': 'application/hal+json' 'Content-Type': 'application/hal+json'
}, JSON.stringify(response)); }, JSON.stringify(response));
} else if (plumb_regexp.test(this.url)) {
key = plumb_regexp.exec(this.url)[1];
if (this.method === "POST") {
if (key === "topwindow") {
// XXX hardcoded * necessarity to send in case of file URL
// Fix needed!!!
window.top.postMessage(this.body, "*");
} else {
this.respond(404, {}, "");
}
} else {
this.respond(405, {}, "");
}
} else { } else {
this.respond(404, {}, ""); this.respond(404, {}, "");
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment