Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit bdb3680

Browse files
authored
Merge pull request #1 from safareli/initial
Initial version
2 parents 4728fbf + ab01a29 commit bdb3680

File tree

12 files changed

+270
-37
lines changed

12 files changed

+270
-37
lines changed

.gitignore

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,10 @@
1-
# Logs
2-
logs
3-
*.log
4-
npm-debug.log*
5-
6-
# Runtime data
7-
pids
8-
*.pid
9-
*.seed
10-
11-
# Directory for instrumented libs generated by jscoverage/JSCover
12-
lib-cov
13-
14-
# Coverage directory used by tools like istanbul
15-
coverage
16-
17-
# nyc test coverage
18-
.nyc_output
19-
20-
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
21-
.grunt
22-
23-
# node-waf configuration
24-
.lock-wscript
25-
26-
# Compiled binary addons (http://nodejs.org/api/addons.html)
27-
build/Release
28-
29-
# Dependency directories
30-
node_modules
31-
jspm_packages
32-
33-
# Optional npm cache directory
34-
.npm
35-
36-
# Optional REPL history
37-
.node_repl_history
1+
npm-debug.log
2+
/.*
3+
!/.gitignore
4+
!/.travis.yml
5+
!/.jscsrc
6+
!/.jshintrc
7+
/bower_components/
8+
/node_modules/
9+
/output/
10+
/example/example.js

.jscsrc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"preset": "grunt",
3+
"disallowSpacesInFunctionExpression": null,
4+
"requireSpacesInFunctionExpression": {
5+
"beforeOpeningRoundBrace": true,
6+
"beforeOpeningCurlyBrace": true
7+
},
8+
"disallowSpacesInAnonymousFunctionExpression": null,
9+
"requireSpacesInAnonymousFunctionExpression": {
10+
"beforeOpeningRoundBrace": true,
11+
"beforeOpeningCurlyBrace": true
12+
},
13+
"disallowSpacesInsideObjectBrackets": null,
14+
"requireSpacesInsideObjectBrackets": "all",
15+
"validateQuoteMarks": "\"",
16+
"requireCurlyBraces": null
17+
}

.jshintrc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"bitwise": true,
3+
"eqeqeq": true,
4+
"forin": true,
5+
"freeze": true,
6+
"funcscope": true,
7+
"futurehostile": true,
8+
"strict": "global",
9+
"latedef": true,
10+
"maxparams": 1,
11+
"noarg": true,
12+
"nocomma": true,
13+
"nonew": true,
14+
"notypeof": true,
15+
"singleGroups": true,
16+
"undef": true,
17+
"unused": true,
18+
"eqnull": true,
19+
"predef": ["exports", "require"]
20+
}

