|
@@ -7,10 +7,12 @@ import moment from 'moment';
|
|
|
import ajax from 'jquery/src/ajax/xhr.js';
|
|
|
import $ from 'jquery/src/ajax';
|
|
|
|
|
|
-var theThis = null;
|
|
|
function uploadImg(s) {
|
|
|
- let myform = new FormData(), _me = s;
|
|
|
- myform.append('file', document.getElementById("fileToUpload").files[0]);
|
|
|
+ let myform = new FormData(), file = document.getElementById("fileToUpload").files[0];
|
|
|
+ if (!file) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ myform.append('file', file);
|
|
|
myform.append('sign', 'news_content_picture');
|
|
|
$.ajax({
|
|
|
method: "post",
|
|
@@ -23,17 +25,21 @@ function uploadImg(s) {
|
|
|
if (data.error && data.error.length) {
|
|
|
message.warning(data.error[0].message);
|
|
|
} else {
|
|
|
- let theUrl = data.data;
|
|
|
- const cursorPosition = theThis.quill.getSelection().index
|
|
|
- theThis.quill.insertText(cursorPosition, '<img src="' + globalConfig.avatarHost + '/upload' + theUrl + '" />')
|
|
|
- theThis.quill.setSelection(cursorPosition + 1)
|
|
|
+ const cursorPosition = s.quill.getSelection().index
|
|
|
+ s.quill.insertEmbed(cursorPosition, 'image', globalConfig.avatarHost + '/upload' + data.data)
|
|
|
+ s.quill.setSelection(cursorPosition + 1)
|
|
|
};
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
function fileSelect() {
|
|
|
- document.getElementById("fileToUpload").click();
|
|
|
- theThis = this;
|
|
|
+ let uploader = document.getElementById("fileToUpload");
|
|
|
+ if (!uploader.onchange) {
|
|
|
+ uploader.onchange = () => {
|
|
|
+ uploadImg(this)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ uploader.click();
|
|
|
}
|
|
|
const Avatar = React.createClass({
|
|
|
getInitialState() {
|
|
@@ -521,8 +527,7 @@ const News = React.createClass({
|
|
|
<input type="file"
|
|
|
name="fileToUpload"
|
|
|
id="fileToUpload"
|
|
|
- style={{ "display": "none" }}
|
|
|
- onChange={() => { uploadImg(modules.toolbar) }} />
|
|
|
+ style={{ "display": "none" }} />
|
|
|
</Tabs.TabPane>
|
|
|
</Tabs>
|
|
|
<div className="modal-box">
|