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;
}
37 changes: 30 additions & 7 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,18 @@ const initForm = ({ widget, formElement, formTpl, mediaEditor, togglePlaceholder
);
};

export default function (stateFactory, ActiveState, formTpl, formElement, inlineHelper) {
/**
*
* @param {Object} config
* @param {Object} config.stateFactory
* @param {Object} config.ActiveState
* @param {Object} config.formTpl
* @param {Object} config.formElement
* @param {Object} config.inlineHelper
* @param {Object} config.htmlEditor
* @returns
*/
export default function (config) {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: It could also have been turned into a restructured declaration as mentioned in the coding guide

Suggested change
export default function (config) {
export default function ({ stateFactory, ActiveState, formTpl, formElement, inlineHelper, htmlEditor }) {

If some parameters are mandatory and need to be given anyway, it could also be split into groups:

Suggested change
export default function (config) {
export default function (stateFactory, ActiveState, { formTpl, formElement, inlineHelper, htmlEditor }) {

/**
* media Editor instance if has been initialized
* @type {null}
Expand All @@ -134,8 +147,8 @@ export default function (stateFactory, ActiveState, formTpl, formElement, inline
let textareaObserver = null;
let texareaHTMLElem = null;

const ImgStateActive = stateFactory.extend(
ActiveState,
const ImgStateActive = config.stateFactory.extend(
config.ActiveState,
function () {
this.initForm();
},
Expand All @@ -145,16 +158,17 @@ export default function (stateFactory, ActiveState, formTpl, formElement, inline
textareaObserver.unobserve(texareaHTMLElem);
}
this.widget.$form.empty();
this.destroyEditor();
}
);

ImgStateActive.prototype.initForm = function () {
initForm({
widget: this.widget,
formElement,
formTpl,
formElement: config.formElement,
formTpl: config.formTpl,
mediaEditor,
togglePlaceholder: inlineHelper.togglePlaceholder
togglePlaceholder: config.inlineHelper.togglePlaceholder
});
const figurelem = this.widget.element;
const $texarea = this.widget.$form.find('textarea#figcaption');
Expand All @@ -170,5 +184,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"]');
config.htmlEditor.buildEditor($editableContainer, {});
_.defer(() => {
config.htmlEditor.destroyEditor($editableContainer);
});
};

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