example update

This commit is contained in:
Kevin Jahns
2015-11-11 17:18:57 +01:00
parent acfce06912
commit dcf6212436
3 changed files with 19 additions and 23 deletions

View File

@@ -1,7 +1,6 @@
<!DOCTYPE html>
<html>
<body>
<h1 id="contenteditable" contentEditable></h1>
<textarea style="width:80%;" rows=40 id="textfield"></textarea>
<script src="../bower_components/yjs/y.js"></script>

View File

@@ -16,13 +16,10 @@ Y({
}).then(function (yconfig) {
// yconfig holds all the information about the shared object
window.yconfig = yconfig
// yconfig.root holds the shared element
window.y = yconfig.root
// now we bind the textarea and the contenteditable h1 element
// to a shared element
var textarea = document.getElementById('textfield')
var contenteditable = document.getElementById('contenteditable')
yconfig.root.observePath(['text'], function (text) {
// every time the 'text' property of the yconfig.root changes,
// this function is called. Then we bind it to the html elements
@@ -30,12 +27,12 @@ Y({
// when the text property is deleted, text may be undefined!
// This is why we have to check if text exists..
text.bind(textarea)
text.bind(contenteditable)
}
})
// create a shared Text
var textpromise = yconfig.root.get('text')
if (textpromise == null) {
// Set the text type if it does not yet exist
yconfig.root.set('text', Y.Text)
}
})