Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
123 lines (99 loc) · 1.9 KB
/
Copy pathindex.js
File metadata and controls
123 lines (99 loc) · 1.9 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
* Module dependencies.
*/
var Emitter = require('emitter');
var tmpl = require('./template.html');
var domify = require('domify');
var event = require('event');
var classes = require('classes');
/**
* Expose `overlay()`.
*/
exports = module.exports = overlay;
/**
* Expose `Overlay`.
*/
exports.Overlay = Overlay;
/**
* Return a new `Overlay` with the given `options`.
*
* @param {Object|Element} options
* @return {Overlay}
* @api public
*/
function overlay(options){
options = options || {};
// element
if (options.nodeName) {
options = { target: options };
}
return new Overlay(options);
}
/**
* Initialize a new `Overlay`.
*
* @param {Object} options
* @api public
*/
function Overlay(options) {
Emitter.call(this);
options = options || {};
this.target = options.target || document.body;
this.closable = options.closable;
this.el = domify(tmpl);
if (this.closable) {
event.bind(this.el, 'click', this.hide.bind(this));
classes(this.el).add('closable');
}
}
/**
* Mixin emitter.
*/
Emitter(Overlay.prototype);
/**
* Show the overlay.
*
* Emits "show" event.
*
* @return {Overlay}
* @api public
*/
Overlay.prototype.show = function(){
var self = this;
this.emit('show');
this.target.appendChild(this.el);
//class removed in a timeout to save animation
setTimeout( function () {
classes(self.el).remove('hidden');
});
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');
classes(this.el).add('hidden');
setTimeout(function(){
self.target.removeChild(self.el);
}, 350);
return this;
};