spiegel-keyman/common/predictive-text/testing/post-blob-webworker/index.html
2018-11-20 11:12:05 -07:00

72 lines
2.5 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<!-- Set the viewport width to match phone and tablet device widths -->
<meta name="viewport" content="width=device-width,user-scalable=no" />
<!-- Allow KeymanWeb to be saved to the iPhone home screen -->
<meta name="apple-mobile-web-app-capable" content="yes" />
<!-- Enable IE9 Standards mode -->
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Blob URI test</title>
<!-- Your page CSS -->
<style type='text/css'>
body {font-family: Tahoma,helvetica;}
h3 {font-size: 1em;font-weight:normal;color: darkred; margin-bottom: 4px}
.test {font-size: 1.5em; width:80%; min-height:30px; border: 1px solid gray;}
#KeymanWebControl {width:50%;min-width:600px;}
</style>
<script>
if (window.Worker) {
var canaryWorker = new Worker('canaryWorker.js');
canaryWorker.onmessage = function(e) {
var message = e.data; // Number of times the WebWorker has been messaged.
console.log("Received message from the WebWorker: " + e.data);
var txtFeedback = document.getElementById("txtFeedback");
txtFeedback.value = message;
}
} else {
console.error("WebWorkers are not supported in this browser!");
}
</script>
</head>
<!-- Sample page HTML -->
<body>
<h2>LM Layer Testing - Sending a function to a WebWorker via a Blob URI test</h2>
<p>This page sends a function over to the Worker via a Blob URI, and
expects the function to reply back.
</p>
<input type='text' id='txtFeedback' value="Haven't heard back yet" readonly> <br>
<script>
var txtFeedback = document.getElementById("txtFeedback");
txtFeedback.value = "Have not heard back from worker";
function sendCode () {
function payload () {
postMessage('Hello, from the blobified code!');
}
// Create an immediately-invoked function expression... to immediately
// invoke the code!
let iife = ['(', payload.toString(), '())'];
let blob = new Blob(iife, { type: 'text/javascript' });
let uri = URL.createObjectURL(blob);
// Go!
canaryWorker.postMessage({ uri: uri });
}
</script>
<input type='button' id='btnInput' onclick='sendCode()' value='Send the source code!' />
<h3><a href="../index.html">Return to testing home page</a></h3>
</body>
</html>