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

HFP 1884 Allow to set text alignment #168

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion css/dragquestion.css
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ html.h5p-iframe .h5p-container.h5p-dragquestion.h5p-semi-fullscreen {
border: 0.1em solid #c6c6c6;
cursor: pointer;
position: absolute;
text-align: center;
padding: 0.3em 0.3em;
line-height: 1.25em;

Expand Down
6 changes: 3 additions & 3 deletions library.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"description": "Drag and drop the elements into the correct drop zones.",
"contentType": "Question",
"majorVersion": 1,
"minorVersion": 14,
"patchVersion": 20,
"minorVersion": 15,
"patchVersion": 0,
"embedTypes": [
"iframe"
],
Expand Down Expand Up @@ -66,4 +66,4 @@
"minorVersion": 0
}
]
}
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "h5p-drag-question",
"version": "1.10.1",
"version": "1.15.0",
"description": "Drag and drop the elements into the correct drop zones.",
"main": "h5p-drag-question.js",
"scripts": {
Expand Down
27 changes: 27 additions & 0 deletions upgrades.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,33 @@ H5PUpgrades['H5P.DragQuestion'] = (function () {
});
}

finished(null, parameters, extras);
},
/**
* Regardless of what alignment was set in the editor, the stylesheet
* would always center the text. For not breaking the view of existing
* content, set all text to be centered in params - can be changed by
* user in the editor after upgrade.
*/
15: function (parameters, finished, extras) {
if (Array.isArray(parameters.question.task.elements)) {
parameters.question.task.elements =
parameters.question.task.elements.map((element) => {
if (
element.type?.library !== 'H5P.AdvancedText 1.1' ||
typeof element.type?.params?.text !== 'string'
) {
return element;
}

element.type.params.text = element.type.params.text.replace(
/<p[^>]*>/g, '<p style="text-align: center;">'
);

return element;
});
}

finished(null, parameters, extras);
}
}
Expand Down