ggContextMenu
Plugin based on jquery that allows you to add contextual options (mouse right click) to elements of the DOM.
by GGaritaJ
HTML
<script src="https://www.ggaritaj.com"></script>
<script src="https://github.com/GGaritaJ/ggContextMenu"></script>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="Context Menu jQuery plugin" />
<meta name="author" content="GGaritaJ Gerardo Garita" />
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<meta http-equiv="X-Xss-Protection" content="'1; mode=block' always">
<meta http-equiv="X-Content-Type-Options" content="'nosniff' always">
<title>Context Menu jQuery plugin</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link href="css/contextMenu-1.0.css" rel="stylesheet" />
<link href="css/myStyle.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="js/contextMenu-1.0.js"></script>
<script src="js/myScript.js"></script>
<link rel="icon" href="favicon.ico" type="image/x-icon" />
</head>
<body>
<div id="mainContainer">
<!-- CONTENT : START -->
<div id="table-container" context-menu="menu1">
<table id="table1" class="table table-bordered table-condensed table-striped table-responsive">
<thead>
<tr>
<td>FIELD 1</td>
<td>FIELD 2</td>
...
CSS
#mainContainer {
padding:20px;
}
/*/////////////////////////////////////////////
// ggContextMenu JS/CSS PlugIn V1.0 //
// Developed by: Ing.Gerardo Garita J. //
// FullStack Developer //
// email: [email protected] //
// date: friday, 2018-09-10 //
// last date: friday, 2018-09-10 //
/////////////////////////////////////////////*/
.ggContextMenu {
font-family: Tahoma;
font-size: 14px;
display: none;
border: 1px solid #ddd;
border-radius: 8px;
position: fixed;
background-color: #f9f9f9;
padding: 9px;
max-width: 250px;
min-width: 200px;
max-height: 400px;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.ggContextMenu > label {
height: 25px;
width: 100%;
margin: 0px;
text-align: left;
color: #337ab7;
margin-bottom: 10px;
}
.ggContextMenu > div {
max-width: 250px;
max-height: 360px;
overflow: auto;
}
.ggContextMenu.active {
display: block;
box-shadow: 0 4px 5px 0 rgba(0, 0, 0, .14),
0 1px 10px 0 rgba(0, 0, 0, .12),
0 2px 4px -1px rgba(0, 0, 0, .2);
}
.ggContextMenu ul {
list-style-type:none;
}
.ggContextMenu div ul {
padding:0px;
margin:0px;
}
.ggContextMenu > div > ul {
margin-bottom: 1px;
}
.ggContextMenu > div > ul > li:not(:last-child) {
border-bottom: 1px solid #ddd;
}
.ggContextMenu li {
margin-bottom: 10px;
min-width: 100px;
}
.ggContextMenu li:last-child {
margin-bottom: 0px;
}
.ggContextMenu li:hover > span {
color: #e88d00;
}
.ggContextMenu li:hover {
cursor: pointer;
-webkit-transition: all 0.3s ease;
-moz-transition: all 0.3s ease;
transition: all 0.3s ease;
}
.ggContextMenu label span.glyphicon {
margin-right: 5px;
padding-right: 5px;
font-size: 18px;
}
.ggContextMenu li...
JavaScript
$(document).ready(function () {
$("[context-menu]").ggContextMenu();
});
///////////////////////////////////////////////
// ggContextMenu JS/CSS PlugIn V1.0 //
// Developed by: Ing.Gerardo Garita J. //
// FullStack Developer //
// email: [email protected] //
// date: friday, 2018-09-10 //
// last date: friday, 2018-09-10 //
///////////////////////////////////////////////
; (function ($) {
jQuery.fn.ggContextMenu = function () {
try {
$(this).each(function () {
$(this).contextmenu(function (event) {
event.preventDefault();
var menuId = ("#" + $(event.currentTarget).attr("context-menu"));
$("div.ggContextMenu").removeClass("active").removeAttr("style");
$(menuId).find(".active").removeClass("active");
_ggRelocateMenu(menuId, event.clientX, event.clientY);
$(menuId).addClass("active");
});
});
$("li.sub-level").on("click", function (event) {
var opts = $(this).find("div.sub-level")[0];
if (!$(opts).hasClass("active")) {
$(opts).addClass("active");
$(this).addClass("active");
var menuId = ("#" + $(event.currentTarget).closest(".ggContextMenu").attr("id"));
var pos = $(menuId).position();
_ggRelocateMenu(menuId, pos.left, pos.top);
} else if (!($(this).find("div").find(event.target).length == 0)){
$(opts).addClass("active");
$(this).addClass("active");
} else {
$(opts).removeClass("active");
$(this).removeClass("active");
}
});
$('html').unbind("click").on('click', function (event) {
if...