Skip to content

Commit

Permalink
first
Browse files Browse the repository at this point in the history
  • Loading branch information
Raynos committed Aug 22, 2012
0 parents commit 618aad8
Show file tree
Hide file tree
Showing 10 changed files with 376 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
node_modules
*.log
*.err
19 changes: 19 additions & 0 deletions LICENCE
@@ -0,0 +1,19 @@
Copyright (c) 2012 Raynos.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Empty file added Makefile
Empty file.
36 changes: 36 additions & 0 deletions README.md
@@ -0,0 +1,36 @@
# selectron

Keep track of the currently selected thing

## Example

``` js
var selectron = require("selectron")

var sel = selectron()
, ul = document.getElementById("list")

ul.addEventListener("click", function (evt) {
if (evt.target.tagName === "LI") {
sel.select(evt.target)
}
})

sel.on("select", function (li) {
li.classList.add("selected")
})

sel.on("unselect", function (li) {
li.classList.remove("selected")
})
```

## Installation

`npm install selectron`

## Contributors

- Raynos

## MIT Licenced
2 changes: 2 additions & 0 deletions example/Makefile
@@ -0,0 +1,2 @@
run:
node ../node_modules/.bin/browserify-server
18 changes: 18 additions & 0 deletions example/index.js
@@ -0,0 +1,18 @@
var selectron = require("../index")

var sel = selectron()
, ul = document.getElementById("list")

ul.addEventListener("click", function (evt) {
if (evt.target.tagName === "LI") {
sel.select(evt.target)
}
})

sel.on("select", function (li) {
li.classList.add("selected")
})

sel.on("unselect", function (li) {
li.classList.remove("selected")
})
213 changes: 213 additions & 0 deletions example/static/bundle.js

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions example/static/index.html
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<title> Your title </title>
<style>
.selected {
color: red;
}
</style>
</head>
<body>
<ul id="list">
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
<!-- the main bundle served from index.js -->
<script src="bundle.js"></script>
<!--
Other bundles
<script src="entry/other-entry.js"></script>
-->
</body>
</html>
31 changes: 31 additions & 0 deletions index.js
@@ -0,0 +1,31 @@
var EventEmitter = require("events").EventEmitter

module.exports = selectron

function selectron() {
var sel = new EventEmitter()
, selected

sel.select = select
sel.unselect = unselect

return sel

function select(thing) {
unselect()

selected = thing

selected.select && selected.select()
sel.emit("select", selected)
}

function unselect() {
if (selected) {
selected.unselect && selected.unselect()
sel.emit("unselect", selected)
}

selected = null
}
}
30 changes: 30 additions & 0 deletions package.json
@@ -0,0 +1,30 @@
{
"name": "selectron",
"version": "0.0.1",
"description": "Keep track of the currently selected thing",
"keywords": [],
"author": "Raynos <raynos2@gmail.com>",
"repository": "git://github.com/Raynos/selectron.git",
"main": "index",
"homepage": "https://github.com/Raynos/selectron",
"contributors": [
{
"name": "Jake Verbaten"
}
],
"bugs": {
"url": "https://github.com/Raynos/selectron/issues",
"email": "raynos2@gmail.com"
},
"dependencies": {},
"devDependencies": {
"browserify-server": "~1.0.2"
},
"licenses": [
{
"type": "MIT",
"url": "http://github.com/Raynos/selectron/raw/master/LICENSE"
}
],
"scripts": {}
}

0 comments on commit 618aad8

Please sign in to comment.