-
Notifications
You must be signed in to change notification settings - Fork 0
/
winbar.js
52 lines (42 loc) · 1.84 KB
/
winbar.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
"use strict";
class WinBar {
constructor(window, elementName, title, ...extraClasses) {
this.elementName = '#' + elementName
this._title = title
let minBtn = $('<div/>').attr('id', 'winBar-btn-min').addClass('winBar-btn').html('').click(() => window.minimize())
let maxBtn = $('<div/>').attr('id', 'winBar-btn-max').addClass('winBar-btn').html('')
let restoreBtn = $('<div/>').attr('id', 'winBar-btn-restore').addClass('winBar-btn').html('')
let closeBtn = $('<div/>').attr('id', 'winBar-btn-close').addClass('winBar-btn').html('').click(() => window.close())
let toggleMaxRestoreButtons = () => {
if (window.isMaximized()) {
maxBtn.hide()
restoreBtn.css('display', 'flex')
} else {
maxBtn.css('display', 'flex')
restoreBtn.hide()
}
}
maxBtn.click(() => {
window.maximize()
toggleMaxRestoreButtons()
})
restoreBtn.click(() => {
window.unmaximize()
toggleMaxRestoreButtons()
})
$(this.elementName).empty().addClass(['winBar'].concat(extraClasses).join(' ')).append(
$('<div/>').attr('id', 'winBar-drag-region')
.append($('<div/>').attr('id', 'winBar-title').text(title))
.append(
$('<div/>').attr('id', 'winBar-controls')
.append(minBtn).append(maxBtn).append(restoreBtn).append(closeBtn)
)
)
toggleMaxRestoreButtons()
window.on('maximize', toggleMaxRestoreButtons)
window.on('unmaximize', toggleMaxRestoreButtons)
}
tempTitle(title) { $('#winBar-title').text(this._title + title) }
restoreTitle() { $('#winBar-title').text(this._title) }
}
module.exports = WinBar