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

pull/1/head
ansuz 7 years ago
commit cca3c04d43

@ -172,7 +172,9 @@ define(function () {
out.viewOpen = "Voir dans un nouvel onglet"; out.viewOpen = "Voir dans un nouvel onglet";
out.viewOpenTitle = "Ouvrir le lien en lecture seule dans un nouvel onglet"; out.viewOpenTitle = "Ouvrir le lien en lecture seule dans un nouvel onglet";
out.fileShare = "Copier le lien"; out.fileShare = "Copier le lien";
out.fileEmbed = "Obtenir le code d'intégration"; out.getEmbedCode = "Obtenir le code d'intégration";
out.viewEmbedTitle = "Intégrer le pad dans une page web";
out.viewEmbedTag = "Pour intégrer ce pad, veuillez inclure l'iframe suivant dans votre page là om vous souhaitez l'afficher. Vous pouvez changer sa taille en utilisant du code CSS ou des attributs HTML.";
out.fileEmbedTitle = "Intégrer le fichier dans une page web"; out.fileEmbedTitle = "Intégrer le fichier dans une page web";
out.fileEmbedScript = "Pour intégrer un fichier, veuillez inclure le script suivant une fois dans votre page afin de pouvoir charger le Media Tag :"; out.fileEmbedScript = "Pour intégrer un fichier, veuillez inclure le script suivant une fois dans votre page afin de pouvoir charger le Media Tag :";
out.fileEmbedTag = "Ensuite vous pouvez placer ce Media Tag où vous souhaitez dans votre page pour l'intégrer :"; out.fileEmbedTag = "Ensuite vous pouvez placer ce Media Tag où vous souhaitez dans votre page pour l'intégrer :";

@ -174,7 +174,9 @@ define(function () {
out.viewOpen = "Open read-only link in a new tab"; out.viewOpen = "Open read-only link in a new tab";
out.viewOpenTitle = "Open this pad in read-only mode in a new tab"; out.viewOpenTitle = "Open this pad in read-only mode in a new tab";
out.fileShare = "Copy link"; out.fileShare = "Copy link";
out.fileEmbed = "Get embed code"; out.getEmbedCode = "Get embed code";
out.viewEmbedTitle = "Embed the pad in an external page";
out.viewEmbedTag = "To embed this pad, include this iframe in your page wherever you want. You can style it using CSS or HTML attributes.";
out.fileEmbedTitle = "Embed the file in an external page"; out.fileEmbedTitle = "Embed the file in an external page";
out.fileEmbedScript = "To embed this file, include this script once in your page to load the Media Tag:"; out.fileEmbedScript = "To embed this file, include this script once in your page to load the Media Tag:";
out.fileEmbedTag = "Then place this Media Tag wherever in your page you would like to embed:"; out.fileEmbedTag = "Then place this Media Tag wherever in your page you would like to embed:";

@ -193,6 +193,39 @@ define([
&& secret.hashData.present); && secret.hashData.present);
}, "Couldn't handle multiple successive slashes"); }, "Couldn't handle multiple successive slashes");
// test support for present & embed mode in hashes
assert(function (cb) {
var secret = Cryptpad.parsePadUrl('/pad/#/1/edit//CmN5+YJkrHFS3NSBg-P7Sg/DNZ2wcG683GscU4fyOyqA87G/embed/present/');
return cb(secret.hashData.version === 1
&& secret.hashData.mode === "edit"
&& secret.hashData.channel === "CmN5+YJkrHFS3NSBg-P7Sg"
&& secret.hashData.key === "DNZ2wcG683GscU4fyOyqA87G"
&& secret.hashData.present
&& secret.hashData.embed);
}, "Couldn't handle multiple successive slashes");
// test support for present & embed mode in hashes
assert(function (cb) {
var secret = Cryptpad.parsePadUrl('/pad/#/1/edit//CmN5+YJkrHFS3NSBg-P7Sg/DNZ2wcG683GscU4fyOyqA87G/present/embed');
return cb(secret.hashData.version === 1
&& secret.hashData.mode === "edit"
&& secret.hashData.channel === "CmN5+YJkrHFS3NSBg-P7Sg"
&& secret.hashData.key === "DNZ2wcG683GscU4fyOyqA87G"
&& secret.hashData.present
&& secret.hashData.embed);
}, "Couldn't handle multiple successive slashes");
// test support for embed mode in hashes
assert(function (cb) {
var secret = Cryptpad.parsePadUrl('/pad/#/1/edit//CmN5+YJkrHFS3NSBg-P7Sg/DNZ2wcG683GscU4fyOyqA87G///embed//');
return cb(secret.hashData.version === 1
&& secret.hashData.mode === "edit"
&& secret.hashData.channel === "CmN5+YJkrHFS3NSBg-P7Sg"
&& secret.hashData.key === "DNZ2wcG683GscU4fyOyqA87G"
&& !secret.hashData.present
&& secret.hashData.embed);
}, "Couldn't handle multiple successive slashes");
// test support for trailing slash // test support for trailing slash
assert(function (cb) { assert(function (cb) {
var secret = Cryptpad.parsePadUrl('/pad/#/1/edit/3Ujt4F2Sjnjbis6CoYWpoQ/usn4+9CqVja8Q7RZOGTfRgqI/'); var secret = Cryptpad.parsePadUrl('/pad/#/1/edit/3Ujt4F2Sjnjbis6CoYWpoQ/usn4+9CqVja8Q7RZOGTfRgqI/');

@ -112,6 +112,7 @@ define([
var updateIndentSettings = function () { var updateIndentSettings = function () {
if (!metadataMgr) { return; } if (!metadataMgr) { return; }
var data = metadataMgr.getPrivateData().settings; var data = metadataMgr.getPrivateData().settings;
data = data.codemirror || {};
var indentUnit = data[indentKey]; var indentUnit = data[indentKey];
var useTabs = data[useTabsKey]; var useTabs = data[useTabsKey];
setIndentation( setIndentation(
@ -255,7 +256,7 @@ define([
readOnly = metadataMgr.getPrivateData().readOnly; readOnly = metadataMgr.getPrivateData().readOnly;
var titleCfg = { getHeadingText: CodeMirror.getHeadingText }; var titleCfg = { getHeadingText: CodeMirror.getHeadingText };
Title = common.createTitle(titleCfg, config.onLocal, common, metadataMgr); Title = common.createTitle(titleCfg, config.onLocal);
var configTb = { var configTb = {
displayed: ['title', 'useradmin', 'spinner', 'share', 'userlist', 'newpad', 'limit'], displayed: ['title', 'useradmin', 'spinner', 'share', 'userlist', 'newpad', 'limit'],
@ -368,7 +369,7 @@ define([
} }
} }
}; };
common.initFilePicker(common, fileDialogCfg); common.initFilePicker(fileDialogCfg);
APP.$mediaTagButton = $('<button>', { APP.$mediaTagButton = $('<button>', {
title: Messages.filePickerButton, title: Messages.filePickerButton,
'class': 'cp-toolbar-rightside-button fa fa-picture-o', 'class': 'cp-toolbar-rightside-button fa fa-picture-o',
@ -378,7 +379,7 @@ define([
types: ['file'], types: ['file'],
where: ['root'] where: ['root']
}; };
common.openFilePicker(common, pickerCfg); common.openFilePicker(pickerCfg);
}).appendTo($rightside); }).appendTo($rightside);
}; };
@ -488,7 +489,7 @@ define([
} }
if (isNew) { if (isNew) {
common.openTemplatePicker(common); common.openTemplatePicker();
} }
var fmConfig = { var fmConfig = {

@ -68,7 +68,9 @@ Version 1
parsed.mode = hashArr[2]; parsed.mode = hashArr[2];
parsed.channel = hashArr[3]; parsed.channel = hashArr[3];
parsed.key = hashArr[4].replace(/-/g, '/'); parsed.key = hashArr[4].replace(/-/g, '/');
parsed.present = typeof(hashArr[5]) === "string" && hashArr[5] === 'present'; var options = hashArr.slice(5);
parsed.present = options.indexOf('present') !== -1;
parsed.embed = options.indexOf('embed') !== -1;
return parsed; return parsed;
} }
return parsed; return parsed;
@ -115,6 +117,27 @@ Version 1
var idx; var idx;
ret.getUrl = function (options) {
options = options || {};
var url = '/';
if (!ret.type) { return url; }
url += ret.type + '/';
if (!ret.hashData) { return url; }
if (ret.hashData.type !== 'pad') { return url + '#' + ret.hash; }
if (ret.hashData.version !== 1) { throw new Error("Only v1 hashes are managed here."); }
url += '#/' + ret.hashData.version +
'/' + ret.hashData.mode +
'/' + ret.hashData.channel.replace(/\//g, '-') +
'/' + ret.hashData.key.replace(/\//g, '-') +'/';
if (options.embed) {
url += 'embed/';
}
if (options.present) {
url += 'present/';
}
return url;
};
if (!/^https*:\/\//.test(href)) { if (!/^https*:\/\//.test(href)) {
idx = href.indexOf('/#'); idx = href.indexOf('/#');
ret.type = href.slice(1, idx); ret.type = href.slice(1, idx);

@ -196,11 +196,14 @@ define([
return store.getProfile().avatar; return store.getProfile().avatar;
} }
}; };
common.getDisplayName = function () { common.getDisplayName = function (cb) {
var name;
if (getProxy()) { if (getProxy()) {
return getProxy()[common.displayNameKey] || ''; name = getProxy()[common.displayNameKey];
} }
return ''; name = name || '';
if (typeof cb === "function") { cb(null, name); }
return name;
}; };
common.getAccountName = function () { common.getAccountName = function () {
return localStorage[common.userNameKey]; return localStorage[common.userNameKey];
@ -481,11 +484,22 @@ define([
var href = getRelativeHref(window.location.href); var href = getRelativeHref(window.location.href);
getStore().setPadAttribute(href, attr, value, cb); getStore().setPadAttribute(href, attr, value, cb);
}; };
common.setDisplayName = function (value, cb) {
if (getProxy()) {
getProxy()[common.displayNameKey] = value;
}
if (typeof cb === "function") { cb(); }
};
common.setAttribute = function (attr, value, cb) { common.setAttribute = function (attr, value, cb) {
getStore().set(["cryptpad", attr].join('.'), value, function (err, data) { getStore().setAttribute(attr, value, function (err, data) {
if (cb) { cb(err, data); } if (cb) { cb(err, data); }
}); });
}; };
/*common.setAttribute = function (attr, value, cb) {
getStore().set(["cryptpad", attr].join('.'), value, function (err, data) {
if (cb) { cb(err, data); }
});
};*/
common.setLSAttribute = function (attr, value) { common.setLSAttribute = function (attr, value) {
localStorage[attr] = value; localStorage[attr] = value;
}; };
@ -496,10 +510,15 @@ define([
getStore().getPadAttribute(href, attr, cb); getStore().getPadAttribute(href, attr, cb);
}; };
common.getAttribute = function (attr, cb) { common.getAttribute = function (attr, cb) {
getStore().get(["cryptpad", attr].join('.'), function (err, data) { getStore().getAttribute(attr, function (err, data) {
cb(err, data); cb(err, data);
}); });
}; };
/*common.getAttribute = function (attr, cb) {
getStore().get(["cryptpad", attr].join('.'), function (err, data) {
cb(err, data);
});
};*/
/* this returns a reference to your proxy. changing it will change your drive. /* this returns a reference to your proxy. changing it will change your drive.
*/ */
@ -663,11 +682,12 @@ define([
}; };
// STORAGE: Display Name // STORAGE: Display Name
common.getLastName = function (cb) { common.getLastName = common.getDisplayName;
common.getAttribute('username', function (err, userName) { /* function (cb) {
common.getDisplayName(function (err, userName) {
cb(err, userName); cb(err, userName);
}); });
}; };*/
var _onDisplayNameChanged = []; var _onDisplayNameChanged = [];
common.onDisplayNameChanged = function (h) { common.onDisplayNameChanged = function (h) {
if (typeof(h) !== "function") { return; } if (typeof(h) !== "function") { return; }
@ -694,7 +714,8 @@ define([
var href = typeof padHref === "string" ? padHref : window.location.href; var href = typeof padHref === "string" ? padHref : window.location.href;
var parsed = parsePadUrl(href); var parsed = parsePadUrl(href);
if (!parsed.hash) { return; } if (!parsed.hash) { return; }
href = getRelativeHref(href); href = parsed.getUrl({present: parsed.present});
//href = getRelativeHref(href);
// getRecentPads return the array from the drive, not a copy // getRecentPads return the array from the drive, not a copy
// We don't have to call "set..." at the end, everything is stored with listmap // We don't have to call "set..." at the end, everything is stored with listmap
getRecentPads(function (err, recent) { getRecentPads(function (err, recent) {

@ -61,8 +61,46 @@ define([
cb(void 0, res); cb(void 0, res);
}; };
ret.setPadAttribute = filesOp.setAttribute; var getAttributeObject = function (attr) {
ret.getPadAttribute = filesOp.getAttribute; if (typeof attr === "string") {
console.error('DEPRECATED: use setAttribute with an array, not a string');
return {
obj: storeObj.settings,
key: attr
};
}
if (!Array.isArray(attr)) { throw new Error("Attribute must be string or array"); }
if (attr.length === 0) { throw new Error("Attribute can't be empty"); }
var obj = storeObj.settings;
attr.forEach(function (el, i) {
if (i === attr.length-1) { return; }
if (!obj[el]) {
obj[el] = {};
}
else if (typeof obj[el] !== "object") { throw new Error("Wrong attribute"); }
obj = obj[el];
});
return {
obj: obj,
key: attr[attr.length-1]
};
};
ret.setAttribute = function (attr, value, cb) {
try {
var object = getAttributeObject(attr);
object.obj[object.key] = value;
} catch (e) { return void cb(e); }
cb();
};
ret.getAttribute = function (attr, cb) {
var object;
try {
object = getAttributeObject(attr);
} catch (e) { return void cb(e); }
cb(null, object.obj[object.key]);
};
ret.setPadAttribute = filesOp.setPadAttribute;
ret.getPadAttribute = filesOp.getPadAttribute;
ret.getIdFromHref = filesOp.getIdFromHref; ret.getIdFromHref = filesOp.getIdFromHref;
ret.getDrive = function (key, cb) { ret.getDrive = function (key, cb) {

@ -64,5 +64,37 @@ define([], function () {
Cryptpad.feedback('Migrate-2', true); Cryptpad.feedback('Migrate-2', true);
userObject.version = version = 2; userObject.version = version = 2;
} }
// Migration 3: global attributes from root to 'settings' subobjects
var migrateAttributes = function () {
var drawer = 'cryptpad.userlist-drawer';
var polls = 'cryptpad.hide_poll_text';
var indentKey = 'indentUnit';
var useTabsKey = 'indentWithTabs';
var settings = userObject.settings = userObject.settings || {};
if (settings[indentKey] || settings[useTabsKey]) {
settings.codemirror = settings.codemirror || {};
settings.codemirror.indentUnit = settings[indentKey];
settings.codemirror.indentWithTabs = settings[useTabsKey];
delete settings[indentKey];
delete settings[useTabsKey];
}
if (userObject[drawer]) {
settings.toolbar = settings.toolbar || {};
settings.toolbar['userlist-drawer'] = userObject[drawer];
delete userObject[drawer];
}
if (userObject[polls]) {
settings.poll = settings.poll || {};
settings.poll['hide-text'] = userObject[polls];
delete userObject[polls];
}
};
if (version < 3) {
migrateAttributes();
Cryptpad.feedback('Migrate-3', true);
userObject.version = version = 3;
}
}; };
}); });

@ -7,7 +7,7 @@ define([
return Math.random().toString(16).replace('0.', '') + Math.random().toString(16).replace('0.', ''); return Math.random().toString(16).replace('0.', '') + Math.random().toString(16).replace('0.', '');
}; };
var create = function (ow, cb) { var create = function (ow, cb, isSandbox) {
var otherWindow; var otherWindow;
var handlers = {}; var handlers = {};
var queries = {}; var queries = {};
@ -131,7 +131,7 @@ define([
console.log(msg); console.log(msg);
} }
}); });
if (window !== window.top) { if (isSandbox) {
// we're in the sandbox // we're in the sandbox
otherWindow = ow; otherWindow = ow;
cb(chan); cb(chan);

@ -23,6 +23,11 @@ define([
} }
}; };
module.uploadFile = function (common, data, cb) {
var sframeChan = common.getSframeChannel();
sframeChan.query('Q_UPLOAD_FILE', data, cb);
};
module.create = function (common, config) { module.create = function (common, config) {
var File = {}; var File = {};
var Cryptpad = common.getCryptpadCommon(); var Cryptpad = common.getCryptpadCommon();

@ -22,6 +22,173 @@ define([
* - createDropdown * - createDropdown
*/ */
UI.createButton = function (common, type, rightside, data, callback) {
var AppConfig = common.getAppConfig();
var button;
var size = "17px";
switch (type) {
case 'export':
button = $('<button>', {
'class': 'fa fa-download',
title: Messages.exportButtonTitle,
}).append($('<span>', {'class': 'cp-toolbar-drawer-element'}).text(Messages.exportButton));
button.click(common.prepareFeedback(type));
if (callback) {
button.click(callback);
}
break;
case 'import':
button = $('<button>', {
'class': 'fa fa-upload',
title: Messages.importButtonTitle,
}).append($('<span>', {'class': 'cp-toolbar-drawer-element'}).text(Messages.importButton));
if (callback) {
button
.click(common.prepareFeedback(type))
.click(Cryptpad.importContent('text/plain', function (content, file) {
callback(content, file);
}, {accept: data ? data.accept : undefined}));
}
break;
case 'upload':
button = $('<button>', {
'class': 'btn btn-primary new',
title: Messages.uploadButtonTitle,
}).append($('<span>', {'class':'fa fa-upload'})).append(' '+Messages.uploadButton);
if (!data.FM) { return; }
var $input = $('<input>', {
'type': 'file',
'style': 'display: none;'
}).on('change', function (e) {
var file = e.target.files[0];
var ev = {
target: data.target
};
if (data.filter && !data.filter(file)) {
Cryptpad.log('TODO: invalid avatar (type or size)');
return;
}
data.FM.handleFile(file, ev);
if (callback) { callback(); }
});
if (data.accept) { $input.attr('accept', data.accept); }
button.click(function () { $input.click(); });
break;
case 'template':
if (!AppConfig.enableTemplates) { return; }
button = $('<button>', {
title: Messages.saveTemplateButton,
}).append($('<span>', {'class':'fa fa-bookmark', style: 'font:'+size+' FontAwesome'}));
if (data.rt) {
button
.click(function () {
var title = data.getTitle() || document.title;
var todo = function (val) {
if (typeof(val) !== "string") { return; }
var toSave = data.rt.getUserDoc();
if (val.trim()) {
val = val.trim();
title = val;
try {
var parsed = JSON.parse(toSave);
var meta;
if (Array.isArray(parsed) && typeof(parsed[3]) === "object") {
meta = parsed[3].metadata; // pad
} else if (parsed.info) {
meta = parsed.info; // poll
} else {
meta = parsed.metadata;
}
if (typeof(meta) === "object") {
meta.title = val;
meta.defaultTitle = val;
delete meta.users;
}
toSave = JSON.stringify(parsed);
} catch(e) {
console.error("Parse error while setting the title", e);
}
}
ctx.sframeChan.query('Q_SAVE_AS_TEMPLATE', {
title: title,
toSave: toSave
}, function () {
Cryptpad.alert(Messages.templateSaved);
common.feedback('TEMPLATE_CREATED');
});
};
Cryptpad.prompt(Messages.saveTemplatePrompt, title, todo);
});
}
break;
case 'forget':
button = $('<button>', {
id: 'cryptpad-forget',
title: Messages.forgetButtonTitle,
'class': "fa fa-trash cryptpad-forget",
style: 'font:'+size+' FontAwesome'
});
if (!common.isStrongestStored()) {
button.addClass('cp-toolbar-hidden');
}
if (callback) {
button
.click(common.prepareFeedback(type))
.click(function() {
var msg = isLoggedIn() ? Messages.forgetPrompt : Messages.fm_removePermanentlyDialog;
Cryptpad.confirm(msg, function (yes) {
if (!yes) { return; }
ctx.sframeChan.query('Q_MOVE_TO_TRASH', null, function (err) {
if (err) { return void callback(err); }
var cMsg = isLoggedIn() ? Messages.movedToTrash : Messages.deleted;
Cryptpad.alert(cMsg, undefined, true);
callback();
return;
});
});
});
}
break;
case 'history':
if (!AppConfig.enableHistory) {
button = $('<span>');
break;
}
button = $('<button>', {
title: Messages.historyButton,
'class': "fa fa-history history",
}).append($('<span>', {'class': 'cp-toolbar-drawer-element'}).text(Messages.historyText));
if (data.histConfig) {
button
.click(common.prepareFeedback(type))
.on('click', function () {
common.getHistory(data.histConfig);
});
}
break;
case 'more':
button = $('<button>', {
title: Messages.moreActions || 'TODO',
'class': "cp-toolbar-drawer-button fa fa-ellipsis-h",
style: 'font:'+size+' FontAwesome'
});
break;
default:
button = $('<button>', {
'class': "fa fa-question",
style: 'font:'+size+' FontAwesome'
})
.click(common.prepareFeedback(type));
}
if (rightside) {
button.addClass('cp-toolbar-rightside-button');
}
return button;
};
UI.getFileSize = function (Common, href, cb) { UI.getFileSize = function (Common, href, cb) {
var channelId = Cryptpad.hrefToHexChannelId(href); var channelId = Cryptpad.hrefToHexChannelId(href);
Common.sendAnonRpcMsg("GET_FILE_SIZE", channelId, function (data) { Common.sendAnonRpcMsg("GET_FILE_SIZE", channelId, function (data) {
@ -101,9 +268,8 @@ define([
} }
}; };
UI.createUserAdminMenu = function (config) { UI.createUserAdminMenu = function (Common, config) {
var Common = config.Common; var metadataMgr = Common.getMetadataMgr();
var metadataMgr = config.metadataMgr;
var displayNameCls = config.displayNameCls || 'displayName'; var displayNameCls = config.displayNameCls || 'displayName';
var $displayedName = $('<span>', {'class': displayNameCls}); var $displayedName = $('<span>', {'class': displayNameCls});
@ -230,31 +396,31 @@ define([
$userAdmin.find('a.logout').click(function () { $userAdmin.find('a.logout').click(function () {
Common.logout(function () { Common.logout(function () {
window.top.location = origin+'/'; window.parent.location = origin+'/';
}); });
}); });
$userAdmin.find('a.settings').click(function () { $userAdmin.find('a.settings').click(function () {
if (padType) { if (padType) {
window.open(origin+'/settings/'); window.open(origin+'/settings/');
} else { } else {
window.top.location = origin+'/settings/'; window.parent.location = origin+'/settings/';
} }
}); });
$userAdmin.find('a.profile').click(function () { $userAdmin.find('a.profile').click(function () {
if (padType) { if (padType) {
window.open(origin+'/profile/'); window.open(origin+'/profile/');
} else { } else {
window.top.location = origin+'/profile/'; window.parent.location = origin+'/profile/';
} }
}); });
$userAdmin.find('a.login').click(function () { $userAdmin.find('a.login').click(function () {
Common.setLoginRedirect(function () { Common.setLoginRedirect(function () {
window.top.location = origin+'/login/'; window.parent.location = origin+'/login/';
}); });
}); });
$userAdmin.find('a.register').click(function () { $userAdmin.find('a.register').click(function () {
Common.setLoginRedirect(function () { Common.setLoginRedirect(function () {
window.top.location = origin+'/register/'; window.parent.location = origin+'/register/';
}); });
}); });

@ -82,7 +82,9 @@ define([
isTemplate: Cryptpad.isTemplate(window.location.href), isTemplate: Cryptpad.isTemplate(window.location.href),
feedbackAllowed: Cryptpad.isFeedbackAllowed(), feedbackAllowed: Cryptpad.isFeedbackAllowed(),
friends: proxy.friends || {}, friends: proxy.friends || {},
settings: proxy.settings || {} settings: proxy.settings || {},
isPresent: parsed.hashData && parsed.hashData.present,
isEmbed: parsed.hashData && parsed.hashData.embed,
} }
}); });
}); });
@ -113,7 +115,7 @@ define([
}); });
sframeChan.on('Q_SETTINGS_SET_DISPLAY_NAME', function (newName, cb) { sframeChan.on('Q_SETTINGS_SET_DISPLAY_NAME', function (newName, cb) {
Cryptpad.setAttribute('username', newName, function (err) { Cryptpad.setDisplayName(newName, function (err) {
if (err) { if (err) {
console.log("Couldn't set username"); console.log("Couldn't set username");
console.error(err); console.error(err);
@ -218,6 +220,20 @@ define([
}); });
}); });
sframeChan.on('Q_GET_ATTRIBUTE', function (data, cb) {
Cryptpad.getAttribute(data.key, function (e, data) {
cb({
error: e,
data: data
});
});
});
sframeChan.on('Q_SET_ATTRIBUTE', function (data, cb) {
Cryptpad.setAttribute(data.key, data.value, function (e) {
cb({error:e});
});
});
var onFileUpload = function (sframeChan, data, cb) { var onFileUpload = function (sframeChan, data, cb) {
var sendEvent = function (data) { var sendEvent = function (data) {
@ -290,6 +306,13 @@ define([
readOnly: readOnly, readOnly: readOnly,
crypto: Crypto.createEncryptor(secret.keys), crypto: Crypto.createEncryptor(secret.keys),
onConnect: function (wc) { onConnect: function (wc) {
if (window.location.hash && window.location.hash !== '#') {
window.location = parsed.getUrl({
present: parsed.hashData.present,
embed: parsed.hashData.embed
});
return;
}
if (readOnly) { return; } if (readOnly) { return; }
Cryptpad.replaceHash(Cryptpad.getEditHashFromKeys(wc.id, secret.keys)); Cryptpad.replaceHash(Cryptpad.getEditHashFromKeys(wc.id, secret.keys));
} }

@ -1,34 +1,26 @@
define(['jquery'], function ($) { define(['jquery'], function ($) {
var module = {}; var module = {};
module.create = function (cfg, onLocal, Common, metadataMgr) { module.create = function (Common, cfg, onLocal) {
var exp = {}; var exp = {};
var metadataMgr = Common.getMetadataMgr();
var sframeChan = Common.getSframeChannel();
var titleUpdated;
exp.defaultTitle = Common.getDefaultTitle(); exp.defaultTitle = metadataMgr.getMetadata().defaultTitle;
exp.title = document.title; exp.title = document.title;
cfg = cfg || {}; cfg = cfg || {};
var getHeadingText = cfg.getHeadingText || function () { return; }; var getHeadingText = cfg.getHeadingText || function () { return; };
/* var updateLocalTitle = function (newTitle) {
console.error(newTitle);
exp.title = newTitle;
onLocal();
if (typeof cfg.updateLocalTitle === "function") {
cfg.updateLocalTitle(newTitle);
} else {
document.title = newTitle;
}
};*/
var $title; var $title;
exp.setToolbar = function (toolbar) { exp.setToolbar = function (toolbar) {
$title = toolbar && toolbar.title; $title = toolbar && toolbar.title;
}; };
exp.getTitle = function () { return exp.title; }; exp.getTitle = function () { return exp.title; };
var isDefaultTitle = exp.isDefaultTitle = function (){return exp.title === exp.defaultTitle;}; var isDefaultTitle = exp.isDefaultTitle = function (){return exp.title === exp.defaultTitle;};
var suggestTitle = exp.suggestTitle = function (fallback) { var suggestTitle = exp.suggestTitle = function (fallback) {
@ -40,32 +32,25 @@ define(['jquery'], function ($) {
} }
}; };
/*var renameCb = function (err, newTitle) {
if (err) { return; }
onLocal();
//updateLocalTitle(newTitle);
};*/
// update title: href is optional; if not specified, we use window.location.href // update title: href is optional; if not specified, we use window.location.href
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; }
Common.updateTitle(newTitle, cb); metadataMgr.updateTitle(newTitle);
titleUpdated = cb;
}; };
// TODO not needed?
/*exp.updateDefaultTitle = function (newDefaultTitle) {
exp.defaultTitle = newDefaultTitle;
if (!$title) { return; }
$title.find('input').attr("placeholder", exp.defaultTitle);
};*/
metadataMgr.onChange(function () { metadataMgr.onChange(function () {
var md = metadataMgr.getMetadata(); var md = metadataMgr.getMetadata();
$title.find('span.cp-toolbar-title-value').text(md.title || md.defaultTitle); $title.find('span.cp-toolbar-title-value').text(md.title || md.defaultTitle);
$title.find('input').val(md.title || md.defaultTitle); $title.find('input').val(md.title || md.defaultTitle);
exp.title = md.title; exp.title = md.title;
//exp.updateTitle(md.title || md.defaultTitle); });
metadataMgr.onTitleChange(function (title) {
sframeChan.query('Q_SET_PAD_TITLE_IN_DRIVE', title, function (err) {
if (err) { return; }
if (titleUpdated) { titleUpdated(undefined, title); }
});
}); });
exp.getTitleConfig = function () { exp.getTitleConfig = function () {

@ -31,55 +31,55 @@ define([
return ctx.cpNfInner; return ctx.cpNfInner;
}; };
funcs.getMetadataMgr = function () { funcs.getMetadataMgr = function () { return ctx.metadataMgr; };
return ctx.metadataMgr; funcs.getCryptpadCommon = function () { return Cryptpad; };
}; funcs.getSframeChannel = function () { return ctx.sframeChan; };
funcs.getCryptpadCommon = function () { funcs.getAppConfig = function () { return AppConfig; };
return Cryptpad;
};
funcs.getSframeChannel = function () {
return ctx.sframeChan;
};
var isLoggedIn = funcs.isLoggedIn = function () { var isLoggedIn = funcs.isLoggedIn = function () {
if (!ctx.cpNfInner) { throw new Error("cpNfInner is not ready!"); } if (!ctx.cpNfInner) { throw new Error("cpNfInner is not ready!"); }
return ctx.cpNfInner.metadataMgr.getPrivateData().accountName; return ctx.cpNfInner.metadataMgr.getPrivateData().accountName;
}; };
var titleUpdated; // MISC
funcs.updateTitle = function (title, cb) {
ctx.metadataMgr.updateTitle(title); // Call the selected function with 'funcs' as a (new) first parameter
titleUpdated = cb; var callWithCommon = function (f) {
return function () {
[].unshift.call(arguments, funcs);
return f.apply(null, arguments);
};
}; };
// UI // UI
funcs.createUserAdminMenu = UI.createUserAdminMenu; funcs.createUserAdminMenu = callWithCommon(UI.createUserAdminMenu);
funcs.displayAvatar = UI.displayAvatar; funcs.initFilePicker = callWithCommon(UI.initFilePicker);
funcs.initFilePicker = UI.initFilePicker; funcs.openFilePicker = callWithCommon(UI.openFilePicker);
funcs.openFilePicker = UI.openFilePicker; funcs.openTemplatePicker = callWithCommon(UI.openTemplatePicker);
funcs.openTemplatePicker = UI.openTemplatePicker; funcs.displayAvatar = callWithCommon(UI.displayAvatar);
funcs.createButton = callWithCommon(UI.createButton);
// History // History
funcs.getHistory = function (config) { return History.create(funcs, config); }; funcs.getHistory = callWithCommon(History.create);
// Title module // Title module
funcs.createTitle = Title.create; funcs.createTitle = callWithCommon(Title.create);
funcs.getDefaultTitle = function () { // Files
if (!ctx.cpNfInner) { throw new Error("cpNfInner is not ready!"); } funcs.uploadFile = callWithCommon(File.uploadFile);
return ctx.cpNfInner.metadataMgr.getMetadata().defaultTitle; funcs.createFileManager = callWithCommon(File.create);
};
// Misc
funcs.setDisplayName = function (name, cb) { funcs.setDisplayName = function (name, cb) {
ctx.sframeChan.query('Q_SETTINGS_SET_DISPLAY_NAME', name, function (err) { cb = cb || $.noop;
if (cb) { cb(err); } ctx.sframeChan.query('Q_SETTINGS_SET_DISPLAY_NAME', name, cb);
});
}; };
// Window
funcs.logout = function (cb) { funcs.logout = function (cb) {
ctx.sframeChan.query('Q_LOGOUT', null, function (err) { cb = cb || $.noop;
if (cb) { cb(err); } ctx.sframeChan.query('Q_LOGOUT', null, cb);
});
}; };
funcs.notify = function () { funcs.notify = function () {
@ -87,11 +87,11 @@ define([
}; };
funcs.setLoginRedirect = function (cb) { funcs.setLoginRedirect = function (cb) {
ctx.sframeChan.query('Q_SET_LOGIN_REDIRECT', null, function (err) { cb = cb || $.noop;
if (cb) { cb(err); } ctx.sframeChan.query('Q_SET_LOGIN_REDIRECT', null, cb);
});
}; };
// Store
funcs.sendAnonRpcMsg = function (msg, content, cb) { funcs.sendAnonRpcMsg = function (msg, content, cb) {
ctx.sframeChan.query('Q_ANON_RPC_MESSAGE', { ctx.sframeChan.query('Q_ANON_RPC_MESSAGE', {
msg: msg, msg: msg,
@ -128,11 +128,25 @@ define([
}, cb); }, cb);
}; };
// Files funcs.getAttribute = function (key, cb) {
funcs.uploadFile = function (data, cb) { ctx.sframeChan.query('Q_GET_ATTRIBUTE', {
ctx.sframeChan.query('Q_UPLOAD_FILE', data, cb); key: key
}, function (err, res) {
cb (err || res.error, res.data);
});
};
funcs.setAttribute = function (key, value, cb) {
cb = cb || $.noop;
ctx.sframeChan.query('Q_SET_ATTRIBUTE', {
key: key,
value: value
}, cb);
};
funcs.isStrongestStored = function () {
var data = ctx.metadataMgr.getPrivateData();
return !data.readOnly || !data.availableHashes.editHash;
}; };
funcs.createFileManager = function (config) { return File.create(funcs, config); };
// Friends // Friends
var pendingFriends = []; var pendingFriends = [];
@ -160,7 +174,7 @@ define([
url: href, url: href,
}); });
}; };
var prepareFeedback = funcs.prepareFeedback = function (key) { funcs.prepareFeedback = function (key) {
if (typeof(key) !== 'string') { return $.noop; } if (typeof(key) !== 'string') { return $.noop; }
var type = ctx.metadataMgr.getMetadata().type; var type = ctx.metadataMgr.getMetadata().type;
@ -169,178 +183,8 @@ define([
}; };
}; };
// BUTTONS // RESTRICTED
var isStrongestStored = function () { // Filepicker app
var data = ctx.metadataMgr.getPrivateData();
return !data.readOnly || !data.availableHashes.editHash;
};
funcs.createButton = function (type, rightside, data, callback) {
var button;
var size = "17px";
switch (type) {
case 'export':
button = $('<button>', {
'class': 'fa fa-download',
title: Messages.exportButtonTitle,
}).append($('<span>', {'class': 'cp-toolbar-drawer-element'}).text(Messages.exportButton));
button.click(prepareFeedback(type));
if (callback) {
button.click(callback);
}
break;
case 'import':
button = $('<button>', {
'class': 'fa fa-upload',
title: Messages.importButtonTitle,
}).append($('<span>', {'class': 'cp-toolbar-drawer-element'}).text(Messages.importButton));
if (callback) {
button
.click(prepareFeedback(type))
.click(Cryptpad.importContent('text/plain', function (content, file) {
callback(content, file);
}, {accept: data ? data.accept : undefined}));
}
break;
case 'upload':
button = $('<button>', {
'class': 'btn btn-primary new',
title: Messages.uploadButtonTitle,
}).append($('<span>', {'class':'fa fa-upload'})).append(' '+Messages.uploadButton);
if (!data.FM) { return; }
var $input = $('<input>', {
'type': 'file',
'style': 'display: none;'
}).on('change', function (e) {
var file = e.target.files[0];
var ev = {
target: data.target
};
if (data.filter && !data.filter(file)) {
Cryptpad.log('TODO: invalid avatar (type or size)');
return;
}
data.FM.handleFile(file, ev);
if (callback) { callback(); }
});
if (data.accept) { $input.attr('accept', data.accept); }
button.click(function () { $input.click(); });
break;
case 'template':
if (!AppConfig.enableTemplates) { return; }
button = $('<button>', {
title: Messages.saveTemplateButton,
}).append($('<span>', {'class':'fa fa-bookmark', style: 'font:'+size+' FontAwesome'}));
if (data.rt) {
button
.click(function () {
var title = data.getTitle() || document.title;
var todo = function (val) {
if (typeof(val) !== "string") { return; }
var toSave = data.rt.getUserDoc();
if (val.trim()) {
val = val.trim();
title = val;
try {
var parsed = JSON.parse(toSave);
var meta;
if (Array.isArray(parsed) && typeof(parsed[3]) === "object") {
meta = parsed[3].metadata; // pad
} else if (parsed.info) {
meta = parsed.info; // poll
} else {
meta = parsed.metadata;
}
if (typeof(meta) === "object") {
meta.title = val;
meta.defaultTitle = val;
delete meta.users;
}
toSave = JSON.stringify(parsed);
} catch(e) {
console.error("Parse error while setting the title", e);
}
}
ctx.sframeChan.query('Q_SAVE_AS_TEMPLATE', {
title: title,
toSave: toSave
}, function () {
Cryptpad.alert(Messages.templateSaved);
funcs.feedback('TEMPLATE_CREATED');
});
};
Cryptpad.prompt(Messages.saveTemplatePrompt, title, todo);
});
}
break;
case 'forget':
button = $('<button>', {
id: 'cryptpad-forget',
title: Messages.forgetButtonTitle,
'class': "fa fa-trash cryptpad-forget",
style: 'font:'+size+' FontAwesome'
});
if (!isStrongestStored()) {
button.addClass('cp-toolbar-hidden');
}
if (callback) {
button
.click(prepareFeedback(type))
.click(function() {
var msg = isLoggedIn() ? Messages.forgetPrompt : Messages.fm_removePermanentlyDialog;
Cryptpad.confirm(msg, function (yes) {
if (!yes) { return; }
ctx.sframeChan.query('Q_MOVE_TO_TRASH', null, function (err) {
if (err) { return void callback(err); }
var cMsg = isLoggedIn() ? Messages.movedToTrash : Messages.deleted;
Cryptpad.alert(cMsg, undefined, true);
callback();
return;
});
});
});
}
break;
case 'history':
if (!AppConfig.enableHistory) {
button = $('<span>');
break;
}
button = $('<button>', {
title: Messages.historyButton,
'class': "fa fa-history history",
}).append($('<span>', {'class': 'cp-toolbar-drawer-element'}).text(Messages.historyText));
if (data.histConfig) {
button
.click(prepareFeedback(type))
.on('click', function () {
funcs.getHistory(data.histConfig);
});
}
break;
case 'more':
button = $('<button>', {
title: Messages.moreActions || 'TODO',
'class': "cp-toolbar-drawer-button fa fa-ellipsis-h",
style: 'font:'+size+' FontAwesome'
});
break;
default:
button = $('<button>', {
'class': "fa fa-question",
style: 'font:'+size+' FontAwesome'
})
.click(prepareFeedback(type));
}
if (rightside) {
button.addClass('cp-toolbar-rightside-button');
}
return button;
};
// Can, only be called by the filepicker app
funcs.getFilesList = function (types, cb) { funcs.getFilesList = function (types, cb) {
ctx.sframeChan.query('Q_GET_FILES_LIST', types, function (err, data) { ctx.sframeChan.query('Q_GET_FILES_LIST', types, function (err, data) {
cb(err || data.error, data.data); cb(err || data.error, data.data);
@ -351,22 +195,15 @@ define([
ctx.sframeChan.query('Q_STORE_LINK_TO_CLIPBOARD', readOnly, function (err) { ctx.sframeChan.query('Q_STORE_LINK_TO_CLIPBOARD', readOnly, function (err) {
if (cb) { cb(err); } if (cb) { cb(err); }
}); });
}; }; */
*/
Object.freeze(funcs); Object.freeze(funcs);
return { create: function (cb) { return { create: function (cb) {
nThen(function (waitFor) { nThen(function (waitFor) {
SFrameChannel.create(window.top, waitFor(function (sfc) { ctx.sframeChan = sfc; })); SFrameChannel.create(window.parent, waitFor(function (sfc) { ctx.sframeChan = sfc; }), true);
// CpNfInner.start() should be here.... // CpNfInner.start() should be here....
}).nThen(function () { }).nThen(function () {
ctx.metadataMgr = MetadataMgr.create(ctx.sframeChan); ctx.metadataMgr = MetadataMgr.create(ctx.sframeChan);
ctx.metadataMgr.onTitleChange(function (title) {
ctx.sframeChan.query('Q_SET_PAD_TITLE_IN_DRIVE', title, function (err) {
if (err) { return; }
if (titleUpdated) { titleUpdated(undefined, title); }
});
});
ctx.sframeChan.on('EV_RT_CONNECT', function () { CommonRealtime.setConnectionState(true); }); ctx.sframeChan.on('EV_RT_CONNECT', function () { CommonRealtime.setConnectionState(true); });
ctx.sframeChan.on('EV_RT_DISCONNECT', function () { CommonRealtime.setConnectionState(false); }); ctx.sframeChan.on('EV_RT_DISCONNECT', function () { CommonRealtime.setConnectionState(false); });

@ -85,7 +85,9 @@ define({
// Send the new settings to the inner iframe when they are changed in the proxy // Send the new settings to the inner iframe when they are changed in the proxy
'EV_SETTINGS_UPDATE': true, 'EV_SETTINGS_UPDATE': true,
// Get and set pad attributes stored in the drive from the inner iframe // Get and set (pad) attributes stored in the drive from the inner iframe
'Q_GET_ATTRIBUTE': true,
'Q_SET_ATTRIBUTE': true,
'Q_GET_PAD_ATTRIBUTE': true, 'Q_GET_PAD_ATTRIBUTE': true,
'Q_SET_PAD_ATTRIBUTE': true, 'Q_SET_PAD_ATTRIBUTE': true,

@ -351,7 +351,7 @@ define([
$content.css('margin-top', h+'px'); $content.css('margin-top', h+'px');
}); });
$closeIcon.click(function () { $closeIcon.click(function () {
Cryptpad.setAttribute('userlist-drawer', false); Cryptpad.setAttribute(['toolbar', 'userlist-drawer'], false);
hide(); hide();
}); });
$button.click(function () { $button.click(function () {
@ -359,11 +359,11 @@ define([
if (visible) { hide(); } if (visible) { hide(); }
else { show(); } else { show(); }
visible = !visible; visible = !visible;
Cryptpad.setAttribute('userlist-drawer', visible); Cryptpad.setAttribute(['toolbar', 'userlist-drawer'], visible);
Cryptpad.feedback(visible?'USERLIST_SHOW': 'USERLIST_HIDE'); Cryptpad.feedback(visible?'USERLIST_SHOW': 'USERLIST_HIDE');
}); });
Cryptpad.getAttribute('userlist-drawer', function (err, val) { Cryptpad.getAttribute(['toolbar', 'userlist-drawer'], function (err, val) {
if (val === false || mobile) { return void hide(); } if (val === false || mobile) { return void hide(); }
show(); show();
}); });
@ -491,8 +491,8 @@ define([
}); });
options.push({ options.push({
tag: 'a', tag: 'a',
attributes: {title: Messages.editShareTitle, 'class': 'fileEmbed'}, attributes: {title: Messages.fileEmbedTitle, 'class': 'fileEmbed'},
content: '<span class="fa fa-file"></span> ' + Messages.fileEmbed content: '<span class="fa fa-file"></span> ' + Messages.getEmbedCode
}); });
var dropdownConfigShare = { var dropdownConfigShare = {
text: $('<div>').append($shareIcon).html(), text: $('<div>').append($shareIcon).html(),
@ -840,7 +840,7 @@ define([
if (newName === null && typeof(lastName) === "string") { return; } if (newName === null && typeof(lastName) === "string") { return; }
if (newName === null) { newName = ''; } if (newName === null) { newName = ''; }
else { Cryptpad.feedback('NAME_CHANGED'); } else { Cryptpad.feedback('NAME_CHANGED'); }
Cryptpad.setAttribute('username', newName, function (err) { Cryptpad.setDisplayName(newName, function (err) {
if (err) { if (err) {
console.log("Couldn't set username"); console.log("Couldn't set username");
console.error(err); console.error(err);

@ -50,6 +50,12 @@ define([
var createRealtimeToolbar = function (config) { var createRealtimeToolbar = function (config) {
if (!config.$container) { return; } if (!config.$container) { return; }
var $container = config.$container; var $container = config.$container;
var isEmbed = Bar.isEmbed = config.metadataMgr.getPrivateData().isEmbed;
if (isEmbed) {
$container.hide();
}
var $toolbar = $('<div>', { var $toolbar = $('<div>', {
'class': TOOLBAR_CLS, 'class': TOOLBAR_CLS,
id: uid(), id: uid(),
@ -222,7 +228,7 @@ define([
$span.append(avatars[data.avatar]); $span.append(avatars[data.avatar]);
$span.append($rightCol); $span.append($rightCol);
} else { } else {
Common.displayAvatar(Common, $span, data.avatar, name, function ($img) { Common.displayAvatar($span, data.avatar, name, function ($img) {
if (data.avatar && $img) { if (data.avatar && $img) {
avatars[data.avatar] = $img[0].outerHTML; avatars[data.avatar] = $img[0].outerHTML;
} }
@ -250,17 +256,12 @@ define([
}; };
var initUserList = function (toolbar, config) { var initUserList = function (toolbar, config) {
// TODO clean comments if (config.metadataMgr) {
if (config.metadataMgr) { /* && config.userList.list && config.userList.userNetfluxId) {*/
//var userList = config.userList.list;
//userList.change.push
var metadataMgr = config.metadataMgr; var metadataMgr = config.metadataMgr;
metadataMgr.onChange(function () { metadataMgr.onChange(function () {
if (metadataMgr.isConnected()) {toolbar.connected = true;} if (metadataMgr.isConnected()) {toolbar.connected = true;}
if (!toolbar.connected) { return; } if (!toolbar.connected) { return; }
//if (config.userList.data) { updateUserList(toolbar, config);
updateUserList(toolbar, config);
//}
}); });
} }
}; };
@ -304,6 +305,7 @@ define([
}); });
}; };
var show = function () { var show = function () {
if (Bar.isEmbed) { $content.hide(); return; }
$content.show(); $content.show();
if (mobile) { if (mobile) {
$ck.hide(); $ck.hide();
@ -326,7 +328,7 @@ define([
$content.css('margin-top', h+'px'); $content.css('margin-top', h+'px');
}); });
$closeIcon.click(function () { $closeIcon.click(function () {
//Cryptpad.setAttribute('userlist-drawer', false); TODO iframe Common.setAttribute(['toolbar', 'userlist-drawer'], false);
hide(); hide();
}); });
$button.click(function () { $button.click(function () {
@ -334,16 +336,14 @@ define([
if (visible) { hide(); } if (visible) { hide(); }
else { show(); } else { show(); }
visible = !visible; visible = !visible;
// TODO iframe Common.setAttribute(['toolbar', 'userlist-drawer'], visible);
//Cryptpad.setAttribute('userlist-drawer', visible);
Common.feedback(visible?'USERLIST_SHOW': 'USERLIST_HIDE'); Common.feedback(visible?'USERLIST_SHOW': 'USERLIST_HIDE');
}); });
show(); show();
// TODO iframe Common.getAttribute(['toolbar', 'userlist-drawer'], function (err, val) {
/*Cryptpad.getAttribute('userlist-drawer', function (err, val) {
if (val === false || mobile) { return void hide(); } if (val === false || mobile) { return void hide(); }
show(); show();
});*/ });
return $container; return $container;
}; };
@ -401,6 +401,15 @@ define([
content: '<span class="fa fa-eye"></span> ' + Messages.viewOpen content: '<span class="fa fa-eye"></span> ' + Messages.viewOpen
}); });
} }
options.push({tag: 'hr'});
options.push({
tag: 'a',
attributes: {
title: Messages.viewEmbedTitle,
'class': 'cp-toolbar-share-view-embed',
},
content: '<span class="fa fa-eye"></span> ' + Messages.getEmbedCode
});
} }
var dropdownConfigShare = { var dropdownConfigShare = {
text: $('<div>').append($shareIcon).html(), text: $('<div>').append($shareIcon).html(),
@ -431,6 +440,31 @@ define([
var success = Cryptpad.Clipboard.copy(url); var success = Cryptpad.Clipboard.copy(url);
if (success) { Cryptpad.log(Messages.shareSuccess); } if (success) { Cryptpad.log(Messages.shareSuccess); }
}); });
$shareBlock.find('a.cp-toolbar-share-view-embed').click(function () {
var url = origin + pathname + '#' + hashes.viewHash;
var parsed = Cryptpad.parsePadUrl(url);
url = origin + parsed.getUrl({embed: true});
// Alertify content
var $content = $('<div>');
$('<input>', {'style':'display:none;'}).appendTo($content);
$('<h3>').text(Messages.viewEmbedTitle).appendTo($content);
var $tag = $('<p>').text(Messages.fileEmbedTag).appendTo($content);
$('<br>').appendTo($tag);
var iframeId = uid();
var iframeEmbed = '<iframe src="' + url + '"></iframe>';
$('<input>', {
type: 'text',
id: iframeId,
readonly: 'readonly',
value: iframeEmbed,
}).appendTo($tag);
Cryptpad.alert($content.html(), null, true);
$('#'+iframeId).click(function () {
this.select();
});
//var success = Cryptpad.Clipboard.copy(url);
//if (success) { Cryptpad.log(Messages.shareSuccess); }
});
} }
toolbar.$leftside.append($shareBlock); toolbar.$leftside.append($shareBlock);
@ -440,7 +474,7 @@ define([
}; };
var createFileShare = function (toolbar) { var createFileShare = function (toolbar) {
try { throw new Error('TODO: Update createFileShare to add "embed" and work in secure iframes'); } catch (e) { return; } if (true) { throw new Error('TODO: Update createFileShare to add "embed" and work in secure iframes'); }
if (!window.location.hash) { if (!window.location.hash) {
throw new Error("Unable to display the share button: hash required in the URL"); throw new Error("Unable to display the share button: hash required in the URL");
} }
@ -604,7 +638,7 @@ define([
window.open(href); window.open(href);
return; return;
} }
window.top.location = href; window.parent.location = href;
}; };
var onContext = function (e) { e.stopPropagation(); }; var onContext = function (e) { e.stopPropagation(); };
@ -733,8 +767,6 @@ define([
var $userAdmin = toolbar.$userAdmin.find('.'+USERADMIN_CLS).show(); var $userAdmin = toolbar.$userAdmin.find('.'+USERADMIN_CLS).show();
var userMenuCfg = { var userMenuCfg = {
$initBlock: $userAdmin, $initBlock: $userAdmin,
metadataMgr: metadataMgr,
Common: Common
}; };
if (!config.hideDisplayName) { if (!config.hideDisplayName) {
$.extend(true, userMenuCfg, { $.extend(true, userMenuCfg, {

@ -142,14 +142,14 @@ define([
if (type === 'name') { return data.filename; } if (type === 'name') { return data.filename; }
return data.filename || data.title || NEW_FILE_NAME; return data.filename || data.title || NEW_FILE_NAME;
}; };
exp.getAttribute = function (href, attr, cb) { exp.getPadAttribute = function (href, attr, cb) {
cb = cb || $.noop; cb = cb || $.noop;
var id = exp.getIdFromHref(href); var id = exp.getIdFromHref(href);
if (!id) { return void cb(null, undefined); } if (!id) { return void cb(null, undefined); }
var data = getFileData(id); var data = getFileData(id);
cb(null, clone(data[attr])); cb(null, clone(data[attr]));
}; };
exp.setAttribute = function (href, attr, value, cb) { exp.setPadAttribute = function (href, attr, value, cb) {
cb = cb || $.noop; cb = cb || $.noop;
var id = exp.getIdFromHref(href); var id = exp.getIdFromHref(href);
if (!id) { return void cb("E_INVAL_HREF"); } if (!id) { return void cb("E_INVAL_HREF"); }

@ -2774,7 +2774,7 @@ define([
myUserNameTemp = myUserNameTemp.substr(0, 32); myUserNameTemp = myUserNameTemp.substr(0, 32);
} }
var myUserName = myUserNameTemp; var myUserName = myUserNameTemp;
Cryptpad.setAttribute('username', myUserName, function (err) { Cryptpad.setDisplayName(myUserName, function (err) {
if (err) { if (err) {
logError("Couldn't set username", err); logError("Couldn't set username", err);
return; return;

@ -514,7 +514,7 @@ define([
readOnly = metadataMgr.getPrivateData().readOnly; readOnly = metadataMgr.getPrivateData().readOnly;
console.log('onInit'); console.log('onInit');
var titleCfg = { getHeadingText: getHeadingText }; var titleCfg = { getHeadingText: getHeadingText };
Title = common.createTitle(titleCfg, realtimeOptions.onLocal, common, metadataMgr); Title = common.createTitle(titleCfg, realtimeOptions.onLocal);
var configTb = { var configTb = {
displayed: ['userlist', 'title', 'useradmin', 'spinner', 'newpad', 'share', 'limit'], displayed: ['userlist', 'title', 'useradmin', 'spinner', 'newpad', 'share', 'limit'],
title: Title.getTitleConfig(), title: Title.getTitleConfig(),
@ -673,7 +673,7 @@ define([
if (newPad) { if (newPad) {
common.openTemplatePicker(common); common.openTemplatePicker();
} }
onLocal(); onLocal();

@ -21,7 +21,7 @@ define([
$(function () { $(function () {
var HIDE_INTRODUCTION_TEXT = "hide_poll_text"; var HIDE_INTRODUCTION_TEXT = "hide-text";
var defaultName; var defaultName;
var secret = Cryptpad.getSecrets(); var secret = Cryptpad.getSecrets();
@ -782,10 +782,10 @@ var create = function (info) {
.on('disconnect', disconnect) .on('disconnect', disconnect)
.on('reconnect', reconnect); .on('reconnect', reconnect);
Cryptpad.getAttribute(HIDE_INTRODUCTION_TEXT, function (e, value) { Cryptpad.getAttribute(['poll', HIDE_INTRODUCTION_TEXT], function (e, value) {
if (e) { console.error(e); } if (e) { console.error(e); }
if (!value) { if (!value) {
Cryptpad.setAttribute(HIDE_INTRODUCTION_TEXT, "1", function (e) { Cryptpad.setAttribute(['poll', HIDE_INTRODUCTION_TEXT], "1", function (e) {
if (e) { console.error(e); } if (e) { console.error(e); }
}); });
showHelp(true); showHelp(true);

@ -131,33 +131,6 @@ define([
}); });
}; };
/*
var addDisplayName = function ($container) {
var $block = $('<div>', {id: DISPLAYNAME_ID}).appendTo($container);
var getValue = function (cb) {
Cryptpad.getLastName(function (err, name) {
if (err) { return void console.error(err); }
cb(name);
});
};
if (APP.readOnly) {
var $span = $('<span>', {'class': DISPLAYNAME_ID}).appendTo($block);
getValue(function (value) {
$span.text(value);
});
return;
}
var setValue = function (value, cb) {
Cryptpad.setAttribute('username', value, function (err) {
cb(err);
});
};
var placeholder = Messages.anonymous;
var rt = Cryptpad.getStore().getProxy().info.realtime;
createEditableInput($block, DISPLAYNAME_ID, placeholder, 32, getValue, setValue, rt);
};
*/
/* jshint ignore:start */ /* jshint ignore:start */
var isFriend = function (proxy, edKey) { var isFriend = function (proxy, edKey) {
var friends = Cryptpad.find(proxy, ['friends']); var friends = Cryptpad.find(proxy, ['friends']);

@ -1,7 +1,8 @@
define([ define([
'jquery', 'jquery',
'/common/diffMarked.js', '/common/diffMarked.js',
],function ($, DiffMd) { '/common/cryptpad-common.js',
],function ($, DiffMd, Cryptpad) {
var Slide = { var Slide = {
index: 0, index: 0,
@ -116,13 +117,13 @@ define([
}; };
var isPresentURL = Slide.isPresentURL = function () { var isPresentURL = Slide.isPresentURL = function () {
var hash = window.location.hash; var parsed = Cryptpad.parsePadUrl(window.location.href);
// Present mode has /present at the end of the hash return parsed && parsed.hashData && parsed.hashData.present;
var urlLastFragment = hash.slice(hash.lastIndexOf('/')+1);
return urlLastFragment === "present";
}; };
var show = Slide.show = function (bool, content) { var show = Slide.show = function (bool, content) {
var parsed = Cryptpad.parsePadUrl(window.location.href);
var hashData = parsed.hashData || {};
Slide.shown = bool; Slide.shown = bool;
if (bool) { if (bool) {
Slide.update(content); Slide.update(content);
@ -131,10 +132,7 @@ define([
$(ifrw).focus(); $(ifrw).focus();
change(null, Slide.index); change(null, Slide.index);
if (!isPresentURL()) { if (!isPresentURL()) {
if (window.location.href.slice(-1) !== '/') { window.location += parsed.getUrl({present: true, embed: hashData.embed});
window.location.hash += '/';
}
window.location.hash += 'present';
} }
$pad.contents().find('.cryptpad-present-button').hide(); $pad.contents().find('.cryptpad-present-button').hide();
$pad.contents().find('.cryptpad-source-button').show(); $pad.contents().find('.cryptpad-source-button').show();
@ -144,7 +142,7 @@ define([
updateFontSize(); updateFontSize();
return; return;
} }
window.location.hash = window.location.hash.replace(/\/present$/, '/'); window.location = parsed.getUrl({embed: hashData.embed});
change(Slide.index, null); change(Slide.index, null);
$pad.contents().find('.cryptpad-present-button').show(); $pad.contents().find('.cryptpad-present-button').show();
$pad.contents().find('.cryptpad-source-button').hide(); $pad.contents().find('.cryptpad-source-button').hide();

Loading…
Cancel
Save