From da61ca0b5615d93a27c22c42bc7686dd568d7402 Mon Sep 17 00:00:00 2001 From: Hanna Dzmitryieva Date: Tue, 18 Oct 2022 09:09:15 +0200 Subject: [PATCH 1/5] fix: count scale of background for coords --- src/qtiCommonRenderer/helpers/Graphic.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/qtiCommonRenderer/helpers/Graphic.js b/src/qtiCommonRenderer/helpers/Graphic.js index 244e660b..7cd71b1c 100644 --- a/src/qtiCommonRenderer/helpers/Graphic.js +++ b/src/qtiCommonRenderer/helpers/Graphic.js @@ -467,13 +467,14 @@ var GraphicHelper = { * @param {Raphael.Element} element - the shape to get the coords from * @returns {String} the QTI coords */ - qtiCoords: function qtiCoords(element) { + qtiCoords: function qtiCoords(element, paper, width) { var mapper = raph2qtiCoordsMapper[element.type]; var result = ''; + var factor = paper && width ? width / paper.w : 1; if (_.isFunction(mapper)) { result = _.map(mapper.call(raph2qtiCoordsMapper, element.attr()), function(coord) { - return _.parseInt(coord); + return Math.round(coord * factor); }).join(','); } From 6080f40a923a9055e762ffa9af5c9736361e3f60 Mon Sep 17 00:00:00 2001 From: Hanna Dzmitryieva Date: Tue, 18 Oct 2022 12:05:37 +0200 Subject: [PATCH 2/5] fix: use only givenWidth --- src/qtiCommonRenderer/helpers/Graphic.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/qtiCommonRenderer/helpers/Graphic.js b/src/qtiCommonRenderer/helpers/Graphic.js index 7cd71b1c..0f4caed6 100644 --- a/src/qtiCommonRenderer/helpers/Graphic.js +++ b/src/qtiCommonRenderer/helpers/Graphic.js @@ -225,23 +225,20 @@ var GraphicHelper = { * @private */ function resizePaper(e, givenWidth) { - var diff, maxWidth, containerWidth, containerHeight, factor; + var maxWidth, containerWidth, containerHeight, factor; if (e) { e.stopPropagation(); } - diff = $editor.outerWidth() - $editor.width() + ($container.outerWidth() - $container.width()) + 1; maxWidth = $body.width(); - containerWidth = $container.innerWidth(); + containerWidth = $editor.innerWidth(); - if (containerWidth > 0 || givenWidth > 0) { - if (givenWidth < containerWidth && givenWidth < maxWidth) { - containerWidth = givenWidth - diff; - } else if (containerWidth > maxWidth) { - containerWidth = maxWidth - diff; + if (givenWidth > 0) { + if (givenWidth < maxWidth) { + containerWidth = givenWidth; } else { - containerWidth -= diff; + containerWidth = maxWidth; } factor = containerWidth / imgWidth; From 4a07108f461b8d38fddac9f013d1663f6f25df6b Mon Sep 17 00:00:00 2001 From: Hanna Dzmitryieva Date: Tue, 18 Oct 2022 12:28:18 +0200 Subject: [PATCH 3/5] fix: resize on screen resize --- src/qtiCommonRenderer/helpers/Graphic.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/qtiCommonRenderer/helpers/Graphic.js b/src/qtiCommonRenderer/helpers/Graphic.js index 0f4caed6..d2adc9d7 100644 --- a/src/qtiCommonRenderer/helpers/Graphic.js +++ b/src/qtiCommonRenderer/helpers/Graphic.js @@ -195,6 +195,7 @@ var GraphicHelper = { var imgWidth = options.width || $container.innerWidth(); var imgHeight = options.height || $container.innerHeight(); + paper = scaleRaphael(id, imgWidth, imgHeight); image = paper.image(options.img, 0, 0, imgWidth, imgHeight); image.id = options.imgId || image.id; @@ -234,10 +235,10 @@ var GraphicHelper = { maxWidth = $body.width(); containerWidth = $editor.innerWidth(); - if (givenWidth > 0) { - if (givenWidth < maxWidth) { + if (givenWidth > 0 || containerWidth > maxWidth) { + if (givenWidth > 0 && givenWidth < maxWidth) { containerWidth = givenWidth; - } else { + } else if (containerWidth > maxWidth) { containerWidth = maxWidth; } @@ -251,9 +252,8 @@ var GraphicHelper = { if (typeof options.resize === 'function') { options.resize(containerWidth, factor); } - - $container.trigger('resized.qti-widget'); } + $container.trigger('resized.qti-widget'); } return paper; From b6e254adbe1ddb17f62fc74d2f954737fb98dcb2 Mon Sep 17 00:00:00 2001 From: Hanna Dzmitryieva Date: Tue, 18 Oct 2022 15:47:33 +0200 Subject: [PATCH 4/5] chore: JSDoc --- src/qtiCommonRenderer/helpers/Graphic.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/qtiCommonRenderer/helpers/Graphic.js b/src/qtiCommonRenderer/helpers/Graphic.js index d2adc9d7..a962f2bb 100644 --- a/src/qtiCommonRenderer/helpers/Graphic.js +++ b/src/qtiCommonRenderer/helpers/Graphic.js @@ -462,6 +462,8 @@ var GraphicHelper = { /** * Get the QTI coordinates from a Raphael Element * @param {Raphael.Element} element - the shape to get the coords from + * @param {Raphael.Element} paper - the interaction paper + * @param {number} width - width of background image * @returns {String} the QTI coords */ qtiCoords: function qtiCoords(element, paper, width) { From f56b7772177975154a91c0fcf755d8ab787c1382 Mon Sep 17 00:00:00 2001 From: Hanna Dzmitryieva Date: Wed, 19 Oct 2022 14:19:40 +0200 Subject: [PATCH 5/5] chore: bump version --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4706c5e2..bc200c56 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@oat-sa/tao-item-runner-qti", - "version": "1.5.2", + "version": "1.5.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 1602de20..ae715a40 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@oat-sa/tao-item-runner-qti", - "version": "1.5.2", + "version": "1.5.3", "displayName": "TAO Item Runner QTI", "description": "TAO QTI Item Runner modules", "files": [