Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicated image node when updateing already inserted image. [5.1.x] #1370

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions src/pat/tinymce/js/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,10 @@ export default Base.extend({
self.tiny.selection.setRng(self.rng);
var cssclasses = [
"image-richtext",
self.$align.val(),
];
if(self.$align.val()) {
cssclasses.push(self.$align.val());
}
if(self.linkType !== "externalImage"){
cssclasses.push("picture-variant-" + self.$scale.val())
}
Expand All @@ -692,19 +694,16 @@ export default Base.extend({
if (enableImageZoom) {
cssclasses.push("zoomable");
}
var data = $.extend(
true,
{},
{
"src": src,
"title": title ? title : null,
"alt": self.$alt.val(),
"class": cssclasses.join(" "),
"data-linkType": self.linkType,
"data-scale": self.getScaleFromSrcset(self.$scale.val()),
},
self.linkTypes[self.linkType].attributes()
);
var data = {
"src": src,
"title": title ? title : null,
"alt": self.$alt.val(),
"class": cssclasses.join(" "),
"data-linkType": self.linkType,
"data-scale": self.getScaleFromSrcset(self.$scale.val()),
...self.linkTypes[self.linkType].attributes()
};

if(self.linkType !== "externalImage"){
data["data-picturevariant"] = self.$scale.val();
}
Expand All @@ -714,12 +713,12 @@ export default Base.extend({
}
if (self.imgElm && !self.imgElm.getAttribute("data-mce-object")) {
const imgWidth = self.dom.getAttrib(self.imgElm, "width");
const imgHight = self.dom.getAttrib(self.imgElm, "height");
const imgHeight = self.dom.getAttrib(self.imgElm, "height");
if (imgWidth) {
data.width = imgWidth;
}
if (imgHight) {
data.height = imgHight;
if (imgHeight) {
data.height = imgHeight;
}
} else {
self.imgElm = null;
Expand All @@ -732,13 +731,14 @@ export default Base.extend({
};
}

data.id = "__mcenew";
var html_inner = self.dom.createHTML("img", data);
var html_string;
html_string = html_inner;
self.tiny.insertContent(html_string);
self.imgElm = self.dom.get("__mcenew");
self.dom.setAttrib(self.imgElm, "id", null);
var newImgElm = self.dom.create("img", data);

if(self.imgElm && self.imgElm.tagName.toLowerCase() == "img") {
self.imgElm.replaceWith(newImgElm);
} else {
self.rng.insertNode(newImgElm);
}
self.imgElm = newImgElm;

waitLoad(self.imgElm);
if (self.imgElm.complete) {
Expand Down