-
Notifications
You must be signed in to change notification settings - Fork 505
/
html-editor.jsx
58 lines (49 loc) · 1.71 KB
/
html-editor.jsx
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
var React = require('react');
var AceEditor = require('./ace-editor.jsx');
var EventMixin = require('react-backbone-events-mixin');
module.exports = React.createClass({
mixins: [EventMixin],
registerListeners: function (props, state) {
this.listenTo(state.code, 'ready-to-run', function () {
this.setState({ editing: false });
});
//this.listenTo(state.code, 'change:code', function () {
// this.forceUpdate();
//});
},
getInitialState: function () {
return {
editing: false,
code: app.store.code,
};
},
switchMode: function () {
var newValue = !this.state.editing;
this.setState({ editing: newValue });
},
onCodeChange: function (newCode) {
this.state.code.htmlScratchpad = newCode;
},
render: function () {
if (this.state.editing) {
return (
<div className="flexChild columnParent">
<div className='editor-switch'><button onClick={this.switchMode}>Save</button></div>
<AceEditor
mode="html"
onBlur={this.onEditBlur}
onCodeChange={this.onCodeChange}
initialValue={this.state.code.rawHtmlScratchpad}
/>
</div>
);
};
var innerHTML = { __html: this.state.code.rawHtmlScratchpad };
return (
<div className="flexChild columnParent">
<div className='editor-switch'><button onClick={this.switchMode}>Edit</button></div>
<div className='html-scratchpad flexChild' dangerouslySetInnerHTML={innerHTML}></div>
</div>
);
}
});