Fix above and below to work properly with the new parser, and add a slightly better error message for runtime issues.

This commit is contained in:
evancz 2012-06-10 04:13:00 -05:00
parent 368b63c4f5
commit 0735c6bdc6
3 changed files with 6 additions and 6 deletions

View File

@ -207,11 +207,11 @@ var Element = function() {
};
var beside = function(a) { return function(b) {
return flow(1)(["Cons",a,["Cons",b,["Nil"]]]); }; };
return flow(4)(["Cons",a,["Cons",b,["Nil"]]]); }; };
var above = function(a) { return function(b) {
return flow(0)(["Cons",a,["Cons",b,["Nil"]]]); }; };
var below = function(a) { return function(b) {
return flow(3)(["Cons",a,["Cons",b,["Nil"]]]); }; };
var below = function(a) { return function(b) {
return flow(0)(["Cons",a,["Cons",b,["Nil"]]]); }; };
var box = function(pos) { return function(e) {
e.style.position = "absolute";

View File

@ -109,7 +109,7 @@ var Dispatcher = function() {
var initialize = function() {
try { program = main(); } catch (e) {
document.body.innerHTML = "An Error Occured: Better Messages to come.";
document.body.innerHTML = monospace("Runtime Error:<br>JavaScript " + e);
throw e;
}
if (!program.hasOwnProperty('recv')) {

View File

@ -7,7 +7,7 @@ e=d(0)("left"),c=d(0)("justify"),f=d(0)("center"),h=function(n){return"DIV"===n.
i)return j("Z",g,b)}},l=function(a){return function(b){if("A"===b.tagName)return l(a)(b.firstChild),b;if(b.hasOwnProperty("isElmText")){var c=d(a)(b.style.textAlign)(b.innerHTML);b.style.height=c.style.height}b.style.width=a+"px";return b}};return{text:e,image:function(a){var c=b("img");c.isElmLeaf=!0;c.onload=function(){""===c.style.width&&0<this.width&&(c.style.width=c.width=this.width+"px");""===c.style.height&&0<this.height&&(c.style.height=c.height=this.height+"px");Dispatcher.adjust()};c.src=
String.toText(a);c.name=c.src;return c},fittedImage:function(a){return function(c){return function(d){var e=b("canvas");e.style.width=a+"px";e.style.height=c+"px";e.width=a;e.height=c;e.innerHTML="Your browser does not support the canvas element.";e.isElmLeaf=!0;var g=b("img");g.onload=function(){if(e.getContext){var b=e.getContext("2d"),d=0,q=0,f=this.width,j=this.height;a/c>this.width/this.height?(j=this.width*c/a,q=(this.height-j)/2):(f=this.height*a/c,d=(this.width-f)/2);b.drawImage(g,d,q,f,j,
0,0,e.width,e.height)}};g.src=String.toText(d);return e}}},video:function(a){var a=String.toText(a),c=b("video");c.controls="controls";var d=b("source");d.src=a;d.type="video/"+a.substring(a.length-3,a.length);c.appendChild(d);c.isElmLeaf=!0;return c},audio:function(a){var a=String.toString(a),c=b("video");c.controls="controls";var d=b("source");d.src=a;d.type="audio/"+a.substring(a.length-3,a.length);c.appendChild(d);c.isElmLeaf=!0;return c},collage:function(a){return function(c){return function(d){var e=
b("canvas");e.style.width=a+"px";e.style.height=c+"px";e.width=a;e.height=c;if(e.getContext){var g=e.getContext("2d");for(g.clearRect(0,0,e.width,e.height);"Cons"===d[0];)g=d[1](g),d=d[2];return e}e.innerHTML="Your browser does not support the canvas element.";e.isElmLeaf=!0;return e}}},flow:m,layers:m(2),beside:function(a){return function(c){return m(1)(["Cons",a,["Cons",c,["Nil"]]])}},above:function(a){return function(c){return m(0)(["Cons",a,["Cons",c,["Nil"]]])}},below:function(a){return function(c){return m(3)(["Cons",
b("canvas");e.style.width=a+"px";e.style.height=c+"px";e.width=a;e.height=c;if(e.getContext){var g=e.getContext("2d");for(g.clearRect(0,0,e.width,e.height);"Cons"===d[0];)g=d[1](g),d=d[2];return e}e.innerHTML="Your browser does not support the canvas element.";e.isElmLeaf=!0;return e}}},flow:m,layers:m(2),beside:function(a){return function(c){return m(4)(["Cons",a,["Cons",c,["Nil"]]])}},above:function(a){return function(c){return m(3)(["Cons",a,["Cons",c,["Nil"]]])}},below:function(a){return function(c){return m(0)(["Cons",
a,["Cons",c,["Nil"]]])}},box:function(a){return function(c){c.style.position="absolute";c.style.margin="auto";var d=(a-1)%3,e=(a-1)/3;2>d&&(c.style.left=0);0<d&&(c.style.right=0);2>e&&(c.style.top=0);0<e&&(c.style.bottom=0);d=b("div");d.style.position="relative";d.appendChild(c);return d}},width:l,height:function(a){return function(c){("A"===c.tagName?c.firstChild:c).style.height=a+"px";return c}},size:function(a){return function(c){return function(b){var d="A"===b.tagName?b.firstChild:b;d.style.width=
a+"px";d.style.height=c+"px";return b}}},color:function(a){return function(c){c.style.backgroundColor=Color.Internal.extract(a);return c}},opacity:function(a){return function(c){c.style.opacity=a;return c}},link:function(c){return function(d){var e=b("a");e.href=Text.fromString(c);e.appendChild(d);return a(e)}},asText:function(a){return d(0)("left")(Value.show(a))},plainText:function(a){return d(0)("left")(String.toText(a))},justifiedText:c,centeredText:f,up:0,left:1,inward:2,down:3,right:4,outward:5}}(),
Text=function(){var b=function(a){if("string"===typeof a)return a;for(var c=[];"Cons"===a[0];)c.push(a[1]),a=a[2];return String.properEscape(c.join(""))},a=function(a){return function(c){return"<"+a+">"+c+"</"+a+">"}},d=function(a,c){return function(b){return"<span style='"+a+":"+c+"'>"+b+"</span>"}},e=a("h1"),c=d("font-style","italic"),a=a("b"),f=d("text-decoration","underline"),h=d("text-decoration","overline"),k=d("text-decoration","line-through");return{fromString:b,toText:b,header:e,height:function(a){return d("font-size",
@ -20,7 +20,7 @@ e.center[1]);c.rotate(e.theta);c.scale(e.scale,e.scale);var h=a,k=e.points,g=k.l
b,e){for(var d=a.length;d--;)a[d].recv(b,e)},a=function(a){this.id=Guid.guid();this.value=a;this.kids=[];this.recv=function(a,c,e){if(c=c===this.id)this.value=e;b(this.kids,a,c)};Dispatcher.inputs.push(this)},d=function(a,e){this.id=Guid.guid();this.value=null;this.kids=[];this.inbox={};e.reverse();this.recalc=function(){for(var b=a,d=e.length;d--;)b=b(e[d].value);this.value=b};this.recalc();this.recv=function(a,c){this.inbox.hasOwnProperty(a)||(this.inbox[a]={changed:!1,count:0});var d=this.inbox[a];
d.count+=1;c&&(d.changed=!0);d.count==e.length&&(d.changed&&this.recalc(),b(this.kids,a,d.changed),delete this.inbox[a])};for(var d=e.length;d--;)e[d].kids.push(this)},e=function(a,e,d){this.id=Guid.guid();this.value=e;this.kids=[];this.recv=function(e,g){g&&(this.value=a(d.value)(this.value));b(this.kids,e,g)};d.kids.push(this)};return{Input:function(c){return new a(c)},Lift:function(a,b){return new d(a,b)},Fold:function(a,b,d){return new e(a,b,d)}}}(),Dispatcher=function(){var b=null,a=0,d=[],e=
function(a){var b=a.childNodes,d=b.length;if(a.hasOwnProperty("isElmLeaf")){var b=""===a.style.width?0:a.style.width.slice(0,-2)-0,k=""===a.style.height?0:a.style.height.slice(0,-2)-0;return[b,k]}if(1===d){var g=e(b[0]);""!==a.style.width&&(g[0]=a.style.width.slice(0,-2)-0);""!==a.style.height&&(g[1]=a.style.height.slice(0,-2)-0);0!==g[0]&&(a.style.width=g[0]+"px");0!==g[1]&&(a.style.height=g[1]+"px");return g}for(var j=0,m=k=0,l=0,n=!0,i=!0;d--;)g=e(b[d]),j=Math.max(j,g[0]),k=Math.max(k,g[1]),m+=
g[0],l+=g[1],n=n&&0<g[0],i=i&&0<g[1];b=j;d=a.elmFlowDirection;"X"===d&&(b=n?m:0);"Y"===d&&(k=i?l:0);0<b&&(a.style.width=b+"px");0<k&&(a.style.height=k+"px");return[b,k]};return{initialize:function(){try{b=main()}catch(a){throw document.body.innerHTML="An Error Occured: Better Messages to come.",a;}b.hasOwnProperty("recv")||(b=Elm.Input(b));var d=document.getElementById("content");d.appendChild(b.value);e(d);d=document.getElementById("widthChecker").offsetWidth;d!==window.innerWidth&&Dispatcher.notify(Window.dimensions.id,
g[0],l+=g[1],n=n&&0<g[0],i=i&&0<g[1];b=j;d=a.elmFlowDirection;"X"===d&&(b=n?m:0);"Y"===d&&(k=i?l:0);0<b&&(a.style.width=b+"px");0<k&&(a.style.height=k+"px");return[b,k]};return{initialize:function(){try{b=main()}catch(a){throw document.body.innerHTML=monospace("Runtime Error:<br>JavaScript "+a),a;}b.hasOwnProperty("recv")||(b=Elm.Input(b));var d=document.getElementById("content");d.appendChild(b.value);e(d);d=document.getElementById("widthChecker").offsetWidth;d!==window.innerWidth&&Dispatcher.notify(Window.dimensions.id,
Value.Tuple(d,window.innerHeight));b=Elm.Lift(function(a){var b=document.getElementById("content");b.replaceChild(a,b.children[0]);e(b);return a},[b])},notify:function(b,e){a+=1;for(var h=d.length;h--;)d[h].recv(a,b,e)},adjust:function(){var a=document.getElementById("content");e(a)},inputs:d}}(),Signal=function(){function b(a){for(var b=["Nil"],c=a.length;c--;)b=["Cons",a[c],b];return b}var a=function(){return document.addEventListener?function(a,b,c){a.addEventListener(b,c,!1)}:function(a,b,c){a.attachEvent("on"+
b,c)}}(),d=function(){function b(a){var c=0,d=0;a||(a=window.event);if(a.pageX||a.pageY)c=a.pageX,d=a.pageY;else if(a.clientX||a.clientY)c=a.clientX+document.body.scrollLeft+document.documentElement.scrollLeft,d=a.clientY+document.body.scrollTop+document.documentElement.scrollTop;return Value.Tuple(c,d)}var c=Elm.Input(Value.Tuple(0,0)),d=Elm.Input(!1),e=Elm.Input(!1);a(document,"click",function(){Dispatcher.notify(e.id,!0);Dispatcher.notify(e.id,!1)});a(document,"mousedown",function(){Dispatcher.notify(d.id,
!0)});a(document,"mouseup",function(){Dispatcher.notify(d.id,!1)});a(document,"mousemove",function(a){Dispatcher.notify(c.id,b(a))});return{position:c,x:Elm.Lift(function(a){return a[1]},[c]),y:Elm.Lift(function(a){return a[2]},[c]),isClicked:e,isDown:d,clickedOn:function(b){var c=Elm.Input(!1);a(b,"click",function(){Dispatcher.notify(c.id,!0);Dispatcher.notify(c.id,!1)});return Value.Tuple(b,c)}}}(),e=function(){return{every:function(a){var a=1E3*a,b=Elm.Input(0),c=0;setInterval(function(){c+=a;