Skip to content

Commit 2e07fd1

Browse files
committed
Merge branch 'brasycad-master'
2 parents 2ccb131 + 8a7e8db commit 2e07fd1

File tree

7 files changed

+168
-72
lines changed

7 files changed

+168
-72
lines changed

build/scripts/ng-map.debug.js

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ angular.module('ngMap', []);
3333
var Attr2MapOptions;
3434

3535
var __MapController = function(
36-
$scope, $element, $attrs, $parse, _Attr2MapOptions_, NgMap, NgMapPool
36+
$scope, $element, $attrs, $parse, $interpolate, _Attr2MapOptions_, NgMap, NgMapPool, escapeRegExp
3737
) {
3838
Attr2MapOptions = _Attr2MapOptions_;
3939
var vm = this;
40+
var exprStartSymbol = $interpolate.startSymbol();
41+
var exprEndSymbol = $interpolate.endSymbol();
4042

4143
vm.mapOptions; /** @memberof __MapController */
4244
vm.mapEvents; /** @memberof __MapController */
@@ -196,8 +198,10 @@ angular.module('ngMap', []);
196198
// set options
197199
mapOptions.zoom = mapOptions.zoom || 15;
198200
var center = mapOptions.center;
201+
var exprRegExp = new RegExp(escapeRegExp(exprStartSymbol) + '.*' + escapeRegExp(exprEndSymbol));
202+
199203
if (!mapOptions.center ||
200-
((typeof center === 'string') && center.match(/\{\{.*\}\}/))
204+
((typeof center === 'string') && center.match(exprRegExp))
201205
) {
202206
mapOptions.center = new google.maps.LatLng(0, 0);
203207
} else if( (typeof center === 'string') && center.match(/[0-9.-]*,[0-9.-]*/) ){
@@ -245,14 +249,14 @@ angular.module('ngMap', []);
245249
$parse($attrs.mapInitialized)($scope, {map: vm.map});
246250
}
247251
});
248-
252+
249253
//add maximum zoom listeners if zoom-to-include-markers and and maximum-zoom are valid attributes
250254
if (mapOptions.zoomToIncludeMarkers && mapOptions.maximumZoom) {
251255
google.maps.event.addListener(vm.map, 'zoom_changed', function() {
252256
if (vm.enableMaximumZoomCheck == true) {
253257
vm.enableMaximumZoomCheck = false;
254-
google.maps.event.addListenerOnce(vm.map, 'bounds_changed', function() {
255-
vm.map.setZoom(Math.min(mapOptions.maximumZoom, vm.map.getZoom()));
258+
google.maps.event.addListenerOnce(vm.map, 'bounds_changed', function() {
259+
vm.map.setZoom(Math.min(mapOptions.maximumZoom, vm.map.getZoom()));
256260
});
257261
}
258262
});
@@ -279,11 +283,11 @@ angular.module('ngMap', []);
279283

280284
if (options.lazyInit) { // allows controlled initialization
281285
// parse angular expression for dynamic ids
282-
if (!!$attrs.id &&
286+
if (!!$attrs.id &&
283287
// starts with, at position 0
284-
$attrs.id.indexOf("{{", 0) === 0 &&
288+
$attrs.id.indexOf(exprStartSymbol, 0) === 0 &&
285289
// ends with
286-
$attrs.id.indexOf("}}", $attrs.id.length - "}}".length) !== -1) {
290+
$attrs.id.indexOf(exprEndSymbol, $attrs.id.length - exprEndSymbol.length) !== -1) {
287291
var idExpression = $attrs.id.slice(2,-2);
288292
var mapId = $parse(idExpression)($scope);
289293
} else {
@@ -307,7 +311,7 @@ angular.module('ngMap', []);
307311
}; // __MapController
308312

309313
__MapController.$inject = [
310-
'$scope', '$element', '$attrs', '$parse', 'Attr2MapOptions', 'NgMap', 'NgMapPool'
314+
'$scope', '$element', '$attrs', '$parse', '$interpolate', 'Attr2MapOptions', 'NgMap', 'NgMapPool', 'escapeRegexpFilter'
311315
];
312316
angular.module('ngMap').controller('__MapController', __MapController);
313317
})();
@@ -522,7 +526,7 @@ angular.module('ngMap', []);
522526
_this.el.style.top = y + "px";
523527
_this.el.style.visibility = "visible";
524528
};
525-
if (_this.el.offsetWidth && _this.el.offsetHeight) {
529+
if (_this.el.offsetWidth && _this.el.offsetHeight) {
526530
setPosition();
527531
} else {
528532
//delayed left/top calculation when width/height are not set instantly
@@ -634,29 +638,33 @@ angular.module('ngMap', []);
634638

635639

636640
var customMarkerDirective = function(
637-
_$timeout_, _$compile_, Attr2MapOptions, _NgMap_
641+
_$timeout_, _$compile_, $interpolate, Attr2MapOptions, _NgMap_, escapeRegExp
638642
) {
639643
parser = Attr2MapOptions;
640644
$timeout = _$timeout_;
641645
$compile = _$compile_;
642646
NgMap = _NgMap_;
643647

648+
var exprStartSymbol = $interpolate.startSymbol();
649+
var exprEndSymbol = $interpolate.endSymbol();
650+
var exprRegExp = new RegExp(escapeRegExp(exprStartSymbol) + '([^' + exprEndSymbol.substring(0, 1) + ']+)' + escapeRegExp(exprEndSymbol), 'g');
651+
644652
return {
645653
restrict: 'E',
646654
require: ['?^map','?^ngMap'],
647655
compile: function(element) {
648656
setCustomMarker();
649657
element[0].style.display ='none';
650658
var orgHtml = element.html();
651-
var matches = orgHtml.match(/{{([^}]+)}}/g);
659+
var matches = orgHtml.match(exprRegExp);
652660
var varsToWatch = [];
653661
//filter out that contains '::', 'this.'
654662
(matches || []).forEach(function(match) {
655-
var toWatch = match.replace('{{','').replace('}}','');
663+
var toWatch = match.replace(exprStartSymbol,'').replace(exprEndSymbol,'');
656664
if (match.indexOf('::') == -1 &&
657665
match.indexOf('this.') == -1 &&
658666
varsToWatch.indexOf(toWatch) == -1) {
659-
varsToWatch.push(match.replace('{{','').replace('}}',''));
667+
varsToWatch.push(match.replace(exprStartSymbol,'').replace(exprEndSymbol,''));
660668
}
661669
});
662670

@@ -665,7 +673,7 @@ angular.module('ngMap', []);
665673
}; // return
666674
};// function
667675
customMarkerDirective.$inject =
668-
['$timeout', '$compile', 'Attr2MapOptions', 'NgMap'];
676+
['$timeout', '$compile', '$interpolate', 'Attr2MapOptions', 'NgMap', 'escapeRegexpFilter'];
669677

670678
angular.module('ngMap').directive('customMarker', customMarkerDirective);
671679
})();
@@ -2317,6 +2325,26 @@ angular.module('ngMap', []);
23172325
angular.module('ngMap').filter('camelCase', camelCaseFilter);
23182326
})();
23192327

