1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 01:39:36 +01:00

Lint code

This commit is contained in:
vrde 2015-06-05 14:14:59 +02:00
parent e8627cd0a3
commit 62cc6b41df
3 changed files with 27 additions and 11 deletions

View File

@ -1,3 +1,5 @@
'use strict';
import React from 'react'; import React from 'react';
import InjectInHeadMixin from '../../mixins/inject_in_head_mixin'; import InjectInHeadMixin from '../../mixins/inject_in_head_mixin';
import Panel from 'react-bootstrap/lib/Panel'; import Panel from 'react-bootstrap/lib/Panel';
@ -15,6 +17,10 @@ import Panel from 'react-bootstrap/lib/Panel';
let Other = React.createClass({ let Other = React.createClass({
propTypes: {
url: React.PropTypes.string.isRequired
},
render() { render() {
let ext = this.props.url.split('.').pop(); let ext = this.props.url.split('.').pop();
@ -29,6 +35,11 @@ let Other = React.createClass({
}); });
let Image = React.createClass({ let Image = React.createClass({
propTypes: {
url: React.PropTypes.string.isRequired,
preview: React.PropTypes.string.isRequired
},
mixins: [InjectInHeadMixin], mixins: [InjectInHeadMixin],
componentDidMount() { componentDidMount() {
@ -37,7 +48,7 @@ let Image = React.createClass({
Promise.all([ Promise.all([
this.inject('node_modules/shmui/shmui.css'), this.inject('node_modules/shmui/shmui.css'),
this.inject('node_modules/shmui/jquery.shmui.js') this.inject('node_modules/shmui/jquery.shmui.js')
]).then(() => { $('.shmui-ascribe').shmui(); })); ]).then(() => { window.jQuery('.shmui-ascribe').shmui(); }));
}, },
render() { render() {
@ -66,7 +77,11 @@ let Video = React.createClass({
Promise.all([ 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/mediaelement-and-player.min.js'),
this.inject('https://cdnjs.cloudflare.com/ajax/libs/mediaelement/2.17.0/mediaelementplayer.min.css') this.inject('https://cdnjs.cloudflare.com/ajax/libs/mediaelement/2.17.0/mediaelementplayer.min.css')
]).then(() => { this.setState({ready: true}); })); ]).then(this.ready));
},
ready() {
this.setState({ready: true});
}, },
render() { render() {
@ -79,7 +94,7 @@ let Video = React.createClass({
</video> </video>
); );
} else { } else {
return( return (
<Image src={this.props.preview} /> <Image src={this.props.preview} />
); );
} }
@ -91,13 +106,14 @@ let resourceMap = {
'image': Image, 'image': Image,
'video': Video, 'video': Video,
'other': Other 'other': Other
} };
let MediaPlayer = React.createClass({ let MediaPlayer = React.createClass({
propTypes: { propTypes: {
mimetype: React.PropTypes.oneOf(['image', 'video', 'audio', 'pdf', 'other']).isRequired, mimetype: React.PropTypes.oneOf(['image', 'video', 'audio', 'pdf', 'other']).isRequired,
preview: React.PropTypes.string.isRequired, preview: React.PropTypes.string.isRequired,
url: React.PropTypes.string.isRequired url: React.PropTypes.string.isRequired,
extraData: React.PropTypes.array
}, },
render() { render() {

View File

@ -2,7 +2,7 @@
let mapAttr = { let mapAttr = {
link: 'href', link: 'href',
source: 'src' script: 'src'
}; };
let mapTag = { let mapTag = {
@ -24,14 +24,14 @@ let InjectInHeadMixin = {
return document.querySelector(query); return document.querySelector(query);
}, },
injectTag(tag, src, extraAttrs) { injectTag(tag, src) {
let promise = new Promise((resolve, reject) => { let promise = new Promise((resolve, reject) => {
if (InjectInHeadMixin.isPresent(tag, src)) { if (InjectInHeadMixin.isPresent(tag, src)) {
resolve(); resolve();
} else { } else {
let attr = mapAttr[tag]; let attr = mapAttr[tag];
let element = document.createElement(tag); let element = document.createElement(tag);
if (tag == 'script') { if (tag === 'script') {
element.onload = () => resolve(); element.onload = () => resolve();
element.onerror = () => reject(); element.onerror = () => reject();
} else { } else {
@ -39,8 +39,8 @@ let InjectInHeadMixin = {
} }
document.head.appendChild(element); document.head.appendChild(element);
element[attr] = src; element[attr] = src;
if (tag == 'link') { if (tag === 'link') {
element['rel'] = 'stylesheet'; element.rel = 'stylesheet';
} }
} }
}); });