Download
User Rating: 0/5 ( 0 votes)
contextMenu.js is a plugin to create windows like context menu with keyboard interaction, different type of inputs ,trigger events and much more.
Why contextMenu.js ?
-
Use as simple popup or as a context menu. With some twick can be used for multi purpose.
-
Adjust position and size to fit in viewport.
-
Keyboard interaction.
-
Support different type of inputs (json, UL list).
-
Trigger Context menu with right-click, left-click,hover or any other mouse events.
-
Css outside of javascript so you can edit the look of menu.
-
Enable/disable options.
-
Optional icons for commands.
-
Lot of configurable options.
-
Submenus
Source: ignitersworld.com
1. INCLUDE JS FILES
<link href="assets/css/contextMenu.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script src="assets/js/contextMenuScript.js"></script>
2. HTML
<div class="testButton" id="testButton1">Click me</div>
3. JAVASCRIPT
var menu = [{
name: 'create',
img: 'images/create.png',
title: 'create button',
fun: function () {
alert('i am add button')
}
}, {
name: 'update',
img: 'images/update.png',
title: 'update button',
fun: function () {
alert('i am update button')
}
}, {
name: 'delete',
img: 'images/delete.png',
title: 'create button',
fun: function () {
alert('i am add button')
}
}];
//Calling context menu
$('.testButton').contextMenu(menu);
4. OPTIONS
Option |
Default |
Allowed |
Description |
triggerOn |
click |
click,hover, mousemove, dblclick and all mouse events |
Event in which context menu is binded with a trigger. |
displayAround |
cursor |
cursor , trigger (button) |
Display context menu around cursor position or trigger position |
mouseClick |
left |
left,right |
which mouse button to trigger context menu if trigger event is mouse click or mouse up event. |
verAdjust |
0 |
Numeric value |
Adjusting the vertical distance from its original pixel. |
horAdjust |
0 |
Numeric value |
Adjusting the horizontal distance from its original pixel. |
top |
auto |
auto,top position in px or % |
Defines the exact top position relative to the containment where menu to be shown. |
left |
auto |
auto,top position in px or % |
Defines the exact left position relative to the containment where menu to be shown. |
containment |
window |
window, any selector,jquery object, document object |
Define the container inside which context menu will be contained. |
winEventClose |
true |
true,false |
If true close the context menu on window scroll and resize event. |
sizeStyle |
auto |
auto, content |
If auto, size of context menu depends on browser size and options you selected. If content size depends on content width and height. |
position |
auto |
auto,left,right,top,bottom |
Context menu adjust according to viewport. If other than auto is given it ill force contenxt menu to be on that position. It is considered only when displayAround is set to trigger. |
5. METHODS
Method |
Description |
menu |
This mode is used to show context menu. Keyboard interaction and sub menus are activated in this mode. |
popup |
If you just want to display an popup window at your trigger point popup mode serve best. This will just show element defined in selector while adjusting it according to view port. |
update |
This mode is used to update the menu items (like enabling, disabling, icon change and function) and configuration option. |
refresh |
If new trigger with specific selector is added, this method is used to initialize context menu on those newly added elements. |
destroy |
Remove context menu instance for that trigger completely. |
close |
To manually close context menu. |
Popup method is default when selector type is selector string , jquery object, DOM object. Menu method is default when selector type is JSON object.
6. CALLBACKS
Callback |
Description |
onOpen |
This is called just before context menu opens. |
afterOpen |
This is called after context menu opens. |
onClose |
This is called just after context menu is closed. |
Callback accept two argument.
1. data : Which containg refrence to trigger and menu.
You can get trigger and menu using data.trigger and data.menu.
2. event : A event object which is binded with trigger to open context menu.
Inside callback this refers to trigger element.