I have the following html in a MVC View
<div class="main-container">
<link href="/Content/styles.css" rel="stylesheet" />
<link href="/Content/contextmenu.css" rel="stylesheet" />
<div class="filemanager">
<div class="search">
<input type="search" placeholder="Find a file.." />
</div>
<div class="breadcrumbs"></div>
<ul class="data">
</ul>
@*<div class="nothingfound">
<div class="nofiles"></div>
<span>No files here.</span>
</div>*@
</div>
<script src="/Scripts/contextmenu.js"></script>
<script src="/Scripts/script.js"></script>
</div>
Then I have the following javascript code
function FileRightClick(item) {
// Show contextmenu
$("#copymenu").finish().toggle(100).css({ top: event.pageY + "px", left: event.pageX + "px" });
return false;
};
$(".main-container").bind("contextmenu", function (event) {
// Avoid the real one
event.preventDefault();
// Show contextmenu
$("#pastemenu").finish().toggle(100).
// In the right position (the mouse)
css({
top: event.pageY + "px",
left: event.pageX + "px"
});
});
<ul class="data"> gets populated by the files and folders, the <li> for each file contains the following piece of code oncontextmenu="return FileRightClick(this);" However if I right click anywhere on a file both menus will pop up. but if I right click anywhere where there is not a file or folder the #pastmenu is displayed.
How can I prevent both from be called or combine the FileRightClick into the $(".main-container")