From 03fd05564968e023b259aafc5e91986cdcbd1bba Mon Sep 17 00:00:00 2001 From: pkempenaers Date: Fri, 10 Feb 2017 15:34:03 +0100 Subject: [PATCH 01/11] Add Contributing info --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 1ba92e8b..cffa8a66 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,10 @@ http://dotansimha.github.io/angularjs-dropdown-multiselect/ 3. Include the module in angular (i.e. in `app.js`) - `angularjs-dropdown-multiselect` +## Contributing +Issues and PR's are much appreciated. We're currently working on reducing them. +When you create a new PR please make it against the fix branch instead of master. + ## Usage and Documentation See the documentation and examples in the GitHub pages: http://dotansimha.github.io/angularjs-dropdown-multiselect/ From 2d8ddee854c387f7f04ae6e4f8740e942e8bdb65 Mon Sep 17 00:00:00 2001 From: pkempenaers Date: Fri, 10 Feb 2017 15:39:11 +0100 Subject: [PATCH 02/11] Adjust contributing info --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cffa8a66..90de6c6f 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ http://dotansimha.github.io/angularjs-dropdown-multiselect/ ## Contributing Issues and PR's are much appreciated. We're currently working on reducing them. -When you create a new PR please make it against the fix branch instead of master. +When you create a new PR please make it against the develop branch when adding new features and to the fix branch when fixing small issues instead of master. ## Usage and Documentation See the documentation and examples in the GitHub pages: From e64f23df9a0e771b2fe0ba8d4b552a23753077b5 Mon Sep 17 00:00:00 2001 From: pkempenaers Date: Fri, 10 Feb 2017 15:42:17 +0100 Subject: [PATCH 03/11] Release 1.11.1 --- bower.json | 2 +- dist/angularjs-dropdown-multiselect.min.js | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bower.json b/bower.json index 26672bf6..4face5a3 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angularjs-dropdown-multiselect", - "version": "1.11.0", + "version": "1.11.1", "authors": [ "Dotan Simha ", "Pieter Kempenaers " diff --git a/dist/angularjs-dropdown-multiselect.min.js b/dist/angularjs-dropdown-multiselect.min.js index 5acfc3e1..f92ee98b 100644 --- a/dist/angularjs-dropdown-multiselect.min.js +++ b/dist/angularjs-dropdown-multiselect.min.js @@ -1 +1 @@ -!function(angular){"use strict";function contains(collection,target){var containsTarget=!1;return collection.some(function(object){return object===target?(containsTarget=!0,!0):void 0}),containsTarget}function find(collection,properties){var target;return collection.some(function(object){var hasAllSameProperties=!0;return Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(target=object,!0):void 0}),target}function findIndex(collection,properties){var index=-1,counter=-1;return collection.some(function(object){var hasAllSameProperties=!0;return counter+=1,Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(index=counter,!0):void 0}),index}var directiveModule=angular.module("angularjs-dropdown-multiselect",[]);directiveModule.directive("dmDropdownStaticInclude",["$compile",function($compile){return function(scope,element,attrs){var template=attrs.dmDropdownStaticInclude,contents=element.html(template).contents();$compile(contents)(scope)}}]),directiveModule.directive("ngDropdownMultiselect",["$filter","$document","$compile","$parse",function($filter,$document,$compile,$parse){return{restrict:"AE",scope:{selectedModel:"=",options:"=",extraSettings:"=",events:"=",searchFilter:"=?",translationTexts:"=",groupBy:"@",disabled:"="},template:function(element,attrs){var checkboxes=attrs.checkboxes?!0:!1,groups=attrs.groupBy?!0:!1,template='"},link:function($scope,$element,$attrs){function getFindObj(id){var findObj={};return""===$scope.settings.externalIdProp?findObj[$scope.settings.idProp]=id:findObj[$scope.settings.externalIdProp]=id,findObj}function clearObject(object){for(var prop in object)delete object[prop]}function textWidth(text){var $btn=$element.find("button"),canvas=document.createElement("canvas"),ctx=canvas.getContext("2d");return ctx.font=$btn.css("font-size")+$btn.css("font-family"),ctx.originalFont=$btn.css("font-size")+$btn.css("font-family"),ctx.fillStyle="#000000",ctx.measureText(text).width}var $dropdownTrigger=$element.children()[0];$scope.toggleDropdown=function(){$scope.open?$scope.close():$scope.open=!0,$scope.settings.keyboardControls&&$scope.open&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):setTimeout(function(){angular.element($element)[0].querySelector(".option").focus()},0))},$scope.checkboxClick=function($event,id){$scope.setSelectedItem(id,!1,!0),$event.stopImmediatePropagation()},$scope.externalEvents={onItemSelect:angular.noop,onItemDeselect:angular.noop,onSelectAll:angular.noop,onDeselectAll:angular.noop,onInitDone:angular.noop,onMaxSelectionReached:angular.noop,onSelectionChanged:angular.noop,onClose:angular.noop},$scope.settings={dynamicTitle:!0,scrollable:!1,scrollableHeight:"300px",closeOnBlur:!0,displayProp:"label",idProp:"id",externalIdProp:"id",enableSearch:!1,selectionLimit:0,showCheckAll:!0,showUncheckAll:!0,showEnableSearchButton:!1,closeOnSelect:!1,buttonClasses:"btn btn-default",closeOnDeselect:!1,groupBy:$attrs.groupBy||void 0,groupByTextProvider:null,smartButtonMaxItems:0,smartButtonTextConverter:angular.noop,styleActive:!1,keyboardControls:!1,template:"{{getPropertyForObject(option, settings.displayProp)}}",searchField:"$",showAllSelectedText:!1},$scope.texts={checkAll:"Check All",uncheckAll:"Uncheck All",selectionCount:"checked",selectionOf:"/",searchPlaceholder:"Search...",buttonDefaultText:"Select",dynamicButtonTextSuffix:"checked",disableSearch:"Disable search",enableSearch:"Enable search",selectGroup:"Select all:",allSelectedText:"All"},$scope.input={searchFilter:$scope.searchFilter||""},angular.isDefined($scope.settings.groupBy)&&$scope.$watch("options",function(newValue){angular.isDefined(newValue)&&($scope.orderedItems=$filter("orderBy")(newValue,$scope.settings.groupBy))}),$scope.$watch("selectedModel",function(newValue){Array.isArray(newValue)?$scope.singleSelection=!1:$scope.singleSelection=!0}),$scope.close=function(){$scope.open=!1,$scope.externalEvents.onClose()},$scope.selectCurrentGroup=function(currentGroup){$scope.selectedModel.splice(0,$scope.selectedModel.length),$scope.orderedItems&&$scope.orderedItems.forEach(function(item){item[$scope.groupBy]===currentGroup&&$scope.setSelectedItem($scope.getPropertyForObject(item,$scope.settings.idProp),!1,!1)}),$scope.externalEvents.onSelectionChanged()},angular.extend($scope.settings,$scope.extraSettings||[]),angular.extend($scope.externalEvents,$scope.events||[]),angular.extend($scope.texts,$scope.translationTexts),$scope.singleSelection=1===$scope.settings.selectionLimit,$scope.singleSelection&&angular.isArray($scope.selectedModel)&&0===$scope.selectedModel.length&&clearObject($scope.selectedModel),$scope.settings.closeOnBlur&&$document.on("click",function(e){if($scope.open){for(var target=e.target.parentElement,parentFound=!1;angular.isDefined(target)&&null!==target&&!parentFound;)target.className.split&&contains(target.className.split(" "),"multiselect-parent")&&!parentFound&&target===$dropdownTrigger&&(parentFound=!0),target=target.parentElement;parentFound||$scope.$apply(function(){$scope.close()})}}),$scope.getGroupLabel=function(groupValue){return null!==$scope.settings.groupByTextProvider?$scope.settings.groupByTextProvider(groupValue):groupValue},$scope.getButtonText=function(){if($scope.settings.dynamicTitle&&($scope.selectedModel.length>0||angular.isObject($scope.selectedModel)&&Object.keys($scope.selectedModel).length>0)){if($scope.settings.smartButtonMaxItems>0){var paddingWidth=24,borderWidth=2,dropdownIconWidth=8,widthLimit=(textWidth("..."),$element[0].offsetWidth-paddingWidth-borderWidth-dropdownIconWidth),itemsText=[];angular.forEach($scope.options,function(optionItem){if($scope.isChecked($scope.getPropertyForObject(optionItem,$scope.settings.idProp))){var displayText=$scope.getPropertyForObject(optionItem,$scope.settings.displayProp),converterResponse=$scope.settings.smartButtonTextConverter(displayText,optionItem);itemsText.push(converterResponse?converterResponse:displayText)}}),$scope.selectedModel.length>$scope.settings.smartButtonMaxItems&&(itemsText=itemsText.slice(0,$scope.settings.smartButtonMaxItems),itemsText.push("..."));for(var result=itemsText.join(", "),index=result.length-4;textWidth(result)>widthLimit;)"..."!==itemsText[itemsText.length-1]&&(itemsText.push("..."),result+="..."),result=result.slice(0,index)+result.slice(index+1),index--;return result}var totalSelected;return totalSelected=$scope.singleSelection?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.idProp])?1:0:angular.isDefined($scope.selectedModel)?$scope.selectedModel.length:0,0===totalSelected?$scope.texts.buttonDefaultText:$scope.settings.showAllSelectedText&&totalSelected===$scope.options.length?$scope.texts.allSelectedText:totalSelected+" "+$scope.texts.dynamicButtonTextSuffix}return $scope.texts.buttonDefaultText},$scope.getPropertyForObject=function(object,property){return angular.isDefined(object)&&object.hasOwnProperty(property)?object[property]:void 0},$scope.selectAll=function(){var searchResult;$scope.deselectAll(!0),$scope.externalEvents.onSelectAll(),searchResult=$filter("filter")($scope.options,$scope.getFilter($scope.input.searchFilter)),angular.forEach(searchResult,function(value){$scope.setSelectedItem(value[$scope.settings.idProp],!0,!1)}),$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.deselectAll=function(dontSendEvent){dontSendEvent=dontSendEvent||!1,dontSendEvent||$scope.externalEvents.onDeselectAll(),$scope.singleSelection?clearObject($scope.selectedModel):$scope.selectedModel.splice(0,$scope.selectedModel.length),dontSendEvent||$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.setSelectedItem=function(id,dontRemove,fireSelectionChange){var findObj=getFindObj(id),finalObj=null;if(finalObj=""===$scope.settings.externalIdProp?find($scope.options,findObj):findObj,$scope.singleSelection)clearObject($scope.selectedModel),angular.extend($scope.selectedModel,finalObj),fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),($scope.settings.closeOnSelect||$scope.settings.closeOnDeselect)&&$scope.close();else{dontRemove=dontRemove||!1;var exists=-1!==findIndex($scope.selectedModel,findObj);!dontRemove&&exists?($scope.selectedModel.splice(findIndex($scope.selectedModel,findObj),1),$scope.externalEvents.onItemDeselect(findObj),$scope.settings.closeOnDeselect&&$scope.close()):!exists&&(0===$scope.settings.selectionLimit||$scope.selectedModel.length<$scope.settings.selectionLimit)&&($scope.selectedModel.push(finalObj),fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),$scope.settings.closeOnSelect&&$scope.close(),$scope.settings.selectionLimit>0&&$scope.selectedModel.length===$scope.settings.selectionLimit&&$scope.externalEvents.onMaxSelectionReached())}fireSelectionChange&&$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.isChecked=function(id){return $scope.singleSelection?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.externalIdProp])&&$scope.selectedModel[$scope.settings.externalIdProp]===getFindObj(id)[$scope.settings.externalIdProp]:-1!==findIndex($scope.selectedModel,getFindObj(id))},$scope.externalEvents.onInitDone(),$scope.keyDownLink=function(event){var nextOption,sourceScope=angular.element(event.target).scope(),parent=event.target.parentNode;if($scope.settings.keyboardControls)if(13===event.keyCode||32===event.keyCode)event.preventDefault(),sourceScope.option?$scope.setSelectedItem($scope.getPropertyForObject(sourceScope.option,$scope.settings.idProp),!1,!0):"deselectAll"===event.target.id?$scope.deselectAll():"selectAll"===event.target.id&&$scope.selectAll();else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else if(40===event.keyCode){for(event.preventDefault(),parent.nextElementSibling&&(nextOption=parent.nextElementSibling.querySelector("a")||parent.nextElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.nextElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearchDefault=function(event){var nextOption,parent=event.target.parentNode.parentNode;if($scope.settings.keyboardControls)if(9===event.keyCode||40===event.keyCode)event.preventDefault(),setTimeout(function(){angular.element($element)[0].querySelector(".option").focus()},0);else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearch=function(event,searchFilter){var searchResult;$scope.settings.keyboardControls&&13===event.keyCode&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?(searchResult=$filter("filter")($scope.options,$scope.getFilter(searchFilter)),1===searchResult.length&&$scope.setSelectedItem($scope.getPropertyForObject(searchResult[0],$scope.settings.idProp),!1,!0)):$scope.settings.enableSearch&&$scope.selectAll())},$scope.getFilter=function(searchFilter){var filter={};return filter[$scope.settings.searchField]=searchFilter,filter},$scope.toggleSearch=function($event){$event&&$event.stopPropagation(),$scope.settings.enableSearch=!$scope.settings.enableSearch,$scope.settings.enableSearch||($scope.input.searchFilter="")},$scope.keyDownToggleSearch=function(){$scope.settings.keyboardControls&&13===event.keyCode&&($scope.toggleSearch(),$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):angular.element($element)[0].querySelector(".option").focus())}}}}])}(angular); \ No newline at end of file +!function(angular){"use strict";function contains(collection,target){var containsTarget=!1;return collection.some(function(object){return object===target?(containsTarget=!0,!0):void 0}),containsTarget}function find(collection,properties){var target;return collection.some(function(object){var hasAllSameProperties=!0;return Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(target=object,!0):void 0}),target}function findIndex(collection,properties){var index=-1,counter=-1;return collection.some(function(object){var hasAllSameProperties=!0;return counter+=1,Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(index=counter,!0):void 0}),index}var directiveModule=angular.module("angularjs-dropdown-multiselect",[]);directiveModule.directive("dmDropdownStaticInclude",["$compile",function($compile){return function(scope,element,attrs){var template=attrs.dmDropdownStaticInclude,contents=element.html(template).contents();$compile(contents)(scope)}}]),directiveModule.directive("ngDropdownMultiselect",["$filter","$document","$compile","$parse",function($filter,$document,$compile,$parse){return{restrict:"AE",scope:{selectedModel:"=",options:"=",extraSettings:"=",events:"=",searchFilter:"=?",translationTexts:"=",groupBy:"@",disabled:"="},template:function(element,attrs){var checkboxes=attrs.checkboxes?!0:!1,groups=attrs.groupBy?!0:!1,template='"},link:function($scope,$element,$attrs){function getFindObj(id){var findObj={};return""===$scope.settings.externalIdProp?findObj[$scope.settings.idProp]=id:findObj[$scope.settings.externalIdProp]=id,findObj}function clearObject(object){for(var prop in object)delete object[prop]}function textWidth(text){var $btn=$element.find("button"),canvas=document.createElement("canvas"),ctx=canvas.getContext("2d");return ctx.font=$btn.css("font-size")+$btn.css("font-family"),ctx.originalFont=$btn.css("font-size")+$btn.css("font-family"),ctx.fillStyle="#000000",ctx.measureText(text).width}function focusFirstOption(){setTimeout(function(){var elementToFocus=angular.element($element)[0].querySelector(".option");angular.isDefined(elementToFocus)&&null!=elementToFocus&&elementToFocus.focus()},0)}var $dropdownTrigger=$element.children()[0];$scope.toggleDropdown=function(){$scope.open?$scope.close():$scope.open=!0,$scope.settings.keyboardControls&&$scope.open&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):focusFirstOption())},$scope.checkboxClick=function($event,id){$scope.setSelectedItem(id,!1,!0),$event.stopImmediatePropagation()},$scope.externalEvents={onItemSelect:angular.noop,onItemDeselect:angular.noop,onSelectAll:angular.noop,onDeselectAll:angular.noop,onInitDone:angular.noop,onMaxSelectionReached:angular.noop,onSelectionChanged:angular.noop,onClose:angular.noop},$scope.settings={dynamicTitle:!0,scrollable:!1,scrollableHeight:"300px",closeOnBlur:!0,displayProp:"label",idProp:"id",externalIdProp:"id",enableSearch:!1,selectionLimit:0,showCheckAll:!0,showUncheckAll:!0,showEnableSearchButton:!1,closeOnSelect:!1,buttonClasses:"btn btn-default",closeOnDeselect:!1,groupBy:$attrs.groupBy||void 0,groupByTextProvider:null,smartButtonMaxItems:0,smartButtonTextConverter:angular.noop,styleActive:!1,keyboardControls:!1,template:"{{getPropertyForObject(option, settings.displayProp)}}",searchField:"$",showAllSelectedText:!1},$scope.texts={checkAll:"Check All",uncheckAll:"Uncheck All",selectionCount:"checked",selectionOf:"/",searchPlaceholder:"Search...",buttonDefaultText:"Select",dynamicButtonTextSuffix:"checked",disableSearch:"Disable search",enableSearch:"Enable search",selectGroup:"Select all:",allSelectedText:"All"},$scope.input={searchFilter:$scope.searchFilter||""},angular.isDefined($scope.settings.groupBy)&&$scope.$watch("options",function(newValue){angular.isDefined(newValue)&&($scope.orderedItems=$filter("orderBy")(newValue,$scope.settings.groupBy))}),$scope.$watch("selectedModel",function(newValue){Array.isArray(newValue)?$scope.singleSelection=!1:$scope.singleSelection=!0}),$scope.close=function(){$scope.open=!1,$scope.externalEvents.onClose()},$scope.selectCurrentGroup=function(currentGroup){$scope.selectedModel.splice(0,$scope.selectedModel.length),$scope.orderedItems&&$scope.orderedItems.forEach(function(item){item[$scope.groupBy]===currentGroup&&$scope.setSelectedItem($scope.getPropertyForObject(item,$scope.settings.idProp),!1,!1)}),$scope.externalEvents.onSelectionChanged()},angular.extend($scope.settings,$scope.extraSettings||[]),angular.extend($scope.externalEvents,$scope.events||[]),angular.extend($scope.texts,$scope.translationTexts),$scope.singleSelection=1===$scope.settings.selectionLimit,$scope.singleSelection&&angular.isArray($scope.selectedModel)&&0===$scope.selectedModel.length&&clearObject($scope.selectedModel),$scope.settings.closeOnBlur&&$document.on("click",function(e){if($scope.open){for(var target=e.target.parentElement,parentFound=!1;angular.isDefined(target)&&null!==target&&!parentFound;)target.className.split&&contains(target.className.split(" "),"multiselect-parent")&&!parentFound&&target===$dropdownTrigger&&(parentFound=!0),target=target.parentElement;parentFound||$scope.$apply(function(){$scope.close()})}}),$scope.getGroupLabel=function(groupValue){return null!==$scope.settings.groupByTextProvider?$scope.settings.groupByTextProvider(groupValue):groupValue},$scope.getButtonText=function(){if($scope.settings.dynamicTitle&&($scope.selectedModel.length>0||angular.isObject($scope.selectedModel)&&Object.keys($scope.selectedModel).length>0)){if($scope.settings.smartButtonMaxItems>0){var paddingWidth=24,borderWidth=2,dropdownIconWidth=8,widthLimit=(textWidth("..."),$element[0].offsetWidth-paddingWidth-borderWidth-dropdownIconWidth),itemsText=[];angular.forEach($scope.options,function(optionItem){if($scope.isChecked($scope.getPropertyForObject(optionItem,$scope.settings.idProp))){var displayText=$scope.getPropertyForObject(optionItem,$scope.settings.displayProp),converterResponse=$scope.settings.smartButtonTextConverter(displayText,optionItem);itemsText.push(converterResponse?converterResponse:displayText)}}),$scope.selectedModel.length>$scope.settings.smartButtonMaxItems&&(itemsText=itemsText.slice(0,$scope.settings.smartButtonMaxItems),itemsText.push("..."));for(var result=itemsText.join(", "),index=result.length-4;textWidth(result)>widthLimit;)"..."!==itemsText[itemsText.length-1]&&(itemsText.push("..."),result+="..."),result=result.slice(0,index)+result.slice(index+1),index--;return result}var totalSelected;return totalSelected=$scope.singleSelection?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.idProp])?1:0:angular.isDefined($scope.selectedModel)?$scope.selectedModel.length:0,0===totalSelected?$scope.texts.buttonDefaultText:$scope.settings.showAllSelectedText&&totalSelected===$scope.options.length?$scope.texts.allSelectedText:totalSelected+" "+$scope.texts.dynamicButtonTextSuffix}return $scope.texts.buttonDefaultText},$scope.getPropertyForObject=function(object,property){return angular.isDefined(object)&&object.hasOwnProperty(property)?object[property]:void 0},$scope.selectAll=function(){var searchResult;$scope.deselectAll(!0),$scope.externalEvents.onSelectAll(),searchResult=$filter("filter")($scope.options,$scope.getFilter($scope.input.searchFilter)),angular.forEach(searchResult,function(value){$scope.setSelectedItem(value[$scope.settings.idProp],!0,!1)}),$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.deselectAll=function(dontSendEvent){dontSendEvent=dontSendEvent||!1,dontSendEvent||$scope.externalEvents.onDeselectAll(),$scope.singleSelection?clearObject($scope.selectedModel):$scope.selectedModel.splice(0,$scope.selectedModel.length),dontSendEvent||$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.setSelectedItem=function(id,dontRemove,fireSelectionChange){var findObj=getFindObj(id),finalObj=null;if(finalObj=""===$scope.settings.externalIdProp?find($scope.options,findObj):findObj,$scope.singleSelection)clearObject($scope.selectedModel),angular.extend($scope.selectedModel,finalObj),fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),($scope.settings.closeOnSelect||$scope.settings.closeOnDeselect)&&$scope.close();else{dontRemove=dontRemove||!1;var exists=-1!==findIndex($scope.selectedModel,findObj);!dontRemove&&exists?($scope.selectedModel.splice(findIndex($scope.selectedModel,findObj),1),$scope.externalEvents.onItemDeselect(findObj),$scope.settings.closeOnDeselect&&$scope.close()):!exists&&(0===$scope.settings.selectionLimit||$scope.selectedModel.length<$scope.settings.selectionLimit)&&($scope.selectedModel.push(finalObj),fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),$scope.settings.closeOnSelect&&$scope.close(),$scope.settings.selectionLimit>0&&$scope.selectedModel.length===$scope.settings.selectionLimit&&$scope.externalEvents.onMaxSelectionReached())}fireSelectionChange&&$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.isChecked=function(id){return $scope.singleSelection?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.externalIdProp])&&$scope.selectedModel[$scope.settings.externalIdProp]===getFindObj(id)[$scope.settings.externalIdProp]:-1!==findIndex($scope.selectedModel,getFindObj(id))},$scope.externalEvents.onInitDone(),$scope.keyDownLink=function(event){var nextOption,sourceScope=angular.element(event.target).scope(),parent=event.target.parentNode;if($scope.settings.keyboardControls)if(13===event.keyCode||32===event.keyCode)event.preventDefault(),sourceScope.option?$scope.setSelectedItem($scope.getPropertyForObject(sourceScope.option,$scope.settings.idProp),!1,!0):"deselectAll"===event.target.id?$scope.deselectAll():"selectAll"===event.target.id&&$scope.selectAll();else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else if(40===event.keyCode){for(event.preventDefault(),parent.nextElementSibling&&(nextOption=parent.nextElementSibling.querySelector("a")||parent.nextElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.nextElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearchDefault=function(event){var nextOption,parent=event.target.parentNode.parentNode;if($scope.settings.keyboardControls)if(9===event.keyCode||40===event.keyCode)event.preventDefault(),focusFirstOption();else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearch=function(event,searchFilter){var searchResult;$scope.settings.keyboardControls&&13===event.keyCode&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?(searchResult=$filter("filter")($scope.options,$scope.getFilter(searchFilter)),1===searchResult.length&&$scope.setSelectedItem($scope.getPropertyForObject(searchResult[0],$scope.settings.idProp),!1,!0)):$scope.settings.enableSearch&&$scope.selectAll())},$scope.getFilter=function(searchFilter){var filter={};return filter[$scope.settings.searchField]=searchFilter,filter},$scope.toggleSearch=function($event){$event&&$event.stopPropagation(),$scope.settings.enableSearch=!$scope.settings.enableSearch,$scope.settings.enableSearch||($scope.input.searchFilter="")},$scope.keyDownToggleSearch=function(){$scope.settings.keyboardControls&&13===event.keyCode&&($scope.toggleSearch(),$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):focusFirstOption())}}}}])}(angular); \ No newline at end of file diff --git a/package.json b/package.json index 8d1d6c9b..2a883cdd 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "author": "pkempenaers@myforce.be", "name": "angularjs-dropdown-multiselect", - "version": "1.11.0", + "version": "1.11.1", "description": "This directive gives you a Bootstrap Dropdown with the power of AngularJS directives.", "homepage": "http://dotansimha.github.io/angularjs-dropdown-multiselect/#/", "dependencies": { From c6d5aa2fe530c3aac746a6a4fb751774d63ea0d0 Mon Sep 17 00:00:00 2001 From: pkempenaers Date: Wed, 8 Mar 2017 09:51:14 +0100 Subject: [PATCH 04/11] Release 1.11.2 --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index a5d6421c..665b827b 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angularjs-dropdown-multiselect", - "version": "1.11.1", + "version": "1.11.2", "authors": [ "Dotan Simha ", "Pieter Kempenaers " From 7684ea8427702d4282af772985d1a2adaf4ccb7e Mon Sep 17 00:00:00 2001 From: pkempenaers Date: Wed, 8 Mar 2017 11:29:58 +0100 Subject: [PATCH 05/11] Release 1.11.3 --- bower.json | 2 +- dist/angularjs-dropdown-multiselect.min.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bower.json b/bower.json index 665b827b..f3cedf3f 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angularjs-dropdown-multiselect", - "version": "1.11.2", + "version": "1.11.3", "authors": [ "Dotan Simha ", "Pieter Kempenaers " diff --git a/dist/angularjs-dropdown-multiselect.min.js b/dist/angularjs-dropdown-multiselect.min.js index f92ee98b..67e90ce6 100644 --- a/dist/angularjs-dropdown-multiselect.min.js +++ b/dist/angularjs-dropdown-multiselect.min.js @@ -1 +1 @@ -!function(angular){"use strict";function contains(collection,target){var containsTarget=!1;return collection.some(function(object){return object===target?(containsTarget=!0,!0):void 0}),containsTarget}function find(collection,properties){var target;return collection.some(function(object){var hasAllSameProperties=!0;return Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(target=object,!0):void 0}),target}function findIndex(collection,properties){var index=-1,counter=-1;return collection.some(function(object){var hasAllSameProperties=!0;return counter+=1,Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(index=counter,!0):void 0}),index}var directiveModule=angular.module("angularjs-dropdown-multiselect",[]);directiveModule.directive("dmDropdownStaticInclude",["$compile",function($compile){return function(scope,element,attrs){var template=attrs.dmDropdownStaticInclude,contents=element.html(template).contents();$compile(contents)(scope)}}]),directiveModule.directive("ngDropdownMultiselect",["$filter","$document","$compile","$parse",function($filter,$document,$compile,$parse){return{restrict:"AE",scope:{selectedModel:"=",options:"=",extraSettings:"=",events:"=",searchFilter:"=?",translationTexts:"=",groupBy:"@",disabled:"="},template:function(element,attrs){var checkboxes=attrs.checkboxes?!0:!1,groups=attrs.groupBy?!0:!1,template='"},link:function($scope,$element,$attrs){function getFindObj(id){var findObj={};return""===$scope.settings.externalIdProp?findObj[$scope.settings.idProp]=id:findObj[$scope.settings.externalIdProp]=id,findObj}function clearObject(object){for(var prop in object)delete object[prop]}function textWidth(text){var $btn=$element.find("button"),canvas=document.createElement("canvas"),ctx=canvas.getContext("2d");return ctx.font=$btn.css("font-size")+$btn.css("font-family"),ctx.originalFont=$btn.css("font-size")+$btn.css("font-family"),ctx.fillStyle="#000000",ctx.measureText(text).width}function focusFirstOption(){setTimeout(function(){var elementToFocus=angular.element($element)[0].querySelector(".option");angular.isDefined(elementToFocus)&&null!=elementToFocus&&elementToFocus.focus()},0)}var $dropdownTrigger=$element.children()[0];$scope.toggleDropdown=function(){$scope.open?$scope.close():$scope.open=!0,$scope.settings.keyboardControls&&$scope.open&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):focusFirstOption())},$scope.checkboxClick=function($event,id){$scope.setSelectedItem(id,!1,!0),$event.stopImmediatePropagation()},$scope.externalEvents={onItemSelect:angular.noop,onItemDeselect:angular.noop,onSelectAll:angular.noop,onDeselectAll:angular.noop,onInitDone:angular.noop,onMaxSelectionReached:angular.noop,onSelectionChanged:angular.noop,onClose:angular.noop},$scope.settings={dynamicTitle:!0,scrollable:!1,scrollableHeight:"300px",closeOnBlur:!0,displayProp:"label",idProp:"id",externalIdProp:"id",enableSearch:!1,selectionLimit:0,showCheckAll:!0,showUncheckAll:!0,showEnableSearchButton:!1,closeOnSelect:!1,buttonClasses:"btn btn-default",closeOnDeselect:!1,groupBy:$attrs.groupBy||void 0,groupByTextProvider:null,smartButtonMaxItems:0,smartButtonTextConverter:angular.noop,styleActive:!1,keyboardControls:!1,template:"{{getPropertyForObject(option, settings.displayProp)}}",searchField:"$",showAllSelectedText:!1},$scope.texts={checkAll:"Check All",uncheckAll:"Uncheck All",selectionCount:"checked",selectionOf:"/",searchPlaceholder:"Search...",buttonDefaultText:"Select",dynamicButtonTextSuffix:"checked",disableSearch:"Disable search",enableSearch:"Enable search",selectGroup:"Select all:",allSelectedText:"All"},$scope.input={searchFilter:$scope.searchFilter||""},angular.isDefined($scope.settings.groupBy)&&$scope.$watch("options",function(newValue){angular.isDefined(newValue)&&($scope.orderedItems=$filter("orderBy")(newValue,$scope.settings.groupBy))}),$scope.$watch("selectedModel",function(newValue){Array.isArray(newValue)?$scope.singleSelection=!1:$scope.singleSelection=!0}),$scope.close=function(){$scope.open=!1,$scope.externalEvents.onClose()},$scope.selectCurrentGroup=function(currentGroup){$scope.selectedModel.splice(0,$scope.selectedModel.length),$scope.orderedItems&&$scope.orderedItems.forEach(function(item){item[$scope.groupBy]===currentGroup&&$scope.setSelectedItem($scope.getPropertyForObject(item,$scope.settings.idProp),!1,!1)}),$scope.externalEvents.onSelectionChanged()},angular.extend($scope.settings,$scope.extraSettings||[]),angular.extend($scope.externalEvents,$scope.events||[]),angular.extend($scope.texts,$scope.translationTexts),$scope.singleSelection=1===$scope.settings.selectionLimit,$scope.singleSelection&&angular.isArray($scope.selectedModel)&&0===$scope.selectedModel.length&&clearObject($scope.selectedModel),$scope.settings.closeOnBlur&&$document.on("click",function(e){if($scope.open){for(var target=e.target.parentElement,parentFound=!1;angular.isDefined(target)&&null!==target&&!parentFound;)target.className.split&&contains(target.className.split(" "),"multiselect-parent")&&!parentFound&&target===$dropdownTrigger&&(parentFound=!0),target=target.parentElement;parentFound||$scope.$apply(function(){$scope.close()})}}),$scope.getGroupLabel=function(groupValue){return null!==$scope.settings.groupByTextProvider?$scope.settings.groupByTextProvider(groupValue):groupValue},$scope.getButtonText=function(){if($scope.settings.dynamicTitle&&($scope.selectedModel.length>0||angular.isObject($scope.selectedModel)&&Object.keys($scope.selectedModel).length>0)){if($scope.settings.smartButtonMaxItems>0){var paddingWidth=24,borderWidth=2,dropdownIconWidth=8,widthLimit=(textWidth("..."),$element[0].offsetWidth-paddingWidth-borderWidth-dropdownIconWidth),itemsText=[];angular.forEach($scope.options,function(optionItem){if($scope.isChecked($scope.getPropertyForObject(optionItem,$scope.settings.idProp))){var displayText=$scope.getPropertyForObject(optionItem,$scope.settings.displayProp),converterResponse=$scope.settings.smartButtonTextConverter(displayText,optionItem);itemsText.push(converterResponse?converterResponse:displayText)}}),$scope.selectedModel.length>$scope.settings.smartButtonMaxItems&&(itemsText=itemsText.slice(0,$scope.settings.smartButtonMaxItems),itemsText.push("..."));for(var result=itemsText.join(", "),index=result.length-4;textWidth(result)>widthLimit;)"..."!==itemsText[itemsText.length-1]&&(itemsText.push("..."),result+="..."),result=result.slice(0,index)+result.slice(index+1),index--;return result}var totalSelected;return totalSelected=$scope.singleSelection?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.idProp])?1:0:angular.isDefined($scope.selectedModel)?$scope.selectedModel.length:0,0===totalSelected?$scope.texts.buttonDefaultText:$scope.settings.showAllSelectedText&&totalSelected===$scope.options.length?$scope.texts.allSelectedText:totalSelected+" "+$scope.texts.dynamicButtonTextSuffix}return $scope.texts.buttonDefaultText},$scope.getPropertyForObject=function(object,property){return angular.isDefined(object)&&object.hasOwnProperty(property)?object[property]:void 0},$scope.selectAll=function(){var searchResult;$scope.deselectAll(!0),$scope.externalEvents.onSelectAll(),searchResult=$filter("filter")($scope.options,$scope.getFilter($scope.input.searchFilter)),angular.forEach(searchResult,function(value){$scope.setSelectedItem(value[$scope.settings.idProp],!0,!1)}),$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.deselectAll=function(dontSendEvent){dontSendEvent=dontSendEvent||!1,dontSendEvent||$scope.externalEvents.onDeselectAll(),$scope.singleSelection?clearObject($scope.selectedModel):$scope.selectedModel.splice(0,$scope.selectedModel.length),dontSendEvent||$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.setSelectedItem=function(id,dontRemove,fireSelectionChange){var findObj=getFindObj(id),finalObj=null;if(finalObj=""===$scope.settings.externalIdProp?find($scope.options,findObj):findObj,$scope.singleSelection)clearObject($scope.selectedModel),angular.extend($scope.selectedModel,finalObj),fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),($scope.settings.closeOnSelect||$scope.settings.closeOnDeselect)&&$scope.close();else{dontRemove=dontRemove||!1;var exists=-1!==findIndex($scope.selectedModel,findObj);!dontRemove&&exists?($scope.selectedModel.splice(findIndex($scope.selectedModel,findObj),1),$scope.externalEvents.onItemDeselect(findObj),$scope.settings.closeOnDeselect&&$scope.close()):!exists&&(0===$scope.settings.selectionLimit||$scope.selectedModel.length<$scope.settings.selectionLimit)&&($scope.selectedModel.push(finalObj),fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),$scope.settings.closeOnSelect&&$scope.close(),$scope.settings.selectionLimit>0&&$scope.selectedModel.length===$scope.settings.selectionLimit&&$scope.externalEvents.onMaxSelectionReached())}fireSelectionChange&&$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.isChecked=function(id){return $scope.singleSelection?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.externalIdProp])&&$scope.selectedModel[$scope.settings.externalIdProp]===getFindObj(id)[$scope.settings.externalIdProp]:-1!==findIndex($scope.selectedModel,getFindObj(id))},$scope.externalEvents.onInitDone(),$scope.keyDownLink=function(event){var nextOption,sourceScope=angular.element(event.target).scope(),parent=event.target.parentNode;if($scope.settings.keyboardControls)if(13===event.keyCode||32===event.keyCode)event.preventDefault(),sourceScope.option?$scope.setSelectedItem($scope.getPropertyForObject(sourceScope.option,$scope.settings.idProp),!1,!0):"deselectAll"===event.target.id?$scope.deselectAll():"selectAll"===event.target.id&&$scope.selectAll();else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else if(40===event.keyCode){for(event.preventDefault(),parent.nextElementSibling&&(nextOption=parent.nextElementSibling.querySelector("a")||parent.nextElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.nextElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearchDefault=function(event){var nextOption,parent=event.target.parentNode.parentNode;if($scope.settings.keyboardControls)if(9===event.keyCode||40===event.keyCode)event.preventDefault(),focusFirstOption();else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearch=function(event,searchFilter){var searchResult;$scope.settings.keyboardControls&&13===event.keyCode&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?(searchResult=$filter("filter")($scope.options,$scope.getFilter(searchFilter)),1===searchResult.length&&$scope.setSelectedItem($scope.getPropertyForObject(searchResult[0],$scope.settings.idProp),!1,!0)):$scope.settings.enableSearch&&$scope.selectAll())},$scope.getFilter=function(searchFilter){var filter={};return filter[$scope.settings.searchField]=searchFilter,filter},$scope.toggleSearch=function($event){$event&&$event.stopPropagation(),$scope.settings.enableSearch=!$scope.settings.enableSearch,$scope.settings.enableSearch||($scope.input.searchFilter="")},$scope.keyDownToggleSearch=function(){$scope.settings.keyboardControls&&13===event.keyCode&&($scope.toggleSearch(),$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):focusFirstOption())}}}}])}(angular); \ No newline at end of file +!function(angular){"use strict";function contains(collection,target){var containsTarget=!1;return collection.some(function(object){return object===target?(containsTarget=!0,!0):void 0}),containsTarget}function find(collection,properties){var target;return collection.some(function(object){var hasAllSameProperties=!0;return Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(target=object,!0):void 0}),target}function findIndex(collection,properties){var index=-1,counter=-1;return collection.some(function(object){var hasAllSameProperties=!0;return counter+=1,Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(index=counter,!0):void 0}),index}var directiveModule=angular.module("angularjs-dropdown-multiselect",[]);directiveModule.directive("dmDropdownStaticInclude",["$compile",function($compile){return function(scope,element,attrs){var template=attrs.dmDropdownStaticInclude,contents=element.html(template).contents();$compile(contents)(scope)}}]),directiveModule.directive("ngDropdownMultiselect",["$filter","$document","$compile","$parse",function($filter,$document,$compile,$parse){return{restrict:"AE",scope:{selectedModel:"=",options:"=",extraSettings:"=",events:"=",searchFilter:"=?",translationTexts:"=",groupBy:"@",disabled:"="},template:function(element,attrs){var checkboxes=attrs.checkboxes?!0:!1,groups=attrs.groupBy?!0:!1,template='"},link:function($scope,$element,$attrs){function getFindObj(id){var findObj={};return""===$scope.settings.externalIdProp?findObj[$scope.settings.idProp]=id:findObj[$scope.settings.externalIdProp]=id,findObj}function clearObject(object){for(var prop in object)delete object[prop]}function textWidth(text){var $btn=$element.find("button"),canvas=document.createElement("canvas"),ctx=canvas.getContext("2d");return ctx.font=$btn.css("font-size")+$btn.css("font-family"),ctx.originalFont=$btn.css("font-size")+$btn.css("font-family"),ctx.fillStyle="#000000",ctx.measureText(text).width}function focusFirstOption(){setTimeout(function(){var elementToFocus=angular.element($element)[0].querySelector(".option");angular.isDefined(elementToFocus)&&null!=elementToFocus&&elementToFocus.focus()},0)}var $dropdownTrigger=$element.children()[0];$scope.toggleDropdown=function(){$scope.open?$scope.close():$scope.open=!0,$scope.settings.keyboardControls&&$scope.open&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):focusFirstOption())},$scope.checkboxClick=function($event,id){$scope.setSelectedItem(id,!1,!0),$event.stopImmediatePropagation()},$scope.externalEvents={onItemSelect:angular.noop,onItemDeselect:angular.noop,onSelectAll:angular.noop,onDeselectAll:angular.noop,onInitDone:angular.noop,onMaxSelectionReached:angular.noop,onSelectionChanged:angular.noop,onClose:angular.noop},$scope.settings={dynamicTitle:!0,scrollable:!1,scrollableHeight:"300px",closeOnBlur:!0,displayProp:"label",idProp:"id",externalIdProp:"id",enableSearch:!1,selectionLimit:0,showCheckAll:!0,showUncheckAll:!0,showEnableSearchButton:!1,closeOnSelect:!1,buttonClasses:"btn btn-default",closeOnDeselect:!1,groupBy:$attrs.groupBy||void 0,groupByTextProvider:null,smartButtonMaxItems:0,smartButtonTextConverter:angular.noop,styleActive:!1,keyboardControls:!1,template:"{{getPropertyForObject(option, settings.displayProp)}}",searchField:"$",showAllSelectedText:!1},$scope.texts={checkAll:"Check All",uncheckAll:"Uncheck All",selectionCount:"checked",selectionOf:"/",searchPlaceholder:"Search...",buttonDefaultText:"Select",dynamicButtonTextSuffix:"checked",disableSearch:"Disable search",enableSearch:"Enable search",selectGroup:"Select all:",allSelectedText:"All"},$scope.input={searchFilter:$scope.searchFilter||""},angular.isDefined($scope.settings.groupBy)&&$scope.$watch("options",function(newValue){angular.isDefined(newValue)&&($scope.orderedItems=$filter("orderBy")(newValue,$scope.settings.groupBy))}),$scope.$watch("selectedModel",function(newValue){Array.isArray(newValue)?$scope.singleSelection=!1:$scope.singleSelection=!0}),$scope.close=function(){$scope.open=!1,$scope.externalEvents.onClose()},$scope.selectCurrentGroup=function(currentGroup){$scope.selectedModel.splice(0,$scope.selectedModel.length),$scope.orderedItems&&$scope.orderedItems.forEach(function(item){item[$scope.groupBy]===currentGroup&&$scope.setSelectedItem($scope.getPropertyForObject(item,$scope.settings.idProp),!1,!1)}),$scope.externalEvents.onSelectionChanged()},angular.extend($scope.settings,$scope.extraSettings||[]),angular.extend($scope.externalEvents,$scope.events||[]),angular.extend($scope.texts,$scope.translationTexts),$scope.singleSelection=1===$scope.settings.selectionLimit,$scope.singleSelection&&angular.isArray($scope.selectedModel)&&0===$scope.selectedModel.length&&clearObject($scope.selectedModel),$scope.settings.closeOnBlur&&$document.on("click",function(e){if($scope.open){for(var target=e.target.parentElement,parentFound=!1;angular.isDefined(target)&&null!==target&&!parentFound;)target.className.split&&contains(target.className.split(" "),"multiselect-parent")&&!parentFound&&target===$dropdownTrigger&&(parentFound=!0),target=target.parentElement;parentFound||$scope.$apply(function(){$scope.close()})}}),$scope.getGroupLabel=function(groupValue){return null!==$scope.settings.groupByTextProvider?$scope.settings.groupByTextProvider(groupValue):groupValue},$scope.getButtonText=function(){if($scope.settings.dynamicTitle&&($scope.selectedModel.length>0||angular.isObject($scope.selectedModel)&&Object.keys($scope.selectedModel).length>0)){if($scope.settings.smartButtonMaxItems>0){var paddingWidth=24,borderWidth=2,dropdownIconWidth=8,widthLimit=(textWidth("..."),$element[0].offsetWidth-paddingWidth-borderWidth-dropdownIconWidth),itemsText=[];angular.forEach($scope.options,function(optionItem){if($scope.isChecked($scope.getPropertyForObject(optionItem,$scope.settings.idProp))){var displayText=$scope.getPropertyForObject(optionItem,$scope.settings.displayProp),converterResponse=$scope.settings.smartButtonTextConverter(displayText,optionItem);itemsText.push(converterResponse?converterResponse:displayText)}}),$scope.selectedModel.length>$scope.settings.smartButtonMaxItems&&(itemsText=itemsText.slice(0,$scope.settings.smartButtonMaxItems),itemsText.push("..."));for(var result=itemsText.join(", "),index=result.length-4;textWidth(result)>widthLimit;)"..."!==itemsText[itemsText.length-1]&&(itemsText.push("..."),result+="..."),result=result.slice(0,index)+result.slice(index+1),index--;return result}var totalSelected;return totalSelected=$scope.singleSelection?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.idProp])?1:0:angular.isDefined($scope.selectedModel)?$scope.selectedModel.length:0,0===totalSelected?$scope.texts.buttonDefaultText:$scope.settings.showAllSelectedText&&totalSelected===$scope.options.length?$scope.texts.allSelectedText:totalSelected+" "+$scope.texts.dynamicButtonTextSuffix}return $scope.texts.buttonDefaultText},$scope.getPropertyForObject=function(object,property){return angular.isDefined(object)&&object.hasOwnProperty(property)?object[property]:void 0},$scope.selectAll=function(){var searchResult;$scope.deselectAll(!0),$scope.externalEvents.onSelectAll(),searchResult=$filter("filter")($scope.options,$scope.getFilter($scope.input.searchFilter)),angular.forEach(searchResult,function(value){$scope.setSelectedItem(value[$scope.settings.idProp],!0,!1)}),$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.deselectAll=function(dontSendEvent){dontSendEvent=dontSendEvent||!1,dontSendEvent||$scope.externalEvents.onDeselectAll(),$scope.singleSelection?clearObject($scope.selectedModel):$scope.selectedModel.splice(0,$scope.selectedModel.length),dontSendEvent||$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.setSelectedItem=function(id,dontRemove,fireSelectionChange){var findObj=getFindObj(id),finalObj=null;if(finalObj=""===$scope.settings.externalIdProp?find($scope.options,findObj):findObj,$scope.singleSelection)clearObject($scope.selectedModel),angular.extend($scope.selectedModel,finalObj),fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),($scope.settings.closeOnSelect||$scope.settings.closeOnDeselect)&&$scope.close();else{dontRemove=dontRemove||!1;var exists=-1!==findIndex($scope.selectedModel,findObj);!dontRemove&&exists?($scope.selectedModel.splice(findIndex($scope.selectedModel,findObj),1),$scope.externalEvents.onItemDeselect(findObj),$scope.settings.closeOnDeselect&&$scope.close()):!exists&&(0===$scope.settings.selectionLimit||$scope.selectedModel.length<$scope.settings.selectionLimit)&&($scope.selectedModel.push(finalObj),fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),$scope.settings.closeOnSelect&&$scope.close(),$scope.settings.selectionLimit>0&&$scope.selectedModel.length===$scope.settings.selectionLimit&&$scope.externalEvents.onMaxSelectionReached())}fireSelectionChange&&$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.isChecked=function(id){return $scope.singleSelection?""===$scope.settings.externalIdProp?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.idProp])&&$scope.selectedModel[$scope.settings.idProp]===getFindObj(id)[$scope.settings.idProp]:null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.externalIdProp])&&$scope.selectedModel[$scope.settings.externalIdProp]===getFindObj(id)[$scope.settings.externalIdProp]:-1!==findIndex($scope.selectedModel,getFindObj(id))},$scope.externalEvents.onInitDone(),$scope.keyDownLink=function(event){var nextOption,sourceScope=angular.element(event.target).scope(),parent=event.target.parentNode;if($scope.settings.keyboardControls)if(13===event.keyCode||32===event.keyCode)event.preventDefault(),sourceScope.option?$scope.setSelectedItem($scope.getPropertyForObject(sourceScope.option,$scope.settings.idProp),!1,!0):"deselectAll"===event.target.id?$scope.deselectAll():"selectAll"===event.target.id&&$scope.selectAll();else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else if(40===event.keyCode){for(event.preventDefault(),parent.nextElementSibling&&(nextOption=parent.nextElementSibling.querySelector("a")||parent.nextElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.nextElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearchDefault=function(event){var nextOption,parent=event.target.parentNode.parentNode;if($scope.settings.keyboardControls)if(9===event.keyCode||40===event.keyCode)event.preventDefault(),focusFirstOption();else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearch=function(event,searchFilter){var searchResult;$scope.settings.keyboardControls&&13===event.keyCode&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?(searchResult=$filter("filter")($scope.options,$scope.getFilter(searchFilter)),1===searchResult.length&&$scope.setSelectedItem($scope.getPropertyForObject(searchResult[0],$scope.settings.idProp),!1,!0)):$scope.settings.enableSearch&&$scope.selectAll())},$scope.getFilter=function(searchFilter){var filter={};return filter[$scope.settings.searchField]=searchFilter,filter},$scope.toggleSearch=function($event){$event&&$event.stopPropagation(),$scope.settings.enableSearch=!$scope.settings.enableSearch,$scope.settings.enableSearch||($scope.input.searchFilter="")},$scope.keyDownToggleSearch=function(){$scope.settings.keyboardControls&&13===event.keyCode&&($scope.toggleSearch(),$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):focusFirstOption())}}}}])}(angular); \ No newline at end of file From dcf51375c4a9fcc057d3f040ef2caac83154647f Mon Sep 17 00:00:00 2001 From: pkempenaers Date: Thu, 9 Mar 2017 10:45:14 +0100 Subject: [PATCH 06/11] Release 1.11.4 --- bower.json | 2 +- dist/angularjs-dropdown-multiselect.min.js | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bower.json b/bower.json index f3cedf3f..b9775662 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angularjs-dropdown-multiselect", - "version": "1.11.3", + "version": "1.11.4", "authors": [ "Dotan Simha ", "Pieter Kempenaers " diff --git a/dist/angularjs-dropdown-multiselect.min.js b/dist/angularjs-dropdown-multiselect.min.js index 67e90ce6..c252f927 100644 --- a/dist/angularjs-dropdown-multiselect.min.js +++ b/dist/angularjs-dropdown-multiselect.min.js @@ -1 +1 @@ -!function(angular){"use strict";function contains(collection,target){var containsTarget=!1;return collection.some(function(object){return object===target?(containsTarget=!0,!0):void 0}),containsTarget}function find(collection,properties){var target;return collection.some(function(object){var hasAllSameProperties=!0;return Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(target=object,!0):void 0}),target}function findIndex(collection,properties){var index=-1,counter=-1;return collection.some(function(object){var hasAllSameProperties=!0;return counter+=1,Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(index=counter,!0):void 0}),index}var directiveModule=angular.module("angularjs-dropdown-multiselect",[]);directiveModule.directive("dmDropdownStaticInclude",["$compile",function($compile){return function(scope,element,attrs){var template=attrs.dmDropdownStaticInclude,contents=element.html(template).contents();$compile(contents)(scope)}}]),directiveModule.directive("ngDropdownMultiselect",["$filter","$document","$compile","$parse",function($filter,$document,$compile,$parse){return{restrict:"AE",scope:{selectedModel:"=",options:"=",extraSettings:"=",events:"=",searchFilter:"=?",translationTexts:"=",groupBy:"@",disabled:"="},template:function(element,attrs){var checkboxes=attrs.checkboxes?!0:!1,groups=attrs.groupBy?!0:!1,template='"},link:function($scope,$element,$attrs){function getFindObj(id){var findObj={};return""===$scope.settings.externalIdProp?findObj[$scope.settings.idProp]=id:findObj[$scope.settings.externalIdProp]=id,findObj}function clearObject(object){for(var prop in object)delete object[prop]}function textWidth(text){var $btn=$element.find("button"),canvas=document.createElement("canvas"),ctx=canvas.getContext("2d");return ctx.font=$btn.css("font-size")+$btn.css("font-family"),ctx.originalFont=$btn.css("font-size")+$btn.css("font-family"),ctx.fillStyle="#000000",ctx.measureText(text).width}function focusFirstOption(){setTimeout(function(){var elementToFocus=angular.element($element)[0].querySelector(".option");angular.isDefined(elementToFocus)&&null!=elementToFocus&&elementToFocus.focus()},0)}var $dropdownTrigger=$element.children()[0];$scope.toggleDropdown=function(){$scope.open?$scope.close():$scope.open=!0,$scope.settings.keyboardControls&&$scope.open&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):focusFirstOption())},$scope.checkboxClick=function($event,id){$scope.setSelectedItem(id,!1,!0),$event.stopImmediatePropagation()},$scope.externalEvents={onItemSelect:angular.noop,onItemDeselect:angular.noop,onSelectAll:angular.noop,onDeselectAll:angular.noop,onInitDone:angular.noop,onMaxSelectionReached:angular.noop,onSelectionChanged:angular.noop,onClose:angular.noop},$scope.settings={dynamicTitle:!0,scrollable:!1,scrollableHeight:"300px",closeOnBlur:!0,displayProp:"label",idProp:"id",externalIdProp:"id",enableSearch:!1,selectionLimit:0,showCheckAll:!0,showUncheckAll:!0,showEnableSearchButton:!1,closeOnSelect:!1,buttonClasses:"btn btn-default",closeOnDeselect:!1,groupBy:$attrs.groupBy||void 0,groupByTextProvider:null,smartButtonMaxItems:0,smartButtonTextConverter:angular.noop,styleActive:!1,keyboardControls:!1,template:"{{getPropertyForObject(option, settings.displayProp)}}",searchField:"$",showAllSelectedText:!1},$scope.texts={checkAll:"Check All",uncheckAll:"Uncheck All",selectionCount:"checked",selectionOf:"/",searchPlaceholder:"Search...",buttonDefaultText:"Select",dynamicButtonTextSuffix:"checked",disableSearch:"Disable search",enableSearch:"Enable search",selectGroup:"Select all:",allSelectedText:"All"},$scope.input={searchFilter:$scope.searchFilter||""},angular.isDefined($scope.settings.groupBy)&&$scope.$watch("options",function(newValue){angular.isDefined(newValue)&&($scope.orderedItems=$filter("orderBy")(newValue,$scope.settings.groupBy))}),$scope.$watch("selectedModel",function(newValue){Array.isArray(newValue)?$scope.singleSelection=!1:$scope.singleSelection=!0}),$scope.close=function(){$scope.open=!1,$scope.externalEvents.onClose()},$scope.selectCurrentGroup=function(currentGroup){$scope.selectedModel.splice(0,$scope.selectedModel.length),$scope.orderedItems&&$scope.orderedItems.forEach(function(item){item[$scope.groupBy]===currentGroup&&$scope.setSelectedItem($scope.getPropertyForObject(item,$scope.settings.idProp),!1,!1)}),$scope.externalEvents.onSelectionChanged()},angular.extend($scope.settings,$scope.extraSettings||[]),angular.extend($scope.externalEvents,$scope.events||[]),angular.extend($scope.texts,$scope.translationTexts),$scope.singleSelection=1===$scope.settings.selectionLimit,$scope.singleSelection&&angular.isArray($scope.selectedModel)&&0===$scope.selectedModel.length&&clearObject($scope.selectedModel),$scope.settings.closeOnBlur&&$document.on("click",function(e){if($scope.open){for(var target=e.target.parentElement,parentFound=!1;angular.isDefined(target)&&null!==target&&!parentFound;)target.className.split&&contains(target.className.split(" "),"multiselect-parent")&&!parentFound&&target===$dropdownTrigger&&(parentFound=!0),target=target.parentElement;parentFound||$scope.$apply(function(){$scope.close()})}}),$scope.getGroupLabel=function(groupValue){return null!==$scope.settings.groupByTextProvider?$scope.settings.groupByTextProvider(groupValue):groupValue},$scope.getButtonText=function(){if($scope.settings.dynamicTitle&&($scope.selectedModel.length>0||angular.isObject($scope.selectedModel)&&Object.keys($scope.selectedModel).length>0)){if($scope.settings.smartButtonMaxItems>0){var paddingWidth=24,borderWidth=2,dropdownIconWidth=8,widthLimit=(textWidth("..."),$element[0].offsetWidth-paddingWidth-borderWidth-dropdownIconWidth),itemsText=[];angular.forEach($scope.options,function(optionItem){if($scope.isChecked($scope.getPropertyForObject(optionItem,$scope.settings.idProp))){var displayText=$scope.getPropertyForObject(optionItem,$scope.settings.displayProp),converterResponse=$scope.settings.smartButtonTextConverter(displayText,optionItem);itemsText.push(converterResponse?converterResponse:displayText)}}),$scope.selectedModel.length>$scope.settings.smartButtonMaxItems&&(itemsText=itemsText.slice(0,$scope.settings.smartButtonMaxItems),itemsText.push("..."));for(var result=itemsText.join(", "),index=result.length-4;textWidth(result)>widthLimit;)"..."!==itemsText[itemsText.length-1]&&(itemsText.push("..."),result+="..."),result=result.slice(0,index)+result.slice(index+1),index--;return result}var totalSelected;return totalSelected=$scope.singleSelection?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.idProp])?1:0:angular.isDefined($scope.selectedModel)?$scope.selectedModel.length:0,0===totalSelected?$scope.texts.buttonDefaultText:$scope.settings.showAllSelectedText&&totalSelected===$scope.options.length?$scope.texts.allSelectedText:totalSelected+" "+$scope.texts.dynamicButtonTextSuffix}return $scope.texts.buttonDefaultText},$scope.getPropertyForObject=function(object,property){return angular.isDefined(object)&&object.hasOwnProperty(property)?object[property]:void 0},$scope.selectAll=function(){var searchResult;$scope.deselectAll(!0),$scope.externalEvents.onSelectAll(),searchResult=$filter("filter")($scope.options,$scope.getFilter($scope.input.searchFilter)),angular.forEach(searchResult,function(value){$scope.setSelectedItem(value[$scope.settings.idProp],!0,!1)}),$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.deselectAll=function(dontSendEvent){dontSendEvent=dontSendEvent||!1,dontSendEvent||$scope.externalEvents.onDeselectAll(),$scope.singleSelection?clearObject($scope.selectedModel):$scope.selectedModel.splice(0,$scope.selectedModel.length),dontSendEvent||$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.setSelectedItem=function(id,dontRemove,fireSelectionChange){var findObj=getFindObj(id),finalObj=null;if(finalObj=""===$scope.settings.externalIdProp?find($scope.options,findObj):findObj,$scope.singleSelection)clearObject($scope.selectedModel),angular.extend($scope.selectedModel,finalObj),fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),($scope.settings.closeOnSelect||$scope.settings.closeOnDeselect)&&$scope.close();else{dontRemove=dontRemove||!1;var exists=-1!==findIndex($scope.selectedModel,findObj);!dontRemove&&exists?($scope.selectedModel.splice(findIndex($scope.selectedModel,findObj),1),$scope.externalEvents.onItemDeselect(findObj),$scope.settings.closeOnDeselect&&$scope.close()):!exists&&(0===$scope.settings.selectionLimit||$scope.selectedModel.length<$scope.settings.selectionLimit)&&($scope.selectedModel.push(finalObj),fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),$scope.settings.closeOnSelect&&$scope.close(),$scope.settings.selectionLimit>0&&$scope.selectedModel.length===$scope.settings.selectionLimit&&$scope.externalEvents.onMaxSelectionReached())}fireSelectionChange&&$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.isChecked=function(id){return $scope.singleSelection?""===$scope.settings.externalIdProp?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.idProp])&&$scope.selectedModel[$scope.settings.idProp]===getFindObj(id)[$scope.settings.idProp]:null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.externalIdProp])&&$scope.selectedModel[$scope.settings.externalIdProp]===getFindObj(id)[$scope.settings.externalIdProp]:-1!==findIndex($scope.selectedModel,getFindObj(id))},$scope.externalEvents.onInitDone(),$scope.keyDownLink=function(event){var nextOption,sourceScope=angular.element(event.target).scope(),parent=event.target.parentNode;if($scope.settings.keyboardControls)if(13===event.keyCode||32===event.keyCode)event.preventDefault(),sourceScope.option?$scope.setSelectedItem($scope.getPropertyForObject(sourceScope.option,$scope.settings.idProp),!1,!0):"deselectAll"===event.target.id?$scope.deselectAll():"selectAll"===event.target.id&&$scope.selectAll();else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else if(40===event.keyCode){for(event.preventDefault(),parent.nextElementSibling&&(nextOption=parent.nextElementSibling.querySelector("a")||parent.nextElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.nextElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearchDefault=function(event){var nextOption,parent=event.target.parentNode.parentNode;if($scope.settings.keyboardControls)if(9===event.keyCode||40===event.keyCode)event.preventDefault(),focusFirstOption();else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearch=function(event,searchFilter){var searchResult;$scope.settings.keyboardControls&&13===event.keyCode&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?(searchResult=$filter("filter")($scope.options,$scope.getFilter(searchFilter)),1===searchResult.length&&$scope.setSelectedItem($scope.getPropertyForObject(searchResult[0],$scope.settings.idProp),!1,!0)):$scope.settings.enableSearch&&$scope.selectAll())},$scope.getFilter=function(searchFilter){var filter={};return filter[$scope.settings.searchField]=searchFilter,filter},$scope.toggleSearch=function($event){$event&&$event.stopPropagation(),$scope.settings.enableSearch=!$scope.settings.enableSearch,$scope.settings.enableSearch||($scope.input.searchFilter="")},$scope.keyDownToggleSearch=function(){$scope.settings.keyboardControls&&13===event.keyCode&&($scope.toggleSearch(),$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):focusFirstOption())}}}}])}(angular); \ No newline at end of file +!function(angular){"use strict";function contains(collection,target){var containsTarget=!1;return collection.some(function(object){return object===target?(containsTarget=!0,!0):void 0}),containsTarget}function find(collection,properties){var target;return collection.some(function(object){var hasAllSameProperties=!0;return Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(target=object,!0):void 0}),target}function findIndex(collection,properties){var index=-1,counter=-1;return collection.some(function(object){var hasAllSameProperties=!0;return counter+=1,Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(index=counter,!0):void 0}),index}var directiveModule=angular.module("angularjs-dropdown-multiselect",[]);directiveModule.directive("dmDropdownStaticInclude",["$compile",function($compile){return function(scope,element,attrs){var template=attrs.dmDropdownStaticInclude,contents=element.html(template).contents();$compile(contents)(scope)}}]),directiveModule.directive("ngDropdownMultiselect",["$filter","$document","$compile","$parse",function($filter,$document,$compile,$parse){return{restrict:"AE",scope:{selectedModel:"=",options:"=",extraSettings:"=",events:"=",searchFilter:"=?",translationTexts:"=",groupBy:"@",disabled:"="},template:function(element,attrs){var checkboxes=attrs.checkboxes?!0:!1,groups=attrs.groupBy?!0:!1,template='"},link:function($scope,$element,$attrs){function getFindObj(id){var findObj={};return""===$scope.settings.externalIdProp?findObj[$scope.settings.idProp]=id:findObj[$scope.settings.externalIdProp]=id,findObj}function clearObject(object){for(var prop in object)delete object[prop]}function textWidth(text){var $btn=$element.find("button"),canvas=document.createElement("canvas"),ctx=canvas.getContext("2d");return ctx.font=$btn.css("font-size")+$btn.css("font-family"),ctx.originalFont=$btn.css("font-size")+$btn.css("font-family"),ctx.fillStyle="#000000",ctx.measureText(text).width}function focusFirstOption(){setTimeout(function(){var elementToFocus=angular.element($element)[0].querySelector(".option");angular.isDefined(elementToFocus)&&null!=elementToFocus&&elementToFocus.focus()},0)}var $dropdownTrigger=$element.children()[0];$scope.toggleDropdown=function(){$scope.open?$scope.close():$scope.open=!0,$scope.settings.keyboardControls&&$scope.open&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):focusFirstOption()),$scope.settings.enableSearch&&$scope.open&&setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0)},$scope.checkboxClick=function($event,id){$scope.setSelectedItem(id,!1,!0),$event.stopImmediatePropagation()},$scope.externalEvents={onItemSelect:angular.noop,onItemDeselect:angular.noop,onSelectAll:angular.noop,onDeselectAll:angular.noop,onInitDone:angular.noop,onMaxSelectionReached:angular.noop,onSelectionChanged:angular.noop,onClose:angular.noop},$scope.settings={dynamicTitle:!0,scrollable:!1,scrollableHeight:"300px",closeOnBlur:!0,displayProp:"label",idProp:"id",externalIdProp:"id",enableSearch:!1,selectionLimit:0,showCheckAll:!0,showUncheckAll:!0,showEnableSearchButton:!1,closeOnSelect:!1,buttonClasses:"btn btn-default",closeOnDeselect:!1,groupBy:$attrs.groupBy||void 0,groupByTextProvider:null,smartButtonMaxItems:0,smartButtonTextConverter:angular.noop,styleActive:!1,keyboardControls:!1,template:"{{getPropertyForObject(option, settings.displayProp)}}",searchField:"$",showAllSelectedText:!1},$scope.texts={checkAll:"Check All",uncheckAll:"Uncheck All",selectionCount:"checked",selectionOf:"/",searchPlaceholder:"Search...",buttonDefaultText:"Select",dynamicButtonTextSuffix:"checked",disableSearch:"Disable search",enableSearch:"Enable search",selectGroup:"Select all:",allSelectedText:"All"},$scope.input={searchFilter:$scope.searchFilter||""},angular.isDefined($scope.settings.groupBy)&&$scope.$watch("options",function(newValue){angular.isDefined(newValue)&&($scope.orderedItems=$filter("orderBy")(newValue,$scope.settings.groupBy))}),$scope.$watch("selectedModel",function(newValue){Array.isArray(newValue)?$scope.singleSelection=!1:$scope.singleSelection=!0}),$scope.close=function(){$scope.open=!1,$scope.externalEvents.onClose()},$scope.selectCurrentGroup=function(currentGroup){$scope.selectedModel.splice(0,$scope.selectedModel.length),$scope.orderedItems&&$scope.orderedItems.forEach(function(item){item[$scope.groupBy]===currentGroup&&$scope.setSelectedItem($scope.getPropertyForObject(item,$scope.settings.idProp),!1,!1)}),$scope.externalEvents.onSelectionChanged()},angular.extend($scope.settings,$scope.extraSettings||[]),angular.extend($scope.externalEvents,$scope.events||[]),angular.extend($scope.texts,$scope.translationTexts),$scope.singleSelection=1===$scope.settings.selectionLimit,$scope.singleSelection&&angular.isArray($scope.selectedModel)&&0===$scope.selectedModel.length&&clearObject($scope.selectedModel),$scope.settings.closeOnBlur&&$document.on("click",function(e){if($scope.open){for(var target=e.target.parentElement,parentFound=!1;angular.isDefined(target)&&null!==target&&!parentFound;)target.className.split&&contains(target.className.split(" "),"multiselect-parent")&&!parentFound&&target===$dropdownTrigger&&(parentFound=!0),target=target.parentElement;parentFound||$scope.$apply(function(){$scope.close()})}}),$scope.getGroupLabel=function(groupValue){return null!==$scope.settings.groupByTextProvider?$scope.settings.groupByTextProvider(groupValue):groupValue},$scope.getButtonText=function(){if($scope.settings.dynamicTitle&&($scope.selectedModel.length>0||angular.isObject($scope.selectedModel)&&Object.keys($scope.selectedModel).length>0)){if($scope.settings.smartButtonMaxItems>0){var paddingWidth=24,borderWidth=2,dropdownIconWidth=8,widthLimit=(textWidth("..."),$element[0].offsetWidth-paddingWidth-borderWidth-dropdownIconWidth),itemsText=[];angular.forEach($scope.options,function(optionItem){if($scope.isChecked($scope.getPropertyForObject(optionItem,$scope.settings.idProp))){var displayText=$scope.getPropertyForObject(optionItem,$scope.settings.displayProp),converterResponse=$scope.settings.smartButtonTextConverter(displayText,optionItem);itemsText.push(converterResponse?converterResponse:displayText)}}),$scope.selectedModel.length>$scope.settings.smartButtonMaxItems&&(itemsText=itemsText.slice(0,$scope.settings.smartButtonMaxItems),itemsText.push("..."));var result=itemsText.join(", "),index=result.length-4;if(0===$element[0].offsetWidth)return result;for(;textWidth(result)>widthLimit;)"..."!==itemsText[itemsText.length-1]&&(itemsText.push("..."),result+="..."),result=result.slice(0,index)+result.slice(index+1),index--;return result}var totalSelected;return totalSelected=$scope.singleSelection?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.idProp])?1:0:angular.isDefined($scope.selectedModel)?$scope.selectedModel.length:0,0===totalSelected?$scope.texts.buttonDefaultText:$scope.settings.showAllSelectedText&&totalSelected===$scope.options.length?$scope.texts.allSelectedText:totalSelected+" "+$scope.texts.dynamicButtonTextSuffix}return $scope.texts.buttonDefaultText},$scope.getPropertyForObject=function(object,property){return angular.isDefined(object)&&object.hasOwnProperty(property)?object[property]:void 0},$scope.selectAll=function(){var searchResult;$scope.deselectAll(!0),$scope.externalEvents.onSelectAll(),searchResult=$filter("filter")($scope.options,$scope.getFilter($scope.input.searchFilter)),angular.forEach(searchResult,function(value){$scope.setSelectedItem(value[$scope.settings.idProp],!0,!1)}),$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.deselectAll=function(dontSendEvent){dontSendEvent=dontSendEvent||!1,dontSendEvent||$scope.externalEvents.onDeselectAll(),$scope.singleSelection?clearObject($scope.selectedModel):$scope.selectedModel.splice(0,$scope.selectedModel.length),dontSendEvent||$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.setSelectedItem=function(id,dontRemove,fireSelectionChange){var findObj=getFindObj(id),finalObj=null;if(finalObj=""===$scope.settings.externalIdProp?find($scope.options,findObj):findObj,$scope.singleSelection)clearObject($scope.selectedModel),angular.extend($scope.selectedModel,finalObj),fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),($scope.settings.closeOnSelect||$scope.settings.closeOnDeselect)&&$scope.close();else{dontRemove=dontRemove||!1;var exists=-1!==findIndex($scope.selectedModel,findObj);!dontRemove&&exists?($scope.selectedModel.splice(findIndex($scope.selectedModel,findObj),1),$scope.externalEvents.onItemDeselect(findObj),$scope.settings.closeOnDeselect&&$scope.close()):!exists&&(0===$scope.settings.selectionLimit||$scope.selectedModel.length<$scope.settings.selectionLimit)&&($scope.selectedModel.push(finalObj),fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),$scope.settings.closeOnSelect&&$scope.close(),$scope.settings.selectionLimit>0&&$scope.selectedModel.length===$scope.settings.selectionLimit&&$scope.externalEvents.onMaxSelectionReached())}fireSelectionChange&&$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.isChecked=function(id){return $scope.singleSelection?""===$scope.settings.externalIdProp?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.idProp])&&$scope.selectedModel[$scope.settings.idProp]===getFindObj(id)[$scope.settings.idProp]:null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.externalIdProp])&&$scope.selectedModel[$scope.settings.externalIdProp]===getFindObj(id)[$scope.settings.externalIdProp]:-1!==findIndex($scope.selectedModel,getFindObj(id))},$scope.externalEvents.onInitDone(),$scope.keyDownLink=function(event){var nextOption,sourceScope=angular.element(event.target).scope(),parent=event.target.parentNode;if($scope.settings.keyboardControls)if(13===event.keyCode||32===event.keyCode)event.preventDefault(),sourceScope.option?$scope.setSelectedItem($scope.getPropertyForObject(sourceScope.option,$scope.settings.idProp),!1,!0):"deselectAll"===event.target.id?$scope.deselectAll():"selectAll"===event.target.id&&$scope.selectAll();else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else if(40===event.keyCode){for(event.preventDefault(),parent.nextElementSibling&&(nextOption=parent.nextElementSibling.querySelector("a")||parent.nextElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.nextElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearchDefault=function(event){var nextOption,parent=event.target.parentNode.parentNode;if($scope.settings.keyboardControls)if(9===event.keyCode||40===event.keyCode)event.preventDefault(),focusFirstOption();else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearch=function(event,searchFilter){var searchResult;$scope.settings.keyboardControls&&13===event.keyCode&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?(searchResult=$filter("filter")($scope.options,$scope.getFilter(searchFilter)),1===searchResult.length&&$scope.setSelectedItem($scope.getPropertyForObject(searchResult[0],$scope.settings.idProp),!1,!0)):$scope.settings.enableSearch&&$scope.selectAll())},$scope.getFilter=function(searchFilter){var filter={};return filter[$scope.settings.searchField]=searchFilter,filter},$scope.toggleSearch=function($event){$event&&$event.stopPropagation(),$scope.settings.enableSearch=!$scope.settings.enableSearch,$scope.settings.enableSearch||($scope.input.searchFilter="")},$scope.keyDownToggleSearch=function(){$scope.settings.keyboardControls&&13===event.keyCode&&($scope.toggleSearch(),$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):focusFirstOption())}}}}])}(angular); \ No newline at end of file diff --git a/package.json b/package.json index 2a883cdd..cd289d3b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "author": "pkempenaers@myforce.be", "name": "angularjs-dropdown-multiselect", - "version": "1.11.1", + "version": "1.11.4", "description": "This directive gives you a Bootstrap Dropdown with the power of AngularJS directives.", "homepage": "http://dotansimha.github.io/angularjs-dropdown-multiselect/#/", "dependencies": { From 8aefee29cc9725fd0ff20447ece2342d84712adb Mon Sep 17 00:00:00 2001 From: pkempenaers Date: Mon, 13 Mar 2017 17:13:34 +0100 Subject: [PATCH 07/11] Release 1.11.5 --- bower.json | 2 +- dist/angularjs-dropdown-multiselect.min.js | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bower.json b/bower.json index b9775662..c6e75e7e 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angularjs-dropdown-multiselect", - "version": "1.11.4", + "version": "1.11.5", "authors": [ "Dotan Simha ", "Pieter Kempenaers " diff --git a/dist/angularjs-dropdown-multiselect.min.js b/dist/angularjs-dropdown-multiselect.min.js index c252f927..cc64aae7 100644 --- a/dist/angularjs-dropdown-multiselect.min.js +++ b/dist/angularjs-dropdown-multiselect.min.js @@ -1 +1 @@ -!function(angular){"use strict";function contains(collection,target){var containsTarget=!1;return collection.some(function(object){return object===target?(containsTarget=!0,!0):void 0}),containsTarget}function find(collection,properties){var target;return collection.some(function(object){var hasAllSameProperties=!0;return Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(target=object,!0):void 0}),target}function findIndex(collection,properties){var index=-1,counter=-1;return collection.some(function(object){var hasAllSameProperties=!0;return counter+=1,Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(index=counter,!0):void 0}),index}var directiveModule=angular.module("angularjs-dropdown-multiselect",[]);directiveModule.directive("dmDropdownStaticInclude",["$compile",function($compile){return function(scope,element,attrs){var template=attrs.dmDropdownStaticInclude,contents=element.html(template).contents();$compile(contents)(scope)}}]),directiveModule.directive("ngDropdownMultiselect",["$filter","$document","$compile","$parse",function($filter,$document,$compile,$parse){return{restrict:"AE",scope:{selectedModel:"=",options:"=",extraSettings:"=",events:"=",searchFilter:"=?",translationTexts:"=",groupBy:"@",disabled:"="},template:function(element,attrs){var checkboxes=attrs.checkboxes?!0:!1,groups=attrs.groupBy?!0:!1,template='"},link:function($scope,$element,$attrs){function getFindObj(id){var findObj={};return""===$scope.settings.externalIdProp?findObj[$scope.settings.idProp]=id:findObj[$scope.settings.externalIdProp]=id,findObj}function clearObject(object){for(var prop in object)delete object[prop]}function textWidth(text){var $btn=$element.find("button"),canvas=document.createElement("canvas"),ctx=canvas.getContext("2d");return ctx.font=$btn.css("font-size")+$btn.css("font-family"),ctx.originalFont=$btn.css("font-size")+$btn.css("font-family"),ctx.fillStyle="#000000",ctx.measureText(text).width}function focusFirstOption(){setTimeout(function(){var elementToFocus=angular.element($element)[0].querySelector(".option");angular.isDefined(elementToFocus)&&null!=elementToFocus&&elementToFocus.focus()},0)}var $dropdownTrigger=$element.children()[0];$scope.toggleDropdown=function(){$scope.open?$scope.close():$scope.open=!0,$scope.settings.keyboardControls&&$scope.open&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):focusFirstOption()),$scope.settings.enableSearch&&$scope.open&&setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0)},$scope.checkboxClick=function($event,id){$scope.setSelectedItem(id,!1,!0),$event.stopImmediatePropagation()},$scope.externalEvents={onItemSelect:angular.noop,onItemDeselect:angular.noop,onSelectAll:angular.noop,onDeselectAll:angular.noop,onInitDone:angular.noop,onMaxSelectionReached:angular.noop,onSelectionChanged:angular.noop,onClose:angular.noop},$scope.settings={dynamicTitle:!0,scrollable:!1,scrollableHeight:"300px",closeOnBlur:!0,displayProp:"label",idProp:"id",externalIdProp:"id",enableSearch:!1,selectionLimit:0,showCheckAll:!0,showUncheckAll:!0,showEnableSearchButton:!1,closeOnSelect:!1,buttonClasses:"btn btn-default",closeOnDeselect:!1,groupBy:$attrs.groupBy||void 0,groupByTextProvider:null,smartButtonMaxItems:0,smartButtonTextConverter:angular.noop,styleActive:!1,keyboardControls:!1,template:"{{getPropertyForObject(option, settings.displayProp)}}",searchField:"$",showAllSelectedText:!1},$scope.texts={checkAll:"Check All",uncheckAll:"Uncheck All",selectionCount:"checked",selectionOf:"/",searchPlaceholder:"Search...",buttonDefaultText:"Select",dynamicButtonTextSuffix:"checked",disableSearch:"Disable search",enableSearch:"Enable search",selectGroup:"Select all:",allSelectedText:"All"},$scope.input={searchFilter:$scope.searchFilter||""},angular.isDefined($scope.settings.groupBy)&&$scope.$watch("options",function(newValue){angular.isDefined(newValue)&&($scope.orderedItems=$filter("orderBy")(newValue,$scope.settings.groupBy))}),$scope.$watch("selectedModel",function(newValue){Array.isArray(newValue)?$scope.singleSelection=!1:$scope.singleSelection=!0}),$scope.close=function(){$scope.open=!1,$scope.externalEvents.onClose()},$scope.selectCurrentGroup=function(currentGroup){$scope.selectedModel.splice(0,$scope.selectedModel.length),$scope.orderedItems&&$scope.orderedItems.forEach(function(item){item[$scope.groupBy]===currentGroup&&$scope.setSelectedItem($scope.getPropertyForObject(item,$scope.settings.idProp),!1,!1)}),$scope.externalEvents.onSelectionChanged()},angular.extend($scope.settings,$scope.extraSettings||[]),angular.extend($scope.externalEvents,$scope.events||[]),angular.extend($scope.texts,$scope.translationTexts),$scope.singleSelection=1===$scope.settings.selectionLimit,$scope.singleSelection&&angular.isArray($scope.selectedModel)&&0===$scope.selectedModel.length&&clearObject($scope.selectedModel),$scope.settings.closeOnBlur&&$document.on("click",function(e){if($scope.open){for(var target=e.target.parentElement,parentFound=!1;angular.isDefined(target)&&null!==target&&!parentFound;)target.className.split&&contains(target.className.split(" "),"multiselect-parent")&&!parentFound&&target===$dropdownTrigger&&(parentFound=!0),target=target.parentElement;parentFound||$scope.$apply(function(){$scope.close()})}}),$scope.getGroupLabel=function(groupValue){return null!==$scope.settings.groupByTextProvider?$scope.settings.groupByTextProvider(groupValue):groupValue},$scope.getButtonText=function(){if($scope.settings.dynamicTitle&&($scope.selectedModel.length>0||angular.isObject($scope.selectedModel)&&Object.keys($scope.selectedModel).length>0)){if($scope.settings.smartButtonMaxItems>0){var paddingWidth=24,borderWidth=2,dropdownIconWidth=8,widthLimit=(textWidth("..."),$element[0].offsetWidth-paddingWidth-borderWidth-dropdownIconWidth),itemsText=[];angular.forEach($scope.options,function(optionItem){if($scope.isChecked($scope.getPropertyForObject(optionItem,$scope.settings.idProp))){var displayText=$scope.getPropertyForObject(optionItem,$scope.settings.displayProp),converterResponse=$scope.settings.smartButtonTextConverter(displayText,optionItem);itemsText.push(converterResponse?converterResponse:displayText)}}),$scope.selectedModel.length>$scope.settings.smartButtonMaxItems&&(itemsText=itemsText.slice(0,$scope.settings.smartButtonMaxItems),itemsText.push("..."));var result=itemsText.join(", "),index=result.length-4;if(0===$element[0].offsetWidth)return result;for(;textWidth(result)>widthLimit;)"..."!==itemsText[itemsText.length-1]&&(itemsText.push("..."),result+="..."),result=result.slice(0,index)+result.slice(index+1),index--;return result}var totalSelected;return totalSelected=$scope.singleSelection?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.idProp])?1:0:angular.isDefined($scope.selectedModel)?$scope.selectedModel.length:0,0===totalSelected?$scope.texts.buttonDefaultText:$scope.settings.showAllSelectedText&&totalSelected===$scope.options.length?$scope.texts.allSelectedText:totalSelected+" "+$scope.texts.dynamicButtonTextSuffix}return $scope.texts.buttonDefaultText},$scope.getPropertyForObject=function(object,property){return angular.isDefined(object)&&object.hasOwnProperty(property)?object[property]:void 0},$scope.selectAll=function(){var searchResult;$scope.deselectAll(!0),$scope.externalEvents.onSelectAll(),searchResult=$filter("filter")($scope.options,$scope.getFilter($scope.input.searchFilter)),angular.forEach(searchResult,function(value){$scope.setSelectedItem(value[$scope.settings.idProp],!0,!1)}),$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.deselectAll=function(dontSendEvent){dontSendEvent=dontSendEvent||!1,dontSendEvent||$scope.externalEvents.onDeselectAll(),$scope.singleSelection?clearObject($scope.selectedModel):$scope.selectedModel.splice(0,$scope.selectedModel.length),dontSendEvent||$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.setSelectedItem=function(id,dontRemove,fireSelectionChange){var findObj=getFindObj(id),finalObj=null;if(finalObj=""===$scope.settings.externalIdProp?find($scope.options,findObj):findObj,$scope.singleSelection)clearObject($scope.selectedModel),angular.extend($scope.selectedModel,finalObj),fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),($scope.settings.closeOnSelect||$scope.settings.closeOnDeselect)&&$scope.close();else{dontRemove=dontRemove||!1;var exists=-1!==findIndex($scope.selectedModel,findObj);!dontRemove&&exists?($scope.selectedModel.splice(findIndex($scope.selectedModel,findObj),1),$scope.externalEvents.onItemDeselect(findObj),$scope.settings.closeOnDeselect&&$scope.close()):!exists&&(0===$scope.settings.selectionLimit||$scope.selectedModel.length<$scope.settings.selectionLimit)&&($scope.selectedModel.push(finalObj),fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),$scope.settings.closeOnSelect&&$scope.close(),$scope.settings.selectionLimit>0&&$scope.selectedModel.length===$scope.settings.selectionLimit&&$scope.externalEvents.onMaxSelectionReached())}fireSelectionChange&&$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.isChecked=function(id){return $scope.singleSelection?""===$scope.settings.externalIdProp?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.idProp])&&$scope.selectedModel[$scope.settings.idProp]===getFindObj(id)[$scope.settings.idProp]:null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.externalIdProp])&&$scope.selectedModel[$scope.settings.externalIdProp]===getFindObj(id)[$scope.settings.externalIdProp]:-1!==findIndex($scope.selectedModel,getFindObj(id))},$scope.externalEvents.onInitDone(),$scope.keyDownLink=function(event){var nextOption,sourceScope=angular.element(event.target).scope(),parent=event.target.parentNode;if($scope.settings.keyboardControls)if(13===event.keyCode||32===event.keyCode)event.preventDefault(),sourceScope.option?$scope.setSelectedItem($scope.getPropertyForObject(sourceScope.option,$scope.settings.idProp),!1,!0):"deselectAll"===event.target.id?$scope.deselectAll():"selectAll"===event.target.id&&$scope.selectAll();else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else if(40===event.keyCode){for(event.preventDefault(),parent.nextElementSibling&&(nextOption=parent.nextElementSibling.querySelector("a")||parent.nextElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.nextElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearchDefault=function(event){var nextOption,parent=event.target.parentNode.parentNode;if($scope.settings.keyboardControls)if(9===event.keyCode||40===event.keyCode)event.preventDefault(),focusFirstOption();else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearch=function(event,searchFilter){var searchResult;$scope.settings.keyboardControls&&13===event.keyCode&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?(searchResult=$filter("filter")($scope.options,$scope.getFilter(searchFilter)),1===searchResult.length&&$scope.setSelectedItem($scope.getPropertyForObject(searchResult[0],$scope.settings.idProp),!1,!0)):$scope.settings.enableSearch&&$scope.selectAll())},$scope.getFilter=function(searchFilter){var filter={};return filter[$scope.settings.searchField]=searchFilter,filter},$scope.toggleSearch=function($event){$event&&$event.stopPropagation(),$scope.settings.enableSearch=!$scope.settings.enableSearch,$scope.settings.enableSearch||($scope.input.searchFilter="")},$scope.keyDownToggleSearch=function(){$scope.settings.keyboardControls&&13===event.keyCode&&($scope.toggleSearch(),$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):focusFirstOption())}}}}])}(angular); \ No newline at end of file +!function(angular){"use strict";function contains(collection,target){var containsTarget=!1;return collection.some(function(object){return object===target?(containsTarget=!0,!0):void 0}),containsTarget}function find(collection,properties){var target;return collection.some(function(object){var hasAllSameProperties=!0;return Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(target=object,!0):void 0}),target}function findIndex(collection,properties){var index=-1,counter=-1;return collection.some(function(object){var hasAllSameProperties=!0;return counter+=1,Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(index=counter,!0):void 0}),index}var directiveModule=angular.module("angularjs-dropdown-multiselect",[]);directiveModule.directive("dmDropdownStaticInclude",["$compile",function($compile){return function(scope,element,attrs){var template=attrs.dmDropdownStaticInclude,contents=element.html(template).contents();$compile(contents)(scope)}}]),directiveModule.directive("ngDropdownMultiselect",["$filter","$document","$compile","$parse",function($filter,$document,$compile,$parse){return{restrict:"AE",scope:{selectedModel:"=",options:"=",extraSettings:"=",events:"=",searchFilter:"=?",translationTexts:"=",groupBy:"@",disabled:"="},template:function(element,attrs){var checkboxes=attrs.checkboxes?!0:!1,groups=attrs.groupBy?!0:!1,template='"},link:function($scope,$element,$attrs){function getFindObj(id){var findObj={};return""===$scope.settings.externalIdProp?findObj[$scope.settings.idProp]=id:findObj[$scope.settings.externalIdProp]=id,findObj}function clearObject(object){for(var prop in object)delete object[prop]}function textWidth(text){var $btn=$element.find("button"),canvas=document.createElement("canvas"),ctx=canvas.getContext("2d");return ctx.font=$btn.css("font-size")+$btn.css("font-family"),ctx.originalFont=$btn.css("font-size")+$btn.css("font-family"),ctx.fillStyle="#000000",ctx.measureText(text).width}function focusFirstOption(){setTimeout(function(){var elementToFocus=angular.element($element)[0].querySelector(".option");angular.isDefined(elementToFocus)&&null!=elementToFocus&&elementToFocus.focus()},0)}var $dropdownTrigger=$element.children()[0];$scope.toggleDropdown=function(){$scope.open?$scope.close():$scope.open=!0,$scope.settings.keyboardControls&&$scope.open&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):focusFirstOption()),$scope.settings.enableSearch&&$scope.open&&setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0)},$scope.checkboxClick=function($event,id){$scope.setSelectedItem(id,!1,!0),$event.stopImmediatePropagation()},$scope.externalEvents={onItemSelect:angular.noop,onItemDeselect:angular.noop,onSelectAll:angular.noop,onDeselectAll:angular.noop,onInitDone:angular.noop,onMaxSelectionReached:angular.noop,onSelectionChanged:angular.noop,onClose:angular.noop},$scope.settings={dynamicTitle:!0,scrollable:!1,scrollableHeight:"300px",closeOnBlur:!0,displayProp:"label",idProp:"id",externalIdProp:"id",enableSearch:!1,selectionLimit:0,showCheckAll:!0,showUncheckAll:!0,showEnableSearchButton:!1,closeOnSelect:!1,buttonClasses:"btn btn-default",closeOnDeselect:!1,groupBy:$attrs.groupBy||void 0,groupByTextProvider:null,smartButtonMaxItems:0,smartButtonTextConverter:angular.noop,styleActive:!1,keyboardControls:!1,template:"{{getPropertyForObject(option, settings.displayProp)}}",searchField:"$",showAllSelectedText:!1},$scope.texts={checkAll:"Check All",uncheckAll:"Uncheck All",selectionCount:"checked",selectionOf:"/",searchPlaceholder:"Search...",buttonDefaultText:"Select",dynamicButtonTextSuffix:"checked",disableSearch:"Disable search",enableSearch:"Enable search",selectGroup:"Select all:",allSelectedText:"All"},$scope.input={searchFilter:$scope.searchFilter||""},angular.isDefined($scope.settings.groupBy)&&$scope.$watch("options",function(newValue){angular.isDefined(newValue)&&($scope.orderedItems=$filter("orderBy")(newValue,$scope.settings.groupBy))}),$scope.$watch("selectedModel",function(newValue){Array.isArray(newValue)?$scope.singleSelection=!1:$scope.singleSelection=!0}),$scope.close=function(){$scope.open=!1,$scope.externalEvents.onClose()},$scope.selectCurrentGroup=function(currentGroup){$scope.selectedModel.splice(0,$scope.selectedModel.length),$scope.orderedItems&&$scope.orderedItems.forEach(function(item){item[$scope.groupBy]===currentGroup&&$scope.setSelectedItem($scope.getPropertyForObject(item,$scope.settings.idProp),!1,!1)}),$scope.externalEvents.onSelectionChanged()},angular.extend($scope.settings,$scope.extraSettings||[]),angular.extend($scope.externalEvents,$scope.events||[]),angular.extend($scope.texts,$scope.translationTexts),$scope.singleSelection=1===$scope.settings.selectionLimit,$scope.singleSelection&&angular.isArray($scope.selectedModel)&&0===$scope.selectedModel.length&&clearObject($scope.selectedModel),$scope.settings.closeOnBlur&&$document.on("click",function(e){if($scope.open){for(var target=e.target.parentElement,parentFound=!1;angular.isDefined(target)&&null!==target&&!parentFound;)target.className.split&&contains(target.className.split(" "),"multiselect-parent")&&!parentFound&&target===$dropdownTrigger&&(parentFound=!0),target=target.parentElement;parentFound||$scope.$apply(function(){$scope.close()})}}),$scope.getGroupLabel=function(groupValue){return null!==$scope.settings.groupByTextProvider?$scope.settings.groupByTextProvider(groupValue):groupValue},$scope.getButtonText=function(){if($scope.settings.dynamicTitle&&$scope.selectedModel&&($scope.selectedModel.length>0||angular.isObject($scope.selectedModel)&&Object.keys($scope.selectedModel).length>0)){if($scope.settings.smartButtonMaxItems>0){var paddingWidth=24,borderWidth=2,dropdownIconWidth=8,widthLimit=(textWidth("..."),$element[0].offsetWidth-paddingWidth-borderWidth-dropdownIconWidth),itemsText=[];angular.forEach($scope.options,function(optionItem){if($scope.isChecked($scope.getPropertyForObject(optionItem,$scope.settings.idProp))){var displayText=$scope.getPropertyForObject(optionItem,$scope.settings.displayProp),converterResponse=$scope.settings.smartButtonTextConverter(displayText,optionItem);itemsText.push(converterResponse?converterResponse:displayText)}}),$scope.selectedModel.length>$scope.settings.smartButtonMaxItems&&(itemsText=itemsText.slice(0,$scope.settings.smartButtonMaxItems),itemsText.push("..."));var result=itemsText.join(", "),index=result.length-4;if(0===$element[0].offsetWidth)return result;for(;textWidth(result)>widthLimit;)"..."!==itemsText[itemsText.length-1]&&(itemsText.push("..."),result+="..."),result=result.slice(0,index)+result.slice(index+1),index--;return result}var totalSelected;return totalSelected=$scope.singleSelection?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.idProp])?1:0:angular.isDefined($scope.selectedModel)?$scope.selectedModel.length:0,0===totalSelected?$scope.texts.buttonDefaultText:$scope.settings.showAllSelectedText&&totalSelected===$scope.options.length?$scope.texts.allSelectedText:totalSelected+" "+$scope.texts.dynamicButtonTextSuffix}return $scope.texts.buttonDefaultText},$scope.getPropertyForObject=function(object,property){return angular.isDefined(object)&&object.hasOwnProperty(property)?object[property]:void 0},$scope.selectAll=function(){var searchResult;$scope.deselectAll(!0),$scope.externalEvents.onSelectAll(),searchResult=$filter("filter")($scope.options,$scope.getFilter($scope.input.searchFilter)),angular.forEach(searchResult,function(value){$scope.setSelectedItem(value[$scope.settings.idProp],!0,!1)}),$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.deselectAll=function(dontSendEvent){dontSendEvent=dontSendEvent||!1,dontSendEvent||$scope.externalEvents.onDeselectAll(),$scope.singleSelection?clearObject($scope.selectedModel):$scope.selectedModel.splice(0,$scope.selectedModel.length),dontSendEvent||$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.setSelectedItem=function(id,dontRemove,fireSelectionChange){var findObj=getFindObj(id),finalObj=null;if(finalObj=""===$scope.settings.externalIdProp?find($scope.options,findObj):findObj,$scope.singleSelection)clearObject($scope.selectedModel),angular.extend($scope.selectedModel,finalObj),fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),($scope.settings.closeOnSelect||$scope.settings.closeOnDeselect)&&$scope.close();else{dontRemove=dontRemove||!1;var exists=-1!==findIndex($scope.selectedModel,findObj);!dontRemove&&exists?($scope.selectedModel.splice(findIndex($scope.selectedModel,findObj),1),$scope.externalEvents.onItemDeselect(findObj),$scope.settings.closeOnDeselect&&$scope.close()):!exists&&(0===$scope.settings.selectionLimit||$scope.selectedModel.length<$scope.settings.selectionLimit)&&($scope.selectedModel.push(finalObj),fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),$scope.settings.closeOnSelect&&$scope.close(),$scope.settings.selectionLimit>0&&$scope.selectedModel.length===$scope.settings.selectionLimit&&$scope.externalEvents.onMaxSelectionReached())}fireSelectionChange&&$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.isChecked=function(id){return $scope.singleSelection?""===$scope.settings.externalIdProp?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.idProp])&&$scope.selectedModel[$scope.settings.idProp]===getFindObj(id)[$scope.settings.idProp]:null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.externalIdProp])&&$scope.selectedModel[$scope.settings.externalIdProp]===getFindObj(id)[$scope.settings.externalIdProp]:-1!==findIndex($scope.selectedModel,getFindObj(id))},$scope.externalEvents.onInitDone(),$scope.keyDownLink=function(event){var nextOption,sourceScope=angular.element(event.target).scope(),parent=event.target.parentNode;if($scope.settings.keyboardControls)if(13===event.keyCode||32===event.keyCode)event.preventDefault(),sourceScope.option?$scope.setSelectedItem($scope.getPropertyForObject(sourceScope.option,$scope.settings.idProp),!1,!0):"deselectAll"===event.target.id?$scope.deselectAll():"selectAll"===event.target.id&&$scope.selectAll();else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else if(40===event.keyCode){for(event.preventDefault(),parent.nextElementSibling&&(nextOption=parent.nextElementSibling.querySelector("a")||parent.nextElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.nextElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearchDefault=function(event){var nextOption,parent=event.target.parentNode.parentNode;if($scope.settings.keyboardControls)if(9===event.keyCode||40===event.keyCode)event.preventDefault(),focusFirstOption();else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearch=function(event,searchFilter){var searchResult;$scope.settings.keyboardControls&&13===event.keyCode&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?(searchResult=$filter("filter")($scope.options,$scope.getFilter(searchFilter)),1===searchResult.length&&$scope.setSelectedItem($scope.getPropertyForObject(searchResult[0],$scope.settings.idProp),!1,!0)):$scope.settings.enableSearch&&$scope.selectAll())},$scope.getFilter=function(searchFilter){var filter={};return filter[$scope.settings.searchField]=searchFilter,filter},$scope.toggleSearch=function($event){$event&&$event.stopPropagation(),$scope.settings.enableSearch=!$scope.settings.enableSearch,$scope.settings.enableSearch||($scope.input.searchFilter="")},$scope.keyDownToggleSearch=function(){$scope.settings.keyboardControls&&13===event.keyCode&&($scope.toggleSearch(),$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):focusFirstOption())}}}}])}(angular); \ No newline at end of file diff --git a/package.json b/package.json index cd289d3b..5bf8b3dd 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "author": "pkempenaers@myforce.be", "name": "angularjs-dropdown-multiselect", - "version": "1.11.4", + "version": "1.11.5", "description": "This directive gives you a Bootstrap Dropdown with the power of AngularJS directives.", "homepage": "http://dotansimha.github.io/angularjs-dropdown-multiselect/#/", "dependencies": { From d4f28ff6c621919695b147ae28be18a51d01e519 Mon Sep 17 00:00:00 2001 From: pkempenaers Date: Thu, 16 Mar 2017 10:50:51 +0100 Subject: [PATCH 08/11] Release 1.11.6 --- bower.json | 2 +- dist/angularjs-dropdown-multiselect.min.js | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bower.json b/bower.json index c6e75e7e..cfb7aa18 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angularjs-dropdown-multiselect", - "version": "1.11.5", + "version": "1.11.6", "authors": [ "Dotan Simha ", "Pieter Kempenaers " diff --git a/dist/angularjs-dropdown-multiselect.min.js b/dist/angularjs-dropdown-multiselect.min.js index cc64aae7..2c2aacb0 100644 --- a/dist/angularjs-dropdown-multiselect.min.js +++ b/dist/angularjs-dropdown-multiselect.min.js @@ -1 +1 @@ -!function(angular){"use strict";function contains(collection,target){var containsTarget=!1;return collection.some(function(object){return object===target?(containsTarget=!0,!0):void 0}),containsTarget}function find(collection,properties){var target;return collection.some(function(object){var hasAllSameProperties=!0;return Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(target=object,!0):void 0}),target}function findIndex(collection,properties){var index=-1,counter=-1;return collection.some(function(object){var hasAllSameProperties=!0;return counter+=1,Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(index=counter,!0):void 0}),index}var directiveModule=angular.module("angularjs-dropdown-multiselect",[]);directiveModule.directive("dmDropdownStaticInclude",["$compile",function($compile){return function(scope,element,attrs){var template=attrs.dmDropdownStaticInclude,contents=element.html(template).contents();$compile(contents)(scope)}}]),directiveModule.directive("ngDropdownMultiselect",["$filter","$document","$compile","$parse",function($filter,$document,$compile,$parse){return{restrict:"AE",scope:{selectedModel:"=",options:"=",extraSettings:"=",events:"=",searchFilter:"=?",translationTexts:"=",groupBy:"@",disabled:"="},template:function(element,attrs){var checkboxes=attrs.checkboxes?!0:!1,groups=attrs.groupBy?!0:!1,template='"},link:function($scope,$element,$attrs){function getFindObj(id){var findObj={};return""===$scope.settings.externalIdProp?findObj[$scope.settings.idProp]=id:findObj[$scope.settings.externalIdProp]=id,findObj}function clearObject(object){for(var prop in object)delete object[prop]}function textWidth(text){var $btn=$element.find("button"),canvas=document.createElement("canvas"),ctx=canvas.getContext("2d");return ctx.font=$btn.css("font-size")+$btn.css("font-family"),ctx.originalFont=$btn.css("font-size")+$btn.css("font-family"),ctx.fillStyle="#000000",ctx.measureText(text).width}function focusFirstOption(){setTimeout(function(){var elementToFocus=angular.element($element)[0].querySelector(".option");angular.isDefined(elementToFocus)&&null!=elementToFocus&&elementToFocus.focus()},0)}var $dropdownTrigger=$element.children()[0];$scope.toggleDropdown=function(){$scope.open?$scope.close():$scope.open=!0,$scope.settings.keyboardControls&&$scope.open&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):focusFirstOption()),$scope.settings.enableSearch&&$scope.open&&setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0)},$scope.checkboxClick=function($event,id){$scope.setSelectedItem(id,!1,!0),$event.stopImmediatePropagation()},$scope.externalEvents={onItemSelect:angular.noop,onItemDeselect:angular.noop,onSelectAll:angular.noop,onDeselectAll:angular.noop,onInitDone:angular.noop,onMaxSelectionReached:angular.noop,onSelectionChanged:angular.noop,onClose:angular.noop},$scope.settings={dynamicTitle:!0,scrollable:!1,scrollableHeight:"300px",closeOnBlur:!0,displayProp:"label",idProp:"id",externalIdProp:"id",enableSearch:!1,selectionLimit:0,showCheckAll:!0,showUncheckAll:!0,showEnableSearchButton:!1,closeOnSelect:!1,buttonClasses:"btn btn-default",closeOnDeselect:!1,groupBy:$attrs.groupBy||void 0,groupByTextProvider:null,smartButtonMaxItems:0,smartButtonTextConverter:angular.noop,styleActive:!1,keyboardControls:!1,template:"{{getPropertyForObject(option, settings.displayProp)}}",searchField:"$",showAllSelectedText:!1},$scope.texts={checkAll:"Check All",uncheckAll:"Uncheck All",selectionCount:"checked",selectionOf:"/",searchPlaceholder:"Search...",buttonDefaultText:"Select",dynamicButtonTextSuffix:"checked",disableSearch:"Disable search",enableSearch:"Enable search",selectGroup:"Select all:",allSelectedText:"All"},$scope.input={searchFilter:$scope.searchFilter||""},angular.isDefined($scope.settings.groupBy)&&$scope.$watch("options",function(newValue){angular.isDefined(newValue)&&($scope.orderedItems=$filter("orderBy")(newValue,$scope.settings.groupBy))}),$scope.$watch("selectedModel",function(newValue){Array.isArray(newValue)?$scope.singleSelection=!1:$scope.singleSelection=!0}),$scope.close=function(){$scope.open=!1,$scope.externalEvents.onClose()},$scope.selectCurrentGroup=function(currentGroup){$scope.selectedModel.splice(0,$scope.selectedModel.length),$scope.orderedItems&&$scope.orderedItems.forEach(function(item){item[$scope.groupBy]===currentGroup&&$scope.setSelectedItem($scope.getPropertyForObject(item,$scope.settings.idProp),!1,!1)}),$scope.externalEvents.onSelectionChanged()},angular.extend($scope.settings,$scope.extraSettings||[]),angular.extend($scope.externalEvents,$scope.events||[]),angular.extend($scope.texts,$scope.translationTexts),$scope.singleSelection=1===$scope.settings.selectionLimit,$scope.singleSelection&&angular.isArray($scope.selectedModel)&&0===$scope.selectedModel.length&&clearObject($scope.selectedModel),$scope.settings.closeOnBlur&&$document.on("click",function(e){if($scope.open){for(var target=e.target.parentElement,parentFound=!1;angular.isDefined(target)&&null!==target&&!parentFound;)target.className.split&&contains(target.className.split(" "),"multiselect-parent")&&!parentFound&&target===$dropdownTrigger&&(parentFound=!0),target=target.parentElement;parentFound||$scope.$apply(function(){$scope.close()})}}),$scope.getGroupLabel=function(groupValue){return null!==$scope.settings.groupByTextProvider?$scope.settings.groupByTextProvider(groupValue):groupValue},$scope.getButtonText=function(){if($scope.settings.dynamicTitle&&$scope.selectedModel&&($scope.selectedModel.length>0||angular.isObject($scope.selectedModel)&&Object.keys($scope.selectedModel).length>0)){if($scope.settings.smartButtonMaxItems>0){var paddingWidth=24,borderWidth=2,dropdownIconWidth=8,widthLimit=(textWidth("..."),$element[0].offsetWidth-paddingWidth-borderWidth-dropdownIconWidth),itemsText=[];angular.forEach($scope.options,function(optionItem){if($scope.isChecked($scope.getPropertyForObject(optionItem,$scope.settings.idProp))){var displayText=$scope.getPropertyForObject(optionItem,$scope.settings.displayProp),converterResponse=$scope.settings.smartButtonTextConverter(displayText,optionItem);itemsText.push(converterResponse?converterResponse:displayText)}}),$scope.selectedModel.length>$scope.settings.smartButtonMaxItems&&(itemsText=itemsText.slice(0,$scope.settings.smartButtonMaxItems),itemsText.push("..."));var result=itemsText.join(", "),index=result.length-4;if(0===$element[0].offsetWidth)return result;for(;textWidth(result)>widthLimit;)"..."!==itemsText[itemsText.length-1]&&(itemsText.push("..."),result+="..."),result=result.slice(0,index)+result.slice(index+1),index--;return result}var totalSelected;return totalSelected=$scope.singleSelection?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.idProp])?1:0:angular.isDefined($scope.selectedModel)?$scope.selectedModel.length:0,0===totalSelected?$scope.texts.buttonDefaultText:$scope.settings.showAllSelectedText&&totalSelected===$scope.options.length?$scope.texts.allSelectedText:totalSelected+" "+$scope.texts.dynamicButtonTextSuffix}return $scope.texts.buttonDefaultText},$scope.getPropertyForObject=function(object,property){return angular.isDefined(object)&&object.hasOwnProperty(property)?object[property]:void 0},$scope.selectAll=function(){var searchResult;$scope.deselectAll(!0),$scope.externalEvents.onSelectAll(),searchResult=$filter("filter")($scope.options,$scope.getFilter($scope.input.searchFilter)),angular.forEach(searchResult,function(value){$scope.setSelectedItem(value[$scope.settings.idProp],!0,!1)}),$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.deselectAll=function(dontSendEvent){dontSendEvent=dontSendEvent||!1,dontSendEvent||$scope.externalEvents.onDeselectAll(),$scope.singleSelection?clearObject($scope.selectedModel):$scope.selectedModel.splice(0,$scope.selectedModel.length),dontSendEvent||$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.setSelectedItem=function(id,dontRemove,fireSelectionChange){var findObj=getFindObj(id),finalObj=null;if(finalObj=""===$scope.settings.externalIdProp?find($scope.options,findObj):findObj,$scope.singleSelection)clearObject($scope.selectedModel),angular.extend($scope.selectedModel,finalObj),fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),($scope.settings.closeOnSelect||$scope.settings.closeOnDeselect)&&$scope.close();else{dontRemove=dontRemove||!1;var exists=-1!==findIndex($scope.selectedModel,findObj);!dontRemove&&exists?($scope.selectedModel.splice(findIndex($scope.selectedModel,findObj),1),$scope.externalEvents.onItemDeselect(findObj),$scope.settings.closeOnDeselect&&$scope.close()):!exists&&(0===$scope.settings.selectionLimit||$scope.selectedModel.length<$scope.settings.selectionLimit)&&($scope.selectedModel.push(finalObj),fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),$scope.settings.closeOnSelect&&$scope.close(),$scope.settings.selectionLimit>0&&$scope.selectedModel.length===$scope.settings.selectionLimit&&$scope.externalEvents.onMaxSelectionReached())}fireSelectionChange&&$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.isChecked=function(id){return $scope.singleSelection?""===$scope.settings.externalIdProp?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.idProp])&&$scope.selectedModel[$scope.settings.idProp]===getFindObj(id)[$scope.settings.idProp]:null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.externalIdProp])&&$scope.selectedModel[$scope.settings.externalIdProp]===getFindObj(id)[$scope.settings.externalIdProp]:-1!==findIndex($scope.selectedModel,getFindObj(id))},$scope.externalEvents.onInitDone(),$scope.keyDownLink=function(event){var nextOption,sourceScope=angular.element(event.target).scope(),parent=event.target.parentNode;if($scope.settings.keyboardControls)if(13===event.keyCode||32===event.keyCode)event.preventDefault(),sourceScope.option?$scope.setSelectedItem($scope.getPropertyForObject(sourceScope.option,$scope.settings.idProp),!1,!0):"deselectAll"===event.target.id?$scope.deselectAll():"selectAll"===event.target.id&&$scope.selectAll();else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else if(40===event.keyCode){for(event.preventDefault(),parent.nextElementSibling&&(nextOption=parent.nextElementSibling.querySelector("a")||parent.nextElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.nextElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearchDefault=function(event){var nextOption,parent=event.target.parentNode.parentNode;if($scope.settings.keyboardControls)if(9===event.keyCode||40===event.keyCode)event.preventDefault(),focusFirstOption();else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearch=function(event,searchFilter){var searchResult;$scope.settings.keyboardControls&&13===event.keyCode&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?(searchResult=$filter("filter")($scope.options,$scope.getFilter(searchFilter)),1===searchResult.length&&$scope.setSelectedItem($scope.getPropertyForObject(searchResult[0],$scope.settings.idProp),!1,!0)):$scope.settings.enableSearch&&$scope.selectAll())},$scope.getFilter=function(searchFilter){var filter={};return filter[$scope.settings.searchField]=searchFilter,filter},$scope.toggleSearch=function($event){$event&&$event.stopPropagation(),$scope.settings.enableSearch=!$scope.settings.enableSearch,$scope.settings.enableSearch||($scope.input.searchFilter="")},$scope.keyDownToggleSearch=function(){$scope.settings.keyboardControls&&13===event.keyCode&&($scope.toggleSearch(),$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):focusFirstOption())}}}}])}(angular); \ No newline at end of file +!function(angular){"use strict";function contains(collection,target){var containsTarget=!1;return collection.some(function(object){return object===target?(containsTarget=!0,!0):void 0}),containsTarget}function find(collection,properties){var target;return 0===Object.keys(properties).length?void 0:(collection.some(function(object){var hasAllSameProperties=!0;return Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(target=object,!0):void 0}),target)}function findIndex(collection,properties){var index=-1,counter=-1;return collection.some(function(object){var hasAllSameProperties=!0;return counter+=1,Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(index=counter,!0):void 0}),index}var directiveModule=angular.module("angularjs-dropdown-multiselect",[]);directiveModule.directive("dmDropdownStaticInclude",["$compile",function($compile){return function(scope,element,attrs){var template=attrs.dmDropdownStaticInclude,contents=element.html(template).contents();$compile(contents)(scope)}}]),directiveModule.directive("ngDropdownMultiselect",["$filter","$document","$compile","$parse",function($filter,$document,$compile,$parse){return{restrict:"AE",scope:{selectedModel:"=",options:"=",extraSettings:"=",events:"=",searchFilter:"=?",translationTexts:"=",groupBy:"@",disabled:"="},template:function(element,attrs){var checkboxes=attrs.checkboxes?!0:!1,groups=attrs.groupBy?!0:!1,template='"},link:function($scope,$element,$attrs){function getFindObj(id){var findObj={};return""===$scope.settings.externalIdProp?findObj[$scope.settings.idProp]=id:findObj[$scope.settings.externalIdProp]=id,findObj}function textWidth(text){var $btn=$element.find("button"),canvas=document.createElement("canvas"),ctx=canvas.getContext("2d");return ctx.font=$btn.css("font-size")+$btn.css("font-family"),ctx.originalFont=$btn.css("font-size")+$btn.css("font-family"),ctx.fillStyle="#000000",ctx.measureText(text).width}function focusFirstOption(){setTimeout(function(){var elementToFocus=angular.element($element)[0].querySelector(".option");angular.isDefined(elementToFocus)&&null!=elementToFocus&&elementToFocus.focus()},0)}var $dropdownTrigger=$element.children()[0];$scope.toggleDropdown=function(){$scope.open?$scope.close():$scope.open=!0,$scope.settings.keyboardControls&&$scope.open&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):focusFirstOption()),$scope.settings.enableSearch&&$scope.open&&setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0)},$scope.checkboxClick=function($event,id){$scope.setSelectedItem(id,!1,!0),$event.stopImmediatePropagation()},$scope.externalEvents={onItemSelect:angular.noop,onItemDeselect:angular.noop,onSelectAll:angular.noop,onDeselectAll:angular.noop,onInitDone:angular.noop,onMaxSelectionReached:angular.noop,onSelectionChanged:angular.noop,onClose:angular.noop},$scope.settings={dynamicTitle:!0,scrollable:!1,scrollableHeight:"300px",closeOnBlur:!0,displayProp:"label",idProp:"id",externalIdProp:"id",enableSearch:!1,selectionLimit:0,showCheckAll:!0,showUncheckAll:!0,showEnableSearchButton:!1,closeOnSelect:!1,buttonClasses:"btn btn-default",closeOnDeselect:!1,groupBy:$attrs.groupBy||void 0,groupByTextProvider:null,smartButtonMaxItems:0,smartButtonTextConverter:angular.noop,styleActive:!1,keyboardControls:!1,template:"{{getPropertyForObject(option, settings.displayProp)}}",searchField:"$",showAllSelectedText:!1},$scope.texts={checkAll:"Check All",uncheckAll:"Uncheck All",selectionCount:"checked",selectionOf:"/",searchPlaceholder:"Search...",buttonDefaultText:"Select",dynamicButtonTextSuffix:"checked",disableSearch:"Disable search",enableSearch:"Enable search",selectGroup:"Select all:",allSelectedText:"All"},$scope.input={searchFilter:$scope.searchFilter||""},angular.isDefined($scope.settings.groupBy)&&$scope.$watch("options",function(newValue){angular.isDefined(newValue)&&($scope.orderedItems=$filter("orderBy")(newValue,$scope.settings.groupBy))}),$scope.$watch("selectedModel",function(newValue){Array.isArray(newValue)?$scope.singleSelection=!1:$scope.singleSelection=!0}),$scope.close=function(){$scope.open=!1,$scope.externalEvents.onClose()},$scope.selectCurrentGroup=function(currentGroup){$scope.selectedModel.splice(0,$scope.selectedModel.length),$scope.orderedItems&&$scope.orderedItems.forEach(function(item){item[$scope.groupBy]===currentGroup&&$scope.setSelectedItem($scope.getPropertyForObject(item,$scope.settings.idProp),!1,!1)}),$scope.externalEvents.onSelectionChanged()},angular.extend($scope.settings,$scope.extraSettings||[]),angular.extend($scope.externalEvents,$scope.events||[]),angular.extend($scope.texts,$scope.translationTexts),$scope.singleSelection=1===$scope.settings.selectionLimit,$scope.singleSelection&&angular.isArray($scope.selectedModel)&&0===$scope.selectedModel.length&&($scope.selectedModel={}),$scope.settings.closeOnBlur&&$document.on("click",function(e){if($scope.open){for(var target=e.target.parentElement,parentFound=!1;angular.isDefined(target)&&null!==target&&!parentFound;)target.className.split&&contains(target.className.split(" "),"multiselect-parent")&&!parentFound&&target===$dropdownTrigger&&(parentFound=!0),target=target.parentElement;parentFound||$scope.$apply(function(){$scope.close()})}}),$scope.getGroupLabel=function(groupValue){return null!==$scope.settings.groupByTextProvider?$scope.settings.groupByTextProvider(groupValue):groupValue},$scope.getButtonText=function(){if($scope.settings.dynamicTitle&&$scope.selectedModel&&($scope.selectedModel.length>0||angular.isObject($scope.selectedModel)&&Object.keys($scope.selectedModel).length>0)){if($scope.settings.smartButtonMaxItems>0){var paddingWidth=24,borderWidth=2,dropdownIconWidth=8,widthLimit=(textWidth("..."),$element[0].offsetWidth-paddingWidth-borderWidth-dropdownIconWidth),itemsText=[];angular.forEach($scope.options,function(optionItem){if($scope.isChecked($scope.getPropertyForObject(optionItem,$scope.settings.idProp))){var displayText=$scope.getPropertyForObject(optionItem,$scope.settings.displayProp),converterResponse=$scope.settings.smartButtonTextConverter(displayText,optionItem);itemsText.push(converterResponse?converterResponse:displayText)}}),$scope.selectedModel.length>$scope.settings.smartButtonMaxItems&&(itemsText=itemsText.slice(0,$scope.settings.smartButtonMaxItems),itemsText.push("..."));var result=itemsText.join(", "),index=result.length-4;if(0===$element[0].offsetWidth)return result;for(;textWidth(result)>widthLimit;)"..."!==itemsText[itemsText.length-1]&&(itemsText.push("..."),result+="..."),result=result.slice(0,index)+result.slice(index+1),index--;return result}var totalSelected;return totalSelected=$scope.singleSelection?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.idProp])?1:0:angular.isDefined($scope.selectedModel)?$scope.selectedModel.length:0,0===totalSelected?$scope.texts.buttonDefaultText:$scope.settings.showAllSelectedText&&totalSelected===$scope.options.length?$scope.texts.allSelectedText:totalSelected+" "+$scope.texts.dynamicButtonTextSuffix}return $scope.texts.buttonDefaultText},$scope.getPropertyForObject=function(object,property){return angular.isDefined(object)&&object.hasOwnProperty(property)?object[property]:void 0},$scope.selectAll=function(){var searchResult;$scope.deselectAll(!0),$scope.externalEvents.onSelectAll(),searchResult=$filter("filter")($scope.options,$scope.getFilter($scope.input.searchFilter)),angular.forEach(searchResult,function(value){$scope.setSelectedItem(value[$scope.settings.idProp],!0,!1)}),$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.deselectAll=function(dontSendEvent){dontSendEvent=dontSendEvent||!1,dontSendEvent||$scope.externalEvents.onDeselectAll(),$scope.singleSelection?$scope.selectedModel={}:$scope.selectedModel.splice(0,$scope.selectedModel.length),dontSendEvent||$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.setSelectedItem=function(id,dontRemove,fireSelectionChange){var findObj=getFindObj(id),finalObj=null;if(finalObj=""===$scope.settings.externalIdProp?find($scope.options,findObj):findObj,$scope.singleSelection)find($scope.options,$scope.selectedModel)===find($scope.options,findObj)?$scope.selectedModel={}:$scope.selectedModel=finalObj,fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),($scope.settings.closeOnSelect||$scope.settings.closeOnDeselect)&&$scope.close();else{dontRemove=dontRemove||!1;var exists=-1!==findIndex($scope.selectedModel,findObj);!dontRemove&&exists?($scope.selectedModel.splice(findIndex($scope.selectedModel,findObj),1),$scope.externalEvents.onItemDeselect(findObj),$scope.settings.closeOnDeselect&&$scope.close()):!exists&&(0===$scope.settings.selectionLimit||$scope.selectedModel.length<$scope.settings.selectionLimit)&&($scope.selectedModel.push(finalObj),fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),$scope.settings.closeOnSelect&&$scope.close(),$scope.settings.selectionLimit>0&&$scope.selectedModel.length===$scope.settings.selectionLimit&&$scope.externalEvents.onMaxSelectionReached())}fireSelectionChange&&$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.isChecked=function(id){return $scope.singleSelection?""===$scope.settings.externalIdProp?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.idProp])&&$scope.selectedModel[$scope.settings.idProp]===getFindObj(id)[$scope.settings.idProp]:null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.externalIdProp])&&$scope.selectedModel[$scope.settings.externalIdProp]===getFindObj(id)[$scope.settings.externalIdProp]:-1!==findIndex($scope.selectedModel,getFindObj(id))},$scope.externalEvents.onInitDone(),$scope.keyDownLink=function(event){var nextOption,sourceScope=angular.element(event.target).scope(),parent=event.target.parentNode;if($scope.settings.keyboardControls)if(13===event.keyCode||32===event.keyCode)event.preventDefault(),sourceScope.option?$scope.setSelectedItem($scope.getPropertyForObject(sourceScope.option,$scope.settings.idProp),!1,!0):"deselectAll"===event.target.id?$scope.deselectAll():"selectAll"===event.target.id&&$scope.selectAll();else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else if(40===event.keyCode){for(event.preventDefault(),parent.nextElementSibling&&(nextOption=parent.nextElementSibling.querySelector("a")||parent.nextElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.nextElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearchDefault=function(event){var nextOption,parent=event.target.parentNode.parentNode;if($scope.settings.keyboardControls)if(9===event.keyCode||40===event.keyCode)event.preventDefault(),focusFirstOption();else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearch=function(event,searchFilter){var searchResult;$scope.settings.keyboardControls&&13===event.keyCode&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?(searchResult=$filter("filter")($scope.options,$scope.getFilter(searchFilter)),1===searchResult.length&&$scope.setSelectedItem($scope.getPropertyForObject(searchResult[0],$scope.settings.idProp),!1,!0)):$scope.settings.enableSearch&&$scope.selectAll())},$scope.getFilter=function(searchFilter){var filter={};return filter[$scope.settings.searchField]=searchFilter,filter},$scope.toggleSearch=function($event){$event&&$event.stopPropagation(),$scope.settings.enableSearch=!$scope.settings.enableSearch,$scope.settings.enableSearch||($scope.input.searchFilter="")},$scope.keyDownToggleSearch=function(){$scope.settings.keyboardControls&&13===event.keyCode&&($scope.toggleSearch(),$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):focusFirstOption())}}}}])}(angular); \ No newline at end of file diff --git a/package.json b/package.json index 5bf8b3dd..a657fe98 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "author": "pkempenaers@myforce.be", "name": "angularjs-dropdown-multiselect", - "version": "1.11.5", + "version": "1.11.6", "description": "This directive gives you a Bootstrap Dropdown with the power of AngularJS directives.", "homepage": "http://dotansimha.github.io/angularjs-dropdown-multiselect/#/", "dependencies": { From 04de84ddb33de7fcaff591f826151326e8a19e67 Mon Sep 17 00:00:00 2001 From: pkempenaers Date: Thu, 16 Mar 2017 16:04:16 +0100 Subject: [PATCH 09/11] Release 1.11.7 --- bower.json | 2 +- dist/angularjs-dropdown-multiselect.min.js | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bower.json b/bower.json index cfb7aa18..90c2304b 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angularjs-dropdown-multiselect", - "version": "1.11.6", + "version": "1.11.7", "authors": [ "Dotan Simha ", "Pieter Kempenaers " diff --git a/dist/angularjs-dropdown-multiselect.min.js b/dist/angularjs-dropdown-multiselect.min.js index 2c2aacb0..cc64aae7 100644 --- a/dist/angularjs-dropdown-multiselect.min.js +++ b/dist/angularjs-dropdown-multiselect.min.js @@ -1 +1 @@ -!function(angular){"use strict";function contains(collection,target){var containsTarget=!1;return collection.some(function(object){return object===target?(containsTarget=!0,!0):void 0}),containsTarget}function find(collection,properties){var target;return 0===Object.keys(properties).length?void 0:(collection.some(function(object){var hasAllSameProperties=!0;return Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(target=object,!0):void 0}),target)}function findIndex(collection,properties){var index=-1,counter=-1;return collection.some(function(object){var hasAllSameProperties=!0;return counter+=1,Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(index=counter,!0):void 0}),index}var directiveModule=angular.module("angularjs-dropdown-multiselect",[]);directiveModule.directive("dmDropdownStaticInclude",["$compile",function($compile){return function(scope,element,attrs){var template=attrs.dmDropdownStaticInclude,contents=element.html(template).contents();$compile(contents)(scope)}}]),directiveModule.directive("ngDropdownMultiselect",["$filter","$document","$compile","$parse",function($filter,$document,$compile,$parse){return{restrict:"AE",scope:{selectedModel:"=",options:"=",extraSettings:"=",events:"=",searchFilter:"=?",translationTexts:"=",groupBy:"@",disabled:"="},template:function(element,attrs){var checkboxes=attrs.checkboxes?!0:!1,groups=attrs.groupBy?!0:!1,template='"},link:function($scope,$element,$attrs){function getFindObj(id){var findObj={};return""===$scope.settings.externalIdProp?findObj[$scope.settings.idProp]=id:findObj[$scope.settings.externalIdProp]=id,findObj}function textWidth(text){var $btn=$element.find("button"),canvas=document.createElement("canvas"),ctx=canvas.getContext("2d");return ctx.font=$btn.css("font-size")+$btn.css("font-family"),ctx.originalFont=$btn.css("font-size")+$btn.css("font-family"),ctx.fillStyle="#000000",ctx.measureText(text).width}function focusFirstOption(){setTimeout(function(){var elementToFocus=angular.element($element)[0].querySelector(".option");angular.isDefined(elementToFocus)&&null!=elementToFocus&&elementToFocus.focus()},0)}var $dropdownTrigger=$element.children()[0];$scope.toggleDropdown=function(){$scope.open?$scope.close():$scope.open=!0,$scope.settings.keyboardControls&&$scope.open&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):focusFirstOption()),$scope.settings.enableSearch&&$scope.open&&setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0)},$scope.checkboxClick=function($event,id){$scope.setSelectedItem(id,!1,!0),$event.stopImmediatePropagation()},$scope.externalEvents={onItemSelect:angular.noop,onItemDeselect:angular.noop,onSelectAll:angular.noop,onDeselectAll:angular.noop,onInitDone:angular.noop,onMaxSelectionReached:angular.noop,onSelectionChanged:angular.noop,onClose:angular.noop},$scope.settings={dynamicTitle:!0,scrollable:!1,scrollableHeight:"300px",closeOnBlur:!0,displayProp:"label",idProp:"id",externalIdProp:"id",enableSearch:!1,selectionLimit:0,showCheckAll:!0,showUncheckAll:!0,showEnableSearchButton:!1,closeOnSelect:!1,buttonClasses:"btn btn-default",closeOnDeselect:!1,groupBy:$attrs.groupBy||void 0,groupByTextProvider:null,smartButtonMaxItems:0,smartButtonTextConverter:angular.noop,styleActive:!1,keyboardControls:!1,template:"{{getPropertyForObject(option, settings.displayProp)}}",searchField:"$",showAllSelectedText:!1},$scope.texts={checkAll:"Check All",uncheckAll:"Uncheck All",selectionCount:"checked",selectionOf:"/",searchPlaceholder:"Search...",buttonDefaultText:"Select",dynamicButtonTextSuffix:"checked",disableSearch:"Disable search",enableSearch:"Enable search",selectGroup:"Select all:",allSelectedText:"All"},$scope.input={searchFilter:$scope.searchFilter||""},angular.isDefined($scope.settings.groupBy)&&$scope.$watch("options",function(newValue){angular.isDefined(newValue)&&($scope.orderedItems=$filter("orderBy")(newValue,$scope.settings.groupBy))}),$scope.$watch("selectedModel",function(newValue){Array.isArray(newValue)?$scope.singleSelection=!1:$scope.singleSelection=!0}),$scope.close=function(){$scope.open=!1,$scope.externalEvents.onClose()},$scope.selectCurrentGroup=function(currentGroup){$scope.selectedModel.splice(0,$scope.selectedModel.length),$scope.orderedItems&&$scope.orderedItems.forEach(function(item){item[$scope.groupBy]===currentGroup&&$scope.setSelectedItem($scope.getPropertyForObject(item,$scope.settings.idProp),!1,!1)}),$scope.externalEvents.onSelectionChanged()},angular.extend($scope.settings,$scope.extraSettings||[]),angular.extend($scope.externalEvents,$scope.events||[]),angular.extend($scope.texts,$scope.translationTexts),$scope.singleSelection=1===$scope.settings.selectionLimit,$scope.singleSelection&&angular.isArray($scope.selectedModel)&&0===$scope.selectedModel.length&&($scope.selectedModel={}),$scope.settings.closeOnBlur&&$document.on("click",function(e){if($scope.open){for(var target=e.target.parentElement,parentFound=!1;angular.isDefined(target)&&null!==target&&!parentFound;)target.className.split&&contains(target.className.split(" "),"multiselect-parent")&&!parentFound&&target===$dropdownTrigger&&(parentFound=!0),target=target.parentElement;parentFound||$scope.$apply(function(){$scope.close()})}}),$scope.getGroupLabel=function(groupValue){return null!==$scope.settings.groupByTextProvider?$scope.settings.groupByTextProvider(groupValue):groupValue},$scope.getButtonText=function(){if($scope.settings.dynamicTitle&&$scope.selectedModel&&($scope.selectedModel.length>0||angular.isObject($scope.selectedModel)&&Object.keys($scope.selectedModel).length>0)){if($scope.settings.smartButtonMaxItems>0){var paddingWidth=24,borderWidth=2,dropdownIconWidth=8,widthLimit=(textWidth("..."),$element[0].offsetWidth-paddingWidth-borderWidth-dropdownIconWidth),itemsText=[];angular.forEach($scope.options,function(optionItem){if($scope.isChecked($scope.getPropertyForObject(optionItem,$scope.settings.idProp))){var displayText=$scope.getPropertyForObject(optionItem,$scope.settings.displayProp),converterResponse=$scope.settings.smartButtonTextConverter(displayText,optionItem);itemsText.push(converterResponse?converterResponse:displayText)}}),$scope.selectedModel.length>$scope.settings.smartButtonMaxItems&&(itemsText=itemsText.slice(0,$scope.settings.smartButtonMaxItems),itemsText.push("..."));var result=itemsText.join(", "),index=result.length-4;if(0===$element[0].offsetWidth)return result;for(;textWidth(result)>widthLimit;)"..."!==itemsText[itemsText.length-1]&&(itemsText.push("..."),result+="..."),result=result.slice(0,index)+result.slice(index+1),index--;return result}var totalSelected;return totalSelected=$scope.singleSelection?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.idProp])?1:0:angular.isDefined($scope.selectedModel)?$scope.selectedModel.length:0,0===totalSelected?$scope.texts.buttonDefaultText:$scope.settings.showAllSelectedText&&totalSelected===$scope.options.length?$scope.texts.allSelectedText:totalSelected+" "+$scope.texts.dynamicButtonTextSuffix}return $scope.texts.buttonDefaultText},$scope.getPropertyForObject=function(object,property){return angular.isDefined(object)&&object.hasOwnProperty(property)?object[property]:void 0},$scope.selectAll=function(){var searchResult;$scope.deselectAll(!0),$scope.externalEvents.onSelectAll(),searchResult=$filter("filter")($scope.options,$scope.getFilter($scope.input.searchFilter)),angular.forEach(searchResult,function(value){$scope.setSelectedItem(value[$scope.settings.idProp],!0,!1)}),$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.deselectAll=function(dontSendEvent){dontSendEvent=dontSendEvent||!1,dontSendEvent||$scope.externalEvents.onDeselectAll(),$scope.singleSelection?$scope.selectedModel={}:$scope.selectedModel.splice(0,$scope.selectedModel.length),dontSendEvent||$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.setSelectedItem=function(id,dontRemove,fireSelectionChange){var findObj=getFindObj(id),finalObj=null;if(finalObj=""===$scope.settings.externalIdProp?find($scope.options,findObj):findObj,$scope.singleSelection)find($scope.options,$scope.selectedModel)===find($scope.options,findObj)?$scope.selectedModel={}:$scope.selectedModel=finalObj,fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),($scope.settings.closeOnSelect||$scope.settings.closeOnDeselect)&&$scope.close();else{dontRemove=dontRemove||!1;var exists=-1!==findIndex($scope.selectedModel,findObj);!dontRemove&&exists?($scope.selectedModel.splice(findIndex($scope.selectedModel,findObj),1),$scope.externalEvents.onItemDeselect(findObj),$scope.settings.closeOnDeselect&&$scope.close()):!exists&&(0===$scope.settings.selectionLimit||$scope.selectedModel.length<$scope.settings.selectionLimit)&&($scope.selectedModel.push(finalObj),fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),$scope.settings.closeOnSelect&&$scope.close(),$scope.settings.selectionLimit>0&&$scope.selectedModel.length===$scope.settings.selectionLimit&&$scope.externalEvents.onMaxSelectionReached())}fireSelectionChange&&$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.isChecked=function(id){return $scope.singleSelection?""===$scope.settings.externalIdProp?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.idProp])&&$scope.selectedModel[$scope.settings.idProp]===getFindObj(id)[$scope.settings.idProp]:null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.externalIdProp])&&$scope.selectedModel[$scope.settings.externalIdProp]===getFindObj(id)[$scope.settings.externalIdProp]:-1!==findIndex($scope.selectedModel,getFindObj(id))},$scope.externalEvents.onInitDone(),$scope.keyDownLink=function(event){var nextOption,sourceScope=angular.element(event.target).scope(),parent=event.target.parentNode;if($scope.settings.keyboardControls)if(13===event.keyCode||32===event.keyCode)event.preventDefault(),sourceScope.option?$scope.setSelectedItem($scope.getPropertyForObject(sourceScope.option,$scope.settings.idProp),!1,!0):"deselectAll"===event.target.id?$scope.deselectAll():"selectAll"===event.target.id&&$scope.selectAll();else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else if(40===event.keyCode){for(event.preventDefault(),parent.nextElementSibling&&(nextOption=parent.nextElementSibling.querySelector("a")||parent.nextElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.nextElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearchDefault=function(event){var nextOption,parent=event.target.parentNode.parentNode;if($scope.settings.keyboardControls)if(9===event.keyCode||40===event.keyCode)event.preventDefault(),focusFirstOption();else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearch=function(event,searchFilter){var searchResult;$scope.settings.keyboardControls&&13===event.keyCode&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?(searchResult=$filter("filter")($scope.options,$scope.getFilter(searchFilter)),1===searchResult.length&&$scope.setSelectedItem($scope.getPropertyForObject(searchResult[0],$scope.settings.idProp),!1,!0)):$scope.settings.enableSearch&&$scope.selectAll())},$scope.getFilter=function(searchFilter){var filter={};return filter[$scope.settings.searchField]=searchFilter,filter},$scope.toggleSearch=function($event){$event&&$event.stopPropagation(),$scope.settings.enableSearch=!$scope.settings.enableSearch,$scope.settings.enableSearch||($scope.input.searchFilter="")},$scope.keyDownToggleSearch=function(){$scope.settings.keyboardControls&&13===event.keyCode&&($scope.toggleSearch(),$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):focusFirstOption())}}}}])}(angular); \ No newline at end of file +!function(angular){"use strict";function contains(collection,target){var containsTarget=!1;return collection.some(function(object){return object===target?(containsTarget=!0,!0):void 0}),containsTarget}function find(collection,properties){var target;return collection.some(function(object){var hasAllSameProperties=!0;return Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(target=object,!0):void 0}),target}function findIndex(collection,properties){var index=-1,counter=-1;return collection.some(function(object){var hasAllSameProperties=!0;return counter+=1,Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(index=counter,!0):void 0}),index}var directiveModule=angular.module("angularjs-dropdown-multiselect",[]);directiveModule.directive("dmDropdownStaticInclude",["$compile",function($compile){return function(scope,element,attrs){var template=attrs.dmDropdownStaticInclude,contents=element.html(template).contents();$compile(contents)(scope)}}]),directiveModule.directive("ngDropdownMultiselect",["$filter","$document","$compile","$parse",function($filter,$document,$compile,$parse){return{restrict:"AE",scope:{selectedModel:"=",options:"=",extraSettings:"=",events:"=",searchFilter:"=?",translationTexts:"=",groupBy:"@",disabled:"="},template:function(element,attrs){var checkboxes=attrs.checkboxes?!0:!1,groups=attrs.groupBy?!0:!1,template='"},link:function($scope,$element,$attrs){function getFindObj(id){var findObj={};return""===$scope.settings.externalIdProp?findObj[$scope.settings.idProp]=id:findObj[$scope.settings.externalIdProp]=id,findObj}function clearObject(object){for(var prop in object)delete object[prop]}function textWidth(text){var $btn=$element.find("button"),canvas=document.createElement("canvas"),ctx=canvas.getContext("2d");return ctx.font=$btn.css("font-size")+$btn.css("font-family"),ctx.originalFont=$btn.css("font-size")+$btn.css("font-family"),ctx.fillStyle="#000000",ctx.measureText(text).width}function focusFirstOption(){setTimeout(function(){var elementToFocus=angular.element($element)[0].querySelector(".option");angular.isDefined(elementToFocus)&&null!=elementToFocus&&elementToFocus.focus()},0)}var $dropdownTrigger=$element.children()[0];$scope.toggleDropdown=function(){$scope.open?$scope.close():$scope.open=!0,$scope.settings.keyboardControls&&$scope.open&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):focusFirstOption()),$scope.settings.enableSearch&&$scope.open&&setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0)},$scope.checkboxClick=function($event,id){$scope.setSelectedItem(id,!1,!0),$event.stopImmediatePropagation()},$scope.externalEvents={onItemSelect:angular.noop,onItemDeselect:angular.noop,onSelectAll:angular.noop,onDeselectAll:angular.noop,onInitDone:angular.noop,onMaxSelectionReached:angular.noop,onSelectionChanged:angular.noop,onClose:angular.noop},$scope.settings={dynamicTitle:!0,scrollable:!1,scrollableHeight:"300px",closeOnBlur:!0,displayProp:"label",idProp:"id",externalIdProp:"id",enableSearch:!1,selectionLimit:0,showCheckAll:!0,showUncheckAll:!0,showEnableSearchButton:!1,closeOnSelect:!1,buttonClasses:"btn btn-default",closeOnDeselect:!1,groupBy:$attrs.groupBy||void 0,groupByTextProvider:null,smartButtonMaxItems:0,smartButtonTextConverter:angular.noop,styleActive:!1,keyboardControls:!1,template:"{{getPropertyForObject(option, settings.displayProp)}}",searchField:"$",showAllSelectedText:!1},$scope.texts={checkAll:"Check All",uncheckAll:"Uncheck All",selectionCount:"checked",selectionOf:"/",searchPlaceholder:"Search...",buttonDefaultText:"Select",dynamicButtonTextSuffix:"checked",disableSearch:"Disable search",enableSearch:"Enable search",selectGroup:"Select all:",allSelectedText:"All"},$scope.input={searchFilter:$scope.searchFilter||""},angular.isDefined($scope.settings.groupBy)&&$scope.$watch("options",function(newValue){angular.isDefined(newValue)&&($scope.orderedItems=$filter("orderBy")(newValue,$scope.settings.groupBy))}),$scope.$watch("selectedModel",function(newValue){Array.isArray(newValue)?$scope.singleSelection=!1:$scope.singleSelection=!0}),$scope.close=function(){$scope.open=!1,$scope.externalEvents.onClose()},$scope.selectCurrentGroup=function(currentGroup){$scope.selectedModel.splice(0,$scope.selectedModel.length),$scope.orderedItems&&$scope.orderedItems.forEach(function(item){item[$scope.groupBy]===currentGroup&&$scope.setSelectedItem($scope.getPropertyForObject(item,$scope.settings.idProp),!1,!1)}),$scope.externalEvents.onSelectionChanged()},angular.extend($scope.settings,$scope.extraSettings||[]),angular.extend($scope.externalEvents,$scope.events||[]),angular.extend($scope.texts,$scope.translationTexts),$scope.singleSelection=1===$scope.settings.selectionLimit,$scope.singleSelection&&angular.isArray($scope.selectedModel)&&0===$scope.selectedModel.length&&clearObject($scope.selectedModel),$scope.settings.closeOnBlur&&$document.on("click",function(e){if($scope.open){for(var target=e.target.parentElement,parentFound=!1;angular.isDefined(target)&&null!==target&&!parentFound;)target.className.split&&contains(target.className.split(" "),"multiselect-parent")&&!parentFound&&target===$dropdownTrigger&&(parentFound=!0),target=target.parentElement;parentFound||$scope.$apply(function(){$scope.close()})}}),$scope.getGroupLabel=function(groupValue){return null!==$scope.settings.groupByTextProvider?$scope.settings.groupByTextProvider(groupValue):groupValue},$scope.getButtonText=function(){if($scope.settings.dynamicTitle&&$scope.selectedModel&&($scope.selectedModel.length>0||angular.isObject($scope.selectedModel)&&Object.keys($scope.selectedModel).length>0)){if($scope.settings.smartButtonMaxItems>0){var paddingWidth=24,borderWidth=2,dropdownIconWidth=8,widthLimit=(textWidth("..."),$element[0].offsetWidth-paddingWidth-borderWidth-dropdownIconWidth),itemsText=[];angular.forEach($scope.options,function(optionItem){if($scope.isChecked($scope.getPropertyForObject(optionItem,$scope.settings.idProp))){var displayText=$scope.getPropertyForObject(optionItem,$scope.settings.displayProp),converterResponse=$scope.settings.smartButtonTextConverter(displayText,optionItem);itemsText.push(converterResponse?converterResponse:displayText)}}),$scope.selectedModel.length>$scope.settings.smartButtonMaxItems&&(itemsText=itemsText.slice(0,$scope.settings.smartButtonMaxItems),itemsText.push("..."));var result=itemsText.join(", "),index=result.length-4;if(0===$element[0].offsetWidth)return result;for(;textWidth(result)>widthLimit;)"..."!==itemsText[itemsText.length-1]&&(itemsText.push("..."),result+="..."),result=result.slice(0,index)+result.slice(index+1),index--;return result}var totalSelected;return totalSelected=$scope.singleSelection?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.idProp])?1:0:angular.isDefined($scope.selectedModel)?$scope.selectedModel.length:0,0===totalSelected?$scope.texts.buttonDefaultText:$scope.settings.showAllSelectedText&&totalSelected===$scope.options.length?$scope.texts.allSelectedText:totalSelected+" "+$scope.texts.dynamicButtonTextSuffix}return $scope.texts.buttonDefaultText},$scope.getPropertyForObject=function(object,property){return angular.isDefined(object)&&object.hasOwnProperty(property)?object[property]:void 0},$scope.selectAll=function(){var searchResult;$scope.deselectAll(!0),$scope.externalEvents.onSelectAll(),searchResult=$filter("filter")($scope.options,$scope.getFilter($scope.input.searchFilter)),angular.forEach(searchResult,function(value){$scope.setSelectedItem(value[$scope.settings.idProp],!0,!1)}),$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.deselectAll=function(dontSendEvent){dontSendEvent=dontSendEvent||!1,dontSendEvent||$scope.externalEvents.onDeselectAll(),$scope.singleSelection?clearObject($scope.selectedModel):$scope.selectedModel.splice(0,$scope.selectedModel.length),dontSendEvent||$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.setSelectedItem=function(id,dontRemove,fireSelectionChange){var findObj=getFindObj(id),finalObj=null;if(finalObj=""===$scope.settings.externalIdProp?find($scope.options,findObj):findObj,$scope.singleSelection)clearObject($scope.selectedModel),angular.extend($scope.selectedModel,finalObj),fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),($scope.settings.closeOnSelect||$scope.settings.closeOnDeselect)&&$scope.close();else{dontRemove=dontRemove||!1;var exists=-1!==findIndex($scope.selectedModel,findObj);!dontRemove&&exists?($scope.selectedModel.splice(findIndex($scope.selectedModel,findObj),1),$scope.externalEvents.onItemDeselect(findObj),$scope.settings.closeOnDeselect&&$scope.close()):!exists&&(0===$scope.settings.selectionLimit||$scope.selectedModel.length<$scope.settings.selectionLimit)&&($scope.selectedModel.push(finalObj),fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),$scope.settings.closeOnSelect&&$scope.close(),$scope.settings.selectionLimit>0&&$scope.selectedModel.length===$scope.settings.selectionLimit&&$scope.externalEvents.onMaxSelectionReached())}fireSelectionChange&&$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.isChecked=function(id){return $scope.singleSelection?""===$scope.settings.externalIdProp?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.idProp])&&$scope.selectedModel[$scope.settings.idProp]===getFindObj(id)[$scope.settings.idProp]:null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.externalIdProp])&&$scope.selectedModel[$scope.settings.externalIdProp]===getFindObj(id)[$scope.settings.externalIdProp]:-1!==findIndex($scope.selectedModel,getFindObj(id))},$scope.externalEvents.onInitDone(),$scope.keyDownLink=function(event){var nextOption,sourceScope=angular.element(event.target).scope(),parent=event.target.parentNode;if($scope.settings.keyboardControls)if(13===event.keyCode||32===event.keyCode)event.preventDefault(),sourceScope.option?$scope.setSelectedItem($scope.getPropertyForObject(sourceScope.option,$scope.settings.idProp),!1,!0):"deselectAll"===event.target.id?$scope.deselectAll():"selectAll"===event.target.id&&$scope.selectAll();else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else if(40===event.keyCode){for(event.preventDefault(),parent.nextElementSibling&&(nextOption=parent.nextElementSibling.querySelector("a")||parent.nextElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.nextElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearchDefault=function(event){var nextOption,parent=event.target.parentNode.parentNode;if($scope.settings.keyboardControls)if(9===event.keyCode||40===event.keyCode)event.preventDefault(),focusFirstOption();else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearch=function(event,searchFilter){var searchResult;$scope.settings.keyboardControls&&13===event.keyCode&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?(searchResult=$filter("filter")($scope.options,$scope.getFilter(searchFilter)),1===searchResult.length&&$scope.setSelectedItem($scope.getPropertyForObject(searchResult[0],$scope.settings.idProp),!1,!0)):$scope.settings.enableSearch&&$scope.selectAll())},$scope.getFilter=function(searchFilter){var filter={};return filter[$scope.settings.searchField]=searchFilter,filter},$scope.toggleSearch=function($event){$event&&$event.stopPropagation(),$scope.settings.enableSearch=!$scope.settings.enableSearch,$scope.settings.enableSearch||($scope.input.searchFilter="")},$scope.keyDownToggleSearch=function(){$scope.settings.keyboardControls&&13===event.keyCode&&($scope.toggleSearch(),$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):focusFirstOption())}}}}])}(angular); \ No newline at end of file diff --git a/package.json b/package.json index a657fe98..6695c0be 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "author": "pkempenaers@myforce.be", "name": "angularjs-dropdown-multiselect", - "version": "1.11.6", + "version": "1.11.7", "description": "This directive gives you a Bootstrap Dropdown with the power of AngularJS directives.", "homepage": "http://dotansimha.github.io/angularjs-dropdown-multiselect/#/", "dependencies": { From 98abfaecfa8d3b23f39daf9db7f4295d04fec1fe Mon Sep 17 00:00:00 2001 From: pkempenaers Date: Tue, 28 Mar 2017 08:31:10 +0200 Subject: [PATCH 10/11] Release 1.11.8 --- bower.json | 2 +- dist/angularjs-dropdown-multiselect.min.js | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bower.json b/bower.json index 90c2304b..c16629e9 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angularjs-dropdown-multiselect", - "version": "1.11.7", + "version": "1.11.8", "authors": [ "Dotan Simha ", "Pieter Kempenaers " diff --git a/dist/angularjs-dropdown-multiselect.min.js b/dist/angularjs-dropdown-multiselect.min.js index cc64aae7..68ef0f3e 100644 --- a/dist/angularjs-dropdown-multiselect.min.js +++ b/dist/angularjs-dropdown-multiselect.min.js @@ -1 +1 @@ -!function(angular){"use strict";function contains(collection,target){var containsTarget=!1;return collection.some(function(object){return object===target?(containsTarget=!0,!0):void 0}),containsTarget}function find(collection,properties){var target;return collection.some(function(object){var hasAllSameProperties=!0;return Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(target=object,!0):void 0}),target}function findIndex(collection,properties){var index=-1,counter=-1;return collection.some(function(object){var hasAllSameProperties=!0;return counter+=1,Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(index=counter,!0):void 0}),index}var directiveModule=angular.module("angularjs-dropdown-multiselect",[]);directiveModule.directive("dmDropdownStaticInclude",["$compile",function($compile){return function(scope,element,attrs){var template=attrs.dmDropdownStaticInclude,contents=element.html(template).contents();$compile(contents)(scope)}}]),directiveModule.directive("ngDropdownMultiselect",["$filter","$document","$compile","$parse",function($filter,$document,$compile,$parse){return{restrict:"AE",scope:{selectedModel:"=",options:"=",extraSettings:"=",events:"=",searchFilter:"=?",translationTexts:"=",groupBy:"@",disabled:"="},template:function(element,attrs){var checkboxes=attrs.checkboxes?!0:!1,groups=attrs.groupBy?!0:!1,template='"},link:function($scope,$element,$attrs){function getFindObj(id){var findObj={};return""===$scope.settings.externalIdProp?findObj[$scope.settings.idProp]=id:findObj[$scope.settings.externalIdProp]=id,findObj}function clearObject(object){for(var prop in object)delete object[prop]}function textWidth(text){var $btn=$element.find("button"),canvas=document.createElement("canvas"),ctx=canvas.getContext("2d");return ctx.font=$btn.css("font-size")+$btn.css("font-family"),ctx.originalFont=$btn.css("font-size")+$btn.css("font-family"),ctx.fillStyle="#000000",ctx.measureText(text).width}function focusFirstOption(){setTimeout(function(){var elementToFocus=angular.element($element)[0].querySelector(".option");angular.isDefined(elementToFocus)&&null!=elementToFocus&&elementToFocus.focus()},0)}var $dropdownTrigger=$element.children()[0];$scope.toggleDropdown=function(){$scope.open?$scope.close():$scope.open=!0,$scope.settings.keyboardControls&&$scope.open&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):focusFirstOption()),$scope.settings.enableSearch&&$scope.open&&setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0)},$scope.checkboxClick=function($event,id){$scope.setSelectedItem(id,!1,!0),$event.stopImmediatePropagation()},$scope.externalEvents={onItemSelect:angular.noop,onItemDeselect:angular.noop,onSelectAll:angular.noop,onDeselectAll:angular.noop,onInitDone:angular.noop,onMaxSelectionReached:angular.noop,onSelectionChanged:angular.noop,onClose:angular.noop},$scope.settings={dynamicTitle:!0,scrollable:!1,scrollableHeight:"300px",closeOnBlur:!0,displayProp:"label",idProp:"id",externalIdProp:"id",enableSearch:!1,selectionLimit:0,showCheckAll:!0,showUncheckAll:!0,showEnableSearchButton:!1,closeOnSelect:!1,buttonClasses:"btn btn-default",closeOnDeselect:!1,groupBy:$attrs.groupBy||void 0,groupByTextProvider:null,smartButtonMaxItems:0,smartButtonTextConverter:angular.noop,styleActive:!1,keyboardControls:!1,template:"{{getPropertyForObject(option, settings.displayProp)}}",searchField:"$",showAllSelectedText:!1},$scope.texts={checkAll:"Check All",uncheckAll:"Uncheck All",selectionCount:"checked",selectionOf:"/",searchPlaceholder:"Search...",buttonDefaultText:"Select",dynamicButtonTextSuffix:"checked",disableSearch:"Disable search",enableSearch:"Enable search",selectGroup:"Select all:",allSelectedText:"All"},$scope.input={searchFilter:$scope.searchFilter||""},angular.isDefined($scope.settings.groupBy)&&$scope.$watch("options",function(newValue){angular.isDefined(newValue)&&($scope.orderedItems=$filter("orderBy")(newValue,$scope.settings.groupBy))}),$scope.$watch("selectedModel",function(newValue){Array.isArray(newValue)?$scope.singleSelection=!1:$scope.singleSelection=!0}),$scope.close=function(){$scope.open=!1,$scope.externalEvents.onClose()},$scope.selectCurrentGroup=function(currentGroup){$scope.selectedModel.splice(0,$scope.selectedModel.length),$scope.orderedItems&&$scope.orderedItems.forEach(function(item){item[$scope.groupBy]===currentGroup&&$scope.setSelectedItem($scope.getPropertyForObject(item,$scope.settings.idProp),!1,!1)}),$scope.externalEvents.onSelectionChanged()},angular.extend($scope.settings,$scope.extraSettings||[]),angular.extend($scope.externalEvents,$scope.events||[]),angular.extend($scope.texts,$scope.translationTexts),$scope.singleSelection=1===$scope.settings.selectionLimit,$scope.singleSelection&&angular.isArray($scope.selectedModel)&&0===$scope.selectedModel.length&&clearObject($scope.selectedModel),$scope.settings.closeOnBlur&&$document.on("click",function(e){if($scope.open){for(var target=e.target.parentElement,parentFound=!1;angular.isDefined(target)&&null!==target&&!parentFound;)target.className.split&&contains(target.className.split(" "),"multiselect-parent")&&!parentFound&&target===$dropdownTrigger&&(parentFound=!0),target=target.parentElement;parentFound||$scope.$apply(function(){$scope.close()})}}),$scope.getGroupLabel=function(groupValue){return null!==$scope.settings.groupByTextProvider?$scope.settings.groupByTextProvider(groupValue):groupValue},$scope.getButtonText=function(){if($scope.settings.dynamicTitle&&$scope.selectedModel&&($scope.selectedModel.length>0||angular.isObject($scope.selectedModel)&&Object.keys($scope.selectedModel).length>0)){if($scope.settings.smartButtonMaxItems>0){var paddingWidth=24,borderWidth=2,dropdownIconWidth=8,widthLimit=(textWidth("..."),$element[0].offsetWidth-paddingWidth-borderWidth-dropdownIconWidth),itemsText=[];angular.forEach($scope.options,function(optionItem){if($scope.isChecked($scope.getPropertyForObject(optionItem,$scope.settings.idProp))){var displayText=$scope.getPropertyForObject(optionItem,$scope.settings.displayProp),converterResponse=$scope.settings.smartButtonTextConverter(displayText,optionItem);itemsText.push(converterResponse?converterResponse:displayText)}}),$scope.selectedModel.length>$scope.settings.smartButtonMaxItems&&(itemsText=itemsText.slice(0,$scope.settings.smartButtonMaxItems),itemsText.push("..."));var result=itemsText.join(", "),index=result.length-4;if(0===$element[0].offsetWidth)return result;for(;textWidth(result)>widthLimit;)"..."!==itemsText[itemsText.length-1]&&(itemsText.push("..."),result+="..."),result=result.slice(0,index)+result.slice(index+1),index--;return result}var totalSelected;return totalSelected=$scope.singleSelection?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.idProp])?1:0:angular.isDefined($scope.selectedModel)?$scope.selectedModel.length:0,0===totalSelected?$scope.texts.buttonDefaultText:$scope.settings.showAllSelectedText&&totalSelected===$scope.options.length?$scope.texts.allSelectedText:totalSelected+" "+$scope.texts.dynamicButtonTextSuffix}return $scope.texts.buttonDefaultText},$scope.getPropertyForObject=function(object,property){return angular.isDefined(object)&&object.hasOwnProperty(property)?object[property]:void 0},$scope.selectAll=function(){var searchResult;$scope.deselectAll(!0),$scope.externalEvents.onSelectAll(),searchResult=$filter("filter")($scope.options,$scope.getFilter($scope.input.searchFilter)),angular.forEach(searchResult,function(value){$scope.setSelectedItem(value[$scope.settings.idProp],!0,!1)}),$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.deselectAll=function(dontSendEvent){dontSendEvent=dontSendEvent||!1,dontSendEvent||$scope.externalEvents.onDeselectAll(),$scope.singleSelection?clearObject($scope.selectedModel):$scope.selectedModel.splice(0,$scope.selectedModel.length),dontSendEvent||$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.setSelectedItem=function(id,dontRemove,fireSelectionChange){var findObj=getFindObj(id),finalObj=null;if(finalObj=""===$scope.settings.externalIdProp?find($scope.options,findObj):findObj,$scope.singleSelection)clearObject($scope.selectedModel),angular.extend($scope.selectedModel,finalObj),fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),($scope.settings.closeOnSelect||$scope.settings.closeOnDeselect)&&$scope.close();else{dontRemove=dontRemove||!1;var exists=-1!==findIndex($scope.selectedModel,findObj);!dontRemove&&exists?($scope.selectedModel.splice(findIndex($scope.selectedModel,findObj),1),$scope.externalEvents.onItemDeselect(findObj),$scope.settings.closeOnDeselect&&$scope.close()):!exists&&(0===$scope.settings.selectionLimit||$scope.selectedModel.length<$scope.settings.selectionLimit)&&($scope.selectedModel.push(finalObj),fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),$scope.settings.closeOnSelect&&$scope.close(),$scope.settings.selectionLimit>0&&$scope.selectedModel.length===$scope.settings.selectionLimit&&$scope.externalEvents.onMaxSelectionReached())}fireSelectionChange&&$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.isChecked=function(id){return $scope.singleSelection?""===$scope.settings.externalIdProp?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.idProp])&&$scope.selectedModel[$scope.settings.idProp]===getFindObj(id)[$scope.settings.idProp]:null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.externalIdProp])&&$scope.selectedModel[$scope.settings.externalIdProp]===getFindObj(id)[$scope.settings.externalIdProp]:-1!==findIndex($scope.selectedModel,getFindObj(id))},$scope.externalEvents.onInitDone(),$scope.keyDownLink=function(event){var nextOption,sourceScope=angular.element(event.target).scope(),parent=event.target.parentNode;if($scope.settings.keyboardControls)if(13===event.keyCode||32===event.keyCode)event.preventDefault(),sourceScope.option?$scope.setSelectedItem($scope.getPropertyForObject(sourceScope.option,$scope.settings.idProp),!1,!0):"deselectAll"===event.target.id?$scope.deselectAll():"selectAll"===event.target.id&&$scope.selectAll();else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else if(40===event.keyCode){for(event.preventDefault(),parent.nextElementSibling&&(nextOption=parent.nextElementSibling.querySelector("a")||parent.nextElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.nextElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearchDefault=function(event){var nextOption,parent=event.target.parentNode.parentNode;if($scope.settings.keyboardControls)if(9===event.keyCode||40===event.keyCode)event.preventDefault(),focusFirstOption();else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearch=function(event,searchFilter){var searchResult;$scope.settings.keyboardControls&&13===event.keyCode&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?(searchResult=$filter("filter")($scope.options,$scope.getFilter(searchFilter)),1===searchResult.length&&$scope.setSelectedItem($scope.getPropertyForObject(searchResult[0],$scope.settings.idProp),!1,!0)):$scope.settings.enableSearch&&$scope.selectAll())},$scope.getFilter=function(searchFilter){var filter={};return filter[$scope.settings.searchField]=searchFilter,filter},$scope.toggleSearch=function($event){$event&&$event.stopPropagation(),$scope.settings.enableSearch=!$scope.settings.enableSearch,$scope.settings.enableSearch||($scope.input.searchFilter="")},$scope.keyDownToggleSearch=function(){$scope.settings.keyboardControls&&13===event.keyCode&&($scope.toggleSearch(),$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):focusFirstOption())}}}}])}(angular); \ No newline at end of file +!function(angular){"use strict";function contains(collection,target){var containsTarget=!1;return collection.some(function(object){return object===target?(containsTarget=!0,!0):void 0}),containsTarget}function find(collection,properties){var target;return collection.some(function(object){var hasAllSameProperties=!0;return Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(target=object,!0):void 0}),target}function findIndex(collection,properties){var index=-1,counter=-1;return collection.some(function(object){var hasAllSameProperties=!0;return counter+=1,Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(index=counter,!0):void 0}),index}var directiveModule=angular.module("angularjs-dropdown-multiselect",[]);directiveModule.directive("dmDropdownStaticInclude",["$compile",function($compile){return function(scope,element,attrs){var template=attrs.dmDropdownStaticInclude,contents=element.html(template).contents();$compile(contents)(scope)}}]),directiveModule.directive("ngDropdownMultiselect",["$filter","$document","$compile","$parse",function($filter,$document,$compile,$parse){return{restrict:"AE",scope:{selectedModel:"=",options:"=",extraSettings:"=",events:"=",searchFilter:"=?",translationTexts:"=",groupBy:"@",disabled:"="},template:function(element,attrs){var checkboxes=attrs.checkboxes?!0:!1,groups=attrs.groupBy?!0:!1,template='"},link:function($scope,$element,$attrs){function getFindObj(id){var findObj={};return""===$scope.settings.externalIdProp?findObj[$scope.settings.idProp]=id:findObj[$scope.settings.externalIdProp]=id,findObj}function clearObject(object){for(var prop in object)delete object[prop]}function textWidth(text){var $btn=$element.find("button"),canvas=document.createElement("canvas"),ctx=canvas.getContext("2d");return ctx.font=$btn.css("font-size")+$btn.css("font-family"),ctx.originalFont=$btn.css("font-size")+$btn.css("font-family"),ctx.fillStyle="#000000",ctx.measureText(text).width}function focusFirstOption(){setTimeout(function(){var elementToFocus=angular.element($element)[0].querySelector(".option");angular.isDefined(elementToFocus)&&null!=elementToFocus&&elementToFocus.focus()},0)}var $dropdownTrigger=$element.children()[0];$scope.toggleDropdown=function(){$scope.open?$scope.close():$scope.open=!0,$scope.settings.keyboardControls&&$scope.open&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):focusFirstOption()),$scope.settings.enableSearch&&$scope.open&&setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0)},$scope.checkboxClick=function($event,id){$scope.setSelectedItem(id,!1,!0),$event.stopImmediatePropagation()},$scope.externalEvents={onItemSelect:angular.noop,onItemDeselect:angular.noop,onSelectAll:angular.noop,onDeselectAll:angular.noop,onInitDone:angular.noop,onMaxSelectionReached:angular.noop,onSelectionChanged:angular.noop,onClose:angular.noop},$scope.settings={dynamicTitle:!0,scrollable:!1,scrollableHeight:"300px",closeOnBlur:!0,displayProp:"label",idProp:"id",externalIdProp:"id",enableSearch:!1,selectionLimit:0,showCheckAll:!0,showUncheckAll:!0,showEnableSearchButton:!1,closeOnSelect:!1,buttonClasses:"btn btn-default",closeOnDeselect:!1,groupBy:$attrs.groupBy||void 0,groupByTextProvider:null,smartButtonMaxItems:0,smartButtonTextConverter:angular.noop,styleActive:!1,keyboardControls:!1,template:"{{getPropertyForObject(option, settings.displayProp)}}",searchField:"$",showAllSelectedText:!1},$scope.texts={checkAll:"Check All",uncheckAll:"Uncheck All",selectionCount:"checked",selectionOf:"/",searchPlaceholder:"Search...",buttonDefaultText:"Select",dynamicButtonTextSuffix:"checked",disableSearch:"Disable search",enableSearch:"Enable search",selectGroup:"Select all:",allSelectedText:"All"},$scope.input={searchFilter:$scope.searchFilter||""},angular.isDefined($scope.settings.groupBy)&&$scope.$watch("options",function(newValue){angular.isDefined(newValue)&&($scope.orderedItems=$filter("orderBy")(newValue,$scope.settings.groupBy))}),$scope.$watch("selectedModel",function(newValue){Array.isArray(newValue)?$scope.singleSelection=!1:$scope.singleSelection=!0}),$scope.close=function(){$scope.open=!1,$scope.externalEvents.onClose()},$scope.selectCurrentGroup=function(currentGroup){$scope.selectedModel.splice(0,$scope.selectedModel.length),$scope.orderedItems&&$scope.orderedItems.forEach(function(item){item[$scope.groupBy]===currentGroup&&$scope.setSelectedItem($scope.getPropertyForObject(item,$scope.settings.idProp),!1,!1)}),$scope.externalEvents.onSelectionChanged()},angular.extend($scope.settings,$scope.extraSettings||[]),angular.extend($scope.externalEvents,$scope.events||[]),angular.extend($scope.texts,$scope.translationTexts),$scope.singleSelection=1===$scope.settings.selectionLimit,$scope.singleSelection&&angular.isArray($scope.selectedModel)&&0===$scope.selectedModel.length&&clearObject($scope.selectedModel),$scope.settings.closeOnBlur&&$document.on("click",function(e){if($scope.open){for(var target=e.target.parentElement,parentFound=!1;angular.isDefined(target)&&null!==target&&!parentFound;)target.className.split&&contains(target.className.split(" "),"multiselect-parent")&&!parentFound&&target===$dropdownTrigger&&(parentFound=!0),target=target.parentElement;parentFound||$scope.$apply(function(){$scope.close()})}}),$scope.getGroupLabel=function(groupValue){return null!==$scope.settings.groupByTextProvider?$scope.settings.groupByTextProvider(groupValue):groupValue},$scope.getButtonText=function(){if($scope.settings.dynamicTitle&&$scope.selectedModel&&($scope.selectedModel.length>0||angular.isObject($scope.selectedModel)&&Object.keys($scope.selectedModel).length>0)){if($scope.settings.smartButtonMaxItems>0){var paddingWidth=24,borderWidth=2,dropdownIconWidth=8,widthLimit=$element[0].offsetWidth-paddingWidth-borderWidth-dropdownIconWidth,itemsText=[];angular.forEach($scope.options,function(optionItem){if($scope.isChecked($scope.getPropertyForObject(optionItem,$scope.settings.idProp))){var displayText=$scope.getPropertyForObject(optionItem,$scope.settings.displayProp),converterResponse=$scope.settings.smartButtonTextConverter(displayText,optionItem);itemsText.push(converterResponse?converterResponse:displayText)}}),$scope.selectedModel.length>$scope.settings.smartButtonMaxItems&&(itemsText=itemsText.slice(0,$scope.settings.smartButtonMaxItems),itemsText.push("..."));var result=itemsText.join(", "),index=result.length-4;if(0===$element[0].offsetWidth)return result;for(;textWidth(result)>widthLimit&&index>0;)"..."!==itemsText[itemsText.length-1]&&(itemsText.push("..."),result+="..."),result=result.slice(0,index)+result.slice(index+1),index--;return result}var totalSelected;return totalSelected=$scope.singleSelection?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.idProp])?1:0:angular.isDefined($scope.selectedModel)?$scope.selectedModel.length:0,0===totalSelected?$scope.texts.buttonDefaultText:$scope.settings.showAllSelectedText&&totalSelected===$scope.options.length?$scope.texts.allSelectedText:totalSelected+" "+$scope.texts.dynamicButtonTextSuffix}return $scope.texts.buttonDefaultText},$scope.getPropertyForObject=function(object,property){return angular.isDefined(object)&&object.hasOwnProperty(property)?object[property]:void 0},$scope.selectAll=function(){var searchResult;$scope.deselectAll(!0),$scope.externalEvents.onSelectAll(),searchResult=$filter("filter")($scope.options,$scope.getFilter($scope.input.searchFilter)),angular.forEach(searchResult,function(value){$scope.setSelectedItem(value[$scope.settings.idProp],!0,!1)}),$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.deselectAll=function(dontSendEvent){dontSendEvent=dontSendEvent||!1,dontSendEvent||$scope.externalEvents.onDeselectAll(),$scope.singleSelection?clearObject($scope.selectedModel):$scope.selectedModel.splice(0,$scope.selectedModel.length),dontSendEvent||$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.setSelectedItem=function(id,dontRemove,fireSelectionChange){var findObj=getFindObj(id),finalObj=null;if(finalObj=""===$scope.settings.externalIdProp?find($scope.options,findObj):findObj,$scope.singleSelection)clearObject($scope.selectedModel),angular.extend($scope.selectedModel,finalObj),fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),($scope.settings.closeOnSelect||$scope.settings.closeOnDeselect)&&$scope.close();else{dontRemove=dontRemove||!1;var exists=-1!==findIndex($scope.selectedModel,findObj);!dontRemove&&exists?($scope.selectedModel.splice(findIndex($scope.selectedModel,findObj),1),$scope.externalEvents.onItemDeselect(findObj),$scope.settings.closeOnDeselect&&$scope.close()):!exists&&(0===$scope.settings.selectionLimit||$scope.selectedModel.length<$scope.settings.selectionLimit)&&($scope.selectedModel.push(finalObj),fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),$scope.settings.closeOnSelect&&$scope.close(),$scope.settings.selectionLimit>0&&$scope.selectedModel.length===$scope.settings.selectionLimit&&$scope.externalEvents.onMaxSelectionReached())}fireSelectionChange&&$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.isChecked=function(id){return $scope.singleSelection?""===$scope.settings.externalIdProp?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.idProp])&&$scope.selectedModel[$scope.settings.idProp]===getFindObj(id)[$scope.settings.idProp]:null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.externalIdProp])&&$scope.selectedModel[$scope.settings.externalIdProp]===getFindObj(id)[$scope.settings.externalIdProp]:-1!==findIndex($scope.selectedModel,getFindObj(id))},$scope.externalEvents.onInitDone(),$scope.keyDownLink=function(event){var nextOption,sourceScope=angular.element(event.target).scope(),parent=event.target.parentNode;if($scope.settings.keyboardControls)if(13===event.keyCode||32===event.keyCode)event.preventDefault(),sourceScope.option?$scope.setSelectedItem($scope.getPropertyForObject(sourceScope.option,$scope.settings.idProp),!1,!0):"deselectAll"===event.target.id?$scope.deselectAll():"selectAll"===event.target.id&&$scope.selectAll();else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else if(40===event.keyCode){for(event.preventDefault(),parent.nextElementSibling&&(nextOption=parent.nextElementSibling.querySelector("a")||parent.nextElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.nextElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearchDefault=function(event){var nextOption,parent=event.target.parentNode.parentNode;if($scope.settings.keyboardControls)if(9===event.keyCode||40===event.keyCode)event.preventDefault(),focusFirstOption();else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearch=function(event,searchFilter){var searchResult;$scope.settings.keyboardControls&&13===event.keyCode&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?(searchResult=$filter("filter")($scope.options,$scope.getFilter(searchFilter)),1===searchResult.length&&$scope.setSelectedItem($scope.getPropertyForObject(searchResult[0],$scope.settings.idProp),!1,!0)):$scope.settings.enableSearch&&$scope.selectAll())},$scope.getFilter=function(searchFilter){var filter={};return filter[$scope.settings.searchField]=searchFilter,filter},$scope.toggleSearch=function($event){$event&&$event.stopPropagation(),$scope.settings.enableSearch=!$scope.settings.enableSearch,$scope.settings.enableSearch||($scope.input.searchFilter="")},$scope.keyDownToggleSearch=function(){$scope.settings.keyboardControls&&13===event.keyCode&&($scope.toggleSearch(),$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):focusFirstOption())}}}}])}(angular); \ No newline at end of file diff --git a/package.json b/package.json index 6695c0be..3bd110a1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "author": "pkempenaers@myforce.be", "name": "angularjs-dropdown-multiselect", - "version": "1.11.7", + "version": "1.11.8", "description": "This directive gives you a Bootstrap Dropdown with the power of AngularJS directives.", "homepage": "http://dotansimha.github.io/angularjs-dropdown-multiselect/#/", "dependencies": { From de567b2efbc0da8a92131cfa9e1bb5b28c82382a Mon Sep 17 00:00:00 2001 From: Jason P Date: Fri, 20 Oct 2017 10:25:25 +0800 Subject: [PATCH 11/11] fixed event not triggering --- dist/angularjs-dropdown-multiselect.min.js | 2 +- package-lock.json | 1285 ++++++++++++++++++++ src/angularjs-dropdown-multiselect.js | 10 +- 3 files changed, 1292 insertions(+), 5 deletions(-) create mode 100644 package-lock.json diff --git a/dist/angularjs-dropdown-multiselect.min.js b/dist/angularjs-dropdown-multiselect.min.js index 68ef0f3e..0fdd6f13 100644 --- a/dist/angularjs-dropdown-multiselect.min.js +++ b/dist/angularjs-dropdown-multiselect.min.js @@ -1 +1 @@ -!function(angular){"use strict";function contains(collection,target){var containsTarget=!1;return collection.some(function(object){return object===target?(containsTarget=!0,!0):void 0}),containsTarget}function find(collection,properties){var target;return collection.some(function(object){var hasAllSameProperties=!0;return Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(target=object,!0):void 0}),target}function findIndex(collection,properties){var index=-1,counter=-1;return collection.some(function(object){var hasAllSameProperties=!0;return counter+=1,Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(index=counter,!0):void 0}),index}var directiveModule=angular.module("angularjs-dropdown-multiselect",[]);directiveModule.directive("dmDropdownStaticInclude",["$compile",function($compile){return function(scope,element,attrs){var template=attrs.dmDropdownStaticInclude,contents=element.html(template).contents();$compile(contents)(scope)}}]),directiveModule.directive("ngDropdownMultiselect",["$filter","$document","$compile","$parse",function($filter,$document,$compile,$parse){return{restrict:"AE",scope:{selectedModel:"=",options:"=",extraSettings:"=",events:"=",searchFilter:"=?",translationTexts:"=",groupBy:"@",disabled:"="},template:function(element,attrs){var checkboxes=attrs.checkboxes?!0:!1,groups=attrs.groupBy?!0:!1,template='"},link:function($scope,$element,$attrs){function getFindObj(id){var findObj={};return""===$scope.settings.externalIdProp?findObj[$scope.settings.idProp]=id:findObj[$scope.settings.externalIdProp]=id,findObj}function clearObject(object){for(var prop in object)delete object[prop]}function textWidth(text){var $btn=$element.find("button"),canvas=document.createElement("canvas"),ctx=canvas.getContext("2d");return ctx.font=$btn.css("font-size")+$btn.css("font-family"),ctx.originalFont=$btn.css("font-size")+$btn.css("font-family"),ctx.fillStyle="#000000",ctx.measureText(text).width}function focusFirstOption(){setTimeout(function(){var elementToFocus=angular.element($element)[0].querySelector(".option");angular.isDefined(elementToFocus)&&null!=elementToFocus&&elementToFocus.focus()},0)}var $dropdownTrigger=$element.children()[0];$scope.toggleDropdown=function(){$scope.open?$scope.close():$scope.open=!0,$scope.settings.keyboardControls&&$scope.open&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):focusFirstOption()),$scope.settings.enableSearch&&$scope.open&&setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0)},$scope.checkboxClick=function($event,id){$scope.setSelectedItem(id,!1,!0),$event.stopImmediatePropagation()},$scope.externalEvents={onItemSelect:angular.noop,onItemDeselect:angular.noop,onSelectAll:angular.noop,onDeselectAll:angular.noop,onInitDone:angular.noop,onMaxSelectionReached:angular.noop,onSelectionChanged:angular.noop,onClose:angular.noop},$scope.settings={dynamicTitle:!0,scrollable:!1,scrollableHeight:"300px",closeOnBlur:!0,displayProp:"label",idProp:"id",externalIdProp:"id",enableSearch:!1,selectionLimit:0,showCheckAll:!0,showUncheckAll:!0,showEnableSearchButton:!1,closeOnSelect:!1,buttonClasses:"btn btn-default",closeOnDeselect:!1,groupBy:$attrs.groupBy||void 0,groupByTextProvider:null,smartButtonMaxItems:0,smartButtonTextConverter:angular.noop,styleActive:!1,keyboardControls:!1,template:"{{getPropertyForObject(option, settings.displayProp)}}",searchField:"$",showAllSelectedText:!1},$scope.texts={checkAll:"Check All",uncheckAll:"Uncheck All",selectionCount:"checked",selectionOf:"/",searchPlaceholder:"Search...",buttonDefaultText:"Select",dynamicButtonTextSuffix:"checked",disableSearch:"Disable search",enableSearch:"Enable search",selectGroup:"Select all:",allSelectedText:"All"},$scope.input={searchFilter:$scope.searchFilter||""},angular.isDefined($scope.settings.groupBy)&&$scope.$watch("options",function(newValue){angular.isDefined(newValue)&&($scope.orderedItems=$filter("orderBy")(newValue,$scope.settings.groupBy))}),$scope.$watch("selectedModel",function(newValue){Array.isArray(newValue)?$scope.singleSelection=!1:$scope.singleSelection=!0}),$scope.close=function(){$scope.open=!1,$scope.externalEvents.onClose()},$scope.selectCurrentGroup=function(currentGroup){$scope.selectedModel.splice(0,$scope.selectedModel.length),$scope.orderedItems&&$scope.orderedItems.forEach(function(item){item[$scope.groupBy]===currentGroup&&$scope.setSelectedItem($scope.getPropertyForObject(item,$scope.settings.idProp),!1,!1)}),$scope.externalEvents.onSelectionChanged()},angular.extend($scope.settings,$scope.extraSettings||[]),angular.extend($scope.externalEvents,$scope.events||[]),angular.extend($scope.texts,$scope.translationTexts),$scope.singleSelection=1===$scope.settings.selectionLimit,$scope.singleSelection&&angular.isArray($scope.selectedModel)&&0===$scope.selectedModel.length&&clearObject($scope.selectedModel),$scope.settings.closeOnBlur&&$document.on("click",function(e){if($scope.open){for(var target=e.target.parentElement,parentFound=!1;angular.isDefined(target)&&null!==target&&!parentFound;)target.className.split&&contains(target.className.split(" "),"multiselect-parent")&&!parentFound&&target===$dropdownTrigger&&(parentFound=!0),target=target.parentElement;parentFound||$scope.$apply(function(){$scope.close()})}}),$scope.getGroupLabel=function(groupValue){return null!==$scope.settings.groupByTextProvider?$scope.settings.groupByTextProvider(groupValue):groupValue},$scope.getButtonText=function(){if($scope.settings.dynamicTitle&&$scope.selectedModel&&($scope.selectedModel.length>0||angular.isObject($scope.selectedModel)&&Object.keys($scope.selectedModel).length>0)){if($scope.settings.smartButtonMaxItems>0){var paddingWidth=24,borderWidth=2,dropdownIconWidth=8,widthLimit=$element[0].offsetWidth-paddingWidth-borderWidth-dropdownIconWidth,itemsText=[];angular.forEach($scope.options,function(optionItem){if($scope.isChecked($scope.getPropertyForObject(optionItem,$scope.settings.idProp))){var displayText=$scope.getPropertyForObject(optionItem,$scope.settings.displayProp),converterResponse=$scope.settings.smartButtonTextConverter(displayText,optionItem);itemsText.push(converterResponse?converterResponse:displayText)}}),$scope.selectedModel.length>$scope.settings.smartButtonMaxItems&&(itemsText=itemsText.slice(0,$scope.settings.smartButtonMaxItems),itemsText.push("..."));var result=itemsText.join(", "),index=result.length-4;if(0===$element[0].offsetWidth)return result;for(;textWidth(result)>widthLimit&&index>0;)"..."!==itemsText[itemsText.length-1]&&(itemsText.push("..."),result+="..."),result=result.slice(0,index)+result.slice(index+1),index--;return result}var totalSelected;return totalSelected=$scope.singleSelection?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.idProp])?1:0:angular.isDefined($scope.selectedModel)?$scope.selectedModel.length:0,0===totalSelected?$scope.texts.buttonDefaultText:$scope.settings.showAllSelectedText&&totalSelected===$scope.options.length?$scope.texts.allSelectedText:totalSelected+" "+$scope.texts.dynamicButtonTextSuffix}return $scope.texts.buttonDefaultText},$scope.getPropertyForObject=function(object,property){return angular.isDefined(object)&&object.hasOwnProperty(property)?object[property]:void 0},$scope.selectAll=function(){var searchResult;$scope.deselectAll(!0),$scope.externalEvents.onSelectAll(),searchResult=$filter("filter")($scope.options,$scope.getFilter($scope.input.searchFilter)),angular.forEach(searchResult,function(value){$scope.setSelectedItem(value[$scope.settings.idProp],!0,!1)}),$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.deselectAll=function(dontSendEvent){dontSendEvent=dontSendEvent||!1,dontSendEvent||$scope.externalEvents.onDeselectAll(),$scope.singleSelection?clearObject($scope.selectedModel):$scope.selectedModel.splice(0,$scope.selectedModel.length),dontSendEvent||$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.setSelectedItem=function(id,dontRemove,fireSelectionChange){var findObj=getFindObj(id),finalObj=null;if(finalObj=""===$scope.settings.externalIdProp?find($scope.options,findObj):findObj,$scope.singleSelection)clearObject($scope.selectedModel),angular.extend($scope.selectedModel,finalObj),fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),($scope.settings.closeOnSelect||$scope.settings.closeOnDeselect)&&$scope.close();else{dontRemove=dontRemove||!1;var exists=-1!==findIndex($scope.selectedModel,findObj);!dontRemove&&exists?($scope.selectedModel.splice(findIndex($scope.selectedModel,findObj),1),$scope.externalEvents.onItemDeselect(findObj),$scope.settings.closeOnDeselect&&$scope.close()):!exists&&(0===$scope.settings.selectionLimit||$scope.selectedModel.length<$scope.settings.selectionLimit)&&($scope.selectedModel.push(finalObj),fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),$scope.settings.closeOnSelect&&$scope.close(),$scope.settings.selectionLimit>0&&$scope.selectedModel.length===$scope.settings.selectionLimit&&$scope.externalEvents.onMaxSelectionReached())}fireSelectionChange&&$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.isChecked=function(id){return $scope.singleSelection?""===$scope.settings.externalIdProp?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.idProp])&&$scope.selectedModel[$scope.settings.idProp]===getFindObj(id)[$scope.settings.idProp]:null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.externalIdProp])&&$scope.selectedModel[$scope.settings.externalIdProp]===getFindObj(id)[$scope.settings.externalIdProp]:-1!==findIndex($scope.selectedModel,getFindObj(id))},$scope.externalEvents.onInitDone(),$scope.keyDownLink=function(event){var nextOption,sourceScope=angular.element(event.target).scope(),parent=event.target.parentNode;if($scope.settings.keyboardControls)if(13===event.keyCode||32===event.keyCode)event.preventDefault(),sourceScope.option?$scope.setSelectedItem($scope.getPropertyForObject(sourceScope.option,$scope.settings.idProp),!1,!0):"deselectAll"===event.target.id?$scope.deselectAll():"selectAll"===event.target.id&&$scope.selectAll();else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else if(40===event.keyCode){for(event.preventDefault(),parent.nextElementSibling&&(nextOption=parent.nextElementSibling.querySelector("a")||parent.nextElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.nextElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearchDefault=function(event){var nextOption,parent=event.target.parentNode.parentNode;if($scope.settings.keyboardControls)if(9===event.keyCode||40===event.keyCode)event.preventDefault(),focusFirstOption();else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearch=function(event,searchFilter){var searchResult;$scope.settings.keyboardControls&&13===event.keyCode&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?(searchResult=$filter("filter")($scope.options,$scope.getFilter(searchFilter)),1===searchResult.length&&$scope.setSelectedItem($scope.getPropertyForObject(searchResult[0],$scope.settings.idProp),!1,!0)):$scope.settings.enableSearch&&$scope.selectAll())},$scope.getFilter=function(searchFilter){var filter={};return filter[$scope.settings.searchField]=searchFilter,filter},$scope.toggleSearch=function($event){$event&&$event.stopPropagation(),$scope.settings.enableSearch=!$scope.settings.enableSearch,$scope.settings.enableSearch||($scope.input.searchFilter="")},$scope.keyDownToggleSearch=function(){$scope.settings.keyboardControls&&13===event.keyCode&&($scope.toggleSearch(),$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):focusFirstOption())}}}}])}(angular); \ No newline at end of file +!function(angular){"use strict";function contains(collection,target){var containsTarget=!1;return collection.some(function(object){return object===target?(containsTarget=!0,!0):void 0}),containsTarget}function find(collection,properties){var target;return collection.some(function(object){var hasAllSameProperties=!0;return Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(target=object,!0):void 0}),target}function findIndex(collection,properties){var index=-1,counter=-1;return collection.some(function(object){var hasAllSameProperties=!0;return counter+=1,Object.keys(properties).forEach(function(key){object[key]!==properties[key]&&(hasAllSameProperties=!1)}),hasAllSameProperties?(index=counter,!0):void 0}),index}var directiveModule=angular.module("angularjs-dropdown-multiselect",[]);directiveModule.directive("dmDropdownStaticInclude",["$compile",function($compile){return function(scope,element,attrs){var template=attrs.dmDropdownStaticInclude,contents=element.html(template).contents();$compile(contents)(scope)}}]),directiveModule.directive("ngDropdownMultiselect",["$filter","$document","$timeout",function($filter,$document,$timeout){return{restrict:"AE",scope:{selectedModel:"=",options:"=",extraSettings:"=",events:"=",searchFilter:"=?",translationTexts:"=",groupBy:"@",disabled:"="},template:function(element,attrs){var checkboxes=attrs.checkboxes?!0:!1,groups=attrs.groupBy?!0:!1,template='"},link:function($scope,$element,$attrs){function getFindObj(id){var findObj={};return""===$scope.settings.externalIdProp?findObj[$scope.settings.idProp]=id:findObj[$scope.settings.externalIdProp]=id,findObj}function clearObject(object){for(var prop in object)delete object[prop]}function textWidth(text){var $btn=$element.find("button"),canvas=document.createElement("canvas"),ctx=canvas.getContext("2d");return ctx.font=$btn.css("font-size")+$btn.css("font-family"),ctx.originalFont=$btn.css("font-size")+$btn.css("font-family"),ctx.fillStyle="#000000",ctx.measureText(text).width}function focusFirstOption(){setTimeout(function(){var elementToFocus=angular.element($element)[0].querySelector(".option");angular.isDefined(elementToFocus)&&null!=elementToFocus&&elementToFocus.focus()},0)}var $dropdownTrigger=$element.children()[0];$scope.toggleDropdown=function(){$scope.open?$scope.close():$scope.open=!0,$scope.settings.keyboardControls&&$scope.open&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):focusFirstOption()),$scope.settings.enableSearch&&$scope.open&&setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0)},$scope.checkboxClick=function($event,id){$scope.setSelectedItem(id,!1,!0),$event.stopImmediatePropagation()},$scope.externalEvents={onItemSelect:angular.noop,onItemDeselect:angular.noop,onSelectAll:angular.noop,onDeselectAll:angular.noop,onInitDone:angular.noop,onMaxSelectionReached:angular.noop,onSelectionChanged:angular.noop,onClose:angular.noop},$scope.settings={dynamicTitle:!0,scrollable:!1,scrollableHeight:"300px",closeOnBlur:!0,displayProp:"label",idProp:"id",externalIdProp:"id",enableSearch:!1,selectionLimit:0,showCheckAll:!0,showUncheckAll:!0,showEnableSearchButton:!1,closeOnSelect:!1,buttonClasses:"btn btn-default",closeOnDeselect:!1,groupBy:$attrs.groupBy||void 0,groupByTextProvider:null,smartButtonMaxItems:0,smartButtonTextConverter:angular.noop,styleActive:!1,keyboardControls:!1,template:"{{getPropertyForObject(option, settings.displayProp)}}",searchField:"$",showAllSelectedText:!1},$scope.texts={checkAll:"Check All",uncheckAll:"Uncheck All",selectionCount:"checked",selectionOf:"/",searchPlaceholder:"Search...",buttonDefaultText:"Select",dynamicButtonTextSuffix:"checked",disableSearch:"Disable search",enableSearch:"Enable search",selectGroup:"Select all:",allSelectedText:"All"},$scope.input={searchFilter:$scope.searchFilter||""},angular.isDefined($scope.settings.groupBy)&&$scope.$watch("options",function(newValue){angular.isDefined(newValue)&&($scope.orderedItems=$filter("orderBy")(newValue,$scope.settings.groupBy))}),$scope.$watch("selectedModel",function(newValue){Array.isArray(newValue)?$scope.singleSelection=!1:$scope.singleSelection=!0}),$scope.close=function(){$scope.open=!1,$scope.externalEvents.onClose()},$scope.selectCurrentGroup=function(currentGroup){$scope.selectedModel.splice(0,$scope.selectedModel.length),$scope.orderedItems&&$scope.orderedItems.forEach(function(item){item[$scope.groupBy]===currentGroup&&$scope.setSelectedItem($scope.getPropertyForObject(item,$scope.settings.idProp),!1,!1)}),$scope.externalEvents.onSelectionChanged()},$timeout(function(){angular.extend($scope.settings,$scope.extraSettings||[]),angular.extend($scope.externalEvents,$scope.events||[]),angular.extend($scope.texts,$scope.translationTexts)}),$scope.singleSelection=1===$scope.settings.selectionLimit,$scope.singleSelection&&angular.isArray($scope.selectedModel)&&0===$scope.selectedModel.length&&clearObject($scope.selectedModel),$scope.settings.closeOnBlur&&$document.on("click",function(e){if($scope.open){for(var target=e.target.parentElement,parentFound=!1;angular.isDefined(target)&&null!==target&&!parentFound;)target.className.split&&contains(target.className.split(" "),"multiselect-parent")&&!parentFound&&target===$dropdownTrigger&&(parentFound=!0),target=target.parentElement;parentFound||$scope.$apply(function(){$scope.close()})}}),$scope.getGroupLabel=function(groupValue){return null!==$scope.settings.groupByTextProvider?$scope.settings.groupByTextProvider(groupValue):groupValue},$scope.getButtonText=function(){if($scope.settings.dynamicTitle&&$scope.selectedModel&&($scope.selectedModel.length>0||angular.isObject($scope.selectedModel)&&Object.keys($scope.selectedModel).length>0)){if($scope.settings.smartButtonMaxItems>0){var paddingWidth=24,borderWidth=2,dropdownIconWidth=8,widthLimit=$element[0].offsetWidth-paddingWidth-borderWidth-dropdownIconWidth,itemsText=[];angular.forEach($scope.options,function(optionItem){if($scope.isChecked($scope.getPropertyForObject(optionItem,$scope.settings.idProp))){var displayText=$scope.getPropertyForObject(optionItem,$scope.settings.displayProp),converterResponse=$scope.settings.smartButtonTextConverter(displayText,optionItem);itemsText.push(converterResponse?converterResponse:displayText)}}),$scope.selectedModel.length>$scope.settings.smartButtonMaxItems&&(itemsText=itemsText.slice(0,$scope.settings.smartButtonMaxItems),itemsText.push("..."));var result=itemsText.join(", "),index=result.length-4;if(0===$element[0].offsetWidth)return result;for(;textWidth(result)>widthLimit&&index>0;)"..."!==itemsText[itemsText.length-1]&&(itemsText.push("..."),result+="..."),result=result.slice(0,index)+result.slice(index+1),index--;return result}var totalSelected;return totalSelected=$scope.singleSelection?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.idProp])?1:0:angular.isDefined($scope.selectedModel)?$scope.selectedModel.length:0,0===totalSelected?$scope.texts.buttonDefaultText:$scope.settings.showAllSelectedText&&totalSelected===$scope.options.length?$scope.texts.allSelectedText:totalSelected+" "+$scope.texts.dynamicButtonTextSuffix}return $scope.texts.buttonDefaultText},$scope.getPropertyForObject=function(object,property){return angular.isDefined(object)&&object.hasOwnProperty(property)?object[property]:void 0},$scope.selectAll=function(){var searchResult;$scope.deselectAll(!0),$scope.externalEvents.onSelectAll(),searchResult=$filter("filter")($scope.options,$scope.getFilter($scope.input.searchFilter)),angular.forEach(searchResult,function(value){$scope.setSelectedItem(value[$scope.settings.idProp],!0,!1)}),$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.deselectAll=function(dontSendEvent){dontSendEvent=dontSendEvent||!1,dontSendEvent||$scope.externalEvents.onDeselectAll(),$scope.singleSelection?clearObject($scope.selectedModel):$scope.selectedModel.splice(0,$scope.selectedModel.length),dontSendEvent||$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.setSelectedItem=function(id,dontRemove,fireSelectionChange){var findObj=getFindObj(id),finalObj=null;if(finalObj=""===$scope.settings.externalIdProp?find($scope.options,findObj):findObj,$scope.singleSelection)clearObject($scope.selectedModel),angular.extend($scope.selectedModel,finalObj),fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),($scope.settings.closeOnSelect||$scope.settings.closeOnDeselect)&&$scope.close();else{dontRemove=dontRemove||!1;var exists=-1!==findIndex($scope.selectedModel,findObj);!dontRemove&&exists?($scope.selectedModel.splice(findIndex($scope.selectedModel,findObj),1),$scope.externalEvents.onItemDeselect(findObj),$scope.settings.closeOnDeselect&&$scope.close()):!exists&&(0===$scope.settings.selectionLimit||$scope.selectedModel.length<$scope.settings.selectionLimit)&&($scope.selectedModel.push(finalObj),fireSelectionChange&&$scope.externalEvents.onItemSelect(finalObj),$scope.settings.closeOnSelect&&$scope.close(),$scope.settings.selectionLimit>0&&$scope.selectedModel.length===$scope.settings.selectionLimit&&$scope.externalEvents.onMaxSelectionReached())}fireSelectionChange&&$scope.externalEvents.onSelectionChanged(),$scope.selectedGroup=null},$scope.isChecked=function(id){return $scope.singleSelection?""===$scope.settings.externalIdProp?null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.idProp])&&$scope.selectedModel[$scope.settings.idProp]===getFindObj(id)[$scope.settings.idProp]:null!==$scope.selectedModel&&angular.isDefined($scope.selectedModel[$scope.settings.externalIdProp])&&$scope.selectedModel[$scope.settings.externalIdProp]===getFindObj(id)[$scope.settings.externalIdProp]:-1!==findIndex($scope.selectedModel,getFindObj(id))},$scope.externalEvents.onInitDone(),$scope.keyDownLink=function(event){var nextOption,sourceScope=angular.element(event.target).scope(),parent=event.target.parentNode;if($scope.settings.keyboardControls)if(13===event.keyCode||32===event.keyCode)event.preventDefault(),sourceScope.option?$scope.setSelectedItem($scope.getPropertyForObject(sourceScope.option,$scope.settings.idProp),!1,!0):"deselectAll"===event.target.id?$scope.deselectAll():"selectAll"===event.target.id&&$scope.selectAll();else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else if(40===event.keyCode){for(event.preventDefault(),parent.nextElementSibling&&(nextOption=parent.nextElementSibling.querySelector("a")||parent.nextElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.nextElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearchDefault=function(event){var nextOption,parent=event.target.parentNode.parentNode;if($scope.settings.keyboardControls)if(9===event.keyCode||40===event.keyCode)event.preventDefault(),focusFirstOption();else if(38===event.keyCode){for(event.preventDefault(),parent.previousElementSibling&&(nextOption=parent.previousElementSibling.querySelector("a")||parent.previousElementSibling.querySelector("input"));!nextOption&&parent;)parent=parent.previousElementSibling,parent&&(nextOption=parent.querySelector("a")||parent.querySelector("input"));nextOption&&nextOption.focus()}else 27===event.keyCode&&(event.preventDefault(),$scope.toggleDropdown())},$scope.keyDownSearch=function(event,searchFilter){var searchResult;$scope.settings.keyboardControls&&13===event.keyCode&&(1===$scope.settings.selectionLimit&&$scope.settings.enableSearch?(searchResult=$filter("filter")($scope.options,$scope.getFilter(searchFilter)),1===searchResult.length&&$scope.setSelectedItem($scope.getPropertyForObject(searchResult[0],$scope.settings.idProp),!1,!0)):$scope.settings.enableSearch&&$scope.selectAll())},$scope.getFilter=function(searchFilter){var filter={};return filter[$scope.settings.searchField]=searchFilter,filter},$scope.toggleSearch=function($event){$event&&$event.stopPropagation(),$scope.settings.enableSearch=!$scope.settings.enableSearch,$scope.settings.enableSearch||($scope.input.searchFilter="")},$scope.keyDownToggleSearch=function(){$scope.settings.keyboardControls&&13===event.keyCode&&($scope.toggleSearch(),$scope.settings.enableSearch?setTimeout(function(){angular.element($element)[0].querySelector(".searchField").focus()},0):focusFirstOption())}}}}])}(angular); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 00000000..87269cdf --- /dev/null +++ b/package-lock.json @@ -0,0 +1,1285 @@ +{ + "name": "angularjs-dropdown-multiselect", + "version": "1.11.8", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "abbrev": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", + "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==", + "dev": true + }, + "ajv": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-5.2.3.tgz", + "integrity": "sha1-wG9Zh3jETGsWGrr+NGa4GtGBTtI=", + "dev": true, + "optional": true, + "requires": { + "co": "4.6.0", + "fast-deep-equal": "1.0.0", + "json-schema-traverse": "0.3.1", + "json-stable-stringify": "1.0.1" + } + }, + "amdefine": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz", + "integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU=", + "dev": true + }, + "angular": { + "version": "1.6.6", + "resolved": "https://registry.npmjs.org/angular/-/angular-1.6.6.tgz", + "integrity": "sha1-/Vo8+0N844LYVO4BEgeXl4Uny2Q=" + }, + "argparse": { + "version": "0.1.16", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-0.1.16.tgz", + "integrity": "sha1-z9AeD7uj1srtBJ+9dY1A9lGW9Xw=", + "dev": true, + "requires": { + "underscore": "1.7.0", + "underscore.string": "2.4.0" + }, + "dependencies": { + "underscore.string": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/underscore.string/-/underscore.string-2.4.0.tgz", + "integrity": "sha1-jN2PusTi0uoefi6Al8QvRCKA+Fs=", + "dev": true + } + } + }, + "asn1": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.3.tgz", + "integrity": "sha1-2sh4dxPJlmhJ/IGAd36+nB3fO4Y=", + "dev": true, + "optional": true + }, + "assert-plus": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", + "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=", + "dev": true + }, + "async": { + "version": "0.1.22", + "resolved": "https://registry.npmjs.org/async/-/async-0.1.22.tgz", + "integrity": "sha1-D8GqoIig4+8Ovi2IMbqw3PiEUGE=", + "dev": true + }, + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=", + "dev": true, + "optional": true + }, + "aws-sign2": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz", + "integrity": "sha1-tG6JCTSpWR8tL2+G1+ap8bP+dqg=", + "dev": true, + "optional": true + }, + "aws4": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.6.0.tgz", + "integrity": "sha1-g+9cqGCysy5KDe7e6MdxudtXRx4=", + "dev": true, + "optional": true + }, + "batch": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/batch/-/batch-0.5.0.tgz", + "integrity": "sha1-/S4Fp6XWlrTbkxQBPihdj/NVfsM=", + "dev": true + }, + "bcrypt-pbkdf": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.1.tgz", + "integrity": "sha1-Y7xdy2EzG5K8Bf1SiVPDNGKgb40=", + "dev": true, + "optional": true, + "requires": { + "tweetnacl": "0.14.5" + } + }, + "boom": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/boom/-/boom-4.3.1.tgz", + "integrity": "sha1-T4owBctKfjiJ90kDD9JbluAdLjE=", + "dev": true, + "optional": true, + "requires": { + "hoek": "4.2.0" + } + }, + "buffer-crc32": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.1.tgz", + "integrity": "sha1-vj5TgvwCttYySVasGvmKqYsIU0w=", + "dev": true + }, + "bytes": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-0.2.1.tgz", + "integrity": "sha1-VVsIq8sGP4l1kFMCUj5M1P/f3zE=", + "dev": true + }, + "camelcase": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-1.2.1.tgz", + "integrity": "sha1-m7UwTS4LVmmLLHWLCKPqqdqlijk=", + "dev": true + }, + "caseless": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", + "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=", + "dev": true, + "optional": true + }, + "clean-css": { + "version": "2.0.8", + "resolved": "https://registry.npmjs.org/clean-css/-/clean-css-2.0.8.tgz", + "integrity": "sha1-6TfN/cxXgaAIF67EB56Fs+wVeiA=", + "dev": true, + "requires": { + "commander": "2.0.0" + }, + "dependencies": { + "commander": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.0.0.tgz", + "integrity": "sha1-0bhvkB+LZL2UG96tr5JFMDk76Sg=", + "dev": true + } + } + }, + "cli": { + "version": "0.4.5", + "resolved": "https://registry.npmjs.org/cli/-/cli-0.4.5.tgz", + "integrity": "sha1-ePlIXNFhtWbppsctcXDEJw6B22E=", + "dev": true, + "requires": { + "glob": "3.1.21" + } + }, + "co": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", + "integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=", + "dev": true, + "optional": true + }, + "coffee-script": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/coffee-script/-/coffee-script-1.3.3.tgz", + "integrity": "sha1-FQ1rTLUiiUNp7+1qIQHCC8f0pPQ=", + "dev": true + }, + "colors": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/colors/-/colors-0.6.2.tgz", + "integrity": "sha1-JCP+ZnisDF2uiFLl0OW+CMmXq8w=", + "dev": true + }, + "combined-stream": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.5.tgz", + "integrity": "sha1-k4NwpXtKUd6ix3wV1cX9+JUWQAk=", + "dev": true, + "requires": { + "delayed-stream": "1.0.0" + } + }, + "commander": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/commander/-/commander-1.3.2.tgz", + "integrity": "sha1-io8w7GcKb91kr1LxkUuQfXnq1bU=", + "dev": true, + "requires": { + "keypress": "0.1.0" + } + }, + "connect": { + "version": "2.12.0", + "resolved": "https://registry.npmjs.org/connect/-/connect-2.12.0.tgz", + "integrity": "sha1-Mdj6DcrN8ZCNgivSkjvootKn7Zo=", + "dev": true, + "requires": { + "batch": "0.5.0", + "buffer-crc32": "0.2.1", + "bytes": "0.2.1", + "cookie": "0.1.0", + "cookie-signature": "1.0.1", + "debug": "0.8.1", + "fresh": "0.2.0", + "methods": "0.1.0", + "multiparty": "2.2.0", + "negotiator": "0.3.0", + "pause": "0.0.1", + "qs": "0.6.6", + "raw-body": "1.1.2", + "send": "0.1.4", + "uid2": "0.0.3" + } + }, + "console-browserify": { + "version": "0.1.6", + "resolved": "https://registry.npmjs.org/console-browserify/-/console-browserify-0.1.6.tgz", + "integrity": "sha1-0SijwLuINQ61YmxufHGm8P1ImDw=", + "dev": true + }, + "cookie": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.1.0.tgz", + "integrity": "sha1-kOtGndzpBchm3mh+/EMTHYgB+dA=", + "dev": true + }, + "cookie-signature": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.1.tgz", + "integrity": "sha1-ROByFIrwHm6OJK+/EmkNaK5pjss=", + "dev": true + }, + "core-util-is": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", + "dev": true + }, + "cryptiles": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/cryptiles/-/cryptiles-3.1.2.tgz", + "integrity": "sha1-qJ+7Ig9c4l7FboxKqKT9e1sNKf4=", + "dev": true, + "optional": true, + "requires": { + "boom": "5.2.0" + }, + "dependencies": { + "boom": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/boom/-/boom-5.2.0.tgz", + "integrity": "sha512-Z5BTk6ZRe4tXXQlkqftmsAUANpXmuwlsF5Oov8ThoMbQRzdGTA1ngYRW160GexgOgjsFOKJz0LYhoNi+2AMBUw==", + "dev": true, + "optional": true, + "requires": { + "hoek": "4.2.0" + } + } + } + }, + "dashdash": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", + "integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=", + "dev": true, + "optional": true, + "requires": { + "assert-plus": "1.0.0" + } + }, + "dateformat": { + "version": "1.0.2-1.2.3", + "resolved": "https://registry.npmjs.org/dateformat/-/dateformat-1.0.2-1.2.3.tgz", + "integrity": "sha1-sCIMAt6YYXQztyhRz0fePfLNvuk=", + "dev": true + }, + "debug": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-0.8.1.tgz", + "integrity": "sha1-IP9NJvXkIstoobrLu2EDmtjBwTA=", + "dev": true + }, + "decamelize": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", + "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=", + "dev": true + }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=", + "dev": true + }, + "ecc-jsbn": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz", + "integrity": "sha1-D8c6ntXw1Tw4GTOYUj735UN3dQU=", + "dev": true, + "optional": true, + "requires": { + "jsbn": "0.1.1" + } + }, + "esprima": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-1.0.4.tgz", + "integrity": "sha1-n1V+CPw7TSbs6d00+Pv0drYlha0=", + "dev": true + }, + "eventemitter2": { + "version": "0.4.14", + "resolved": "https://registry.npmjs.org/eventemitter2/-/eventemitter2-0.4.14.tgz", + "integrity": "sha1-j2G3XN4BKy6esoTUVFWDtWQ7Yas=", + "dev": true + }, + "exit": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/exit/-/exit-0.1.2.tgz", + "integrity": "sha1-BjJjj42HfMghB9MKD/8aF8uhzQw=", + "dev": true + }, + "express": { + "version": "3.4.8", + "resolved": "https://registry.npmjs.org/express/-/express-3.4.8.tgz", + "integrity": "sha1-qnqJht4HBTM39Lxe2aZFPZzI4uE=", + "dev": true, + "requires": { + "buffer-crc32": "0.2.1", + "commander": "1.3.2", + "connect": "2.12.0", + "cookie": "0.1.0", + "cookie-signature": "1.0.1", + "debug": "0.8.1", + "fresh": "0.2.0", + "merge-descriptors": "0.0.1", + "methods": "0.1.0", + "mkdirp": "0.3.5", + "range-parser": "0.0.4", + "send": "0.1.4" + } + }, + "extend": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.1.tgz", + "integrity": "sha1-p1Xqe8Gt/MWjHOfnYtuq3F5jZEQ=", + "dev": true, + "optional": true + }, + "extsprintf": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", + "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=", + "dev": true + }, + "fast-deep-equal": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-1.0.0.tgz", + "integrity": "sha1-liVqO8l1WV6zbYLpkp0GDYk0Of8=", + "dev": true, + "optional": true + }, + "findup-sync": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/findup-sync/-/findup-sync-0.1.3.tgz", + "integrity": "sha1-fz56l7gjksZTvwZYm9hRkOk8NoM=", + "dev": true, + "requires": { + "glob": "3.2.11", + "lodash": "2.4.2" + }, + "dependencies": { + "glob": { + "version": "3.2.11", + "resolved": "https://registry.npmjs.org/glob/-/glob-3.2.11.tgz", + "integrity": "sha1-Spc/Y1uRkPcV0QmH1cAP0oFevj0=", + "dev": true, + "requires": { + "inherits": "2.0.3", + "minimatch": "0.3.0" + } + }, + "lodash": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-2.4.2.tgz", + "integrity": "sha1-+t2DS5aDBz2hebPq5tnA0VBT9z4=", + "dev": true + }, + "minimatch": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.3.0.tgz", + "integrity": "sha1-J12O2qxPG7MyZHIInnlJyDlGmd0=", + "dev": true, + "requires": { + "lru-cache": "2.7.3", + "sigmund": "1.0.1" + } + } + } + }, + "forever-agent": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", + "integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=", + "dev": true, + "optional": true + }, + "form-data": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.1.tgz", + "integrity": "sha1-b7lPvXGIUwbXPRXMSX/kzE7NRL8=", + "dev": true, + "optional": true, + "requires": { + "asynckit": "0.4.0", + "combined-stream": "1.0.5", + "mime-types": "2.1.17" + } + }, + "fresh": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.2.0.tgz", + "integrity": "sha1-v9lALPPfEsSkwxDHn5mj3eE9NKc=", + "dev": true + }, + "getobject": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/getobject/-/getobject-0.1.0.tgz", + "integrity": "sha1-BHpEl4n6Fg0Bj1SG7ZEyC27HiFw=", + "dev": true + }, + "getpass": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", + "integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=", + "dev": true, + "optional": true, + "requires": { + "assert-plus": "1.0.0" + } + }, + "glob": { + "version": "3.1.21", + "resolved": "https://registry.npmjs.org/glob/-/glob-3.1.21.tgz", + "integrity": "sha1-0p4KBV3qUTj00H7UDomC6DwgZs0=", + "dev": true, + "requires": { + "graceful-fs": "1.2.3", + "inherits": "1.0.2", + "minimatch": "0.2.14" + }, + "dependencies": { + "inherits": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-1.0.2.tgz", + "integrity": "sha1-ykMJ2t7mtUzAuNJH6NfHoJdb3Js=", + "dev": true + } + } + }, + "graceful-fs": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-1.2.3.tgz", + "integrity": "sha1-FaSAaldUfLLS2/J/QuiajDRRs2Q=", + "dev": true + }, + "grunt": { + "version": "0.4.5", + "resolved": "https://registry.npmjs.org/grunt/-/grunt-0.4.5.tgz", + "integrity": "sha1-VpN81RlDJK3/bSB2MYMqnWuk5/A=", + "dev": true, + "requires": { + "async": "0.1.22", + "coffee-script": "1.3.3", + "colors": "0.6.2", + "dateformat": "1.0.2-1.2.3", + "eventemitter2": "0.4.14", + "exit": "0.1.2", + "findup-sync": "0.1.3", + "getobject": "0.1.0", + "glob": "3.1.21", + "grunt-legacy-log": "0.1.3", + "grunt-legacy-util": "0.2.0", + "hooker": "0.2.3", + "iconv-lite": "0.2.11", + "js-yaml": "2.0.5", + "lodash": "0.9.2", + "minimatch": "0.2.14", + "nopt": "1.0.10", + "rimraf": "2.2.8", + "underscore.string": "2.2.1", + "which": "1.0.9" + } + }, + "grunt-build-control": { + "version": "0.1.8", + "resolved": "https://registry.npmjs.org/grunt-build-control/-/grunt-build-control-0.1.8.tgz", + "integrity": "sha1-6AeHwkUcsrR4dA6026j/+QWaHu0=", + "dev": true, + "requires": { + "shelljs": "0.2.6" + } + }, + "grunt-contrib-concat": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/grunt-contrib-concat/-/grunt-contrib-concat-0.3.0.tgz", + "integrity": "sha1-SPoNQzbSm2U62CJaa9b4VrRIPjI=", + "dev": true + }, + "grunt-contrib-cssmin": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/grunt-contrib-cssmin/-/grunt-contrib-cssmin-0.7.0.tgz", + "integrity": "sha1-pXNenx0mMUnkn+A1KU5CnYxnC6s=", + "dev": true, + "requires": { + "clean-css": "2.0.8", + "grunt-lib-contrib": "0.6.1" + } + }, + "grunt-contrib-jshint": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/grunt-contrib-jshint/-/grunt-contrib-jshint-0.7.2.tgz", + "integrity": "sha1-KYWd3PQuf2xUxD/nXaPEvZA4So4=", + "dev": true, + "requires": { + "jshint": "2.3.0" + } + }, + "grunt-contrib-less": { + "version": "0.8.3", + "resolved": "https://registry.npmjs.org/grunt-contrib-less/-/grunt-contrib-less-0.8.3.tgz", + "integrity": "sha1-ig6Rg1dzOa0Icp9XqaSt7/bEFBA=", + "dev": true, + "requires": { + "grunt-lib-contrib": "0.6.1", + "less": "1.5.1" + } + }, + "grunt-contrib-uglify": { + "version": "0.2.7", + "resolved": "https://registry.npmjs.org/grunt-contrib-uglify/-/grunt-contrib-uglify-0.2.7.tgz", + "integrity": "sha1-5r2lHgxAoUWfbOrUI8Ze/XJaG/c=", + "dev": true, + "requires": { + "grunt-lib-contrib": "0.6.1", + "uglify-js": "2.4.24" + } + }, + "grunt-karma": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/grunt-karma/-/grunt-karma-0.6.2.tgz", + "integrity": "sha1-QptXKfhdEP3RmKLPsoug9j56Lps=", + "dev": true, + "requires": { + "optimist": "0.6.1" + } + }, + "grunt-legacy-log": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/grunt-legacy-log/-/grunt-legacy-log-0.1.3.tgz", + "integrity": "sha1-7ClCboAwIa9ZAp+H0vnNczWgVTE=", + "dev": true, + "requires": { + "colors": "0.6.2", + "grunt-legacy-log-utils": "0.1.1", + "hooker": "0.2.3", + "lodash": "2.4.2", + "underscore.string": "2.3.3" + }, + "dependencies": { + "lodash": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-2.4.2.tgz", + "integrity": "sha1-+t2DS5aDBz2hebPq5tnA0VBT9z4=", + "dev": true + }, + "underscore.string": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/underscore.string/-/underscore.string-2.3.3.tgz", + "integrity": "sha1-ccCL9rQosRM/N+ePo6Icgvcymw0=", + "dev": true + } + } + }, + "grunt-legacy-log-utils": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/grunt-legacy-log-utils/-/grunt-legacy-log-utils-0.1.1.tgz", + "integrity": "sha1-wHBrndkGThFvNvI/5OawSGcsD34=", + "dev": true, + "requires": { + "colors": "0.6.2", + "lodash": "2.4.2", + "underscore.string": "2.3.3" + }, + "dependencies": { + "lodash": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-2.4.2.tgz", + "integrity": "sha1-+t2DS5aDBz2hebPq5tnA0VBT9z4=", + "dev": true + }, + "underscore.string": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/underscore.string/-/underscore.string-2.3.3.tgz", + "integrity": "sha1-ccCL9rQosRM/N+ePo6Icgvcymw0=", + "dev": true + } + } + }, + "grunt-legacy-util": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/grunt-legacy-util/-/grunt-legacy-util-0.2.0.tgz", + "integrity": "sha1-kzJIhNv343qf98Am3/RR2UqeVUs=", + "dev": true, + "requires": { + "async": "0.1.22", + "exit": "0.1.2", + "getobject": "0.1.0", + "hooker": "0.2.3", + "lodash": "0.9.2", + "underscore.string": "2.2.1", + "which": "1.0.9" + } + }, + "grunt-lib-contrib": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/grunt-lib-contrib/-/grunt-lib-contrib-0.6.1.tgz", + "integrity": "sha1-P1att9oG6BR5XuJBWw6+X7iQPrs=", + "dev": true, + "requires": { + "zlib-browserify": "0.0.1" + } + }, + "har-schema": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", + "integrity": "sha1-qUwiJOvKwEeCoNkDVSHyRzW37JI=", + "dev": true, + "optional": true + }, + "har-validator": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-5.0.3.tgz", + "integrity": "sha1-ukAsJmGU8VlW7xXg/PJCmT9qff0=", + "dev": true, + "optional": true, + "requires": { + "ajv": "5.2.3", + "har-schema": "2.0.0" + } + }, + "hawk": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/hawk/-/hawk-6.0.2.tgz", + "integrity": "sha512-miowhl2+U7Qle4vdLqDdPt9m09K6yZhkLDTWGoUiUzrQCn+mHHSmfJgAyGaLRZbPmTqfFFjRV1QWCW0VWUJBbQ==", + "dev": true, + "optional": true, + "requires": { + "boom": "4.3.1", + "cryptiles": "3.1.2", + "hoek": "4.2.0", + "sntp": "2.0.2" + } + }, + "hoek": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/hoek/-/hoek-4.2.0.tgz", + "integrity": "sha512-v0XCLxICi9nPfYrS9RL8HbYnXi9obYAeLbSP00BmnZwCK9+Ih9WOjoZ8YoHCoav2csqn4FOz4Orldsy2dmDwmQ==", + "dev": true + }, + "hooker": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/hooker/-/hooker-0.2.3.tgz", + "integrity": "sha1-uDT3I8xKJCqmWWNFnfbZhMXT2Vk=", + "dev": true + }, + "http-signature": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", + "integrity": "sha1-muzZJRFHcvPZW2WmCruPfBj7rOE=", + "dev": true, + "optional": true, + "requires": { + "assert-plus": "1.0.0", + "jsprim": "1.4.1", + "sshpk": "1.13.1" + } + }, + "iconv-lite": { + "version": "0.2.11", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.2.11.tgz", + "integrity": "sha1-HOYKOleGSiktEyH/RgnKS7llrcg=", + "dev": true + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", + "dev": true + }, + "is-typedarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", + "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=", + "dev": true, + "optional": true + }, + "isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=", + "dev": true + }, + "isstream": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", + "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=", + "dev": true, + "optional": true + }, + "js-yaml": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-2.0.5.tgz", + "integrity": "sha1-olrmUJmZ6X3yeMZxnaEb0Gh3Q6g=", + "dev": true, + "requires": { + "argparse": "0.1.16", + "esprima": "1.0.4" + } + }, + "jsbn": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", + "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=", + "dev": true, + "optional": true + }, + "jshint": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/jshint/-/jshint-2.3.0.tgz", + "integrity": "sha1-GVBEVaLCDEbuGDNh64fzocC33Ec=", + "dev": true, + "requires": { + "cli": "0.4.5", + "console-browserify": "0.1.6", + "minimatch": "0.2.14", + "shelljs": "0.1.4", + "underscore": "1.4.4" + }, + "dependencies": { + "shelljs": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.1.4.tgz", + "integrity": "sha1-37vnjVbDwBaNL7eeEOzR28sH7A4=", + "dev": true + }, + "underscore": { + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.4.4.tgz", + "integrity": "sha1-YaajIBBiKvoHljvzJSA88SI51gQ=", + "dev": true + } + } + }, + "json-schema": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", + "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=", + "dev": true, + "optional": true + }, + "json-schema-traverse": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz", + "integrity": "sha1-NJptRMU6Ud6JtAgFxdXlm0F9M0A=", + "dev": true, + "optional": true + }, + "json-stable-stringify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json-stable-stringify/-/json-stable-stringify-1.0.1.tgz", + "integrity": "sha1-mnWdOcXy/1A/1TAGRu1EX4jE+a8=", + "dev": true, + "optional": true, + "requires": { + "jsonify": "0.0.0" + } + }, + "json-stringify-safe": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", + "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=", + "dev": true, + "optional": true + }, + "jsonify": { + "version": "0.0.0", + "resolved": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.0.tgz", + "integrity": "sha1-LHS27kHZPKUbe1qu6PUDYx0lKnM=", + "dev": true, + "optional": true + }, + "jsprim": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", + "integrity": "sha1-MT5mvB5cwG5Di8G3SZwuXFastqI=", + "dev": true, + "optional": true, + "requires": { + "assert-plus": "1.0.0", + "extsprintf": "1.3.0", + "json-schema": "0.2.3", + "verror": "1.10.0" + } + }, + "keypress": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/keypress/-/keypress-0.1.0.tgz", + "integrity": "sha1-SjGI1CkbZrT2XtuZ+AaqmuKTWSo=", + "dev": true + }, + "less": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/less/-/less-1.5.1.tgz", + "integrity": "sha1-YzMTEw79EqO3jFaqeZ2rPu////Q=", + "dev": true, + "requires": { + "clean-css": "2.0.8", + "mime": "1.2.11", + "mkdirp": "0.3.5", + "request": "2.83.0", + "source-map": "0.1.43" + } + }, + "lodash": { + "version": "0.9.2", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-0.9.2.tgz", + "integrity": "sha1-jzSZxSRdNG1oLlsNO0B2fgnxqSw=", + "dev": true + }, + "lru-cache": { + "version": "2.7.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.7.3.tgz", + "integrity": "sha1-bUUk6LlV+V1PW1iFHOId1y+06VI=", + "dev": true + }, + "merge-descriptors": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-0.0.1.tgz", + "integrity": "sha1-L/CYDJJM+B0LXR+2ARd8uLtWwNA=", + "dev": true + }, + "methods": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/methods/-/methods-0.1.0.tgz", + "integrity": "sha1-M11Cnu/SG3us8unJIqjSvRSjDk8=", + "dev": true + }, + "mime": { + "version": "1.2.11", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.2.11.tgz", + "integrity": "sha1-WCA+7Ybjpe8XrtK32evUfwpg3RA=", + "dev": true + }, + "mime-db": { + "version": "1.30.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.30.0.tgz", + "integrity": "sha1-dMZD2i3Z1qRTmZY0ZbJtXKfXHwE=", + "dev": true + }, + "mime-types": { + "version": "2.1.17", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.17.tgz", + "integrity": "sha1-Cdejk/A+mVp5+K+Fe3Cp4KsWVXo=", + "dev": true, + "requires": { + "mime-db": "1.30.0" + } + }, + "minimatch": { + "version": "0.2.14", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.2.14.tgz", + "integrity": "sha1-x054BXT2PG+aCQ6Q775u9TpqdWo=", + "dev": true, + "requires": { + "lru-cache": "2.7.3", + "sigmund": "1.0.1" + } + }, + "minimist": { + "version": "0.0.10", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz", + "integrity": "sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8=", + "dev": true + }, + "mkdirp": { + "version": "0.3.5", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.5.tgz", + "integrity": "sha1-3j5fiWHIjHh+4TaN+EmsRBPsqNc=", + "dev": true + }, + "multiparty": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/multiparty/-/multiparty-2.2.0.tgz", + "integrity": "sha1-pWfCrwAK0i3I8qZT2Rl4rh9TFvQ=", + "dev": true, + "requires": { + "readable-stream": "1.1.14", + "stream-counter": "0.2.0" + } + }, + "negotiator": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.3.0.tgz", + "integrity": "sha1-cG1pLv7d9XTVfqn7GriaT6fuj2A=", + "dev": true + }, + "nopt": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/nopt/-/nopt-1.0.10.tgz", + "integrity": "sha1-bd0hvSoxQXuScn3Vhfim83YI6+4=", + "dev": true, + "requires": { + "abbrev": "1.1.1" + } + }, + "oauth-sign": { + "version": "0.8.2", + "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.8.2.tgz", + "integrity": "sha1-Rqarfwrq2N6unsBWV4C31O/rnUM=", + "dev": true, + "optional": true + }, + "optimist": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz", + "integrity": "sha1-2j6nRob6IaGaERwybpDrFaAZZoY=", + "dev": true, + "requires": { + "minimist": "0.0.10", + "wordwrap": "0.0.2" + } + }, + "pause": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/pause/-/pause-0.0.1.tgz", + "integrity": "sha1-HUCLP9t2kjuVQ9lvtMnf1TXZy10=", + "dev": true + }, + "performance-now": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", + "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=", + "dev": true, + "optional": true + }, + "punycode": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", + "integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=", + "dev": true, + "optional": true + }, + "qs": { + "version": "0.6.6", + "resolved": "https://registry.npmjs.org/qs/-/qs-0.6.6.tgz", + "integrity": "sha1-bgFQmP9RlouKPIGQAdXyyJvEsQc=", + "dev": true + }, + "range-parser": { + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-0.0.4.tgz", + "integrity": "sha1-wEJ//vUcEKy6B4KkbJYC50T/Ygs=", + "dev": true + }, + "raw-body": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-1.1.2.tgz", + "integrity": "sha1-x0swBN6l3v0WlhcRBqx0DsMdYr4=", + "dev": true, + "requires": { + "bytes": "0.2.1" + } + }, + "readable-stream": { + "version": "1.1.14", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", + "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", + "dev": true, + "requires": { + "core-util-is": "1.0.2", + "inherits": "2.0.3", + "isarray": "0.0.1", + "string_decoder": "0.10.31" + } + }, + "request": { + "version": "2.83.0", + "resolved": "https://registry.npmjs.org/request/-/request-2.83.0.tgz", + "integrity": "sha512-lR3gD69osqm6EYLk9wB/G1W/laGWjzH90t1vEa2xuxHD5KUrSzp9pUSfTm+YC5Nxt2T8nMPEvKlhbQayU7bgFw==", + "dev": true, + "optional": true, + "requires": { + "aws-sign2": "0.7.0", + "aws4": "1.6.0", + "caseless": "0.12.0", + "combined-stream": "1.0.5", + "extend": "3.0.1", + "forever-agent": "0.6.1", + "form-data": "2.3.1", + "har-validator": "5.0.3", + "hawk": "6.0.2", + "http-signature": "1.2.0", + "is-typedarray": "1.0.0", + "isstream": "0.1.2", + "json-stringify-safe": "5.0.1", + "mime-types": "2.1.17", + "oauth-sign": "0.8.2", + "performance-now": "2.1.0", + "qs": "6.5.1", + "safe-buffer": "5.1.1", + "stringstream": "0.0.5", + "tough-cookie": "2.3.3", + "tunnel-agent": "0.6.0", + "uuid": "3.1.0" + }, + "dependencies": { + "qs": { + "version": "6.5.1", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.1.tgz", + "integrity": "sha512-eRzhrN1WSINYCDCbrz796z37LOe3m5tmW7RQf6oBntukAG1nmovJvhnwHHRMAfeoItc1m2Hk02WER2aQ/iqs+A==", + "dev": true, + "optional": true + } + } + }, + "rimraf": { + "version": "2.2.8", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.2.8.tgz", + "integrity": "sha1-5Dm+Kq7jJzIZUnMPmaiSnk/FBYI=", + "dev": true + }, + "safe-buffer": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", + "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==", + "dev": true + }, + "send": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/send/-/send-0.1.4.tgz", + "integrity": "sha1-vnDY0b4B3mGCGvE3gLUDRaT3Gr0=", + "dev": true, + "requires": { + "debug": "0.8.1", + "fresh": "0.2.0", + "mime": "1.2.11", + "range-parser": "0.0.4" + } + }, + "shelljs": { + "version": "0.2.6", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.2.6.tgz", + "integrity": "sha1-kEktcv/MgVmXa6umL7D2iE8MM3g=", + "dev": true + }, + "sigmund": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz", + "integrity": "sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA=", + "dev": true + }, + "sntp": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/sntp/-/sntp-2.0.2.tgz", + "integrity": "sha1-UGQRDwr4X3z9t9a2ekACjOUrSys=", + "dev": true, + "optional": true, + "requires": { + "hoek": "4.2.0" + } + }, + "source-map": { + "version": "0.1.43", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.1.43.tgz", + "integrity": "sha1-wkvBRspRfBRx9drL4lcbK3+eM0Y=", + "dev": true, + "optional": true, + "requires": { + "amdefine": "1.0.1" + } + }, + "sshpk": { + "version": "1.13.1", + "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.13.1.tgz", + "integrity": "sha1-US322mKHFEMW3EwY/hzx2UBzm+M=", + "dev": true, + "optional": true, + "requires": { + "asn1": "0.2.3", + "assert-plus": "1.0.0", + "bcrypt-pbkdf": "1.0.1", + "dashdash": "1.14.1", + "ecc-jsbn": "0.1.1", + "getpass": "0.1.7", + "jsbn": "0.1.1", + "tweetnacl": "0.14.5" + } + }, + "stream-counter": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/stream-counter/-/stream-counter-0.2.0.tgz", + "integrity": "sha1-3tJmVWMZyLDiIoErnPOyb6fZR94=", + "dev": true, + "requires": { + "readable-stream": "1.1.14" + } + }, + "string_decoder": { + "version": "0.10.31", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", + "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=", + "dev": true + }, + "stringstream": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz", + "integrity": "sha1-TkhM1N5aC7vuGORjB3EKioFiGHg=", + "dev": true, + "optional": true + }, + "tough-cookie": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.3.3.tgz", + "integrity": "sha1-C2GKVWW23qkL80JdBNVe3EdadWE=", + "dev": true, + "optional": true, + "requires": { + "punycode": "1.4.1" + } + }, + "tunnel-agent": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", + "integrity": "sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0=", + "dev": true, + "optional": true, + "requires": { + "safe-buffer": "5.1.1" + } + }, + "tweetnacl": { + "version": "0.14.5", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", + "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=", + "dev": true, + "optional": true + }, + "uglify-js": { + "version": "2.4.24", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-2.4.24.tgz", + "integrity": "sha1-+tV1XB4Vd2WLsG/5q25UjJW+vW4=", + "dev": true, + "requires": { + "async": "0.2.10", + "source-map": "0.1.34", + "uglify-to-browserify": "1.0.2", + "yargs": "3.5.4" + }, + "dependencies": { + "async": { + "version": "0.2.10", + "resolved": "https://registry.npmjs.org/async/-/async-0.2.10.tgz", + "integrity": "sha1-trvgsGdLnXGXCMo43owjfLUmw9E=", + "dev": true + }, + "source-map": { + "version": "0.1.34", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.1.34.tgz", + "integrity": "sha1-p8/omux7FoLDsZjQrPtH19CQVms=", + "dev": true, + "requires": { + "amdefine": "1.0.1" + } + } + } + }, + "uglify-to-browserify": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/uglify-to-browserify/-/uglify-to-browserify-1.0.2.tgz", + "integrity": "sha1-bgkk1r2mta/jSeOabWMoUKD4grc=", + "dev": true + }, + "uid2": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/uid2/-/uid2-0.0.3.tgz", + "integrity": "sha1-SDEm4Rd03y9xuLY53NeZw3YWK4I=", + "dev": true + }, + "underscore": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.7.0.tgz", + "integrity": "sha1-a7rwh3UA02vjTsqlhODbn+8DUgk=", + "dev": true + }, + "underscore.string": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/underscore.string/-/underscore.string-2.2.1.tgz", + "integrity": "sha1-18D6KvXVoaZ/QlPa7pgTLnM/Dxk=", + "dev": true + }, + "uuid": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.1.0.tgz", + "integrity": "sha512-DIWtzUkw04M4k3bf1IcpS2tngXEL26YUD2M0tMDUpnUrz2hgzUBlD55a4FjdLGPvfHxS6uluGWvaVEqgBcVa+g==", + "dev": true, + "optional": true + }, + "verror": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz", + "integrity": "sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=", + "dev": true, + "optional": true, + "requires": { + "assert-plus": "1.0.0", + "core-util-is": "1.0.2", + "extsprintf": "1.3.0" + } + }, + "which": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/which/-/which-1.0.9.tgz", + "integrity": "sha1-RgwdoPgQED0DIam2M6+eV15kSG8=", + "dev": true + }, + "window-size": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/window-size/-/window-size-0.1.0.tgz", + "integrity": "sha1-VDjNLqk7IC76Ohn+iIeu58lPnJ0=", + "dev": true + }, + "wordwrap": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.2.tgz", + "integrity": "sha1-t5Zpu0LstAn4PVg8rVLKF+qhZD8=", + "dev": true + }, + "yargs": { + "version": "3.5.4", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-3.5.4.tgz", + "integrity": "sha1-2K/49mXpTDS9JZvevRv68N3TU2E=", + "dev": true, + "requires": { + "camelcase": "1.2.1", + "decamelize": "1.2.0", + "window-size": "0.1.0", + "wordwrap": "0.0.2" + } + }, + "zlib-browserify": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/zlib-browserify/-/zlib-browserify-0.0.1.tgz", + "integrity": "sha1-T6akXQDbwV8xikr6HZr8Aljhdsw=", + "dev": true + } + } +} diff --git a/src/angularjs-dropdown-multiselect.js b/src/angularjs-dropdown-multiselect.js index b0487381..5f4fef54 100644 --- a/src/angularjs-dropdown-multiselect.js +++ b/src/angularjs-dropdown-multiselect.js @@ -11,7 +11,7 @@ directiveModule.directive('dmDropdownStaticInclude', ['$compile', function($comp }; }]); -directiveModule.directive('ngDropdownMultiselect', ['$filter', '$document', '$compile', '$parse', function($filter, $document, $compile, $parse) { +directiveModule.directive('ngDropdownMultiselect', ['$filter', '$document', '$timeout', function($filter, $document, $timeout) { return { restrict: 'AE', scope: { @@ -189,9 +189,11 @@ directiveModule.directive('ngDropdownMultiselect', ['$filter', '$document', '$co $scope.externalEvents.onSelectionChanged(); }; - angular.extend($scope.settings, $scope.extraSettings || []); - angular.extend($scope.externalEvents, $scope.events || []); - angular.extend($scope.texts, $scope.translationTexts); + $timeout(function () { + angular.extend($scope.settings, $scope.extraSettings || []); + angular.extend($scope.externalEvents, $scope.events || []); + angular.extend($scope.texts, $scope.translationTexts); + }); $scope.singleSelection = $scope.settings.selectionLimit === 1;