Skip to content

Commit 66f4876

Browse files
committed
Did commits by @jevzee for html5 events PR swisnl#205
1 parent cb918c5 commit 66f4876

File tree

1 file changed

+42
-11
lines changed

1 file changed

+42
-11
lines changed

src/jquery.contextMenu.js

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,17 @@ var // currently active contextMenu trigger
181181
// default callback
182182
callback: null,
183183
// list of contextMenu items
184-
items: {}
184+
items: {},
185+
domEventTypes: function () {
186+
var result = [];
187+
var domObj = $('div').get(0);
188+
$.each(domObj, function (key, val) {
189+
if (key.slice(0, 2) === 'on') {
190+
result.push(key.slice(2));
191+
}
192+
});
193+
return result;
194+
}
185195
},
186196
// mouse position for hover activation
187197
hoveract = {
@@ -1530,7 +1540,21 @@ function menuChildren(items, $children, counter) {
15301540
* <command>, <menuitem>, <hr>, <span>, <p> <input [text, radio, checkbox]>, <textarea>, <select> and of course <menu>.
15311541
* Everything else will be imported as an html node, which is not interfaced with contextMenu.
15321542
*/
1533-
1543+
1544+
1545+
var createTriggerEvent = function(eventname) {
1546+
return function() {
1547+
$node.trigger(eventname);
1548+
};
1549+
};
1550+
var get_events = function() {
1551+
var events = {},
1552+
to_handle = $.contextMenu.defaults.domEventTypes;
1553+
$.each(to_handle, function() {
1554+
events[this] = createTriggerEvent(this);
1555+
});
1556+
return events;
1557+
};
15341558
// http://www.whatwg.org/specs/web-apps/current-work/multipage/commands.html#concept-command
15351559
switch (nodeName) {
15361560
// http://www.whatwg.org/specs/web-apps/current-work/multipage/interactive-elements.html#the-menu-element
@@ -1546,7 +1570,7 @@ function menuChildren(items, $children, counter) {
15461570
item = {
15471571
name: $node.text(),
15481572
disabled: !!$node.attr('disabled'),
1549-
callback: (function(){ return function(){ $node.click(); }; })()
1573+
callback: createTriggerEvent('click')
15501574
};
15511575
break;
15521576

@@ -1562,7 +1586,7 @@ function menuChildren(items, $children, counter) {
15621586
name: $node.attr('label'),
15631587
disabled: !!$node.attr('disabled'),
15641588
icon: $node.attr('icon'),
1565-
callback: (function(){ return function(){ $node.click(); }; })()
1589+
callback: createTriggerEvent('click')
15661590
};
15671591
break;
15681592

@@ -1571,7 +1595,8 @@ function menuChildren(items, $children, counter) {
15711595
type: 'checkbox',
15721596
disabled: !!$node.attr('disabled'),
15731597
name: $node.attr('label'),
1574-
selected: !!$node.attr('checked')
1598+
selected: !!$node.attr('checked'),
1599+
events: get_events()
15751600
};
15761601
break;
15771602
case 'radio':
@@ -1581,7 +1606,8 @@ function menuChildren(items, $children, counter) {
15811606
name: $node.attr('label'),
15821607
radio: $node.attr('radiogroup'),
15831608
value: $node.attr('id'),
1584-
selected: !!$node.attr('checked')
1609+
selected: !!$node.attr('checked'),
1610+
events: get_events()
15851611
};
15861612
break;
15871613

@@ -1601,7 +1627,8 @@ function menuChildren(items, $children, counter) {
16011627
type: 'text',
16021628
name: label || inputLabel(node),
16031629
disabled: !!$node.attr('disabled'),
1604-
value: $node.val()
1630+
value: $node.val(),
1631+
events: get_events()
16051632
};
16061633
break;
16071634

@@ -1610,7 +1637,8 @@ function menuChildren(items, $children, counter) {
16101637
type: 'checkbox',
16111638
name: label || inputLabel(node),
16121639
disabled: !!$node.attr('disabled'),
1613-
selected: !!$node.attr('checked')
1640+
selected: !!$node.attr('checked'),
1641+
events: get_events()
16141642
};
16151643
break;
16161644

@@ -1621,7 +1649,8 @@ function menuChildren(items, $children, counter) {
16211649
disabled: !!$node.attr('disabled'),
16221650
radio: !!$node.attr('name'),
16231651
value: $node.val(),
1624-
selected: !!$node.attr('checked')
1652+
selected: !!$node.attr('checked'),
1653+
events: get_events()
16251654
};
16261655
break;
16271656

@@ -1637,7 +1666,8 @@ function menuChildren(items, $children, counter) {
16371666
name: label || inputLabel(node),
16381667
disabled: !!$node.attr('disabled'),
16391668
selected: $node.val(),
1640-
options: {}
1669+
options: {},
1670+
events: get_events()
16411671
};
16421672
$node.children().each(function(){
16431673
item.options[this.value] = $(this).text();
@@ -1649,7 +1679,8 @@ function menuChildren(items, $children, counter) {
16491679
type: 'textarea',
16501680
name: label || inputLabel(node),
16511681
disabled: !!$node.attr('disabled'),
1652-
value: $node.val()
1682+
value: $node.val(),
1683+
events: get_events()
16531684
};
16541685
break;
16551686

0 commit comments

Comments
 (0)