2018-01-05 01:21:38 +03:00
|
|
|
/*
|
2018-01-05 01:51:49 +03:00
|
|
|
Copyright 2018 New Vector Ltd
|
2018-01-05 01:21:38 +03:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2018-03-08 15:31:01 +03:00
|
|
|
import MImageBody from './MImageBody';
|
2018-02-28 02:07:59 +03:00
|
|
|
import sdk from '../../../index';
|
2018-03-08 15:31:01 +03:00
|
|
|
import TintableSVG from '../elements/TintableSvg';
|
2018-01-05 01:21:38 +03:00
|
|
|
|
2018-02-26 17:01:33 +03:00
|
|
|
export default class MStickerBody extends MImageBody {
|
|
|
|
displayName: 'MStickerBody'
|
2018-01-05 01:21:38 +03:00
|
|
|
|
2018-02-26 17:01:33 +03:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2018-02-28 02:07:59 +03:00
|
|
|
|
|
|
|
this._onMouseEnter = this._onMouseEnter.bind(this);
|
|
|
|
this._onMouseLeave = this._onMouseLeave.bind(this);
|
2018-03-08 15:31:01 +03:00
|
|
|
this._onImageLoad = this._onImageLoad.bind(this);
|
2018-02-28 02:07:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
_onMouseEnter() {
|
|
|
|
this.setState({showTooltip: true});
|
|
|
|
}
|
|
|
|
|
|
|
|
_onMouseLeave() {
|
|
|
|
this.setState({showTooltip: false});
|
2018-02-26 17:01:33 +03:00
|
|
|
}
|
2018-01-05 01:21:38 +03:00
|
|
|
|
2018-03-08 15:31:01 +03:00
|
|
|
_onImageLoad() {
|
2018-05-08 11:49:53 +03:00
|
|
|
this.fixupHeight();
|
2018-03-08 15:31:01 +03:00
|
|
|
this.setState({
|
|
|
|
placeholderClasses: 'mx_MStickerBody_placeholder_invisible',
|
|
|
|
});
|
2018-03-10 00:12:56 +03:00
|
|
|
const hidePlaceholderTimer = setTimeout(() => {
|
2018-03-08 15:31:01 +03:00
|
|
|
this.setState({
|
|
|
|
placeholderVisible: false,
|
2018-03-14 14:11:21 +03:00
|
|
|
imageClasses: 'mx_MStickerBody_image_visible',
|
2018-03-08 15:31:01 +03:00
|
|
|
});
|
|
|
|
}, 500);
|
2018-03-10 00:12:56 +03:00
|
|
|
this.setState({hidePlaceholderTimer});
|
2018-03-29 19:08:07 +03:00
|
|
|
if (this.props.onWidgetLoad) {
|
|
|
|
this.props.onWidgetLoad();
|
|
|
|
}
|
2018-03-08 15:31:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
_afterComponentDidMount() {
|
|
|
|
if (this.refs.image.complete) {
|
|
|
|
// Image already loaded
|
|
|
|
this.setState({
|
|
|
|
placeholderVisible: false,
|
|
|
|
placeholderClasses: '.mx_MStickerBody_placeholder_invisible',
|
2018-03-14 14:11:21 +03:00
|
|
|
imageClasses: 'mx_MStickerBody_image_visible',
|
2018-03-08 15:31:01 +03:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// Image not already loaded
|
|
|
|
this.setState({
|
|
|
|
placeholderVisible: true,
|
|
|
|
placeholderClasses: '',
|
2018-03-14 14:11:21 +03:00
|
|
|
imageClasses: '',
|
2018-03-08 15:31:01 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-10 00:12:56 +03:00
|
|
|
_afterComponentWillUnmount() {
|
|
|
|
if (this.state.hidePlaceholderTimer) {
|
|
|
|
clearTimeout(this.state.hidePlaceholderTimer);
|
|
|
|
this.setState({hidePlaceholderTimer: null});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-26 17:01:33 +03:00
|
|
|
_messageContent(contentUrl, thumbUrl, content) {
|
2018-02-28 02:07:59 +03:00
|
|
|
let tooltip;
|
|
|
|
const tooltipBody = (
|
|
|
|
this.props.mxEvent &&
|
|
|
|
this.props.mxEvent.getContent() &&
|
|
|
|
this.props.mxEvent.getContent().body) ?
|
|
|
|
this.props.mxEvent.getContent().body : null;
|
|
|
|
if (this.state.showTooltip && tooltipBody) {
|
2018-03-08 15:31:01 +03:00
|
|
|
const RoomTooltip = sdk.getComponent('rooms.RoomTooltip');
|
2018-02-28 02:07:59 +03:00
|
|
|
tooltip = <RoomTooltip
|
2018-03-08 15:31:01 +03:00
|
|
|
className='mx_RoleButton_tooltip'
|
2018-02-28 16:43:19 +03:00
|
|
|
label={tooltipBody} />;
|
2018-02-28 02:07:59 +03:00
|
|
|
}
|
|
|
|
|
2018-03-08 15:31:01 +03:00
|
|
|
const gutterSize = 0;
|
|
|
|
let placeholderSize = 75;
|
|
|
|
let placeholderFixupHeight = '100px';
|
|
|
|
let placeholderTop = 0;
|
|
|
|
let placeholderLeft = 0;
|
|
|
|
|
|
|
|
if (content.info) {
|
|
|
|
placeholderTop = Math.floor((content.info.h/2) - (placeholderSize/2)) + 'px';
|
|
|
|
placeholderLeft = Math.floor((content.info.w/2) - (placeholderSize/2) + gutterSize) + 'px';
|
|
|
|
placeholderFixupHeight = content.info.h + 'px';
|
|
|
|
}
|
|
|
|
|
|
|
|
placeholderSize = placeholderSize + 'px';
|
|
|
|
|
2018-03-29 23:16:12 +03:00
|
|
|
// Body 'ref' required by MImageBody
|
2018-01-05 01:21:38 +03:00
|
|
|
return (
|
2018-03-29 23:16:12 +03:00
|
|
|
<span className='mx_MStickerBody' ref='body'
|
2018-03-08 15:31:01 +03:00
|
|
|
style={{
|
|
|
|
height: placeholderFixupHeight,
|
|
|
|
}}>
|
2018-03-14 14:11:21 +03:00
|
|
|
<div className={'mx_MStickerBody_image_container'}>
|
2018-03-09 02:12:12 +03:00
|
|
|
{ this.state.placeholderVisible &&
|
2018-03-08 15:31:01 +03:00
|
|
|
<div
|
|
|
|
className={'mx_MStickerBody_placeholder ' + this.state.placeholderClasses}
|
|
|
|
style={{
|
|
|
|
top: placeholderTop,
|
|
|
|
left: placeholderLeft,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<TintableSVG
|
|
|
|
src={'img/icons-show-stickers.svg'}
|
|
|
|
width={placeholderSize}
|
|
|
|
height={placeholderSize} />
|
2018-03-09 02:12:12 +03:00
|
|
|
</div> }
|
2018-03-08 15:31:01 +03:00
|
|
|
<img
|
2018-03-14 14:11:21 +03:00
|
|
|
className={'mx_MStickerBody_image ' + this.state.imageClasses}
|
|
|
|
src={contentUrl}
|
2018-03-08 15:31:01 +03:00
|
|
|
ref='image'
|
2018-03-06 13:48:32 +03:00
|
|
|
alt={content.body}
|
2018-03-08 15:31:01 +03:00
|
|
|
onLoad={this._onImageLoad}
|
2018-03-06 13:48:32 +03:00
|
|
|
onMouseEnter={this._onMouseEnter}
|
|
|
|
onMouseLeave={this._onMouseLeave}
|
|
|
|
/>
|
|
|
|
{ tooltip }
|
|
|
|
</div>
|
2018-02-26 17:01:33 +03:00
|
|
|
</span>
|
2018-01-05 01:21:38 +03:00
|
|
|
);
|
2018-02-26 17:01:33 +03:00
|
|
|
}
|
2018-01-05 01:21:38 +03:00
|
|
|
|
2018-03-29 19:09:03 +03:00
|
|
|
// Empty to prevent default behaviour of MImageBody
|
2018-02-26 17:01:33 +03:00
|
|
|
onClick() {
|
|
|
|
}
|
|
|
|
}
|