Updated examples

This commit is contained in:
jos 2016-12-26 10:41:07 +01:00
parent f209df27a9
commit c7418807d8
2 changed files with 18 additions and 7 deletions

View File

@ -18,6 +18,10 @@
height: 500px; height: 500px;
margin-right: 24px; margin-right: 24px;
} }
code {
background: #e5e5e5;
}
</style> </style>
</head> </head>
<body> <body>
@ -25,7 +29,7 @@
<h1>Synchronize two editors</h1> <h1>Synchronize two editors</h1>
<p> <p>
This example demonstrates how to keep two editors synchronized by listening for This example demonstrates how to keep two editors synchronized by listening for
the onChange event. the <code>onPatch</code> event. Other related events are <code>onChange</code> and <code>onChangeText</code>.
</p> </p>
<div id="jsoneditor1"></div> <div id="jsoneditor1"></div>
@ -42,14 +46,14 @@
} }
var editor1 = jsoneditor(document.getElementById('jsoneditor1'), { var editor1 = jsoneditor(document.getElementById('jsoneditor1'), {
onChange: function (patch, revert) { onPatch: function (patch, revert) {
editor2.patch(patch) editor2.patch(patch)
} }
}) })
editor1.set(json) editor1.set(json)
var editor2 = jsoneditor(document.getElementById('jsoneditor2'), { var editor2 = jsoneditor(document.getElementById('jsoneditor2'), {
onChange: function (patch, revert) { onPatch: function (patch, revert) {
editor1.patch(patch) editor1.patch(patch)
} }
}) })

View File

@ -56,13 +56,20 @@
const container = document.getElementById('container') const container = document.getElementById('container')
const options = { const options = {
name: 'myObject', name: 'myObject',
onChange: function (patch, revert) { onPatch: function (patch, revert) {
console.log('onChange patch=', patch, ', revert=', revert) console.log('onPatch patch=', patch, ', revert=', revert)
window.patch = patch window.patch = patch
window.revert = revert window.revert = revert
}, },
onChangeText: function () { onPatchText: function (patch, revert) {
console.log('onChangeText') // FIXME: implement onPatchText
console.log('onPatchText patch=', patch, ', revert=', revert)
},
onChange: function (json) {
console.log('onChange json=', json)
},
onChangeText: function (text) {
console.log('onChangeText', text)
}, },
onChangeMode: function (mode, prevMode) { onChangeMode: function (mode, prevMode) {
console.log('switched mode from', prevMode, 'to', mode) console.log('switched mode from', prevMode, 'to', mode)