forked from bendr/bender
/
run.html
62 lines (59 loc) · 1.63 KB
/
run.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!DOCTYPE html>
<html lang="en">
<head>
<title>⚐ Bender Runtime</title>
<meta charset="UTF-8">
<style>
body {
font-family: Univers, "Helvetica Neue", Helvetica, sans-serif;
}
code {
font-family: Inconsolata, Menlo, monospace;
}
.bender--runtime-message {
color: #888;
font-style: italic;
}
.bender--runtime-error {
color: #ff4040;
}
</style>
<script src="flexo.js"></script>
<script src="bender.js"></script>
</head>
<body>
<script>
"use strict";
bender.instance.rendering = function () {
if (this.reference && this.reference.id && this.views.$root) {
this.views.$root.classList.add(this.reference.id);
}
};
var context = bender.create_context();
var args = flexo.get_args();
if (args.href) {
var component = context.create_component(args);
var instance = bender.create_instance({ reference: component });
flexo.listen(instance, "@error", function (e) {
document.body.appendChild(flexo.$("p.bender--runtime-error",
"Error loading ", flexo.$code(e.uri), ": {0}.".fmt(e.message)));
});
flexo.listen(instance, "@rendering", function (e) {
console.log("[run] rendering", e.source);
});
flexo.listen(instance, "@rendered", function (e) {
console.log("[run] rendered", e.source);
if (e.instance) {
console.log("[run] updating instance:", e.instance);
instance = e.instance;
}
});
context.add_instance(instance, document.body);
} else {
document.body.appendChild(flexo.$("p.bender--runtime-message",
"Nothing to run. Please specify a Bender component to load with the ",
flexo.$code("href"), " URL parameter."));
}
</script>
</body>
</html>