Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81165 views
1
/**
2
* Copyright 2013-2014, Facebook, Inc.
3
* All rights reserved.
4
*
5
* This source code is licensed under the BSD-style license found in the
6
* LICENSE file in the root directory of this source tree. An additional grant
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
* @providesModule ReactDOMImg
10
*/
11
12
"use strict";
13
14
var EventConstants = require('EventConstants');
15
var LocalEventTrapMixin = require('LocalEventTrapMixin');
16
var ReactBrowserComponentMixin = require('ReactBrowserComponentMixin');
17
var ReactCompositeComponent = require('ReactCompositeComponent');
18
var ReactElement = require('ReactElement');
19
var ReactDOM = require('ReactDOM');
20
21
// Store a reference to the <img> `ReactDOMComponent`. TODO: use string
22
var img = ReactElement.createFactory(ReactDOM.img.type);
23
24
/**
25
* Since onLoad doesn't bubble OR capture on the top level in IE8, we need to
26
* capture it on the <img> element itself. There are lots of hacks we could do
27
* to accomplish this, but the most reliable is to make <img> a composite
28
* component and use `componentDidMount` to attach the event handlers.
29
*/
30
var ReactDOMImg = ReactCompositeComponent.createClass({
31
displayName: 'ReactDOMImg',
32
tagName: 'IMG',
33
34
mixins: [ReactBrowserComponentMixin, LocalEventTrapMixin],
35
36
render: function() {
37
return img(this.props);
38
},
39
40
componentDidMount: function() {
41
this.trapBubbledEvent(EventConstants.topLevelTypes.topLoad, 'load');
42
this.trapBubbledEvent(EventConstants.topLevelTypes.topError, 'error');
43
}
44
});
45
46
module.exports = ReactDOMImg;
47
48