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
36 function notify(id, v) {
37 var timestep = Date.now();
38 var hasListener = false;
39 for (var i = inputs.length; i--; ) {
40 // must maintain the order of this stmt to avoid having the ||
41 // short-circuiting the necessary work of recv
42 hasListener = inputs[i].recv(timestep, id, v) || hasListener;
47 container.offsetX = 0;
48 container.offsetY = 0;
50 // create the actual RTS. Any impure modules will attach themselves to this
51 // object. This permits many Elm programs to be embedded per document.
52 var elm = { notify:notify,
59 // Set up methods to communicate with Elm program from JS.
60 function send(name, value) {
61 if (typeof value === 'undefined') return function(v) { return send(name,v); };
62 var e = document.createEvent('Event');
63 e.initEvent(name + '_' + elm.id, true, true);
65 document.dispatchEvent(e);
67 function recv(name, handler) {
68 document.addEventListener(name + '_' + elm.id, handler);
71 recv('log', function(e) {console.log(e.value)});
72 recv('title', function(e) {document.title = e.value});
73 recv('redirect', function(e) {
74 if (e.value.length > 0) { window.location = e.value; }
77 var Module = module(elm);
78 inputs = ElmRuntime.filterDeadInputs(inputs);
80 // If graphics are not enabled, escape early, skip over setting up DOM stuff.
81 if (display !== ElmRuntime.Display.NONE) { initGraphics(elm, Module); }
83 return { send:send, recv:recv,
84 __private__ : { inputs:inputs, container:container } };
87function initGraphics(elm, Module) {
88 if (!('main' in Module)) throw new Error("'main' is missing! What do I display?!");
89 var signalGraph = Module.main;
91 // make sure the signal graph is actually a signal & extract the visual model
92 if (!('recv' in signalGraph)) {
93 var Signal = Elm.Signal(elm);
94 signalGraph = Signal.constant(signalGraph);
96 var currentScene = signalGraph.value;
98 // Add the currentScene to the DOM
99 var Render = ElmRuntime.use(ElmRuntime.Render.Element);
100 container.appendChild(Render.render(currentScene));
101 if (elm.Native.Window) elm.Native.Window.resizeIfNeeded();
103 // set up updates so that the DOM is adjusted as necessary.
104 function domUpdate(newScene) {
105 ElmRuntime.draw(function(_) {
106 Render.update(container.firstChild, currentScene, newScene);
107 currentScene = newScene;
108 if (elm.Native.Window) elm.Native.Window.resizeIfNeeded();
112 A2(Signal.lift, domUpdate, signalGraph);
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