Skip to content

Commit 0abe30e

Browse files
committed
getEventHandlers should convert camelcase to underscored event names
1 parent 76ae49c commit 0abe30e

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/services/angulargmUtils.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@
133133
// retrieve gm-on-___ handlers
134134
angular.forEach(attrs, function(value, key) {
135135
if (key.lastIndexOf('gmOn', 0) === 0) {
136-
var event = angular.lowercase(key.substring(4));
136+
var event = angular.lowercase(
137+
key.substring(4)
138+
.replace(/(?!^)([A-Z])/g, '_$&')
139+
);
137140
var fn = $parse(value);
138141
handlers[event] = fn;
139142
}

test/unit/services/angulargmUtilsSpec.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ describe('angulargmUtils', function() {
33
boundsEqual,
44
latLngToObj,
55
objToLatLng,
6-
hasNaN;
6+
hasNaN,
7+
getEventHandlers;
78

89
var latLngG,
910
latLngObj;
@@ -18,6 +19,7 @@ describe('angulargmUtils', function() {
1819
latLngToObj = angulargmUtils.latLngToObj;
1920
objToLatLng = angulargmUtils.objToLatLng;
2021
hasNaN = angulargmUtils.hasNaN;
22+
getEventHandlers = angulargmUtils.getEventHandlers;
2123

2224
latLngG = new google.maps.LatLng(1, 2);
2325
latLngObj = {lat: 1, lng: 2};
@@ -122,4 +124,21 @@ describe('angulargmUtils', function() {
122124

123125
});
124126

127+
describe('getEventHandlers', function() {
128+
it('converts attributes that begin with gmOn', function() {
129+
var attrs = {
130+
'gmOnClick': function() {},
131+
'gmMapId': '',
132+
'gmOnZoomChanged': function() {}
133+
}; // represents an Attribute object in the link function
134+
135+
var handlers = getEventHandlers(attrs);
136+
expect(handlers).toEqual({
137+
'click': jasmine.any(Function),
138+
// Converts camelcased names to underscore spearated
139+
'zoom_changed': jasmine.any(Function)
140+
});
141+
});
142+
});
143+
125144
});

0 commit comments

Comments
 (0)