2328+
/**
2329+
* @ngdoc filter
2330+
* @name escape-regex
2331+
* @description
2332+
* Escapes all regex special characters in a string
2333+
*/
2334+
(function() {
2335+
'use strict';
2336+
2337+
2338+
2339+
var escapeRegexpFilter = function() {
2340+
return function(string) {
2341+
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
2342+
};
2343+
};
2344+
2345+
angular.module('ngMap').filter('escapeRegexp', escapeRegexpFilter);
2346+
})();
2347+
23202348
/**
23212349
* @ngdoc filter
23222350
* @name jsonize
@@ -2367,10 +2395,13 @@ angular.module('ngMap', []);
23672395
/^(\d{4}\-\d\d\-\d\d([tT][\d:\.]*)?)([zZ]|([+\-])(\d\d):?(\d\d))?$/;
23682396

23692397
var Attr2MapOptions = function(
2370-
$parse, $timeout, $log, NavigatorGeolocation, GeoCoder,
2371-
camelCaseFilter, jsonizeFilter
2398+
$parse, $timeout, $log, $interpolate, NavigatorGeolocation, GeoCoder,
2399+
camelCaseFilter, jsonizeFilter, escapeRegExp
23722400
) {
23732401

2402+
var exprStartSymbol = $interpolate.startSymbol();
2403+
var exprEndSymbol = $interpolate.endSymbol();
2404+
23742405
/**
23752406
* Returns the attributes of an element as hash
23762407
* @memberof Attr2MapOptions
@@ -2468,9 +2499,9 @@ angular.module('ngMap', []);
24682499
output = input;
24692500
}
24702501
// 7. evaluate dynamically bound values
2471-
} else if (input.match(/^{/) && options.scope) {
2502+
} else if (input.match(new RegExp('^' + escapeRegExp(exprStartSymbol))) && options.scope) {
24722503
try {
2473-
var expr = input.replace(/{{/,'').replace(/}}/g,'');
2504+
var expr = input.replace(new RegExp(escapeRegExp(exprStartSymbol)),'').replace(new RegExp(escapeRegExp(exprEndSymbol), 'g'),'');
24742505
output = options.scope.$eval(expr);
24752506
} catch (err) {
24762507
output = input;
@@ -2525,11 +2556,12 @@ angular.module('ngMap', []);
25252556

25262557
var getAttrsToObserve = function(attrs) {
25272558
var attrsToObserve = [];
2559+
var exprRegExp = new RegExp(escapeRegExp(exprStartSymbol) + '.*' + escapeRegExp(exprEndSymbol), 'g');
25282560

25292561
if (!attrs.noWatcher) {
25302562
for (var attrName in attrs) { //jshint ignore:line
25312563
var attrValue = attrs[attrName];
2532-
if (attrValue && attrValue.match(/\{\{.*\}\}/)) { // if attr value is {{..}}
2564+
if (attrValue && attrValue.match(exprRegExp)) { // if attr value is {{..}}
25332565
attrsToObserve.push(camelCaseFilter(attrName));
25342566
}
25352567
}
@@ -2601,7 +2633,7 @@ angular.module('ngMap', []);
26012633
};
26022634

26032635
/**
2604-
* converts attributes hash to scope-specific event function
2636+
* converts attributes hash to scope-specific event function
26052637
* @memberof Attr2MapOptions
26062638
* @param {scope} scope angularjs scope
26072639
* @param {Hash} attrs tag attributes
@@ -2725,8 +2757,8 @@ angular.module('ngMap', []);
27252757

27262758
};
27272759
Attr2MapOptions.$inject= [
2728-
'$parse', '$timeout', '$log', 'NavigatorGeolocation', 'GeoCoder',
2729-
'camelCaseFilter', 'jsonizeFilter'
2760+
'$parse', '$timeout', '$log', '$interpolate', 'NavigatorGeolocation', 'GeoCoder',
2761+
'camelCaseFilter', 'jsonizeFilter', 'escapeRegexpFilter'
27302762
];
27312763

27322764
angular.module('ngMap').service('Attr2MapOptions', Attr2MapOptions);

0 commit comments

Comments
 (0)