summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Orben <florian.orben@gmail.com>2015-10-19 21:15:10 +0200
committerFlorian Orben <florian.orben@gmail.com>2015-10-21 18:13:59 +0200
commit420c754ca300d6f089adc9f22d34a8acb00a571e (patch)
tree821dc68d4c82d5b3d989e6e65f5b5500e87c3bc1
parentd167e18f0048344c54685a08c19113a84a995ed9 (diff)
downloadchat-420c754ca300d6f089adc9f22d34a8acb00a571e.tar.gz
chat-420c754ca300d6f089adc9f22d34a8acb00a571e.tar.bz2
chat-420c754ca300d6f089adc9f22d34a8acb00a571e.zip
Horizontally align images if image height > image width
-rw-r--r--web/react/components/file_attachment.jsx18
-rw-r--r--web/sass-files/sass/partials/_files.scss1
2 files changed, 16 insertions, 3 deletions
diff --git a/web/react/components/file_attachment.jsx b/web/react/components/file_attachment.jsx
index 817834334..afd4e32fe 100644
--- a/web/react/components/file_attachment.jsx
+++ b/web/react/components/file_attachment.jsx
@@ -94,16 +94,28 @@ export default class FileAttachment extends React.Component {
return true;
}
- playGif(e, fileUrl) {
+ playGif(e, filename) {
var img = new Image();
+ var fileUrl = utils.getFileUrl(filename);
this.setState({loading: true});
img.load(fileUrl);
- img.onload = () => this.setState({playing: true, loading: false});
+ img.onload = () => {
+ this.setState({playing: true, loading: false});
+
+ // keep displaying background image for a short moment while browser is
+ // loading gif, to prevent white background flashing through
+ setTimeout(() => this.removeBackgroundImage.bind(this)(filename), 100);
+ };
img.onError = () => this.setState({loading: false});
e.stopPropagation();
}
+ removeBackgroundImage(name) {
+ if (name in this.refs) {
+ $(ReactDOM.findDOMNode(this.refs[name])).css('background-image', 'initial');
+ }
+ }
render() {
var filename = this.props.filename;
@@ -118,7 +130,7 @@ export default class FileAttachment extends React.Component {
playButton = (
<div
className='file-play-button'
- onClick={(e) => this.playGif(e, fileUrl)}
+ onClick={(e) => this.playGif(e, filename)}
>
{"►"}
</div>
diff --git a/web/sass-files/sass/partials/_files.scss b/web/sass-files/sass/partials/_files.scss
index 1d7754445..cb9ff6862 100644
--- a/web/sass-files/sass/partials/_files.scss
+++ b/web/sass-files/sass/partials/_files.scss
@@ -135,6 +135,7 @@
background-repeat: no-repeat;
overflow: hidden;
position: relative;
+ text-align: center;
&.small {
background-position: center;
}