I'm using this jquery plugin. The instantiation of the menu looks like this:
$.contextMenu({
selector:'.disposition-menu',
zIndex: 120,
callback: function(key, options) {
var stepID = $(this).closest('.card').attr("id").substring(5);
handle_disposition(key,stepID);
},
items: {
"pin": {name: "Pin to top"},
"unpin": {name:"Unpin"},
"complete": {name: "Mark step completed"},
"remove": {name: "Remove step from Map"},
},
events: {
show: function(){}, //this is where I'm lost
hide: function(){} //this is where I'm lost
},
trigger: 'hover'
});
The 'handle disposition' function interacts with php and the database to record the '.card' as pinned or unpinned in the database so that it appears properly when the page is reloaded. The HTML is a bootstrap 4 card like this:
<div class="card" >
<div class="card-header ">
<table class="title-table">
<tr>
<td>...</td>
<td>...</td>
<td>...</td>
<td class="disposition-menu">⋮</td>
</tr>
</table>
</div>
<div class="card-body">
...{body content}
</div>
</div>
What I am trying to do is toggle between the pin and unpin menu items. Only one of these should appear on the menu at a time. If the item is already "pinned" (i.e. flagged in database, and represented by a data attribute in the '.card' html) then "Unpin" should appear...and vice versa. Similarly as soon as the "Pin..." is clicked on the menu, the menu should immediately be changed to hide the "Pin" item and expose the "Unpin" item and vice versa
I've looked at the documentation for the plugin, but I'm a bit of a newbie when it comes to using functions after the keys with colons (eg selector: ) and callbacks. The plugin apparently has a "visible:" key, and also "show:" and "hide:" keys (used as per this issue, but I'm at a loss as to how to string these elements together to accomplish my objective.