Skip to content

Commit 23f9fc2

Browse files
committed
2 parents 5fdfd3f + 40d24d1 commit 23f9fc2

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed

README.md

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,52 @@
1-
# Extension-jsapi
2-
Official extension to Diamond for a javascript api.
1+
# jsapi
2+
3+
[![Dub version](https://img.shields.io/dub/v/diamond-ext-jsapi.svg)](http://code.dlang.org/packages/diamond-ext-jsapi)
4+
[![Dub downloads](https://img.shields.io/dub/dt/diamond-ext-jsapi.svg)](http://code.dlang.org/packages/diamond-ext-jsapi)
5+
[![License](https://img.shields.io/dub/l/diamond-ext-jsapi.svg)](http://code.dlang.org/packages/diamond-ext-jsapi)
6+
7+
Jsapi is an extension to views in Diamond, which extends views with an easy-to-use integration of js/jquery.
8+
9+
## extensions.config
10+
11+
```
12+
ViewExtension|jsapi|diamond.extensions.jsapi
13+
```
14+
15+
## API Docs
16+
17+
### void ajax(HTTPMethod method, string name, string url, string prepareFunction, string callbackFunction)
18+
19+
Requires: http://jquery.com/
20+
21+
This function will generate a javascript function that executes an ajax call through jquery.
22+
23+
Example:
24+
```
25+
<a href="#" onclick="authenticate()">Authenticate</a>
26+
27+
@:ajax(HTTPMethod.POST, "authenticate", "/login", "prepareAuth", "authenticated");
28+
29+
<script type="text/javascript">
30+
function prepareAuth() {
31+
var authArgs = {
32+
data: {
33+
username: 'test',
34+
password: '1234'
35+
},
36+
dataType: 'json'
37+
};
38+
39+
return authArgs;
40+
}
41+
42+
function authenticated(result) {
43+
if (result.success) {
44+
console.info(result);
45+
} else {
46+
console.error("An error happened during the request.");
47+
}
48+
}
49+
</script>
50+
```
51+
52+
*Note: You don't need to specify dataType if the dataType is json. The example above only has it for demonstration.*

0 commit comments

Comments
 (0)