From 992bc4f44928fb5d74fad80acdef43435ca1fb48 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 25 Jul 2016 11:09:25 +0200 Subject: [PATCH] add missing script --- www/code/inner.html | 1 + www/code/main.js | 1 - www/pad/main.js | 39 +++++++++++++++++++++++++++------------ 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/www/code/inner.html b/www/code/inner.html index b80598df7..106430ec0 100644 --- a/www/code/inner.html +++ b/www/code/inner.html @@ -10,6 +10,7 @@ + diff --git a/www/code/main.js b/www/code/main.js index a97020be5..51814cfe4 100644 --- a/www/code/main.js +++ b/www/code/main.js @@ -445,7 +445,6 @@ define([ var lastName = getLastName(); if (typeof(lastName) === 'string' && lastName.length) { - console.log("Setting previous name to %s", lastName); setName(lastName); } }; diff --git a/www/pad/main.js b/www/pad/main.js index dfdf3f9cb..166b3ab24 100644 --- a/www/pad/main.js +++ b/www/pad/main.js @@ -234,21 +234,32 @@ define([ myID = info.myID || null; }; + var getLastName = function () { + return Cryptpad.getPadAttribute('username') || ''; + }; + + var setName = module.setName = function (newName) { + if (!(typeof(newName) === 'string' && newName.trim())) { return; } + var myUserNameTemp = newName.trim(); + if(myUserNameTemp.length > 32) { + myUserNameTemp = myUserNameTemp.substr(0, 32); + } + myUserName = myUserNameTemp; + myData[myID] = { + name: myUserName + }; + addToUserList(myData); + editor.fire('change'); + + Cryptpad.setPadAttribute('username', newName); + }; + var createChangeName = function(id, $container) { var buttonElmt = $container.find('#'+id)[0]; + var lastName = getLastName(); buttonElmt.addEventListener("click", function() { - Cryptpad.prompt(Messages.changeNamePrompt, '', function (newName) { - if (!(typeof(newName) === 'string' && newName.trim())) { return; } - var myUserNameTemp = newName.trim(); - if(myUserNameTemp.length > 32) { - myUserNameTemp = myUserNameTemp.substr(0, 32); - } - myUserName = myUserNameTemp; - myData[myID] = { - name: myUserName - }; - addToUserList(myData); - editor.fire('change'); + Cryptpad.prompt(Messages.changeNamePrompt, lastName, function (newName) { + setName(newName); }); }); }; @@ -524,6 +535,10 @@ define([ console.log("Unlocking editor"); setEditable(true); initializing = false; + var lastName = getLastName(); + if (typeof(lastName) === 'string' && lastName.length) { + setName(lastName); + } }; var onAbort = realtimeOptions.onAbort = function (info) {