|
|
@ -6,12 +6,15 @@ define([
|
|
|
|
'/common/convert.js',
|
|
|
|
'/common/convert.js',
|
|
|
|
'/common/toolbar.js',
|
|
|
|
'/common/toolbar.js',
|
|
|
|
'/common/cursor.js',
|
|
|
|
'/common/cursor.js',
|
|
|
|
|
|
|
|
'/bower_components/diff-dom/diffDOM.js',
|
|
|
|
|
|
|
|
|
|
|
|
'/bower_components/jquery/dist/jquery.min.js',
|
|
|
|
'/bower_components/jquery/dist/jquery.min.js',
|
|
|
|
'/customize/pad.js'
|
|
|
|
'/customize/pad.js'
|
|
|
|
], function (Config, Messages, Crypto, realtimeInput, Convert, Toolbar, Cursor) {
|
|
|
|
], function (Config, Messages, Crypto, realtimeInput, Convert, Toolbar, Cursor) {
|
|
|
|
var $ = window.jQuery;
|
|
|
|
var $ = window.jQuery;
|
|
|
|
var ifrw = $('#pad-iframe')[0].contentWindow;
|
|
|
|
var ifrw = $('#pad-iframe')[0].contentWindow;
|
|
|
|
window.Ckeditor = ifrw.CKEDITOR;
|
|
|
|
window.Ckeditor = ifrw.CKEDITOR;
|
|
|
|
|
|
|
|
var DiffDom = window.diffDOM;
|
|
|
|
|
|
|
|
|
|
|
|
var userName = Crypto.rand64(8),
|
|
|
|
var userName = Crypto.rand64(8),
|
|
|
|
toolbar;
|
|
|
|
toolbar;
|
|
|
@ -59,28 +62,22 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
var applyHjson = function (shjson) {
|
|
|
|
var applyHjson = function (shjson) {
|
|
|
|
console.log("Applying HJSON");
|
|
|
|
console.log("Applying HJSON");
|
|
|
|
// before integrating external changes, check in your own
|
|
|
|
var userDocStateDom = Vdom.create(Convert.hjson.to.vdom(JSON.parse(shjson)));
|
|
|
|
vdom1 = Convert.dom.to.vdom(inner);
|
|
|
|
userDocStateDom.setAttribute("contentEditable", "true"); // lol wtf
|
|
|
|
// the authoritative document is hyperjson, parse it
|
|
|
|
var patch = (new DiffDom()).diff(inner, userDocStateDom);
|
|
|
|
var authDoc = JSON.parse(shjson);
|
|
|
|
(new DiffDom()).apply(inner, patch);
|
|
|
|
// use the authdoc to construct a second vdom
|
|
|
|
|
|
|
|
var vdom2 = Convert.hjson.to.vdom(authDoc);
|
|
|
|
|
|
|
|
// diff it against your version
|
|
|
|
|
|
|
|
var patches = Vdom.diff(vdom1, vdom2);
|
|
|
|
|
|
|
|
// apply the resulting patches
|
|
|
|
|
|
|
|
Vdom.patch(inner, patches);
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var onRemote = function (shjson) {
|
|
|
|
var onRemote = function (shjson) {
|
|
|
|
// remember where the cursor is
|
|
|
|
// remember where the cursor is
|
|
|
|
cursor.update()
|
|
|
|
//cursor.update()
|
|
|
|
|
|
|
|
|
|
|
|
applyHjson(shjson);
|
|
|
|
applyHjson(shjson);
|
|
|
|
|
|
|
|
|
|
|
|
cursor.find();
|
|
|
|
//cursor.find();
|
|
|
|
|
|
|
|
|
|
|
|
// put the cursor back where you left it
|
|
|
|
// put the cursor back where you left it
|
|
|
|
cursor.replace();
|
|
|
|
//cursor.replace();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var onInit = function (info) {
|
|
|
|
var onInit = function (info) {
|
|
|
@ -141,14 +138,14 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
$textarea.val(JSON.stringify(hjson));
|
|
|
|
$textarea.val(JSON.stringify(hjson));
|
|
|
|
rti.bumpSharejs();
|
|
|
|
rti.bumpSharejs();
|
|
|
|
cursor.update()
|
|
|
|
//cursor.update()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
['mouseup', 'keyup'].forEach(function (type) {
|
|
|
|
/*['mouseup', 'keyup'].forEach(function (type) {
|
|
|
|
editor.document.on(type, function (e) {
|
|
|
|
editor.document.on(type, function (e) {
|
|
|
|
cursor.update();
|
|
|
|
cursor.update();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});*/
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|