-
Notifications
You must be signed in to change notification settings - Fork 0
/
modal.js
111 lines (101 loc) · 2.27 KB
/
modal.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
102
103
104
105
106
107
108
109
110
111
(function(root, factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
define(['react'], factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory(require('react'));
} else {
root.LightBox = factory(root.React);
}
}(this, function(React) {
'use strict';
var D = React.DOM;
var LightBox = React.createClass({
open: function() {
this.setState({
open: true
});
this.props.onOpen();
},
close: function() {
this.setState({
open: false
});
this.props.onClose();
},
skip: function() {
if (!this.props.noSkip) {
this.close();
}
},
is_open: function() {
if (typeof this.props.open !== 'undefined') {
return this.props.open;
}
return this.state.open;
},
componentWillMount: function() {
this.keyupListener = function(event) {
if (event.keyCode === 27) {
this.skip();
}
}.bind(this);
window.addEventListener('keyup', this.keyupListener);
},
componentWillUnmount: function() {
window.removeEventListener('keyup', this.keyupListener);
},
getDefaultProps: function() {
return {
noSkip: false,
openInitial: false,
iconclass: '__none__',
onClose: function() {},
onOpen: function() {}
};
},
getInitialState: function() {
return {
open: this.props.openInitial
};
},
render: function() {
var className = 'clean-modal';
var titleClassName = '';
if (!this.props.title) {
titleClassName = 'hidden';
}
if (!this.is_open()) {
return D.div();
}
if (this.props.className) {
className = className + ' ' + this.props.className;
}
if (this.props.noSkip) {
className = className + ' no-skip';
}
return D.div({className: className,},
D.div({className: 'clean-modal-wrapper'},
D.h1(
{className: 'clean-modal-title ' + titleClassName},
D.div({className: 'icon ' + this.props.iconclass}),
D.span({}, this.props.title)
),
D.div(
{className: 'clean-modal-content'},
this.props.children
),
D.div(
{
className: 'clean-modal-close',
onClick: this.skip
},
this.props.noSkip ? '' : '×'
)
),
D.div({className: 'clean-modal-overlay', onClick: this.skip})
);
}
});
return LightBox;
}));