Skip to content

Commit 3b06455

Browse files
committed
Added update call to update visibility, disabled, icon and form value stats for items. Fixes issue Issue #555
1 parent df2480e commit 3b06455

File tree

5 files changed

+37
-7
lines changed

5 files changed

+37
-7
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
* Ability to define touchstart as trigger (thanks @npuser)
88
* Extra event `activated` that triggers after the menu is activated (thanks @AliShahrivarian)
99
* Flag denoting if a second trigger should close the menu (thanks @OliverColeman)
10+
* Added update call to update visibility, disabled, icon and form value stats for items. Fixes issue ([Issue #555](https://github.com/swisnl/jQuery-contextMenu/issues/555)).
11+
12+
```javascript
13+
$('.context-menu-one').contextMenu('update'); // update single menu
14+
$.contextMenu('update') // update all open menus
15+
```
1016

1117
#### Fixed
1218

documentation/docs.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ currentMenu: options
88

99

1010
- [Register new contextMenu](#register-new-contextmenu)
11+
- [Update contextMenu state](#update-contextmenu-state)
1112
- [Options (at registration)](#options-at-registration)
1213
- [selector](#selector)
1314
- [items](#items)
@@ -38,6 +39,15 @@ To register a new contextMenu:
3839
$.contextMenu( options );
3940
```
4041

42+
## Update contextMenu state
43+
44+
It is possible to refresh the state of the contextmenu [disabled](https://swisnl.github.io/jQuery-contextMenu/docs/items.html#disabled), [visibility](https://swisnl.github.io/jQuery-contextMenu/docs/items.html#visible), [icons](https://swisnl.github.io/jQuery-contextMenu/docs/items.html#icon) and [input values](https://swisnl.github.io/jQuery-contextMenu/docs/items.html#type) through the `update` command. This will reevaluate any custom callbacks.
45+
46+
```javascript
47+
$('.context-menu-one').contextMenu('update'); // update single menu
48+
$.contextMenu('update') // update all open menus
49+
```
50+
4151
## Options (at registration)
4252

4353
### selector

src/jquery.contextMenu.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,6 +1649,20 @@
16491649
}
16501650

16511651
switch (operation) {
1652+
1653+
case 'update':
1654+
// Updates visibility and such
1655+
if(_hasContext){
1656+
op.update($context);
1657+
} else {
1658+
for(var menu in menus){
1659+
if(menus.hasOwnProperty(menu)){
1660+
op.update(menus[menu]);
1661+
}
1662+
}
1663+
}
1664+
break;
1665+
16521666
case 'create':
16531667
// no selector no joy
16541668
if (!o.selector) {

test/integration/html/disabled-callback.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,12 @@ <h2 id="example-code">Example code</h2>
336336
"edit": {
337337
name: "Clickable",
338338
icon: "edit",
339-
disabled: function(){ return false; }
339+
disabled: function(){ return Math.random() >= 0.5; }
340340
},
341341
"cut": {
342342
name: "Disabled",
343343
icon: "cut",
344-
disabled: function(){ return true; }
344+
disabled: function(){ return Math.random() >= 0.5; }
345345
}
346346
}
347347
});

test/integration/html/sub-menus.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ <h2 id="example-code">Example code</h2>
337337
window.console && console.log(m) || alert(m);
338338
},
339339
items: {
340-
"edit": {"name": "Edit", "icon": "edit"},
340+
"edit": {"name": "Edit", "icon": "edit", disabled: function(){ return Math.random() >= 0.5; }},
341341
"cut": {"name": "Cut", "icon": "cut"},
342342
"sep1": "---------",
343343
"quit": {"name": "Quit", "icon": "quit"},
@@ -349,8 +349,8 @@ <h2 id="example-code">Example code</h2>
349349
"fold2": {
350350
"name": "Sub group 2",
351351
"items": {
352-
"fold2-key1": {"name": "alpha"},
353-
"fold2-key2": {"name": "bravo"},
352+
"fold2-key1": {"name": "alpha", disabled: function(){ return Math.random() >= 0.5; }},
353+
"fold2-key2": {"name": "bravo", visible: function(){ return Math.random() >= 0.5; }},
354354
"fold2-key3": {"name": "charlie"}
355355
}
356356
},
@@ -360,8 +360,8 @@ <h2 id="example-code">Example code</h2>
360360
"fold1a": {
361361
"name": "Other group",
362362
"items": {
363-
"fold1a-key1": {"name": "echo"},
364-
"fold1a-key2": {"name": "foxtrot"},
363+
"fold1a-key1": {"name": "echo", disabled: function(){ return Math.random() >= 0.5; }},
364+
"fold1a-key2": {"name": "foxtrot", visible: function(){ return Math.random() >= 0.5; }},
365365
"fold1a-key3": {"name": "golf"}
366366
}
367367
}

0 commit comments

Comments
 (0)