|
| 1 | +/*! react-swf v1.0.3 | @syranide | MIT license */ |
| 2 | + |
| 3 | +(function(root, factory) { |
| 4 | + if (typeof define === 'function' && define.amd) { |
| 5 | + define(['react', 'react-dom', 'react-dom/server', 'react-swf'], factory); |
| 6 | + } else if (typeof exports === 'object') { |
| 7 | + module.exports = factory(require('react'), require('react-dom'), require('react-dom-server'), require('react-swf')); |
| 8 | + } else { |
| 9 | + root.ReactSWFCompat = factory(root.React, root.ReactDOM, root.ReactDOMServer, root.ReactSWF); |
| 10 | + } |
| 11 | +}(this, function(React, ReactDOM, ReactDOMServer, ReactSWF) { |
| 12 | + 'use strict'; |
| 13 | + |
| 14 | + var PropTypes = React.PropTypes; |
| 15 | + |
| 16 | + function ReactSWFCompat(props) { |
| 17 | + React.Component.call(this, props); |
| 18 | + |
| 19 | + var that = this; |
| 20 | + this._containerRefCallback = function(c) { |
| 21 | + that._container = c; |
| 22 | + }; |
| 23 | + this._swfRefCallback = function(c) { |
| 24 | + that._swf = c; |
| 25 | + }; |
| 26 | + } |
| 27 | + |
| 28 | + ReactSWFCompat.prototype = Object.create(React.Component.prototype); |
| 29 | + ReactSWFCompat.prototype.constructor = ReactSWFCompat; |
| 30 | + Object.assign(ReactSWFCompat, React.Component); |
| 31 | + |
| 32 | + ReactSWFCompat.propTypes = { |
| 33 | + container: PropTypes.element.isRequired |
| 34 | + }; |
| 35 | + |
| 36 | + ReactSWFCompat.prototype._createSWFElement = function() { |
| 37 | + var swfProps = Object.assign({}, this.props); |
| 38 | + swfProps.container = undefined; |
| 39 | + swfProps.movie = swfProps.src; |
| 40 | + swfProps.ref = this._swfRefCallback; |
| 41 | + |
| 42 | + return React.createElement(ReactSWF, swfProps); |
| 43 | + }; |
| 44 | + |
| 45 | + ReactSWFCompat.prototype.getFPDOMNode = function() { |
| 46 | + return this._swf.getFPDOMNode(); |
| 47 | + }; |
| 48 | + |
| 49 | + ReactSWFCompat.prototype.componentDidMount = function() { |
| 50 | + var swfElement = this._createSWFElement(); |
| 51 | + this._container.innerHTML = ReactDOMServer.renderToString(swfElement); |
| 52 | + ReactDOM.render(swfElement, this._container); |
| 53 | + }; |
| 54 | + |
| 55 | + ReactSWFCompat.prototype.componentDidUpdate = function() { |
| 56 | + var swfElement = this._createSWFElement(); |
| 57 | + ReactDOM.render(swfElement, this._container); |
| 58 | + }; |
| 59 | + |
| 60 | + ReactSWFCompat.prototype.render = function() { |
| 61 | + var containerProps = { |
| 62 | + ref: this._containerRefCallback |
| 63 | + }; |
| 64 | + |
| 65 | + return React.cloneElement(this.props.container, containerProps, null); |
| 66 | + }; |
| 67 | + |
| 68 | + return ReactSWFCompat; |
| 69 | +})); |
0 commit comments