Skip to content
This repository was archived by the owner on Feb 8, 2020. It is now read-only.

Commit 26150b4

Browse files
Initial commit
0 parents  commit 26150b4

File tree

8 files changed

+460
-0
lines changed

8 files changed

+460
-0
lines changed

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
### PureScript ###
2+
.psci*
3+
.psci_modules
4+
.pulp-cache
5+
bower_components
6+
node_modules
7+
output
8+
src/.webpack.js
9+
10+
### Vim ###
11+
[._]*.s[a-w][a-z]
12+
[._]s[a-w][a-z]
13+
*.un~
14+
Session.vim
15+
.netrwhist
16+
*~

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Pierre Beaucamp
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

bower.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "purescript-tutorial",
3+
"version": "1.0.0",
4+
"moduleType": [
5+
"node"
6+
],
7+
"ignore": [
8+
"**/.*",
9+
"node_modules",
10+
"bower_components",
11+
"output"
12+
],
13+
"dependencies": {
14+
"purescript-simple-dom": "~0.1.3"
15+
}
16+
}

index.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
7+
<title>Pirate badge</title>
8+
9+
<script async src="main.js"></script>
10+
<link rel="stylesheet" href="styles.css">
11+
</head>
12+
13+
<body>
14+
<h1>Pirate badge</h1>
15+
<div class="widgets">
16+
<input type="text" id="inputName" maxlength="15">
17+
</div>
18+
<div class="badge">
19+
<div class="greeting">
20+
Arrr! Me name is
21+
</div>
22+
<div class="name">
23+
<span id="badgeName"> </span>
24+
</div>
25+
</div>
26+
</body>
27+
</html>

main.js

Lines changed: 284 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Main.purs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module Main where
2+
3+
import Control.Monad.Eff
4+
import Data.DOM.Simple.Unsafe.Element
5+
import Data.DOM.Simple.Unsafe.Events
6+
import Data.DOM.Simple.Unsafe.Window
7+
import Data.DOM.Simple.Types
8+
import Data.DOM.Simple.Window
9+
import DOM
10+
import Prelude
11+
12+
{-|
13+
main is the entry point of this program. Its sole purpose is to add an event
14+
listener to the input field.
15+
-}
16+
main :: forall eff. Eff (dom :: DOM | eff) Unit
17+
main = do
18+
element <- unsafeDocument globalWindow >>= unsafeQuerySelector "#inputName"
19+
unsafeAddEventListener "input" updateBadge element
20+
21+
{-|
22+
updateBadge is the callback method for the event listener of the input
23+
field. It will display the value of the input field on the badge.
24+
-}
25+
updateBadge :: forall eff. DOMEvent -> Eff (dom :: DOM | eff) Unit
26+
updateBadge event = do
27+
badge <- unsafeDocument globalWindow >>= unsafeQuerySelector "#badgeName"
28+
input <- unsafeEventTarget event >>= unsafeValue
29+
unsafeSetTextContent input badge

0 commit comments

Comments
 (0)