From cb51aa8abbed4b2d9ae163e0e716cfc1ed2a03f5 Mon Sep 17 00:00:00 2001 From: Sebastian Oergel Date: Wed, 19 Mar 2014 20:44:50 +0100 Subject: [PATCH 1/2] Added callback functionality for ui-map. Added the possibility to call an arbitrary scope function after having compiled the ui-map directive. This can e.g. be used to additionally modify or work with the map from within the controller after it has been created. The callback gets the map object as its first parameter. --- demo/demo.html | 2 +- demo/demo.js | 4 ++++ src/ui-map.js | 5 +++++ test/karma.conf.js | 6 +++--- test/mapSpec.js | 12 ++++++++++++ 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/demo/demo.html b/demo/demo.html index f470c4a..067b7e4 100644 --- a/demo/demo.html +++ b/demo/demo.html @@ -35,7 +35,7 @@

Marker

google maps-->
+ ui-options="mapOptions" ui-on-finish="myCallback">
diff --git a/demo/demo.js b/demo/demo.js index 9a6fb27..b42948b 100644 --- a/demo/demo.js +++ b/demo/demo.js @@ -12,6 +12,10 @@ angular.module('doc.ui-map', ['ui.map', 'prettifyDirective', 'ui.bootstrap', 'pl $scope.myMarkers = []; + $scope.myCallback = function() { + console.log('callback called'); + }; + $scope.mapOptions = { center: new google.maps.LatLng(35.784, -78.670), zoom: 15, diff --git a/src/ui-map.js b/src/ui-map.js index 7df3e36..d52ff8c 100644 --- a/src/ui-map.js +++ b/src/ui-map.js @@ -40,6 +40,11 @@ model.assign(scope, map); bindMapEvents(scope, mapEvents, map, elm); + + if (attrs.uiOnFinish) { + // call the callback + scope[attrs.uiOnFinish](map); + } } }; }]); diff --git a/test/karma.conf.js b/test/karma.conf.js index f4901f7..6fc76ab 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -14,9 +14,9 @@ module.exports = function(config) { // list of files / patterns to load in the browser files: [ - 'bower_components/angular/angular.js', - 'bower_components/angular-mocks/angular-mocks.js', - 'bower_components/angular-ui-utils/event.js', + 'app/bower_components/angular/angular.js', + 'app/bower_components/angular-mocks/angular-mocks.js', + 'app/bower_components/angular-ui-utils/event.js', 'src/*', 'test/googlemaps.js', 'test/*Spec.js' diff --git a/test/mapSpec.js b/test/mapSpec.js index 03e738e..ca1af5f 100644 --- a/test/mapSpec.js +++ b/test/mapSpec.js @@ -55,6 +55,18 @@ describe('uiMap', function () { google.maps.event.trigger(scope.gmap, 'dragend'); expect(scope.county).toBe(2); }); + + it('should execute the passed callback after having compiled the directive', function() { + scope.callbackCalled = false; + scope.gmapCallback = function(map) { + if (map) { + scope.callbackCalled = true; + } + }; + + $compile("
")(scope); + expect(scope.callbackCalled).toBeTruthy(); + }); }); describe('test infoWindow', function () { From c15b32df032726a45fb205c3d21625e3917bdb21 Mon Sep 17 00:00:00 2001 From: Sebastian Oergel Date: Wed, 19 Mar 2014 21:23:01 +0100 Subject: [PATCH 2/2] Fixed karma path specs --- test/karma.conf.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/karma.conf.js b/test/karma.conf.js index 6fc76ab..f4901f7 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -14,9 +14,9 @@ module.exports = function(config) { // list of files / patterns to load in the browser files: [ - 'app/bower_components/angular/angular.js', - 'app/bower_components/angular-mocks/angular-mocks.js', - 'app/bower_components/angular-ui-utils/event.js', + 'bower_components/angular/angular.js', + 'bower_components/angular-mocks/angular-mocks.js', + 'bower_components/angular-ui-utils/event.js', 'src/*', 'test/googlemaps.js', 'test/*Spec.js'