Skip to content

Commit d79132f

Browse files
committed
Merge pull request #327 from swisnl/finalize-pull-request-zindex
Finalize pull request zindex
2 parents 51db735 + 6784e46 commit d79132f

File tree

6 files changed

+22
-10
lines changed

6 files changed

+22
-10
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ Font-Awesome icons used from [encharm/Font-Awesome-SVG-PNG](https://github.com/e
106106
### Unreleased ###
107107

108108
* Fixed a swith to use the correct type for separators (thanks @RareDevil)
109+
* Added support for providing a function as zIndex value in options object (thanks @eivindga)
109110

110111
### 2.0.1 (December 3rd 2015) ###
111112

dist/jquery.contextMenu.js

+8-3
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-12-17T20:34:43.837Z
15+
* Date: 2015-12-20T18:49:14.965Z
1616
*/
1717

1818
(function (factory) {
@@ -268,7 +268,7 @@
268268
if ((e.data.trigger !== 'right' && e.data.trigger !== 'demand') && e.originalEvent) {
269269
return;
270270
}
271-
271+
272272
// Let the current contextmenu decide if it should show or not based on its own trigger settings
273273
if (e.mouseButton !== undefined && e.data) {
274274
if (!(e.data.trigger == 'left' && e.mouseButton === 0) && !(e.data.trigger == 'right' && e.mouseButton === 2)) {
@@ -897,7 +897,12 @@
897897

898898
// make sure we're in front
899899
if (opt.zIndex) {
900-
css.zIndex = zindex($trigger) + opt.zIndex;
900+
var additionalZValue = opt.zIndex;
901+
// If opt.zIndex is a function, call the function to get the right zIndex.
902+
if (typeof opt.zIndex === 'function') {
903+
additionalZValue = opt.zIndex.call($trigger, opt);
904+
}
905+
css.zIndex = zindex($trigger) + additionalZValue;
901906
}
902907

903908
// add layer

dist/jquery.contextMenu.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jquery.contextMenu.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

documentation/docs.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,22 @@ $.contextMenu({
184184

185185
### zIndex
186186

187-
Specifies the offset to add to the calculated zIndex of the [trigger](#trigger) element. Set to `0` to prevent zIndex manipulation
187+
Specifies the offset to add to the calculated zIndex of the [trigger](#trigger) element. Set to `0` to prevent zIndex manipulation. Can be a function that returns an int to calculate the zIndex on build.
188188

189-
`zIndex`: `int` default: `1`
189+
`zIndex`: `int`|`function` default: `1`
190190

191191
#### Example
192192
```javascript
193193
$.contextMenu({
194194
selector: 'span.context-menu',
195195
zIndex: 10
196196
});
197+
198+
$.contextMenu({
199+
selector: 'span.context-menu',
200+
zIndex: function($trigger, opt){
201+
return 120;
202+
});
197203
```
198204
199205
### className

src/jquery.contextMenu.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -899,8 +899,8 @@
899899
if (opt.zIndex) {
900900
var additionalZValue = opt.zIndex;
901901
// If opt.zIndex is a function, call the function to get the right zIndex.
902-
if (typeof opt.zIndex === "function") {
903-
additionalZValue = opt.zIndex.call(this);
902+
if (typeof opt.zIndex === 'function') {
903+
additionalZValue = opt.zIndex.call($trigger, opt);
904904
}
905905
css.zIndex = zindex($trigger) + additionalZValue;
906906
}

0 commit comments

Comments
 (0)