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
496b070d
Commit
496b070d
authored
Sep 01, 2020
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
If adding .png fallback fails, revert to original URL
parent
ac31d41c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
8 deletions
+17
-8
docs/source/configuration.rst
docs/source/configuration.rst
+1
-1
src/templates/directives/image.js
src/templates/directives/image.js
+15
-6
src/templates/image.js
src/templates/image.js
+1
-1
No files found.
docs/source/configuration.rst
View file @
496b070d
...
...
@@ -850,7 +850,7 @@ If you are using prebinding, can specify the fullname of the currently
logged in user, otherwise the user's vCard will be fetched.
geouri_regex
------------
----
------------
* Default: ``/https:\/\/www.openstreetmap.org\/.*#map=[0-9]+\/([\-0-9.]+)\/([\-0-9.]+)\S*/g``
...
...
src/templates/directives/image.js
View file @
496b070d
...
...
@@ -2,25 +2,34 @@ import { converse } from "@converse/headless/converse-core";
import
{
directive
,
html
}
from
"
lit-html
"
;
export
const
renderImage
=
directive
((
url
,
onLoad
,
onClick
)
=>
part
=>
{
/**
* lit-html directive which attempts to render an <img> element from a URL.
* It will fall back to rendering an <a> element if it can't.
*
* @param { String } src - The value that will be assigned to the `src` attribute of the `<img>` element.
* @param { String } href - The value that will be assigned to the `href` attribute of the `<img>` element.
* @param { Function } onLoad - A callback function to be called once the image has loaded.
* @param { Function } onClick - A callback function to be called once the image has been clicked.
*/
export
const
renderImage
=
directive
((
src
,
href
,
onLoad
,
onClick
)
=>
part
=>
{
function
onError
()
{
const
u
=
converse
.
env
.
utils
;
if
(
u
.
isURLWithImageExtension
(
url
))
{
part
.
setValue
(
u
.
convertUrlToHyperlink
(
url
));
if
(
u
.
isURLWithImageExtension
(
src
))
{
part
.
setValue
(
u
.
convertUrlToHyperlink
(
href
));
part
.
commit
();
}
else
{
// Before giving up and falling back to just rendering a hyperlink,
// we attach `.png` and try one more time.
// This works with some Imgur URLs
part
.
setValue
(
renderImage
(
`
${
url
}
.png`
,
onLoad
,
onClick
));
part
.
setValue
(
renderImage
(
`
${
src
}
.png`
,
href
,
onLoad
,
onClick
));
part
.
commit
();
}
}
part
.
setValue
(
html
`<a href="
${
url
}
"
html
`<a href="
${
href
}
"
class="chat-image__link"
target="_blank"
rel="noopener"
><img class="chat-image img-thumbnail" src="
${
url
}
" @click=
${
onClick
}
@error=
${
onError
}
@load=
${
onLoad
}
/></a>`
><img class="chat-image img-thumbnail" src="
${
src
}
" @click=
${
onClick
}
@error=
${
onError
}
@load=
${
onLoad
}
/></a>`
);
});
src/templates/image.js
View file @
496b070d
import
{
html
}
from
"
lit-html
"
;
import
{
renderImage
}
from
"
./directives/image.js
"
;
export
default
(
o
)
=>
html
`
${
renderImage
(
o
.
url
,
o
.
onLoad
,
o
.
onClick
)}
`
;
export
default
(
o
)
=>
html
`
${
renderImage
(
o
.
url
,
o
.
url
,
o
.
onLoad
,
o
.
onClick
)}
`
;
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