Skip to content

Commit

Permalink
fix:2.30.6
Browse files Browse the repository at this point in the history
  • Loading branch information
JiHong88 authored Jun 27, 2020
2 parents cbac68b + e68b936 commit 1ac8059
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 80 deletions.
63 changes: 46 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1128,33 +1128,62 @@ editor.onAudioUploadError = function (errorMessage, result, core) {

// It replaces the default callback function of the image upload
/**
* xmlHttpRequest: xmlHttpRequest object
* info (Input information): {
* xmlHttp: xmlHttpRequest object
* info: Input information
* - linkValue: Link url value
* - linkNewWindow: Open in new window Check Value
* - inputWidth: Value of width input
* - inputHeight: Value of height input
* - align: Align Check Value
* - isUpdate: Update image if true, create image if false
* - element: If isUpdate is true, the currently selected image.
* }
* core: Core object
*/
editor.imageUploadHandler = function (xmlHttpRequest, info, core) {
// Example of upload method
const res = JSON.parse(xmlHttpRequest.responseText);

// Error
if (res.errorMessage) {
if (core.functions.onImageUploadError !== 'function' || core.functions.onImageUploadError(res.errorMessage, res, core)) {
core.notice.open.call(core, res.errorMessage);
} else {
core.notice.open.call(core, res.errorMessage);
}
editor.imageUploadHandler = function (xmlHttp, info, core) {
// Editor code
const response = JSON.parse(xmlHttp.responseText);
if (response.errorMessage) {
this.plugins.image.error.call(this, response.errorMessage, response);
} else {
this.plugins.image.register.call(this, info, response);
}
// Success
else {
core.plugins.image.register.call(core, info, res);
}
/**
* @description It replaces the default callback function of the video upload
* xmlHttp: xmlHttpRequest object
* info: Input information
* - inputWidth: Value of width input
* - inputHeight: Value of height input
* - align: Align Check Value
* - isUpdate: Update video if true, create video if false
* - element: If isUpdate is true, the currently selected video.
* core: Core object
*/
editor.videoUploadHandler = function (xmlHttp, info, core) {
// Editor code
const response = JSON.parse(xmlHttp.responseText);
if (response.errorMessage) {
this.plugins.video.error.call(this, response.errorMessage, response);
} else {
this.plugins.video.register.call(this, info, response);
}
}

/**
* @description It replaces the default callback function of the audio upload
* xmlHttp xmlHttpRequest object
* info Input information
* - isUpdate: Update audio if true, create audio if false
* - element: If isUpdate is true, the currently selected audio.
* core Core object
*/
editor.audioUploadHandler = function (xmlHttp, info, core) {
// Editor code
const response = JSON.parse(xmlHttp.responseText);
if (response.errorMessage) {
this.plugins.audio.error.call(this, response.errorMessage, response);
} else {
this.plugins.audio.register.call(this, info, response);
}
}

Expand Down
2 changes: 1 addition & 1 deletion dist/suneditor.min.js

Large diffs are not rendered by default.

105 changes: 52 additions & 53 deletions sample/html/out/document-user.html
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ <h4 class="name" id="onImageUploadBefore"><span class="type-signature"></span>on
<span style="color:#ffe4c4;">@example</span><br>
<span style="color:#ffe4c4;">Also you can call directly image register not execute "uploadHandler".</span><br>
<span style="color:#ffe4c4;">This work is not execute default upload handler.</span><br>
const response = { // Same format as "imageUploadUrl" response<br>
const response = { <span style="color:#ffe4c4;">// Same format as "imageUploadUrl" response</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;"errorMessage": "insert error message",<br>
&nbsp;&nbsp;&nbsp;&nbsp;"result": [ { "url": "...", "name": "...", "size": "999" }, ]<br>
};<br>
Expand Down Expand Up @@ -1086,7 +1086,7 @@ <h4 class="name" id="onImageUploadError"><span class="type-signature"></span>onI


<h4 class="name" id="imageUploadHandler"><span class="type-signature"></span>imageUploadHandler<span
class="signature">(xmlHttpRequest, info, core)</span><span class="type-signature"></span></h4>
class="signature">(xmlHttp, info, core)</span><span class="type-signature"></span></h4>
<div class="description">
It replaces the default callback function of the image upload.
</div>
Expand All @@ -1100,7 +1100,7 @@ <h4 class="name" id="imageUploadHandler"><span class="type-signature"></span>ima
</thead>
<tbody>
<tr>
<td class="name"><code>xmlHttpRequest</code></td>
<td class="name"><code>xmlHttp</code></td>
<td class="type">
<span class="param-type">XMLHttpRequest</span>
</td>
Expand Down Expand Up @@ -1143,7 +1143,7 @@ <h4 class="name" id="onVideoUploadBefore"><span class="type-signature"></span>on
<span style="color:#ffe4c4;">@example</span><br>
<span style="color:#ffe4c4;">Also you can call directly image register not execute "uploadHandler".</span><br>
<span style="color:#ffe4c4;">This work is not execute default upload handler.</span><br>
const response = { // Same format as "imageUploadUrl" response<br>
const response = { <span style="color:#ffe4c4;">// Same format as "imageUploadUrl" response</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;"errorMessage": "insert error message",<br>
&nbsp;&nbsp;&nbsp;&nbsp;"result": [ { "url": "...", "name": "...", "size": "999" }, ]<br>
};<br>
Expand Down Expand Up @@ -1312,20 +1312,10 @@ <h4 class="name" id="onVideoUploadError"><span class="type-signature"></span>onV
<dl class="details"></dl>


<h4 class="name" id="onAudioUploadBefore"><span class="type-signature"></span>onAudioUploadBefore<span
class="signature">(files, info, core, uploadHandler)</span><span class="type-signature"> &rarr; {Boolean|Array|undefined}</span></h4>
<h4 class="name" id="videoUploadHandler"><span class="type-signature"></span>videoUploadHandler<span
class="signature">(xmlHttp, info, core)</span><span class="type-signature"></span></h4>
<div class="description">
Called before the audio is uploaded.<br>
If false is returned, no audio upload is performed.<br>
If new fileList are returned, replaced the previous fileList<br>
<span style="color:#ffe4c4;">@example</span><br>
<span style="color:#ffe4c4;">Also you can call directly image register not execute "uploadHandler".</span><br>
<span style="color:#ffe4c4;">This work is not execute default upload handler.</span><br>
const response = { // Same format as "imageUploadUrl" response<br>
&nbsp;&nbsp;&nbsp;&nbsp;"errorMessage": "insert error message",<br>
&nbsp;&nbsp;&nbsp;&nbsp;"result": [ { "url": "...", "name": "...", "size": "999" }, ]<br>
};<br>
core.plugins.image.register.call(core, info, response);
It replaces the default callback function of the video upload.
</div>
<table class="params">
<thead>
Expand All @@ -1337,20 +1327,24 @@ <h4 class="name" id="onAudioUploadBefore"><span class="type-signature"></span>on
</thead>
<tbody>
<tr>
<td class="name"><code>files</code></td>
<td class="name"><code>xmlHttp</code></td>
<td class="type">
<span class="param-type">FileList</span>
<span class="param-type">XMLHttpRequest</span>
</td>
<td class="description last">Files array</td>
<td class="description last">xmlHttpRequest object</td>
</tr>
<tr>
<td class="name"><code>info</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last">
<strong>isUpdate</strong>: Update audio if true, create audio if false<br>
<strong>element</strong>: If isUpdate is true, the currently selected audio<br>
-- Input information --<br>
<strong>inputWidth:</strong> Value of width input<br>
<strong>inputHeight:</strong> Value of height input<br>
<strong>align:</strong> Align Check Value<br>
<strong>isUpdate:</strong> Update video if true, create video if false<br>
<strong>element:</strong> If isUpdate is true, the currently selected video.
</td>
</tr>
<tr>
Expand All @@ -1360,29 +1354,25 @@ <h4 class="name" id="onAudioUploadBefore"><span class="type-signature"></span>on
</td>
<td class="description last"><a href="document-editor.html">Core Object</a></td>
</tr>
<tr>
<td class="name"><code>uploadHandler</code></td>
<td class="type">
<span class="param-type">Function</span>
</td>
<td class="description last">
If undefined is returned, it waits until "uploadHandler" is executed.<br>
"uploadHandler" is an upload function with "core" and "info" bound. (plugin.upload.bind(core, info))<br>
[upload files] : <span style="color: #ffe4c4;">uploadHandler(files or [new File(...),])</span><br>
[error] &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : <span style="color: #ffe4c4;">uploadHandler("Error message")</span><br>
[Just finish] &nbsp; &nbsp;: <span style="color: #ffe4c4;">uploadHandler()</span>
</td>
</tr>
</tbody>
</table>
<dl class="details"></dl>


<h4 class="name" id="videoUploadHandler"><span class="type-signature"></span>videoUploadHandler<span
class="signature">(xmlHttpRequest, info, core)</span><span class="type-signature"></span></h4>
<h4 class="name" id="onAudioUploadBefore"><span class="type-signature"></span>onAudioUploadBefore<span
class="signature">(files, info, core, uploadHandler)</span><span class="type-signature"> &rarr; {Boolean|Array|undefined}</span></h4>
<div class="description">
It replaces the default callback function of the video upload.
</div>
Called before the audio is uploaded.<br>
If false is returned, no audio upload is performed.<br>
If new fileList are returned, replaced the previous fileList<br>
<span style="color:#ffe4c4;">@example</span><br>
<span style="color:#ffe4c4;">Also you can call directly image register not execute "uploadHandler".</span><br>
<span style="color:#ffe4c4;">This work is not execute default upload handler.</span><br>
const response = { <span style="color:#ffe4c4;">// Same format as "imageUploadUrl" response</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;"errorMessage": "insert error message",<br>
&nbsp;&nbsp;&nbsp;&nbsp;"result": [ { "url": "...", "name": "...", "size": "999" }, ]<br>
};<br>
core.plugins.image.register.call(core, info, response);
<table class="params">
<thead>
<tr>
Expand All @@ -1393,24 +1383,20 @@ <h4 class="name" id="videoUploadHandler"><span class="type-signature"></span>vid
</thead>
<tbody>
<tr>
<td class="name"><code>xmlHttpRequest</code></td>
<td class="name"><code>files</code></td>
<td class="type">
<span class="param-type">XMLHttpRequest</span>
<span class="param-type">FileList</span>
</td>
<td class="description last">xmlHttpRequest object</td>
<td class="description last">Files array</td>
</tr>
<tr>
<td class="name"><code>info</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last">
-- Input information --<br>
<strong>inputWidth:</strong> Value of width input<br>
<strong>inputHeight:</strong> Value of height input<br>
<strong>align:</strong> Align Check Value<br>
<strong>isUpdate:</strong> Update video if true, create video if false<br>
<strong>element:</strong> If isUpdate is true, the currently selected video.<br>
<strong>isUpdate</strong>: Update audio if true, create audio if false<br>
<strong>element</strong>: If isUpdate is true, the currently selected audio<br>
</td>
</tr>
<tr>
Expand All @@ -1420,6 +1406,19 @@ <h4 class="name" id="videoUploadHandler"><span class="type-signature"></span>vid
</td>
<td class="description last"><a href="document-editor.html">Core Object</a></td>
</tr>
<tr>
<td class="name"><code>uploadHandler</code></td>
<td class="type">
<span class="param-type">Function</span>
</td>
<td class="description last">
If undefined is returned, it waits until "uploadHandler" is executed.<br>
"uploadHandler" is an upload function with "core" and "info" bound. (plugin.upload.bind(core, info))<br>
[upload files] : <span style="color: #ffe4c4;">uploadHandler(files or [new File(...),])</span><br>
[error] &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : <span style="color: #ffe4c4;">uploadHandler("Error message")</span><br>
[Just finish] &nbsp; &nbsp;: <span style="color: #ffe4c4;">uploadHandler()</span>
</td>
</tr>
</tbody>
</table>
<dl class="details"></dl>
Expand Down Expand Up @@ -1534,10 +1533,10 @@ <h4 class="name" id="onAudioUploadError"><span class="type-signature"></span>onA
<dl class="details"></dl>


<h4 class="name" id="videoUploadHandler"><span class="type-signature"></span>videoUploadHandler<span
class="signature">(xmlHttpRequest, info, core)</span><span class="type-signature"></span></h4>
<h4 class="name" id="audioUploadHandler"><span class="type-signature"></span>audioUploadHandler<span
class="signature">(xmlHttp, info, core)</span><span class="type-signature"></span></h4>
<div class="description">
It replaces the default callback function of the audio upload.
It replaces the default callback function of the audio upload
</div>
<table class="params">
<thead>
Expand All @@ -1549,7 +1548,7 @@ <h4 class="name" id="videoUploadHandler"><span class="type-signature"></span>vid
</thead>
<tbody>
<tr>
<td class="name"><code>xmlHttpRequest</code></td>
<td class="name"><code>xmlHttp</code></td>
<td class="type">
<span class="param-type">XMLHttpRequest</span>
</td>
Expand All @@ -1563,7 +1562,7 @@ <h4 class="name" id="videoUploadHandler"><span class="type-signature"></span>vid
<td class="description last">
-- Input information --<br>
<strong>isUpdate:</strong> Update audio if true, create audio if false<br>
<strong>element:</strong> If isUpdate is true, the currently selected audio.<br>
<strong>element:</strong> If isUpdate is true, the currently selected audio
</td>
</tr>
<tr>
Expand Down
12 changes: 6 additions & 6 deletions src/lib/core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ export default class SunEditor {

/**
* @description It replaces the default callback function of the image upload
* @param xmlHttpRequest xmlHttpRequest object
* @param xmlHttp xmlHttpRequest object
* @param info Input information
* - linkValue: Link url value
* - linkNewWindow: Open in new window Check Value
Expand All @@ -624,11 +624,11 @@ export default class SunEditor {
* - element: If isUpdate is true, the currently selected image.
* @param core Core object
*/
imageUploadHandler: (xmlHttpRequest: XMLHttpRequest, info: imageInputInformation, core: Core) => void;
imageUploadHandler: (xmlHttp: XMLHttpRequest, info: imageInputInformation, core: Core) => void;

/**
* @description It replaces the default callback function of the video upload
* @param xmlHttpRequest xmlHttpRequest object
* @param xmlHttp xmlHttpRequest object
* @param info Input information
* - inputWidth: Value of width input
* - inputHeight: Value of height input
Expand All @@ -637,17 +637,17 @@ export default class SunEditor {
* - element: If isUpdate is true, the currently selected video.
* @param core Core object
*/
videoUploadHandler: (xmlHttpRequest: XMLHttpRequest, info: videoInputInformation, core: Core) => void;
videoUploadHandler: (xmlHttp: XMLHttpRequest, info: videoInputInformation, core: Core) => void;

/**
* @description It replaces the default callback function of the audio upload
* @param xmlHttpRequest xmlHttpRequest object
* @param xmlHttp xmlHttpRequest object
* @param info Input information
* - isUpdate: Update audio if true, create audio if false
* - element: If isUpdate is true, the currently selected audio.
* @param core Core object
*/
audioUploadHandler: (xmlHttpRequest: XMLHttpRequest, info: audioInputInformation, core: Core) => void;
audioUploadHandler: (xmlHttp: XMLHttpRequest, info: audioInputInformation, core: Core) => void;

/**
* @description Called before the image is uploaded
Expand Down
23 changes: 23 additions & 0 deletions src/lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -6635,6 +6635,29 @@ export default function (context, pluginCallButtons, plugins, lang, options, _ic
*/
imageUploadHandler: null,

/**
* @description It replaces the default callback function of the video upload
* @param xmlHttp xmlHttpRequest object
* @param info Input information
* - inputWidth: Value of width input
* - inputHeight: Value of height input
* - align: Align Check Value
* - isUpdate: Update video if true, create video if false
* - element: If isUpdate is true, the currently selected video.
* @param core Core object
*/
videoUploadHandler: null,

/**
* @description It replaces the default callback function of the audio upload
* @param xmlHttp xmlHttpRequest object
* @param info Input information
* - isUpdate: Update audio if true, create audio if false
* - element: If isUpdate is true, the currently selected audio.
* @param core Core object
*/
audioUploadHandler: null,

/**
* @description Called before the image is uploaded
* If false is returned, no image upload is performed.
Expand Down
Loading

0 comments on commit 1ac8059

Please sign in to comment.