|
22 | 22 |
|
23 | 23 |
|
24 | 24 | $.widget("ui.contextmenu", { |
25 | | - version: "0.4.0", |
| 25 | + version: "0.4.1", |
26 | 26 | options: { |
27 | | - delegate: "[data-menu]", // selector |
| 27 | + delegate: "[data-menu]", // selector |
28 | 28 | hide: { effect: "fadeOut", duration: "fast"}, |
29 | 29 | show: { effect: "slideDown", duration: "slow"}, |
30 | | - ignoreParentSelect: true, // Don't trigger 'select' for sub-menu parents |
31 | | - menu: null, // selector or jQuery or a function returning such |
32 | | - preventSelect: false, // disable text selection of target |
33 | | - taphold: false, // open menu on taphold events (requires external plugins) |
| 30 | + position: null, // specify positional preferences (added for issue #18 and #13). |
| 31 | + ignoreParentSelect: true, // Don't trigger 'select' for sub-menu parents |
| 32 | + menu: null, // selector or jQuery or a function returning such |
| 33 | + preventSelect: false, // disable text selection of target |
| 34 | + taphold: false, // open menu on taphold events (requires external plugins) |
34 | 35 | // Events: |
35 | | - beforeOpen: $.noop, // menu about to open; return `false` to prevent opening |
36 | | - blur: $.noop, // menu option lost focus |
37 | | - close: $.noop, // menu was closed |
38 | | - create: $.noop, // menu was initialized |
39 | | - focus: $.noop, // menu option got focus |
40 | | - init: $.noop, // ui-contextmenu was initialized |
41 | | - open: $.noop, // menu was opened |
42 | | - select: $.noop // menu option was selected; return `false` to prevent closing |
| 36 | + beforeOpen: $.noop, // menu about to open; return `false` to prevent opening |
| 37 | + blur: $.noop, // menu option lost focus |
| 38 | + close: $.noop, // menu was closed |
| 39 | + create: $.noop, // menu was initialized |
| 40 | + focus: $.noop, // menu option got focus |
| 41 | + init: $.noop, // ui-contextmenu was initialized |
| 42 | + open: $.noop, // menu was opened |
| 43 | + select: $.noop // menu option was selected; return `false` to prevent closing |
43 | 44 | }, |
44 | 45 | /** Construtcor */ |
45 | 46 | _create: function () { |
|
155 | 156 | self._closeMenu(); |
156 | 157 | } |
157 | 158 | }); |
| 159 | + |
| 160 | + // required for custom positioning (issue #18 and #13). |
| 161 | + var posOption = this.options.position; |
| 162 | + |
| 163 | + if (posOption == null) { |
| 164 | + posOption = { |
| 165 | + my: "left top", |
| 166 | + at: "left bottom", |
| 167 | + of: parentTarget, |
| 168 | + collision: "fit" |
| 169 | + } |
| 170 | + } else if (jQuery.isFunction(this.options.position)) { |
| 171 | + posOption = posOption(event, ui); |
| 172 | + } else { |
| 173 | + // do we need to add the of? |
| 174 | + var posTarget = posOption.of; |
| 175 | + if (posTarget == null) { |
| 176 | + posOption.of = parentTarget; |
| 177 | + } |
| 178 | + } |
| 179 | + |
158 | 180 | // Finally display the popup |
159 | 181 | $menu |
160 | 182 | .show() // required to fix positioning error (issue #3) |
161 | 183 | .css({ |
162 | 184 | position: "absolute", |
163 | 185 | left: 0, |
164 | 186 | top: 0 |
165 | | - }).position({ |
166 | | - my: "left top", |
167 | | - at: "left bottom", |
168 | | - of: parentTarget, |
169 | | - collision: "fit" |
170 | | - }).hide(); |
| 187 | + }).position(posOption).hide(); |
171 | 188 |
|
172 | 189 | this._show($menu, this.options.show, function(){ |
173 | 190 | self._trigger.call(self, "open", event); |
|
232 | 249 | $menu.menu("refresh"); |
233 | 250 | }else{ |
234 | 251 | $.error("not implemented"); |
235 | | -// this.orgMenu = opts.menu; |
236 | | -// opts.menu = $.ui.contextmenu.createMenuMarkup(data); |
| 252 | +// this.orgMenu = opts.menu; |
| 253 | +// opts.menu = $.ui.contextmenu.createMenuMarkup(data); |
237 | 254 | } |
238 | 255 | }else{ |
239 | | -// if(this.orgMenu){ |
240 | | -// // re-use existing temporary <ul> |
241 | | -// }else{ |
242 | | -// } |
243 | | -// $menu.menu("option", "menu", opts.menu); |
| 256 | +// if(this.orgMenu){ |
| 257 | +// // re-use existing temporary <ul> |
| 258 | +// }else{ |
| 259 | +// } |
| 260 | +// $menu.menu("option", "menu", opts.menu); |
244 | 261 | $.error("not implemented"); |
245 | 262 | } |
246 | 263 | }, |
|
0 commit comments