Skip to content
This repository has been archived by the owner on Nov 30, 2018. It is now read-only.

Commit

Permalink
fix(markers-parent-model events): internal events are not getting unh…
Browse files Browse the repository at this point in the history
…ooked; added saftey check

issue /#1448
  • Loading branch information
nmccready committed Aug 25, 2015
1 parent cf178c8 commit 117be87
Show file tree
Hide file tree
Showing 21 changed files with 121 additions and 112 deletions.
10 changes: 6 additions & 4 deletions dist/angular-google-maps-street-view.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! angular-google-maps 2.1.5 2015-08-23
/*! angular-google-maps 2.1.5 2015-08-24
* AngularJS directives for Google Maps
* git: https://github.com/angular-ui/angular-google-maps.git
*/
Expand Down Expand Up @@ -538,14 +538,16 @@ return UUID;
}
},
removeEvents: function(listeners) {
var key, l;
if (!listeners) {
return;
}
return listeners.forEach(function(l) {
for (key in listeners) {
l = listeners[key];
if (l) {
return google.maps.event.removeListener(l);
google.maps.event.removeListener(l);
}
});
}
}
};
}
Expand Down
4 changes: 2 additions & 2 deletions dist/angular-google-maps-street-view.min.js

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions dist/angular-google-maps-street-view_dev_mapped.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/angular-google-maps-street-view_dev_mapped.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/angular-google-maps-street-view_dev_mapped.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/angular-google-maps-street-view_dev_mapped.min.js.map

Large diffs are not rendered by default.

66 changes: 31 additions & 35 deletions dist/angular-google-maps.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! angular-google-maps 2.1.5 2015-08-23
/*! angular-google-maps 2.1.5 2015-08-24
* AngularJS directives for Google Maps
* git: https://github.com/angular-ui/angular-google-maps.git
*/
Expand Down Expand Up @@ -811,14 +811,16 @@ Nicholas McCready - https://twitter.com/nmccready
}
},
removeEvents: function(listeners) {
var key, l;
if (!listeners) {
return;
}
return listeners.forEach(function(l) {
for (key in listeners) {
l = listeners[key];
if (l) {
return google.maps.event.removeListener(l);
google.maps.event.removeListener(l);
}
});
}
}
};
}
Expand Down Expand Up @@ -1847,7 +1849,7 @@ Nicholas McCready - https://twitter.com/nmccready
var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };

