Files
yjs/examples/IwcJson/index.js

50 lines
1.7 KiB
JavaScript
Raw Normal View History

2014-08-05 05:00:22 +02:00
/**
## IWC + JSON Example
2014-08-05 05:11:36 +02:00
Here, I will give a short overview on how to use the IwcJson Framework in Role-SDK widgets.
2014-08-05 05:00:22 +02:00
First you have to include the following libraries in your widget file:
```
<script src="http://open-app.googlecode.com/files/openapp.js"></script>
<script src="http://dbis.rwth-aachen.de/gadgets/iwc/lib/iwc.js"></script>
<script src="http://dbis.rwth-aachen.de/~jahns/role-widgets/widgetbundles/libraries/DUIClient.js"></script>
2014-08-12 20:23:54 +02:00
<script src="../../build/browser/Frameworks/JsonYatta.min.js"></script>
<script src="../../build/browser/Connectors/IwcConnector.min.js"></script>
<script src="./index.js"></script>
2014-08-05 05:00:22 +02:00
```
2014-08-12 20:40:07 +02:00
A working widget implementation is [IwcJson.xml](./IwcJson.xml) and the js-file is [index.js](./index.js)
2014-08-05 05:00:22 +02:00
*/
function init(){
2014-08-14 20:33:55 +02:00
Y.createIwcConnector(function(Connector, user_id){
2014-08-05 05:00:22 +02:00
/**
2014-08-06 13:33:08 +02:00
yatta is the shared json object. If you change something on this object,
it will be instantly shared with all the other collaborators.
2014-08-05 05:00:22 +02:00
*/
2014-08-14 20:33:55 +02:00
yatta = new Y.JsonYatta(user_id, Connector);
2014-08-05 05:00:22 +02:00
/**
Add a integer-property like this
*/
yatta.val('x', 7);
/**
Get the value of property x like this
*/
console.log(yatta.val('x') === 7); // true
/**
A string property can be either mutable or immutable.
*/
yatta.val('mutable_string', "text", "mutable");
yatta.val('immutable_string', "text", "immutable");
console.log(yatta.val('immutable_string') === "text"); // true
yatta.val('mutable_string').insertText(2,"XXX"); // position, string
yatta.val('mutable_string').deleteText(0,1); // position, deletion length
console.log(yatta.val('mutable_string').val() === "eXXXxt"); // true
})
}
window.onload = init