@@ -56,7 +56,7 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$
5656 onOpen : '&' ,
5757 onClose : '&' ,
5858 onBlur : '&' ,
59- onFocus : '&'
59+ onFocus : '&' ,
6060 } ,
6161
6262 template :
@@ -93,9 +93,8 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$
9393 $scope . selectedItems = [ ] ;
9494 $scope . backUp = [ ] ;
9595 $scope . varButtonLabel = '' ;
96- $scope . tabIndex = 0 ;
97- $scope . tabables = null ;
9896 $scope . currentButton = null ;
97+ $scope . scrolled = false ;
9998
10099 // Show or hide a helper element
101100 $scope . displayHelper = function ( elementString ) {
@@ -135,7 +134,7 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$
135134 break ;
136135 default :
137136 break ;
138- }
137+ } $scope
139138 }
140139
141140 // Call this function when a checkbox is ticked...
@@ -207,7 +206,7 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$
207206
208207 if ( $scope . more === true ) {
209208 $scope . varButtonLabel += ', ... (Total: ' + $scope . selectedItems . length + ')' ;
210- }
209+ } $scope
211210 }
212211 $scope . varButtonLabel = $sce . trustAsHtml ( $scope . varButtonLabel + '<span class="multiSelect caret"></span>' ) ;
213212 }
@@ -219,7 +218,7 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$
219218 if ( item [ $scope . disableProperty ] === true ) {
220219 return true ;
221220 }
222- else {
221+ else { $scope
223222 if ( $scope . isDisabled === true ) {
224223 return true ;
225224 }
@@ -249,6 +248,7 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$
249248 // UI operations to show/hide checkboxes based on click event..
250249 $scope . toggleCheckboxes = function ( e ) {
251250
251+ // Determine what element is clicked (has to be button).
252252 if ( e . target ) {
253253 if ( e . target . tagName . toUpperCase ( ) !== 'BUTTON' && e . target . className . indexOf ( 'multiSelectButton' ) < 0 ) {
254254 if ( attrs . selectionMode && $scope . selectionMode . toUpperCase ( ) === 'SINGLE' ) {
@@ -269,31 +269,36 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$
269269
270270 $scope . labelFilter = '' ;
271271
272- // We search them based on the class names
272+ // Search all the multi-select instances based on the class names
273273 var multiSelectIndex = - 1 ;
274274 var checkboxes = document . querySelectorAll ( '.checkboxLayer' ) ;
275275 var multiSelectButtons = document . querySelectorAll ( '.multiSelectButton' ) ;
276276
277+ // Mark which instance is clicked
277278 for ( i = 0 ; i < multiSelectButtons . length ; i ++ ) {
278279 if ( e === multiSelectButtons [ i ] ) {
279280 multiSelectIndex = i ;
280281 break ;
281282 }
282283 }
283284
285+ // Apply the hide css to all multi-select instances except the clicked one
284286 if ( multiSelectIndex > - 1 ) {
285287 for ( i = 0 ; i < checkboxes . length ; i ++ ) {
286288 if ( i != multiSelectIndex ) {
287289 checkboxes [ i ] . className = 'multiSelect checkboxLayer hide' ;
288290 }
289291 }
290292
293+ // If it's already hidden, show it
291294 if ( checkboxes [ multiSelectIndex ] . className == 'multiSelect checkboxLayer hide' ) {
292295 $scope . currentButton = multiSelectButtons [ multiSelectIndex ] ;
293296 checkboxes [ multiSelectIndex ] . className = 'multiSelect checkboxLayer show' ;
294297 // https://github.com/isteven/angular-multi-select/pull/5 - On open callback
295298 $scope . onOpen ( ) ;
296299 }
300+
301+ // If it's already displayed, hide it
297302 else if ( checkboxes [ multiSelectIndex ] . className == 'multiSelect checkboxLayer show' ) {
298303 checkboxes [ multiSelectIndex ] . className = 'multiSelect checkboxLayer hide' ;
299304 // https://github.com/isteven/angular-multi-select/pull/5 - On close callback
@@ -419,17 +424,33 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$
419424 // Watch for changes in directive state (disabled or enabled)
420425 $scope . $watch ( 'isDisabled' , function ( newVal ) {
421426 $scope . isDisabled = newVal ;
427+ } ) ;
428+
429+ // This is for touch enabled devices. We don't want to hide checkboxes on scroll.
430+ angular . element ( document ) . bind ( 'touchstart' , function ( e ) {
431+ $scope . $apply ( function ( ) {
432+ $scope . scrolled = false ;
433+ } ) ;
422434 } ) ;
423435
424- // Monitor for clicks or touches outside the button element to hide the checkboxes
425- angular . element ( document ) . bind ( 'click touchstart' , function ( e ) {
426- var checkboxes = document . querySelectorAll ( '.checkboxLayer' ) ;
427- if ( e . target . className . indexOf ( 'multiSelect' ) === - 1 ) {
428- for ( i = 0 ; i < checkboxes . length ; i ++ ) {
429- checkboxes [ i ] . className = 'multiSelect checkboxLayer hide' ;
430- }
431- e . stopPropagation ( ) ;
432- }
436+ angular . element ( document ) . bind ( 'touchmove' , function ( e ) {
437+ $scope . $apply ( function ( ) {
438+ $scope . scrolled = true ;
439+ } ) ;
440+ } ) ;
441+
442+ // Monitor for click or touches outside the button element to hide the checkboxes
443+ angular . element ( document ) . bind ( 'click touchend' , function ( e ) {
444+
445+ if ( e . type === 'click' || e . type === 'touchend' && $scope . scrolled === false ) {
446+ var checkboxes = document . querySelectorAll ( '.checkboxLayer' ) ;
447+ if ( e . target . className . indexOf ( 'multiSelect' ) === - 1 ) {
448+ for ( i = 0 ; i < checkboxes . length ; i ++ ) {
449+ checkboxes [ i ] . className = 'multiSelect checkboxLayer hide' ;
450+ }
451+ e . stopPropagation ( ) ;
452+ }
453+ }
433454 } ) ;
434455
435456 // For IE8, perhaps. Not sure if this is really executed.
0 commit comments