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

This commit is contained in:
yflory 2016-09-21 15:03:36 +02:00
parent 7cc5218422
commit 47e8be1681
2 changed files with 84 additions and 69 deletions

View File

@ -305,38 +305,40 @@ define([
.click(exportText);
$rightside.append($export);
/* add an import button */
var $import = $('<button>',{
title: Messages.importButtonTitle
})
.text(Messages.importButton)
.addClass('rightside-button')
.click(Cryptpad.importContent('text/plain', function (content, file) {
var mode;
var mime = CodeMirror.findModeByMIME(file.type);
if (!readOnly) {
/* add an import button */
var $import = $('<button>',{
title: Messages.importButtonTitle
})
.text(Messages.importButton)
.addClass('rightside-button')
.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]);
if (!mime) {
var ext = /.+\.([^.]+)$/.exec(file.name);
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; })) {
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');
}
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);
editor.setValue(content);
onLocal();
}));
$rightside.append($import);
}
/* add a rename button */
var $setTitle = $('<button>', {
@ -410,7 +412,7 @@ define([
.addClass('rightside-button')
.click(function () {
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);
});
$rightside.append($links);
@ -470,9 +472,14 @@ define([
});
};
configureLanguage(function () {
if (!readOnly) {
configureLanguage(function () {
configureTheme();
});
}
else {
configureTheme();
});
}
// set the hash
if (!readOnly) {

View File

@ -86,6 +86,11 @@ define([
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 */
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
applyHjson(shjson);
if (readOnly) { return; }
if (!readOnly) {
var shjson2 = stringifyDOM(inner);
if (shjson2 !== shjson) {
console.error("shjson2 !== shjson");
module.patchText(shjson2);
var shjson2 = stringifyDOM(inner);
if (shjson2 !== shjson) {
console.error("shjson2 !== shjson");
module.patchText(shjson2);
/* pushing back over the wire is necessary, but it can
result in a feedback loop, which we call a browser
fight */
if (module.logFights) {
// what changed?
var op = TextPatcher.diff(shjson, shjson2);
// log the changes
TextPatcher.log(shjson, op);
var sop = JSON.stringify(TextPatcher.format(shjson, op));
/* pushing back over the wire is necessary, but it can
result in a feedback loop, which we call a browser
fight */
if (module.logFights) {
// what changed?
var op = TextPatcher.diff(shjson, shjson2);
// log the changes
TextPatcher.log(shjson, op);
var sop = JSON.stringify(TextPatcher.format(shjson, op));
var index = module.fights.indexOf(sop);
if (index === -1) {
module.fights.push(sop);
console.log("Found a new type of browser disagreement");
console.log("You can inspect the list in your " +
"console at `REALTIME_MODULE.fights`");
console.log(module.fights);
} else {
console.log("Encountered a known browser disagreement: " +
"available at `REALTIME_MODULE.fights[%s]`", index);
var index = module.fights.indexOf(sop);
if (index === -1) {
module.fights.push(sop);
console.log("Found a new type of browser disagreement");
console.log("You can inspect the list in your " +
"console at `REALTIME_MODULE.fights`");
console.log(module.fights);
} else {
console.log("Encountered a known browser disagreement: " +
"available at `REALTIME_MODULE.fights[%s]`", index);
}
}
}
}
@ -505,19 +510,22 @@ define([
.text(Messages.exportButton)
.addClass('rightside-button')
.click(exportFile);
$rightside.append($export);
/* add an import button */
var $import = $('<button>', {
title: Messages.importButtonTitle
})
.text(Messages.importButton)
.addClass('rightside-button')
.click(Cryptpad.importContent('text/plain', function (content) {
var shjson = stringify(Hyperjson.fromDOM(domFromHTML(content).body));
applyHjson(shjson);
realtimeOptions.onLocal();
}));
$rightside.append($export).append($import);
if (!readOnly) {
/* add an import button */
var $import = $('<button>', {
title: Messages.importButtonTitle
})
.text(Messages.importButton)
.addClass('rightside-button')
.click(Cryptpad.importContent('text/plain', function (content) {
var shjson = stringify(Hyperjson.fromDOM(domFromHTML(content).body));
applyHjson(shjson);
realtimeOptions.onLocal();
}));
$rightside.append($import);
}
/* add a rename button */
var $rename = $('<button>', {
@ -578,7 +586,7 @@ define([
.addClass('rightside-button')
.click(function () {
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);
});
$rightside.append($links);