|
| 1 | +var gui = require("nw.gui"); |
| 2 | + |
| 3 | +// Extend application menu for Mac OS |
| 4 | +if (process.platform == "darwin") { |
| 5 | + var menu = new gui.Menu({type: "menubar"}); |
| 6 | + menu.createMacBuiltin && menu.createMacBuiltin(window.document.title); |
| 7 | + gui.Window.get().menu = menu; |
| 8 | +} |
| 9 | + |
1 | 10 | function updateCheckbox() { |
2 | 11 | var top_checkbox = document.getElementById("top-box"); |
3 | 12 | var bottom_checkbox = document.getElementById("bottom-box"); |
@@ -36,27 +45,47 @@ function initCheckbox(checkboxId, titlebar_name, titlebar_icon_url, titlebar_tex |
36 | 45 | window.onfocus = function() { |
37 | 46 | console.log("focus"); |
38 | 47 | focusTitlebars(true); |
39 | | -} |
| 48 | +}; |
40 | 49 |
|
41 | 50 | window.onblur = function() { |
42 | 51 | console.log("blur"); |
43 | 52 | focusTitlebars(false); |
44 | | -} |
| 53 | +}; |
45 | 54 |
|
46 | 55 | window.onresize = function() { |
47 | 56 | updateContentStyle(); |
48 | | -} |
| 57 | +}; |
49 | 58 |
|
50 | 59 | window.onload = function() { |
| 60 | + |
51 | 61 | initCheckbox("top-box", "top-titlebar", "top-titlebar.png", "Top Titlebar"); |
52 | 62 | initCheckbox("bottom-box", "bottom-titlebar", "bottom-titlebar.png", "Bottom Titlebar"); |
53 | 63 | initCheckbox("left-box", "left-titlebar", "left-titlebar.png", "Left Titlebar"); |
54 | 64 | initCheckbox("right-box", "right-titlebar", "right-titlebar.png", "Right Titlebar"); |
55 | | - |
| 65 | + |
56 | 66 | document.getElementById("close-window-button").onclick = function() { |
57 | 67 | window.close(); |
58 | | - } |
59 | | - |
| 68 | + }; |
| 69 | + |
| 70 | + document.querySelector('#minimize-window-button').onclick = function () { |
| 71 | + gui.Window.get().minimize(); |
| 72 | + }; |
| 73 | + |
| 74 | + document.querySelector('#maximize-window-button').onclick = function () { |
| 75 | + gui.Window.get().maximize(); |
| 76 | + }; |
| 77 | + |
| 78 | + document.querySelector('#open-inspector-button').onclick = function () { |
| 79 | + var win = gui.Window.get(); |
| 80 | + if (win.isDevToolsOpen()) { |
| 81 | + win.closeDevTools(); |
| 82 | + this.innerText = "Open Developer Tools"; |
| 83 | + } else { |
| 84 | + win.showDevTools(); |
| 85 | + this.innerText = "Close Developer Tools"; |
| 86 | + } |
| 87 | + }; |
| 88 | + |
60 | 89 | updateContentStyle(); |
61 | | - require("nw.gui").Window.get().show(); |
62 | | -} |
| 90 | + gui.Window.get().show(); |
| 91 | +}; |
0 commit comments