Skip to content

Commit

Permalink
Added timeout on adding listeners do avoid latency issue
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsharman committed Jun 26, 2024
1 parent 9ccf3c9 commit ed2b5c6
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion dist/assessment/core.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/assessment/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/authoring/core.js

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

2 changes: 1 addition & 1 deletion dist/authoring/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const version = '2.13.1';
export const version = '2.13.2';
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": "@caspingus/lt",
"version": "2.13.1",
"version": "2.13.2",
"description": "A utility library of helpers and tools for working with Learnosity APIs.",
"author": "michael@learnosity.com",
"license": "MIT",
Expand Down
25 changes: 14 additions & 11 deletions src/authoring/extensions/ui/imageUploader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,7 @@ function setupUploderUI() {
wrapper.setAttribute('id', 'uppy-dashboard');
lrnImageUploader.insertAdjacentElement('afterbegin', wrapper);

const modalParent = document.querySelector('.lrn-modal-dialog');
prepareModalButtons(modalParent);
prepareModalButtons();

elMoreOptions.removeAttribute('hidden');

Expand Down Expand Up @@ -438,10 +437,10 @@ function uploadImage(fileId) {
const src = document.querySelector('[data-authorapi-selector="asset-uploader-source"]');
src.value = assetUrl.trim();
src.dispatchEvent(new Event('input', { bubbles: true }));
logger.debug('Added image path to URI', LOG_LEVEL);

setTimeout(() => {
const modalParent = document.querySelector('.lrn-modal');
prepareModalButtons(modalParent);
prepareModalButtons();
}, 1500);
})
.catch(error => console.error('Error in uploading image:', error));
Expand All @@ -456,18 +455,22 @@ function uploadImage(fileId) {
* @ignore
* @param {object} modalParent
*/
function prepareModalButtons(modalParent) {
function prepareModalButtons() {
logger.debug('prepareModalButtons()', LOG_LEVEL);
const elCloseButtons = ['lrn-modal-button-close', 'lrn-btn-default', 'lrn-btn-primary-legacy'];
const modalParent = document.querySelector('.lrn-modal');

removeHandler();

for (let btn of elCloseButtons) {
let elBtn = modalParent.querySelector(`.lrn-modal-dialog button.${btn}`);
if (elBtn) {
logger.debug(`Adding clickHanders for: ${btn}`, LOG_LEVEL);
elBtn.addEventListener('click', clickHandler);
setTimeout(() => {
for (let btn of elCloseButtons) {
let elBtn = modalParent.querySelector(`.lrn-modal-dialog button.${btn}`);
if (elBtn) {
logger.debug(`Adding clickHanders for: ${btn}`, LOG_LEVEL);
elBtn.addEventListener('click', clickHandler);
}
}
}
}, 750);

function clickHandler() {
logger.debug('clickHandler()', LOG_LEVEL);
Expand Down

0 comments on commit ed2b5c6

Please sign in to comment.