Skip to content

Commit 7709a40

Browse files
committed
Add changelog and some docs (reference #429)
1 parent 4eb55f7 commit 7709a40

File tree

3 files changed

+103
-3
lines changed

3 files changed

+103
-3
lines changed

README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# jQuery contextMenu plugin & polyfill #
22

3-
__IMPORTANT: 2.0.0 is release and has change the default names of the icon classes in order to stop CSS conflicts with frameworks which define the class 'icon'.__
4-
5-
63
[![Travis Build Status](https://travis-ci.org/swisnl/jQuery-contextMenu.svg?branch=master)](https://travis-ci.org/swisnl/jQuery-contextMenu)
74

85
$.contextMenu is a management facility for - you guessed it - context menus. It was designed for an application where there are hundreds of elements that may show a context menu - so intialization speed and memory usage are kept fairly small. It also allows to register context menus without providing actual markup, as $.contextMenu generates DOMElements as needed.
@@ -97,6 +94,12 @@ Font-Awesome icons used from [encharm/Font-Awesome-SVG-PNG](https://github.com/e
9794

9895
## Changelog ##
9996

97+
### Unreleased ###
98+
99+
### Added
100+
101+
* Asynchronous promise support for submenu's ([Issue #429](https://github.com/swisnl/jQuery-contextMenu/issues/429)) thanks @Ruud-cb for the hard work.
102+
100103
### 2.2.4 ###
101104

102105
#### Fixed

documentation/demo/async-promise.md

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
currentMenu: async-promis
3+
---
4+
5+
# Demo: Submenu through promis (asynchronous)
6+
7+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
8+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
9+
10+
11+
- [Example code](#example-code)
12+
- [Example HTML](#example-html)
13+
14+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
15+
16+
<span class="context-menu-one btn btn-neutral">right click me</span>
17+
18+
## Example code
19+
20+
<script type="text/javascript" class="showcase">
21+
var $ = jQuery;
22+
$(document).ready(function () {
23+
'use strict';
24+
var errorItems = { "errorItem": { name: "Items Load error" },};
25+
var loadItems = function () {
26+
var dfd = jQuery.Deferred();
27+
setTimeout(function () {
28+
dfd.resolve(subItems);
29+
}, 2000);
30+
//setTimeout(function () {
31+
// dfd.reject(errorItems);
32+
//}, 1000);
33+
return dfd.promise();
34+
};
35+
36+
var subItems = {
37+
"sub1": { name: "Submenu1", icon: "edit" },
38+
"sub2": { name: "Submenu2", icon: "cut" },
39+
};
40+
41+
$.contextMenu({
42+
selector: '.context-menu-one',
43+
build: function ($trigger, e) {
44+
return {
45+
callback: function (key, options) {
46+
var m = "clicked: " + key;
47+
console.log(m);
48+
},
49+
items: {
50+
"edit": { name: "Edit", icon: "edit" },
51+
"cut": { name: "Cut", icon: "cut" },
52+
"status": {
53+
name: "Status",
54+
icon: "delete",
55+
items: loadItems(),
56+
},
57+
"normalSub": {
58+
name: "Normal Sub",
59+
items: {
60+
"normalsub1": { name: "normal Sub 1"},
61+
"normalsub2": { name: "normal Sub 2"},
62+
"normalsub3": { name: "normal Sub 3" },
63+
}
64+
}
65+
}
66+
};
67+
}
68+
});
69+
70+
//normal promise usage example
71+
var completedPromise = function (status) {
72+
console.log("completed promise:", status);
73+
};
74+
75+
var failPromise = function (status) {
76+
console.log("fail promise:", status);
77+
};
78+
79+
var notifyPromise = function (status) {
80+
console.log("notify promise:", status);
81+
};
82+
83+
$.loadItemsAsync = function() {
84+
console.log("loadItemsAsync");
85+
var promise = loadItems();
86+
$.when(promise).then(completedPromise, failPromise, notifyPromise);
87+
};
88+
89+
});
90+
</script>
91+
92+
## Example HTML
93+
<div style="display:none;" class="showcase" data-showcase-import=".context-menu-one"></div>

documentation/docs/items.md

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ var items = {
4040
}
4141
```
4242

43+
Since 2.3 it is also possible to use a promise as item, so you can build submenu's based on a snynchronous promis.
44+
45+
Check out the [demo using a promise](demo/async-promise.md) for an example how to use this. The example uses jQuery deferred, but any promise should do.
46+
4347
## options.items
4448

4549
### name

0 commit comments

Comments
 (0)