@@ -1,194 +0,0 @@
2−Elm.Native.Misc = function(elm) {
5− elm.node.addEventListener('elm_log', function(e) { console.log(e.value); });
6− elm.node.addEventListener('elm_title', function(e) {document.title = e.value;});
7− elm.node.addEventListener('elm_redirect', function(e) {
8− if (e.value.length > 0) { window.location = e.value; }
10− elm.node.addEventListener('elm_viewport', function(e) {
11− var node = document.getElementById('elm_viewport');
13− node = document.createElement('meta');
14− node.id = 'elm_viewport';
15− node.name = 'viewport';
16− document.head.appendChild(node);
18− node.content = e.value;
19− Dispatcher.notify(elm.Window.dimensions.id,
20− Tuple2(window.innerWidth, window.innerHeight));
23− var NativeList = Elm.Native.List(elm);
24− var List = Elm.List(elm);
25− var Maybe = Elm.Maybe(elm);
26− var JS = Elm.JavaScript(elm);
27− var Dict = Elm.Dict(elm);
28− var Json = Elm.Json(elm);
30− function getTextSize(w,h,txt) {
31− var t = document.createElement('div');
33− t.style.textAlign = 'left';
34− if (w > 0) { t.style.width = w + "px"; }
36− t.style.visibility = "hidden";
37− t.style.styleFloat = "left";
38− t.style.cssFloat = "left";
40− document.body.appendChild(t);
41− var cStyle = window.getComputedStyle(t,null);
42− var realW = cStyle.getPropertyValue("width").slice(0,-2) - 0;
43− var realH = cStyle.getPropertyValue("height").slice(0,-2) - 0;
44− document.body.removeChild(t);
46− return [Math.ceil(realW),Math.ceil(Math.max(h,realH))];
49− function getSize(e) {
50− var t = e.cloneNode(true);
52− t.style.visibility = "hidden";
53− t.style.styleFloat = "left";
54− t.style.cssFloat = "left";
56− document.body.appendChild(t);
57− var w = t.offsetWidth;
58− var h = t.offsetHeight;
59− document.body.removeChild(t);
64− function getExcess(e) {
65− var t = e.cloneNode(true);
67− t.style.visibility = "hidden";
68− t.style.styleFloat = "left";
69− t.style.cssFloat = "left";
71− document.body.appendChild(t);
72− var ow = t.offsetWidth;
73− var oh = t.offsetHeight;
74− var cStyle = window.getComputedStyle(t,null);
75− var w = cStyle.getPropertyValue("width").slice(0,-2) - 0;
76− var h = cStyle.getPropertyValue("height").slice(0,-2) - 0;
77− document.body.removeChild(t);
83− function groupForms(forms) {
84− forms = JS.fromList(forms);
87− for (var i = forms.length; i--; ) {
91− if (arr.length > 0) {
101− if (arr.length > 0) groups.push(arr);
105− var toString = function(v) {
106− if (typeof v === "function") {
107− return "<function>";
108− } else if (typeof v === "boolean") {
109− return v ? "True" : "False";
110− } else if (typeof v === "number") {
112− } else if (typeof v === "string" && v.length < 2) {
114− } else if (typeof v === "object" && ('_' in v)) {
116− for (var k in v._) {
117− console.log(k,v._[k]);
118− for (var i = v._[k].length; i--; ) {
119− output.push(k + " = " + toString(v._[k][i]));
123− if (k === '_') continue;
124− output.push(k + " = " + toString(v[k]));
126− if (output.length === 0) return "{}";
127− return "{ " + output.join(", ") + " }";
128− } else if ('ctor' in v) {
129− if (v.ctor.substring(0,5) === "Tuple") {
130− var output = new Array(v.length-1);
131− for (var i = v.length; --i; ) { output[i-1] = toString(v[i]); }
132− return "(" + output.join(",") + ")";
133− } else if (v.ctor === "Cons") {
134− var isStr = typeof v._0 === "string";
135− var start = isStr ? '"' : "[";
136− var end = isStr ? '"' : "]";
137− var sep = isStr ? "" : ",";
138− var f = isStr ? function(x){return x} : toString;
139− var output = start + f(v._0);
141− while (v.ctor === "Cons") {
142− output += sep + f(v._0);
145− return output + end;
146− } else if (v.ctor === "Nil") {
148− } else if (v.ctor === "JSON") {
149− return "(JSON.fromList " + toString(Json.toList(v)) + ")";
150− } else if (v.ctor === "RBNode" || v.ctor === "RBEmpty") {
151− function cons(k){ return function(v) { return function(acc) { return NativeList.Cons(Tuple2(k,v),acc); }; }; }
152− var list = Dict.foldr(cons)(NativeList.Nil)(v);
154− if (list.ctor === "Cons" && list._0._1.ctor === "Tuple0") {
156− list = A2(List.map, function(x){return x._0}, list);
158− return "(" + name + ".fromList " + toString(list) + ")";
161− for (var i = v.length; --i; ) { output = ' ' + toString(v[i]) + output; }
162− output = v.ctor + output;
163− return (v.length > 1) ? "(" + output + ")" : output;
168− var show = function(v) { return NativeList.fromArray(toString(v)); };
170− var addListener = function() {
171− if(document.addEventListener) {
172− return function(element, event, handler) {
173− element.addEventListener(event, handler, false);
176− return function(element, event, handler) {
177− element.attachEvent('on' + event, handler);
182− return elm.Native.Misc = {
188− getTextSize : getTextSize,
190− getExcess : getExcess,
191− groupForms : groupForms,
192− addListener : addListener