Last active
April 29, 2016 06:16
-
-
Save BraynStorm/2361fadb56b03b1222668a06bd0a6de8 to your computer and use it in GitHub Desktop.
JS Context-menu helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Context Menu JS Test</title> | |
<link href="context-menu.css" rel="stylesheet"/> | |
<script src="../crude-jquery/crude-jquery.js"></script> | |
<script src="context-menu.js"></script> | |
<script> | |
'use strict'; | |
var stuff = {}; | |
function f (e) { | |
debug(e); | |
} | |
function main () { | |
stuff.menu1 = new ContextMenu("#context-menu"); | |
stuff.menu1.addListChoice("Invite to room", f); | |
stuff.menu1.addListChoice("Freak out", f); | |
stuff.menu1.addListChoice("Chat", f); | |
stuff.menu1.addSeparator(); | |
stuff.menu1.addListChoice("Broadcast", f); | |
stuff.menu1.addListChoice("Smite!", f); | |
var playerName = $("#clickMe"); | |
playerName.onContextMenu(function (e) { | |
stuff.menu1.setPosition(e.pageX - 5, e.pageY - 5); | |
stuff.menu1.open(); | |
e.preventDefault(); | |
return false; | |
}); | |
} | |
</script> | |
<style> | |
#clickMe { | |
width: 100px; | |
height: 100px; | |
background: yellow; | |
} | |
</style> | |
</head> | |
<body onload="main()"> | |
<div id="clickMe">Click Me!</div> | |
<div id="context-menu"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment