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

Wrap postmessage inside ajax call.

parent 04733133
......@@ -41,8 +41,20 @@
$(this).append("<li><button id='" + i + "'>" +
value._links.contents[i].href + "</button></li>");
$(this).find("#" + i.toString()).on('click', function(e, target) {
// XXX What to do with the url info?
console.log($(this).text());
$.ajax({
// 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>");
......@@ -61,7 +73,6 @@
$(document).ready(function () {
mapUrl(window.location);
window.top.postMessage({"type":"foo", "bar":"hello"}, window.location);
});
}(document, jQuery));
......@@ -16,6 +16,7 @@
};
var handler = function (event) {
console.log(event.origin);
console.log("hello inside handler");
console.log(event);
};
......
......@@ -1057,9 +1057,10 @@
dispatch = function () {
// XXX Local hack
var ls_regexp = /browser:\/\/localstorage\/([\w\W]+)/,
browse_file_regexp = /browser:\/\/browse\/ls\/([\w\W]+)/,
browse_directory_regexp = /browser:\/\/browse\/ls\//,
var ls_regexp = /^browser:\/\/localstorage\/([\w\W]+)/,
browse_file_regexp = /^browser:\/\/browse\/ls\/([\w\W]+)/,
browse_directory_regexp = /^browser:\/\/browse\/ls\//,
plumb_regexp = /^browser:\/\/plumb\/([\w\W]+)\//,
key;
if (ls_regexp.test(this.url)) {
key = ls_regexp.exec(this.url)[1];
......@@ -1101,6 +1102,19 @@
this.respond(200, {
'Content-Type': 'application/hal+json'
}, 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 {
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