define([ 'jquery', '/bower_components/chainpad-crypto/crypto.js', '/bower_components/chainpad-listmap/chainpad-listmap.js', '/common/toolbar3.js', '/bower_components/nthen/index.js', '/common/sframe-common.js', '/common/common-util.js', '/common/common-interface.js', '/common/common-realtime.js', '/customize/messages.js', '/bower_components/marked/marked.min.js', 'cm/lib/codemirror', 'cm/mode/markdown/markdown', 'css!/bower_components/codemirror/lib/codemirror.css', 'css!/bower_components/codemirror/addon/dialog/dialog.css', 'css!/bower_components/codemirror/addon/fold/foldgutter.css', 'css!/bower_components/bootstrap/dist/css/bootstrap.min.css', 'less!/bower_components/components-font-awesome/css/font-awesome.min.css', 'less!/customize/src/less2/main.less', ], function ( $, Crypto, Listmap, Toolbar, nThen, SFCommon, Util, UI, Realtime, Messages, Marked, CodeMirror ) { var APP = window.APP = { _onRefresh: [] }; // Decryption event for avatar mediatag (TODO not needed anymore?) $(window.document).on('decryption', function (e) { var decrypted = e.originalEvent; if (decrypted.callback) { decrypted.callback(); } }) .on('decryptionError', function (e) { var error = e.originalEvent; UI.alert(error.message); }); $(window).click(function () { $('.cp-dropdown-content').hide(); }); // 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'; }; var DISPLAYNAME_ID = "cp-app-profile-displayname"; var LINK_ID = "cp-app-profile-link"; var AVATAR_ID = "cp-app-profile-avatar"; var DESCRIPTION_ID = "cp-app-profile-description"; var PUBKEY_ID = "cp-app-profile-pubkey"; var CREATE_ID = "cp-app-profile-create"; var HEADER_ID = "cp-app-profile-header"; var HEADER_RIGHT_ID = "cp-app-profile-rightside"; var CREATE_INVITE_BUTTON = 'cp-app-profile-invite-button'; /* jshint ignore: line */ var VIEW_PROFILE_BUTTON = 'cp-app-profile-viewprofile-button'; var common; var sFrameChan; var createEditableInput = function ($block, name, ph, getValue, setValue, 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 cp-app-profile-input-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); } lastVal = newVal; UI.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); }); }; /* jshint ignore:start */ var isFriend = function (proxy, edKey) { var friends = Util.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 = Util.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 = Util.fixHTML(unsafeName) || Messages.anonymous; console.log(name); console.log("Creating invite button"); $("