Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
904a1394
Commit
904a1394
authored
Sep 26, 2020
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Always render avatar via lit-html
Fixes #2244 by checking if image already is in the `data:` format.
parent
5dac2d88
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
22 additions
and
32 deletions
+22
-32
src/converse-chatboxviews.js
src/converse-chatboxviews.js
+4
-5
src/templates/avatar.js
src/templates/avatar.js
+7
-2
src/templates/avatar.svg
src/templates/avatar.svg
+0
-3
src/templates/directives/avatar.js
src/templates/directives/avatar.js
+4
-19
src/utils/html.js
src/utils/html.js
+7
-3
No files found.
src/converse-chatboxviews.js
View file @
904a1394
...
...
@@ -5,7 +5,7 @@
*/
import
'
./components/converse.js
'
;
import
"
@converse/headless/converse-chatboxes
"
;
import
tpl_avatar
from
"
templates/avatar.
svg
"
;
import
tpl_avatar
from
"
templates/avatar.
js
"
;
import
tpl_background_logo
from
"
templates/background_logo.js
"
;
import
tpl_converse
from
"
templates/converse.js
"
;
import
{
Overview
}
from
"
@converse/skeletor/src/overview
"
;
...
...
@@ -30,11 +30,10 @@ const AvatarMixin = {
'
classes
'
:
avatar_el
.
getAttribute
(
'
class
'
),
'
width
'
:
avatar_el
.
getAttribute
(
'
width
'
),
'
height
'
:
avatar_el
.
getAttribute
(
'
height
'
),
'
image_type
'
:
this
.
model
.
vcard
.
get
(
'
image_type
'
),
'
image
'
:
this
.
model
.
vcard
.
get
(
'
image
'
)
}
const
image_type
=
this
.
model
.
vcard
.
get
(
'
image_type
'
);
const
image
=
this
.
model
.
vcard
.
get
(
'
image
'
);
data
[
'
image
'
]
=
"
data:
"
+
image_type
+
"
;base64,
"
+
image
;
avatar_el
.
outerHTML
=
tpl_avatar
(
data
);
avatar_el
.
outerHTML
=
u
.
getElementFromTemplateResult
(
tpl_avatar
(
data
)).
outerHTML
;
}
},
};
...
...
src/templates/avatar.js
View file @
904a1394
import
{
html
}
from
"
lit-html
"
;
const
getImgHref
=
(
image
,
image_type
)
=>
{
return
image
.
startsWith
(
'
data:
'
)
?
image
:
`data:
${
image_type
}
;base64,
${
image
}
`
;
}
export
default
(
o
)
=>
html
`
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" class="
${
o
.
classes
}
" width="
${
o
.
width
}
" height="
${
o
.
height
}
">
<image width="
${
o
.
width
}
" height="
${
o
.
height
}
" preserveAspectRatio="xMidYMid meet" href="
data:
${
o
.
image_type
}
;base64,
${
o
.
image
}
"/>
<svg xmlns="http://www.w3.org/2000/svg"
class="avatar
${
o
.
classes
}
" width="
${
o
.
width
}
" height="
${
o
.
height
}
">
<image width="
${
o
.
width
}
" height="
${
o
.
height
}
" preserveAspectRatio="xMidYMid meet" href="
${
getImgHref
(
o
.
image
,
o
.
image_type
)
}
"/>
</svg>`
;
src/templates/avatar.svg
deleted
100644 → 0
View file @
5dac2d88
<svg
xmlns=
"http://www.w3.org/2000/svg"
xmlns:xlink=
"http://www.w3.org/1999/xlink"
class=
"{{{o.classes}}}"
width=
"{{{o.width}}}"
height=
"{{{o.height}}}"
>
<image
width=
"{{{o.width}}}"
height=
"{{{o.height}}}"
preserveAspectRatio=
"xMidYMid meet"
href=
"{{{o.image}}}"
/>
</svg>
src/templates/directives/avatar.js
View file @
904a1394
import
xss
from
"
xss/dist/xss
"
;
import
{
directive
,
html
}
from
"
lit-html
"
;
import
{
unsafeSVG
}
from
'
lit-html/directives/unsafe-svg.js
'
;
const
whitelist_opts
=
{
'
whiteList
'
:
{
'
svg
'
:
[
'
xmlns
'
,
'
class
'
,
'
width
'
,
'
height
'
],
'
image
'
:
[
'
width
'
,
'
height
'
,
'
preserveAspectRatio
'
,
'
href
'
]
}
};
const
tpl_svg
=
(
o
)
=>
xss
.
filterXSS
(
`<image width="
${
o
.
width
}
" height="
${
o
.
height
}
" preserveAspectRatio="xMidYMid meet" href="
${
o
.
image
}
"/>`
,
whitelist_opts
);
const
tpl_avatar
=
(
o
)
=>
html
`
<svg xmlns="http://www.w3.org/2000/svg" class="avatar
${
o
.
classes
}
" width="
${
o
.
width
}
" height="
${
o
.
height
}
">
${
unsafeSVG
(
tpl_svg
(
o
))
}
</svg>
`
;
import
tpl_avatar
from
'
../avatar.js
'
;
import
{
directive
}
from
"
lit-html
"
;
export
const
renderAvatar
=
directive
(
o
=>
part
=>
{
const
data
=
{
'
classes
'
:
o
.
classes
||
'
'
,
'
classes
'
:
o
.
classes
?
`
${
o
.
classes
}
avatar`
:
'
avatar
'
,
'
height
'
:
o
.
width
||
36
,
'
image
'
:
o
.
image
,
'
image_type
'
:
o
.
image_type
,
'
width
'
:
o
.
height
||
36
,
}
part
.
setValue
(
tpl_avatar
(
data
));
...
...
src/utils/html.js
View file @
904a1394
...
...
@@ -177,10 +177,14 @@ u.applyDragResistance = function (value, default_value) {
};
/**
* Return the height of the passed in DOM element,
* based on the heights of its children.
* @method u#calculateElementHeight
* @param {HTMLElement} el
* @returns {integer}
*/
u
.
calculateElementHeight
=
function
(
el
)
{
/* Return the height of the passed in DOM element,
* based on the heights of its children.
*/
return
Array
.
from
(
el
.
children
).
reduce
((
result
,
child
)
=>
result
+
child
.
offsetHeight
,
0
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment