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.embed = function(module, container) {
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 var updateInProgress = false;
35 function notify(id, v) {
36 if (updateInProgress) {
38 'The notify function has been called synchronously!\n' +
39 'This can lead to frames being dropped.\n' +
40 'Definitely report this to <https://github.com/evancz/Elm/issues>\n');
42 updateInProgress = true;
43 var timestep = Date.now();
44 for (var i = inputs.length; i--; ) {
45 inputs[i].recv(timestep, id, v);
47 updateInProgress = false;
51 function addListener(relevantInputs, domNode, eventName, func) {
52 domNode.addEventListener(eventName, func);
54 relevantInputs: relevantInputs,
59 listeners.push(listener);
62 // create the actual RTS. Any impure modules will attach themselves to this
63 // object. This permits many Elm programs to be embedded per document.
69 addListener:addListener,
73 // Set up methods to communicate with Elm program from JS.
74 function send(name, value) {
75 if (typeof value === 'undefined') return function(v) { return send(name,v); };
76 var e = document.createEvent('Event');
77 e.initEvent(name + '_' + elm.id, true, true);
79 document.dispatchEvent(e);
81 function recv(name, handler) {
82 document.addEventListener(name + '_' + elm.id, handler);
85 recv('log', function(e) {console.log(e.value)});
86 recv('title', function(e) {document.title = e.value});
87 recv('redirect', function(e) {
88 if (e.value.length > 0) { window.location = e.value; }
91 function swap(newModule) {
92 removeListeners(listeners);
93 var div = document.createElement('div');
94 var newElm = init(display, div, newModule, elm);
96 // elm.send = newElm.send;
97 // elm.recv = newElm.recv;
98 // elm.swap = newElm.swap;
103 var reportAnyErrors = function() {};
105 Module = module.make(elm);
107 var directions = "<br/> Open the developer console for more details."
108 Module.main = Elm.Text.make(elm).text('<code>' + e.message + directions + '</code>');
109 reportAnyErrors = function() { throw e; }
111 inputs = ElmRuntime.filterDeadInputs(inputs);
112 filterListeners(inputs, listeners);
113 if (display !== ElmRuntime.Display.NONE) {
114 var graphicsNode = initGraphics(elm, Module);
116 if (typeof moduleToReplace !== 'undefined') {
117 ElmRuntime.swap(moduleToReplace, elm);
119 // rerender scene if graphics are enabled.
120 if (typeof graphicsNode !== 'undefined') {
121 graphicsNode.recv(0, true, 0);
126 return { send:send, recv:recv, swap:swap };
129function filterListeners(inputs, listeners) {
131 for (var i = listeners.length; i--; ) {
132 var listener = listeners[i];
133 for (var j = inputs.length; j--; ) {
134 if (listener.relevantInputs.indexOf(inputs[j].id) >= 0) {
138 listener.domNode.removeEventListener(listener.eventName, listener.func);
142function removeListeners(listeners) {
143 for (var i = listeners.length; i--; ) {
144 var listener = listeners[i];
145 listener.domNode.removeEventListener(listener.eventName, listener.func);
149function initGraphics(elm, Module) {
150 if (!('main' in Module))
151 throw new Error("'main' is missing! What do I display?!");
153 var signalGraph = Module.main;
155 // make sure the signal graph is actually a signal & extract the visual model
156 var Signal = Elm.Signal.make(elm);
157 if (!('recv' in signalGraph)) {
158 signalGraph = Signal.constant(signalGraph);
160 var currentScene = signalGraph.value;
162 // Add the currentScene to the DOM
163 var Render = ElmRuntime.use(ElmRuntime.Render.Element);
164 elm.node.appendChild(Render.render(currentScene));
166 // set up updates so that the DOM is adjusted as necessary.
167 function domUpdate(newScene, currentScene) {
168 ElmRuntime.draw(function(_) {
169 Render.update(elm.node.firstChild, currentScene, newScene);
170 if (elm.Native.Window) elm.Native.Window.values.resizeIfNeeded();
174 var renderer = A3(Signal.foldp, F2(domUpdate), currentScene, signalGraph);
176 // must check for resize after 'renderer' is created so
177 // that changes show up.
178 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