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

Hotfix/aut 2673/inline figure img to November release #459

Merged
merged 8 commits into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion views/js/loader/taoMediaManager.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion views/js/loader/taoMediaManager.min.js.map

Large diffs are not rendered by default.

42 changes: 38 additions & 4 deletions views/js/qtiCreator/renderers/Img.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,22 @@
define([
'lodash',
'taoQtiItem/qtiCommonRenderer/renderers/Img',
'taoMediaManager/qtiCreator/widgets/static/img/Widget'
], function (_, Renderer, Widget) {
'taoMediaManager/qtiCreator/widgets/static/img/Widget',
'taoQtiItem/qtiCreator/widgets/static/figure/Widget',
'taoQtiItem/qtiCreator/model/Figure',
'taoQtiItem/qtiCreator/helper/findParentElement'
], function (_, Renderer, Widget, FigureWidget, FigureModel, findParentElement) {
'use strict';

const CreatorImg = _.clone(Renderer);

CreatorImg.render = function render(img, options) {
const $container = Renderer.getContainer(img);
if ($container.parent('figure').length) {
if ($container.parent('figure').length || $container.parent('span').length && $container.parent('span').data('figure')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Discrepancy with original PR is this expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here backport for 2 PRs, this changes from second #457

// don't create widget if has figure parent
if (!$container.parent('figure').length && $container.siblings('figcaption').length) {
$container.siblings('figcaption').remove();
}
return CreatorImg;
}

Expand All @@ -39,7 +45,35 @@ define([
options.mediaManager = this.getOption('mediaManager');
options.assetManager = this.getAssetManager();

Widget.build(img, Renderer.getContainer(img), this.getOption('bodyElementOptionForm'), options);
if (
!$container.closest('.qti-choice, .qti-flow-container').length &&
!$container.closest('.qti-table caption').length
) {
const parent = findParentElement(img.rootElement, img.serial);
parent.removeElement(img);
const figure = new FigureModel();
parent.setElement(figure);
const figureRenderer = parent.getRenderer();
if (figureRenderer) {
figure.setRenderer(figureRenderer);
figureRenderer.load(() => { }, ['figure']);
}
figure.setElement(img);
const $wrap = $container.wrap(`<span data-serial="${figure.serial}">`).parent();
FigureWidget.build(
figure,
$wrap,
this.getOption('bodyElementOptionForm'),
options
);
} else {
Widget.build(
img,
Renderer.getContainer(img),
this.getOption('bodyElementOptionForm'),
options
);
}
};

return CreatorImg;
Expand Down
8 changes: 7 additions & 1 deletion views/js/qtiCreator/widgets/static/figure/Widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ define([
};

FigureWidget.buildContainer = function buildContainer() {
helper.buildBlockContainer(this);
if (this.element.attr('showFigure')) {
// If it is aligned to left or right, it will have FigCaption and will need Figure tag
helper.buildBlockContainer(this);
} else {
// On inline aligment, it must be an Image
helper.buildInlineContainer(this);
}
const img = _.find(this.element.getBody().elements, elem => elem.is('img'));
const $img = this.$original.find('img');
if ($img.length) {
Expand Down
4 changes: 2 additions & 2 deletions views/js/qtiCreator/widgets/static/figure/states/Active.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ define([
'taoQtiItem/qtiCreator/widgets/helpers/formElement',
'taoQtiItem/qtiCreator/widgets/static/helpers/inline',
'ui/figure/FigureStateActive',
], function (stateFactory, ActiveState, formTpl, formElement, inlineHelper, FigureStateActive) {
], function (stateFactory, ActiveState, formTpl, formElement, inlineHelper,FigureStateActive) {
'use strict';
return FigureStateActive(stateFactory, ActiveState, formTpl, formElement, inlineHelper);
return FigureStateActive({ stateFactory, ActiveState, formTpl, formElement, inlineHelper });
});