You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.8 KiB
JavaScript
57 lines
1.8 KiB
JavaScript
define([
|
|
'jquery',
|
|
|
|
'/bower_components/tweetnacl/nacl-fast.min.js',
|
|
'css!/bower_components/components-font-awesome/css/font-awesome.min.css',
|
|
'less!/checkup/app-checkup.less',
|
|
], function ($) {
|
|
var postMessage = function (content) {
|
|
window.parent.postMessage(JSON.stringify(content), '*');
|
|
};
|
|
postMessage({ command: "READY", });
|
|
var getHeaders = function (url, cb) {
|
|
$.ajax(url + "?test=" + (+new Date()), {
|
|
dataType: 'text',
|
|
complete: function (xhr) {
|
|
var allHeaders = xhr.getAllResponseHeaders();
|
|
return void cb(void 0, allHeaders, xhr);
|
|
},
|
|
});
|
|
};
|
|
var COMMANDS = {};
|
|
COMMANDS.GET_HEADER = function (content, cb) {
|
|
var url = content.url;
|
|
getHeaders(url, function (err, headers, xhr) {
|
|
cb(xhr.getResponseHeader(content.header));
|
|
});
|
|
};
|
|
|
|
window.addEventListener("message", function (event) {
|
|
var txid, command;
|
|
if (event && event.data) {
|
|
try {
|
|
//console.log(JSON.parse(event.data));
|
|
var msg = JSON.parse(event.data);
|
|
command = msg.command;
|
|
txid = msg.txid;
|
|
if (!txid) { return; }
|
|
COMMANDS[command](msg.content, function (response) {
|
|
// postMessage with same txid
|
|
postMessage({
|
|
txid: txid,
|
|
content: response,
|
|
});
|
|
});
|
|
} catch (err) {
|
|
postMessage({
|
|
txid: txid,
|
|
content: err,
|
|
});
|
|
console.error(err, command);
|
|
}
|
|
} else {
|
|
console.error(event);
|
|
}
|
|
});
|
|
});
|