Merge branch 'pad2' of github.com:xwiki-labs/cryptpad into pad2
This commit is contained in:
commit
f88a6f63fe
31
www/common/loading.js
Normal file
31
www/common/loading.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
define([
|
||||||
|
'less!/customize/src/less/cryptpad.less'
|
||||||
|
], function () {
|
||||||
|
var urlArgs = window.location.href.replace(/^.*\?([^\?]*)$/, function (all, x) { return x; });
|
||||||
|
var elem = document.createElement('div');
|
||||||
|
elem.setAttribute('id', 'loading');
|
||||||
|
elem.innerHTML = [
|
||||||
|
'<div class="loadingContainer">',
|
||||||
|
'<img class="cryptofist" src="/customize/cryptpad-new-logo-colors-logoonly.png?' + urlArgs + '">',
|
||||||
|
'<div class="spinnerContainer">',
|
||||||
|
'<span class="fa fa-circle-o-notch fa-spin fa-4x fa-fw"></span>',
|
||||||
|
'</div>',
|
||||||
|
'<p id="cp-loading-message"></p>',
|
||||||
|
'</div>'
|
||||||
|
].join('');
|
||||||
|
var intr;
|
||||||
|
var append = function () {
|
||||||
|
if (!document.body) { return; }
|
||||||
|
clearInterval(intr);
|
||||||
|
document.body.appendChild(elem);
|
||||||
|
require([
|
||||||
|
'/customize/messages.js',
|
||||||
|
|
||||||
|
'css!/bower_components/components-font-awesome/css/font-awesome.min.css',
|
||||||
|
], function (Messages) {
|
||||||
|
document.getElementById('cp-loading-message').innerText = Messages.loading;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
intr = setInterval(append, 100);
|
||||||
|
append();
|
||||||
|
});
|
||||||
@ -4,7 +4,7 @@ define([
|
|||||||
var out = {
|
var out = {
|
||||||
// fix up locations so that relative urls work.
|
// fix up locations so that relative urls work.
|
||||||
baseUrl: window.location.pathname,
|
baseUrl: window.location.pathname,
|
||||||
paths: {
|
paths: {
|
||||||
// jquery declares itself as literally "jquery" so it cannot be pulled by path :(
|
// jquery declares itself as literally "jquery" so it cannot be pulled by path :(
|
||||||
"jquery": "/bower_components/jquery/dist/jquery.min",
|
"jquery": "/bower_components/jquery/dist/jquery.min",
|
||||||
// json.sortify same
|
// json.sortify same
|
||||||
|
|||||||
@ -1,9 +1,14 @@
|
|||||||
// Stage 0, this gets cached which means we can't change it. boot2-sframe.js is changable.
|
// Stage 0, this gets cached which means we can't change it. boot2-sframe.js is changable.
|
||||||
// Note that this file is meant to be executed only inside of a sandbox iframe.
|
// Note that this file is meant to be executed only inside of a sandbox iframe.
|
||||||
|
;(function () {
|
||||||
window.addEventListener('message', function (msg) {
|
window.addEventListener('message', function (msg) {
|
||||||
var data = JSON.parse(msg.data);
|
var data = JSON.parse(msg.data);
|
||||||
if (data.q !== 'INIT') { return; }
|
if (data.q !== 'INIT') { return; }
|
||||||
msg.source.postMessage(JSON.stringify({ txid: data.txid, content: 'OK' }), '*');
|
msg.source.postMessage(JSON.stringify({ txid: data.txid, content: 'OK' }), '*');
|
||||||
if (data.content && data.content.requireConf) { require.config(data.content.requireConf); }
|
if (data.content && data.content.requireConf) { require.config(data.content.requireConf); }
|
||||||
require(['/common/sframe-boot2.js'], function () { });
|
require(['/common/sframe-boot2.js'], function () { });
|
||||||
});
|
});
|
||||||
|
var req = JSON.parse(decodeURIComponent(window.location.hash.substring(1)));
|
||||||
|
if (req.cfg) { require.config(req.cfg); }
|
||||||
|
if (req.req) { require(req.req, function () { }); }
|
||||||
|
}());
|
||||||
@ -50,10 +50,7 @@ define(['jquery'], function ($) {
|
|||||||
exp.updateTitle = function (newTitle, cb) {
|
exp.updateTitle = function (newTitle, cb) {
|
||||||
cb = cb || $.noop;
|
cb = cb || $.noop;
|
||||||
if (newTitle === exp.title) { return; }
|
if (newTitle === exp.title) { return; }
|
||||||
// Change the title now, and set it back to the old value if there is an error
|
Common.updateTitle(newTitle, cb);
|
||||||
//var oldTitle = exp.title;
|
|
||||||
Common.updateTitle(newTitle, cb)
|
|
||||||
//cb(null, newTitle);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO not needed?
|
// TODO not needed?
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html class="cp pad">
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>CryptPad</title>
|
<title>CryptPad</title>
|
||||||
<meta content="text/html; charset=utf-8" http-equiv="content-type"/>
|
<meta content="text/html; charset=utf-8" http-equiv="content-type"/>
|
||||||
@ -27,4 +27,4 @@
|
|||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<iframe id="sbox-iframe"></iframe>
|
<iframe id="sbox-iframe">
|
||||||
@ -1,5 +1,5 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html class="cp pad">
|
||||||
<head>
|
<head>
|
||||||
<meta content="text/html; charset=utf-8" http-equiv="content-type"/>
|
<meta content="text/html; charset=utf-8" http-equiv="content-type"/>
|
||||||
<link rel="stylesheet" href="/bower_components/components-font-awesome/css/font-awesome.min.css">
|
<link rel="stylesheet" href="/bower_components/components-font-awesome/css/font-awesome.min.css">
|
||||||
|
|||||||
@ -1,136 +1,129 @@
|
|||||||
|
|
||||||
define([
|
define([
|
||||||
'/api/config',
|
'/api/config',
|
||||||
'/common/sframe-channel.js',
|
|
||||||
'jquery',
|
'jquery',
|
||||||
'/common/sframe-chainpad-netflux-outer.js',
|
'/common/requireconfig.js'
|
||||||
'/bower_components/nthen/index.js',
|
], function (ApiConfig, $, RequireConfig) {
|
||||||
'/common/cryptpad-common.js',
|
$(function () {
|
||||||
'/bower_components/chainpad-crypto/crypto.js'
|
var req = {
|
||||||
], function (ApiConfig, SFrameChannel, $, CpNfOuter, nThen, Cryptpad, Crypto) {
|
cfg: RequireConfig,
|
||||||
console.log('xxx');
|
req: [ '/common/loading.js' ],
|
||||||
var sframeChan;
|
};
|
||||||
var hashes;
|
|
||||||
nThen(function (waitFor) {
|
|
||||||
$(waitFor());
|
|
||||||
}).nThen(function (waitFor) {
|
|
||||||
$('#sbox-iframe').attr('src',
|
$('#sbox-iframe').attr('src',
|
||||||
ApiConfig.httpSafeOrigin + '/pad2/inner.html?' + ApiConfig.requireConf.urlArgs);
|
ApiConfig.httpSafeOrigin + '/pad2/inner.html?' + ApiConfig.requireConf.urlArgs +
|
||||||
SFrameChannel.create($('#sbox-iframe')[0].contentWindow, waitFor(function (sfc) {
|
'#' + encodeURIComponent(JSON.stringify(req)));
|
||||||
sframeChan = sfc;
|
});
|
||||||
console.log('sframe initialized');
|
require([
|
||||||
}));
|
'/common/sframe-channel.js',
|
||||||
Cryptpad.ready(waitFor());
|
'/common/sframe-chainpad-netflux-outer.js',
|
||||||
}).nThen(function (waitFor) {
|
'/bower_components/nthen/index.js',
|
||||||
Cryptpad.getShareHashes(function (err, h) {
|
'/common/cryptpad-common.js',
|
||||||
hashes = h;
|
'/bower_components/chainpad-crypto/crypto.js'
|
||||||
waitFor()();
|
], function (SFrameChannel, CpNfOuter, nThen, Cryptpad, Crypto) {
|
||||||
});
|
console.log('xxx');
|
||||||
}).nThen(function (waitFor) {
|
var sframeChan;
|
||||||
var secret = Cryptpad.getSecrets();
|
var hashes;
|
||||||
var readOnly = secret.keys && !secret.keys.editKeyStr;
|
nThen(function (waitFor) {
|
||||||
if (!secret.keys) { secret.keys = secret.key; }
|
$(waitFor());
|
||||||
|
}).nThen(function (waitFor) {
|
||||||
|
SFrameChannel.create($('#sbox-iframe')[0].contentWindow, waitFor(function (sfc) {
|
||||||
|
sframeChan = sfc;
|
||||||
|
console.log('sframe initialized');
|
||||||
|
}));
|
||||||
|
Cryptpad.ready(waitFor());
|
||||||
|
}).nThen(function (waitFor) {
|
||||||
|
Cryptpad.getShareHashes(waitFor(function (err, h) { hashes = h; }));
|
||||||
|
}).nThen(function (waitFor) {
|
||||||
|
var secret = Cryptpad.getSecrets();
|
||||||
|
var readOnly = secret.keys && !secret.keys.editKeyStr;
|
||||||
|
if (!secret.keys) { secret.keys = secret.key; }
|
||||||
|
|
||||||
|
var parsed = Cryptpad.parsePadUrl(window.location.href);
|
||||||
|
parsed.type = parsed.type.replace('pad2', 'pad');
|
||||||
|
if (!parsed.type) { throw new Error(); }
|
||||||
|
var defaultTitle = Cryptpad.getDefaultName(parsed);
|
||||||
|
var updateMeta = function () {
|
||||||
|
//console.log('EV_METADATA_UPDATE');
|
||||||
|
var name;
|
||||||
|
nThen(function (waitFor) {
|
||||||
|
Cryptpad.getLastName(waitFor(function (err, n) {
|
||||||
|
if (err) { console.log(err); }
|
||||||
|
name = n;
|
||||||
|
}));
|
||||||
|
}).nThen(function (waitFor) {
|
||||||
|
sframeChan.event('EV_METADATA_UPDATE', {
|
||||||
|
doc: {
|
||||||
|
defaultTitle: defaultTitle,
|
||||||
|
type: parsed.type
|
||||||
|
},
|
||||||
|
user: {
|
||||||
|
name: name,
|
||||||
|
uid: Cryptpad.getUid(),
|
||||||
|
avatar: Cryptpad.getAvatarUrl(),
|
||||||
|
profile: Cryptpad.getProfileUrl(),
|
||||||
|
curvePublic: Cryptpad.getProxy().curvePublic,
|
||||||
|
netfluxId: Cryptpad.getNetwork().webChannels[0].myID,
|
||||||
|
},
|
||||||
|
priv: {
|
||||||
|
accountName: Cryptpad.getAccountName(),
|
||||||
|
origin: window.location.origin,
|
||||||
|
pathname: window.location.pathname,
|
||||||
|
readOnly: readOnly,
|
||||||
|
availableHashes: hashes
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
Cryptpad.onDisplayNameChanged(updateMeta);
|
||||||
|
sframeChan.onReg('EV_METADATA_UPDATE', updateMeta);
|
||||||
|
|
||||||
var parsed = Cryptpad.parsePadUrl(window.location.href);
|
Cryptpad.onError(function (info) {
|
||||||
parsed.type = parsed.type.replace('pad2', 'pad');
|
console.log('error');
|
||||||
if (!parsed.type) { throw new Error(); }
|
console.log(info);
|
||||||
var defaultTitle = Cryptpad.getDefaultName(parsed);
|
if (info && info.type === "store") {
|
||||||
var updateMeta = function () {
|
//onConnectError();
|
||||||
//console.log('EV_METADATA_UPDATE');
|
}
|
||||||
var name;
|
});
|
||||||
nThen(function (waitFor) {
|
|
||||||
Cryptpad.getLastName(waitFor(function (err, n) {
|
sframeChan.on('Q_SET_PAD_TITLE_IN_DRIVE', function (newTitle, cb) {
|
||||||
if (err) { console.log(err); }
|
Cryptpad.renamePad(newTitle, undefined, function (err) {
|
||||||
name = n;
|
if (err) { cb('ERROR'); } else { cb(); }
|
||||||
}));
|
|
||||||
}).nThen(function (waitFor) {
|
|
||||||
sframeChan.event('EV_METADATA_UPDATE', {
|
|
||||||
doc: {
|
|
||||||
defaultTitle: defaultTitle,
|
|
||||||
type: parsed.type
|
|
||||||
},
|
|
||||||
user: {
|
|
||||||
name: name,
|
|
||||||
uid: Cryptpad.getUid(),
|
|
||||||
avatar: Cryptpad.getAvatarUrl(),
|
|
||||||
profile: Cryptpad.getProfileUrl(),
|
|
||||||
curvePublic: Cryptpad.getProxy().curvePublic,
|
|
||||||
netfluxId: Cryptpad.getNetwork().webChannels[0].myID,
|
|
||||||
},
|
|
||||||
priv: {
|
|
||||||
accountName: Cryptpad.getAccountName(),
|
|
||||||
origin: window.location.origin,
|
|
||||||
pathname: window.location.pathname,
|
|
||||||
readOnly: readOnly,
|
|
||||||
availableHashes: hashes
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
|
||||||
Cryptpad.onDisplayNameChanged(updateMeta);
|
|
||||||
sframeChan.onReg('EV_METADATA_UPDATE', updateMeta);
|
|
||||||
|
|
||||||
Cryptpad.onError(function (info) {
|
sframeChan.on('Q_SETTINGS_SET_DISPLAY_NAME', function (newName, cb) {
|
||||||
console.log('error');
|
Cryptpad.setAttribute('username', newName, function (err) {
|
||||||
console.log(info);
|
if (err) {
|
||||||
if (info && info.type === "store") {
|
console.log("Couldn't set username");
|
||||||
//onConnectError();
|
console.error(err);
|
||||||
}
|
cb('ERROR');
|
||||||
});
|
return;
|
||||||
|
}
|
||||||
sframeChan.on('Q_SET_PAD_TITLE_IN_DRIVE', function (newTitle, cb) {
|
Cryptpad.changeDisplayName(newName, true);
|
||||||
Cryptpad.renamePad(newTitle, undefined, function (err) {
|
cb();
|
||||||
if (err) { cb('ERROR'); } else { cb(); }
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
sframeChan.on('Q_SETTINGS_SET_DISPLAY_NAME', function (newName, cb) {
|
sframeChan.on('Q_LOGOUT', function (data, cb) {
|
||||||
Cryptpad.setAttribute('username', newName, function (err) {
|
Cryptpad.logout(cb);
|
||||||
if (err) {
|
});
|
||||||
console.log("Couldn't set username");
|
|
||||||
console.error(err);
|
sframeChan.on('Q_SET_LOGIN_REDIRECT', function (data, cb) {
|
||||||
cb('ERROR');
|
sessionStorage.redirectTo = window.location.href;
|
||||||
return;
|
|
||||||
}
|
|
||||||
Cryptpad.changeDisplayName(newName, true);
|
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
sframeChan.on('Q_LOGOUT', function (data, cb) {
|
CpNfOuter.start({
|
||||||
Cryptpad.logout(cb);
|
sframeChan: sframeChan,
|
||||||
});
|
channel: secret.channel,
|
||||||
|
network: Cryptpad.getNetwork(),
|
||||||
sframeChan.on('Q_SET_LOGIN_REDIRECT', function (data, cb) {
|
validateKey: secret.keys.validateKey || undefined,
|
||||||
sessionStorage.redirectTo = window.location.href;
|
readOnly: readOnly,
|
||||||
cb();
|
crypto: Crypto.createEncryptor(secret.keys),
|
||||||
});
|
onConnect: function (wc) {
|
||||||
|
if (readOnly) { return; }
|
||||||
sframeChan.on('Q_STORE_LINK_TO_CLIPBOARD', function (readOnly, cb) {
|
Cryptpad.replaceHash(Cryptpad.getEditHashFromKeys(wc.id, secret.keys));
|
||||||
if (readOnly) {
|
}
|
||||||
if (!hashes.viewHash) { return void cb('E_INVALID_HASH'); }
|
});
|
||||||
var url = window.location.origin + window.location.pathname + '#' + hashes.viewHash;
|
|
||||||
var success = Cryptpad.Clipboard.copy(url);
|
|
||||||
cb(!success);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!hashes.editHash) { return void cb('E_INVALID_HASH'); }
|
|
||||||
var eUrl = window.location.origin + window.location.pathname + '#' + hashes.editHash;
|
|
||||||
var eSuccess = Cryptpad.Clipboard.copy(eUrl);
|
|
||||||
cb(!eSuccess);
|
|
||||||
});
|
|
||||||
|
|
||||||
CpNfOuter.start({
|
|
||||||
sframeChan: sframeChan,
|
|
||||||
channel: secret.channel,
|
|
||||||
network: Cryptpad.getNetwork(),
|
|
||||||
validateKey: secret.keys.validateKey || undefined,
|
|
||||||
readOnly: readOnly,
|
|
||||||
crypto: Crypto.createEncryptor(secret.keys),
|
|
||||||
onConnect: function (wc) {
|
|
||||||
if (readOnly) { return; }
|
|
||||||
Cryptpad.replaceHash(Cryptpad.getEditHashFromKeys(wc.id, secret.keys));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Loading…
x
Reference in New Issue
Block a user