Skip to content

Commit

Permalink
v2.0.1 - cleanup/simplify "handleImageLoad" logic
Browse files Browse the repository at this point in the history
  • Loading branch information
clarketm committed Jul 19, 2020
1 parent cd709a8 commit 13fe38d
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 19 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "image-map",
"version": "2.0.0",
"version": "2.0.1",
"author": {
"name": "Travis Clarke",
"email": "travis.m.clarke@gmail.com",
Expand Down
7 changes: 3 additions & 4 deletions dist/image-map.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function _createClass(Constructor, protoProps, staticProps) {
return Constructor;
}

var version = "2.0.0";
var version = "2.0.1";

var RESIZE = "resize";
var LOAD = "load";
Expand Down Expand Up @@ -108,8 +108,6 @@ var ImageMap = /*#__PURE__*/function () {
return function (e) {
var w = e.target.width;
var h = e.target.height;
var wPercent = offsetWidth / 100;
var hPercent = offsetHeight / 100;
var mapName = e.target.getAttribute(USEMAP).replace(/^#/, "");
var areas = document.querySelectorAll(ImageMap.genAreaSelector(mapName));

Expand All @@ -118,7 +116,8 @@ var ImageMap = /*#__PURE__*/function () {
var coordsString = area.dataset[COORDS] = area.dataset[COORDS] || area.getAttribute(COORDS);
var coordsArrayOld = coordsString.split(",");
var coordsArrayNew = coordsArrayOld.map(function (_, i) {
return i % 2 === 0 ? Number(coordsArrayOld[i] / w * 100 * wPercent) : Number(coordsArrayOld[i] / h * 100 * hPercent);
// Scale the coordinate from the original width/height to the actual rendered width/height (i.e. offset)
return i % 2 === 0 ? Number(coordsArrayOld[i] / w * offsetWidth) : Number(coordsArrayOld[i] / h * offsetHeight);
});
area.setAttribute(COORDS, coordsArrayNew.toString());
};
Expand Down
7 changes: 3 additions & 4 deletions dist/image-map.jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
return Constructor;
}

var version = "2.0.0";
var version = "2.0.1";

var RESIZE = "resize";
var LOAD = "load";
Expand Down Expand Up @@ -113,8 +113,6 @@
return function (e) {
var w = e.target.width;
var h = e.target.height;
var wPercent = offsetWidth / 100;
var hPercent = offsetHeight / 100;
var mapName = e.target.getAttribute(USEMAP).replace(/^#/, "");
var areas = document.querySelectorAll(ImageMap.genAreaSelector(mapName));

Expand All @@ -123,7 +121,8 @@
var coordsString = area.dataset[COORDS] = area.dataset[COORDS] || area.getAttribute(COORDS);
var coordsArrayOld = coordsString.split(",");
var coordsArrayNew = coordsArrayOld.map(function (_, i) {
return i % 2 === 0 ? Number(coordsArrayOld[i] / w * 100 * wPercent) : Number(coordsArrayOld[i] / h * 100 * hPercent);
// Scale the coordinate from the original width/height to the actual rendered width/height (i.e. offset)
return i % 2 === 0 ? Number(coordsArrayOld[i] / w * offsetWidth) : Number(coordsArrayOld[i] / h * offsetHeight);
});
area.setAttribute(COORDS, coordsArrayNew.toString());
};
Expand Down
7 changes: 3 additions & 4 deletions dist/image-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
return Constructor;
}

var version = "2.0.0";
var version = "2.0.1";

var RESIZE = "resize";
var LOAD = "load";
Expand Down Expand Up @@ -114,8 +114,6 @@
return function (e) {
var w = e.target.width;
var h = e.target.height;
var wPercent = offsetWidth / 100;
var hPercent = offsetHeight / 100;
var mapName = e.target.getAttribute(USEMAP).replace(/^#/, "");
var areas = document.querySelectorAll(ImageMap.genAreaSelector(mapName));

Expand All @@ -124,7 +122,8 @@
var coordsString = area.dataset[COORDS] = area.dataset[COORDS] || area.getAttribute(COORDS);
var coordsArrayOld = coordsString.split(",");
var coordsArrayNew = coordsArrayOld.map(function (_, i) {
return i % 2 === 0 ? Number(coordsArrayOld[i] / w * 100 * wPercent) : Number(coordsArrayOld[i] / h * 100 * hPercent);
// Scale the coordinate from the original width/height to the actual rendered width/height (i.e. offset)
return i % 2 === 0 ? Number(coordsArrayOld[i] / w * offsetWidth) : Number(coordsArrayOld[i] / h * offsetHeight);
});
area.setAttribute(COORDS, coordsArrayNew.toString());
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "image-map",
"version": "2.0.0",
"version": "2.0.1",
"description": "Response, dynamic image maps",
"main": "dist/image-map.js",
"module": "dist/image-map.es.js",
Expand Down
9 changes: 4 additions & 5 deletions src/image-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ class ImageMap {
return e => {
const w = e.target.width;
const h = e.target.height;
const wPercent = offsetWidth / 100;
const hPercent = offsetHeight / 100;
const mapName = e.target.getAttribute(USEMAP).replace(/^#/, "");

const areas = document.querySelectorAll(ImageMap.genAreaSelector(mapName));
Expand All @@ -75,9 +73,10 @@ class ImageMap {

const coordsString = (area.dataset[COORDS] = area.dataset[COORDS] || area.getAttribute(COORDS));
const coordsArrayOld = coordsString.split(",");
const coordsArrayNew = coordsArrayOld.map((_, i) =>
i % 2 === 0 ? Number((coordsArrayOld[i] / w) * 100 * wPercent) : Number((coordsArrayOld[i] / h) * 100 * hPercent)
);
const coordsArrayNew = coordsArrayOld.map((_, i) => {
// Scale the coordinate from the original width/height to the actual rendered width/height (i.e. offset)
return i % 2 === 0 ? Number((coordsArrayOld[i] / w) * offsetWidth) : Number((coordsArrayOld[i] / h) * offsetHeight);
});
area.setAttribute(COORDS, coordsArrayNew.toString());
}
};
Expand Down

0 comments on commit 13fe38d

Please sign in to comment.