Skip to content

Commit

Permalink
Resolves #338 - Fix event listener issues
Browse files Browse the repository at this point in the history
  • Loading branch information
techfg committed Jan 20, 2021
1 parent b2d4dfd commit 8895993
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 16 deletions.
20 changes: 13 additions & 7 deletions dist/jquery.imagemapster.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* imagemapster - v1.3.2-beta.0 - 2021-01-19
* imagemapster - v1.3.2-beta.0 - 2021-01-20
* https://github.com/jamietre/ImageMapster/
* Copyright (c) 2011 - 2021 James Treworgy
* License: MIT
Expand Down Expand Up @@ -510,7 +510,9 @@
this.impl = null;
$.fn.mapster = null;
$.mapster = null;
$('*').off();
// Note - We intentionally do not remove tooltip ns here in order to ensure
// that if a tooltip is currently open it can still be closed
return $('*').off('.mapster');
}
};

Expand Down Expand Up @@ -1112,7 +1114,6 @@
me.unbind.apply(img);
if (!md.complete) {
// will be queued
img.on();
return true;
}
md = null;
Expand Down Expand Up @@ -1883,10 +1884,10 @@
index = me._add(image[0]);

image
.on('load', function (e) {
.on('load.mapster', function (e) {
me.imageLoaded.call(me, e);
})
.on('error', function (e) {
.on('error.mapster', function (e) {
me.imageLoadError.call(me, e);
});

Expand Down Expand Up @@ -3959,12 +3960,17 @@
beforeClose,
onClose
) {
var event_name = event + '.mapster-tooltip';
// Tooltip namespace is intentionally different from standard
// .mapster namespace because if tooltip is open when mapster
// is unbound, there wouldn't be a way to close the tooltip
// if the event listener was removed.
var tooltip_ns = '.mapster-tooltip',
event_name = event + tooltip_ns;

if ($.inArray(bindOption, options) >= 0) {
target.off(event_name).on(event_name, function (e) {
if (!beforeClose || beforeClose.call(this, e)) {
target.off('.mapster-tooltip');
target.off(tooltip_ns);
if (onClose) {
onClose.call(this);
}
Expand Down
4 changes: 2 additions & 2 deletions dist/jquery.imagemapster.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/jquery.imagemapster.min.js.map

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,9 @@
this.impl = null;
$.fn.mapster = null;
$.mapster = null;
$('*').off();
// Note - We intentionally do not remove tooltip ns here in order to ensure
// that if a tooltip is currently open it can still be closed
return $('*').off('.mapster');
}
};

Expand Down Expand Up @@ -1023,7 +1025,6 @@
me.unbind.apply(img);
if (!md.complete) {
// will be queued
img.on();
return true;
}
md = null;
Expand Down
4 changes: 2 additions & 2 deletions src/mapimage.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@
index = me._add(image[0]);

image
.on('load', function (e) {
.on('load.mapster', function (e) {
me.imageLoaded.call(me, e);
})
.on('error', function (e) {
.on('error.mapster', function (e) {
me.imageLoadError.call(me, e);
});

Expand Down
9 changes: 7 additions & 2 deletions src/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,17 @@
beforeClose,
onClose
) {
var event_name = event + '.mapster-tooltip';
// Tooltip namespace is intentionally different from standard
// .mapster namespace because if tooltip is open when mapster
// is unbound, there wouldn't be a way to close the tooltip
// if the event listener was removed.
var tooltip_ns = '.mapster-tooltip',
event_name = event + tooltip_ns;

if ($.inArray(bindOption, options) >= 0) {
target.off(event_name).on(event_name, function (e) {
if (!beforeClose || beforeClose.call(this, e)) {
target.off('.mapster-tooltip');
target.off(tooltip_ns);
if (onClose) {
onClose.call(this);
}
Expand Down

0 comments on commit 8895993

Please sign in to comment.