From ef61470b5f701a06fa3b9a707ca12b2027eab03a Mon Sep 17 00:00:00 2001 From: vrde Date: Wed, 29 Jul 2015 18:00:49 +0200 Subject: [PATCH] First iteration --- js/components/ascribe_media/media_player.js | 36 +++++++++++++++------ js/utils/general_utils.js | 12 +++++++ 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/js/components/ascribe_media/media_player.js b/js/components/ascribe_media/media_player.js index da89f4a5..46f6550b 100644 --- a/js/components/ascribe_media/media_player.js +++ b/js/components/ascribe_media/media_player.js @@ -3,6 +3,8 @@ import React from 'react'; import Q from 'q'; +import { escapeHTML } from '../../utils/general_utils'; + import InjectInHeadMixin from '../../mixins/inject_in_head_mixin'; import Panel from 'react-bootstrap/lib/Panel'; import ProgressBar from 'react-bootstrap/lib/ProgressBar'; @@ -97,7 +99,7 @@ let Video = React.createClass({ mixins: [InjectInHeadMixin], getInitialState() { - return { ready: false }; + return { ready: false, videoMounted: false }; }, componentDidMount() { @@ -108,24 +110,38 @@ let Video = React.createClass({ }, componentDidUpdate() { - if (this.state.ready && !this.state.videojs) { - window.videojs(React.findDOMNode(this.refs.video)); + if (this.state.ready && !this.state.videoMounted) { + window.videojs('#mainvideo'); + this.setState({videoMounted: true}); } }, + componentWillUnmount() { + window.videojs('#mainvideo').dispose(); + }, + ready() { - this.setState({ready: true, videojs: false}); + this.setState({ready: true, videoMounted: false}); + }, + + prepareVideoHTML() { + let sources = this.props.extraData.map((data) => ''); + let html = [ + '']; + return html.join('\n'); + }, + + shouldComponentUpdate(nextProps, nextState) { + return nextState.videoMounted === false; }, render() { if (this.state.ready) { return ( - +
); } else { return ( diff --git a/js/utils/general_utils.js b/js/utils/general_utils.js index 00f1da2c..4dfda21d 100644 --- a/js/utils/general_utils.js +++ b/js/utils/general_utils.js @@ -166,3 +166,15 @@ function _mergeOptions(obj1, obj2) { } return obj3; } + +/** + * Escape HTML in a string so it can be injected safely using + * React's `dangerouslySetInnerHTML` + * + * @param s the string to be sanitized + * + * Taken from: http://stackoverflow.com/a/17546215/597097 + */ +export function escapeHTML(s) { + return document.createElement('div').appendChild(document.createTextNode(s)).parentNode.innerHTML; +}