Skip to content

Commit

Permalink
add: #654 options-imageGalleryHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
JiHong88 committed Mar 9, 2021
1 parent 4e22c3e commit b566095
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ imageGalleryUrl : The url of the image gallery, if you use the image gallery
]
}
You can redefine the "plugins.imageGallery.drawItems" method.
imageGalleryHeader: Http Header when get image gallery. default: null {Object}

// Video----------------------------------------------------------------------------------------------------------
videoResizing : Can resize the video (iframe, video). default: true {Boolean}
Expand Down
5 changes: 4 additions & 1 deletion sample/html/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,11 @@ <h4 style="color: #b94a48;">--Image</h4>
<label><input type="checkbox" id="imageAccept">&nbsp;&nbsp;imageAccept</label>
<input type="text" id="imageAccept_value" placeholder='String( * or .jpg, .png...)'>
<br>
<h4 style="color: #b94a48;">--Image - image gallery</h4>
<h4 style="color: #b94a48;">--image gallery</h4>
<label><input type="checkbox" id="imageGalleryUrl" checked>&nbsp;&nbsp;imageGalleryUrl</label>
<input type="text" id="imageGalleryUrl_value" placeholder="String(URL address)" style="width: 200px" value="https://etyswjpn79.execute-api.ap-northeast-1.amazonaws.com/suneditor-demo">
<label><input type="checkbox" id="imageGalleryHeader" checked>&nbsp;&nbsp;imageGalleryHeader</label>
<textarea id="imageGalleryHeader_value" placeholder='{"xxx": "xxx"}' style="width: 300px; vertical-align: top;"></textarea>

<br>
<h4 style="color: #b94a48;">--Video</h4>
Expand Down Expand Up @@ -601,6 +603,7 @@ <h2 class="sub-title">Applied options</h2>
imageUploadSizeLimit: document.getElementById('imageUploadSizeLimit').checked ? document.getElementById('imageUploadSizeLimit_value').value : undefined,
imageAccept: document.getElementById('imageAccept').checked ? document.getElementById('imageAccept_value').value : undefined,
imageGalleryUrl: document.getElementById('imageGalleryUrl').checked ? document.getElementById('imageGalleryUrl_value').value : undefined,
imageGalleryHeader: document.getElementById('imageGalleryHeader').checked ? JSON.parse(document.getElementById('imageGalleryHeader_value').value) : undefined,
videoResizing: document.getElementById('videoResizing').checked ? undefined : false,
videoHeightShow: document.getElementById('videoHeightShow').checked ? undefined : false,
videoFileInput: document.getElementById('videoFileInput').checked ? undefined : false,
Expand Down
1 change: 1 addition & 0 deletions src/lib/constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ export default {
options.imageAccept = (typeof options.imageAccept !== 'string' || options.imageAccept.trim() === "*") ? 'image/*' : options.imageAccept.trim() || 'image/*';
/** Image - image gallery */
options.imageGalleryUrl = typeof options.imageGalleryUrl === 'string' ? options.imageGalleryUrl : null;
options.imageGalleryHeader = options.imageGalleryHeader || null;
/** Video */
options.videoResizing = options.videoResizing === undefined ? true : options.videoResizing;
options.videoHeightShow = options.videoHeightShow === undefined ? true : !!options.videoHeightShow;
Expand Down
6 changes: 6 additions & 0 deletions src/options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,15 @@ export interface SunEditorOptions {
/**
* Image - image gallery
* =====
*/
/**
* The url of the image gallery, if you use the image gallery
*/
imageGalleryUrl?: string;
/**
* Http Header when get image gallery.
*/
imageGalleryHeader?: Record<string, string>;
/**
* Video
* =====
Expand Down
1 change: 1 addition & 0 deletions src/plugins/fileBrowser/imageGallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default {
context.imageGallery = {
title: core.lang.toolbar.imageGallery, // @Required @Override fileBrowser - File browser window title.
url: core.options.imageGalleryUrl, // @Required @Override fileBrowser - File server url.
header: core.options.imageGalleryHeader, // @Required @Override fileBrowser - File server http header.
listClass: 'se-image-list', // @Required @Override fileBrowser - Class name of list div.
itemTemplateHandler: this.drawItems, // @Required @Override fileBrowser - Function that defines the HTML of an file item.
selectorHandler: this.setImage.bind(core), // @Required @Override fileBrowser - Function that action when item click.
Expand Down
9 changes: 7 additions & 2 deletions src/plugins/modules/fileBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
fileBrowserContext.titleArea.textContent = pluginContext.title;
fileBrowserContext.area.style.display = 'block';

this.plugins.fileBrowser._drawFileList.call(this, this.context[pluginName].url);
this.plugins.fileBrowser._drawFileList.call(this, this.context[pluginName].url, this.context[pluginName].header);
},

_bindClose: null,
Expand Down Expand Up @@ -208,11 +208,16 @@
this._loading.style.display = 'none';
},

_drawFileList: function (url) {
_drawFileList: function (url, browserHeader) {
const fileBrowserPlugin = this.plugins.fileBrowser;

const xmlHttp = fileBrowserPlugin._xmlHttp = this.util.getXMLHttpRequest();
xmlHttp.onreadystatechange = fileBrowserPlugin._callBackGet.bind(this, xmlHttp);
if(browserHeader !== null && typeof browserHeader === 'object' && this._w.Object.keys(browserHeader).length > 0){
for(let key in browserHeader){
xmlHttp.setRequestHeader(key, browserHeader[key]);
}
}
xmlHttp.open('get', url, true);
xmlHttp.send(null);

Expand Down

0 comments on commit b566095

Please sign in to comment.