Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
124 lines (112 sloc) 4.3 KB
<!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>
</head>
<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: 'CommandOrControl+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>
<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>
You can’t perform that action at this time.