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/AUT-2673/inline-figure-img #528

Merged
merged 12 commits into from
Nov 28, 2022
4 changes: 4 additions & 0 deletions scss/inc/_feedback.scss
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,7 @@
.bg-error {
background-color: $errorBgColor;
}

textarea + .feedback-info {
padding: 5px;
}
16 changes: 14 additions & 2 deletions src/figure/FigureStateActive.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,14 @@ const formCallbacks = ({ widget, formElement, mediaEditor, togglePlaceholder })
const initForm = ({ widget, formElement, formTpl, mediaEditor, togglePlaceholder }) => {
const imageElem = getImageElement(widget);
const figcaptionElem = getCaptionElement(widget);
const showFigure = widget.element.attr('showFigure');
widget.$form.html(
formTpl({
baseUrl: widget.options.baseUrl || '',
src: imageElem.attr('src'),
alt: imageElem.attr('alt'),
figcaption: figcaptionElem ? figcaptionElem.body() : ''
figcaption: figcaptionElem ? figcaptionElem.body() : '',
showFigure: showFigure
})
);

Expand All @@ -125,7 +127,7 @@ const initForm = ({ widget, formElement, formTpl, mediaEditor, togglePlaceholder
);
};

export default function (stateFactory, ActiveState, formTpl, formElement, inlineHelper) {
export default function (stateFactory, ActiveState, formTpl, formElement, inlineHelper, htmlEditor) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quibble: The signatures becomes heavier and heavier. Maybe it is the right time to think about simplifying it. If the API is not used in too many places, it could be simplified with a config object, allowing to addition of more entries without breaking the signature.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!

/**
* media Editor instance if has been initialized
* @type {null}
Expand All @@ -145,6 +147,7 @@ export default function (stateFactory, ActiveState, formTpl, formElement, inline
textareaObserver.unobserve(texareaHTMLElem);
}
this.widget.$form.empty();
this.destroyEditor();
}
);

Expand All @@ -170,5 +173,14 @@ export default function (stateFactory, ActiveState, formTpl, formElement, inline
}
};

ImgStateActive.prototype.destroyEditor = function () {
const widget = this.widget;
const $editableContainer = widget.$original.parents('[data-qti-class="_container"]');
htmlEditor.buildEditor($editableContainer, {});
_.defer(() => {
htmlEditor.destroyEditor($editableContainer);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Why building then destroying the editor immediately?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CKEditor reads the Figure HTML tag, and if it is inside a block, it moves out of it.
To achieve this effect, I must rebuild the editor, but I don't want to have it active, so I destroy it afterwards. Otherwise, I will have an error in the XML structure.

};

return ImgStateActive;
}
7 changes: 6 additions & 1 deletion src/mediaEditor/plugins/mediaAlignment/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@ export const positionFloat = function positionFloat(widget, position) {
// Update DOM
widget.$container.addClass(className);
// Update model
const prevClassName = widget.element.attr('class');
if (className) {
widget.element.attr('class', className);
} else {
widget.element.removeAttr('class');
}


if ((prevClassName || className.length) && prevClassName !== className) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Why test the value only for one variable and the length only for the other variable? Both are string, so it could be tested by value for both...

suggestion:

Suggested change
if ((prevClassName || className.length) && prevClassName !== className) {
if ((prevClassName || className) && prevClassName !== className) {

// Re-build Figure widget to toggle between inline/block
widget.refresh(widget.$container);
}
widget.$original.trigger('contentChange.qti-widget');
};

Expand Down