From 420c754ca300d6f089adc9f22d34a8acb00a571e Mon Sep 17 00:00:00 2001 From: Florian Orben Date: Mon, 19 Oct 2015 21:15:10 +0200 Subject: Horizontally align images if image height > image width --- web/react/components/file_attachment.jsx | 18 +++++++++++++++--- web/sass-files/sass/partials/_files.scss | 1 + 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'web') 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 = (
this.playGif(e, fileUrl)} + onClick={(e) => this.playGif(e, filename)} > {"►"}
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; } -- cgit v1.2.3-1-g7c22