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.recv(0, true, 0);
123 return { send:send, recv:recv, swap:swap };
126function filterListeners(inputs, listeners) {
128 for (var i = listeners.length; i--; ) {
129 var listener = listeners[i];
130 for (var j = inputs.length; j--; ) {
131 if (listener.relevantInputs.indexOf(inputs[j].id) >= 0) {
135 listener.domNode.removeEventListener(listener.eventName, listener.func);
139function removeListeners(listeners) {
140 for (var i = listeners.length; i--; ) {
141 var listener = listeners[i];
142 listener.domNode.removeEventListener(listener.eventName, listener.func);
146function initGraphics(elm, Module) {
147 if (!('main' in Module))
148 throw new Error("'main' is missing! What do I display?!");
150 var signalGraph = Module.main;
152 // make sure the signal graph is actually a signal & extract the visual model
153 var Signal = Elm.Signal(elm);
154 if (!('recv' in signalGraph)) {
155 signalGraph = Signal.constant(signalGraph);
157 var currentScene = signalGraph.value;
159 // Add the currentScene to the DOM
160 var Render = ElmRuntime.use(ElmRuntime.Render.Element);
161 elm.node.appendChild(Render.render(currentScene));
163 // set up updates so that the DOM is adjusted as necessary.
164 function domUpdate(newScene, currentScene) {
165 ElmRuntime.draw(function(_) {
166 Render.update(elm.node.firstChild, currentScene, newScene);
167 if (elm.Native.Window) elm.Native.Window.resizeIfNeeded();
171 var renderer = A3(Signal.foldp, F2(domUpdate), currentScene, signalGraph);
173 // must check for resize after 'renderer' is created so
174 // that changes show up.
175 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