forked from 2xAA/nwjs-menu-browser
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdemo.html
127 lines (116 loc) · 4.45 KB
/
demo.html
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<!DOCTYPE html>
<html>
<head>
<title>jsMenus example demo</title>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
<link type='text/css' rel='stylesheet' href='jsMenus.css'>
<script type='text/javascript' src='examples/screenfull.js'> </script>
<script type='text/javascript' src='jsMenus.js'> </script>
<style type="text/css">
.menubar > .menu-item > button { border: solid thin black; }
.menu-item, ul.contextmenu { background-color: lightyellow }
</style>
<script type='text/javascript'>
var fileMenu = new Menu();
var editMenu = new Menu();
var viewMenu = new Menu();
var helpMenu = new Menu();
let menuBar = new Menu({ type: 'menubar' });
menuBar.append(new MenuItem({label: 'File', submenu: fileMenu}));
menuBar.append(new MenuItem({label: 'Edit', submenu: editMenu}));
menuBar.append(new MenuItem({label: 'View', submenu: viewMenu}));
menuBar.append(new MenuItem({label: 'Help', submenu: helpMenu}));
var copyItem = new MenuItem({label: "Copy",
accelerator: 'CommandOrControl+C',
click: function() {
if (! document.execCommand("copy", false))
alert("execCommand copy failed");
}});
var pasteItem = new MenuItem({label: "Paste",
accelerator: 'CmdOrControl+V',
click: function() {
if (! document.execCommand("paste", false))
alert("execCommand paste failed");
}});
var showingMenuBar = true;
var showMenuBarItem = new MenuItem({
label: 'Show menubar',
type: 'checkbox',
click: function() {
showingMenuBar = ! showingMenuBar;
Menu.setApplicationMenu(showingMenuBar ? menuBar : null);
},
checked: true});
fileMenu.append(new MenuItem({
label: 'Clear console',
icon: 'examples/terminal.png',
key: 'D',
modifiers: 'cmd+shift+alt',
tooltip: 'This MenuItem actually does nothing!'}));
fileMenu.append(new MenuItem({
label: "Close",
click: function() {
alert("(close may be disallowed)");
window.close(); }}));
fileMenu.append(new MenuItem({
label: 'Save as...',
enabled: false
}));
var changeTitleMenu = new Menu();
function changeTitle(menuItem) {
document.title = "jsMenus title "+menuItem.label;
}
// if other code may change document.title add beforeShow handler
changeTitleMenu.append(new MenuItem({label: "demo", type: "radio",
checked: true, click: changeTitle}));
changeTitleMenu.append(new MenuItem({label: "example", type: "radio",
click: changeTitle}));
changeTitleMenu.append(new MenuItem({label: "test", type: "radio",
click: changeTitle}));
viewMenu.append(showMenuBarItem);
viewMenu.append(new MenuItem({
label: "Full Screen",
type: 'checkbox',
checked: false,
beforeShow: function(item) { item.checked = screenfull.isFullscreen; },
click: function() {
screenfull.toggle();
}}));
editMenu.append(copyItem);
editMenu.append(pasteItem);
editMenu.append(new MenuItem({type: 'separator'}));
editMenu.append(new MenuItem({label: "Change title", submenu: changeTitleMenu}));
var contextMenu = new Menu();
contextMenu.append(copyItem);
contextMenu.append(pasteItem);
contextMenu.append(new MenuItem({type: 'separator'}));
contextMenu.append(new MenuItem({label: "Change title", submenu: changeTitleMenu}));
contextMenu.append(showMenuBarItem);
const exitFullscreenItem = new MenuItem({
label: "Exit full screen",
visible: false, // hidden unless fullscreen
beforeShow: function(item) { item.visible = screenfull.isFullscreen; },
click: function() {
screenfull.exit();
}})
contextMenu.append(exitFullscreenItem);
function loadHandler() {
Menu.setApplicationMenu(menuBar);
document.addEventListener('contextmenu', (e) => {
e.preventDefault();
contextMenu.popup(e.clientX, e.clientY);
return false;
});
}
window.addEventListener("load", loadHandler, false);
</script>
</head>
<body>
<h1 contenteditable="true">Hello - jsMenus test!</h1>
<p>
This is a test of <a href="https://github.com/PerBothner/jsMenus">jsMenus</a>,
a JavaScript library for creating menus.
Try clicking on the menubar above, or bringing up the context menu
(usually by right-clicking).
</body>
</html>