-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
37 lines (34 loc) · 1.17 KB
/
index.js
File metadata and controls
37 lines (34 loc) · 1.17 KB
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
/** @jsx React.DOM */
"use strict";
if ("undefined" == typeof React)
var React = require('react');
//escapeTextForBrowser = require('react/lib/escapeTextForBrowser');
module.exports = React.createClass({
displayName: "Editable",
propTypes: {
html: React.PropTypes.string
},
shouldComponentUpdate: function (nextProps) {
return nextProps.editable !== this.props.editable;
},
componentDidUpdate: function () {
if (this.props.html !== this.getDOMNode().innerHTML) {
this.getDOMNode().innerHTML = this.props.html;
}
},
handleChange: function (e) {
var html = this.getDOMNode().innerHTML;
if (this.props.onChange && html !== this.lastHtml) {
e.target = {value: html};
this.props.onChange(e);
}
this.lastHtml = html;
},
render: function () {
return React.createElement('div', {
onInput: this.handleChange,
onBlur: this.handleChange,
contentEditable: undefined === this.props.editable ? true: this.props.editable,
dangerouslySetInnerHTML: {__html: this.props.html}});
}
});