2016-05-31 06:07:02 +08:00
|
|
|
import React, { PropTypes } from 'react';
|
2017-02-23 08:10:30 +08:00
|
|
|
import ShapeGroupContainer from '../whiteboard/shape-group/container.jsx';
|
2016-07-16 04:45:54 +08:00
|
|
|
import Cursor from './cursor/component.jsx';
|
2017-02-24 04:20:21 +08:00
|
|
|
import PresentationToolbarContainer from './presentation-toolbar/container.jsx';
|
2016-05-31 06:07:02 +08:00
|
|
|
import Slide from './slide/component.jsx';
|
|
|
|
import styles from './styles.scss';
|
|
|
|
import ReactCSSTransitionGroup from 'react-addons-css-transition-group';
|
2016-07-08 01:08:26 +08:00
|
|
|
import PollingContainer from '/imports/ui/components/polling/container';
|
2017-02-24 08:11:27 +08:00
|
|
|
import PresentationOverlayContainer from './presentation-overlay/container';
|
2017-03-01 02:35:56 +08:00
|
|
|
import WhiteboardOverlayContainer from '/imports/ui/components/whiteboard/whiteboard-overlay/component';
|
2016-05-31 06:07:02 +08:00
|
|
|
|
2017-02-17 05:11:46 +08:00
|
|
|
export default class PresentationArea extends React.Component {
|
2016-05-31 06:07:02 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2017-03-24 05:52:36 +08:00
|
|
|
this.state = {
|
|
|
|
paperWidth: 0,
|
|
|
|
paperHeight: 0,
|
|
|
|
showSlide: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
window.removeEventListener('resize', this.handleResize);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
var fn = setTimeout(this.handleResize.bind(this), 0);
|
|
|
|
window.addEventListener('resize', () => {
|
|
|
|
setTimeout(this.handleResize.bind(this), 0);
|
|
|
|
});
|
|
|
|
this.setState({
|
|
|
|
paperHeight: this.refs.presentationPaper.parentNode.clientHeight,
|
|
|
|
paperWidth: this.refs.presentationPaper.parentNode.clientWidth,
|
|
|
|
showSlide: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
calculateSize() {
|
|
|
|
let originalWidth;
|
|
|
|
let originalHeight;
|
|
|
|
let adjustedWidth;
|
|
|
|
let adjustedHeight;
|
|
|
|
|
|
|
|
originalWidth = this.props.currentSlide.slide.width;
|
|
|
|
originalHeight = this.props.currentSlide.slide.height;
|
|
|
|
|
|
|
|
//Slide has a portrait orientation
|
|
|
|
if (originalWidth <= originalHeight) {
|
|
|
|
adjustedWidth = this.state.paperHeight * originalWidth / originalHeight;
|
|
|
|
if (this.state.paperWidth < adjustedWidth) {
|
|
|
|
adjustedHeight = this.state.paperHeight * this.state.paperWidth / adjustedWidth;
|
|
|
|
adjustedWidth = this.state.paperWidth;
|
|
|
|
} else {
|
|
|
|
adjustedHeight = this.state.paperHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Slide has a landscape orientation
|
|
|
|
} else {
|
|
|
|
adjustedHeight = this.state.paperWidth * originalHeight / originalWidth;
|
|
|
|
if (this.state.paperHeight < adjustedHeight) {
|
|
|
|
adjustedWidth = this.state.paperWidth * this.state.paperHeight / adjustedHeight;
|
|
|
|
adjustedHeight = this.state.paperHeight;
|
|
|
|
} else {
|
|
|
|
adjustedWidth = this.state.paperWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
width: adjustedWidth,
|
|
|
|
height: adjustedHeight,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
handleResize() {
|
|
|
|
this.setState({
|
|
|
|
paperHeight: this.refs.presentationPaper.clientHeight,
|
|
|
|
paperWidth: this.refs.presentationPaper.clientWidth,
|
|
|
|
});
|
2016-06-02 07:37:51 +08:00
|
|
|
}
|
|
|
|
|
2017-02-17 05:11:46 +08:00
|
|
|
renderPresentationArea() {
|
2016-07-27 04:56:43 +08:00
|
|
|
|
2016-06-27 22:48:17 +08:00
|
|
|
if (this.props.currentSlide) {
|
2017-03-24 05:52:36 +08:00
|
|
|
let adjustedSizes = this.calculateSize();
|
|
|
|
let slideObj = this.props.currentSlide.slide;
|
|
|
|
let x = -slideObj.x_offset * 2 * adjustedSizes.width / 100;
|
|
|
|
let y = -slideObj.y_offset * 2 * adjustedSizes.height / 100;
|
|
|
|
let viewBoxWidth = adjustedSizes.width * slideObj.width_ratio / 100;
|
|
|
|
let viewBoxHeight = adjustedSizes.height * slideObj.height_ratio / 100;
|
2016-06-02 07:37:51 +08:00
|
|
|
return (
|
2017-03-24 05:52:36 +08:00
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
width: adjustedSizes.width,
|
|
|
|
height: adjustedSizes.height,
|
|
|
|
WebkitTransition: 'width 0.2s', /* Safari */
|
|
|
|
transition: 'width 0.2s',
|
|
|
|
WebkitTransition: 'height 0.2s', /* Safari */
|
|
|
|
transition: 'height 0.2s',
|
|
|
|
}}
|
|
|
|
>
|
2016-06-03 06:09:28 +08:00
|
|
|
<ReactCSSTransitionGroup
|
|
|
|
transitionName={ {
|
|
|
|
enter: styles.enter,
|
|
|
|
enterActive: styles.enterActive,
|
|
|
|
appear: styles.appear,
|
|
|
|
appearActive: styles.appearActive,
|
|
|
|
} }
|
|
|
|
transitionAppear={true}
|
|
|
|
transitionEnter={true}
|
|
|
|
transitionLeave={false}
|
|
|
|
transitionAppearTimeout={400}
|
|
|
|
transitionEnterTimeout={400}
|
|
|
|
transitionLeaveTimeout={400}
|
2016-06-02 07:37:51 +08:00
|
|
|
>
|
2016-06-03 06:09:28 +08:00
|
|
|
<svg
|
2016-06-25 05:30:37 +08:00
|
|
|
viewBox={`${x} ${y} ${viewBoxWidth} ${viewBoxHeight}`}
|
2016-06-03 06:09:28 +08:00
|
|
|
version="1.1"
|
2017-03-24 05:52:36 +08:00
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
2016-06-03 06:09:28 +08:00
|
|
|
className={styles.svgStyles}
|
2016-06-05 07:09:50 +08:00
|
|
|
key={slideObj.id}
|
2016-05-31 06:07:02 +08:00
|
|
|
>
|
2016-06-10 03:00:44 +08:00
|
|
|
<defs>
|
|
|
|
<clipPath id="viewBox">
|
|
|
|
<rect x={x} y={y} width="100%" height="100%" fill="none"/>
|
|
|
|
</clipPath>
|
|
|
|
</defs>
|
|
|
|
<g clipPath="url(#viewBox)">
|
2017-03-24 05:52:36 +08:00
|
|
|
<Slide
|
|
|
|
id="slideComponent"
|
|
|
|
currentSlide={this.props.currentSlide}
|
|
|
|
paperWidth={adjustedSizes.width}
|
|
|
|
paperHeight={adjustedSizes.height}
|
|
|
|
/>
|
2017-02-23 08:10:30 +08:00
|
|
|
<ShapeGroupContainer
|
2017-03-24 05:52:36 +08:00
|
|
|
width = {adjustedSizes.width}
|
|
|
|
height = {adjustedSizes.height}
|
2017-02-23 08:10:30 +08:00
|
|
|
whiteboardId = {slideObj.id}
|
|
|
|
/>
|
2016-08-21 10:59:32 +08:00
|
|
|
{this.props.cursor ?
|
|
|
|
<Cursor
|
2016-07-16 04:45:54 +08:00
|
|
|
viewBoxWidth={viewBoxWidth}
|
|
|
|
viewBoxHeight={viewBoxHeight}
|
|
|
|
viewBoxX={x}
|
|
|
|
viewBoxY={y}
|
|
|
|
widthRatio={slideObj.width_ratio}
|
2016-08-21 10:59:32 +08:00
|
|
|
cursorX={this.props.cursor.x}
|
|
|
|
cursorY={this.props.cursor.y}
|
|
|
|
/>
|
|
|
|
: null }
|
2016-06-10 03:00:44 +08:00
|
|
|
</g>
|
2017-02-07 08:10:50 +08:00
|
|
|
{this.props.userIsPresenter ?
|
2017-02-24 08:11:27 +08:00
|
|
|
<PresentationOverlayContainer
|
2017-02-07 08:10:50 +08:00
|
|
|
x={x}
|
|
|
|
y={y}
|
|
|
|
vbwidth={viewBoxWidth}
|
|
|
|
vbheight={viewBoxHeight}
|
2017-03-01 02:35:56 +08:00
|
|
|
>
|
|
|
|
<WhiteboardOverlayContainer />
|
|
|
|
</PresentationOverlayContainer>
|
2017-02-07 08:10:50 +08:00
|
|
|
: null }
|
2016-06-03 06:09:28 +08:00
|
|
|
</svg>
|
|
|
|
</ReactCSSTransitionGroup>
|
2017-03-24 05:52:36 +08:00
|
|
|
</div>
|
2016-06-02 07:37:51 +08:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-24 04:20:21 +08:00
|
|
|
renderPresentationToolbar() {
|
2016-08-06 02:39:24 +08:00
|
|
|
if (this.props.currentSlide) {
|
|
|
|
return (
|
2017-02-24 04:20:21 +08:00
|
|
|
<PresentationToolbarContainer
|
2016-08-06 02:39:24 +08:00
|
|
|
currentSlideNum={this.props.currentSlide.slide.num}
|
|
|
|
presentationId={this.props.currentSlide.presentationId}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-02 07:37:51 +08:00
|
|
|
render() {
|
|
|
|
return (
|
2017-02-17 05:11:46 +08:00
|
|
|
<div className={styles.presentationContainer}>
|
2017-03-24 05:52:36 +08:00
|
|
|
<div
|
|
|
|
ref="presentationPaper"
|
|
|
|
className={styles.presentationPaper}
|
|
|
|
>
|
|
|
|
{this.state.showSlide ?
|
|
|
|
this.renderPresentationArea()
|
|
|
|
: null }
|
2016-07-01 06:21:46 +08:00
|
|
|
</div>
|
2016-06-30 06:00:06 +08:00
|
|
|
<PollingContainer />
|
2017-02-24 04:20:21 +08:00
|
|
|
{this.renderPresentationToolbar()}
|
2016-05-31 06:07:02 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-17 05:11:46 +08:00
|
|
|
PresentationArea.defaultProps = {
|
2016-05-31 06:07:02 +08:00
|
|
|
svgProps: {
|
2016-06-03 06:09:28 +08:00
|
|
|
|
2016-05-31 06:07:02 +08:00
|
|
|
},
|
|
|
|
svgStyle: {
|
2016-06-03 06:09:28 +08:00
|
|
|
|
2016-05-31 06:07:02 +08:00
|
|
|
},
|
|
|
|
};
|