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 bbff1822c..744eff569 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 3d4ba85c6..09c044481 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 fc10fd7c9..e02335579 100644 --- a/www/code/main.js +++ b/www/code/main.js @@ -271,6 +271,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'); @@ -291,113 +317,44 @@ 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(); - }); - }); - }); - }); - $rightside.append($setTitle); - } + /* add a rename button */ + 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 519c5014e..be886517b 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -5,11 +5,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 (Config, Messages, Store, Crypto, Alertify, Spinner, User) { +], function (Config, 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. @@ -627,7 +628,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) { @@ -637,6 +638,9 @@ define([ 'class': "fa fa-download", style: 'font:'+size+' FontAwesome' }); + if (callback) { + button.click(callback); + } break; case 'import': button = $('