|
22 | 22 |
|
23 | 23 |
|
24 | 24 | $.widget("ui.contextmenu", {
|
25 |
| - version: "0.4.0", |
| 25 | + version: "0.4.1", |
26 | 26 | options: {
|
27 | 27 | delegate: "[data-menu]", // selector
|
28 | 28 | hide: { effect: "fadeOut", duration: "fast"},
|
29 | 29 | show: { effect: "slideDown", duration: "slow"},
|
| 30 | + position: null, // specify positional preferences. |
30 | 31 | ignoreParentSelect: true, // Don't trigger 'select' for sub-menu parents
|
31 | 32 | menu: null, // selector or jQuery or a function returning such
|
32 | 33 | preventSelect: false, // disable text selection of target
|
|
155 | 156 | self._closeMenu();
|
156 | 157 | }
|
157 | 158 | });
|
| 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 | + |
158 | 179 | // Finally display the popup
|
159 | 180 | $menu
|
160 | 181 | .show() // required to fix positioning error (issue #3)
|
161 | 182 | .css({
|
162 | 183 | position: "absolute",
|
163 | 184 | left: 0,
|
164 | 185 | top: 0
|
165 |
| - }).position({ |
166 |
| - my: "left top", |
167 |
| - at: "left bottom", |
168 |
| - of: parentTarget, |
169 |
| - collision: "fit" |
170 |
| - }).hide(); |
| 186 | + }).position(posOption).hide(); |
171 | 187 |
|
172 | 188 | this._show($menu, this.options.show, function(){
|
173 | 189 | self._trigger.call(self, "open", event);
|
|
0 commit comments