diff --git a/src/rating/docs/demo.html b/src/rating/docs/demo.html index 24c229d4d5..5182fafdf7 100644 --- a/src/rating/docs/demo.html +++ b/src/rating/docs/demo.html @@ -1,8 +1,8 @@
- +
-
Rate: {{rate}}  - Readonly is: {{isReadonly}}
+
Rate: {{rate}} - Readonly is: {{isReadonly}} - Hovering over: {{overStar || "none"}}

diff --git a/src/rating/docs/demo.js b/src/rating/docs/demo.js index efb7a88f43..bd69a0be57 100644 --- a/src/rating/docs/demo.js +++ b/src/rating/docs/demo.js @@ -1,4 +1,7 @@ var RatingDemoCtrl = function ($scope) { $scope.rate = 7; $scope.isReadonly = false; + $scope.hoveringOver = function(value) { + $scope.overStar = value; + }; }; diff --git a/src/rating/docs/readme.md b/src/rating/docs/readme.md index fbcdfb268c..40a99b5e99 100644 --- a/src/rating/docs/readme.md +++ b/src/rating/docs/readme.md @@ -1,3 +1,3 @@ Rating directive that will take care of visualising a star rating bar. -It also provides optional attribute `max` to vary the number of stars and `readonly` attribute to diasble user's interaction. \ No newline at end of file +It also provides optional attributes: `max` to vary the number of stars, `readonly` to disable user's interaction, `on-hover` to signal when the user's mouse is over a particular star, and `on-leave` to signal when the mouse leaves the control altogether. \ No newline at end of file diff --git a/src/rating/rating.js b/src/rating/rating.js index 7d623e1782..ff3a18d1eb 100644 --- a/src/rating/rating.js +++ b/src/rating/rating.js @@ -8,7 +8,9 @@ angular.module('ui.bootstrap.rating', []) return { restrict: 'EA', scope: { - value: '=' + value: '=', + onHover: '&', + onLeave: '&' }, templateUrl: 'template/rating/rating.html', replace: true, @@ -31,10 +33,12 @@ angular.module('ui.bootstrap.rating', []) if ( ! scope.readonly ) { scope.val = value; } + scope.onHover({value: value}); }; scope.reset = function() { scope.val = angular.copy(scope.value); + scope.onLeave(); }; scope.reset(); diff --git a/src/rating/test/rating.spec.js b/src/rating/test/rating.spec.js index 4d289c04ef..614ef0a497 100644 --- a/src/rating/test/rating.spec.js +++ b/src/rating/test/rating.spec.js @@ -27,7 +27,7 @@ describe('rating directive', function () { expect(getState(stars)).toEqual([true, true, true, false, false]); }); - it('handles correcty the click event', function() { + it('handles correctly the click event', function() { var stars = element.find('i'); var star2 = stars.eq(1); @@ -43,7 +43,7 @@ describe('rating directive', function () { expect($rootScope.rate).toBe(5); }); - it('handles correcty the hover event', function() { + it('handles correctly the hover event', function() { var stars = element.find('i'); var star2 = stars.eq(1); @@ -99,6 +99,28 @@ describe('rating directive', function () { expect(getState(stars)).toEqual([true, true, true, true, true]); }); + it('should fire onHover', function() { + $rootScope.hoveringOver = jasmine.createSpy('hoveringOver'); + + element = $compile('')($rootScope); + $rootScope.$digest(); + + var star3 = element.find('i').eq(2); + star3.trigger('mouseover'); + $rootScope.$digest(); + expect($rootScope.hoveringOver).toHaveBeenCalledWith(3); + }); + + it('should fire onLeave', function() { + $rootScope.leaving = jasmine.createSpy('leaving'); + + element = $compile('')($rootScope); + $rootScope.$digest(); + + element.trigger('mouseleave'); + $rootScope.$digest(); + expect($rootScope.leaving).toHaveBeenCalled(); + }); }); describe('setting ratingConfig', function() { @@ -123,6 +145,4 @@ describe('setting ratingConfig', function() { it('should change number of icon elements', function () { expect(element.find('i').length).toBe(10); }); - -}); - +}); \ No newline at end of file diff --git a/template/rating/rating.html b/template/rating/rating.html index df902ca3c1..2c9dcc746d 100644 --- a/template/rating/rating.html +++ b/template/rating/rating.html @@ -1,3 +1,3 @@ - + \ No newline at end of file