on master help sign in
Fix bug in `typeface` and in `makeSpaces`. Remove form example so that it is not duplicated.
commit9020b2249989f253918a53f31259c41a495fcaca authorevancz <info@elm-lang.org> dateSun 16 Sep 2012, 00:50 (14 years ago) parentf5e3ad4
6 files changed+7−85
Examples/elm-js/Form/Form.elm−68 Examples/elm-js/Form/FormHelp.js−3 Examples/elm-js/Form/README.md−12 core-js/Everything.js+2−1 core-js/Text.js+4−1 core-js/Value.js+1
Examples/elm-js/Form/Form.elmdeleted−68
@@ -1,68 +0,0 @@
1−
2−module Form where
3−
4−import Data.Maybe (mapMaybe)
5−import Foreign.JavaScript
6−import Signal.Input
7−import Signal.Window as Win
8−
9−foreign export jsevent "redirect"
10− redirectTo :: Signal JSString
11−
12−
13−-- Helpers
14−
15−isEmpty xs = case xs of { [] -> True ; _ -> False }
16−
17−getErrors first last email remail =
18− mapMaybe (\(err,msg) -> if err then Just msg else Nothing)
19− [ (isEmpty first , "First name required.")
20− , (isEmpty last , "Last name required.")
21− , (isEmpty email , "Must enter your email address.")
22− , (isEmpty remail , "Must re-enter your email address.")
23− , (email /= remail, "Email addresses do not match.")
24− ]
25−
26−url first last email =
27− "login?first=" ++ first ++ "&last=" ++ last ++ "&email="++ email
28−
29−
30−-- Signals
31−
32−(firstBox , first) = textField "First Name"
33−(lastBox , last) = textField "Last Name"
34−(emailBox , email) = textField "Your Email"
35−(remailBox, remail) = textField "Re-enter Email"
36−(butn , press) = button "Submit"
37−
38−pressCount = foldp (\p c -> if p then c+1 else c) 0 press
39−errors = lift4 getErrors first last email remail
40−sendable = lift2 (&&) press (lift isEmpty errors)
41−
42−redirectTo = lift castStringToJSString $
43− keepWhen sendable "" (lift3 url first last email)
44−
45−
46−-- Display
47−
48−field txt fld =
49− width 400 . flow right $
50− [ size 120 30 . box 6 $ plainText txt
51− , size 200 30 . box 5 $ size 180 20 fld
52− ]
53−
54−showErrors presses errs =
55− if presses == 0 || isEmpty errs then rectangle 10 10 else
56− flow down $ map (text . Text.color red . toText) errs
57−
58−form presses errs (w,h) =
59− size w h . box 5 . color (rgb 230 230 230) . flow down $
60− [ field "First Name:" firstBox
61− , field "Last Name:" lastBox
62− , field "Your Email:" emailBox
63− , field "Re-enter Email:" remailBox
64− , showErrors presses errs
65− , size 310 40 . box 6 $ size 60 30 butn
66− ]
67−
68−main = lift3 form pressCount errors Win.dimensions
Examples/elm-js/Form/FormHelp.jsdeleted−3
@@ -1,3 +0,0 @@
1−document.addEventListener('redirect', function(e) {
2− if (e.value.length > 0) { window.location = e.value; }
3− });
Examples/elm-js/Form/README.mddeleted−12
@@ -1,12 +0,0 @@
1−
2−To compile this example yourself use:
3−
4− elm --import-js="FormHelp.js" Form.elm
5−
6−This compiles the Elm file and includes the necessary JavaScript code.
7−It produces a self-contained HTML file.
8−
9−
10−Note: Not all browsers like reading the elm-runtime-x.y.z.js file from
11−an absolute path, so you may have to specify a relative path with
12−the --runtime flag (e.g. --runtime="../../../elm/elm-runtime-0.3.5.js").
core-js/Everything.js+2−1
@@ -56,4 +56,5 @@ ElmCode.Data = Data;
5656ElmCode.Signal = Signal;
5757ElmCode.Data.List = List;
5858ElmCode.Foreign = Foreign;
59−ElmCode.Prelude = Prelude;
59+ElmCode.Prelude = Prelude;
60+ElmCode.Graphics.Text = Text;
core-js/Text.js+4−1
@@ -11,7 +11,10 @@ var Text = function() {
1111 };
1212 };
1313
14− var typeface = function(name) { return addStyle('font-family', name); };
14+ var typeface = function(name) {
15+ name = Foreign.JavaScript.castStringToJSString(name);
16+ return addStyle('font-family', name);
17+ };
1518 var size = function(px) {
1619 return addStyle('font-size', px + 'px');
1720 };
core-js/Value.js+1
@@ -33,6 +33,7 @@ var Value = function(){
3333 };
3434
3535 function makeSpaces(s) {
36+ if (s.length == 0) { return s; }
3637 var arr = s.split('');
3738 if (arr[0] == ' ') { arr[0] = "&nbsp;" }
3839 for (var i = arr.length; --i; ) {