Skip to content

Commit f8011a4

Browse files
committed
pass jshint and prepare 0.4.0
2 parents 554bbb4 + 54585de commit f8011a4

File tree

5 files changed

+69
-32
lines changed

5 files changed

+69
-32
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# 0.4.0 / Unreleased
1+
# 0.5.0 / Unreleased
2+
3+
*
4+
5+
# 0.4.0 / 2013-05-28
26

37
* [FEATURE] `position` option (thanks to Jeffrey Dean Altemus)
48

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,19 @@ structure (see [jQueryUI menu] for details):
129129
If an array of objects is passed, it will be used to generate
130130
such markup on the fly.
131131
</dd>
132+
<dt>position</dt>
133+
<dd>
134+
Type: <code>Object | Function</code>, default: <code>{my: "left top", at: "left bottom", of: parentTarget, collision: "fit"}</code><br>
135+
Define position where popup opens. A simple <a href="http://api.jqueryui.com/position/">position</a> may be passed.<br>
136+
Also a function may be specified, to recalculate position every time:<br>
137+
<pre><code>
138+
$("#container").contextmenu({
139+
// position: {my: "left bottom", at: "right top"},
140+
position: function(event, ui){
141+
return {my: "left top", at: "center", of: event};
142+
},
143+
</code></pre>
144+
</dd>
132145
<dt>preventSelect</dt>
133146
<dd>
134147
Type: <code>Boolean</code>, default: <code>false</code><br>

demo/index.html

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@
112112
$("#container").contextmenu({
113113
delegate: ".hasmenu2",
114114
menu: "#options",
115+
// position: {my: "left bottom", at: "right top"},
116+
position: function(event, ui){
117+
return {my: "left top", at: "center", of: event};
118+
},
115119
preventSelect: true,
116120
taphold: true,
117121
hide: { effect: "explode", duration: "slow" },
@@ -154,24 +158,29 @@ <h1>jquery.ui-contextmenu.js</h1>
154158

155159
<p><a href="https://github.com/mar10/jquery-ui-contextmenu">View project on GitHub</a></p>
156160

157-
Not-so-obvious features:
161+
<h3>Sample 1</h3>
158162
<ul>
163+
<li>Initialized using a command-array.
164+
<li>The menu is modified in the `beforeOpen` event (disabling an renaming entries).
159165
<li>`preventSelect: true` prevents accidential selection of the menu
160166
targets (i.e. 'AAA') when double-clicking or dragging the mouse.
161167
<li>`taphold: true` enables long-press to open the menu (useful on
162168
tablet computers).
163169
<li>Ctrl+Click or two-finger-click on the touchpad also works (MacBook).
164-
<li>The menu is modified in the `beforeOpen` event.
165170
</ul>
166-
167-
<p>Right-click in an element to open the context menu (initialized by command-array):</p>
171+
<p>Right-click in an element to open the context menu:</p>
168172
<div>
169173
<span class="hasmenu">AAA</span>
170174
<span class="hasmenu">BBB</span>
171175
<span class="hasmenu">CCC</span>
172176
</div>
173177

174-
<p>Right-click in an element to open the context menu (initialized by hidden &lt;ul> element):</p>
178+
<h3>Sample 2</h3>
179+
<ul>
180+
<li>Initialized by hidden &lt;ul> element.
181+
<li>Use custom show/hide effects.
182+
<li>Define custom position.
183+
</ul>
175184
<div id="container">
176185
<span class="hasmenu2">AAA</span>
177186
<span class="hasmenu2">BBB</span>
@@ -190,6 +199,7 @@ <h1>jquery.ui-contextmenu.js</h1>
190199
</ul>
191200
</ul>
192201

202+
<h3>Sample 3</h3>
193203
<p>Open context menu using <code>$("#container").contextmenu("open", $(".hasmenu:first"))</code> and close after 2 sec.:</p>
194204
<button id="triggerPopup">Trigger popup</button>
195205
</body>

jquery.ui-contextmenu.js

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,23 @@
1919
$.widget("ui.contextmenu", {
2020
version: "0.4.0",
2121
options: {
22-
delegate: "[data-menu]", // selector
22+
delegate: "[data-menu]", // selector
2323
hide: { effect: "fadeOut", duration: "fast"},
2424
show: { effect: "slideDown", duration: "slow"},
25+
position: null, // specify positional preferences (added for issue #18 and #13).
2526
ignoreParentSelect: true, // Don't trigger 'select' for sub-menu parents
2627
menu: null, // selector or jQuery or a function returning such
2728
preventSelect: false, // disable text selection of target
28-
taphold: false, // open menu on taphold events (requires external plugins)
29+
taphold: false, // open menu on taphold events (requires external plugins)
2930
// Events:
30-
beforeOpen: $.noop, // menu about to open; return `false` to prevent opening
31-
blur: $.noop, // menu option lost focus
32-
close: $.noop, // menu was closed
33-
create: $.noop, // menu was initialized
34-
focus: $.noop, // menu option got focus
35-
init: $.noop, // ui-contextmenu was initialized
36-
open: $.noop, // menu was opened
37-
select: $.noop // menu option was selected; return `false` to prevent closing
31+
beforeOpen: $.noop, // menu about to open; return `false` to prevent opening
32+
blur: $.noop, // menu option lost focus
33+
close: $.noop, // menu was closed
34+
create: $.noop, // menu was initialized
35+
focus: $.noop, // menu option got focus
36+
init: $.noop, // ui-contextmenu was initialized
37+
open: $.noop, // menu was opened
38+
select: $.noop // menu option was selected; return `false` to prevent closing
3839
},
3940
/** Construtcor */
4041
_create: function () {
@@ -122,7 +123,9 @@
122123
},
123124
/** Open popup (called on 'contextmenu' event). */
124125
_openMenu: function(event){
125-
var self = this,
126+
var opts = this.options,
127+
posOption = opts.position,
128+
self = this,
126129
$menu = this._getMenu(),
127130
openEvent = event,
128131
// if called by 'open' method, 'relatedTarget' is the requested target object
@@ -150,19 +153,26 @@
150153
self._closeMenu();
151154
}
152155
});
156+
157+
// required for custom positioning (issue #18 and #13).
158+
if ($.isFunction(posOption)) {
159+
posOption = posOption(event, ui);
160+
}
161+
posOption = $.extend({
162+
my: "left top",
163+
at: "left bottom",
164+
of: parentTarget,
165+
collision: "fit"
166+
}, posOption);
167+
153168
// Finally display the popup
154169
$menu
155170
.show() // required to fix positioning error (issue #3)
156171
.css({
157172
position: "absolute",
158173
left: 0,
159174
top: 0
160-
}).position({
161-
my: "left top",
162-
at: "left bottom",
163-
of: parentTarget,
164-
collision: "fit"
165-
}).hide();
175+
}).position(posOption).hide();
166176

167177
this._show($menu, this.options.show, function(){
168178
self._trigger.call(self, "open", event);
@@ -227,15 +237,15 @@
227237
$menu.menu("refresh");
228238
}else{
229239
$.error("not implemented");
230-
// this.orgMenu = opts.menu;
231-
// opts.menu = $.ui.contextmenu.createMenuMarkup(data);
240+
// this.orgMenu = opts.menu;
241+
// opts.menu = $.ui.contextmenu.createMenuMarkup(data);
232242
}
233243
}else{
234-
// if(this.orgMenu){
235-
// // re-use existing temporary <ul>
236-
// }else{
237-
// }
238-
// $menu.menu("option", "menu", opts.menu);
244+
// if(this.orgMenu){
245+
// // re-use existing temporary <ul>
246+
// }else{
247+
// }
248+
// $menu.menu("option", "menu", opts.menu);
239249
$.error("not implemented");
240250
}
241251
},

jquery.ui-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.

0 commit comments

Comments
 (0)