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;
100 var reportAnyErrors = function() {};
102 Module = module(elm);
104 var directions = "<br/> Open the developer console for more details."
105 Module.main = Elm.Text(elm).text('<code>' + e.message + directions + '</code>');
106 reportAnyErrors = function() { throw e; }
108 inputs = ElmRuntime.filterDeadInputs(inputs);
109 filterListeners(inputs, listeners);
110 if (display !== ElmRuntime.Display.NONE) {
111 var graphicsNode = initGraphics(elm, Module);
113 if (typeof moduleToReplace !== 'undefined') {
114 ElmRuntime.swap(moduleToReplace, elm);
116 // rerender scene if graphics are enabled.
117 if (typeof graphicsNode !== 'undefined') {
118 graphicsNode.value = A2( Elm.Graphics.Element(elm).spacer, 0, 0 );
119 graphicsNode.recv(0, true, 0);
124 return { send:send, recv:recv, swap:swap };
127function filterListeners(inputs, listeners) {
129 for (var i = listeners.length; i--; ) {
130 var listener = listeners[i];
131 for (var j = inputs.length; j--; ) {
132 if (listener.relevantInputs.indexOf(inputs[j].id) >= 0) {
136 listener.domNode.removeEventListener(listener.eventName, listener.func);
140function removeListeners(listeners) {
141 for (var i = listeners.length; i--; ) {
142 var listener = listeners[i];
143 listener.domNode.removeEventListener(listener.eventName, listener.func);
147function initGraphics(elm, Module) {
148 if (!('main' in Module))
149 throw new Error("'main' is missing! What do I display?!");
151 var signalGraph = Module.main;
153 // make sure the signal graph is actually a signal & extract the visual model
154 var Signal = Elm.Signal(elm);
155 if (!('recv' in signalGraph)) {
156 signalGraph = Signal.constant(signalGraph);
158 var currentScene = signalGraph.value;
160 // Add the currentScene to the DOM
161 var Render = ElmRuntime.use(ElmRuntime.Render.Element);
162 elm.node.appendChild(Render.render(currentScene));
164 // set up updates so that the DOM is adjusted as necessary.
165 function domUpdate(newScene, currentScene) {
166 ElmRuntime.draw(function(_) {
167 Render.update(elm.node.firstChild, currentScene, newScene);
168 if (elm.Native.Window) elm.Native.Window.resizeIfNeeded();
172 var renderer = A3(Signal.foldp, F2(domUpdate), currentScene, signalGraph);
174 // must check for resize after 'renderer' is created so
175 // that changes show up.
176 if (elm.Native.Window) elm.Native.Window.resizeIfNeeded();
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