5Elm.fullscreen = function(module) {
6 var style = document.createElement('style');
7 style.type = 'text/css';
8 style.innerHTML = "html,head,body { padding:0; margin:0; }" +
9 "body { font-family: calibri, helvetica, arial, sans-serif; }";
10 document.head.appendChild(style);
11 var container = document.createElement('div');
12 document.body.appendChild(container);
13 return init(ElmRuntime.Display.FULLSCREEN, container, module);
16Elm.byId = function(id, module) {
17 var container = document.getElementById(id);
18 var tag = container.tagName;
20 throw new Error('Elm.byId must be given a div, not a ' + tag + '.');
22 while (container.hasChildNodes()) {
23 container.removeChild(container.lastChild);
25 return init(ElmRuntime.Display.COMPONENT, container, module);
28Elm.worker = function(module) {
29 return init(ElmRuntime.Display.NONE, {}, module);
32function init(display, container, module) {
33 // defining state needed for an instance of the Elm RTS
34 var signalGraph = null;
36 var visualModel = null;
38 function notify(id, v) {
39 var timestep = Date.now();
40 var hasListener = false;
41 for (var i = inputs.length; i--; ) {
42 // must maintain the order of this stmt to avoid having the ||
43 // short-circuiting the necessary work of recv
44 hasListener = inputs[i].recv(timestep, id, v) || hasListener;
49 container.offsetX = 0;
50 container.offsetY = 0;
52 // create the actual RTS. Any impure modules will attach themselves to this
53 // object. This permits many Elm programs to be embedded per document.
54 var elm = { notify:notify,
61 // Set up methods to communicate with Elm program from JS.
62 function send(name, value) {
63 if (typeof value === 'undefined') return function(v) { return send(name,v); };
64 var e = document.createEvent('Event');
65 e.initEvent(name + '_' + elm.id, true, true);
67 document.dispatchEvent(e);
69 function recv(name, handler) {
70 document.addEventListener(name + '_' + elm.id, handler);
73 recv('log', function(e) {console.log(e.value)});
74 recv('title', function(e) {document.title = e.value});
75 recv('redirect', function(e) {
76 if (e.value.length > 0) { window.location = e.value; }
79 // If graphics are not enabled, escape early, skip over setting up DOM stuff.
80 if (display === ElmRuntime.Display.NONE) {
82 return { send : send, recv : recv };
85 var Render = ElmRuntime.use(ElmRuntime.Render.Element);
87 // evaluate the given module and extract its 'main' value.
88 signalGraph = module(elm).main;
90 // make sure the signal graph is actually a signal, extract the visual model,
91 // and filter out any unused inputs.
92 var Signal = Elm.Signal(elm);
93 if (!('recv' in signalGraph)) signalGraph = Signal.constant(signalGraph);
94 visualModel = signalGraph.value;
95 inputs = ElmRuntime.filterDeadInputs(inputs);
97 // Add the visualModel to the DOM
98 container.appendChild(Render.render(visualModel));
99 if (elm.Native.Window) elm.Native.Window.resizeIfNeeded();
101 // set up updates so that the DOM is adjusted as necessary.
102 var update = Render.update;
103 function domUpdate(value) {
104 ElmRuntime.draw(function(_) {
105 update(container.firstChild, visualModel, value);
107 if (elm.Native.Window) elm.Native.Window.resizeIfNeeded();
112 signalGraph = A2(Signal.lift, domUpdate, signalGraph);
114 return { send : send, recv : recv, node : container };
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list