diff options
author | isteven <isteven@server.fake> | 2014-04-16 18:58:11 +0800 |
---|---|---|
committer | isteven <isteven@server.fake> | 2014-04-16 18:58:11 +0800 |
commit | d6f039eb7f719495c95a3cb127235704cf7fca70 (patch) | |
tree | a3218650b2f07a25f44f92de89827178d2a787e2 /angular-multi-select.js | |
parent | 28ff031cf88cdc0247179379f0432fb9ca206e8d (diff) | |
download | angular-multi-select-d6f039eb7f719495c95a3cb127235704cf7fca70.zip angular-multi-select-d6f039eb7f719495c95a3cb127235704cf7fca70.tar.gz angular-multi-select-d6f039eb7f719495c95a3cb127235704cf7fca70.tar.bz2 |
bug fix: selection-mode attribute is now non compulsory
Diffstat (limited to 'angular-multi-select.js')
-rw-r--r-- | angular-multi-select.js | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/angular-multi-select.js b/angular-multi-select.js index d2a7033..5b8d173 100644 --- a/angular-multi-select.js +++ b/angular-multi-select.js @@ -75,7 +75,7 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', fu '</div>' + '<div class="multiSelect acol">' + '<label class="multiSelect" ng-class="{checkboxSelected:item[ tickProperty ]}">' + - '<input class="multiSelect checkbox" type="checkbox" ng-disabled="itemIsDisabled( item )" ng-checked="item[ tickProperty ]" ng-click="syncItems( item )" />' + + '<input class="multiSelect checkbox" type="checkbox" ng-disabled="itemIsDisabled( item )" ng-checked="item[ tickProperty ]" ng-click="syncItems( item, $event )" />' + '<span class="multiSelect" ng-class="{disabled:itemIsDisabled( item )}" ng-bind-html="writeLabel( item, \'itemLabel\' )"></span>' + '</label> ' + '</div>' + @@ -90,18 +90,19 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', fu $scope.varButtonLabel = ''; // Checkbox is ticked - $scope.syncItems = function( item ) { - index = $scope.inputModel.indexOf( item ); - tempState = $scope.inputModel[ index ][ $scope.tickProperty ]; - $scope.inputModel[ index ][ $scope.tickProperty ] = !tempState; + $scope.syncItems = function( item, e ) { + index = $scope.inputModel.indexOf( item ); + $scope.inputModel[ index ][ $scope.tickProperty ] = !$scope.inputModel[ index ][ $scope.tickProperty ]; // If it's single selection mode - if ( $scope.selectionMode.toUpperCase() === 'SINGLE' ) { + if ( attrs.selectionMode && $scope.selectionMode.toUpperCase() === 'SINGLE' ) { + $scope.inputModel[ index ][ $scope.tickProperty ] = true; for( i=0; i<$scope.inputModel.length;i++) { if ( i !== index ) { - $scope.inputModel[ i ][ $scope.tickProperty ] = tempState; + $scope.inputModel[ i ][ $scope.tickProperty ] = false; } - } + } + $scope.toggleCheckboxes( e ); } $scope.refreshSelectedItems(); @@ -197,7 +198,7 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', fu // UI operations to show/hide checkboxes $scope.toggleCheckboxes = function( e ) { - + $scope.labelFilter = ''; // We search them based on the class names @@ -210,7 +211,16 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', fu multiSelectIndex = i; break; } - } + } + + if ( attrs.selectionMode && $scope.selectionMode.toUpperCase() === 'SINGLE' ) { + for( i=0; i < multiSelectButtons.length; i++ ) { + if ( e.target.parentNode.parentNode.parentNode.parentNode.previousSibling === multiSelectButtons[ i ] ) { + multiSelectIndex = i; + break; + } + } + } if ( multiSelectIndex > -1 ) { for( i=0; i < checkboxes.length; i++ ) { |