Skip to content

Commit

Permalink
small fixes :
Browse files Browse the repository at this point in the history
- no more default href in constructor
- better prompt for href
- unshift the bgLayer
  • Loading branch information
n-peugnet committed Mar 6, 2018
1 parent b64137d commit 6cc4d99
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/class.area.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Area {
* @param {XY[]} coords the list of coordinates
* @param {string} href the link this area is going to point to
*/
constructor(shape, coords = [], href = "http://") {
constructor(shape, coords = [], href) {
this.shape = shape;
this.coords = coords;
this.href = href;
Expand Down Expand Up @@ -37,7 +37,7 @@ class Area {
}

class AreaRect extends Area {
constructor(coords = [], href = "http://") {
constructor(coords = [], href) {
super("rect");
this.coords = coords.slice(0, 2);
if (this.coords.length < 2)
Expand All @@ -63,12 +63,12 @@ class AreaRect extends Area {
}

class AreaCircle extends Area {
constructor(coords = [], href = "http://") {
constructor(coords = [], href) {
super("circle", coords, href);
}
}
class AreaPoly extends Area {
constructor(coords = [], href = "http://") {
constructor(coords = [], href) {
super("poly", coords, href);
}
}
6 changes: 5 additions & 1 deletion src/class.image-map.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class ImageMap {

/**
*
* Contructor
* @param {Area[]} areas
* @param {string} image
*/
Expand All @@ -10,6 +10,10 @@ class ImageMap {
this.image = image;
}

unshiftArea(area) {
this.areas.unshift(area);
}

addArea(area) {
this.areas.push(area);
}
Expand Down
8 changes: 4 additions & 4 deletions src/p5.image-map-creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ var imageMapCreator = function (p) {
} else if (p.mouseButton == p.RIGHT) {
var area = p.mouseIsHoverArea();
if (area != undefined) {
var input = prompt("Entrez l'url vers laquelle devrait pointer cette zone", area.href);
if (input)
var input = prompt("Entrez l'url vers laquelle devrait pointer cette zone", area.href ? area.href : "http://" );
if (input != null)
area.href = input;
}
return false;
Expand All @@ -61,7 +61,7 @@ var imageMapCreator = function (p) {

p.mouseIsHoverArea = function () {
var allAreas = p.map.areas.slice();
return area = allAreas.reverse().find(area => {
return allAreas.reverse().find(area => {
return area.isHover(p.mouseX, p.mouseY);
});
}
Expand Down Expand Up @@ -105,7 +105,7 @@ var imageMapCreator = function (p) {
p.addBgArea = function () {
var coords = [new XY(0, 0), new XY(p.width - 1, p.height - 1)];
var area = new AreaRect(coords);
p.map.addArea(area);
p.map.unshiftArea(area);
}

//---------------------------- P5 Classes ---------------------------------
Expand Down

0 comments on commit 6cc4d99

Please sign in to comment.