1
1
angular . module ( 'ui.bootstrap.buttons' , [ ] )
2
2
3
- . constant ( 'buttonConfig ' , {
3
+ . constant ( 'uibButtonConfig ' , {
4
4
activeClass : 'active' ,
5
5
toggleEvent : 'click'
6
6
} )
7
7
8
- . controller ( 'ButtonsController ' , [ 'buttonConfig ' , function ( buttonConfig ) {
8
+ . controller ( 'UibButtonsController ' , [ 'uibButtonConfig ' , function ( buttonConfig ) {
9
9
this . activeClass = buttonConfig . activeClass || 'active' ;
10
10
this . toggleEvent = buttonConfig . toggleEvent || 'click' ;
11
11
} ] )
12
12
13
- . directive ( 'btnRadio ' , function ( ) {
13
+ . directive ( 'uibBtnRadio ' , function ( ) {
14
14
return {
15
- require : [ 'btnRadio ' , 'ngModel' ] ,
16
- controller : 'ButtonsController ' ,
15
+ require : [ 'uibBtnRadio ' , 'ngModel' ] ,
16
+ controller : 'UibButtonsController ' ,
17
17
controllerAs : 'buttons' ,
18
18
link : function ( scope , element , attrs , ctrls ) {
19
19
var buttonsCtrl = ctrls [ 0 ] , ngModelCtrl = ctrls [ 1 ] ;
@@ -22,7 +22,7 @@ angular.module('ui.bootstrap.buttons', [])
22
22
23
23
//model -> UI
24
24
ngModelCtrl . $render = function ( ) {
25
- element . toggleClass ( buttonsCtrl . activeClass , angular . equals ( ngModelCtrl . $modelValue , scope . $eval ( attrs . btnRadio ) ) ) ;
25
+ element . toggleClass ( buttonsCtrl . activeClass , angular . equals ( ngModelCtrl . $modelValue , scope . $eval ( attrs . uibBtnRadio ) ) ) ;
26
26
} ;
27
27
28
28
//ui->model
@@ -35,7 +35,7 @@ angular.module('ui.bootstrap.buttons', [])
35
35
36
36
if ( ! isActive || angular . isDefined ( attrs . uncheckable ) ) {
37
37
scope . $apply ( function ( ) {
38
- ngModelCtrl . $setViewValue ( isActive ? null : scope . $eval ( attrs . btnRadio ) ) ;
38
+ ngModelCtrl . $setViewValue ( isActive ? null : scope . $eval ( attrs . uibBtnRadio ) ) ;
39
39
ngModelCtrl . $render ( ) ;
40
40
} ) ;
41
41
}
@@ -44,10 +44,10 @@ angular.module('ui.bootstrap.buttons', [])
44
44
} ;
45
45
} )
46
46
47
- . directive ( 'btnCheckbox ' , [ '$document' , function ( $document ) {
47
+ . directive ( 'uibBtnCheckbox ' , [ '$document' , function ( $document ) {
48
48
return {
49
- require : [ 'btnCheckbox ' , 'ngModel' ] ,
50
- controller : 'ButtonsController ' ,
49
+ require : [ 'uibBtnCheckbox ' , 'ngModel' ] ,
50
+ controller : 'UibButtonsController ' ,
51
51
controllerAs : 'button' ,
52
52
link : function ( scope , element , attrs , ctrls ) {
53
53
var buttonsCtrl = ctrls [ 0 ] , ngModelCtrl = ctrls [ 1 ] ;
@@ -98,3 +98,107 @@ angular.module('ui.bootstrap.buttons', [])
98
98
}
99
99
} ;
100
100
} ] ) ;
101
+
102
+ /* Deprecated buttons below */
103
+
104
+ angular . module ( 'ui.bootstrap.buttons' )
105
+
106
+ . value ( '$buttonsSuppressWarning' , false )
107
+
108
+ . directive ( 'btnRadio' , [ '$log' , '$buttonsSuppressWarning' , function ( $log , $buttonsSuppressWarning ) {
109
+ return {
110
+ require : [ 'btnRadio' , 'ngModel' ] ,
111
+ controller : 'UibButtonsController' ,
112
+ controllerAs : 'buttons' ,
113
+ link : function ( scope , element , attrs , ctrls ) {
114
+ if ( ! $buttonsSuppressWarning ) {
115
+ $log . warn ( 'btn-radio is now deprecated. Use uib-btn-radio instead.' ) ;
116
+ }
117
+
118
+ var buttonsCtrl = ctrls [ 0 ] , ngModelCtrl = ctrls [ 1 ] ;
119
+
120
+ element . find ( 'input' ) . css ( { display : 'none' } ) ;
121
+
122
+ //model -> UI
123
+ ngModelCtrl . $render = function ( ) {
124
+ element . toggleClass ( buttonsCtrl . activeClass , angular . equals ( ngModelCtrl . $modelValue , scope . $eval ( attrs . btnRadio ) ) ) ;
125
+ } ;
126
+
127
+ //ui->model
128
+ element . bind ( buttonsCtrl . toggleEvent , function ( ) {
129
+ if ( attrs . disabled ) {
130
+ return ;
131
+ }
132
+
133
+ var isActive = element . hasClass ( buttonsCtrl . activeClass ) ;
134
+
135
+ if ( ! isActive || angular . isDefined ( attrs . uncheckable ) ) {
136
+ scope . $apply ( function ( ) {
137
+ ngModelCtrl . $setViewValue ( isActive ? null : scope . $eval ( attrs . btnRadio ) ) ;
138
+ ngModelCtrl . $render ( ) ;
139
+ } ) ;
140
+ }
141
+ } ) ;
142
+ }
143
+ } ;
144
+ } ] )
145
+
146
+ . directive ( 'btnCheckbox' , [ '$document' , '$log' , '$buttonsSuppressWarning' , function ( $document , $log , $buttonsSuppressWarning ) {
147
+ return {
148
+ require : [ 'btnCheckbox' , 'ngModel' ] ,
149
+ controller : 'UibButtonsController' ,
150
+ controllerAs : 'button' ,
151
+ link : function ( scope , element , attrs , ctrls ) {
152
+ if ( ! $buttonsSuppressWarning ) {
153
+ $log . warn ( 'btn-checkbox is now deprecated. Use uib-btn-checkbox instead.' ) ;
154
+ }
155
+
156
+ var buttonsCtrl = ctrls [ 0 ] , ngModelCtrl = ctrls [ 1 ] ;
157
+
158
+ element . find ( 'input' ) . css ( { display : 'none' } ) ;
159
+
160
+ function getTrueValue ( ) {
161
+ return getCheckboxValue ( attrs . btnCheckboxTrue , true ) ;
162
+ }
163
+
164
+ function getFalseValue ( ) {
165
+ return getCheckboxValue ( attrs . btnCheckboxFalse , false ) ;
166
+ }
167
+
168
+ function getCheckboxValue ( attributeValue , defaultValue ) {
169
+ var val = scope . $eval ( attributeValue ) ;
170
+ return angular . isDefined ( val ) ? val : defaultValue ;
171
+ }
172
+
173
+ //model -> UI
174
+ ngModelCtrl . $render = function ( ) {
175
+ element . toggleClass ( buttonsCtrl . activeClass , angular . equals ( ngModelCtrl . $modelValue , getTrueValue ( ) ) ) ;
176
+ } ;
177
+
178
+ //ui->model
179
+ element . bind ( buttonsCtrl . toggleEvent , function ( ) {
180
+ if ( attrs . disabled ) {
181
+ return ;
182
+ }
183
+
184
+ scope . $apply ( function ( ) {
185
+ ngModelCtrl . $setViewValue ( element . hasClass ( buttonsCtrl . activeClass ) ? getFalseValue ( ) : getTrueValue ( ) ) ;
186
+ ngModelCtrl . $render ( ) ;
187
+ } ) ;
188
+ } ) ;
189
+
190
+ //accessibility
191
+ element . on ( 'keypress' , function ( e ) {
192
+ if ( attrs . disabled || e . which !== 32 || $document [ 0 ] . activeElement !== element [ 0 ] ) {
193
+ return ;
194
+ }
195
+
196
+ scope . $apply ( function ( ) {
197
+ ngModelCtrl . $setViewValue ( element . hasClass ( buttonsCtrl . activeClass ) ? getFalseValue ( ) : getTrueValue ( ) ) ;
198
+ ngModelCtrl . $render ( ) ;
199
+ } ) ;
200
+ } ) ;
201
+ }
202
+ } ;
203
+ } ] ) ;
204
+
0 commit comments