Skip to content

Instantly share code, notes, and snippets.

@jojobyte
Forked from b1rdex/main.js
Created December 6, 2013 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jojobyte/7823216 to your computer and use it in GitHub Desktop.
Save jojobyte/7823216 to your computer and use it in GitHub Desktop.
$(function(
function Menu(cutLabel, copyLabel, pasteLabel) {
var gui = require('nw.gui')
, menu = new gui.Menu()
, cut = new gui.MenuItem({
label: cutLabel || "Cut"
, click: function() {
document.execCommand("cut");
console.log('Menu:', 'cutted to clipboard');
}
})
, copy = new gui.MenuItem({
label: copyLabel || "Copy"
, click: function() {
document.execCommand("copy");
console.log('Menu:', 'copied to clipboard');
}
})
, paste = new gui.MenuItem({
label: pasteLabel || "Paste"
, click: function() {
document.execCommand("paste");
console.log('Menu:', 'pasted to textarea');
}
})
;
menu.append(cut);
menu.append(copy);
menu.append(paste);
return menu;
}
var menu = new Menu(/* pass cut, copy, paste labels if you need i18n*/);
$(document).on("contextmenu", function(e) {
e.preventDefault();
menu.popup(e.originalEvent.x, e.originalEvent.y);
});
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment