outsourced examples
This commit is contained in:
parent
33b7588497
commit
e2e89e198f
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
node_modules
|
||||||
|
Examples/bower_components
|
||||||
|
.directory
|
||||||
|
.codio
|
||||||
|
.settings
|
||||||
|
.jshintignore
|
||||||
|
.jshintrc
|
||||||
|
.validate.json
|
12
Examples/OfflineEditing/index.html
Normal file
12
Examples/OfflineEditing/index.html
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<button id="button">Disconnect</button>
|
||||||
|
<h1 id="contenteditable" contentEditable></h1>
|
||||||
|
<textarea style="width:80%;" rows=40 id="textfield"></textarea>
|
||||||
|
|
||||||
|
<script src="../../node_modules/simplewebrtc/simplewebrtc.bundle.js"></script>
|
||||||
|
<script src="../bower_components/yjs/y.js"></script>
|
||||||
|
<script src="./index.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
50
Examples/OfflineEditing/index.js
Normal file
50
Examples/OfflineEditing/index.js
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/* global Y */
|
||||||
|
|
||||||
|
// create a shared object. This function call will return a promise!
|
||||||
|
Y({
|
||||||
|
db: {
|
||||||
|
name: 'IndexedDB',
|
||||||
|
namespace: 'offlineEditingDemo'
|
||||||
|
},
|
||||||
|
connector: {
|
||||||
|
name: 'WebRTC',
|
||||||
|
room: 'offlineEditingDemo',
|
||||||
|
debug: true
|
||||||
|
}
|
||||||
|
}).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
|
||||||
|
if (text != null) {
|
||||||
|
// 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 TextBind
|
||||||
|
var textpromise = yconfig.root.get('text')
|
||||||
|
if (textpromise == null) {
|
||||||
|
yconfig.root.set('text', Y.TextBind)
|
||||||
|
}
|
||||||
|
// We also provide a button for disconnecting/reconnecting the shared element
|
||||||
|
var button = document.querySelector('#button')
|
||||||
|
button.onclick = function () {
|
||||||
|
if (button.innerText === 'Disconnect') {
|
||||||
|
yconfig.disconnect()
|
||||||
|
button.innerText = 'Reconnect'
|
||||||
|
} else {
|
||||||
|
yconfig.reconnect()
|
||||||
|
button.innerText = 'Disconnect'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
12
Examples/TextBind/index.html
Normal file
12
Examples/TextBind/index.html
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<button id="button">Disconnect</button>
|
||||||
|
<h1 id="contenteditable" contentEditable></h1>
|
||||||
|
<textarea style="width:80%;" rows=40 id="textfield"></textarea>
|
||||||
|
|
||||||
|
<script src="../../node_modules/simplewebrtc/simplewebrtc.bundle.js"></script>
|
||||||
|
<script src="../../y.js"></script>
|
||||||
|
<script src="./index.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
47
Examples/TextBind/index.js
Normal file
47
Examples/TextBind/index.js
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/* global Y */
|
||||||
|
|
||||||
|
// create a shared object. This function call will return a promise!
|
||||||
|
Y({
|
||||||
|
db: {
|
||||||
|
name: 'Memory'
|
||||||
|
},
|
||||||
|
connector: {
|
||||||
|
name: 'WebRTC',
|
||||||
|
room: 'TextBindDemo',
|
||||||
|
debug: true
|
||||||
|
}
|
||||||
|
}).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
|
||||||
|
if (text != null) {
|
||||||
|
// 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 TextBind
|
||||||
|
yconfig.root.set('text', Y.TextBind)
|
||||||
|
|
||||||
|
// We also provide a button for disconnecting/reconnecting the shared element
|
||||||
|
var button = document.querySelector('#button')
|
||||||
|
button.onclick = function () {
|
||||||
|
if (button.innerText === 'Disconnect') {
|
||||||
|
yconfig.disconnect()
|
||||||
|
button.innerText = 'Reconnect'
|
||||||
|
} else {
|
||||||
|
yconfig.reconnect()
|
||||||
|
button.innerText = 'Disconnect'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
14
Examples/bower.json
Normal file
14
Examples/bower.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "yjs-examples",
|
||||||
|
"version": "0.0",
|
||||||
|
"homepage": "y-js.org",
|
||||||
|
"authors": [
|
||||||
|
"Kevin Jahns <kevin.jahns@rwth-aachen.de>"
|
||||||
|
],
|
||||||
|
"description": "Examples for yjs",
|
||||||
|
"license": "MIT",
|
||||||
|
"ignore": [],
|
||||||
|
"dependencies": {
|
||||||
|
"yjs": "../"
|
||||||
|
}
|
||||||
|
}
|
19
bower.json
Normal file
19
bower.json
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"name": "yjs",
|
||||||
|
"version": "0.6.25",
|
||||||
|
"homepage": "y-js.org",
|
||||||
|
"authors": [
|
||||||
|
"Kevin Jahns <kevin.jahns@rwth-aachen.de>"
|
||||||
|
],
|
||||||
|
"description": "A Framework that enables Real-Time collaboration on arbitrary data structures.",
|
||||||
|
"main": "y.js",
|
||||||
|
"keywords": [
|
||||||
|
"OT",
|
||||||
|
"collaboration",
|
||||||
|
"synchronization",
|
||||||
|
"sharejs",
|
||||||
|
"coweb",
|
||||||
|
"concurrency"
|
||||||
|
],
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
28
package.json
28
package.json
@ -1,21 +1,19 @@
|
|||||||
{
|
{
|
||||||
"name": "yjs",
|
"name": "yjs",
|
||||||
"version": "0.6.23",
|
"version": "0.6.25",
|
||||||
"description": "A framework for real-time p2p shared editing on arbitrary complex data types",
|
"description": "A framework for real-time p2p shared editing on arbitrary complex data types",
|
||||||
"main": "y.js",
|
"main": "y.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node --harmony ./node_modules/.bin/gulp test",
|
"lint": "./node_modules/.bin/standard"
|
||||||
"lint": "./node_modules/.bin/standard",
|
|
||||||
"build": "./node_modules/.bin/standard build"
|
|
||||||
},
|
},
|
||||||
"pre-commit": [
|
"pre-commit": [
|
||||||
"lint",
|
"lint"
|
||||||
"test"
|
|
||||||
],
|
],
|
||||||
"standard": {
|
"standard": {
|
||||||
"parser": "babel-eslint",
|
"parser": "babel-eslint",
|
||||||
"ignore": [
|
"ignore": [
|
||||||
"build/**",
|
"build/**",
|
||||||
|
"dist/**",
|
||||||
"./y.js",
|
"./y.js",
|
||||||
"./y.js.map"
|
"./y.js.map"
|
||||||
]
|
]
|
||||||
@ -41,25 +39,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "http://y-js.org",
|
"homepage": "http://y-js.org",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-eslint": "^4.1.2",
|
|
||||||
"gulp": "^3.9.0",
|
|
||||||
"gulp-babel": "^5.2.1",
|
|
||||||
"gulp-bump": "^1.0.0",
|
|
||||||
"gulp-concat": "^2.6.0",
|
|
||||||
"gulp-filter": "^3.0.1",
|
|
||||||
"gulp-git": "^1.6.0",
|
|
||||||
"gulp-jasmine": "^2.0.1",
|
|
||||||
"gulp-jasmine-browser": "^0.2.3",
|
|
||||||
"gulp-load-plugins": "^1.0.0",
|
|
||||||
"gulp-shell": "^0.5.1",
|
|
||||||
"gulp-sourcemaps": "^1.5.2",
|
|
||||||
"gulp-tag-version": "^1.3.0",
|
|
||||||
"gulp-uglify": "^1.4.1",
|
|
||||||
"gulp-util": "^3.0.6",
|
|
||||||
"gulp-watch": "^4.3.5",
|
|
||||||
"minimist": "^1.2.0",
|
|
||||||
"pre-commit": "^1.1.1",
|
"pre-commit": "^1.1.1",
|
||||||
"promise-polyfill": "^2.1.0",
|
|
||||||
"standard": "^5.2.2"
|
"standard": "^5.2.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user