'use strict'; var React = require('react'); var request = require('superagent'); var Router = require('react-router'); var Link = require('react-router').Link; var Foot = require('./foot.jsx'); var MusicItem = React.createClass({ render: function() { if (!this.props.item.matched_at) { return (
); } else if (!this.props.item.id) { return (
No Match
); } else { return (
{this.props.inc == 0 ? "Found matches using this link": ""}
); } } }); var VideoItem = React.createClass({ render: function() { if (this.props.item.id) { return (
More Youtube matches
); } else { return (
); } } }); module.exports = React.createClass({ mixins: [ Router.State ], getInitialState: function () { if (this.props.shares && this.props.shares[0].id == this.getParams().id) { return { name: this.props.shares[0].name, artist: this.props.shares[0].artist.name, shares: this.props.shares, shareUrl: "https://match.audio/" + this.getParams().service + "/" + this.getParams().type + "/" + this.getParams().id }; } return { name: "", artist: "", shares: [], shareUrl: "" }; }, componentWillUnmount: function() { if (this.state.interval) { clearInterval(this.state.interval); } }, componentDidMount: function () { var complete = this.state.shares.length > 0; this.state.shares.forEach(function(share) { if (typeof share.matched_at === "undefined") { complete = false; } }); var getShares = function() { request.get(this.getPathname() + ".json").end(function(res) { var shares = res.body.shares; complete = true; shares.forEach(function(share) { if (typeof share.matched_at === "undefined") { complete = false; } }); if (complete) { clearInterval(this.state.interval); } this.setState({ name: shares[0].name, artist: shares[0].artist.name, shares: shares }); }.bind(this)); }.bind(this) if (!this.state.shares.length) { getShares(); } // Temporary until websockets implementation this.state.interval = setInterval(function() { if (!complete) { getShares(); } }.bind(this), 2000); // Some hacks to pop open the Twitter/Facebook/Google Plus sharing dialogs without using their code. Array.prototype.forEach.call(document.querySelectorAll(".share-dialog"), function(dialog){ dialog.addEventListener("click", function(event) { event.preventDefault(); var w = 845; var h = 670; var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left; var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top; var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width; var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height; var left = ((width / 2) - (w / 2)) + dualScreenLeft; var top = ((height / 2) - (h / 2)) + dualScreenTop; var newWindow = window.open(dialog.href, "Share Music", 'scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left); if (window.focus) { newWindow.focus(); } }); }); }, render: function() { return (

match.audio

Matched {this.state.shares[0] ? this.state.shares[0].type + "s" : ""} for

{this.state.name} - {this.state.artist}

  • Share this
  • Twitter
  • Facebook
  • Google+
{this.state.shares.map(function(item, i){ if (item.service == "youtube") { return (); } else { return (); } }.bind(this))}
); } });