on master help sign in
Set margin and padding to 0 explicitly.

Move JSElementToElement (and vice-versa) to Foreign.JavaScripct.Experimental. Add clicks and sampleOn functions.

commit913aaf050930de219025347c5c2803afe08c6f85 authorevancz <info@elm-lang.org> dateFri 29 Jun 2012, 10:21 (14 years ago) parentabb3851
7 files changed+46−44
core-js/Element.js+2−26 core-js/Text.js+1−1 core-js/cat-js.sh−1 core-js/cat.bat+7 core-js/foreign/JavaScript.js+2−2 core-js/runtime/Dispatcher.js+29−12 core-js/runtime/Signal.js+5−2
core-js/Element.js+2−26
@@ -3,39 +3,15 @@ var Element = function() {
33 var newElement = function(elementType) {
44 var e = document.createElement(elementType);
55 e.id = Guid.guid();
6− //e.timesAdded = 0;
6+ e.style.padding = "0";
7+ e.style.margin = "0";
78 return e;
89 };
910 var addTo = function(container, elem) {
1011 container.appendChild(clone(elem));
11− //elem.timesAdded += 1;
1212 };
1313 var clone = function(e) {
1414 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− }*/
3915 };
4016 var divify = function(e) {
4117 var div = newElement('div');
core-js/Text.js+1−1
@@ -11,7 +11,7 @@ var Text = function() {
1111 };
1212
1313 var addTag = function(tag) { return function(text) {
14− return '<' + tag + '>' + text + '</' + tag + '>';
14+ return '<' + tag + ' style="padding:0;margin:0">' + text + '</' + tag + '>';
1515 };
1616 };
1717 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() {
4444 castFloatToJSNumber:castFloatToJSNumber,
4545 castJSNumberToInt:castJSNumberToInt,
4646 castIntToJSNumber:castIntToJSNumber,
47− castJSElementToElement:castJSElementToElement,
48− castElementToJSElement:castElementToJSElement,
47+ Experimental : {castJSElementToElement:castJSElementToElement,
48+ castElementToJSElement:castElementToJSElement},
4949 castJSArrayToList:castJSArrayToList,
5050 castListToJSArray:castListToJSArray,
5151 castJSStringToString:castJSStringToString,
core-js/runtime/Dispatcher.js+29−12
@@ -1,8 +1,9 @@
11
22var Elm = function() {
3− var send = function(kids, timestep, changed) {
3+ var send = function(node, timestep, changed) {
4+ var kids = node.kids;
45 for (var i = kids.length; i--; ) {
5− kids[i].recv(timestep, changed);
6+ kids[i].recv(timestep, changed, node.id);
67 }
78 };
89 var input = function(base) {
@@ -12,7 +13,7 @@ var Elm = function() {
1213 this.recv = function(timestep, eid, v) {
1314 var changed = eid === this.id;
1415 if (changed) { this.value = v; }
15− send(this.kids, timestep, changed);
16+ send(this, timestep, changed);
1617 };
1718 Dispatcher.inputs.push(this);
1819 };
@@ -32,7 +33,7 @@ var Elm = function() {
3233 };
3334 this.recalc();
3435
35− this.recv = function(timestep, changed) {
36+ this.recv = function(timestep, changed, parentID) {
3637 if (!this.inbox.hasOwnProperty(timestep)) {
3738 this.inbox[timestep] = { changed: false, count: 0 };
3839 }
@@ -41,7 +42,7 @@ var Elm = function() {
4142 if (changed) { box.changed = true; }
4243 if (box.count == args.length) {
4344 if (box.changed) { this.recalc() }
44− send(this.kids, timestep, box.changed);
45+ send(this, timestep, box.changed);
4546 delete this.inbox[timestep];
4647 }
4748 };
@@ -53,9 +54,9 @@ var Elm = function() {
5354 this.id = Guid.guid();
5455 this.value = base;
5556 this.kids = [];
56− this.recv = function(timestep, changed) {
57+ this.recv = function(timestep, changed, parentID) {
5758 if (changed) { this.value = func(input.value)(this.value); }
58− send(this.kids, timestep, changed);
59+ send(this, timestep, changed);
5960 };
6061 input.kids.push(this);
6162 };
@@ -64,10 +65,10 @@ var Elm = function() {
6465 this.id = Guid.guid();
6566 this.value = pred(input.value) ? base : input.value;
6667 this.kids = [];
67− this.recv = function(timestep, changed) {
68+ this.recv = function(timestep, changed, parentID) {
6869 var chng = changed && !pred(input.value);
6970 if (chng) { this.value = input.value; }
70− send(this.kids, timestep, chng);
71+ send(this, timestep, chng);
7172 };
7273 input.kids.push(this);
7374 };
@@ -75,10 +76,10 @@ var Elm = function() {
7576 this.id = Guid.guid();
7677 this.value = input.value;
7778 this.kids = [];
78− this.recv = function(timestep, changed) {
79+ this.recv = function(timestep, changed, parentID) {
7980 var chng = changed && !eq(this.value,input.value);
8081 if (chng) { this.value = input.value; }
81− send(this.kids, timestep, chng);
82+ send(this, timestep, chng);
8283 };
8384 input.kids.push(this);
8485 };
@@ -89,6 +90,21 @@ var Elm = function() {
8990 return new lift(function(p){return p[1];},[dropped]); }; };
9091 };
9192
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+
92108 return {Input: function(x) {return new input(x);},
93109 Lift: function(f,xs){return new lift(f,xs);},
94110 Fold: function(f,b,x){return new fold(f,b,x);},
@@ -98,7 +114,8 @@ var Elm = function() {
98114 return new dropIf(pred,base,sig); }; }; },
99115 keepWhen : function(s) { return dropWhen(new lift(function(b){return !b;},[s])); },
100116 dropWhen : dropWhen,
101− dropRepeats : function(s) { return new dropRepeats(s);}
117+ dropRepeats : function(s) { return new dropRepeats(s);},
118+ sampleOn : sampleOn
102119 };
103120}();
104121
core-js/runtime/Signal.js+5−2
@@ -24,6 +24,7 @@ var Signal = function() {
2424 var position = Elm.Input(Value.Tuple(0,0));
2525 var isDown = Elm.Input(false);
2626 var isClicked = Elm.Input(false);
27+ var clicks = Elm.Input(Value.Tuple());
2728
2829 function getXY(e) {
2930 var posx = 0;
@@ -43,6 +44,7 @@ var Signal = function() {
4344
4445 addListener(document, 'click', function(e) {
4546 Dispatcher.notify(isClicked.id, true);
47+ Dispatcher.notify(clicks.id, Value.Tuple());
4648 Dispatcher.notify(isClicked.id, false);
4749 });
4850 addListener(document, 'mousedown', function(e) {
@@ -64,7 +66,8 @@ var Signal = function() {
6466 y: Elm.Lift(function(p){return p[2];},[position]),
6567 isClicked: isClicked,
6668 isDown: isDown,
67− clickedOn: clickedOn
69+ clicks: clicks
70+ //clickedOn: clickedOn
6871 };
6972 }();
7073
@@ -303,7 +306,7 @@ var Signal = function() {
303306 return Elm.Lift(f, [e1,e2,e3,e4]); }; }; }; }; },
304307 foldp : function(f) { return function(b) { return function(e) {
305308 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)},
307310 keepIf : Elm.keepIf,
308311 dropIf : Elm.dropIf,
309312 keepWhen : Elm.keepWhen,