angular.module('uiGmapgoogle-maps.directives.api.managers').factory('uiGmapClustererMarkerManager', [
'uiGmapLogger', 'uiGmapFitHelper', 'uiGmapPropMap', function($log, FitHelper, PropMap) {
'uiGmapLogger', 'uiGmapFitHelper', 'uiGmapPropMap', 'uiGmapEventsHelper', function($log, FitHelper, PropMap, EventsHelper) {
var ClustererMarkerManager;
ClustererMarkerManager = (function() {
ClustererMarkerManager.type = 'ClustererMarkerManager';
Expand All @@ -1862,6 +1864,7 @@ Nicholas McCready - https://twitter.com/nmccready
this.getGMarkers = bind(this.getGMarkers, this);
this.fit = bind(this.fit, this);
this.destroy = bind(this.destroy, this);
this.attachEvents = bind(this.attachEvents, this);
this.clear = bind(this.clear, this);
this.draw = bind(this.draw, this);
this.removeMany = bind(this.removeMany, this);
Expand Down Expand Up @@ -1936,13 +1939,14 @@ Nicholas McCready - https://twitter.com/nmccready

ClustererMarkerManager.prototype.attachEvents = function(options, optionsName) {
var eventHandler, eventName, results;
this.listeners = [];
if (angular.isDefined(options) && (options != null) && angular.isObject(options)) {
results = [];
for (eventName in options) {
eventHandler = options[eventName];
if (options.hasOwnProperty(eventName) && angular.isFunction(options[eventName])) {
$log.info(optionsName + ": Attaching event: " + eventName + " to clusterer");
results.push(google.maps.event.addListener(this.clusterer, eventName, options[eventName]));
results.push(this.listeners.push(google.maps.event.addListener(this.clusterer, eventName, options[eventName])));
} else {
results.push(void 0);
}
Expand All @@ -1951,25 +1955,13 @@ Nicholas McCready - https://twitter.com/nmccready
}
};

ClustererMarkerManager.prototype.clearEvents = function(options, optionsName) {
var eventHandler, eventName, results;
if (angular.isDefined(options) && (options != null) && angular.isObject(options)) {
results = [];
for (eventName in options) {
eventHandler = options[eventName];
if (options.hasOwnProperty(eventName) && angular.isFunction(options[eventName])) {
$log.info(optionsName + ": Clearing event: " + eventName + " to clusterer");
results.push(google.maps.event.clearListeners(this.clusterer, eventName));
} else {
results.push(void 0);
}
}
return results;
}
ClustererMarkerManager.prototype.clearEvents = function() {
EventsHelper.removeEvents(this.listeners);
return this.listeners = [];
};

ClustererMarkerManager.prototype.destroy = function() {
this.clearEvents(this.opt_events, 'opt_events');
this.clearEvents();
return this.clear();
};

Expand Down Expand Up @@ -2242,19 +2234,15 @@ Nicholas McCready - https://twitter.com/nmccready
};

SpiderfierMarkerManager.prototype.clearEvents = function(options, optionsName) {
var eventHandler, eventName, results;
var eventHandler, eventName;
if (angular.isDefined(options) && (options != null) && angular.isObject(options)) {
results = [];
for (eventName in options) {
eventHandler = options[eventName];
if (options.hasOwnProperty(eventName) && angular.isFunction(options[eventName])) {
$log.info(optionsName + ": Clearing event: " + eventName + " to markerSpiderfier");
results.push(this.markerSpiderfier.clearListeners(eventName));
} else {
results.push(void 0);
this.markerSpiderfier.clearListeners(eventName);
}
}
return results;
}
};

Expand Down Expand Up @@ -4720,6 +4708,7 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
MarkersParentModel.include(ModelsWatcher);

function MarkersParentModel(scope, element, attrs, map) {
this.maybeExecMappedEvent = bind(this.maybeExecMappedEvent, this);
this.onDestroy = bind(this.onDestroy, this);
this.newChildMarker = bind(this.newChildMarker, this);
this.pieceMeal = bind(this.pieceMeal, this);
Expand Down Expand Up @@ -4991,7 +4980,7 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
}
}, _async.chunkSizeFrom(_this.scope.cleanchunk, false)).then(function() {
if (_this.gManager != null) {
_this.gManager.clear();
_this.gManager.destroy();
}
_this.plurals.removeAll();
if (_this.plurals !== _this.scope.plurals) {
Expand All @@ -5005,6 +4994,9 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi

MarkersParentModel.prototype.maybeExecMappedEvent = function(group, fnName) {
var pair, typeEvents;
if (this.scope.$$destroyed) {
return;
}
typeEvents = this.scope.typeEvents || this.scope.clusterEvents;
if (_.isFunction(typeEvents != null ? typeEvents[fnName] : void 0)) {
pair = this.mapTypeToPlurals(group);
Expand All @@ -5015,7 +5007,7 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
};

MarkersParentModel.prototype.mapTypeToPlurals = function(group) {
var arrayToMap, mapped;
var arrayToMap, mapped, ref;
if (_.isArray(group)) {
arrayToMap = group;
} else if (_.isFunction(group.getMarkers)) {
Expand All @@ -5025,11 +5017,15 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
$log.error("Unable to map event as we cannot find the array group to map");
return;
}
mapped = arrayToMap.map((function(_this) {
return function(g) {
return _this.scope.plurals.get(g.key).model;
};
})(this));
if ((ref = this.scope.plurals.values()) != null ? ref.length : void 0) {
mapped = arrayToMap.map((function(_this) {
return function(g) {
return _this.scope.plurals.get(g.key).model;
};
})(this));
} else {
mapped = [];
}
return {
cluster: group,
mapped: mapped,
Expand Down
8 changes: 4 additions & 4 deletions dist/angular-google-maps.min.js

Large diffs are not rendered by default.

66 changes: 31 additions & 35 deletions dist/angular-google-maps_dev_mapped.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! angular-google-maps 2.1.5 2015-08-23
/*! angular-google-maps 2.1.5 2015-08-24
* AngularJS directives for Google Maps
* git: https://github.com/angular-ui/angular-google-maps.git
*/
Expand Down Expand Up @@ -811,14 +811,16 @@ Nicholas McCready - https://twitter.com/nmccready
}
},
removeEvents: function(listeners) {
var key, l;
if (!listeners) {
return;
}
return listeners.forEach(function(l) {
for (key in listeners) {
l = listeners[key];
if (l) {
return google.maps.event.removeListener(l);
google.maps.event.removeListener(l);
}
});
}
}
};
}
Expand Down Expand Up @@ -1847,7 +1849,7 @@ Nicholas McCready - https://twitter.com/nmccready
var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };

angular.module('uiGmapgoogle-maps.directives.api.managers').factory('uiGmapClustererMarkerManager', [
'uiGmapLogger', 'uiGmapFitHelper', 'uiGmapPropMap', function($log, FitHelper, PropMap) {
'uiGmapLogger', 'uiGmapFitHelper', 'uiGmapPropMap', 'uiGmapEventsHelper', function($log, FitHelper, PropMap, EventsHelper) {
var ClustererMarkerManager;
ClustererMarkerManager = (function() {
ClustererMarkerManager.type = 'ClustererMarkerManager';
Expand All @@ -1862,6 +1864,7 @@ Nicholas McCready - https://twitter.com/nmccready
this.getGMarkers = bind(this.getGMarkers, this);
this.fit = bind(this.fit, this);
this.destroy = bind(this.destroy, this);
this.attachEvents = bind(this.attachEvents, this);
this.clear = bind(this.clear, this);
this.draw = bind(this.draw, this);
this.removeMany = bind(this.removeMany, this);
Expand Down Expand Up @@ -1936,13 +1939,14 @@ Nicholas McCready - https://twitter.com/nmccready

ClustererMarkerManager.prototype.attachEvents = function(options, optionsName) {
var eventHandler, eventName, results;
this.listeners = [];
if (angular.isDefined(options) && (options != null) && angular.isObject(options)) {
results = [];
for (eventName in options) {
eventHandler = options[eventName];
if (options.hasOwnProperty(eventName) && angular.isFunction(options[eventName])) {
$log.info(optionsName + ": Attaching event: " + eventName + " to clusterer");
results.push(google.maps.event.addListener(this.clusterer, eventName, options[eventName]));
results.push(this.listeners.push(google.maps.event.addListener(this.clusterer, eventName, options[eventName])));
} else {
results.push(void 0);
}
Expand All @@ -1951,25 +1955,13 @@ Nicholas McCready - https://twitter.com/nmccready
}
};

ClustererMarkerManager.prototype.clearEvents = function(options, optionsName) {
var eventHandler, eventName, results;
if (angular.isDefined(options) && (options != null) && angular.isObject(options)) {
results = [];
for (eventName in options) {
eventHandler = options[eventName];
if (options.hasOwnProperty(eventName) && angular.isFunction(options[eventName])) {
$log.info(optionsName + ": Clearing event: " + eventName + " to clusterer");
results.push(google.maps.event.clearListeners(this.clusterer, eventName));
} else {
results.push(void 0);
}
}
return results;
}
ClustererMarkerManager.prototype.clearEvents = function() {
EventsHelper.removeEvents(this.listeners);
return this.listeners = [];
};

ClustererMarkerManager.prototype.destroy = function() {
this.clearEvents(this.opt_events, 'opt_events');
this.clearEvents();
return this.clear();
};

Expand Down Expand Up @@ -2242,19 +2234,15 @@ Nicholas McCready - https://twitter.com/nmccready
};

SpiderfierMarkerManager.prototype.clearEvents = function(options, optionsName) {
var eventHandler, eventName, results;
var eventHandler, eventName;
if (angular.isDefined(options) && (options != null) && angular.isObject(options)) {
results = [];
for (eventName in options) {
eventHandler = options[eventName];
if (options.hasOwnProperty(eventName) && angular.isFunction(options[eventName])) {
$log.info(optionsName + ": Clearing event: " + eventName + " to markerSpiderfier");
results.push(this.markerSpiderfier.clearListeners(eventName));
} else {
results.push(void 0);
this.markerSpiderfier.clearListeners(eventName);
}
}
return results;
}
};

Expand Down Expand Up @@ -4720,6 +4708,7 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
MarkersParentModel.include(ModelsWatcher);

function MarkersParentModel(scope, element, attrs, map) {
this.maybeExecMappedEvent = bind(this.maybeExecMappedEvent, this);
this.onDestroy = bind(this.onDestroy, this);
this.newChildMarker = bind(this.newChildMarker, this);
this.pieceMeal = bind(this.pieceMeal, this);
Expand Down Expand Up @@ -4991,7 +4980,7 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
}
}, _async.chunkSizeFrom(_this.scope.cleanchunk, false)).then(function() {
if (_this.gManager != null) {
_this.gManager.clear();
_this.gManager.destroy();
}
_this.plurals.removeAll();
if (_this.plurals !== _this.scope.plurals) {
Expand All @@ -5005,6 +4994,9 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi

MarkersParentModel.prototype.maybeExecMappedEvent = function(group, fnName) {
var pair, typeEvents;
if (this.scope.$$destroyed) {
return;
}
typeEvents = this.scope.typeEvents || this.scope.clusterEvents;
if (_.isFunction(typeEvents != null ? typeEvents[fnName] : void 0)) {
pair = this.mapTypeToPlurals(group);
Expand All @@ -5015,7 +5007,7 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
};

MarkersParentModel.prototype.mapTypeToPlurals = function(group) {
var arrayToMap, mapped;
var arrayToMap, mapped, ref;
if (_.isArray(group)) {
arrayToMap = group;
} else if (_.isFunction(group.getMarkers)) {
Expand All @@ -5025,11 +5017,15 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
$log.error("Unable to map event as we cannot find the array group to map");
return;
}
mapped = arrayToMap.map((function(_this) {
return function(g) {
return _this.scope.plurals.get(g.key).model;
};
})(this));
if ((ref = this.scope.plurals.values()) != null ? ref.length : void 0) {
mapped = arrayToMap.map((function(_this) {
return function(g) {
return _this.scope.plurals.get(g.key).model;
};
})(this));
} else {
mapped = [];
}
return {
cluster: group,
mapped: mapped,
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-google-maps_dev_mapped.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/angular-google-maps_dev_mapped.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/angular-google-maps_dev_mapped.min.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions dist/architecture/dot/all.dot
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,9 @@ digraph dependencies {
"uiGmapPropMap"[label="uiGmapPropMap"]
"uiGmapPropMap" -> "uiGmapClustererMarkerManager"

"uiGmapEventsHelper"[label="uiGmapEventsHelper"]
"uiGmapEventsHelper" -> "uiGmapClustererMarkerManager"



"uiGmapLogger"[label="uiGmapLogger"]
Expand Down
Loading

0 comments on commit 117be87

Please sign in to comment.