var React = require('react'); var render = require('../../lib/render.jsx'); var FormattedHTMLMessage = require('react-intl').FormattedHTMLMessage; var FormattedMessage = require('react-intl').FormattedMessage; var api = require('../../lib/api'); var Page = require('../../components/page/www/page.jsx'); var TitleBanner = require('../../components/title-banner/title-banner.jsx'); var FlexRow = require('../../components/flex-row/flex-row.jsx'); var SubNavigation = require('../../components/subnavigation/subnavigation.jsx'); require('./download.scss'); require('../../components/forms/button.scss'); var Download = React.createClass({ type: 'Download', getInitialState: function () { return { swfVersion: '' }; }, componentDidMount: function () { api({ host: '', uri: '/scratchr2/static/sa/version.xml', responseType: 'string' }, function (err, body, res) { if (err || res.statusCode >= 400) { return this.setState({ swfVersion: -1 }); } var doc = new DOMParser().parseFromString(body, 'text/xml'); return this.setState({ swfVersion: doc.getElementsByTagName('versionNumber')[0].childNodes[0].nodeValue }); }.bind(this)); }, render: function () { if (this.state.swfVersion.length > 0 && this.state.swfVersion !== -1) { var downloadUrls = { mac: '/scratchr2/static/sa/Scratch-'+ this.state.swfVersion + '.dmg', mac105: '/scratchr2/static/sa/Scratch-'+ this.state.swfVersion + '.air', windows: '/scratchr2/static/sa/Scratch-'+ this.state.swfVersion + '.exe', linux: '/scratchr2/static/sa/Scratch-'+ this.state.swfVersion + '.air' }; } return (

    • - {' '}
    • - {' '}
    • - {' '}
    • - {' '}

    {downloadUrls ? [
    • - {' '}
    • - {' '}
    • - {' '}
    • - {' '}
    ] : []} {this.state.swfVersion === -1 ? [

    ] : []}

    • - {' '}
    • - {' '}
    • - {' '}

    {this.state.swfVersion !== -1 ? [

    ] : []}

    ); } }); render(, document.getElementById('app'));