Skip to content

Commit e40e5fd

Browse files
unknownunknown
unknown
authored and
unknown
committed
Added position option - Issue 18 and 13
1 parent 1a8954a commit e40e5fd

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

jquery.ui-contextmenu.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222

2323

2424
$.widget("ui.contextmenu", {
25-
version: "0.4.0",
25+
version: "0.4.1",
2626
options: {
2727
delegate: "[data-menu]", // selector
2828
hide: { effect: "fadeOut", duration: "fast"},
2929
show: { effect: "slideDown", duration: "slow"},
30+
position: null, // specify positional preferences.
3031
ignoreParentSelect: true, // Don't trigger 'select' for sub-menu parents
3132
menu: null, // selector or jQuery or a function returning such
3233
preventSelect: false, // disable text selection of target
@@ -155,19 +156,34 @@
155156
self._closeMenu();
156157
}
157158
});
159+
160+
var posOption = this.options.position;
161+
162+
if (posOption == null) {
163+
posOption = {
164+
my: "left top",
165+
at: "left bottom",
166+
of: parentTarget,
167+
collision: "fit"
168+
}
169+
} else if (jQuery.isFunction(this.options.position)) {
170+
posOption = posOption(event, ui);
171+
} else {
172+
// do we need to add the of?
173+
var posTarget = posOption.of;
174+
if (posTarget == null) {
175+
posOption.of = parentTarget;
176+
}
177+
}
178+
158179
// Finally display the popup
159180
$menu
160181
.show() // required to fix positioning error (issue #3)
161182
.css({
162183
position: "absolute",
163184
left: 0,
164185
top: 0
165-
}).position({
166-
my: "left top",
167-
at: "left bottom",
168-
of: parentTarget,
169-
collision: "fit"
170-
}).hide();
186+
}).position(posOption).hide();
171187

172188
this._show($menu, this.options.show, function(){
173189
self._trigger.call(self, "open", event);

0 commit comments

Comments
 (0)