Skip to content

Commit c836061

Browse files
committed
Backport fixes from 2.0 branch.
1 parent a55b620 commit c836061

File tree

5 files changed

+37
-16
lines changed

5 files changed

+37
-16
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ $.contextMenu is published under the [MIT license](http://www.opensource.org/lic
100100
### Unreleased ###
101101

102102
* Remove executable bit from jquery.contextMenu.js (thanks @jacknagel)
103+
* Fixed a problem there was when using a function for icons (thanks @RareDevil)
104+
* Fixed a problem where submenus resized wrong (thanks @RareDevil)
105+
* 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))
106+
* Fixed regression of node name's not being appended to the label of input elements. (thanks @RareDevil)
107+
* Add check that root.$layer exists, to prevent calling hide() on an defined object. (thanks @andreasrosdal)
103108

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

dist/jquery.contextMenu.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* MIT License http://www.opensource.org/licenses/mit-license
1313
* GPL v3 http://opensource.org/licenses/GPL-3.0
1414
*
15-
* Date: 2015-11-07T19:34:40.001Z
15+
* Date: 2015-12-03T19:37:35.602Z
1616
*/
1717

1818
(function (factory) {
@@ -269,6 +269,14 @@
269269
return;
270270
}
271271

272+
// Let the current contextmenu decide if it should show or not based on its own trigger settings
273+
if (e.mouseButton !== undefined && e.data) {
274+
if (!(e.data.trigger == 'left' && e.mouseButton === 0) && !(e.data.trigger == 'right' && e.mouseButton === 2)) {
275+
// Mouse click is not valid.
276+
return;
277+
}
278+
}
279+
272280
// abort event if menu is visible for this trigger
273281
if ($this.hasClass('context-menu-active')) {
274282
return;
@@ -431,7 +439,7 @@
431439
var triggerAction = ((root.trigger === 'left' && button === 0) || (root.trigger === 'right' && button === 2));
432440

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

469477
if (target && triggerAction) {
470478
root.$trigger.one('contextmenu:hidden', function () {
471-
$(target).contextMenu({x: x, y: y});
479+
$(target).contextMenu({ x: x, y: y, button: button });
472480
});
473481
}
474482

@@ -1090,7 +1098,7 @@
10901098
$t.addClass('context-menu-html ' + root.classNames.notSelectable);
10911099
} else if (item.type) {
10921100
$label = $('<label></label>').appendTo($t);
1093-
createNameNode(item).appendTo($t);
1101+
createNameNode(item).appendTo($label);
10941102

10951103
$t.addClass('context-menu-input');
10961104
opt.hasTypes = true;
@@ -1190,7 +1198,7 @@
11901198
// add icons
11911199
if (item.icon) {
11921200
if ($.isFunction(item.icon)) {
1193-
item._icon = item.icon.call(this, $t, key, item);
1201+
item._icon = item.icon.call(this, this, $t, key, item);
11941202
} else {
11951203
item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
11961204

@@ -1279,7 +1287,7 @@
12791287

12801288
if ($.isFunction(item.icon)) {
12811289
$item.removeClass(item._icon);
1282-
item._icon = item.icon.call(this, $trigger, key, item);
1290+
item._icon = item.icon.call(this, $trigger, $item, key, item);
12831291
$item.addClass(item._icon);
12841292
}
12851293

@@ -1355,7 +1363,7 @@
13551363
if (operation === undefined) {
13561364
this.first().trigger('contextmenu');
13571365
} else if (operation.x !== undefined && operation.y !== undefined) {
1358-
this.first().trigger($.Event('contextmenu', {pageX: operation.x, pageY: operation.y}));
1366+
this.first().trigger($.Event('contextmenu', { pageX: operation.x, pageY: operation.y, mouseButton: operation.button }));
13591367
} else if (operation === 'hide') {
13601368
var $menu = this.first().data('contextMenu') ? this.first().data('contextMenu').$menu : null;
13611369
$menu && $menu.trigger('contextmenu:hide');

dist/jquery.contextMenu.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jquery.contextMenu.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/jquery.contextMenu.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,14 @@
269269
return;
270270
}
271271

272+
// Let the current contextmenu decide if it should show or not based on its own trigger settings
273+
if (e.mouseButton !== undefined && e.data) {
274+
if (!(e.data.trigger == 'left' && e.mouseButton === 0) && !(e.data.trigger == 'right' && e.mouseButton === 2)) {
275+
// Mouse click is not valid.
276+
return;
277+
}
278+
}
279+
272280
// abort event if menu is visible for this trigger
273281
if ($this.hasClass('context-menu-active')) {
274282
return;
@@ -431,7 +439,7 @@
431439
var triggerAction = ((root.trigger === 'left' && button === 0) || (root.trigger === 'right' && button === 2));
432440

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

469477
if (target && triggerAction) {
470478
root.$trigger.one('contextmenu:hidden', function () {
471-
$(target).contextMenu({x: x, y: y});
479+
$(target).contextMenu({ x: x, y: y, button: button });
472480
});
473481
}
474482

@@ -1090,7 +1098,7 @@
10901098
$t.addClass('context-menu-html ' + root.classNames.notSelectable);
10911099
} else if (item.type) {
10921100
$label = $('<label></label>').appendTo($t);
1093-
createNameNode(item).appendTo($t);
1101+
createNameNode(item).appendTo($label);
10941102

10951103
$t.addClass('context-menu-input');
10961104
opt.hasTypes = true;
@@ -1190,7 +1198,7 @@
11901198
// add icons
11911199
if (item.icon) {
11921200
if ($.isFunction(item.icon)) {
1193-
item._icon = item.icon.call(this, $t, key, item);
1201+
item._icon = item.icon.call(this, this, $t, key, item);
11941202
} else {
11951203
item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
11961204

@@ -1279,7 +1287,7 @@
12791287

12801288
if ($.isFunction(item.icon)) {
12811289
$item.removeClass(item._icon);
1282-
item._icon = item.icon.call(this, $trigger, key, item);
1290+
item._icon = item.icon.call(this, $trigger, $item, key, item);
12831291
$item.addClass(item._icon);
12841292
}
12851293

@@ -1355,7 +1363,7 @@
13551363
if (operation === undefined) {
13561364
this.first().trigger('contextmenu');
13571365
} else if (operation.x !== undefined && operation.y !== undefined) {
1358-
this.first().trigger($.Event('contextmenu', {pageX: operation.x, pageY: operation.y}));
1366+
this.first().trigger($.Event('contextmenu', { pageX: operation.x, pageY: operation.y, mouseButton: operation.button }));
13591367
} else if (operation === 'hide') {
13601368
var $menu = this.first().data('contextMenu') ? this.first().data('contextMenu').$menu : null;
13611369
$menu && $menu.trigger('contextmenu:hide');

0 commit comments

Comments
 (0)