forked from kapetan/titlebar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
80 lines (67 loc) · 2.37 KB
/
index.js
File metadata and controls
80 lines (67 loc) · 2.37 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
var util = require('util');
var fs = require('fs');
var React = require('react/addons');
var defaultcss = require('defaultcss');
var classNames = require('classnames');
var stoplight = require('./stoplight');
var style = fs.readFileSync(__dirname + '/index.css', 'utf-8');
style = util.format(style, stoplight);
var ALT = 18;
module.exports = React.createClass({displayName: "exports",
getInitialState: function() {
return {
altDown: false,
draggable: this.props.draggable,
}
},
componentDidMount: function() {
document.body.addEventListener('keydown', this.handleKeyDown);
document.body.addEventListener('keyup', this.handleKeyUp);
},
componentWillUnMount: function() {
document.body.removeEventListener('keydown', this.handleKeyDown);
document.body.removeEventListener('keyup', this.handleKeyUp);
},
handleKeyDown: function(e) {
if (e.keyCode === ALT) {
this.setState({ altDown: true });
}
},
handleKeyUp: function(e) {
if (e.keyCode === ALT) {
this.setState({ altDown: false });
}
},
handleMaximize: function(e) {
if (this.state.altDown) {
// maximize
this.props.handleMaximize(e);
} else {
this.props.handleFullScreen(e);
}
},
// simply prevent event
handleNop: function(e) {
e.preventDefault();
e.stopPropagation();
},
render: function() {
var classes = classNames('titlebar',
{
'webkit-draggable': this.state.draggable,
'alt': this.state.altDown,
});
// set default CSS
defaultcss('titlebar', style);
return (
React.createElement("div", {className: classes, id: "titlebar"},
React.createElement("div", {className: "titlebar-stoplight"},
React.createElement("div", {onDoubleClick: this.handleNop, onClick: this.props.handleClose, className: "titlebar-close"}),
React.createElement("div", {onDoubleClick: this.handleNop, onClick: this.props.handleMinimize, className: "titlebar-minimize"}),
React.createElement("div", {onDoubleClick: this.handleNop, onClick: this.handleMaximize, className: "titlebar-fullscreen"})
),
this.props.children
)
)
}
});