Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed May 4, 2012
0 parents commit 4d5ba6a
Show file tree
Hide file tree
Showing 9 changed files with 202 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
node_modules
test/*.js
test/*.css
1 change: 1 addition & 0 deletions .npmignore
@@ -0,0 +1 @@
test
8 changes: 8 additions & 0 deletions Makefile
@@ -0,0 +1,8 @@

test/out.js: overlay.js overlay.css
component build package.json test/out

clean:
rm -f test/out.{js,css}

.PHONY: clean
31 changes: 31 additions & 0 deletions Readme.md
@@ -0,0 +1,31 @@

# Emitter

Event emitter component.

## Installation

```
$ npm install emitter-component
```

## API

### Emitter#on(event, fn)

Register an `event` handler `fn`.

### Emitter#once(event, fn)

Register a single-shot `event` handler `fn`,
removed immediately after it is invoked the
first time.

### Emitter#off(event, fn)

Remove `event` handler `fn`, or pass only the `event`
name to remove all handlers for `event`.

### Emitter#emit(event, ...)

Emit an `event` with variable option args.
16 changes: 16 additions & 0 deletions overlay.css
@@ -0,0 +1,16 @@
#overlay {
position: fixed;
top: 0;
left: 0;
opacity: 1;
width: 100%;
height: 100%;
background: rgba(0,0,0,.75);
transition: opacity 300ms;
z-index: 500;
}

#overlay.hide {
pointer-events: none;
opacity: 0;
}
1 change: 1 addition & 0 deletions overlay.html
@@ -0,0 +1 @@
<div id="overlay" class="hide"></div>
92 changes: 92 additions & 0 deletions overlay.js
@@ -0,0 +1,92 @@

/**
* Module dependencies.
*/

var Emitter = require('emitter')
, $ = require('jquery');

/**
* Expose `overlay()`.
*/

exports = module.exports = overlay;

/**
* Expose `Overlay`.
*/

exports.Overlay = Overlay;

/**
* Return a new `Overlay` with the given `options`.
*
* @param {Object} options
* @return {Overlay}
* @api public
*/

function overlay(options){
return new Overlay(options);
};

/**
* Initialize a new `Overlay`.
*
* @param {Object} options
* @api public
*/

function Overlay(options) {
Emitter.call(this);
var self = this;
options = options || {};
this.closable = options.closable;
this.el = $(render('overlay'));
this.el.appendTo('body');
if (this.closable) {
this.el.click(function(){
self.hide();
});
}
}

/**
* Inherits from `Emitter.prototype`.
*/

Overlay.prototype.__proto__ = Emitter.prototype;

/**
* Show the overlay.
*
* Emits "show" event.
*
* @return {Overlay} for chaining
* @api public
*/

Overlay.prototype.show = function(){
this.emit('show');
this.el.removeClass('hide');
return this;
};

/**
* Hide the overlay.
*
* Emits "hide" event.
*
* @return {Overlay} for chaining
* @api public
*/

Overlay.prototype.hide = function(){
var self = this;
this.emit('hide');
this.el.addClass('hide');
setTimeout(function(){
self.el.remove();
}, 2000);
return this;
};
18 changes: 18 additions & 0 deletions package.json
@@ -0,0 +1,18 @@
{
"name": "overlay-component",
"description": "Page overlay component",
"version": "0.0.1",
"dependencies": {
"emitter-component": "*",
"jquery-component": "*"
},
"component": {
"styles": ["overlay.css"],
"scripts": {
"overlay": "overlay.js"
},
"templates": {
"overlay": "overlay.html"
}
}
}
32 changes: 32 additions & 0 deletions test/index.html
@@ -0,0 +1,32 @@
<!DOCTYPE 5>
<html>
<head>
<title>Overlay</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="out.css" />
</head>
<body>
<title>Overlay</title>
<script src="out.js"></script>
<script>
var overlay = require('overlay');

var o = overlay()
.show()
.on('hide', function(){
console.log('hidden');
setTimeout(function(){
overlay({ closable: true })
.show()
.on('hide', function(){
console.log('hidden 2');
});
}, 500);
});

setTimeout(function(){
o.hide();
}, 1000);
</script>
</body>
</html>

0 comments on commit 4d5ba6a

Please sign in to comment.