Add clipboard image paste feature #168
This commit is contained in:
parent
621c44e28c
commit
7740952956
|
@ -1,5 +1,6 @@
|
|||
.idea
|
||||
.jshintrc
|
||||
client/package-lock.json
|
||||
tests/Gemfile.lock
|
||||
server/composer.lock
|
||||
server/vendor
|
||||
|
|
|
@ -51,7 +51,7 @@ class TextEditor extends React.Component {
|
|||
|
||||
render() {
|
||||
return (
|
||||
<div className={this.getClass()}>
|
||||
<div className={this.getClass()} onPaste={this.onPaste.bind(this)}>
|
||||
{isIE() ? this.renderTextArea() : this.renderQuill()}
|
||||
</div>
|
||||
);
|
||||
|
@ -141,6 +141,29 @@ class TextEditor extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
onPaste(event) {
|
||||
let items = event.nativeEvent && event.nativeEvent.clipboardData.items;
|
||||
|
||||
for (let index in items) {
|
||||
let item = items[index];
|
||||
if (item.kind === 'file') {
|
||||
let blob = item.getAsFile();
|
||||
let reader = new FileReader();
|
||||
reader.onload = (event) => {
|
||||
this.props.onChange({
|
||||
target: {
|
||||
value: (
|
||||
this.props.value
|
||||
+ `<img src="${event.target.result}" />`
|
||||
)
|
||||
}
|
||||
});
|
||||
};
|
||||
reader.readAsDataURL(blob);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
focus() {
|
||||
if (this.refs.editor) {
|
||||
this.refs.editor.focus();
|
||||
|
|
Loading…
Reference in New Issue