Move the toolbar buttons' events handlers in cryptpad-common
This commit is contained in:
parent
1c808b3da8
commit
e84a54556c
@ -154,6 +154,9 @@ tr {
|
|||||||
margin-bottom: 12px;
|
margin-bottom: 12px;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
.alertify button {
|
||||||
|
margin: 3px 0px;
|
||||||
|
}
|
||||||
/* Tables */
|
/* Tables */
|
||||||
table {
|
table {
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
|
|||||||
@ -187,6 +187,9 @@ p, pre, td, a, table, tr {
|
|||||||
margin-bottom: 2 * 6px;
|
margin-bottom: 2 * 6px;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
.alertify button {
|
||||||
|
margin: 3px 0px;
|
||||||
|
}
|
||||||
/* Tables */
|
/* Tables */
|
||||||
|
|
||||||
table {
|
table {
|
||||||
|
|||||||
@ -74,7 +74,10 @@ define(function () {
|
|||||||
|
|
||||||
out.getViewButton = 'LECTURE SEULE';
|
out.getViewButton = 'LECTURE SEULE';
|
||||||
out.getViewButtonTitle = "Obtenir l'adresse d'accès à ce document en lecture seule";
|
out.getViewButtonTitle = "Obtenir l'adresse d'accès à ce document en lecture seule";
|
||||||
out.readonlyUrl = 'URL de lecture seule';
|
out.readonlyUrl = 'Document en lecture seule';
|
||||||
|
out.copyReadOnly = "Copier l'URL dans le presse-papiers";
|
||||||
|
out.openReadOnly = "Ouvrir dans un nouvel onglet";
|
||||||
|
|
||||||
|
|
||||||
out.disconnectAlert = 'Perte de la connexion au réseau !';
|
out.disconnectAlert = 'Perte de la connexion au réseau !';
|
||||||
|
|
||||||
|
|||||||
@ -75,7 +75,9 @@ define(function () {
|
|||||||
|
|
||||||
out.getViewButton = 'READ-ONLY URL';
|
out.getViewButton = 'READ-ONLY URL';
|
||||||
out.getViewButtonTitle = 'Get the read-only URL for this document';
|
out.getViewButtonTitle = 'Get the read-only URL for this document';
|
||||||
out.readonlyUrl = 'Read only URL';
|
out.readonlyUrl = 'Read only document';
|
||||||
|
out.copyReadOnly = "Copy URL to clipboard";
|
||||||
|
out.openReadOnly = "Open in a new tab";
|
||||||
|
|
||||||
out.disconnectAlert = 'Network connection lost!';
|
out.disconnectAlert = 'Network connection lost!';
|
||||||
|
|
||||||
|
|||||||
132
www/code/main.js
132
www/code/main.js
@ -265,6 +265,32 @@ define([
|
|||||||
saveAs(blob, filename);
|
saveAs(blob, filename);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
var importText = function (content, file) {
|
||||||
|
var $bar = $('#pad-iframe')[0].contentWindow.$('#cme_toolbox');
|
||||||
|
var mode;
|
||||||
|
var mime = CodeMirror.findModeByMIME(file.type);
|
||||||
|
|
||||||
|
if (!mime) {
|
||||||
|
var ext = /.+\.([^.]+)$/.exec(file.name);
|
||||||
|
if (ext[1]) {
|
||||||
|
mode = CodeMirror.findModeByExtension(ext[1]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mode = mime && mime.mode || null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode && Modes.list.some(function (o) { return o.mode === mode; })) {
|
||||||
|
setMode(mode);
|
||||||
|
$bar.find('#language-mode').val(mode);
|
||||||
|
} else {
|
||||||
|
console.log("Couldn't find a suitable highlighting mode: %s", mode);
|
||||||
|
setMode('text');
|
||||||
|
$bar.find('#language-mode').val('text');
|
||||||
|
}
|
||||||
|
|
||||||
|
editor.setValue(content);
|
||||||
|
onLocal();
|
||||||
|
};
|
||||||
|
|
||||||
var onInit = config.onInit = function (info) {
|
var onInit = config.onInit = function (info) {
|
||||||
var $bar = $('#pad-iframe')[0].contentWindow.$('#cme_toolbox');
|
var $bar = $('#pad-iframe')[0].contentWindow.$('#cme_toolbox');
|
||||||
@ -285,113 +311,45 @@ define([
|
|||||||
editHash = Cryptpad.getEditHashFromKeys(info.channel, secret.keys);
|
editHash = Cryptpad.getEditHashFromKeys(info.channel, secret.keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* add a "change username" button */
|
||||||
getLastName(function (err, lastName) {
|
getLastName(function (err, lastName) {
|
||||||
var $username = Cryptpad.createButton('username', true)
|
var usernameCb = function (newName) {
|
||||||
.click(function() {
|
setName (newName);
|
||||||
Cryptpad.prompt(Messages.changeNamePrompt, lastName, function (newName) {
|
};
|
||||||
setName(newName);
|
var $username = Cryptpad.createButton('username', true, {lastName: lastName}, usernameCb);
|
||||||
});
|
|
||||||
});
|
|
||||||
$rightside.append($username);
|
$rightside.append($username);
|
||||||
});
|
});
|
||||||
|
|
||||||
/* add an export button */
|
/* add an export button */
|
||||||
var $export = Cryptpad.createButton('export', true).click(exportText);
|
var $export = Cryptpad.createButton('export', true, {}, exportText);
|
||||||
$rightside.append($export);
|
$rightside.append($export);
|
||||||
|
|
||||||
if (!readOnly) {
|
if (!readOnly) {
|
||||||
/* add an import button */
|
/* add an import button */
|
||||||
var $import = Cryptpad.createButton('import', true)
|
var $import = Cryptpad.createButton('import', true, {}, importText);
|
||||||
.click(Cryptpad.importContent('text/plain', function (content, file) {
|
|
||||||
var mode;
|
|
||||||
var mime = CodeMirror.findModeByMIME(file.type);
|
|
||||||
|
|
||||||
if (!mime) {
|
|
||||||
var ext = /.+\.([^.]+)$/.exec(file.name);
|
|
||||||
if (ext[1]) {
|
|
||||||
mode = CodeMirror.findModeByExtension(ext[1]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mode = mime && mime.mode || null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode && Modes.list.some(function (o) { return o.mode === mode; })) {
|
|
||||||
setMode(mode);
|
|
||||||
$bar.find('#language-mode').val(mode);
|
|
||||||
} else {
|
|
||||||
console.log("Couldn't find a suitable highlighting mode: %s", mode);
|
|
||||||
setMode('text');
|
|
||||||
$bar.find('#language-mode').val('text');
|
|
||||||
}
|
|
||||||
|
|
||||||
editor.setValue(content);
|
|
||||||
onLocal();
|
|
||||||
}));
|
|
||||||
$rightside.append($import);
|
$rightside.append($import);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add a rename button */
|
/* add a rename button */
|
||||||
var $setTitle = Cryptpad.createButton('rename', true)
|
var renameCb = function (err, title) {
|
||||||
.click(function () {
|
if (err) { return; }
|
||||||
var suggestion = suggestName();
|
document.title = title;
|
||||||
|
onLocal();
|
||||||
Cryptpad.prompt(Messages.renamePrompt,
|
};
|
||||||
suggestion, function (title, ev) {
|
var $setTitle = Cryptpad.createButton('rename', true, {suggestName: suggestName}, renameCb);
|
||||||
if (title === null) { return; }
|
|
||||||
|
|
||||||
Cryptpad.causesNamingConflict(title, function (err, conflicts) {
|
|
||||||
if (err) {
|
|
||||||
console.log("Unable to determine if name caused a conflict");
|
|
||||||
console.error(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (conflicts) {
|
|
||||||
Cryptpad.alert(Messages.renameConflict);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Cryptpad.setPadTitle(title, function (err, data) {
|
|
||||||
if (err) {
|
|
||||||
console.log("unable to set pad title");
|
|
||||||
console.log(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
document.title = title;
|
|
||||||
onLocal();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
$rightside.append($setTitle);
|
$rightside.append($setTitle);
|
||||||
|
|
||||||
/* add a forget button */
|
/* add a forget button */
|
||||||
var $forgetPad = Cryptpad.createButton('forget', true)
|
var forgetCb = function (err, title) {
|
||||||
.click(function () {
|
if (err) { return; }
|
||||||
var href = window.location.href;
|
document.title = title;
|
||||||
Cryptpad.confirm(Messages.forgetPrompt, function (yes) {
|
};
|
||||||
if (!yes) { return; }
|
var $forgetPad = Cryptpad.createButton('forget', true, {}, forgetCb);
|
||||||
Cryptpad.forgetPad(href, function (err, data) {
|
|
||||||
if (err) {
|
|
||||||
console.log("unable to forget pad");
|
|
||||||
console.error(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var parsed = Cryptpad.parsePadUrl(href);
|
|
||||||
document.title = Cryptpad.getDefaultName(parsed, []);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
$rightside.append($forgetPad);
|
$rightside.append($forgetPad);
|
||||||
|
|
||||||
if (!readOnly && viewHash) {
|
if (!readOnly && viewHash) {
|
||||||
/* add a 'links' button */
|
/* add a 'links' button */
|
||||||
var $links = Cryptpad.createButton('readonly', true)
|
var $links = Cryptpad.createButton('readonly', true, {viewHash: viewHash});
|
||||||
.click(function () {
|
|
||||||
var baseUrl = window.location.origin + window.location.pathname + '#';
|
|
||||||
var content = '<b>' + Messages.readonlyUrl + '</b><br><a>' + baseUrl + viewHash + '</a><br>';
|
|
||||||
Cryptpad.alert(content);
|
|
||||||
});
|
|
||||||
$rightside.append($links);
|
$rightside.append($links);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,11 +4,12 @@ define([
|
|||||||
'/bower_components/chainpad-crypto/crypto.js',
|
'/bower_components/chainpad-crypto/crypto.js',
|
||||||
'/bower_components/alertifyjs/dist/js/alertify.js',
|
'/bower_components/alertifyjs/dist/js/alertify.js',
|
||||||
'/bower_components/spin.js/spin.min.js',
|
'/bower_components/spin.js/spin.min.js',
|
||||||
|
'/common/clipboard.js',
|
||||||
|
|
||||||
'/customize/user.js',
|
'/customize/user.js',
|
||||||
|
|
||||||
'/bower_components/jquery/dist/jquery.min.js',
|
'/bower_components/jquery/dist/jquery.min.js',
|
||||||
], function (Messages, Store, Crypto, Alertify, Spinner, User) {
|
], function (Messages, Store, Crypto, Alertify, Spinner, Clipboard, User) {
|
||||||
/* This file exposes functionality which is specific to Cryptpad, but not to
|
/* This file exposes functionality which is specific to Cryptpad, but not to
|
||||||
any particular pad type. This includes functions for committing metadata
|
any particular pad type. This includes functions for committing metadata
|
||||||
about pads to your local storage for future use and improved usability.
|
about pads to your local storage for future use and improved usability.
|
||||||
@ -610,7 +611,7 @@ define([
|
|||||||
/*
|
/*
|
||||||
* Buttons
|
* Buttons
|
||||||
*/
|
*/
|
||||||
var createButton = common.createButton = function (type, rightside) {
|
var createButton = common.createButton = function (type, rightside, data, callback) {
|
||||||
var button;
|
var button;
|
||||||
var size = "17px";
|
var size = "17px";
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@ -620,6 +621,9 @@ define([
|
|||||||
'class': "fa fa-download",
|
'class': "fa fa-download",
|
||||||
style: 'font:'+size+' FontAwesome'
|
style: 'font:'+size+' FontAwesome'
|
||||||
});
|
});
|
||||||
|
if (callback) {
|
||||||
|
button.click(callback);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'import':
|
case 'import':
|
||||||
button = $('<button>', {
|
button = $('<button>', {
|
||||||
@ -627,6 +631,11 @@ define([
|
|||||||
'class': "fa fa-upload",
|
'class': "fa fa-upload",
|
||||||
style: 'font:'+size+' FontAwesome'
|
style: 'font:'+size+' FontAwesome'
|
||||||
});
|
});
|
||||||
|
if (callback) {
|
||||||
|
button.click(common.importContent('text/plain', function (content, file) {
|
||||||
|
callback(content, file);
|
||||||
|
}));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'rename':
|
case 'rename':
|
||||||
button = $('<button>', {
|
button = $('<button>', {
|
||||||
@ -635,6 +644,40 @@ define([
|
|||||||
'class': "fa fa-bookmark cryptpad-rename",
|
'class': "fa fa-bookmark cryptpad-rename",
|
||||||
style: 'font:'+size+' FontAwesome'
|
style: 'font:'+size+' FontAwesome'
|
||||||
});
|
});
|
||||||
|
if (data && data.suggestName && callback) {
|
||||||
|
var suggestName = data.suggestName;
|
||||||
|
button.click(function() {
|
||||||
|
var suggestion = suggestName();
|
||||||
|
|
||||||
|
common.prompt(Messages.renamePrompt,
|
||||||
|
suggestion, function (title, ev) {
|
||||||
|
if (title === null) { return; }
|
||||||
|
|
||||||
|
common.causesNamingConflict(title, function (err, conflicts) {
|
||||||
|
if (err) {
|
||||||
|
console.log("Unable to determine if name caused a conflict");
|
||||||
|
console.error(err);
|
||||||
|
callback(err, title);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (conflicts) {
|
||||||
|
common.alert(Messages.renameConflict);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
common.setPadTitle(title, function (err, data) {
|
||||||
|
if (err) {
|
||||||
|
console.log("unable to set pad title");
|
||||||
|
console.log(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
callback(null, title);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'forget':
|
case 'forget':
|
||||||
button = $('<button>', {
|
button = $('<button>', {
|
||||||
@ -643,6 +686,25 @@ define([
|
|||||||
'class': "fa fa-trash cryptpad-forget",
|
'class': "fa fa-trash cryptpad-forget",
|
||||||
style: 'font:'+size+' FontAwesome'
|
style: 'font:'+size+' FontAwesome'
|
||||||
});
|
});
|
||||||
|
if (callback) {
|
||||||
|
button.click(function() {
|
||||||
|
var href = window.location.href;
|
||||||
|
common.confirm(Messages.forgetPrompt, function (yes) {
|
||||||
|
if (!yes) { return; }
|
||||||
|
common.forgetPad(href, function (err, data) {
|
||||||
|
if (err) {
|
||||||
|
console.log("unable to forget pad");
|
||||||
|
console.error(err);
|
||||||
|
callback(err, null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var parsed = common.parsePadUrl(href);
|
||||||
|
callback(null, common.getDefaultName(parsed, []));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'username':
|
case 'username':
|
||||||
button = $('<button>', {
|
button = $('<button>', {
|
||||||
@ -650,6 +712,14 @@ define([
|
|||||||
'class': "fa fa-user",
|
'class': "fa fa-user",
|
||||||
style: 'font:'+size+' FontAwesome'
|
style: 'font:'+size+' FontAwesome'
|
||||||
});
|
});
|
||||||
|
if (data && data.lastName && callback) {
|
||||||
|
var lastName = data.lastName;
|
||||||
|
button.click(function() {
|
||||||
|
common.prompt(Messages.changeNamePrompt, lastName, function (newName) {
|
||||||
|
callback(newName);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'readonly':
|
case 'readonly':
|
||||||
button = $('<button>', {
|
button = $('<button>', {
|
||||||
@ -657,6 +727,37 @@ define([
|
|||||||
'class': "fa fa-eye",
|
'class': "fa fa-eye",
|
||||||
style: 'font:'+size+' FontAwesome'
|
style: 'font:'+size+' FontAwesome'
|
||||||
});
|
});
|
||||||
|
if (data && data.viewHash) {
|
||||||
|
var viewHash = data.viewHash;
|
||||||
|
button.click(function() {
|
||||||
|
var baseUrl = window.location.origin + window.location.pathname + '#';
|
||||||
|
var url = baseUrl + viewHash;
|
||||||
|
var $content = $('<div>').text(Messages.readonlyUrl);
|
||||||
|
var $copy = $('<button>', {
|
||||||
|
id: "cryptpad-readonly-copy",
|
||||||
|
'class': "button action"
|
||||||
|
}).text(Messages.copyReadOnly);
|
||||||
|
var $open = $('<button>', {
|
||||||
|
id: "cryptpad-readonly-open",
|
||||||
|
'class': "button action"
|
||||||
|
}).text(Messages.openReadOnly);
|
||||||
|
$content.append('<br>').append($copy).append($open);
|
||||||
|
common.alert($content.html());
|
||||||
|
$("#cryptpad-readonly-copy").click(function() {
|
||||||
|
var success = Clipboard.copy(url);
|
||||||
|
if (success) {
|
||||||
|
common.log(Messages.shareSuccess);
|
||||||
|
common.findOKButton().click();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$("#cryptpad-readonly-open").click(function() {
|
||||||
|
window.open(url);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (callback) { callback(); }
|
||||||
|
});
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'present':
|
case 'present':
|
||||||
button = $('<button>', {
|
button = $('<button>', {
|
||||||
|
|||||||
@ -493,6 +493,11 @@ define([
|
|||||||
saveAs(blob, filename);
|
saveAs(blob, filename);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
var importFile = function (content, file) {
|
||||||
|
var shjson = stringify(Hyperjson.fromDOM(domFromHTML(content).body));
|
||||||
|
applyHjson(shjson);
|
||||||
|
realtimeOptions.onLocal();
|
||||||
|
};
|
||||||
|
|
||||||
var onInit = realtimeOptions.onInit = function (info) {
|
var onInit = realtimeOptions.onInit = function (info) {
|
||||||
var $bar = $('#pad-iframe')[0].contentWindow.$('#cke_1_toolbox');
|
var $bar = $('#pad-iframe')[0].contentWindow.$('#cke_1_toolbox');
|
||||||
@ -513,80 +518,45 @@ define([
|
|||||||
editHash = Cryptpad.getEditHashFromKeys(info.channel, secret.keys);
|
editHash = Cryptpad.getEditHashFromKeys(info.channel, secret.keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* add a "change username" button */
|
||||||
getLastName(function (err, lastName) {
|
getLastName(function (err, lastName) {
|
||||||
var $username = Cryptpad.createButton('username', true)
|
var usernameCb = function (newName) {
|
||||||
.click(function() {
|
setName (newName);
|
||||||
Cryptpad.prompt(Messages.changeNamePrompt, lastName, function (newName) {
|
};
|
||||||
setName(newName);
|
var $username = Cryptpad.createButton('username', true, {lastName: lastName}, usernameCb);
|
||||||
});
|
|
||||||
});
|
|
||||||
$rightside.append($username);
|
$rightside.append($username);
|
||||||
});
|
});
|
||||||
|
|
||||||
/* add an export button */
|
/* add an export button */
|
||||||
var $export = Cryptpad.createButton('export', true).click(exportFile);
|
var $export = Cryptpad.createButton('export', true, {}, exportFile);
|
||||||
$rightside.append($export);
|
$rightside.append($export);
|
||||||
|
|
||||||
if (!readOnly) {
|
if (!readOnly) {
|
||||||
/* add an import button */
|
/* add an import button */
|
||||||
var $import = Cryptpad.createButton('import', true)
|
var $import = Cryptpad.createButton('import', true, {}, importFile);
|
||||||
.click(Cryptpad.importContent('text/plain', function (content) {
|
|
||||||
var shjson = stringify(Hyperjson.fromDOM(domFromHTML(content).body));
|
|
||||||
applyHjson(shjson);
|
|
||||||
realtimeOptions.onLocal();
|
|
||||||
}));
|
|
||||||
$rightside.append($import);
|
$rightside.append($import);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add a rename button */
|
/* add a rename button */
|
||||||
var $rename = Cryptpad.createButton('rename', true)
|
var renameCb = function (err, title) {
|
||||||
.click(function () {
|
if (err) { return; }
|
||||||
var suggestion = suggestName();
|
document.title = title;
|
||||||
|
editor.fire('change');
|
||||||
Cryptpad.prompt(Messages.renamePrompt, suggestion, function (title) {
|
};
|
||||||
if (title === null) { return; }
|
var $setTitle = Cryptpad.createButton('rename', true, {suggestName: suggestName}, renameCb);
|
||||||
Cryptpad.causesNamingConflict(title, function (err, conflicts) {
|
$rightside.append($setTitle);
|
||||||
if (conflicts) {
|
|
||||||
Cryptpad.alert(Messages.renameConflict);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Cryptpad.setPadTitle(title, function (err, data) {
|
|
||||||
if (err) {
|
|
||||||
console.log("Couldn't set pad title");
|
|
||||||
console.error(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
document.title = title;
|
|
||||||
editor.fire('change');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
$rightside.append($rename);
|
|
||||||
|
|
||||||
/* add a forget button */
|
/* add a forget button */
|
||||||
var $forgetPad = Cryptpad.createButton('forget', true)
|
var forgetCb = function (err, title) {
|
||||||
.click(function () {
|
if (err) { return; }
|
||||||
var href = window.location.href;
|
document.title = title;
|
||||||
Cryptpad.confirm(Messages.forgetPrompt, function (yes) {
|
};
|
||||||
if (!yes) { return; }
|
var $forgetPad = Cryptpad.createButton('forget', true, {}, forgetCb);
|
||||||
Cryptpad.forgetPad(href, function (err, data) {
|
|
||||||
var parsed = Cryptpad.parsePadUrl(href);
|
|
||||||
document.title = Cryptpad.getDefaultName(parsed, []);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
$rightside.append($forgetPad);
|
$rightside.append($forgetPad);
|
||||||
|
|
||||||
if (!readOnly && viewHash) {
|
if (!readOnly && viewHash) {
|
||||||
/* add a 'links' button */
|
/* add a 'links' button */
|
||||||
var $links = Cryptpad.createButton('readonly', true)
|
var $links = Cryptpad.createButton('readonly', true, {viewHash: viewHash});
|
||||||
.click(function () {
|
|
||||||
var baseUrl = window.location.origin + window.location.pathname + '#';
|
|
||||||
var content = '<b>' + Messages.readonlyUrl + '</b><br><a>' + baseUrl + viewHash + '</a><br>';
|
|
||||||
Cryptpad.alert(content);
|
|
||||||
});
|
|
||||||
$rightside.append($links);
|
$rightside.append($links);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
128
www/poll/main.js
128
www/poll/main.js
@ -456,6 +456,21 @@ define([
|
|||||||
module.tabNotification = Notify.tab(1000, 10);
|
module.tabNotification = Notify.tab(1000, 10);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var updateTitle = function (newTitle) {
|
||||||
|
if (newTitle === document.title) { return; }
|
||||||
|
// Change the title now, and set it back to the old value if there is an error
|
||||||
|
var oldTitle = document.title;
|
||||||
|
document.title = newTitle;
|
||||||
|
Cryptpad.setPadTitle(newTitle, function (err, data) {
|
||||||
|
if (err) {
|
||||||
|
console.log("Couldn't set pad title");
|
||||||
|
console.error(err);
|
||||||
|
document.title = oldTitle;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// don't make changes until the interface is ready
|
// don't make changes until the interface is ready
|
||||||
setEditable(false);
|
setEditable(false);
|
||||||
|
|
||||||
@ -464,9 +479,12 @@ define([
|
|||||||
module.ready = true;
|
module.ready = true;
|
||||||
|
|
||||||
var proxy = module.rt.proxy;
|
var proxy = module.rt.proxy;
|
||||||
|
|
||||||
var First = false;
|
var First = false;
|
||||||
|
|
||||||
|
if (proxy.metadata && proxy.metadata.title) {
|
||||||
|
updateTitle(proxy.metadata.title);
|
||||||
|
}
|
||||||
|
|
||||||
// ensure that proxy.info and proxy.table exist
|
// ensure that proxy.info and proxy.table exist
|
||||||
['info', 'table'].forEach(function (k) {
|
['info', 'table'].forEach(function (k) {
|
||||||
if (typeof(proxy[k]) === 'undefined') {
|
if (typeof(proxy[k]) === 'undefined') {
|
||||||
@ -627,19 +645,8 @@ define([
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.on('change', ['metadata'], function (o, n, p) {
|
.on('change', ['metadata'], function (o, n, p) {
|
||||||
var newTitle = n.title;
|
var newTitle = proxy.metadata.title;
|
||||||
if (newTitle === document.title) { return; }
|
updateTitle(newTitle);
|
||||||
// Change the title now, and set it back to the old value if there is an error
|
|
||||||
var oldTitle = document.title;
|
|
||||||
document.title = newTitle;
|
|
||||||
Cryptpad.setPadTitle(newTitle, function (err, data) {
|
|
||||||
if (err) {
|
|
||||||
console.log("Couldn't set pad title");
|
|
||||||
console.error(err);
|
|
||||||
document.title = oldTitle;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.on('remove', [], function (o, p, root) {
|
.on('remove', [], function (o, p, root) {
|
||||||
//console.log("remove: (%s, [%s])", o, p.join(', '));
|
//console.log("remove: (%s, [%s])", o, p.join(', '));
|
||||||
@ -704,60 +711,35 @@ define([
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$toolbar.append(Button({
|
/* add a forget button */
|
||||||
id: 'forget',
|
var forgetCb = function (err, title) {
|
||||||
'class': 'forget button action',
|
if (err) { return; }
|
||||||
title: Messages.forgetButtonTitle,
|
document.title = title;
|
||||||
}).text(Messages.forgetButton).click(function () {
|
};
|
||||||
var href = window.location.href;
|
var $forgetPad = Cryptpad.createButton('forget', false, {}, forgetCb)
|
||||||
Cryptpad.confirm(Messages.forgetPrompt, function (yes) {
|
.text(Messages.forgetButton)
|
||||||
if (!yes) { return; }
|
.removeAttr('style')
|
||||||
Cryptpad.forgetPad(href, function (err, data) {
|
.attr('class', 'action button forget');
|
||||||
if (err) {
|
$toolbar.append($forgetPad);
|
||||||
console.log("unable to forget pad");
|
|
||||||
console.error(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var parsed = Cryptpad.parsePadUrl(href);
|
|
||||||
document.title = Cryptpad.getDefaultName(parsed, []);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
$toolbar.append(Button({
|
/* add a rename button */
|
||||||
id: 'rename',
|
var renameCb = function (err, title) {
|
||||||
'class': 'rename button action',
|
if (err) { return; }
|
||||||
title: Messages.renameButtonTitle,
|
document.title = title;
|
||||||
}).text(Messages.renameButton).click(function () {
|
module.tabNotification && module.tabNotification.update(title);
|
||||||
var suggestion = suggestName();
|
var proxy = module.rt.proxy;
|
||||||
Cryptpad.prompt(Messages.renamePrompt,
|
if (proxy.metadata) {
|
||||||
suggestion, function (title, ev) {
|
proxy.metadata.title = title;
|
||||||
if (title === null) { return; }
|
}
|
||||||
|
else {
|
||||||
Cryptpad.causesNamingConflict(title, function (err, conflicts) {
|
proxy.metadata = {title: title};
|
||||||
if (conflicts) {
|
}
|
||||||
Cryptpad.alert(Messages.renameConflict);
|
};
|
||||||
return;
|
var $setTitle = Cryptpad.createButton('rename', true, {suggestName: suggestName}, renameCb)
|
||||||
}
|
.text(Messages.renameButton)
|
||||||
Cryptpad.setPadTitle(title, function (err, data) {
|
.removeAttr('style')
|
||||||
if (err) {
|
.attr('class', 'action button rename');
|
||||||
console.log("unable to set pad title");
|
$toolbar.append($setTitle);
|
||||||
console.error(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
document.title = title;
|
|
||||||
module.tabNotification.update(title);
|
|
||||||
var proxy = module.rt.proxy;
|
|
||||||
if (proxy.metadata) {
|
|
||||||
proxy.metadata.title = title;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
proxy.metadata = {title: title};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
if (!readOnly) {
|
if (!readOnly) {
|
||||||
$toolbar.append(Button({
|
$toolbar.append(Button({
|
||||||
@ -774,16 +756,10 @@ define([
|
|||||||
|
|
||||||
if (!readOnly && module.viewHash) {
|
if (!readOnly && module.viewHash) {
|
||||||
/* add a 'links' button */
|
/* add a 'links' button */
|
||||||
var $links = $('<button>', {
|
var $links = Cryptpad.createButton('readonly', true, {viewHash: module.viewHash})
|
||||||
title: Messages.getViewButtonTitle
|
|
||||||
})
|
|
||||||
.text(Messages.getViewButton)
|
.text(Messages.getViewButton)
|
||||||
.addClass('button action')
|
.removeAttr('style')
|
||||||
.click(function () {
|
.attr('class', 'action button readonly');
|
||||||
var baseUrl = window.location.origin + window.location.pathname + '#';
|
|
||||||
var content = '<b>' + Messages.readonlyUrl + '</b><br><a>' + baseUrl + module.viewHash + '</a><br>';
|
|
||||||
Cryptpad.alert(content);
|
|
||||||
});
|
|
||||||
$toolbar.append($links);
|
$toolbar.append($links);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -14,11 +14,10 @@ define([
|
|||||||
'/common/visible.js',
|
'/common/visible.js',
|
||||||
'/common/notify.js',
|
'/common/notify.js',
|
||||||
'/slide/slide.js',
|
'/slide/slide.js',
|
||||||
'/common/clipboard.js',
|
|
||||||
'/bower_components/file-saver/FileSaver.min.js',
|
'/bower_components/file-saver/FileSaver.min.js',
|
||||||
'/bower_components/jquery/dist/jquery.min.js',
|
'/bower_components/jquery/dist/jquery.min.js',
|
||||||
'/customize/pad.js'
|
'/customize/pad.js'
|
||||||
], function (Config, /*RTCode,*/ Messages, Crypto, Realtime, TextPatcher, Toolbar, JSONSortify, JsonOT, Cryptpad, Modes, Themes, Visible, Notify, Slide, Clipboard) {
|
], function (Config, /*RTCode,*/ Messages, Crypto, Realtime, TextPatcher, Toolbar, JSONSortify, JsonOT, Cryptpad, Modes, Themes, Visible, Notify, Slide) {
|
||||||
var $ = window.jQuery;
|
var $ = window.jQuery;
|
||||||
var saveAs = window.saveAs;
|
var saveAs = window.saveAs;
|
||||||
|
|
||||||
@ -280,6 +279,32 @@ define([
|
|||||||
saveAs(blob, filename);
|
saveAs(blob, filename);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
var importText = function (content, file) {
|
||||||
|
var $bar = $('#pad-iframe')[0].contentWindow.$('#cme_toolbox');
|
||||||
|
var mode;
|
||||||
|
var mime = CodeMirror.findModeByMIME(file.type);
|
||||||
|
|
||||||
|
if (!mime) {
|
||||||
|
var ext = /.+\.([^.]+)$/.exec(file.name);
|
||||||
|
if (ext[1]) {
|
||||||
|
mode = CodeMirror.findModeByExtension(ext[1]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mode = mime && mime.mode || null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode && Modes.list.some(function (o) { return o.mode === mode; })) {
|
||||||
|
setMode(mode);
|
||||||
|
$bar.find('#language-mode').val(mode);
|
||||||
|
} else {
|
||||||
|
console.log("Couldn't find a suitable highlighting mode: %s", mode);
|
||||||
|
setMode('text');
|
||||||
|
$bar.find('#language-mode').val('text');
|
||||||
|
}
|
||||||
|
|
||||||
|
editor.setValue(content);
|
||||||
|
onLocal();
|
||||||
|
};
|
||||||
|
|
||||||
var onInit = config.onInit = function (info) {
|
var onInit = config.onInit = function (info) {
|
||||||
var $bar = $('#pad-iframe')[0].contentWindow.$('#cme_toolbox');
|
var $bar = $('#pad-iframe')[0].contentWindow.$('#cme_toolbox');
|
||||||
@ -300,116 +325,47 @@ define([
|
|||||||
editHash = Cryptpad.getEditHashFromKeys(info.channel, secret.keys);
|
editHash = Cryptpad.getEditHashFromKeys(info.channel, secret.keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* add a "change username" button */
|
||||||
getLastName(function (err, lastName) {
|
getLastName(function (err, lastName) {
|
||||||
var $username = Cryptpad.createButton('username', true)
|
var usernameCb = function (newName) {
|
||||||
.click(function() {
|
setName (newName);
|
||||||
Cryptpad.prompt(Messages.changeNamePrompt, lastName, function (newName) {
|
};
|
||||||
setName(newName);
|
var $username = Cryptpad.createButton('username', true, {lastName: lastName}, usernameCb);
|
||||||
});
|
|
||||||
});
|
|
||||||
$rightside.append($username);
|
$rightside.append($username);
|
||||||
});
|
});
|
||||||
|
|
||||||
/* add an export button */
|
/* add an export button */
|
||||||
var $export = Cryptpad.createButton('export', true).click(exportText);
|
var $export = Cryptpad.createButton('export', true, {}, exportText);
|
||||||
$rightside.append($export);
|
$rightside.append($export);
|
||||||
|
|
||||||
if (!readOnly) {
|
if (!readOnly) {
|
||||||
/* add an import button */
|
/* add an import button */
|
||||||
var $import = Cryptpad.createButton('import', true)
|
var $import = Cryptpad.createButton('import', true, {}, importText);
|
||||||
.click(Cryptpad.importContent('text/plain', function (content, file) {
|
|
||||||
var mode;
|
|
||||||
var mime = CodeMirror.findModeByMIME(file.type);
|
|
||||||
|
|
||||||
if (!mime) {
|
|
||||||
var ext = /.+\.([^.]+)$/.exec(file.name);
|
|
||||||
if (ext[1]) {
|
|
||||||
mode = CodeMirror.findModeByExtension(ext[1]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mode = mime && mime.mode || null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode && Modes.list.some(function (o) { return o.mode === mode; })) {
|
|
||||||
setMode(mode);
|
|
||||||
$bar.find('#language-mode').val(mode);
|
|
||||||
} else {
|
|
||||||
console.log("Couldn't find a suitable highlighting mode: %s", mode);
|
|
||||||
setMode('text');
|
|
||||||
$bar.find('#language-mode').val('text');
|
|
||||||
}
|
|
||||||
|
|
||||||
editor.setValue(content);
|
|
||||||
onLocal();
|
|
||||||
}));
|
|
||||||
$rightside.append($import);
|
$rightside.append($import);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add a rename button */
|
/* add a rename button */
|
||||||
var $setTitle = Cryptpad.createButton('rename', true)
|
var renameCb = function (err, title) {
|
||||||
.click(function () {
|
if (err) { return; }
|
||||||
var suggestion = suggestName();
|
APP.title = title;
|
||||||
|
setTabTitle();
|
||||||
Cryptpad.prompt(Messages.renamePrompt,
|
onLocal();
|
||||||
suggestion, function (title, ev) {
|
};
|
||||||
if (title === null) { return; }
|
var $setTitle = Cryptpad.createButton('rename', true, {suggestName: suggestName}, renameCb);
|
||||||
|
|
||||||
Cryptpad.causesNamingConflict(title, function (err, conflicts) {
|
|
||||||
if (err) {
|
|
||||||
console.log("Unable to determine if name caused a conflict");
|
|
||||||
console.error(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (conflicts) {
|
|
||||||
Cryptpad.alert(Messages.renameConflict);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Cryptpad.setPadTitle(title, function (err, data) {
|
|
||||||
if (err) {
|
|
||||||
console.log("unable to set pad title");
|
|
||||||
console.log(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
APP.title = title;
|
|
||||||
setTabTitle();
|
|
||||||
onLocal();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
$rightside.append($setTitle);
|
$rightside.append($setTitle);
|
||||||
|
|
||||||
/* add a forget button */
|
/* add a forget button */
|
||||||
var $forgetPad = Cryptpad.createButton('forget', true)
|
var forgetCb = function (err, title) {
|
||||||
.click(function () {
|
if (err) { return; }
|
||||||
var href = window.location.href;
|
APP.title = title;
|
||||||
Cryptpad.confirm(Messages.forgetPrompt, function (yes) {
|
setTabTitle();
|
||||||
if (!yes) { return; }
|
};
|
||||||
Cryptpad.forgetPad(href, function (err, data) {
|
var $forgetPad = Cryptpad.createButton('forget', true, {}, forgetCb);
|
||||||
if (err) {
|
|
||||||
console.log("unable to forget pad");
|
|
||||||
console.error(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var parsed = Cryptpad.parsePadUrl(href);
|
|
||||||
APP.title = Cryptpad.getDefaultName(parsed, []);
|
|
||||||
setTabTitle();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
$rightside.append($forgetPad);
|
$rightside.append($forgetPad);
|
||||||
|
|
||||||
if (!readOnly && viewHash) {
|
if (!readOnly && viewHash) {
|
||||||
/* add a 'links' button */
|
/* add a 'links' button */
|
||||||
var $links = Cryptpad.createButton('readonly', true)
|
var $links = Cryptpad.createButton('readonly', true, {viewHash: viewHash + '/present'});
|
||||||
.click(function () {
|
|
||||||
var baseUrl = window.location.origin + window.location.pathname + '#';
|
|
||||||
var url = baseUrl + viewHash + '/present';
|
|
||||||
var content = '<b>' + Messages.readonlyUrl + '</b><br><a href="' + url + '" target="_blank" rel="noopener noreferrer">' + url + '</a><br>';
|
|
||||||
Cryptpad.alert(content);
|
|
||||||
});
|
|
||||||
$rightside.append($links);
|
$rightside.append($links);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user