@@ -135,105 +135,40 @@ angular.module('angularify.semantic.accordion', [])
135
135
'use strict' ;
136
136
137
137
angular . module ( 'angularify.semantic.checkbox' , [ ] )
138
-
139
138
. directive ( 'checkbox' , function ( ) {
140
139
return {
141
140
restrict : 'E' ,
142
141
replace : true ,
143
142
transclude : true ,
144
143
scope : {
145
- type : "@" ,
146
- size : "@" ,
147
- checked : "@" ,
148
- disabled : "@" ,
149
- model : '=ngModel'
144
+ checked : '&?' ,
145
+ disabled : '&?' ,
146
+ ngModel : '=ngModel'
150
147
} ,
151
- template : "<div class=\"{{checkbox_class}}\">" +
152
- "<input type=\"checkbox\">" +
153
- "<label ng-click=\"click_on_checkbox()\" ng-transclude></label>" +
154
- "</div>" ,
155
- link : function ( scope , element , attrs , ngModel ) {
148
+ controller : function ( ) {
149
+ var vm = this ;
156
150
157
- //
158
- // set up checkbox class and type
159
- //
160
- if ( scope . type == 'standard' || scope . type === undefined ) {
161
- scope . type = 'standard' ;
162
- scope . checkbox_class = 'ui checkbox' ;
163
- } else if ( scope . type == 'slider' ) {
164
- scope . type = 'slider' ;
165
- scope . checkbox_class = 'ui slider checkbox' ;
166
- } else if ( scope . type == 'toggle' ) {
167
- scope . type = 'toggle' ;
168
- scope . checkbox_class = 'ui toggle checkbox' ;
169
- } else {
170
- scope . type = 'standard' ;
171
- scope . checkbox_class = 'ui checkbox' ;
172
- }
173
-
174
- //
175
- // set checkbox size
176
- //
177
- if ( scope . size == 'large' ) {
178
- scope . checkbox_class = scope . checkbox_class + ' large' ;
179
- } else if ( scope . size == 'huge' ) {
180
- scope . checkbox_class = scope . checkbox_class + ' huge' ;
181
- }
151
+ // TODO: assert this is usefull ?
152
+ // if(angular.isUndefined(vm.ngModel)) { vm.ngModel = !!vm.ngModel; }
182
153
183
- //
184
- // set checked/unchecked
185
- //
186
- if ( scope . checked == 'false' || scope . checked === undefined ) {
187
- scope . checked = false ;
188
- } else {
189
- scope . checked = true ;
190
- element . children ( ) [ 0 ] . setAttribute ( 'checked' , '' ) ;
191
- }
154
+ if ( angular . isFunction ( vm . checked ) ) { vm . ngModel = ! ! vm . checked ( ) ; }
192
155
193
- //
194
- // check if the parameter disabled is available
195
- //
196
- if ( scope . disabled == 'disabled' ) {
197
- scope . checkbox_class += ' disabled' ;
156
+ vm . toggle = function ( ) {
157
+ if ( angular . isFunction ( vm . disabled ) && vm . disabled ( ) ) return ;
158
+ vm . ngModel = ! vm . ngModel ;
198
159
}
199
-
200
- //
201
- // Click handler
202
- //
203
- element . bind ( 'click' , function ( ) {
204
- scope . $apply ( function ( ) {
205
- if ( scope . disabled === undefined ) {
206
- if ( scope . checked === true ) {
207
- scope . checked = true ;
208
- scope . model = false ;
209
- element . children ( ) [ 0 ] . removeAttribute ( 'checked' ) ;
210
- } else {
211
- scope . checked = true ;
212
- scope . model = true ;
213
- element . children ( ) [ 0 ] . setAttribute ( 'checked' , 'true' ) ;
214
- }
215
- }
216
- } ) ;
217
- } ) ;
218
-
219
- //
220
- // Watch for ng-model
221
- //
222
- scope . $watch ( 'model' , function ( val ) {
223
- if ( val === undefined )
224
- return ;
225
-
226
- if ( val === true ) {
227
- scope . checked = true ;
228
- element . children ( ) [ 0 ] . setAttribute ( 'checked' , 'true' ) ;
229
- } else {
230
- scope . checked = false ;
231
- element . children ( ) [ 0 ] . removeAttribute ( 'checked' ) ;
232
- }
233
- } ) ;
234
- }
160
+ } ,
161
+ controllerAs : 'vm' ,
162
+ bindToController : true ,
163
+ require : 'ngModel' ,
164
+ template : '<div class="ui checkbox">' +
165
+ '<input type="checkbox" ng-model="vm.ngModel" ng-disabled="vm.disabled()"/>' +
166
+ '<label ng-click="vm.toggle()" ng-transclude></label>' +
167
+ '</div>' ,
168
+ link : function ( ) { }
235
169
} ;
236
170
} ) ;
171
+
237
172
'use strict' ;
238
173
239
174
angular . module ( 'angularify.semantic.dimmer' , [ ] )
0 commit comments