Skip to content

Commit c4bcf5c

Browse files
committed
New option closeOnWindowBlur
Close mar10#118
1 parent c966ac0 commit c4bcf5c

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
# 1.16.0-1 / Unreleased
1+
# 1.17.0-1 / Unreleased
22

33
* [FEATURE] #116 `autoFocus` skips leading disabled entries.
4+
* [FEATURE] #118 New option `closeOnWindowBlur`
45
* Use `.on()` / `.off()` syntax
56
* Add check for missing `.delegate` option
67

jquery.ui-contextmenu.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ $.widget("moogle.contextmenu", {
3434
version: "@VERSION",
3535
options: {
3636
addClass: "ui-contextmenu", // Add this class to the outer <ul>
37+
closeOnWindowBlur: true, // Close menu when window loses focus
3738
autoFocus: false, // Set keyboard focus to first entry on open
3839
autoTrigger: true, // open menu on browser's `contextmenu` event
3940
delegate: null, // selector
@@ -244,6 +245,11 @@ $.widget("moogle.contextmenu", {
244245
self._closeMenu();
245246
}
246247
});
248+
$(window).on("blur" + this.eventNamespace, function(event) {
249+
if ( opts.closeOnWindowBlur ) {
250+
self._closeMenu();
251+
}
252+
});
247253

248254
// required for custom positioning (issue #18 and #13).
249255
if ($.isFunction(posOption)) {
@@ -299,6 +305,8 @@ $.widget("moogle.contextmenu", {
299305
.off("mousedown" + this.eventNamespace)
300306
.off("touchstart" + this.eventNamespace)
301307
.off("keydown" + this.eventNamespace);
308+
$(window)
309+
.off("blur" + this.eventNamespace);
302310

303311
self.currentTarget = null; // issue #44 after hide animation is too late
304312
self.extraData = {};

0 commit comments

Comments
 (0)