Skip to content

Commit

Permalink
add: #603 options.mediaAuthSelect
Browse files Browse the repository at this point in the history
  • Loading branch information
JiHong88 committed Jan 28, 2021
1 parent 378f31b commit 3b83f4e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/lib/constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ export default {
options.templates = !options.templates ? null : options.templates;
/** ETC */
options.placeholder = typeof options.placeholder === 'string' ? options.placeholder : null;
options.mediaAutoSelect = options.mediaAutoSelect === undefined ? true : !!options.mediaAutoSelect;
/** Buttons */
options.buttonList = !!options.buttonList ? options.buttonList : [
['undo', 'redo'],
Expand Down
28 changes: 18 additions & 10 deletions src/options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,22 @@ export interface SunEditorOptions {
* Define position to the table cell controller. ('cell', 'top')
*/
tableCellControllerPosition?: string;
/**
* Link
* =====
*/
/**
* Protocol for the links (if link has been added without any protocol this one will be used).
*/
linkProtocol?: string;
/**
* Defines "rel" attribute list of anchor tag.
*/
linkRel?: string[];
/**
* Defines default "rel" attribute list of anchor tag.
*/
linkRelDefault?: {default?: string; check_new_window?: string; check_bookmark?: string;};
/**
* Key actions
* =====
Expand Down Expand Up @@ -476,17 +492,9 @@ export interface SunEditorOptions {
*/
placeholder?: string;
/**
* Protocol for the links (if link has been added without any protocol this one will be used).
*/
linkProtocol?: string;
/**
* Defines "rel" attribute list of anchor tag.
*/
linkRel?: string[];
/**
* Defines default "rel" attribute list of anchor tag.
* Choose whether to activate the media selection status immediately after inserting the media tag. (default: true)
*/
linkRelDefault?: {default?: string; check_new_window?: string; check_bookmark?: string;};
mediaAutoSelect?: boolean;
/**
* You can redefine icons.
*/
Expand Down
8 changes: 6 additions & 2 deletions src/plugins/dialog/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,23 +425,27 @@ export default {
element.src = src;
const cover = this.plugins.component.set_cover.call(this, element);
const container = this.plugins.component.set_container.call(this, cover, '');
if (!this.insertComponent(container, false, true, false)) {
if (!this.insertComponent(container, false, true, !this.options.mediaAutoSelect)) {
this.focus();
return;
}
if (!this.options.mediaAutoSelect) {
const line = this.appendFormatTag(container, null);
this.setRange(line, 0, line, 0);
}
} // update
else {
if (contextAudio._element) element = contextAudio._element;
if (element && element.src !== src) {
element.src = src;
this.selectComponent(element, 'audio');
} else {
this.selectComponent(element, 'audio');
return;
}
}

this.plugins.fileManager.setInfo.call(this, 'audio', element, this.functions.onAudioUpload, file, false);
this.selectComponent(element, 'audio');
if (isUpdate) this.history.push(false);
},

Expand Down
11 changes: 8 additions & 3 deletions src/plugins/dialog/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,15 +660,20 @@ export default {
// align
imagePlugin.setAlign.call(this, align, oImg, cover, container);

oImg.onload = imagePlugin._image_create_onload.bind(this, oImg, contextImage.svgDefaultSize);
oImg.onload = imagePlugin._image_create_onload.bind(this, oImg, contextImage.svgDefaultSize, container);
if (this.insertComponent(container, true, true, true)) this.plugins.fileManager.setInfo.call(this, 'image', oImg, this.functions.onImageUpload, file, true);
this.context.resizing._resize_plugin = '';
},

_image_create_onload: function (oImg, svgDefaultSize) {
_image_create_onload: function (oImg, svgDefaultSize, container) {
// svg exception handling
if (oImg.offsetWidth === 0) this.plugins.image.applySize.call(this, svgDefaultSize, '');
this.selectComponent.call(this, oImg, 'image');
if (this.options.mediaAutoSelect) {
this.selectComponent(oImg, 'image');
} else {
const line = this.appendFormatTag(container, null);
this.setRange(line, 0, line, 0);
}
},

update_image: function (init, openController, notHistoryPush) {
Expand Down
6 changes: 5 additions & 1 deletion src/plugins/dialog/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,11 @@ export default {

let changed = true;
if (!isUpdate) {
changed = this.insertComponent(container, false, true, false);
changed = this.insertComponent(container, false, true, !this.options.mediaAutoSelect);
if (!this.options.mediaAutoSelect) {
const line = this.appendFormatTag(container, null);
this.setRange(line, 0, line, 0);
}
} else if (contextVideo._resizing && this.context.resizing._rotateVertical && changeSize) {
this.plugins.resizing.setTransformSize.call(this, oFrame, null, null);
}
Expand Down
1 change: 1 addition & 0 deletions test/dev/suneditor_build_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ let ss = window.ss = suneditor.create(document.getElementById('editor1'), {
value: "aa",
stickyToolbar: 50,
fullScreenOffset: '10px',
mediaAutoSelect: false,
// rtl: true,
// fullPage: true,
// pasteTagsWhitelist: 'p|a|strong|em|h3|h4|h5|ul|ol|li|blockquote|table|thead|tbody|tfoot|tr|td|sup|sub',
Expand Down

0 comments on commit 3b83f4e

Please sign in to comment.