Skip to content

Commit

Permalink
SlidingMarker now correctly handles google.maps.event.trigger method.
Browse files Browse the repository at this point in the history
Fixed regression with MarkerWithLabel.
  • Loading branch information
viskin committed Mar 28, 2015
1 parent 641d85e commit f652488
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 19 deletions.
28 changes: 18 additions & 10 deletions SlidingMarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@

//from MVCObject
addListener: function (eventName, handler) {
var target = getEventTarget.call(this, eventName);
var target = (eventName === "map_changed") ? this._instance : getEventTarget.call(this, eventName);
return this.originalAddListener.apply(target, arguments);
},

Expand All @@ -115,28 +115,36 @@
//call it on SlidingMarker
var getEventTarget = function (eventName) {
//redirect _changed events to this, other events to _instance
if (eventName.endsWith("_changed") && eventName !== "map_changed") { //all _changed except of map redirect to this
if (eventName.endsWith("_changed")) { //all _changed redirect to this
return this;
}
return this._instance;
};

var originalAddListener = google.maps.event.addListener;
google.maps.event.addListener = function (instance, eventName, handler) {
var newHandler;

//If event is position_changed, supply alternative handler
//Redirect listener to target
if (instance instanceof SlidingMarker) {
var target = getEventTarget.call(instance, eventName);
newHandler = function () {
return handler.apply(this, arguments);
};
return originalAddListener.call(this, target, eventName, newHandler);
var target = (eventName === "map_changed") ? instance._instance : getEventTarget.call(instance, eventName);
return originalAddListener.call(this, target, eventName, handler);
}

return originalAddListener.apply(this, arguments);
};

var originalTrigger = google.maps.event.trigger;
google.maps.event.trigger = function (instance, eventName) {
//Replace instance parameter to target
if (instance instanceof SlidingMarker) {
var target = (eventName === "map_changed") ? instance : getEventTarget.call(instance, eventName),
newArgs = [target].concat(Array.prototype.slice.call(arguments, 1)); //replaces instance parameter with target

return originalTrigger.apply(this, newArgs);
}

return originalTrigger.apply(this, arguments);
};

//just string helper
String.prototype.endsWith = String.prototype.endsWith || function(suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
Expand Down
2 changes: 1 addition & 1 deletion dist/MarkerWithGhost.min.js

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

4 changes: 2 additions & 2 deletions dist/SlidingMarker.min.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/SlidingMarker.min.js.map

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,7 +1,7 @@
{
"name": "marker-animate-unobtrusive",
"title": "SlidingMarker",
"version": "0.1.4",
"version": "0.1.5",
"description": "Unobtrusive Google Maps animated marker",
"main": "SlidingMarker.js",

Expand Down
3 changes: 0 additions & 3 deletions tests/spec/SlidingMarkerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,6 @@
afterEach(function () {
google.maps.event.removeListener(mapChangedListener);
map_changes = [];
});

afterEach(function () {
marker.setMap(null);
});

Expand Down
2 changes: 1 addition & 1 deletion vendor/markerwithlabel.terikon.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ MarkerLabel_.prototype.onAdd = function () {
}

var position_changed = this.marker_.ghostAnimationPosition !== undefined ? "ghostanimationposition_changed"
: this.marker_.animationPosition !== undefined ? "animationPosition"
: this.marker_.animationPosition !== undefined ? "animationposition_changed"
: "position_changed";

this.listeners_ = [
Expand Down

0 comments on commit f652488

Please sign in to comment.