|
| 1 | +<!DOCTYPE HTML> |
| 2 | +<html> |
| 3 | +<head> |
| 4 | + <title>Try PureScript!</title> |
| 5 | + <meta content="text/html;charset=utf-8" http-equiv="Content-Type"> |
| 6 | + <meta content="utf-8" http-equiv="encoding"> |
| 7 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 8 | + <link rel="stylesheet" href="css/style.css"> |
| 9 | +</head> |
| 10 | +<body> |
| 11 | +<main id="main"></main> |
| 12 | +<script type="text/javascript"> |
| 13 | + (function() { |
| 14 | + function evalPureScript(sources) { |
| 15 | + var modules = {}; |
| 16 | + return function load(name) { |
| 17 | + if (modules[name]) { |
| 18 | + return modules[name].exports; |
| 19 | + } |
| 20 | + function require(path) { |
| 21 | + if (path === "./foreign.js") { |
| 22 | + return load(name + "$Foreign"); |
| 23 | + } |
| 24 | + if (path.indexOf("../") === 0) { |
| 25 | + return load(path.slice(3).replace(/\/index\.js$/, "")); |
| 26 | + } |
| 27 | + return load(path); |
| 28 | + } |
| 29 | + var module = modules[name] = { exports: {} }; |
| 30 | + new Function("module", "exports", "require", sources[name])(module, module.exports, require); |
| 31 | + return module.exports; |
| 32 | + }; |
| 33 | + } |
| 34 | + |
| 35 | + function loadScripts(scripts, cb) { |
| 36 | + if (scripts.length === 0) { |
| 37 | + return cb(); |
| 38 | + } |
| 39 | + var script = document.createElement("script"); |
| 40 | + script.type = "text/javascript"; |
| 41 | + script.src = scripts[0]; |
| 42 | + script.addEventListener("load", function() { |
| 43 | + loadScripts(scripts.slice(1), cb); |
| 44 | + }, { once: true }); |
| 45 | + document.head.appendChild(script); |
| 46 | + } |
| 47 | + |
| 48 | + document.addEventListener("DOMContentLoaded", function() { |
| 49 | + window.addEventListener("message", function(event) { |
| 50 | + loadScripts(event.data.scripts, function() { |
| 51 | + var file = evalPureScript(event.data.sources)("<file>"); |
| 52 | + if (file.main && typeof file.main === "function") { |
| 53 | + file.main(); |
| 54 | + } |
| 55 | + }); |
| 56 | + event.source.postMessage("trypurescript", "*"); |
| 57 | + }, { once: true }); |
| 58 | + }, { once: true }); |
| 59 | + })(); |
| 60 | +</script> |
| 61 | +</body> |
| 62 | +</html> |
0 commit comments