2Elm.Native.Utils.make = function(elm) {
4 elm.Native = elm.Native || {};
5 elm.Native.Utils = elm.Native.Utils || {};
6 if (elm.Native.Utils.values) return elm.Native.Utils.values;
9 var stack = [{'x': l, 'y': r}]
10 while (stack.length > 0) {
11 var front = stack.pop();
14 if (x === y) continue;
15 if (typeof x === "object") {
21 stack.push({ 'x': x[i], 'y': y[i] });
28 stack.push({'x': x.ctor, 'y': y.ctor});
30 if (c !== Object.keys(y).length) {
33 } else if (typeof x === 'function') {
34 throw new Error('Equality error: general function equality is ' +
35 'undecidable, and therefore, unsupported');
43 // code in Generate/JavaScript.hs depends on the particular
44 // integer values assigned to LT, EQ, and GT
45 var LT = -1, EQ = 0, GT = 1, ord = ['LT','EQ','GT'];
46 function compare(x,y) { return { ctor: ord[cmp(x,y)+1] } }
49 if (typeof x !== 'object'){
50 return x === y ? EQ : x < y ? LT : GT;
55 return a === b ? EQ : a < b ? LT : GT;
57 else if (x.ctor === "::" || x.ctor === "[]") {
59 if (x.ctor === "[]" && y.ctor === "[]") return EQ;
60 if (x.ctor !== y.ctor) return x.ctor === '[]' ? LT : GT;
61 ord = cmp(x._0, y._0);
62 if (ord !== EQ) return ord;
67 else if (x.ctor.slice(0,6) === '_Tuple') {
68 var n = x.ctor.slice(6) - 0;
69 var err = 'cannot compare tuples with more than 6 elements.';
70 if (n === 0) return EQ;
71 if (n >= 1) { ord = cmp(x._0, y._0); if (ord !== EQ) return ord;
72 if (n >= 2) { ord = cmp(x._1, y._1); if (ord !== EQ) return ord;
73 if (n >= 3) { ord = cmp(x._2, y._2); if (ord !== EQ) return ord;
74 if (n >= 4) { ord = cmp(x._3, y._3); if (ord !== EQ) return ord;
75 if (n >= 5) { ord = cmp(x._4, y._4); if (ord !== EQ) return ord;
76 if (n >= 6) { ord = cmp(x._5, y._5); if (ord !== EQ) return ord;
77 if (n >= 7) throw new Error('Comparison error: ' + err); } } } } } }
81 throw new Error('Comparison error: comparison is only defined on ints, ' +
82 'floats, times, chars, strings, lists of comparable values, ' +
83 'and tuples of comparable values.');
88 var Tuple0 = { ctor: "_Tuple0" };
89 function Tuple2(x,y) { return { ctor:"_Tuple2", _0:x, _1:y } }
92 var x = new String(c);
98 var t = new String(str);
103 function makeText(text) {
117 if (href) text = '<a href="' + href + '">' + text + '</a>';
118 if (style) text = '<span style="' + style + '">' + text + '</span>';
124 function guid(_) { return count++ }
126 function copy(oldRecord) {
128 for (var key in oldRecord) {
129 var value = key === '_'
133 newRecord[key] = value;
138 function remove(key, oldRecord) {
139 var record = copy(oldRecord);
140 if (key in record._) {
141 record[key] = record._[key][0];
142 record._[key] = record._[key].slice(1);
143 if (record._[key].length === 0) {
144 delete record._[key];
152 function replace(keyValuePairs, oldRecord) {
153 var record = copy(oldRecord);
154 for (var i = keyValuePairs.length; i--; ) {
155 var pair = keyValuePairs[i];
156 record[pair[0]] = pair[1];
161 function insert(key, value, oldRecord) {
162 var newRecord = copy(oldRecord);
163 if (key in newRecord) {
164 var values = newRecord._[key];
165 var copiedValues = values ? values.slice(0) : [];
166 newRecord._[key] = [newRecord[key]].concat(copiedValues);
168 newRecord[key] = value;
172 function max(a,b) { return a > b ? a : b }
173 function min(a,b) { return a < b ? a : b }
177 throw new Error("Cannot perform mod 0. Division by zero error.");
180 var m = a === 0 ? 0 : (b > 0 ? (a >= 0 ? r : r+b) : -mod(-a,-b));
182 return m === b ? 0 : m;
185 function htmlHeight(width, rawHtml) {
187 var html = rawHtml.html;
188 var t = document.createElement('div');
190 if (width > 0) { t.style.width = width + "px"; }
191 t.style.visibility = "hidden";
192 t.style.styleFloat = "left";
193 t.style.cssFloat = "left";
195 document.body.appendChild(t);
197 // insert interpolated values
198 var args = rawHtml.args;
199 var guid = rawHtml.guid;
200 for (var i = args.length; i--; ) {
202 var span = document.getElementById('md-' + guid + '-' + i);
204 span.style.width = arg.props.width + 'px';
205 span.style.height = arg.props.height + 'px';
207 span.innerHTML = arg;
212 var style = window.getComputedStyle(t, null);
213 var w = Math.ceil(style.getPropertyValue("width").slice(0,-2) - 0);
214 var h = Math.ceil(style.getPropertyValue("height").slice(0,-2) - 0);
215 document.body.removeChild(t);
222 if (e.pageX || e.pageY) {
225 } else if (e.clientX || e.clientY) {
226 posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
227 posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
230 if (elm.display === ElmRuntime.Display.COMPONENT) {
231 var rect = elm.node.getBoundingClientRect();
232 var relx = rect.left + document.body.scrollLeft + document.documentElement.scrollLeft;
233 var rely = rect.top + document.body.scrollTop + document.documentElement.scrollTop;
234 // TODO: figure out if there is a way to avoid rounding here
235 posx = posx - Math.round(relx) - elm.node.clientLeft;
236 posy = posy - Math.round(rely) - elm.node.clientTop;
238 return Tuple2(posx, posy);
241 function isJSArray(a) {
242 return a instanceof Array;
245 return elm.Native.Utils.values = {
262 htmlHeight: F2(htmlHeight),
264 isJSArray: isJSArray,
265 toFloat: function(x) { return +x; }
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