-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathreact-swf-compat.js
81 lines (66 loc) · 2.49 KB
/
react-swf-compat.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*! react-swf v1.0.7 | @syranide | MIT license */
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define(['prop-types', 'react', 'react-dom', 'react-dom/server', 'react-swf'], factory);
} else if (typeof exports === 'object') {
module.exports = factory(require('prop-types'), require('react'), require('react-dom'), require('react-dom/server'), require('react-swf'));
} else {
root.ReactSWFCompat = factory(root.PropTypes, root.React, root.ReactDOM, root.ReactDOMServer, root.ReactSWF);
}
}(this, function(PropTypes, React, ReactDOM, ReactDOMServer, ReactSWF) {
'use strict';
function ReactSWFCompat(props) {
React.Component.call(this, props);
var that = this;
this._containerRefCallback = function(c) {
that._container = c;
};
this._swfRefCallback = function(c) {
that._swf = c;
};
}
ReactSWFCompat.prototype = Object.create(React.Component.prototype);
ReactSWFCompat.prototype.constructor = ReactSWFCompat;
Object.assign(ReactSWFCompat, React.Component);
ReactSWFCompat.propTypes = {
container: PropTypes.element.isRequired
};
ReactSWFCompat.prototype._createSWFElement = function() {
var props = Object.assign({}, this.props);
delete props.container;
props.movie = props.src;
props.ref = this._swfRefCallback;
return React.createElement(ReactSWF, props);
};
ReactSWFCompat.prototype.getFPDOMNode = function() {
return this._swf.getFPDOMNode();
};
ReactSWFCompat.prototype.componentDidMount = function() {
var swfElement = this._createSWFElement();
this._container.innerHTML = ReactDOMServer.renderToString(swfElement);
ReactDOM.render(swfElement, this._container);
};
ReactSWFCompat.prototype.componentDidUpdate = function() {
var swfElement = this._createSWFElement();
ReactDOM.render(swfElement, this._container);
};
ReactSWFCompat.prototype.componentWillUnmount = function() {
// IE8 leaks nodes if AS3 `ExternalInterface.addCallback`-functions remain.
if (document.documentMode < 9) {
var node = this.getFPDOMNode();
// Node-methods are not enumerable in IE8, but properties are.
for (var key in node) {
if (typeof node[key] === 'function') {
node[key] = null;
}
}
}
};
ReactSWFCompat.prototype.render = function() {
var containerProps = {
ref: this._containerRefCallback
};
return React.cloneElement(this.props.container, containerProps, null);
};
return ReactSWFCompat;
}));