/
index.js
102 lines (83 loc) · 1.49 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* Module dependencies.
*/
var Emitter = require('emitter')
, o = 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);
options = options || {};
this.closable = options.closable;
this.el = o(require('./template'));
this.el.appendTo('body');
if (this.closable) this.el.click(this.hide.bind(this));
}
/**
* Inherits from `Emitter.prototype`.
*/
Overlay.prototype.__proto__ = Emitter.prototype;
/**
* Show the overlay.
*
* Emits "show" event.
*
* @return {Overlay}
* @api public
*/
Overlay.prototype.show = function(){
this.emit('show');
this.el.removeClass('hide');
return this;
};
/**
* Hide the overlay.
*
* Emits "hide" event.
*
* @return {Overlay}
* @api public
*/
Overlay.prototype.hide = function(){
this.emit('hide');
return this.remove();
};
/**
* Hide the overlay without emitting "hide".
*
* Emits "close" event.
*
* @return {Overlay}
* @api public
*/
Overlay.prototype.remove = function(){
var self = this;
this.emit('close');
this.el.addClass('hide');
setTimeout(function(){
self.el.remove();
}, 2000);
return this;
};