diff --git a/angular-multi-select.js b/angular-multi-select.js index 6117d63..9153ab0 100644 --- a/angular-multi-select.js +++ b/angular-multi-select.js @@ -49,6 +49,7 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$ tickProperty : '@', disableProperty : '@', orientation : '@', + defaultLabel : '@', maxLabels : '@', isDisabled : '=', directiveId : '@', @@ -179,11 +180,11 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$ // Write label... if ( $scope.selectedItems.length === 0 ) { - $scope.varButtonLabel = 'None selected'; + $scope.varButtonLabel = ($scope.defaultLabel)? $scope.defaultLabel : 'None selected'; } - else { + else { var tempMaxLabels = $scope.selectedItems.length; - if ( typeof $scope.maxLabels !== 'undefined' && $scope.maxLabels !== '' && $scope.maxLabels !== "0" ) { + if ( typeof $scope.maxLabels !== 'undefined' && $scope.maxLabels !== '' ) { tempMaxLabels = $scope.maxLabels; } @@ -202,11 +203,15 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$ } ctr++; } - }); + }); if ( $scope.more === true ) { - $scope.varButtonLabel += ', ... (Total: ' + $scope.selectedItems.length + ')'; - }$scope + if (tempMaxLabels > 0) { + $scope.varButtonLabel += ', ... '; + } + + $scope.varButtonLabel += '(Total: ' + $scope.selectedItems.length + ')'; + } } $scope.varButtonLabel = $sce.trustAsHtml( $scope.varButtonLabel + '' ); } @@ -444,7 +449,7 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$ if ( e.type === 'click' || e.type === 'touchend' && $scope.scrolled === false ) { var checkboxes = document.querySelectorAll( '.checkboxLayer' ); - if ( e.target.className.indexOf( 'multiSelect' ) === -1 ) { + if ( e.target.className.indexOf === undefined || e.target.className.indexOf( 'multiSelect' )) { for( i=0; i < checkboxes.length; i++ ) { checkboxes[i].className = 'multiSelect checkboxLayer hide'; } diff --git a/angular-multi-select.min.js b/angular-multi-select.min.js deleted file mode 100644 index 3acf268..0000000 --- a/angular-multi-select.min.js +++ /dev/null @@ -1,6 +0,0 @@ -/* - * Angular JS Multi Select - * http://github.com/isteven/angular-multi-select - * Copyright (c) 2014 Ignatius Steven - */ -angular.module("multi-select",["ng"]).directive("multiSelect",["$sce","$filter",function(e,t){return{restrict:"AE",replace:true,scope:{inputModel:"=",outputModel:"=",buttonLabel:"@",selectionMode:"@",itemLabel:"@",tickProperty:"@",disableProperty:"@",orientation:"@",maxLabels:"@",isDisabled:"=",directiveId:"@",helperElements:"@",onOpen:"&",onClose:"&",onBlur:"&",onFocus:"&"},template:''+'"+'
'+"
"+"Select:  "+' '+' '+''+"
"+'
'+'Filter: '+' '+"
"+'
'+'
'+'
'+"
"+'
'+'  "+"
"+"
"+"
"+"
",link:function(t,n,r){t.selectedItems=[];t.backUp=[];t.varButtonLabel="";t.currentButton=null;t.scrolled=false;t.displayHelper=function(e){if(typeof r.helperElements==="undefined"){return true}switch(e.toUpperCase()){case"ALL":if(r.selectionMode&&t.selectionMode.toUpperCase()==="SINGLE"){return false}else{if(r.helperElements&&t.helperElements.toUpperCase().indexOf("ALL")>=0){return true}}break;case"NONE":if(r.selectionMode&&t.selectionMode.toUpperCase()==="SINGLE"){return false}else{if(r.helperElements&&t.helperElements.toUpperCase().indexOf("NONE")>=0){return true}}break;case"RESET":if(r.helperElements&&t.helperElements.toUpperCase().indexOf("RESET")>=0){return true}break;case"FILTER":if(r.helperElements&&t.helperElements.toUpperCase().indexOf("FILTER")>=0){return true}break;default:break}t};t.syncItems=function(e,n){index=t.inputModel.indexOf(e);t.inputModel[index][t.tickProperty]=!t.inputModel[index][t.tickProperty];if(r.selectionMode&&t.selectionMode.toUpperCase()==="SINGLE"){t.inputModel[index][t.tickProperty]=true;for(i=0;in){t.more=true}else{t.more=false}angular.forEach(t.selectedItems,function(e,r){if(typeof e!=="undefined"){if(ctr0?", ":"")+t.writeLabel(e,"buttonLabel")}ctr++}});if(t.more===true){t.varButtonLabel+=", ... (Total: "+t.selectedItems.length+")"}t}t.varButtonLabel=e.trustAsHtml(t.varButtonLabel+'')};t.itemIsDisabled=function(e){if(e[t.disableProperty]===true){return true}else{t;if(t.isDisabled===true){return true}else{return false}}};t.writeLabel=function(n,r){var i="";var s=t[r].split(" ");angular.forEach(s,function(e,t){if(typeof e!=="undefined"){angular.forEach(n,function(t,n){if(n==e){i+=" "+t}})}});return e.trustAsHtml(i)};t.toggleCheckboxes=function(e){if(e.target){if(e.target.tagName.toUpperCase()!=="BUTTON"&&e.target.className.indexOf("multiSelectButton")<0){if(r.selectionMode&&t.selectionMode.toUpperCase()==="SINGLE"){if(e.target.tagName.toUpperCase()==="INPUT"){e=t.findUpTag(e.target,"div","checkboxLayer");e=e.previousSibling}}else{e=t.findUpTag(e.target,"button","multiSelectButton")}}else{e=e.target}}t.labelFilter="";var n=-1;var s=document.querySelectorAll(".checkboxLayer");var o=document.querySelectorAll(".multiSelectButton");for(i=0;i-1){for(i=0;i-1){return e}}}return null};t.select=function(e){var n=[];switch(e.toUpperCase()){case"ALL":angular.forEach(t.inputModel,function(e,n){if(typeof e!=="undefined"&&e[t.disableProperty]!==true){e[t.tickProperty]=true}});break;case"NONE":angular.forEach(t.inputModel,function(e,n){if(typeof e!=="undefined"&&e[t.disableProperty]!==true){e[t.tickProperty]=false}});break;case"RESET":t.inputModel=angular.copy(t.backUp);break;default:}t.refreshSelectedItems()};validate=function(){if(!("inputModel"in r)){console.log("Multi-select error: input-model is not defined! (ID: "+t.directiveId+")")}if(!("buttonLabel"in r)){console.log("Multi-select error: button-label is not defined! (ID: "+t.directiveId+")")}if(!("itemLabel"in r)){console.log("Multi-select error: item-label is not defined! (ID: "+t.directiveId+")")}if(!("tickProperty"in r)){console.log("Multi-select error: tick-property is not defined! (ID: "+t.directiveId+")")}};validateProperties=function(e,n){var r=false;var i="";angular.forEach(e,function(e,t){if(typeof e!=="undefined"){var i=true;angular.forEach(n,function(t,n){if(typeof t!=="undefined"&&i){if(!(e in t)){r=true;i=false;missingLabel=e}}})}});if(r===true){console.log('Multi-select error: property "'+missingLabel+'" is not available in the input model. (Name: '+t.directiveId+")")}};validate();t.refreshSelectedItems();t.$watch("inputModel",function(e,n){if(t.newVal!=="undefined"){validateProperties(t.itemLabel.split(" "),t.inputModel);validateProperties(new Array(t.tickProperty),t.inputModel)}t.refreshSelectedItems()},true);t.$watch("inputModel",function(e,n){if(t.newVal!=="undefined"){validateProperties(t.itemLabel.split(" "),t.inputModel);validateProperties(new Array(t.tickProperty),t.inputModel)}t.backUp=angular.copy(t.inputModel);t.refreshSelectedItems()});t.$watch("isDisabled",function(e){t.isDisabled=e});angular.element(document).bind("touchstart",function(e){t.$apply(function(){t.scrolled=false})});angular.element(document).bind("touchmove",function(e){t.$apply(function(){t.scrolled=true})});angular.element(document).bind("click touchend",function(e){if(e.type==="click"||e.type==="touchend"&&t.scrolled===false){var n=document.querySelectorAll(".checkboxLayer");if(e.target.className.indexOf("multiSelect")===-1){for(i=0;i