-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
61 lines (45 loc) · 1.04 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
/**
* Module dependencies.
*/
var overlay = require('overlay')
, domify = require('domify')
, classes = require('classes')
, query = require('query')
, template = require('./template');
/**
* Module exports.
*/
module.exports = function(content){
// close all remaining popouts
var el = query('.popout');
if (el) classes(el).remove('popout');
return new Popout(content);
};
/**
* Initialize new popout.
*/
function Popout(content) {
var el = this.el = content.el || content
, overlay;
// render content
classes(el).add('popout');
// init overlay
overlay = query('#popout-overlay');
if (overlay) {
this._overlay = overlay;
} else {
// create overlay
overlay = this._overlay = document.createElement('div');
overlay.setAttribute('id', 'popout-overlay');
document.body.appendChild(overlay);
}
}
/**
* Close the popover.
*/
Popout.prototype.close = function(){
if (classes(this.el).has('popout')) {
classes(this.el).remove('popout');
document.body.removeChild(this._overlay);
}
};