drop a bunch of stuff and use diff dom and hyperjson

pull/1/head
ansuz 9 years ago
parent 69f3f4c9a8
commit f94c06abc0

@ -3,16 +3,14 @@ define([
'/bower_components/chainpad-netflux/chainpad-netflux.js', '/bower_components/chainpad-netflux/chainpad-netflux.js',
'/bower_components/chainpad-crypto/crypto.js', '/bower_components/chainpad-crypto/crypto.js',
'/bower_components/marked/marked.min.js', '/bower_components/marked/marked.min.js',
'/common/convert.js', '/bower_components/hyperjson/hyperjson.js',
'/common/rainbow.js', //'/common/convert.js',
'/bower_components/jquery/dist/jquery.min.js', '/bower_components/jquery/dist/jquery.min.js',
'/bower_components/diff-dom/diffDOM.js',
'/customize/pad.js' '/customize/pad.js'
], function (Config, Realtime, Crypto, Marked, Convert, Rainbow) { ], function (Config, Realtime, Crypto, Marked, Hyperjson) {
var $ = window.jQuery; var $ = window.jQuery;
var DiffDom = window.diffDOM;
var Vdom = Convert.core.vdom,
Hyperjson = Convert.core.hyperjson,
Hyperscript = Convert.core.hyperscript;
var key; var key;
var channel = ''; var channel = '';
@ -27,20 +25,15 @@ define([
// set markdown rendering options :: strip html to prevent XSS // set markdown rendering options :: strip html to prevent XSS
Marked.setOptions({ Marked.setOptions({
sanitize: true //sanitize: true
}); });
var module = window.APP = { var module = window.APP = { };
Vdom: Vdom,
Hyperjson: Hyperjson,
Hyperscript: Hyperscript
};
var $target = module.$target = $('#target'); var $target = module.$target = $('#target');
var config = { var config = {
websocketURL: Config.websocketURL, websocketURL: Config.websocketURL,
userName: Crypto.rand64(8),
channel: channel, channel: channel,
cryptKey: key, cryptKey: key,
crypto: Crypto crypto: Crypto
@ -51,41 +44,26 @@ define([
inner = $target.find('#inner')[0]; inner = $target.find('#inner')[0];
if (!target) { throw new Error(); } if (!target) { throw new Error(); }
var DD = new DiffDom({});
var Previous = Convert.dom.to.vdom(inner);
return function (md) { return function (md) {
var rendered = Marked(md||""); var rendered = Marked(md||"");
// make a dom // make a dom
var R = $('<div id="inner">'+rendered+'</div>')[0]; var New = $('<div id="inner">'+rendered+'</div>')[0];
var New = Convert.dom.to.vdom(R);
var patches = Vdom.diff(Previous, New); var patches = (DD).diff(inner, New);
Vdom.patch(inner, patches); DD.apply(inner, patches);
Previous = New; Previous = New;
return patches; return patches;
}; };
}()); }());
var colour = module.colour = Rainbow();
var $inner = $('#inner'); var $inner = $('#inner');
window.makeRainbow = false;
var makeRainbows = function () {
$inner
.find('*:not(.untouched)')
.css({
'border': '5px solid '+colour(),
margin: '5px'
})
.addClass('untouched');
};
var redrawTimeout; var redrawTimeout;
var lazyDraw = function (md) { var lazyDraw = function (md) {
if (redrawTimeout) { clearTimeout(redrawTimeout); } if (redrawTimeout) { clearTimeout(redrawTimeout); }
redrawTimeout = setTimeout(function () { redrawTimeout = setTimeout(function () {
draw(md); draw(md);
if (window.makeRainbow) { makeRainbows(); }
}, 450); }, 450);
}; };
@ -98,12 +76,9 @@ define([
// when your editor is ready // when your editor is ready
var onReady = config.onReady = function (info) { var onReady = config.onReady = function (info) {
//if (info.userList) { console.log("Userlist: [%s]", info.userList.join(',')); }
console.log("Realtime is ready!"); console.log("Realtime is ready!");
var userDoc = module.realtime.getUserDoc(); var userDoc = module.realtime.getUserDoc();
lazyDraw(userDoc); lazyDraw(userDoc);
initializing = false; initializing = false;
}; };

Loading…
Cancel
Save