1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 09:35:10 +01:00

Add support for videos and images

This commit is contained in:
vrde 2015-06-03 16:53:27 +02:00
parent 633f7f5b33
commit 34cf9e6871
5 changed files with 93 additions and 32 deletions

View File

@ -14,7 +14,6 @@ class PieceListActions {
PieceListFetcher PieceListFetcher
.fetch(page, pageSize, search, orderBy, orderAsc) .fetch(page, pageSize, search, orderBy, orderAsc)
.then((res) => { .then((res) => {
console.log(res);
this.actions.updatePieceList({ this.actions.updatePieceList({
page, page,
pageSize, pageSize,

View File

@ -12,26 +12,73 @@ import InjectInHeadMixin from '../../mixins/inject_in_head_mixin';
* - other * - other
*/ */
let resourceMap = {
'image': 1
}
let ResourceViewer = React.createClass({ let Image = React.createClass({
render() {
return (<img className="img-responsive" src={this.props.preview} />);
}
});
let Video = React.createClass({
propTypes: { propTypes: {
thumbnail: React.PropTypes.string.isRequired, preview: React.PropTypes.string.isRequired,
mimetype: React.PropTypes.oneOf(['image', 'video', 'audio', 'pdf', 'other']).isRequired url: React.PropTypes.string.isRequired,
extraData: React.PropTypes.array.isRequired
}, },
mixins: [InjectInHeadMixin], mixins: [InjectInHeadMixin],
getInitialState() {
return { ready: false };
},
componentDidMount() { componentDidMount() {
this.inject('http://antani.com'); this.inject('http://code.jquery.com/jquery-2.1.4.min.js')
.then(() =>
Promise.all([
this.inject('https://cdnjs.cloudflare.com/ajax/libs/mediaelement/2.17.0/mediaelement-and-player.min.js'),
this.inject('https://cdnjs.cloudflare.com/ajax/libs/mediaelement/2.17.0/mediaelementplayer.min.css')
]).then(() => { this.setState({ready: true}); }));
}, },
render() { render() {
if (this.state.ready) {
return ( return (
<div> <video poster={this.props.preview} controls="controls" preload="none">
resourceviewer {this.props.thumbnail} {this.props.mimetype} {this.props.extraData.map((data, i) =>
<source key={i} type={'video/' + data.type} src={data.url} />
)}
</video>
);
} else {
return(
<Image src={this.props.preview} />
);
}
}
});
let resourceMap = {
'image': Image,
'video': Video
}
let ResourceViewer = React.createClass({
propTypes: {
mimetype: React.PropTypes.oneOf(['image', 'video', 'audio', 'pdf', 'other']).isRequired,
preview: React.PropTypes.string.isRequired,
url: React.PropTypes.string.isRequired
},
render() {
let Component = resourceMap[this.props.mimetype] || Image;
return (
<div className="media">
<Component preview={this.props.preview}
url={this.props.url}
extraData={this.props.extraData} />
</div> </div>
); );
} }

View File

@ -10,13 +10,19 @@ let Edition = React.createClass({
render() { render() {
let thumbnail = this.props.edition.thumbnail; let thumbnail = this.props.edition.thumbnail;
let mimetype = this.props.edition.digital_work.mime; let mimetype = this.props.edition.digital_work.mime;
let extraData = null;
if (this.props.edition.digital_work.encoding_urls) {
extraData = this.props.edition.digital_work.encoding_urls.map(e => { return { url: e.url, type: e.label } });
}
return ( return (
<div> <div>
<div className="col-md-7"> <div className="col-md-7">
<ResourceViewer thumbnail={thumbnail} <ResourceViewer mimetype={mimetype}
mimetype={mimetype} preview={thumbnail}
/> url={this.props.edition.digital_work.url}
extraData={extraData} />
</div> </div>
<div className="col-md-5"> <div className="col-md-5">
<EditionHeader edition={this.props.edition}/> <EditionHeader edition={this.props.edition}/>

View File

@ -37,7 +37,8 @@ let EditionContainer = React.createClass({
if('title' in this.state.edition) { if('title' in this.state.edition) {
return ( return (
<Edition edition={this.state.edition } currentUser={this.state.currentUser}></Edition> <Edition edition={this.state.edition}
currentUser={this.state.currentUser} />
); );
} else { } else {
return ( return (

View File

@ -1,10 +1,10 @@
let mapAttr = { let mapAttr = {
link: 'href', link: 'href',
source: 'src' script: 'src'
} }
let mapExt = { let mapTag = {
js: 'source', js: 'script',
css: 'link' css: 'link'
} }
@ -23,33 +23,41 @@ let InjectInHeadMixin = {
}, },
injectTag(tag, src){ injectTag(tag, src){
console.log(this.foobar); let promise = new Promise((resolve, reject) => {
if (InjectInHeadMixin.isPresent(tag, src)) if (InjectInHeadMixin.isPresent(tag, src)) {
return; resolve();
} else {
let attr = mapAttr[tag]; let attr = mapAttr[tag];
let element = document.createElement(tag); let element = document.createElement(tag);
if (tag == 'script') {
element.onload = () => resolve();
element.onerror = () => reject();
} else {
resolve();
}
document.head.appendChild(element); document.head.appendChild(element);
element[attr] = src; element[attr] = src;
}
});
return promise;
}, },
injectStylesheet(src) { injectStylesheet(src) {
this.injectTag('link', src); return InjectInHeadMixin.injectTag('link', src);
}, },
injectScript(src) { injectScript(src) {
this.injectTag('source', src); return InjectInHeadMixin.injectTag('source', src);
}, },
inject(src) { inject(src) {
let ext = src.split('.').pop(); let ext = src.split('.').pop();
let tag = null; let tag = mapTag[ext];
try { if (!tag)
tag = mapAttr(src);
} catch (e) {
throw new Error(`Cannot inject ${src} in the DOM, cannot guess the tag name from extension "${ext}". Valid extensions are "js" and "css".`); throw new Error(`Cannot inject ${src} in the DOM, cannot guess the tag name from extension "${ext}". Valid extensions are "js" and "css".`);
}
InjectInHeadMixin.injectTag(tag, src); return InjectInHeadMixin.injectTag(tag, src);
} }
}; };