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.domNode = function(container, module) {
17 var tag = container.tagName;
19 throw new Error('Elm.node must be given a DIV, not a ' + tag + '.');
20 } else if (container.hasChildNodes()) {
21 throw new Error('Elm.node must be given an empty DIV. No children allowed!');
23 return init(ElmRuntime.Display.COMPONENT, container, module);
26Elm.worker = function(module) {
27 return init(ElmRuntime.Display.NONE, {}, module);
30function init(display, container, module, moduleToReplace) {
31 // defining state needed for an instance of the Elm RTS
34 function notify(id, v) {
35 var timestep = Date.now();
37 for (var i = inputs.length; i--; ) {
38 // order is important here to avoid short-circuiting
39 changed = inputs[i].recv(timestep, id, v) || changed;
44 container.offsetX = 0;
45 container.offsetY = 0;
48 function addListener(relevantInputs, domNode, eventName, func) {
49 domNode.addEventListener(eventName, func);
51 relevantInputs: relevantInputs,
56 listeners.push(listener);
59 // create the actual RTS. Any impure modules will attach themselves to this
60 // object. This permits many Elm programs to be embedded per document.
66 addListener:addListener,
70 // Set up methods to communicate with Elm program from JS.
71 function send(name, value) {
72 if (typeof value === 'undefined') return function(v) { return send(name,v); };
73 var e = document.createEvent('Event');
74 e.initEvent(name + '_' + elm.id, true, true);
76 document.dispatchEvent(e);
78 function recv(name, handler) {
79 document.addEventListener(name + '_' + elm.id, handler);
82 recv('log', function(e) {console.log(e.value)});
83 recv('title', function(e) {document.title = e.value});
84 recv('redirect', function(e) {
85 if (e.value.length > 0) { window.location = e.value; }
88 function swap(newModule) {
89 removeListeners(listeners);
90 var div = document.createElement('div');
91 var newElm = init(display, div, newModule, elm);
93 // elm.send = newElm.send;
94 // elm.recv = newElm.recv;
95 // elm.swap = newElm.swap;
99 var Module = module(elm);
100 inputs = ElmRuntime.filterDeadInputs(inputs);
101 filterListeners(inputs, listeners);
102 if (display !== ElmRuntime.Display.NONE) {
103 var graphicsNode = initGraphics(elm, Module);
105 if (typeof moduleToReplace !== 'undefined') {
106 ElmRuntime.swap(moduleToReplace, elm);
108 // rerender scene if graphics are enabled.
109 if (typeof graphicsNode !== 'undefined') {
110 graphicsNode.value = A2( Elm.Graphics.Element(elm).spacer, 0, 0 );
111 graphicsNode.recv(0, true, 0);
115 return { send:send, recv:recv, swap:swap };
118function filterListeners(inputs, listeners) {
120 for (var i = listeners.length; i--; ) {
121 var listener = listeners[i];
122 for (var j = inputs.length; j--; ) {
123 if (listener.relevantInputs.indexOf(inputs[j].id) >= 0) {
127 listener.domNode.removeEventListener(listener.eventName, listener.func);
131function removeListeners(listeners) {
132 for (var i = listeners.length; i--; ) {
133 var listener = listeners[i];
134 listener.domNode.removeEventListener(listener.eventName, listener.func);
138function initGraphics(elm, Module) {
139 if (!('main' in Module))
140 throw new Error("'main' is missing! What do I display?!");
142 var signalGraph = Module.main;
144 // make sure the signal graph is actually a signal & extract the visual model
145 var Signal = Elm.Signal(elm);
146 if (!('recv' in signalGraph)) {
147 signalGraph = Signal.constant(signalGraph);
149 var currentScene = signalGraph.value;
151 // Add the currentScene to the DOM
152 var Render = ElmRuntime.use(ElmRuntime.Render.Element);
153 elm.node.appendChild(Render.render(currentScene));
154 if (elm.Native.Window) elm.Native.Window.resizeIfNeeded();
156 // set up updates so that the DOM is adjusted as necessary.
157 function domUpdate(newScene, currentScene) {
158 ElmRuntime.draw(function(_) {
159 Render.update(elm.node.firstChild, currentScene, newScene);
160 if (elm.Native.Window) elm.Native.Window.resizeIfNeeded();
164 return A3(Signal.foldp, F2(domUpdate), currentScene, 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