diff --git a/customize.dist/main.css b/customize.dist/main.css index 72190a3a1..0c063e6e8 100644 --- a/customize.dist/main.css +++ b/customize.dist/main.css @@ -154,6 +154,9 @@ tr { margin-bottom: 12px; white-space: nowrap; } +.alertify button { + margin: 3px 0px; +} /* Tables */ table { border-collapse: collapse; diff --git a/customize.dist/src/cryptpad.less b/customize.dist/src/cryptpad.less index 16448646f..c41af4de9 100644 --- a/customize.dist/src/cryptpad.less +++ b/customize.dist/src/cryptpad.less @@ -187,6 +187,9 @@ p, pre, td, a, table, tr { margin-bottom: 2 * 6px; white-space: nowrap; } +.alertify button { + margin: 3px 0px; +} /* Tables */ table { diff --git a/customize.dist/translations/messages.fr.js b/customize.dist/translations/messages.fr.js index c6a9be3fe..cd41d5fb5 100644 --- a/customize.dist/translations/messages.fr.js +++ b/customize.dist/translations/messages.fr.js @@ -74,7 +74,10 @@ define(function () { out.getViewButton = '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 !'; diff --git a/customize.dist/translations/messages.js b/customize.dist/translations/messages.js index df1bd18de..63a0dc40e 100644 --- a/customize.dist/translations/messages.js +++ b/customize.dist/translations/messages.js @@ -75,7 +75,9 @@ define(function () { out.getViewButton = 'READ-ONLY URL'; 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!'; diff --git a/www/code/main.js b/www/code/main.js index 71f3bfd14..35e475098 100644 --- a/www/code/main.js +++ b/www/code/main.js @@ -265,6 +265,32 @@ define([ 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 $bar = $('#pad-iframe')[0].contentWindow.$('#cme_toolbox'); @@ -285,113 +311,45 @@ define([ editHash = Cryptpad.getEditHashFromKeys(info.channel, secret.keys); } + /* add a "change username" button */ getLastName(function (err, lastName) { - var $username = Cryptpad.createButton('username', true) - .click(function() { - Cryptpad.prompt(Messages.changeNamePrompt, lastName, function (newName) { - setName(newName); - }); - }); + var usernameCb = function (newName) { + setName (newName); + }; + var $username = Cryptpad.createButton('username', true, {lastName: lastName}, usernameCb); $rightside.append($username); }); /* add an export button */ - var $export = Cryptpad.createButton('export', true).click(exportText); + var $export = Cryptpad.createButton('export', true, {}, exportText); $rightside.append($export); if (!readOnly) { /* add an import button */ - var $import = Cryptpad.createButton('import', true) - .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(); - })); + var $import = Cryptpad.createButton('import', true, {}, importText); $rightside.append($import); } /* add a rename button */ - var $setTitle = Cryptpad.createButton('rename', true) - .click(function () { - var suggestion = suggestName(); - - Cryptpad.prompt(Messages.renamePrompt, - suggestion, function (title, ev) { - 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(); - }); - }); - }); - }); + var renameCb = function (err, title) { + if (err) { return; } + document.title = title; + onLocal(); + }; + var $setTitle = Cryptpad.createButton('rename', true, {suggestName: suggestName}, renameCb); $rightside.append($setTitle); /* add a forget button */ - var $forgetPad = Cryptpad.createButton('forget', true) - .click(function () { - var href = window.location.href; - Cryptpad.confirm(Messages.forgetPrompt, function (yes) { - if (!yes) { return; } - 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, []); - }); - }); - }); + var forgetCb = function (err, title) { + if (err) { return; } + document.title = title; + }; + var $forgetPad = Cryptpad.createButton('forget', true, {}, forgetCb); $rightside.append($forgetPad); if (!readOnly && viewHash) { /* add a 'links' button */ - var $links = Cryptpad.createButton('readonly', true) - .click(function () { - var baseUrl = window.location.origin + window.location.pathname + '#'; - var content = '' + Messages.readonlyUrl + '
' + baseUrl + viewHash + '
'; - Cryptpad.alert(content); - }); + var $links = Cryptpad.createButton('readonly', true, {viewHash: viewHash}); $rightside.append($links); } diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 68fa9be7a..b2a2fce50 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -4,11 +4,12 @@ define([ '/bower_components/chainpad-crypto/crypto.js', '/bower_components/alertifyjs/dist/js/alertify.js', '/bower_components/spin.js/spin.min.js', + '/common/clipboard.js', '/customize/user.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 any particular pad type. This includes functions for committing metadata about pads to your local storage for future use and improved usability. @@ -610,7 +611,7 @@ define([ /* * Buttons */ - var createButton = common.createButton = function (type, rightside) { + var createButton = common.createButton = function (type, rightside, data, callback) { var button; var size = "17px"; switch (type) { @@ -620,6 +621,9 @@ define([ 'class': "fa fa-download", style: 'font:'+size+' FontAwesome' }); + if (callback) { + button.click(callback); + } break; case 'import': button = $('