[ticket/13713] Move mentions avatar template HTML to html file

PHPBB3-13713
This commit is contained in:
Marc Alexander 2021-05-18 17:13:58 +02:00
parent 5c2ada19c8
commit 51097d937a
No known key found for this signature in database
GPG key ID: 50E0D2423696F995
4 changed files with 24 additions and 7 deletions

View file

@ -8,6 +8,8 @@
// ]]>
</script>
{% include 'mentions_templates.html' %}
<!-- INCLUDEJS {T_ASSETS_PATH}/javascript/editor.js -->
<!-- INCLUDEJS {T_ASSETS_PATH}/javascript/tribute.min.js -->
<!-- INCLUDEJS {T_ASSETS_PATH}/javascript/mentions.js -->

View file

@ -24,6 +24,7 @@
const mentionNamesLimit = $mentionDataContainer.data('mentionNamesLimit');
const mentionTopicId = $mentionDataContainer.data('topicId');
const mentionUserId = $mentionDataContainer.data('userId');
const $mentionAvatarTemplate = $('[data-id="mentions-avatar-span"]');
let queryInProgress = null;
const cachedNames = [];
const cachedAll = [];
@ -51,15 +52,26 @@
* @return {string} Avatar HTML
*/
function getAvatar(data, type) {
const avatarToHtml = avatarData => {
if (avatarData.html === '') {
return '<img class="avatar" src="' + avatarData.src + '" width="' + avatarData.width + '" height="' + avatarData.height + '" alt="' + avatarData.title + '" />';
}
if (data.html === '' && data.src === '') {
return defaultAvatar(type);
}
return avatarData.html;
};
const $avatarSpan = $mentionAvatarTemplate.clone();
$avatarSpan.removeAttr('style'); // Remove automatically added display: none
return data.html === '' && data.src === '' ? defaultAvatar(type) : '<span class=\'mention-media-avatar\'>' + avatarToHtml(data) + '</span>';
if (data.html === '') {
const $avatarImg = $avatarSpan.find('img');
$avatarImg.attr({
src: data.src,
width: data.width,
height: data.height,
alt: data.title,
});
} else {
$avatarSpan.html(data.html);
}
return $avatarSpan.get(0).outerHTML;
}
/**

View file

@ -0,0 +1 @@
<template data-id="mentions-avatar-span"><span class="mention-media-avatar"><img class="avatar" src="" width="" height="" alt="" /></span></template>

View file

@ -26,6 +26,8 @@
}
</script>
{% include 'mentions_templates.html' %}
<!-- INCLUDEJS {T_ASSETS_PATH}/javascript/editor.js -->
<!-- INCLUDEJS {T_ASSETS_PATH}/javascript/tribute.min.js -->
<!-- INCLUDEJS {T_ASSETS_PATH}/javascript/mentions.js -->