.travis.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
language: node_js
2+
dist: trusty
3+
sudo: required
4+
node_js: stable
5+
install:
6+
- npm install -g bower
7+
- npm install
8+
- bower install --production
9+
script:
10+
- npm run -s build
11+
- bower install
12+
- npm -s test
13+
after_success:
14+
- >-
15+
test $TRAVIS_TAG &&
16+
echo $GITHUB_TOKEN | pulp login &&
17+
echo y | pulp publish --no-push

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# purescript-clipboard
2+
3+
[![Latest release](http://img.shields.io/github/release/slamdata/purescript-clipboard.svg)](https://github.com/slamdata/purescript-clipboard/releases)
4+
[![Build status](https://travis-ci.org/slamdata/purescript-clipboard.svg?branch=master)](https://travis-ci.org/slamdata/purescript-clipboard)
5+
6+
Basic PureScript bindings for the [clipboard.js](https://github.com/zenorocha/clipboard.js/) library.
7+
8+
## Installation
9+
10+
```
11+
bower install purescript-clipboard
12+
```
13+
14+
## Documentation
15+
16+
Module documentation is [published on Pursuit](http://pursuit.purescript.org/packages/purescript-clipboard).

bower.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "purescript-clipboard",
3+
"license": "Apache-2.0",
4+
"authors": [
5+
"Irakli Safareli <[email protected]> (https://github.com/safareli)"
6+
],
7+
"repository": {
8+
"type": "git",
9+
"url": "git://github.com/slamdata/purescript-clipboard.git"
10+
},
11+
"ignore": [
12+
"**/.*",
13+
"bower_components",
14+
"node_modules",
15+
"output",
16+
"example",
17+
"bower.json",
18+
"package.json"
19+
],
20+
"dependencies": {
21+
"purescript-prelude": "^2.4.0",
22+
"purescript-dom": "^3.5.1",
23+
"purescript-css": "^2.1.0"
24+
}
25+
}

example/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
This example can be build by running the following command in the project root:
2+
3+
```
4+
npm run build-example
5+
```

example/index.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>purescript-clipboard test page</title>
5+
<script type="text/javascript" src="./example.js"></script>
6+
</head>
7+
<body>
8+
<form>
9+
<button id="test-element" type="button" data-copy-text="From test-element!">
10+
Copy
11+
</button>
12+
<br>
13+
<button class="test-selector" type="button" data-copy-text="From test-selector child#1!">
14+
Copy
15+
</button>
16+
<br>
17+
<button class="test-selector" type="button" data-copy-text="From test-selector child#2!">
18+
Copy
19+
</button>
20+
</form>
21+
</body>
22+
</html>

example/src/Main.purs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
module Main where
2+
3+
import Prelude
4+
5+
import Control.Monad.Eff (Eff)
6+
7+
import Data.Maybe (fromMaybe)
8+
import Data.Nullable (toMaybe)
9+
10+
import DOM (DOM)
11+
import CSS (Selector, fromString)
12+
import DOM.Event.EventTarget (addEventListener, eventListener)
13+
import DOM.HTML (window)
14+
import DOM.HTML.Event.EventTypes (load)
15+
import DOM.HTML.Types (windowToEventTarget, htmlDocumentToDocument)
16+
import DOM.HTML.Window (document)
17+
import DOM.Node.NonElementParentNode (getElementById)
18+
import DOM.Node.Types (Element, ElementId(..), documentToNonElementParentNode)
19+
import DOM.Node.Element (getAttribute)
20+
21+
import Clipboard as C
22+
23+
onLoad :: forall eff. (Eff (dom :: DOM | eff) Unit) -> Eff (dom :: DOM | eff) Unit
24+
onLoad action
25+
= addEventListener load (eventListener (const action)) false
26+
<<< windowToEventTarget
27+
=<< window
28+
29+
stringFromAttr :: forall eff. String -> Element -> Eff (dom :: DOM | eff) String
30+
stringFromAttr attr el = do
31+
val <- getAttribute attr el
32+
pure $ fromMaybe "" $ toMaybe val
33+
34+
testElement :: forall eff. Element -> Eff (dom :: DOM | eff) Unit
35+
testElement el = void $ C.fromElement el $ stringFromAttr "data-copy-text" el
36+
37+
testSelector :: forall eff. Selector -> Eff (dom :: DOM | eff) Unit
38+
testSelector sel = void $ C.fromCSSSelector sel $ stringFromAttr "data-copy-text"
39+
40+
main :: forall eff. Eff (dom :: DOM | eff) Unit
41+
main = onLoad do
42+
win <- window
43+
doc <- documentToNonElementParentNode <<< htmlDocumentToDocument <$> document win
44+
element <- toMaybe <$> getElementById (ElementId "test-element") doc
45+
fromMaybe (pure unit) $ testElement <$> element
46+
testSelector $ fromString ".test-selector"

package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"private": true,
3+
"scripts": {
4+
"clean": "rimraf output && rimraf .pulp-cache",
5+
"build": "jshint src && jscs src && pulp build --censor-lib --strict",
6+
"test": "pulp build -I example/src --censor-lib --strict",
7+
"build-example": "pulp browserify -I example/src --to example/example.js"
8+
},
9+
"devDependencies": {
10+
"jscs": "^3.0.7",
11+
"jshint": "^2.9.4",
12+
"pulp": "^9.0.1",
13+
"purescript": "^0.10.7",
14+
"purescript-psa": "^0.3.9",
15+
"rimraf": "^2.6.1"
16+
},
17+
"dependencies": {
18+
"clipboard": "1.6.1"
19+
}
20+
}

0 commit comments

Comments
 (0)