Skip to content

Backport fixes from 2.0 branch. #318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ $.contextMenu is published under the [MIT license](http://www.opensource.org/lic
### Unreleased ###

* Remove executable bit from jquery.contextMenu.js (thanks @jacknagel)
* Fixed a problem there was when using a function for icons (thanks @RareDevil)
* Fixed a problem where submenus resized wrong (thanks @RareDevil)
* Fixed a problem where the contextmenu would open another menu (thanks @RareDevil) - ([Issue #252](https://github.com/swisnl/jQuery-contextMenu/issues/252) and [Issue #293](https://github.com/swisnl/jQuery-contextMenu/issues/293))
* Fixed regression of node name's not being appended to the label of input elements. (thanks @RareDevil)
* Add check that root.$layer exists, to prevent calling hide() on an defined object. (thanks @andreasrosdal)

### 1.10.2 (October 28th 2015) ###

Expand Down
22 changes: 15 additions & 7 deletions dist/jquery.contextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* MIT License http://www.opensource.org/licenses/mit-license
* GPL v3 http://opensource.org/licenses/GPL-3.0
*
* Date: 2015-11-07T19:34:40.001Z
* Date: 2015-12-03T19:37:35.602Z
*/

(function (factory) {
Expand Down Expand Up @@ -269,6 +269,14 @@
return;
}

// Let the current contextmenu decide if it should show or not based on its own trigger settings
if (e.mouseButton !== undefined && e.data) {
if (!(e.data.trigger == 'left' && e.mouseButton === 0) && !(e.data.trigger == 'right' && e.mouseButton === 2)) {
// Mouse click is not valid.
return;
}
}

// abort event if menu is visible for this trigger
if ($this.hasClass('context-menu-active')) {
return;
Expand Down Expand Up @@ -431,7 +439,7 @@
var triggerAction = ((root.trigger === 'left' && button === 0) || (root.trigger === 'right' && button === 2));

// find the element that would've been clicked, wasn't the layer in the way
if (document.elementFromPoint) {
if (document.elementFromPoint && root.$layer) {
root.$layer.hide();
target = document.elementFromPoint(x - $win.scrollLeft(), y - $win.scrollTop());
root.$layer.show();
Expand Down Expand Up @@ -468,7 +476,7 @@

if (target && triggerAction) {
root.$trigger.one('contextmenu:hidden', function () {
$(target).contextMenu({x: x, y: y});
$(target).contextMenu({ x: x, y: y, button: button });
});
}

Expand Down Expand Up @@ -1090,7 +1098,7 @@
$t.addClass('context-menu-html ' + root.classNames.notSelectable);
} else if (item.type) {
$label = $('<label></label>').appendTo($t);
createNameNode(item).appendTo($t);
createNameNode(item).appendTo($label);

$t.addClass('context-menu-input');
opt.hasTypes = true;
Expand Down Expand Up @@ -1190,7 +1198,7 @@
// add icons
if (item.icon) {
if ($.isFunction(item.icon)) {
item._icon = item.icon.call(this, $t, key, item);
item._icon = item.icon.call(this, this, $t, key, item);
} else {
item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;

Expand Down Expand Up @@ -1279,7 +1287,7 @@

if ($.isFunction(item.icon)) {
$item.removeClass(item._icon);
item._icon = item.icon.call(this, $trigger, key, item);
item._icon = item.icon.call(this, $trigger, $item, key, item);
$item.addClass(item._icon);
}

Expand Down Expand Up @@ -1355,7 +1363,7 @@
if (operation === undefined) {
this.first().trigger('contextmenu');
} else if (operation.x !== undefined && operation.y !== undefined) {
this.first().trigger($.Event('contextmenu', {pageX: operation.x, pageY: operation.y}));
this.first().trigger($.Event('contextmenu', { pageX: operation.x, pageY: operation.y, mouseButton: operation.button }));
} else if (operation === 'hide') {
var $menu = this.first().data('contextMenu') ? this.first().data('contextMenu').$menu : null;
$menu && $menu.trigger('contextmenu:hide');
Expand Down
4 changes: 2 additions & 2 deletions dist/jquery.contextMenu.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/jquery.contextMenu.min.js.map

Large diffs are not rendered by default.

20 changes: 14 additions & 6 deletions src/jquery.contextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,14 @@
return;
}

// Let the current contextmenu decide if it should show or not based on its own trigger settings
if (e.mouseButton !== undefined && e.data) {
if (!(e.data.trigger == 'left' && e.mouseButton === 0) && !(e.data.trigger == 'right' && e.mouseButton === 2)) {
// Mouse click is not valid.
return;
}
}

// abort event if menu is visible for this trigger
if ($this.hasClass('context-menu-active')) {
return;
Expand Down Expand Up @@ -431,7 +439,7 @@
var triggerAction = ((root.trigger === 'left' && button === 0) || (root.trigger === 'right' && button === 2));

// find the element that would've been clicked, wasn't the layer in the way
if (document.elementFromPoint) {
if (document.elementFromPoint && root.$layer) {
root.$layer.hide();
target = document.elementFromPoint(x - $win.scrollLeft(), y - $win.scrollTop());
root.$layer.show();
Expand Down Expand Up @@ -468,7 +476,7 @@

if (target && triggerAction) {
root.$trigger.one('contextmenu:hidden', function () {
$(target).contextMenu({x: x, y: y});
$(target).contextMenu({ x: x, y: y, button: button });
});
}

Expand Down Expand Up @@ -1090,7 +1098,7 @@
$t.addClass('context-menu-html ' + root.classNames.notSelectable);
} else if (item.type) {
$label = $('<label></label>').appendTo($t);
createNameNode(item).appendTo($t);
createNameNode(item).appendTo($label);

$t.addClass('context-menu-input');
opt.hasTypes = true;
Expand Down Expand Up @@ -1190,7 +1198,7 @@
// add icons
if (item.icon) {
if ($.isFunction(item.icon)) {
item._icon = item.icon.call(this, $t, key, item);
item._icon = item.icon.call(this, this, $t, key, item);
} else {
item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;

Expand Down Expand Up @@ -1279,7 +1287,7 @@

if ($.isFunction(item.icon)) {
$item.removeClass(item._icon);
item._icon = item.icon.call(this, $trigger, key, item);
item._icon = item.icon.call(this, $trigger, $item, key, item);
$item.addClass(item._icon);
}

Expand Down Expand Up @@ -1355,7 +1363,7 @@
if (operation === undefined) {
this.first().trigger('contextmenu');
} else if (operation.x !== undefined && operation.y !== undefined) {
this.first().trigger($.Event('contextmenu', {pageX: operation.x, pageY: operation.y}));
this.first().trigger($.Event('contextmenu', { pageX: operation.x, pageY: operation.y, mouseButton: operation.button }));
} else if (operation === 'hide') {
var $menu = this.first().data('contextMenu') ? this.first().data('contextMenu').$menu : null;
$menu && $menu.trigger('contextmenu:hide');
Expand Down