require.config({ paths: { cm: '/bower_components/codemirror' } }); define([ 'jquery', '/common/cryptpad-common.js', '/bower_components/chainpad-listmap/chainpad-listmap.js', '/bower_components/chainpad-crypto/crypto.js', '/bower_components/marked/marked.min.js', '/common/toolbar2.js', 'cm/lib/codemirror', 'cm/mode/markdown/markdown', 'less!/profile/main.less', 'less!/customize/src/less/toolbar.less', 'less!/customize/src/less/cryptpad.less', 'css!/bower_components/bootstrap/dist/css/bootstrap.min.css', ], function ($, Cryptpad, Listmap, Crypto, Marked, Toolbar, CodeMirror) { var APP = window.APP = { Cryptpad: Cryptpad, _onRefresh: [] }; $(window.document).on('decryption', function (e) { var decrypted = e.originalEvent; if (decrypted.callback) { decrypted.callback(); } }) .on('decryptionError', function (e) { var error = e.originalEvent; Cryptpad.alert(error.message); }); // Marked var renderer = new Marked.Renderer(); Marked.setOptions({ renderer: renderer, sanitize: true }); // Tasks list var checkedTaskItemPtn = /^\s*\[x\]\s*/; var uncheckedTaskItemPtn = /^\s*\[ \]\s*/; renderer.listitem = function (text) { var isCheckedTaskItem = checkedTaskItemPtn.test(text); var isUncheckedTaskItem = uncheckedTaskItemPtn.test(text); if (isCheckedTaskItem) { text = text.replace(checkedTaskItemPtn, ' ') + '\n'; } if (isUncheckedTaskItem) { text = text.replace(uncheckedTaskItemPtn, ' ') + '\n'; } var cls = (isCheckedTaskItem || isUncheckedTaskItem) ? ' class="todo-list-item"' : ''; return '' + text + '\n'; }; /*renderer.image = function (href, title, text) { if (href.slice(0,6) === '/file/') { var parsed = Cryptpad.parsePadUrl(href); var hexFileName = Cryptpad.base64ToHex(parsed.hashData.channel); var src = '/blob/' + hexFileName.slice(0,2) + '/' + hexFileName; var mt = ''; mt += ''; return mt; } var out = '' + text + '' : '>'; return out; };*/ var Messages = Cryptpad.Messages; var DISPLAYNAME_ID = "displayName"; var LINK_ID = "link"; var AVATAR_ID = "avatar"; var DESCRIPTION_ID = "description"; var PUBKEY_ID = "pubKey"; var CREATE_ID = "createProfile"; var HEADER_ID = "header"; var HEADER_RIGHT_ID = "rightside"; var CREATE_INVITE_BUTTON = 'inviteButton'; /* jshint ignore: line */ var VIEW_PROFILE_BUTTON = 'viewProfileButton'; var createEditableInput = function ($block, name, ph, getValue, setValue, realtime, fallbackValue) { fallbackValue = fallbackValue || ''; // don't ever display 'null' or 'undefined' var lastVal; getValue(function (value) { lastVal = value; var $input = $('', { 'id': name+'Input', placeholder: ph }).val(value); var $icon = $('', {'class': 'fa fa-pencil edit'}); var editing = false; var todo = function () { if (editing) { return; } editing = true; var newVal = $input.val().trim(); if (newVal === lastVal) { editing = false; return; } setValue(newVal, function (err) { if (err) { return void console.error(err); } Cryptpad.whenRealtimeSyncs(realtime, function () { lastVal = newVal; Cryptpad.log(Messages._getKey('profile_fieldSaved', [newVal || fallbackValue])); editing = false; }); }); }; $input.on('keyup', function (e) { if (e.which === 13) { return void todo(); } if (e.which === 27) { $input.val(lastVal); } }); $icon.click(function () { $input.focus(); }); $input.focus(function () { $input.width(''); }); $input.focusout(todo); $block.append($input).append($icon); }); }; /* var addDisplayName = function ($container) { var $block = $('
', {id: DISPLAYNAME_ID}).appendTo($container); var getValue = function (cb) { Cryptpad.getLastName(function (err, name) { if (err) { return void console.error(err); } cb(name); }); }; if (APP.readOnly) { var $span = $('', {'class': DISPLAYNAME_ID}).appendTo($block); getValue(function (value) { $span.text(value); }); return; } var setValue = function (value, cb) { Cryptpad.setAttribute('username', value, function (err) { cb(err); }); }; var placeholder = Messages.anonymous; var rt = Cryptpad.getStore().getProxy().info.realtime; createEditableInput($block, DISPLAYNAME_ID, placeholder, 32, getValue, setValue, rt); }; */ /* jshint ignore:start */ var isFriend = function (proxy, edKey) { var friends = Cryptpad.find(proxy, ['friends']); return typeof(edKey) === 'string' && friends && (edKey in friends); }; var addCreateInviteLinkButton = function ($container) { return; var obj = APP.lm.proxy; var proxy = Cryptpad.getProxy(); var userViewHash = Cryptpad.find(proxy, ['profile', 'view']); var edKey = obj.edKey; var curveKey = obj.curveKey; if (!APP.readOnly || !curveKey || !edKey || userViewHash === window.location.hash.slice(1) || isFriend(proxy, edKey)) { //console.log("edit mode or missing curve key, or you're viewing your own profile"); return; } // sanitize user inputs var unsafeName = obj.name || ''; console.log(unsafeName); var name = Cryptpad.fixHTML(unsafeName) || Messages.anonymous; console.log(name); console.log("Creating invite button"); $("