Remove the IMPORT button and editor toolbars in read-only mode

pull/1/head
yflory 8 years ago
parent 7cc5218422
commit 47e8be1681

@ -305,38 +305,40 @@ define([
.click(exportText); .click(exportText);
$rightside.append($export); $rightside.append($export);
/* add an import button */ if (!readOnly) {
var $import = $('<button>',{ /* add an import button */
title: Messages.importButtonTitle var $import = $('<button>',{
}) title: Messages.importButtonTitle
.text(Messages.importButton) })
.addClass('rightside-button') .text(Messages.importButton)
.click(Cryptpad.importContent('text/plain', function (content, file) { .addClass('rightside-button')
var mode; .click(Cryptpad.importContent('text/plain', function (content, file) {
var mime = CodeMirror.findModeByMIME(file.type); var mode;
var mime = CodeMirror.findModeByMIME(file.type);
if (!mime) {
var ext = /.+\.([^.]+)$/.exec(file.name); if (!mime) {
if (ext[1]) { var ext = /.+\.([^.]+)$/.exec(file.name);
mode = CodeMirror.findModeByExtension(ext[1]); if (ext[1]) {
mode = CodeMirror.findModeByExtension(ext[1]);
}
} else {
mode = mime && mime.mode || null;
} }
} else {
mode = mime && mime.mode || null;
}
if (mode && Modes.list.some(function (o) { return o.mode === mode; })) { if (mode && Modes.list.some(function (o) { return o.mode === mode; })) {
setMode(mode); setMode(mode);
$bar.find('#language-mode').val(mode); $bar.find('#language-mode').val(mode);
} else { } else {
console.log("Couldn't find a suitable highlighting mode: %s", mode); console.log("Couldn't find a suitable highlighting mode: %s", mode);
setMode('text'); setMode('text');
$bar.find('#language-mode').val('text'); $bar.find('#language-mode').val('text');
} }
editor.setValue(content); editor.setValue(content);
onLocal(); onLocal();
})); }));
$rightside.append($import); $rightside.append($import);
}
/* add a rename button */ /* add a rename button */
var $setTitle = $('<button>', { var $setTitle = $('<button>', {
@ -410,7 +412,7 @@ define([
.addClass('rightside-button') .addClass('rightside-button')
.click(function () { .click(function () {
var baseUrl = window.location.origin + window.location.pathname + '#'; var baseUrl = window.location.origin + window.location.pathname + '#';
var content = '<b>' + Messages.readonlyUrl + '</b><br><a target="_blank">' + baseUrl + viewHash + '</a><br>'; var content = '<b>' + Messages.readonlyUrl + '</b><br><a>' + baseUrl + viewHash + '</a><br>';
Cryptpad.alert(content); Cryptpad.alert(content);
}); });
$rightside.append($links); $rightside.append($links);
@ -470,9 +472,14 @@ define([
}); });
}; };
configureLanguage(function () { if (!readOnly) {
configureLanguage(function () {
configureTheme();
});
}
else {
configureTheme(); configureTheme();
}); }
// set the hash // set the hash
if (!readOnly) { if (!readOnly) {

@ -86,6 +86,11 @@ define([
editor.on('instanceReady', function (Ckeditor) { editor.on('instanceReady', function (Ckeditor) {
if (readOnly) {
$('#pad-iframe')[0].contentWindow.$('#cke_1_toolbox > .cke_toolbar').hide();
}
/* add a class to the magicline plugin so we can pick it out more easily */ /* add a class to the magicline plugin so we can pick it out more easily */
var ml = $('iframe')[0].contentWindow.CKEDITOR.instances.editor1.plugins.magicline var ml = $('iframe')[0].contentWindow.CKEDITOR.instances.editor1.plugins.magicline
@ -397,33 +402,33 @@ define([
// build a dom from HJSON, diff, and patch the editor // build a dom from HJSON, diff, and patch the editor
applyHjson(shjson); applyHjson(shjson);
if (readOnly) { return; } if (!readOnly) {
var shjson2 = stringifyDOM(inner);
var shjson2 = stringifyDOM(inner); if (shjson2 !== shjson) {
if (shjson2 !== shjson) { console.error("shjson2 !== shjson");
console.error("shjson2 !== shjson"); module.patchText(shjson2);
module.patchText(shjson2);
/* pushing back over the wire is necessary, but it can
/* pushing back over the wire is necessary, but it can result in a feedback loop, which we call a browser
result in a feedback loop, which we call a browser fight */
fight */ if (module.logFights) {
if (module.logFights) { // what changed?
// what changed? var op = TextPatcher.diff(shjson, shjson2);
var op = TextPatcher.diff(shjson, shjson2); // log the changes
// log the changes TextPatcher.log(shjson, op);
TextPatcher.log(shjson, op); var sop = JSON.stringify(TextPatcher.format(shjson, op));
var sop = JSON.stringify(TextPatcher.format(shjson, op));
var index = module.fights.indexOf(sop);
var index = module.fights.indexOf(sop); if (index === -1) {
if (index === -1) { module.fights.push(sop);
module.fights.push(sop); console.log("Found a new type of browser disagreement");
console.log("Found a new type of browser disagreement"); console.log("You can inspect the list in your " +
console.log("You can inspect the list in your " + "console at `REALTIME_MODULE.fights`");
"console at `REALTIME_MODULE.fights`"); console.log(module.fights);
console.log(module.fights); } else {
} else { console.log("Encountered a known browser disagreement: " +
console.log("Encountered a known browser disagreement: " + "available at `REALTIME_MODULE.fights[%s]`", index);
"available at `REALTIME_MODULE.fights[%s]`", index); }
} }
} }
} }
@ -505,19 +510,22 @@ define([
.text(Messages.exportButton) .text(Messages.exportButton)
.addClass('rightside-button') .addClass('rightside-button')
.click(exportFile); .click(exportFile);
$rightside.append($export);
/* add an import button */ if (!readOnly) {
var $import = $('<button>', { /* add an import button */
title: Messages.importButtonTitle var $import = $('<button>', {
}) title: Messages.importButtonTitle
.text(Messages.importButton) })
.addClass('rightside-button') .text(Messages.importButton)
.click(Cryptpad.importContent('text/plain', function (content) { .addClass('rightside-button')
var shjson = stringify(Hyperjson.fromDOM(domFromHTML(content).body)); .click(Cryptpad.importContent('text/plain', function (content) {
applyHjson(shjson); var shjson = stringify(Hyperjson.fromDOM(domFromHTML(content).body));
realtimeOptions.onLocal(); applyHjson(shjson);
})); realtimeOptions.onLocal();
$rightside.append($export).append($import); }));
$rightside.append($import);
}
/* add a rename button */ /* add a rename button */
var $rename = $('<button>', { var $rename = $('<button>', {
@ -578,7 +586,7 @@ define([
.addClass('rightside-button') .addClass('rightside-button')
.click(function () { .click(function () {
var baseUrl = window.location.origin + window.location.pathname + '#'; var baseUrl = window.location.origin + window.location.pathname + '#';
var content = '<b>' + Messages.readonlyUrl + '</b><br><a target="_blank">' + baseUrl + viewHash + '</a><br>'; var content = '<b>' + Messages.readonlyUrl + '</b><br><a>' + baseUrl + viewHash + '</a><br>';
Cryptpad.alert(content); Cryptpad.alert(content);
}); });
$rightside.append($links); $rightside.append($links);

Loading…
Cancel
Save