Merge branch 'staging' of github.com:xwiki-labs/cryptpad into prop

This commit is contained in:
yflory
2017-03-21 10:44:10 +01:00
12 changed files with 26239 additions and 506 deletions

View File

@@ -1018,7 +1018,7 @@ define([
parsed = common.parseHash(parsed.hash);
if (parsed.version === 0) {
return channel;
return parsed.channel;
} else if (parsed.version !== 1) {
console.error("parsed href had no version");
console.error(parsed);

View File

@@ -11,7 +11,7 @@ define([
var verbose = function (x) { if (window.verboseMode) { console.log(x); } };
/* accepts the document used by the editor */
return function (inner) {
var Cursor = function (inner) {
var cursor = {};
// there ought to only be one cursor at a time, so let's just
@@ -387,6 +387,58 @@ define([
}
};
cursor.lastTextNode = function () {
var lastEl = Tree.rightmostNode(inner);
if (lastEl && lastEl.nodeType === 3) { return lastEl; }
var firstEl = Tree.leftmostNode(inner);
while (lastEl !== firstEl) {
lastEl = Tree.previousNode(lastEl, inner);
if (lastEl && lastEl.nodeType === 3) { return lastEl; }
}
return lastEl;
};
cursor.firstTextNode = function () {
var firstEl = Tree.leftmostNode(inner);
if (firstEl && firstEl.nodeType === 3) { return firstEl; }
var lastEl = Tree.rightmostNode(inner);
while (firstEl !== lastEl) {
firstEl = Tree.nextNode(firstEl, inner);
if (firstEl && firstEl.nodeType === 3) { return firstEl; }
}
return firstEl;
};
cursor.setToStart = function () {
var el = cursor.firstTextNode();
if (!el) { return; }
fixStart(el, 0);
fixEnd(el, 0);
fixSelection(makeSelection(), makeRange());
return el;
};
cursor.setToEnd = function () {
var el = cursor.lastTextNode();
if (!el) { return; }
var offset = el.textContent.length;
fixStart(el, offset);
fixEnd(el, offset);
fixSelection(makeSelection(), makeRange());
return el;
};
return cursor;
};
Cursor.Tree = Tree;
return Cursor;
});

View File

@@ -343,10 +343,10 @@ define([
id: uid(),
});
var $a = $('<span>', {id: 'newLag'});
$s1 = $('<span>', {'class': 'bar1'}).appendTo($a);
$s2 = $('<span>', {'class': 'bar2'}).appendTo($a);
$s3 = $('<span>', {'class': 'bar3'}).appendTo($a);
$s4 = $('<span>', {'class': 'bar4'}).appendTo($a);
$('<span>', {'class': 'bar1'}).appendTo($a);
$('<span>', {'class': 'bar2'}).appendTo($a);
$('<span>', {'class': 'bar3'}).appendTo($a);
$('<span>', {'class': 'bar4'}).appendTo($a);
return $a[0];
};

26125
www/examples/canvas/fabric.js Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -10,7 +10,7 @@ define([
'json.sortify',
'/bower_components/chainpad-json-validator/json-ot.js',
'/common/cryptpad-common.js',
'/bower_components/fabric.js/dist/fabric.min.js',
'fabric.js',
'/bower_components/jquery/dist/jquery.min.js',
'/bower_components/file-saver/FileSaver.min.js',
//'/customize/pad.js'
@@ -76,34 +76,47 @@ define([
var config = module.config = {
initialState: '{}',
// TODO initialState ?
websocketURL: Config.websocketURL,
//userName: Crypto.rand64(8),
websocketURL: Cryptpad.getWebsocketURL(),
validateKey: secret.keys.validateKey,
readOnly: false, // TODO
channel: secret.channel,
//cryptKey: key,
crypto: Crypto.createEncryptor(secret.key),
crypto: Crypto.createEncryptor(secret.keys),
transformFunction: JsonOT.validate,
};
var editHash;
var onInit = config.onInit = function (info) {
window.location.hash = info.channel + secret.key;
$(window).on('hashchange', function() {
window.location.reload();
});
editHash = Cryptpad.getEditHashFromKeys(info.channel, secret.keys);
Cryptpad.replaceHash(editHash);
//window.location.hash = info.channel + secret.key;
//$(window).on('hashchange', function() { window.location.reload(); });
};
var onRemote = config.onRemote = function () {
var Catch = function (f) {
return function () {
try {
f();
} catch (e) {
console.error(e);
}
};
};
var onRemote = config.onRemote = Catch(function () {
if (initializing) { return; }
var userDoc = module.realtime.getUserDoc();
canvas.loadFromJSON(userDoc);
canvas.renderAll();
};
});
var onLocal = config.onLocal = function () {
var onLocal = config.onLocal = Catch(function () {
if (initializing) { return; }
var content = JSONSortify(canvas.toDatalessJSON());
module.patchText(content);
};
});
var onReady = config.onReady = function (info) {
var realtime = module.realtime = info.realtime;

View File

@@ -64,6 +64,7 @@ define([
logFights: true,
fights: [],
Cryptpad: Cryptpad,
Cursor: Cursor,
};
var emitResize = module.emitResize = function () {
@@ -131,7 +132,7 @@ define([
color: '#fff',
});
var cursor = window.cursor = Cursor(inner);
var cursor = module.cursor = Cursor(inner);
var setEditable = module.setEditable = function (bool) {
if (bool) {
@@ -718,6 +719,13 @@ define([
realtimeOptions.onLocal();
module.$userNameButton.click();
}
editor.focus();
if (newPad) {
cursor.setToEnd();
} else {
cursor.setToFix();
}
});
};