on master help sign in
Set margin and padding to 0 explicitly.
913aaf0evancz
core-js/Element.js+2−26
@@ -3,39 +3,15 @@ var Element = function() {
3 var newElement = function(elementType) {
3 var newElement = function(elementType) {
4 var e = document.createElement(elementType);
4 var e = document.createElement(elementType);
5 e.id = Guid.guid();
5 e.id = Guid.guid();
6− //e.timesAdded = 0;
6+ e.style.padding = "0";
7+ e.style.margin = "0";
7 return e;
8 return e;
8 };
9 };
9 var addTo = function(container, elem) {
10 var addTo = function(container, elem) {
10 container.appendChild(clone(elem));
11 container.appendChild(clone(elem));
11− //elem.timesAdded += 1;
12 };
12 };
13 var clone = function(e) {
13 var clone = function(e) {
14 return e;
14 return e;
15− /*if (e.timesAdded === 0) { return e; }
16− if (e.tagName === "CANVAS") {
17− var newCanvas = e.cloneNode(true);
18− var ctx = newCanvas.getContext('2d');
19− ctx.drawImage(e, 0, 0);
20− return newCanvas;
21− } else if (e.tagName === "IMG") {
22− d = image([]);
23− d.src = e.src;
24− d.name = e.name;
25− if (e.style.width !== "") { d.style.width = d.width = e.style.width; }
26− if (e.style.height !== ""){d.style.height = d.height = e.style.height;}
27− return d;
28− } else if (e.hasOwnProperty('isElmLeaf')) {
29− return e.cloneNode(true);
30− } else {
31− d = e.cloneNode(false);
32− var kids = e.childNodes;
33− var len = kids.length;
34− for (var i = 0; i < len; i++) {
35− d.appendChild(clone(kids[i]));
36− }
37− return d;
38− }*/
39 };
15 };
40 var divify = function(e) {
16 var divify = function(e) {
41 var div = newElement('div');
17 var div = newElement('div');
core-js/Text.js+1−1
@@ -11,7 +11,7 @@ var Text = function() {
11 };
11 };
12
12
13 var addTag = function(tag) { return function(text) {
13 var addTag = function(tag) { return function(text) {
14− return '<' + tag + '>' + text + '</' + tag + '>';
14+ return '<' + tag + ' style="padding:0;margin:0">' + text + '</' + tag + '>';
15 };
15 };
16 };
16 };
17 var addStyle = function(style, value) { return function(text) {
17 var addStyle = function(style, value) { return function(text) {
core-js/cat-js.shdeleted−1
@@ -1 +0,0 @@
1−cat Guid.js foreign/JavaScript.js Value.js List.js Data.js collage/Color.js Element.js Text.js collage/Shape.js collage/Line.js runtime/Dispatcher.js runtime/Signal.js Prelude.js Everything.js > ../elm-mini.js ; ls
core-js/cat.batnew file+7
@@ -0,0 +1,7 @@
1+copy /B Guid.js+foreign\JavaScript.js+Value.js+List.js+Data.js+collage\Color.js+Element.js+Text.js+collage\Shape.js+collage\Line.js+runtime\Dispatcher.js+runtime\Signal.js+Prelude.js+Everything.js ..\elm-mini.js
2+
3+cd ..\elm
4+
5+copy /B ..\elm-mini.js elm-runtime-0.3.5.js
6+
7+cabal install
core-js/foreign/JavaScript.js+2−2
@@ -44,8 +44,8 @@ var Foreign = function() {
44 castFloatToJSNumber:castFloatToJSNumber,
44 castFloatToJSNumber:castFloatToJSNumber,
45 castJSNumberToInt:castJSNumberToInt,
45 castJSNumberToInt:castJSNumberToInt,
46 castIntToJSNumber:castIntToJSNumber,
46 castIntToJSNumber:castIntToJSNumber,
47− castJSElementToElement:castJSElementToElement,
47+ Experimental : {castJSElementToElement:castJSElementToElement,
48− castElementToJSElement:castElementToJSElement,
48+ castElementToJSElement:castElementToJSElement},
49 castJSArrayToList:castJSArrayToList,
49 castJSArrayToList:castJSArrayToList,
50 castListToJSArray:castListToJSArray,
50 castListToJSArray:castListToJSArray,
51 castJSStringToString:castJSStringToString,
51 castJSStringToString:castJSStringToString,
core-js/runtime/Dispatcher.js+29−12
@@ -1,8 +1,9 @@
1
1
2var Elm = function() {
2var Elm = function() {
3− var send = function(kids, timestep, changed) {
3+ var send = function(node, timestep, changed) {
4+ var kids = node.kids;
4 for (var i = kids.length; i--; ) {
5 for (var i = kids.length; i--; ) {
5− kids[i].recv(timestep, changed);
6+ kids[i].recv(timestep, changed, node.id);
6 }
7 }
7 };
8 };
8 var input = function(base) {
9 var input = function(base) {
@@ -12,7 +13,7 @@ var Elm = function() {
12 this.recv = function(timestep, eid, v) {
13 this.recv = function(timestep, eid, v) {
13 var changed = eid === this.id;
14 var changed = eid === this.id;
14 if (changed) { this.value = v; }
15 if (changed) { this.value = v; }
15− send(this.kids, timestep, changed);
16+ send(this, timestep, changed);
16 };
17 };
17 Dispatcher.inputs.push(this);
18 Dispatcher.inputs.push(this);
18 };
19 };
@@ -32,7 +33,7 @@ var Elm = function() {
32 };
33 };
33 this.recalc();
34 this.recalc();
34
35
35− this.recv = function(timestep, changed) {
36+ this.recv = function(timestep, changed, parentID) {
36 if (!this.inbox.hasOwnProperty(timestep)) {
37 if (!this.inbox.hasOwnProperty(timestep)) {
37 this.inbox[timestep] = { changed: false, count: 0 };
38 this.inbox[timestep] = { changed: false, count: 0 };
38 }
39 }
@@ -41,7 +42,7 @@ var Elm = function() {
41 if (changed) { box.changed = true; }
42 if (changed) { box.changed = true; }
42 if (box.count == args.length) {
43 if (box.count == args.length) {
43 if (box.changed) { this.recalc() }
44 if (box.changed) { this.recalc() }
44− send(this.kids, timestep, box.changed);
45+ send(this, timestep, box.changed);
45 delete this.inbox[timestep];
46 delete this.inbox[timestep];
46 }
47 }
47 };
48 };
@@ -53,9 +54,9 @@ var Elm = function() {
53 this.id = Guid.guid();
54 this.id = Guid.guid();
54 this.value = base;
55 this.value = base;
55 this.kids = [];
56 this.kids = [];
56− this.recv = function(timestep, changed) {
57+ this.recv = function(timestep, changed, parentID) {
57 if (changed) { this.value = func(input.value)(this.value); }
58 if (changed) { this.value = func(input.value)(this.value); }
58− send(this.kids, timestep, changed);
59+ send(this, timestep, changed);
59 };
60 };
60 input.kids.push(this);
61 input.kids.push(this);
61 };
62 };
@@ -64,10 +65,10 @@ var Elm = function() {
64 this.id = Guid.guid();
65 this.id = Guid.guid();
65 this.value = pred(input.value) ? base : input.value;
66 this.value = pred(input.value) ? base : input.value;
66 this.kids = [];
67 this.kids = [];
67− this.recv = function(timestep, changed) {
68+ this.recv = function(timestep, changed, parentID) {
68 var chng = changed && !pred(input.value);
69 var chng = changed && !pred(input.value);
69 if (chng) { this.value = input.value; }
70 if (chng) { this.value = input.value; }
70− send(this.kids, timestep, chng);
71+ send(this, timestep, chng);
71 };
72 };
72 input.kids.push(this);
73 input.kids.push(this);
73 };
74 };
@@ -75,10 +76,10 @@ var Elm = function() {
75 this.id = Guid.guid();
76 this.id = Guid.guid();
76 this.value = input.value;
77 this.value = input.value;
77 this.kids = [];
78 this.kids = [];
78− this.recv = function(timestep, changed) {
79+ this.recv = function(timestep, changed, parentID) {
79 var chng = changed && !eq(this.value,input.value);
80 var chng = changed && !eq(this.value,input.value);
80 if (chng) { this.value = input.value; }
81 if (chng) { this.value = input.value; }
81− send(this.kids, timestep, chng);
82+ send(this, timestep, chng);
82 };
83 };
83 input.kids.push(this);
84 input.kids.push(this);
84 };
85 };
@@ -89,6 +90,21 @@ var Elm = function() {
89 return new lift(function(p){return p[1];},[dropped]); }; };
90 return new lift(function(p){return p[1];},[dropped]); }; };
90 };
91 };
91
92
93+ var sampleOn = function(s1,s2) {
94+ this.id = Guid.guid();
95+ this.value = s2.value;
96+ this.kids = [];
97+ this.inbox = {};
98+
99+ this.recv = function(timestep, changed, parentID) {
100+ var chng = changed && parentID === s1.id;
101+ if (chng) { this.value = s2.value; }
102+ send(this, timestep, chng);
103+ };
104+ s1.kids.push(this);
105+ s2.kids.push(this);
106+ };
107+
92 return {Input: function(x) {return new input(x);},
108 return {Input: function(x) {return new input(x);},
93 Lift: function(f,xs){return new lift(f,xs);},
109 Lift: function(f,xs){return new lift(f,xs);},
94 Fold: function(f,b,x){return new fold(f,b,x);},
110 Fold: function(f,b,x){return new fold(f,b,x);},
@@ -98,7 +114,8 @@ var Elm = function() {
98 return new dropIf(pred,base,sig); }; }; },
114 return new dropIf(pred,base,sig); }; }; },
99 keepWhen : function(s) { return dropWhen(new lift(function(b){return !b;},[s])); },
115 keepWhen : function(s) { return dropWhen(new lift(function(b){return !b;},[s])); },
100 dropWhen : dropWhen,
116 dropWhen : dropWhen,
101− dropRepeats : function(s) { return new dropRepeats(s);}
117+ dropRepeats : function(s) { return new dropRepeats(s);},
118+ sampleOn : sampleOn
102 };
119 };
103}();
120}();
104
121
core-js/runtime/Signal.js+5−2
@@ -24,6 +24,7 @@ var Signal = function() {
24 var position = Elm.Input(Value.Tuple(0,0));
24 var position = Elm.Input(Value.Tuple(0,0));
25 var isDown = Elm.Input(false);
25 var isDown = Elm.Input(false);
26 var isClicked = Elm.Input(false);
26 var isClicked = Elm.Input(false);
27+ var clicks = Elm.Input(Value.Tuple());
27
28
28 function getXY(e) {
29 function getXY(e) {
29 var posx = 0;
30 var posx = 0;
@@ -43,6 +44,7 @@ var Signal = function() {
43
44
44 addListener(document, 'click', function(e) {
45 addListener(document, 'click', function(e) {
45 Dispatcher.notify(isClicked.id, true);
46 Dispatcher.notify(isClicked.id, true);
47+ Dispatcher.notify(clicks.id, Value.Tuple());
46 Dispatcher.notify(isClicked.id, false);
48 Dispatcher.notify(isClicked.id, false);
47 });
49 });
48 addListener(document, 'mousedown', function(e) {
50 addListener(document, 'mousedown', function(e) {
@@ -64,7 +66,8 @@ var Signal = function() {
64 y: Elm.Lift(function(p){return p[2];},[position]),
66 y: Elm.Lift(function(p){return p[2];},[position]),
65 isClicked: isClicked,
67 isClicked: isClicked,
66 isDown: isDown,
68 isDown: isDown,
69+ clicks: clicks
67− clickedOn: clickedOn
70+ //clickedOn: clickedOn
68 };
71 };
69 }();
72 }();
70
73
@@ -303,7 +306,7 @@ var Signal = function() {
303 return Elm.Lift(f, [e1,e2,e3,e4]); }; }; }; }; },
306 return Elm.Lift(f, [e1,e2,e3,e4]); }; }; }; }; },
304 foldp : function(f) { return function(b) { return function(e) {
307 foldp : function(f) { return function(b) { return function(e) {
305 return Elm.Fold(f,b,e); }; }; },
308 return Elm.Fold(f,b,e); }; }; },
306− count : function(sig){return Elm.fold(function(c){return c+1},0,sig)},
309+ count : function(sig){return Elm.Fold(function(_){return function(c){return c+1;};},0,sig)},
307 keepIf : Elm.keepIf,
310 keepIf : Elm.keepIf,
308 dropIf : Elm.dropIf,
311 dropIf : Elm.dropIf,
309 keepWhen : Elm.keepWhen,
312 keepWhen : Elm.keepWhen,