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

Commit 6aff569

Browse files
committed
merging with latest changes
2 parents f0e584c + 8d45271 commit 6aff569

14 files changed

+429
-317
lines changed

Gruntfile.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ module.exports = function (grunt) {
4848
'tmp/spec/js/oo/oo.spec.js': 'spec/coffee/oo/*.spec.coffee',
4949

5050
'tmp/spec/js/directives/api/models/child/children.spec.js': 'spec/coffee/directives/api/models/child/*.spec.coffee',
51+
'tmp/spec/js/directives/api/models/parent/parents.spec.js': 'spec/coffee/directives/api/models/parent/*.spec.coffee',
5152
'tmp/spec/js/directives/api/utils/async-processor.spec.js': 'spec/coffee/directives/api/utils/async-processor.spec.coffee'
5253
}
5354
}
@@ -76,7 +77,7 @@ module.exports = function (grunt) {
7677
dest: 'tmp/output.js'
7778
},
7879
example: {
79-
//src: ['dist/angular-google-maps.js'],
80+
// src: ['dist/angular-google-maps.js'],
8081
src: ['dist/angular-google-maps.min.js'], //use min for release, otherwise other for testing
8182
dest: 'example/<%= pkg.name %>.js'
8283
}
@@ -149,7 +150,7 @@ module.exports = function (grunt) {
149150
taskName: {
150151
src: ['dist/angular-google-maps.js'],
151152
options: {
152-
keepRunner: false,
153+
keepRunner: true,
153154
vendor: ['http://maps.googleapis.com/maps/api/js?sensor=false&language=en', 'lib/*.js', 'dist/angular-google-maps.js'],
154155
specs: ['spec/*.spec.js', 'spec/**/*.spec.js', 'spec/**/**/*-spec.js', 'spec/**/**/**/*.spec.js',
155156
'tmp/spec/js/*/spec.js', 'tmp/spec/**/*.spec.js', 'tmp/spec/**/**/*-spec.js', 'tmp/spec/**/**/**/*.spec.js'
@@ -161,10 +162,10 @@ module.exports = function (grunt) {
161162
coverage: 'spec/coverage/coverage.json',
162163
report: 'spec/coverage',
163164
thresholds: {
164-
lines: 75,
165-
statements: 75,
166-
branches: 75,
167-
functions: 74
165+
lines: 25,
166+
statements: 25,
167+
branches: 5,
168+
functions: 25
168169
}
169170
}
170171
}

dist/angular-google-maps.js

+117-70
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151
})();;(function() {
5252
this.ngGmapModule = function(names, fn) {
5353
var space, _name;
54+
if (fn == null) {
55+
fn = function() {};
56+
}
5457
if (typeof names === 'string') {
5558
names = names.split('.');
5659
}
@@ -385,10 +388,12 @@
385388
return opts;
386389
},
387390
createWindowOptions: function(gMarker, scope, content, defaults) {
388-
return angular.extend({}, defaults, {
389-
content: content,
390-
position: angular.isObject(gMarker) ? gMarker.getPosition() : new google.maps.LatLng(scope.coords.latitude, scope.coords.longitude)
391-
});
391+
if ((content != null) && (defaults != null)) {
392+
return angular.extend({}, defaults, {
393+
content: content,
394+
position: angular.isObject(gMarker) ? gMarker.getPosition() : new google.maps.LatLng(scope.coords.latitude, scope.coords.longitude)
395+
});
396+
}
392397
},
393398
defaultDelay: 50
394399
};
@@ -420,19 +425,30 @@
420425

421426
(function() {
422427
this.ngGmapModule("directives.api.utils", function() {
423-
return this.Logger = {
428+
var logger;
429+
this.Logger = {
424430
logger: void 0,
425431
doLog: false,
426432
info: function(msg) {
427-
if (directives.api.utils.Logger.doLog) {
428-
if (directives.api.utils.Logger.logger != null) {
429-
return directives.api.utils.Logger.logger.info(msg);
433+
if (logger.doLog) {
434+
if (logger.logger != null) {
435+
return logger.logger.info(msg);
430436
} else {
431437
return console.info(msg);
432438
}
433439
}
440+
},
441+
error: function(msg) {
442+
if (logger.doLog) {
443+
if (logger.logger != null) {
444+
return logger.logger.error(msg);
445+
} else {
446+
return console.error(msg);
447+
}
448+
}
434449
}
435450
};
451+
return logger = this.Logger;
436452
});
437453

438454
}).call(this);
@@ -771,7 +787,10 @@
771787
return this.WindowChildModel = (function(_super) {
772788
__extends(WindowChildModel, _super);
773789

774-
function WindowChildModel(scope, opts, isIconVisibleOnClick, mapCtrl, markerCtrl, $http, $templateCache, $compile, needToManualDestroy) {
790+
WindowChildModel.include(directives.api.utils.GmapUtil);
791+
792+
function WindowChildModel(scope, opts, isIconVisibleOnClick, mapCtrl, markerCtrl, $http, $templateCache, $compile, element, needToManualDestroy) {
793+
this.element = element;
775794
if (needToManualDestroy == null) {
776795
needToManualDestroy = false;
777796
}
@@ -781,6 +800,7 @@
781800
this.handleClick = __bind(this.handleClick, this);
782801
this.watchCoords = __bind(this.watchCoords, this);
783802
this.watchShow = __bind(this.watchShow, this);
803+
this.createGWin = __bind(this.createGWin, this);
784804
this.scope = scope;
785805
this.opts = opts;
786806
this.mapCtrl = mapCtrl;
@@ -791,7 +811,7 @@
791811
this.$http = $http;
792812
this.$templateCache = $templateCache;
793813
this.$compile = $compile;
794-
this.gWin = new google.maps.InfoWindow(opts);
814+
this.createGWin();
795815
if (this.markerCtrl != null) {
796816
this.markerCtrl.setClickable(true);
797817
}
@@ -802,6 +822,27 @@
802822
this.$log.info(this);
803823
}
804824

825+
WindowChildModel.prototype.createGWin = function(createOpts) {
826+
var _this = this;
827+
if (createOpts == null) {
828+
createOpts = false;
829+
}
830+
if ((this.gWin == null) && createOpts) {
831+
this.opts = this.markerCtrl != null ? this.createWindowOptions(this.markerCtrl, this.scope, this.element.html(), {}) : {};
832+
}
833+
if ((this.opts != null) && this.gWin === void 0) {
834+
this.gWin = new google.maps.InfoWindow(this.opts);
835+
return google.maps.event.addListener(this.gWin, 'closeclick', function() {
836+
if (_this.markerCtrl != null) {
837+
_this.markerCtrl.setVisible(_this.initialMarkerVisibility);
838+
}
839+
if (_this.scope.closeClick != null) {
840+
return _this.scope.closeClick();
841+
}
842+
});
843+
}
844+
};
845+
805846
WindowChildModel.prototype.watchShow = function() {
806847
var _this = this;
807848
return this.scope.$watch('show', function(newValue, oldValue) {
@@ -812,8 +853,10 @@
812853
return _this.hideWindow();
813854
}
814855
} else {
815-
if (newValue && !_this.gWin.getMap()) {
816-
return _this.showWindow();
856+
if (_this.gWin != null) {
857+
if (newValue && !_this.gWin.getMap()) {
858+
return _this.showWindow();
859+
}
817860
}
818861
}
819862
}, true);
@@ -831,44 +874,47 @@
831874
WindowChildModel.prototype.handleClick = function() {
832875
var _this = this;
833876
if (this.markerCtrl != null) {
834-
google.maps.event.addListener(this.markerCtrl, 'click', function() {
835-
_this.gWin.setPosition(_this.markerCtrl.getPosition());
836-
_this.gWin.open(_this.mapCtrl);
877+
return google.maps.event.addListener(this.markerCtrl, 'click', function() {
878+
var pos;
879+
_this.createGWin(true);
880+
pos = _this.markerCtrl.getPosition();
881+
if (_this.gWin != null) {
882+
_this.gWin.setPosition(pos);
883+
_this.gWin.open(_this.mapCtrl);
884+
}
837885
return _this.markerCtrl.setVisible(_this.isIconVisibleOnClick);
838886
});
839887
}
840-
return google.maps.event.addListener(this.gWin, 'closeclick', function() {
841-
if (_this.markerCtrl != null) {
842-
_this.markerCtrl.setVisible(_this.initialMarkerVisibility);
843-
}
844-
if (_this.scope.closeClick != null) {
845-
return _this.scope.closeClick();
846-
}
847-
});
848888
};
849889

850890
WindowChildModel.prototype.showWindow = function() {
851891
var _this = this;
852892
if (this.scope.templateUrl) {
853-
return this.$http.get(this.scope.templateUrl, {
854-
cache: this.$templateCache
855-
}).then(function(content) {
856-
var compiled, templateScope;
857-
templateScope = _this.scope.$new();
858-
if (angular.isDefined(_this.scope.templateParameter)) {
859-
templateScope.parameter = _this.scope.templateParameter;
860-
}
861-
compiled = _this.$compile(content.data)(templateScope);
862-
_this.gWin.setContent(compiled.get(0));
863-
return _this.gWin.open(_this.mapCtrl);
864-
});
893+
if (this.gWin) {
894+
return this.$http.get(this.scope.templateUrl, {
895+
cache: this.$templateCache
896+
}).then(function(content) {
897+
var compiled, templateScope;
898+
templateScope = _this.scope.$new();
899+
if (angular.isDefined(_this.scope.templateParameter)) {
900+
templateScope.parameter = _this.scope.templateParameter;
901+
}
902+
compiled = _this.$compile(content.data)(templateScope);
903+
_this.gWin.setContent(compiled.get(0));
904+
return _this.gWin.open(_this.mapCtrl);
905+
});
906+
}
865907
} else {
866-
return this.gWin.open(this.mapCtrl);
908+
if (this.gWin != null) {
909+
return this.gWin.open(this.mapCtrl);
910+
}
867911
}
868912
};
869913

870914
WindowChildModel.prototype.hideWindow = function() {
871-
return this.gWin.close();
915+
if (this.gWin != null) {
916+
return this.gWin.close();
917+
}
872918
};
873919

874920
WindowChildModel.prototype.destroy = function() {
@@ -914,25 +960,25 @@
914960
};
915961

916962
function IMarkerParentModel(scope, element, attrs, mapCtrl, $timeout) {
963+
var self,
964+
_this = this;
965+
this.scope = scope;
966+
this.element = element;
967+
this.attrs = attrs;
968+
this.mapCtrl = mapCtrl;
969+
this.$timeout = $timeout;
917970
this.linkInit = __bind(this.linkInit, this);
918971
this.onDestroy = __bind(this.onDestroy, this);
919972
this.onWatch = __bind(this.onWatch, this);
920973
this.watch = __bind(this.watch, this);
921974
this.validateScope = __bind(this.validateScope, this);
922975
this.onTimeOut = __bind(this.onTimeOut, this);
923-
var self,
924-
_this = this;
925976
self = this;
926-
this.scope = scope;
927-
this.element = element;
928-
this.attrs = attrs;
929-
if (this.validateScope(scope)) {
977+
this.$log = directives.api.utils.Logger;
978+
if (!this.validateScope(scope)) {
930979
return;
931980
}
932981
this.doClick = angular.isDefined(attrs.click);
933-
this.mapCtrl = mapCtrl;
934-
this.$log = directives.api.utils.Logger;
935-
this.$timeout = $timeout;
936982
if (scope.options != null) {
937983
this.DEFAULTS = scope.options;
938984
}
@@ -951,8 +997,11 @@
951997

952998
IMarkerParentModel.prototype.validateScope = function(scope) {
953999
var ret;
954-
ret = angular.isUndefined(scope.coords) || scope.coords === void 0;
955-
if (ret) {
1000+
if (scope == null) {
1001+
return false;
1002+
}
1003+
ret = scope.coords != null;
1004+
if (!ret) {
9561005
this.$log.error(this.constructor.name + ": no valid coords attribute found");
9571006
}
9581007
return ret;
@@ -1114,29 +1163,26 @@
11141163
function MarkerParentModel(scope, element, attrs, mapCtrl, $timeout) {
11151164
this.onDestroy = __bind(this.onDestroy, this);
11161165
this.onWatch = __bind(this.onWatch, this);
1117-
this.validateScope = __bind(this.validateScope, this);
1118-
var self,
1119-
_this = this;
1166+
this.onTimeOut = __bind(this.onTimeOut, this);
1167+
var self;
11201168
MarkerParentModel.__super__.constructor.call(this, scope, element, attrs, mapCtrl, $timeout);
11211169
self = this;
1122-
$timeout(function() {
1123-
var opts;
1124-
opts = _this.createMarkerOptions(_this.scope.coords, _this.scope.icon, _this.scope.options, _this.mapCtrl.getMap());
1125-
_this.gMarker = new google.maps.Marker(opts);
1126-
_this.element.data('instance', _this.gMarker);
1127-
google.maps.event.addListener(_this.gMarker, 'click', function() {
1128-
if (_this.doClick && (scope.click != null)) {
1129-
return $timeout(function() {
1130-
return _this.scope.click();
1131-
});
1132-
}
1133-
});
1134-
return _this.$log.info(_this);
1135-
}, directives.api.utils.GmapUtil.defaultDelay);
11361170
}
11371171

1138-
MarkerParentModel.prototype.validateScope = function(scope) {
1139-
return MarkerParentModel.__super__.validateScope.call(this, scope) || angular.isUndefined(scope.coords.latitude) || angular.isUndefined(scope.coords.longitude);
1172+
MarkerParentModel.prototype.onTimeOut = function(scope) {
1173+
var opts,
1174+
_this = this;
1175+
opts = this.createMarkerOptions(scope.coords, scope.icon, scope.options, this.mapCtrl.getMap());
1176+
this.gMarker = new google.maps.Marker(opts);
1177+
this.element.data('instance', this.gMarker);
1178+
google.maps.event.addListener(this.gMarker, 'click', function() {
1179+
if (_this.doClick && (scope.click != null)) {
1180+
return _this.$timeout(function() {
1181+
return _this.scope.click();
1182+
});
1183+
}
1184+
});
1185+
return this.$log.info(this);
11401186
};
11411187

11421188
MarkerParentModel.prototype.onWatch = function(propNameToWatch, scope) {
@@ -1950,17 +1996,18 @@ not 1:1 in this setting.
19501996
Window.prototype.link = function(scope, element, attrs, ctrls) {
19511997
var _this = this;
19521998
return this.$timeout(function() {
1953-
var defaults, isIconVisibleOnClick, mapCtrl, markerCtrl, opts, window;
1999+
var defaults, hasScopeCoords, isIconVisibleOnClick, mapCtrl, markerCtrl, opts, window;
19542000
isIconVisibleOnClick = true;
19552001
if (angular.isDefined(attrs.isiconvisibleonclick)) {
19562002
isIconVisibleOnClick = scope.isIconVisibleOnClick;
19572003
}
19582004
mapCtrl = ctrls[0].getMap();
19592005
markerCtrl = ctrls.length > 1 && (ctrls[1] != null) ? ctrls[1].getMarker() : void 0;
19602006
defaults = scope.options != null ? scope.options : {};
1961-
opts = _this.createWindowOptions(markerCtrl, scope, element.html(), defaults);
2007+
hasScopeCoords = (scope != null) && (scope.coords != null) && (scope.coords.latitude != null) && (scope.coords.longitude != null);
2008+
opts = (markerCtrl != null) && hasScopeCoords ? _this.createWindowOptions(markerCtrl, scope, element.html(), defaults) : void 0;
19622009
if (mapCtrl != null) {
1963-
window = new directives.api.models.child.WindowChildModel(scope, opts, isIconVisibleOnClick, mapCtrl, markerCtrl, _this.$http, _this.$templateCache, _this.$compile);
2010+
window = new directives.api.models.child.WindowChildModel(scope, opts, isIconVisibleOnClick, mapCtrl, markerCtrl, _this.$http, _this.$templateCache, _this.$compile, element);
19642011
}
19652012
return scope.$on("$destroy", function() {
19662013
return window.destroy();

dist/angular-google-maps.min.js

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/example.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ <h1>angular-google-maps example</h1>
8888
<!-- can not put google.map.animations.BOUNCE , since it is not initiaized yet -->
8989
<div ng-init="opts = {animation:1}">
9090
<marker coords="map.clickedMarker" options="opts">
91-
<marker-label content="map.clickedMarker.title" anchor="24 40" class="marker-labels"/>
92-
<window isIconVisibleOnClick="false">This is my clicked marker!
91+
<!--<marker-label content="map.clickedMarker.title" anchor="24 40" class="marker-labels"/>-->
92+
<window isIconVisibleOnClick="true">This is my clicked marker!
9393
<p class="muted">My marker will reappear when you close me.</p>
9494
</window>
9595
</marker>

spec/coffee/directives/api/models/child/window-child-model.spec.coffee

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ describe("WindowChildModel", ->
1717
.value('mapCtrl',document.gMap)
1818
.value('markerCtrl',@gMarker)
1919
.value('opts',@windowOpts)
20+
.value('element','<span>hi</span>')
2021
.value('needToManualDestroy',false)
2122
.controller('childModel', directives.api.models.child.WindowChildModel)
2223

0 commit comments

Comments
 (0)