From 5882e2ac2028da878a814e59aed05c8056f53925 Mon Sep 17 00:00:00 2001
From: Donovan Buck
Date: Thu, 30 Aug 2012 15:10:42 -0500
Subject: [PATCH 1/2] Passing opt as data to jQuery.Event
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
I want to be able to access the $trigger element in the items.events handlers.
In my case, when a user triggers a change event on an input type=select I want my change handler to know which dom element triggered the contextual menu.
Passing this to the jQuery event exposes it within the handler as:
e.data.$triggerÂ
At first blush this seems like an awful lot to pass along to the handler, but it mimics the behavior of item.callback
---
src/jquery.contextMenu.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/jquery.contextMenu.js b/src/jquery.contextMenu.js
index e6744f90..ea5bccff 100755
--- a/src/jquery.contextMenu.js
+++ b/src/jquery.contextMenu.js
@@ -1051,7 +1051,7 @@ var // currently active contextMenu trigger
.on('blur', handle.blurInput);
if (item.events) {
- $input.on(item.events);
+ $input.on(item.events, opt);
}
}
From e91d7927ca4949c170af754f64a0edc11ef921a6 Mon Sep 17 00:00:00 2001
From: Donovan Buck
Date: Thu, 30 Aug 2012 15:34:04 -0500
Subject: [PATCH 2/2] options.object contents are passed to event.data
---
docs.html | 2 ++
1 file changed, 2 insertions(+)
diff --git a/docs.html b/docs.html
index 63f2f0d0..a5ce603c 100755
--- a/docs.html
+++ b/docs.html
@@ -252,6 +252,8 @@ options.items
Events to register on <input> elements
Only used with types "text", "textarea", "radio", "checkbox" and "select".
Example: { command1: {name: "Foobar", type: "text", events: {keyup: function(e){alert(e.keyCode);}} }}
+ The contents of the options object are passed to jQuery event.data.
+ Example: { command1: {name: "Foobar", type: "text", events: {keyup: function(e){alert(e.data.$trigger.attr("id"));}} }}
(string) value