@@ -4,54 +4,55 @@ angular.module('ui.bootstrap.rating', [])
44 max : 5
55} )
66
7- . directive ( 'rating' , [ 'ratingConfig' , '$parse' , function ( ratingConfig , $parse ) {
7+ . controller ( 'RatingController' , [ '$scope' , '$attrs' , '$parse' , 'ratingConfig' , function ( $scope , $attrs , $parse , ratingConfig ) {
8+
9+ this . maxRange = angular . isDefined ( $attrs . max ) ? $scope . $parent . $eval ( $attrs . max ) : ratingConfig . max ;
10+
11+ $scope . range = [ ] ;
12+ for ( var i = 1 ; i <= this . maxRange ; i ++ ) {
13+ $scope . range . push ( i ) ;
14+ }
15+
16+ $scope . rate = function ( value ) {
17+ if ( ! $scope . readonly ) {
18+ $scope . value = value ;
19+ }
20+ } ;
21+
22+ $scope . enter = function ( value ) {
23+ if ( ! $scope . readonly ) {
24+ $scope . val = value ;
25+ }
26+ $scope . onHover ( { value : value } ) ;
27+ } ;
28+
29+ $scope . reset = function ( ) {
30+ $scope . val = angular . copy ( $scope . value ) ;
31+ $scope . onLeave ( ) ;
32+ } ;
33+
34+ $scope . $watch ( 'value' , function ( value ) {
35+ $scope . val = value ;
36+ } ) ;
37+
38+ $scope . readonly = false ;
39+ if ( $attrs . readonly ) {
40+ $scope . $parent . $watch ( $parse ( $attrs . readonly ) , function ( value ) {
41+ $scope . readonly = ! ! value ;
42+ } ) ;
43+ }
44+ } ] )
45+
46+ . directive ( 'rating' , function ( ) {
847 return {
948 restrict : 'EA' ,
1049 scope : {
1150 value : '=' ,
1251 onHover : '&' ,
1352 onLeave : '&'
1453 } ,
54+ controller : 'RatingController' ,
1555 templateUrl : 'template/rating/rating.html' ,
16- replace : true ,
17- link : function ( scope , element , attrs ) {
18-
19- var maxRange = angular . isDefined ( attrs . max ) ? scope . $parent . $eval ( attrs . max ) : ratingConfig . max ;
20-
21- scope . range = [ ] ;
22- for ( var i = 1 ; i <= maxRange ; i ++ ) {
23- scope . range . push ( i ) ;
24- }
25-
26- scope . rate = function ( value ) {
27- if ( ! scope . readonly ) {
28- scope . value = value ;
29- }
30- } ;
31-
32- scope . enter = function ( value ) {
33- if ( ! scope . readonly ) {
34- scope . val = value ;
35- }
36- scope . onHover ( { value : value } ) ;
37- } ;
38-
39- scope . reset = function ( ) {
40- scope . val = angular . copy ( scope . value ) ;
41- scope . onLeave ( ) ;
42- } ;
43- scope . reset ( ) ;
44-
45- scope . $watch ( 'value' , function ( value ) {
46- scope . val = value ;
47- } ) ;
48-
49- scope . readonly = false ;
50- if ( attrs . readonly ) {
51- scope . $parent . $watch ( $parse ( attrs . readonly ) , function ( value ) {
52- scope . readonly = ! ! value ;
53- } ) ;
54- }
55- }
56+ replace : true
5657 } ;
57- } ] ) ;
58+ } ) ;
0 commit comments