5Elm.fullscreen = function(module, ports) {
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, ports || {});
16Elm.embed = function(module, container, ports) {
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, ports || {});
26Elm.worker = function(module, ports) {
27 return init(ElmRuntime.Display.NONE, {}, module, ports || {});
30function init(display, container, module, ports, moduleToReplace) {
31 // defining state needed for an instance of the Elm RTS
35 * Elm's time traveling debugger lets you interrupt the smooth flow of time
36 * by pausing and continuing program execution. To ensure the user sees a
37 * program that moves smoothly through the pause/continue time gap,
38 * we need to adjsut the value of Date.now().
40 var timer = function() {
43 var now = function() {
44 return Date.now() - inducedDelay;
47 var addDelay = function(d) {
57 var updateInProgress = false;
58 function notify(id, v) {
59 if (updateInProgress) {
61 'The notify function has been called synchronously!\n' +
62 'This can lead to frames being dropped.\n' +
63 'Definitely report this to <https://github.com/elm-lang/Elm/issues>\n');
65 updateInProgress = true;
66 var timestep = timer.now();
67 for (var i = inputs.length; i--; ) {
68 inputs[i].recv(timestep, id, v);
70 updateInProgress = false;
72 function setTimeout(func, delay) {
73 window.setTimeout(func, delay);
77 function addListener(relevantInputs, domNode, eventName, func) {
78 domNode.addEventListener(eventName, func);
80 relevantInputs: relevantInputs,
85 listeners.push(listener);
89 for (var key in ports) {
92 // create the actual RTS. Any impure modules will attach themselves to this
93 // object. This permits many Elm programs to be embedded per document.
96 setTimeout:setTimeout,
100 addListener:addListener,
103 ports: { incoming:ports, outgoing:{}, uses:portUses }
106 function swap(newModule) {
107 removeListeners(listeners);
108 var div = document.createElement('div');
109 var newElm = init(display, div, newModule, ports, elm);
111 // elm.swap = newElm.swap;
116 removeListeners(listeners);
121 var reportAnyErrors = function() {};
123 Module = module.make(elm);
126 var directions = "<br/> Open the developer console for more details."
127 Module.main = Elm.Text.make(elm).leftAligned('<code>' + e.message + directions + '</code>');
128 reportAnyErrors = function() { throw e; }
130 inputs = ElmRuntime.filterDeadInputs(inputs);
131 filterListeners(inputs, listeners);
132 addReceivers(elm.ports.outgoing);
133 if (display !== ElmRuntime.Display.NONE) {
134 var graphicsNode = initGraphics(elm, Module);
136 if (typeof moduleToReplace !== 'undefined') {
137 ElmRuntime.swap(moduleToReplace, elm);
139 // rerender scene if graphics are enabled.
140 if (typeof graphicsNode !== 'undefined') {
141 graphicsNode.recv(0, true, 0);
148 ports:elm.ports.outgoing,
153function checkPorts(elm) {
154 var portUses = elm.ports.uses;
155 for (var key in portUses) {
156 var uses = portUses[key]
159 "Initialization Error: provided port '" + key +
160 "' to a module that does not take it as in input.\n" +
161 "Remove '" + key + "' from the module initialization code.");
162 } else if (uses > 1) {
164 "Initialization Error: port '" + key +
165 "' has been declared multiple times in the Elm code.\n" +
166 "Remove declarations until there is exactly one.");
171function filterListeners(inputs, listeners) {
173 for (var i = listeners.length; i--; ) {
174 var listener = listeners[i];
175 for (var j = inputs.length; j--; ) {
176 if (listener.relevantInputs.indexOf(inputs[j].id) >= 0) {
180 listener.domNode.removeEventListener(listener.eventName, listener.func);
184function removeListeners(listeners) {
185 for (var i = listeners.length; i--; ) {
186 var listener = listeners[i];
187 listener.domNode.removeEventListener(listener.eventName, listener.func);
191// add receivers for built-in ports if they are defined
192function addReceivers(ports) {
193 if ('log' in ports) {
194 ports.log.subscribe(function(v) { console.log(v) });
196 if ('stdout' in ports) {
197 var process = process || {};
198 var handler = process.stdout
199 ? function(v) { process.stdout.write(v); }
200 : function(v) { console.log(v); };
201 ports.stdout.subscribe(handler);
203 if ('stderr' in ports) {
204 var process = process || {};
205 var handler = process.stderr
206 ? function(v) { process.stderr.write(v); }
207 : function(v) { console.log('Error:' + v); };
208 ports.stderr.subscribe(handler);
210 if ('title' in ports) {
211 if (typeof ports.title === 'string') {
212 document.title = ports.title;
214 ports.title.subscribe(function(v) { document.title = v; });
217 if ('redirect' in ports) {
218 ports.redirect.subscribe(function(v) {
219 if (v.length > 0) window.location = v;
222 if ('favicon' in ports) {
223 if (typeof ports.favicon === 'string') {
224 changeFavicon(ports.favicon);
226 ports.favicon.subscribe(changeFavicon);
229 function changeFavicon(src) {
230 var link = document.createElement('link');
231 var oldLink = document.getElementById('elm-favicon');
232 link.id = 'elm-favicon';
233 link.rel = 'shortcut icon';
236 document.head.removeChild(oldLink);
238 document.head.appendChild(link);
242function initGraphics(elm, Module) {
243 if (!('main' in Module)) {
244 throw new Error("'main' is missing! What do I display?!");
247 var signalGraph = Module.main;
249 // make sure the signal graph is actually a signal & extract the visual model
250 var Signal = Elm.Signal.make(elm);
251 if (!('recv' in signalGraph)) {
252 signalGraph = Signal.constant(signalGraph);
254 var currentScene = signalGraph.value;
256 // Add the currentScene to the DOM
257 var Render = ElmRuntime.use(ElmRuntime.Render.Element);
258 elm.node.appendChild(Render.render(currentScene));
260 // set up updates so that the DOM is adjusted as necessary.
261 var savedScene = currentScene;
262 var previousDrawId = 0;
263 function domUpdate(newScene) {
264 previousDrawId = ElmRuntime.draw(previousDrawId, function(_) {
265 Render.update(elm.node.firstChild, savedScene, newScene);
266 if (elm.Native.Window) elm.Native.Window.values.resizeIfNeeded();
267 savedScene = newScene;
270 var renderer = A2(Signal.lift, domUpdate, signalGraph);
272 // must check for resize after 'renderer' is created so
273 // that changes show up.
274 if (elm.Native.Window) elm.Native.Window.values.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