jQuery Overall Context Menu
jQuery Context menu for an overall page based on certain elements
by Cody0913
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-contextmenu/2.4.2/jquery.ui.position.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-contextmenu/2.4.2/jquery.contextMenu.js"></script>
<script src="https://use.fontawesome.com/ff212c5d76.js"></script>
<body>
<div id="topmost">
<a id="test_URL" href="#">
<h1 id="test_Head">
Test
</h1>
<img src="https://i.vimeocdn.com/portrait/58832_300x300" width="50px" height="50px">
</a>
</div>
<div id="bottom">
<img src="https://i.vimeocdn.com/portrait/58832_300x300">
<button class="testButton">
Run
</button>
<input type="text">
</div>
</body>
CSS
body {
overflow: hidden;
margin: 0;
background: white;
display: block;
position: relative;
}
#topmost {
height: 200px;
background: grey;
width: 100%;
}
JavaScript
$(function() {
var posx;var posy;
document.onmousemove=function(e) {
var e=e||window.event;
posx=e.pageX||e.clientX+document.body.scrollLeft;
posy=e.pageY||e.clientY+document.body.scrollTop;
};
function createSomeMenu() {
var copy_site, copy_image;
var all_array = {};
var elementMouseIsOver = document.elementFromPoint(posx, posy);
if (elementMouseIsOver.closest('a')) {
all_array["Link-Fold"] = {
name: "Link",
icon: "fa-external-link",
items: {
"fold1-key1": {
name: "Open Site in New Tab",
icon: "fa-external-link-square",
callback: function(key, option) {
alert('Attempted to open ' + elementMouseIsOver.closest('a').getAttribute("href") + ' in a new tab');
}
},
"fold2-key1": {
name: "Open Site in Split Tab",
icon: "fa-arrows-h",
callback: function(key, option) {
alert('Attempted to open ' + elementMouseIsOver.closest('a').getAttribute("href") + ' in a split tab');
}
}
}
};
copy_site = true;
}
if (elementMouseIsOver.closest('img')) {
all_array["Image-Fold"] = {
name: "Image",
icon: "fa-picture-o",
items: {
"fold2-key1": {
name: "Download Image",
icon: "fa-download"
},
"fold2-key3": {
name: "Go To Image",
icon: "fa-file-image-o",
callback: function(key, option) {
window.location.href = elementMouseIsOver.closest('img').getAttribute("src");
}
}
}
};
copy_image = true;
}
if (copy_site) {
all_array["copy_url"] = {
name: "Copy URL",
icon: "fa-link",
callback: function(key, option) {
alert(elementMouseIsOver.closest('a').getAttribute("href"));
}
};
}
if (copy_image) {
...