2017-08-25 20:35:06 +02:00
|
|
|
/* global Y */
|
|
|
|
|
|
|
|
|
|
// initialize a shared object. This function call returns a promise!
|
2017-10-19 17:36:28 +02:00
|
|
|
let y = new Y({
|
2017-08-25 20:35:06 +02:00
|
|
|
connector: {
|
|
|
|
|
name: 'websockets-client',
|
2017-09-29 22:33:28 +02:00
|
|
|
url: 'http://127.0.0.1:1234',
|
2017-10-02 15:50:56 +02:00
|
|
|
room: 'html-editor-example6'
|
2017-10-02 15:45:23 +02:00
|
|
|
// maxBufferLength: 100
|
2017-08-25 20:35:06 +02:00
|
|
|
}
|
|
|
|
|
})
|
2017-10-19 17:36:28 +02:00
|
|
|
window.yXml = y
|
2017-11-08 13:40:36 -08:00
|
|
|
window.yXmlType = y.define('xml', Y.XmlFragment)
|
2017-10-19 17:36:28 +02:00
|
|
|
window.onload = function () {
|
|
|
|
|
console.log('start!')
|
|
|
|
|
// Bind children of XmlFragment to the document.body
|
2017-10-30 11:33:00 +01:00
|
|
|
window.yXmlType.bindToDom(document.body)
|
|
|
|
|
}
|
2017-11-08 17:31:12 -08:00
|
|
|
window.undoManager = new Y.utils.UndoManager(window.yXmlType, {
|
|
|
|
|
captureTimeout: 1000
|
|
|
|
|
})
|
2017-10-30 11:33:00 +01:00
|
|
|
|
|
|
|
|
document.onkeydown = function interceptUndoRedo (e) {
|
|
|
|
|
if (e.keyCode === 90 && e.ctrlKey) {
|
|
|
|
|
if (!e.shiftKey) {
|
|
|
|
|
console.info('Undo!')
|
|
|
|
|
window.undoManager.undo()
|
|
|
|
|
} else {
|
|
|
|
|
console.info('Redo!')
|
|
|
|
|
window.undoManager.redo()
|
|
|
|
|
}
|
|
|
|
|
e.preventDefault()
|
|
|
|
|
}
|
2017-10-19 17:36:28 +02:00
|
|
|
}
|