ep_profile_modal
Version:
profile modal for Etherpad
3 lines (2 loc) • 38.1 kB
JavaScript
exports.init = (() => { const e = (e, o, r) => { if ('admin/ep_profile_modal' !== o) return []; let a; const l = document.location; const s = '' == l.port ? 'https:' == l.protocol ? 443 : 80 : l.port; const i = `${l.protocol}//${l.hostname}:${s}/`; const t = location.pathname.split('/'); const n = `${t.slice(0, t.length - 2).join('/')}/`; const p = `${n.substring(1)}socket.io`; const d = `${i}pluginfw/admin/ep_profile_modal`; return a = io.connect(d, {path: `${n}socket.io`, resource: p}), a.on('load-settings-result', (e) => { console.log(e), _.setFormData($('#settings-form'), e); }), $('#save-settings').on('click', () => { const e = _.getFormData($('#settings-form')); console.log(e, 'data'), a.emit('save-settings', e), alert('Succesfully saved.'); }), a.emit('load-settings'), []; }; const o = (() => { const e = function (e, o, r, a, l, s, i) { let t; return l = l || '', s = s || '', a && 'Anonymous' == o ? (t = `background: url(${r}) no-repeat 50% 50% ; background-size : 69px ;`, `<div data-user-ids='${e}' data-anonymouseCount='1' data-id='user_list_${a}' class='ep_profile_user_row'><div style='${t}' class='ep_profile_user_img'></div><div class='ep_profile_user_list_profile_userDesc'><div class='ep_profile_user_list_username'><div class='ep_profile_user_list_username_text' >${o}</div><div class='ep_profile_contributor_status'>${i}</div></div><p class='ep_profile_user_list_profile_desc'>${l}</p></div> </div>`) : (t = `background: url(${r}) no-repeat 50% 50% ; background-size : 69px ;`, `<div data-id='user_list_${e}' class='ep_profile_user_row'><div style='${t}' class='ep_profile_user_img'></div><div class='ep_profile_user_list_profile_userDesc'><div class='ep_profile_user_list_username'><div class='ep_profile_user_list_username_text' >${o}</div><a target='_blank' class='ep_profile_contributor_link_container' title='${_.getValidUrl(s)}' href='${_.getValidUrl(s)}'> </a><div class='ep_profile_contributor_status'>${i}</div></div><p class='ep_profile_user_list_profile_desc'>${l}</p></div> </div>`); }; const o = function (e, o) { const r = e.attr('data-anonymouseCount'); const a = e.attr('data-user-ids').split(','); if (-1 == a.indexOf(o)) { a.push(o), e.attr('data-user-ids', a.join(',')); const l = parseInt(r) + 1; e.attr('data-anonymouseCount', l), e.children('.ep_profile_user_list_profile_userDesc').children('.ep_profile_user_list_username').children('.ep_profile_user_list_username_text').text(`Anonymous ×${l}`); } }; const r = function (e, o) { const r = e.attr('data-anonymouseCount'); let a = e.attr('data-user-ids').split(','); a = $.grep(a, (e) => e != o), e.attr('data-user-ids', a.join(',')); const l = parseInt(r) - 1; return e.attr('data-anonymouseCount', l), l > 1 ? e.children('.ep_profile_user_list_profile_userDesc').children('.ep_profile_user_list_username').children('.ep_profile_user_list_username_text').text(`Anonymous ×${l}`) : e.children('.ep_profile_user_list_profile_userDesc').children('.ep_profile_user_list_username').children('.ep_profile_user_list_username_text').text('Anonymous'), l < 1 && e.remove(), l; }; const a = function (e, o) { const r = e.attr('data-anonymouseCount'); let a = e.attr('data-user-ids'); a = $.grep(a, (e) => e != o), e.attr('data-user-ids', a); const l = parseInt(r) + 1; e.attr('data-anonymouseCount', l), e.children('.ep_profile_user_list_profile_userDesc').children('.ep_profile_user_list_username').children('.ep_profile_user_list_username_text').text(`Anonymous ×${l}`); }; const l = function (o, r, a, l, s) { const i = e(o, 'Anonymous', r, 'off_Anonymous', a, l, 'Today'); let t = $('#ep_profile_user_list_offline'); if (t.length) { const e = $(".ep_profile_user_row[data-id='user_list_off_Anonymous']"); e.length ? s.insertBefore(e) : t.append(s); } else { $('#ep_profile_user_list_container_off').prepend("<div class='ep_profile_user_list_date_title' id='ep_profile_user_list_offline'></div>"), t = $('#ep_profile_user_list_offline'), t.append(i); } }; const s = function (e) { let o = $('#ep_profile_user_list_offline'); if (o.length) { const r = $(".ep_profile_user_row[data-id='user_list_off_Anonymous']"); r.length ? e.insertBefore(r) : o.append(e); } else { $('#ep_profile_user_list_container_off').prepend("<div class='ep_profile_user_list_date_title' id='ep_profile_user_list_offline'></div>"), o = $('#ep_profile_user_list_offline'), o.append(e); }e.children('.ep_profile_user_list_profile_userDesc').children('.ep_profile_user_list_username').children('.ep_profile_contributor_status').text('Last seen today'); }; return {createHTMLforUserList(e, o, r, a) { let l; let s = "<div id='usersIconList' class='ep_profile_inlineAvatars'>"; let i = ''; return $.each(o.reverse(), (e, o) => { l = `background: url(/static/getUserProfileImage/${o.userId}/${r}) no-repeat 50% 50% ; background-size : 28px;background-color: #fff;`, a && a.length && 'null' !== a && null !== a && (i = -1 == a.indexOf(o.userId) ? '' : 'box-shadow: 0px 0px 1px 1px rgba(38,121,255,1);margin: 1px;'), l += i, s += `<div class='avatar' data-userId="${o.userId}" data-id="user_${o.userId}" id="user_${o.userId}" ><div data-userId="${o.userId}" class='avatarImg' style='${l}' data-id="user_${o.userId}"></div></div>`; }), s += ' </div>', `${s}<span class='slash_profile'>⧸</span><span id='userlist_count' class='userlist_count'>${e}</span><input value='Share' id='ep_profile_modal_share' type='button' class='ep_profile_modal_share'>`; }, increaseUserFromList(e, o) { const r = `background: url(/static/getUserProfileImage/${e}/${o}) no-repeat 50% 50% ; background-size : 26px;background-color: #fff;`; if (!$(`.avatar[data-id="user_${e}"]`).length) { const o = $(`<div class='avatar' data-userId="${e}" data-id="user_${e}" id="user_${e}" ><div class='avatarImg' data-userId="${e}" data-id="user_${e}" style='${r}'></div></div>`); o.prependTo('#usersIconList'), o.hide().slideDown(200); } }, decreaseUserFromList(e, o) { $(`.avatar[data-id="user_${e}"]`).animate({opacity: 0}, 1e3, 'linear', (function () { $(this).remove(); })); const i = $(`.ep_profile_user_row[data-id="user_list_${e}"]`); if (i.length) { s(i); } else { const o = $('.ep_profile_user_row[data-id="user_list_on_Anonymous"]'); if (o.length) { const s = $('.ep_profile_user_row[data-id="user_list_off_Anonymous"]'); r(o, e), s.length ? a(s, e) : l(e, '../static/plugins/ep_profile_modal/static/img/user.png', null, null, i); } else { let o = $('#ep_profile_user_list_offline'); if (o.length) { o.append($(`.ep_profile_user_row[data-id="user_list_${e}"]`)); } else { $('#ep_profile_user_list_container_off').prepend("<div class='ep_profile_user_list_date_title' id='ep_profile_user_list_offline'> </div>"), o = $('#ep_profile_user_list_offline'), $(`.ep_profile_user_row[data-id="user_list_${e}"]`).appendTo(o); } } } const t = `/static/getUserProfileImage/${e}/${o}?t=${(new Date()).getTime()}`; const _ = $(`.ep_profile_user_row[data-id="user_list_${e}"]`); _.length && _.children('.ep_profile_user_img').css({'background-position': '50% 50%', 'background-image': `url(${t})`, 'background-repeat': 'no-repeat', 'background-size': '69px'}); }, moveOnlineUserToOffline: s, decreaseFromOnlineAnonymous: r, increaseToOfflineAnonymous: a, createOfflineAnonymousElement: l, manageOnlineOfflineUsers(r, a, l) { const s = $('#ep_profile_user_list_container'); const i = $('#ep_profile_user_list_container_off'); i.empty(), $.each(r, (r, t) => { if ($.grep(a, (e) => e.userId == t.userId).length) if ('Anonymous' == t.userName) { const r = $('.ep_profile_user_row[data-id="user_list_on_Anonymous"]'); if (r.length) { o(r, t.userId); } else { var n = e(t.userId, t.userName, t.imageUrl, 'on_Anonymous', t.about, t.homepage, 'Online'); s.append(n); }l == t.userId && $(".ep_profile_user_row[data-id='user_list_on_Anonymous']").css({'margin-top': '28px'}); } else { if ($(`.ep_profile_user_row[data-id="user_list_${t.userId}"]`).length) { l == t.userId ? $(`.ep_profile_user_row[data-id="user_list_${t.userId}"]`).prependTo(s) : $(`.ep_profile_user_row[data-id="user_list_${t.userId}"]`).appendTo(s); } else { n = e(t.userId, t.userName, t.imageUrl, !1, t.about, t.homepage, 'Online'); try { s.append(n); } catch (e) { console.log(e); } }l == t.userId && $(`.ep_profile_user_row[data-id="user_list_${t.userId}"]`).css({'margin-top': '28px'}); } else if ('' !== t.last_seen_date && 'Anonymous' != t.userName) if ($(`.ep_profile_user_row[data-id="user_list_${t.userId}"]`).length) { $(`.ep_profile_user_row[data-id="user_list_${t.userId}"]`).appendTo(i); } else { n = e(t.userId, t.userName, t.imageUrl, !1, t.about, t.homepage, _.getCustomDate(t.last_seen_date)); const o = $('#ep_profile_user_list_offline'); o.length ? o.append(n) : $('#ep_profile_user_list_container_off').append(`<div class='ep_profile_user_list_date_title' id='ep_profile_user_list_offline'> ${n}</div>`); } }), $.each(r, (o, r) => { if (!$.grep(a, (e) => e.userId == r.userId).length && '' !== r.last_seen_date && 'Anonymous' == r.userName) { const o = $('.ep_profile_user_row[data-id="user_list_off_Anonymous"]'); if (o.length) { const e = o.attr('data-anonymouseCount'); const a = parseInt(e) + 1; const l = o.attr('data-user-ids').split(','); l.push(r.userId), o.attr('data-user-ids', l.join(',')), o.attr('data-anonymouseCount', a), o.children('.ep_profile_user_list_profile_userDesc').children('.ep_profile_user_list_username').text(`Anonymous ×${a}`); } else { const o = e(r.userId, 'Anonymous', r.imageUrl, 'off_Anonymous', r.about, r.homepage, _.getCustomDate(r.last_seen_date)); const a = $('#ep_profile_user_list_offline'); a.length ? a.append(o) : $('#ep_profile_user_list_container_off').append(`<div class='ep_profile_user_list_date_title' id='ep_profile_user_list_offline'> ${o}</div>`); } } }); }, increaseToOnlineAnonymous: o, createOnlineUserElementInUserList(o, r, a, l, s) { const i = $(`.ep_profile_user_row[data-id="user_list_${o}"]`); if (i.length) { i.children('.ep_profile_user_list_profile_userDesc').children('.ep_profile_user_list_username').children('.ep_profile_user_list_username_text').text(r), i.children('.ep_profile_user_img').css({'background-position': '50% 50%', 'background-image': `url(${a})`, 'background-repeat': 'no-repeat', 'background-size': '69px'}); } else { const i = e(o, r, a, !1, s.about, s.homepage, 'Online'); if (o == l) { const e = $('#ep_profile_user_list_date_title'); e.length ? $(i).insertAfter(e) : $('#ep_profile_user_list_container').prepend(i); } else { $('#ep_profile_user_list_container').append(i); } } }, isThereOnlineAnonymous() { const e = $('.ep_profile_user_row[data-id="user_list_on_Anonymous"]'); return !!e.length && e; }, checkUserExistInOnlineAnonymous(e, o) { return -1 != e.attr('data-user-ids').split(',').indexOf(o); }, createOnlineAnonymousElement(o, r, a, l) { const s = $('#ep_profile_user_list_container'); const i = e(o, r, a, 'on_Anonymous', l.about, l.homepage, 'Online'); s.append(i); }, removeUserElementInUserList(e) { $(`.ep_profile_user_row[data-id="user_list_${e}"]`).remove(); }}; })(); const r = (() => { const e = function () { $('#ep_profile_formModal_overlay').removeClass('ep_profile_formModal_overlay_show'), $('#ep_profile_formModal_overlay').css({display: 'none'}), o(); }; const o = function () { const e = pad.getUserId(); const o = pad.getPadId(); const a = $('#ep_profile_formModal_msform'); const l = r(a); const s = {}; if ('' == l.ep_profile_modalForm_name) return !1; let i = `Please welcome ${l.ep_profile_modalForm_name}`; if ('' !== l.ep_profile_modalForm_about_yourself && (i += `, ${l.ep_profile_modalForm_about_yourself}`), '' !== l.ep_profile_modalForm_homepage) { i += `, <a target='_blank' href='${_.getValidUrl(l.ep_profile_modalForm_homepage)}'>${l.ep_profile_modalForm_homepage}</a>`; }s.text = `<span><b>${i}</b></span>`, s.target = 'profile', s.userId = e, s.time = new Date(); const t = {type: 'ep_profile_modal', action: 'EP_PROFILE_MODAL_SEND_MESSAGE_TO_CHAT', userId: e, data: s, padId: o}; pad.collabClient.sendMessage(t); }; const r = function (e) { const o = e.serializeArray(); const r = {}; return $.map(o, (e, o) => { r[e.name] = e.value; }), r; }; return {showModal() { $('#ep_profile_formModal').addClass('ep_profile_formModal_show'), $('#ep_profile_formModal_overlay').addClass('ep_profile_formModal_overlay_show'), $('#ep_profile_formModal_overlay').css({display: 'block'}), setTimeout(() => { $('#ep_profile_modalForm_name').focus(); }, 1e3); }, hideFormModalOverlay: e, handleOnCloseOverlay: o, resetModal() { $('#ep_profile_formModal_msform fieldset').each((function (e) { 0 == e ? $(this).show() : $(this).hide(); })); }, getFormData: r, initModal(o) { let a; let l; let s; let i; const n = $('#ep_profile_formModal_script').tmpl(o); function p() { const e = pad.getUserId(); const o = pad.getPadId(); const a = $('#ep_profile_formModal_msform'); const l = {type: 'ep_profile_modal', action: 'ep_profile_modal_info', userId: e, data: r(a), padId: o}; pad.collabClient.sendMessage(l); } function d() { const o = pad.getUserId(); const r = pad.getPadId(); $('#ep_profile_formModal').removeClass('ep_profile_formModal_show'), e(), p(); const a = $('#ep_profile_modalForm_name').val(); t.userLogin({email: $('#ep_profile_modalForm_email').val(), username: a}), setTimeout(() => { t.refreshUserImage(o, r); }, 2200); } function u(e, r) { if (console.log('clicked'), i) return !1; const a = e.attr('data-section'); if ('name' == a) { if ('' == $('#ep_profile_modalForm_name').val()) return $('#ep_profile_modalForm_name').css({border: '1px solid red'}), !1; var l = $('#ep_profile_modalForm_name').val(); $('#ep_profile_modalForm_name').css({border: '0px solid gray'}), t.userLogin({username: l}), _.loginByEmailAndUsernameWithoutValidation(l, '', !1); } if ('email' == a) { const e = $('#ep_profile_modalForm_email').val(); if (!_.isEmail(e) || '' == e) return $('#ep_profile_modalForm_email').css({border: '1px solid red'}), !1; l = $('#ep_profile_modalForm_name').val(); _.loginByEmailAndUsernameWithoutValidation(l, e, !0), function (e, o) { $.ajax({url: `/static/${pad.getPadId()}/pluginfw/ep_profile_modal/sendVerificationEmail/${pad.getUserId()}/${o}/${e}`, type: 'get', data: {}, contentType: !1, processData: !1, beforeSend() { $('#ep_profile_modal_verification').text('Sending...'); }, error(e) { $('#ep_profile_modal_verification').text('Error'), setTimeout(() => { $('#ep_profile_modal_verification').text(oldText); }, 2e3); }, success(e) { $('#ep_profile_modal_verification').text('Verification email has been sent.'), $('#ep_profile_modal_verification').attr('data-verification-status', 'true'); }}); }(e, l), $('#ep_profile_modalForm_email').css({border: '0px solid gray'}); } if ('homepage' == a) { const e = $('#ep_profile_modal_homepage').val(); if (console.log(_.IsValid(e)), !_.IsValid(e) || '' == e) return $('#ep_profile_modal_homepage').css({border: '1px solid red'}), !1; $('#ep_profile_modal_homepage').css({border: '0px solid gray'}), p(); } if ('image' == a && function () { const e = pad.getUserId(); const r = new FormData(); const a = $('#profile_file_modal')[0].files[0]; if (r.append('file', a), !a) return; $.ajax({url: `/static/${o.padId}/pluginfw/ep_profile_modal/upload/${e}`, type: 'post', data: r, contentType: !1, processData: !1, beforeSend() { t.refreshLoadingImage(e, o.padId); }, error(r) { t.refreshUserImage(e, o.padId), $('#profile_modal_selected_image').attr('style', (e, o) => o && o.replace(/background-image[^;]+;?/g, '')); }, success(r) { t.refreshUserImage(e, o.padId), $('#profile_modal_selected_image').attr('style', (e, o) => o && o.replace(/background-image[^;]+;?/g, '')); }}); }(), i = !0, e.hide(), r.length) { r.show(); const e = r.attr('data-section'); 'email' == e && $('#ep_profile_modalForm_email').focus().select(), 'homepage' == e && $('#ep_profile_modal_homepage').focus().select(), 'bio' == e && $('#ep_profile_modalForm_about_yourself').focus().select(); } else { d(); }i = !1; }$('body').append(n), $('#ep_profile_formModal_msform fieldset').on('keypress', (function (e) { 13 == e.keyCode && (e.preventDefault(), a = $(this), l = $(this).next(), u(a, l)); })), $('.next').click((function () { a = $(this).parent(), l = $(this).parent().next(), u(a, l); })), $('.skip').click((function () { if (i) return !1; $('#ep_profile_modalForm_name').css({border: '1px solid gray'}), i = !0, a = $(this).parent(), l = $(this).parent().next(), a.hide(), l.show(), i = !1; })), $('.close , #ep_profile_formModal_overlay , .ep_profile_formModal_topClose').click(() => ($('#ep_profile_formModal').removeClass('ep_profile_formModal_show'), e(), !1)), $('.previous').click((function () { if (i) return !1; i = !0, a = $(this).parent(), s = $(this).parent().prev(), a.hide(), s.show(), i = !1; })), $('.submit').click(() => (d(), !1)), $('.clear').click((function () { _.resetAllProfileImage($(this).attr('data-userId'), $(this).attr('data-padId')); })), $('#profile_file_modal').on('change', (e) => { const o = $('#profile_file_modal')[0].files[0]; const r = URL.createObjectURL(o); $('#profile_modal_selected_image').css({'background-position': '50% 50%', 'background-image': `url(${r})`, 'background-repeat': 'no-repeat', 'background-size': '64px'}); }); }}; })(); const a = {initiate(e) { const o = $('#ep_profile_users_profile_script').tmpl(e); $('body').append(o); }, initiateListeners() { $('#usersIconList').on('click', '.avatar', (function () { console.log('clicked'); const e = $(this).attr('data-userId'); const o = pad.getPadId(); $.ajax({url: `/static/${o}/pluginfw/ep_profile_modal/getUserInfo/${e}`, type: 'get', data: {}, contentType: !1, processData: !1, beforeSend() { $('#ep_profile_users_profile_userImage').css({'background-position': '50% 50%', 'background-image': 'url(../static/plugins/ep_profile_modal/static/img/loading.gif)', 'background-repeat': 'no-repeat', 'background-size': '69px', 'background-color': '#3873E0'}), $('#ep_profile_users_profile').removeClass('ep_profile_formModal_show'); }, error(e) {}, success(r) { console.log(r); const a = `/static/getUserProfileImage/${e}/${o}?t=${(new Date()).getTime()}`; let l = r.user.username; null != l && '' != l || (l = 'Anonymous'); const s = r.user.about || ''; const i = r.user.homepage || ''; $('#ep_profile_users_profile_name').text(l), $('#ep_profile_users_profile_desc').text(s), $('#ep_profile_users_profile_homepage').attr({href: _.getValidUrl(i), target: '_blank'}), $('#ep_profile_users_profile').addClass('ep_profile_formModal_show'), _.showGeneralOverlay(), $('#ep_profile_users_profile_userImage').css({'background-position': '50% 50%', 'background-image': `url(${a})`, 'background-repeat': 'no-repeat', 'background-size': '69px', 'background-color': '#3873E0'}); }}); })), $('#ep_profile_users_profile_close').on('click', () => { $('#ep_profile_users_profile').removeClass('ep_profile_formModal_show'), _.hideGeneralOverlay(); }); }}; const l = function (e, o) { return a.initiateListeners(), $('#ep_profile_modal_save').on('click', () => { const e = pad.getUserId(); const o = pad.getPadId(); const r = $('#ep_profile_modal-username'); const a = $('#ep_profile_modal-email'); const l = ($('#ep_profile_modal-about'), $('#ep_profile_modal-homepage')); if ('' == r.val()) return r.css({border: '1px solid red'}), !1; r.css({border: '0'}); const s = a.val(); if (!_.isEmail(s) || '' == s) return a.css({border: '1px solid red'}), !1; a.css({border: '0'}); const i = l.val(); if (console.log(_.IsValid(i)), !_.IsValid(i) || '' == i) return l.css({border: '1px solid red'}), !1; l.css({border: '0'}); const t = $('#ep_profile_modal_one'); const n = {type: 'ep_profile_modal', action: 'ep_profile_modal_info', userId: e, data: _.getFormData(t), padId: o}; pad.collabClient.sendMessage(n), pad.collabClient.updateUserInfo({userId: o, name: r.val(), colorId: '#b4b39a'}), 'login' == window.user_status && ($('#ep_profile_modal').hasClass('ep_profile_modal-show') ? ($('#ep_profile_modal').removeClass('ep_profile_modal-show'), _.hideGeneralOverlay()) : ($('#ep_profile_modal').addClass('ep_profile_modal-show'), $('#online_ep_profile_modal_status').show(), $('#offline_ep_profile_modal_status').hide(), _.showGeneralOverlay())); }), $('#userlist_count,#ep_profile_modal_user_list_close').on('click', () => { $('#ep_profile_modal_user_list').hasClass('ep_profile_modal-show') ? ($('#ep_profile_modal_user_list').removeClass('ep_profile_modal-show'), _.hideGeneralOverlay()) : (_.showGeneralOverlay(), $('#ep_profile_modal_user_list').addClass('ep_profile_modal-show')); }), $('#ep_profile_modal_verification').on('click', (function () { const e = $(this).attr('data-verification-status'); const o = $(this).text(); return 'true' != e && $.ajax({url: `/static/${pad.getPadId()}/pluginfw/ep_profile_modal/sendVerificationEmail/${pad.getUserId()}/null/null`, type: 'get', data: {}, contentType: !1, processData: !1, beforeSend() { $('#ep_profile_modal_verification').text('Sending...'); }, error(e) { $('#ep_profile_modal_verification').text('Error'), setTimeout(() => { $('#ep_profile_modal_verification').text(o); }, 2e3); }, success(e) { $('#ep_profile_modal_verification').text('Verification email has been sent.'), $('#ep_profile_modal_verification').attr('data-verification-status', 'true'); }}), !1; })), $('#ep_profile_modal_share').on('click', () => { const e = document.createElement('input'); const o = window.location.href; document.body.appendChild(e), e.value = o, e.select(), document.execCommand('copy'), document.body.removeChild(e), $.gritter.add({text: 'Link copied to clipboard'}); }), $('#ep-profile-button').on('click', () => { 'login' == window.user_status ? $('#ep_profile_modal').hasClass('ep_profile_modal-show') ? $('#ep_profile_modal').removeClass('ep_profile_modal-show') : ($('#ep_profile_modal').addClass('ep_profile_modal-show'), $('#online_ep_profile_modal_status').show(), $('#offline_ep_profile_modal_status').hide(), _.showGeneralOverlay()) : (r.resetModal(), r.showModal()); }), $('#ep_profile_modal_close').on('click', () => { $('#ep_profile_modal').hasClass('ep_profile_modal-show') ? ($('#ep_profile_modal').removeClass('ep_profile_modal-show'), _.hideGeneralOverlay()) : (_.showGeneralOverlay(), $('#ep_profile_modal').addClass('ep_profile_modal-show')); }), $('#ep_profile_modal_close_ask').on('click', () => { $('#ep_profile_modal_ask').hasClass('ep_profile_modal-show') ? $('#ep_profile_modal_ask').removeClass('ep_profile_modal-show') : $('#ep_profile_modal_ask').addClass('ep_profile_modal-show'); }), $('#ep_profile_modal_signout').on('click', () => { const e = pad.getUserId(); const o = pad.getPadId(); window.user_status = 'out'; const r = {type: 'ep_profile_modal', action: 'ep_profile_modal_logout', email: $('#ep_profile_hidden_email').val(), userId: e, padId: o}; pad.collabClient.sendMessage(r), $('#ep_profile_modal').removeClass('ep_profile_modal-show'), $('#online_ep_profile_modal_status').hide(), $('#offline_ep_profile_modal_status').show(), n.resetProfileModalFields(), _.hideGeneralOverlay(), $(`.avatar[data-id="user_${e}"]`).attr({style: ''}), t.userLogout(); }), $('#profile_file').on('change', (e) => { const o = pad.getUserId(); const r = new FormData(); const a = $('#profile_file')[0].files[0]; r.append('file', a), a && $.ajax({url: `/static/${clientVars.padId}/pluginfw/ep_profile_modal/upload/${o}`, type: 'post', data: r, contentType: !1, processData: !1, beforeSend() { t.refreshLoadingImage(o, clientVars.padId); }, error(e) { t.refreshUserImage(o, clientVars.padId); }, success(e) { t.refreshUserImage(o, clientVars.padId); }}); }), $('#ep_profile_modal_submit').on('click', () => { const e = $('#ep_profile_modal_username').val(); const o = $('#ep_profile_modal_email').val(); _.loginByEmailAndUsername(e, o); }), $('#ep_profile_modal_login').on('click', () => { const e = $('#ep_profile_modal-username').val(); const o = $('#ep_profile_modal-email').val(); _.loginByEmailAndUsername(e, o), $('#ep_profile_modal').removeClass('ep_profile_modal-show'); }), $('#ep_profile_general_overlay').on('click', () => { _.hideGeneralOverlay(); }), []; }; const s = (e, l) => { const s = pad.getUserId(); let i = $('#ep_profile_askmodal_script').tmpl(clientVars); r.initModal(clientVars), !0 !== clientVars.ep_profile_modal.form_passed && r.showModal(), a.initiate(clientVars), $('body').append(i), i = $('#ep_profile_modal_script').tmpl(clientVars), $('body').append(i), i = $('#ep_profile_modal_user_list_script').tmpl(clientVars), $('body').append(i), i = $('#ep_profile_modal_general_script').tmpl(clientVars), $('body').append(i); const t = `background : url(/static/getUserProfileImage/${s}/${clientVars.padId}) no-repeat 50% 50% ; background-size :32px`; const _ = pad.collabClient.getConnectedUsers(); const n = o.createHTMLforUserList(clientVars.ep_profile_modal.contributed_authors_count, _, clientVars.padId, clientVars.ep_profile_modal.verified_users); '2' == clientVars.ep_profile_modal.user_status ? (window.user_status = 'login', $('#pad_title').append(`<div class='ep_profile_modal_header'><div class='userlist' id='userlist'>${n}</div><div class='ep-profile-button' id='ep-profile-button'><div id='ep-profile-image' style='${t}' /></div></div>`)) : ($('#pad_title').append(`<div class='ep_profile_modal_header'><div class='userlist' id='userlist'>${n} </div><div class='ep-profile-button' id='ep-profile-button'><div id='ep-profile-image' style='${t}' /></div></div>`), window.user_status = 'out', 1 == clientVars.ep_profile_modal.form_passed && setTimeout(() => { r.showModal(); }, 1e3)); const p = {type: 'ep_profile_modal', action: 'ep_profile_modal_ready', userId: s, padId: pad.getPadId(), data: clientVars.ep_profile_modal}; return pad.collabClient.sendMessage(p), 'Anonymous' == clientVars.ep_profile_modal.userName && pad.collabClient.updateUserInfo({userId: s, name: 'Anonymous', colorId: '#b4b39a'}), []; }; const i = {handleClientMessage_USER_NEWINFO: (e, r) => { const a = pad.getPadId(); return o.increaseUserFromList(r.payload.userId, a), []; }, handleClientMessage_USER_LEAVE: (e, r) => { const a = pad.getPadId(); return o.decreaseUserFromList(r.payload.userId, a), []; }, handleClientMessage_CUSTOM: (e, r, a) => { const l = pad.getUserId(); if ('totalUserHasBeenChanged' == r.payload.action) { const e = r.payload.totalUserCount; $('#userlist_count').text(e); } if ('EP_PROFILE_MODAL_PROMPT_DATA' == r.payload.action) { var s = `/static/getUserProfileImage/${r.payload.userId}/${r.payload.padId}?t=${(new Date()).getTime()}`; $('#ep_profile_modal_homepage').val(r.payload.data.homepage), $('#ep_profile_modalForm_about_yourself').val(r.payload.data.about), $('#profile_modal_selected_image').css({'background-position': '50% 50%', 'background-image': `url(${s})`, 'background-repeat': 'no-repeat', 'background-size': '64px'}); } if ('EP_PROFILE_USERS_LIST' == r.payload.action) { const e = pad.collabClient.getConnectedUsers(); o.manageOnlineOfflineUsers(r.payload.list, e, pad.getUserId()); } if ('EP_PROFILE_USER_IMAGE_CHANGE' == r.payload.action && t.refreshGeneralImage(r.payload.userId, r.payload.padId), 'EP_PROFILE_USER_LOGOUT_UPDATE' == r.payload.action && (s = `/static/getUserProfileImage/${r.payload.userId}/${r.payload.padId}?t=${(new Date()).getTime()}`, l == r.payload.userId ? (t.refreshUserImage(l, r.payload.padId), t.logoutCssFix(l)) : t.refreshGeneralImage(r.payload.userId, r.payload.padId), n.resetGeneralFields(r.payload.userId), (i = o.isThereOnlineAnonymous()) ? o.increaseToOnlineAnonymous(i, r.payload.userId) : o.createOnlineAnonymousElement(r.payload.userId, 'Anonymous', s, {}), o.removeUserElementInUserList(r.payload.userId)), 'EP_PROFILE_MODAL_SEND_MESSAGE_TO_CHAT' == r.payload.action && _.addTextChatMessage(r.payload.msg), 'EP_PROFILE_USER_LOGIN_UPDATE' == r.payload.action) { var i = o.isThereOnlineAnonymous(); 'Anonymous' == r.payload.userName ? (i ? o.increaseToOnlineAnonymous(i, r.payload.userId) : o.createOnlineAnonymousElement(r.payload.userId, r.payload.userName, r.payload.img, r.payload.user), o.removeUserElementInUserList(r.payload.userId)) : (i && o.checkUserExistInOnlineAnonymous(i, r.payload.userId) && o.decreaseFromOnlineAnonymous(i, r.payload.userId), o.createOnlineUserElementInUserList(r.payload.userId, r.payload.userName, r.payload.img, l, r.payload.user)), l == r.payload.userId ? (t.refreshUserImage(l, r.payload.padId), n.syncAllFormsData(r.payload.userId, r.payload.user)) : (t.refreshGeneralImage(r.payload.userId, r.payload.padId), n.syncGeneralFormsData(r.payload.userId, r.payload.user)); } return []; }}; const t = {userLogin(e) { window.user_status = 'login', pad.collabClient.updateUserInfo({userId: pad.getUserId(), name: e.username, colorId: '#b4b39a'}); }, userLogout() { window.user_status = 'logout', pad.collabClient.updateUserInfo({userId: pad.getUserId(), name: 'Anonymous', colorId: '#b4b39a'}); }, logoutCssFix(e) { const o = $(`.avatarImg[data-id="user_${e}"]`); o.length && o.css({'margin': '0px', 'box-shadow': 'none'}); }, refreshUserImage(e, o) { const r = `/static/getUserProfileImage/${e}/${o}?t=${(new Date()).getTime()}`; const a = $(`.avatarImg[data-id="user_${e}"]`); a.length && a.css({'background-position': '50% 50%', 'background-image': `url(${r})`, 'background-repeat': 'no-repeat', 'background-size': '28px', 'background-color': '#fff'}), $('.ep_profile_modal_section_image_big_ask').css({'background-position': '50% 50%', 'background-image': `url(${r})`, 'background-repeat': 'no-repeat'}), $('.ep_profile_modal_section_image_big').css({'background-position': '50% 50%', 'background-image': `url(${r})`, 'background-repeat': 'no-repeat', 'background-size': '72px'}), $('#ep-profile-image').css({'background-position': '50% 50%', 'background-image': `url(${r})`, 'background-repeat': 'no-repeat', 'background-size': '32px'}); const l = $(`.ep_profile_user_row[data-id="user_list_${e}"]`); l.length && l.children('.ep_profile_user_img').css({'background-position': '50% 50%', 'background-image': `url(${r})`, 'background-repeat': 'no-repeat', 'background-size': '69px'}); }, refreshLoadingImage(e, o) { const r = '../static/plugins/ep_profile_modal/static/img/loading.gif'; const a = $(`.avatarImg[data-id="user_${e}"]`); a.length && a.css({'background-position': '50% 50%', 'background-image': `url(${r})`, 'background-repeat': 'no-repeat', 'background-size': '28px', 'background-color': '#fff'}), $('.ep_profile_modal_section_image_big_ask').css({'background-position': '50% 50%', 'background-image': `url(${r})`, 'background-repeat': 'no-repeat'}), $('.ep_profile_modal_section_image_big').css({'background-position': '50% 50%', 'background-image': `url(${r})`, 'background-repeat': 'no-repeat', 'background-size': '72px'}), $('#ep-profile-image').css({'background-position': '50% 50%', 'background-image': `url(${r})`, 'background-repeat': 'no-repeat', 'background-size': '32px'}); const l = $(`.ep_profile_user_row[data-id="user_list_${e}"]`); l.length && l.children('.ep_profile_user_img').css({'background-position': '50% 50%', 'background-image': `url(${r})`, 'background-repeat': 'no-repeat', 'background-size': '69px'}); }, refreshGeneralImage(e, o) { const r = `/static/getUserProfileImage/${e}/${o}?t=${(new Date()).getTime()}`; const a = $(`.avatarImg[data-id="user_${e}"]`); a.length && a.css({'background-position': '50% 50%', 'background-image': `url(${r})`, 'background-repeat': 'no-repeat', 'background-size': '28px', 'background-color': '#fff'}); const l = $(`.ep_profile_user_row[data-id="user_list_${e}"]`); l.length && l.children('.ep_profile_user_img').css({'background-position': '50% 50%', 'background-image': `url(${r})`, 'background-repeat': 'no-repeat', 'background-size': '69px'}); }}; const _ = (() => { const e = function (e) { const o = $(e); if (o.length <= 0 || !o[0]) return !0; o.animate({scrollTop: o[0].scrollHeight}, {duration: 400, queue: !1}); }; const o = function (e) { return '' == e || /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(e); }; const r = function (e) { return ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][e - 1]; }; return {resetAllProfileImage(e, o) { $.ajax({url: `/static/${o}/pluginfw/ep_profile_modal/resetProfileImage/${e}`, type: 'get', data: {}, contentType: !1, processData: !1, beforeSend() { t.refreshLoadingImage(e, o); }, error(r) { t.refreshUserImage(e, o); }, success(r) { t.refreshUserImage(e, o); }}); }, sendSignOutMessage(e, o) { const r = {type: 'ep_profile_modal', action: 'ep_profile_modal_send_signout_message', userId: e, padId: o}; pad.collabClient.sendMessage(r); }, addTextChatMessage(o) { const r = `author-${o.userId.replace(/[^a-y0-9]/g, (e) => '.' === e ? '-' : `z${e.charCodeAt(0)}z`)}`; let a = `${new Date(o.time).getMinutes()}`; let l = `${new Date(o.time).getHours()}`; 1 === a.length && (a = `0${a}`), 1 === l.length && (l = `0${l}`); const s = `<p><span class='time ${r}'>${`${l}:${a}`}</span> ${o.text}</p>`; $(document).find('#chatbox #chattext').append(s), e('#chatbox #chattext'); }, scrollDownToLastChatText: e, loginByEmailAndUsernameWithoutValidation(e, o, r) { window.user_status = 'login'; const a = {type: 'ep_profile_modal', action: 'ep_profile_modal_login', email: o, userId: pad.getUserId(), name: e, padId: pad.getPadId(), suggestData: r}; pad.collabClient.sendMessage(a); }, loginByEmailAndUsername(e, r) { if ('' == e || !o(r)) return o(r) || ($('#ep_profile_modal_email').focus(), $('#ep_profile_modal_email').addClass('ep_profile_modal_validation_error')), !1; { $('#ep_profile_modal_email').removeClass('ep_profile_modal_validation_error'), window.user_status = 'login'; const o = {type: 'ep_profile_modal', action: 'ep_profile_modal_login', email: r, userId: pad.getUserId(), name: e, padId: pad.getPadId(), suggestData: !1}; pad.collabClient.sendMessage(o), t.userLogin({email: r, username: e}), $('#online_ep_profile_modal_status').show(), $('#offline_ep_profile_modal_status').hide(); } }, isEmail: o, IsValid(e) { return /^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/.test(e); }, getFormData(e) { const o = e.serializeArray(); const r = {}; return $.map(o, (e, o) => { r[e.name] = e.value; }), r; }, setFormData(e, o) { $.map(o, (e, o) => { $(`#${o}`).val(e); }); }, isUsername(e) { return /^([a-zA-Z0-9_.+-])/.test(e); }, showGeneralOverlay() { $('#ep_profile_general_overlay').addClass('ep_profile_formModal_overlay_show'), $('#ep_profile_general_overlay').css({display: 'block'}); }, hideGeneralOverlay() { $('#ep_profile_general_overlay').removeClass('ep_profile_formModal_overlay_show'), $('#ep_profile_general_overlay').css({display: 'none'}), $('#ep_profile_modal').removeClass('ep_profile_modal-show'), $('#ep_profile_modal_user_list').removeClass('ep_profile_modal-show'), $('#ep_profile_users_profile').removeClass('ep_profile_formModal_show'); }, getValidUrl(e) { if ('' == e || !e) return ''; let o = window.decodeURIComponent(e); return o = o.trim().replace(/\s/g, ''), /^(:\/\/)/.test(o) ? `http${o}` : /^(f|ht)tps?:\/\//i.test(o) ? o : `http://${o}`; }, getMonthName: r, getCustomeFormatDate(e) { return 'today' == e || 'yesterday' == e ? `Last seen ${e}` : `Last seen ${(e = e.split('-'))[2]} ${r(e[1])} ${e[0]}`; }, getCustomDate(e) { return 'today' == e || 'yesterday' == e ? `Last seen ${e}` : `Last seen ${(e = e.split('-'))[2]}/${e[1]}/${e[0]}`; }}; })(); const n = {syncAllFormsData(e, o) { const r = $(`.ep_profile_user_row[data-id="user_list_${e}"]`); if (r.length) { const e = r.children('.ep_profile_user_list_profile_userDesc').children('.ep_profile_user_list_username'); e.children('.ep_profile_user_list_username_text').text(o.username), r.children('.ep_profile_user_list_profile_userDesc').children('.ep_profile_user_list_profile_desc').text(o.about), o.homepage && e.children('.ep_profile_contributor_link_container').attr({href: _.getValidUrl(o.homepage)}), e.children('.ep_profile_contributor_status').text('Online'); }$('#ep_profile_modal-username').val(o.username), $('#ep_profile_modal-about').val(o.about), $('#ep_profile_modal-homepage').val(o.homepage), $('#ep_profile_modal-email').val(o.email), 1 == o.verified ? ($('#ep_profile_modal_verification').attr('data-verification-status', 'true'), $('#ep_profile_modal_verification').text('Verified')) : ($('#ep_profile_modal_verification').attr('data-verification-status', 'false'), $('#ep_profile_modal_verification').text('Send verification email')); }, syncGeneralFormsData(e, o) { const r = $(`.ep_profile_user_row[data-id="user_list_${e}"]`); if (r.length) { const e = r.children('.ep_profile_user_list_profile_userDesc').children('.ep_profile_user_list_username'); e.children('.ep_profile_user_list_username_text').text(o.username), r.children('.ep_profile_user_list_profile_userDesc').children('.ep_profile_user_list_profile_desc').text(o.about), e.children('.ep_profile_contributor_link_container').attr({href: _.getValidUrl(o.homepage)}), e.children('.ep_profile_contributor_status').text('Online'); } }, resetProfileModalFields() { $('#ep_profile_modal-username').val(''), $('#ep_profile_modal-about').val(''), $('#ep_profile_modal-homepage').val(''), $('#ep_profile_modal-email').val(''), $('#ep_profile_modalForm_name').val(''), $('#ep_profile_modalForm_email').val(''), $('#ep_profile_modal_homepage').val(''), $('#ep_profile_modalForm_about_yourself').val(''); }, resetGeneralFields(e) { const o = $(`.ep_profile_user_row[data-id="user_list_${e}"]`); if (o.length) { const e = o.children('.ep_profile_user_list_profile_userDesc').children('.ep_profile_user_list_username'); e.children('.ep_profile_user_list_username_text').text(''), o.children('.ep_profile_user_list_profile_userDesc').children('.ep_profile_user_list_profile_desc').text(''), e.children('.ep_profile_contributor_link_container').attr({href: ''}), e.children('.ep_profile_contributor_status').text(''); } }}; return {documentReady: e, contributors: o, profileForm: r, usersProfileSection: a, postAceInit: l, aceInitialized: s, handleClientMessage: i, helper: t, shared: _, syncData: n}; })();
// # sourceMappingURL=ep.profile.modal.mini.js.map