Skip to content

Commit

Permalink
handle triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
rodneyrehm committed Jul 6, 2011
1 parent ce869f7 commit 9df6d2a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ <h2 id="commands">Demo: Context Menu triggered by right click</h2>
<strong>menu2</strong>
<em>(golf disabled)</em>
</div>
<div class="context-menu-two context-menu-disabled box menu-2">
<div class="context-menu-two context-menu-disabled box menu-2" id="menu2disabled">
<strong>menu2</strong>
<em>(disabled)</em>
</div>
Expand Down
16 changes: 16 additions & 0 deletions jquery.contextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// TODO
// document opt.appendTo
// document item.items for sub-menus
// document $.fn.contextMenu
// plain text - non-hover - item.name but no item.callback supplied.
// richtext - non-hover - if item.html supplied.
// allow registration of event-handlers on <input> commands to dynamically update the $menu
Expand Down Expand Up @@ -797,6 +798,21 @@ var // currently active contextMenu trigger
}
};

// handle contextMenu triggers
$.fn.contextMenu = function(operation) {
if (operation === undefined) {
this.first().trigger('contextmenu');
} else if (operation.x && operation.y) {
this.first().trigger(jQuery.Event("contextmenu", {pageX: operation.x, pageY: operation.y}));
} else if (operation) {
this.removeClass('context-menu-disabled');
} else if (!operation) {
this.addClass('context-menu-disabled');
}

return this;
};

// manage contextMenu instances
$.contextMenu = function(operation, options) {
if (typeof operation != 'string') {
Expand Down

0 comments on commit 9df6d2a

Please sign in to comment.