From 33f4d9ff9b7c2bbd7abc1b0bb4dc7e8a877464fc Mon Sep 17 00:00:00 2001 From: Andrea Budel Date: Mon, 2 Feb 2015 11:03:06 +0100 Subject: [PATCH 01/28] refresh on active --- src/uiSelectChoicesDirective.js | 12 +++++++++++- src/uiSelectController.js | 4 ++++ test/select.spec.js | 31 ++++++++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/uiSelectChoicesDirective.js b/src/uiSelectChoicesDirective.js index b61bf89b0..a6421c3e2 100644 --- a/src/uiSelectChoicesDirective.js +++ b/src/uiSelectChoicesDirective.js @@ -27,6 +27,8 @@ uis.directive('uiSelectChoices', $select.disableChoiceExpression = attrs.uiDisableChoice; $select.onHighlightCallback = attrs.onHighlight; + $select.refreshOnActive = scope.$eval(attrs.refreshOnActive); + if(groupByExp) { var groups = element.querySelectorAll('.ui-select-choices-group'); if (groups.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-group but got '{0}'.", groups.length); @@ -52,7 +54,15 @@ uis.directive('uiSelectChoices', scope.$watch('$select.search', function(newValue) { if(newValue && !$select.open && $select.multiple) $select.activate(false, true); $select.activeIndex = $select.tagging.isActivated ? -1 : 0; - $select.refresh(attrs.refresh); + if(!$select.refreshOnActive || ($select.refreshOnActive && $select.refreshIsActive)) { + $select.refresh(attrs.refresh); + } + }); + + scope.$watch('$select.refreshIsActive', function(newValue, oldValue){ + if(angular.isUndefined(oldValue) && newValue){ + $select.refresh(attrs.refresh); + } }); attrs.$observe('refreshDelay', function() { diff --git a/src/uiSelectController.js b/src/uiSelectController.js index a683181ce..f9e8aef3b 100644 --- a/src/uiSelectController.js +++ b/src/uiSelectController.js @@ -34,6 +34,8 @@ uis.controller('uiSelectCtrl', ctrl.closeOnSelect = true; // Initialized inside uiSelect directive link function ctrl.clickTriggeredSelect = false; ctrl.$filter = $filter; + ctrl.refreshOnActive = undefined; + ctrl.refreshIsActive = undefined; ctrl.isEmpty = function() { return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === ''; @@ -65,6 +67,8 @@ uis.controller('uiSelectCtrl', ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex; + ctrl.refreshIsActive = true; + // ensure that the index is set to zero for tagging variants // that where first option is auto-selected if ( ctrl.activeIndex === -1 && ctrl.taggingLabel !== false ) { diff --git a/test/select.spec.js b/test/select.spec.js index 8be66afa8..90576726d 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -191,7 +191,7 @@ describe('ui-select tests', function() { expect(getMatchLabel(el)).toEqual('Adam'); }); - + it('should correctly render initial state with track by feature', function() { var el = compileTemplate( ' \ @@ -1791,4 +1791,33 @@ describe('ui-select tests', function() { } }); }); + + describe('with refresh on active', function(){ + it('should not refresh untill is activate', function(){ + + var el = compileTemplate( + ' \ + \ + \ + \ +
\ +
\ + I should appear only once\ +
\ +
\ +
' + ); + + scope.fetchFromServer = function(){}; + spyOn(scope, 'fetchFromServer'); + $timeout.flush(); + expect(scope.fetchFromServer.calls.any()).toEqual(false); + + el.scope().$select.activate(); + $timeout.flush(); + expect(scope.fetchFromServer.calls.any()).toEqual(true); + }); + + }); }); From 453294fa3722754bf2251fe7c85d06736e4ed22e Mon Sep 17 00:00:00 2001 From: Jonathan Nelson Date: Wed, 8 Jul 2015 17:30:24 -0400 Subject: [PATCH 02/28] add onBeforeSelect callback Adds an onBeforeSelect callback to allow intercepting a selection. Ensures access to both the prospective new selection and the current selection. --- src/uiSelectController.js | 47 ++++++++---- src/uiSelectDirective.js | 1 + test/select.spec.js | 154 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 188 insertions(+), 14 deletions(-) diff --git a/src/uiSelectController.js b/src/uiSelectController.js index c0a1a94ac..e74bd8e48 100644 --- a/src/uiSelectController.js +++ b/src/uiSelectController.js @@ -5,8 +5,8 @@ * put as much logic in the controller (instead of the link functions) as possible so it can be easily tested. */ uis.controller('uiSelectCtrl', - ['$scope', '$element', '$timeout', '$filter', 'uisRepeatParser', 'uiSelectMinErr', 'uiSelectConfig', - function($scope, $element, $timeout, $filter, RepeatParser, uiSelectMinErr, uiSelectConfig) { + ['$scope', '$element', '$timeout', '$filter', '$q', 'uisRepeatParser', 'uiSelectMinErr', 'uiSelectConfig', + function($scope, $element, $timeout, $filter, $q, RepeatParser, uiSelectMinErr, uiSelectConfig) { var ctrl = this; @@ -284,24 +284,43 @@ uis.controller('uiSelectCtrl', } } - $scope.$broadcast('uis:select', item); + var completeSelection = function() { + $scope.$broadcast('uis:select', item); + + $timeout(function(){ + ctrl.onSelectCallback($scope, callbackContext); + }); + + if (ctrl.closeOnSelect) { + ctrl.close(skipFocusser); + } + if ($event && $event.type === 'click') { + ctrl.clickTriggeredSelect = true; + } + }; var locals = {}; locals[ctrl.parserResult.itemName] = item; - $timeout(function(){ - ctrl.onSelectCallback($scope, { - $item: item, - $model: ctrl.parserResult.modelMapper($scope, locals) - }); - }); + var callbackContext = { + $item: item, + $model: ctrl.parserResult.modelMapper($scope, locals) + }; - if (ctrl.closeOnSelect) { - ctrl.close(skipFocusser); - } - if ($event && $event.type === 'click') { - ctrl.clickTriggeredSelect = true; + var onBeforeSelectResult = ctrl.onBeforeSelectCallback($scope, callbackContext); + + if (angular.isDefined(onBeforeSelectResult)) { + if (!onBeforeSelectResult) { + return; // abort the selection in case of deliberate falsey result + } else if (angular.isDefined(onBeforeSelectResult.promise)) { + onBeforeSelectResult.promise.then(completeSelection); + } else { + completeSelection(); + } + } else { + completeSelection(); } + } } }; diff --git a/src/uiSelectDirective.js b/src/uiSelectDirective.js index fc6cc4138..4af6acb7f 100644 --- a/src/uiSelectDirective.js +++ b/src/uiSelectDirective.js @@ -41,6 +41,7 @@ uis.directive('uiSelect', } }(); + $select.onBeforeSelectCallback = $parse(attrs.onBeforeSelect); $select.onSelectCallback = $parse(attrs.onSelect); $select.onRemoveCallback = $parse(attrs.onRemove); diff --git a/test/select.spec.js b/test/select.spec.js index 2ba86fb2a..3875f2181 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -959,6 +959,160 @@ describe('ui-select tests', function() { }); + it('should invoke before-select callback before select callback synchronously', function () { + + var order = []; + scope.onBeforeSelectFn = function ($item, $model, $label) { + order.push('onBeforeSelectFn'); + }; + scope.onSelectFn = function ($item, $model, $label) { + order.push('onSelectFn'); + }; + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
\ +
\ +
\ +
' + ); + + clickItem(el, 'Samantha'); + $timeout.flush(); + + expect(order[0]).toEqual('onBeforeSelectFn'); + expect(order[1]).toEqual('onSelectFn'); + + }); + + it('should invoke before-select callback before select callback when promised', inject(function ($q) { + + var order = []; + scope.onBeforeSelectFn = function ($item, $model, $label) { + var deferred = $q.defer(); + $timeout(function () { + order.push('onBeforeSelectFn'); + deferred.resolve(order); + }, 50); + return deferred; + }; + scope.onSelectFn = function ($item, $model, $label) { + order.push('onSelectFn'); + }; + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
\ +
\ +
\ +
' + ); + + clickItem(el, 'Samantha'); + $timeout.flush(); + + expect(order[0]).toEqual('onBeforeSelectFn'); + expect(order[1]).toEqual('onSelectFn'); + + })); + + it('should abort selection if before-select callback returns falsy', function () { + + scope.onBeforeSelectFn = function ($item, $model, $label) { + return false; + }; + scope.onSelectFn = function ($item, $model, $label) { + scope.$item = $item; + scope.$model = $model; + }; + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
\ +
\ +
\ +
' + ); + + expect(scope.$item).toBeFalsy(); + expect(scope.$model).toBeFalsy(); + + clickItem(el, 'Samantha'); + $timeout.flush(); + + expect(scope.$item).toBeFalsy(); + expect(scope.$model).toBeFalsy(); + + }); + + it('should abort selection if before-select callback rejects promise', inject(function ($q) { + + scope.onBeforeSelectFn = function ($item, $model, $label) { + var deferred = $q.defer(); + $timeout(function () { + deferred.reject(); + }, 50); + return deferred; + }; + scope.onSelectFn = function ($item, $model, $label) { + scope.$item = $item; + scope.$model = $model; + }; + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
\ +
\ +
\ +
' + ); + + expect(scope.$item).toBeFalsy(); + expect(scope.$model).toBeFalsy(); + + clickItem(el, 'Samantha'); + $timeout.flush(); + + expect(scope.$item).toBeFalsy(); + expect(scope.$model).toBeFalsy(); + + })); + + it('should keep reference to current selection and incoming selection within before-select callback', function () { + + var currentSelection, incomingSelection; + scope.onBeforeSelectFn = function ($item, $model, $label) { + incomingSelection = $item; + currentSelection = scope.selection.selected; + }; + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
\ +
\ +
\ +
' + ); + + clickItem(el, 'Samantha'); + $timeout.flush(); + + expect(currentSelection).toBeFalsy(); + expect(incomingSelection.name).toBe('Samantha'); + + clickItem(el, 'Adam'); + $timeout.flush(); + + expect(currentSelection).toBe('Samantha'); + expect(incomingSelection.name).toBe('Adam'); + + }); + it('should invoke hover callback', function(){ var highlighted; From a62af5bbce31a4062760a3393bbcd5a655980e08 Mon Sep 17 00:00:00 2001 From: Jonathan Nelson Date: Wed, 8 Jul 2015 18:11:42 -0400 Subject: [PATCH 03/28] remove unused on-select attribute --- test/select.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/select.spec.js b/test/select.spec.js index 3875f2181..fd4ae96c9 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -1090,7 +1090,7 @@ describe('ui-select tests', function() { currentSelection = scope.selection.selected; }; var el = compileTemplate( - ' \ + ' \ {{$select.selected.name}} \ \
\ From 326dd7f6d7d1f167022319998f832c7b5f891ebb Mon Sep 17 00:00:00 2001 From: Jonathan Nelson Date: Thu, 9 Jul 2015 13:08:55 -0400 Subject: [PATCH 04/28] remove duration --- test/select.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/select.spec.js b/test/select.spec.js index fd4ae96c9..deecc5453 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -994,7 +994,7 @@ describe('ui-select tests', function() { $timeout(function () { order.push('onBeforeSelectFn'); deferred.resolve(order); - }, 50); + }); return deferred; }; scope.onSelectFn = function ($item, $model, $label) { @@ -1054,7 +1054,7 @@ describe('ui-select tests', function() { var deferred = $q.defer(); $timeout(function () { deferred.reject(); - }, 50); + }); return deferred; }; scope.onSelectFn = function ($item, $model, $label) { From bb8bfd0abd0b660eb4f4e5a58b2a4192f736a3fc Mon Sep 17 00:00:00 2001 From: Jonathan Nelson Date: Thu, 9 Jul 2015 13:11:14 -0400 Subject: [PATCH 05/28] use typical promise-handling convention --- src/uiSelectController.js | 4 ++-- test/select.spec.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/uiSelectController.js b/src/uiSelectController.js index e74bd8e48..c14e4bea3 100644 --- a/src/uiSelectController.js +++ b/src/uiSelectController.js @@ -312,8 +312,8 @@ uis.controller('uiSelectCtrl', if (angular.isDefined(onBeforeSelectResult)) { if (!onBeforeSelectResult) { return; // abort the selection in case of deliberate falsey result - } else if (angular.isDefined(onBeforeSelectResult.promise)) { - onBeforeSelectResult.promise.then(completeSelection); + } else if (angular.isFunction(onBeforeSelectResult.then)) { + onBeforeSelectResult.then(completeSelection); } else { completeSelection(); } diff --git a/test/select.spec.js b/test/select.spec.js index deecc5453..5c47fd383 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -995,7 +995,7 @@ describe('ui-select tests', function() { order.push('onBeforeSelectFn'); deferred.resolve(order); }); - return deferred; + return deferred.promise; }; scope.onSelectFn = function ($item, $model, $label) { order.push('onSelectFn'); @@ -1055,7 +1055,7 @@ describe('ui-select tests', function() { $timeout(function () { deferred.reject(); }); - return deferred; + return deferred.promise; }; scope.onSelectFn = function ($item, $model, $label) { scope.$item = $item; From 284dc8395c73fc43578edd105b9f17ef6d564c7b Mon Sep 17 00:00:00 2001 From: Jonathan Nelson Date: Thu, 9 Jul 2015 13:12:00 -0400 Subject: [PATCH 06/28] add test for promise resolve success --- test/select.spec.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/select.spec.js b/test/select.spec.js index 5c47fd383..0ef4d4394 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -1018,6 +1018,42 @@ describe('ui-select tests', function() { })); + it('should complete on-select if before-select callback promise is resolved', inject(function ($q) { + + scope.onBeforeSelectFn = function ($item, $model, $label) { + var deferred = $q.defer(); + $timeout(function () { + deferred.resolve(); + }); + return deferred.promise; + }; + scope.onSelectFn = function ($item, $model, $label) { + scope.$item = $item; + scope.$model = $model; + }; + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
\ +
\ +
\ +
' + ); + + expect(scope.$item).toBeFalsy(); + expect(scope.$model).toBeFalsy(); + + clickItem(el, 'Samantha'); + $timeout.flush(); + + expect(scope.selection.selected).toBe('Samantha'); + + expect(scope.$item).toEqual(scope.people[5]); + expect(scope.$model).toEqual('Samantha'); + + })); + it('should abort selection if before-select callback returns falsy', function () { scope.onBeforeSelectFn = function ($item, $model, $label) { From cb0f41584212522099733afa1c8d124abfc9c966 Mon Sep 17 00:00:00 2001 From: Chris Jackson Date: Sun, 26 Jul 2015 15:04:36 +0100 Subject: [PATCH 07/28] Don't hide select when SearchEnable is false https://github.com/angular-ui/ui-select/issues/453 --- src/bootstrap/match.tpl.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/match.tpl.html b/src/bootstrap/match.tpl.html index a76c9b862..ec1bb47f5 100644 --- a/src/bootstrap/match.tpl.html +++ b/src/bootstrap/match.tpl.html @@ -1,4 +1,4 @@ -
+
Date: Mon, 25 May 2015 18:43:53 +0100 Subject: [PATCH 08/28] Protect against empty selection causing exception when getting placeholder --- src/uiSelectController.js | 2 +- src/uiSelectMultipleDirective.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/uiSelectController.js b/src/uiSelectController.js index c0a1a94ac..4f1753c66 100644 --- a/src/uiSelectController.js +++ b/src/uiSelectController.js @@ -145,7 +145,7 @@ uis.controller('uiSelectCtrl', data = data || ctrl.parserResult.source($scope); var selectedItems = ctrl.selected; //TODO should implement for single mode removeSelected - if ((angular.isArray(selectedItems) && !selectedItems.length) || !ctrl.removeSelected) { + if (ctrl.isEmpty() || (angular.isArray(selectedItems) && !selectedItems.length) || !ctrl.removeSelected) { ctrl.setItemsFn(data); }else{ if ( data !== undefined ) { diff --git a/src/uiSelectMultipleDirective.js b/src/uiSelectMultipleDirective.js index b1e997ec5..141470747 100644 --- a/src/uiSelectMultipleDirective.js +++ b/src/uiSelectMultipleDirective.js @@ -56,7 +56,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec ctrl.getPlaceholder = function(){ //Refactor single? - if($select.selected.length) return; + if($select.selected && $select.selected.length) return; return $select.placeholder; }; From bd76b8724c75aa8fac82c9e31d7d29da8ee3494a Mon Sep 17 00:00:00 2001 From: Chris Jackson Date: Wed, 22 Apr 2015 20:50:31 +0100 Subject: [PATCH 09/28] Fix styling for bootstrap placeholder --- src/bootstrap/match.tpl.html | 4 ++-- src/common.css | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/match.tpl.html b/src/bootstrap/match.tpl.html index a76c9b862..7f788c319 100644 --- a/src/bootstrap/match.tpl.html +++ b/src/bootstrap/match.tpl.html @@ -1,11 +1,11 @@
- {{$select.placeholder}} + {{$select.placeholder}} .ui-select-bootstrap.open { border-right: 1px solid #428bca; } +.ui-select-bootstrap .ui-select-placeholder { + color: #999; + opacity: 1; +} + +.ui-select-bootstrap .ui-select-placeholder { + color: #999; +} + +.ui-select-bootstrap .ui-select-placeholder { + color: #999; +} + .ui-select-bootstrap .ui-select-choices-row>a { display: block; padding: 3px 20px; From 69a160465c3c44062aee9d75ffc18734e28d84da Mon Sep 17 00:00:00 2001 From: Chris Jackson Date: Wed, 22 Apr 2015 20:44:28 +0100 Subject: [PATCH 10/28] Fix width calculation to allow for different padding --- src/uiSelectController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uiSelectController.js b/src/uiSelectController.js index 4f1753c66..98e3f80c1 100644 --- a/src/uiSelectController.js +++ b/src/uiSelectController.js @@ -364,7 +364,7 @@ uis.controller('uiSelectCtrl', if (containerWidth === 0) { return false; } - var inputWidth = containerWidth - input.offsetLeft - 10; + var inputWidth = containerWidth - input.offsetLeft - ctrl.searchInput.parent()[0].offsetLeft - 5; if (inputWidth < 50) inputWidth = containerWidth; ctrl.searchInput.css('width', inputWidth+'px'); return true; From 5c370c357a2a3b601e4d31b54ce20cfafa2bf2ce Mon Sep 17 00:00:00 2001 From: Chris Jackson Date: Sun, 26 Jul 2015 15:04:36 +0100 Subject: [PATCH 11/28] Don't hide select when SearchEnable is false https://github.com/angular-ui/ui-select/issues/453 --- src/bootstrap/match.tpl.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/match.tpl.html b/src/bootstrap/match.tpl.html index 7f788c319..33e607123 100644 --- a/src/bootstrap/match.tpl.html +++ b/src/bootstrap/match.tpl.html @@ -1,4 +1,4 @@ -
+
Date: Sun, 26 Jul 2015 15:48:13 +0100 Subject: [PATCH 12/28] Limit the number of selections allowed in multiple mode --- src/uiSelectDirective.js | 3 +++ src/uiSelectMultipleDirective.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/uiSelectDirective.js b/src/uiSelectDirective.js index 8fad7e386..3d391825c 100644 --- a/src/uiSelectDirective.js +++ b/src/uiSelectDirective.js @@ -44,6 +44,9 @@ uis.directive('uiSelect', $select.onSelectCallback = $parse(attrs.onSelect); $select.onRemoveCallback = $parse(attrs.onRemove); + //Limit the number of selections allowed + $select.limit = (angular.isDefined(attrs.limit)) ? parseInt(attrs.limit, 10) : undefined; + //Set reference to ngModel from uiSelectCtrl $select.ngModel = ngModel; diff --git a/src/uiSelectMultipleDirective.js b/src/uiSelectMultipleDirective.js index 141470747..d1b5d373e 100644 --- a/src/uiSelectMultipleDirective.js +++ b/src/uiSelectMultipleDirective.js @@ -155,6 +155,9 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec }; scope.$on('uis:select', function (event, item) { + if($select.selected.length >= $select.limit) { + return; + } $select.selected.push(item); $selectMultiple.updateModel(); }); From 4eaf47dc15879029ee8fc7a63b9eaef2c317c5a0 Mon Sep 17 00:00:00 2001 From: Chris Jackson Date: Tue, 28 Jul 2015 21:17:08 +0100 Subject: [PATCH 13/28] Update examples to add search-enabled example --- examples/bootstrap.html | 37 +++++++++++++++++++++--------- examples/select2-bootstrap3.html | 37 +++++++++++++++++++++--------- examples/selectize-bootstrap3.html | 37 +++++++++++++++++++++--------- 3 files changed, 78 insertions(+), 33 deletions(-) diff --git a/examples/bootstrap.html b/examples/bootstrap.html index a1e362b46..2cafd573a 100644 --- a/examples/bootstrap.html +++ b/examples/bootstrap.html @@ -42,20 +42,35 @@
ui-select inside a Bootstrap form -
- -
+
+ +
+ + + {{$select.selected.name}} + +
+ +
+
+ +
+
- - {{$select.selected.name}} - -
- -
-
+
+ +
+ + + {{$select.selected.name}} + +
+ +
+
+
-
diff --git a/examples/select2-bootstrap3.html b/examples/select2-bootstrap3.html index 1065e05c2..ddd27f656 100644 --- a/examples/select2-bootstrap3.html +++ b/examples/select2-bootstrap3.html @@ -49,20 +49,35 @@
ui-select inside a Bootstrap form -
- -
+
+ +
+ + + {{$select.selected.name}} + +
+ +
+
+ +
+
- - {{$select.selected.name}} - -
- -
-
+
+ +
+ + + {{$select.selected.name}} + +
+ +
+
+
-
diff --git a/examples/selectize-bootstrap3.html b/examples/selectize-bootstrap3.html index 834407a08..141c811d6 100644 --- a/examples/selectize-bootstrap3.html +++ b/examples/selectize-bootstrap3.html @@ -64,20 +64,35 @@
ui-select inside a Bootstrap form -
- -
+
+ +
+ + + {{$select.selected.name}} + +
+ +
+
+ +
+
- - {{$select.selected.name}} - -
- -
-
+
+ +
+ + + {{$select.selected.name}} + +
+ +
+
+
-
From fe9547944f4e510635ba85c62c2af6a7cbad9c8d Mon Sep 17 00:00:00 2001 From: Chris Jackson Date: Tue, 28 Jul 2015 21:41:57 +0100 Subject: [PATCH 14/28] Remove watches on static options --- examples/bootstrap.html | 17 ++++++++++- src/uiSelectDirective.js | 62 +++++++++++++++++----------------------- 2 files changed, 42 insertions(+), 37 deletions(-) diff --git a/examples/bootstrap.html b/examples/bootstrap.html index 2cafd573a..a341cc6ed 100644 --- a/examples/bootstrap.html +++ b/examples/bootstrap.html @@ -72,7 +72,22 @@
-
+
+ +
+ + + {{$item.name}} + +
+ +
+
+ +
+
+ +
diff --git a/src/uiSelectDirective.js b/src/uiSelectDirective.js index ce9ed93b4..3645e67d2 100644 --- a/src/uiSelectDirective.js +++ b/src/uiSelectDirective.js @@ -62,15 +62,11 @@ uis.directive('uiSelect', }); } - scope.$watch('searchEnabled', function() { - var searchEnabled = scope.$eval(attrs.searchEnabled); - $select.searchEnabled = searchEnabled !== undefined ? searchEnabled : uiSelectConfig.searchEnabled; - }); + var searchEnabled = scope.$eval(attrs.searchEnabled); + $select.searchEnabled = searchEnabled !== undefined ? searchEnabled : uiSelectConfig.searchEnabled; - scope.$watch('sortable', function() { - var sortable = scope.$eval(attrs.sortable); - $select.sortable = sortable !== undefined ? sortable : uiSelectConfig.sortable; - }); + var sortable = scope.$eval(attrs.sortable); + $select.sortable = sortable !== undefined ? sortable : uiSelectConfig.sortable; attrs.$observe('disabled', function() { // No need to use $eval() (thanks to ng-disabled) since we already get a boolean instead of a string @@ -83,40 +79,34 @@ uis.directive('uiSelect', $select.resetSearchInput = resetSearchInput !== undefined ? resetSearchInput : true; }); - attrs.$observe('tagging', function() { - if(attrs.tagging !== undefined) - { - // $eval() is needed otherwise we get a string instead of a boolean - var taggingEval = scope.$eval(attrs.tagging); + if(attrs.tagging !== undefined) + { + // $eval() is needed otherwise we get a string instead of a boolean + var taggingEval = scope.$eval(attrs.tagging); $select.tagging = {isActivated: true, fct: taggingEval !== true ? taggingEval : undefined}; + } + else + { + $select.tagging = {isActivated: false, fct: undefined}; + } + + if(attrs.tagging !== undefined ) + { + // check eval for FALSE, in this case, we disable the labels + // associated with tagging + if ( attrs.taggingLabel === 'false' ) { + $select.taggingLabel = false; } else { - $select.tagging = {isActivated: false, fct: undefined}; - } - }); - - attrs.$observe('taggingLabel', function() { - if(attrs.tagging !== undefined ) - { - // check eval for FALSE, in this case, we disable the labels - // associated with tagging - if ( attrs.taggingLabel === 'false' ) { - $select.taggingLabel = false; - } - else - { - $select.taggingLabel = attrs.taggingLabel !== undefined ? attrs.taggingLabel : '(new)'; - } + $select.taggingLabel = attrs.taggingLabel !== undefined ? attrs.taggingLabel : '(new)'; } - }); + } - attrs.$observe('taggingTokens', function() { - if (attrs.tagging !== undefined) { - var tokens = attrs.taggingTokens !== undefined ? attrs.taggingTokens.split('|') : [',','ENTER']; - $select.taggingTokens = {isActivated: true, tokens: tokens }; - } - }); + if (attrs.tagging !== undefined) { + var tokens = attrs.taggingTokens !== undefined ? attrs.taggingTokens.split('|') : [',','ENTER']; + $select.taggingTokens = {isActivated: true, tokens: tokens }; + } //Automatically gets focus when loaded if (angular.isDefined(attrs.autofocus)){ From 86c2ab0ce9be69861af8444fd4ff916f66118226 Mon Sep 17 00:00:00 2001 From: Chris Jackson Date: Sat, 1 Aug 2015 13:01:49 +0100 Subject: [PATCH 15/28] Update to move search box off screen --- examples/bootstrap.html | 37 ++++++++++++++++++++++++----------- src/bootstrap/select.tpl.html | 2 +- src/uiSelectController.js | 10 ++++++++++ 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/examples/bootstrap.html b/examples/bootstrap.html index a1e362b46..051db596f 100644 --- a/examples/bootstrap.html +++ b/examples/bootstrap.html @@ -42,20 +42,35 @@
ui-select inside a Bootstrap form -
- -
+
+ +
+ + + {{$select.selected.name}} + +
+ +
+
+ +
+
- - {{$select.selected.name}} - -
- -
-
+
+ +
+ + {{$select.selected.name}} + +
+ +
+
+ +
-
diff --git a/src/bootstrap/select.tpl.html b/src/bootstrap/select.tpl.html index 880396a38..409135b67 100644 --- a/src/bootstrap/select.tpl.html +++ b/src/bootstrap/select.tpl.html @@ -8,6 +8,6 @@ class="form-control ui-select-search" placeholder="{{$select.placeholder}}" ng-model="$select.search" - ng-show="$select.searchEnabled && $select.open"> + ng-show="$select.open">
diff --git a/src/uiSelectController.js b/src/uiSelectController.js index c0a1a94ac..203fa4942 100644 --- a/src/uiSelectController.js +++ b/src/uiSelectController.js @@ -79,6 +79,9 @@ uis.controller('uiSelectCtrl', $scope.$broadcast('uis:activate'); ctrl.open = true; + if(!ctrl.searchEnabled) { + angular.element(ctrl.searchInput[0]).addClass('ui-select-offscreen'); + } ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex; @@ -94,6 +97,10 @@ uis.controller('uiSelectCtrl', ctrl.searchInput[0].focus(); }); } + else if (ctrl.open && !ctrl.searchEnabled) { + // Close the selection if we don't have search enabled, and we click on the select again + ctrl.close(); + } }; ctrl.findGroupByName = function(name) { @@ -312,6 +319,9 @@ uis.controller('uiSelectCtrl', if (ctrl.ngModel && ctrl.ngModel.$setTouched) ctrl.ngModel.$setTouched(); _resetSearchInput(); ctrl.open = false; + if(!ctrl.searchEnabled) { + angular.element(ctrl.searchInput[0]).removeClass('ui-select-offscreen'); + } $scope.$broadcast('uis:close', skipFocusser); From 1d9a673a33b9471356e09f6b7483bf36233cc6ae Mon Sep 17 00:00:00 2001 From: Chris Jackson Date: Sat, 1 Aug 2015 13:09:46 +0100 Subject: [PATCH 16/28] Fix test to check against ui-select-offscreen class, not ng-hide --- test/select.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/select.spec.js b/test/select.spec.js index 5f58b5f97..a2fd670f5 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -1307,13 +1307,13 @@ describe('ui-select tests', function() { it('should show search input when true', function() { setupSelectComponent('true', 'bootstrap'); clickMatch(el); - expect($(el).find('.ui-select-search')).not.toHaveClass('ng-hide'); + expect($(el).find('.ui-select-search')).not.toHaveClass('ui-select-offscreen'); }); it('should hide search input when false', function() { setupSelectComponent('false', 'bootstrap'); clickMatch(el); - expect($(el).find('.ui-select-search')).toHaveClass('ng-hide'); + expect($(el).find('.ui-select-search')).toHaveClass('ui-select-offscreen'); }); }); From af50d3646c67fdfd4717d0e995754f8b4ff4f744 Mon Sep 17 00:00:00 2001 From: Chris Jackson Date: Sun, 2 Aug 2015 12:32:57 +0100 Subject: [PATCH 17/28] Remove watch on refreshDelay --- src/uiSelectChoicesDirective.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/uiSelectChoicesDirective.js b/src/uiSelectChoicesDirective.js index 69e29b6cc..654f6496e 100644 --- a/src/uiSelectChoicesDirective.js +++ b/src/uiSelectChoicesDirective.js @@ -56,11 +56,9 @@ uis.directive('uiSelectChoices', $select.refresh(attrs.refresh); }); - attrs.$observe('refreshDelay', function() { - // $eval() is needed otherwise we get a string instead of a number - var refreshDelay = scope.$eval(attrs.refreshDelay); - $select.refreshDelay = refreshDelay !== undefined ? refreshDelay : uiSelectConfig.refreshDelay; - }); + // $eval() is needed otherwise we get a string instead of a number + var refreshDelay = scope.$eval(attrs.refreshDelay); + $select.refreshDelay = refreshDelay !== undefined ? refreshDelay : uiSelectConfig.refreshDelay; }; } }; From 287febf5a3253e255b2390d6f7ada2a9afe98453 Mon Sep 17 00:00:00 2001 From: Chris Jackson Date: Sun, 2 Aug 2015 13:12:56 +0100 Subject: [PATCH 18/28] Update search disabled example to remove search attributes --- examples/bootstrap.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/bootstrap.html b/examples/bootstrap.html index a341cc6ed..75735f9fe 100644 --- a/examples/bootstrap.html +++ b/examples/bootstrap.html @@ -63,9 +63,9 @@ {{$select.selected.name}} - -
- + +
+
From e0ba3f3343c11fe42bfdafe4802c37b0de48aa57 Mon Sep 17 00:00:00 2001 From: Chris Jackson Date: Sun, 2 Aug 2015 16:55:12 +0100 Subject: [PATCH 19/28] Initial refactoring to remove tagging and add lifecycle calls (+1 squashed commit) Squashed commits: [25d355a] Hacking!!! --- dist/select.bootstrap.js | 1521 +++++++++++++++++ dist/select.bootstrap.min.js | 7 + dist/select.css | 15 +- dist/select.js | 1837 +++++++++------------ dist/select.min.css | 4 +- dist/select.min.js | 5 +- dist/select.no-tpl.js | 1516 +++++++++++++++++ dist/select.no-tpl.min.js | 7 + dist/select.select2.js | 1521 +++++++++++++++++ dist/select.select2.min.js | 7 + dist/select.selectize.js | 1519 +++++++++++++++++ dist/select.selectize.min.js | 7 + dist/select.tpl.js | 21 + examples/newdemo.html | 174 ++ examples/newdemo.js | 534 ++++++ gulpfile.js | 238 ++- src/{ => addons}/uiSelectSortDirective.js | 0 src/uiSelectChoicesDirective.js | 2 +- src/uiSelectController.js | 1056 ++++++------ src/uiSelectDirective.js | 561 +++---- src/uiSelectMultipleDirective.js | 146 +- 21 files changed, 8589 insertions(+), 2109 deletions(-) create mode 100644 dist/select.bootstrap.js create mode 100644 dist/select.bootstrap.min.js create mode 100644 dist/select.no-tpl.js create mode 100644 dist/select.no-tpl.min.js create mode 100644 dist/select.select2.js create mode 100644 dist/select.select2.min.js create mode 100644 dist/select.selectize.js create mode 100644 dist/select.selectize.min.js create mode 100644 dist/select.tpl.js create mode 100644 examples/newdemo.html create mode 100644 examples/newdemo.js rename src/{ => addons}/uiSelectSortDirective.js (100%) diff --git a/dist/select.bootstrap.js b/dist/select.bootstrap.js new file mode 100644 index 000000000..6dacfe976 --- /dev/null +++ b/dist/select.bootstrap.js @@ -0,0 +1,1521 @@ +/*! + * ui-select + * http://github.com/angular-ui/ui-select + * Version: 0.12.1 - 2015-08-02T20:56:31.504Z + * License: MIT + */ + + +(function () { +"use strict"; + +var KEY = { + TAB: 9, + ENTER: 13, + ESC: 27, + SPACE: 32, + LEFT: 37, + UP: 38, + RIGHT: 39, + DOWN: 40, + SHIFT: 16, + CTRL: 17, + ALT: 18, + PAGE_UP: 33, + PAGE_DOWN: 34, + HOME: 36, + END: 35, + BACKSPACE: 8, + DELETE: 46, + COMMAND: 91, + + MAP: { 91 : "COMMAND", 8 : "BACKSPACE" , 9 : "TAB" , 13 : "ENTER" , 16 : "SHIFT" , 17 : "CTRL" , 18 : "ALT" , 19 : "PAUSEBREAK" , 20 : "CAPSLOCK" , 27 : "ESC" , 32 : "SPACE" , 33 : "PAGE_UP", 34 : "PAGE_DOWN" , 35 : "END" , 36 : "HOME" , 37 : "LEFT" , 38 : "UP" , 39 : "RIGHT" , 40 : "DOWN" , 43 : "+" , 44 : "PRINTSCREEN" , 45 : "INSERT" , 46 : "DELETE", 48 : "0" , 49 : "1" , 50 : "2" , 51 : "3" , 52 : "4" , 53 : "5" , 54 : "6" , 55 : "7" , 56 : "8" , 57 : "9" , 59 : ";", 61 : "=" , 65 : "A" , 66 : "B" , 67 : "C" , 68 : "D" , 69 : "E" , 70 : "F" , 71 : "G" , 72 : "H" , 73 : "I" , 74 : "J" , 75 : "K" , 76 : "L", 77 : "M" , 78 : "N" , 79 : "O" , 80 : "P" , 81 : "Q" , 82 : "R" , 83 : "S" , 84 : "T" , 85 : "U" , 86 : "V" , 87 : "W" , 88 : "X" , 89 : "Y" , 90 : "Z", 96 : "0" , 97 : "1" , 98 : "2" , 99 : "3" , 100 : "4" , 101 : "5" , 102 : "6" , 103 : "7" , 104 : "8" , 105 : "9", 106 : "*" , 107 : "+" , 109 : "-" , 110 : "." , 111 : "/", 112 : "F1" , 113 : "F2" , 114 : "F3" , 115 : "F4" , 116 : "F5" , 117 : "F6" , 118 : "F7" , 119 : "F8" , 120 : "F9" , 121 : "F10" , 122 : "F11" , 123 : "F12", 144 : "NUMLOCK" , 145 : "SCROLLLOCK" , 186 : ";" , 187 : "=" , 188 : "," , 189 : "-" , 190 : "." , 191 : "/" , 192 : "`" , 219 : "[" , 220 : "\\" , 221 : "]" , 222 : "'" + }, + + isControl: function (e) { + var k = e.which; + switch (k) { + case KEY.COMMAND: + case KEY.SHIFT: + case KEY.CTRL: + case KEY.ALT: + return true; + } + + if (e.metaKey) return true; + + return false; + }, + isFunctionKey: function (k) { + k = k.which ? k.which : k; + return k >= 112 && k <= 123; + }, + isVerticalMovement: function (k){ + return ~[KEY.UP, KEY.DOWN].indexOf(k); + }, + isHorizontalMovement: function (k){ + return ~[KEY.LEFT,KEY.RIGHT,KEY.BACKSPACE,KEY.DELETE].indexOf(k); + } + }; + +/** + * Add querySelectorAll() to jqLite. + * + * jqLite find() is limited to lookups by tag name. + * TODO This will change with future versions of AngularJS, to be removed when this happens + * + * See jqLite.find - why not use querySelectorAll? https://github.com/angular/angular.js/issues/3586 + * See feat(jqLite): use querySelectorAll instead of getElementsByTagName in jqLite.find https://github.com/angular/angular.js/pull/3598 + */ +if (angular.element.prototype.querySelectorAll === undefined) { + angular.element.prototype.querySelectorAll = function(selector) { + return angular.element(this[0].querySelectorAll(selector)); + }; +} + +/** + * Add closest() to jqLite. + */ +if (angular.element.prototype.closest === undefined) { + angular.element.prototype.closest = function( selector) { + var elem = this[0]; + var matchesSelector = elem.matches || elem.webkitMatchesSelector || elem.mozMatchesSelector || elem.msMatchesSelector; + + while (elem) { + if (matchesSelector.bind(elem)(selector)) { + return elem; + } else { + elem = elem.parentElement; + } + } + return false; + }; +} + +var latestId = 0; + +var uis = angular.module('ui.select', []) + +.constant('uiSelectConfig', { + theme: 'bootstrap', + searchEnabled: true, + sortable: false, + placeholder: '', // Empty by default, like HTML tag "); + $compile(focusser)(scope); + $select.focusser = focusser; + + //Input that will handle focus + $select.focusInput = focusser; + + element.parent().append(focusser); + focusser.bind("focus", function(){ + scope.$evalAsync(function(){ + $select.focus = true; + }); + }); + focusser.bind("blur", function(){ + scope.$evalAsync(function(){ + $select.focus = false; + }); + }); + focusser.bind("keydown", function(e){ + + if (e.which === KEY.BACKSPACE) { + e.preventDefault(); + e.stopPropagation(); + $select.select(undefined); + scope.$apply(); + return; + } + + if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) { + return; + } + + if (e.which == KEY.DOWN || e.which == KEY.UP || e.which == KEY.ENTER || e.which == KEY.SPACE){ + e.preventDefault(); + e.stopPropagation(); + $select.activate(); + } + + scope.$digest(); + }); + + focusser.bind("keyup input", function(e){ + + if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { + return; + } + + $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input + focusser.val(''); + scope.$digest(); + + }); + + + } + }; +}]); +/** + * Parses "repeat" attribute. + * + * Taken from AngularJS ngRepeat source code + * See https://github.com/angular/angular.js/blob/v1.2.15/src/ng/directive/ngRepeat.js#L211 + * + * Original discussion about parsing "repeat" attribute instead of fully relying on ng-repeat: + * https://github.com/angular-ui/ui-select/commit/5dd63ad#commitcomment-5504697 + */ + +uis.service('uisRepeatParser', ['uiSelectMinErr','$parse', function(uiSelectMinErr, $parse) { + var self = this; + + /** + * Example: + * expression = "address in addresses | filter: {street: $select.search} track by $index" + * itemName = "address", + * source = "addresses | filter: {street: $select.search}", + * trackByExp = "$index", + */ + self.parse = function(expression) { + + var match = expression.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/); + + if (!match) { + throw uiSelectMinErr('iexp', "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.", + expression); + } + + return { + itemName: match[2], // (lhs) Left-hand side, + source: $parse(match[3]), + trackByExp: match[4], + modelMapper: $parse(match[1] || match[2]) + }; + + }; + + self.getGroupNgRepeatExpression = function() { + return '$group in $select.groups'; + }; + + self.getNgRepeatExpression = function(itemName, source, trackByExp, grouped) { + var expression = itemName + ' in ' + (grouped ? '$group.items' : source); + if (trackByExp) { + expression += ' track by ' + trackByExp; + } + return expression; + }; +}]); + +}()); +angular.module("ui.select").run(["$templateCache", function($templateCache) {$templateCache.put("bootstrap/choices.tpl.html","
    0\">
  • 0\">
"); +$templateCache.put("bootstrap/match-multiple.tpl.html"," × "); +$templateCache.put("bootstrap/match.tpl.html","
"); +$templateCache.put("bootstrap/select-multiple.tpl.html","
"); +$templateCache.put("bootstrap/select.tpl.html","
");}]); \ No newline at end of file diff --git a/dist/select.bootstrap.min.js b/dist/select.bootstrap.min.js new file mode 100644 index 000000000..ccfbc8736 --- /dev/null +++ b/dist/select.bootstrap.min.js @@ -0,0 +1,7 @@ +/*! + * ui-select + * http://github.com/angular-ui/ui-select + * Version: 0.12.1 - 2015-08-02T20:56:31.504Z + * License: MIT + */ +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var n=t.which;switch(n){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,n=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",refreshDelay:1e3,closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,i,c){c(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var i=n[0].getBoundingClientRect();return{width:i.width||n.prop("offsetWidth"),height:i.height||n.prop("offsetHeight"),top:i.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:i.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);n.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(c,l){if(!l.repeat)throw n("repeat","Expected 'repeat' expression.");return function(c,l,s,r,a){var o=s.groupBy,u=s.groupFilter;if(r.parseRepeatAttr(s.repeat,o,u),r.disableChoiceExpression=s.uiDisableChoice,r.onHighlightCallback=s.onHighlight,r.refreshOnActive=c.$eval(s.refreshOnActive),o){var p=l.querySelectorAll(".ui-select-choices-group");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",p.length);p.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=l.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(r.parserResult.itemName,"$select.items",r.parserResult.trackByExp,o)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+r.parserResult.itemName+")").attr("ng-click","$select.select("+r.parserResult.itemName+",false,$event)");var h=l.querySelectorAll(".ui-select-choices-row-inner");if(1!==h.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",h.length);h.attr("uis-transclude-append",""),i(l,a)(c),c.$watch("$select.search",function(e){e&&!r.open&&r.multiple&&r.activate(!1,!0),r.activeIndex=0,(!r.refreshOnActive||r.refreshOnActive&&r.refreshIsActive)&&r.refresh(s.refresh)}),c.$watch("$select.refreshIsActive",function(e,t){angular.isUndefined(t)&&e&&r.refresh(s.refresh)});var f=c.$eval(s.refreshDelay);r.refreshDelay=void 0!==f?f:e.refreshDelay}}}}]),n.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,n,i,c,l,s,r,a){function o(){(h.resetSearchInput||void 0===h.resetSearchInput&&a.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var n,i,c=[];for(n=0;n0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:n=!1}return n}function d(){var e=n.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw r("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var i=t[h.activeIndex],c=i.offsetTop+i.clientHeight-e[0].scrollTop,l=e[0].offsetHeight;c>l?e[0].scrollTop+=c-l:c=h.items.length?0:h.activeIndex,h.refreshIsActive=!0,i(function(){h.search=e||h.search,h.searchInput[0].focus()}))},h.findGroupByName=function(e){return h.groups&&h.groups.filter(function(t){return t.name===e})[0]},h.parseRepeatAttr=function(e,n,i){function c(e){var c=t.$eval(n);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(c)?c(e):e[c],n=h.findGroupByName(t);n?n.items.push(e):h.groups.push({name:t,items:[e]})}),i){var l=t.$eval(i);angular.isFunction(l)?h.groups=l(h.groups):angular.isArray(l)&&(h.groups=u(h.groups,l))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function l(e){h.items=e}h.setItemsFn=n?c:l,h.parserResult=s.parse(e),h.isGrouped=!!n,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var n=h.selected;if(h.isEmpty()||angular.isArray(n)&&!n.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var i=e.filter(function(e){return n.indexOf(e)<0});h.setItemsFn(i)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw r("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})};var v;h.refresh=function(e){void 0!==e&&(v&&i.cancel(v),v=i(function(){t.$eval(e)},h.refreshDelay))},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),n=t===h.activeIndex;return n&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),n},h.isDisabled=function(e){if(!h.open)return!1;var t,n=h.items.indexOf(e[h.itemProperty]),i=!1;return n>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[n],i=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i},h.select=function(e,n,c){if(void 0===e||!e._uiSelectChoiceDisabled){if(!h.items&&!h.search)return;if(!e||!e._uiSelectChoiceDisabled){var l=function(){t.$broadcast("uis:select",e),i(function(){h.onSelectCallback(t,r)}),h.closeOnSelect&&h.close(n),c&&"click"===c.type&&(h.clickTriggeredSelect=!0)},s={};s[h.parserResult.itemName]=e;var r={$item:e,$model:h.parserResult.modelMapper(t,s)},a=h.onBeforeSelectCallback(t,r);if(angular.isDefined(a)){if(!a)return;angular.isFunction(a.then)?a.then(function(e){e&&l(e)}):a===!0?l(e):l(a)}else l(e)}}},h.close=function(e){h.open&&(h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),o(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e))},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),i(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var n,i=h.selected[t];return i&&!angular.isUndefined(h.lockChoiceExpression)&&(n=!!e.$eval(h.lockChoiceExpression),i._uiSelectChoiceLocked=n),n};var g=null;h.sizeSearchInput=function(){var e=h.searchInput[0],n=h.searchInput.parent().parent()[0],c=function(){return n.clientWidth*!!e.offsetParent},l=function(t){if(0===t)return!1;var n=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=t),h.searchInput.css("width",n+"px"),!0};h.searchInput.css("width","10px"),i(function(){null!==g||l(c())||(g=t.$watch(c,function(e){l(e)&&(g(),g=null)}))})},h.searchInput.on("keydown",function(n){var i=n.which;t.$apply(function(){p(i)}),e.isVerticalMovement(i)&&h.items.length>0&&d(),(i===e.ENTER||i===e.ESC)&&(n.preventDefault(),n.stopPropagation())}),h.searchInput.on("keyup",function(n){n.which===e.TAB||e.isControl(n)||e.isFunctionKey(n)||n.which===e.ESC||e.isVerticalMovement(n.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:n})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),n.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,i,c,l,s){return{restrict:"EA",templateUrl:function(e,n){var i=n.theme||t.theme;return i+(angular.isDefined(n.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(c,r){return angular.isDefined(r.multiple)?c.append("").removeAttr("multiple"):c.append(""),function(c,r,a,o,u){function p(e){if(f.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(r[0],e.target):r[0].contains(e.target),!t&&!f.clickTriggeredSelect){var n=["input","button","textarea"],i=angular.element(e.target).scope(),l=i&&i.$select&&i.$select!==f;l||(l=~n.indexOf(e.target.tagName.toLowerCase())),f.close(l),c.$digest()}f.clickTriggeredSelect=!1}}function d(){var t=i(r);b=angular.element('
'),b[0].style.width=t.width+"px",b[0].style.height=t.height+"px",r.after(b),E=r[0].style.width,e.find("body").append(r),r[0].style.position="absolute",r[0].style.left=t.left+"px",r[0].style.top=t.top+"px",r[0].style.width=t.width+"px"}function h(){null!==b&&(b.replaceWith(r),b=null,r[0].style.position="",r[0].style.left="",r[0].style.top="",r[0].style.width=E)}var f=o[0],v=o[1];f.generatedId=t.generateId(),f.baseTitle=a.title||"Select box",f.focusserTitle=f.baseTitle+" focus",f.focusserId="focusser-"+f.generatedId,f.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?l(a.closeOnSelect)():t.closeOnSelect}(),f.onBeforeSelectCallback=l(a.onBeforeSelect),f.onSelectCallback=l(a.onSelect),f.onRemoveCallback=l(a.onRemove),f.onKeypressCallback=l(a.onKeypress),f.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,f.ngModel=v,f.choiceGrouped=function(e){return f.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){f.focusInput.attr("tabindex",e),r.removeAttr("tabindex")});var g=c.$eval(a.searchEnabled);f.searchEnabled=void 0!==g?g:t.searchEnabled;var m=c.$eval(a.sortable);f.sortable=void 0!==m?m:t.sortable,a.$observe("disabled",function(){f.disabled=void 0!==a.disabled?a.disabled:!1}),a.$observe("resetSearchInput",function(){var e=c.$eval(a.resetSearchInput);f.resetSearchInput=void 0!==e?e:!0}),angular.isDefined(a.autofocus)&&s(function(){f.setFocus()}),angular.isDefined(a.focusOn)&&c.$on(a.focusOn,function(){s(function(){f.setFocus()})}),e.on("click",p),c.$on("$destroy",function(){e.off("click",p)}),u(c,function(e){var t=angular.element("
").append(e),i=t.querySelectorAll(".ui-select-match");if(i.removeAttr("ui-select-match"),i.removeAttr("data-ui-select-match"),1!==i.length)throw n("transcluded","Expected 1 .ui-select-match but got '{0}'.",i.length);r.querySelectorAll(".ui-select-match").replaceWith(i);var c=t.querySelectorAll(".ui-select-choices");if(c.removeAttr("ui-select-choices"),c.removeAttr("data-ui-select-choices"),1!==c.length)throw n("transcluded","Expected 1 .ui-select-choices but got '{0}'.",c.length);r.querySelectorAll(".ui-select-choices").replaceWith(c)});var $=c.$eval(a.appendToBody);(void 0!==$?$:t.appendToBody)&&(c.$watch("$select.open",function(e){e?d():h()}),c.$on("$destroy",function(){h()}));var b=null,E="",y=null,w="direction-up";c.$watch("$select.open",function(t){if(t){if(y=angular.element(r).querySelectorAll(".ui-select-dropdown"),null===y)return;y[0].style.opacity=0,s(function(){var t=i(r),n=i(y);t.top+t.height+n.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&(y[0].style.position="absolute",y[0].style.top=-1*n.height+"px",r.addClass(w)),y[0].style.opacity=1})}else{if(null===y)return;y[0].style.position="",y[0].style.top="",r.removeClass(w)}})}}}}]),n.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return n+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,i,c){function l(e){c.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}c.lockChoiceExpression=i.uiLockChoice,i.$observe("placeholder",function(t){c.placeholder=void 0!==t?t:e.placeholder}),i.$observe("allowClear",l),l(i.allowClear),c.multiple&&c.sizeSearchInput()}}}]),n.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,i=this,c=e.$select;e.$evalAsync(function(){n=e.ngModel}),i.activeMatchIndex=-1,i.updateModel=function(){n.$setViewValue(Date.now()),i.refreshComponent()},i.refreshComponent=function(){c.refreshItems(),c.sizeSearchInput()},i.removeChoice=function(n){var l=c.selected[n];if(!l._uiSelectChoiceLocked){var s={};s[c.parserResult.itemName]=l,c.selected.splice(n,1),i.activeMatchIndex=-1,c.sizeSearchInput(),t(function(){c.onRemoveCallback(e,{$item:l,$model:c.parserResult.modelMapper(e,s)})}),i.updateModel()}},i.getPlaceholder=function(){return c.selected&&c.selected.length?void 0:c.placeholder}}],controllerAs:"$selectMultiple",link:function(i,c,l,s){function r(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(t){function n(){switch(t){case e.LEFT:return~p.activeMatchIndex?d:s;case e.RIGHT:return~p.activeMatchIndex&&a!==s?u:(o.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(a),d):s;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),a):!1}}var i=r(o.searchInput[0]),c=o.selected.length,l=0,s=c-1,a=p.activeMatchIndex,u=p.activeMatchIndex+1,d=p.activeMatchIndex-1,h=a;return i>0||o.search.length&&t==e.RIGHT?!1:(o.close(),h=n(),p.activeMatchIndex=o.selected.length&&h!==!1?Math.min(s,Math.max(l,h)):-1,!0)}var o=s[0],u=i.ngModel=s[1],p=i.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,u.$parsers.unshift(function(){for(var e,t={},n=[],c=o.selected.length-1;c>=0;c--)t={},t[o.parserResult.itemName]=o.selected[c],e=o.parserResult.modelMapper(i,t),n.unshift(e);return n}),u.$formatters.unshift(function(e){var t,n=o.parserResult.source(i,{$select:{search:""}}),c={};if(!n)return e;var l=[],s=function(e,n){if(e&&e.length){for(var s=e.length-1;s>=0;s--){if(c[o.parserResult.itemName]=e[s],t=o.parserResult.modelMapper(i,c),o.parserResult.trackByExp){var r=/\.(.+)/.exec(o.parserResult.trackByExp);if(r.length>0&&t[r[1]]==n[r[1]])return l.unshift(e[s]),!0}if(angular.equals(t,n))return l.unshift(e[s]),!0}return!1}};if(!e)return l;for(var r=e.length-1;r>=0;r--)s(o.selected,e[r])||s(n,e[r])||l.unshift(e[r]);return l}),i.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);o.selected=[]}o.selected=u.$viewValue,i.$evalAsync()},i.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),p.updateModel())}),i.$on("uis:activate",function(){p.activeMatchIndex=-1}),i.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(t){var n=t.which;i.$apply(function(){var t=!1;e.isHorizontalMovement(n)&&(t=a(n)),t&&n!=e.TAB})}),o.searchInput.on("blur",function(){n(function(){p.activeMatchIndex=-1})})}}}]),n.directive("uiSelectSingle",["$timeout","$compile",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(i,c,l,s){var r=s[0],a=s[1];a.$parsers.unshift(function(e){var t,n={};return n[r.parserResult.itemName]=e,t=r.parserResult.modelMapper(i,n)}),a.$formatters.unshift(function(e){var t,n=r.parserResult.source(i,{$select:{search:""}}),c={};if(n){var l=function(n){return c[r.parserResult.itemName]=n,t=r.parserResult.modelMapper(i,c),t==e};if(r.selected&&l(r.selected))return r.selected;for(var s=n.length-1;s>=0;s--)if(l(n[s]))return n[s]}return e}),i.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){r.selected=a.$viewValue},i.$on("uis:select",function(e,t){r.selected=t}),i.$on("uis:close",function(e,n){t(function(){r.focusser.prop("disabled",!1),n||r.focusser[0].focus()},0,!1)}),i.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");n(o)(i),r.focusser=o,r.focusInput=o,c.parent().append(o),o.bind("focus",function(){i.$evalAsync(function(){r.focus=!0})}),o.bind("blur",function(){i.$evalAsync(function(){r.focus=!1})}),o.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),r.select(void 0),i.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),r.activate()),i.$digest()),void 0)}),o.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(r.activate(o.val()),o.val(""),i.$digest())})}}}]),n.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var i=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!i)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:i[2],source:t(i[3]),trackByExp:i[4],modelMapper:t(i[1]||i[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,i){var c=e+" in "+(i?"$group.items":t);return n&&(c+=" track by "+n),c}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",'
{{$select.placeholder}}
'),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",'')}]); \ No newline at end of file diff --git a/dist/select.css b/dist/select.css index fe2b1da3b..b4d99a09e 100644 --- a/dist/select.css +++ b/dist/select.css @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-07-28T03:50:59.080Z + * Version: 0.12.1 - 2015-08-02T20:56:31.552Z * License: MIT */ @@ -215,6 +215,19 @@ body > .ui-select-bootstrap.open { border-right: 1px solid #428bca; } +.ui-select-bootstrap .ui-select-placeholder { + color: #999; + opacity: 1; +} + +.ui-select-bootstrap .ui-select-placeholder { + color: #999; +} + +.ui-select-bootstrap .ui-select-placeholder { + color: #999; +} + .ui-select-bootstrap .ui-select-choices-row>a { display: block; padding: 3px 20px; diff --git a/dist/select.js b/dist/select.js index 8ba040885..f86c7c7e6 100644 --- a/dist/select.js +++ b/dist/select.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-07-28T03:50:59.076Z + * Version: 0.12.1 - 2015-08-02T20:56:31.549Z * License: MIT */ @@ -197,6 +197,8 @@ uis.directive('uiSelectChoices', $select.disableChoiceExpression = attrs.uiDisableChoice; $select.onHighlightCallback = attrs.onHighlight; + $select.refreshOnActive = scope.$eval(attrs.refreshOnActive); + if(groupByExp) { var groups = element.querySelectorAll('.ui-select-choices-group'); if (groups.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-group but got '{0}'.", groups.length); @@ -221,15 +223,21 @@ uis.directive('uiSelectChoices', scope.$watch('$select.search', function(newValue) { if(newValue && !$select.open && $select.multiple) $select.activate(false, true); - $select.activeIndex = $select.tagging.isActivated ? -1 : 0; - $select.refresh(attrs.refresh); + $select.activeIndex = 0; + if(!$select.refreshOnActive || ($select.refreshOnActive && $select.refreshIsActive)) { + $select.refresh(attrs.refresh); + } }); - attrs.$observe('refreshDelay', function() { - // $eval() is needed otherwise we get a string instead of a number - var refreshDelay = scope.$eval(attrs.refreshDelay); - $select.refreshDelay = refreshDelay !== undefined ? refreshDelay : uiSelectConfig.refreshDelay; + scope.$watch('$select.refreshIsActive', function(newValue, oldValue){ + if(angular.isUndefined(oldValue) && newValue){ + $select.refresh(attrs.refresh); + } }); + + // $eval() is needed otherwise we get a string instead of a number + var refreshDelay = scope.$eval(attrs.refreshDelay); + $select.refreshDelay = refreshDelay !== undefined ? refreshDelay : uiSelectConfig.refreshDelay; }; } }; @@ -242,817 +250,797 @@ uis.directive('uiSelectChoices', * put as much logic in the controller (instead of the link functions) as possible so it can be easily tested. */ uis.controller('uiSelectCtrl', - ['$scope', '$element', '$timeout', '$filter', 'uisRepeatParser', 'uiSelectMinErr', 'uiSelectConfig', - function($scope, $element, $timeout, $filter, RepeatParser, uiSelectMinErr, uiSelectConfig) { - - var ctrl = this; - - var EMPTY_SEARCH = ''; - - ctrl.placeholder = uiSelectConfig.placeholder; - ctrl.searchEnabled = uiSelectConfig.searchEnabled; - ctrl.sortable = uiSelectConfig.sortable; - ctrl.refreshDelay = uiSelectConfig.refreshDelay; - - ctrl.removeSelected = false; //If selected item(s) should be removed from dropdown list - ctrl.closeOnSelect = true; //Initialized inside uiSelect directive link function - ctrl.search = EMPTY_SEARCH; - - ctrl.activeIndex = 0; //Dropdown of choices - ctrl.items = []; //All available choices - - ctrl.open = false; - ctrl.focus = false; - ctrl.disabled = false; - ctrl.selected = undefined; - - ctrl.focusser = undefined; //Reference to input element used to handle focus events - ctrl.resetSearchInput = true; - ctrl.multiple = undefined; // Initialized inside uiSelect directive link function - ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelectChoices directive link function - ctrl.tagging = {isActivated: false, fct: undefined}; - ctrl.taggingTokens = {isActivated: false, tokens: undefined}; - ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelectMatch directive link function - ctrl.clickTriggeredSelect = false; - ctrl.$filter = $filter; - - ctrl.searchInput = $element.querySelectorAll('input.ui-select-search'); - if (ctrl.searchInput.length !== 1) { - throw uiSelectMinErr('searchInput', "Expected 1 input.ui-select-search but got '{0}'.", ctrl.searchInput.length); - } - - ctrl.isEmpty = function() { - return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === ''; - }; - - // Most of the time the user does not want to empty the search input when in typeahead mode - function _resetSearchInput() { - if (ctrl.resetSearchInput || (ctrl.resetSearchInput === undefined && uiSelectConfig.resetSearchInput)) { - ctrl.search = EMPTY_SEARCH; - //reset activeIndex - if (ctrl.selected && ctrl.items.length && !ctrl.multiple) { - ctrl.activeIndex = ctrl.items.indexOf(ctrl.selected); - } - } - } - - function _groupsFilter(groups, groupNames) { - var i, j, result = []; - for(i = 0; i < groupNames.length ;i++){ - for(j = 0; j < groups.length ;j++){ - if(groups[j].name == [groupNames[i]]){ - result.push(groups[j]); - } - } - } - return result; - } - - // When the user clicks on ui-select, displays the dropdown list - ctrl.activate = function(initSearchValue, avoidReset) { - if (!ctrl.disabled && !ctrl.open) { - if(!avoidReset) _resetSearchInput(); - - $scope.$broadcast('uis:activate'); - - ctrl.open = true; - - ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex; - - // ensure that the index is set to zero for tagging variants - // that where first option is auto-selected - if ( ctrl.activeIndex === -1 && ctrl.taggingLabel !== false ) { - ctrl.activeIndex = 0; - } - - // Give it time to appear before focus - $timeout(function() { - ctrl.search = initSearchValue || ctrl.search; - ctrl.searchInput[0].focus(); - }); - } - }; - - ctrl.findGroupByName = function(name) { - return ctrl.groups && ctrl.groups.filter(function(group) { - return group.name === name; - })[0]; - }; - - ctrl.parseRepeatAttr = function(repeatAttr, groupByExp, groupFilterExp) { - function updateGroups(items) { - var groupFn = $scope.$eval(groupByExp); - ctrl.groups = []; - angular.forEach(items, function(item) { - var groupName = angular.isFunction(groupFn) ? groupFn(item) : item[groupFn]; - var group = ctrl.findGroupByName(groupName); - if(group) { - group.items.push(item); - } - else { - ctrl.groups.push({name: groupName, items: [item]}); - } - }); - if(groupFilterExp){ - var groupFilterFn = $scope.$eval(groupFilterExp); - if( angular.isFunction(groupFilterFn)){ - ctrl.groups = groupFilterFn(ctrl.groups); - } else if(angular.isArray(groupFilterFn)){ - ctrl.groups = _groupsFilter(ctrl.groups, groupFilterFn); - } - } - ctrl.items = []; - ctrl.groups.forEach(function(group) { - ctrl.items = ctrl.items.concat(group.items); - }); - } - - function setPlainItems(items) { - ctrl.items = items; - } - - ctrl.setItemsFn = groupByExp ? updateGroups : setPlainItems; - - ctrl.parserResult = RepeatParser.parse(repeatAttr); - - ctrl.isGrouped = !!groupByExp; - ctrl.itemProperty = ctrl.parserResult.itemName; - - ctrl.refreshItems = function (data){ - data = data || ctrl.parserResult.source($scope); - var selectedItems = ctrl.selected; - //TODO should implement for single mode removeSelected - if ((angular.isArray(selectedItems) && !selectedItems.length) || !ctrl.removeSelected) { - ctrl.setItemsFn(data); - }else{ - if ( data !== undefined ) { - var filteredItems = data.filter(function(i) {return selectedItems.indexOf(i) < 0;}); - ctrl.setItemsFn(filteredItems); - } - } - }; - - // See https://github.com/angular/angular.js/blob/v1.2.15/src/ng/directive/ngRepeat.js#L259 - $scope.$watchCollection(ctrl.parserResult.source, function(items) { - if (items === undefined || items === null) { - // If the user specifies undefined or null => reset the collection - // Special case: items can be undefined if the user did not initialized the collection on the scope - // i.e $scope.addresses = [] is missing - ctrl.items = []; - } else { - if (!angular.isArray(items)) { - throw uiSelectMinErr('items', "Expected an array but got '{0}'.", items); - } else { - //Remove already selected items (ex: while searching) - //TODO Should add a test - ctrl.refreshItems(items); - ctrl.ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters - } - } - }); - - }; - - var _refreshDelayPromise; - - /** - * Typeahead mode: lets the user refresh the collection using his own function. - * - * See Expose $select.search for external / remote filtering https://github.com/angular-ui/ui-select/pull/31 - */ - ctrl.refresh = function(refreshAttr) { - if (refreshAttr !== undefined) { - - // Debounce - // See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L155 - // FYI AngularStrap typeahead does not have debouncing: https://github.com/mgcrea/angular-strap/blob/v2.0.0-rc.4/src/typeahead/typeahead.js#L177 - if (_refreshDelayPromise) { - $timeout.cancel(_refreshDelayPromise); - } - _refreshDelayPromise = $timeout(function() { - $scope.$eval(refreshAttr); - }, ctrl.refreshDelay); - } - }; - - ctrl.setActiveItem = function(item) { - ctrl.activeIndex = ctrl.items.indexOf(item); - }; - - ctrl.isActive = function(itemScope) { - if ( !ctrl.open ) { - return false; - } - var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); - var isActive = itemIndex === ctrl.activeIndex; - - if ( !isActive || ( itemIndex < 0 && ctrl.taggingLabel !== false ) ||( itemIndex < 0 && ctrl.taggingLabel === false) ) { - return false; - } - - if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { - itemScope.$eval(ctrl.onHighlightCallback); - } - - return isActive; - }; - - ctrl.isDisabled = function(itemScope) { - - if (!ctrl.open) return; - - var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); - var isDisabled = false; - var item; - - if (itemIndex >= 0 && !angular.isUndefined(ctrl.disableChoiceExpression)) { - item = ctrl.items[itemIndex]; - isDisabled = !!(itemScope.$eval(ctrl.disableChoiceExpression)); // force the boolean value - item._uiSelectChoiceDisabled = isDisabled; // store this for later reference - } - - return isDisabled; - }; - - - // When the user selects an item with ENTER or clicks the dropdown - ctrl.select = function(item, skipFocusser, $event) { - if (item === undefined || !item._uiSelectChoiceDisabled) { - - if ( ! ctrl.items && ! ctrl.search ) return; - - if (!item || !item._uiSelectChoiceDisabled) { - if(ctrl.tagging.isActivated) { - // if taggingLabel is disabled, we pull from ctrl.search val - if ( ctrl.taggingLabel === false ) { - if ( ctrl.activeIndex < 0 ) { - item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : ctrl.search; - if (!item || angular.equals( ctrl.items[0], item ) ) { - return; - } - } else { - // keyboard nav happened first, user selected from dropdown - item = ctrl.items[ctrl.activeIndex]; - } - } else { - // tagging always operates at index zero, taggingLabel === false pushes - // the ctrl.search value without having it injected - if ( ctrl.activeIndex === 0 ) { - // ctrl.tagging pushes items to ctrl.items, so we only have empty val - // for `item` if it is a detected duplicate - if ( item === undefined ) return; - - // create new item on the fly if we don't already have one; - // use tagging function if we have one - if ( ctrl.tagging.fct !== undefined && typeof item === 'string' ) { - item = ctrl.tagging.fct(ctrl.search); - if (!item) return; - // if item type is 'string', apply the tagging label - } else if ( typeof item === 'string' ) { - // trim the trailing space - item = item.replace(ctrl.taggingLabel,'').trim(); - } + ['$scope', '$element', '$timeout', '$filter', '$q', 'uisRepeatParser', 'uiSelectMinErr', 'uiSelectConfig', + function ($scope, $element, $timeout, $filter, $q, RepeatParser, uiSelectMinErr, uiSelectConfig) { + + var ctrl = this; + + var EMPTY_SEARCH = ''; + + ctrl.placeholder = uiSelectConfig.placeholder; + ctrl.searchEnabled = uiSelectConfig.searchEnabled; + ctrl.sortable = uiSelectConfig.sortable; + ctrl.refreshDelay = uiSelectConfig.refreshDelay; + + ctrl.removeSelected = false; //If selected item(s) should be removed from dropdown list + ctrl.closeOnSelect = true; //Initialized inside uiSelect directive link function + ctrl.search = EMPTY_SEARCH; + + ctrl.activeIndex = 0; //Dropdown of choices + ctrl.items = []; //All available choices + + ctrl.open = false; + ctrl.focus = false; + ctrl.disabled = false; + ctrl.selected = undefined; + + ctrl.focusser = undefined; //Reference to input element used to handle focus events + ctrl.resetSearchInput = true; + ctrl.multiple = undefined; // Initialized inside uiSelect directive link function + ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelectChoices directive link function + ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelectMatch directive link function + ctrl.clickTriggeredSelect = false; + ctrl.$filter = $filter; + ctrl.refreshOnActive = undefined; + ctrl.refreshIsActive = undefined; + + ctrl.searchInput = $element.querySelectorAll('input.ui-select-search'); + if (ctrl.searchInput.length !== 1) { + throw uiSelectMinErr('searchInput', "Expected 1 input.ui-select-search but got '{0}'.", + ctrl.searchInput.length); } - } - // search ctrl.selected for dupes potentially caused by tagging and return early if found - if ( ctrl.selected && angular.isArray(ctrl.selected) && ctrl.selected.filter( function (selection) { return angular.equals(selection, item); }).length > 0 ) { - ctrl.close(skipFocusser); - return; - } - } - - $scope.$broadcast('uis:select', item); - - var locals = {}; - locals[ctrl.parserResult.itemName] = item; - - $timeout(function(){ - ctrl.onSelectCallback($scope, { - $item: item, - $model: ctrl.parserResult.modelMapper($scope, locals) - }); - }); - - if (ctrl.closeOnSelect) { - ctrl.close(skipFocusser); - } - if ($event && $event.type === 'click') { - ctrl.clickTriggeredSelect = true; - } - } - } - }; - - // Closes the dropdown - ctrl.close = function(skipFocusser) { - if (!ctrl.open) return; - if (ctrl.ngModel && ctrl.ngModel.$setTouched) ctrl.ngModel.$setTouched(); - _resetSearchInput(); - ctrl.open = false; - - $scope.$broadcast('uis:close', skipFocusser); - - }; - - ctrl.setFocus = function(){ - if (!ctrl.focus) ctrl.focusInput[0].focus(); - }; - - ctrl.clear = function($event) { - ctrl.select(undefined); - $event.stopPropagation(); - $timeout(function() { - ctrl.focusser[0].focus(); - }, 0, false); - }; - - // Toggle dropdown - ctrl.toggle = function(e) { - if (ctrl.open) { - ctrl.close(); - e.preventDefault(); - e.stopPropagation(); - } else { - ctrl.activate(); - } - }; - - ctrl.isLocked = function(itemScope, itemIndex) { - var isLocked, item = ctrl.selected[itemIndex]; - - if (item && !angular.isUndefined(ctrl.lockChoiceExpression)) { - isLocked = !!(itemScope.$eval(ctrl.lockChoiceExpression)); // force the boolean value - item._uiSelectChoiceLocked = isLocked; // store this for later reference - } - - return isLocked; - }; - - var sizeWatch = null; - ctrl.sizeSearchInput = function() { - - var input = ctrl.searchInput[0], - container = ctrl.searchInput.parent().parent()[0], - calculateContainerWidth = function() { - // Return the container width only if the search input is visible - return container.clientWidth * !!input.offsetParent; - }, - updateIfVisible = function(containerWidth) { - if (containerWidth === 0) { - return false; - } - var inputWidth = containerWidth - input.offsetLeft - 10; - if (inputWidth < 50) inputWidth = containerWidth; - ctrl.searchInput.css('width', inputWidth+'px'); - return true; - }; - - ctrl.searchInput.css('width', '10px'); - $timeout(function() { //Give tags time to render correctly - if (sizeWatch === null && !updateIfVisible(calculateContainerWidth())) { - sizeWatch = $scope.$watch(calculateContainerWidth, function(containerWidth) { - if (updateIfVisible(containerWidth)) { - sizeWatch(); - sizeWatch = null; - } - }); - } - }); - }; - - function _handleDropDownSelection(key) { - var processed = true; - switch (key) { - case KEY.DOWN: - if (!ctrl.open && ctrl.multiple) ctrl.activate(false, true); //In case its the search input in 'multiple' mode - else if (ctrl.activeIndex < ctrl.items.length - 1) { ctrl.activeIndex++; } - break; - case KEY.UP: - if (!ctrl.open && ctrl.multiple) ctrl.activate(false, true); //In case its the search input in 'multiple' mode - else if (ctrl.activeIndex > 0 || (ctrl.search.length === 0 && ctrl.tagging.isActivated && ctrl.activeIndex > -1)) { ctrl.activeIndex--; } - break; - case KEY.TAB: - if (!ctrl.multiple || ctrl.open) ctrl.select(ctrl.items[ctrl.activeIndex], true); - break; - case KEY.ENTER: - if(ctrl.open && (ctrl.tagging.isActivated || ctrl.activeIndex >= 0)){ - ctrl.select(ctrl.items[ctrl.activeIndex]); // Make sure at least one dropdown item is highlighted before adding if not in tagging mode - } else { - ctrl.activate(false, true); //In case its the search input in 'multiple' mode - } - break; - case KEY.ESC: - ctrl.close(); - break; - default: - processed = false; - } - return processed; - } - - // Bind to keyboard shortcuts - ctrl.searchInput.on('keydown', function(e) { - - var key = e.which; - - // if(~[KEY.ESC,KEY.TAB].indexOf(key)){ - // //TODO: SEGURO? - // ctrl.close(); - // } - - $scope.$apply(function() { - - var tagged = false; - if (ctrl.items.length > 0 || ctrl.tagging.isActivated) { - _handleDropDownSelection(key); - if ( ctrl.taggingTokens.isActivated ) { - for (var i = 0; i < ctrl.taggingTokens.tokens.length; i++) { - if ( ctrl.taggingTokens.tokens[i] === KEY.MAP[e.keyCode] ) { - // make sure there is a new value to push via tagging - if ( ctrl.search.length > 0 ) { - tagged = true; - } + ctrl.isEmpty = function () { + return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === ''; + }; + + // Most of the time the user does not want to empty the search input when in typeahead mode + function _resetSearchInput() { + if (ctrl.resetSearchInput || (ctrl.resetSearchInput === undefined && uiSelectConfig.resetSearchInput)) { + ctrl.search = EMPTY_SEARCH; + //reset activeIndex + if (ctrl.selected && ctrl.items.length && !ctrl.multiple) { + ctrl.activeIndex = ctrl.items.indexOf(ctrl.selected); + } + } } - } - if ( tagged ) { - $timeout(function() { - ctrl.searchInput.triggerHandler('tagged'); - var newItem = ctrl.search.replace(KEY.MAP[e.keyCode],'').trim(); - if ( ctrl.tagging.fct ) { - newItem = ctrl.tagging.fct( newItem ); - } - if (newItem) ctrl.select(newItem, true); - }); - } - } - } - - }); - if(KEY.isVerticalMovement(key) && ctrl.items.length > 0){ - _ensureHighlightVisible(); - } + function _groupsFilter(groups, groupNames) { + var i, j, result = []; + for (i = 0; i < groupNames.length; i++) { + for (j = 0; j < groups.length; j++) { + if (groups[j].name == [groupNames[i]]) { + result.push(groups[j]); + } + } + } + return result; + } - if (key === KEY.ENTER || key === KEY.ESC) { - e.preventDefault(); - e.stopPropagation(); - } + // When the user clicks on ui-select, displays the dropdown list + ctrl.activate = function (initSearchValue, avoidReset) { + if (!ctrl.disabled && !ctrl.open) { + if (!avoidReset) _resetSearchInput(); - }); - - // If tagging try to split by tokens and add items - ctrl.searchInput.on('paste', function (e) { - var data = e.originalEvent.clipboardData.getData('text/plain'); - if (data && data.length > 0 && ctrl.taggingTokens.isActivated && ctrl.tagging.fct) { - var items = data.split(ctrl.taggingTokens.tokens[0]); // split by first token only - if (items && items.length > 0) { - angular.forEach(items, function (item) { - var newItem = ctrl.tagging.fct(item); - if (newItem) { - ctrl.select(newItem, true); - } - }); - e.preventDefault(); - e.stopPropagation(); - } - } - }); - - ctrl.searchInput.on('tagged', function() { - $timeout(function() { - _resetSearchInput(); - }); - }); - - // See https://github.com/ivaynberg/select2/blob/3.4.6/select2.js#L1431 - function _ensureHighlightVisible() { - var container = $element.querySelectorAll('.ui-select-choices-content'); - var choices = container.querySelectorAll('.ui-select-choices-row'); - if (choices.length < 1) { - throw uiSelectMinErr('choices', "Expected multiple .ui-select-choices-row but got '{0}'.", choices.length); - } + $scope.$broadcast('uis:activate'); - if (ctrl.activeIndex < 0) { - return; - } + ctrl.open = true; + if (!ctrl.searchEnabled) { + angular.element(ctrl.searchInput[0]).addClass('ui-select-offscreen'); + } - var highlighted = choices[ctrl.activeIndex]; - var posY = highlighted.offsetTop + highlighted.clientHeight - container[0].scrollTop; - var height = container[0].offsetHeight; - - if (posY > height) { - container[0].scrollTop += posY - height; - } else if (posY < highlighted.clientHeight) { - if (ctrl.isGrouped && ctrl.activeIndex === 0) - container[0].scrollTop = 0; //To make group header visible when going all the way up - else - container[0].scrollTop -= highlighted.clientHeight - posY; - } - } + ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex; + ctrl.refreshIsActive = true; - $scope.$on('$destroy', function() { - ctrl.searchInput.off('keyup keydown tagged blur paste'); - }); + // Give it time to appear before focus + $timeout(function () { + ctrl.search = initSearchValue || ctrl.search; + ctrl.searchInput[0].focus(); + }); + } + else if (ctrl.open && !ctrl.searchEnabled) { + // Close the selection if we don't have search enabled, and we click on the select again + ctrl.close(); + } + }; + + ctrl.findGroupByName = function (name) { + return ctrl.groups && ctrl.groups.filter(function (group) { + return group.name === name; + })[0]; + }; + + ctrl.parseRepeatAttr = function (repeatAttr, groupByExp, groupFilterExp) { + function updateGroups(items) { + var groupFn = $scope.$eval(groupByExp); + ctrl.groups = []; + angular.forEach(items, function (item) { + var groupName = angular.isFunction(groupFn) ? groupFn(item) : item[groupFn]; + var group = ctrl.findGroupByName(groupName); + if (group) { + group.items.push(item); + } + else { + ctrl.groups.push({name: groupName, items: [item]}); + } + }); + if (groupFilterExp) { + var groupFilterFn = $scope.$eval(groupFilterExp); + if (angular.isFunction(groupFilterFn)) { + ctrl.groups = groupFilterFn(ctrl.groups); + } else if (angular.isArray(groupFilterFn)) { + ctrl.groups = _groupsFilter(ctrl.groups, groupFilterFn); + } + } + ctrl.items = []; + ctrl.groups.forEach(function (group) { + ctrl.items = ctrl.items.concat(group.items); + }); + } -}]); + function setPlainItems(items) { + ctrl.items = items; + } -uis.directive('uiSelect', - ['$document', 'uiSelectConfig', 'uiSelectMinErr', 'uisOffset', '$compile', '$parse', '$timeout', - function($document, uiSelectConfig, uiSelectMinErr, uisOffset, $compile, $parse, $timeout) { + ctrl.setItemsFn = groupByExp ? updateGroups : setPlainItems; + + ctrl.parserResult = RepeatParser.parse(repeatAttr); + + ctrl.isGrouped = !!groupByExp; + ctrl.itemProperty = ctrl.parserResult.itemName; + + ctrl.refreshItems = function (data) { + data = data || ctrl.parserResult.source($scope); + var selectedItems = ctrl.selected; + //TODO should implement for single mode removeSelected + if (ctrl.isEmpty() || (angular.isArray(selectedItems) && !selectedItems.length) || + !ctrl.removeSelected) { + ctrl.setItemsFn(data); + } else { + if (data !== undefined) { + var filteredItems = data.filter(function (i) { + return selectedItems.indexOf(i) < 0; + }); + ctrl.setItemsFn(filteredItems); + } + } + }; + + // See https://github.com/angular/angular.js/blob/v1.2.15/src/ng/directive/ngRepeat.js#L259 + $scope.$watchCollection(ctrl.parserResult.source, function (items) { + if (items === undefined || items === null) { + // If the user specifies undefined or null => reset the collection + // Special case: items can be undefined if the user did not initialized the collection on the scope + // i.e $scope.addresses = [] is missing + ctrl.items = []; + } else { + if (!angular.isArray(items)) { + throw uiSelectMinErr('items', "Expected an array but got '{0}'.", items); + } else { + //Remove already selected items (ex: while searching) + //TODO Should add a test + ctrl.refreshItems(items); + ctrl.ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters + } + } + }); - return { - restrict: 'EA', - templateUrl: function(tElement, tAttrs) { - var theme = tAttrs.theme || uiSelectConfig.theme; - return theme + (angular.isDefined(tAttrs.multiple) ? '/select-multiple.tpl.html' : '/select.tpl.html'); - }, - replace: true, - transclude: true, - require: ['uiSelect', '^ngModel'], - scope: true, + }; + + var _refreshDelayPromise; + + /** + * Typeahead mode: lets the user refresh the collection using his own function. + * + * See Expose $select.search for external / remote filtering https://github.com/angular-ui/ui-select/pull/31 + */ + ctrl.refresh = function (refreshAttr) { + if (refreshAttr !== undefined) { + + // Debounce + // See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L155 + // FYI AngularStrap typeahead does not have debouncing: https://github.com/mgcrea/angular-strap/blob/v2.0.0-rc.4/src/typeahead/typeahead.js#L177 + if (_refreshDelayPromise) { + $timeout.cancel(_refreshDelayPromise); + } + _refreshDelayPromise = $timeout(function () { + $scope.$eval(refreshAttr); + }, ctrl.refreshDelay); + } + }; - controller: 'uiSelectCtrl', - controllerAs: '$select', - compile: function(tElement, tAttrs) { + ctrl.setActiveItem = function (item) { + ctrl.activeIndex = ctrl.items.indexOf(item); + }; - //Multiple or Single depending if multiple attribute presence - if (angular.isDefined(tAttrs.multiple)) - tElement.append("").removeAttr('multiple'); - else - tElement.append(""); + ctrl.isActive = function (itemScope) { + if (!ctrl.open) { + return false; + } + var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); + var isActive = itemIndex === ctrl.activeIndex; - return function(scope, element, attrs, ctrls, transcludeFn) { + if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { + itemScope.$eval(ctrl.onHighlightCallback); + } - var $select = ctrls[0]; - var ngModel = ctrls[1]; + return isActive; + }; - $select.generatedId = uiSelectConfig.generateId(); - $select.baseTitle = attrs.title || 'Select box'; - $select.focusserTitle = $select.baseTitle + ' focus'; - $select.focusserId = 'focusser-' + $select.generatedId; + /** + * Checks if the item is disabled + * @return boolean true if the item is disabled + */ + ctrl.isDisabled = function (itemScope) { - $select.closeOnSelect = function() { - if (angular.isDefined(attrs.closeOnSelect)) { - return $parse(attrs.closeOnSelect)(); - } else { - return uiSelectConfig.closeOnSelect; - } - }(); + if (!ctrl.open) return false; - $select.onSelectCallback = $parse(attrs.onSelect); - $select.onRemoveCallback = $parse(attrs.onRemove); - - //Set reference to ngModel from uiSelectCtrl - $select.ngModel = ngModel; + var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); + var isDisabled = false; + var item; - $select.choiceGrouped = function(group){ - return $select.isGrouped && group && group.name; - }; + if (itemIndex >= 0 && !angular.isUndefined(ctrl.disableChoiceExpression)) { + item = ctrl.items[itemIndex]; + isDisabled = !!(itemScope.$eval(ctrl.disableChoiceExpression)); // force the boolean value + item._uiSelectChoiceDisabled = isDisabled; // store this for later reference + } - if(attrs.tabindex){ - attrs.$observe('tabindex', function(value) { - $select.focusInput.attr("tabindex", value); - element.removeAttr("tabindex"); - }); - } + return isDisabled; + }; + + + /** + * Called when the user selects an item with ENTER or clicks the dropdown + */ + ctrl.select = function (item, skipFocusser, $event) { + if (item === undefined || !item._uiSelectChoiceDisabled) { + + if (!ctrl.items && !ctrl.search){ + return; + } + + if (!item || !item._uiSelectChoiceDisabled) { + + var completeSelection = function () { + $scope.$broadcast('uis:select', item); + + $timeout(function () { + ctrl.onSelectCallback($scope, callbackContext); + }); + + if (ctrl.closeOnSelect) { + ctrl.close(skipFocusser); + } + if ($event && $event.type === 'click') { + ctrl.clickTriggeredSelect = true; + } + }; + + var locals = {}; + locals[ctrl.parserResult.itemName] = item; + + var callbackContext = { + $item: item, + $model: ctrl.parserResult.modelMapper($scope, locals) + }; + + // Call the onBeforeSelect callback + // Allowable responses are -: + // falsy: Abort the selection + // promise: Wait for response + // true: Complete selection + // object: Add the returned object + var onBeforeSelectResult = ctrl.onBeforeSelectCallback($scope, callbackContext); + if (angular.isDefined(onBeforeSelectResult)) { + if (!onBeforeSelectResult) { + return; // abort the selection in case of deliberate falsey result + } else if (angular.isFunction(onBeforeSelectResult.then)) { + onBeforeSelectResult.then(function (result) { + if (!result) { + return; + } + completeSelection(result); + }); + } else if (onBeforeSelectResult === true) { + completeSelection(item); + } else { + completeSelection(onBeforeSelectResult); + } + } else { + completeSelection(item); + } + } + } + }; - scope.$watch('searchEnabled', function() { - var searchEnabled = scope.$eval(attrs.searchEnabled); - $select.searchEnabled = searchEnabled !== undefined ? searchEnabled : uiSelectConfig.searchEnabled; - }); + // Closes the dropdown + ctrl.close = function (skipFocusser) { + if (!ctrl.open) { + return; + } + if (ctrl.ngModel && ctrl.ngModel.$setTouched) ctrl.ngModel.$setTouched(); + _resetSearchInput(); + ctrl.open = false; + if (!ctrl.searchEnabled) { + angular.element(ctrl.searchInput[0]).removeClass('ui-select-offscreen'); + } - scope.$watch('sortable', function() { - var sortable = scope.$eval(attrs.sortable); - $select.sortable = sortable !== undefined ? sortable : uiSelectConfig.sortable; - }); + $scope.$broadcast('uis:close', skipFocusser); + }; - attrs.$observe('disabled', function() { - // No need to use $eval() (thanks to ng-disabled) since we already get a boolean instead of a string - $select.disabled = attrs.disabled !== undefined ? attrs.disabled : false; - }); + ctrl.setFocus = function () { + if (!ctrl.focus) { + ctrl.focusInput[0].focus(); + } + }; + + ctrl.clear = function ($event) { + ctrl.select(undefined); + $event.stopPropagation(); + $timeout(function () { + ctrl.focusser[0].focus(); + }, 0, false); + }; + + // Toggle dropdown + ctrl.toggle = function (e) { + if (ctrl.open) { + ctrl.close(); + e.preventDefault(); + e.stopPropagation(); + } else { + ctrl.activate(); + } + }; - attrs.$observe('resetSearchInput', function() { - // $eval() is needed otherwise we get a string instead of a boolean - var resetSearchInput = scope.$eval(attrs.resetSearchInput); - $select.resetSearchInput = resetSearchInput !== undefined ? resetSearchInput : true; - }); + ctrl.isLocked = function (itemScope, itemIndex) { + var isLocked, item = ctrl.selected[itemIndex]; - attrs.$observe('tagging', function() { - if(attrs.tagging !== undefined) - { - // $eval() is needed otherwise we get a string instead of a boolean - var taggingEval = scope.$eval(attrs.tagging); - $select.tagging = {isActivated: true, fct: taggingEval !== true ? taggingEval : undefined}; - } - else - { - $select.tagging = {isActivated: false, fct: undefined}; - } - }); + if (item && !angular.isUndefined(ctrl.lockChoiceExpression)) { + isLocked = !!(itemScope.$eval(ctrl.lockChoiceExpression)); // force the boolean value + item._uiSelectChoiceLocked = isLocked; // store this for later reference + } - attrs.$observe('taggingLabel', function() { - if(attrs.tagging !== undefined ) - { - // check eval for FALSE, in this case, we disable the labels - // associated with tagging - if ( attrs.taggingLabel === 'false' ) { - $select.taggingLabel = false; - } - else - { - $select.taggingLabel = attrs.taggingLabel !== undefined ? attrs.taggingLabel : '(new)'; + return isLocked; + }; + + var sizeWatch = null; + ctrl.sizeSearchInput = function () { + + var input = ctrl.searchInput[0], + container = ctrl.searchInput.parent().parent()[0], + calculateContainerWidth = function () { + // Return the container width only if the search input is visible + return container.clientWidth * !!input.offsetParent; + }, + updateIfVisible = function (containerWidth) { + if (containerWidth === 0) { + return false; + } + var inputWidth = containerWidth - input.offsetLeft - ctrl.searchInput.parent()[0].offsetLeft - + 5; + if (inputWidth < 50) { + inputWidth = containerWidth; + } + ctrl.searchInput.css('width', inputWidth + 'px'); + return true; + }; + + ctrl.searchInput.css('width', '10px'); + $timeout(function () { //Give time to render correctly + if (sizeWatch === null && !updateIfVisible(calculateContainerWidth())) { + sizeWatch = $scope.$watch(calculateContainerWidth, function (containerWidth) { + if (updateIfVisible(containerWidth)) { + sizeWatch(); + sizeWatch = null; + } + }); + } + }); + }; + + function _handleDropDownSelection(key) { + var processed = true; + switch (key) { + case KEY.DOWN: + if (!ctrl.open && ctrl.multiple) { + ctrl.activate(false, true); //In case its the search input in 'multiple' mode + } + else if (ctrl.activeIndex < ctrl.items.length - 1) { + ctrl.activeIndex++; + } + break; + case KEY.UP: + if (!ctrl.open && ctrl.multiple) { + ctrl.activate(false, true); + } //In case its the search input in 'multiple' mode + else if (ctrl.activeIndex > 0) { + ctrl.activeIndex--; + } + break; + case KEY.TAB: + if (!ctrl.multiple || ctrl.open) ctrl.select(ctrl.items[ctrl.activeIndex], true); + break; + case KEY.ENTER: + if (ctrl.open) { + // Make sure at least one dropdown item is highlighted before adding + ctrl.select(ctrl.items[ctrl.activeIndex]); + } else { + // In case its the search input in 'multiple' mode + ctrl.activate(false, true); + } + break; + case KEY.ESC: + ctrl.close(); + break; + default: + processed = false; + } + return processed; } - } - }); - - attrs.$observe('taggingTokens', function() { - if (attrs.tagging !== undefined) { - var tokens = attrs.taggingTokens !== undefined ? attrs.taggingTokens.split('|') : [',','ENTER']; - $select.taggingTokens = {isActivated: true, tokens: tokens }; - } - }); - - //Automatically gets focus when loaded - if (angular.isDefined(attrs.autofocus)){ - $timeout(function(){ - $select.setFocus(); - }); - } - - //Gets focus based on scope event name (e.g. focus-on='SomeEventName') - if (angular.isDefined(attrs.focusOn)){ - scope.$on(attrs.focusOn, function() { - $timeout(function(){ - $select.setFocus(); - }); - }); - } - - function onDocumentClick(e) { - if (!$select.open) return; //Skip it if dropdown is close - - var contains = false; - - if (window.jQuery) { - // Firefox 3.6 does not support element.contains() - // See Node.contains https://developer.mozilla.org/en-US/docs/Web/API/Node.contains - contains = window.jQuery.contains(element[0], e.target); - } else { - contains = element[0].contains(e.target); - } - - if (!contains && !$select.clickTriggeredSelect) { - //Will lose focus only with certain targets - var focusableControls = ['input','button','textarea']; - var targetScope = angular.element(e.target).scope(); //To check if target is other ui-select - var skipFocusser = targetScope && targetScope.$select && targetScope.$select !== $select; //To check if target is other ui-select - if (!skipFocusser) skipFocusser = ~focusableControls.indexOf(e.target.tagName.toLowerCase()); //Check if target is input, button or textarea - $select.close(skipFocusser); - scope.$digest(); - } - $select.clickTriggeredSelect = false; - } - - // See Click everywhere but here event http://stackoverflow.com/questions/12931369 - $document.on('click', onDocumentClick); - scope.$on('$destroy', function() { - $document.off('click', onDocumentClick); - }); - - // Move transcluded elements to their correct position in main template - transcludeFn(scope, function(clone) { - // See Transclude in AngularJS http://blog.omkarpatil.com/2012/11/transclude-in-angularjs.html + // Bind to keyboard shortcuts + ctrl.searchInput.on('keydown', function (e) { - // One day jqLite will be replaced by jQuery and we will be able to write: - // var transcludedElement = clone.filter('.my-class') - // instead of creating a hackish DOM element: - var transcluded = angular.element('
').append(clone); + var key = e.which; - var transcludedMatch = transcluded.querySelectorAll('.ui-select-match'); - transcludedMatch.removeAttr('ui-select-match'); //To avoid loop in case directive as attr - transcludedMatch.removeAttr('data-ui-select-match'); // Properly handle HTML5 data-attributes - if (transcludedMatch.length !== 1) { - throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-match but got '{0}'.", transcludedMatch.length); - } - element.querySelectorAll('.ui-select-match').replaceWith(transcludedMatch); + // if(~[KEY.ESC,KEY.TAB].indexOf(key)){ + // //TODO: SEGURO? + // ctrl.close(); + // } - var transcludedChoices = transcluded.querySelectorAll('.ui-select-choices'); - transcludedChoices.removeAttr('ui-select-choices'); //To avoid loop in case directive as attr - transcludedChoices.removeAttr('data-ui-select-choices'); // Properly handle HTML5 data-attributes - if (transcludedChoices.length !== 1) { - throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-choices but got '{0}'.", transcludedChoices.length); - } - element.querySelectorAll('.ui-select-choices').replaceWith(transcludedChoices); - }); - - // Support for appending the select field to the body when its open - var appendToBody = scope.$eval(attrs.appendToBody); - if (appendToBody !== undefined ? appendToBody : uiSelectConfig.appendToBody) { - scope.$watch('$select.open', function(isOpen) { - if (isOpen) { - positionDropdown(); - } else { - resetDropdown(); - } - }); - - // Move the dropdown back to its original location when the scope is destroyed. Otherwise - // it might stick around when the user routes away or the select field is otherwise removed - scope.$on('$destroy', function() { - resetDropdown(); - }); - } - - // Hold on to a reference to the .ui-select-container element for appendToBody support - var placeholder = null, - originalWidth = ''; - - function positionDropdown() { - // Remember the absolute position of the element - var offset = uisOffset(element); + $scope.$apply(function () { + _handleDropDownSelection(key); + }); - // Clone the element into a placeholder element to take its original place in the DOM - placeholder = angular.element('
'); - placeholder[0].style.width = offset.width + 'px'; - placeholder[0].style.height = offset.height + 'px'; - element.after(placeholder); + if (KEY.isVerticalMovement(key) && ctrl.items.length > 0) { + _ensureHighlightVisible(); + } - // Remember the original value of the element width inline style, so it can be restored - // when the dropdown is closed - originalWidth = element[0].style.width; + if (key === KEY.ENTER || key === KEY.ESC) { + e.preventDefault(); + e.stopPropagation(); + } + }); - // Now move the actual dropdown element to the end of the body - $document.find('body').append(element); + // If tagging try to split by tokens and add items + /* ctrl.searchInput.on('paste', function (e) { + var data = e.originalEvent.clipboardData.getData('text/plain'); + if (data && data.length > 0 && ctrl.taggingTokens.isActivated && ctrl.tagging.fct) { + var items = data.split(ctrl.taggingTokens.tokens[0]); // split by first token only + if (items && items.length > 0) { + angular.forEach(items, function (item) { + var newItem = ctrl.tagging.fct(item); + if (newItem) { + ctrl.select(newItem, true); + } + }); + e.preventDefault(); + e.stopPropagation(); + } + } + });*/ - element[0].style.position = 'absolute'; - element[0].style.left = offset.left + 'px'; - element[0].style.top = offset.top + 'px'; - element[0].style.width = offset.width + 'px'; - } + ctrl.searchInput.on('keyup', function (e) { + // return early with these keys + if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || + KEY.isVerticalMovement(e.which)) { + return; + } - function resetDropdown() { - if (placeholder === null) { - // The dropdown has not actually been display yet, so there's nothing to reset - return; - } + if (ctrl.onKeypressCallback === undefined) { + return; + } + ctrl.onKeypressCallback($scope, {event: e}); + }); - // Move the dropdown element back to its original location in the DOM - placeholder.replaceWith(element); - placeholder = null; - element[0].style.position = ''; - element[0].style.left = ''; - element[0].style.top = ''; - element[0].style.width = originalWidth; - } + // See https://github.com/ivaynberg/select2/blob/3.4.6/select2.js#L1431 + function _ensureHighlightVisible() { + var container = $element.querySelectorAll('.ui-select-choices-content'); + var choices = container.querySelectorAll('.ui-select-choices-row'); + if (choices.length < 1) { + throw uiSelectMinErr('choices', "Expected multiple .ui-select-choices-row but got '{0}'.", + choices.length); + } - // Hold on to a reference to the .ui-select-dropdown element for direction support. - var dropdown = null, - directionUpClassName = 'direction-up'; + if (ctrl.activeIndex < 0) { + return; + } - // Support changing the direction of the dropdown if there isn't enough space to render it. - scope.$watch('$select.open', function(isOpen) { - if (isOpen) { - dropdown = angular.element(element).querySelectorAll('.ui-select-dropdown'); - if (dropdown === null) { - return; + var highlighted = choices[ctrl.activeIndex]; + var posY = highlighted.offsetTop + highlighted.clientHeight - container[0].scrollTop; + var height = container[0].offsetHeight; + + if (posY > height) { + container[0].scrollTop += posY - height; + } else if (posY < highlighted.clientHeight) { + if (ctrl.isGrouped && ctrl.activeIndex === 0) + container[0].scrollTop = 0; //To make group header visible when going all the way up + else + container[0].scrollTop -= highlighted.clientHeight - posY; + } } - // Hide the dropdown so there is no flicker until $timeout is done executing. - dropdown[0].style.opacity = 0; - - // Delay positioning the dropdown until all choices have been added so its height is correct. - $timeout(function(){ - var offset = uisOffset(element); - var offsetDropdown = uisOffset(dropdown); - - // Determine if the direction of the dropdown needs to be changed. - if (offset.top + offset.height + offsetDropdown.height > $document[0].documentElement.scrollTop + $document[0].documentElement.clientHeight) { - dropdown[0].style.position = 'absolute'; - dropdown[0].style.top = (offsetDropdown.height * -1) + 'px'; - element.addClass(directionUpClassName); - } - - // Display the dropdown once it has been positioned. - dropdown[0].style.opacity = 1; + $scope.$on('$destroy', function () { + ctrl.searchInput.off('keyup keydown blur paste'); }); - } else { - if (dropdown === null) { - return; - } - // Reset the position of the dropdown. - dropdown[0].style.position = ''; - dropdown[0].style.top = ''; - element.removeClass(directionUpClassName); - } - }); - }; - } - }; -}]); + }]); + +uis.directive('uiSelect', + ['$document', 'uiSelectConfig', 'uiSelectMinErr', 'uisOffset', '$compile', '$parse', '$timeout', + function ($document, uiSelectConfig, uiSelectMinErr, uisOffset, $compile, $parse, $timeout) { + + return { + restrict: 'EA', + templateUrl: function (tElement, tAttrs) { + var theme = tAttrs.theme || uiSelectConfig.theme; + return theme + + (angular.isDefined(tAttrs.multiple) ? '/select-multiple.tpl.html' : '/select.tpl.html'); + }, + replace: true, + transclude: true, + require: ['uiSelect', '^ngModel'], + scope: true, + controller: 'uiSelectCtrl', + controllerAs: '$select', + compile: function (tElement, tAttrs) { + + //Multiple or Single depending if multiple attribute presence + if (angular.isDefined(tAttrs.multiple)) + tElement.append("").removeAttr('multiple'); + else + tElement.append(""); + + return function (scope, element, attrs, ctrls, transcludeFn) { + + var $select = ctrls[0]; + var ngModel = ctrls[1]; + + $select.generatedId = uiSelectConfig.generateId(); + $select.baseTitle = attrs.title || 'Select box'; + $select.focusserTitle = $select.baseTitle + ' focus'; + $select.focusserId = 'focusser-' + $select.generatedId; + + $select.closeOnSelect = function () { + if (angular.isDefined(attrs.closeOnSelect)) { + return $parse(attrs.closeOnSelect)(); + } else { + return uiSelectConfig.closeOnSelect; + } + }(); + + $select.onBeforeSelectCallback = $parse(attrs.onBeforeSelect); + $select.onSelectCallback = $parse(attrs.onSelect); + $select.onRemoveCallback = $parse(attrs.onRemove); + $select.onKeypressCallback = $parse(attrs.onKeypress); + + //Limit the number of selections allowed + $select.limit = (angular.isDefined(attrs.limit)) ? parseInt(attrs.limit, 10) : undefined; + + //Set reference to ngModel from uiSelectCtrl + $select.ngModel = ngModel; + + $select.choiceGrouped = function (group) { + return $select.isGrouped && group && group.name; + }; + + if (attrs.tabindex) { + attrs.$observe('tabindex', function (value) { + $select.focusInput.attr("tabindex", value); + element.removeAttr("tabindex"); + }); + } + + var searchEnabled = scope.$eval(attrs.searchEnabled); + $select.searchEnabled = + searchEnabled !== undefined ? searchEnabled : uiSelectConfig.searchEnabled; + + var sortable = scope.$eval(attrs.sortable); + $select.sortable = sortable !== undefined ? sortable : uiSelectConfig.sortable; + + attrs.$observe('disabled', function () { + // No need to use $eval() (thanks to ng-disabled) since we already get a boolean instead of a string + $select.disabled = attrs.disabled !== undefined ? attrs.disabled : false; + }); + + attrs.$observe('resetSearchInput', function () { + // $eval() is needed otherwise we get a string instead of a boolean + var resetSearchInput = scope.$eval(attrs.resetSearchInput); + $select.resetSearchInput = resetSearchInput !== undefined ? resetSearchInput : true; + }); + + //Automatically gets focus when loaded + if (angular.isDefined(attrs.autofocus)) { + $timeout(function () { + $select.setFocus(); + }); + } + + //Gets focus based on scope event name (e.g. focus-on='SomeEventName') + if (angular.isDefined(attrs.focusOn)) { + scope.$on(attrs.focusOn, function () { + $timeout(function () { + $select.setFocus(); + }); + }); + } + + function onDocumentClick(e) { + if (!$select.open) return; //Skip it if dropdown is close + + var contains = false; + + if (window.jQuery) { + // Firefox 3.6 does not support element.contains() + // See Node.contains https://developer.mozilla.org/en-US/docs/Web/API/Node.contains + contains = window.jQuery.contains(element[0], e.target); + } else { + contains = element[0].contains(e.target); + } + + if (!contains && !$select.clickTriggeredSelect) { + //Will lose focus only with certain targets + var focusableControls = ['input', 'button', 'textarea']; + //To check if target is other ui-select + var targetScope = angular.element(e.target).scope(); + //To check if target is other ui-select + var skipFocusser = targetScope && targetScope.$select && + targetScope.$select !== $select; + //Check if target is input, button or textarea + if (!skipFocusser) { + skipFocusser = ~focusableControls.indexOf(e.target.tagName.toLowerCase()); + } + $select.close(skipFocusser); + scope.$digest(); + } + $select.clickTriggeredSelect = false; + } + + // See Click everywhere but here event http://stackoverflow.com/questions/12931369 + $document.on('click', onDocumentClick); + + scope.$on('$destroy', function () { + $document.off('click', onDocumentClick); + }); + + // Move transcluded elements to their correct position in main template + transcludeFn(scope, function (clone) { + // See Transclude in AngularJS http://blog.omkarpatil.com/2012/11/transclude-in-angularjs.html + + // One day jqLite will be replaced by jQuery and we will be able to write: + // var transcludedElement = clone.filter('.my-class') + // instead of creating a hackish DOM element: + var transcluded = angular.element('
').append(clone); + + var transcludedMatch = transcluded.querySelectorAll('.ui-select-match'); + transcludedMatch.removeAttr('ui-select-match'); //To avoid loop in case directive as attr + transcludedMatch.removeAttr('data-ui-select-match'); // Properly handle HTML5 data-attributes + if (transcludedMatch.length !== 1) { + throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-match but got '{0}'.", + transcludedMatch.length); + } + element.querySelectorAll('.ui-select-match').replaceWith(transcludedMatch); + + var transcludedChoices = transcluded.querySelectorAll('.ui-select-choices'); + transcludedChoices.removeAttr('ui-select-choices'); //To avoid loop in case directive as attr + transcludedChoices.removeAttr('data-ui-select-choices'); // Properly handle HTML5 data-attributes + if (transcludedChoices.length !== 1) { + throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-choices but got '{0}'.", + transcludedChoices.length); + } + element.querySelectorAll('.ui-select-choices').replaceWith(transcludedChoices); + }); + + // Support for appending the select field to the body when its open + var appendToBody = scope.$eval(attrs.appendToBody); + if (appendToBody !== undefined ? appendToBody : uiSelectConfig.appendToBody) { + scope.$watch('$select.open', function (isOpen) { + if (isOpen) { + positionDropdown(); + } else { + resetDropdown(); + } + }); + + // Move the dropdown back to its original location when the scope is destroyed. Otherwise + // it might stick around when the user routes away or the select field is otherwise removed + scope.$on('$destroy', function () { + resetDropdown(); + }); + } + + // Hold on to a reference to the .ui-select-container element for appendToBody support + var placeholder = null, + originalWidth = ''; + + function positionDropdown() { + // Remember the absolute position of the element + var offset = uisOffset(element); + + // Clone the element into a placeholder element to take its original place in the DOM + placeholder = angular.element('
'); + placeholder[0].style.width = offset.width + 'px'; + placeholder[0].style.height = offset.height + 'px'; + element.after(placeholder); + + // Remember the original value of the element width inline style, so it can be restored + // when the dropdown is closed + originalWidth = element[0].style.width; + + // Now move the actual dropdown element to the end of the body + $document.find('body').append(element); + + element[0].style.position = 'absolute'; + element[0].style.left = offset.left + 'px'; + element[0].style.top = offset.top + 'px'; + element[0].style.width = offset.width + 'px'; + } + + function resetDropdown() { + if (placeholder === null) { + // The dropdown has not actually been display yet, so there's nothing to reset + return; + } + + // Move the dropdown element back to its original location in the DOM + placeholder.replaceWith(element); + placeholder = null; + + element[0].style.position = ''; + element[0].style.left = ''; + element[0].style.top = ''; + element[0].style.width = originalWidth; + } + + // Hold on to a reference to the .ui-select-dropdown element for direction support. + var dropdown = null, + directionUpClassName = 'direction-up'; + + // Support changing the direction of the dropdown if there isn't enough space to render it. + scope.$watch('$select.open', function (isOpen) { + if (isOpen) { + dropdown = angular.element(element).querySelectorAll('.ui-select-dropdown'); + if (dropdown === null) { + return; + } + + // Hide the dropdown so there is no flicker until $timeout is done executing. + dropdown[0].style.opacity = 0; + + // Delay positioning the dropdown until all choices have been added so its height is correct. + $timeout(function () { + var offset = uisOffset(element); + var offsetDropdown = uisOffset(dropdown); + + // Determine if the direction of the dropdown needs to be changed. + if (offset.top + offset.height + offsetDropdown.height > + $document[0].documentElement.scrollTop + + $document[0].documentElement.clientHeight) { + dropdown[0].style.position = 'absolute'; + dropdown[0].style.top = (offsetDropdown.height * -1) + 'px'; + element.addClass(directionUpClassName); + } + + // Display the dropdown once it has been positioned. + dropdown[0].style.opacity = 1; + }); + } else { + if (dropdown === null) { + return; + } + + // Reset the position of the dropdown. + dropdown[0].style.position = ''; + dropdown[0].style.top = ''; + element.removeClass(directionUpClassName); + } + }); + }; + } + }; + }]); uis.directive('uiSelectMatch', ['uiSelectConfig', function(uiSelectConfig) { return { @@ -1145,7 +1133,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec ctrl.getPlaceholder = function(){ //Refactor single? - if($select.selected.length) return; + if($select.selected && $select.selected.length) return; return $select.placeholder; }; @@ -1244,6 +1232,9 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec }; scope.$on('uis:select', function (event, item) { + if($select.selected.length >= $select.limit) { + return; + } $select.selected.push(item); $selectMultiple.updateModel(); }); @@ -1261,15 +1252,14 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec var key = e.which; scope.$apply(function() { var processed = false; - // var tagged = false; //Checkme if(KEY.isHorizontalMovement(key)){ processed = _handleMatchSelection(key); } if (processed && key != KEY.TAB) { //TODO Check si el tab selecciona aun correctamente //Crear test - e.preventDefault(); - e.stopPropagation(); +// e.preventDefault(); + // e.stopPropagation(); } }); }); @@ -1338,147 +1328,6 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec return true; } - $select.searchInput.on('keyup', function(e) { - - if ( ! KEY.isVerticalMovement(e.which) ) { - scope.$evalAsync( function () { - $select.activeIndex = $select.taggingLabel === false ? -1 : 0; - }); - } - // Push a "create new" item into array if there is a search string - if ( $select.tagging.isActivated && $select.search.length > 0 ) { - - // return early with these keys - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || KEY.isVerticalMovement(e.which) ) { - return; - } - // always reset the activeIndex to the first item when tagging - $select.activeIndex = $select.taggingLabel === false ? -1 : 0; - // taggingLabel === false bypasses all of this - if ($select.taggingLabel === false) return; - - var items = angular.copy( $select.items ); - var stashArr = angular.copy( $select.items ); - var newItem; - var item; - var hasTag = false; - var dupeIndex = -1; - var tagItems; - var tagItem; - - // case for object tagging via transform `$select.tagging.fct` function - if ( $select.tagging.fct !== undefined) { - tagItems = $select.$filter('filter')(items,{'isTag': true}); - if ( tagItems.length > 0 ) { - tagItem = tagItems[0]; - } - // remove the first element, if it has the `isTag` prop we generate a new one with each keyup, shaving the previous - if ( items.length > 0 && tagItem ) { - hasTag = true; - items = items.slice(1,items.length); - stashArr = stashArr.slice(1,stashArr.length); - } - newItem = $select.tagging.fct($select.search); - newItem.isTag = true; - // verify the the tag doesn't match the value of an existing item - if ( stashArr.filter( function (origItem) { return angular.equals( origItem, $select.tagging.fct($select.search) ); } ).length > 0 ) { - return; - } - newItem.isTag = true; - // handle newItem string and stripping dupes in tagging string context - } else { - // find any tagging items already in the $select.items array and store them - tagItems = $select.$filter('filter')(items,function (item) { - return item.match($select.taggingLabel); - }); - if ( tagItems.length > 0 ) { - tagItem = tagItems[0]; - } - item = items[0]; - // remove existing tag item if found (should only ever be one tag item) - if ( item !== undefined && items.length > 0 && tagItem ) { - hasTag = true; - items = items.slice(1,items.length); - stashArr = stashArr.slice(1,stashArr.length); - } - newItem = $select.search+' '+$select.taggingLabel; - if ( _findApproxDupe($select.selected, $select.search) > -1 ) { - return; - } - // verify the the tag doesn't match the value of an existing item from - // the searched data set or the items already selected - if ( _findCaseInsensitiveDupe(stashArr.concat($select.selected)) ) { - // if there is a tag from prev iteration, strip it / queue the change - // and return early - if ( hasTag ) { - items = stashArr; - scope.$evalAsync( function () { - $select.activeIndex = 0; - $select.items = items; - }); - } - return; - } - if ( _findCaseInsensitiveDupe(stashArr) ) { - // if there is a tag from prev iteration, strip it - if ( hasTag ) { - $select.items = stashArr.slice(1,stashArr.length); - } - return; - } - } - if ( hasTag ) dupeIndex = _findApproxDupe($select.selected, newItem); - // dupe found, shave the first item - if ( dupeIndex > -1 ) { - items = items.slice(dupeIndex+1,items.length-1); - } else { - items = []; - items.push(newItem); - items = items.concat(stashArr); - } - scope.$evalAsync( function () { - $select.activeIndex = 0; - $select.items = items; - }); - } - }); - function _findCaseInsensitiveDupe(arr) { - if ( arr === undefined || $select.search === undefined ) { - return false; - } - var hasDupe = arr.filter( function (origItem) { - if ( $select.search.toUpperCase() === undefined || origItem === undefined ) { - return false; - } - return origItem.toUpperCase() === $select.search.toUpperCase(); - }).length > 0; - - return hasDupe; - } - function _findApproxDupe(haystack, needle) { - var dupeIndex = -1; - if(angular.isArray(haystack)) { - var tempArr = angular.copy(haystack); - for (var i = 0; i
"); +$templateCache.put("selectize/match.tpl.html","
"); +$templateCache.put("selectize/select.tpl.html","
");}]); angular.module("ui.select").run(["$templateCache", function($templateCache) {$templateCache.put("bootstrap/choices.tpl.html","
    0\">
  • 0\">
"); $templateCache.put("bootstrap/match-multiple.tpl.html"," × "); -$templateCache.put("bootstrap/match.tpl.html","
{{$select.placeholder}}
"); +$templateCache.put("bootstrap/match.tpl.html","
{{$select.placeholder}}
"); $templateCache.put("bootstrap/select-multiple.tpl.html","
"); -$templateCache.put("bootstrap/select.tpl.html","
"); -$templateCache.put("select2/choices.tpl.html","
"); +$templateCache.put("bootstrap/select.tpl.html","
");}]); +angular.module("ui.select").run(["$templateCache", function($templateCache) {$templateCache.put("select2/choices.tpl.html","
"); $templateCache.put("select2/match-multiple.tpl.html","
  • "); $templateCache.put("select2/match.tpl.html","{{$select.placeholder}} "); $templateCache.put("select2/select-multiple.tpl.html","
    "); -$templateCache.put("select2/select.tpl.html","
    "); -$templateCache.put("selectize/choices.tpl.html","
    "); -$templateCache.put("selectize/match.tpl.html","
    "); -$templateCache.put("selectize/select.tpl.html","
    ");}]); \ No newline at end of file +$templateCache.put("select2/select.tpl.html","
    ");}]); \ No newline at end of file diff --git a/dist/select.min.css b/dist/select.min.css index 31d2e6935..bcb84cd02 100644 --- a/dist/select.min.css +++ b/dist/select.min.css @@ -1,6 +1,6 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-07-28T03:50:59.080Z + * Version: 0.12.1 - 2015-08-02T20:56:31.552Z * License: MIT - */.ui-select-highlight{font-weight:700}.ui-select-offscreen{clip:rect(0 0 0 0)!important;width:1px!important;height:1px!important;border:0!important;margin:0!important;padding:0!important;overflow:hidden!important;position:absolute!important;outline:0!important;left:0!important;top:0!important}.ng-dirty.ng-invalid>a.select2-choice{border-color:#D44950}.select2-result-single{padding-left:0}.select-locked>.ui-select-match-close,.select2-locked>.select2-search-choice-close{display:none}body>.select2-container.open{z-index:9999}.ui-select-container[theme=select2].direction-up .ui-select-match{border-radius:0 0 4px 4px}.ui-select-container[theme=select2].direction-up .ui-select-dropdown{border-radius:4px 4px 0 0;border-top-width:1px;border-top-style:solid;box-shadow:0 -4px 8px rgba(0,0,0,.25);margin-top:-4px}.ui-select-container[theme=select2].direction-up .ui-select-dropdown .select2-search{margin-top:4px}.ui-select-container[theme=select2].direction-up.select2-dropdown-open .ui-select-match{border-bottom-color:#5897fb}.selectize-input.selectize-focus{border-color:#007FBB!important}.selectize-control>.selectize-dropdown,.selectize-control>.selectize-input>input{width:100%}.ng-dirty.ng-invalid>div.selectize-input{border-color:#D44950}.ui-select-container[theme=selectize].direction-up .ui-select-dropdown{box-shadow:0 -4px 8px rgba(0,0,0,.25);margin-top:-2px}.btn-default-focus{color:#333;background-color:#EBEBEB;border-color:#ADADAD;text-decoration:none;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.ui-select-bootstrap .ui-select-toggle{position:relative}.ui-select-bootstrap .ui-select-toggle>.caret{position:absolute;height:10px;top:50%;right:10px;margin-top:-2px}.input-group>.ui-select-bootstrap.dropdown{position:static}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control{border-radius:4px 0 0 4px}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control.direction-up{border-radius:4px 0 0 4px!important}.ui-select-bootstrap>.ui-select-match>.btn{text-align:left!important}.ui-select-bootstrap>.ui-select-match>.caret{position:absolute;top:45%;right:15px}.ui-select-bootstrap>.ui-select-choices{width:100%;height:auto;max-height:200px;overflow-x:hidden;margin-top:-1px}body>.ui-select-bootstrap.open{z-index:1000}.ui-select-multiple.ui-select-bootstrap{height:auto;padding:3px 3px 0}.ui-select-multiple.ui-select-bootstrap input.ui-select-search{background-color:transparent!important;border:none;outline:0;height:1.666666em;margin-bottom:3px}.ui-select-multiple.ui-select-bootstrap .ui-select-match .close{font-size:1.6em;line-height:.75}.ui-select-multiple.ui-select-bootstrap .ui-select-match-item{outline:0;margin:0 3px 3px 0}.ui-select-multiple .ui-select-match-item{position:relative}.ui-select-multiple .ui-select-match-item.dropping-before:before{content:"";position:absolute;top:0;right:100%;height:100%;margin-right:2px;border-left:1px solid #428bca}.ui-select-multiple .ui-select-match-item.dropping-after:after{content:"";position:absolute;top:0;left:100%;height:100%;margin-left:2px;border-right:1px solid #428bca}.ui-select-bootstrap .ui-select-choices-row>a{display:block;padding:3px 20px;clear:both;font-weight:400;line-height:1.42857143;color:#333;white-space:nowrap}.ui-select-bootstrap .ui-select-choices-row>a:focus,.ui-select-bootstrap .ui-select-choices-row>a:hover{text-decoration:none;color:#262626;background-color:#f5f5f5}.ui-select-bootstrap .ui-select-choices-row.active>a{color:#fff;text-decoration:none;outline:0;background-color:#428bca}.ui-select-bootstrap .ui-select-choices-row.active.disabled>a,.ui-select-bootstrap .ui-select-choices-row.disabled>a{color:#777;cursor:not-allowed;background-color:#fff}.ui-select-match.ng-hide-add,.ui-select-search.ng-hide-add{display:none!important}.ui-select-bootstrap.ng-dirty.ng-invalid>button.btn.ui-select-match{border-color:#D44950}.ui-select-container[theme=bootstrap].direction-up .ui-select-dropdown{box-shadow:0 -4px 8px rgba(0,0,0,.25)} \ No newline at end of file + */.ui-select-highlight{font-weight:700}.ui-select-offscreen{clip:rect(0 0 0 0)!important;width:1px!important;height:1px!important;border:0!important;margin:0!important;padding:0!important;overflow:hidden!important;position:absolute!important;outline:0!important;left:0!important;top:0!important}.ng-dirty.ng-invalid>a.select2-choice{border-color:#D44950}.select2-result-single{padding-left:0}.select-locked>.ui-select-match-close,.select2-locked>.select2-search-choice-close{display:none}body>.select2-container.open{z-index:9999}.ui-select-container[theme=select2].direction-up .ui-select-match{border-radius:0 0 4px 4px}.ui-select-container[theme=select2].direction-up .ui-select-dropdown{border-radius:4px 4px 0 0;border-top-width:1px;border-top-style:solid;box-shadow:0 -4px 8px rgba(0,0,0,.25);margin-top:-4px}.ui-select-container[theme=select2].direction-up .ui-select-dropdown .select2-search{margin-top:4px}.ui-select-container[theme=select2].direction-up.select2-dropdown-open .ui-select-match{border-bottom-color:#5897fb}.selectize-input.selectize-focus{border-color:#007FBB!important}.selectize-control>.selectize-dropdown,.selectize-control>.selectize-input>input{width:100%}.ng-dirty.ng-invalid>div.selectize-input{border-color:#D44950}.ui-select-container[theme=selectize].direction-up .ui-select-dropdown{box-shadow:0 -4px 8px rgba(0,0,0,.25);margin-top:-2px}.btn-default-focus{color:#333;background-color:#EBEBEB;border-color:#ADADAD;text-decoration:none;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.ui-select-bootstrap .ui-select-toggle{position:relative}.ui-select-bootstrap .ui-select-toggle>.caret{position:absolute;height:10px;top:50%;right:10px;margin-top:-2px}.input-group>.ui-select-bootstrap.dropdown{position:static}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control{border-radius:4px 0 0 4px}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control.direction-up{border-radius:4px 0 0 4px!important}.ui-select-bootstrap>.ui-select-match>.btn{text-align:left!important}.ui-select-bootstrap>.ui-select-match>.caret{position:absolute;top:45%;right:15px}.ui-select-bootstrap>.ui-select-choices{width:100%;height:auto;max-height:200px;overflow-x:hidden;margin-top:-1px}body>.ui-select-bootstrap.open{z-index:1000}.ui-select-multiple.ui-select-bootstrap{height:auto;padding:3px 3px 0}.ui-select-multiple.ui-select-bootstrap input.ui-select-search{background-color:transparent!important;border:none;outline:0;height:1.666666em;margin-bottom:3px}.ui-select-multiple.ui-select-bootstrap .ui-select-match .close{font-size:1.6em;line-height:.75}.ui-select-multiple.ui-select-bootstrap .ui-select-match-item{outline:0;margin:0 3px 3px 0}.ui-select-multiple .ui-select-match-item{position:relative}.ui-select-multiple .ui-select-match-item.dropping-before:before{content:"";position:absolute;top:0;right:100%;height:100%;margin-right:2px;border-left:1px solid #428bca}.ui-select-multiple .ui-select-match-item.dropping-after:after{content:"";position:absolute;top:0;left:100%;height:100%;margin-left:2px;border-right:1px solid #428bca}.ui-select-bootstrap .ui-select-placeholder{opacity:1;color:#999}.ui-select-bootstrap .ui-select-choices-row>a{display:block;padding:3px 20px;clear:both;font-weight:400;line-height:1.42857143;color:#333;white-space:nowrap}.ui-select-bootstrap .ui-select-choices-row>a:focus,.ui-select-bootstrap .ui-select-choices-row>a:hover{text-decoration:none;color:#262626;background-color:#f5f5f5}.ui-select-bootstrap .ui-select-choices-row.active>a{color:#fff;text-decoration:none;outline:0;background-color:#428bca}.ui-select-bootstrap .ui-select-choices-row.active.disabled>a,.ui-select-bootstrap .ui-select-choices-row.disabled>a{color:#777;cursor:not-allowed;background-color:#fff}.ui-select-match.ng-hide-add,.ui-select-search.ng-hide-add{display:none!important}.ui-select-bootstrap.ng-dirty.ng-invalid>button.btn.ui-select-match{border-color:#D44950}.ui-select-container[theme=bootstrap].direction-up .ui-select-dropdown{box-shadow:0 -4px 8px rgba(0,0,0,.25)} \ No newline at end of file diff --git a/dist/select.min.js b/dist/select.min.js index 3e7e81052..715a2300b 100644 --- a/dist/select.min.js +++ b/dist/select.min.js @@ -1,8 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-07-28T03:50:59.076Z + * Version: 0.12.1 - 2015-08-02T20:56:31.549Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],c=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(c.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,c=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",refreshDelay:1e3,closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,i,l){l(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(c){var i=c[0].getBoundingClientRect();return{width:i.width||c.prop("offsetWidth"),height:i.height||c.prop("offsetHeight"),top:i.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:i.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);c.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,c,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(l,s){if(!s.repeat)throw c("repeat","Expected 'repeat' expression.");return function(l,s,n,a,r){var o=n.groupBy,u=n.groupFilter;if(a.parseRepeatAttr(n.repeat,o,u),a.disableChoiceExpression=n.uiDisableChoice,a.onHighlightCallback=n.onHighlight,o){var d=s.querySelectorAll(".ui-select-choices-group");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",d.length);d.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=s.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(a.parserResult.itemName,"$select.items",a.parserResult.trackByExp,o)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+a.parserResult.itemName+")").attr("ng-click","$select.select("+a.parserResult.itemName+",false,$event)");var g=s.querySelectorAll(".ui-select-choices-row-inner");if(1!==g.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",g.length);g.attr("uis-transclude-append",""),i(s,r)(l),l.$watch("$select.search",function(e){e&&!a.open&&a.multiple&&a.activate(!1,!0),a.activeIndex=a.tagging.isActivated?-1:0,a.refresh(n.refresh)}),n.$observe("refreshDelay",function(){var t=l.$eval(n.refreshDelay);a.refreshDelay=void 0!==t?t:e.refreshDelay})}}}}]),c.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,c,i,l,s,n,a){function r(){(p.resetSearchInput||void 0===p.resetSearchInput&&a.resetSearchInput)&&(p.search=g,p.selected&&p.items.length&&!p.multiple&&(p.activeIndex=p.items.indexOf(p.selected)))}function o(e,t){var c,i,l=[];for(c=0;c0||0===p.search.length&&p.tagging.isActivated&&p.activeIndex>-1)&&p.activeIndex--;break;case e.TAB:(!p.multiple||p.open)&&p.select(p.items[p.activeIndex],!0);break;case e.ENTER:p.open&&(p.tagging.isActivated||p.activeIndex>=0)?p.select(p.items[p.activeIndex]):p.activate(!1,!0);break;case e.ESC:p.close();break;default:c=!1}return c}function d(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw n("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(p.activeIndex<0)){var i=t[p.activeIndex],l=i.offsetTop+i.clientHeight-e[0].scrollTop,s=e[0].offsetHeight;l>s?e[0].scrollTop+=l-s:l=p.items.length?0:p.activeIndex,-1===p.activeIndex&&p.taggingLabel!==!1&&(p.activeIndex=0),i(function(){p.search=e||p.search,p.searchInput[0].focus()}))},p.findGroupByName=function(e){return p.groups&&p.groups.filter(function(t){return t.name===e})[0]},p.parseRepeatAttr=function(e,c,i){function l(e){var l=t.$eval(c);if(p.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(l)?l(e):e[l],c=p.findGroupByName(t);c?c.items.push(e):p.groups.push({name:t,items:[e]})}),i){var s=t.$eval(i);angular.isFunction(s)?p.groups=s(p.groups):angular.isArray(s)&&(p.groups=o(p.groups,s))}p.items=[],p.groups.forEach(function(e){p.items=p.items.concat(e.items)})}function a(e){p.items=e}p.setItemsFn=c?l:a,p.parserResult=s.parse(e),p.isGrouped=!!c,p.itemProperty=p.parserResult.itemName,p.refreshItems=function(e){e=e||p.parserResult.source(t);var c=p.selected;if(angular.isArray(c)&&!c.length||!p.removeSelected)p.setItemsFn(e);else if(void 0!==e){var i=e.filter(function(e){return c.indexOf(e)<0});p.setItemsFn(i)}},t.$watchCollection(p.parserResult.source,function(e){if(void 0===e||null===e)p.items=[];else{if(!angular.isArray(e))throw n("items","Expected an array but got '{0}'.",e);p.refreshItems(e),p.ngModel.$modelValue=null}})};var h;p.refresh=function(e){void 0!==e&&(h&&i.cancel(h),h=i(function(){t.$eval(e)},p.refreshDelay))},p.setActiveItem=function(e){p.activeIndex=p.items.indexOf(e)},p.isActive=function(e){if(!p.open)return!1;var t=p.items.indexOf(e[p.itemProperty]),c=t===p.activeIndex;return!c||0>t&&p.taggingLabel!==!1||0>t&&p.taggingLabel===!1?!1:(c&&!angular.isUndefined(p.onHighlightCallback)&&e.$eval(p.onHighlightCallback),c)},p.isDisabled=function(e){if(p.open){var t,c=p.items.indexOf(e[p.itemProperty]),i=!1;return c>=0&&!angular.isUndefined(p.disableChoiceExpression)&&(t=p.items[c],i=!!e.$eval(p.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i}},p.select=function(e,c,l){if(void 0===e||!e._uiSelectChoiceDisabled){if(!p.items&&!p.search)return;if(!e||!e._uiSelectChoiceDisabled){if(p.tagging.isActivated){if(p.taggingLabel===!1)if(p.activeIndex<0){if(e=void 0!==p.tagging.fct?p.tagging.fct(p.search):p.search,!e||angular.equals(p.items[0],e))return}else e=p.items[p.activeIndex];else if(0===p.activeIndex){if(void 0===e)return;if(void 0!==p.tagging.fct&&"string"==typeof e){if(e=p.tagging.fct(p.search),!e)return}else"string"==typeof e&&(e=e.replace(p.taggingLabel,"").trim())}if(p.selected&&angular.isArray(p.selected)&&p.selected.filter(function(t){return angular.equals(t,e)}).length>0)return p.close(c),void 0}t.$broadcast("uis:select",e);var s={};s[p.parserResult.itemName]=e,i(function(){p.onSelectCallback(t,{$item:e,$model:p.parserResult.modelMapper(t,s)})}),p.closeOnSelect&&p.close(c),l&&"click"===l.type&&(p.clickTriggeredSelect=!0)}}},p.close=function(e){p.open&&(p.ngModel&&p.ngModel.$setTouched&&p.ngModel.$setTouched(),r(),p.open=!1,t.$broadcast("uis:close",e))},p.setFocus=function(){p.focus||p.focusInput[0].focus()},p.clear=function(e){p.select(void 0),e.stopPropagation(),i(function(){p.focusser[0].focus()},0,!1)},p.toggle=function(e){p.open?(p.close(),e.preventDefault(),e.stopPropagation()):p.activate()},p.isLocked=function(e,t){var c,i=p.selected[t];return i&&!angular.isUndefined(p.lockChoiceExpression)&&(c=!!e.$eval(p.lockChoiceExpression),i._uiSelectChoiceLocked=c),c};var f=null;p.sizeSearchInput=function(){var e=p.searchInput[0],c=p.searchInput.parent().parent()[0],l=function(){return c.clientWidth*!!e.offsetParent},s=function(t){if(0===t)return!1;var c=t-e.offsetLeft-10;return 50>c&&(c=t),p.searchInput.css("width",c+"px"),!0};p.searchInput.css("width","10px"),i(function(){null!==f||s(l())||(f=t.$watch(l,function(e){s(e)&&(f(),f=null)}))})},p.searchInput.on("keydown",function(c){var l=c.which;t.$apply(function(){var t=!1;if((p.items.length>0||p.tagging.isActivated)&&(u(l),p.taggingTokens.isActivated)){for(var s=0;s0&&(t=!0);t&&i(function(){p.searchInput.triggerHandler("tagged");var t=p.search.replace(e.MAP[c.keyCode],"").trim();p.tagging.fct&&(t=p.tagging.fct(t)),t&&p.select(t,!0)})}}),e.isVerticalMovement(l)&&p.items.length>0&&d(),(l===e.ENTER||l===e.ESC)&&(c.preventDefault(),c.stopPropagation())}),p.searchInput.on("paste",function(e){var t=e.originalEvent.clipboardData.getData("text/plain");if(t&&t.length>0&&p.taggingTokens.isActivated&&p.tagging.fct){var c=t.split(p.taggingTokens.tokens[0]);c&&c.length>0&&(angular.forEach(c,function(e){var t=p.tagging.fct(e);t&&p.select(t,!0)}),e.preventDefault(),e.stopPropagation())}}),p.searchInput.on("tagged",function(){i(function(){r()})}),t.$on("$destroy",function(){p.searchInput.off("keyup keydown tagged blur paste")})}]),c.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,c,i,l,s,n){return{restrict:"EA",templateUrl:function(e,c){var i=c.theme||t.theme;return i+(angular.isDefined(c.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(l,a){return angular.isDefined(a.multiple)?l.append("").removeAttr("multiple"):l.append(""),function(l,a,r,o,u){function d(e){if(h.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(a[0],e.target):a[0].contains(e.target),!t&&!h.clickTriggeredSelect){var c=["input","button","textarea"],i=angular.element(e.target).scope(),s=i&&i.$select&&i.$select!==h;s||(s=~c.indexOf(e.target.tagName.toLowerCase())),h.close(s),l.$digest()}h.clickTriggeredSelect=!1}}function p(){var t=i(a);m=angular.element('
    '),m[0].style.width=t.width+"px",m[0].style.height=t.height+"px",a.after(m),$=a[0].style.width,e.find("body").append(a),a[0].style.position="absolute",a[0].style.left=t.left+"px",a[0].style.top=t.top+"px",a[0].style.width=t.width+"px"}function g(){null!==m&&(m.replaceWith(a),m=null,a[0].style.position="",a[0].style.left="",a[0].style.top="",a[0].style.width=$)}var h=o[0],f=o[1];h.generatedId=t.generateId(),h.baseTitle=r.title||"Select box",h.focusserTitle=h.baseTitle+" focus",h.focusserId="focusser-"+h.generatedId,h.closeOnSelect=function(){return angular.isDefined(r.closeOnSelect)?s(r.closeOnSelect)():t.closeOnSelect}(),h.onSelectCallback=s(r.onSelect),h.onRemoveCallback=s(r.onRemove),h.ngModel=f,h.choiceGrouped=function(e){return h.isGrouped&&e&&e.name},r.tabindex&&r.$observe("tabindex",function(e){h.focusInput.attr("tabindex",e),a.removeAttr("tabindex")}),l.$watch("searchEnabled",function(){var e=l.$eval(r.searchEnabled);h.searchEnabled=void 0!==e?e:t.searchEnabled}),l.$watch("sortable",function(){var e=l.$eval(r.sortable);h.sortable=void 0!==e?e:t.sortable}),r.$observe("disabled",function(){h.disabled=void 0!==r.disabled?r.disabled:!1}),r.$observe("resetSearchInput",function(){var e=l.$eval(r.resetSearchInput);h.resetSearchInput=void 0!==e?e:!0}),r.$observe("tagging",function(){if(void 0!==r.tagging){var e=l.$eval(r.tagging);h.tagging={isActivated:!0,fct:e!==!0?e:void 0}}else h.tagging={isActivated:!1,fct:void 0}}),r.$observe("taggingLabel",function(){void 0!==r.tagging&&(h.taggingLabel="false"===r.taggingLabel?!1:void 0!==r.taggingLabel?r.taggingLabel:"(new)")}),r.$observe("taggingTokens",function(){if(void 0!==r.tagging){var e=void 0!==r.taggingTokens?r.taggingTokens.split("|"):[",","ENTER"];h.taggingTokens={isActivated:!0,tokens:e}}}),angular.isDefined(r.autofocus)&&n(function(){h.setFocus()}),angular.isDefined(r.focusOn)&&l.$on(r.focusOn,function(){n(function(){h.setFocus()})}),e.on("click",d),l.$on("$destroy",function(){e.off("click",d)}),u(l,function(e){var t=angular.element("
    ").append(e),i=t.querySelectorAll(".ui-select-match");if(i.removeAttr("ui-select-match"),i.removeAttr("data-ui-select-match"),1!==i.length)throw c("transcluded","Expected 1 .ui-select-match but got '{0}'.",i.length);a.querySelectorAll(".ui-select-match").replaceWith(i);var l=t.querySelectorAll(".ui-select-choices");if(l.removeAttr("ui-select-choices"),l.removeAttr("data-ui-select-choices"),1!==l.length)throw c("transcluded","Expected 1 .ui-select-choices but got '{0}'.",l.length);a.querySelectorAll(".ui-select-choices").replaceWith(l)});var v=l.$eval(r.appendToBody);(void 0!==v?v:t.appendToBody)&&(l.$watch("$select.open",function(e){e?p():g()}),l.$on("$destroy",function(){g()}));var m=null,$="",b=null,x="direction-up";l.$watch("$select.open",function(t){if(t){if(b=angular.element(a).querySelectorAll(".ui-select-dropdown"),null===b)return;b[0].style.opacity=0,n(function(){var t=i(a),c=i(b);t.top+t.height+c.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&(b[0].style.position="absolute",b[0].style.top=-1*c.height+"px",a.addClass(x)),b[0].style.opacity=1})}else{if(null===b)return;b[0].style.position="",b[0].style.top="",a.removeClass(x)}})}}}}]),c.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return c+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,i,l){function s(e){l.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}l.lockChoiceExpression=i.uiLockChoice,i.$observe("placeholder",function(t){l.placeholder=void 0!==t?t:e.placeholder}),i.$observe("allowClear",s),s(i.allowClear),l.multiple&&l.sizeSearchInput()}}}]),c.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var c,i=this,l=e.$select;e.$evalAsync(function(){c=e.ngModel}),i.activeMatchIndex=-1,i.updateModel=function(){c.$setViewValue(Date.now()),i.refreshComponent()},i.refreshComponent=function(){l.refreshItems(),l.sizeSearchInput()},i.removeChoice=function(c){var s=l.selected[c];if(!s._uiSelectChoiceLocked){var n={};n[l.parserResult.itemName]=s,l.selected.splice(c,1),i.activeMatchIndex=-1,l.sizeSearchInput(),t(function(){l.onRemoveCallback(e,{$item:s,$model:l.parserResult.modelMapper(e,n)})}),i.updateModel()}},i.getPlaceholder=function(){return l.selected.length?void 0:l.placeholder}}],controllerAs:"$selectMultiple",link:function(i,l,s,n){function a(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function r(t){function c(){switch(t){case e.LEFT:return~g.activeMatchIndex?u:n;case e.RIGHT:return~g.activeMatchIndex&&r!==n?o:(d.activate(),!1);case e.BACKSPACE:return~g.activeMatchIndex?(g.removeChoice(r),u):n;case e.DELETE:return~g.activeMatchIndex?(g.removeChoice(g.activeMatchIndex),r):!1}}var i=a(d.searchInput[0]),l=d.selected.length,s=0,n=l-1,r=g.activeMatchIndex,o=g.activeMatchIndex+1,u=g.activeMatchIndex-1,p=r;return i>0||d.search.length&&t==e.RIGHT?!1:(d.close(),p=c(),g.activeMatchIndex=d.selected.length&&p!==!1?Math.min(n,Math.max(s,p)):-1,!0)}function o(e){if(void 0===e||void 0===d.search)return!1;var t=e.filter(function(e){return void 0===d.search.toUpperCase()||void 0===e?!1:e.toUpperCase()===d.search.toUpperCase()}).length>0;return t}function u(e,t){var c=-1;if(angular.isArray(e))for(var i=angular.copy(e),l=0;l=0;l--)t={},t[d.parserResult.itemName]=d.selected[l],e=d.parserResult.modelMapper(i,t),c.unshift(e);return c}),p.$formatters.unshift(function(e){var t,c=d.parserResult.source(i,{$select:{search:""}}),l={};if(!c)return e;var s=[],n=function(e,c){if(e&&e.length){for(var n=e.length-1;n>=0;n--){if(l[d.parserResult.itemName]=e[n],t=d.parserResult.modelMapper(i,l),d.parserResult.trackByExp){var a=/\.(.+)/.exec(d.parserResult.trackByExp);if(a.length>0&&t[a[1]]==c[a[1]])return s.unshift(e[n]),!0}if(angular.equals(t,c))return s.unshift(e[n]),!0}return!1}};if(!e)return s;for(var a=e.length-1;a>=0;a--)n(d.selected,e[a])||n(c,e[a])||s.unshift(e[a]);return s}),i.$watchCollection(function(){return p.$modelValue},function(e,t){t!=e&&(p.$modelValue=null,g.refreshComponent())}),p.$render=function(){if(!angular.isArray(p.$viewValue)){if(!angular.isUndefined(p.$viewValue)&&null!==p.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",p.$viewValue);d.selected=[]}d.selected=p.$viewValue,i.$evalAsync()},i.$on("uis:select",function(e,t){d.selected.push(t),g.updateModel()}),i.$on("uis:activate",function(){g.activeMatchIndex=-1}),i.$watch("$select.disabled",function(e,t){t&&!e&&d.sizeSearchInput()}),d.searchInput.on("keydown",function(t){var c=t.which;i.$apply(function(){var i=!1;e.isHorizontalMovement(c)&&(i=r(c)),i&&c!=e.TAB&&(t.preventDefault(),t.stopPropagation())})}),d.searchInput.on("keyup",function(t){if(e.isVerticalMovement(t.which)||i.$evalAsync(function(){d.activeIndex=d.taggingLabel===!1?-1:0}),d.tagging.isActivated&&d.search.length>0){if(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||e.isVerticalMovement(t.which))return;if(d.activeIndex=d.taggingLabel===!1?-1:0,d.taggingLabel===!1)return;var c,l,s,n,a=angular.copy(d.items),r=angular.copy(d.items),p=!1,g=-1;if(void 0!==d.tagging.fct){if(s=d.$filter("filter")(a,{isTag:!0}),s.length>0&&(n=s[0]),a.length>0&&n&&(p=!0,a=a.slice(1,a.length),r=r.slice(1,r.length)),c=d.tagging.fct(d.search),c.isTag=!0,r.filter(function(e){return angular.equals(e,d.tagging.fct(d.search))}).length>0)return;c.isTag=!0}else{if(s=d.$filter("filter")(a,function(e){return e.match(d.taggingLabel)}),s.length>0&&(n=s[0]),l=a[0],void 0!==l&&a.length>0&&n&&(p=!0,a=a.slice(1,a.length),r=r.slice(1,r.length)),c=d.search+" "+d.taggingLabel,u(d.selected,d.search)>-1)return;if(o(r.concat(d.selected)))return p&&(a=r,i.$evalAsync(function(){d.activeIndex=0,d.items=a})),void 0;if(o(r))return p&&(d.items=r.slice(1,r.length)),void 0}p&&(g=u(d.selected,c)),g>-1?a=a.slice(g+1,a.length-1):(a=[],a.push(c),a=a.concat(r)),i.$evalAsync(function(){d.activeIndex=0,d.items=a})}}),d.searchInput.on("blur",function(){c(function(){g.activeMatchIndex=-1})})}}}]),c.directive("uiSelectSingle",["$timeout","$compile",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(i,l,s,n){var a=n[0],r=n[1];r.$parsers.unshift(function(e){var t,c={};return c[a.parserResult.itemName]=e,t=a.parserResult.modelMapper(i,c)}),r.$formatters.unshift(function(e){var t,c=a.parserResult.source(i,{$select:{search:""}}),l={};if(c){var s=function(c){return l[a.parserResult.itemName]=c,t=a.parserResult.modelMapper(i,l),t==e};if(a.selected&&s(a.selected))return a.selected;for(var n=c.length-1;n>=0;n--)if(s(c[n]))return c[n]}return e}),i.$watch("$select.selected",function(e){r.$viewValue!==e&&r.$setViewValue(e)}),r.$render=function(){a.selected=r.$viewValue},i.$on("uis:select",function(e,t){a.selected=t}),i.$on("uis:close",function(e,c){t(function(){a.focusser.prop("disabled",!1),c||a.focusser[0].focus()},0,!1)}),i.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");c(o)(i),a.focusser=o,a.focusInput=o,l.parent().append(o),o.bind("focus",function(){i.$evalAsync(function(){a.focus=!0})}),o.bind("blur",function(){i.$evalAsync(function(){a.focus=!1})}),o.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),a.select(void 0),i.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),a.activate()),i.$digest()),void 0)}),o.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(a.activate(o.val()),o.val(""),i.$digest())})}}}]),c.directive("uiSelectSort",["$timeout","uiSelectConfig","uiSelectMinErr",function(e,t,c){return{require:"^uiSelect",link:function(t,i,l,s){if(null===t[l.uiSelectSort])throw c("sort","Expected a list to sort");var n=angular.extend({axis:"horizontal"},t.$eval(l.uiSelectSortOptions)),a=n.axis,r="dragging",o="dropping",u="dropping-before",d="dropping-after";t.$watch(function(){return s.sortable},function(e){e?i.attr("draggable",!0):i.removeAttr("draggable")}),i.on("dragstart",function(e){i.addClass(r),(e.dataTransfer||e.originalEvent.dataTransfer).setData("text/plain",t.$index)}),i.on("dragend",function(){i.removeClass(r)});var p,g=function(e,t){this.splice(t,0,this.splice(e,1)[0])},h=function(e){e.preventDefault();var t="vertical"===a?e.offsetY||e.layerY||(e.originalEvent?e.originalEvent.offsetY:0):e.offsetX||e.layerX||(e.originalEvent?e.originalEvent.offsetX:0);t
  • '),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",'
    {{$select.placeholder}}
    '),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("select2/choices.tpl.html",'
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    '),e.put("selectize/choices.tpl.html",'
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ') -}]); \ No newline at end of file +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],c=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(c.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,c=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",refreshDelay:1e3,closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,l,s){s(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(c){var l=c[0].getBoundingClientRect();return{width:l.width||c.prop("offsetWidth"),height:l.height||c.prop("offsetHeight"),top:l.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:l.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);c.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,c,l){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(s,i){if(!i.repeat)throw c("repeat","Expected 'repeat' expression.");return function(s,i,n,a,r){var o=n.groupBy,u=n.groupFilter;if(a.parseRepeatAttr(n.repeat,o,u),a.disableChoiceExpression=n.uiDisableChoice,a.onHighlightCallback=n.onHighlight,a.refreshOnActive=s.$eval(n.refreshOnActive),o){var d=i.querySelectorAll(".ui-select-choices-group");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",d.length);d.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=i.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(a.parserResult.itemName,"$select.items",a.parserResult.trackByExp,o)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+a.parserResult.itemName+")").attr("ng-click","$select.select("+a.parserResult.itemName+",false,$event)");var h=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==h.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",h.length);h.attr("uis-transclude-append",""),l(i,r)(s),s.$watch("$select.search",function(e){e&&!a.open&&a.multiple&&a.activate(!1,!0),a.activeIndex=0,(!a.refreshOnActive||a.refreshOnActive&&a.refreshIsActive)&&a.refresh(n.refresh)}),s.$watch("$select.refreshIsActive",function(e,t){angular.isUndefined(t)&&e&&a.refresh(n.refresh)});var f=s.$eval(n.refreshDelay);a.refreshDelay=void 0!==f?f:e.refreshDelay}}}}]),c.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,c,l,s,i,n,a,r){function o(){(h.resetSearchInput||void 0===h.resetSearchInput&&r.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var c,l,s=[];for(c=0;c0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:c=!1}return c}function p(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw a("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var l=t[h.activeIndex],s=l.offsetTop+l.clientHeight-e[0].scrollTop,i=e[0].offsetHeight;s>i?e[0].scrollTop+=s-i:s=h.items.length?0:h.activeIndex,h.refreshIsActive=!0,l(function(){h.search=e||h.search,h.searchInput[0].focus()}))},h.findGroupByName=function(e){return h.groups&&h.groups.filter(function(t){return t.name===e})[0]},h.parseRepeatAttr=function(e,c,l){function s(e){var s=t.$eval(c);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(s)?s(e):e[s],c=h.findGroupByName(t);c?c.items.push(e):h.groups.push({name:t,items:[e]})}),l){var i=t.$eval(l);angular.isFunction(i)?h.groups=i(h.groups):angular.isArray(i)&&(h.groups=u(h.groups,i))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function i(e){h.items=e}h.setItemsFn=c?s:i,h.parserResult=n.parse(e),h.isGrouped=!!c,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var c=h.selected;if(h.isEmpty()||angular.isArray(c)&&!c.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var l=e.filter(function(e){return c.indexOf(e)<0});h.setItemsFn(l)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw a("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})};var v;h.refresh=function(e){void 0!==e&&(v&&l.cancel(v),v=l(function(){t.$eval(e)},h.refreshDelay))},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),c=t===h.activeIndex;return c&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),c},h.isDisabled=function(e){if(!h.open)return!1;var t,c=h.items.indexOf(e[h.itemProperty]),l=!1;return c>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[c],l=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=l),l},h.select=function(e,c,s){if(void 0===e||!e._uiSelectChoiceDisabled){if(!h.items&&!h.search)return;if(!e||!e._uiSelectChoiceDisabled){var i=function(){t.$broadcast("uis:select",e),l(function(){h.onSelectCallback(t,a)}),h.closeOnSelect&&h.close(c),s&&"click"===s.type&&(h.clickTriggeredSelect=!0)},n={};n[h.parserResult.itemName]=e;var a={$item:e,$model:h.parserResult.modelMapper(t,n)},r=h.onBeforeSelectCallback(t,a);if(angular.isDefined(r)){if(!r)return;angular.isFunction(r.then)?r.then(function(e){e&&i(e)}):r===!0?i(e):i(r)}else i(e)}}},h.close=function(e){h.open&&(h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),o(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e))},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),l(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var c,l=h.selected[t];return l&&!angular.isUndefined(h.lockChoiceExpression)&&(c=!!e.$eval(h.lockChoiceExpression),l._uiSelectChoiceLocked=c),c};var g=null;h.sizeSearchInput=function(){var e=h.searchInput[0],c=h.searchInput.parent().parent()[0],s=function(){return c.clientWidth*!!e.offsetParent},i=function(t){if(0===t)return!1;var c=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>c&&(c=t),h.searchInput.css("width",c+"px"),!0};h.searchInput.css("width","10px"),l(function(){null!==g||i(s())||(g=t.$watch(s,function(e){i(e)&&(g(),g=null)}))})},h.searchInput.on("keydown",function(c){var l=c.which;t.$apply(function(){d(l)}),e.isVerticalMovement(l)&&h.items.length>0&&p(),(l===e.ENTER||l===e.ESC)&&(c.preventDefault(),c.stopPropagation())}),h.searchInput.on("keyup",function(c){c.which===e.TAB||e.isControl(c)||e.isFunctionKey(c)||c.which===e.ESC||e.isVerticalMovement(c.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:c})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),c.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,c,l,s,i,n){return{restrict:"EA",templateUrl:function(e,c){var l=c.theme||t.theme;return l+(angular.isDefined(c.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(s,a){return angular.isDefined(a.multiple)?s.append("").removeAttr("multiple"):s.append(""),function(s,a,r,o,u){function d(e){if(f.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(a[0],e.target):a[0].contains(e.target),!t&&!f.clickTriggeredSelect){var c=["input","button","textarea"],l=angular.element(e.target).scope(),i=l&&l.$select&&l.$select!==f;i||(i=~c.indexOf(e.target.tagName.toLowerCase())),f.close(i),s.$digest()}f.clickTriggeredSelect=!1}}function p(){var t=l(a);b=angular.element('
    '),b[0].style.width=t.width+"px",b[0].style.height=t.height+"px",a.after(b),w=a[0].style.width,e.find("body").append(a),a[0].style.position="absolute",a[0].style.left=t.left+"px",a[0].style.top=t.top+"px",a[0].style.width=t.width+"px"}function h(){null!==b&&(b.replaceWith(a),b=null,a[0].style.position="",a[0].style.left="",a[0].style.top="",a[0].style.width=w)}var f=o[0],v=o[1];f.generatedId=t.generateId(),f.baseTitle=r.title||"Select box",f.focusserTitle=f.baseTitle+" focus",f.focusserId="focusser-"+f.generatedId,f.closeOnSelect=function(){return angular.isDefined(r.closeOnSelect)?i(r.closeOnSelect)():t.closeOnSelect}(),f.onBeforeSelectCallback=i(r.onBeforeSelect),f.onSelectCallback=i(r.onSelect),f.onRemoveCallback=i(r.onRemove),f.onKeypressCallback=i(r.onKeypress),f.limit=angular.isDefined(r.limit)?parseInt(r.limit,10):void 0,f.ngModel=v,f.choiceGrouped=function(e){return f.isGrouped&&e&&e.name},r.tabindex&&r.$observe("tabindex",function(e){f.focusInput.attr("tabindex",e),a.removeAttr("tabindex")});var g=s.$eval(r.searchEnabled);f.searchEnabled=void 0!==g?g:t.searchEnabled;var m=s.$eval(r.sortable);f.sortable=void 0!==m?m:t.sortable,r.$observe("disabled",function(){f.disabled=void 0!==r.disabled?r.disabled:!1}),r.$observe("resetSearchInput",function(){var e=s.$eval(r.resetSearchInput);f.resetSearchInput=void 0!==e?e:!0}),angular.isDefined(r.autofocus)&&n(function(){f.setFocus()}),angular.isDefined(r.focusOn)&&s.$on(r.focusOn,function(){n(function(){f.setFocus()})}),e.on("click",d),s.$on("$destroy",function(){e.off("click",d)}),u(s,function(e){var t=angular.element("
    ").append(e),l=t.querySelectorAll(".ui-select-match");if(l.removeAttr("ui-select-match"),l.removeAttr("data-ui-select-match"),1!==l.length)throw c("transcluded","Expected 1 .ui-select-match but got '{0}'.",l.length);a.querySelectorAll(".ui-select-match").replaceWith(l);var s=t.querySelectorAll(".ui-select-choices");if(s.removeAttr("ui-select-choices"),s.removeAttr("data-ui-select-choices"),1!==s.length)throw c("transcluded","Expected 1 .ui-select-choices but got '{0}'.",s.length);a.querySelectorAll(".ui-select-choices").replaceWith(s)});var $=s.$eval(r.appendToBody);(void 0!==$?$:t.appendToBody)&&(s.$watch("$select.open",function(e){e?p():h()}),s.$on("$destroy",function(){h()}));var b=null,w="",E=null,x="direction-up";s.$watch("$select.open",function(t){if(t){if(E=angular.element(a).querySelectorAll(".ui-select-dropdown"),null===E)return;E[0].style.opacity=0,n(function(){var t=l(a),c=l(E);t.top+t.height+c.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&(E[0].style.position="absolute",E[0].style.top=-1*c.height+"px",a.addClass(x)),E[0].style.opacity=1})}else{if(null===E)return;E[0].style.position="",E[0].style.top="",a.removeClass(x)}})}}}}]),c.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,l=t.parent().attr("multiple");return c+(l?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,l,s){function i(e){s.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}s.lockChoiceExpression=l.uiLockChoice,l.$observe("placeholder",function(t){s.placeholder=void 0!==t?t:e.placeholder}),l.$observe("allowClear",i),i(l.allowClear),s.multiple&&s.sizeSearchInput()}}}]),c.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var c,l=this,s=e.$select;e.$evalAsync(function(){c=e.ngModel}),l.activeMatchIndex=-1,l.updateModel=function(){c.$setViewValue(Date.now()),l.refreshComponent()},l.refreshComponent=function(){s.refreshItems(),s.sizeSearchInput()},l.removeChoice=function(c){var i=s.selected[c];if(!i._uiSelectChoiceLocked){var n={};n[s.parserResult.itemName]=i,s.selected.splice(c,1),l.activeMatchIndex=-1,s.sizeSearchInput(),t(function(){s.onRemoveCallback(e,{$item:i,$model:s.parserResult.modelMapper(e,n)})}),l.updateModel()}},l.getPlaceholder=function(){return s.selected&&s.selected.length?void 0:s.placeholder}}],controllerAs:"$selectMultiple",link:function(l,s,i,n){function a(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function r(t){function c(){switch(t){case e.LEFT:return~d.activeMatchIndex?p:n;case e.RIGHT:return~d.activeMatchIndex&&r!==n?u:(o.activate(),!1);case e.BACKSPACE:return~d.activeMatchIndex?(d.removeChoice(r),p):n;case e.DELETE:return~d.activeMatchIndex?(d.removeChoice(d.activeMatchIndex),r):!1}}var l=a(o.searchInput[0]),s=o.selected.length,i=0,n=s-1,r=d.activeMatchIndex,u=d.activeMatchIndex+1,p=d.activeMatchIndex-1,h=r;return l>0||o.search.length&&t==e.RIGHT?!1:(o.close(),h=c(),d.activeMatchIndex=o.selected.length&&h!==!1?Math.min(n,Math.max(i,h)):-1,!0)}var o=n[0],u=l.ngModel=n[1],d=l.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,u.$parsers.unshift(function(){for(var e,t={},c=[],s=o.selected.length-1;s>=0;s--)t={},t[o.parserResult.itemName]=o.selected[s],e=o.parserResult.modelMapper(l,t),c.unshift(e);return c}),u.$formatters.unshift(function(e){var t,c=o.parserResult.source(l,{$select:{search:""}}),s={};if(!c)return e;var i=[],n=function(e,c){if(e&&e.length){for(var n=e.length-1;n>=0;n--){if(s[o.parserResult.itemName]=e[n],t=o.parserResult.modelMapper(l,s),o.parserResult.trackByExp){var a=/\.(.+)/.exec(o.parserResult.trackByExp);if(a.length>0&&t[a[1]]==c[a[1]])return i.unshift(e[n]),!0}if(angular.equals(t,c))return i.unshift(e[n]),!0}return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(o.selected,e[a])||n(c,e[a])||i.unshift(e[a]);return i}),l.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,d.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);o.selected=[]}o.selected=u.$viewValue,l.$evalAsync()},l.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),d.updateModel())}),l.$on("uis:activate",function(){d.activeMatchIndex=-1}),l.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(t){var c=t.which;l.$apply(function(){var t=!1;e.isHorizontalMovement(c)&&(t=r(c)),t&&c!=e.TAB})}),o.searchInput.on("blur",function(){c(function(){d.activeMatchIndex=-1})})}}}]),c.directive("uiSelectSingle",["$timeout","$compile",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(l,s,i,n){var a=n[0],r=n[1];r.$parsers.unshift(function(e){var t,c={};return c[a.parserResult.itemName]=e,t=a.parserResult.modelMapper(l,c)}),r.$formatters.unshift(function(e){var t,c=a.parserResult.source(l,{$select:{search:""}}),s={};if(c){var i=function(c){return s[a.parserResult.itemName]=c,t=a.parserResult.modelMapper(l,s),t==e};if(a.selected&&i(a.selected))return a.selected;for(var n=c.length-1;n>=0;n--)if(i(c[n]))return c[n]}return e}),l.$watch("$select.selected",function(e){r.$viewValue!==e&&r.$setViewValue(e)}),r.$render=function(){a.selected=r.$viewValue},l.$on("uis:select",function(e,t){a.selected=t}),l.$on("uis:close",function(e,c){t(function(){a.focusser.prop("disabled",!1),c||a.focusser[0].focus()},0,!1)}),l.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");c(o)(l),a.focusser=o,a.focusInput=o,s.parent().append(o),o.bind("focus",function(){l.$evalAsync(function(){a.focus=!0})}),o.bind("blur",function(){l.$evalAsync(function(){a.focus=!1})}),o.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),a.select(void 0),l.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),a.activate()),l.$digest()),void 0)}),o.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(a.activate(o.val()),o.val(""),l.$digest())})}}}]),c.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var l=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!l)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:l[2],source:t(l[3]),trackByExp:l[4],modelMapper:t(l[1]||l[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,l){var s=e+" in "+(l?"$group.items":t);return c&&(s+=" track by "+c),s}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("selectize/choices.tpl.html",'
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",'
    {{$select.placeholder}}
    '),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",'')}]),angular.module("ui.select").run(["$templateCache",function(e){e.put("select2/choices.tpl.html",'
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/dist/select.no-tpl.js b/dist/select.no-tpl.js new file mode 100644 index 000000000..ea71b1436 --- /dev/null +++ b/dist/select.no-tpl.js @@ -0,0 +1,1516 @@ +/*! + * ui-select + * http://github.com/angular-ui/ui-select + * Version: 0.12.1 - 2015-08-02T20:56:31.493Z + * License: MIT + */ + + +(function () { +"use strict"; + +var KEY = { + TAB: 9, + ENTER: 13, + ESC: 27, + SPACE: 32, + LEFT: 37, + UP: 38, + RIGHT: 39, + DOWN: 40, + SHIFT: 16, + CTRL: 17, + ALT: 18, + PAGE_UP: 33, + PAGE_DOWN: 34, + HOME: 36, + END: 35, + BACKSPACE: 8, + DELETE: 46, + COMMAND: 91, + + MAP: { 91 : "COMMAND", 8 : "BACKSPACE" , 9 : "TAB" , 13 : "ENTER" , 16 : "SHIFT" , 17 : "CTRL" , 18 : "ALT" , 19 : "PAUSEBREAK" , 20 : "CAPSLOCK" , 27 : "ESC" , 32 : "SPACE" , 33 : "PAGE_UP", 34 : "PAGE_DOWN" , 35 : "END" , 36 : "HOME" , 37 : "LEFT" , 38 : "UP" , 39 : "RIGHT" , 40 : "DOWN" , 43 : "+" , 44 : "PRINTSCREEN" , 45 : "INSERT" , 46 : "DELETE", 48 : "0" , 49 : "1" , 50 : "2" , 51 : "3" , 52 : "4" , 53 : "5" , 54 : "6" , 55 : "7" , 56 : "8" , 57 : "9" , 59 : ";", 61 : "=" , 65 : "A" , 66 : "B" , 67 : "C" , 68 : "D" , 69 : "E" , 70 : "F" , 71 : "G" , 72 : "H" , 73 : "I" , 74 : "J" , 75 : "K" , 76 : "L", 77 : "M" , 78 : "N" , 79 : "O" , 80 : "P" , 81 : "Q" , 82 : "R" , 83 : "S" , 84 : "T" , 85 : "U" , 86 : "V" , 87 : "W" , 88 : "X" , 89 : "Y" , 90 : "Z", 96 : "0" , 97 : "1" , 98 : "2" , 99 : "3" , 100 : "4" , 101 : "5" , 102 : "6" , 103 : "7" , 104 : "8" , 105 : "9", 106 : "*" , 107 : "+" , 109 : "-" , 110 : "." , 111 : "/", 112 : "F1" , 113 : "F2" , 114 : "F3" , 115 : "F4" , 116 : "F5" , 117 : "F6" , 118 : "F7" , 119 : "F8" , 120 : "F9" , 121 : "F10" , 122 : "F11" , 123 : "F12", 144 : "NUMLOCK" , 145 : "SCROLLLOCK" , 186 : ";" , 187 : "=" , 188 : "," , 189 : "-" , 190 : "." , 191 : "/" , 192 : "`" , 219 : "[" , 220 : "\\" , 221 : "]" , 222 : "'" + }, + + isControl: function (e) { + var k = e.which; + switch (k) { + case KEY.COMMAND: + case KEY.SHIFT: + case KEY.CTRL: + case KEY.ALT: + return true; + } + + if (e.metaKey) return true; + + return false; + }, + isFunctionKey: function (k) { + k = k.which ? k.which : k; + return k >= 112 && k <= 123; + }, + isVerticalMovement: function (k){ + return ~[KEY.UP, KEY.DOWN].indexOf(k); + }, + isHorizontalMovement: function (k){ + return ~[KEY.LEFT,KEY.RIGHT,KEY.BACKSPACE,KEY.DELETE].indexOf(k); + } + }; + +/** + * Add querySelectorAll() to jqLite. + * + * jqLite find() is limited to lookups by tag name. + * TODO This will change with future versions of AngularJS, to be removed when this happens + * + * See jqLite.find - why not use querySelectorAll? https://github.com/angular/angular.js/issues/3586 + * See feat(jqLite): use querySelectorAll instead of getElementsByTagName in jqLite.find https://github.com/angular/angular.js/pull/3598 + */ +if (angular.element.prototype.querySelectorAll === undefined) { + angular.element.prototype.querySelectorAll = function(selector) { + return angular.element(this[0].querySelectorAll(selector)); + }; +} + +/** + * Add closest() to jqLite. + */ +if (angular.element.prototype.closest === undefined) { + angular.element.prototype.closest = function( selector) { + var elem = this[0]; + var matchesSelector = elem.matches || elem.webkitMatchesSelector || elem.mozMatchesSelector || elem.msMatchesSelector; + + while (elem) { + if (matchesSelector.bind(elem)(selector)) { + return elem; + } else { + elem = elem.parentElement; + } + } + return false; + }; +} + +var latestId = 0; + +var uis = angular.module('ui.select', []) + +.constant('uiSelectConfig', { + theme: 'bootstrap', + searchEnabled: true, + sortable: false, + placeholder: '', // Empty by default, like HTML tag "); + $compile(focusser)(scope); + $select.focusser = focusser; + + //Input that will handle focus + $select.focusInput = focusser; + + element.parent().append(focusser); + focusser.bind("focus", function(){ + scope.$evalAsync(function(){ + $select.focus = true; + }); + }); + focusser.bind("blur", function(){ + scope.$evalAsync(function(){ + $select.focus = false; + }); + }); + focusser.bind("keydown", function(e){ + + if (e.which === KEY.BACKSPACE) { + e.preventDefault(); + e.stopPropagation(); + $select.select(undefined); + scope.$apply(); + return; + } + + if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) { + return; + } + + if (e.which == KEY.DOWN || e.which == KEY.UP || e.which == KEY.ENTER || e.which == KEY.SPACE){ + e.preventDefault(); + e.stopPropagation(); + $select.activate(); + } + + scope.$digest(); + }); + + focusser.bind("keyup input", function(e){ + + if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { + return; + } + + $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input + focusser.val(''); + scope.$digest(); + + }); + + + } + }; +}]); +/** + * Parses "repeat" attribute. + * + * Taken from AngularJS ngRepeat source code + * See https://github.com/angular/angular.js/blob/v1.2.15/src/ng/directive/ngRepeat.js#L211 + * + * Original discussion about parsing "repeat" attribute instead of fully relying on ng-repeat: + * https://github.com/angular-ui/ui-select/commit/5dd63ad#commitcomment-5504697 + */ + +uis.service('uisRepeatParser', ['uiSelectMinErr','$parse', function(uiSelectMinErr, $parse) { + var self = this; + + /** + * Example: + * expression = "address in addresses | filter: {street: $select.search} track by $index" + * itemName = "address", + * source = "addresses | filter: {street: $select.search}", + * trackByExp = "$index", + */ + self.parse = function(expression) { + + var match = expression.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/); + + if (!match) { + throw uiSelectMinErr('iexp', "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.", + expression); + } + + return { + itemName: match[2], // (lhs) Left-hand side, + source: $parse(match[3]), + trackByExp: match[4], + modelMapper: $parse(match[1] || match[2]) + }; + + }; + + self.getGroupNgRepeatExpression = function() { + return '$group in $select.groups'; + }; + + self.getNgRepeatExpression = function(itemName, source, trackByExp, grouped) { + var expression = itemName + ' in ' + (grouped ? '$group.items' : source); + if (trackByExp) { + expression += ' track by ' + trackByExp; + } + return expression; + }; +}]); + +}()); \ No newline at end of file diff --git a/dist/select.no-tpl.min.js b/dist/select.no-tpl.min.js new file mode 100644 index 000000000..f7f98e2d6 --- /dev/null +++ b/dist/select.no-tpl.min.js @@ -0,0 +1,7 @@ +/*! + * ui-select + * http://github.com/angular-ui/ui-select + * Version: 0.12.1 - 2015-08-02T20:56:31.493Z + * License: MIT + */ +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var n=t.which;switch(n){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,n=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",refreshDelay:1e3,closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,r,i){i(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var r=n[0].getBoundingClientRect();return{width:r.width||n.prop("offsetWidth"),height:r.height||n.prop("offsetHeight"),top:r.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:r.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);n.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,r){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(i,c){if(!c.repeat)throw n("repeat","Expected 'repeat' expression.");return function(i,c,l,s,o){var a=l.groupBy,u=l.groupFilter;if(s.parseRepeatAttr(l.repeat,a,u),s.disableChoiceExpression=l.uiDisableChoice,s.onHighlightCallback=l.onHighlight,s.refreshOnActive=i.$eval(l.refreshOnActive),a){var p=c.querySelectorAll(".ui-select-choices-group");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",p.length);p.attr("ng-repeat",t.getGroupNgRepeatExpression())}var f=c.querySelectorAll(".ui-select-choices-row");if(1!==f.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",f.length);f.attr("ng-repeat",t.getNgRepeatExpression(s.parserResult.itemName,"$select.items",s.parserResult.trackByExp,a)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+s.parserResult.itemName+")").attr("ng-click","$select.select("+s.parserResult.itemName+",false,$event)");var h=c.querySelectorAll(".ui-select-choices-row-inner");if(1!==h.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",h.length);h.attr("uis-transclude-append",""),r(c,o)(i),i.$watch("$select.search",function(e){e&&!s.open&&s.multiple&&s.activate(!1,!0),s.activeIndex=0,(!s.refreshOnActive||s.refreshOnActive&&s.refreshIsActive)&&s.refresh(l.refresh)}),i.$watch("$select.refreshIsActive",function(e,t){angular.isUndefined(t)&&e&&s.refresh(l.refresh)});var d=i.$eval(l.refreshDelay);s.refreshDelay=void 0!==d?d:e.refreshDelay}}}}]),n.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,n,r,i,c,l,s,o){function a(){(h.resetSearchInput||void 0===h.resetSearchInput&&o.resetSearchInput)&&(h.search=d,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var n,r,i=[];for(n=0;n0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:n=!1}return n}function f(){var e=n.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw s("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var r=t[h.activeIndex],i=r.offsetTop+r.clientHeight-e[0].scrollTop,c=e[0].offsetHeight;i>c?e[0].scrollTop+=i-c:i=h.items.length?0:h.activeIndex,h.refreshIsActive=!0,r(function(){h.search=e||h.search,h.searchInput[0].focus()}))},h.findGroupByName=function(e){return h.groups&&h.groups.filter(function(t){return t.name===e})[0]},h.parseRepeatAttr=function(e,n,r){function i(e){var i=t.$eval(n);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(i)?i(e):e[i],n=h.findGroupByName(t);n?n.items.push(e):h.groups.push({name:t,items:[e]})}),r){var c=t.$eval(r);angular.isFunction(c)?h.groups=c(h.groups):angular.isArray(c)&&(h.groups=u(h.groups,c))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function c(e){h.items=e}h.setItemsFn=n?i:c,h.parserResult=l.parse(e),h.isGrouped=!!n,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var n=h.selected;if(h.isEmpty()||angular.isArray(n)&&!n.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var r=e.filter(function(e){return n.indexOf(e)<0});h.setItemsFn(r)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw s("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})};var v;h.refresh=function(e){void 0!==e&&(v&&r.cancel(v),v=r(function(){t.$eval(e)},h.refreshDelay))},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),n=t===h.activeIndex;return n&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),n},h.isDisabled=function(e){if(!h.open)return!1;var t,n=h.items.indexOf(e[h.itemProperty]),r=!1;return n>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[n],r=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=r),r},h.select=function(e,n,i){if(void 0===e||!e._uiSelectChoiceDisabled){if(!h.items&&!h.search)return;if(!e||!e._uiSelectChoiceDisabled){var c=function(){t.$broadcast("uis:select",e),r(function(){h.onSelectCallback(t,s)}),h.closeOnSelect&&h.close(n),i&&"click"===i.type&&(h.clickTriggeredSelect=!0)},l={};l[h.parserResult.itemName]=e;var s={$item:e,$model:h.parserResult.modelMapper(t,l)},o=h.onBeforeSelectCallback(t,s);if(angular.isDefined(o)){if(!o)return;angular.isFunction(o.then)?o.then(function(e){e&&c(e)}):o===!0?c(e):c(o)}else c(e)}}},h.close=function(e){h.open&&(h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),a(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e))},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),r(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var n,r=h.selected[t];return r&&!angular.isUndefined(h.lockChoiceExpression)&&(n=!!e.$eval(h.lockChoiceExpression),r._uiSelectChoiceLocked=n),n};var m=null;h.sizeSearchInput=function(){var e=h.searchInput[0],n=h.searchInput.parent().parent()[0],i=function(){return n.clientWidth*!!e.offsetParent},c=function(t){if(0===t)return!1;var n=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=t),h.searchInput.css("width",n+"px"),!0};h.searchInput.css("width","10px"),r(function(){null!==m||c(i())||(m=t.$watch(i,function(e){c(e)&&(m(),m=null)}))})},h.searchInput.on("keydown",function(n){var r=n.which;t.$apply(function(){p(r)}),e.isVerticalMovement(r)&&h.items.length>0&&f(),(r===e.ENTER||r===e.ESC)&&(n.preventDefault(),n.stopPropagation())}),h.searchInput.on("keyup",function(n){n.which===e.TAB||e.isControl(n)||e.isFunctionKey(n)||n.which===e.ESC||e.isVerticalMovement(n.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:n})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),n.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,r,i,c,l){return{restrict:"EA",templateUrl:function(e,n){var r=n.theme||t.theme;return r+(angular.isDefined(n.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(i,s){return angular.isDefined(s.multiple)?i.append("").removeAttr("multiple"):i.append(""),function(i,s,o,a,u){function p(e){if(d.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(s[0],e.target):s[0].contains(e.target),!t&&!d.clickTriggeredSelect){var n=["input","button","textarea"],r=angular.element(e.target).scope(),c=r&&r.$select&&r.$select!==d;c||(c=~n.indexOf(e.target.tagName.toLowerCase())),d.close(c),i.$digest()}d.clickTriggeredSelect=!1}}function f(){var t=r(s);E=angular.element('
    '),E[0].style.width=t.width+"px",E[0].style.height=t.height+"px",s.after(E),S=s[0].style.width,e.find("body").append(s),s[0].style.position="absolute",s[0].style.left=t.left+"px",s[0].style.top=t.top+"px",s[0].style.width=t.width+"px"}function h(){null!==E&&(E.replaceWith(s),E=null,s[0].style.position="",s[0].style.left="",s[0].style.top="",s[0].style.width=S)}var d=a[0],v=a[1];d.generatedId=t.generateId(),d.baseTitle=o.title||"Select box",d.focusserTitle=d.baseTitle+" focus",d.focusserId="focusser-"+d.generatedId,d.closeOnSelect=function(){return angular.isDefined(o.closeOnSelect)?c(o.closeOnSelect)():t.closeOnSelect}(),d.onBeforeSelectCallback=c(o.onBeforeSelect),d.onSelectCallback=c(o.onSelect),d.onRemoveCallback=c(o.onRemove),d.onKeypressCallback=c(o.onKeypress),d.limit=angular.isDefined(o.limit)?parseInt(o.limit,10):void 0,d.ngModel=v,d.choiceGrouped=function(e){return d.isGrouped&&e&&e.name},o.tabindex&&o.$observe("tabindex",function(e){d.focusInput.attr("tabindex",e),s.removeAttr("tabindex")});var m=i.$eval(o.searchEnabled);d.searchEnabled=void 0!==m?m:t.searchEnabled;var g=i.$eval(o.sortable);d.sortable=void 0!==g?g:t.sortable,o.$observe("disabled",function(){d.disabled=void 0!==o.disabled?o.disabled:!1}),o.$observe("resetSearchInput",function(){var e=i.$eval(o.resetSearchInput);d.resetSearchInput=void 0!==e?e:!0}),angular.isDefined(o.autofocus)&&l(function(){d.setFocus()}),angular.isDefined(o.focusOn)&&i.$on(o.focusOn,function(){l(function(){d.setFocus()})}),e.on("click",p),i.$on("$destroy",function(){e.off("click",p)}),u(i,function(e){var t=angular.element("
    ").append(e),r=t.querySelectorAll(".ui-select-match");if(r.removeAttr("ui-select-match"),r.removeAttr("data-ui-select-match"),1!==r.length)throw n("transcluded","Expected 1 .ui-select-match but got '{0}'.",r.length);s.querySelectorAll(".ui-select-match").replaceWith(r);var i=t.querySelectorAll(".ui-select-choices");if(i.removeAttr("ui-select-choices"),i.removeAttr("data-ui-select-choices"),1!==i.length)throw n("transcluded","Expected 1 .ui-select-choices but got '{0}'.",i.length);s.querySelectorAll(".ui-select-choices").replaceWith(i)});var $=i.$eval(o.appendToBody);(void 0!==$?$:t.appendToBody)&&(i.$watch("$select.open",function(e){e?f():h()}),i.$on("$destroy",function(){h()}));var E=null,S="",y=null,b="direction-up";i.$watch("$select.open",function(t){if(t){if(y=angular.element(s).querySelectorAll(".ui-select-dropdown"),null===y)return;y[0].style.opacity=0,l(function(){var t=r(s),n=r(y);t.top+t.height+n.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&(y[0].style.position="absolute",y[0].style.top=-1*n.height+"px",s.addClass(b)),y[0].style.opacity=1})}else{if(null===y)return;y[0].style.position="",y[0].style.top="",s.removeClass(b)}})}}}}]),n.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,r=t.parent().attr("multiple");return n+(r?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,r,i){function c(e){i.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}i.lockChoiceExpression=r.uiLockChoice,r.$observe("placeholder",function(t){i.placeholder=void 0!==t?t:e.placeholder}),r.$observe("allowClear",c),c(r.allowClear),i.multiple&&i.sizeSearchInput()}}}]),n.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,r=this,i=e.$select;e.$evalAsync(function(){n=e.ngModel}),r.activeMatchIndex=-1,r.updateModel=function(){n.$setViewValue(Date.now()),r.refreshComponent()},r.refreshComponent=function(){i.refreshItems(),i.sizeSearchInput()},r.removeChoice=function(n){var c=i.selected[n];if(!c._uiSelectChoiceLocked){var l={};l[i.parserResult.itemName]=c,i.selected.splice(n,1),r.activeMatchIndex=-1,i.sizeSearchInput(),t(function(){i.onRemoveCallback(e,{$item:c,$model:i.parserResult.modelMapper(e,l)})}),r.updateModel()}},r.getPlaceholder=function(){return i.selected&&i.selected.length?void 0:i.placeholder}}],controllerAs:"$selectMultiple",link:function(r,i,c,l){function s(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function o(t){function n(){switch(t){case e.LEFT:return~p.activeMatchIndex?f:l;case e.RIGHT:return~p.activeMatchIndex&&o!==l?u:(a.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(o),f):l;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),o):!1}}var r=s(a.searchInput[0]),i=a.selected.length,c=0,l=i-1,o=p.activeMatchIndex,u=p.activeMatchIndex+1,f=p.activeMatchIndex-1,h=o;return r>0||a.search.length&&t==e.RIGHT?!1:(a.close(),h=n(),p.activeMatchIndex=a.selected.length&&h!==!1?Math.min(l,Math.max(c,h)):-1,!0)}var a=l[0],u=r.ngModel=l[1],p=r.$selectMultiple;a.multiple=!0,a.removeSelected=!0,a.focusInput=a.searchInput,u.$parsers.unshift(function(){for(var e,t={},n=[],i=a.selected.length-1;i>=0;i--)t={},t[a.parserResult.itemName]=a.selected[i],e=a.parserResult.modelMapper(r,t),n.unshift(e);return n}),u.$formatters.unshift(function(e){var t,n=a.parserResult.source(r,{$select:{search:""}}),i={};if(!n)return e;var c=[],l=function(e,n){if(e&&e.length){for(var l=e.length-1;l>=0;l--){if(i[a.parserResult.itemName]=e[l],t=a.parserResult.modelMapper(r,i),a.parserResult.trackByExp){var s=/\.(.+)/.exec(a.parserResult.trackByExp);if(s.length>0&&t[s[1]]==n[s[1]])return c.unshift(e[l]),!0}if(angular.equals(t,n))return c.unshift(e[l]),!0}return!1}};if(!e)return c;for(var s=e.length-1;s>=0;s--)l(a.selected,e[s])||l(n,e[s])||c.unshift(e[s]);return c}),r.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);a.selected=[]}a.selected=u.$viewValue,r.$evalAsync()},r.$on("uis:select",function(e,t){a.selected.length>=a.limit||(a.selected.push(t),p.updateModel())}),r.$on("uis:activate",function(){p.activeMatchIndex=-1}),r.$watch("$select.disabled",function(e,t){t&&!e&&a.sizeSearchInput()}),a.searchInput.on("keydown",function(t){var n=t.which;r.$apply(function(){var t=!1;e.isHorizontalMovement(n)&&(t=o(n)),t&&n!=e.TAB})}),a.searchInput.on("blur",function(){n(function(){p.activeMatchIndex=-1})})}}}]),n.directive("uiSelectSingle",["$timeout","$compile",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(r,i,c,l){var s=l[0],o=l[1];o.$parsers.unshift(function(e){var t,n={};return n[s.parserResult.itemName]=e,t=s.parserResult.modelMapper(r,n)}),o.$formatters.unshift(function(e){var t,n=s.parserResult.source(r,{$select:{search:""}}),i={};if(n){var c=function(n){return i[s.parserResult.itemName]=n,t=s.parserResult.modelMapper(r,i),t==e};if(s.selected&&c(s.selected))return s.selected;for(var l=n.length-1;l>=0;l--)if(c(n[l]))return n[l]}return e}),r.$watch("$select.selected",function(e){o.$viewValue!==e&&o.$setViewValue(e)}),o.$render=function(){s.selected=o.$viewValue},r.$on("uis:select",function(e,t){s.selected=t}),r.$on("uis:close",function(e,n){t(function(){s.focusser.prop("disabled",!1),n||s.focusser[0].focus()},0,!1)}),r.$on("uis:activate",function(){a.prop("disabled",!0)});var a=angular.element("");n(a)(r),s.focusser=a,s.focusInput=a,i.parent().append(a),a.bind("focus",function(){r.$evalAsync(function(){s.focus=!0})}),a.bind("blur",function(){r.$evalAsync(function(){s.focus=!1})}),a.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),s.select(void 0),r.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),s.activate()),r.$digest()),void 0)}),a.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(s.activate(a.val()),a.val(""),r.$digest())})}}}]),n.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var r=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!r)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:r[2],source:t(r[3]),trackByExp:r[4],modelMapper:t(r[1]||r[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,r){var i=e+" in "+(r?"$group.items":t);return n&&(i+=" track by "+n),i}}])}(); \ No newline at end of file diff --git a/dist/select.select2.js b/dist/select.select2.js new file mode 100644 index 000000000..5898e0d1a --- /dev/null +++ b/dist/select.select2.js @@ -0,0 +1,1521 @@ +/*! + * ui-select + * http://github.com/angular-ui/ui-select + * Version: 0.12.1 - 2015-08-02T20:56:31.513Z + * License: MIT + */ + + +(function () { +"use strict"; + +var KEY = { + TAB: 9, + ENTER: 13, + ESC: 27, + SPACE: 32, + LEFT: 37, + UP: 38, + RIGHT: 39, + DOWN: 40, + SHIFT: 16, + CTRL: 17, + ALT: 18, + PAGE_UP: 33, + PAGE_DOWN: 34, + HOME: 36, + END: 35, + BACKSPACE: 8, + DELETE: 46, + COMMAND: 91, + + MAP: { 91 : "COMMAND", 8 : "BACKSPACE" , 9 : "TAB" , 13 : "ENTER" , 16 : "SHIFT" , 17 : "CTRL" , 18 : "ALT" , 19 : "PAUSEBREAK" , 20 : "CAPSLOCK" , 27 : "ESC" , 32 : "SPACE" , 33 : "PAGE_UP", 34 : "PAGE_DOWN" , 35 : "END" , 36 : "HOME" , 37 : "LEFT" , 38 : "UP" , 39 : "RIGHT" , 40 : "DOWN" , 43 : "+" , 44 : "PRINTSCREEN" , 45 : "INSERT" , 46 : "DELETE", 48 : "0" , 49 : "1" , 50 : "2" , 51 : "3" , 52 : "4" , 53 : "5" , 54 : "6" , 55 : "7" , 56 : "8" , 57 : "9" , 59 : ";", 61 : "=" , 65 : "A" , 66 : "B" , 67 : "C" , 68 : "D" , 69 : "E" , 70 : "F" , 71 : "G" , 72 : "H" , 73 : "I" , 74 : "J" , 75 : "K" , 76 : "L", 77 : "M" , 78 : "N" , 79 : "O" , 80 : "P" , 81 : "Q" , 82 : "R" , 83 : "S" , 84 : "T" , 85 : "U" , 86 : "V" , 87 : "W" , 88 : "X" , 89 : "Y" , 90 : "Z", 96 : "0" , 97 : "1" , 98 : "2" , 99 : "3" , 100 : "4" , 101 : "5" , 102 : "6" , 103 : "7" , 104 : "8" , 105 : "9", 106 : "*" , 107 : "+" , 109 : "-" , 110 : "." , 111 : "/", 112 : "F1" , 113 : "F2" , 114 : "F3" , 115 : "F4" , 116 : "F5" , 117 : "F6" , 118 : "F7" , 119 : "F8" , 120 : "F9" , 121 : "F10" , 122 : "F11" , 123 : "F12", 144 : "NUMLOCK" , 145 : "SCROLLLOCK" , 186 : ";" , 187 : "=" , 188 : "," , 189 : "-" , 190 : "." , 191 : "/" , 192 : "`" , 219 : "[" , 220 : "\\" , 221 : "]" , 222 : "'" + }, + + isControl: function (e) { + var k = e.which; + switch (k) { + case KEY.COMMAND: + case KEY.SHIFT: + case KEY.CTRL: + case KEY.ALT: + return true; + } + + if (e.metaKey) return true; + + return false; + }, + isFunctionKey: function (k) { + k = k.which ? k.which : k; + return k >= 112 && k <= 123; + }, + isVerticalMovement: function (k){ + return ~[KEY.UP, KEY.DOWN].indexOf(k); + }, + isHorizontalMovement: function (k){ + return ~[KEY.LEFT,KEY.RIGHT,KEY.BACKSPACE,KEY.DELETE].indexOf(k); + } + }; + +/** + * Add querySelectorAll() to jqLite. + * + * jqLite find() is limited to lookups by tag name. + * TODO This will change with future versions of AngularJS, to be removed when this happens + * + * See jqLite.find - why not use querySelectorAll? https://github.com/angular/angular.js/issues/3586 + * See feat(jqLite): use querySelectorAll instead of getElementsByTagName in jqLite.find https://github.com/angular/angular.js/pull/3598 + */ +if (angular.element.prototype.querySelectorAll === undefined) { + angular.element.prototype.querySelectorAll = function(selector) { + return angular.element(this[0].querySelectorAll(selector)); + }; +} + +/** + * Add closest() to jqLite. + */ +if (angular.element.prototype.closest === undefined) { + angular.element.prototype.closest = function( selector) { + var elem = this[0]; + var matchesSelector = elem.matches || elem.webkitMatchesSelector || elem.mozMatchesSelector || elem.msMatchesSelector; + + while (elem) { + if (matchesSelector.bind(elem)(selector)) { + return elem; + } else { + elem = elem.parentElement; + } + } + return false; + }; +} + +var latestId = 0; + +var uis = angular.module('ui.select', []) + +.constant('uiSelectConfig', { + theme: 'bootstrap', + searchEnabled: true, + sortable: false, + placeholder: '', // Empty by default, like HTML tag "); + $compile(focusser)(scope); + $select.focusser = focusser; + + //Input that will handle focus + $select.focusInput = focusser; + + element.parent().append(focusser); + focusser.bind("focus", function(){ + scope.$evalAsync(function(){ + $select.focus = true; + }); + }); + focusser.bind("blur", function(){ + scope.$evalAsync(function(){ + $select.focus = false; + }); + }); + focusser.bind("keydown", function(e){ + + if (e.which === KEY.BACKSPACE) { + e.preventDefault(); + e.stopPropagation(); + $select.select(undefined); + scope.$apply(); + return; + } + + if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) { + return; + } + + if (e.which == KEY.DOWN || e.which == KEY.UP || e.which == KEY.ENTER || e.which == KEY.SPACE){ + e.preventDefault(); + e.stopPropagation(); + $select.activate(); + } + + scope.$digest(); + }); + + focusser.bind("keyup input", function(e){ + + if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { + return; + } + + $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input + focusser.val(''); + scope.$digest(); + + }); + + + } + }; +}]); +/** + * Parses "repeat" attribute. + * + * Taken from AngularJS ngRepeat source code + * See https://github.com/angular/angular.js/blob/v1.2.15/src/ng/directive/ngRepeat.js#L211 + * + * Original discussion about parsing "repeat" attribute instead of fully relying on ng-repeat: + * https://github.com/angular-ui/ui-select/commit/5dd63ad#commitcomment-5504697 + */ + +uis.service('uisRepeatParser', ['uiSelectMinErr','$parse', function(uiSelectMinErr, $parse) { + var self = this; + + /** + * Example: + * expression = "address in addresses | filter: {street: $select.search} track by $index" + * itemName = "address", + * source = "addresses | filter: {street: $select.search}", + * trackByExp = "$index", + */ + self.parse = function(expression) { + + var match = expression.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/); + + if (!match) { + throw uiSelectMinErr('iexp', "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.", + expression); + } + + return { + itemName: match[2], // (lhs) Left-hand side, + source: $parse(match[3]), + trackByExp: match[4], + modelMapper: $parse(match[1] || match[2]) + }; + + }; + + self.getGroupNgRepeatExpression = function() { + return '$group in $select.groups'; + }; + + self.getNgRepeatExpression = function(itemName, source, trackByExp, grouped) { + var expression = itemName + ' in ' + (grouped ? '$group.items' : source); + if (trackByExp) { + expression += ' track by ' + trackByExp; + } + return expression; + }; +}]); + +}()); +angular.module("ui.select").run(["$templateCache", function($templateCache) {$templateCache.put("select2/choices.tpl.html","
    "); +$templateCache.put("select2/match-multiple.tpl.html","
  • "); +$templateCache.put("select2/match.tpl.html","{{$select.placeholder}} "); +$templateCache.put("select2/select-multiple.tpl.html","
    "); +$templateCache.put("select2/select.tpl.html","
    ");}]); \ No newline at end of file diff --git a/dist/select.select2.min.js b/dist/select.select2.min.js new file mode 100644 index 000000000..6934a9d78 --- /dev/null +++ b/dist/select.select2.min.js @@ -0,0 +1,7 @@ +/*! + * ui-select + * http://github.com/angular-ui/ui-select + * Version: 0.12.1 - 2015-08-02T20:56:31.513Z + * License: MIT + */ +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],c=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(c.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,c=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",refreshDelay:1e3,closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,l,s){s(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(c){var l=c[0].getBoundingClientRect();return{width:l.width||c.prop("offsetWidth"),height:l.height||c.prop("offsetHeight"),top:l.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:l.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);c.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,c,l){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(s,i){if(!i.repeat)throw c("repeat","Expected 'repeat' expression.");return function(s,i,n,r,a){var o=n.groupBy,u=n.groupFilter;if(r.parseRepeatAttr(n.repeat,o,u),r.disableChoiceExpression=n.uiDisableChoice,r.onHighlightCallback=n.onHighlight,r.refreshOnActive=s.$eval(n.refreshOnActive),o){var p=i.querySelectorAll(".ui-select-choices-group");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",p.length);p.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=i.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(r.parserResult.itemName,"$select.items",r.parserResult.trackByExp,o)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+r.parserResult.itemName+")").attr("ng-click","$select.select("+r.parserResult.itemName+",false,$event)");var h=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==h.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",h.length);h.attr("uis-transclude-append",""),l(i,a)(s),s.$watch("$select.search",function(e){e&&!r.open&&r.multiple&&r.activate(!1,!0),r.activeIndex=0,(!r.refreshOnActive||r.refreshOnActive&&r.refreshIsActive)&&r.refresh(n.refresh)}),s.$watch("$select.refreshIsActive",function(e,t){angular.isUndefined(t)&&e&&r.refresh(n.refresh)});var f=s.$eval(n.refreshDelay);r.refreshDelay=void 0!==f?f:e.refreshDelay}}}}]),c.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,c,l,s,i,n,r,a){function o(){(h.resetSearchInput||void 0===h.resetSearchInput&&a.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var c,l,s=[];for(c=0;c0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:c=!1}return c}function d(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw r("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var l=t[h.activeIndex],s=l.offsetTop+l.clientHeight-e[0].scrollTop,i=e[0].offsetHeight;s>i?e[0].scrollTop+=s-i:s=h.items.length?0:h.activeIndex,h.refreshIsActive=!0,l(function(){h.search=e||h.search,h.searchInput[0].focus()}))},h.findGroupByName=function(e){return h.groups&&h.groups.filter(function(t){return t.name===e})[0]},h.parseRepeatAttr=function(e,c,l){function s(e){var s=t.$eval(c);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(s)?s(e):e[s],c=h.findGroupByName(t);c?c.items.push(e):h.groups.push({name:t,items:[e]})}),l){var i=t.$eval(l);angular.isFunction(i)?h.groups=i(h.groups):angular.isArray(i)&&(h.groups=u(h.groups,i))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function i(e){h.items=e}h.setItemsFn=c?s:i,h.parserResult=n.parse(e),h.isGrouped=!!c,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var c=h.selected;if(h.isEmpty()||angular.isArray(c)&&!c.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var l=e.filter(function(e){return c.indexOf(e)<0});h.setItemsFn(l)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw r("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})};var v;h.refresh=function(e){void 0!==e&&(v&&l.cancel(v),v=l(function(){t.$eval(e)},h.refreshDelay))},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),c=t===h.activeIndex;return c&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),c},h.isDisabled=function(e){if(!h.open)return!1;var t,c=h.items.indexOf(e[h.itemProperty]),l=!1;return c>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[c],l=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=l),l},h.select=function(e,c,s){if(void 0===e||!e._uiSelectChoiceDisabled){if(!h.items&&!h.search)return;if(!e||!e._uiSelectChoiceDisabled){var i=function(){t.$broadcast("uis:select",e),l(function(){h.onSelectCallback(t,r)}),h.closeOnSelect&&h.close(c),s&&"click"===s.type&&(h.clickTriggeredSelect=!0)},n={};n[h.parserResult.itemName]=e;var r={$item:e,$model:h.parserResult.modelMapper(t,n)},a=h.onBeforeSelectCallback(t,r);if(angular.isDefined(a)){if(!a)return;angular.isFunction(a.then)?a.then(function(e){e&&i(e)}):a===!0?i(e):i(a)}else i(e)}}},h.close=function(e){h.open&&(h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),o(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e))},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),l(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var c,l=h.selected[t];return l&&!angular.isUndefined(h.lockChoiceExpression)&&(c=!!e.$eval(h.lockChoiceExpression),l._uiSelectChoiceLocked=c),c};var g=null;h.sizeSearchInput=function(){var e=h.searchInput[0],c=h.searchInput.parent().parent()[0],s=function(){return c.clientWidth*!!e.offsetParent},i=function(t){if(0===t)return!1;var c=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>c&&(c=t),h.searchInput.css("width",c+"px"),!0};h.searchInput.css("width","10px"),l(function(){null!==g||i(s())||(g=t.$watch(s,function(e){i(e)&&(g(),g=null)}))})},h.searchInput.on("keydown",function(c){var l=c.which;t.$apply(function(){p(l)}),e.isVerticalMovement(l)&&h.items.length>0&&d(),(l===e.ENTER||l===e.ESC)&&(c.preventDefault(),c.stopPropagation())}),h.searchInput.on("keyup",function(c){c.which===e.TAB||e.isControl(c)||e.isFunctionKey(c)||c.which===e.ESC||e.isVerticalMovement(c.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:c})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),c.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,c,l,s,i,n){return{restrict:"EA",templateUrl:function(e,c){var l=c.theme||t.theme;return l+(angular.isDefined(c.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(s,r){return angular.isDefined(r.multiple)?s.append("").removeAttr("multiple"):s.append(""),function(s,r,a,o,u){function p(e){if(f.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(r[0],e.target):r[0].contains(e.target),!t&&!f.clickTriggeredSelect){var c=["input","button","textarea"],l=angular.element(e.target).scope(),i=l&&l.$select&&l.$select!==f;i||(i=~c.indexOf(e.target.tagName.toLowerCase())),f.close(i),s.$digest()}f.clickTriggeredSelect=!1}}function d(){var t=l(r);b=angular.element('
    '),b[0].style.width=t.width+"px",b[0].style.height=t.height+"px",r.after(b),E=r[0].style.width,e.find("body").append(r),r[0].style.position="absolute",r[0].style.left=t.left+"px",r[0].style.top=t.top+"px",r[0].style.width=t.width+"px"}function h(){null!==b&&(b.replaceWith(r),b=null,r[0].style.position="",r[0].style.left="",r[0].style.top="",r[0].style.width=E)}var f=o[0],v=o[1];f.generatedId=t.generateId(),f.baseTitle=a.title||"Select box",f.focusserTitle=f.baseTitle+" focus",f.focusserId="focusser-"+f.generatedId,f.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?i(a.closeOnSelect)():t.closeOnSelect}(),f.onBeforeSelectCallback=i(a.onBeforeSelect),f.onSelectCallback=i(a.onSelect),f.onRemoveCallback=i(a.onRemove),f.onKeypressCallback=i(a.onKeypress),f.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,f.ngModel=v,f.choiceGrouped=function(e){return f.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){f.focusInput.attr("tabindex",e),r.removeAttr("tabindex")});var g=s.$eval(a.searchEnabled);f.searchEnabled=void 0!==g?g:t.searchEnabled;var m=s.$eval(a.sortable);f.sortable=void 0!==m?m:t.sortable,a.$observe("disabled",function(){f.disabled=void 0!==a.disabled?a.disabled:!1}),a.$observe("resetSearchInput",function(){var e=s.$eval(a.resetSearchInput);f.resetSearchInput=void 0!==e?e:!0}),angular.isDefined(a.autofocus)&&n(function(){f.setFocus()}),angular.isDefined(a.focusOn)&&s.$on(a.focusOn,function(){n(function(){f.setFocus()})}),e.on("click",p),s.$on("$destroy",function(){e.off("click",p)}),u(s,function(e){var t=angular.element("
    ").append(e),l=t.querySelectorAll(".ui-select-match");if(l.removeAttr("ui-select-match"),l.removeAttr("data-ui-select-match"),1!==l.length)throw c("transcluded","Expected 1 .ui-select-match but got '{0}'.",l.length);r.querySelectorAll(".ui-select-match").replaceWith(l);var s=t.querySelectorAll(".ui-select-choices");if(s.removeAttr("ui-select-choices"),s.removeAttr("data-ui-select-choices"),1!==s.length)throw c("transcluded","Expected 1 .ui-select-choices but got '{0}'.",s.length);r.querySelectorAll(".ui-select-choices").replaceWith(s)});var $=s.$eval(a.appendToBody);(void 0!==$?$:t.appendToBody)&&(s.$watch("$select.open",function(e){e?d():h()}),s.$on("$destroy",function(){h()}));var b=null,E="",w=null,y="direction-up";s.$watch("$select.open",function(t){if(t){if(w=angular.element(r).querySelectorAll(".ui-select-dropdown"),null===w)return;w[0].style.opacity=0,n(function(){var t=l(r),c=l(w);t.top+t.height+c.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&(w[0].style.position="absolute",w[0].style.top=-1*c.height+"px",r.addClass(y)),w[0].style.opacity=1})}else{if(null===w)return;w[0].style.position="",w[0].style.top="",r.removeClass(y)}})}}}}]),c.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,l=t.parent().attr("multiple");return c+(l?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,l,s){function i(e){s.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}s.lockChoiceExpression=l.uiLockChoice,l.$observe("placeholder",function(t){s.placeholder=void 0!==t?t:e.placeholder}),l.$observe("allowClear",i),i(l.allowClear),s.multiple&&s.sizeSearchInput()}}}]),c.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var c,l=this,s=e.$select;e.$evalAsync(function(){c=e.ngModel}),l.activeMatchIndex=-1,l.updateModel=function(){c.$setViewValue(Date.now()),l.refreshComponent()},l.refreshComponent=function(){s.refreshItems(),s.sizeSearchInput()},l.removeChoice=function(c){var i=s.selected[c];if(!i._uiSelectChoiceLocked){var n={};n[s.parserResult.itemName]=i,s.selected.splice(c,1),l.activeMatchIndex=-1,s.sizeSearchInput(),t(function(){s.onRemoveCallback(e,{$item:i,$model:s.parserResult.modelMapper(e,n)})}),l.updateModel()}},l.getPlaceholder=function(){return s.selected&&s.selected.length?void 0:s.placeholder}}],controllerAs:"$selectMultiple",link:function(l,s,i,n){function r(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(t){function c(){switch(t){case e.LEFT:return~p.activeMatchIndex?d:n;case e.RIGHT:return~p.activeMatchIndex&&a!==n?u:(o.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(a),d):n;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),a):!1}}var l=r(o.searchInput[0]),s=o.selected.length,i=0,n=s-1,a=p.activeMatchIndex,u=p.activeMatchIndex+1,d=p.activeMatchIndex-1,h=a;return l>0||o.search.length&&t==e.RIGHT?!1:(o.close(),h=c(),p.activeMatchIndex=o.selected.length&&h!==!1?Math.min(n,Math.max(i,h)):-1,!0)}var o=n[0],u=l.ngModel=n[1],p=l.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,u.$parsers.unshift(function(){for(var e,t={},c=[],s=o.selected.length-1;s>=0;s--)t={},t[o.parserResult.itemName]=o.selected[s],e=o.parserResult.modelMapper(l,t),c.unshift(e);return c}),u.$formatters.unshift(function(e){var t,c=o.parserResult.source(l,{$select:{search:""}}),s={};if(!c)return e;var i=[],n=function(e,c){if(e&&e.length){for(var n=e.length-1;n>=0;n--){if(s[o.parserResult.itemName]=e[n],t=o.parserResult.modelMapper(l,s),o.parserResult.trackByExp){var r=/\.(.+)/.exec(o.parserResult.trackByExp);if(r.length>0&&t[r[1]]==c[r[1]])return i.unshift(e[n]),!0}if(angular.equals(t,c))return i.unshift(e[n]),!0}return!1}};if(!e)return i;for(var r=e.length-1;r>=0;r--)n(o.selected,e[r])||n(c,e[r])||i.unshift(e[r]);return i}),l.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);o.selected=[]}o.selected=u.$viewValue,l.$evalAsync()},l.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),p.updateModel())}),l.$on("uis:activate",function(){p.activeMatchIndex=-1}),l.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(t){var c=t.which;l.$apply(function(){var t=!1;e.isHorizontalMovement(c)&&(t=a(c)),t&&c!=e.TAB})}),o.searchInput.on("blur",function(){c(function(){p.activeMatchIndex=-1})})}}}]),c.directive("uiSelectSingle",["$timeout","$compile",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(l,s,i,n){var r=n[0],a=n[1];a.$parsers.unshift(function(e){var t,c={};return c[r.parserResult.itemName]=e,t=r.parserResult.modelMapper(l,c)}),a.$formatters.unshift(function(e){var t,c=r.parserResult.source(l,{$select:{search:""}}),s={};if(c){var i=function(c){return s[r.parserResult.itemName]=c,t=r.parserResult.modelMapper(l,s),t==e};if(r.selected&&i(r.selected))return r.selected;for(var n=c.length-1;n>=0;n--)if(i(c[n]))return c[n]}return e}),l.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){r.selected=a.$viewValue},l.$on("uis:select",function(e,t){r.selected=t}),l.$on("uis:close",function(e,c){t(function(){r.focusser.prop("disabled",!1),c||r.focusser[0].focus()},0,!1)}),l.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");c(o)(l),r.focusser=o,r.focusInput=o,s.parent().append(o),o.bind("focus",function(){l.$evalAsync(function(){r.focus=!0})}),o.bind("blur",function(){l.$evalAsync(function(){r.focus=!1})}),o.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),r.select(void 0),l.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),r.activate()),l.$digest()),void 0)}),o.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(r.activate(o.val()),o.val(""),l.$digest())})}}}]),c.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var l=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!l)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:l[2],source:t(l[3]),trackByExp:l[4],modelMapper:t(l[1]||l[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,l){var s=e+" in "+(l?"$group.items":t);return c&&(s+=" track by "+c),s}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("select2/choices.tpl.html",'
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/dist/select.selectize.js b/dist/select.selectize.js new file mode 100644 index 000000000..9f10f28b6 --- /dev/null +++ b/dist/select.selectize.js @@ -0,0 +1,1519 @@ +/*! + * ui-select + * http://github.com/angular-ui/ui-select + * Version: 0.12.1 - 2015-08-02T20:56:31.517Z + * License: MIT + */ + + +(function () { +"use strict"; + +var KEY = { + TAB: 9, + ENTER: 13, + ESC: 27, + SPACE: 32, + LEFT: 37, + UP: 38, + RIGHT: 39, + DOWN: 40, + SHIFT: 16, + CTRL: 17, + ALT: 18, + PAGE_UP: 33, + PAGE_DOWN: 34, + HOME: 36, + END: 35, + BACKSPACE: 8, + DELETE: 46, + COMMAND: 91, + + MAP: { 91 : "COMMAND", 8 : "BACKSPACE" , 9 : "TAB" , 13 : "ENTER" , 16 : "SHIFT" , 17 : "CTRL" , 18 : "ALT" , 19 : "PAUSEBREAK" , 20 : "CAPSLOCK" , 27 : "ESC" , 32 : "SPACE" , 33 : "PAGE_UP", 34 : "PAGE_DOWN" , 35 : "END" , 36 : "HOME" , 37 : "LEFT" , 38 : "UP" , 39 : "RIGHT" , 40 : "DOWN" , 43 : "+" , 44 : "PRINTSCREEN" , 45 : "INSERT" , 46 : "DELETE", 48 : "0" , 49 : "1" , 50 : "2" , 51 : "3" , 52 : "4" , 53 : "5" , 54 : "6" , 55 : "7" , 56 : "8" , 57 : "9" , 59 : ";", 61 : "=" , 65 : "A" , 66 : "B" , 67 : "C" , 68 : "D" , 69 : "E" , 70 : "F" , 71 : "G" , 72 : "H" , 73 : "I" , 74 : "J" , 75 : "K" , 76 : "L", 77 : "M" , 78 : "N" , 79 : "O" , 80 : "P" , 81 : "Q" , 82 : "R" , 83 : "S" , 84 : "T" , 85 : "U" , 86 : "V" , 87 : "W" , 88 : "X" , 89 : "Y" , 90 : "Z", 96 : "0" , 97 : "1" , 98 : "2" , 99 : "3" , 100 : "4" , 101 : "5" , 102 : "6" , 103 : "7" , 104 : "8" , 105 : "9", 106 : "*" , 107 : "+" , 109 : "-" , 110 : "." , 111 : "/", 112 : "F1" , 113 : "F2" , 114 : "F3" , 115 : "F4" , 116 : "F5" , 117 : "F6" , 118 : "F7" , 119 : "F8" , 120 : "F9" , 121 : "F10" , 122 : "F11" , 123 : "F12", 144 : "NUMLOCK" , 145 : "SCROLLLOCK" , 186 : ";" , 187 : "=" , 188 : "," , 189 : "-" , 190 : "." , 191 : "/" , 192 : "`" , 219 : "[" , 220 : "\\" , 221 : "]" , 222 : "'" + }, + + isControl: function (e) { + var k = e.which; + switch (k) { + case KEY.COMMAND: + case KEY.SHIFT: + case KEY.CTRL: + case KEY.ALT: + return true; + } + + if (e.metaKey) return true; + + return false; + }, + isFunctionKey: function (k) { + k = k.which ? k.which : k; + return k >= 112 && k <= 123; + }, + isVerticalMovement: function (k){ + return ~[KEY.UP, KEY.DOWN].indexOf(k); + }, + isHorizontalMovement: function (k){ + return ~[KEY.LEFT,KEY.RIGHT,KEY.BACKSPACE,KEY.DELETE].indexOf(k); + } + }; + +/** + * Add querySelectorAll() to jqLite. + * + * jqLite find() is limited to lookups by tag name. + * TODO This will change with future versions of AngularJS, to be removed when this happens + * + * See jqLite.find - why not use querySelectorAll? https://github.com/angular/angular.js/issues/3586 + * See feat(jqLite): use querySelectorAll instead of getElementsByTagName in jqLite.find https://github.com/angular/angular.js/pull/3598 + */ +if (angular.element.prototype.querySelectorAll === undefined) { + angular.element.prototype.querySelectorAll = function(selector) { + return angular.element(this[0].querySelectorAll(selector)); + }; +} + +/** + * Add closest() to jqLite. + */ +if (angular.element.prototype.closest === undefined) { + angular.element.prototype.closest = function( selector) { + var elem = this[0]; + var matchesSelector = elem.matches || elem.webkitMatchesSelector || elem.mozMatchesSelector || elem.msMatchesSelector; + + while (elem) { + if (matchesSelector.bind(elem)(selector)) { + return elem; + } else { + elem = elem.parentElement; + } + } + return false; + }; +} + +var latestId = 0; + +var uis = angular.module('ui.select', []) + +.constant('uiSelectConfig', { + theme: 'bootstrap', + searchEnabled: true, + sortable: false, + placeholder: '', // Empty by default, like HTML tag "); + $compile(focusser)(scope); + $select.focusser = focusser; + + //Input that will handle focus + $select.focusInput = focusser; + + element.parent().append(focusser); + focusser.bind("focus", function(){ + scope.$evalAsync(function(){ + $select.focus = true; + }); + }); + focusser.bind("blur", function(){ + scope.$evalAsync(function(){ + $select.focus = false; + }); + }); + focusser.bind("keydown", function(e){ + + if (e.which === KEY.BACKSPACE) { + e.preventDefault(); + e.stopPropagation(); + $select.select(undefined); + scope.$apply(); + return; + } + + if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) { + return; + } + + if (e.which == KEY.DOWN || e.which == KEY.UP || e.which == KEY.ENTER || e.which == KEY.SPACE){ + e.preventDefault(); + e.stopPropagation(); + $select.activate(); + } + + scope.$digest(); + }); + + focusser.bind("keyup input", function(e){ + + if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { + return; + } + + $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input + focusser.val(''); + scope.$digest(); + + }); + + + } + }; +}]); +/** + * Parses "repeat" attribute. + * + * Taken from AngularJS ngRepeat source code + * See https://github.com/angular/angular.js/blob/v1.2.15/src/ng/directive/ngRepeat.js#L211 + * + * Original discussion about parsing "repeat" attribute instead of fully relying on ng-repeat: + * https://github.com/angular-ui/ui-select/commit/5dd63ad#commitcomment-5504697 + */ + +uis.service('uisRepeatParser', ['uiSelectMinErr','$parse', function(uiSelectMinErr, $parse) { + var self = this; + + /** + * Example: + * expression = "address in addresses | filter: {street: $select.search} track by $index" + * itemName = "address", + * source = "addresses | filter: {street: $select.search}", + * trackByExp = "$index", + */ + self.parse = function(expression) { + + var match = expression.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/); + + if (!match) { + throw uiSelectMinErr('iexp', "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.", + expression); + } + + return { + itemName: match[2], // (lhs) Left-hand side, + source: $parse(match[3]), + trackByExp: match[4], + modelMapper: $parse(match[1] || match[2]) + }; + + }; + + self.getGroupNgRepeatExpression = function() { + return '$group in $select.groups'; + }; + + self.getNgRepeatExpression = function(itemName, source, trackByExp, grouped) { + var expression = itemName + ' in ' + (grouped ? '$group.items' : source); + if (trackByExp) { + expression += ' track by ' + trackByExp; + } + return expression; + }; +}]); + +}()); +angular.module("ui.select").run(["$templateCache", function($templateCache) {$templateCache.put("selectize/choices.tpl.html","
    "); +$templateCache.put("selectize/match.tpl.html","
    "); +$templateCache.put("selectize/select.tpl.html","
    ");}]); \ No newline at end of file diff --git a/dist/select.selectize.min.js b/dist/select.selectize.min.js new file mode 100644 index 000000000..c02a71103 --- /dev/null +++ b/dist/select.selectize.min.js @@ -0,0 +1,7 @@ +/*! + * ui-select + * http://github.com/angular-ui/ui-select + * Version: 0.12.1 - 2015-08-02T20:56:31.517Z + * License: MIT + */ +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var n=t.which;switch(n){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,n=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",refreshDelay:1e3,closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,i,r){r(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var i=n[0].getBoundingClientRect();return{width:i.width||n.prop("offsetWidth"),height:i.height||n.prop("offsetHeight"),top:i.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:i.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);n.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(r,c){if(!c.repeat)throw n("repeat","Expected 'repeat' expression.");return function(r,c,l,s,o){var a=l.groupBy,u=l.groupFilter;if(s.parseRepeatAttr(l.repeat,a,u),s.disableChoiceExpression=l.uiDisableChoice,s.onHighlightCallback=l.onHighlight,s.refreshOnActive=r.$eval(l.refreshOnActive),a){var p=c.querySelectorAll(".ui-select-choices-group");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",p.length);p.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=c.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(s.parserResult.itemName,"$select.items",s.parserResult.trackByExp,a)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+s.parserResult.itemName+")").attr("ng-click","$select.select("+s.parserResult.itemName+",false,$event)");var h=c.querySelectorAll(".ui-select-choices-row-inner");if(1!==h.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",h.length);h.attr("uis-transclude-append",""),i(c,o)(r),r.$watch("$select.search",function(e){e&&!s.open&&s.multiple&&s.activate(!1,!0),s.activeIndex=0,(!s.refreshOnActive||s.refreshOnActive&&s.refreshIsActive)&&s.refresh(l.refresh)}),r.$watch("$select.refreshIsActive",function(e,t){angular.isUndefined(t)&&e&&s.refresh(l.refresh)});var f=r.$eval(l.refreshDelay);s.refreshDelay=void 0!==f?f:e.refreshDelay}}}}]),n.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,n,i,r,c,l,s,o){function a(){(h.resetSearchInput||void 0===h.resetSearchInput&&o.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var n,i,r=[];for(n=0;n0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:n=!1}return n}function d(){var e=n.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw s("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var i=t[h.activeIndex],r=i.offsetTop+i.clientHeight-e[0].scrollTop,c=e[0].offsetHeight;r>c?e[0].scrollTop+=r-c:r=h.items.length?0:h.activeIndex,h.refreshIsActive=!0,i(function(){h.search=e||h.search,h.searchInput[0].focus()}))},h.findGroupByName=function(e){return h.groups&&h.groups.filter(function(t){return t.name===e})[0]},h.parseRepeatAttr=function(e,n,i){function r(e){var r=t.$eval(n);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(r)?r(e):e[r],n=h.findGroupByName(t);n?n.items.push(e):h.groups.push({name:t,items:[e]})}),i){var c=t.$eval(i);angular.isFunction(c)?h.groups=c(h.groups):angular.isArray(c)&&(h.groups=u(h.groups,c))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function c(e){h.items=e}h.setItemsFn=n?r:c,h.parserResult=l.parse(e),h.isGrouped=!!n,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var n=h.selected;if(h.isEmpty()||angular.isArray(n)&&!n.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var i=e.filter(function(e){return n.indexOf(e)<0});h.setItemsFn(i)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw s("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})};var v;h.refresh=function(e){void 0!==e&&(v&&i.cancel(v),v=i(function(){t.$eval(e)},h.refreshDelay))},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),n=t===h.activeIndex;return n&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),n},h.isDisabled=function(e){if(!h.open)return!1;var t,n=h.items.indexOf(e[h.itemProperty]),i=!1;return n>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[n],i=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i},h.select=function(e,n,r){if(void 0===e||!e._uiSelectChoiceDisabled){if(!h.items&&!h.search)return;if(!e||!e._uiSelectChoiceDisabled){var c=function(){t.$broadcast("uis:select",e),i(function(){h.onSelectCallback(t,s)}),h.closeOnSelect&&h.close(n),r&&"click"===r.type&&(h.clickTriggeredSelect=!0)},l={};l[h.parserResult.itemName]=e;var s={$item:e,$model:h.parserResult.modelMapper(t,l)},o=h.onBeforeSelectCallback(t,s);if(angular.isDefined(o)){if(!o)return;angular.isFunction(o.then)?o.then(function(e){e&&c(e)}):o===!0?c(e):c(o)}else c(e)}}},h.close=function(e){h.open&&(h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),a(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e))},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),i(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var n,i=h.selected[t];return i&&!angular.isUndefined(h.lockChoiceExpression)&&(n=!!e.$eval(h.lockChoiceExpression),i._uiSelectChoiceLocked=n),n};var g=null;h.sizeSearchInput=function(){var e=h.searchInput[0],n=h.searchInput.parent().parent()[0],r=function(){return n.clientWidth*!!e.offsetParent},c=function(t){if(0===t)return!1;var n=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=t),h.searchInput.css("width",n+"px"),!0};h.searchInput.css("width","10px"),i(function(){null!==g||c(r())||(g=t.$watch(r,function(e){c(e)&&(g(),g=null)}))})},h.searchInput.on("keydown",function(n){var i=n.which;t.$apply(function(){p(i)}),e.isVerticalMovement(i)&&h.items.length>0&&d(),(i===e.ENTER||i===e.ESC)&&(n.preventDefault(),n.stopPropagation())}),h.searchInput.on("keyup",function(n){n.which===e.TAB||e.isControl(n)||e.isFunctionKey(n)||n.which===e.ESC||e.isVerticalMovement(n.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:n})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),n.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,i,r,c,l){return{restrict:"EA",templateUrl:function(e,n){var i=n.theme||t.theme;return i+(angular.isDefined(n.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(r,s){return angular.isDefined(s.multiple)?r.append("").removeAttr("multiple"):r.append(""),function(r,s,o,a,u){function p(e){if(f.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(s[0],e.target):s[0].contains(e.target),!t&&!f.clickTriggeredSelect){var n=["input","button","textarea"],i=angular.element(e.target).scope(),c=i&&i.$select&&i.$select!==f;c||(c=~n.indexOf(e.target.tagName.toLowerCase())),f.close(c),r.$digest()}f.clickTriggeredSelect=!1}}function d(){var t=i(s);E=angular.element('
    '),E[0].style.width=t.width+"px",E[0].style.height=t.height+"px",s.after(E),b=s[0].style.width,e.find("body").append(s),s[0].style.position="absolute",s[0].style.left=t.left+"px",s[0].style.top=t.top+"px",s[0].style.width=t.width+"px"}function h(){null!==E&&(E.replaceWith(s),E=null,s[0].style.position="",s[0].style.left="",s[0].style.top="",s[0].style.width=b)}var f=a[0],v=a[1];f.generatedId=t.generateId(),f.baseTitle=o.title||"Select box",f.focusserTitle=f.baseTitle+" focus",f.focusserId="focusser-"+f.generatedId,f.closeOnSelect=function(){return angular.isDefined(o.closeOnSelect)?c(o.closeOnSelect)():t.closeOnSelect}(),f.onBeforeSelectCallback=c(o.onBeforeSelect),f.onSelectCallback=c(o.onSelect),f.onRemoveCallback=c(o.onRemove),f.onKeypressCallback=c(o.onKeypress),f.limit=angular.isDefined(o.limit)?parseInt(o.limit,10):void 0,f.ngModel=v,f.choiceGrouped=function(e){return f.isGrouped&&e&&e.name},o.tabindex&&o.$observe("tabindex",function(e){f.focusInput.attr("tabindex",e),s.removeAttr("tabindex")});var g=r.$eval(o.searchEnabled);f.searchEnabled=void 0!==g?g:t.searchEnabled;var m=r.$eval(o.sortable);f.sortable=void 0!==m?m:t.sortable,o.$observe("disabled",function(){f.disabled=void 0!==o.disabled?o.disabled:!1}),o.$observe("resetSearchInput",function(){var e=r.$eval(o.resetSearchInput);f.resetSearchInput=void 0!==e?e:!0}),angular.isDefined(o.autofocus)&&l(function(){f.setFocus()}),angular.isDefined(o.focusOn)&&r.$on(o.focusOn,function(){l(function(){f.setFocus()})}),e.on("click",p),r.$on("$destroy",function(){e.off("click",p)}),u(r,function(e){var t=angular.element("
    ").append(e),i=t.querySelectorAll(".ui-select-match");if(i.removeAttr("ui-select-match"),i.removeAttr("data-ui-select-match"),1!==i.length)throw n("transcluded","Expected 1 .ui-select-match but got '{0}'.",i.length);s.querySelectorAll(".ui-select-match").replaceWith(i);var r=t.querySelectorAll(".ui-select-choices");if(r.removeAttr("ui-select-choices"),r.removeAttr("data-ui-select-choices"),1!==r.length)throw n("transcluded","Expected 1 .ui-select-choices but got '{0}'.",r.length);s.querySelectorAll(".ui-select-choices").replaceWith(r)});var $=r.$eval(o.appendToBody);(void 0!==$?$:t.appendToBody)&&(r.$watch("$select.open",function(e){e?d():h()}),r.$on("$destroy",function(){h()}));var E=null,b="",S=null,y="direction-up";r.$watch("$select.open",function(t){if(t){if(S=angular.element(s).querySelectorAll(".ui-select-dropdown"),null===S)return;S[0].style.opacity=0,l(function(){var t=i(s),n=i(S);t.top+t.height+n.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&(S[0].style.position="absolute",S[0].style.top=-1*n.height+"px",s.addClass(y)),S[0].style.opacity=1})}else{if(null===S)return;S[0].style.position="",S[0].style.top="",s.removeClass(y)}})}}}}]),n.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return n+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,i,r){function c(e){r.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}r.lockChoiceExpression=i.uiLockChoice,i.$observe("placeholder",function(t){r.placeholder=void 0!==t?t:e.placeholder}),i.$observe("allowClear",c),c(i.allowClear),r.multiple&&r.sizeSearchInput()}}}]),n.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,i=this,r=e.$select;e.$evalAsync(function(){n=e.ngModel}),i.activeMatchIndex=-1,i.updateModel=function(){n.$setViewValue(Date.now()),i.refreshComponent()},i.refreshComponent=function(){r.refreshItems(),r.sizeSearchInput()},i.removeChoice=function(n){var c=r.selected[n];if(!c._uiSelectChoiceLocked){var l={};l[r.parserResult.itemName]=c,r.selected.splice(n,1),i.activeMatchIndex=-1,r.sizeSearchInput(),t(function(){r.onRemoveCallback(e,{$item:c,$model:r.parserResult.modelMapper(e,l)})}),i.updateModel()}},i.getPlaceholder=function(){return r.selected&&r.selected.length?void 0:r.placeholder}}],controllerAs:"$selectMultiple",link:function(i,r,c,l){function s(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function o(t){function n(){switch(t){case e.LEFT:return~p.activeMatchIndex?d:l;case e.RIGHT:return~p.activeMatchIndex&&o!==l?u:(a.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(o),d):l;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),o):!1}}var i=s(a.searchInput[0]),r=a.selected.length,c=0,l=r-1,o=p.activeMatchIndex,u=p.activeMatchIndex+1,d=p.activeMatchIndex-1,h=o;return i>0||a.search.length&&t==e.RIGHT?!1:(a.close(),h=n(),p.activeMatchIndex=a.selected.length&&h!==!1?Math.min(l,Math.max(c,h)):-1,!0)}var a=l[0],u=i.ngModel=l[1],p=i.$selectMultiple;a.multiple=!0,a.removeSelected=!0,a.focusInput=a.searchInput,u.$parsers.unshift(function(){for(var e,t={},n=[],r=a.selected.length-1;r>=0;r--)t={},t[a.parserResult.itemName]=a.selected[r],e=a.parserResult.modelMapper(i,t),n.unshift(e);return n}),u.$formatters.unshift(function(e){var t,n=a.parserResult.source(i,{$select:{search:""}}),r={};if(!n)return e;var c=[],l=function(e,n){if(e&&e.length){for(var l=e.length-1;l>=0;l--){if(r[a.parserResult.itemName]=e[l],t=a.parserResult.modelMapper(i,r),a.parserResult.trackByExp){var s=/\.(.+)/.exec(a.parserResult.trackByExp);if(s.length>0&&t[s[1]]==n[s[1]])return c.unshift(e[l]),!0}if(angular.equals(t,n))return c.unshift(e[l]),!0}return!1}};if(!e)return c;for(var s=e.length-1;s>=0;s--)l(a.selected,e[s])||l(n,e[s])||c.unshift(e[s]);return c}),i.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);a.selected=[]}a.selected=u.$viewValue,i.$evalAsync()},i.$on("uis:select",function(e,t){a.selected.length>=a.limit||(a.selected.push(t),p.updateModel())}),i.$on("uis:activate",function(){p.activeMatchIndex=-1}),i.$watch("$select.disabled",function(e,t){t&&!e&&a.sizeSearchInput()}),a.searchInput.on("keydown",function(t){var n=t.which;i.$apply(function(){var t=!1;e.isHorizontalMovement(n)&&(t=o(n)),t&&n!=e.TAB})}),a.searchInput.on("blur",function(){n(function(){p.activeMatchIndex=-1})})}}}]),n.directive("uiSelectSingle",["$timeout","$compile",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(i,r,c,l){var s=l[0],o=l[1];o.$parsers.unshift(function(e){var t,n={};return n[s.parserResult.itemName]=e,t=s.parserResult.modelMapper(i,n)}),o.$formatters.unshift(function(e){var t,n=s.parserResult.source(i,{$select:{search:""}}),r={};if(n){var c=function(n){return r[s.parserResult.itemName]=n,t=s.parserResult.modelMapper(i,r),t==e};if(s.selected&&c(s.selected))return s.selected;for(var l=n.length-1;l>=0;l--)if(c(n[l]))return n[l]}return e}),i.$watch("$select.selected",function(e){o.$viewValue!==e&&o.$setViewValue(e)}),o.$render=function(){s.selected=o.$viewValue},i.$on("uis:select",function(e,t){s.selected=t}),i.$on("uis:close",function(e,n){t(function(){s.focusser.prop("disabled",!1),n||s.focusser[0].focus()},0,!1)}),i.$on("uis:activate",function(){a.prop("disabled",!0)});var a=angular.element("");n(a)(i),s.focusser=a,s.focusInput=a,r.parent().append(a),a.bind("focus",function(){i.$evalAsync(function(){s.focus=!0})}),a.bind("blur",function(){i.$evalAsync(function(){s.focus=!1})}),a.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),s.select(void 0),i.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),s.activate()),i.$digest()),void 0)}),a.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(s.activate(a.val()),a.val(""),i.$digest())})}}}]),n.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var i=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!i)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:i[2],source:t(i[3]),trackByExp:i[4],modelMapper:t(i[1]||i[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,i){var r=e+" in "+(i?"$group.items":t);return n&&(r+=" track by "+n),r}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("selectize/choices.tpl.html",'
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/dist/select.tpl.js b/dist/select.tpl.js new file mode 100644 index 000000000..744e094b1 --- /dev/null +++ b/dist/select.tpl.js @@ -0,0 +1,21 @@ +/*! + * ui-select + * http://github.com/angular-ui/ui-select + * Version: 0.12.1 - 2015-08-02T20:56:31.470Z + * License: MIT + */ + + +angular.module("ui.select").run(["$templateCache", function($templateCache) {$templateCache.put("selectize/choices.tpl.html","
    "); +$templateCache.put("selectize/match.tpl.html","
    "); +$templateCache.put("selectize/select.tpl.html","
    ");}]); +angular.module("ui.select").run(["$templateCache", function($templateCache) {$templateCache.put("bootstrap/choices.tpl.html","
      0\">
    • 0\">
    "); +$templateCache.put("bootstrap/match-multiple.tpl.html"," × "); +$templateCache.put("bootstrap/match.tpl.html","
    {{$select.placeholder}}
    "); +$templateCache.put("bootstrap/select-multiple.tpl.html","
    "); +$templateCache.put("bootstrap/select.tpl.html","
    ");}]); +angular.module("ui.select").run(["$templateCache", function($templateCache) {$templateCache.put("select2/choices.tpl.html","
    "); +$templateCache.put("select2/match-multiple.tpl.html","
  • "); +$templateCache.put("select2/match.tpl.html","{{$select.placeholder}} "); +$templateCache.put("select2/select-multiple.tpl.html","
    "); +$templateCache.put("select2/select.tpl.html","
    ");}]); \ No newline at end of file diff --git a/examples/newdemo.html b/examples/newdemo.html new file mode 100644 index 000000000..ab615f67b --- /dev/null +++ b/examples/newdemo.html @@ -0,0 +1,174 @@ + + + + + AngularJS ui-select + + + + + + + + + + + + + + + + + + +

    Selected: {{person.selected.name}}

    + +
    +
    + ui-select inside a Bootstrap form + +
    + + +
    + + + {{$select.selected.name}} + + +
    + +
    +
    +
    +
    + +
    + + +
    + + + {{$select.selected.name}} + + +
    + +
    +
    + +
    +
    + +
    + + +
    + + + {{$item.name}} + + +
    + +
    +
    + +
    +
    + +
    + + +
    + + + {{$select.selected.name}} + + + + + + + +
    +
    + +
    + + +
    +
    + + + + {{$select.selected.name}} + + + + + + + + + + + +
    +
    +
    + +
    + + +
    + + {{$select.selected.name}} + + +
    + +
    +
    +
    +
    + +
    + + +
    + + {{$item}} + + {{color}} + + +
    +
    + +
    +
    + + + diff --git a/examples/newdemo.js b/examples/newdemo.js new file mode 100644 index 000000000..06570658f --- /dev/null +++ b/examples/newdemo.js @@ -0,0 +1,534 @@ +'use strict'; + +var app = angular.module('demo', ['ngSanitize', 'ui.select']); + +/** + * AngularJS default filter with the following expression: + * "person in people | filter: {name: $select.search, age: $select.search}" + * performs a AND between 'name: $select.search' and 'age: $select.search'. + * We want to perform a OR. + */ +app.filter('propsFilter', function () { + return function (items, props) { + var out = []; + + if (angular.isArray(items)) { + items.forEach(function (item) { + var itemMatches = false; + + var keys = Object.keys(props); + for (var i = 0; i < keys.length; i++) { + var prop = keys[i]; + var text = props[prop].toLowerCase(); + if (item[prop].toString().toLowerCase().indexOf(text) !== -1) { + itemMatches = true; + break; + } + } + + if (itemMatches) { + out.push(item); + } + }); + } else { + // Let the output be the input untouched + out = items; + } + + return out; + }; +}); + +app.controller('DemoCtrl', function ($scope, $http, $timeout, $interval) { + $scope.theme = "bootstrap"; + $scope.disabled = undefined; + $scope.searchEnabled = undefined; + + $scope.setInputFocus = function () { + $scope.$broadcast('UiSelectDemo1'); + } + + $scope.enable = function () { + $scope.disabled = false; + }; + + $scope.disable = function () { + $scope.disabled = true; + }; + + $scope.enableSearch = function () { + $scope.searchEnabled = true; + } + + $scope.disableSearch = function () { + $scope.searchEnabled = false; + } + + $scope.clear = function () { + $scope.person.selected = undefined; + $scope.address.selected = undefined; + $scope.country.selected = undefined; + }; + + $scope.someGroupFn = function (item) { + + if (item.name[0] >= 'A' && item.name[0] <= 'M') + return 'From A - M'; + + if (item.name[0] >= 'N' && item.name[0] <= 'Z') + return 'From N - Z'; + + }; + + $scope.firstLetterGroupFn = function (item) { + return item.name[0]; + }; + + $scope.reverseOrderFilterFn = function (groups) { + return groups.reverse(); + }; + + $scope.personAsync = {selected: "wladimir@email.com"}; + $scope.peopleAsync = []; + + $timeout(function () { + $scope.peopleAsync = [ + {name: 'Adam', email: 'adam@email.com', age: 12, country: 'United States'}, + {name: 'Amalie', email: 'amalie@email.com', age: 12, country: 'Argentina'}, + {name: 'Estefanía', email: 'estefania@email.com', age: 21, country: 'Argentina'}, + {name: 'Adrian', email: 'adrian@email.com', age: 21, country: 'Ecuador'}, + {name: 'Wladimir', email: 'wladimir@email.com', age: 30, country: 'Ecuador'}, + {name: 'Samantha', email: 'samantha@email.com', age: 30, country: 'United States'}, + {name: 'Nicole', email: 'nicole@email.com', age: 43, country: 'Colombia'}, + {name: 'Natasha', email: 'natasha@email.com', age: 54, country: 'Ecuador'}, + {name: 'Michael', email: 'michael@email.com', age: 15, country: 'Colombia'}, + {name: 'Nicolás', email: 'nicole@email.com', age: 43, country: 'Colombia'} + ]; + }, 3000); + + $scope.counter = 0; + $scope.someFunction = function (item, model) { + $scope.counter++; + $scope.eventResult = {item: item, model: model}; + }; + + $scope.removed = function (item, model) { + $scope.lastRemoved = { + item: item, + model: model + }; + }; + + $scope.tagTransform = function (newTag) { + var item = { + name: newTag, + email: newTag.toLowerCase() + '@email.com', + age: 'unknown', + country: 'unknown' + }; + + return item; + }; + + $scope.person = {}; + $scope.people = [ + {name: 'Adam', email: 'adam@email.com', age: 12, country: 'United States'}, + {name: 'Amalie', email: 'amalie@email.com', age: 12, country: 'Argentina'}, + {name: 'Estefanía', email: 'estefania@email.com', age: 21, country: 'Argentina'}, + {name: 'Adrian', email: 'adrian@email.com', age: 21, country: 'Ecuador'}, + {name: 'Wladimir', email: 'wladimir@email.com', age: 30, country: 'Ecuador'}, + {name: 'Samantha', email: 'samantha@email.com', age: 30, country: 'United States'}, + {name: 'Nicole', email: 'nicole@email.com', age: 43, country: 'Colombia'}, + {name: 'Natasha', email: 'natasha@email.com', age: 54, country: 'Ecuador'}, + {name: 'Michael', email: 'michael@email.com', age: 15, country: 'Colombia'}, + {name: 'Nicolás', email: 'nicolas@email.com', age: 43, country: 'Colombia'} + ]; + + $scope.availableColors = ['Red', 'Green', 'Blue', 'Yellow', 'Magenta', 'Maroon', 'Umbra', 'Turquoise']; + + $scope.singleDemo = {}; + $scope.singleDemo.color = ''; + $scope.multipleDemo = {}; + $scope.multipleDemo.colors = ['Blue', 'Red']; + $scope.multipleDemo.colors2 = ['Blue', 'Red']; + $scope.multipleDemo.selectedPeople = [$scope.people[5], $scope.people[4]]; + $scope.multipleDemo.selectedPeople2 = $scope.multipleDemo.selectedPeople; + $scope.multipleDemo.selectedPeopleWithGroupBy = [$scope.people[8], $scope.people[6]]; + $scope.multipleDemo.selectedPeopleSimple = ['samantha@email.com', 'wladimir@email.com']; + + $scope.appendToBodyDemo = { + remainingToggleTime: 0, + present: true, + startToggleTimer: function () { + var scope = $scope.appendToBodyDemo; + var promise = $interval(function () { + if (scope.remainingTime < 1000) { + $interval.cancel(promise); + scope.present = !scope.present; + scope.remainingTime = 0; + } else { + scope.remainingTime -= 1000; + } + }, 1000); + scope.remainingTime = 3000; + } + }; + + $scope.address = {}; + $scope.refreshAddresses = function (address) { + var params = {address: address, sensor: false}; + return $http.get( + 'http://maps.googleapis.com/maps/api/geocode/json', + {params: params} + ).then(function (response) { + $scope.addresses = response.data.results; + }); + }; + + $scope.addPerson = function (item, model) { + if (item.hasOwnProperty('isTag')) { + delete item.isTag; + $scope.people.push(item); + } + } + + $scope.country = {}; + $scope.countries = [ // Taken from https://gist.github.com/unceus/6501985 + {name: 'Afghanistan', code: 'AF'}, + {name: 'Åland Islands', code: 'AX'}, + {name: 'Albania', code: 'AL'}, + {name: 'Algeria', code: 'DZ'}, + {name: 'American Samoa', code: 'AS'}, + {name: 'Andorra', code: 'AD'}, + {name: 'Angola', code: 'AO'}, + {name: 'Anguilla', code: 'AI'}, + {name: 'Antarctica', code: 'AQ'}, + {name: 'Antigua and Barbuda', code: 'AG'}, + {name: 'Argentina', code: 'AR'}, + {name: 'Armenia', code: 'AM'}, + {name: 'Aruba', code: 'AW'}, + {name: 'Australia', code: 'AU'}, + {name: 'Austria', code: 'AT'}, + {name: 'Azerbaijan', code: 'AZ'}, + {name: 'Bahamas', code: 'BS'}, + {name: 'Bahrain', code: 'BH'}, + {name: 'Bangladesh', code: 'BD'}, + {name: 'Barbados', code: 'BB'}, + {name: 'Belarus', code: 'BY'}, + {name: 'Belgium', code: 'BE'}, + {name: 'Belize', code: 'BZ'}, + {name: 'Benin', code: 'BJ'}, + {name: 'Bermuda', code: 'BM'}, + {name: 'Bhutan', code: 'BT'}, + {name: 'Bolivia', code: 'BO'}, + {name: 'Bosnia and Herzegovina', code: 'BA'}, + {name: 'Botswana', code: 'BW'}, + {name: 'Bouvet Island', code: 'BV'}, + {name: 'Brazil', code: 'BR'}, + {name: 'British Indian Ocean Territory', code: 'IO'}, + {name: 'Brunei Darussalam', code: 'BN'}, + {name: 'Bulgaria', code: 'BG'}, + {name: 'Burkina Faso', code: 'BF'}, + {name: 'Burundi', code: 'BI'}, + {name: 'Cambodia', code: 'KH'}, + {name: 'Cameroon', code: 'CM'}, + {name: 'Canada', code: 'CA'}, + {name: 'Cape Verde', code: 'CV'}, + {name: 'Cayman Islands', code: 'KY'}, + {name: 'Central African Republic', code: 'CF'}, + {name: 'Chad', code: 'TD'}, + {name: 'Chile', code: 'CL'}, + {name: 'China', code: 'CN'}, + {name: 'Christmas Island', code: 'CX'}, + {name: 'Cocos (Keeling) Islands', code: 'CC'}, + {name: 'Colombia', code: 'CO'}, + {name: 'Comoros', code: 'KM'}, + {name: 'Congo', code: 'CG'}, + {name: 'Congo, The Democratic Republic of the', code: 'CD'}, + {name: 'Cook Islands', code: 'CK'}, + {name: 'Costa Rica', code: 'CR'}, + {name: 'Cote D\'Ivoire', code: 'CI'}, + {name: 'Croatia', code: 'HR'}, + {name: 'Cuba', code: 'CU'}, + {name: 'Cyprus', code: 'CY'}, + {name: 'Czech Republic', code: 'CZ'}, + {name: 'Denmark', code: 'DK'}, + {name: 'Djibouti', code: 'DJ'}, + {name: 'Dominica', code: 'DM'}, + {name: 'Dominican Republic', code: 'DO'}, + {name: 'Ecuador', code: 'EC'}, + {name: 'Egypt', code: 'EG'}, + {name: 'El Salvador', code: 'SV'}, + {name: 'Equatorial Guinea', code: 'GQ'}, + {name: 'Eritrea', code: 'ER'}, + {name: 'Estonia', code: 'EE'}, + {name: 'Ethiopia', code: 'ET'}, + {name: 'Falkland Islands (Malvinas)', code: 'FK'}, + {name: 'Faroe Islands', code: 'FO'}, + {name: 'Fiji', code: 'FJ'}, + {name: 'Finland', code: 'FI'}, + {name: 'France', code: 'FR'}, + {name: 'French Guiana', code: 'GF'}, + {name: 'French Polynesia', code: 'PF'}, + {name: 'French Southern Territories', code: 'TF'}, + {name: 'Gabon', code: 'GA'}, + {name: 'Gambia', code: 'GM'}, + {name: 'Georgia', code: 'GE'}, + {name: 'Germany', code: 'DE'}, + {name: 'Ghana', code: 'GH'}, + {name: 'Gibraltar', code: 'GI'}, + {name: 'Greece', code: 'GR'}, + {name: 'Greenland', code: 'GL'}, + {name: 'Grenada', code: 'GD'}, + {name: 'Guadeloupe', code: 'GP'}, + {name: 'Guam', code: 'GU'}, + {name: 'Guatemala', code: 'GT'}, + {name: 'Guernsey', code: 'GG'}, + {name: 'Guinea', code: 'GN'}, + {name: 'Guinea-Bissau', code: 'GW'}, + {name: 'Guyana', code: 'GY'}, + {name: 'Haiti', code: 'HT'}, + {name: 'Heard Island and Mcdonald Islands', code: 'HM'}, + {name: 'Holy See (Vatican City State)', code: 'VA'}, + {name: 'Honduras', code: 'HN'}, + {name: 'Hong Kong', code: 'HK'}, + {name: 'Hungary', code: 'HU'}, + {name: 'Iceland', code: 'IS'}, + {name: 'India', code: 'IN'}, + {name: 'Indonesia', code: 'ID'}, + {name: 'Iran, Islamic Republic Of', code: 'IR'}, + {name: 'Iraq', code: 'IQ'}, + {name: 'Ireland', code: 'IE'}, + {name: 'Isle of Man', code: 'IM'}, + {name: 'Israel', code: 'IL'}, + {name: 'Italy', code: 'IT'}, + {name: 'Jamaica', code: 'JM'}, + {name: 'Japan', code: 'JP'}, + {name: 'Jersey', code: 'JE'}, + {name: 'Jordan', code: 'JO'}, + {name: 'Kazakhstan', code: 'KZ'}, + {name: 'Kenya', code: 'KE'}, + {name: 'Kiribati', code: 'KI'}, + {name: 'Korea, Democratic People\'s Republic of', code: 'KP'}, + {name: 'Korea, Republic of', code: 'KR'}, + {name: 'Kuwait', code: 'KW'}, + {name: 'Kyrgyzstan', code: 'KG'}, + {name: 'Lao People\'s Democratic Republic', code: 'LA'}, + {name: 'Latvia', code: 'LV'}, + {name: 'Lebanon', code: 'LB'}, + {name: 'Lesotho', code: 'LS'}, + {name: 'Liberia', code: 'LR'}, + {name: 'Libyan Arab Jamahiriya', code: 'LY'}, + {name: 'Liechtenstein', code: 'LI'}, + {name: 'Lithuania', code: 'LT'}, + {name: 'Luxembourg', code: 'LU'}, + {name: 'Macao', code: 'MO'}, + {name: 'Macedonia, The Former Yugoslav Republic of', code: 'MK'}, + {name: 'Madagascar', code: 'MG'}, + {name: 'Malawi', code: 'MW'}, + {name: 'Malaysia', code: 'MY'}, + {name: 'Maldives', code: 'MV'}, + {name: 'Mali', code: 'ML'}, + {name: 'Malta', code: 'MT'}, + {name: 'Marshall Islands', code: 'MH'}, + {name: 'Martinique', code: 'MQ'}, + {name: 'Mauritania', code: 'MR'}, + {name: 'Mauritius', code: 'MU'}, + {name: 'Mayotte', code: 'YT'}, + {name: 'Mexico', code: 'MX'}, + {name: 'Micronesia, Federated States of', code: 'FM'}, + {name: 'Moldova, Republic of', code: 'MD'}, + {name: 'Monaco', code: 'MC'}, + {name: 'Mongolia', code: 'MN'}, + {name: 'Montserrat', code: 'MS'}, + {name: 'Morocco', code: 'MA'}, + {name: 'Mozambique', code: 'MZ'}, + {name: 'Myanmar', code: 'MM'}, + {name: 'Namibia', code: 'NA'}, + {name: 'Nauru', code: 'NR'}, + {name: 'Nepal', code: 'NP'}, + {name: 'Netherlands', code: 'NL'}, + {name: 'Netherlands Antilles', code: 'AN'}, + {name: 'New Caledonia', code: 'NC'}, + {name: 'New Zealand', code: 'NZ'}, + {name: 'Nicaragua', code: 'NI'}, + {name: 'Niger', code: 'NE'}, + {name: 'Nigeria', code: 'NG'}, + {name: 'Niue', code: 'NU'}, + {name: 'Norfolk Island', code: 'NF'}, + {name: 'Northern Mariana Islands', code: 'MP'}, + {name: 'Norway', code: 'NO'}, + {name: 'Oman', code: 'OM'}, + {name: 'Pakistan', code: 'PK'}, + {name: 'Palau', code: 'PW'}, + {name: 'Palestinian Territory, Occupied', code: 'PS'}, + {name: 'Panama', code: 'PA'}, + {name: 'Papua New Guinea', code: 'PG'}, + {name: 'Paraguay', code: 'PY'}, + {name: 'Peru', code: 'PE'}, + {name: 'Philippines', code: 'PH'}, + {name: 'Pitcairn', code: 'PN'}, + {name: 'Poland', code: 'PL'}, + {name: 'Portugal', code: 'PT'}, + {name: 'Puerto Rico', code: 'PR'}, + {name: 'Qatar', code: 'QA'}, + {name: 'Reunion', code: 'RE'}, + {name: 'Romania', code: 'RO'}, + {name: 'Russian Federation', code: 'RU'}, + {name: 'Rwanda', code: 'RW'}, + {name: 'Saint Helena', code: 'SH'}, + {name: 'Saint Kitts and Nevis', code: 'KN'}, + {name: 'Saint Lucia', code: 'LC'}, + {name: 'Saint Pierre and Miquelon', code: 'PM'}, + {name: 'Saint Vincent and the Grenadines', code: 'VC'}, + {name: 'Samoa', code: 'WS'}, + {name: 'San Marino', code: 'SM'}, + {name: 'Sao Tome and Principe', code: 'ST'}, + {name: 'Saudi Arabia', code: 'SA'}, + {name: 'Senegal', code: 'SN'}, + {name: 'Serbia and Montenegro', code: 'CS'}, + {name: 'Seychelles', code: 'SC'}, + {name: 'Sierra Leone', code: 'SL'}, + {name: 'Singapore', code: 'SG'}, + {name: 'Slovakia', code: 'SK'}, + {name: 'Slovenia', code: 'SI'}, + {name: 'Solomon Islands', code: 'SB'}, + {name: 'Somalia', code: 'SO'}, + {name: 'South Africa', code: 'ZA'}, + {name: 'South Georgia and the South Sandwich Islands', code: 'GS'}, + {name: 'Spain', code: 'ES'}, + {name: 'Sri Lanka', code: 'LK'}, + {name: 'Sudan', code: 'SD'}, + {name: 'Suriname', code: 'SR'}, + {name: 'Svalbard and Jan Mayen', code: 'SJ'}, + {name: 'Swaziland', code: 'SZ'}, + {name: 'Sweden', code: 'SE'}, + {name: 'Switzerland', code: 'CH'}, + {name: 'Syrian Arab Republic', code: 'SY'}, + {name: 'Taiwan, Province of China', code: 'TW'}, + {name: 'Tajikistan', code: 'TJ'}, + {name: 'Tanzania, United Republic of', code: 'TZ'}, + {name: 'Thailand', code: 'TH'}, + {name: 'Timor-Leste', code: 'TL'}, + {name: 'Togo', code: 'TG'}, + {name: 'Tokelau', code: 'TK'}, + {name: 'Tonga', code: 'TO'}, + {name: 'Trinidad and Tobago', code: 'TT'}, + {name: 'Tunisia', code: 'TN'}, + {name: 'Turkey', code: 'TR'}, + {name: 'Turkmenistan', code: 'TM'}, + {name: 'Turks and Caicos Islands', code: 'TC'}, + {name: 'Tuvalu', code: 'TV'}, + {name: 'Uganda', code: 'UG'}, + {name: 'Ukraine', code: 'UA'}, + {name: 'United Arab Emirates', code: 'AE'}, + {name: 'United Kingdom', code: 'GB'}, + {name: 'United States', code: 'US'}, + {name: 'United States Minor Outlying Islands', code: 'UM'}, + {name: 'Uruguay', code: 'UY'}, + {name: 'Uzbekistan', code: 'UZ'}, + {name: 'Vanuatu', code: 'VU'}, + {name: 'Venezuela', code: 'VE'}, + {name: 'Vietnam', code: 'VN'}, + {name: 'Virgin Islands, British', code: 'VG'}, + {name: 'Virgin Islands, U.S.', code: 'VI'}, + {name: 'Wallis and Futuna', code: 'WF'}, + {name: 'Western Sahara', code: 'EH'}, + {name: 'Yemen', code: 'YE'}, + {name: 'Zambia', code: 'ZM'}, + {name: 'Zimbabwe', code: 'ZW'} + ]; + + var tagging = {isActivated: false, fct: undefined}; + var taggingTokens = {isActivated: false, tokens: undefined}; + + $scope.onKeypress = function (e) { + var $select = this.$select; + // Push a "create new" item into array if there is a search string + if ($select.search.length > 0) { + // always reset the activeIndex to the first item when tagging + $select.activeIndex = $select.taggingLabel === false ? -1 : 0; + + var items = angular.copy($select.items); + var stashArr = angular.copy($select.items); + var newItem; + var item; + var hasTag = false; + var dupeIndex = -1; + var tagItems; + var tagItem; + + newItem = $select.search; + dupeIndex = _findApproxDupe($select.items, newItem); + if(dupeIndex != -1) { + items = items.slice(dupeIndex + 1, items.length - 1); + } + + // Verify that the tag doesn't match the value of a selected item + if (_findCaseInsensitiveDupe($select.search, stashArr.concat($select.selected))) { + $scope.$evalAsync(function () { + $select.activeIndex = 0; + $select.items = items; + }); + return; + } + + // Verify that the tag doesn't match the value of a new tag item + if (_findCaseInsensitiveDupe($select.search, stashArr)) { + $scope.$evalAsync(function () { + $select.activeIndex = 0; + $select.items = items; + }); + return; + } + + // Add the new item + stashArr = []; + stashArr.push(newItem); + stashArr = stashArr.concat(items); + + $scope.$evalAsync(function () { + $select.activeIndex = 0; + $select.items = stashArr; + }); + } + }; + + $scope.onBeforeSelect = function ($item) { + var $select = this.$select; + + // For tagging, use the search if there's no item selected + var item = $item !== undefined ? $item : $select.search; + + return !_findCaseInsensitiveDupe(item, $select.selected); + }; + + + function _findCaseInsensitiveDupe(search, arr) { + if (arr === undefined || search === undefined) { + return false; + } + var hasDupe = arr.filter(function (origItem) { + if (search.toUpperCase() === undefined || origItem === undefined) { + return false; + } + return origItem.toUpperCase() === search.toUpperCase(); + }).length > 0; + + return hasDupe; + } + + function _findApproxDupe(haystack, needle) { + var dupeIndex = -1; + if (angular.isArray(haystack)) { + for (var i = 0; i < haystack.length; i++) { + if(needle.indexOf(haystack[i]) == 0) { + dupeIndex = i; + } + } + } + return dupeIndex; + } + + +}); diff --git a/gulpfile.js b/gulpfile.js index 85659f2a8..96f71c295 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -16,91 +16,201 @@ var gutil = require('gulp-util'); var plumber = require('gulp-plumber');//To prevent pipe breaking caused by errors at 'watch' var config = { - pkg : JSON.parse(fs.readFileSync('./package.json')), - banner: - '/*!\n' + - ' * <%= pkg.name %>\n' + - ' * <%= pkg.homepage %>\n' + - ' * Version: <%= pkg.version %> - <%= timestamp %>\n' + - ' * License: <%= pkg.license %>\n' + - ' */\n\n\n' + pkg: JSON.parse(fs.readFileSync('./package.json')), + banner: '/*!\n' + + ' * <%= pkg.name %>\n' + + ' * <%= pkg.homepage %>\n' + + ' * Version: <%= pkg.version %> - <%= timestamp %>\n' + + ' * License: <%= pkg.license %>\n' + + ' */\n\n\n' }; -gulp.task('default', ['build','test']); +gulp.task('default', ['build', 'test']); gulp.task('build', ['scripts', 'styles']); gulp.task('test', ['build', 'karma']); -gulp.task('watch', ['build','karma-watch'], function() { - gulp.watch(['src/**/*.{js,html}'], ['build']); +gulp.task('watch', ['build', 'karma-watch'], function () { + gulp.watch(['src/**/*.{js,html}'], ['build']); }); -gulp.task('clean', function(cb) { - del(['dist'], cb); +gulp.task('clean', function (cb) { + del(['dist'], cb); }); -gulp.task('scripts', ['clean'], function() { +gulp.task('scripts', ['clean'], function () { - var buildTemplates = function () { - return gulp.src('src/**/*.html') - .pipe(minifyHtml({ - empty: true, - spare: true, - quotes: true + var buildTplBootstrap = function () { + return gulp.src('src/bootstrap/*.html') + .pipe(minifyHtml({ + empty: true, + spare: true, + quotes: true })) - .pipe(templateCache({module: 'ui.select'})); - }; - - var buildLib = function(){ - return gulp.src(['src/common.js','src/*.js']) - .pipe(plumber({ - errorHandler: handleError - })) - .pipe(concat('select_without_templates.js')) - .pipe(header('(function () { \n"use strict";\n')) - .pipe(footer('\n}());')) - .pipe(jshint()) - .pipe(jshint.reporter('jshint-stylish')) - .pipe(jshint.reporter('fail')); - }; - - return es.merge(buildLib(), buildTemplates()) - .pipe(plumber({ - errorHandler: handleError - })) - .pipe(concat('select.js')) - .pipe(header(config.banner, { - timestamp: (new Date()).toISOString(), pkg: config.pkg - })) - .pipe(gulp.dest('dist')) - .pipe(uglify({preserveComments: 'some'})) - .pipe(rename({ext:'.min.js'})) - .pipe(gulp.dest('dist')); + .pipe(templateCache({root: "bootstrap", module: 'ui.select'})); + }; + + var buildTplSelect2 = function () { + return gulp.src('src/select2/*.html') + .pipe(minifyHtml({ + empty: true, + spare: true, + quotes: true + })) + .pipe(templateCache({root: "select2", module: 'ui.select'})); + }; + + var buildTplSelectize = function () { + return gulp.src('src/selectize/*.html') + .pipe(minifyHtml({ + empty: true, + spare: true, + quotes: true + })) + .pipe(templateCache({root: "selectize", module: 'ui.select'})); + }; + + var buildLib = function () { + return gulp.src(['src/*.js']) + .pipe(plumber({ + errorHandler: handleError + })) + .pipe(concat('select_without_templates.js')) + .pipe(header('(function () { \n"use strict";\n')) + .pipe(footer('\n}());')) + .pipe(jshint()) + .pipe(jshint.reporter('jshint-stylish')) + .pipe(jshint.reporter('fail')); + }; + + var buildSort = function () { + return gulp.src(['src/addons/uiSelectSortDirective.js']) + .pipe(plumber({ + errorHandler: handleError + })) + .pipe(concat('select.sort.js')) + .pipe(header('(function () { \n"use strict";\n')) + .pipe(footer('\n}());')) + .pipe(jshint()) + .pipe(jshint.reporter('jshint-stylish')) + .pipe(jshint.reporter('fail') + ); + }; + + es.merge(buildTplBootstrap(), buildTplSelect2(), buildTplSelectize()) + .pipe(plumber({ + errorHandler: handleError + })) + .pipe(concat('select.js')) + .pipe(header(config.banner, { + timestamp: (new Date()).toISOString(), pkg: config.pkg + })) + .pipe(rename({ext: '.tpl.js'})) + .pipe(gulp.dest('dist')); + + es.merge(buildLib()) + .pipe(plumber({ + errorHandler: handleError + })) + .pipe(concat('select.js')) + .pipe(header(config.banner, { + timestamp: (new Date()).toISOString(), pkg: config.pkg + })) + .pipe(rename({ext: '.no-tpl.js'})) + .pipe(gulp.dest('dist')) + .pipe(uglify({preserveComments: 'some'})) + .pipe(rename({ext: '.no-tpl.min.js'})) + .pipe(gulp.dest('dist')); + + es.merge(buildLib(), buildTplBootstrap()) + .pipe(plumber({ + errorHandler: handleError + })) + .pipe(concat('select.bootstrap.js')) + .pipe(header(config.banner, { + timestamp: (new Date()).toISOString(), pkg: config.pkg + })) + .pipe(gulp.dest('dist')) + .pipe(uglify({preserveComments: 'some'})) + .pipe(rename({ext: '.bootstrap.min.js'})) + .pipe(gulp.dest('dist')); + + es.merge(buildLib(), buildTplSelect2()) + .pipe(plumber({ + errorHandler: handleError + })) + .pipe(concat('select.select2.js')) + .pipe(header(config.banner, { + timestamp: (new Date()).toISOString(), pkg: config.pkg + })) + .pipe(gulp.dest('dist')) + .pipe(uglify({preserveComments: 'some'})) + .pipe(rename({ext: '.select2.min.js'})) + .pipe(gulp.dest('dist')); + + es.merge(buildLib(), buildTplSelectize()) + .pipe(plumber({ + errorHandler: handleError + })) + .pipe(concat('select.selectize.js')) + .pipe(header(config.banner, { + timestamp: (new Date()).toISOString(), pkg: config.pkg + })) + .pipe(gulp.dest('dist')) + .pipe(uglify({preserveComments: 'some'})) + .pipe(rename({ext: '.selectize.min.js'})) + .pipe(gulp.dest('dist')); + + es.merge(buildSort()) + .pipe(plumber({ + errorHandler: handleError + })) + .pipe(concat('select.sort.js')) + .pipe(header(config.banner, { + timestamp: (new Date()).toISOString(), pkg: config.pkg + })) + .pipe(gulp.dest('dist')) + .pipe(uglify({preserveComments: 'some'})) + .pipe(rename({ext: '.sort.min.js'})) + .pipe(gulp.dest('dist')); + + return es.merge(buildLib(), buildSort(), buildTplBootstrap(), buildTplSelect2(), buildTplSelectize()) + .pipe(plumber({ + errorHandler: handleError + })) + .pipe(concat('select.js')) + .pipe(header(config.banner, { + timestamp: (new Date()).toISOString(), pkg: config.pkg + })) + .pipe(gulp.dest('dist')) + .pipe(uglify({preserveComments: 'some'})) + .pipe(rename({ext: '.min.js'})) + .pipe(gulp.dest('dist')); }); -gulp.task('styles', ['clean'], function() { +gulp.task('styles', ['clean'], function () { - return gulp.src('src/common.css') - .pipe(header(config.banner, { - timestamp: (new Date()).toISOString(), pkg: config.pkg - })) - .pipe(rename('select.css')) - .pipe(gulp.dest('dist')) - .pipe(minifyCSS()) - .pipe(rename({ext:'.min.css'})) - .pipe(gulp.dest('dist')); + return gulp.src('src/common.css') + .pipe(header(config.banner, { + timestamp: (new Date()).toISOString(), pkg: config.pkg + })) + .pipe(rename('select.css')) + .pipe(gulp.dest('dist')) + .pipe(minifyCSS()) + .pipe(rename({ext: '.min.css'})) + .pipe(gulp.dest('dist')); }); -gulp.task('karma', ['build'], function() { - karma.start({configFile : __dirname +'/karma.conf.js', singleRun: true}); +gulp.task('karma', ['build'], function () { + karma.start({configFile: __dirname + '/karma.conf.js', singleRun: true}); }); -gulp.task('karma-watch', ['build'], function() { - karma.start({configFile : __dirname +'/karma.conf.js', singleRun: false}); +gulp.task('karma-watch', ['build'], function () { + karma.start({configFile: __dirname + '/karma.conf.js', singleRun: false}); }); var handleError = function (err) { - console.log(err.toString()); - this.emit('end'); + console.log(err.toString()); + this.emit('end'); }; \ No newline at end of file diff --git a/src/uiSelectSortDirective.js b/src/addons/uiSelectSortDirective.js similarity index 100% rename from src/uiSelectSortDirective.js rename to src/addons/uiSelectSortDirective.js diff --git a/src/uiSelectChoicesDirective.js b/src/uiSelectChoicesDirective.js index 0276246e1..328f99cfd 100644 --- a/src/uiSelectChoicesDirective.js +++ b/src/uiSelectChoicesDirective.js @@ -54,7 +54,7 @@ uis.directive('uiSelectChoices', scope.$watch('$select.search', function(newValue) { if(newValue && !$select.open && $select.multiple) $select.activate(false, true); - $select.activeIndex = $select.tagging.isActivated ? -1 : 0; + $select.activeIndex = 0; if(!$select.refreshOnActive || ($select.refreshOnActive && $select.refreshIsActive)) { $select.refresh(attrs.refresh); } diff --git a/src/uiSelectController.js b/src/uiSelectController.js index 0c05d719f..dfb05c513 100644 --- a/src/uiSelectController.js +++ b/src/uiSelectController.js @@ -5,550 +5,520 @@ * put as much logic in the controller (instead of the link functions) as possible so it can be easily tested. */ uis.controller('uiSelectCtrl', - ['$scope', '$element', '$timeout', '$filter', '$q', 'uisRepeatParser', 'uiSelectMinErr', 'uiSelectConfig', - function($scope, $element, $timeout, $filter, $q, RepeatParser, uiSelectMinErr, uiSelectConfig) { - - var ctrl = this; - - var EMPTY_SEARCH = ''; - - ctrl.placeholder = uiSelectConfig.placeholder; - ctrl.searchEnabled = uiSelectConfig.searchEnabled; - ctrl.sortable = uiSelectConfig.sortable; - ctrl.refreshDelay = uiSelectConfig.refreshDelay; - - ctrl.removeSelected = false; //If selected item(s) should be removed from dropdown list - ctrl.closeOnSelect = true; //Initialized inside uiSelect directive link function - ctrl.search = EMPTY_SEARCH; - - ctrl.activeIndex = 0; //Dropdown of choices - ctrl.items = []; //All available choices - - ctrl.open = false; - ctrl.focus = false; - ctrl.disabled = false; - ctrl.selected = undefined; - - ctrl.focusser = undefined; //Reference to input element used to handle focus events - ctrl.resetSearchInput = true; - ctrl.multiple = undefined; // Initialized inside uiSelect directive link function - ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelectChoices directive link function - ctrl.tagging = {isActivated: false, fct: undefined}; - ctrl.taggingTokens = {isActivated: false, tokens: undefined}; - ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelectMatch directive link function - ctrl.clickTriggeredSelect = false; - ctrl.$filter = $filter; - ctrl.refreshOnActive = undefined; - ctrl.refreshIsActive = undefined; - - ctrl.searchInput = $element.querySelectorAll('input.ui-select-search'); - if (ctrl.searchInput.length !== 1) { - throw uiSelectMinErr('searchInput', "Expected 1 input.ui-select-search but got '{0}'.", ctrl.searchInput.length); - } - - ctrl.isEmpty = function() { - return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === ''; - }; - - // Most of the time the user does not want to empty the search input when in typeahead mode - function _resetSearchInput() { - if (ctrl.resetSearchInput || (ctrl.resetSearchInput === undefined && uiSelectConfig.resetSearchInput)) { - ctrl.search = EMPTY_SEARCH; - //reset activeIndex - if (ctrl.selected && ctrl.items.length && !ctrl.multiple) { - ctrl.activeIndex = ctrl.items.indexOf(ctrl.selected); - } - } - } - - function _groupsFilter(groups, groupNames) { - var i, j, result = []; - for(i = 0; i < groupNames.length ;i++){ - for(j = 0; j < groups.length ;j++){ - if(groups[j].name == [groupNames[i]]){ - result.push(groups[j]); - } - } - } - return result; - } - - // When the user clicks on ui-select, displays the dropdown list - ctrl.activate = function(initSearchValue, avoidReset) { - if (!ctrl.disabled && !ctrl.open) { - if(!avoidReset) _resetSearchInput(); - - $scope.$broadcast('uis:activate'); - - ctrl.open = true; - if(!ctrl.searchEnabled) { - angular.element(ctrl.searchInput[0]).addClass('ui-select-offscreen'); - } - - ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex; - - ctrl.refreshIsActive = true; - - // ensure that the index is set to zero for tagging variants - // that where first option is auto-selected - if ( ctrl.activeIndex === -1 && ctrl.taggingLabel !== false ) { - ctrl.activeIndex = 0; - } - - // Give it time to appear before focus - $timeout(function() { - ctrl.search = initSearchValue || ctrl.search; - ctrl.searchInput[0].focus(); - }); - } - else if (ctrl.open && !ctrl.searchEnabled) { - // Close the selection if we don't have search enabled, and we click on the select again - ctrl.close(); - } - }; - - ctrl.findGroupByName = function(name) { - return ctrl.groups && ctrl.groups.filter(function(group) { - return group.name === name; - })[0]; - }; - - ctrl.parseRepeatAttr = function(repeatAttr, groupByExp, groupFilterExp) { - function updateGroups(items) { - var groupFn = $scope.$eval(groupByExp); - ctrl.groups = []; - angular.forEach(items, function(item) { - var groupName = angular.isFunction(groupFn) ? groupFn(item) : item[groupFn]; - var group = ctrl.findGroupByName(groupName); - if(group) { - group.items.push(item); - } - else { - ctrl.groups.push({name: groupName, items: [item]}); - } - }); - if(groupFilterExp){ - var groupFilterFn = $scope.$eval(groupFilterExp); - if( angular.isFunction(groupFilterFn)){ - ctrl.groups = groupFilterFn(ctrl.groups); - } else if(angular.isArray(groupFilterFn)){ - ctrl.groups = _groupsFilter(ctrl.groups, groupFilterFn); - } - } - ctrl.items = []; - ctrl.groups.forEach(function(group) { - ctrl.items = ctrl.items.concat(group.items); - }); - } - - function setPlainItems(items) { - ctrl.items = items; - } - - ctrl.setItemsFn = groupByExp ? updateGroups : setPlainItems; - - ctrl.parserResult = RepeatParser.parse(repeatAttr); - - ctrl.isGrouped = !!groupByExp; - ctrl.itemProperty = ctrl.parserResult.itemName; - - ctrl.refreshItems = function (data){ - data = data || ctrl.parserResult.source($scope); - var selectedItems = ctrl.selected; - //TODO should implement for single mode removeSelected - if (ctrl.isEmpty() || (angular.isArray(selectedItems) && !selectedItems.length) || !ctrl.removeSelected) { - ctrl.setItemsFn(data); - }else{ - if ( data !== undefined ) { - var filteredItems = data.filter(function(i) {return selectedItems.indexOf(i) < 0;}); - ctrl.setItemsFn(filteredItems); - } - } - }; - - // See https://github.com/angular/angular.js/blob/v1.2.15/src/ng/directive/ngRepeat.js#L259 - $scope.$watchCollection(ctrl.parserResult.source, function(items) { - if (items === undefined || items === null) { - // If the user specifies undefined or null => reset the collection - // Special case: items can be undefined if the user did not initialized the collection on the scope - // i.e $scope.addresses = [] is missing - ctrl.items = []; - } else { - if (!angular.isArray(items)) { - throw uiSelectMinErr('items', "Expected an array but got '{0}'.", items); - } else { - //Remove already selected items (ex: while searching) - //TODO Should add a test - ctrl.refreshItems(items); - ctrl.ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters - } - } - }); - - }; - - var _refreshDelayPromise; - - /** - * Typeahead mode: lets the user refresh the collection using his own function. - * - * See Expose $select.search for external / remote filtering https://github.com/angular-ui/ui-select/pull/31 - */ - ctrl.refresh = function(refreshAttr) { - if (refreshAttr !== undefined) { - - // Debounce - // See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L155 - // FYI AngularStrap typeahead does not have debouncing: https://github.com/mgcrea/angular-strap/blob/v2.0.0-rc.4/src/typeahead/typeahead.js#L177 - if (_refreshDelayPromise) { - $timeout.cancel(_refreshDelayPromise); - } - _refreshDelayPromise = $timeout(function() { - $scope.$eval(refreshAttr); - }, ctrl.refreshDelay); - } - }; - - ctrl.setActiveItem = function(item) { - ctrl.activeIndex = ctrl.items.indexOf(item); - }; - - ctrl.isActive = function(itemScope) { - if ( !ctrl.open ) { - return false; - } - var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); - var isActive = itemIndex === ctrl.activeIndex; - - if ( !isActive || ( itemIndex < 0 && ctrl.taggingLabel !== false ) ||( itemIndex < 0 && ctrl.taggingLabel === false) ) { - return false; - } - - if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { - itemScope.$eval(ctrl.onHighlightCallback); - } - - return isActive; - }; - - ctrl.isDisabled = function(itemScope) { - - if (!ctrl.open) return; - - var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); - var isDisabled = false; - var item; - - if (itemIndex >= 0 && !angular.isUndefined(ctrl.disableChoiceExpression)) { - item = ctrl.items[itemIndex]; - isDisabled = !!(itemScope.$eval(ctrl.disableChoiceExpression)); // force the boolean value - item._uiSelectChoiceDisabled = isDisabled; // store this for later reference - } - - return isDisabled; - }; - - - // When the user selects an item with ENTER or clicks the dropdown - ctrl.select = function(item, skipFocusser, $event) { - if (item === undefined || !item._uiSelectChoiceDisabled) { - - if ( ! ctrl.items && ! ctrl.search ) return; - - if (!item || !item._uiSelectChoiceDisabled) { - if(ctrl.tagging.isActivated) { - // if taggingLabel is disabled, we pull from ctrl.search val - if ( ctrl.taggingLabel === false ) { - if ( ctrl.activeIndex < 0 ) { - item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : ctrl.search; - if (!item || angular.equals( ctrl.items[0], item ) ) { - return; - } - } else { - // keyboard nav happened first, user selected from dropdown - item = ctrl.items[ctrl.activeIndex]; + ['$scope', '$element', '$timeout', '$filter', '$q', 'uisRepeatParser', 'uiSelectMinErr', 'uiSelectConfig', + function ($scope, $element, $timeout, $filter, $q, RepeatParser, uiSelectMinErr, uiSelectConfig) { + + var ctrl = this; + + var EMPTY_SEARCH = ''; + + ctrl.placeholder = uiSelectConfig.placeholder; + ctrl.searchEnabled = uiSelectConfig.searchEnabled; + ctrl.sortable = uiSelectConfig.sortable; + ctrl.refreshDelay = uiSelectConfig.refreshDelay; + + ctrl.removeSelected = false; //If selected item(s) should be removed from dropdown list + ctrl.closeOnSelect = true; //Initialized inside uiSelect directive link function + ctrl.search = EMPTY_SEARCH; + + ctrl.activeIndex = 0; //Dropdown of choices + ctrl.items = []; //All available choices + + ctrl.open = false; + ctrl.focus = false; + ctrl.disabled = false; + ctrl.selected = undefined; + + ctrl.focusser = undefined; //Reference to input element used to handle focus events + ctrl.resetSearchInput = true; + ctrl.multiple = undefined; // Initialized inside uiSelect directive link function + ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelectChoices directive link function + ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelectMatch directive link function + ctrl.clickTriggeredSelect = false; + ctrl.$filter = $filter; + ctrl.refreshOnActive = undefined; + ctrl.refreshIsActive = undefined; + + ctrl.searchInput = $element.querySelectorAll('input.ui-select-search'); + if (ctrl.searchInput.length !== 1) { + throw uiSelectMinErr('searchInput', "Expected 1 input.ui-select-search but got '{0}'.", + ctrl.searchInput.length); } - } else { - // tagging always operates at index zero, taggingLabel === false pushes - // the ctrl.search value without having it injected - if ( ctrl.activeIndex === 0 ) { - // ctrl.tagging pushes items to ctrl.items, so we only have empty val - // for `item` if it is a detected duplicate - if ( item === undefined ) return; - - // create new item on the fly if we don't already have one; - // use tagging function if we have one - if ( ctrl.tagging.fct !== undefined && typeof item === 'string' ) { - item = ctrl.tagging.fct(ctrl.search); - if (!item) return; - // if item type is 'string', apply the tagging label - } else if ( typeof item === 'string' ) { - // trim the trailing space - item = item.replace(ctrl.taggingLabel,'').trim(); - } + + ctrl.isEmpty = function () { + return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === ''; + }; + + // Most of the time the user does not want to empty the search input when in typeahead mode + function _resetSearchInput() { + if (ctrl.resetSearchInput || (ctrl.resetSearchInput === undefined && uiSelectConfig.resetSearchInput)) { + ctrl.search = EMPTY_SEARCH; + //reset activeIndex + if (ctrl.selected && ctrl.items.length && !ctrl.multiple) { + ctrl.activeIndex = ctrl.items.indexOf(ctrl.selected); + } + } + } + + function _groupsFilter(groups, groupNames) { + var i, j, result = []; + for (i = 0; i < groupNames.length; i++) { + for (j = 0; j < groups.length; j++) { + if (groups[j].name == [groupNames[i]]) { + result.push(groups[j]); + } + } + } + return result; + } + + // When the user clicks on ui-select, displays the dropdown list + ctrl.activate = function (initSearchValue, avoidReset) { + if (!ctrl.disabled && !ctrl.open) { + if (!avoidReset) _resetSearchInput(); + + $scope.$broadcast('uis:activate'); + + ctrl.open = true; + if (!ctrl.searchEnabled) { + angular.element(ctrl.searchInput[0]).addClass('ui-select-offscreen'); + } + + ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex; + ctrl.refreshIsActive = true; + + // Give it time to appear before focus + $timeout(function () { + ctrl.search = initSearchValue || ctrl.search; + ctrl.searchInput[0].focus(); + }); + } + else if (ctrl.open && !ctrl.searchEnabled) { + // Close the selection if we don't have search enabled, and we click on the select again + ctrl.close(); + } + }; + + ctrl.findGroupByName = function (name) { + return ctrl.groups && ctrl.groups.filter(function (group) { + return group.name === name; + })[0]; + }; + + ctrl.parseRepeatAttr = function (repeatAttr, groupByExp, groupFilterExp) { + function updateGroups(items) { + var groupFn = $scope.$eval(groupByExp); + ctrl.groups = []; + angular.forEach(items, function (item) { + var groupName = angular.isFunction(groupFn) ? groupFn(item) : item[groupFn]; + var group = ctrl.findGroupByName(groupName); + if (group) { + group.items.push(item); + } + else { + ctrl.groups.push({name: groupName, items: [item]}); + } + }); + if (groupFilterExp) { + var groupFilterFn = $scope.$eval(groupFilterExp); + if (angular.isFunction(groupFilterFn)) { + ctrl.groups = groupFilterFn(ctrl.groups); + } else if (angular.isArray(groupFilterFn)) { + ctrl.groups = _groupsFilter(ctrl.groups, groupFilterFn); + } + } + ctrl.items = []; + ctrl.groups.forEach(function (group) { + ctrl.items = ctrl.items.concat(group.items); + }); + } + + function setPlainItems(items) { + ctrl.items = items; + } + + ctrl.setItemsFn = groupByExp ? updateGroups : setPlainItems; + + ctrl.parserResult = RepeatParser.parse(repeatAttr); + + ctrl.isGrouped = !!groupByExp; + ctrl.itemProperty = ctrl.parserResult.itemName; + + ctrl.refreshItems = function (data) { + data = data || ctrl.parserResult.source($scope); + var selectedItems = ctrl.selected; + //TODO should implement for single mode removeSelected + if (ctrl.isEmpty() || (angular.isArray(selectedItems) && !selectedItems.length) || + !ctrl.removeSelected) { + ctrl.setItemsFn(data); + } else { + if (data !== undefined) { + var filteredItems = data.filter(function (i) { + return selectedItems.indexOf(i) < 0; + }); + ctrl.setItemsFn(filteredItems); + } + } + }; + + // See https://github.com/angular/angular.js/blob/v1.2.15/src/ng/directive/ngRepeat.js#L259 + $scope.$watchCollection(ctrl.parserResult.source, function (items) { + if (items === undefined || items === null) { + // If the user specifies undefined or null => reset the collection + // Special case: items can be undefined if the user did not initialized the collection on the scope + // i.e $scope.addresses = [] is missing + ctrl.items = []; + } else { + if (!angular.isArray(items)) { + throw uiSelectMinErr('items', "Expected an array but got '{0}'.", items); + } else { + //Remove already selected items (ex: while searching) + //TODO Should add a test + ctrl.refreshItems(items); + ctrl.ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters + } + } + }); + + }; + + var _refreshDelayPromise; + + /** + * Typeahead mode: lets the user refresh the collection using his own function. + * + * See Expose $select.search for external / remote filtering https://github.com/angular-ui/ui-select/pull/31 + */ + ctrl.refresh = function (refreshAttr) { + if (refreshAttr !== undefined) { + + // Debounce + // See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L155 + // FYI AngularStrap typeahead does not have debouncing: https://github.com/mgcrea/angular-strap/blob/v2.0.0-rc.4/src/typeahead/typeahead.js#L177 + if (_refreshDelayPromise) { + $timeout.cancel(_refreshDelayPromise); + } + _refreshDelayPromise = $timeout(function () { + $scope.$eval(refreshAttr); + }, ctrl.refreshDelay); + } + }; + + ctrl.setActiveItem = function (item) { + ctrl.activeIndex = ctrl.items.indexOf(item); + }; + + ctrl.isActive = function (itemScope) { + if (!ctrl.open) { + return false; + } + var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); + var isActive = itemIndex === ctrl.activeIndex; + + if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { + itemScope.$eval(ctrl.onHighlightCallback); + } + + return isActive; + }; + + /** + * Checks if the item is disabled + * @return boolean true if the item is disabled + */ + ctrl.isDisabled = function (itemScope) { + + if (!ctrl.open) return false; + + var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); + var isDisabled = false; + var item; + + if (itemIndex >= 0 && !angular.isUndefined(ctrl.disableChoiceExpression)) { + item = ctrl.items[itemIndex]; + isDisabled = !!(itemScope.$eval(ctrl.disableChoiceExpression)); // force the boolean value + item._uiSelectChoiceDisabled = isDisabled; // store this for later reference + } + + return isDisabled; + }; + + + /** + * Called when the user selects an item with ENTER or clicks the dropdown + */ + ctrl.select = function (item, skipFocusser, $event) { + if (item === undefined || !item._uiSelectChoiceDisabled) { + + if (!ctrl.items && !ctrl.search){ + return; + } + + if (!item || !item._uiSelectChoiceDisabled) { + + var completeSelection = function () { + $scope.$broadcast('uis:select', item); + + $timeout(function () { + ctrl.onSelectCallback($scope, callbackContext); + }); + + if (ctrl.closeOnSelect) { + ctrl.close(skipFocusser); + } + if ($event && $event.type === 'click') { + ctrl.clickTriggeredSelect = true; + } + }; + + var locals = {}; + locals[ctrl.parserResult.itemName] = item; + + var callbackContext = { + $item: item, + $model: ctrl.parserResult.modelMapper($scope, locals) + }; + + // Call the onBeforeSelect callback + // Allowable responses are -: + // falsy: Abort the selection + // promise: Wait for response + // true: Complete selection + // object: Add the returned object + var onBeforeSelectResult = ctrl.onBeforeSelectCallback($scope, callbackContext); + if (angular.isDefined(onBeforeSelectResult)) { + if (!onBeforeSelectResult) { + return; // abort the selection in case of deliberate falsey result + } else if (angular.isFunction(onBeforeSelectResult.then)) { + onBeforeSelectResult.then(function (result) { + if (!result) { + return; + } + completeSelection(result); + }); + } else if (onBeforeSelectResult === true) { + completeSelection(item); + } else { + completeSelection(onBeforeSelectResult); + } + } else { + completeSelection(item); + } + } + } + }; + + // Closes the dropdown + ctrl.close = function (skipFocusser) { + if (!ctrl.open) { + return; + } + if (ctrl.ngModel && ctrl.ngModel.$setTouched) ctrl.ngModel.$setTouched(); + _resetSearchInput(); + ctrl.open = false; + if (!ctrl.searchEnabled) { + angular.element(ctrl.searchInput[0]).removeClass('ui-select-offscreen'); + } + + $scope.$broadcast('uis:close', skipFocusser); + }; + + ctrl.setFocus = function () { + if (!ctrl.focus) { + ctrl.focusInput[0].focus(); + } + }; + + ctrl.clear = function ($event) { + ctrl.select(undefined); + $event.stopPropagation(); + $timeout(function () { + ctrl.focusser[0].focus(); + }, 0, false); + }; + + // Toggle dropdown + ctrl.toggle = function (e) { + if (ctrl.open) { + ctrl.close(); + e.preventDefault(); + e.stopPropagation(); + } else { + ctrl.activate(); + } + }; + + ctrl.isLocked = function (itemScope, itemIndex) { + var isLocked, item = ctrl.selected[itemIndex]; + + if (item && !angular.isUndefined(ctrl.lockChoiceExpression)) { + isLocked = !!(itemScope.$eval(ctrl.lockChoiceExpression)); // force the boolean value + item._uiSelectChoiceLocked = isLocked; // store this for later reference + } + + return isLocked; + }; + + var sizeWatch = null; + ctrl.sizeSearchInput = function () { + + var input = ctrl.searchInput[0], + container = ctrl.searchInput.parent().parent()[0], + calculateContainerWidth = function () { + // Return the container width only if the search input is visible + return container.clientWidth * !!input.offsetParent; + }, + updateIfVisible = function (containerWidth) { + if (containerWidth === 0) { + return false; + } + var inputWidth = containerWidth - input.offsetLeft - ctrl.searchInput.parent()[0].offsetLeft - + 5; + if (inputWidth < 50) { + inputWidth = containerWidth; + } + ctrl.searchInput.css('width', inputWidth + 'px'); + return true; + }; + + ctrl.searchInput.css('width', '10px'); + $timeout(function () { //Give time to render correctly + if (sizeWatch === null && !updateIfVisible(calculateContainerWidth())) { + sizeWatch = $scope.$watch(calculateContainerWidth, function (containerWidth) { + if (updateIfVisible(containerWidth)) { + sizeWatch(); + sizeWatch = null; + } + }); + } + }); + }; + + function _handleDropDownSelection(key) { + var processed = true; + switch (key) { + case KEY.DOWN: + if (!ctrl.open && ctrl.multiple) { + ctrl.activate(false, true); //In case its the search input in 'multiple' mode + } + else if (ctrl.activeIndex < ctrl.items.length - 1) { + ctrl.activeIndex++; + } + break; + case KEY.UP: + if (!ctrl.open && ctrl.multiple) { + ctrl.activate(false, true); + } //In case its the search input in 'multiple' mode + else if (ctrl.activeIndex > 0) { + ctrl.activeIndex--; + } + break; + case KEY.TAB: + if (!ctrl.multiple || ctrl.open) ctrl.select(ctrl.items[ctrl.activeIndex], true); + break; + case KEY.ENTER: + if (ctrl.open) { + // Make sure at least one dropdown item is highlighted before adding + ctrl.select(ctrl.items[ctrl.activeIndex]); + } else { + // In case its the search input in 'multiple' mode + ctrl.activate(false, true); + } + break; + case KEY.ESC: + ctrl.close(); + break; + default: + processed = false; + } + return processed; } - } - // search ctrl.selected for dupes potentially caused by tagging and return early if found - if ( ctrl.selected && angular.isArray(ctrl.selected) && ctrl.selected.filter( function (selection) { return angular.equals(selection, item); }).length > 0 ) { - ctrl.close(skipFocusser); - return; - } - } - - var completeSelection = function() { - $scope.$broadcast('uis:select', item); - - $timeout(function(){ - ctrl.onSelectCallback($scope, callbackContext); - }); - - if (ctrl.closeOnSelect) { - ctrl.close(skipFocusser); - } - if ($event && $event.type === 'click') { - ctrl.clickTriggeredSelect = true; - } - }; - - var locals = {}; - locals[ctrl.parserResult.itemName] = item; - - var callbackContext = { - $item: item, - $model: ctrl.parserResult.modelMapper($scope, locals) - }; - - var onBeforeSelectResult = ctrl.onBeforeSelectCallback($scope, callbackContext); - - if (angular.isDefined(onBeforeSelectResult)) { - if (!onBeforeSelectResult) { - return; // abort the selection in case of deliberate falsey result - } else if (angular.isFunction(onBeforeSelectResult.then)) { - onBeforeSelectResult.then(completeSelection); - } else { - completeSelection(); - } - } else { - completeSelection(); - } - - } - } - }; - - // Closes the dropdown - ctrl.close = function(skipFocusser) { - if (!ctrl.open) return; - if (ctrl.ngModel && ctrl.ngModel.$setTouched) ctrl.ngModel.$setTouched(); - _resetSearchInput(); - ctrl.open = false; - if(!ctrl.searchEnabled) { - angular.element(ctrl.searchInput[0]).removeClass('ui-select-offscreen'); - } - - $scope.$broadcast('uis:close', skipFocusser); - - }; - - ctrl.setFocus = function(){ - if (!ctrl.focus) ctrl.focusInput[0].focus(); - }; - - ctrl.clear = function($event) { - ctrl.select(undefined); - $event.stopPropagation(); - $timeout(function() { - ctrl.focusser[0].focus(); - }, 0, false); - }; - - // Toggle dropdown - ctrl.toggle = function(e) { - if (ctrl.open) { - ctrl.close(); - e.preventDefault(); - e.stopPropagation(); - } else { - ctrl.activate(); - } - }; - - ctrl.isLocked = function(itemScope, itemIndex) { - var isLocked, item = ctrl.selected[itemIndex]; - - if (item && !angular.isUndefined(ctrl.lockChoiceExpression)) { - isLocked = !!(itemScope.$eval(ctrl.lockChoiceExpression)); // force the boolean value - item._uiSelectChoiceLocked = isLocked; // store this for later reference - } - - return isLocked; - }; - - var sizeWatch = null; - ctrl.sizeSearchInput = function() { - - var input = ctrl.searchInput[0], - container = ctrl.searchInput.parent().parent()[0], - calculateContainerWidth = function() { - // Return the container width only if the search input is visible - return container.clientWidth * !!input.offsetParent; - }, - updateIfVisible = function(containerWidth) { - if (containerWidth === 0) { - return false; - } - var inputWidth = containerWidth - input.offsetLeft - ctrl.searchInput.parent()[0].offsetLeft - 5; - if (inputWidth < 50) inputWidth = containerWidth; - ctrl.searchInput.css('width', inputWidth+'px'); - return true; - }; - - ctrl.searchInput.css('width', '10px'); - $timeout(function() { //Give tags time to render correctly - if (sizeWatch === null && !updateIfVisible(calculateContainerWidth())) { - sizeWatch = $scope.$watch(calculateContainerWidth, function(containerWidth) { - if (updateIfVisible(containerWidth)) { - sizeWatch(); - sizeWatch = null; - } - }); - } - }); - }; - - function _handleDropDownSelection(key) { - var processed = true; - switch (key) { - case KEY.DOWN: - if (!ctrl.open && ctrl.multiple) ctrl.activate(false, true); //In case its the search input in 'multiple' mode - else if (ctrl.activeIndex < ctrl.items.length - 1) { ctrl.activeIndex++; } - break; - case KEY.UP: - if (!ctrl.open && ctrl.multiple) ctrl.activate(false, true); //In case its the search input in 'multiple' mode - else if (ctrl.activeIndex > 0 || (ctrl.search.length === 0 && ctrl.tagging.isActivated && ctrl.activeIndex > -1)) { ctrl.activeIndex--; } - break; - case KEY.TAB: - if (!ctrl.multiple || ctrl.open) ctrl.select(ctrl.items[ctrl.activeIndex], true); - break; - case KEY.ENTER: - if(ctrl.open && (ctrl.tagging.isActivated || ctrl.activeIndex >= 0)){ - ctrl.select(ctrl.items[ctrl.activeIndex]); // Make sure at least one dropdown item is highlighted before adding if not in tagging mode - } else { - ctrl.activate(false, true); //In case its the search input in 'multiple' mode - } - break; - case KEY.ESC: - ctrl.close(); - break; - default: - processed = false; - } - return processed; - } - - // Bind to keyboard shortcuts - ctrl.searchInput.on('keydown', function(e) { - - var key = e.which; - - // if(~[KEY.ESC,KEY.TAB].indexOf(key)){ - // //TODO: SEGURO? - // ctrl.close(); - // } - - $scope.$apply(function() { - - var tagged = false; - - if (ctrl.items.length > 0 || ctrl.tagging.isActivated) { - _handleDropDownSelection(key); - if ( ctrl.taggingTokens.isActivated ) { - for (var i = 0; i < ctrl.taggingTokens.tokens.length; i++) { - if ( ctrl.taggingTokens.tokens[i] === KEY.MAP[e.keyCode] ) { - // make sure there is a new value to push via tagging - if ( ctrl.search.length > 0 ) { - tagged = true; - } + + // Bind to keyboard shortcuts + ctrl.searchInput.on('keydown', function (e) { + + var key = e.which; + + // if(~[KEY.ESC,KEY.TAB].indexOf(key)){ + // //TODO: SEGURO? + // ctrl.close(); + // } + + $scope.$apply(function () { + _handleDropDownSelection(key); + }); + + if (KEY.isVerticalMovement(key) && ctrl.items.length > 0) { + _ensureHighlightVisible(); + } + + if (key === KEY.ENTER || key === KEY.ESC) { + e.preventDefault(); + e.stopPropagation(); + } + }); + + // If tagging try to split by tokens and add items + /* ctrl.searchInput.on('paste', function (e) { + var data = e.originalEvent.clipboardData.getData('text/plain'); + if (data && data.length > 0 && ctrl.taggingTokens.isActivated && ctrl.tagging.fct) { + var items = data.split(ctrl.taggingTokens.tokens[0]); // split by first token only + if (items && items.length > 0) { + angular.forEach(items, function (item) { + var newItem = ctrl.tagging.fct(item); + if (newItem) { + ctrl.select(newItem, true); + } + }); + e.preventDefault(); + e.stopPropagation(); + } + } + });*/ + + ctrl.searchInput.on('keyup', function (e) { + // return early with these keys + if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || + KEY.isVerticalMovement(e.which)) { + return; + } + + if (ctrl.onKeypressCallback === undefined) { + return; + } + ctrl.onKeypressCallback($scope, {event: e}); + }); + + + // See https://github.com/ivaynberg/select2/blob/3.4.6/select2.js#L1431 + function _ensureHighlightVisible() { + var container = $element.querySelectorAll('.ui-select-choices-content'); + var choices = container.querySelectorAll('.ui-select-choices-row'); + if (choices.length < 1) { + throw uiSelectMinErr('choices', "Expected multiple .ui-select-choices-row but got '{0}'.", + choices.length); + } + + if (ctrl.activeIndex < 0) { + return; + } + + var highlighted = choices[ctrl.activeIndex]; + var posY = highlighted.offsetTop + highlighted.clientHeight - container[0].scrollTop; + var height = container[0].offsetHeight; + + if (posY > height) { + container[0].scrollTop += posY - height; + } else if (posY < highlighted.clientHeight) { + if (ctrl.isGrouped && ctrl.activeIndex === 0) + container[0].scrollTop = 0; //To make group header visible when going all the way up + else + container[0].scrollTop -= highlighted.clientHeight - posY; + } } - } - if ( tagged ) { - $timeout(function() { - ctrl.searchInput.triggerHandler('tagged'); - var newItem = ctrl.search.replace(KEY.MAP[e.keyCode],'').trim(); - if ( ctrl.tagging.fct ) { - newItem = ctrl.tagging.fct( newItem ); - } - if (newItem) ctrl.select(newItem, true); + + $scope.$on('$destroy', function () { + ctrl.searchInput.off('keyup keydown blur paste'); }); - } - } - } - - }); - - if(KEY.isVerticalMovement(key) && ctrl.items.length > 0){ - _ensureHighlightVisible(); - } - - if (key === KEY.ENTER || key === KEY.ESC) { - e.preventDefault(); - e.stopPropagation(); - } - - }); - - // If tagging try to split by tokens and add items - ctrl.searchInput.on('paste', function (e) { - var data = e.originalEvent.clipboardData.getData('text/plain'); - if (data && data.length > 0 && ctrl.taggingTokens.isActivated && ctrl.tagging.fct) { - var items = data.split(ctrl.taggingTokens.tokens[0]); // split by first token only - if (items && items.length > 0) { - angular.forEach(items, function (item) { - var newItem = ctrl.tagging.fct(item); - if (newItem) { - ctrl.select(newItem, true); - } - }); - e.preventDefault(); - e.stopPropagation(); - } - } - }); - - ctrl.searchInput.on('tagged', function() { - $timeout(function() { - _resetSearchInput(); - }); - }); - - // See https://github.com/ivaynberg/select2/blob/3.4.6/select2.js#L1431 - function _ensureHighlightVisible() { - var container = $element.querySelectorAll('.ui-select-choices-content'); - var choices = container.querySelectorAll('.ui-select-choices-row'); - if (choices.length < 1) { - throw uiSelectMinErr('choices', "Expected multiple .ui-select-choices-row but got '{0}'.", choices.length); - } - - if (ctrl.activeIndex < 0) { - return; - } - - var highlighted = choices[ctrl.activeIndex]; - var posY = highlighted.offsetTop + highlighted.clientHeight - container[0].scrollTop; - var height = container[0].offsetHeight; - - if (posY > height) { - container[0].scrollTop += posY - height; - } else if (posY < highlighted.clientHeight) { - if (ctrl.isGrouped && ctrl.activeIndex === 0) - container[0].scrollTop = 0; //To make group header visible when going all the way up - else - container[0].scrollTop -= highlighted.clientHeight - posY; - } - } - - $scope.$on('$destroy', function() { - ctrl.searchInput.off('keyup keydown tagged blur paste'); - }); - -}]); + + }]); diff --git a/src/uiSelectDirective.js b/src/uiSelectDirective.js index 3645e67d2..41e81a774 100644 --- a/src/uiSelectDirective.js +++ b/src/uiSelectDirective.js @@ -1,290 +1,273 @@ uis.directive('uiSelect', - ['$document', 'uiSelectConfig', 'uiSelectMinErr', 'uisOffset', '$compile', '$parse', '$timeout', - function($document, uiSelectConfig, uiSelectMinErr, uisOffset, $compile, $parse, $timeout) { - - return { - restrict: 'EA', - templateUrl: function(tElement, tAttrs) { - var theme = tAttrs.theme || uiSelectConfig.theme; - return theme + (angular.isDefined(tAttrs.multiple) ? '/select-multiple.tpl.html' : '/select.tpl.html'); - }, - replace: true, - transclude: true, - require: ['uiSelect', '^ngModel'], - scope: true, - - controller: 'uiSelectCtrl', - controllerAs: '$select', - compile: function(tElement, tAttrs) { - - //Multiple or Single depending if multiple attribute presence - if (angular.isDefined(tAttrs.multiple)) - tElement.append("").removeAttr('multiple'); - else - tElement.append(""); - - return function(scope, element, attrs, ctrls, transcludeFn) { - - var $select = ctrls[0]; - var ngModel = ctrls[1]; - - $select.generatedId = uiSelectConfig.generateId(); - $select.baseTitle = attrs.title || 'Select box'; - $select.focusserTitle = $select.baseTitle + ' focus'; - $select.focusserId = 'focusser-' + $select.generatedId; - - $select.closeOnSelect = function() { - if (angular.isDefined(attrs.closeOnSelect)) { - return $parse(attrs.closeOnSelect)(); - } else { - return uiSelectConfig.closeOnSelect; - } - }(); - - $select.onBeforeSelectCallback = $parse(attrs.onBeforeSelect); - $select.onSelectCallback = $parse(attrs.onSelect); - $select.onRemoveCallback = $parse(attrs.onRemove); - - //Limit the number of selections allowed - $select.limit = (angular.isDefined(attrs.limit)) ? parseInt(attrs.limit, 10) : undefined; - - //Set reference to ngModel from uiSelectCtrl - $select.ngModel = ngModel; - - $select.choiceGrouped = function(group){ - return $select.isGrouped && group && group.name; - }; - - if(attrs.tabindex){ - attrs.$observe('tabindex', function(value) { - $select.focusInput.attr("tabindex", value); - element.removeAttr("tabindex"); - }); - } - - var searchEnabled = scope.$eval(attrs.searchEnabled); - $select.searchEnabled = searchEnabled !== undefined ? searchEnabled : uiSelectConfig.searchEnabled; - - var sortable = scope.$eval(attrs.sortable); - $select.sortable = sortable !== undefined ? sortable : uiSelectConfig.sortable; - - attrs.$observe('disabled', function() { - // No need to use $eval() (thanks to ng-disabled) since we already get a boolean instead of a string - $select.disabled = attrs.disabled !== undefined ? attrs.disabled : false; - }); - - attrs.$observe('resetSearchInput', function() { - // $eval() is needed otherwise we get a string instead of a boolean - var resetSearchInput = scope.$eval(attrs.resetSearchInput); - $select.resetSearchInput = resetSearchInput !== undefined ? resetSearchInput : true; - }); - - if(attrs.tagging !== undefined) - { - // $eval() is needed otherwise we get a string instead of a boolean - var taggingEval = scope.$eval(attrs.tagging); - $select.tagging = {isActivated: true, fct: taggingEval !== true ? taggingEval : undefined}; - } - else - { - $select.tagging = {isActivated: false, fct: undefined}; - } - - if(attrs.tagging !== undefined ) - { - // check eval for FALSE, in this case, we disable the labels - // associated with tagging - if ( attrs.taggingLabel === 'false' ) { - $select.taggingLabel = false; - } - else - { - $select.taggingLabel = attrs.taggingLabel !== undefined ? attrs.taggingLabel : '(new)'; - } - } - - if (attrs.tagging !== undefined) { - var tokens = attrs.taggingTokens !== undefined ? attrs.taggingTokens.split('|') : [',','ENTER']; - $select.taggingTokens = {isActivated: true, tokens: tokens }; - } - - //Automatically gets focus when loaded - if (angular.isDefined(attrs.autofocus)){ - $timeout(function(){ - $select.setFocus(); - }); - } - - //Gets focus based on scope event name (e.g. focus-on='SomeEventName') - if (angular.isDefined(attrs.focusOn)){ - scope.$on(attrs.focusOn, function() { - $timeout(function(){ - $select.setFocus(); - }); - }); - } - - function onDocumentClick(e) { - if (!$select.open) return; //Skip it if dropdown is close - - var contains = false; - - if (window.jQuery) { - // Firefox 3.6 does not support element.contains() - // See Node.contains https://developer.mozilla.org/en-US/docs/Web/API/Node.contains - contains = window.jQuery.contains(element[0], e.target); - } else { - contains = element[0].contains(e.target); - } - - if (!contains && !$select.clickTriggeredSelect) { - //Will lose focus only with certain targets - var focusableControls = ['input','button','textarea']; - var targetScope = angular.element(e.target).scope(); //To check if target is other ui-select - var skipFocusser = targetScope && targetScope.$select && targetScope.$select !== $select; //To check if target is other ui-select - if (!skipFocusser) skipFocusser = ~focusableControls.indexOf(e.target.tagName.toLowerCase()); //Check if target is input, button or textarea - $select.close(skipFocusser); - scope.$digest(); - } - $select.clickTriggeredSelect = false; - } - - // See Click everywhere but here event http://stackoverflow.com/questions/12931369 - $document.on('click', onDocumentClick); - - scope.$on('$destroy', function() { - $document.off('click', onDocumentClick); - }); - - // Move transcluded elements to their correct position in main template - transcludeFn(scope, function(clone) { - // See Transclude in AngularJS http://blog.omkarpatil.com/2012/11/transclude-in-angularjs.html - - // One day jqLite will be replaced by jQuery and we will be able to write: - // var transcludedElement = clone.filter('.my-class') - // instead of creating a hackish DOM element: - var transcluded = angular.element('
    ').append(clone); - - var transcludedMatch = transcluded.querySelectorAll('.ui-select-match'); - transcludedMatch.removeAttr('ui-select-match'); //To avoid loop in case directive as attr - transcludedMatch.removeAttr('data-ui-select-match'); // Properly handle HTML5 data-attributes - if (transcludedMatch.length !== 1) { - throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-match but got '{0}'.", transcludedMatch.length); - } - element.querySelectorAll('.ui-select-match').replaceWith(transcludedMatch); - - var transcludedChoices = transcluded.querySelectorAll('.ui-select-choices'); - transcludedChoices.removeAttr('ui-select-choices'); //To avoid loop in case directive as attr - transcludedChoices.removeAttr('data-ui-select-choices'); // Properly handle HTML5 data-attributes - if (transcludedChoices.length !== 1) { - throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-choices but got '{0}'.", transcludedChoices.length); - } - element.querySelectorAll('.ui-select-choices').replaceWith(transcludedChoices); - }); - - // Support for appending the select field to the body when its open - var appendToBody = scope.$eval(attrs.appendToBody); - if (appendToBody !== undefined ? appendToBody : uiSelectConfig.appendToBody) { - scope.$watch('$select.open', function(isOpen) { - if (isOpen) { - positionDropdown(); - } else { - resetDropdown(); - } - }); - - // Move the dropdown back to its original location when the scope is destroyed. Otherwise - // it might stick around when the user routes away or the select field is otherwise removed - scope.$on('$destroy', function() { - resetDropdown(); - }); - } - - // Hold on to a reference to the .ui-select-container element for appendToBody support - var placeholder = null, - originalWidth = ''; - - function positionDropdown() { - // Remember the absolute position of the element - var offset = uisOffset(element); - - // Clone the element into a placeholder element to take its original place in the DOM - placeholder = angular.element('
    '); - placeholder[0].style.width = offset.width + 'px'; - placeholder[0].style.height = offset.height + 'px'; - element.after(placeholder); - - // Remember the original value of the element width inline style, so it can be restored - // when the dropdown is closed - originalWidth = element[0].style.width; - - // Now move the actual dropdown element to the end of the body - $document.find('body').append(element); - - element[0].style.position = 'absolute'; - element[0].style.left = offset.left + 'px'; - element[0].style.top = offset.top + 'px'; - element[0].style.width = offset.width + 'px'; - } - - function resetDropdown() { - if (placeholder === null) { - // The dropdown has not actually been display yet, so there's nothing to reset - return; - } - - // Move the dropdown element back to its original location in the DOM - placeholder.replaceWith(element); - placeholder = null; - - element[0].style.position = ''; - element[0].style.left = ''; - element[0].style.top = ''; - element[0].style.width = originalWidth; - } - - // Hold on to a reference to the .ui-select-dropdown element for direction support. - var dropdown = null, - directionUpClassName = 'direction-up'; - - // Support changing the direction of the dropdown if there isn't enough space to render it. - scope.$watch('$select.open', function(isOpen) { - if (isOpen) { - dropdown = angular.element(element).querySelectorAll('.ui-select-dropdown'); - if (dropdown === null) { - return; - } - - // Hide the dropdown so there is no flicker until $timeout is done executing. - dropdown[0].style.opacity = 0; - - // Delay positioning the dropdown until all choices have been added so its height is correct. - $timeout(function(){ - var offset = uisOffset(element); - var offsetDropdown = uisOffset(dropdown); - - // Determine if the direction of the dropdown needs to be changed. - if (offset.top + offset.height + offsetDropdown.height > $document[0].documentElement.scrollTop + $document[0].documentElement.clientHeight) { - dropdown[0].style.position = 'absolute'; - dropdown[0].style.top = (offsetDropdown.height * -1) + 'px'; - element.addClass(directionUpClassName); - } - - // Display the dropdown once it has been positioned. - dropdown[0].style.opacity = 1; - }); - } else { - if (dropdown === null) { - return; - } - - // Reset the position of the dropdown. - dropdown[0].style.position = ''; - dropdown[0].style.top = ''; - element.removeClass(directionUpClassName); - } - }); - }; - } - }; -}]); + ['$document', 'uiSelectConfig', 'uiSelectMinErr', 'uisOffset', '$compile', '$parse', '$timeout', + function ($document, uiSelectConfig, uiSelectMinErr, uisOffset, $compile, $parse, $timeout) { + + return { + restrict: 'EA', + templateUrl: function (tElement, tAttrs) { + var theme = tAttrs.theme || uiSelectConfig.theme; + return theme + + (angular.isDefined(tAttrs.multiple) ? '/select-multiple.tpl.html' : '/select.tpl.html'); + }, + replace: true, + transclude: true, + require: ['uiSelect', '^ngModel'], + scope: true, + controller: 'uiSelectCtrl', + controllerAs: '$select', + compile: function (tElement, tAttrs) { + + //Multiple or Single depending if multiple attribute presence + if (angular.isDefined(tAttrs.multiple)) + tElement.append("").removeAttr('multiple'); + else + tElement.append(""); + + return function (scope, element, attrs, ctrls, transcludeFn) { + + var $select = ctrls[0]; + var ngModel = ctrls[1]; + + $select.generatedId = uiSelectConfig.generateId(); + $select.baseTitle = attrs.title || 'Select box'; + $select.focusserTitle = $select.baseTitle + ' focus'; + $select.focusserId = 'focusser-' + $select.generatedId; + + $select.closeOnSelect = function () { + if (angular.isDefined(attrs.closeOnSelect)) { + return $parse(attrs.closeOnSelect)(); + } else { + return uiSelectConfig.closeOnSelect; + } + }(); + + $select.onBeforeSelectCallback = $parse(attrs.onBeforeSelect); + $select.onSelectCallback = $parse(attrs.onSelect); + $select.onRemoveCallback = $parse(attrs.onRemove); + $select.onKeypressCallback = $parse(attrs.onKeypress); + + //Limit the number of selections allowed + $select.limit = (angular.isDefined(attrs.limit)) ? parseInt(attrs.limit, 10) : undefined; + + //Set reference to ngModel from uiSelectCtrl + $select.ngModel = ngModel; + + $select.choiceGrouped = function (group) { + return $select.isGrouped && group && group.name; + }; + + if (attrs.tabindex) { + attrs.$observe('tabindex', function (value) { + $select.focusInput.attr("tabindex", value); + element.removeAttr("tabindex"); + }); + } + + var searchEnabled = scope.$eval(attrs.searchEnabled); + $select.searchEnabled = + searchEnabled !== undefined ? searchEnabled : uiSelectConfig.searchEnabled; + + var sortable = scope.$eval(attrs.sortable); + $select.sortable = sortable !== undefined ? sortable : uiSelectConfig.sortable; + + attrs.$observe('disabled', function () { + // No need to use $eval() (thanks to ng-disabled) since we already get a boolean instead of a string + $select.disabled = attrs.disabled !== undefined ? attrs.disabled : false; + }); + + attrs.$observe('resetSearchInput', function () { + // $eval() is needed otherwise we get a string instead of a boolean + var resetSearchInput = scope.$eval(attrs.resetSearchInput); + $select.resetSearchInput = resetSearchInput !== undefined ? resetSearchInput : true; + }); + + //Automatically gets focus when loaded + if (angular.isDefined(attrs.autofocus)) { + $timeout(function () { + $select.setFocus(); + }); + } + + //Gets focus based on scope event name (e.g. focus-on='SomeEventName') + if (angular.isDefined(attrs.focusOn)) { + scope.$on(attrs.focusOn, function () { + $timeout(function () { + $select.setFocus(); + }); + }); + } + + function onDocumentClick(e) { + if (!$select.open) return; //Skip it if dropdown is close + + var contains = false; + + if (window.jQuery) { + // Firefox 3.6 does not support element.contains() + // See Node.contains https://developer.mozilla.org/en-US/docs/Web/API/Node.contains + contains = window.jQuery.contains(element[0], e.target); + } else { + contains = element[0].contains(e.target); + } + + if (!contains && !$select.clickTriggeredSelect) { + //Will lose focus only with certain targets + var focusableControls = ['input', 'button', 'textarea']; + //To check if target is other ui-select + var targetScope = angular.element(e.target).scope(); + //To check if target is other ui-select + var skipFocusser = targetScope && targetScope.$select && + targetScope.$select !== $select; + //Check if target is input, button or textarea + if (!skipFocusser) { + skipFocusser = ~focusableControls.indexOf(e.target.tagName.toLowerCase()); + } + $select.close(skipFocusser); + scope.$digest(); + } + $select.clickTriggeredSelect = false; + } + + // See Click everywhere but here event http://stackoverflow.com/questions/12931369 + $document.on('click', onDocumentClick); + + scope.$on('$destroy', function () { + $document.off('click', onDocumentClick); + }); + + // Move transcluded elements to their correct position in main template + transcludeFn(scope, function (clone) { + // See Transclude in AngularJS http://blog.omkarpatil.com/2012/11/transclude-in-angularjs.html + + // One day jqLite will be replaced by jQuery and we will be able to write: + // var transcludedElement = clone.filter('.my-class') + // instead of creating a hackish DOM element: + var transcluded = angular.element('
    ').append(clone); + + var transcludedMatch = transcluded.querySelectorAll('.ui-select-match'); + transcludedMatch.removeAttr('ui-select-match'); //To avoid loop in case directive as attr + transcludedMatch.removeAttr('data-ui-select-match'); // Properly handle HTML5 data-attributes + if (transcludedMatch.length !== 1) { + throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-match but got '{0}'.", + transcludedMatch.length); + } + element.querySelectorAll('.ui-select-match').replaceWith(transcludedMatch); + + var transcludedChoices = transcluded.querySelectorAll('.ui-select-choices'); + transcludedChoices.removeAttr('ui-select-choices'); //To avoid loop in case directive as attr + transcludedChoices.removeAttr('data-ui-select-choices'); // Properly handle HTML5 data-attributes + if (transcludedChoices.length !== 1) { + throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-choices but got '{0}'.", + transcludedChoices.length); + } + element.querySelectorAll('.ui-select-choices').replaceWith(transcludedChoices); + }); + + // Support for appending the select field to the body when its open + var appendToBody = scope.$eval(attrs.appendToBody); + if (appendToBody !== undefined ? appendToBody : uiSelectConfig.appendToBody) { + scope.$watch('$select.open', function (isOpen) { + if (isOpen) { + positionDropdown(); + } else { + resetDropdown(); + } + }); + + // Move the dropdown back to its original location when the scope is destroyed. Otherwise + // it might stick around when the user routes away or the select field is otherwise removed + scope.$on('$destroy', function () { + resetDropdown(); + }); + } + + // Hold on to a reference to the .ui-select-container element for appendToBody support + var placeholder = null, + originalWidth = ''; + + function positionDropdown() { + // Remember the absolute position of the element + var offset = uisOffset(element); + + // Clone the element into a placeholder element to take its original place in the DOM + placeholder = angular.element('
    '); + placeholder[0].style.width = offset.width + 'px'; + placeholder[0].style.height = offset.height + 'px'; + element.after(placeholder); + + // Remember the original value of the element width inline style, so it can be restored + // when the dropdown is closed + originalWidth = element[0].style.width; + + // Now move the actual dropdown element to the end of the body + $document.find('body').append(element); + + element[0].style.position = 'absolute'; + element[0].style.left = offset.left + 'px'; + element[0].style.top = offset.top + 'px'; + element[0].style.width = offset.width + 'px'; + } + + function resetDropdown() { + if (placeholder === null) { + // The dropdown has not actually been display yet, so there's nothing to reset + return; + } + + // Move the dropdown element back to its original location in the DOM + placeholder.replaceWith(element); + placeholder = null; + + element[0].style.position = ''; + element[0].style.left = ''; + element[0].style.top = ''; + element[0].style.width = originalWidth; + } + + // Hold on to a reference to the .ui-select-dropdown element for direction support. + var dropdown = null, + directionUpClassName = 'direction-up'; + + // Support changing the direction of the dropdown if there isn't enough space to render it. + scope.$watch('$select.open', function (isOpen) { + if (isOpen) { + dropdown = angular.element(element).querySelectorAll('.ui-select-dropdown'); + if (dropdown === null) { + return; + } + + // Hide the dropdown so there is no flicker until $timeout is done executing. + dropdown[0].style.opacity = 0; + + // Delay positioning the dropdown until all choices have been added so its height is correct. + $timeout(function () { + var offset = uisOffset(element); + var offsetDropdown = uisOffset(dropdown); + + // Determine if the direction of the dropdown needs to be changed. + if (offset.top + offset.height + offsetDropdown.height > + $document[0].documentElement.scrollTop + + $document[0].documentElement.clientHeight) { + dropdown[0].style.position = 'absolute'; + dropdown[0].style.top = (offsetDropdown.height * -1) + 'px'; + element.addClass(directionUpClassName); + } + + // Display the dropdown once it has been positioned. + dropdown[0].style.opacity = 1; + }); + } else { + if (dropdown === null) { + return; + } + + // Reset the position of the dropdown. + dropdown[0].style.position = ''; + dropdown[0].style.top = ''; + element.removeClass(directionUpClassName); + } + }); + }; + } + }; + }]); diff --git a/src/uiSelectMultipleDirective.js b/src/uiSelectMultipleDirective.js index 261640105..40ad28eae 100644 --- a/src/uiSelectMultipleDirective.js +++ b/src/uiSelectMultipleDirective.js @@ -175,15 +175,14 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec var key = e.which; scope.$apply(function() { var processed = false; - // var tagged = false; //Checkme if(KEY.isHorizontalMovement(key)){ processed = _handleMatchSelection(key); } if (processed && key != KEY.TAB) { //TODO Check si el tab selecciona aun correctamente //Crear test - e.preventDefault(); - e.stopPropagation(); +// e.preventDefault(); + // e.stopPropagation(); } }); }); @@ -252,147 +251,6 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec return true; } - $select.searchInput.on('keyup', function(e) { - - if ( ! KEY.isVerticalMovement(e.which) ) { - scope.$evalAsync( function () { - $select.activeIndex = $select.taggingLabel === false ? -1 : 0; - }); - } - // Push a "create new" item into array if there is a search string - if ( $select.tagging.isActivated && $select.search.length > 0 ) { - - // return early with these keys - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || KEY.isVerticalMovement(e.which) ) { - return; - } - // always reset the activeIndex to the first item when tagging - $select.activeIndex = $select.taggingLabel === false ? -1 : 0; - // taggingLabel === false bypasses all of this - if ($select.taggingLabel === false) return; - - var items = angular.copy( $select.items ); - var stashArr = angular.copy( $select.items ); - var newItem; - var item; - var hasTag = false; - var dupeIndex = -1; - var tagItems; - var tagItem; - - // case for object tagging via transform `$select.tagging.fct` function - if ( $select.tagging.fct !== undefined) { - tagItems = $select.$filter('filter')(items,{'isTag': true}); - if ( tagItems.length > 0 ) { - tagItem = tagItems[0]; - } - // remove the first element, if it has the `isTag` prop we generate a new one with each keyup, shaving the previous - if ( items.length > 0 && tagItem ) { - hasTag = true; - items = items.slice(1,items.length); - stashArr = stashArr.slice(1,stashArr.length); - } - newItem = $select.tagging.fct($select.search); - newItem.isTag = true; - // verify the the tag doesn't match the value of an existing item - if ( stashArr.filter( function (origItem) { return angular.equals( origItem, $select.tagging.fct($select.search) ); } ).length > 0 ) { - return; - } - newItem.isTag = true; - // handle newItem string and stripping dupes in tagging string context - } else { - // find any tagging items already in the $select.items array and store them - tagItems = $select.$filter('filter')(items,function (item) { - return item.match($select.taggingLabel); - }); - if ( tagItems.length > 0 ) { - tagItem = tagItems[0]; - } - item = items[0]; - // remove existing tag item if found (should only ever be one tag item) - if ( item !== undefined && items.length > 0 && tagItem ) { - hasTag = true; - items = items.slice(1,items.length); - stashArr = stashArr.slice(1,stashArr.length); - } - newItem = $select.search+' '+$select.taggingLabel; - if ( _findApproxDupe($select.selected, $select.search) > -1 ) { - return; - } - // verify the the tag doesn't match the value of an existing item from - // the searched data set or the items already selected - if ( _findCaseInsensitiveDupe(stashArr.concat($select.selected)) ) { - // if there is a tag from prev iteration, strip it / queue the change - // and return early - if ( hasTag ) { - items = stashArr; - scope.$evalAsync( function () { - $select.activeIndex = 0; - $select.items = items; - }); - } - return; - } - if ( _findCaseInsensitiveDupe(stashArr) ) { - // if there is a tag from prev iteration, strip it - if ( hasTag ) { - $select.items = stashArr.slice(1,stashArr.length); - } - return; - } - } - if ( hasTag ) dupeIndex = _findApproxDupe($select.selected, newItem); - // dupe found, shave the first item - if ( dupeIndex > -1 ) { - items = items.slice(dupeIndex+1,items.length-1); - } else { - items = []; - items.push(newItem); - items = items.concat(stashArr); - } - scope.$evalAsync( function () { - $select.activeIndex = 0; - $select.items = items; - }); - } - }); - function _findCaseInsensitiveDupe(arr) { - if ( arr === undefined || $select.search === undefined ) { - return false; - } - var hasDupe = arr.filter( function (origItem) { - if ( $select.search.toUpperCase() === undefined || origItem === undefined ) { - return false; - } - return origItem.toUpperCase() === $select.search.toUpperCase(); - }).length > 0; - - return hasDupe; - } - function _findApproxDupe(haystack, needle) { - var dupeIndex = -1; - if(angular.isArray(haystack)) { - var tempArr = angular.copy(haystack); - for (var i = 0; i Date: Tue, 4 Aug 2015 17:54:12 +0100 Subject: [PATCH 20/28] Refactor --- dist/select.bootstrap.js | 1482 ++++++++++++++++-------------- dist/select.bootstrap.min.js | 4 +- dist/select.css | 14 +- dist/select.js | 1482 ++++++++++++++++-------------- dist/select.min.css | 4 +- dist/select.min.js | 4 +- dist/select.no-tpl.js | 1482 ++++++++++++++++-------------- dist/select.no-tpl.min.js | 4 +- dist/select.select2.js | 1482 ++++++++++++++++-------------- dist/select.select2.min.js | 4 +- dist/select.selectize.js | 1482 ++++++++++++++++-------------- dist/select.selectize.min.js | 4 +- dist/select.tpl.js | 2 +- src/common.css | 12 + src/common.js | 263 ++++-- src/uiSelectChoicesDirective.js | 144 ++- src/uiSelectController.js | 221 +++-- src/uiSelectDirective.js | 13 +- src/uiSelectMatchDirective.js | 56 +- src/uiSelectMultipleDirective.js | 544 ++++++----- src/uiSelectSingleDirective.js | 244 ++--- src/uisRepeatParserService.js | 73 +- 22 files changed, 4936 insertions(+), 4084 deletions(-) diff --git a/dist/select.bootstrap.js b/dist/select.bootstrap.js index 6dacfe976..70e90f742 100644 --- a/dist/select.bootstrap.js +++ b/dist/select.bootstrap.js @@ -1,14 +1,13 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-02T20:56:31.504Z + * Version: 0.12.1 - 2015-08-04T17:24:10.062Z * License: MIT */ (function () { "use strict"; - var KEY = { TAB: 9, ENTER: 13, @@ -29,20 +28,123 @@ var KEY = { DELETE: 46, COMMAND: 91, - MAP: { 91 : "COMMAND", 8 : "BACKSPACE" , 9 : "TAB" , 13 : "ENTER" , 16 : "SHIFT" , 17 : "CTRL" , 18 : "ALT" , 19 : "PAUSEBREAK" , 20 : "CAPSLOCK" , 27 : "ESC" , 32 : "SPACE" , 33 : "PAGE_UP", 34 : "PAGE_DOWN" , 35 : "END" , 36 : "HOME" , 37 : "LEFT" , 38 : "UP" , 39 : "RIGHT" , 40 : "DOWN" , 43 : "+" , 44 : "PRINTSCREEN" , 45 : "INSERT" , 46 : "DELETE", 48 : "0" , 49 : "1" , 50 : "2" , 51 : "3" , 52 : "4" , 53 : "5" , 54 : "6" , 55 : "7" , 56 : "8" , 57 : "9" , 59 : ";", 61 : "=" , 65 : "A" , 66 : "B" , 67 : "C" , 68 : "D" , 69 : "E" , 70 : "F" , 71 : "G" , 72 : "H" , 73 : "I" , 74 : "J" , 75 : "K" , 76 : "L", 77 : "M" , 78 : "N" , 79 : "O" , 80 : "P" , 81 : "Q" , 82 : "R" , 83 : "S" , 84 : "T" , 85 : "U" , 86 : "V" , 87 : "W" , 88 : "X" , 89 : "Y" , 90 : "Z", 96 : "0" , 97 : "1" , 98 : "2" , 99 : "3" , 100 : "4" , 101 : "5" , 102 : "6" , 103 : "7" , 104 : "8" , 105 : "9", 106 : "*" , 107 : "+" , 109 : "-" , 110 : "." , 111 : "/", 112 : "F1" , 113 : "F2" , 114 : "F3" , 115 : "F4" , 116 : "F5" , 117 : "F6" , 118 : "F7" , 119 : "F8" , 120 : "F9" , 121 : "F10" , 122 : "F11" , 123 : "F12", 144 : "NUMLOCK" , 145 : "SCROLLLOCK" , 186 : ";" , 187 : "=" , 188 : "," , 189 : "-" , 190 : "." , 191 : "/" , 192 : "`" , 219 : "[" , 220 : "\\" , 221 : "]" , 222 : "'" + MAP: { + 91: "COMMAND", + 8: "BACKSPACE", + 9: "TAB", + 13: "ENTER", + 16: "SHIFT", + 17: "CTRL", + 18: "ALT", + 19: "PAUSEBREAK", + 20: "CAPSLOCK", + 27: "ESC", + 32: "SPACE", + 33: "PAGE_UP", + 34: "PAGE_DOWN", + 35: "END", + 36: "HOME", + 37: "LEFT", + 38: "UP", + 39: "RIGHT", + 40: "DOWN", + 43: "+", + 44: "PRINTSCREEN", + 45: "INSERT", + 46: "DELETE", + 48: "0", + 49: "1", + 50: "2", + 51: "3", + 52: "4", + 53: "5", + 54: "6", + 55: "7", + 56: "8", + 57: "9", + 59: ";", + 61: "=", + 65: "A", + 66: "B", + 67: "C", + 68: "D", + 69: "E", + 70: "F", + 71: "G", + 72: "H", + 73: "I", + 74: "J", + 75: "K", + 76: "L", + 77: "M", + 78: "N", + 79: "O", + 80: "P", + 81: "Q", + 82: "R", + 83: "S", + 84: "T", + 85: "U", + 86: "V", + 87: "W", + 88: "X", + 89: "Y", + 90: "Z", + 96: "0", + 97: "1", + 98: "2", + 99: "3", + 100: "4", + 101: "5", + 102: "6", + 103: "7", + 104: "8", + 105: "9", + 106: "*", + 107: "+", + 109: "-", + 110: ".", + 111: "/", + 112: "F1", + 113: "F2", + 114: "F3", + 115: "F4", + 116: "F5", + 117: "F6", + 118: "F7", + 119: "F8", + 120: "F9", + 121: "F10", + 122: "F11", + 123: "F12", + 144: "NUMLOCK", + 145: "SCROLLLOCK", + 186: ";", + 187: "=", + 188: ",", + 189: "-", + 190: ".", + 191: "/", + 192: "`", + 219: "[", + 220: "\\", + 221: "]", + 222: "'" }, isControl: function (e) { var k = e.which; switch (k) { - case KEY.COMMAND: - case KEY.SHIFT: - case KEY.CTRL: - case KEY.ALT: - return true; + case KEY.COMMAND: + case KEY.SHIFT: + case KEY.CTRL: + case KEY.ALT: + return true; } - if (e.metaKey) return true; + if (e.metaKey) { + return true; + } return false; }, @@ -50,13 +152,13 @@ var KEY = { k = k.which ? k.which : k; return k >= 112 && k <= 123; }, - isVerticalMovement: function (k){ - return ~[KEY.UP, KEY.DOWN].indexOf(k); + isVerticalMovement: function (k) { + return ~[KEY.UP, KEY.DOWN].indexOf(k); }, - isHorizontalMovement: function (k){ - return ~[KEY.LEFT,KEY.RIGHT,KEY.BACKSPACE,KEY.DELETE].indexOf(k); + isHorizontalMovement: function (k) { + return ~[KEY.LEFT, KEY.RIGHT, KEY.BACKSPACE, KEY.DELETE].indexOf(k); } - }; +}; /** * Add querySelectorAll() to jqLite. @@ -68,67 +170,67 @@ var KEY = { * See feat(jqLite): use querySelectorAll instead of getElementsByTagName in jqLite.find https://github.com/angular/angular.js/pull/3598 */ if (angular.element.prototype.querySelectorAll === undefined) { - angular.element.prototype.querySelectorAll = function(selector) { - return angular.element(this[0].querySelectorAll(selector)); - }; + angular.element.prototype.querySelectorAll = function (selector) { + return angular.element(this[0].querySelectorAll(selector)); + }; } /** * Add closest() to jqLite. */ if (angular.element.prototype.closest === undefined) { - angular.element.prototype.closest = function( selector) { - var elem = this[0]; - var matchesSelector = elem.matches || elem.webkitMatchesSelector || elem.mozMatchesSelector || elem.msMatchesSelector; - - while (elem) { - if (matchesSelector.bind(elem)(selector)) { - return elem; - } else { - elem = elem.parentElement; - } - } - return false; - }; + angular.element.prototype.closest = function (selector) { + var elem = this[0]; + var matchesSelector = elem.matches || elem.webkitMatchesSelector || elem.mozMatchesSelector || + elem.msMatchesSelector; + + while (elem) { + if (matchesSelector.bind(elem)(selector)) { + return elem; + } else { + elem = elem.parentElement; + } + } + return false; + }; } var latestId = 0; var uis = angular.module('ui.select', []) -.constant('uiSelectConfig', { - theme: 'bootstrap', - searchEnabled: true, - sortable: false, - placeholder: '', // Empty by default, like HTML tag + closeOnSelect: true, + generateId: function () { + return latestId++; + }, + appendToBody: false + }) // See Rename minErr and make it accessible from outside https://github.com/angular/angular.js/issues/6913 -.service('uiSelectMinErr', function() { - var minErr = angular.$$minErr('ui.select'); - return function() { - var error = minErr.apply(this, arguments); - var message = error.message.replace(new RegExp('\nhttp://errors.angularjs.org/.*'), ''); - return new Error(message); - }; -}) + .service('uiSelectMinErr', function () { + var minErr = angular.$$minErr('ui.select'); + return function () { + var error = minErr.apply(this, arguments); + var message = error.message.replace(new RegExp('\nhttp://errors.angularjs.org/.*'), ''); + return new Error(message); + }; + }) // Recreates old behavior of ng-transclude. Used internally. -.directive('uisTranscludeAppend', function () { - return { - link: function (scope, element, attrs, ctrl, transclude) { - transclude(scope, function (clone) { - element.append(clone); - }); - } - }; -}) + .directive('uisTranscludeAppend', function () { + return { + link: function (scope, element, attrs, ctrl, transclude) { + transclude(scope, function (clone) { + element.append(clone); + }); + } + }; + }) /** * Highlights text that matches $select.search. @@ -136,15 +238,16 @@ var uis = angular.module('ui.select', []) * Taken from AngularUI Bootstrap Typeahead * See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L340 */ -.filter('highlight', function() { - function escapeRegexp(queryToEscape) { - return queryToEscape.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1'); - } + .filter('highlight', function () { + function escapeRegexp(queryToEscape) { + return queryToEscape.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1'); + } - return function(matchItem, query) { - return query && matchItem ? matchItem.replace(new RegExp(escapeRegexp(query), 'gi'), '$&') : matchItem; - }; -}) + return function (matchItem, query) { + return query && matchItem ? matchItem.replace(new RegExp(escapeRegexp(query), 'gi'), + '$&') : matchItem; + }; + }) /** * A read-only equivalent of jQuery's offset function: http://api.jquery.com/offset/ @@ -152,96 +255,92 @@ var uis = angular.module('ui.select', []) * Taken from AngularUI Bootstrap Position: * See https://github.com/angular-ui/bootstrap/blob/master/src/position/position.js#L70 */ -.factory('uisOffset', - ['$document', '$window', - function ($document, $window) { - - return function(element) { - var boundingClientRect = element[0].getBoundingClientRect(); - return { - width: boundingClientRect.width || element.prop('offsetWidth'), - height: boundingClientRect.height || element.prop('offsetHeight'), - top: boundingClientRect.top + ($window.pageYOffset || $document[0].documentElement.scrollTop), - left: boundingClientRect.left + ($window.pageXOffset || $document[0].documentElement.scrollLeft) - }; - }; -}]); + .factory('uisOffset', + ['$document', '$window', + function ($document, $window) { + + return function (element) { + var boundingClientRect = element[0].getBoundingClientRect(); + return { + width: boundingClientRect.width || element.prop('offsetWidth'), + height: boundingClientRect.height || element.prop('offsetHeight'), + top: boundingClientRect.top + ($window.pageYOffset || $document[0].documentElement.scrollTop), + left: boundingClientRect.left + ($window.pageXOffset || $document[0].documentElement.scrollLeft) + }; + }; + }]); uis.directive('uiSelectChoices', - ['uiSelectConfig', 'uisRepeatParser', 'uiSelectMinErr', '$compile', - function(uiSelectConfig, RepeatParser, uiSelectMinErr, $compile) { - - return { - restrict: 'EA', - require: '^uiSelect', - replace: true, - transclude: true, - templateUrl: function(tElement) { - // Gets theme attribute from parent (ui-select) - var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; - return theme + '/choices.tpl.html'; - }, + ['uiSelectConfig', 'uisRepeatParser', 'uiSelectMinErr', '$compile', + function (uiSelectConfig, RepeatParser, uiSelectMinErr, $compile) { - compile: function(tElement, tAttrs) { + return { + restrict: 'EA', + require: '^uiSelect', + replace: true, + transclude: true, + templateUrl: function (tElement) { + // Gets theme attribute from parent (ui-select) + var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; + return theme + '/choices.tpl.html'; + }, - if (!tAttrs.repeat) throw uiSelectMinErr('repeat', "Expected 'repeat' expression."); + compile: function (tElement, tAttrs) { - return function link(scope, element, attrs, $select, transcludeFn) { + if (!tAttrs.repeat) { + throw uiSelectMinErr('repeat', "Expected 'repeat' expression."); + } - // var repeat = RepeatParser.parse(attrs.repeat); - var groupByExp = attrs.groupBy; - var groupFilterExp = attrs.groupFilter; + return function link(scope, element, attrs, $select, transcludeFn) { - $select.parseRepeatAttr(attrs.repeat, groupByExp, groupFilterExp); //Result ready at $select.parserResult + // var repeat = RepeatParser.parse(attrs.repeat); + var groupByExp = attrs.groupBy; + var groupFilterExp = attrs.groupFilter; - $select.disableChoiceExpression = attrs.uiDisableChoice; - $select.onHighlightCallback = attrs.onHighlight; + $select.parseRepeatAttr(attrs.repeat, groupByExp, groupFilterExp); //Result ready at $select.parserResult - $select.refreshOnActive = scope.$eval(attrs.refreshOnActive); + $select.disableChoiceExpression = attrs.uiDisableChoice; + $select.onHighlightCallback = attrs.onHighlight; - if(groupByExp) { - var groups = element.querySelectorAll('.ui-select-choices-group'); - if (groups.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-group but got '{0}'.", groups.length); - groups.attr('ng-repeat', RepeatParser.getGroupNgRepeatExpression()); - } + if (groupByExp) { + var groups = element.querySelectorAll('.ui-select-choices-group'); + if (groups.length !== 1) throw uiSelectMinErr('rows', + "Expected 1 .ui-select-choices-group but got '{0}'.", groups.length); + groups.attr('ng-repeat', RepeatParser.getGroupNgRepeatExpression()); + } - var choices = element.querySelectorAll('.ui-select-choices-row'); - if (choices.length !== 1) { - throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row but got '{0}'.", choices.length); - } + var choices = element.querySelectorAll('.ui-select-choices-row'); + if (choices.length !== 1) { + throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row but got '{0}'.", + choices.length); + } - choices.attr('ng-repeat', RepeatParser.getNgRepeatExpression($select.parserResult.itemName, '$select.items', $select.parserResult.trackByExp, groupByExp)) - .attr('ng-if', '$select.open') //Prevent unnecessary watches when dropdown is closed - .attr('ng-mouseenter', '$select.setActiveItem('+$select.parserResult.itemName +')') - .attr('ng-click', '$select.select(' + $select.parserResult.itemName + ',false,$event)'); - - var rowsInner = element.querySelectorAll('.ui-select-choices-row-inner'); - if (rowsInner.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row-inner but got '{0}'.", rowsInner.length); - rowsInner.attr('uis-transclude-append', ''); //Adding uisTranscludeAppend directive to row element after choices element has ngRepeat - - $compile(element, transcludeFn)(scope); //Passing current transcludeFn to be able to append elements correctly from uisTranscludeAppend - - scope.$watch('$select.search', function(newValue) { - if(newValue && !$select.open && $select.multiple) $select.activate(false, true); - $select.activeIndex = 0; - if(!$select.refreshOnActive || ($select.refreshOnActive && $select.refreshIsActive)) { - $select.refresh(attrs.refresh); - } - }); - - scope.$watch('$select.refreshIsActive', function(newValue, oldValue){ - if(angular.isUndefined(oldValue) && newValue){ - $select.refresh(attrs.refresh); - } - }); - - // $eval() is needed otherwise we get a string instead of a number - var refreshDelay = scope.$eval(attrs.refreshDelay); - $select.refreshDelay = refreshDelay !== undefined ? refreshDelay : uiSelectConfig.refreshDelay; - }; - } - }; -}]); + choices.attr('ng-repeat', + RepeatParser.getNgRepeatExpression($select.parserResult.itemName, '$select.items', + $select.parserResult.trackByExp, groupByExp)) + .attr('ng-if', '$select.open') //Prevent unnecessary watches when dropdown is closed + .attr('ng-mouseenter', '$select.setActiveItem(' + $select.parserResult.itemName + ')') + .attr('ng-click', '$select.select(' + $select.parserResult.itemName + ',false,$event)'); + + var rowsInner = element.querySelectorAll('.ui-select-choices-row-inner'); + if (rowsInner.length !== 1) { + throw uiSelectMinErr('rows', + "Expected 1 .ui-select-choices-row-inner but got '{0}'.", rowsInner.length); + } + rowsInner.attr('uis-transclude-append', ''); //Adding uisTranscludeAppend directive to row element after choices element has ngRepeat + + $compile(element, transcludeFn)(scope); //Passing current transcludeFn to be able to append elements correctly from uisTranscludeAppend + + scope.$watch('$select.search', function (newValue) { + if (newValue && !$select.open && $select.multiple) { + $select.activate(false, true); + } + $select.activeIndex = 0; + }); + }; + } + }; + }]); /** * Contains ui-select "intelligence". @@ -260,7 +359,6 @@ uis.controller('uiSelectCtrl', ctrl.placeholder = uiSelectConfig.placeholder; ctrl.searchEnabled = uiSelectConfig.searchEnabled; ctrl.sortable = uiSelectConfig.sortable; - ctrl.refreshDelay = uiSelectConfig.refreshDelay; ctrl.removeSelected = false; //If selected item(s) should be removed from dropdown list ctrl.closeOnSelect = true; //Initialized inside uiSelect directive link function @@ -281,8 +379,6 @@ uis.controller('uiSelectCtrl', ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelectMatch directive link function ctrl.clickTriggeredSelect = false; ctrl.$filter = $filter; - ctrl.refreshOnActive = undefined; - ctrl.refreshIsActive = undefined; ctrl.searchInput = $element.querySelectorAll('input.ui-select-search'); if (ctrl.searchInput.length !== 1) { @@ -290,6 +386,10 @@ uis.controller('uiSelectCtrl', ctrl.searchInput.length); } + /** + * Returns true if the selection is empty + * @returns {boolean|*} + */ ctrl.isEmpty = function () { return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === ''; }; @@ -305,6 +405,12 @@ uis.controller('uiSelectCtrl', } } + ctrl.findGroupByName = function (name) { + return ctrl.groups && ctrl.groups.filter(function (group) { + return group.name === name; + })[0]; + }; + function _groupsFilter(groups, groupNames) { var i, j, result = []; for (i = 0; i < groupNames.length; i++) { @@ -317,10 +423,15 @@ uis.controller('uiSelectCtrl', return result; } - // When the user clicks on ui-select, displays the dropdown list + /** + * Activates the control. + * When the user clicks on ui-select, displays the dropdown list + */ ctrl.activate = function (initSearchValue, avoidReset) { if (!ctrl.disabled && !ctrl.open) { - if (!avoidReset) _resetSearchInput(); + if (!avoidReset) { + _resetSearchInput(); + } $scope.$broadcast('uis:activate'); @@ -330,7 +441,6 @@ uis.controller('uiSelectCtrl', } ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex; - ctrl.refreshIsActive = true; // Give it time to appear before focus $timeout(function () { @@ -344,12 +454,6 @@ uis.controller('uiSelectCtrl', } }; - ctrl.findGroupByName = function (name) { - return ctrl.groups && ctrl.groups.filter(function (group) { - return group.name === name; - })[0]; - }; - ctrl.parseRepeatAttr = function (repeatAttr, groupByExp, groupFilterExp) { function updateGroups(items) { var groupFn = $scope.$eval(groupByExp); @@ -382,6 +486,7 @@ uis.controller('uiSelectCtrl', ctrl.items = items; } + // Set the function to use when displaying items - either groups or single ctrl.setItemsFn = groupByExp ? updateGroups : setPlainItems; ctrl.parserResult = RepeatParser.parse(repeatAttr); @@ -392,7 +497,7 @@ uis.controller('uiSelectCtrl', ctrl.refreshItems = function (data) { data = data || ctrl.parserResult.source($scope); var selectedItems = ctrl.selected; - //TODO should implement for single mode removeSelected + // TODO should implement for single mode removeSelected if (ctrl.isEmpty() || (angular.isArray(selectedItems) && !selectedItems.length) || !ctrl.removeSelected) { ctrl.setItemsFn(data); @@ -424,35 +529,17 @@ uis.controller('uiSelectCtrl', } } }); - - }; - - var _refreshDelayPromise; - - /** - * Typeahead mode: lets the user refresh the collection using his own function. - * - * See Expose $select.search for external / remote filtering https://github.com/angular-ui/ui-select/pull/31 - */ - ctrl.refresh = function (refreshAttr) { - if (refreshAttr !== undefined) { - - // Debounce - // See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L155 - // FYI AngularStrap typeahead does not have debouncing: https://github.com/mgcrea/angular-strap/blob/v2.0.0-rc.4/src/typeahead/typeahead.js#L177 - if (_refreshDelayPromise) { - $timeout.cancel(_refreshDelayPromise); - } - _refreshDelayPromise = $timeout(function () { - $scope.$eval(refreshAttr); - }, ctrl.refreshDelay); - } }; ctrl.setActiveItem = function (item) { ctrl.activeIndex = ctrl.items.indexOf(item); }; + /** + * Checks if the item is active + * @param itemScope the item + * @returns {boolean} true if active + */ ctrl.isActive = function (itemScope) { if (!ctrl.open) { return false; @@ -469,11 +556,14 @@ uis.controller('uiSelectCtrl', /** * Checks if the item is disabled - * @return boolean true if the item is disabled + * @param itemScope the item + * @return {boolean} true if the item is disabled */ ctrl.isDisabled = function (itemScope) { - if (!ctrl.open) return false; + if (!ctrl.open) { + return false; + } var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); var isDisabled = false; @@ -490,75 +580,81 @@ uis.controller('uiSelectCtrl', /** + * Selects an item + * * Called when the user selects an item with ENTER or clicks the dropdown */ ctrl.select = function (item, skipFocusser, $event) { - if (item === undefined || !item._uiSelectChoiceDisabled) { - - if (!ctrl.items && !ctrl.search){ - return; - } - - if (!item || !item._uiSelectChoiceDisabled) { + if (item !== undefined && item._uiSelectChoiceDisabled) { + return; + } - var completeSelection = function () { - $scope.$broadcast('uis:select', item); + // If no items in the list, and no search, then return + if (!ctrl.items && !ctrl.search) { + return; + } - $timeout(function () { - ctrl.onSelectCallback($scope, callbackContext); - }); + // Create the data used to pass to the callbacks + var locals = {}; + locals[ctrl.parserResult.itemName] = item; + var callbackContext = { + $item: item, + $model: ctrl.parserResult.modelMapper($scope, locals) + }; - if (ctrl.closeOnSelect) { - ctrl.close(skipFocusser); - } - if ($event && $event.type === 'click') { - ctrl.clickTriggeredSelect = true; - } - }; + // Local method called when we complete the select + // eg. called after the onselect callback + var completeSelection = function () { + $scope.$broadcast('uis:select', item); - var locals = {}; - locals[ctrl.parserResult.itemName] = item; + $timeout(function () { + ctrl.onSelectCallback($scope, callbackContext); + }); - var callbackContext = { - $item: item, - $model: ctrl.parserResult.modelMapper($scope, locals) - }; + if (ctrl.closeOnSelect) { + ctrl.close(skipFocusser); + } + if ($event && $event.type === 'click') { + ctrl.clickTriggeredSelect = true; + } + }; - // Call the onBeforeSelect callback - // Allowable responses are -: - // falsy: Abort the selection - // promise: Wait for response - // true: Complete selection - // object: Add the returned object - var onBeforeSelectResult = ctrl.onBeforeSelectCallback($scope, callbackContext); - if (angular.isDefined(onBeforeSelectResult)) { - if (!onBeforeSelectResult) { - return; // abort the selection in case of deliberate falsey result - } else if (angular.isFunction(onBeforeSelectResult.then)) { - onBeforeSelectResult.then(function (result) { - if (!result) { - return; - } - completeSelection(result); - }); - } else if (onBeforeSelectResult === true) { - completeSelection(item); - } else { - completeSelection(onBeforeSelectResult); + // Call the onBeforeSelect callback + // Allowable responses are -: + // falsy: Abort the selection + // promise: Wait for response + // true: Complete selection + // object: Add the returned object + var onBeforeSelectResult = ctrl.onBeforeSelectCallback($scope, callbackContext); + if (angular.isDefined(onBeforeSelectResult)) { + if (angular.isFunction(onBeforeSelectResult.then)) { + // Promise returned - wait for it to complete before completing the selection + onBeforeSelectResult.then(function (result) { + if (!result) { + return; } - } else { - completeSelection(item); - } + completeSelection(result); + }); + } else if (onBeforeSelectResult === true) { + completeSelection(item); + } else if (onBeforeSelectResult) { + completeSelection(onBeforeSelectResult); } + } else { + completeSelection(item); } }; - // Closes the dropdown + /** + * Close the dropdown + */ ctrl.close = function (skipFocusser) { if (!ctrl.open) { return; } - if (ctrl.ngModel && ctrl.ngModel.$setTouched) ctrl.ngModel.$setTouched(); + if (ctrl.ngModel && ctrl.ngModel.$setTouched) { + ctrl.ngModel.$setTouched(); + } _resetSearchInput(); ctrl.open = false; if (!ctrl.searchEnabled) { @@ -568,12 +664,19 @@ uis.controller('uiSelectCtrl', $scope.$broadcast('uis:close', skipFocusser); }; + /** + * Set focus on the control + */ ctrl.setFocus = function () { if (!ctrl.focus) { ctrl.focusInput[0].focus(); } }; + /** + * Clears the selection + * @param $event + */ ctrl.clear = function ($event) { ctrl.select(undefined); $event.stopPropagation(); @@ -582,7 +685,9 @@ uis.controller('uiSelectCtrl', }, 0, false); }; - // Toggle dropdown + /** + * Toggle the dropdown open and closed + */ ctrl.toggle = function (e) { if (ctrl.open) { ctrl.close(); @@ -606,7 +711,6 @@ uis.controller('uiSelectCtrl', var sizeWatch = null; ctrl.sizeSearchInput = function () { - var input = ctrl.searchInput[0], container = ctrl.searchInput.parent().parent()[0], calculateContainerWidth = function () { @@ -659,7 +763,9 @@ uis.controller('uiSelectCtrl', } break; case KEY.TAB: - if (!ctrl.multiple || ctrl.open) ctrl.select(ctrl.items[ctrl.activeIndex], true); + if (!ctrl.multiple || ctrl.open) { + ctrl.select(ctrl.items[ctrl.activeIndex], true); + } break; case KEY.ENTER: if (ctrl.open) { @@ -703,24 +809,6 @@ uis.controller('uiSelectCtrl', } }); - // If tagging try to split by tokens and add items - /* ctrl.searchInput.on('paste', function (e) { - var data = e.originalEvent.clipboardData.getData('text/plain'); - if (data && data.length > 0 && ctrl.taggingTokens.isActivated && ctrl.tagging.fct) { - var items = data.split(ctrl.taggingTokens.tokens[0]); // split by first token only - if (items && items.length > 0) { - angular.forEach(items, function (item) { - var newItem = ctrl.tagging.fct(item); - if (newItem) { - ctrl.select(newItem, true); - } - }); - e.preventDefault(); - e.stopPropagation(); - } - } - });*/ - ctrl.searchInput.on('keyup', function (e) { // return early with these keys if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || @@ -734,7 +822,6 @@ uis.controller('uiSelectCtrl', ctrl.onKeypressCallback($scope, {event: e}); }); - // See https://github.com/ivaynberg/select2/blob/3.4.6/select2.js#L1431 function _ensureHighlightVisible() { var container = $element.querySelectorAll('.ui-select-choices-content'); @@ -755,10 +842,13 @@ uis.controller('uiSelectCtrl', if (posY > height) { container[0].scrollTop += posY - height; } else if (posY < highlighted.clientHeight) { - if (ctrl.isGrouped && ctrl.activeIndex === 0) - container[0].scrollTop = 0; //To make group header visible when going all the way up - else + if (ctrl.isGrouped && ctrl.activeIndex === 0) { + //To make group header visible when going all the way up + container[0].scrollTop = 0; + } + else { container[0].scrollTop -= highlighted.clientHeight - posY; + } } } @@ -811,9 +901,10 @@ uis.directive('uiSelect', } }(); - $select.onBeforeSelectCallback = $parse(attrs.onBeforeSelect); $select.onSelectCallback = $parse(attrs.onSelect); + $select.onBeforeSelectCallback = $parse(attrs.onBeforeSelect); $select.onRemoveCallback = $parse(attrs.onRemove); + $select.onBeforeRemoveCallback = $parse(attrs.onBeforeRemove); $select.onKeypressCallback = $parse(attrs.onKeypress); //Limit the number of selections allowed @@ -845,11 +936,6 @@ uis.directive('uiSelect', $select.disabled = attrs.disabled !== undefined ? attrs.disabled : false; }); - attrs.$observe('resetSearchInput', function () { - // $eval() is needed otherwise we get a string instead of a boolean - var resetSearchInput = scope.$eval(attrs.resetSearchInput); - $select.resetSearchInput = resetSearchInput !== undefined ? resetSearchInput : true; - }); //Automatically gets focus when loaded if (angular.isDefined(attrs.autofocus)) { @@ -1001,6 +1087,7 @@ uis.directive('uiSelect', // Support changing the direction of the dropdown if there isn't enough space to render it. scope.$watch('$select.open', function (isOpen) { if (isOpen) { + // Get the dropdown element dropdown = angular.element(element).querySelectorAll('.ui-select-dropdown'); if (dropdown === null) { return; @@ -1018,8 +1105,6 @@ uis.directive('uiSelect', if (offset.top + offset.height + offsetDropdown.height > $document[0].documentElement.scrollTop + $document[0].documentElement.clientHeight) { - dropdown[0].style.position = 'absolute'; - dropdown[0].style.top = (offsetDropdown.height * -1) + 'px'; element.addClass(directionUpClassName); } @@ -1032,8 +1117,6 @@ uis.directive('uiSelect', } // Reset the position of the dropdown. - dropdown[0].style.position = ''; - dropdown[0].style.top = ''; element.removeClass(directionUpClassName); } }); @@ -1042,425 +1125,479 @@ uis.directive('uiSelect', }; }]); -uis.directive('uiSelectMatch', ['uiSelectConfig', function(uiSelectConfig) { - return { - restrict: 'EA', - require: '^uiSelect', - replace: true, - transclude: true, - templateUrl: function(tElement) { - // Gets theme attribute from parent (ui-select) - var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; - var multi = tElement.parent().attr('multiple'); - return theme + (multi ? '/match-multiple.tpl.html' : '/match.tpl.html'); - }, - link: function(scope, element, attrs, $select) { - $select.lockChoiceExpression = attrs.uiLockChoice; - attrs.$observe('placeholder', function(placeholder) { - $select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder; - }); - - function setAllowClear(allow) { - $select.allowClear = (angular.isDefined(allow)) ? (allow === '') ? true : (allow.toLowerCase() === 'true') : false; - } +uis.directive('uiSelectMatch', ['uiSelectConfig', function (uiSelectConfig) { + return { + restrict: 'EA', + require: '^uiSelect', + replace: true, + transclude: true, + templateUrl: function (tElement) { + // Gets theme attribute from parent (ui-select) + var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; + var multi = tElement.parent().attr('multiple'); + return theme + (multi ? '/match-multiple.tpl.html' : '/match.tpl.html'); + }, + link: function (scope, element, attrs, $select) { + $select.lockChoiceExpression = attrs.uiLockChoice; + attrs.$observe('placeholder', function (placeholder) { + $select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder; + }); - attrs.$observe('allowClear', setAllowClear); - setAllowClear(attrs.allowClear); + function setAllowClear(allow) { + $select.allowClear = + (angular.isDefined(allow)) ? (allow === '') ? true : (allow.toLowerCase() === 'true') : false; + } - if($select.multiple){ - $select.sizeSearchInput(); - } + attrs.$observe('allowClear', setAllowClear); + setAllowClear(attrs.allowClear); - } - }; + if ($select.multiple) { + $select.sizeSearchInput(); + } + } + }; }]); -uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelectMinErr, $timeout) { - return { - restrict: 'EA', - require: ['^uiSelect', '^ngModel'], +uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSelectMinErr, $timeout) { + return { + restrict: 'EA', + require: ['^uiSelect', '^ngModel'], + controller: ['$scope', '$timeout', function ($scope, $timeout) { + var ctrl = this, + $select = $scope.$select, + ngModel; + + //Wait for link fn to inject it + $scope.$evalAsync(function () { + ngModel = $scope.ngModel; + }); + + ctrl.activeMatchIndex = -1; - controller: ['$scope','$timeout', function($scope, $timeout){ + ctrl.updateModel = function () { + ngModel.$setViewValue(Date.now()); //Set timestamp as a unique string to force changes + ctrl.refreshComponent(); + }; - var ctrl = this, - $select = $scope.$select, - ngModel; + ctrl.refreshComponent = function () { + // Remove already selected items + // e.g. When user clicks on a selection, the selected array changes and + // the dropdown should remove that item + $select.refreshItems(); + $select.sizeSearchInput(); + }; - //Wait for link fn to inject it - $scope.$evalAsync(function(){ ngModel = $scope.ngModel; }); + // Remove item from multiple select + ctrl.removeChoice = function (index) { + var removedChoice = $select.selected[index]; - ctrl.activeMatchIndex = -1; + // if the choice is locked, can't remove it + if (removedChoice._uiSelectChoiceLocked) { + return; + } - ctrl.updateModel = function(){ - ngModel.$setViewValue(Date.now()); //Set timestamp as a unique string to force changes - ctrl.refreshComponent(); - }; + var locals = {}; + locals[$select.parserResult.itemName] = removedChoice; - ctrl.refreshComponent = function(){ - //Remove already selected items - //e.g. When user clicks on a selection, the selected array changes and - //the dropdown should remove that item - $select.refreshItems(); - $select.sizeSearchInput(); - }; + $select.selected.splice(index, 1); + ctrl.activeMatchIndex = -1; + $select.sizeSearchInput(); - // Remove item from multiple select - ctrl.removeChoice = function(index){ + var callbackContext = { + $item: removedChoice, + $model: $select.parserResult.modelMapper($scope, locals) + }; - var removedChoice = $select.selected[index]; + // Give some time for scope propagation. + function completeRemoval() { + $timeout(function () { + $select.onRemoveCallback($scope, callbackContext); + }); - // if the choice is locked, can't remove it - if(removedChoice._uiSelectChoiceLocked) return; + ctrl.updateModel(); + } - var locals = {}; - locals[$select.parserResult.itemName] = removedChoice; + // Call the onBeforeRemove callback + // Allowable responses are -: + // falsy: Abort the removal + // promise: Wait for response + // true: Complete removal + var onBeforeRemoveResult = ctrl.onBeforeRemoveCallback($scope, callbackContext); + if (angular.isDefined(onBeforeRemoveResult)) { + if (angular.isFunction(onBeforeRemoveResult.then)) { + // Promise returned - wait for it to complete before completing the selection + onBeforeRemoveResult.then(function (result) { + if (!result) { + return; + } + completeRemoval(result); + }); + } else if (onBeforeRemoveResult === true) { + completeRemoval(); + } + } else { + completeRemoval(); + } + }; - $select.selected.splice(index, 1); - ctrl.activeMatchIndex = -1; - $select.sizeSearchInput(); + ctrl.getPlaceholder = function () { + //Refactor single? + if ($select.selected && $select.selected.length) { + return; + } + return $select.placeholder; + }; + }], + controllerAs: '$selectMultiple', + + link: function (scope, element, attrs, ctrls) { + var $select = ctrls[0]; + var ngModel = scope.ngModel = ctrls[1]; + var $selectMultiple = scope.$selectMultiple; + + //$select.selected = raw selected objects (ignoring any property binding) + + $select.multiple = true; + $select.removeSelected = true; + + //Input that will handle focus + $select.focusInput = $select.searchInput; + + //From view --> model + ngModel.$parsers.unshift(function () { + var locals = {}, + result, + resultMultiple = []; + for (var j = $select.selected.length - 1; j >= 0; j--) { + locals = {}; + locals[$select.parserResult.itemName] = $select.selected[j]; + result = $select.parserResult.modelMapper(scope, locals); + resultMultiple.unshift(result); + } + return resultMultiple; + }); - // Give some time for scope propagation. - $timeout(function(){ - $select.onRemoveCallback($scope, { - $item: removedChoice, - $model: $select.parserResult.modelMapper($scope, locals) - }); - }); + // From model --> view + ngModel.$formatters.unshift(function (inputValue) { + var data = $select.parserResult.source(scope, {$select: {search: ''}}), //Overwrite $search + locals = {}, + result; + if (!data) { + return inputValue; + } + var resultMultiple = []; + var checkFnMultiple = function (list, value) { + if (!list || !list.length) { + return; + } + for (var p = list.length - 1; p >= 0; p--) { + locals[$select.parserResult.itemName] = list[p]; + result = $select.parserResult.modelMapper(scope, locals); + if ($select.parserResult.trackByExp) { + var matches = /\.(.+)/.exec($select.parserResult.trackByExp); + if (matches.length > 0 && result[matches[1]] == value[matches[1]]) { + resultMultiple.unshift(list[p]); + return true; + } + } + if (angular.equals(result, value)) { + resultMultiple.unshift(list[p]); + return true; + } + } + return false; + }; + if (!inputValue) return resultMultiple; //If ngModel was undefined + for (var k = inputValue.length - 1; k >= 0; k--) { + //Check model array of currently selected items + if (!checkFnMultiple($select.selected, inputValue[k])) { + //Check model array of all items available + if (!checkFnMultiple(data, inputValue[k])) { + //If not found on previous lists, just add it directly to resultMultiple + resultMultiple.unshift(inputValue[k]); + } + } + } + return resultMultiple; + }); - ctrl.updateModel(); + //Watch for external model changes + scope.$watchCollection(function () { + return ngModel.$modelValue; + }, function (newValue, oldValue) { + if (oldValue != newValue) { + ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters + $selectMultiple.refreshComponent(); + } + }); - }; + ngModel.$render = function () { + // Make sure that model value is array + if (!angular.isArray(ngModel.$viewValue)) { + // Have tolerance for null or undefined values + if (angular.isUndefined(ngModel.$viewValue) || ngModel.$viewValue === null) { + $select.selected = []; + } else { + throw uiSelectMinErr('multiarr', "Expected model value to be array but got '{0}'", + ngModel.$viewValue); + } + } + $select.selected = ngModel.$viewValue; + scope.$evalAsync(); //To force $digest + }; - ctrl.getPlaceholder = function(){ - //Refactor single? - if($select.selected && $select.selected.length) return; - return $select.placeholder; - }; + scope.$on('uis:select', function (event, item) { + if ($select.selected.length >= $select.limit) { + return; + } + $select.selected.push(item); + $selectMultiple.updateModel(); + }); + scope.$on('uis:activate', function () { + $selectMultiple.activeMatchIndex = -1; + }); - }], - controllerAs: '$selectMultiple', + scope.$watch('$select.disabled', function (newValue, oldValue) { + // As the search input field may now become visible, it may be necessary to recompute its size + if (oldValue && !newValue) { + $select.sizeSearchInput(); + } + }); - link: function(scope, element, attrs, ctrls) { + $select.searchInput.on('keydown', function (e) { + var key = e.which; + scope.$apply(function () { + var processed = false; + if (KEY.isHorizontalMovement(key)) { + processed = _handleMatchSelection(key); + } + if (processed && key != KEY.TAB) { + //TODO Check si el tab selecciona aun correctamente + //Crear test +// e.preventDefault(); + // e.stopPropagation(); + } + }); + }); + function _getCaretPosition(el) { + if (angular.isNumber(el.selectionStart)) { + return el.selectionStart; + } + // selectionStart is not supported in IE8 and we don't want hacky workarounds so we compromise + else { + return el.value.length; + } + } - var $select = ctrls[0]; - var ngModel = scope.ngModel = ctrls[1]; - var $selectMultiple = scope.$selectMultiple; + // Handles selected options in "multiple" mode + function _handleMatchSelection(key) { + var caretPosition = _getCaretPosition($select.searchInput[0]), + length = $select.selected.length, + first = 0, + last = length - 1, + curr = $selectMultiple.activeMatchIndex, + next = $selectMultiple.activeMatchIndex + 1, + prev = $selectMultiple.activeMatchIndex - 1, + newIndex = curr; + + if (caretPosition > 0 || ($select.search.length && key == KEY.RIGHT)) { + return false; + } - //$select.selected = raw selected objects (ignoring any property binding) + $select.close(); - $select.multiple = true; - $select.removeSelected = true; + function getNewActiveMatchIndex() { + switch (key) { + case KEY.LEFT: + // Select previous/first item + if (~$selectMultiple.activeMatchIndex) { + return prev; + } + // Select last item + else { + return last; + } + break; + case KEY.RIGHT: + // Open drop-down + if (!~$selectMultiple.activeMatchIndex || curr === last) { + $select.activate(); + return false; + } + // Select next/last item + else { + return next; + } + break; + case KEY.BACKSPACE: + // Remove selected item and select previous/first + if (~$selectMultiple.activeMatchIndex) { + $selectMultiple.removeChoice(curr); + return prev; + } + // Select last item + else { + return last; + } + break; + case KEY.DELETE: + // Remove selected item and select next item + if (~$selectMultiple.activeMatchIndex) { + $selectMultiple.removeChoice($selectMultiple.activeMatchIndex); + return curr; + } + else { + return false; + } + } + } - //Input that will handle focus - $select.focusInput = $select.searchInput; + newIndex = getNewActiveMatchIndex(); - //From view --> model - ngModel.$parsers.unshift(function () { - var locals = {}, - result, - resultMultiple = []; - for (var j = $select.selected.length - 1; j >= 0; j--) { - locals = {}; - locals[$select.parserResult.itemName] = $select.selected[j]; - result = $select.parserResult.modelMapper(scope, locals); - resultMultiple.unshift(result); - } - return resultMultiple; - }); - - // From model --> view - ngModel.$formatters.unshift(function (inputValue) { - var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search - locals = {}, - result; - if (!data) return inputValue; - var resultMultiple = []; - var checkFnMultiple = function(list, value){ - if (!list || !list.length) return; - for (var p = list.length - 1; p >= 0; p--) { - locals[$select.parserResult.itemName] = list[p]; - result = $select.parserResult.modelMapper(scope, locals); - if($select.parserResult.trackByExp){ - var matches = /\.(.+)/.exec($select.parserResult.trackByExp); - if(matches.length>0 && result[matches[1]] == value[matches[1]]){ - resultMultiple.unshift(list[p]); - return true; + if (!$select.selected.length || newIndex === false) { + $selectMultiple.activeMatchIndex = -1; } + else { + $selectMultiple.activeMatchIndex = Math.min(last, Math.max(first, newIndex)); + } + + return true; } - if (angular.equals(result,value)){ - resultMultiple.unshift(list[p]); - return true; - } - } - return false; - }; - if (!inputValue) return resultMultiple; //If ngModel was undefined - for (var k = inputValue.length - 1; k >= 0; k--) { - //Check model array of currently selected items - if (!checkFnMultiple($select.selected, inputValue[k])){ - //Check model array of all items available - if (!checkFnMultiple(data, inputValue[k])){ - //If not found on previous lists, just add it directly to resultMultiple - resultMultiple.unshift(inputValue[k]); - } - } - } - return resultMultiple; - }); - - //Watch for external model changes - scope.$watchCollection(function(){ return ngModel.$modelValue; }, function(newValue, oldValue) { - if (oldValue != newValue){ - ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters - $selectMultiple.refreshComponent(); - } - }); - - ngModel.$render = function() { - // Make sure that model value is array - if(!angular.isArray(ngModel.$viewValue)){ - // Have tolerance for null or undefined values - if(angular.isUndefined(ngModel.$viewValue) || ngModel.$viewValue === null){ - $select.selected = []; - } else { - throw uiSelectMinErr('multiarr', "Expected model value to be array but got '{0}'", ngModel.$viewValue); - } - } - $select.selected = ngModel.$viewValue; - scope.$evalAsync(); //To force $digest - }; - scope.$on('uis:select', function (event, item) { - if($select.selected.length >= $select.limit) { - return; - } - $select.selected.push(item); - $selectMultiple.updateModel(); - }); - - scope.$on('uis:activate', function () { - $selectMultiple.activeMatchIndex = -1; - }); - - scope.$watch('$select.disabled', function(newValue, oldValue) { - // As the search input field may now become visible, it may be necessary to recompute its size - if (oldValue && !newValue) $select.sizeSearchInput(); - }); - - $select.searchInput.on('keydown', function(e) { - var key = e.which; - scope.$apply(function() { - var processed = false; - if(KEY.isHorizontalMovement(key)){ - processed = _handleMatchSelection(key); - } - if (processed && key != KEY.TAB) { - //TODO Check si el tab selecciona aun correctamente - //Crear test -// e.preventDefault(); - // e.stopPropagation(); - } - }); - }); - function _getCaretPosition(el) { - if(angular.isNumber(el.selectionStart)) return el.selectionStart; - // selectionStart is not supported in IE8 and we don't want hacky workarounds so we compromise - else return el.value.length; - } - // Handles selected options in "multiple" mode - function _handleMatchSelection(key){ - var caretPosition = _getCaretPosition($select.searchInput[0]), - length = $select.selected.length, - // none = -1, - first = 0, - last = length-1, - curr = $selectMultiple.activeMatchIndex, - next = $selectMultiple.activeMatchIndex+1, - prev = $selectMultiple.activeMatchIndex-1, - newIndex = curr; - - if(caretPosition > 0 || ($select.search.length && key == KEY.RIGHT)) return false; - - $select.close(); - - function getNewActiveMatchIndex(){ - switch(key){ - case KEY.LEFT: - // Select previous/first item - if(~$selectMultiple.activeMatchIndex) return prev; - // Select last item - else return last; - break; - case KEY.RIGHT: - // Open drop-down - if(!~$selectMultiple.activeMatchIndex || curr === last){ - $select.activate(); - return false; - } - // Select next/last item - else return next; - break; - case KEY.BACKSPACE: - // Remove selected item and select previous/first - if(~$selectMultiple.activeMatchIndex){ - $selectMultiple.removeChoice(curr); - return prev; - } - // Select last item - else return last; - break; - case KEY.DELETE: - // Remove selected item and select next item - if(~$selectMultiple.activeMatchIndex){ - $selectMultiple.removeChoice($selectMultiple.activeMatchIndex); - return curr; - } - else return false; - } + $select.searchInput.on('blur', function () { + $timeout(function () { + $selectMultiple.activeMatchIndex = -1; + }); + }); + } + }; +}]); - newIndex = getNewActiveMatchIndex(); +uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $compile) { + return { + restrict: 'EA', + require: ['^uiSelect', '^ngModel'], + link: function (scope, element, attrs, ctrls) { + + var $select = ctrls[0]; + var ngModel = ctrls[1]; + + //From view --> model + ngModel.$parsers.unshift(function (inputValue) { + var locals = {}, + result; + locals[$select.parserResult.itemName] = inputValue; + result = $select.parserResult.modelMapper(scope, locals); + return result; + }); - if(!$select.selected.length || newIndex === false) $selectMultiple.activeMatchIndex = -1; - else $selectMultiple.activeMatchIndex = Math.min(last,Math.max(first,newIndex)); + //From model --> view + ngModel.$formatters.unshift(function (inputValue) { + var data = $select.parserResult.source(scope, {$select: {search: ''}}), //Overwrite $search + locals = {}, + result; + if (data) { + var checkFnSingle = function (d) { + locals[$select.parserResult.itemName] = d; + result = $select.parserResult.modelMapper(scope, locals); + return result == inputValue; + }; + //If possible pass same object stored in $select.selected + if ($select.selected && checkFnSingle($select.selected)) { + return $select.selected; + } + for (var i = data.length - 1; i >= 0; i--) { + if (checkFnSingle(data[i])) { + return data[i]; + } + } + } + return inputValue; + }); - return true; - } + //Update viewValue if model change + scope.$watch('$select.selected', function (newValue) { + if (ngModel.$viewValue !== newValue) { + ngModel.$setViewValue(newValue); + } + }); - $select.searchInput.on('blur', function() { - $timeout(function() { - $selectMultiple.activeMatchIndex = -1; - }); - }); + ngModel.$render = function () { + $select.selected = ngModel.$viewValue; + }; - } - }; -}]); + scope.$on('uis:select', function (event, item) { + $select.selected = item; + }); -uis.directive('uiSelectSingle', ['$timeout','$compile', function($timeout, $compile) { - return { - restrict: 'EA', - require: ['^uiSelect', '^ngModel'], - link: function(scope, element, attrs, ctrls) { - - var $select = ctrls[0]; - var ngModel = ctrls[1]; - - //From view --> model - ngModel.$parsers.unshift(function (inputValue) { - var locals = {}, - result; - locals[$select.parserResult.itemName] = inputValue; - result = $select.parserResult.modelMapper(scope, locals); - return result; - }); - - //From model --> view - ngModel.$formatters.unshift(function (inputValue) { - var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search - locals = {}, - result; - if (data){ - var checkFnSingle = function(d){ - locals[$select.parserResult.itemName] = d; - result = $select.parserResult.modelMapper(scope, locals); - return result == inputValue; - }; - //If possible pass same object stored in $select.selected - if ($select.selected && checkFnSingle($select.selected)) { - return $select.selected; - } - for (var i = data.length - 1; i >= 0; i--) { - if (checkFnSingle(data[i])) return data[i]; - } - } - return inputValue; - }); + scope.$on('uis:close', function (event, skipFocusser) { + $timeout(function () { + $select.focusser.prop('disabled', false); + if (!skipFocusser) $select.focusser[0].focus(); + }, 0, false); + }); - //Update viewValue if model change - scope.$watch('$select.selected', function(newValue) { - if (ngModel.$viewValue !== newValue) { - ngModel.$setViewValue(newValue); - } - }); - - ngModel.$render = function() { - $select.selected = ngModel.$viewValue; - }; - - scope.$on('uis:select', function (event, item) { - $select.selected = item; - }); - - scope.$on('uis:close', function (event, skipFocusser) { - $timeout(function(){ - $select.focusser.prop('disabled', false); - if (!skipFocusser) $select.focusser[0].focus(); - },0,false); - }); - - scope.$on('uis:activate', function () { - focusser.prop('disabled', true); //Will reactivate it on .close() - }); - - //Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954 - var focusser = angular.element(""); - $compile(focusser)(scope); - $select.focusser = focusser; - - //Input that will handle focus - $select.focusInput = focusser; - - element.parent().append(focusser); - focusser.bind("focus", function(){ - scope.$evalAsync(function(){ - $select.focus = true; - }); - }); - focusser.bind("blur", function(){ - scope.$evalAsync(function(){ - $select.focus = false; - }); - }); - focusser.bind("keydown", function(e){ - - if (e.which === KEY.BACKSPACE) { - e.preventDefault(); - e.stopPropagation(); - $select.select(undefined); - scope.$apply(); - return; - } + scope.$on('uis:activate', function () { + focusser.prop('disabled', true); //Will reactivate it on .close() + }); - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) { - return; - } + //Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954 + var focusser = angular.element(""); + $compile(focusser)(scope); + $select.focusser = focusser; - if (e.which == KEY.DOWN || e.which == KEY.UP || e.which == KEY.ENTER || e.which == KEY.SPACE){ - e.preventDefault(); - e.stopPropagation(); - $select.activate(); - } + //Input that will handle focus + $select.focusInput = focusser; - scope.$digest(); - }); + element.parent().append(focusser); + focusser.bind("focus", function () { + scope.$evalAsync(function () { + $select.focus = true; + }); + }); + focusser.bind("blur", function () { + scope.$evalAsync(function () { + $select.focus = false; + }); + }); + focusser.bind("keydown", function (e) { - focusser.bind("keyup input", function(e){ + if (e.which === KEY.BACKSPACE) { + e.preventDefault(); + e.stopPropagation(); + $select.select(undefined); + scope.$apply(); + return; + } - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { - return; - } + if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) { + return; + } - $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input - focusser.val(''); - scope.$digest(); + if (e.which == KEY.DOWN || e.which == KEY.UP || e.which == KEY.ENTER || e.which == KEY.SPACE) { + e.preventDefault(); + e.stopPropagation(); + $select.activate(); + } - }); + scope.$digest(); + }); + focusser.bind("keyup input", function (e) { - } - }; + if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || + e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { + return; + } + + $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input + focusser.val(''); + scope.$digest(); + }); + } + }; }]); /** * Parses "repeat" attribute. @@ -1472,45 +1609,46 @@ uis.directive('uiSelectSingle', ['$timeout','$compile', function($timeout, $comp * https://github.com/angular-ui/ui-select/commit/5dd63ad#commitcomment-5504697 */ -uis.service('uisRepeatParser', ['uiSelectMinErr','$parse', function(uiSelectMinErr, $parse) { - var self = this; +uis.service('uisRepeatParser', ['uiSelectMinErr', '$parse', function (uiSelectMinErr, $parse) { + var self = this; - /** - * Example: - * expression = "address in addresses | filter: {street: $select.search} track by $index" - * itemName = "address", - * source = "addresses | filter: {street: $select.search}", - * trackByExp = "$index", - */ - self.parse = function(expression) { + /** + * Example: + * expression = "address in addresses | filter: {street: $select.search} track by $index" + * itemName = "address", + * source = "addresses | filter: {street: $select.search}", + * trackByExp = "$index", + */ + self.parse = function (expression) { - var match = expression.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/); + var match = expression.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/); - if (!match) { - throw uiSelectMinErr('iexp', "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.", - expression); - } + if (!match) { + throw uiSelectMinErr('iexp', + "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.", + expression); + } - return { - itemName: match[2], // (lhs) Left-hand side, - source: $parse(match[3]), - trackByExp: match[4], - modelMapper: $parse(match[1] || match[2]) - }; + return { + itemName: match[2], // (lhs) Left-hand side, + source: $parse(match[3]), + trackByExp: match[4], + modelMapper: $parse(match[1] || match[2]) + }; - }; + }; - self.getGroupNgRepeatExpression = function() { - return '$group in $select.groups'; - }; + self.getGroupNgRepeatExpression = function () { + return '$group in $select.groups'; + }; - self.getNgRepeatExpression = function(itemName, source, trackByExp, grouped) { - var expression = itemName + ' in ' + (grouped ? '$group.items' : source); - if (trackByExp) { - expression += ' track by ' + trackByExp; - } - return expression; - }; + self.getNgRepeatExpression = function (itemName, source, trackByExp, grouped) { + var expression = itemName + ' in ' + (grouped ? '$group.items' : source); + if (trackByExp) { + expression += ' track by ' + trackByExp; + } + return expression; + }; }]); }()); diff --git a/dist/select.bootstrap.min.js b/dist/select.bootstrap.min.js index ccfbc8736..e242f43cc 100644 --- a/dist/select.bootstrap.min.js +++ b/dist/select.bootstrap.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-02T20:56:31.504Z + * Version: 0.12.1 - 2015-08-04T17:24:10.062Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var n=t.which;switch(n){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,n=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",refreshDelay:1e3,closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,i,c){c(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var i=n[0].getBoundingClientRect();return{width:i.width||n.prop("offsetWidth"),height:i.height||n.prop("offsetHeight"),top:i.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:i.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);n.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(c,l){if(!l.repeat)throw n("repeat","Expected 'repeat' expression.");return function(c,l,s,r,a){var o=s.groupBy,u=s.groupFilter;if(r.parseRepeatAttr(s.repeat,o,u),r.disableChoiceExpression=s.uiDisableChoice,r.onHighlightCallback=s.onHighlight,r.refreshOnActive=c.$eval(s.refreshOnActive),o){var p=l.querySelectorAll(".ui-select-choices-group");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",p.length);p.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=l.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(r.parserResult.itemName,"$select.items",r.parserResult.trackByExp,o)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+r.parserResult.itemName+")").attr("ng-click","$select.select("+r.parserResult.itemName+",false,$event)");var h=l.querySelectorAll(".ui-select-choices-row-inner");if(1!==h.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",h.length);h.attr("uis-transclude-append",""),i(l,a)(c),c.$watch("$select.search",function(e){e&&!r.open&&r.multiple&&r.activate(!1,!0),r.activeIndex=0,(!r.refreshOnActive||r.refreshOnActive&&r.refreshIsActive)&&r.refresh(s.refresh)}),c.$watch("$select.refreshIsActive",function(e,t){angular.isUndefined(t)&&e&&r.refresh(s.refresh)});var f=c.$eval(s.refreshDelay);r.refreshDelay=void 0!==f?f:e.refreshDelay}}}}]),n.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,n,i,c,l,s,r,a){function o(){(h.resetSearchInput||void 0===h.resetSearchInput&&a.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var n,i,c=[];for(n=0;n0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:n=!1}return n}function d(){var e=n.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw r("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var i=t[h.activeIndex],c=i.offsetTop+i.clientHeight-e[0].scrollTop,l=e[0].offsetHeight;c>l?e[0].scrollTop+=c-l:c=h.items.length?0:h.activeIndex,h.refreshIsActive=!0,i(function(){h.search=e||h.search,h.searchInput[0].focus()}))},h.findGroupByName=function(e){return h.groups&&h.groups.filter(function(t){return t.name===e})[0]},h.parseRepeatAttr=function(e,n,i){function c(e){var c=t.$eval(n);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(c)?c(e):e[c],n=h.findGroupByName(t);n?n.items.push(e):h.groups.push({name:t,items:[e]})}),i){var l=t.$eval(i);angular.isFunction(l)?h.groups=l(h.groups):angular.isArray(l)&&(h.groups=u(h.groups,l))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function l(e){h.items=e}h.setItemsFn=n?c:l,h.parserResult=s.parse(e),h.isGrouped=!!n,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var n=h.selected;if(h.isEmpty()||angular.isArray(n)&&!n.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var i=e.filter(function(e){return n.indexOf(e)<0});h.setItemsFn(i)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw r("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})};var v;h.refresh=function(e){void 0!==e&&(v&&i.cancel(v),v=i(function(){t.$eval(e)},h.refreshDelay))},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),n=t===h.activeIndex;return n&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),n},h.isDisabled=function(e){if(!h.open)return!1;var t,n=h.items.indexOf(e[h.itemProperty]),i=!1;return n>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[n],i=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i},h.select=function(e,n,c){if(void 0===e||!e._uiSelectChoiceDisabled){if(!h.items&&!h.search)return;if(!e||!e._uiSelectChoiceDisabled){var l=function(){t.$broadcast("uis:select",e),i(function(){h.onSelectCallback(t,r)}),h.closeOnSelect&&h.close(n),c&&"click"===c.type&&(h.clickTriggeredSelect=!0)},s={};s[h.parserResult.itemName]=e;var r={$item:e,$model:h.parserResult.modelMapper(t,s)},a=h.onBeforeSelectCallback(t,r);if(angular.isDefined(a)){if(!a)return;angular.isFunction(a.then)?a.then(function(e){e&&l(e)}):a===!0?l(e):l(a)}else l(e)}}},h.close=function(e){h.open&&(h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),o(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e))},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),i(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var n,i=h.selected[t];return i&&!angular.isUndefined(h.lockChoiceExpression)&&(n=!!e.$eval(h.lockChoiceExpression),i._uiSelectChoiceLocked=n),n};var g=null;h.sizeSearchInput=function(){var e=h.searchInput[0],n=h.searchInput.parent().parent()[0],c=function(){return n.clientWidth*!!e.offsetParent},l=function(t){if(0===t)return!1;var n=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=t),h.searchInput.css("width",n+"px"),!0};h.searchInput.css("width","10px"),i(function(){null!==g||l(c())||(g=t.$watch(c,function(e){l(e)&&(g(),g=null)}))})},h.searchInput.on("keydown",function(n){var i=n.which;t.$apply(function(){p(i)}),e.isVerticalMovement(i)&&h.items.length>0&&d(),(i===e.ENTER||i===e.ESC)&&(n.preventDefault(),n.stopPropagation())}),h.searchInput.on("keyup",function(n){n.which===e.TAB||e.isControl(n)||e.isFunctionKey(n)||n.which===e.ESC||e.isVerticalMovement(n.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:n})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),n.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,i,c,l,s){return{restrict:"EA",templateUrl:function(e,n){var i=n.theme||t.theme;return i+(angular.isDefined(n.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(c,r){return angular.isDefined(r.multiple)?c.append("").removeAttr("multiple"):c.append(""),function(c,r,a,o,u){function p(e){if(f.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(r[0],e.target):r[0].contains(e.target),!t&&!f.clickTriggeredSelect){var n=["input","button","textarea"],i=angular.element(e.target).scope(),l=i&&i.$select&&i.$select!==f;l||(l=~n.indexOf(e.target.tagName.toLowerCase())),f.close(l),c.$digest()}f.clickTriggeredSelect=!1}}function d(){var t=i(r);b=angular.element('
    '),b[0].style.width=t.width+"px",b[0].style.height=t.height+"px",r.after(b),E=r[0].style.width,e.find("body").append(r),r[0].style.position="absolute",r[0].style.left=t.left+"px",r[0].style.top=t.top+"px",r[0].style.width=t.width+"px"}function h(){null!==b&&(b.replaceWith(r),b=null,r[0].style.position="",r[0].style.left="",r[0].style.top="",r[0].style.width=E)}var f=o[0],v=o[1];f.generatedId=t.generateId(),f.baseTitle=a.title||"Select box",f.focusserTitle=f.baseTitle+" focus",f.focusserId="focusser-"+f.generatedId,f.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?l(a.closeOnSelect)():t.closeOnSelect}(),f.onBeforeSelectCallback=l(a.onBeforeSelect),f.onSelectCallback=l(a.onSelect),f.onRemoveCallback=l(a.onRemove),f.onKeypressCallback=l(a.onKeypress),f.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,f.ngModel=v,f.choiceGrouped=function(e){return f.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){f.focusInput.attr("tabindex",e),r.removeAttr("tabindex")});var g=c.$eval(a.searchEnabled);f.searchEnabled=void 0!==g?g:t.searchEnabled;var m=c.$eval(a.sortable);f.sortable=void 0!==m?m:t.sortable,a.$observe("disabled",function(){f.disabled=void 0!==a.disabled?a.disabled:!1}),a.$observe("resetSearchInput",function(){var e=c.$eval(a.resetSearchInput);f.resetSearchInput=void 0!==e?e:!0}),angular.isDefined(a.autofocus)&&s(function(){f.setFocus()}),angular.isDefined(a.focusOn)&&c.$on(a.focusOn,function(){s(function(){f.setFocus()})}),e.on("click",p),c.$on("$destroy",function(){e.off("click",p)}),u(c,function(e){var t=angular.element("
    ").append(e),i=t.querySelectorAll(".ui-select-match");if(i.removeAttr("ui-select-match"),i.removeAttr("data-ui-select-match"),1!==i.length)throw n("transcluded","Expected 1 .ui-select-match but got '{0}'.",i.length);r.querySelectorAll(".ui-select-match").replaceWith(i);var c=t.querySelectorAll(".ui-select-choices");if(c.removeAttr("ui-select-choices"),c.removeAttr("data-ui-select-choices"),1!==c.length)throw n("transcluded","Expected 1 .ui-select-choices but got '{0}'.",c.length);r.querySelectorAll(".ui-select-choices").replaceWith(c)});var $=c.$eval(a.appendToBody);(void 0!==$?$:t.appendToBody)&&(c.$watch("$select.open",function(e){e?d():h()}),c.$on("$destroy",function(){h()}));var b=null,E="",y=null,w="direction-up";c.$watch("$select.open",function(t){if(t){if(y=angular.element(r).querySelectorAll(".ui-select-dropdown"),null===y)return;y[0].style.opacity=0,s(function(){var t=i(r),n=i(y);t.top+t.height+n.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&(y[0].style.position="absolute",y[0].style.top=-1*n.height+"px",r.addClass(w)),y[0].style.opacity=1})}else{if(null===y)return;y[0].style.position="",y[0].style.top="",r.removeClass(w)}})}}}}]),n.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return n+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,i,c){function l(e){c.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}c.lockChoiceExpression=i.uiLockChoice,i.$observe("placeholder",function(t){c.placeholder=void 0!==t?t:e.placeholder}),i.$observe("allowClear",l),l(i.allowClear),c.multiple&&c.sizeSearchInput()}}}]),n.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,i=this,c=e.$select;e.$evalAsync(function(){n=e.ngModel}),i.activeMatchIndex=-1,i.updateModel=function(){n.$setViewValue(Date.now()),i.refreshComponent()},i.refreshComponent=function(){c.refreshItems(),c.sizeSearchInput()},i.removeChoice=function(n){var l=c.selected[n];if(!l._uiSelectChoiceLocked){var s={};s[c.parserResult.itemName]=l,c.selected.splice(n,1),i.activeMatchIndex=-1,c.sizeSearchInput(),t(function(){c.onRemoveCallback(e,{$item:l,$model:c.parserResult.modelMapper(e,s)})}),i.updateModel()}},i.getPlaceholder=function(){return c.selected&&c.selected.length?void 0:c.placeholder}}],controllerAs:"$selectMultiple",link:function(i,c,l,s){function r(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(t){function n(){switch(t){case e.LEFT:return~p.activeMatchIndex?d:s;case e.RIGHT:return~p.activeMatchIndex&&a!==s?u:(o.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(a),d):s;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),a):!1}}var i=r(o.searchInput[0]),c=o.selected.length,l=0,s=c-1,a=p.activeMatchIndex,u=p.activeMatchIndex+1,d=p.activeMatchIndex-1,h=a;return i>0||o.search.length&&t==e.RIGHT?!1:(o.close(),h=n(),p.activeMatchIndex=o.selected.length&&h!==!1?Math.min(s,Math.max(l,h)):-1,!0)}var o=s[0],u=i.ngModel=s[1],p=i.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,u.$parsers.unshift(function(){for(var e,t={},n=[],c=o.selected.length-1;c>=0;c--)t={},t[o.parserResult.itemName]=o.selected[c],e=o.parserResult.modelMapper(i,t),n.unshift(e);return n}),u.$formatters.unshift(function(e){var t,n=o.parserResult.source(i,{$select:{search:""}}),c={};if(!n)return e;var l=[],s=function(e,n){if(e&&e.length){for(var s=e.length-1;s>=0;s--){if(c[o.parserResult.itemName]=e[s],t=o.parserResult.modelMapper(i,c),o.parserResult.trackByExp){var r=/\.(.+)/.exec(o.parserResult.trackByExp);if(r.length>0&&t[r[1]]==n[r[1]])return l.unshift(e[s]),!0}if(angular.equals(t,n))return l.unshift(e[s]),!0}return!1}};if(!e)return l;for(var r=e.length-1;r>=0;r--)s(o.selected,e[r])||s(n,e[r])||l.unshift(e[r]);return l}),i.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);o.selected=[]}o.selected=u.$viewValue,i.$evalAsync()},i.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),p.updateModel())}),i.$on("uis:activate",function(){p.activeMatchIndex=-1}),i.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(t){var n=t.which;i.$apply(function(){var t=!1;e.isHorizontalMovement(n)&&(t=a(n)),t&&n!=e.TAB})}),o.searchInput.on("blur",function(){n(function(){p.activeMatchIndex=-1})})}}}]),n.directive("uiSelectSingle",["$timeout","$compile",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(i,c,l,s){var r=s[0],a=s[1];a.$parsers.unshift(function(e){var t,n={};return n[r.parserResult.itemName]=e,t=r.parserResult.modelMapper(i,n)}),a.$formatters.unshift(function(e){var t,n=r.parserResult.source(i,{$select:{search:""}}),c={};if(n){var l=function(n){return c[r.parserResult.itemName]=n,t=r.parserResult.modelMapper(i,c),t==e};if(r.selected&&l(r.selected))return r.selected;for(var s=n.length-1;s>=0;s--)if(l(n[s]))return n[s]}return e}),i.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){r.selected=a.$viewValue},i.$on("uis:select",function(e,t){r.selected=t}),i.$on("uis:close",function(e,n){t(function(){r.focusser.prop("disabled",!1),n||r.focusser[0].focus()},0,!1)}),i.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");n(o)(i),r.focusser=o,r.focusInput=o,c.parent().append(o),o.bind("focus",function(){i.$evalAsync(function(){r.focus=!0})}),o.bind("blur",function(){i.$evalAsync(function(){r.focus=!1})}),o.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),r.select(void 0),i.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),r.activate()),i.$digest()),void 0)}),o.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(r.activate(o.val()),o.val(""),i.$digest())})}}}]),n.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var i=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!i)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:i[2],source:t(i[3]),trackByExp:i[4],modelMapper:t(i[1]||i[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,i){var c=e+" in "+(i?"$group.items":t);return n&&(c+=" track by "+n),c}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",'
    {{$select.placeholder}}
    '),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",'')}]); \ No newline at end of file +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var n=t.which;switch(n){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,n=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,c,i){i(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var c=n[0].getBoundingClientRect();return{width:c.width||n.prop("offsetWidth"),height:c.height||n.prop("offsetHeight"),top:c.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:c.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);n.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,c){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,i){if(!i.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,i,l,s,r){var a=l.groupBy,o=l.groupFilter;if(s.parseRepeatAttr(l.repeat,a,o),s.disableChoiceExpression=l.uiDisableChoice,s.onHighlightCallback=l.onHighlight,a){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=i.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(s.parserResult.itemName,"$select.items",s.parserResult.trackByExp,a)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+s.parserResult.itemName+")").attr("ng-click","$select.select("+s.parserResult.itemName+",false,$event)");var d=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),c(i,r)(e),e.$watch("$select.search",function(e){e&&!s.open&&s.multiple&&s.activate(!1,!0),s.activeIndex=0})}}}}]),n.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,n,c,i,l,s,r,a){function o(){(h.resetSearchInput||void 0===h.resetSearchInput&&a.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var n,c,i=[];for(n=0;n0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:n=!1}return n}function d(){var e=n.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw r("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var c=t[h.activeIndex],i=c.offsetTop+c.clientHeight-e[0].scrollTop,l=e[0].offsetHeight;i>l?e[0].scrollTop+=i-l:i=h.items.length?0:h.activeIndex,c(function(){h.search=e||h.search,h.searchInput[0].focus()}))},h.parseRepeatAttr=function(e,n,c){function i(e){var i=t.$eval(n);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(i)?i(e):e[i],n=h.findGroupByName(t);n?n.items.push(e):h.groups.push({name:t,items:[e]})}),c){var l=t.$eval(c);angular.isFunction(l)?h.groups=l(h.groups):angular.isArray(l)&&(h.groups=u(h.groups,l))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function l(e){h.items=e}h.setItemsFn=n?i:l,h.parserResult=s.parse(e),h.isGrouped=!!n,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var n=h.selected;if(h.isEmpty()||angular.isArray(n)&&!n.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var c=e.filter(function(e){return n.indexOf(e)<0});h.setItemsFn(c)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw r("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),n=t===h.activeIndex;return n&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),n},h.isDisabled=function(e){if(!h.open)return!1;var t,n=h.items.indexOf(e[h.itemProperty]),c=!1;return n>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[n],c=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=c),c},h.select=function(e,n,i){if((void 0===e||!e._uiSelectChoiceDisabled)&&(h.items||h.search)){var l={};l[h.parserResult.itemName]=e;var s={$item:e,$model:h.parserResult.modelMapper(t,l)},r=function(){t.$broadcast("uis:select",e),c(function(){h.onSelectCallback(t,s)}),h.closeOnSelect&&h.close(n),i&&"click"===i.type&&(h.clickTriggeredSelect=!0)},a=h.onBeforeSelectCallback(t,s);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(e){e&&r(e)}):a===!0?r(e):a&&r(a):r(e)}},h.close=function(e){h.open&&(h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),o(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e))},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),c(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var n,c=h.selected[t];return c&&!angular.isUndefined(h.lockChoiceExpression)&&(n=!!e.$eval(h.lockChoiceExpression),c._uiSelectChoiceLocked=n),n};var g=null;h.sizeSearchInput=function(){var e=h.searchInput[0],n=h.searchInput.parent().parent()[0],i=function(){return n.clientWidth*!!e.offsetParent},l=function(t){if(0===t)return!1;var n=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=t),h.searchInput.css("width",n+"px"),!0};h.searchInput.css("width","10px"),c(function(){null!==g||l(i())||(g=t.$watch(i,function(e){l(e)&&(g(),g=null)}))})},h.searchInput.on("keydown",function(n){var c=n.which;t.$apply(function(){p(c)}),e.isVerticalMovement(c)&&h.items.length>0&&d(),(c===e.ENTER||c===e.ESC)&&(n.preventDefault(),n.stopPropagation())}),h.searchInput.on("keyup",function(n){n.which===e.TAB||e.isControl(n)||e.isFunctionKey(n)||n.which===e.ESC||e.isVerticalMovement(n.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:n})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),n.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,c,i,l,s){return{restrict:"EA",templateUrl:function(e,n){var c=n.theme||t.theme;return c+(angular.isDefined(n.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(i,r){return angular.isDefined(r.multiple)?i.append("").removeAttr("multiple"):i.append(""),function(i,r,a,o,u){function p(e){if(f.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(r[0],e.target):r[0].contains(e.target),!t&&!f.clickTriggeredSelect){var n=["input","button","textarea"],c=angular.element(e.target).scope(),l=c&&c.$select&&c.$select!==f;l||(l=~n.indexOf(e.target.tagName.toLowerCase())),f.close(l),i.$digest()}f.clickTriggeredSelect=!1}}function d(){var t=c(r);b=angular.element('
    '),b[0].style.width=t.width+"px",b[0].style.height=t.height+"px",r.after(b),E=r[0].style.width,e.find("body").append(r),r[0].style.position="absolute",r[0].style.left=t.left+"px",r[0].style.top=t.top+"px",r[0].style.width=t.width+"px"}function h(){null!==b&&(b.replaceWith(r),b=null,r[0].style.position="",r[0].style.left="",r[0].style.top="",r[0].style.width=E)}var f=o[0],g=o[1];f.generatedId=t.generateId(),f.baseTitle=a.title||"Select box",f.focusserTitle=f.baseTitle+" focus",f.focusserId="focusser-"+f.generatedId,f.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?l(a.closeOnSelect)():t.closeOnSelect}(),f.onSelectCallback=l(a.onSelect),f.onBeforeSelectCallback=l(a.onBeforeSelect),f.onRemoveCallback=l(a.onRemove),f.onBeforeRemoveCallback=l(a.onBeforeRemove),f.onKeypressCallback=l(a.onKeypress),f.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,f.ngModel=g,f.choiceGrouped=function(e){return f.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){f.focusInput.attr("tabindex",e),r.removeAttr("tabindex")});var m=i.$eval(a.searchEnabled);f.searchEnabled=void 0!==m?m:t.searchEnabled;var v=i.$eval(a.sortable);f.sortable=void 0!==v?v:t.sortable,a.$observe("disabled",function(){f.disabled=void 0!==a.disabled?a.disabled:!1}),angular.isDefined(a.autofocus)&&s(function(){f.setFocus()}),angular.isDefined(a.focusOn)&&i.$on(a.focusOn,function(){s(function(){f.setFocus()})}),e.on("click",p),i.$on("$destroy",function(){e.off("click",p)}),u(i,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),c.removeAttr("data-ui-select-match"),1!==c.length)throw n("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);r.querySelectorAll(".ui-select-match").replaceWith(c);var i=t.querySelectorAll(".ui-select-choices");if(i.removeAttr("ui-select-choices"),i.removeAttr("data-ui-select-choices"),1!==i.length)throw n("transcluded","Expected 1 .ui-select-choices but got '{0}'.",i.length);r.querySelectorAll(".ui-select-choices").replaceWith(i)});var $=i.$eval(a.appendToBody);(void 0!==$?$:t.appendToBody)&&(i.$watch("$select.open",function(e){e?d():h()}),i.$on("$destroy",function(){h()}));var b=null,E="",w=null,x="direction-up";i.$watch("$select.open",function(t){if(t){if(w=angular.element(r).querySelectorAll(".ui-select-dropdown"),null===w)return;w[0].style.opacity=0,s(function(){var t=c(r),n=c(w);t.top+t.height+n.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&r.addClass(x),w[0].style.opacity=1})}else{if(null===w)return;r.removeClass(x)}})}}}}]),n.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,c=t.parent().attr("multiple");return n+(c?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,c,i){function l(e){i.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}i.lockChoiceExpression=c.uiLockChoice,c.$observe("placeholder",function(t){i.placeholder=void 0!==t?t:e.placeholder}),c.$observe("allowClear",l),l(c.allowClear),i.multiple&&i.sizeSearchInput()}}}]),n.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,c=this,i=e.$select;e.$evalAsync(function(){n=e.ngModel}),c.activeMatchIndex=-1,c.updateModel=function(){n.$setViewValue(Date.now()),c.refreshComponent()},c.refreshComponent=function(){i.refreshItems(),i.sizeSearchInput()},c.removeChoice=function(n){function l(){t(function(){i.onRemoveCallback(e,a)}),c.updateModel()}var s=i.selected[n];if(!s._uiSelectChoiceLocked){var r={};r[i.parserResult.itemName]=s,i.selected.splice(n,1),c.activeMatchIndex=-1,i.sizeSearchInput();var a={$item:s,$model:i.parserResult.modelMapper(e,r)},o=c.onBeforeRemoveCallback(e,a);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(e){e&&l(e)}):o===!0&&l():l()}},c.getPlaceholder=function(){return i.selected&&i.selected.length?void 0:i.placeholder}}],controllerAs:"$selectMultiple",link:function(c,i,l,s){function r(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(t){function n(){switch(t){case e.LEFT:return~p.activeMatchIndex?d:s;case e.RIGHT:return~p.activeMatchIndex&&a!==s?u:(o.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(a),d):s;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),a):!1}}var c=r(o.searchInput[0]),i=o.selected.length,l=0,s=i-1,a=p.activeMatchIndex,u=p.activeMatchIndex+1,d=p.activeMatchIndex-1,h=a;return c>0||o.search.length&&t==e.RIGHT?!1:(o.close(),h=n(),p.activeMatchIndex=o.selected.length&&h!==!1?Math.min(s,Math.max(l,h)):-1,!0)}var o=s[0],u=c.ngModel=s[1],p=c.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,u.$parsers.unshift(function(){for(var e,t={},n=[],i=o.selected.length-1;i>=0;i--)t={},t[o.parserResult.itemName]=o.selected[i],e=o.parserResult.modelMapper(c,t),n.unshift(e);return n}),u.$formatters.unshift(function(e){var t,n=o.parserResult.source(c,{$select:{search:""}}),i={};if(!n)return e;var l=[],s=function(e,n){if(e&&e.length){for(var s=e.length-1;s>=0;s--){if(i[o.parserResult.itemName]=e[s],t=o.parserResult.modelMapper(c,i),o.parserResult.trackByExp){var r=/\.(.+)/.exec(o.parserResult.trackByExp);if(r.length>0&&t[r[1]]==n[r[1]])return l.unshift(e[s]),!0}if(angular.equals(t,n))return l.unshift(e[s]),!0}return!1}};if(!e)return l;for(var r=e.length-1;r>=0;r--)s(o.selected,e[r])||s(n,e[r])||l.unshift(e[r]);return l}),c.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);o.selected=[]}o.selected=u.$viewValue,c.$evalAsync()},c.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),p.updateModel())}),c.$on("uis:activate",function(){p.activeMatchIndex=-1}),c.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(t){var n=t.which;c.$apply(function(){var t=!1;e.isHorizontalMovement(n)&&(t=a(n)),t&&n!=e.TAB})}),o.searchInput.on("blur",function(){n(function(){p.activeMatchIndex=-1})})}}}]),n.directive("uiSelectSingle",["$timeout","$compile",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(c,i,l,s){var r=s[0],a=s[1];a.$parsers.unshift(function(e){var t,n={};return n[r.parserResult.itemName]=e,t=r.parserResult.modelMapper(c,n)}),a.$formatters.unshift(function(e){var t,n=r.parserResult.source(c,{$select:{search:""}}),i={};if(n){var l=function(n){return i[r.parserResult.itemName]=n,t=r.parserResult.modelMapper(c,i),t==e};if(r.selected&&l(r.selected))return r.selected;for(var s=n.length-1;s>=0;s--)if(l(n[s]))return n[s]}return e}),c.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){r.selected=a.$viewValue},c.$on("uis:select",function(e,t){r.selected=t}),c.$on("uis:close",function(e,n){t(function(){r.focusser.prop("disabled",!1),n||r.focusser[0].focus()},0,!1)}),c.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");n(o)(c),r.focusser=o,r.focusInput=o,i.parent().append(o),o.bind("focus",function(){c.$evalAsync(function(){r.focus=!0})}),o.bind("blur",function(){c.$evalAsync(function(){r.focus=!1})}),o.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),r.select(void 0),c.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),r.activate()),c.$digest()),void 0)}),o.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(r.activate(o.val()),o.val(""),c.$digest())})}}}]),n.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var c=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!c)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:c[2],source:t(c[3]),trackByExp:c[4],modelMapper:t(c[1]||c[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,c){var i=e+" in "+(c?"$group.items":t);return n&&(i+=" track by "+n),i}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",'
    {{$select.placeholder}}
    '),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",'')}]); \ No newline at end of file diff --git a/dist/select.css b/dist/select.css index b4d99a09e..c70321c5f 100644 --- a/dist/select.css +++ b/dist/select.css @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-02T20:56:31.552Z + * Version: 0.12.1 - 2015-08-04T17:24:10.107Z * License: MIT */ @@ -55,6 +55,10 @@ body > .select2-container.open { border-top-right-radius: 0; } .ui-select-container[theme="select2"].direction-up .ui-select-dropdown { + bottom: 100%; + top: auto; + position: absolute; + border-radius: 4px; /* FIXME hardcoded value :-/ */ border-bottom-left-radius: 0; border-bottom-right-radius: 0; @@ -97,6 +101,10 @@ body > .select2-container.open { /* Handle up direction Selectize */ .ui-select-container[theme="selectize"].direction-up .ui-select-dropdown { + bottom: 100%; + top: auto; + position: absolute; + box-shadow: 0 -4px 8px rgba(0, 0, 0, 0.25); margin-top: -2px; /* FIXME hardcoded value :-/ */ @@ -271,5 +279,9 @@ body > .ui-select-bootstrap.open { /* Handle up direction Bootstrap */ .ui-select-container[theme="bootstrap"].direction-up .ui-select-dropdown { + bottom: 100%; + top: auto; + position: absolute; + box-shadow: 0 -4px 8px rgba(0, 0, 0, 0.25); } diff --git a/dist/select.js b/dist/select.js index f86c7c7e6..50f4297a6 100644 --- a/dist/select.js +++ b/dist/select.js @@ -1,14 +1,13 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-02T20:56:31.549Z + * Version: 0.12.1 - 2015-08-04T17:24:10.105Z * License: MIT */ (function () { "use strict"; - var KEY = { TAB: 9, ENTER: 13, @@ -29,20 +28,123 @@ var KEY = { DELETE: 46, COMMAND: 91, - MAP: { 91 : "COMMAND", 8 : "BACKSPACE" , 9 : "TAB" , 13 : "ENTER" , 16 : "SHIFT" , 17 : "CTRL" , 18 : "ALT" , 19 : "PAUSEBREAK" , 20 : "CAPSLOCK" , 27 : "ESC" , 32 : "SPACE" , 33 : "PAGE_UP", 34 : "PAGE_DOWN" , 35 : "END" , 36 : "HOME" , 37 : "LEFT" , 38 : "UP" , 39 : "RIGHT" , 40 : "DOWN" , 43 : "+" , 44 : "PRINTSCREEN" , 45 : "INSERT" , 46 : "DELETE", 48 : "0" , 49 : "1" , 50 : "2" , 51 : "3" , 52 : "4" , 53 : "5" , 54 : "6" , 55 : "7" , 56 : "8" , 57 : "9" , 59 : ";", 61 : "=" , 65 : "A" , 66 : "B" , 67 : "C" , 68 : "D" , 69 : "E" , 70 : "F" , 71 : "G" , 72 : "H" , 73 : "I" , 74 : "J" , 75 : "K" , 76 : "L", 77 : "M" , 78 : "N" , 79 : "O" , 80 : "P" , 81 : "Q" , 82 : "R" , 83 : "S" , 84 : "T" , 85 : "U" , 86 : "V" , 87 : "W" , 88 : "X" , 89 : "Y" , 90 : "Z", 96 : "0" , 97 : "1" , 98 : "2" , 99 : "3" , 100 : "4" , 101 : "5" , 102 : "6" , 103 : "7" , 104 : "8" , 105 : "9", 106 : "*" , 107 : "+" , 109 : "-" , 110 : "." , 111 : "/", 112 : "F1" , 113 : "F2" , 114 : "F3" , 115 : "F4" , 116 : "F5" , 117 : "F6" , 118 : "F7" , 119 : "F8" , 120 : "F9" , 121 : "F10" , 122 : "F11" , 123 : "F12", 144 : "NUMLOCK" , 145 : "SCROLLLOCK" , 186 : ";" , 187 : "=" , 188 : "," , 189 : "-" , 190 : "." , 191 : "/" , 192 : "`" , 219 : "[" , 220 : "\\" , 221 : "]" , 222 : "'" + MAP: { + 91: "COMMAND", + 8: "BACKSPACE", + 9: "TAB", + 13: "ENTER", + 16: "SHIFT", + 17: "CTRL", + 18: "ALT", + 19: "PAUSEBREAK", + 20: "CAPSLOCK", + 27: "ESC", + 32: "SPACE", + 33: "PAGE_UP", + 34: "PAGE_DOWN", + 35: "END", + 36: "HOME", + 37: "LEFT", + 38: "UP", + 39: "RIGHT", + 40: "DOWN", + 43: "+", + 44: "PRINTSCREEN", + 45: "INSERT", + 46: "DELETE", + 48: "0", + 49: "1", + 50: "2", + 51: "3", + 52: "4", + 53: "5", + 54: "6", + 55: "7", + 56: "8", + 57: "9", + 59: ";", + 61: "=", + 65: "A", + 66: "B", + 67: "C", + 68: "D", + 69: "E", + 70: "F", + 71: "G", + 72: "H", + 73: "I", + 74: "J", + 75: "K", + 76: "L", + 77: "M", + 78: "N", + 79: "O", + 80: "P", + 81: "Q", + 82: "R", + 83: "S", + 84: "T", + 85: "U", + 86: "V", + 87: "W", + 88: "X", + 89: "Y", + 90: "Z", + 96: "0", + 97: "1", + 98: "2", + 99: "3", + 100: "4", + 101: "5", + 102: "6", + 103: "7", + 104: "8", + 105: "9", + 106: "*", + 107: "+", + 109: "-", + 110: ".", + 111: "/", + 112: "F1", + 113: "F2", + 114: "F3", + 115: "F4", + 116: "F5", + 117: "F6", + 118: "F7", + 119: "F8", + 120: "F9", + 121: "F10", + 122: "F11", + 123: "F12", + 144: "NUMLOCK", + 145: "SCROLLLOCK", + 186: ";", + 187: "=", + 188: ",", + 189: "-", + 190: ".", + 191: "/", + 192: "`", + 219: "[", + 220: "\\", + 221: "]", + 222: "'" }, isControl: function (e) { var k = e.which; switch (k) { - case KEY.COMMAND: - case KEY.SHIFT: - case KEY.CTRL: - case KEY.ALT: - return true; + case KEY.COMMAND: + case KEY.SHIFT: + case KEY.CTRL: + case KEY.ALT: + return true; } - if (e.metaKey) return true; + if (e.metaKey) { + return true; + } return false; }, @@ -50,13 +152,13 @@ var KEY = { k = k.which ? k.which : k; return k >= 112 && k <= 123; }, - isVerticalMovement: function (k){ - return ~[KEY.UP, KEY.DOWN].indexOf(k); + isVerticalMovement: function (k) { + return ~[KEY.UP, KEY.DOWN].indexOf(k); }, - isHorizontalMovement: function (k){ - return ~[KEY.LEFT,KEY.RIGHT,KEY.BACKSPACE,KEY.DELETE].indexOf(k); + isHorizontalMovement: function (k) { + return ~[KEY.LEFT, KEY.RIGHT, KEY.BACKSPACE, KEY.DELETE].indexOf(k); } - }; +}; /** * Add querySelectorAll() to jqLite. @@ -68,67 +170,67 @@ var KEY = { * See feat(jqLite): use querySelectorAll instead of getElementsByTagName in jqLite.find https://github.com/angular/angular.js/pull/3598 */ if (angular.element.prototype.querySelectorAll === undefined) { - angular.element.prototype.querySelectorAll = function(selector) { - return angular.element(this[0].querySelectorAll(selector)); - }; + angular.element.prototype.querySelectorAll = function (selector) { + return angular.element(this[0].querySelectorAll(selector)); + }; } /** * Add closest() to jqLite. */ if (angular.element.prototype.closest === undefined) { - angular.element.prototype.closest = function( selector) { - var elem = this[0]; - var matchesSelector = elem.matches || elem.webkitMatchesSelector || elem.mozMatchesSelector || elem.msMatchesSelector; - - while (elem) { - if (matchesSelector.bind(elem)(selector)) { - return elem; - } else { - elem = elem.parentElement; - } - } - return false; - }; + angular.element.prototype.closest = function (selector) { + var elem = this[0]; + var matchesSelector = elem.matches || elem.webkitMatchesSelector || elem.mozMatchesSelector || + elem.msMatchesSelector; + + while (elem) { + if (matchesSelector.bind(elem)(selector)) { + return elem; + } else { + elem = elem.parentElement; + } + } + return false; + }; } var latestId = 0; var uis = angular.module('ui.select', []) -.constant('uiSelectConfig', { - theme: 'bootstrap', - searchEnabled: true, - sortable: false, - placeholder: '', // Empty by default, like HTML tag + closeOnSelect: true, + generateId: function () { + return latestId++; + }, + appendToBody: false + }) // See Rename minErr and make it accessible from outside https://github.com/angular/angular.js/issues/6913 -.service('uiSelectMinErr', function() { - var minErr = angular.$$minErr('ui.select'); - return function() { - var error = minErr.apply(this, arguments); - var message = error.message.replace(new RegExp('\nhttp://errors.angularjs.org/.*'), ''); - return new Error(message); - }; -}) + .service('uiSelectMinErr', function () { + var minErr = angular.$$minErr('ui.select'); + return function () { + var error = minErr.apply(this, arguments); + var message = error.message.replace(new RegExp('\nhttp://errors.angularjs.org/.*'), ''); + return new Error(message); + }; + }) // Recreates old behavior of ng-transclude. Used internally. -.directive('uisTranscludeAppend', function () { - return { - link: function (scope, element, attrs, ctrl, transclude) { - transclude(scope, function (clone) { - element.append(clone); - }); - } - }; -}) + .directive('uisTranscludeAppend', function () { + return { + link: function (scope, element, attrs, ctrl, transclude) { + transclude(scope, function (clone) { + element.append(clone); + }); + } + }; + }) /** * Highlights text that matches $select.search. @@ -136,15 +238,16 @@ var uis = angular.module('ui.select', []) * Taken from AngularUI Bootstrap Typeahead * See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L340 */ -.filter('highlight', function() { - function escapeRegexp(queryToEscape) { - return queryToEscape.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1'); - } + .filter('highlight', function () { + function escapeRegexp(queryToEscape) { + return queryToEscape.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1'); + } - return function(matchItem, query) { - return query && matchItem ? matchItem.replace(new RegExp(escapeRegexp(query), 'gi'), '$&') : matchItem; - }; -}) + return function (matchItem, query) { + return query && matchItem ? matchItem.replace(new RegExp(escapeRegexp(query), 'gi'), + '$&') : matchItem; + }; + }) /** * A read-only equivalent of jQuery's offset function: http://api.jquery.com/offset/ @@ -152,96 +255,92 @@ var uis = angular.module('ui.select', []) * Taken from AngularUI Bootstrap Position: * See https://github.com/angular-ui/bootstrap/blob/master/src/position/position.js#L70 */ -.factory('uisOffset', - ['$document', '$window', - function ($document, $window) { - - return function(element) { - var boundingClientRect = element[0].getBoundingClientRect(); - return { - width: boundingClientRect.width || element.prop('offsetWidth'), - height: boundingClientRect.height || element.prop('offsetHeight'), - top: boundingClientRect.top + ($window.pageYOffset || $document[0].documentElement.scrollTop), - left: boundingClientRect.left + ($window.pageXOffset || $document[0].documentElement.scrollLeft) - }; - }; -}]); + .factory('uisOffset', + ['$document', '$window', + function ($document, $window) { + + return function (element) { + var boundingClientRect = element[0].getBoundingClientRect(); + return { + width: boundingClientRect.width || element.prop('offsetWidth'), + height: boundingClientRect.height || element.prop('offsetHeight'), + top: boundingClientRect.top + ($window.pageYOffset || $document[0].documentElement.scrollTop), + left: boundingClientRect.left + ($window.pageXOffset || $document[0].documentElement.scrollLeft) + }; + }; + }]); uis.directive('uiSelectChoices', - ['uiSelectConfig', 'uisRepeatParser', 'uiSelectMinErr', '$compile', - function(uiSelectConfig, RepeatParser, uiSelectMinErr, $compile) { - - return { - restrict: 'EA', - require: '^uiSelect', - replace: true, - transclude: true, - templateUrl: function(tElement) { - // Gets theme attribute from parent (ui-select) - var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; - return theme + '/choices.tpl.html'; - }, + ['uiSelectConfig', 'uisRepeatParser', 'uiSelectMinErr', '$compile', + function (uiSelectConfig, RepeatParser, uiSelectMinErr, $compile) { - compile: function(tElement, tAttrs) { + return { + restrict: 'EA', + require: '^uiSelect', + replace: true, + transclude: true, + templateUrl: function (tElement) { + // Gets theme attribute from parent (ui-select) + var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; + return theme + '/choices.tpl.html'; + }, - if (!tAttrs.repeat) throw uiSelectMinErr('repeat', "Expected 'repeat' expression."); + compile: function (tElement, tAttrs) { - return function link(scope, element, attrs, $select, transcludeFn) { + if (!tAttrs.repeat) { + throw uiSelectMinErr('repeat', "Expected 'repeat' expression."); + } - // var repeat = RepeatParser.parse(attrs.repeat); - var groupByExp = attrs.groupBy; - var groupFilterExp = attrs.groupFilter; + return function link(scope, element, attrs, $select, transcludeFn) { - $select.parseRepeatAttr(attrs.repeat, groupByExp, groupFilterExp); //Result ready at $select.parserResult + // var repeat = RepeatParser.parse(attrs.repeat); + var groupByExp = attrs.groupBy; + var groupFilterExp = attrs.groupFilter; - $select.disableChoiceExpression = attrs.uiDisableChoice; - $select.onHighlightCallback = attrs.onHighlight; + $select.parseRepeatAttr(attrs.repeat, groupByExp, groupFilterExp); //Result ready at $select.parserResult - $select.refreshOnActive = scope.$eval(attrs.refreshOnActive); + $select.disableChoiceExpression = attrs.uiDisableChoice; + $select.onHighlightCallback = attrs.onHighlight; - if(groupByExp) { - var groups = element.querySelectorAll('.ui-select-choices-group'); - if (groups.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-group but got '{0}'.", groups.length); - groups.attr('ng-repeat', RepeatParser.getGroupNgRepeatExpression()); - } + if (groupByExp) { + var groups = element.querySelectorAll('.ui-select-choices-group'); + if (groups.length !== 1) throw uiSelectMinErr('rows', + "Expected 1 .ui-select-choices-group but got '{0}'.", groups.length); + groups.attr('ng-repeat', RepeatParser.getGroupNgRepeatExpression()); + } - var choices = element.querySelectorAll('.ui-select-choices-row'); - if (choices.length !== 1) { - throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row but got '{0}'.", choices.length); - } + var choices = element.querySelectorAll('.ui-select-choices-row'); + if (choices.length !== 1) { + throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row but got '{0}'.", + choices.length); + } - choices.attr('ng-repeat', RepeatParser.getNgRepeatExpression($select.parserResult.itemName, '$select.items', $select.parserResult.trackByExp, groupByExp)) - .attr('ng-if', '$select.open') //Prevent unnecessary watches when dropdown is closed - .attr('ng-mouseenter', '$select.setActiveItem('+$select.parserResult.itemName +')') - .attr('ng-click', '$select.select(' + $select.parserResult.itemName + ',false,$event)'); - - var rowsInner = element.querySelectorAll('.ui-select-choices-row-inner'); - if (rowsInner.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row-inner but got '{0}'.", rowsInner.length); - rowsInner.attr('uis-transclude-append', ''); //Adding uisTranscludeAppend directive to row element after choices element has ngRepeat - - $compile(element, transcludeFn)(scope); //Passing current transcludeFn to be able to append elements correctly from uisTranscludeAppend - - scope.$watch('$select.search', function(newValue) { - if(newValue && !$select.open && $select.multiple) $select.activate(false, true); - $select.activeIndex = 0; - if(!$select.refreshOnActive || ($select.refreshOnActive && $select.refreshIsActive)) { - $select.refresh(attrs.refresh); - } - }); - - scope.$watch('$select.refreshIsActive', function(newValue, oldValue){ - if(angular.isUndefined(oldValue) && newValue){ - $select.refresh(attrs.refresh); - } - }); - - // $eval() is needed otherwise we get a string instead of a number - var refreshDelay = scope.$eval(attrs.refreshDelay); - $select.refreshDelay = refreshDelay !== undefined ? refreshDelay : uiSelectConfig.refreshDelay; - }; - } - }; -}]); + choices.attr('ng-repeat', + RepeatParser.getNgRepeatExpression($select.parserResult.itemName, '$select.items', + $select.parserResult.trackByExp, groupByExp)) + .attr('ng-if', '$select.open') //Prevent unnecessary watches when dropdown is closed + .attr('ng-mouseenter', '$select.setActiveItem(' + $select.parserResult.itemName + ')') + .attr('ng-click', '$select.select(' + $select.parserResult.itemName + ',false,$event)'); + + var rowsInner = element.querySelectorAll('.ui-select-choices-row-inner'); + if (rowsInner.length !== 1) { + throw uiSelectMinErr('rows', + "Expected 1 .ui-select-choices-row-inner but got '{0}'.", rowsInner.length); + } + rowsInner.attr('uis-transclude-append', ''); //Adding uisTranscludeAppend directive to row element after choices element has ngRepeat + + $compile(element, transcludeFn)(scope); //Passing current transcludeFn to be able to append elements correctly from uisTranscludeAppend + + scope.$watch('$select.search', function (newValue) { + if (newValue && !$select.open && $select.multiple) { + $select.activate(false, true); + } + $select.activeIndex = 0; + }); + }; + } + }; + }]); /** * Contains ui-select "intelligence". @@ -260,7 +359,6 @@ uis.controller('uiSelectCtrl', ctrl.placeholder = uiSelectConfig.placeholder; ctrl.searchEnabled = uiSelectConfig.searchEnabled; ctrl.sortable = uiSelectConfig.sortable; - ctrl.refreshDelay = uiSelectConfig.refreshDelay; ctrl.removeSelected = false; //If selected item(s) should be removed from dropdown list ctrl.closeOnSelect = true; //Initialized inside uiSelect directive link function @@ -281,8 +379,6 @@ uis.controller('uiSelectCtrl', ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelectMatch directive link function ctrl.clickTriggeredSelect = false; ctrl.$filter = $filter; - ctrl.refreshOnActive = undefined; - ctrl.refreshIsActive = undefined; ctrl.searchInput = $element.querySelectorAll('input.ui-select-search'); if (ctrl.searchInput.length !== 1) { @@ -290,6 +386,10 @@ uis.controller('uiSelectCtrl', ctrl.searchInput.length); } + /** + * Returns true if the selection is empty + * @returns {boolean|*} + */ ctrl.isEmpty = function () { return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === ''; }; @@ -305,6 +405,12 @@ uis.controller('uiSelectCtrl', } } + ctrl.findGroupByName = function (name) { + return ctrl.groups && ctrl.groups.filter(function (group) { + return group.name === name; + })[0]; + }; + function _groupsFilter(groups, groupNames) { var i, j, result = []; for (i = 0; i < groupNames.length; i++) { @@ -317,10 +423,15 @@ uis.controller('uiSelectCtrl', return result; } - // When the user clicks on ui-select, displays the dropdown list + /** + * Activates the control. + * When the user clicks on ui-select, displays the dropdown list + */ ctrl.activate = function (initSearchValue, avoidReset) { if (!ctrl.disabled && !ctrl.open) { - if (!avoidReset) _resetSearchInput(); + if (!avoidReset) { + _resetSearchInput(); + } $scope.$broadcast('uis:activate'); @@ -330,7 +441,6 @@ uis.controller('uiSelectCtrl', } ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex; - ctrl.refreshIsActive = true; // Give it time to appear before focus $timeout(function () { @@ -344,12 +454,6 @@ uis.controller('uiSelectCtrl', } }; - ctrl.findGroupByName = function (name) { - return ctrl.groups && ctrl.groups.filter(function (group) { - return group.name === name; - })[0]; - }; - ctrl.parseRepeatAttr = function (repeatAttr, groupByExp, groupFilterExp) { function updateGroups(items) { var groupFn = $scope.$eval(groupByExp); @@ -382,6 +486,7 @@ uis.controller('uiSelectCtrl', ctrl.items = items; } + // Set the function to use when displaying items - either groups or single ctrl.setItemsFn = groupByExp ? updateGroups : setPlainItems; ctrl.parserResult = RepeatParser.parse(repeatAttr); @@ -392,7 +497,7 @@ uis.controller('uiSelectCtrl', ctrl.refreshItems = function (data) { data = data || ctrl.parserResult.source($scope); var selectedItems = ctrl.selected; - //TODO should implement for single mode removeSelected + // TODO should implement for single mode removeSelected if (ctrl.isEmpty() || (angular.isArray(selectedItems) && !selectedItems.length) || !ctrl.removeSelected) { ctrl.setItemsFn(data); @@ -424,35 +529,17 @@ uis.controller('uiSelectCtrl', } } }); - - }; - - var _refreshDelayPromise; - - /** - * Typeahead mode: lets the user refresh the collection using his own function. - * - * See Expose $select.search for external / remote filtering https://github.com/angular-ui/ui-select/pull/31 - */ - ctrl.refresh = function (refreshAttr) { - if (refreshAttr !== undefined) { - - // Debounce - // See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L155 - // FYI AngularStrap typeahead does not have debouncing: https://github.com/mgcrea/angular-strap/blob/v2.0.0-rc.4/src/typeahead/typeahead.js#L177 - if (_refreshDelayPromise) { - $timeout.cancel(_refreshDelayPromise); - } - _refreshDelayPromise = $timeout(function () { - $scope.$eval(refreshAttr); - }, ctrl.refreshDelay); - } }; ctrl.setActiveItem = function (item) { ctrl.activeIndex = ctrl.items.indexOf(item); }; + /** + * Checks if the item is active + * @param itemScope the item + * @returns {boolean} true if active + */ ctrl.isActive = function (itemScope) { if (!ctrl.open) { return false; @@ -469,11 +556,14 @@ uis.controller('uiSelectCtrl', /** * Checks if the item is disabled - * @return boolean true if the item is disabled + * @param itemScope the item + * @return {boolean} true if the item is disabled */ ctrl.isDisabled = function (itemScope) { - if (!ctrl.open) return false; + if (!ctrl.open) { + return false; + } var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); var isDisabled = false; @@ -490,75 +580,81 @@ uis.controller('uiSelectCtrl', /** + * Selects an item + * * Called when the user selects an item with ENTER or clicks the dropdown */ ctrl.select = function (item, skipFocusser, $event) { - if (item === undefined || !item._uiSelectChoiceDisabled) { - - if (!ctrl.items && !ctrl.search){ - return; - } - - if (!item || !item._uiSelectChoiceDisabled) { + if (item !== undefined && item._uiSelectChoiceDisabled) { + return; + } - var completeSelection = function () { - $scope.$broadcast('uis:select', item); + // If no items in the list, and no search, then return + if (!ctrl.items && !ctrl.search) { + return; + } - $timeout(function () { - ctrl.onSelectCallback($scope, callbackContext); - }); + // Create the data used to pass to the callbacks + var locals = {}; + locals[ctrl.parserResult.itemName] = item; + var callbackContext = { + $item: item, + $model: ctrl.parserResult.modelMapper($scope, locals) + }; - if (ctrl.closeOnSelect) { - ctrl.close(skipFocusser); - } - if ($event && $event.type === 'click') { - ctrl.clickTriggeredSelect = true; - } - }; + // Local method called when we complete the select + // eg. called after the onselect callback + var completeSelection = function () { + $scope.$broadcast('uis:select', item); - var locals = {}; - locals[ctrl.parserResult.itemName] = item; + $timeout(function () { + ctrl.onSelectCallback($scope, callbackContext); + }); - var callbackContext = { - $item: item, - $model: ctrl.parserResult.modelMapper($scope, locals) - }; + if (ctrl.closeOnSelect) { + ctrl.close(skipFocusser); + } + if ($event && $event.type === 'click') { + ctrl.clickTriggeredSelect = true; + } + }; - // Call the onBeforeSelect callback - // Allowable responses are -: - // falsy: Abort the selection - // promise: Wait for response - // true: Complete selection - // object: Add the returned object - var onBeforeSelectResult = ctrl.onBeforeSelectCallback($scope, callbackContext); - if (angular.isDefined(onBeforeSelectResult)) { - if (!onBeforeSelectResult) { - return; // abort the selection in case of deliberate falsey result - } else if (angular.isFunction(onBeforeSelectResult.then)) { - onBeforeSelectResult.then(function (result) { - if (!result) { - return; - } - completeSelection(result); - }); - } else if (onBeforeSelectResult === true) { - completeSelection(item); - } else { - completeSelection(onBeforeSelectResult); + // Call the onBeforeSelect callback + // Allowable responses are -: + // falsy: Abort the selection + // promise: Wait for response + // true: Complete selection + // object: Add the returned object + var onBeforeSelectResult = ctrl.onBeforeSelectCallback($scope, callbackContext); + if (angular.isDefined(onBeforeSelectResult)) { + if (angular.isFunction(onBeforeSelectResult.then)) { + // Promise returned - wait for it to complete before completing the selection + onBeforeSelectResult.then(function (result) { + if (!result) { + return; } - } else { - completeSelection(item); - } + completeSelection(result); + }); + } else if (onBeforeSelectResult === true) { + completeSelection(item); + } else if (onBeforeSelectResult) { + completeSelection(onBeforeSelectResult); } + } else { + completeSelection(item); } }; - // Closes the dropdown + /** + * Close the dropdown + */ ctrl.close = function (skipFocusser) { if (!ctrl.open) { return; } - if (ctrl.ngModel && ctrl.ngModel.$setTouched) ctrl.ngModel.$setTouched(); + if (ctrl.ngModel && ctrl.ngModel.$setTouched) { + ctrl.ngModel.$setTouched(); + } _resetSearchInput(); ctrl.open = false; if (!ctrl.searchEnabled) { @@ -568,12 +664,19 @@ uis.controller('uiSelectCtrl', $scope.$broadcast('uis:close', skipFocusser); }; + /** + * Set focus on the control + */ ctrl.setFocus = function () { if (!ctrl.focus) { ctrl.focusInput[0].focus(); } }; + /** + * Clears the selection + * @param $event + */ ctrl.clear = function ($event) { ctrl.select(undefined); $event.stopPropagation(); @@ -582,7 +685,9 @@ uis.controller('uiSelectCtrl', }, 0, false); }; - // Toggle dropdown + /** + * Toggle the dropdown open and closed + */ ctrl.toggle = function (e) { if (ctrl.open) { ctrl.close(); @@ -606,7 +711,6 @@ uis.controller('uiSelectCtrl', var sizeWatch = null; ctrl.sizeSearchInput = function () { - var input = ctrl.searchInput[0], container = ctrl.searchInput.parent().parent()[0], calculateContainerWidth = function () { @@ -659,7 +763,9 @@ uis.controller('uiSelectCtrl', } break; case KEY.TAB: - if (!ctrl.multiple || ctrl.open) ctrl.select(ctrl.items[ctrl.activeIndex], true); + if (!ctrl.multiple || ctrl.open) { + ctrl.select(ctrl.items[ctrl.activeIndex], true); + } break; case KEY.ENTER: if (ctrl.open) { @@ -703,24 +809,6 @@ uis.controller('uiSelectCtrl', } }); - // If tagging try to split by tokens and add items - /* ctrl.searchInput.on('paste', function (e) { - var data = e.originalEvent.clipboardData.getData('text/plain'); - if (data && data.length > 0 && ctrl.taggingTokens.isActivated && ctrl.tagging.fct) { - var items = data.split(ctrl.taggingTokens.tokens[0]); // split by first token only - if (items && items.length > 0) { - angular.forEach(items, function (item) { - var newItem = ctrl.tagging.fct(item); - if (newItem) { - ctrl.select(newItem, true); - } - }); - e.preventDefault(); - e.stopPropagation(); - } - } - });*/ - ctrl.searchInput.on('keyup', function (e) { // return early with these keys if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || @@ -734,7 +822,6 @@ uis.controller('uiSelectCtrl', ctrl.onKeypressCallback($scope, {event: e}); }); - // See https://github.com/ivaynberg/select2/blob/3.4.6/select2.js#L1431 function _ensureHighlightVisible() { var container = $element.querySelectorAll('.ui-select-choices-content'); @@ -755,10 +842,13 @@ uis.controller('uiSelectCtrl', if (posY > height) { container[0].scrollTop += posY - height; } else if (posY < highlighted.clientHeight) { - if (ctrl.isGrouped && ctrl.activeIndex === 0) - container[0].scrollTop = 0; //To make group header visible when going all the way up - else + if (ctrl.isGrouped && ctrl.activeIndex === 0) { + //To make group header visible when going all the way up + container[0].scrollTop = 0; + } + else { container[0].scrollTop -= highlighted.clientHeight - posY; + } } } @@ -811,9 +901,10 @@ uis.directive('uiSelect', } }(); - $select.onBeforeSelectCallback = $parse(attrs.onBeforeSelect); $select.onSelectCallback = $parse(attrs.onSelect); + $select.onBeforeSelectCallback = $parse(attrs.onBeforeSelect); $select.onRemoveCallback = $parse(attrs.onRemove); + $select.onBeforeRemoveCallback = $parse(attrs.onBeforeRemove); $select.onKeypressCallback = $parse(attrs.onKeypress); //Limit the number of selections allowed @@ -845,11 +936,6 @@ uis.directive('uiSelect', $select.disabled = attrs.disabled !== undefined ? attrs.disabled : false; }); - attrs.$observe('resetSearchInput', function () { - // $eval() is needed otherwise we get a string instead of a boolean - var resetSearchInput = scope.$eval(attrs.resetSearchInput); - $select.resetSearchInput = resetSearchInput !== undefined ? resetSearchInput : true; - }); //Automatically gets focus when loaded if (angular.isDefined(attrs.autofocus)) { @@ -1001,6 +1087,7 @@ uis.directive('uiSelect', // Support changing the direction of the dropdown if there isn't enough space to render it. scope.$watch('$select.open', function (isOpen) { if (isOpen) { + // Get the dropdown element dropdown = angular.element(element).querySelectorAll('.ui-select-dropdown'); if (dropdown === null) { return; @@ -1018,8 +1105,6 @@ uis.directive('uiSelect', if (offset.top + offset.height + offsetDropdown.height > $document[0].documentElement.scrollTop + $document[0].documentElement.clientHeight) { - dropdown[0].style.position = 'absolute'; - dropdown[0].style.top = (offsetDropdown.height * -1) + 'px'; element.addClass(directionUpClassName); } @@ -1032,8 +1117,6 @@ uis.directive('uiSelect', } // Reset the position of the dropdown. - dropdown[0].style.position = ''; - dropdown[0].style.top = ''; element.removeClass(directionUpClassName); } }); @@ -1042,425 +1125,479 @@ uis.directive('uiSelect', }; }]); -uis.directive('uiSelectMatch', ['uiSelectConfig', function(uiSelectConfig) { - return { - restrict: 'EA', - require: '^uiSelect', - replace: true, - transclude: true, - templateUrl: function(tElement) { - // Gets theme attribute from parent (ui-select) - var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; - var multi = tElement.parent().attr('multiple'); - return theme + (multi ? '/match-multiple.tpl.html' : '/match.tpl.html'); - }, - link: function(scope, element, attrs, $select) { - $select.lockChoiceExpression = attrs.uiLockChoice; - attrs.$observe('placeholder', function(placeholder) { - $select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder; - }); - - function setAllowClear(allow) { - $select.allowClear = (angular.isDefined(allow)) ? (allow === '') ? true : (allow.toLowerCase() === 'true') : false; - } +uis.directive('uiSelectMatch', ['uiSelectConfig', function (uiSelectConfig) { + return { + restrict: 'EA', + require: '^uiSelect', + replace: true, + transclude: true, + templateUrl: function (tElement) { + // Gets theme attribute from parent (ui-select) + var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; + var multi = tElement.parent().attr('multiple'); + return theme + (multi ? '/match-multiple.tpl.html' : '/match.tpl.html'); + }, + link: function (scope, element, attrs, $select) { + $select.lockChoiceExpression = attrs.uiLockChoice; + attrs.$observe('placeholder', function (placeholder) { + $select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder; + }); - attrs.$observe('allowClear', setAllowClear); - setAllowClear(attrs.allowClear); + function setAllowClear(allow) { + $select.allowClear = + (angular.isDefined(allow)) ? (allow === '') ? true : (allow.toLowerCase() === 'true') : false; + } - if($select.multiple){ - $select.sizeSearchInput(); - } + attrs.$observe('allowClear', setAllowClear); + setAllowClear(attrs.allowClear); - } - }; + if ($select.multiple) { + $select.sizeSearchInput(); + } + } + }; }]); -uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelectMinErr, $timeout) { - return { - restrict: 'EA', - require: ['^uiSelect', '^ngModel'], +uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSelectMinErr, $timeout) { + return { + restrict: 'EA', + require: ['^uiSelect', '^ngModel'], + controller: ['$scope', '$timeout', function ($scope, $timeout) { + var ctrl = this, + $select = $scope.$select, + ngModel; + + //Wait for link fn to inject it + $scope.$evalAsync(function () { + ngModel = $scope.ngModel; + }); + + ctrl.activeMatchIndex = -1; - controller: ['$scope','$timeout', function($scope, $timeout){ + ctrl.updateModel = function () { + ngModel.$setViewValue(Date.now()); //Set timestamp as a unique string to force changes + ctrl.refreshComponent(); + }; - var ctrl = this, - $select = $scope.$select, - ngModel; + ctrl.refreshComponent = function () { + // Remove already selected items + // e.g. When user clicks on a selection, the selected array changes and + // the dropdown should remove that item + $select.refreshItems(); + $select.sizeSearchInput(); + }; - //Wait for link fn to inject it - $scope.$evalAsync(function(){ ngModel = $scope.ngModel; }); + // Remove item from multiple select + ctrl.removeChoice = function (index) { + var removedChoice = $select.selected[index]; - ctrl.activeMatchIndex = -1; + // if the choice is locked, can't remove it + if (removedChoice._uiSelectChoiceLocked) { + return; + } - ctrl.updateModel = function(){ - ngModel.$setViewValue(Date.now()); //Set timestamp as a unique string to force changes - ctrl.refreshComponent(); - }; + var locals = {}; + locals[$select.parserResult.itemName] = removedChoice; - ctrl.refreshComponent = function(){ - //Remove already selected items - //e.g. When user clicks on a selection, the selected array changes and - //the dropdown should remove that item - $select.refreshItems(); - $select.sizeSearchInput(); - }; + $select.selected.splice(index, 1); + ctrl.activeMatchIndex = -1; + $select.sizeSearchInput(); - // Remove item from multiple select - ctrl.removeChoice = function(index){ + var callbackContext = { + $item: removedChoice, + $model: $select.parserResult.modelMapper($scope, locals) + }; - var removedChoice = $select.selected[index]; + // Give some time for scope propagation. + function completeRemoval() { + $timeout(function () { + $select.onRemoveCallback($scope, callbackContext); + }); - // if the choice is locked, can't remove it - if(removedChoice._uiSelectChoiceLocked) return; + ctrl.updateModel(); + } - var locals = {}; - locals[$select.parserResult.itemName] = removedChoice; + // Call the onBeforeRemove callback + // Allowable responses are -: + // falsy: Abort the removal + // promise: Wait for response + // true: Complete removal + var onBeforeRemoveResult = ctrl.onBeforeRemoveCallback($scope, callbackContext); + if (angular.isDefined(onBeforeRemoveResult)) { + if (angular.isFunction(onBeforeRemoveResult.then)) { + // Promise returned - wait for it to complete before completing the selection + onBeforeRemoveResult.then(function (result) { + if (!result) { + return; + } + completeRemoval(result); + }); + } else if (onBeforeRemoveResult === true) { + completeRemoval(); + } + } else { + completeRemoval(); + } + }; - $select.selected.splice(index, 1); - ctrl.activeMatchIndex = -1; - $select.sizeSearchInput(); + ctrl.getPlaceholder = function () { + //Refactor single? + if ($select.selected && $select.selected.length) { + return; + } + return $select.placeholder; + }; + }], + controllerAs: '$selectMultiple', + + link: function (scope, element, attrs, ctrls) { + var $select = ctrls[0]; + var ngModel = scope.ngModel = ctrls[1]; + var $selectMultiple = scope.$selectMultiple; + + //$select.selected = raw selected objects (ignoring any property binding) + + $select.multiple = true; + $select.removeSelected = true; + + //Input that will handle focus + $select.focusInput = $select.searchInput; + + //From view --> model + ngModel.$parsers.unshift(function () { + var locals = {}, + result, + resultMultiple = []; + for (var j = $select.selected.length - 1; j >= 0; j--) { + locals = {}; + locals[$select.parserResult.itemName] = $select.selected[j]; + result = $select.parserResult.modelMapper(scope, locals); + resultMultiple.unshift(result); + } + return resultMultiple; + }); - // Give some time for scope propagation. - $timeout(function(){ - $select.onRemoveCallback($scope, { - $item: removedChoice, - $model: $select.parserResult.modelMapper($scope, locals) - }); - }); + // From model --> view + ngModel.$formatters.unshift(function (inputValue) { + var data = $select.parserResult.source(scope, {$select: {search: ''}}), //Overwrite $search + locals = {}, + result; + if (!data) { + return inputValue; + } + var resultMultiple = []; + var checkFnMultiple = function (list, value) { + if (!list || !list.length) { + return; + } + for (var p = list.length - 1; p >= 0; p--) { + locals[$select.parserResult.itemName] = list[p]; + result = $select.parserResult.modelMapper(scope, locals); + if ($select.parserResult.trackByExp) { + var matches = /\.(.+)/.exec($select.parserResult.trackByExp); + if (matches.length > 0 && result[matches[1]] == value[matches[1]]) { + resultMultiple.unshift(list[p]); + return true; + } + } + if (angular.equals(result, value)) { + resultMultiple.unshift(list[p]); + return true; + } + } + return false; + }; + if (!inputValue) return resultMultiple; //If ngModel was undefined + for (var k = inputValue.length - 1; k >= 0; k--) { + //Check model array of currently selected items + if (!checkFnMultiple($select.selected, inputValue[k])) { + //Check model array of all items available + if (!checkFnMultiple(data, inputValue[k])) { + //If not found on previous lists, just add it directly to resultMultiple + resultMultiple.unshift(inputValue[k]); + } + } + } + return resultMultiple; + }); - ctrl.updateModel(); + //Watch for external model changes + scope.$watchCollection(function () { + return ngModel.$modelValue; + }, function (newValue, oldValue) { + if (oldValue != newValue) { + ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters + $selectMultiple.refreshComponent(); + } + }); - }; + ngModel.$render = function () { + // Make sure that model value is array + if (!angular.isArray(ngModel.$viewValue)) { + // Have tolerance for null or undefined values + if (angular.isUndefined(ngModel.$viewValue) || ngModel.$viewValue === null) { + $select.selected = []; + } else { + throw uiSelectMinErr('multiarr', "Expected model value to be array but got '{0}'", + ngModel.$viewValue); + } + } + $select.selected = ngModel.$viewValue; + scope.$evalAsync(); //To force $digest + }; - ctrl.getPlaceholder = function(){ - //Refactor single? - if($select.selected && $select.selected.length) return; - return $select.placeholder; - }; + scope.$on('uis:select', function (event, item) { + if ($select.selected.length >= $select.limit) { + return; + } + $select.selected.push(item); + $selectMultiple.updateModel(); + }); + scope.$on('uis:activate', function () { + $selectMultiple.activeMatchIndex = -1; + }); - }], - controllerAs: '$selectMultiple', + scope.$watch('$select.disabled', function (newValue, oldValue) { + // As the search input field may now become visible, it may be necessary to recompute its size + if (oldValue && !newValue) { + $select.sizeSearchInput(); + } + }); - link: function(scope, element, attrs, ctrls) { + $select.searchInput.on('keydown', function (e) { + var key = e.which; + scope.$apply(function () { + var processed = false; + if (KEY.isHorizontalMovement(key)) { + processed = _handleMatchSelection(key); + } + if (processed && key != KEY.TAB) { + //TODO Check si el tab selecciona aun correctamente + //Crear test +// e.preventDefault(); + // e.stopPropagation(); + } + }); + }); + function _getCaretPosition(el) { + if (angular.isNumber(el.selectionStart)) { + return el.selectionStart; + } + // selectionStart is not supported in IE8 and we don't want hacky workarounds so we compromise + else { + return el.value.length; + } + } - var $select = ctrls[0]; - var ngModel = scope.ngModel = ctrls[1]; - var $selectMultiple = scope.$selectMultiple; + // Handles selected options in "multiple" mode + function _handleMatchSelection(key) { + var caretPosition = _getCaretPosition($select.searchInput[0]), + length = $select.selected.length, + first = 0, + last = length - 1, + curr = $selectMultiple.activeMatchIndex, + next = $selectMultiple.activeMatchIndex + 1, + prev = $selectMultiple.activeMatchIndex - 1, + newIndex = curr; + + if (caretPosition > 0 || ($select.search.length && key == KEY.RIGHT)) { + return false; + } - //$select.selected = raw selected objects (ignoring any property binding) + $select.close(); - $select.multiple = true; - $select.removeSelected = true; + function getNewActiveMatchIndex() { + switch (key) { + case KEY.LEFT: + // Select previous/first item + if (~$selectMultiple.activeMatchIndex) { + return prev; + } + // Select last item + else { + return last; + } + break; + case KEY.RIGHT: + // Open drop-down + if (!~$selectMultiple.activeMatchIndex || curr === last) { + $select.activate(); + return false; + } + // Select next/last item + else { + return next; + } + break; + case KEY.BACKSPACE: + // Remove selected item and select previous/first + if (~$selectMultiple.activeMatchIndex) { + $selectMultiple.removeChoice(curr); + return prev; + } + // Select last item + else { + return last; + } + break; + case KEY.DELETE: + // Remove selected item and select next item + if (~$selectMultiple.activeMatchIndex) { + $selectMultiple.removeChoice($selectMultiple.activeMatchIndex); + return curr; + } + else { + return false; + } + } + } - //Input that will handle focus - $select.focusInput = $select.searchInput; + newIndex = getNewActiveMatchIndex(); - //From view --> model - ngModel.$parsers.unshift(function () { - var locals = {}, - result, - resultMultiple = []; - for (var j = $select.selected.length - 1; j >= 0; j--) { - locals = {}; - locals[$select.parserResult.itemName] = $select.selected[j]; - result = $select.parserResult.modelMapper(scope, locals); - resultMultiple.unshift(result); - } - return resultMultiple; - }); - - // From model --> view - ngModel.$formatters.unshift(function (inputValue) { - var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search - locals = {}, - result; - if (!data) return inputValue; - var resultMultiple = []; - var checkFnMultiple = function(list, value){ - if (!list || !list.length) return; - for (var p = list.length - 1; p >= 0; p--) { - locals[$select.parserResult.itemName] = list[p]; - result = $select.parserResult.modelMapper(scope, locals); - if($select.parserResult.trackByExp){ - var matches = /\.(.+)/.exec($select.parserResult.trackByExp); - if(matches.length>0 && result[matches[1]] == value[matches[1]]){ - resultMultiple.unshift(list[p]); - return true; + if (!$select.selected.length || newIndex === false) { + $selectMultiple.activeMatchIndex = -1; } + else { + $selectMultiple.activeMatchIndex = Math.min(last, Math.max(first, newIndex)); + } + + return true; } - if (angular.equals(result,value)){ - resultMultiple.unshift(list[p]); - return true; - } - } - return false; - }; - if (!inputValue) return resultMultiple; //If ngModel was undefined - for (var k = inputValue.length - 1; k >= 0; k--) { - //Check model array of currently selected items - if (!checkFnMultiple($select.selected, inputValue[k])){ - //Check model array of all items available - if (!checkFnMultiple(data, inputValue[k])){ - //If not found on previous lists, just add it directly to resultMultiple - resultMultiple.unshift(inputValue[k]); - } - } - } - return resultMultiple; - }); - - //Watch for external model changes - scope.$watchCollection(function(){ return ngModel.$modelValue; }, function(newValue, oldValue) { - if (oldValue != newValue){ - ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters - $selectMultiple.refreshComponent(); - } - }); - - ngModel.$render = function() { - // Make sure that model value is array - if(!angular.isArray(ngModel.$viewValue)){ - // Have tolerance for null or undefined values - if(angular.isUndefined(ngModel.$viewValue) || ngModel.$viewValue === null){ - $select.selected = []; - } else { - throw uiSelectMinErr('multiarr', "Expected model value to be array but got '{0}'", ngModel.$viewValue); - } - } - $select.selected = ngModel.$viewValue; - scope.$evalAsync(); //To force $digest - }; - scope.$on('uis:select', function (event, item) { - if($select.selected.length >= $select.limit) { - return; - } - $select.selected.push(item); - $selectMultiple.updateModel(); - }); - - scope.$on('uis:activate', function () { - $selectMultiple.activeMatchIndex = -1; - }); - - scope.$watch('$select.disabled', function(newValue, oldValue) { - // As the search input field may now become visible, it may be necessary to recompute its size - if (oldValue && !newValue) $select.sizeSearchInput(); - }); - - $select.searchInput.on('keydown', function(e) { - var key = e.which; - scope.$apply(function() { - var processed = false; - if(KEY.isHorizontalMovement(key)){ - processed = _handleMatchSelection(key); - } - if (processed && key != KEY.TAB) { - //TODO Check si el tab selecciona aun correctamente - //Crear test -// e.preventDefault(); - // e.stopPropagation(); - } - }); - }); - function _getCaretPosition(el) { - if(angular.isNumber(el.selectionStart)) return el.selectionStart; - // selectionStart is not supported in IE8 and we don't want hacky workarounds so we compromise - else return el.value.length; - } - // Handles selected options in "multiple" mode - function _handleMatchSelection(key){ - var caretPosition = _getCaretPosition($select.searchInput[0]), - length = $select.selected.length, - // none = -1, - first = 0, - last = length-1, - curr = $selectMultiple.activeMatchIndex, - next = $selectMultiple.activeMatchIndex+1, - prev = $selectMultiple.activeMatchIndex-1, - newIndex = curr; - - if(caretPosition > 0 || ($select.search.length && key == KEY.RIGHT)) return false; - - $select.close(); - - function getNewActiveMatchIndex(){ - switch(key){ - case KEY.LEFT: - // Select previous/first item - if(~$selectMultiple.activeMatchIndex) return prev; - // Select last item - else return last; - break; - case KEY.RIGHT: - // Open drop-down - if(!~$selectMultiple.activeMatchIndex || curr === last){ - $select.activate(); - return false; - } - // Select next/last item - else return next; - break; - case KEY.BACKSPACE: - // Remove selected item and select previous/first - if(~$selectMultiple.activeMatchIndex){ - $selectMultiple.removeChoice(curr); - return prev; - } - // Select last item - else return last; - break; - case KEY.DELETE: - // Remove selected item and select next item - if(~$selectMultiple.activeMatchIndex){ - $selectMultiple.removeChoice($selectMultiple.activeMatchIndex); - return curr; - } - else return false; - } + $select.searchInput.on('blur', function () { + $timeout(function () { + $selectMultiple.activeMatchIndex = -1; + }); + }); + } + }; +}]); - newIndex = getNewActiveMatchIndex(); +uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $compile) { + return { + restrict: 'EA', + require: ['^uiSelect', '^ngModel'], + link: function (scope, element, attrs, ctrls) { + + var $select = ctrls[0]; + var ngModel = ctrls[1]; + + //From view --> model + ngModel.$parsers.unshift(function (inputValue) { + var locals = {}, + result; + locals[$select.parserResult.itemName] = inputValue; + result = $select.parserResult.modelMapper(scope, locals); + return result; + }); - if(!$select.selected.length || newIndex === false) $selectMultiple.activeMatchIndex = -1; - else $selectMultiple.activeMatchIndex = Math.min(last,Math.max(first,newIndex)); + //From model --> view + ngModel.$formatters.unshift(function (inputValue) { + var data = $select.parserResult.source(scope, {$select: {search: ''}}), //Overwrite $search + locals = {}, + result; + if (data) { + var checkFnSingle = function (d) { + locals[$select.parserResult.itemName] = d; + result = $select.parserResult.modelMapper(scope, locals); + return result == inputValue; + }; + //If possible pass same object stored in $select.selected + if ($select.selected && checkFnSingle($select.selected)) { + return $select.selected; + } + for (var i = data.length - 1; i >= 0; i--) { + if (checkFnSingle(data[i])) { + return data[i]; + } + } + } + return inputValue; + }); - return true; - } + //Update viewValue if model change + scope.$watch('$select.selected', function (newValue) { + if (ngModel.$viewValue !== newValue) { + ngModel.$setViewValue(newValue); + } + }); - $select.searchInput.on('blur', function() { - $timeout(function() { - $selectMultiple.activeMatchIndex = -1; - }); - }); + ngModel.$render = function () { + $select.selected = ngModel.$viewValue; + }; - } - }; -}]); + scope.$on('uis:select', function (event, item) { + $select.selected = item; + }); -uis.directive('uiSelectSingle', ['$timeout','$compile', function($timeout, $compile) { - return { - restrict: 'EA', - require: ['^uiSelect', '^ngModel'], - link: function(scope, element, attrs, ctrls) { - - var $select = ctrls[0]; - var ngModel = ctrls[1]; - - //From view --> model - ngModel.$parsers.unshift(function (inputValue) { - var locals = {}, - result; - locals[$select.parserResult.itemName] = inputValue; - result = $select.parserResult.modelMapper(scope, locals); - return result; - }); - - //From model --> view - ngModel.$formatters.unshift(function (inputValue) { - var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search - locals = {}, - result; - if (data){ - var checkFnSingle = function(d){ - locals[$select.parserResult.itemName] = d; - result = $select.parserResult.modelMapper(scope, locals); - return result == inputValue; - }; - //If possible pass same object stored in $select.selected - if ($select.selected && checkFnSingle($select.selected)) { - return $select.selected; - } - for (var i = data.length - 1; i >= 0; i--) { - if (checkFnSingle(data[i])) return data[i]; - } - } - return inputValue; - }); + scope.$on('uis:close', function (event, skipFocusser) { + $timeout(function () { + $select.focusser.prop('disabled', false); + if (!skipFocusser) $select.focusser[0].focus(); + }, 0, false); + }); - //Update viewValue if model change - scope.$watch('$select.selected', function(newValue) { - if (ngModel.$viewValue !== newValue) { - ngModel.$setViewValue(newValue); - } - }); - - ngModel.$render = function() { - $select.selected = ngModel.$viewValue; - }; - - scope.$on('uis:select', function (event, item) { - $select.selected = item; - }); - - scope.$on('uis:close', function (event, skipFocusser) { - $timeout(function(){ - $select.focusser.prop('disabled', false); - if (!skipFocusser) $select.focusser[0].focus(); - },0,false); - }); - - scope.$on('uis:activate', function () { - focusser.prop('disabled', true); //Will reactivate it on .close() - }); - - //Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954 - var focusser = angular.element(""); - $compile(focusser)(scope); - $select.focusser = focusser; - - //Input that will handle focus - $select.focusInput = focusser; - - element.parent().append(focusser); - focusser.bind("focus", function(){ - scope.$evalAsync(function(){ - $select.focus = true; - }); - }); - focusser.bind("blur", function(){ - scope.$evalAsync(function(){ - $select.focus = false; - }); - }); - focusser.bind("keydown", function(e){ - - if (e.which === KEY.BACKSPACE) { - e.preventDefault(); - e.stopPropagation(); - $select.select(undefined); - scope.$apply(); - return; - } + scope.$on('uis:activate', function () { + focusser.prop('disabled', true); //Will reactivate it on .close() + }); - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) { - return; - } + //Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954 + var focusser = angular.element(""); + $compile(focusser)(scope); + $select.focusser = focusser; - if (e.which == KEY.DOWN || e.which == KEY.UP || e.which == KEY.ENTER || e.which == KEY.SPACE){ - e.preventDefault(); - e.stopPropagation(); - $select.activate(); - } + //Input that will handle focus + $select.focusInput = focusser; - scope.$digest(); - }); + element.parent().append(focusser); + focusser.bind("focus", function () { + scope.$evalAsync(function () { + $select.focus = true; + }); + }); + focusser.bind("blur", function () { + scope.$evalAsync(function () { + $select.focus = false; + }); + }); + focusser.bind("keydown", function (e) { - focusser.bind("keyup input", function(e){ + if (e.which === KEY.BACKSPACE) { + e.preventDefault(); + e.stopPropagation(); + $select.select(undefined); + scope.$apply(); + return; + } - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { - return; - } + if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) { + return; + } - $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input - focusser.val(''); - scope.$digest(); + if (e.which == KEY.DOWN || e.which == KEY.UP || e.which == KEY.ENTER || e.which == KEY.SPACE) { + e.preventDefault(); + e.stopPropagation(); + $select.activate(); + } - }); + scope.$digest(); + }); + focusser.bind("keyup input", function (e) { - } - }; + if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || + e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { + return; + } + + $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input + focusser.val(''); + scope.$digest(); + }); + } + }; }]); /** * Parses "repeat" attribute. @@ -1472,45 +1609,46 @@ uis.directive('uiSelectSingle', ['$timeout','$compile', function($timeout, $comp * https://github.com/angular-ui/ui-select/commit/5dd63ad#commitcomment-5504697 */ -uis.service('uisRepeatParser', ['uiSelectMinErr','$parse', function(uiSelectMinErr, $parse) { - var self = this; +uis.service('uisRepeatParser', ['uiSelectMinErr', '$parse', function (uiSelectMinErr, $parse) { + var self = this; - /** - * Example: - * expression = "address in addresses | filter: {street: $select.search} track by $index" - * itemName = "address", - * source = "addresses | filter: {street: $select.search}", - * trackByExp = "$index", - */ - self.parse = function(expression) { + /** + * Example: + * expression = "address in addresses | filter: {street: $select.search} track by $index" + * itemName = "address", + * source = "addresses | filter: {street: $select.search}", + * trackByExp = "$index", + */ + self.parse = function (expression) { - var match = expression.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/); + var match = expression.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/); - if (!match) { - throw uiSelectMinErr('iexp', "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.", - expression); - } + if (!match) { + throw uiSelectMinErr('iexp', + "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.", + expression); + } - return { - itemName: match[2], // (lhs) Left-hand side, - source: $parse(match[3]), - trackByExp: match[4], - modelMapper: $parse(match[1] || match[2]) - }; + return { + itemName: match[2], // (lhs) Left-hand side, + source: $parse(match[3]), + trackByExp: match[4], + modelMapper: $parse(match[1] || match[2]) + }; - }; + }; - self.getGroupNgRepeatExpression = function() { - return '$group in $select.groups'; - }; + self.getGroupNgRepeatExpression = function () { + return '$group in $select.groups'; + }; - self.getNgRepeatExpression = function(itemName, source, trackByExp, grouped) { - var expression = itemName + ' in ' + (grouped ? '$group.items' : source); - if (trackByExp) { - expression += ' track by ' + trackByExp; - } - return expression; - }; + self.getNgRepeatExpression = function (itemName, source, trackByExp, grouped) { + var expression = itemName + ' in ' + (grouped ? '$group.items' : source); + if (trackByExp) { + expression += ' track by ' + trackByExp; + } + return expression; + }; }]); }()); diff --git a/dist/select.min.css b/dist/select.min.css index bcb84cd02..c53af1ab1 100644 --- a/dist/select.min.css +++ b/dist/select.min.css @@ -1,6 +1,6 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-02T20:56:31.552Z + * Version: 0.12.1 - 2015-08-04T17:24:10.107Z * License: MIT - */.ui-select-highlight{font-weight:700}.ui-select-offscreen{clip:rect(0 0 0 0)!important;width:1px!important;height:1px!important;border:0!important;margin:0!important;padding:0!important;overflow:hidden!important;position:absolute!important;outline:0!important;left:0!important;top:0!important}.ng-dirty.ng-invalid>a.select2-choice{border-color:#D44950}.select2-result-single{padding-left:0}.select-locked>.ui-select-match-close,.select2-locked>.select2-search-choice-close{display:none}body>.select2-container.open{z-index:9999}.ui-select-container[theme=select2].direction-up .ui-select-match{border-radius:0 0 4px 4px}.ui-select-container[theme=select2].direction-up .ui-select-dropdown{border-radius:4px 4px 0 0;border-top-width:1px;border-top-style:solid;box-shadow:0 -4px 8px rgba(0,0,0,.25);margin-top:-4px}.ui-select-container[theme=select2].direction-up .ui-select-dropdown .select2-search{margin-top:4px}.ui-select-container[theme=select2].direction-up.select2-dropdown-open .ui-select-match{border-bottom-color:#5897fb}.selectize-input.selectize-focus{border-color:#007FBB!important}.selectize-control>.selectize-dropdown,.selectize-control>.selectize-input>input{width:100%}.ng-dirty.ng-invalid>div.selectize-input{border-color:#D44950}.ui-select-container[theme=selectize].direction-up .ui-select-dropdown{box-shadow:0 -4px 8px rgba(0,0,0,.25);margin-top:-2px}.btn-default-focus{color:#333;background-color:#EBEBEB;border-color:#ADADAD;text-decoration:none;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.ui-select-bootstrap .ui-select-toggle{position:relative}.ui-select-bootstrap .ui-select-toggle>.caret{position:absolute;height:10px;top:50%;right:10px;margin-top:-2px}.input-group>.ui-select-bootstrap.dropdown{position:static}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control{border-radius:4px 0 0 4px}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control.direction-up{border-radius:4px 0 0 4px!important}.ui-select-bootstrap>.ui-select-match>.btn{text-align:left!important}.ui-select-bootstrap>.ui-select-match>.caret{position:absolute;top:45%;right:15px}.ui-select-bootstrap>.ui-select-choices{width:100%;height:auto;max-height:200px;overflow-x:hidden;margin-top:-1px}body>.ui-select-bootstrap.open{z-index:1000}.ui-select-multiple.ui-select-bootstrap{height:auto;padding:3px 3px 0}.ui-select-multiple.ui-select-bootstrap input.ui-select-search{background-color:transparent!important;border:none;outline:0;height:1.666666em;margin-bottom:3px}.ui-select-multiple.ui-select-bootstrap .ui-select-match .close{font-size:1.6em;line-height:.75}.ui-select-multiple.ui-select-bootstrap .ui-select-match-item{outline:0;margin:0 3px 3px 0}.ui-select-multiple .ui-select-match-item{position:relative}.ui-select-multiple .ui-select-match-item.dropping-before:before{content:"";position:absolute;top:0;right:100%;height:100%;margin-right:2px;border-left:1px solid #428bca}.ui-select-multiple .ui-select-match-item.dropping-after:after{content:"";position:absolute;top:0;left:100%;height:100%;margin-left:2px;border-right:1px solid #428bca}.ui-select-bootstrap .ui-select-placeholder{opacity:1;color:#999}.ui-select-bootstrap .ui-select-choices-row>a{display:block;padding:3px 20px;clear:both;font-weight:400;line-height:1.42857143;color:#333;white-space:nowrap}.ui-select-bootstrap .ui-select-choices-row>a:focus,.ui-select-bootstrap .ui-select-choices-row>a:hover{text-decoration:none;color:#262626;background-color:#f5f5f5}.ui-select-bootstrap .ui-select-choices-row.active>a{color:#fff;text-decoration:none;outline:0;background-color:#428bca}.ui-select-bootstrap .ui-select-choices-row.active.disabled>a,.ui-select-bootstrap .ui-select-choices-row.disabled>a{color:#777;cursor:not-allowed;background-color:#fff}.ui-select-match.ng-hide-add,.ui-select-search.ng-hide-add{display:none!important}.ui-select-bootstrap.ng-dirty.ng-invalid>button.btn.ui-select-match{border-color:#D44950}.ui-select-container[theme=bootstrap].direction-up .ui-select-dropdown{box-shadow:0 -4px 8px rgba(0,0,0,.25)} \ No newline at end of file + */.ui-select-highlight{font-weight:700}.ui-select-offscreen{clip:rect(0 0 0 0)!important;width:1px!important;height:1px!important;border:0!important;margin:0!important;padding:0!important;overflow:hidden!important;position:absolute!important;outline:0!important;left:0!important;top:0!important}.ng-dirty.ng-invalid>a.select2-choice{border-color:#D44950}.select2-result-single{padding-left:0}.select-locked>.ui-select-match-close,.select2-locked>.select2-search-choice-close{display:none}body>.select2-container.open{z-index:9999}.ui-select-container[theme=select2].direction-up .ui-select-match{border-radius:0 0 4px 4px}.ui-select-container[theme=select2].direction-up .ui-select-dropdown{bottom:100%;top:auto;position:absolute;border-radius:4px 4px 0 0;border-top-width:1px;border-top-style:solid;box-shadow:0 -4px 8px rgba(0,0,0,.25);margin-top:-4px}.ui-select-container[theme=select2].direction-up .ui-select-dropdown .select2-search{margin-top:4px}.ui-select-container[theme=select2].direction-up.select2-dropdown-open .ui-select-match{border-bottom-color:#5897fb}.selectize-input.selectize-focus{border-color:#007FBB!important}.selectize-control>.selectize-dropdown,.selectize-control>.selectize-input>input{width:100%}.ng-dirty.ng-invalid>div.selectize-input{border-color:#D44950}.ui-select-container[theme=selectize].direction-up .ui-select-dropdown{bottom:100%;top:auto;position:absolute;box-shadow:0 -4px 8px rgba(0,0,0,.25);margin-top:-2px}.btn-default-focus{color:#333;background-color:#EBEBEB;border-color:#ADADAD;text-decoration:none;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.ui-select-bootstrap .ui-select-toggle{position:relative}.ui-select-bootstrap .ui-select-toggle>.caret{position:absolute;height:10px;top:50%;right:10px;margin-top:-2px}.input-group>.ui-select-bootstrap.dropdown{position:static}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control{border-radius:4px 0 0 4px}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control.direction-up{border-radius:4px 0 0 4px!important}.ui-select-bootstrap>.ui-select-match>.btn{text-align:left!important}.ui-select-bootstrap>.ui-select-match>.caret{position:absolute;top:45%;right:15px}.ui-select-bootstrap>.ui-select-choices{width:100%;height:auto;max-height:200px;overflow-x:hidden;margin-top:-1px}body>.ui-select-bootstrap.open{z-index:1000}.ui-select-multiple.ui-select-bootstrap{height:auto;padding:3px 3px 0}.ui-select-multiple.ui-select-bootstrap input.ui-select-search{background-color:transparent!important;border:none;outline:0;height:1.666666em;margin-bottom:3px}.ui-select-multiple.ui-select-bootstrap .ui-select-match .close{font-size:1.6em;line-height:.75}.ui-select-multiple.ui-select-bootstrap .ui-select-match-item{outline:0;margin:0 3px 3px 0}.ui-select-multiple .ui-select-match-item{position:relative}.ui-select-multiple .ui-select-match-item.dropping-before:before{content:"";position:absolute;top:0;right:100%;height:100%;margin-right:2px;border-left:1px solid #428bca}.ui-select-multiple .ui-select-match-item.dropping-after:after{content:"";position:absolute;top:0;left:100%;height:100%;margin-left:2px;border-right:1px solid #428bca}.ui-select-bootstrap .ui-select-placeholder{opacity:1;color:#999}.ui-select-bootstrap .ui-select-choices-row>a{display:block;padding:3px 20px;clear:both;font-weight:400;line-height:1.42857143;color:#333;white-space:nowrap}.ui-select-bootstrap .ui-select-choices-row>a:focus,.ui-select-bootstrap .ui-select-choices-row>a:hover{text-decoration:none;color:#262626;background-color:#f5f5f5}.ui-select-bootstrap .ui-select-choices-row.active>a{color:#fff;text-decoration:none;outline:0;background-color:#428bca}.ui-select-bootstrap .ui-select-choices-row.active.disabled>a,.ui-select-bootstrap .ui-select-choices-row.disabled>a{color:#777;cursor:not-allowed;background-color:#fff}.ui-select-match.ng-hide-add,.ui-select-search.ng-hide-add{display:none!important}.ui-select-bootstrap.ng-dirty.ng-invalid>button.btn.ui-select-match{border-color:#D44950}.ui-select-container[theme=bootstrap].direction-up .ui-select-dropdown{bottom:100%;top:auto;position:absolute;box-shadow:0 -4px 8px rgba(0,0,0,.25)} \ No newline at end of file diff --git a/dist/select.min.js b/dist/select.min.js index 715a2300b..5dc3376d6 100644 --- a/dist/select.min.js +++ b/dist/select.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-02T20:56:31.549Z + * Version: 0.12.1 - 2015-08-04T17:24:10.105Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],c=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(c.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,c=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",refreshDelay:1e3,closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,l,s){s(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(c){var l=c[0].getBoundingClientRect();return{width:l.width||c.prop("offsetWidth"),height:l.height||c.prop("offsetHeight"),top:l.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:l.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);c.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,c,l){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(s,i){if(!i.repeat)throw c("repeat","Expected 'repeat' expression.");return function(s,i,n,a,r){var o=n.groupBy,u=n.groupFilter;if(a.parseRepeatAttr(n.repeat,o,u),a.disableChoiceExpression=n.uiDisableChoice,a.onHighlightCallback=n.onHighlight,a.refreshOnActive=s.$eval(n.refreshOnActive),o){var d=i.querySelectorAll(".ui-select-choices-group");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",d.length);d.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=i.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(a.parserResult.itemName,"$select.items",a.parserResult.trackByExp,o)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+a.parserResult.itemName+")").attr("ng-click","$select.select("+a.parserResult.itemName+",false,$event)");var h=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==h.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",h.length);h.attr("uis-transclude-append",""),l(i,r)(s),s.$watch("$select.search",function(e){e&&!a.open&&a.multiple&&a.activate(!1,!0),a.activeIndex=0,(!a.refreshOnActive||a.refreshOnActive&&a.refreshIsActive)&&a.refresh(n.refresh)}),s.$watch("$select.refreshIsActive",function(e,t){angular.isUndefined(t)&&e&&a.refresh(n.refresh)});var f=s.$eval(n.refreshDelay);a.refreshDelay=void 0!==f?f:e.refreshDelay}}}}]),c.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,c,l,s,i,n,a,r){function o(){(h.resetSearchInput||void 0===h.resetSearchInput&&r.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var c,l,s=[];for(c=0;c0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:c=!1}return c}function p(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw a("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var l=t[h.activeIndex],s=l.offsetTop+l.clientHeight-e[0].scrollTop,i=e[0].offsetHeight;s>i?e[0].scrollTop+=s-i:s=h.items.length?0:h.activeIndex,h.refreshIsActive=!0,l(function(){h.search=e||h.search,h.searchInput[0].focus()}))},h.findGroupByName=function(e){return h.groups&&h.groups.filter(function(t){return t.name===e})[0]},h.parseRepeatAttr=function(e,c,l){function s(e){var s=t.$eval(c);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(s)?s(e):e[s],c=h.findGroupByName(t);c?c.items.push(e):h.groups.push({name:t,items:[e]})}),l){var i=t.$eval(l);angular.isFunction(i)?h.groups=i(h.groups):angular.isArray(i)&&(h.groups=u(h.groups,i))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function i(e){h.items=e}h.setItemsFn=c?s:i,h.parserResult=n.parse(e),h.isGrouped=!!c,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var c=h.selected;if(h.isEmpty()||angular.isArray(c)&&!c.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var l=e.filter(function(e){return c.indexOf(e)<0});h.setItemsFn(l)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw a("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})};var v;h.refresh=function(e){void 0!==e&&(v&&l.cancel(v),v=l(function(){t.$eval(e)},h.refreshDelay))},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),c=t===h.activeIndex;return c&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),c},h.isDisabled=function(e){if(!h.open)return!1;var t,c=h.items.indexOf(e[h.itemProperty]),l=!1;return c>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[c],l=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=l),l},h.select=function(e,c,s){if(void 0===e||!e._uiSelectChoiceDisabled){if(!h.items&&!h.search)return;if(!e||!e._uiSelectChoiceDisabled){var i=function(){t.$broadcast("uis:select",e),l(function(){h.onSelectCallback(t,a)}),h.closeOnSelect&&h.close(c),s&&"click"===s.type&&(h.clickTriggeredSelect=!0)},n={};n[h.parserResult.itemName]=e;var a={$item:e,$model:h.parserResult.modelMapper(t,n)},r=h.onBeforeSelectCallback(t,a);if(angular.isDefined(r)){if(!r)return;angular.isFunction(r.then)?r.then(function(e){e&&i(e)}):r===!0?i(e):i(r)}else i(e)}}},h.close=function(e){h.open&&(h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),o(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e))},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),l(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var c,l=h.selected[t];return l&&!angular.isUndefined(h.lockChoiceExpression)&&(c=!!e.$eval(h.lockChoiceExpression),l._uiSelectChoiceLocked=c),c};var g=null;h.sizeSearchInput=function(){var e=h.searchInput[0],c=h.searchInput.parent().parent()[0],s=function(){return c.clientWidth*!!e.offsetParent},i=function(t){if(0===t)return!1;var c=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>c&&(c=t),h.searchInput.css("width",c+"px"),!0};h.searchInput.css("width","10px"),l(function(){null!==g||i(s())||(g=t.$watch(s,function(e){i(e)&&(g(),g=null)}))})},h.searchInput.on("keydown",function(c){var l=c.which;t.$apply(function(){d(l)}),e.isVerticalMovement(l)&&h.items.length>0&&p(),(l===e.ENTER||l===e.ESC)&&(c.preventDefault(),c.stopPropagation())}),h.searchInput.on("keyup",function(c){c.which===e.TAB||e.isControl(c)||e.isFunctionKey(c)||c.which===e.ESC||e.isVerticalMovement(c.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:c})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),c.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,c,l,s,i,n){return{restrict:"EA",templateUrl:function(e,c){var l=c.theme||t.theme;return l+(angular.isDefined(c.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(s,a){return angular.isDefined(a.multiple)?s.append("").removeAttr("multiple"):s.append(""),function(s,a,r,o,u){function d(e){if(f.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(a[0],e.target):a[0].contains(e.target),!t&&!f.clickTriggeredSelect){var c=["input","button","textarea"],l=angular.element(e.target).scope(),i=l&&l.$select&&l.$select!==f;i||(i=~c.indexOf(e.target.tagName.toLowerCase())),f.close(i),s.$digest()}f.clickTriggeredSelect=!1}}function p(){var t=l(a);b=angular.element('
    '),b[0].style.width=t.width+"px",b[0].style.height=t.height+"px",a.after(b),w=a[0].style.width,e.find("body").append(a),a[0].style.position="absolute",a[0].style.left=t.left+"px",a[0].style.top=t.top+"px",a[0].style.width=t.width+"px"}function h(){null!==b&&(b.replaceWith(a),b=null,a[0].style.position="",a[0].style.left="",a[0].style.top="",a[0].style.width=w)}var f=o[0],v=o[1];f.generatedId=t.generateId(),f.baseTitle=r.title||"Select box",f.focusserTitle=f.baseTitle+" focus",f.focusserId="focusser-"+f.generatedId,f.closeOnSelect=function(){return angular.isDefined(r.closeOnSelect)?i(r.closeOnSelect)():t.closeOnSelect}(),f.onBeforeSelectCallback=i(r.onBeforeSelect),f.onSelectCallback=i(r.onSelect),f.onRemoveCallback=i(r.onRemove),f.onKeypressCallback=i(r.onKeypress),f.limit=angular.isDefined(r.limit)?parseInt(r.limit,10):void 0,f.ngModel=v,f.choiceGrouped=function(e){return f.isGrouped&&e&&e.name},r.tabindex&&r.$observe("tabindex",function(e){f.focusInput.attr("tabindex",e),a.removeAttr("tabindex")});var g=s.$eval(r.searchEnabled);f.searchEnabled=void 0!==g?g:t.searchEnabled;var m=s.$eval(r.sortable);f.sortable=void 0!==m?m:t.sortable,r.$observe("disabled",function(){f.disabled=void 0!==r.disabled?r.disabled:!1}),r.$observe("resetSearchInput",function(){var e=s.$eval(r.resetSearchInput);f.resetSearchInput=void 0!==e?e:!0}),angular.isDefined(r.autofocus)&&n(function(){f.setFocus()}),angular.isDefined(r.focusOn)&&s.$on(r.focusOn,function(){n(function(){f.setFocus()})}),e.on("click",d),s.$on("$destroy",function(){e.off("click",d)}),u(s,function(e){var t=angular.element("
    ").append(e),l=t.querySelectorAll(".ui-select-match");if(l.removeAttr("ui-select-match"),l.removeAttr("data-ui-select-match"),1!==l.length)throw c("transcluded","Expected 1 .ui-select-match but got '{0}'.",l.length);a.querySelectorAll(".ui-select-match").replaceWith(l);var s=t.querySelectorAll(".ui-select-choices");if(s.removeAttr("ui-select-choices"),s.removeAttr("data-ui-select-choices"),1!==s.length)throw c("transcluded","Expected 1 .ui-select-choices but got '{0}'.",s.length);a.querySelectorAll(".ui-select-choices").replaceWith(s)});var $=s.$eval(r.appendToBody);(void 0!==$?$:t.appendToBody)&&(s.$watch("$select.open",function(e){e?p():h()}),s.$on("$destroy",function(){h()}));var b=null,w="",E=null,x="direction-up";s.$watch("$select.open",function(t){if(t){if(E=angular.element(a).querySelectorAll(".ui-select-dropdown"),null===E)return;E[0].style.opacity=0,n(function(){var t=l(a),c=l(E);t.top+t.height+c.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&(E[0].style.position="absolute",E[0].style.top=-1*c.height+"px",a.addClass(x)),E[0].style.opacity=1})}else{if(null===E)return;E[0].style.position="",E[0].style.top="",a.removeClass(x)}})}}}}]),c.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,l=t.parent().attr("multiple");return c+(l?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,l,s){function i(e){s.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}s.lockChoiceExpression=l.uiLockChoice,l.$observe("placeholder",function(t){s.placeholder=void 0!==t?t:e.placeholder}),l.$observe("allowClear",i),i(l.allowClear),s.multiple&&s.sizeSearchInput()}}}]),c.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var c,l=this,s=e.$select;e.$evalAsync(function(){c=e.ngModel}),l.activeMatchIndex=-1,l.updateModel=function(){c.$setViewValue(Date.now()),l.refreshComponent()},l.refreshComponent=function(){s.refreshItems(),s.sizeSearchInput()},l.removeChoice=function(c){var i=s.selected[c];if(!i._uiSelectChoiceLocked){var n={};n[s.parserResult.itemName]=i,s.selected.splice(c,1),l.activeMatchIndex=-1,s.sizeSearchInput(),t(function(){s.onRemoveCallback(e,{$item:i,$model:s.parserResult.modelMapper(e,n)})}),l.updateModel()}},l.getPlaceholder=function(){return s.selected&&s.selected.length?void 0:s.placeholder}}],controllerAs:"$selectMultiple",link:function(l,s,i,n){function a(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function r(t){function c(){switch(t){case e.LEFT:return~d.activeMatchIndex?p:n;case e.RIGHT:return~d.activeMatchIndex&&r!==n?u:(o.activate(),!1);case e.BACKSPACE:return~d.activeMatchIndex?(d.removeChoice(r),p):n;case e.DELETE:return~d.activeMatchIndex?(d.removeChoice(d.activeMatchIndex),r):!1}}var l=a(o.searchInput[0]),s=o.selected.length,i=0,n=s-1,r=d.activeMatchIndex,u=d.activeMatchIndex+1,p=d.activeMatchIndex-1,h=r;return l>0||o.search.length&&t==e.RIGHT?!1:(o.close(),h=c(),d.activeMatchIndex=o.selected.length&&h!==!1?Math.min(n,Math.max(i,h)):-1,!0)}var o=n[0],u=l.ngModel=n[1],d=l.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,u.$parsers.unshift(function(){for(var e,t={},c=[],s=o.selected.length-1;s>=0;s--)t={},t[o.parserResult.itemName]=o.selected[s],e=o.parserResult.modelMapper(l,t),c.unshift(e);return c}),u.$formatters.unshift(function(e){var t,c=o.parserResult.source(l,{$select:{search:""}}),s={};if(!c)return e;var i=[],n=function(e,c){if(e&&e.length){for(var n=e.length-1;n>=0;n--){if(s[o.parserResult.itemName]=e[n],t=o.parserResult.modelMapper(l,s),o.parserResult.trackByExp){var a=/\.(.+)/.exec(o.parserResult.trackByExp);if(a.length>0&&t[a[1]]==c[a[1]])return i.unshift(e[n]),!0}if(angular.equals(t,c))return i.unshift(e[n]),!0}return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(o.selected,e[a])||n(c,e[a])||i.unshift(e[a]);return i}),l.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,d.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);o.selected=[]}o.selected=u.$viewValue,l.$evalAsync()},l.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),d.updateModel())}),l.$on("uis:activate",function(){d.activeMatchIndex=-1}),l.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(t){var c=t.which;l.$apply(function(){var t=!1;e.isHorizontalMovement(c)&&(t=r(c)),t&&c!=e.TAB})}),o.searchInput.on("blur",function(){c(function(){d.activeMatchIndex=-1})})}}}]),c.directive("uiSelectSingle",["$timeout","$compile",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(l,s,i,n){var a=n[0],r=n[1];r.$parsers.unshift(function(e){var t,c={};return c[a.parserResult.itemName]=e,t=a.parserResult.modelMapper(l,c)}),r.$formatters.unshift(function(e){var t,c=a.parserResult.source(l,{$select:{search:""}}),s={};if(c){var i=function(c){return s[a.parserResult.itemName]=c,t=a.parserResult.modelMapper(l,s),t==e};if(a.selected&&i(a.selected))return a.selected;for(var n=c.length-1;n>=0;n--)if(i(c[n]))return c[n]}return e}),l.$watch("$select.selected",function(e){r.$viewValue!==e&&r.$setViewValue(e)}),r.$render=function(){a.selected=r.$viewValue},l.$on("uis:select",function(e,t){a.selected=t}),l.$on("uis:close",function(e,c){t(function(){a.focusser.prop("disabled",!1),c||a.focusser[0].focus()},0,!1)}),l.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");c(o)(l),a.focusser=o,a.focusInput=o,s.parent().append(o),o.bind("focus",function(){l.$evalAsync(function(){a.focus=!0})}),o.bind("blur",function(){l.$evalAsync(function(){a.focus=!1})}),o.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),a.select(void 0),l.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),a.activate()),l.$digest()),void 0)}),o.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(a.activate(o.val()),o.val(""),l.$digest())})}}}]),c.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var l=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!l)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:l[2],source:t(l[3]),trackByExp:l[4],modelMapper:t(l[1]||l[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,l){var s=e+" in "+(l?"$group.items":t);return c&&(s+=" track by "+c),s}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("selectize/choices.tpl.html",'
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",'
    {{$select.placeholder}}
    '),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",'')}]),angular.module("ui.select").run(["$templateCache",function(e){e.put("select2/choices.tpl.html",'
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    ')}]); \ No newline at end of file +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],c=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(c.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,c=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,l,s){s(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(c){var l=c[0].getBoundingClientRect();return{width:l.width||c.prop("offsetWidth"),height:l.height||c.prop("offsetHeight"),top:l.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:l.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);c.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,c,l){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(e,s){if(!s.repeat)throw c("repeat","Expected 'repeat' expression.");return function(e,s,i,n,a){var r=i.groupBy,o=i.groupFilter;if(n.parseRepeatAttr(i.repeat,r,o),n.disableChoiceExpression=i.uiDisableChoice,n.onHighlightCallback=i.onHighlight,r){var u=s.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=s.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(n.parserResult.itemName,"$select.items",n.parserResult.trackByExp,r)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+n.parserResult.itemName+")").attr("ng-click","$select.select("+n.parserResult.itemName+",false,$event)");var p=s.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),l(s,a)(e),e.$watch("$select.search",function(e){e&&!n.open&&n.multiple&&n.activate(!1,!0),n.activeIndex=0})}}}}]),c.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,c,l,s,i,n,a,r){function o(){(h.resetSearchInput||void 0===h.resetSearchInput&&r.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var c,l,s=[];for(c=0;c0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:c=!1}return c}function p(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw a("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var l=t[h.activeIndex],s=l.offsetTop+l.clientHeight-e[0].scrollTop,i=e[0].offsetHeight;s>i?e[0].scrollTop+=s-i:s=h.items.length?0:h.activeIndex,l(function(){h.search=e||h.search,h.searchInput[0].focus()}))},h.parseRepeatAttr=function(e,c,l){function s(e){var s=t.$eval(c);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(s)?s(e):e[s],c=h.findGroupByName(t);c?c.items.push(e):h.groups.push({name:t,items:[e]})}),l){var i=t.$eval(l);angular.isFunction(i)?h.groups=i(h.groups):angular.isArray(i)&&(h.groups=u(h.groups,i))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function i(e){h.items=e}h.setItemsFn=c?s:i,h.parserResult=n.parse(e),h.isGrouped=!!c,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var c=h.selected;if(h.isEmpty()||angular.isArray(c)&&!c.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var l=e.filter(function(e){return c.indexOf(e)<0});h.setItemsFn(l)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw a("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),c=t===h.activeIndex;return c&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),c},h.isDisabled=function(e){if(!h.open)return!1;var t,c=h.items.indexOf(e[h.itemProperty]),l=!1;return c>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[c],l=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=l),l},h.select=function(e,c,s){if((void 0===e||!e._uiSelectChoiceDisabled)&&(h.items||h.search)){var i={};i[h.parserResult.itemName]=e;var n={$item:e,$model:h.parserResult.modelMapper(t,i)},a=function(){t.$broadcast("uis:select",e),l(function(){h.onSelectCallback(t,n)}),h.closeOnSelect&&h.close(c),s&&"click"===s.type&&(h.clickTriggeredSelect=!0)},r=h.onBeforeSelectCallback(t,n);angular.isDefined(r)?angular.isFunction(r.then)?r.then(function(e){e&&a(e)}):r===!0?a(e):r&&a(r):a(e)}},h.close=function(e){h.open&&(h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),o(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e))},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),l(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var c,l=h.selected[t];return l&&!angular.isUndefined(h.lockChoiceExpression)&&(c=!!e.$eval(h.lockChoiceExpression),l._uiSelectChoiceLocked=c),c};var g=null;h.sizeSearchInput=function(){var e=h.searchInput[0],c=h.searchInput.parent().parent()[0],s=function(){return c.clientWidth*!!e.offsetParent},i=function(t){if(0===t)return!1;var c=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>c&&(c=t),h.searchInput.css("width",c+"px"),!0};h.searchInput.css("width","10px"),l(function(){null!==g||i(s())||(g=t.$watch(s,function(e){i(e)&&(g(),g=null)}))})},h.searchInput.on("keydown",function(c){var l=c.which;t.$apply(function(){d(l)}),e.isVerticalMovement(l)&&h.items.length>0&&p(),(l===e.ENTER||l===e.ESC)&&(c.preventDefault(),c.stopPropagation())}),h.searchInput.on("keyup",function(c){c.which===e.TAB||e.isControl(c)||e.isFunctionKey(c)||c.which===e.ESC||e.isVerticalMovement(c.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:c})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),c.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,c,l,s,i,n){return{restrict:"EA",templateUrl:function(e,c){var l=c.theme||t.theme;return l+(angular.isDefined(c.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(s,a){return angular.isDefined(a.multiple)?s.append("").removeAttr("multiple"):s.append(""),function(s,a,r,o,u){function d(e){if(f.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(a[0],e.target):a[0].contains(e.target),!t&&!f.clickTriggeredSelect){var c=["input","button","textarea"],l=angular.element(e.target).scope(),i=l&&l.$select&&l.$select!==f;i||(i=~c.indexOf(e.target.tagName.toLowerCase())),f.close(i),s.$digest()}f.clickTriggeredSelect=!1}}function p(){var t=l(a);b=angular.element('
    '),b[0].style.width=t.width+"px",b[0].style.height=t.height+"px",a.after(b),w=a[0].style.width,e.find("body").append(a),a[0].style.position="absolute",a[0].style.left=t.left+"px",a[0].style.top=t.top+"px",a[0].style.width=t.width+"px"}function h(){null!==b&&(b.replaceWith(a),b=null,a[0].style.position="",a[0].style.left="",a[0].style.top="",a[0].style.width=w)}var f=o[0],g=o[1];f.generatedId=t.generateId(),f.baseTitle=r.title||"Select box",f.focusserTitle=f.baseTitle+" focus",f.focusserId="focusser-"+f.generatedId,f.closeOnSelect=function(){return angular.isDefined(r.closeOnSelect)?i(r.closeOnSelect)():t.closeOnSelect}(),f.onSelectCallback=i(r.onSelect),f.onBeforeSelectCallback=i(r.onBeforeSelect),f.onRemoveCallback=i(r.onRemove),f.onBeforeRemoveCallback=i(r.onBeforeRemove),f.onKeypressCallback=i(r.onKeypress),f.limit=angular.isDefined(r.limit)?parseInt(r.limit,10):void 0,f.ngModel=g,f.choiceGrouped=function(e){return f.isGrouped&&e&&e.name},r.tabindex&&r.$observe("tabindex",function(e){f.focusInput.attr("tabindex",e),a.removeAttr("tabindex")});var v=s.$eval(r.searchEnabled);f.searchEnabled=void 0!==v?v:t.searchEnabled;var m=s.$eval(r.sortable);f.sortable=void 0!==m?m:t.sortable,r.$observe("disabled",function(){f.disabled=void 0!==r.disabled?r.disabled:!1}),angular.isDefined(r.autofocus)&&n(function(){f.setFocus()}),angular.isDefined(r.focusOn)&&s.$on(r.focusOn,function(){n(function(){f.setFocus()})}),e.on("click",d),s.$on("$destroy",function(){e.off("click",d)}),u(s,function(e){var t=angular.element("
    ").append(e),l=t.querySelectorAll(".ui-select-match");if(l.removeAttr("ui-select-match"),l.removeAttr("data-ui-select-match"),1!==l.length)throw c("transcluded","Expected 1 .ui-select-match but got '{0}'.",l.length);a.querySelectorAll(".ui-select-match").replaceWith(l);var s=t.querySelectorAll(".ui-select-choices");if(s.removeAttr("ui-select-choices"),s.removeAttr("data-ui-select-choices"),1!==s.length)throw c("transcluded","Expected 1 .ui-select-choices but got '{0}'.",s.length);a.querySelectorAll(".ui-select-choices").replaceWith(s)});var $=s.$eval(r.appendToBody);(void 0!==$?$:t.appendToBody)&&(s.$watch("$select.open",function(e){e?p():h()}),s.$on("$destroy",function(){h()}));var b=null,w="",E=null,x="direction-up";s.$watch("$select.open",function(t){if(t){if(E=angular.element(a).querySelectorAll(".ui-select-dropdown"),null===E)return;E[0].style.opacity=0,n(function(){var t=l(a),c=l(E);t.top+t.height+c.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&a.addClass(x),E[0].style.opacity=1})}else{if(null===E)return;a.removeClass(x)}})}}}}]),c.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,l=t.parent().attr("multiple");return c+(l?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,l,s){function i(e){s.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}s.lockChoiceExpression=l.uiLockChoice,l.$observe("placeholder",function(t){s.placeholder=void 0!==t?t:e.placeholder}),l.$observe("allowClear",i),i(l.allowClear),s.multiple&&s.sizeSearchInput()}}}]),c.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var c,l=this,s=e.$select;e.$evalAsync(function(){c=e.ngModel}),l.activeMatchIndex=-1,l.updateModel=function(){c.$setViewValue(Date.now()),l.refreshComponent()},l.refreshComponent=function(){s.refreshItems(),s.sizeSearchInput()},l.removeChoice=function(c){function i(){t(function(){s.onRemoveCallback(e,r)}),l.updateModel()}var n=s.selected[c];if(!n._uiSelectChoiceLocked){var a={};a[s.parserResult.itemName]=n,s.selected.splice(c,1),l.activeMatchIndex=-1,s.sizeSearchInput();var r={$item:n,$model:s.parserResult.modelMapper(e,a)},o=l.onBeforeRemoveCallback(e,r);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(e){e&&i(e)}):o===!0&&i():i()}},l.getPlaceholder=function(){return s.selected&&s.selected.length?void 0:s.placeholder}}],controllerAs:"$selectMultiple",link:function(l,s,i,n){function a(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function r(t){function c(){switch(t){case e.LEFT:return~d.activeMatchIndex?p:n;case e.RIGHT:return~d.activeMatchIndex&&r!==n?u:(o.activate(),!1);case e.BACKSPACE:return~d.activeMatchIndex?(d.removeChoice(r),p):n;case e.DELETE:return~d.activeMatchIndex?(d.removeChoice(d.activeMatchIndex),r):!1}}var l=a(o.searchInput[0]),s=o.selected.length,i=0,n=s-1,r=d.activeMatchIndex,u=d.activeMatchIndex+1,p=d.activeMatchIndex-1,h=r;return l>0||o.search.length&&t==e.RIGHT?!1:(o.close(),h=c(),d.activeMatchIndex=o.selected.length&&h!==!1?Math.min(n,Math.max(i,h)):-1,!0)}var o=n[0],u=l.ngModel=n[1],d=l.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,u.$parsers.unshift(function(){for(var e,t={},c=[],s=o.selected.length-1;s>=0;s--)t={},t[o.parserResult.itemName]=o.selected[s],e=o.parserResult.modelMapper(l,t),c.unshift(e);return c}),u.$formatters.unshift(function(e){var t,c=o.parserResult.source(l,{$select:{search:""}}),s={};if(!c)return e;var i=[],n=function(e,c){if(e&&e.length){for(var n=e.length-1;n>=0;n--){if(s[o.parserResult.itemName]=e[n],t=o.parserResult.modelMapper(l,s),o.parserResult.trackByExp){var a=/\.(.+)/.exec(o.parserResult.trackByExp);if(a.length>0&&t[a[1]]==c[a[1]])return i.unshift(e[n]),!0}if(angular.equals(t,c))return i.unshift(e[n]),!0}return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(o.selected,e[a])||n(c,e[a])||i.unshift(e[a]);return i}),l.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,d.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);o.selected=[]}o.selected=u.$viewValue,l.$evalAsync()},l.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),d.updateModel())}),l.$on("uis:activate",function(){d.activeMatchIndex=-1}),l.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(t){var c=t.which;l.$apply(function(){var t=!1;e.isHorizontalMovement(c)&&(t=r(c)),t&&c!=e.TAB})}),o.searchInput.on("blur",function(){c(function(){d.activeMatchIndex=-1})})}}}]),c.directive("uiSelectSingle",["$timeout","$compile",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(l,s,i,n){var a=n[0],r=n[1];r.$parsers.unshift(function(e){var t,c={};return c[a.parserResult.itemName]=e,t=a.parserResult.modelMapper(l,c)}),r.$formatters.unshift(function(e){var t,c=a.parserResult.source(l,{$select:{search:""}}),s={};if(c){var i=function(c){return s[a.parserResult.itemName]=c,t=a.parserResult.modelMapper(l,s),t==e};if(a.selected&&i(a.selected))return a.selected;for(var n=c.length-1;n>=0;n--)if(i(c[n]))return c[n]}return e}),l.$watch("$select.selected",function(e){r.$viewValue!==e&&r.$setViewValue(e)}),r.$render=function(){a.selected=r.$viewValue},l.$on("uis:select",function(e,t){a.selected=t}),l.$on("uis:close",function(e,c){t(function(){a.focusser.prop("disabled",!1),c||a.focusser[0].focus()},0,!1)}),l.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");c(o)(l),a.focusser=o,a.focusInput=o,s.parent().append(o),o.bind("focus",function(){l.$evalAsync(function(){a.focus=!0})}),o.bind("blur",function(){l.$evalAsync(function(){a.focus=!1})}),o.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),a.select(void 0),l.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),a.activate()),l.$digest()),void 0)}),o.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(a.activate(o.val()),o.val(""),l.$digest())})}}}]),c.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var l=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!l)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:l[2],source:t(l[3]),trackByExp:l[4],modelMapper:t(l[1]||l[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,l){var s=e+" in "+(l?"$group.items":t);return c&&(s+=" track by "+c),s}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("selectize/choices.tpl.html",'
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",'
    {{$select.placeholder}}
    '),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",'')}]),angular.module("ui.select").run(["$templateCache",function(e){e.put("select2/choices.tpl.html",'
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/dist/select.no-tpl.js b/dist/select.no-tpl.js index ea71b1436..623d024f9 100644 --- a/dist/select.no-tpl.js +++ b/dist/select.no-tpl.js @@ -1,14 +1,13 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-02T20:56:31.493Z + * Version: 0.12.1 - 2015-08-04T17:24:10.054Z * License: MIT */ (function () { "use strict"; - var KEY = { TAB: 9, ENTER: 13, @@ -29,20 +28,123 @@ var KEY = { DELETE: 46, COMMAND: 91, - MAP: { 91 : "COMMAND", 8 : "BACKSPACE" , 9 : "TAB" , 13 : "ENTER" , 16 : "SHIFT" , 17 : "CTRL" , 18 : "ALT" , 19 : "PAUSEBREAK" , 20 : "CAPSLOCK" , 27 : "ESC" , 32 : "SPACE" , 33 : "PAGE_UP", 34 : "PAGE_DOWN" , 35 : "END" , 36 : "HOME" , 37 : "LEFT" , 38 : "UP" , 39 : "RIGHT" , 40 : "DOWN" , 43 : "+" , 44 : "PRINTSCREEN" , 45 : "INSERT" , 46 : "DELETE", 48 : "0" , 49 : "1" , 50 : "2" , 51 : "3" , 52 : "4" , 53 : "5" , 54 : "6" , 55 : "7" , 56 : "8" , 57 : "9" , 59 : ";", 61 : "=" , 65 : "A" , 66 : "B" , 67 : "C" , 68 : "D" , 69 : "E" , 70 : "F" , 71 : "G" , 72 : "H" , 73 : "I" , 74 : "J" , 75 : "K" , 76 : "L", 77 : "M" , 78 : "N" , 79 : "O" , 80 : "P" , 81 : "Q" , 82 : "R" , 83 : "S" , 84 : "T" , 85 : "U" , 86 : "V" , 87 : "W" , 88 : "X" , 89 : "Y" , 90 : "Z", 96 : "0" , 97 : "1" , 98 : "2" , 99 : "3" , 100 : "4" , 101 : "5" , 102 : "6" , 103 : "7" , 104 : "8" , 105 : "9", 106 : "*" , 107 : "+" , 109 : "-" , 110 : "." , 111 : "/", 112 : "F1" , 113 : "F2" , 114 : "F3" , 115 : "F4" , 116 : "F5" , 117 : "F6" , 118 : "F7" , 119 : "F8" , 120 : "F9" , 121 : "F10" , 122 : "F11" , 123 : "F12", 144 : "NUMLOCK" , 145 : "SCROLLLOCK" , 186 : ";" , 187 : "=" , 188 : "," , 189 : "-" , 190 : "." , 191 : "/" , 192 : "`" , 219 : "[" , 220 : "\\" , 221 : "]" , 222 : "'" + MAP: { + 91: "COMMAND", + 8: "BACKSPACE", + 9: "TAB", + 13: "ENTER", + 16: "SHIFT", + 17: "CTRL", + 18: "ALT", + 19: "PAUSEBREAK", + 20: "CAPSLOCK", + 27: "ESC", + 32: "SPACE", + 33: "PAGE_UP", + 34: "PAGE_DOWN", + 35: "END", + 36: "HOME", + 37: "LEFT", + 38: "UP", + 39: "RIGHT", + 40: "DOWN", + 43: "+", + 44: "PRINTSCREEN", + 45: "INSERT", + 46: "DELETE", + 48: "0", + 49: "1", + 50: "2", + 51: "3", + 52: "4", + 53: "5", + 54: "6", + 55: "7", + 56: "8", + 57: "9", + 59: ";", + 61: "=", + 65: "A", + 66: "B", + 67: "C", + 68: "D", + 69: "E", + 70: "F", + 71: "G", + 72: "H", + 73: "I", + 74: "J", + 75: "K", + 76: "L", + 77: "M", + 78: "N", + 79: "O", + 80: "P", + 81: "Q", + 82: "R", + 83: "S", + 84: "T", + 85: "U", + 86: "V", + 87: "W", + 88: "X", + 89: "Y", + 90: "Z", + 96: "0", + 97: "1", + 98: "2", + 99: "3", + 100: "4", + 101: "5", + 102: "6", + 103: "7", + 104: "8", + 105: "9", + 106: "*", + 107: "+", + 109: "-", + 110: ".", + 111: "/", + 112: "F1", + 113: "F2", + 114: "F3", + 115: "F4", + 116: "F5", + 117: "F6", + 118: "F7", + 119: "F8", + 120: "F9", + 121: "F10", + 122: "F11", + 123: "F12", + 144: "NUMLOCK", + 145: "SCROLLLOCK", + 186: ";", + 187: "=", + 188: ",", + 189: "-", + 190: ".", + 191: "/", + 192: "`", + 219: "[", + 220: "\\", + 221: "]", + 222: "'" }, isControl: function (e) { var k = e.which; switch (k) { - case KEY.COMMAND: - case KEY.SHIFT: - case KEY.CTRL: - case KEY.ALT: - return true; + case KEY.COMMAND: + case KEY.SHIFT: + case KEY.CTRL: + case KEY.ALT: + return true; } - if (e.metaKey) return true; + if (e.metaKey) { + return true; + } return false; }, @@ -50,13 +152,13 @@ var KEY = { k = k.which ? k.which : k; return k >= 112 && k <= 123; }, - isVerticalMovement: function (k){ - return ~[KEY.UP, KEY.DOWN].indexOf(k); + isVerticalMovement: function (k) { + return ~[KEY.UP, KEY.DOWN].indexOf(k); }, - isHorizontalMovement: function (k){ - return ~[KEY.LEFT,KEY.RIGHT,KEY.BACKSPACE,KEY.DELETE].indexOf(k); + isHorizontalMovement: function (k) { + return ~[KEY.LEFT, KEY.RIGHT, KEY.BACKSPACE, KEY.DELETE].indexOf(k); } - }; +}; /** * Add querySelectorAll() to jqLite. @@ -68,67 +170,67 @@ var KEY = { * See feat(jqLite): use querySelectorAll instead of getElementsByTagName in jqLite.find https://github.com/angular/angular.js/pull/3598 */ if (angular.element.prototype.querySelectorAll === undefined) { - angular.element.prototype.querySelectorAll = function(selector) { - return angular.element(this[0].querySelectorAll(selector)); - }; + angular.element.prototype.querySelectorAll = function (selector) { + return angular.element(this[0].querySelectorAll(selector)); + }; } /** * Add closest() to jqLite. */ if (angular.element.prototype.closest === undefined) { - angular.element.prototype.closest = function( selector) { - var elem = this[0]; - var matchesSelector = elem.matches || elem.webkitMatchesSelector || elem.mozMatchesSelector || elem.msMatchesSelector; - - while (elem) { - if (matchesSelector.bind(elem)(selector)) { - return elem; - } else { - elem = elem.parentElement; - } - } - return false; - }; + angular.element.prototype.closest = function (selector) { + var elem = this[0]; + var matchesSelector = elem.matches || elem.webkitMatchesSelector || elem.mozMatchesSelector || + elem.msMatchesSelector; + + while (elem) { + if (matchesSelector.bind(elem)(selector)) { + return elem; + } else { + elem = elem.parentElement; + } + } + return false; + }; } var latestId = 0; var uis = angular.module('ui.select', []) -.constant('uiSelectConfig', { - theme: 'bootstrap', - searchEnabled: true, - sortable: false, - placeholder: '', // Empty by default, like HTML tag + closeOnSelect: true, + generateId: function () { + return latestId++; + }, + appendToBody: false + }) // See Rename minErr and make it accessible from outside https://github.com/angular/angular.js/issues/6913 -.service('uiSelectMinErr', function() { - var minErr = angular.$$minErr('ui.select'); - return function() { - var error = minErr.apply(this, arguments); - var message = error.message.replace(new RegExp('\nhttp://errors.angularjs.org/.*'), ''); - return new Error(message); - }; -}) + .service('uiSelectMinErr', function () { + var minErr = angular.$$minErr('ui.select'); + return function () { + var error = minErr.apply(this, arguments); + var message = error.message.replace(new RegExp('\nhttp://errors.angularjs.org/.*'), ''); + return new Error(message); + }; + }) // Recreates old behavior of ng-transclude. Used internally. -.directive('uisTranscludeAppend', function () { - return { - link: function (scope, element, attrs, ctrl, transclude) { - transclude(scope, function (clone) { - element.append(clone); - }); - } - }; -}) + .directive('uisTranscludeAppend', function () { + return { + link: function (scope, element, attrs, ctrl, transclude) { + transclude(scope, function (clone) { + element.append(clone); + }); + } + }; + }) /** * Highlights text that matches $select.search. @@ -136,15 +238,16 @@ var uis = angular.module('ui.select', []) * Taken from AngularUI Bootstrap Typeahead * See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L340 */ -.filter('highlight', function() { - function escapeRegexp(queryToEscape) { - return queryToEscape.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1'); - } + .filter('highlight', function () { + function escapeRegexp(queryToEscape) { + return queryToEscape.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1'); + } - return function(matchItem, query) { - return query && matchItem ? matchItem.replace(new RegExp(escapeRegexp(query), 'gi'), '$&') : matchItem; - }; -}) + return function (matchItem, query) { + return query && matchItem ? matchItem.replace(new RegExp(escapeRegexp(query), 'gi'), + '$&') : matchItem; + }; + }) /** * A read-only equivalent of jQuery's offset function: http://api.jquery.com/offset/ @@ -152,96 +255,92 @@ var uis = angular.module('ui.select', []) * Taken from AngularUI Bootstrap Position: * See https://github.com/angular-ui/bootstrap/blob/master/src/position/position.js#L70 */ -.factory('uisOffset', - ['$document', '$window', - function ($document, $window) { - - return function(element) { - var boundingClientRect = element[0].getBoundingClientRect(); - return { - width: boundingClientRect.width || element.prop('offsetWidth'), - height: boundingClientRect.height || element.prop('offsetHeight'), - top: boundingClientRect.top + ($window.pageYOffset || $document[0].documentElement.scrollTop), - left: boundingClientRect.left + ($window.pageXOffset || $document[0].documentElement.scrollLeft) - }; - }; -}]); + .factory('uisOffset', + ['$document', '$window', + function ($document, $window) { + + return function (element) { + var boundingClientRect = element[0].getBoundingClientRect(); + return { + width: boundingClientRect.width || element.prop('offsetWidth'), + height: boundingClientRect.height || element.prop('offsetHeight'), + top: boundingClientRect.top + ($window.pageYOffset || $document[0].documentElement.scrollTop), + left: boundingClientRect.left + ($window.pageXOffset || $document[0].documentElement.scrollLeft) + }; + }; + }]); uis.directive('uiSelectChoices', - ['uiSelectConfig', 'uisRepeatParser', 'uiSelectMinErr', '$compile', - function(uiSelectConfig, RepeatParser, uiSelectMinErr, $compile) { - - return { - restrict: 'EA', - require: '^uiSelect', - replace: true, - transclude: true, - templateUrl: function(tElement) { - // Gets theme attribute from parent (ui-select) - var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; - return theme + '/choices.tpl.html'; - }, + ['uiSelectConfig', 'uisRepeatParser', 'uiSelectMinErr', '$compile', + function (uiSelectConfig, RepeatParser, uiSelectMinErr, $compile) { - compile: function(tElement, tAttrs) { + return { + restrict: 'EA', + require: '^uiSelect', + replace: true, + transclude: true, + templateUrl: function (tElement) { + // Gets theme attribute from parent (ui-select) + var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; + return theme + '/choices.tpl.html'; + }, - if (!tAttrs.repeat) throw uiSelectMinErr('repeat', "Expected 'repeat' expression."); + compile: function (tElement, tAttrs) { - return function link(scope, element, attrs, $select, transcludeFn) { + if (!tAttrs.repeat) { + throw uiSelectMinErr('repeat', "Expected 'repeat' expression."); + } - // var repeat = RepeatParser.parse(attrs.repeat); - var groupByExp = attrs.groupBy; - var groupFilterExp = attrs.groupFilter; + return function link(scope, element, attrs, $select, transcludeFn) { - $select.parseRepeatAttr(attrs.repeat, groupByExp, groupFilterExp); //Result ready at $select.parserResult + // var repeat = RepeatParser.parse(attrs.repeat); + var groupByExp = attrs.groupBy; + var groupFilterExp = attrs.groupFilter; - $select.disableChoiceExpression = attrs.uiDisableChoice; - $select.onHighlightCallback = attrs.onHighlight; + $select.parseRepeatAttr(attrs.repeat, groupByExp, groupFilterExp); //Result ready at $select.parserResult - $select.refreshOnActive = scope.$eval(attrs.refreshOnActive); + $select.disableChoiceExpression = attrs.uiDisableChoice; + $select.onHighlightCallback = attrs.onHighlight; - if(groupByExp) { - var groups = element.querySelectorAll('.ui-select-choices-group'); - if (groups.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-group but got '{0}'.", groups.length); - groups.attr('ng-repeat', RepeatParser.getGroupNgRepeatExpression()); - } + if (groupByExp) { + var groups = element.querySelectorAll('.ui-select-choices-group'); + if (groups.length !== 1) throw uiSelectMinErr('rows', + "Expected 1 .ui-select-choices-group but got '{0}'.", groups.length); + groups.attr('ng-repeat', RepeatParser.getGroupNgRepeatExpression()); + } - var choices = element.querySelectorAll('.ui-select-choices-row'); - if (choices.length !== 1) { - throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row but got '{0}'.", choices.length); - } + var choices = element.querySelectorAll('.ui-select-choices-row'); + if (choices.length !== 1) { + throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row but got '{0}'.", + choices.length); + } - choices.attr('ng-repeat', RepeatParser.getNgRepeatExpression($select.parserResult.itemName, '$select.items', $select.parserResult.trackByExp, groupByExp)) - .attr('ng-if', '$select.open') //Prevent unnecessary watches when dropdown is closed - .attr('ng-mouseenter', '$select.setActiveItem('+$select.parserResult.itemName +')') - .attr('ng-click', '$select.select(' + $select.parserResult.itemName + ',false,$event)'); - - var rowsInner = element.querySelectorAll('.ui-select-choices-row-inner'); - if (rowsInner.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row-inner but got '{0}'.", rowsInner.length); - rowsInner.attr('uis-transclude-append', ''); //Adding uisTranscludeAppend directive to row element after choices element has ngRepeat - - $compile(element, transcludeFn)(scope); //Passing current transcludeFn to be able to append elements correctly from uisTranscludeAppend - - scope.$watch('$select.search', function(newValue) { - if(newValue && !$select.open && $select.multiple) $select.activate(false, true); - $select.activeIndex = 0; - if(!$select.refreshOnActive || ($select.refreshOnActive && $select.refreshIsActive)) { - $select.refresh(attrs.refresh); - } - }); - - scope.$watch('$select.refreshIsActive', function(newValue, oldValue){ - if(angular.isUndefined(oldValue) && newValue){ - $select.refresh(attrs.refresh); - } - }); - - // $eval() is needed otherwise we get a string instead of a number - var refreshDelay = scope.$eval(attrs.refreshDelay); - $select.refreshDelay = refreshDelay !== undefined ? refreshDelay : uiSelectConfig.refreshDelay; - }; - } - }; -}]); + choices.attr('ng-repeat', + RepeatParser.getNgRepeatExpression($select.parserResult.itemName, '$select.items', + $select.parserResult.trackByExp, groupByExp)) + .attr('ng-if', '$select.open') //Prevent unnecessary watches when dropdown is closed + .attr('ng-mouseenter', '$select.setActiveItem(' + $select.parserResult.itemName + ')') + .attr('ng-click', '$select.select(' + $select.parserResult.itemName + ',false,$event)'); + + var rowsInner = element.querySelectorAll('.ui-select-choices-row-inner'); + if (rowsInner.length !== 1) { + throw uiSelectMinErr('rows', + "Expected 1 .ui-select-choices-row-inner but got '{0}'.", rowsInner.length); + } + rowsInner.attr('uis-transclude-append', ''); //Adding uisTranscludeAppend directive to row element after choices element has ngRepeat + + $compile(element, transcludeFn)(scope); //Passing current transcludeFn to be able to append elements correctly from uisTranscludeAppend + + scope.$watch('$select.search', function (newValue) { + if (newValue && !$select.open && $select.multiple) { + $select.activate(false, true); + } + $select.activeIndex = 0; + }); + }; + } + }; + }]); /** * Contains ui-select "intelligence". @@ -260,7 +359,6 @@ uis.controller('uiSelectCtrl', ctrl.placeholder = uiSelectConfig.placeholder; ctrl.searchEnabled = uiSelectConfig.searchEnabled; ctrl.sortable = uiSelectConfig.sortable; - ctrl.refreshDelay = uiSelectConfig.refreshDelay; ctrl.removeSelected = false; //If selected item(s) should be removed from dropdown list ctrl.closeOnSelect = true; //Initialized inside uiSelect directive link function @@ -281,8 +379,6 @@ uis.controller('uiSelectCtrl', ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelectMatch directive link function ctrl.clickTriggeredSelect = false; ctrl.$filter = $filter; - ctrl.refreshOnActive = undefined; - ctrl.refreshIsActive = undefined; ctrl.searchInput = $element.querySelectorAll('input.ui-select-search'); if (ctrl.searchInput.length !== 1) { @@ -290,6 +386,10 @@ uis.controller('uiSelectCtrl', ctrl.searchInput.length); } + /** + * Returns true if the selection is empty + * @returns {boolean|*} + */ ctrl.isEmpty = function () { return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === ''; }; @@ -305,6 +405,12 @@ uis.controller('uiSelectCtrl', } } + ctrl.findGroupByName = function (name) { + return ctrl.groups && ctrl.groups.filter(function (group) { + return group.name === name; + })[0]; + }; + function _groupsFilter(groups, groupNames) { var i, j, result = []; for (i = 0; i < groupNames.length; i++) { @@ -317,10 +423,15 @@ uis.controller('uiSelectCtrl', return result; } - // When the user clicks on ui-select, displays the dropdown list + /** + * Activates the control. + * When the user clicks on ui-select, displays the dropdown list + */ ctrl.activate = function (initSearchValue, avoidReset) { if (!ctrl.disabled && !ctrl.open) { - if (!avoidReset) _resetSearchInput(); + if (!avoidReset) { + _resetSearchInput(); + } $scope.$broadcast('uis:activate'); @@ -330,7 +441,6 @@ uis.controller('uiSelectCtrl', } ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex; - ctrl.refreshIsActive = true; // Give it time to appear before focus $timeout(function () { @@ -344,12 +454,6 @@ uis.controller('uiSelectCtrl', } }; - ctrl.findGroupByName = function (name) { - return ctrl.groups && ctrl.groups.filter(function (group) { - return group.name === name; - })[0]; - }; - ctrl.parseRepeatAttr = function (repeatAttr, groupByExp, groupFilterExp) { function updateGroups(items) { var groupFn = $scope.$eval(groupByExp); @@ -382,6 +486,7 @@ uis.controller('uiSelectCtrl', ctrl.items = items; } + // Set the function to use when displaying items - either groups or single ctrl.setItemsFn = groupByExp ? updateGroups : setPlainItems; ctrl.parserResult = RepeatParser.parse(repeatAttr); @@ -392,7 +497,7 @@ uis.controller('uiSelectCtrl', ctrl.refreshItems = function (data) { data = data || ctrl.parserResult.source($scope); var selectedItems = ctrl.selected; - //TODO should implement for single mode removeSelected + // TODO should implement for single mode removeSelected if (ctrl.isEmpty() || (angular.isArray(selectedItems) && !selectedItems.length) || !ctrl.removeSelected) { ctrl.setItemsFn(data); @@ -424,35 +529,17 @@ uis.controller('uiSelectCtrl', } } }); - - }; - - var _refreshDelayPromise; - - /** - * Typeahead mode: lets the user refresh the collection using his own function. - * - * See Expose $select.search for external / remote filtering https://github.com/angular-ui/ui-select/pull/31 - */ - ctrl.refresh = function (refreshAttr) { - if (refreshAttr !== undefined) { - - // Debounce - // See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L155 - // FYI AngularStrap typeahead does not have debouncing: https://github.com/mgcrea/angular-strap/blob/v2.0.0-rc.4/src/typeahead/typeahead.js#L177 - if (_refreshDelayPromise) { - $timeout.cancel(_refreshDelayPromise); - } - _refreshDelayPromise = $timeout(function () { - $scope.$eval(refreshAttr); - }, ctrl.refreshDelay); - } }; ctrl.setActiveItem = function (item) { ctrl.activeIndex = ctrl.items.indexOf(item); }; + /** + * Checks if the item is active + * @param itemScope the item + * @returns {boolean} true if active + */ ctrl.isActive = function (itemScope) { if (!ctrl.open) { return false; @@ -469,11 +556,14 @@ uis.controller('uiSelectCtrl', /** * Checks if the item is disabled - * @return boolean true if the item is disabled + * @param itemScope the item + * @return {boolean} true if the item is disabled */ ctrl.isDisabled = function (itemScope) { - if (!ctrl.open) return false; + if (!ctrl.open) { + return false; + } var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); var isDisabled = false; @@ -490,75 +580,81 @@ uis.controller('uiSelectCtrl', /** + * Selects an item + * * Called when the user selects an item with ENTER or clicks the dropdown */ ctrl.select = function (item, skipFocusser, $event) { - if (item === undefined || !item._uiSelectChoiceDisabled) { - - if (!ctrl.items && !ctrl.search){ - return; - } - - if (!item || !item._uiSelectChoiceDisabled) { + if (item !== undefined && item._uiSelectChoiceDisabled) { + return; + } - var completeSelection = function () { - $scope.$broadcast('uis:select', item); + // If no items in the list, and no search, then return + if (!ctrl.items && !ctrl.search) { + return; + } - $timeout(function () { - ctrl.onSelectCallback($scope, callbackContext); - }); + // Create the data used to pass to the callbacks + var locals = {}; + locals[ctrl.parserResult.itemName] = item; + var callbackContext = { + $item: item, + $model: ctrl.parserResult.modelMapper($scope, locals) + }; - if (ctrl.closeOnSelect) { - ctrl.close(skipFocusser); - } - if ($event && $event.type === 'click') { - ctrl.clickTriggeredSelect = true; - } - }; + // Local method called when we complete the select + // eg. called after the onselect callback + var completeSelection = function () { + $scope.$broadcast('uis:select', item); - var locals = {}; - locals[ctrl.parserResult.itemName] = item; + $timeout(function () { + ctrl.onSelectCallback($scope, callbackContext); + }); - var callbackContext = { - $item: item, - $model: ctrl.parserResult.modelMapper($scope, locals) - }; + if (ctrl.closeOnSelect) { + ctrl.close(skipFocusser); + } + if ($event && $event.type === 'click') { + ctrl.clickTriggeredSelect = true; + } + }; - // Call the onBeforeSelect callback - // Allowable responses are -: - // falsy: Abort the selection - // promise: Wait for response - // true: Complete selection - // object: Add the returned object - var onBeforeSelectResult = ctrl.onBeforeSelectCallback($scope, callbackContext); - if (angular.isDefined(onBeforeSelectResult)) { - if (!onBeforeSelectResult) { - return; // abort the selection in case of deliberate falsey result - } else if (angular.isFunction(onBeforeSelectResult.then)) { - onBeforeSelectResult.then(function (result) { - if (!result) { - return; - } - completeSelection(result); - }); - } else if (onBeforeSelectResult === true) { - completeSelection(item); - } else { - completeSelection(onBeforeSelectResult); + // Call the onBeforeSelect callback + // Allowable responses are -: + // falsy: Abort the selection + // promise: Wait for response + // true: Complete selection + // object: Add the returned object + var onBeforeSelectResult = ctrl.onBeforeSelectCallback($scope, callbackContext); + if (angular.isDefined(onBeforeSelectResult)) { + if (angular.isFunction(onBeforeSelectResult.then)) { + // Promise returned - wait for it to complete before completing the selection + onBeforeSelectResult.then(function (result) { + if (!result) { + return; } - } else { - completeSelection(item); - } + completeSelection(result); + }); + } else if (onBeforeSelectResult === true) { + completeSelection(item); + } else if (onBeforeSelectResult) { + completeSelection(onBeforeSelectResult); } + } else { + completeSelection(item); } }; - // Closes the dropdown + /** + * Close the dropdown + */ ctrl.close = function (skipFocusser) { if (!ctrl.open) { return; } - if (ctrl.ngModel && ctrl.ngModel.$setTouched) ctrl.ngModel.$setTouched(); + if (ctrl.ngModel && ctrl.ngModel.$setTouched) { + ctrl.ngModel.$setTouched(); + } _resetSearchInput(); ctrl.open = false; if (!ctrl.searchEnabled) { @@ -568,12 +664,19 @@ uis.controller('uiSelectCtrl', $scope.$broadcast('uis:close', skipFocusser); }; + /** + * Set focus on the control + */ ctrl.setFocus = function () { if (!ctrl.focus) { ctrl.focusInput[0].focus(); } }; + /** + * Clears the selection + * @param $event + */ ctrl.clear = function ($event) { ctrl.select(undefined); $event.stopPropagation(); @@ -582,7 +685,9 @@ uis.controller('uiSelectCtrl', }, 0, false); }; - // Toggle dropdown + /** + * Toggle the dropdown open and closed + */ ctrl.toggle = function (e) { if (ctrl.open) { ctrl.close(); @@ -606,7 +711,6 @@ uis.controller('uiSelectCtrl', var sizeWatch = null; ctrl.sizeSearchInput = function () { - var input = ctrl.searchInput[0], container = ctrl.searchInput.parent().parent()[0], calculateContainerWidth = function () { @@ -659,7 +763,9 @@ uis.controller('uiSelectCtrl', } break; case KEY.TAB: - if (!ctrl.multiple || ctrl.open) ctrl.select(ctrl.items[ctrl.activeIndex], true); + if (!ctrl.multiple || ctrl.open) { + ctrl.select(ctrl.items[ctrl.activeIndex], true); + } break; case KEY.ENTER: if (ctrl.open) { @@ -703,24 +809,6 @@ uis.controller('uiSelectCtrl', } }); - // If tagging try to split by tokens and add items - /* ctrl.searchInput.on('paste', function (e) { - var data = e.originalEvent.clipboardData.getData('text/plain'); - if (data && data.length > 0 && ctrl.taggingTokens.isActivated && ctrl.tagging.fct) { - var items = data.split(ctrl.taggingTokens.tokens[0]); // split by first token only - if (items && items.length > 0) { - angular.forEach(items, function (item) { - var newItem = ctrl.tagging.fct(item); - if (newItem) { - ctrl.select(newItem, true); - } - }); - e.preventDefault(); - e.stopPropagation(); - } - } - });*/ - ctrl.searchInput.on('keyup', function (e) { // return early with these keys if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || @@ -734,7 +822,6 @@ uis.controller('uiSelectCtrl', ctrl.onKeypressCallback($scope, {event: e}); }); - // See https://github.com/ivaynberg/select2/blob/3.4.6/select2.js#L1431 function _ensureHighlightVisible() { var container = $element.querySelectorAll('.ui-select-choices-content'); @@ -755,10 +842,13 @@ uis.controller('uiSelectCtrl', if (posY > height) { container[0].scrollTop += posY - height; } else if (posY < highlighted.clientHeight) { - if (ctrl.isGrouped && ctrl.activeIndex === 0) - container[0].scrollTop = 0; //To make group header visible when going all the way up - else + if (ctrl.isGrouped && ctrl.activeIndex === 0) { + //To make group header visible when going all the way up + container[0].scrollTop = 0; + } + else { container[0].scrollTop -= highlighted.clientHeight - posY; + } } } @@ -811,9 +901,10 @@ uis.directive('uiSelect', } }(); - $select.onBeforeSelectCallback = $parse(attrs.onBeforeSelect); $select.onSelectCallback = $parse(attrs.onSelect); + $select.onBeforeSelectCallback = $parse(attrs.onBeforeSelect); $select.onRemoveCallback = $parse(attrs.onRemove); + $select.onBeforeRemoveCallback = $parse(attrs.onBeforeRemove); $select.onKeypressCallback = $parse(attrs.onKeypress); //Limit the number of selections allowed @@ -845,11 +936,6 @@ uis.directive('uiSelect', $select.disabled = attrs.disabled !== undefined ? attrs.disabled : false; }); - attrs.$observe('resetSearchInput', function () { - // $eval() is needed otherwise we get a string instead of a boolean - var resetSearchInput = scope.$eval(attrs.resetSearchInput); - $select.resetSearchInput = resetSearchInput !== undefined ? resetSearchInput : true; - }); //Automatically gets focus when loaded if (angular.isDefined(attrs.autofocus)) { @@ -1001,6 +1087,7 @@ uis.directive('uiSelect', // Support changing the direction of the dropdown if there isn't enough space to render it. scope.$watch('$select.open', function (isOpen) { if (isOpen) { + // Get the dropdown element dropdown = angular.element(element).querySelectorAll('.ui-select-dropdown'); if (dropdown === null) { return; @@ -1018,8 +1105,6 @@ uis.directive('uiSelect', if (offset.top + offset.height + offsetDropdown.height > $document[0].documentElement.scrollTop + $document[0].documentElement.clientHeight) { - dropdown[0].style.position = 'absolute'; - dropdown[0].style.top = (offsetDropdown.height * -1) + 'px'; element.addClass(directionUpClassName); } @@ -1032,8 +1117,6 @@ uis.directive('uiSelect', } // Reset the position of the dropdown. - dropdown[0].style.position = ''; - dropdown[0].style.top = ''; element.removeClass(directionUpClassName); } }); @@ -1042,425 +1125,479 @@ uis.directive('uiSelect', }; }]); -uis.directive('uiSelectMatch', ['uiSelectConfig', function(uiSelectConfig) { - return { - restrict: 'EA', - require: '^uiSelect', - replace: true, - transclude: true, - templateUrl: function(tElement) { - // Gets theme attribute from parent (ui-select) - var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; - var multi = tElement.parent().attr('multiple'); - return theme + (multi ? '/match-multiple.tpl.html' : '/match.tpl.html'); - }, - link: function(scope, element, attrs, $select) { - $select.lockChoiceExpression = attrs.uiLockChoice; - attrs.$observe('placeholder', function(placeholder) { - $select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder; - }); - - function setAllowClear(allow) { - $select.allowClear = (angular.isDefined(allow)) ? (allow === '') ? true : (allow.toLowerCase() === 'true') : false; - } +uis.directive('uiSelectMatch', ['uiSelectConfig', function (uiSelectConfig) { + return { + restrict: 'EA', + require: '^uiSelect', + replace: true, + transclude: true, + templateUrl: function (tElement) { + // Gets theme attribute from parent (ui-select) + var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; + var multi = tElement.parent().attr('multiple'); + return theme + (multi ? '/match-multiple.tpl.html' : '/match.tpl.html'); + }, + link: function (scope, element, attrs, $select) { + $select.lockChoiceExpression = attrs.uiLockChoice; + attrs.$observe('placeholder', function (placeholder) { + $select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder; + }); - attrs.$observe('allowClear', setAllowClear); - setAllowClear(attrs.allowClear); + function setAllowClear(allow) { + $select.allowClear = + (angular.isDefined(allow)) ? (allow === '') ? true : (allow.toLowerCase() === 'true') : false; + } - if($select.multiple){ - $select.sizeSearchInput(); - } + attrs.$observe('allowClear', setAllowClear); + setAllowClear(attrs.allowClear); - } - }; + if ($select.multiple) { + $select.sizeSearchInput(); + } + } + }; }]); -uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelectMinErr, $timeout) { - return { - restrict: 'EA', - require: ['^uiSelect', '^ngModel'], +uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSelectMinErr, $timeout) { + return { + restrict: 'EA', + require: ['^uiSelect', '^ngModel'], + controller: ['$scope', '$timeout', function ($scope, $timeout) { + var ctrl = this, + $select = $scope.$select, + ngModel; + + //Wait for link fn to inject it + $scope.$evalAsync(function () { + ngModel = $scope.ngModel; + }); + + ctrl.activeMatchIndex = -1; - controller: ['$scope','$timeout', function($scope, $timeout){ + ctrl.updateModel = function () { + ngModel.$setViewValue(Date.now()); //Set timestamp as a unique string to force changes + ctrl.refreshComponent(); + }; - var ctrl = this, - $select = $scope.$select, - ngModel; + ctrl.refreshComponent = function () { + // Remove already selected items + // e.g. When user clicks on a selection, the selected array changes and + // the dropdown should remove that item + $select.refreshItems(); + $select.sizeSearchInput(); + }; - //Wait for link fn to inject it - $scope.$evalAsync(function(){ ngModel = $scope.ngModel; }); + // Remove item from multiple select + ctrl.removeChoice = function (index) { + var removedChoice = $select.selected[index]; - ctrl.activeMatchIndex = -1; + // if the choice is locked, can't remove it + if (removedChoice._uiSelectChoiceLocked) { + return; + } - ctrl.updateModel = function(){ - ngModel.$setViewValue(Date.now()); //Set timestamp as a unique string to force changes - ctrl.refreshComponent(); - }; + var locals = {}; + locals[$select.parserResult.itemName] = removedChoice; - ctrl.refreshComponent = function(){ - //Remove already selected items - //e.g. When user clicks on a selection, the selected array changes and - //the dropdown should remove that item - $select.refreshItems(); - $select.sizeSearchInput(); - }; + $select.selected.splice(index, 1); + ctrl.activeMatchIndex = -1; + $select.sizeSearchInput(); - // Remove item from multiple select - ctrl.removeChoice = function(index){ + var callbackContext = { + $item: removedChoice, + $model: $select.parserResult.modelMapper($scope, locals) + }; - var removedChoice = $select.selected[index]; + // Give some time for scope propagation. + function completeRemoval() { + $timeout(function () { + $select.onRemoveCallback($scope, callbackContext); + }); - // if the choice is locked, can't remove it - if(removedChoice._uiSelectChoiceLocked) return; + ctrl.updateModel(); + } - var locals = {}; - locals[$select.parserResult.itemName] = removedChoice; + // Call the onBeforeRemove callback + // Allowable responses are -: + // falsy: Abort the removal + // promise: Wait for response + // true: Complete removal + var onBeforeRemoveResult = ctrl.onBeforeRemoveCallback($scope, callbackContext); + if (angular.isDefined(onBeforeRemoveResult)) { + if (angular.isFunction(onBeforeRemoveResult.then)) { + // Promise returned - wait for it to complete before completing the selection + onBeforeRemoveResult.then(function (result) { + if (!result) { + return; + } + completeRemoval(result); + }); + } else if (onBeforeRemoveResult === true) { + completeRemoval(); + } + } else { + completeRemoval(); + } + }; - $select.selected.splice(index, 1); - ctrl.activeMatchIndex = -1; - $select.sizeSearchInput(); + ctrl.getPlaceholder = function () { + //Refactor single? + if ($select.selected && $select.selected.length) { + return; + } + return $select.placeholder; + }; + }], + controllerAs: '$selectMultiple', + + link: function (scope, element, attrs, ctrls) { + var $select = ctrls[0]; + var ngModel = scope.ngModel = ctrls[1]; + var $selectMultiple = scope.$selectMultiple; + + //$select.selected = raw selected objects (ignoring any property binding) + + $select.multiple = true; + $select.removeSelected = true; + + //Input that will handle focus + $select.focusInput = $select.searchInput; + + //From view --> model + ngModel.$parsers.unshift(function () { + var locals = {}, + result, + resultMultiple = []; + for (var j = $select.selected.length - 1; j >= 0; j--) { + locals = {}; + locals[$select.parserResult.itemName] = $select.selected[j]; + result = $select.parserResult.modelMapper(scope, locals); + resultMultiple.unshift(result); + } + return resultMultiple; + }); - // Give some time for scope propagation. - $timeout(function(){ - $select.onRemoveCallback($scope, { - $item: removedChoice, - $model: $select.parserResult.modelMapper($scope, locals) - }); - }); + // From model --> view + ngModel.$formatters.unshift(function (inputValue) { + var data = $select.parserResult.source(scope, {$select: {search: ''}}), //Overwrite $search + locals = {}, + result; + if (!data) { + return inputValue; + } + var resultMultiple = []; + var checkFnMultiple = function (list, value) { + if (!list || !list.length) { + return; + } + for (var p = list.length - 1; p >= 0; p--) { + locals[$select.parserResult.itemName] = list[p]; + result = $select.parserResult.modelMapper(scope, locals); + if ($select.parserResult.trackByExp) { + var matches = /\.(.+)/.exec($select.parserResult.trackByExp); + if (matches.length > 0 && result[matches[1]] == value[matches[1]]) { + resultMultiple.unshift(list[p]); + return true; + } + } + if (angular.equals(result, value)) { + resultMultiple.unshift(list[p]); + return true; + } + } + return false; + }; + if (!inputValue) return resultMultiple; //If ngModel was undefined + for (var k = inputValue.length - 1; k >= 0; k--) { + //Check model array of currently selected items + if (!checkFnMultiple($select.selected, inputValue[k])) { + //Check model array of all items available + if (!checkFnMultiple(data, inputValue[k])) { + //If not found on previous lists, just add it directly to resultMultiple + resultMultiple.unshift(inputValue[k]); + } + } + } + return resultMultiple; + }); - ctrl.updateModel(); + //Watch for external model changes + scope.$watchCollection(function () { + return ngModel.$modelValue; + }, function (newValue, oldValue) { + if (oldValue != newValue) { + ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters + $selectMultiple.refreshComponent(); + } + }); - }; + ngModel.$render = function () { + // Make sure that model value is array + if (!angular.isArray(ngModel.$viewValue)) { + // Have tolerance for null or undefined values + if (angular.isUndefined(ngModel.$viewValue) || ngModel.$viewValue === null) { + $select.selected = []; + } else { + throw uiSelectMinErr('multiarr', "Expected model value to be array but got '{0}'", + ngModel.$viewValue); + } + } + $select.selected = ngModel.$viewValue; + scope.$evalAsync(); //To force $digest + }; - ctrl.getPlaceholder = function(){ - //Refactor single? - if($select.selected && $select.selected.length) return; - return $select.placeholder; - }; + scope.$on('uis:select', function (event, item) { + if ($select.selected.length >= $select.limit) { + return; + } + $select.selected.push(item); + $selectMultiple.updateModel(); + }); + scope.$on('uis:activate', function () { + $selectMultiple.activeMatchIndex = -1; + }); - }], - controllerAs: '$selectMultiple', + scope.$watch('$select.disabled', function (newValue, oldValue) { + // As the search input field may now become visible, it may be necessary to recompute its size + if (oldValue && !newValue) { + $select.sizeSearchInput(); + } + }); - link: function(scope, element, attrs, ctrls) { + $select.searchInput.on('keydown', function (e) { + var key = e.which; + scope.$apply(function () { + var processed = false; + if (KEY.isHorizontalMovement(key)) { + processed = _handleMatchSelection(key); + } + if (processed && key != KEY.TAB) { + //TODO Check si el tab selecciona aun correctamente + //Crear test +// e.preventDefault(); + // e.stopPropagation(); + } + }); + }); + function _getCaretPosition(el) { + if (angular.isNumber(el.selectionStart)) { + return el.selectionStart; + } + // selectionStart is not supported in IE8 and we don't want hacky workarounds so we compromise + else { + return el.value.length; + } + } - var $select = ctrls[0]; - var ngModel = scope.ngModel = ctrls[1]; - var $selectMultiple = scope.$selectMultiple; + // Handles selected options in "multiple" mode + function _handleMatchSelection(key) { + var caretPosition = _getCaretPosition($select.searchInput[0]), + length = $select.selected.length, + first = 0, + last = length - 1, + curr = $selectMultiple.activeMatchIndex, + next = $selectMultiple.activeMatchIndex + 1, + prev = $selectMultiple.activeMatchIndex - 1, + newIndex = curr; + + if (caretPosition > 0 || ($select.search.length && key == KEY.RIGHT)) { + return false; + } - //$select.selected = raw selected objects (ignoring any property binding) + $select.close(); - $select.multiple = true; - $select.removeSelected = true; + function getNewActiveMatchIndex() { + switch (key) { + case KEY.LEFT: + // Select previous/first item + if (~$selectMultiple.activeMatchIndex) { + return prev; + } + // Select last item + else { + return last; + } + break; + case KEY.RIGHT: + // Open drop-down + if (!~$selectMultiple.activeMatchIndex || curr === last) { + $select.activate(); + return false; + } + // Select next/last item + else { + return next; + } + break; + case KEY.BACKSPACE: + // Remove selected item and select previous/first + if (~$selectMultiple.activeMatchIndex) { + $selectMultiple.removeChoice(curr); + return prev; + } + // Select last item + else { + return last; + } + break; + case KEY.DELETE: + // Remove selected item and select next item + if (~$selectMultiple.activeMatchIndex) { + $selectMultiple.removeChoice($selectMultiple.activeMatchIndex); + return curr; + } + else { + return false; + } + } + } - //Input that will handle focus - $select.focusInput = $select.searchInput; + newIndex = getNewActiveMatchIndex(); - //From view --> model - ngModel.$parsers.unshift(function () { - var locals = {}, - result, - resultMultiple = []; - for (var j = $select.selected.length - 1; j >= 0; j--) { - locals = {}; - locals[$select.parserResult.itemName] = $select.selected[j]; - result = $select.parserResult.modelMapper(scope, locals); - resultMultiple.unshift(result); - } - return resultMultiple; - }); - - // From model --> view - ngModel.$formatters.unshift(function (inputValue) { - var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search - locals = {}, - result; - if (!data) return inputValue; - var resultMultiple = []; - var checkFnMultiple = function(list, value){ - if (!list || !list.length) return; - for (var p = list.length - 1; p >= 0; p--) { - locals[$select.parserResult.itemName] = list[p]; - result = $select.parserResult.modelMapper(scope, locals); - if($select.parserResult.trackByExp){ - var matches = /\.(.+)/.exec($select.parserResult.trackByExp); - if(matches.length>0 && result[matches[1]] == value[matches[1]]){ - resultMultiple.unshift(list[p]); - return true; + if (!$select.selected.length || newIndex === false) { + $selectMultiple.activeMatchIndex = -1; } + else { + $selectMultiple.activeMatchIndex = Math.min(last, Math.max(first, newIndex)); + } + + return true; } - if (angular.equals(result,value)){ - resultMultiple.unshift(list[p]); - return true; - } - } - return false; - }; - if (!inputValue) return resultMultiple; //If ngModel was undefined - for (var k = inputValue.length - 1; k >= 0; k--) { - //Check model array of currently selected items - if (!checkFnMultiple($select.selected, inputValue[k])){ - //Check model array of all items available - if (!checkFnMultiple(data, inputValue[k])){ - //If not found on previous lists, just add it directly to resultMultiple - resultMultiple.unshift(inputValue[k]); - } - } - } - return resultMultiple; - }); - - //Watch for external model changes - scope.$watchCollection(function(){ return ngModel.$modelValue; }, function(newValue, oldValue) { - if (oldValue != newValue){ - ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters - $selectMultiple.refreshComponent(); - } - }); - - ngModel.$render = function() { - // Make sure that model value is array - if(!angular.isArray(ngModel.$viewValue)){ - // Have tolerance for null or undefined values - if(angular.isUndefined(ngModel.$viewValue) || ngModel.$viewValue === null){ - $select.selected = []; - } else { - throw uiSelectMinErr('multiarr', "Expected model value to be array but got '{0}'", ngModel.$viewValue); - } - } - $select.selected = ngModel.$viewValue; - scope.$evalAsync(); //To force $digest - }; - scope.$on('uis:select', function (event, item) { - if($select.selected.length >= $select.limit) { - return; - } - $select.selected.push(item); - $selectMultiple.updateModel(); - }); - - scope.$on('uis:activate', function () { - $selectMultiple.activeMatchIndex = -1; - }); - - scope.$watch('$select.disabled', function(newValue, oldValue) { - // As the search input field may now become visible, it may be necessary to recompute its size - if (oldValue && !newValue) $select.sizeSearchInput(); - }); - - $select.searchInput.on('keydown', function(e) { - var key = e.which; - scope.$apply(function() { - var processed = false; - if(KEY.isHorizontalMovement(key)){ - processed = _handleMatchSelection(key); - } - if (processed && key != KEY.TAB) { - //TODO Check si el tab selecciona aun correctamente - //Crear test -// e.preventDefault(); - // e.stopPropagation(); - } - }); - }); - function _getCaretPosition(el) { - if(angular.isNumber(el.selectionStart)) return el.selectionStart; - // selectionStart is not supported in IE8 and we don't want hacky workarounds so we compromise - else return el.value.length; - } - // Handles selected options in "multiple" mode - function _handleMatchSelection(key){ - var caretPosition = _getCaretPosition($select.searchInput[0]), - length = $select.selected.length, - // none = -1, - first = 0, - last = length-1, - curr = $selectMultiple.activeMatchIndex, - next = $selectMultiple.activeMatchIndex+1, - prev = $selectMultiple.activeMatchIndex-1, - newIndex = curr; - - if(caretPosition > 0 || ($select.search.length && key == KEY.RIGHT)) return false; - - $select.close(); - - function getNewActiveMatchIndex(){ - switch(key){ - case KEY.LEFT: - // Select previous/first item - if(~$selectMultiple.activeMatchIndex) return prev; - // Select last item - else return last; - break; - case KEY.RIGHT: - // Open drop-down - if(!~$selectMultiple.activeMatchIndex || curr === last){ - $select.activate(); - return false; - } - // Select next/last item - else return next; - break; - case KEY.BACKSPACE: - // Remove selected item and select previous/first - if(~$selectMultiple.activeMatchIndex){ - $selectMultiple.removeChoice(curr); - return prev; - } - // Select last item - else return last; - break; - case KEY.DELETE: - // Remove selected item and select next item - if(~$selectMultiple.activeMatchIndex){ - $selectMultiple.removeChoice($selectMultiple.activeMatchIndex); - return curr; - } - else return false; - } + $select.searchInput.on('blur', function () { + $timeout(function () { + $selectMultiple.activeMatchIndex = -1; + }); + }); + } + }; +}]); - newIndex = getNewActiveMatchIndex(); +uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $compile) { + return { + restrict: 'EA', + require: ['^uiSelect', '^ngModel'], + link: function (scope, element, attrs, ctrls) { + + var $select = ctrls[0]; + var ngModel = ctrls[1]; + + //From view --> model + ngModel.$parsers.unshift(function (inputValue) { + var locals = {}, + result; + locals[$select.parserResult.itemName] = inputValue; + result = $select.parserResult.modelMapper(scope, locals); + return result; + }); - if(!$select.selected.length || newIndex === false) $selectMultiple.activeMatchIndex = -1; - else $selectMultiple.activeMatchIndex = Math.min(last,Math.max(first,newIndex)); + //From model --> view + ngModel.$formatters.unshift(function (inputValue) { + var data = $select.parserResult.source(scope, {$select: {search: ''}}), //Overwrite $search + locals = {}, + result; + if (data) { + var checkFnSingle = function (d) { + locals[$select.parserResult.itemName] = d; + result = $select.parserResult.modelMapper(scope, locals); + return result == inputValue; + }; + //If possible pass same object stored in $select.selected + if ($select.selected && checkFnSingle($select.selected)) { + return $select.selected; + } + for (var i = data.length - 1; i >= 0; i--) { + if (checkFnSingle(data[i])) { + return data[i]; + } + } + } + return inputValue; + }); - return true; - } + //Update viewValue if model change + scope.$watch('$select.selected', function (newValue) { + if (ngModel.$viewValue !== newValue) { + ngModel.$setViewValue(newValue); + } + }); - $select.searchInput.on('blur', function() { - $timeout(function() { - $selectMultiple.activeMatchIndex = -1; - }); - }); + ngModel.$render = function () { + $select.selected = ngModel.$viewValue; + }; - } - }; -}]); + scope.$on('uis:select', function (event, item) { + $select.selected = item; + }); -uis.directive('uiSelectSingle', ['$timeout','$compile', function($timeout, $compile) { - return { - restrict: 'EA', - require: ['^uiSelect', '^ngModel'], - link: function(scope, element, attrs, ctrls) { - - var $select = ctrls[0]; - var ngModel = ctrls[1]; - - //From view --> model - ngModel.$parsers.unshift(function (inputValue) { - var locals = {}, - result; - locals[$select.parserResult.itemName] = inputValue; - result = $select.parserResult.modelMapper(scope, locals); - return result; - }); - - //From model --> view - ngModel.$formatters.unshift(function (inputValue) { - var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search - locals = {}, - result; - if (data){ - var checkFnSingle = function(d){ - locals[$select.parserResult.itemName] = d; - result = $select.parserResult.modelMapper(scope, locals); - return result == inputValue; - }; - //If possible pass same object stored in $select.selected - if ($select.selected && checkFnSingle($select.selected)) { - return $select.selected; - } - for (var i = data.length - 1; i >= 0; i--) { - if (checkFnSingle(data[i])) return data[i]; - } - } - return inputValue; - }); + scope.$on('uis:close', function (event, skipFocusser) { + $timeout(function () { + $select.focusser.prop('disabled', false); + if (!skipFocusser) $select.focusser[0].focus(); + }, 0, false); + }); - //Update viewValue if model change - scope.$watch('$select.selected', function(newValue) { - if (ngModel.$viewValue !== newValue) { - ngModel.$setViewValue(newValue); - } - }); - - ngModel.$render = function() { - $select.selected = ngModel.$viewValue; - }; - - scope.$on('uis:select', function (event, item) { - $select.selected = item; - }); - - scope.$on('uis:close', function (event, skipFocusser) { - $timeout(function(){ - $select.focusser.prop('disabled', false); - if (!skipFocusser) $select.focusser[0].focus(); - },0,false); - }); - - scope.$on('uis:activate', function () { - focusser.prop('disabled', true); //Will reactivate it on .close() - }); - - //Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954 - var focusser = angular.element(""); - $compile(focusser)(scope); - $select.focusser = focusser; - - //Input that will handle focus - $select.focusInput = focusser; - - element.parent().append(focusser); - focusser.bind("focus", function(){ - scope.$evalAsync(function(){ - $select.focus = true; - }); - }); - focusser.bind("blur", function(){ - scope.$evalAsync(function(){ - $select.focus = false; - }); - }); - focusser.bind("keydown", function(e){ - - if (e.which === KEY.BACKSPACE) { - e.preventDefault(); - e.stopPropagation(); - $select.select(undefined); - scope.$apply(); - return; - } + scope.$on('uis:activate', function () { + focusser.prop('disabled', true); //Will reactivate it on .close() + }); - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) { - return; - } + //Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954 + var focusser = angular.element(""); + $compile(focusser)(scope); + $select.focusser = focusser; - if (e.which == KEY.DOWN || e.which == KEY.UP || e.which == KEY.ENTER || e.which == KEY.SPACE){ - e.preventDefault(); - e.stopPropagation(); - $select.activate(); - } + //Input that will handle focus + $select.focusInput = focusser; - scope.$digest(); - }); + element.parent().append(focusser); + focusser.bind("focus", function () { + scope.$evalAsync(function () { + $select.focus = true; + }); + }); + focusser.bind("blur", function () { + scope.$evalAsync(function () { + $select.focus = false; + }); + }); + focusser.bind("keydown", function (e) { - focusser.bind("keyup input", function(e){ + if (e.which === KEY.BACKSPACE) { + e.preventDefault(); + e.stopPropagation(); + $select.select(undefined); + scope.$apply(); + return; + } - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { - return; - } + if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) { + return; + } - $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input - focusser.val(''); - scope.$digest(); + if (e.which == KEY.DOWN || e.which == KEY.UP || e.which == KEY.ENTER || e.which == KEY.SPACE) { + e.preventDefault(); + e.stopPropagation(); + $select.activate(); + } - }); + scope.$digest(); + }); + focusser.bind("keyup input", function (e) { - } - }; + if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || + e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { + return; + } + + $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input + focusser.val(''); + scope.$digest(); + }); + } + }; }]); /** * Parses "repeat" attribute. @@ -1472,45 +1609,46 @@ uis.directive('uiSelectSingle', ['$timeout','$compile', function($timeout, $comp * https://github.com/angular-ui/ui-select/commit/5dd63ad#commitcomment-5504697 */ -uis.service('uisRepeatParser', ['uiSelectMinErr','$parse', function(uiSelectMinErr, $parse) { - var self = this; +uis.service('uisRepeatParser', ['uiSelectMinErr', '$parse', function (uiSelectMinErr, $parse) { + var self = this; - /** - * Example: - * expression = "address in addresses | filter: {street: $select.search} track by $index" - * itemName = "address", - * source = "addresses | filter: {street: $select.search}", - * trackByExp = "$index", - */ - self.parse = function(expression) { + /** + * Example: + * expression = "address in addresses | filter: {street: $select.search} track by $index" + * itemName = "address", + * source = "addresses | filter: {street: $select.search}", + * trackByExp = "$index", + */ + self.parse = function (expression) { - var match = expression.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/); + var match = expression.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/); - if (!match) { - throw uiSelectMinErr('iexp', "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.", - expression); - } + if (!match) { + throw uiSelectMinErr('iexp', + "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.", + expression); + } - return { - itemName: match[2], // (lhs) Left-hand side, - source: $parse(match[3]), - trackByExp: match[4], - modelMapper: $parse(match[1] || match[2]) - }; + return { + itemName: match[2], // (lhs) Left-hand side, + source: $parse(match[3]), + trackByExp: match[4], + modelMapper: $parse(match[1] || match[2]) + }; - }; + }; - self.getGroupNgRepeatExpression = function() { - return '$group in $select.groups'; - }; + self.getGroupNgRepeatExpression = function () { + return '$group in $select.groups'; + }; - self.getNgRepeatExpression = function(itemName, source, trackByExp, grouped) { - var expression = itemName + ' in ' + (grouped ? '$group.items' : source); - if (trackByExp) { - expression += ' track by ' + trackByExp; - } - return expression; - }; + self.getNgRepeatExpression = function (itemName, source, trackByExp, grouped) { + var expression = itemName + ' in ' + (grouped ? '$group.items' : source); + if (trackByExp) { + expression += ' track by ' + trackByExp; + } + return expression; + }; }]); }()); \ No newline at end of file diff --git a/dist/select.no-tpl.min.js b/dist/select.no-tpl.min.js index f7f98e2d6..25bbe1be5 100644 --- a/dist/select.no-tpl.min.js +++ b/dist/select.no-tpl.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-02T20:56:31.493Z + * Version: 0.12.1 - 2015-08-04T17:24:10.054Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var n=t.which;switch(n){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,n=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",refreshDelay:1e3,closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,r,i){i(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var r=n[0].getBoundingClientRect();return{width:r.width||n.prop("offsetWidth"),height:r.height||n.prop("offsetHeight"),top:r.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:r.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);n.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,r){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(i,c){if(!c.repeat)throw n("repeat","Expected 'repeat' expression.");return function(i,c,l,s,o){var a=l.groupBy,u=l.groupFilter;if(s.parseRepeatAttr(l.repeat,a,u),s.disableChoiceExpression=l.uiDisableChoice,s.onHighlightCallback=l.onHighlight,s.refreshOnActive=i.$eval(l.refreshOnActive),a){var p=c.querySelectorAll(".ui-select-choices-group");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",p.length);p.attr("ng-repeat",t.getGroupNgRepeatExpression())}var f=c.querySelectorAll(".ui-select-choices-row");if(1!==f.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",f.length);f.attr("ng-repeat",t.getNgRepeatExpression(s.parserResult.itemName,"$select.items",s.parserResult.trackByExp,a)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+s.parserResult.itemName+")").attr("ng-click","$select.select("+s.parserResult.itemName+",false,$event)");var h=c.querySelectorAll(".ui-select-choices-row-inner");if(1!==h.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",h.length);h.attr("uis-transclude-append",""),r(c,o)(i),i.$watch("$select.search",function(e){e&&!s.open&&s.multiple&&s.activate(!1,!0),s.activeIndex=0,(!s.refreshOnActive||s.refreshOnActive&&s.refreshIsActive)&&s.refresh(l.refresh)}),i.$watch("$select.refreshIsActive",function(e,t){angular.isUndefined(t)&&e&&s.refresh(l.refresh)});var d=i.$eval(l.refreshDelay);s.refreshDelay=void 0!==d?d:e.refreshDelay}}}}]),n.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,n,r,i,c,l,s,o){function a(){(h.resetSearchInput||void 0===h.resetSearchInput&&o.resetSearchInput)&&(h.search=d,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var n,r,i=[];for(n=0;n0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:n=!1}return n}function f(){var e=n.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw s("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var r=t[h.activeIndex],i=r.offsetTop+r.clientHeight-e[0].scrollTop,c=e[0].offsetHeight;i>c?e[0].scrollTop+=i-c:i=h.items.length?0:h.activeIndex,h.refreshIsActive=!0,r(function(){h.search=e||h.search,h.searchInput[0].focus()}))},h.findGroupByName=function(e){return h.groups&&h.groups.filter(function(t){return t.name===e})[0]},h.parseRepeatAttr=function(e,n,r){function i(e){var i=t.$eval(n);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(i)?i(e):e[i],n=h.findGroupByName(t);n?n.items.push(e):h.groups.push({name:t,items:[e]})}),r){var c=t.$eval(r);angular.isFunction(c)?h.groups=c(h.groups):angular.isArray(c)&&(h.groups=u(h.groups,c))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function c(e){h.items=e}h.setItemsFn=n?i:c,h.parserResult=l.parse(e),h.isGrouped=!!n,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var n=h.selected;if(h.isEmpty()||angular.isArray(n)&&!n.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var r=e.filter(function(e){return n.indexOf(e)<0});h.setItemsFn(r)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw s("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})};var v;h.refresh=function(e){void 0!==e&&(v&&r.cancel(v),v=r(function(){t.$eval(e)},h.refreshDelay))},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),n=t===h.activeIndex;return n&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),n},h.isDisabled=function(e){if(!h.open)return!1;var t,n=h.items.indexOf(e[h.itemProperty]),r=!1;return n>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[n],r=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=r),r},h.select=function(e,n,i){if(void 0===e||!e._uiSelectChoiceDisabled){if(!h.items&&!h.search)return;if(!e||!e._uiSelectChoiceDisabled){var c=function(){t.$broadcast("uis:select",e),r(function(){h.onSelectCallback(t,s)}),h.closeOnSelect&&h.close(n),i&&"click"===i.type&&(h.clickTriggeredSelect=!0)},l={};l[h.parserResult.itemName]=e;var s={$item:e,$model:h.parserResult.modelMapper(t,l)},o=h.onBeforeSelectCallback(t,s);if(angular.isDefined(o)){if(!o)return;angular.isFunction(o.then)?o.then(function(e){e&&c(e)}):o===!0?c(e):c(o)}else c(e)}}},h.close=function(e){h.open&&(h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),a(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e))},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),r(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var n,r=h.selected[t];return r&&!angular.isUndefined(h.lockChoiceExpression)&&(n=!!e.$eval(h.lockChoiceExpression),r._uiSelectChoiceLocked=n),n};var m=null;h.sizeSearchInput=function(){var e=h.searchInput[0],n=h.searchInput.parent().parent()[0],i=function(){return n.clientWidth*!!e.offsetParent},c=function(t){if(0===t)return!1;var n=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=t),h.searchInput.css("width",n+"px"),!0};h.searchInput.css("width","10px"),r(function(){null!==m||c(i())||(m=t.$watch(i,function(e){c(e)&&(m(),m=null)}))})},h.searchInput.on("keydown",function(n){var r=n.which;t.$apply(function(){p(r)}),e.isVerticalMovement(r)&&h.items.length>0&&f(),(r===e.ENTER||r===e.ESC)&&(n.preventDefault(),n.stopPropagation())}),h.searchInput.on("keyup",function(n){n.which===e.TAB||e.isControl(n)||e.isFunctionKey(n)||n.which===e.ESC||e.isVerticalMovement(n.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:n})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),n.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,r,i,c,l){return{restrict:"EA",templateUrl:function(e,n){var r=n.theme||t.theme;return r+(angular.isDefined(n.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(i,s){return angular.isDefined(s.multiple)?i.append("").removeAttr("multiple"):i.append(""),function(i,s,o,a,u){function p(e){if(d.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(s[0],e.target):s[0].contains(e.target),!t&&!d.clickTriggeredSelect){var n=["input","button","textarea"],r=angular.element(e.target).scope(),c=r&&r.$select&&r.$select!==d;c||(c=~n.indexOf(e.target.tagName.toLowerCase())),d.close(c),i.$digest()}d.clickTriggeredSelect=!1}}function f(){var t=r(s);E=angular.element('
    '),E[0].style.width=t.width+"px",E[0].style.height=t.height+"px",s.after(E),S=s[0].style.width,e.find("body").append(s),s[0].style.position="absolute",s[0].style.left=t.left+"px",s[0].style.top=t.top+"px",s[0].style.width=t.width+"px"}function h(){null!==E&&(E.replaceWith(s),E=null,s[0].style.position="",s[0].style.left="",s[0].style.top="",s[0].style.width=S)}var d=a[0],v=a[1];d.generatedId=t.generateId(),d.baseTitle=o.title||"Select box",d.focusserTitle=d.baseTitle+" focus",d.focusserId="focusser-"+d.generatedId,d.closeOnSelect=function(){return angular.isDefined(o.closeOnSelect)?c(o.closeOnSelect)():t.closeOnSelect}(),d.onBeforeSelectCallback=c(o.onBeforeSelect),d.onSelectCallback=c(o.onSelect),d.onRemoveCallback=c(o.onRemove),d.onKeypressCallback=c(o.onKeypress),d.limit=angular.isDefined(o.limit)?parseInt(o.limit,10):void 0,d.ngModel=v,d.choiceGrouped=function(e){return d.isGrouped&&e&&e.name},o.tabindex&&o.$observe("tabindex",function(e){d.focusInput.attr("tabindex",e),s.removeAttr("tabindex")});var m=i.$eval(o.searchEnabled);d.searchEnabled=void 0!==m?m:t.searchEnabled;var g=i.$eval(o.sortable);d.sortable=void 0!==g?g:t.sortable,o.$observe("disabled",function(){d.disabled=void 0!==o.disabled?o.disabled:!1}),o.$observe("resetSearchInput",function(){var e=i.$eval(o.resetSearchInput);d.resetSearchInput=void 0!==e?e:!0}),angular.isDefined(o.autofocus)&&l(function(){d.setFocus()}),angular.isDefined(o.focusOn)&&i.$on(o.focusOn,function(){l(function(){d.setFocus()})}),e.on("click",p),i.$on("$destroy",function(){e.off("click",p)}),u(i,function(e){var t=angular.element("
    ").append(e),r=t.querySelectorAll(".ui-select-match");if(r.removeAttr("ui-select-match"),r.removeAttr("data-ui-select-match"),1!==r.length)throw n("transcluded","Expected 1 .ui-select-match but got '{0}'.",r.length);s.querySelectorAll(".ui-select-match").replaceWith(r);var i=t.querySelectorAll(".ui-select-choices");if(i.removeAttr("ui-select-choices"),i.removeAttr("data-ui-select-choices"),1!==i.length)throw n("transcluded","Expected 1 .ui-select-choices but got '{0}'.",i.length);s.querySelectorAll(".ui-select-choices").replaceWith(i)});var $=i.$eval(o.appendToBody);(void 0!==$?$:t.appendToBody)&&(i.$watch("$select.open",function(e){e?f():h()}),i.$on("$destroy",function(){h()}));var E=null,S="",y=null,b="direction-up";i.$watch("$select.open",function(t){if(t){if(y=angular.element(s).querySelectorAll(".ui-select-dropdown"),null===y)return;y[0].style.opacity=0,l(function(){var t=r(s),n=r(y);t.top+t.height+n.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&(y[0].style.position="absolute",y[0].style.top=-1*n.height+"px",s.addClass(b)),y[0].style.opacity=1})}else{if(null===y)return;y[0].style.position="",y[0].style.top="",s.removeClass(b)}})}}}}]),n.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,r=t.parent().attr("multiple");return n+(r?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,r,i){function c(e){i.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}i.lockChoiceExpression=r.uiLockChoice,r.$observe("placeholder",function(t){i.placeholder=void 0!==t?t:e.placeholder}),r.$observe("allowClear",c),c(r.allowClear),i.multiple&&i.sizeSearchInput()}}}]),n.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,r=this,i=e.$select;e.$evalAsync(function(){n=e.ngModel}),r.activeMatchIndex=-1,r.updateModel=function(){n.$setViewValue(Date.now()),r.refreshComponent()},r.refreshComponent=function(){i.refreshItems(),i.sizeSearchInput()},r.removeChoice=function(n){var c=i.selected[n];if(!c._uiSelectChoiceLocked){var l={};l[i.parserResult.itemName]=c,i.selected.splice(n,1),r.activeMatchIndex=-1,i.sizeSearchInput(),t(function(){i.onRemoveCallback(e,{$item:c,$model:i.parserResult.modelMapper(e,l)})}),r.updateModel()}},r.getPlaceholder=function(){return i.selected&&i.selected.length?void 0:i.placeholder}}],controllerAs:"$selectMultiple",link:function(r,i,c,l){function s(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function o(t){function n(){switch(t){case e.LEFT:return~p.activeMatchIndex?f:l;case e.RIGHT:return~p.activeMatchIndex&&o!==l?u:(a.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(o),f):l;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),o):!1}}var r=s(a.searchInput[0]),i=a.selected.length,c=0,l=i-1,o=p.activeMatchIndex,u=p.activeMatchIndex+1,f=p.activeMatchIndex-1,h=o;return r>0||a.search.length&&t==e.RIGHT?!1:(a.close(),h=n(),p.activeMatchIndex=a.selected.length&&h!==!1?Math.min(l,Math.max(c,h)):-1,!0)}var a=l[0],u=r.ngModel=l[1],p=r.$selectMultiple;a.multiple=!0,a.removeSelected=!0,a.focusInput=a.searchInput,u.$parsers.unshift(function(){for(var e,t={},n=[],i=a.selected.length-1;i>=0;i--)t={},t[a.parserResult.itemName]=a.selected[i],e=a.parserResult.modelMapper(r,t),n.unshift(e);return n}),u.$formatters.unshift(function(e){var t,n=a.parserResult.source(r,{$select:{search:""}}),i={};if(!n)return e;var c=[],l=function(e,n){if(e&&e.length){for(var l=e.length-1;l>=0;l--){if(i[a.parserResult.itemName]=e[l],t=a.parserResult.modelMapper(r,i),a.parserResult.trackByExp){var s=/\.(.+)/.exec(a.parserResult.trackByExp);if(s.length>0&&t[s[1]]==n[s[1]])return c.unshift(e[l]),!0}if(angular.equals(t,n))return c.unshift(e[l]),!0}return!1}};if(!e)return c;for(var s=e.length-1;s>=0;s--)l(a.selected,e[s])||l(n,e[s])||c.unshift(e[s]);return c}),r.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);a.selected=[]}a.selected=u.$viewValue,r.$evalAsync()},r.$on("uis:select",function(e,t){a.selected.length>=a.limit||(a.selected.push(t),p.updateModel())}),r.$on("uis:activate",function(){p.activeMatchIndex=-1}),r.$watch("$select.disabled",function(e,t){t&&!e&&a.sizeSearchInput()}),a.searchInput.on("keydown",function(t){var n=t.which;r.$apply(function(){var t=!1;e.isHorizontalMovement(n)&&(t=o(n)),t&&n!=e.TAB})}),a.searchInput.on("blur",function(){n(function(){p.activeMatchIndex=-1})})}}}]),n.directive("uiSelectSingle",["$timeout","$compile",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(r,i,c,l){var s=l[0],o=l[1];o.$parsers.unshift(function(e){var t,n={};return n[s.parserResult.itemName]=e,t=s.parserResult.modelMapper(r,n)}),o.$formatters.unshift(function(e){var t,n=s.parserResult.source(r,{$select:{search:""}}),i={};if(n){var c=function(n){return i[s.parserResult.itemName]=n,t=s.parserResult.modelMapper(r,i),t==e};if(s.selected&&c(s.selected))return s.selected;for(var l=n.length-1;l>=0;l--)if(c(n[l]))return n[l]}return e}),r.$watch("$select.selected",function(e){o.$viewValue!==e&&o.$setViewValue(e)}),o.$render=function(){s.selected=o.$viewValue},r.$on("uis:select",function(e,t){s.selected=t}),r.$on("uis:close",function(e,n){t(function(){s.focusser.prop("disabled",!1),n||s.focusser[0].focus()},0,!1)}),r.$on("uis:activate",function(){a.prop("disabled",!0)});var a=angular.element("");n(a)(r),s.focusser=a,s.focusInput=a,i.parent().append(a),a.bind("focus",function(){r.$evalAsync(function(){s.focus=!0})}),a.bind("blur",function(){r.$evalAsync(function(){s.focus=!1})}),a.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),s.select(void 0),r.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),s.activate()),r.$digest()),void 0)}),a.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(s.activate(a.val()),a.val(""),r.$digest())})}}}]),n.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var r=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!r)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:r[2],source:t(r[3]),trackByExp:r[4],modelMapper:t(r[1]||r[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,r){var i=e+" in "+(r?"$group.items":t);return n&&(i+=" track by "+n),i}}])}(); \ No newline at end of file +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var n=t.which;switch(n){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,n=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,r,i){i(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var r=n[0].getBoundingClientRect();return{width:r.width||n.prop("offsetWidth"),height:r.height||n.prop("offsetHeight"),top:r.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:r.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);n.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,r){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,i){if(!i.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,i,c,l,o){var a=c.groupBy,s=c.groupFilter;if(l.parseRepeatAttr(c.repeat,a,s),l.disableChoiceExpression=c.uiDisableChoice,l.onHighlightCallback=c.onHighlight,a){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=i.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(l.parserResult.itemName,"$select.items",l.parserResult.trackByExp,a)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+l.parserResult.itemName+")").attr("ng-click","$select.select("+l.parserResult.itemName+",false,$event)");var f=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==f.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",f.length);f.attr("uis-transclude-append",""),r(i,o)(e),e.$watch("$select.search",function(e){e&&!l.open&&l.multiple&&l.activate(!1,!0),l.activeIndex=0})}}}}]),n.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,n,r,i,c,l,o,a){function s(){(d.resetSearchInput||void 0===d.resetSearchInput&&a.resetSearchInput)&&(d.search=h,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function u(e,t){var n,r,i=[];for(n=0;n0&&d.activeIndex--;break;case e.TAB:(!d.multiple||d.open)&&d.select(d.items[d.activeIndex],!0);break;case e.ENTER:d.open?d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case e.ESC:d.close();break;default:n=!1}return n}function f(){var e=n.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw o("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(d.activeIndex<0)){var r=t[d.activeIndex],i=r.offsetTop+r.clientHeight-e[0].scrollTop,c=e[0].offsetHeight;i>c?e[0].scrollTop+=i-c:i=d.items.length?0:d.activeIndex,r(function(){d.search=e||d.search,d.searchInput[0].focus()}))},d.parseRepeatAttr=function(e,n,r){function i(e){var i=t.$eval(n);if(d.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(i)?i(e):e[i],n=d.findGroupByName(t);n?n.items.push(e):d.groups.push({name:t,items:[e]})}),r){var c=t.$eval(r);angular.isFunction(c)?d.groups=c(d.groups):angular.isArray(c)&&(d.groups=u(d.groups,c))}d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function c(e){d.items=e}d.setItemsFn=n?i:c,d.parserResult=l.parse(e),d.isGrouped=!!n,d.itemProperty=d.parserResult.itemName,d.refreshItems=function(e){e=e||d.parserResult.source(t);var n=d.selected;if(d.isEmpty()||angular.isArray(n)&&!n.length||!d.removeSelected)d.setItemsFn(e);else if(void 0!==e){var r=e.filter(function(e){return n.indexOf(e)<0});d.setItemsFn(r)}},t.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw o("items","Expected an array but got '{0}'.",e);d.refreshItems(e),d.ngModel.$modelValue=null}})},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){if(!d.open)return!1;var t=d.items.indexOf(e[d.itemProperty]),n=t===d.activeIndex;return n&&!angular.isUndefined(d.onHighlightCallback)&&e.$eval(d.onHighlightCallback),n},d.isDisabled=function(e){if(!d.open)return!1;var t,n=d.items.indexOf(e[d.itemProperty]),r=!1;return n>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[n],r=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=r),r},d.select=function(e,n,i){if((void 0===e||!e._uiSelectChoiceDisabled)&&(d.items||d.search)){var c={};c[d.parserResult.itemName]=e;var l={$item:e,$model:d.parserResult.modelMapper(t,c)},o=function(){t.$broadcast("uis:select",e),r(function(){d.onSelectCallback(t,l)}),d.closeOnSelect&&d.close(n),i&&"click"===i.type&&(d.clickTriggeredSelect=!0)},a=d.onBeforeSelectCallback(t,l);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(e){e&&o(e)}):a===!0?o(e):a&&o(a):o(e)}},d.close=function(e){d.open&&(d.ngModel&&d.ngModel.$setTouched&&d.ngModel.$setTouched(),s(),d.open=!1,d.searchEnabled||angular.element(d.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e))},d.setFocus=function(){d.focus||d.focusInput[0].focus()},d.clear=function(e){d.select(void 0),e.stopPropagation(),r(function(){d.focusser[0].focus()},0,!1)},d.toggle=function(e){d.open?(d.close(),e.preventDefault(),e.stopPropagation()):d.activate()},d.isLocked=function(e,t){var n,r=d.selected[t];return r&&!angular.isUndefined(d.lockChoiceExpression)&&(n=!!e.$eval(d.lockChoiceExpression),r._uiSelectChoiceLocked=n),n};var v=null;d.sizeSearchInput=function(){var e=d.searchInput[0],n=d.searchInput.parent().parent()[0],i=function(){return n.clientWidth*!!e.offsetParent},c=function(t){if(0===t)return!1;var n=t-e.offsetLeft-d.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=t),d.searchInput.css("width",n+"px"),!0};d.searchInput.css("width","10px"),r(function(){null!==v||c(i())||(v=t.$watch(i,function(e){c(e)&&(v(),v=null)}))})},d.searchInput.on("keydown",function(n){var r=n.which;t.$apply(function(){p(r)}),e.isVerticalMovement(r)&&d.items.length>0&&f(),(r===e.ENTER||r===e.ESC)&&(n.preventDefault(),n.stopPropagation())}),d.searchInput.on("keyup",function(n){n.which===e.TAB||e.isControl(n)||e.isFunctionKey(n)||n.which===e.ESC||e.isVerticalMovement(n.which)||void 0!==d.onKeypressCallback&&d.onKeypressCallback(t,{event:n})}),t.$on("$destroy",function(){d.searchInput.off("keyup keydown blur paste")})}]),n.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,r,i,c,l){return{restrict:"EA",templateUrl:function(e,n){var r=n.theme||t.theme;return r+(angular.isDefined(n.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(i,o){return angular.isDefined(o.multiple)?i.append("").removeAttr("multiple"):i.append(""),function(i,o,a,s,u){function p(e){if(h.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(o[0],e.target):o[0].contains(e.target),!t&&!h.clickTriggeredSelect){var n=["input","button","textarea"],r=angular.element(e.target).scope(),c=r&&r.$select&&r.$select!==h;c||(c=~n.indexOf(e.target.tagName.toLowerCase())),h.close(c),i.$digest()}h.clickTriggeredSelect=!1}}function f(){var t=r(o);$=angular.element('
    '),$[0].style.width=t.width+"px",$[0].style.height=t.height+"px",o.after($),S=o[0].style.width,e.find("body").append(o),o[0].style.position="absolute",o[0].style.left=t.left+"px",o[0].style.top=t.top+"px",o[0].style.width=t.width+"px"}function d(){null!==$&&($.replaceWith(o),$=null,o[0].style.position="",o[0].style.left="",o[0].style.top="",o[0].style.width=S)}var h=s[0],v=s[1];h.generatedId=t.generateId(),h.baseTitle=a.title||"Select box",h.focusserTitle=h.baseTitle+" focus",h.focusserId="focusser-"+h.generatedId,h.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?c(a.closeOnSelect)():t.closeOnSelect}(),h.onSelectCallback=c(a.onSelect),h.onBeforeSelectCallback=c(a.onBeforeSelect),h.onRemoveCallback=c(a.onRemove),h.onBeforeRemoveCallback=c(a.onBeforeRemove),h.onKeypressCallback=c(a.onKeypress),h.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,h.ngModel=v,h.choiceGrouped=function(e){return h.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){h.focusInput.attr("tabindex",e),o.removeAttr("tabindex")});var m=i.$eval(a.searchEnabled);h.searchEnabled=void 0!==m?m:t.searchEnabled;var g=i.$eval(a.sortable);h.sortable=void 0!==g?g:t.sortable,a.$observe("disabled",function(){h.disabled=void 0!==a.disabled?a.disabled:!1}),angular.isDefined(a.autofocus)&&l(function(){h.setFocus()}),angular.isDefined(a.focusOn)&&i.$on(a.focusOn,function(){l(function(){h.setFocus()})}),e.on("click",p),i.$on("$destroy",function(){e.off("click",p)}),u(i,function(e){var t=angular.element("
    ").append(e),r=t.querySelectorAll(".ui-select-match");if(r.removeAttr("ui-select-match"),r.removeAttr("data-ui-select-match"),1!==r.length)throw n("transcluded","Expected 1 .ui-select-match but got '{0}'.",r.length);o.querySelectorAll(".ui-select-match").replaceWith(r);var i=t.querySelectorAll(".ui-select-choices");if(i.removeAttr("ui-select-choices"),i.removeAttr("data-ui-select-choices"),1!==i.length)throw n("transcluded","Expected 1 .ui-select-choices but got '{0}'.",i.length);o.querySelectorAll(".ui-select-choices").replaceWith(i)});var E=i.$eval(a.appendToBody);(void 0!==E?E:t.appendToBody)&&(i.$watch("$select.open",function(e){e?f():d()}),i.$on("$destroy",function(){d()}));var $=null,S="",b=null,C="direction-up";i.$watch("$select.open",function(t){if(t){if(b=angular.element(o).querySelectorAll(".ui-select-dropdown"),null===b)return;b[0].style.opacity=0,l(function(){var t=r(o),n=r(b);t.top+t.height+n.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&o.addClass(C),b[0].style.opacity=1})}else{if(null===b)return;o.removeClass(C)}})}}}}]),n.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,r=t.parent().attr("multiple");return n+(r?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,r,i){function c(e){i.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}i.lockChoiceExpression=r.uiLockChoice,r.$observe("placeholder",function(t){i.placeholder=void 0!==t?t:e.placeholder}),r.$observe("allowClear",c),c(r.allowClear),i.multiple&&i.sizeSearchInput()}}}]),n.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,r=this,i=e.$select;e.$evalAsync(function(){n=e.ngModel}),r.activeMatchIndex=-1,r.updateModel=function(){n.$setViewValue(Date.now()),r.refreshComponent()},r.refreshComponent=function(){i.refreshItems(),i.sizeSearchInput()},r.removeChoice=function(n){function c(){t(function(){i.onRemoveCallback(e,a)}),r.updateModel()}var l=i.selected[n];if(!l._uiSelectChoiceLocked){var o={};o[i.parserResult.itemName]=l,i.selected.splice(n,1),r.activeMatchIndex=-1,i.sizeSearchInput();var a={$item:l,$model:i.parserResult.modelMapper(e,o)},s=r.onBeforeRemoveCallback(e,a);angular.isDefined(s)?angular.isFunction(s.then)?s.then(function(e){e&&c(e)}):s===!0&&c():c()}},r.getPlaceholder=function(){return i.selected&&i.selected.length?void 0:i.placeholder}}],controllerAs:"$selectMultiple",link:function(r,i,c,l){function o(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(t){function n(){switch(t){case e.LEFT:return~p.activeMatchIndex?f:l;case e.RIGHT:return~p.activeMatchIndex&&a!==l?u:(s.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(a),f):l;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),a):!1}}var r=o(s.searchInput[0]),i=s.selected.length,c=0,l=i-1,a=p.activeMatchIndex,u=p.activeMatchIndex+1,f=p.activeMatchIndex-1,d=a;return r>0||s.search.length&&t==e.RIGHT?!1:(s.close(),d=n(),p.activeMatchIndex=s.selected.length&&d!==!1?Math.min(l,Math.max(c,d)):-1,!0)}var s=l[0],u=r.ngModel=l[1],p=r.$selectMultiple;s.multiple=!0,s.removeSelected=!0,s.focusInput=s.searchInput,u.$parsers.unshift(function(){for(var e,t={},n=[],i=s.selected.length-1;i>=0;i--)t={},t[s.parserResult.itemName]=s.selected[i],e=s.parserResult.modelMapper(r,t),n.unshift(e);return n}),u.$formatters.unshift(function(e){var t,n=s.parserResult.source(r,{$select:{search:""}}),i={};if(!n)return e;var c=[],l=function(e,n){if(e&&e.length){for(var l=e.length-1;l>=0;l--){if(i[s.parserResult.itemName]=e[l],t=s.parserResult.modelMapper(r,i),s.parserResult.trackByExp){var o=/\.(.+)/.exec(s.parserResult.trackByExp);if(o.length>0&&t[o[1]]==n[o[1]])return c.unshift(e[l]),!0}if(angular.equals(t,n))return c.unshift(e[l]),!0}return!1}};if(!e)return c;for(var o=e.length-1;o>=0;o--)l(s.selected,e[o])||l(n,e[o])||c.unshift(e[o]);return c}),r.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);s.selected=[]}s.selected=u.$viewValue,r.$evalAsync()},r.$on("uis:select",function(e,t){s.selected.length>=s.limit||(s.selected.push(t),p.updateModel())}),r.$on("uis:activate",function(){p.activeMatchIndex=-1}),r.$watch("$select.disabled",function(e,t){t&&!e&&s.sizeSearchInput()}),s.searchInput.on("keydown",function(t){var n=t.which;r.$apply(function(){var t=!1;e.isHorizontalMovement(n)&&(t=a(n)),t&&n!=e.TAB})}),s.searchInput.on("blur",function(){n(function(){p.activeMatchIndex=-1})})}}}]),n.directive("uiSelectSingle",["$timeout","$compile",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(r,i,c,l){var o=l[0],a=l[1];a.$parsers.unshift(function(e){var t,n={};return n[o.parserResult.itemName]=e,t=o.parserResult.modelMapper(r,n)}),a.$formatters.unshift(function(e){var t,n=o.parserResult.source(r,{$select:{search:""}}),i={};if(n){var c=function(n){return i[o.parserResult.itemName]=n,t=o.parserResult.modelMapper(r,i),t==e};if(o.selected&&c(o.selected))return o.selected;for(var l=n.length-1;l>=0;l--)if(c(n[l]))return n[l]}return e}),r.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){o.selected=a.$viewValue},r.$on("uis:select",function(e,t){o.selected=t}),r.$on("uis:close",function(e,n){t(function(){o.focusser.prop("disabled",!1),n||o.focusser[0].focus()},0,!1)}),r.$on("uis:activate",function(){s.prop("disabled",!0)});var s=angular.element("");n(s)(r),o.focusser=s,o.focusInput=s,i.parent().append(s),s.bind("focus",function(){r.$evalAsync(function(){o.focus=!0})}),s.bind("blur",function(){r.$evalAsync(function(){o.focus=!1})}),s.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),o.select(void 0),r.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),o.activate()),r.$digest()),void 0)}),s.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(o.activate(s.val()),s.val(""),r.$digest())})}}}]),n.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var r=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!r)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:r[2],source:t(r[3]),trackByExp:r[4],modelMapper:t(r[1]||r[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,r){var i=e+" in "+(r?"$group.items":t);return n&&(i+=" track by "+n),i}}])}(); \ No newline at end of file diff --git a/dist/select.select2.js b/dist/select.select2.js index 5898e0d1a..75952de02 100644 --- a/dist/select.select2.js +++ b/dist/select.select2.js @@ -1,14 +1,13 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-02T20:56:31.513Z + * Version: 0.12.1 - 2015-08-04T17:24:10.068Z * License: MIT */ (function () { "use strict"; - var KEY = { TAB: 9, ENTER: 13, @@ -29,20 +28,123 @@ var KEY = { DELETE: 46, COMMAND: 91, - MAP: { 91 : "COMMAND", 8 : "BACKSPACE" , 9 : "TAB" , 13 : "ENTER" , 16 : "SHIFT" , 17 : "CTRL" , 18 : "ALT" , 19 : "PAUSEBREAK" , 20 : "CAPSLOCK" , 27 : "ESC" , 32 : "SPACE" , 33 : "PAGE_UP", 34 : "PAGE_DOWN" , 35 : "END" , 36 : "HOME" , 37 : "LEFT" , 38 : "UP" , 39 : "RIGHT" , 40 : "DOWN" , 43 : "+" , 44 : "PRINTSCREEN" , 45 : "INSERT" , 46 : "DELETE", 48 : "0" , 49 : "1" , 50 : "2" , 51 : "3" , 52 : "4" , 53 : "5" , 54 : "6" , 55 : "7" , 56 : "8" , 57 : "9" , 59 : ";", 61 : "=" , 65 : "A" , 66 : "B" , 67 : "C" , 68 : "D" , 69 : "E" , 70 : "F" , 71 : "G" , 72 : "H" , 73 : "I" , 74 : "J" , 75 : "K" , 76 : "L", 77 : "M" , 78 : "N" , 79 : "O" , 80 : "P" , 81 : "Q" , 82 : "R" , 83 : "S" , 84 : "T" , 85 : "U" , 86 : "V" , 87 : "W" , 88 : "X" , 89 : "Y" , 90 : "Z", 96 : "0" , 97 : "1" , 98 : "2" , 99 : "3" , 100 : "4" , 101 : "5" , 102 : "6" , 103 : "7" , 104 : "8" , 105 : "9", 106 : "*" , 107 : "+" , 109 : "-" , 110 : "." , 111 : "/", 112 : "F1" , 113 : "F2" , 114 : "F3" , 115 : "F4" , 116 : "F5" , 117 : "F6" , 118 : "F7" , 119 : "F8" , 120 : "F9" , 121 : "F10" , 122 : "F11" , 123 : "F12", 144 : "NUMLOCK" , 145 : "SCROLLLOCK" , 186 : ";" , 187 : "=" , 188 : "," , 189 : "-" , 190 : "." , 191 : "/" , 192 : "`" , 219 : "[" , 220 : "\\" , 221 : "]" , 222 : "'" + MAP: { + 91: "COMMAND", + 8: "BACKSPACE", + 9: "TAB", + 13: "ENTER", + 16: "SHIFT", + 17: "CTRL", + 18: "ALT", + 19: "PAUSEBREAK", + 20: "CAPSLOCK", + 27: "ESC", + 32: "SPACE", + 33: "PAGE_UP", + 34: "PAGE_DOWN", + 35: "END", + 36: "HOME", + 37: "LEFT", + 38: "UP", + 39: "RIGHT", + 40: "DOWN", + 43: "+", + 44: "PRINTSCREEN", + 45: "INSERT", + 46: "DELETE", + 48: "0", + 49: "1", + 50: "2", + 51: "3", + 52: "4", + 53: "5", + 54: "6", + 55: "7", + 56: "8", + 57: "9", + 59: ";", + 61: "=", + 65: "A", + 66: "B", + 67: "C", + 68: "D", + 69: "E", + 70: "F", + 71: "G", + 72: "H", + 73: "I", + 74: "J", + 75: "K", + 76: "L", + 77: "M", + 78: "N", + 79: "O", + 80: "P", + 81: "Q", + 82: "R", + 83: "S", + 84: "T", + 85: "U", + 86: "V", + 87: "W", + 88: "X", + 89: "Y", + 90: "Z", + 96: "0", + 97: "1", + 98: "2", + 99: "3", + 100: "4", + 101: "5", + 102: "6", + 103: "7", + 104: "8", + 105: "9", + 106: "*", + 107: "+", + 109: "-", + 110: ".", + 111: "/", + 112: "F1", + 113: "F2", + 114: "F3", + 115: "F4", + 116: "F5", + 117: "F6", + 118: "F7", + 119: "F8", + 120: "F9", + 121: "F10", + 122: "F11", + 123: "F12", + 144: "NUMLOCK", + 145: "SCROLLLOCK", + 186: ";", + 187: "=", + 188: ",", + 189: "-", + 190: ".", + 191: "/", + 192: "`", + 219: "[", + 220: "\\", + 221: "]", + 222: "'" }, isControl: function (e) { var k = e.which; switch (k) { - case KEY.COMMAND: - case KEY.SHIFT: - case KEY.CTRL: - case KEY.ALT: - return true; + case KEY.COMMAND: + case KEY.SHIFT: + case KEY.CTRL: + case KEY.ALT: + return true; } - if (e.metaKey) return true; + if (e.metaKey) { + return true; + } return false; }, @@ -50,13 +152,13 @@ var KEY = { k = k.which ? k.which : k; return k >= 112 && k <= 123; }, - isVerticalMovement: function (k){ - return ~[KEY.UP, KEY.DOWN].indexOf(k); + isVerticalMovement: function (k) { + return ~[KEY.UP, KEY.DOWN].indexOf(k); }, - isHorizontalMovement: function (k){ - return ~[KEY.LEFT,KEY.RIGHT,KEY.BACKSPACE,KEY.DELETE].indexOf(k); + isHorizontalMovement: function (k) { + return ~[KEY.LEFT, KEY.RIGHT, KEY.BACKSPACE, KEY.DELETE].indexOf(k); } - }; +}; /** * Add querySelectorAll() to jqLite. @@ -68,67 +170,67 @@ var KEY = { * See feat(jqLite): use querySelectorAll instead of getElementsByTagName in jqLite.find https://github.com/angular/angular.js/pull/3598 */ if (angular.element.prototype.querySelectorAll === undefined) { - angular.element.prototype.querySelectorAll = function(selector) { - return angular.element(this[0].querySelectorAll(selector)); - }; + angular.element.prototype.querySelectorAll = function (selector) { + return angular.element(this[0].querySelectorAll(selector)); + }; } /** * Add closest() to jqLite. */ if (angular.element.prototype.closest === undefined) { - angular.element.prototype.closest = function( selector) { - var elem = this[0]; - var matchesSelector = elem.matches || elem.webkitMatchesSelector || elem.mozMatchesSelector || elem.msMatchesSelector; - - while (elem) { - if (matchesSelector.bind(elem)(selector)) { - return elem; - } else { - elem = elem.parentElement; - } - } - return false; - }; + angular.element.prototype.closest = function (selector) { + var elem = this[0]; + var matchesSelector = elem.matches || elem.webkitMatchesSelector || elem.mozMatchesSelector || + elem.msMatchesSelector; + + while (elem) { + if (matchesSelector.bind(elem)(selector)) { + return elem; + } else { + elem = elem.parentElement; + } + } + return false; + }; } var latestId = 0; var uis = angular.module('ui.select', []) -.constant('uiSelectConfig', { - theme: 'bootstrap', - searchEnabled: true, - sortable: false, - placeholder: '', // Empty by default, like HTML tag + closeOnSelect: true, + generateId: function () { + return latestId++; + }, + appendToBody: false + }) // See Rename minErr and make it accessible from outside https://github.com/angular/angular.js/issues/6913 -.service('uiSelectMinErr', function() { - var minErr = angular.$$minErr('ui.select'); - return function() { - var error = minErr.apply(this, arguments); - var message = error.message.replace(new RegExp('\nhttp://errors.angularjs.org/.*'), ''); - return new Error(message); - }; -}) + .service('uiSelectMinErr', function () { + var minErr = angular.$$minErr('ui.select'); + return function () { + var error = minErr.apply(this, arguments); + var message = error.message.replace(new RegExp('\nhttp://errors.angularjs.org/.*'), ''); + return new Error(message); + }; + }) // Recreates old behavior of ng-transclude. Used internally. -.directive('uisTranscludeAppend', function () { - return { - link: function (scope, element, attrs, ctrl, transclude) { - transclude(scope, function (clone) { - element.append(clone); - }); - } - }; -}) + .directive('uisTranscludeAppend', function () { + return { + link: function (scope, element, attrs, ctrl, transclude) { + transclude(scope, function (clone) { + element.append(clone); + }); + } + }; + }) /** * Highlights text that matches $select.search. @@ -136,15 +238,16 @@ var uis = angular.module('ui.select', []) * Taken from AngularUI Bootstrap Typeahead * See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L340 */ -.filter('highlight', function() { - function escapeRegexp(queryToEscape) { - return queryToEscape.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1'); - } + .filter('highlight', function () { + function escapeRegexp(queryToEscape) { + return queryToEscape.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1'); + } - return function(matchItem, query) { - return query && matchItem ? matchItem.replace(new RegExp(escapeRegexp(query), 'gi'), '$&') : matchItem; - }; -}) + return function (matchItem, query) { + return query && matchItem ? matchItem.replace(new RegExp(escapeRegexp(query), 'gi'), + '$&') : matchItem; + }; + }) /** * A read-only equivalent of jQuery's offset function: http://api.jquery.com/offset/ @@ -152,96 +255,92 @@ var uis = angular.module('ui.select', []) * Taken from AngularUI Bootstrap Position: * See https://github.com/angular-ui/bootstrap/blob/master/src/position/position.js#L70 */ -.factory('uisOffset', - ['$document', '$window', - function ($document, $window) { - - return function(element) { - var boundingClientRect = element[0].getBoundingClientRect(); - return { - width: boundingClientRect.width || element.prop('offsetWidth'), - height: boundingClientRect.height || element.prop('offsetHeight'), - top: boundingClientRect.top + ($window.pageYOffset || $document[0].documentElement.scrollTop), - left: boundingClientRect.left + ($window.pageXOffset || $document[0].documentElement.scrollLeft) - }; - }; -}]); + .factory('uisOffset', + ['$document', '$window', + function ($document, $window) { + + return function (element) { + var boundingClientRect = element[0].getBoundingClientRect(); + return { + width: boundingClientRect.width || element.prop('offsetWidth'), + height: boundingClientRect.height || element.prop('offsetHeight'), + top: boundingClientRect.top + ($window.pageYOffset || $document[0].documentElement.scrollTop), + left: boundingClientRect.left + ($window.pageXOffset || $document[0].documentElement.scrollLeft) + }; + }; + }]); uis.directive('uiSelectChoices', - ['uiSelectConfig', 'uisRepeatParser', 'uiSelectMinErr', '$compile', - function(uiSelectConfig, RepeatParser, uiSelectMinErr, $compile) { - - return { - restrict: 'EA', - require: '^uiSelect', - replace: true, - transclude: true, - templateUrl: function(tElement) { - // Gets theme attribute from parent (ui-select) - var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; - return theme + '/choices.tpl.html'; - }, + ['uiSelectConfig', 'uisRepeatParser', 'uiSelectMinErr', '$compile', + function (uiSelectConfig, RepeatParser, uiSelectMinErr, $compile) { - compile: function(tElement, tAttrs) { + return { + restrict: 'EA', + require: '^uiSelect', + replace: true, + transclude: true, + templateUrl: function (tElement) { + // Gets theme attribute from parent (ui-select) + var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; + return theme + '/choices.tpl.html'; + }, - if (!tAttrs.repeat) throw uiSelectMinErr('repeat', "Expected 'repeat' expression."); + compile: function (tElement, tAttrs) { - return function link(scope, element, attrs, $select, transcludeFn) { + if (!tAttrs.repeat) { + throw uiSelectMinErr('repeat', "Expected 'repeat' expression."); + } - // var repeat = RepeatParser.parse(attrs.repeat); - var groupByExp = attrs.groupBy; - var groupFilterExp = attrs.groupFilter; + return function link(scope, element, attrs, $select, transcludeFn) { - $select.parseRepeatAttr(attrs.repeat, groupByExp, groupFilterExp); //Result ready at $select.parserResult + // var repeat = RepeatParser.parse(attrs.repeat); + var groupByExp = attrs.groupBy; + var groupFilterExp = attrs.groupFilter; - $select.disableChoiceExpression = attrs.uiDisableChoice; - $select.onHighlightCallback = attrs.onHighlight; + $select.parseRepeatAttr(attrs.repeat, groupByExp, groupFilterExp); //Result ready at $select.parserResult - $select.refreshOnActive = scope.$eval(attrs.refreshOnActive); + $select.disableChoiceExpression = attrs.uiDisableChoice; + $select.onHighlightCallback = attrs.onHighlight; - if(groupByExp) { - var groups = element.querySelectorAll('.ui-select-choices-group'); - if (groups.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-group but got '{0}'.", groups.length); - groups.attr('ng-repeat', RepeatParser.getGroupNgRepeatExpression()); - } + if (groupByExp) { + var groups = element.querySelectorAll('.ui-select-choices-group'); + if (groups.length !== 1) throw uiSelectMinErr('rows', + "Expected 1 .ui-select-choices-group but got '{0}'.", groups.length); + groups.attr('ng-repeat', RepeatParser.getGroupNgRepeatExpression()); + } - var choices = element.querySelectorAll('.ui-select-choices-row'); - if (choices.length !== 1) { - throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row but got '{0}'.", choices.length); - } + var choices = element.querySelectorAll('.ui-select-choices-row'); + if (choices.length !== 1) { + throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row but got '{0}'.", + choices.length); + } - choices.attr('ng-repeat', RepeatParser.getNgRepeatExpression($select.parserResult.itemName, '$select.items', $select.parserResult.trackByExp, groupByExp)) - .attr('ng-if', '$select.open') //Prevent unnecessary watches when dropdown is closed - .attr('ng-mouseenter', '$select.setActiveItem('+$select.parserResult.itemName +')') - .attr('ng-click', '$select.select(' + $select.parserResult.itemName + ',false,$event)'); - - var rowsInner = element.querySelectorAll('.ui-select-choices-row-inner'); - if (rowsInner.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row-inner but got '{0}'.", rowsInner.length); - rowsInner.attr('uis-transclude-append', ''); //Adding uisTranscludeAppend directive to row element after choices element has ngRepeat - - $compile(element, transcludeFn)(scope); //Passing current transcludeFn to be able to append elements correctly from uisTranscludeAppend - - scope.$watch('$select.search', function(newValue) { - if(newValue && !$select.open && $select.multiple) $select.activate(false, true); - $select.activeIndex = 0; - if(!$select.refreshOnActive || ($select.refreshOnActive && $select.refreshIsActive)) { - $select.refresh(attrs.refresh); - } - }); - - scope.$watch('$select.refreshIsActive', function(newValue, oldValue){ - if(angular.isUndefined(oldValue) && newValue){ - $select.refresh(attrs.refresh); - } - }); - - // $eval() is needed otherwise we get a string instead of a number - var refreshDelay = scope.$eval(attrs.refreshDelay); - $select.refreshDelay = refreshDelay !== undefined ? refreshDelay : uiSelectConfig.refreshDelay; - }; - } - }; -}]); + choices.attr('ng-repeat', + RepeatParser.getNgRepeatExpression($select.parserResult.itemName, '$select.items', + $select.parserResult.trackByExp, groupByExp)) + .attr('ng-if', '$select.open') //Prevent unnecessary watches when dropdown is closed + .attr('ng-mouseenter', '$select.setActiveItem(' + $select.parserResult.itemName + ')') + .attr('ng-click', '$select.select(' + $select.parserResult.itemName + ',false,$event)'); + + var rowsInner = element.querySelectorAll('.ui-select-choices-row-inner'); + if (rowsInner.length !== 1) { + throw uiSelectMinErr('rows', + "Expected 1 .ui-select-choices-row-inner but got '{0}'.", rowsInner.length); + } + rowsInner.attr('uis-transclude-append', ''); //Adding uisTranscludeAppend directive to row element after choices element has ngRepeat + + $compile(element, transcludeFn)(scope); //Passing current transcludeFn to be able to append elements correctly from uisTranscludeAppend + + scope.$watch('$select.search', function (newValue) { + if (newValue && !$select.open && $select.multiple) { + $select.activate(false, true); + } + $select.activeIndex = 0; + }); + }; + } + }; + }]); /** * Contains ui-select "intelligence". @@ -260,7 +359,6 @@ uis.controller('uiSelectCtrl', ctrl.placeholder = uiSelectConfig.placeholder; ctrl.searchEnabled = uiSelectConfig.searchEnabled; ctrl.sortable = uiSelectConfig.sortable; - ctrl.refreshDelay = uiSelectConfig.refreshDelay; ctrl.removeSelected = false; //If selected item(s) should be removed from dropdown list ctrl.closeOnSelect = true; //Initialized inside uiSelect directive link function @@ -281,8 +379,6 @@ uis.controller('uiSelectCtrl', ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelectMatch directive link function ctrl.clickTriggeredSelect = false; ctrl.$filter = $filter; - ctrl.refreshOnActive = undefined; - ctrl.refreshIsActive = undefined; ctrl.searchInput = $element.querySelectorAll('input.ui-select-search'); if (ctrl.searchInput.length !== 1) { @@ -290,6 +386,10 @@ uis.controller('uiSelectCtrl', ctrl.searchInput.length); } + /** + * Returns true if the selection is empty + * @returns {boolean|*} + */ ctrl.isEmpty = function () { return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === ''; }; @@ -305,6 +405,12 @@ uis.controller('uiSelectCtrl', } } + ctrl.findGroupByName = function (name) { + return ctrl.groups && ctrl.groups.filter(function (group) { + return group.name === name; + })[0]; + }; + function _groupsFilter(groups, groupNames) { var i, j, result = []; for (i = 0; i < groupNames.length; i++) { @@ -317,10 +423,15 @@ uis.controller('uiSelectCtrl', return result; } - // When the user clicks on ui-select, displays the dropdown list + /** + * Activates the control. + * When the user clicks on ui-select, displays the dropdown list + */ ctrl.activate = function (initSearchValue, avoidReset) { if (!ctrl.disabled && !ctrl.open) { - if (!avoidReset) _resetSearchInput(); + if (!avoidReset) { + _resetSearchInput(); + } $scope.$broadcast('uis:activate'); @@ -330,7 +441,6 @@ uis.controller('uiSelectCtrl', } ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex; - ctrl.refreshIsActive = true; // Give it time to appear before focus $timeout(function () { @@ -344,12 +454,6 @@ uis.controller('uiSelectCtrl', } }; - ctrl.findGroupByName = function (name) { - return ctrl.groups && ctrl.groups.filter(function (group) { - return group.name === name; - })[0]; - }; - ctrl.parseRepeatAttr = function (repeatAttr, groupByExp, groupFilterExp) { function updateGroups(items) { var groupFn = $scope.$eval(groupByExp); @@ -382,6 +486,7 @@ uis.controller('uiSelectCtrl', ctrl.items = items; } + // Set the function to use when displaying items - either groups or single ctrl.setItemsFn = groupByExp ? updateGroups : setPlainItems; ctrl.parserResult = RepeatParser.parse(repeatAttr); @@ -392,7 +497,7 @@ uis.controller('uiSelectCtrl', ctrl.refreshItems = function (data) { data = data || ctrl.parserResult.source($scope); var selectedItems = ctrl.selected; - //TODO should implement for single mode removeSelected + // TODO should implement for single mode removeSelected if (ctrl.isEmpty() || (angular.isArray(selectedItems) && !selectedItems.length) || !ctrl.removeSelected) { ctrl.setItemsFn(data); @@ -424,35 +529,17 @@ uis.controller('uiSelectCtrl', } } }); - - }; - - var _refreshDelayPromise; - - /** - * Typeahead mode: lets the user refresh the collection using his own function. - * - * See Expose $select.search for external / remote filtering https://github.com/angular-ui/ui-select/pull/31 - */ - ctrl.refresh = function (refreshAttr) { - if (refreshAttr !== undefined) { - - // Debounce - // See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L155 - // FYI AngularStrap typeahead does not have debouncing: https://github.com/mgcrea/angular-strap/blob/v2.0.0-rc.4/src/typeahead/typeahead.js#L177 - if (_refreshDelayPromise) { - $timeout.cancel(_refreshDelayPromise); - } - _refreshDelayPromise = $timeout(function () { - $scope.$eval(refreshAttr); - }, ctrl.refreshDelay); - } }; ctrl.setActiveItem = function (item) { ctrl.activeIndex = ctrl.items.indexOf(item); }; + /** + * Checks if the item is active + * @param itemScope the item + * @returns {boolean} true if active + */ ctrl.isActive = function (itemScope) { if (!ctrl.open) { return false; @@ -469,11 +556,14 @@ uis.controller('uiSelectCtrl', /** * Checks if the item is disabled - * @return boolean true if the item is disabled + * @param itemScope the item + * @return {boolean} true if the item is disabled */ ctrl.isDisabled = function (itemScope) { - if (!ctrl.open) return false; + if (!ctrl.open) { + return false; + } var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); var isDisabled = false; @@ -490,75 +580,81 @@ uis.controller('uiSelectCtrl', /** + * Selects an item + * * Called when the user selects an item with ENTER or clicks the dropdown */ ctrl.select = function (item, skipFocusser, $event) { - if (item === undefined || !item._uiSelectChoiceDisabled) { - - if (!ctrl.items && !ctrl.search){ - return; - } - - if (!item || !item._uiSelectChoiceDisabled) { + if (item !== undefined && item._uiSelectChoiceDisabled) { + return; + } - var completeSelection = function () { - $scope.$broadcast('uis:select', item); + // If no items in the list, and no search, then return + if (!ctrl.items && !ctrl.search) { + return; + } - $timeout(function () { - ctrl.onSelectCallback($scope, callbackContext); - }); + // Create the data used to pass to the callbacks + var locals = {}; + locals[ctrl.parserResult.itemName] = item; + var callbackContext = { + $item: item, + $model: ctrl.parserResult.modelMapper($scope, locals) + }; - if (ctrl.closeOnSelect) { - ctrl.close(skipFocusser); - } - if ($event && $event.type === 'click') { - ctrl.clickTriggeredSelect = true; - } - }; + // Local method called when we complete the select + // eg. called after the onselect callback + var completeSelection = function () { + $scope.$broadcast('uis:select', item); - var locals = {}; - locals[ctrl.parserResult.itemName] = item; + $timeout(function () { + ctrl.onSelectCallback($scope, callbackContext); + }); - var callbackContext = { - $item: item, - $model: ctrl.parserResult.modelMapper($scope, locals) - }; + if (ctrl.closeOnSelect) { + ctrl.close(skipFocusser); + } + if ($event && $event.type === 'click') { + ctrl.clickTriggeredSelect = true; + } + }; - // Call the onBeforeSelect callback - // Allowable responses are -: - // falsy: Abort the selection - // promise: Wait for response - // true: Complete selection - // object: Add the returned object - var onBeforeSelectResult = ctrl.onBeforeSelectCallback($scope, callbackContext); - if (angular.isDefined(onBeforeSelectResult)) { - if (!onBeforeSelectResult) { - return; // abort the selection in case of deliberate falsey result - } else if (angular.isFunction(onBeforeSelectResult.then)) { - onBeforeSelectResult.then(function (result) { - if (!result) { - return; - } - completeSelection(result); - }); - } else if (onBeforeSelectResult === true) { - completeSelection(item); - } else { - completeSelection(onBeforeSelectResult); + // Call the onBeforeSelect callback + // Allowable responses are -: + // falsy: Abort the selection + // promise: Wait for response + // true: Complete selection + // object: Add the returned object + var onBeforeSelectResult = ctrl.onBeforeSelectCallback($scope, callbackContext); + if (angular.isDefined(onBeforeSelectResult)) { + if (angular.isFunction(onBeforeSelectResult.then)) { + // Promise returned - wait for it to complete before completing the selection + onBeforeSelectResult.then(function (result) { + if (!result) { + return; } - } else { - completeSelection(item); - } + completeSelection(result); + }); + } else if (onBeforeSelectResult === true) { + completeSelection(item); + } else if (onBeforeSelectResult) { + completeSelection(onBeforeSelectResult); } + } else { + completeSelection(item); } }; - // Closes the dropdown + /** + * Close the dropdown + */ ctrl.close = function (skipFocusser) { if (!ctrl.open) { return; } - if (ctrl.ngModel && ctrl.ngModel.$setTouched) ctrl.ngModel.$setTouched(); + if (ctrl.ngModel && ctrl.ngModel.$setTouched) { + ctrl.ngModel.$setTouched(); + } _resetSearchInput(); ctrl.open = false; if (!ctrl.searchEnabled) { @@ -568,12 +664,19 @@ uis.controller('uiSelectCtrl', $scope.$broadcast('uis:close', skipFocusser); }; + /** + * Set focus on the control + */ ctrl.setFocus = function () { if (!ctrl.focus) { ctrl.focusInput[0].focus(); } }; + /** + * Clears the selection + * @param $event + */ ctrl.clear = function ($event) { ctrl.select(undefined); $event.stopPropagation(); @@ -582,7 +685,9 @@ uis.controller('uiSelectCtrl', }, 0, false); }; - // Toggle dropdown + /** + * Toggle the dropdown open and closed + */ ctrl.toggle = function (e) { if (ctrl.open) { ctrl.close(); @@ -606,7 +711,6 @@ uis.controller('uiSelectCtrl', var sizeWatch = null; ctrl.sizeSearchInput = function () { - var input = ctrl.searchInput[0], container = ctrl.searchInput.parent().parent()[0], calculateContainerWidth = function () { @@ -659,7 +763,9 @@ uis.controller('uiSelectCtrl', } break; case KEY.TAB: - if (!ctrl.multiple || ctrl.open) ctrl.select(ctrl.items[ctrl.activeIndex], true); + if (!ctrl.multiple || ctrl.open) { + ctrl.select(ctrl.items[ctrl.activeIndex], true); + } break; case KEY.ENTER: if (ctrl.open) { @@ -703,24 +809,6 @@ uis.controller('uiSelectCtrl', } }); - // If tagging try to split by tokens and add items - /* ctrl.searchInput.on('paste', function (e) { - var data = e.originalEvent.clipboardData.getData('text/plain'); - if (data && data.length > 0 && ctrl.taggingTokens.isActivated && ctrl.tagging.fct) { - var items = data.split(ctrl.taggingTokens.tokens[0]); // split by first token only - if (items && items.length > 0) { - angular.forEach(items, function (item) { - var newItem = ctrl.tagging.fct(item); - if (newItem) { - ctrl.select(newItem, true); - } - }); - e.preventDefault(); - e.stopPropagation(); - } - } - });*/ - ctrl.searchInput.on('keyup', function (e) { // return early with these keys if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || @@ -734,7 +822,6 @@ uis.controller('uiSelectCtrl', ctrl.onKeypressCallback($scope, {event: e}); }); - // See https://github.com/ivaynberg/select2/blob/3.4.6/select2.js#L1431 function _ensureHighlightVisible() { var container = $element.querySelectorAll('.ui-select-choices-content'); @@ -755,10 +842,13 @@ uis.controller('uiSelectCtrl', if (posY > height) { container[0].scrollTop += posY - height; } else if (posY < highlighted.clientHeight) { - if (ctrl.isGrouped && ctrl.activeIndex === 0) - container[0].scrollTop = 0; //To make group header visible when going all the way up - else + if (ctrl.isGrouped && ctrl.activeIndex === 0) { + //To make group header visible when going all the way up + container[0].scrollTop = 0; + } + else { container[0].scrollTop -= highlighted.clientHeight - posY; + } } } @@ -811,9 +901,10 @@ uis.directive('uiSelect', } }(); - $select.onBeforeSelectCallback = $parse(attrs.onBeforeSelect); $select.onSelectCallback = $parse(attrs.onSelect); + $select.onBeforeSelectCallback = $parse(attrs.onBeforeSelect); $select.onRemoveCallback = $parse(attrs.onRemove); + $select.onBeforeRemoveCallback = $parse(attrs.onBeforeRemove); $select.onKeypressCallback = $parse(attrs.onKeypress); //Limit the number of selections allowed @@ -845,11 +936,6 @@ uis.directive('uiSelect', $select.disabled = attrs.disabled !== undefined ? attrs.disabled : false; }); - attrs.$observe('resetSearchInput', function () { - // $eval() is needed otherwise we get a string instead of a boolean - var resetSearchInput = scope.$eval(attrs.resetSearchInput); - $select.resetSearchInput = resetSearchInput !== undefined ? resetSearchInput : true; - }); //Automatically gets focus when loaded if (angular.isDefined(attrs.autofocus)) { @@ -1001,6 +1087,7 @@ uis.directive('uiSelect', // Support changing the direction of the dropdown if there isn't enough space to render it. scope.$watch('$select.open', function (isOpen) { if (isOpen) { + // Get the dropdown element dropdown = angular.element(element).querySelectorAll('.ui-select-dropdown'); if (dropdown === null) { return; @@ -1018,8 +1105,6 @@ uis.directive('uiSelect', if (offset.top + offset.height + offsetDropdown.height > $document[0].documentElement.scrollTop + $document[0].documentElement.clientHeight) { - dropdown[0].style.position = 'absolute'; - dropdown[0].style.top = (offsetDropdown.height * -1) + 'px'; element.addClass(directionUpClassName); } @@ -1032,8 +1117,6 @@ uis.directive('uiSelect', } // Reset the position of the dropdown. - dropdown[0].style.position = ''; - dropdown[0].style.top = ''; element.removeClass(directionUpClassName); } }); @@ -1042,425 +1125,479 @@ uis.directive('uiSelect', }; }]); -uis.directive('uiSelectMatch', ['uiSelectConfig', function(uiSelectConfig) { - return { - restrict: 'EA', - require: '^uiSelect', - replace: true, - transclude: true, - templateUrl: function(tElement) { - // Gets theme attribute from parent (ui-select) - var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; - var multi = tElement.parent().attr('multiple'); - return theme + (multi ? '/match-multiple.tpl.html' : '/match.tpl.html'); - }, - link: function(scope, element, attrs, $select) { - $select.lockChoiceExpression = attrs.uiLockChoice; - attrs.$observe('placeholder', function(placeholder) { - $select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder; - }); - - function setAllowClear(allow) { - $select.allowClear = (angular.isDefined(allow)) ? (allow === '') ? true : (allow.toLowerCase() === 'true') : false; - } +uis.directive('uiSelectMatch', ['uiSelectConfig', function (uiSelectConfig) { + return { + restrict: 'EA', + require: '^uiSelect', + replace: true, + transclude: true, + templateUrl: function (tElement) { + // Gets theme attribute from parent (ui-select) + var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; + var multi = tElement.parent().attr('multiple'); + return theme + (multi ? '/match-multiple.tpl.html' : '/match.tpl.html'); + }, + link: function (scope, element, attrs, $select) { + $select.lockChoiceExpression = attrs.uiLockChoice; + attrs.$observe('placeholder', function (placeholder) { + $select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder; + }); - attrs.$observe('allowClear', setAllowClear); - setAllowClear(attrs.allowClear); + function setAllowClear(allow) { + $select.allowClear = + (angular.isDefined(allow)) ? (allow === '') ? true : (allow.toLowerCase() === 'true') : false; + } - if($select.multiple){ - $select.sizeSearchInput(); - } + attrs.$observe('allowClear', setAllowClear); + setAllowClear(attrs.allowClear); - } - }; + if ($select.multiple) { + $select.sizeSearchInput(); + } + } + }; }]); -uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelectMinErr, $timeout) { - return { - restrict: 'EA', - require: ['^uiSelect', '^ngModel'], +uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSelectMinErr, $timeout) { + return { + restrict: 'EA', + require: ['^uiSelect', '^ngModel'], + controller: ['$scope', '$timeout', function ($scope, $timeout) { + var ctrl = this, + $select = $scope.$select, + ngModel; + + //Wait for link fn to inject it + $scope.$evalAsync(function () { + ngModel = $scope.ngModel; + }); + + ctrl.activeMatchIndex = -1; - controller: ['$scope','$timeout', function($scope, $timeout){ + ctrl.updateModel = function () { + ngModel.$setViewValue(Date.now()); //Set timestamp as a unique string to force changes + ctrl.refreshComponent(); + }; - var ctrl = this, - $select = $scope.$select, - ngModel; + ctrl.refreshComponent = function () { + // Remove already selected items + // e.g. When user clicks on a selection, the selected array changes and + // the dropdown should remove that item + $select.refreshItems(); + $select.sizeSearchInput(); + }; - //Wait for link fn to inject it - $scope.$evalAsync(function(){ ngModel = $scope.ngModel; }); + // Remove item from multiple select + ctrl.removeChoice = function (index) { + var removedChoice = $select.selected[index]; - ctrl.activeMatchIndex = -1; + // if the choice is locked, can't remove it + if (removedChoice._uiSelectChoiceLocked) { + return; + } - ctrl.updateModel = function(){ - ngModel.$setViewValue(Date.now()); //Set timestamp as a unique string to force changes - ctrl.refreshComponent(); - }; + var locals = {}; + locals[$select.parserResult.itemName] = removedChoice; - ctrl.refreshComponent = function(){ - //Remove already selected items - //e.g. When user clicks on a selection, the selected array changes and - //the dropdown should remove that item - $select.refreshItems(); - $select.sizeSearchInput(); - }; + $select.selected.splice(index, 1); + ctrl.activeMatchIndex = -1; + $select.sizeSearchInput(); - // Remove item from multiple select - ctrl.removeChoice = function(index){ + var callbackContext = { + $item: removedChoice, + $model: $select.parserResult.modelMapper($scope, locals) + }; - var removedChoice = $select.selected[index]; + // Give some time for scope propagation. + function completeRemoval() { + $timeout(function () { + $select.onRemoveCallback($scope, callbackContext); + }); - // if the choice is locked, can't remove it - if(removedChoice._uiSelectChoiceLocked) return; + ctrl.updateModel(); + } - var locals = {}; - locals[$select.parserResult.itemName] = removedChoice; + // Call the onBeforeRemove callback + // Allowable responses are -: + // falsy: Abort the removal + // promise: Wait for response + // true: Complete removal + var onBeforeRemoveResult = ctrl.onBeforeRemoveCallback($scope, callbackContext); + if (angular.isDefined(onBeforeRemoveResult)) { + if (angular.isFunction(onBeforeRemoveResult.then)) { + // Promise returned - wait for it to complete before completing the selection + onBeforeRemoveResult.then(function (result) { + if (!result) { + return; + } + completeRemoval(result); + }); + } else if (onBeforeRemoveResult === true) { + completeRemoval(); + } + } else { + completeRemoval(); + } + }; - $select.selected.splice(index, 1); - ctrl.activeMatchIndex = -1; - $select.sizeSearchInput(); + ctrl.getPlaceholder = function () { + //Refactor single? + if ($select.selected && $select.selected.length) { + return; + } + return $select.placeholder; + }; + }], + controllerAs: '$selectMultiple', + + link: function (scope, element, attrs, ctrls) { + var $select = ctrls[0]; + var ngModel = scope.ngModel = ctrls[1]; + var $selectMultiple = scope.$selectMultiple; + + //$select.selected = raw selected objects (ignoring any property binding) + + $select.multiple = true; + $select.removeSelected = true; + + //Input that will handle focus + $select.focusInput = $select.searchInput; + + //From view --> model + ngModel.$parsers.unshift(function () { + var locals = {}, + result, + resultMultiple = []; + for (var j = $select.selected.length - 1; j >= 0; j--) { + locals = {}; + locals[$select.parserResult.itemName] = $select.selected[j]; + result = $select.parserResult.modelMapper(scope, locals); + resultMultiple.unshift(result); + } + return resultMultiple; + }); - // Give some time for scope propagation. - $timeout(function(){ - $select.onRemoveCallback($scope, { - $item: removedChoice, - $model: $select.parserResult.modelMapper($scope, locals) - }); - }); + // From model --> view + ngModel.$formatters.unshift(function (inputValue) { + var data = $select.parserResult.source(scope, {$select: {search: ''}}), //Overwrite $search + locals = {}, + result; + if (!data) { + return inputValue; + } + var resultMultiple = []; + var checkFnMultiple = function (list, value) { + if (!list || !list.length) { + return; + } + for (var p = list.length - 1; p >= 0; p--) { + locals[$select.parserResult.itemName] = list[p]; + result = $select.parserResult.modelMapper(scope, locals); + if ($select.parserResult.trackByExp) { + var matches = /\.(.+)/.exec($select.parserResult.trackByExp); + if (matches.length > 0 && result[matches[1]] == value[matches[1]]) { + resultMultiple.unshift(list[p]); + return true; + } + } + if (angular.equals(result, value)) { + resultMultiple.unshift(list[p]); + return true; + } + } + return false; + }; + if (!inputValue) return resultMultiple; //If ngModel was undefined + for (var k = inputValue.length - 1; k >= 0; k--) { + //Check model array of currently selected items + if (!checkFnMultiple($select.selected, inputValue[k])) { + //Check model array of all items available + if (!checkFnMultiple(data, inputValue[k])) { + //If not found on previous lists, just add it directly to resultMultiple + resultMultiple.unshift(inputValue[k]); + } + } + } + return resultMultiple; + }); - ctrl.updateModel(); + //Watch for external model changes + scope.$watchCollection(function () { + return ngModel.$modelValue; + }, function (newValue, oldValue) { + if (oldValue != newValue) { + ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters + $selectMultiple.refreshComponent(); + } + }); - }; + ngModel.$render = function () { + // Make sure that model value is array + if (!angular.isArray(ngModel.$viewValue)) { + // Have tolerance for null or undefined values + if (angular.isUndefined(ngModel.$viewValue) || ngModel.$viewValue === null) { + $select.selected = []; + } else { + throw uiSelectMinErr('multiarr', "Expected model value to be array but got '{0}'", + ngModel.$viewValue); + } + } + $select.selected = ngModel.$viewValue; + scope.$evalAsync(); //To force $digest + }; - ctrl.getPlaceholder = function(){ - //Refactor single? - if($select.selected && $select.selected.length) return; - return $select.placeholder; - }; + scope.$on('uis:select', function (event, item) { + if ($select.selected.length >= $select.limit) { + return; + } + $select.selected.push(item); + $selectMultiple.updateModel(); + }); + scope.$on('uis:activate', function () { + $selectMultiple.activeMatchIndex = -1; + }); - }], - controllerAs: '$selectMultiple', + scope.$watch('$select.disabled', function (newValue, oldValue) { + // As the search input field may now become visible, it may be necessary to recompute its size + if (oldValue && !newValue) { + $select.sizeSearchInput(); + } + }); - link: function(scope, element, attrs, ctrls) { + $select.searchInput.on('keydown', function (e) { + var key = e.which; + scope.$apply(function () { + var processed = false; + if (KEY.isHorizontalMovement(key)) { + processed = _handleMatchSelection(key); + } + if (processed && key != KEY.TAB) { + //TODO Check si el tab selecciona aun correctamente + //Crear test +// e.preventDefault(); + // e.stopPropagation(); + } + }); + }); + function _getCaretPosition(el) { + if (angular.isNumber(el.selectionStart)) { + return el.selectionStart; + } + // selectionStart is not supported in IE8 and we don't want hacky workarounds so we compromise + else { + return el.value.length; + } + } - var $select = ctrls[0]; - var ngModel = scope.ngModel = ctrls[1]; - var $selectMultiple = scope.$selectMultiple; + // Handles selected options in "multiple" mode + function _handleMatchSelection(key) { + var caretPosition = _getCaretPosition($select.searchInput[0]), + length = $select.selected.length, + first = 0, + last = length - 1, + curr = $selectMultiple.activeMatchIndex, + next = $selectMultiple.activeMatchIndex + 1, + prev = $selectMultiple.activeMatchIndex - 1, + newIndex = curr; + + if (caretPosition > 0 || ($select.search.length && key == KEY.RIGHT)) { + return false; + } - //$select.selected = raw selected objects (ignoring any property binding) + $select.close(); - $select.multiple = true; - $select.removeSelected = true; + function getNewActiveMatchIndex() { + switch (key) { + case KEY.LEFT: + // Select previous/first item + if (~$selectMultiple.activeMatchIndex) { + return prev; + } + // Select last item + else { + return last; + } + break; + case KEY.RIGHT: + // Open drop-down + if (!~$selectMultiple.activeMatchIndex || curr === last) { + $select.activate(); + return false; + } + // Select next/last item + else { + return next; + } + break; + case KEY.BACKSPACE: + // Remove selected item and select previous/first + if (~$selectMultiple.activeMatchIndex) { + $selectMultiple.removeChoice(curr); + return prev; + } + // Select last item + else { + return last; + } + break; + case KEY.DELETE: + // Remove selected item and select next item + if (~$selectMultiple.activeMatchIndex) { + $selectMultiple.removeChoice($selectMultiple.activeMatchIndex); + return curr; + } + else { + return false; + } + } + } - //Input that will handle focus - $select.focusInput = $select.searchInput; + newIndex = getNewActiveMatchIndex(); - //From view --> model - ngModel.$parsers.unshift(function () { - var locals = {}, - result, - resultMultiple = []; - for (var j = $select.selected.length - 1; j >= 0; j--) { - locals = {}; - locals[$select.parserResult.itemName] = $select.selected[j]; - result = $select.parserResult.modelMapper(scope, locals); - resultMultiple.unshift(result); - } - return resultMultiple; - }); - - // From model --> view - ngModel.$formatters.unshift(function (inputValue) { - var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search - locals = {}, - result; - if (!data) return inputValue; - var resultMultiple = []; - var checkFnMultiple = function(list, value){ - if (!list || !list.length) return; - for (var p = list.length - 1; p >= 0; p--) { - locals[$select.parserResult.itemName] = list[p]; - result = $select.parserResult.modelMapper(scope, locals); - if($select.parserResult.trackByExp){ - var matches = /\.(.+)/.exec($select.parserResult.trackByExp); - if(matches.length>0 && result[matches[1]] == value[matches[1]]){ - resultMultiple.unshift(list[p]); - return true; + if (!$select.selected.length || newIndex === false) { + $selectMultiple.activeMatchIndex = -1; } + else { + $selectMultiple.activeMatchIndex = Math.min(last, Math.max(first, newIndex)); + } + + return true; } - if (angular.equals(result,value)){ - resultMultiple.unshift(list[p]); - return true; - } - } - return false; - }; - if (!inputValue) return resultMultiple; //If ngModel was undefined - for (var k = inputValue.length - 1; k >= 0; k--) { - //Check model array of currently selected items - if (!checkFnMultiple($select.selected, inputValue[k])){ - //Check model array of all items available - if (!checkFnMultiple(data, inputValue[k])){ - //If not found on previous lists, just add it directly to resultMultiple - resultMultiple.unshift(inputValue[k]); - } - } - } - return resultMultiple; - }); - - //Watch for external model changes - scope.$watchCollection(function(){ return ngModel.$modelValue; }, function(newValue, oldValue) { - if (oldValue != newValue){ - ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters - $selectMultiple.refreshComponent(); - } - }); - - ngModel.$render = function() { - // Make sure that model value is array - if(!angular.isArray(ngModel.$viewValue)){ - // Have tolerance for null or undefined values - if(angular.isUndefined(ngModel.$viewValue) || ngModel.$viewValue === null){ - $select.selected = []; - } else { - throw uiSelectMinErr('multiarr', "Expected model value to be array but got '{0}'", ngModel.$viewValue); - } - } - $select.selected = ngModel.$viewValue; - scope.$evalAsync(); //To force $digest - }; - scope.$on('uis:select', function (event, item) { - if($select.selected.length >= $select.limit) { - return; - } - $select.selected.push(item); - $selectMultiple.updateModel(); - }); - - scope.$on('uis:activate', function () { - $selectMultiple.activeMatchIndex = -1; - }); - - scope.$watch('$select.disabled', function(newValue, oldValue) { - // As the search input field may now become visible, it may be necessary to recompute its size - if (oldValue && !newValue) $select.sizeSearchInput(); - }); - - $select.searchInput.on('keydown', function(e) { - var key = e.which; - scope.$apply(function() { - var processed = false; - if(KEY.isHorizontalMovement(key)){ - processed = _handleMatchSelection(key); - } - if (processed && key != KEY.TAB) { - //TODO Check si el tab selecciona aun correctamente - //Crear test -// e.preventDefault(); - // e.stopPropagation(); - } - }); - }); - function _getCaretPosition(el) { - if(angular.isNumber(el.selectionStart)) return el.selectionStart; - // selectionStart is not supported in IE8 and we don't want hacky workarounds so we compromise - else return el.value.length; - } - // Handles selected options in "multiple" mode - function _handleMatchSelection(key){ - var caretPosition = _getCaretPosition($select.searchInput[0]), - length = $select.selected.length, - // none = -1, - first = 0, - last = length-1, - curr = $selectMultiple.activeMatchIndex, - next = $selectMultiple.activeMatchIndex+1, - prev = $selectMultiple.activeMatchIndex-1, - newIndex = curr; - - if(caretPosition > 0 || ($select.search.length && key == KEY.RIGHT)) return false; - - $select.close(); - - function getNewActiveMatchIndex(){ - switch(key){ - case KEY.LEFT: - // Select previous/first item - if(~$selectMultiple.activeMatchIndex) return prev; - // Select last item - else return last; - break; - case KEY.RIGHT: - // Open drop-down - if(!~$selectMultiple.activeMatchIndex || curr === last){ - $select.activate(); - return false; - } - // Select next/last item - else return next; - break; - case KEY.BACKSPACE: - // Remove selected item and select previous/first - if(~$selectMultiple.activeMatchIndex){ - $selectMultiple.removeChoice(curr); - return prev; - } - // Select last item - else return last; - break; - case KEY.DELETE: - // Remove selected item and select next item - if(~$selectMultiple.activeMatchIndex){ - $selectMultiple.removeChoice($selectMultiple.activeMatchIndex); - return curr; - } - else return false; - } + $select.searchInput.on('blur', function () { + $timeout(function () { + $selectMultiple.activeMatchIndex = -1; + }); + }); + } + }; +}]); - newIndex = getNewActiveMatchIndex(); +uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $compile) { + return { + restrict: 'EA', + require: ['^uiSelect', '^ngModel'], + link: function (scope, element, attrs, ctrls) { + + var $select = ctrls[0]; + var ngModel = ctrls[1]; + + //From view --> model + ngModel.$parsers.unshift(function (inputValue) { + var locals = {}, + result; + locals[$select.parserResult.itemName] = inputValue; + result = $select.parserResult.modelMapper(scope, locals); + return result; + }); - if(!$select.selected.length || newIndex === false) $selectMultiple.activeMatchIndex = -1; - else $selectMultiple.activeMatchIndex = Math.min(last,Math.max(first,newIndex)); + //From model --> view + ngModel.$formatters.unshift(function (inputValue) { + var data = $select.parserResult.source(scope, {$select: {search: ''}}), //Overwrite $search + locals = {}, + result; + if (data) { + var checkFnSingle = function (d) { + locals[$select.parserResult.itemName] = d; + result = $select.parserResult.modelMapper(scope, locals); + return result == inputValue; + }; + //If possible pass same object stored in $select.selected + if ($select.selected && checkFnSingle($select.selected)) { + return $select.selected; + } + for (var i = data.length - 1; i >= 0; i--) { + if (checkFnSingle(data[i])) { + return data[i]; + } + } + } + return inputValue; + }); - return true; - } + //Update viewValue if model change + scope.$watch('$select.selected', function (newValue) { + if (ngModel.$viewValue !== newValue) { + ngModel.$setViewValue(newValue); + } + }); - $select.searchInput.on('blur', function() { - $timeout(function() { - $selectMultiple.activeMatchIndex = -1; - }); - }); + ngModel.$render = function () { + $select.selected = ngModel.$viewValue; + }; - } - }; -}]); + scope.$on('uis:select', function (event, item) { + $select.selected = item; + }); -uis.directive('uiSelectSingle', ['$timeout','$compile', function($timeout, $compile) { - return { - restrict: 'EA', - require: ['^uiSelect', '^ngModel'], - link: function(scope, element, attrs, ctrls) { - - var $select = ctrls[0]; - var ngModel = ctrls[1]; - - //From view --> model - ngModel.$parsers.unshift(function (inputValue) { - var locals = {}, - result; - locals[$select.parserResult.itemName] = inputValue; - result = $select.parserResult.modelMapper(scope, locals); - return result; - }); - - //From model --> view - ngModel.$formatters.unshift(function (inputValue) { - var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search - locals = {}, - result; - if (data){ - var checkFnSingle = function(d){ - locals[$select.parserResult.itemName] = d; - result = $select.parserResult.modelMapper(scope, locals); - return result == inputValue; - }; - //If possible pass same object stored in $select.selected - if ($select.selected && checkFnSingle($select.selected)) { - return $select.selected; - } - for (var i = data.length - 1; i >= 0; i--) { - if (checkFnSingle(data[i])) return data[i]; - } - } - return inputValue; - }); + scope.$on('uis:close', function (event, skipFocusser) { + $timeout(function () { + $select.focusser.prop('disabled', false); + if (!skipFocusser) $select.focusser[0].focus(); + }, 0, false); + }); - //Update viewValue if model change - scope.$watch('$select.selected', function(newValue) { - if (ngModel.$viewValue !== newValue) { - ngModel.$setViewValue(newValue); - } - }); - - ngModel.$render = function() { - $select.selected = ngModel.$viewValue; - }; - - scope.$on('uis:select', function (event, item) { - $select.selected = item; - }); - - scope.$on('uis:close', function (event, skipFocusser) { - $timeout(function(){ - $select.focusser.prop('disabled', false); - if (!skipFocusser) $select.focusser[0].focus(); - },0,false); - }); - - scope.$on('uis:activate', function () { - focusser.prop('disabled', true); //Will reactivate it on .close() - }); - - //Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954 - var focusser = angular.element(""); - $compile(focusser)(scope); - $select.focusser = focusser; - - //Input that will handle focus - $select.focusInput = focusser; - - element.parent().append(focusser); - focusser.bind("focus", function(){ - scope.$evalAsync(function(){ - $select.focus = true; - }); - }); - focusser.bind("blur", function(){ - scope.$evalAsync(function(){ - $select.focus = false; - }); - }); - focusser.bind("keydown", function(e){ - - if (e.which === KEY.BACKSPACE) { - e.preventDefault(); - e.stopPropagation(); - $select.select(undefined); - scope.$apply(); - return; - } + scope.$on('uis:activate', function () { + focusser.prop('disabled', true); //Will reactivate it on .close() + }); - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) { - return; - } + //Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954 + var focusser = angular.element(""); + $compile(focusser)(scope); + $select.focusser = focusser; - if (e.which == KEY.DOWN || e.which == KEY.UP || e.which == KEY.ENTER || e.which == KEY.SPACE){ - e.preventDefault(); - e.stopPropagation(); - $select.activate(); - } + //Input that will handle focus + $select.focusInput = focusser; - scope.$digest(); - }); + element.parent().append(focusser); + focusser.bind("focus", function () { + scope.$evalAsync(function () { + $select.focus = true; + }); + }); + focusser.bind("blur", function () { + scope.$evalAsync(function () { + $select.focus = false; + }); + }); + focusser.bind("keydown", function (e) { - focusser.bind("keyup input", function(e){ + if (e.which === KEY.BACKSPACE) { + e.preventDefault(); + e.stopPropagation(); + $select.select(undefined); + scope.$apply(); + return; + } - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { - return; - } + if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) { + return; + } - $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input - focusser.val(''); - scope.$digest(); + if (e.which == KEY.DOWN || e.which == KEY.UP || e.which == KEY.ENTER || e.which == KEY.SPACE) { + e.preventDefault(); + e.stopPropagation(); + $select.activate(); + } - }); + scope.$digest(); + }); + focusser.bind("keyup input", function (e) { - } - }; + if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || + e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { + return; + } + + $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input + focusser.val(''); + scope.$digest(); + }); + } + }; }]); /** * Parses "repeat" attribute. @@ -1472,45 +1609,46 @@ uis.directive('uiSelectSingle', ['$timeout','$compile', function($timeout, $comp * https://github.com/angular-ui/ui-select/commit/5dd63ad#commitcomment-5504697 */ -uis.service('uisRepeatParser', ['uiSelectMinErr','$parse', function(uiSelectMinErr, $parse) { - var self = this; +uis.service('uisRepeatParser', ['uiSelectMinErr', '$parse', function (uiSelectMinErr, $parse) { + var self = this; - /** - * Example: - * expression = "address in addresses | filter: {street: $select.search} track by $index" - * itemName = "address", - * source = "addresses | filter: {street: $select.search}", - * trackByExp = "$index", - */ - self.parse = function(expression) { + /** + * Example: + * expression = "address in addresses | filter: {street: $select.search} track by $index" + * itemName = "address", + * source = "addresses | filter: {street: $select.search}", + * trackByExp = "$index", + */ + self.parse = function (expression) { - var match = expression.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/); + var match = expression.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/); - if (!match) { - throw uiSelectMinErr('iexp', "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.", - expression); - } + if (!match) { + throw uiSelectMinErr('iexp', + "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.", + expression); + } - return { - itemName: match[2], // (lhs) Left-hand side, - source: $parse(match[3]), - trackByExp: match[4], - modelMapper: $parse(match[1] || match[2]) - }; + return { + itemName: match[2], // (lhs) Left-hand side, + source: $parse(match[3]), + trackByExp: match[4], + modelMapper: $parse(match[1] || match[2]) + }; - }; + }; - self.getGroupNgRepeatExpression = function() { - return '$group in $select.groups'; - }; + self.getGroupNgRepeatExpression = function () { + return '$group in $select.groups'; + }; - self.getNgRepeatExpression = function(itemName, source, trackByExp, grouped) { - var expression = itemName + ' in ' + (grouped ? '$group.items' : source); - if (trackByExp) { - expression += ' track by ' + trackByExp; - } - return expression; - }; + self.getNgRepeatExpression = function (itemName, source, trackByExp, grouped) { + var expression = itemName + ' in ' + (grouped ? '$group.items' : source); + if (trackByExp) { + expression += ' track by ' + trackByExp; + } + return expression; + }; }]); }()); diff --git a/dist/select.select2.min.js b/dist/select.select2.min.js index 6934a9d78..b119c669d 100644 --- a/dist/select.select2.min.js +++ b/dist/select.select2.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-02T20:56:31.513Z + * Version: 0.12.1 - 2015-08-04T17:24:10.068Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],c=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(c.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,c=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",refreshDelay:1e3,closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,l,s){s(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(c){var l=c[0].getBoundingClientRect();return{width:l.width||c.prop("offsetWidth"),height:l.height||c.prop("offsetHeight"),top:l.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:l.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);c.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,c,l){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(s,i){if(!i.repeat)throw c("repeat","Expected 'repeat' expression.");return function(s,i,n,r,a){var o=n.groupBy,u=n.groupFilter;if(r.parseRepeatAttr(n.repeat,o,u),r.disableChoiceExpression=n.uiDisableChoice,r.onHighlightCallback=n.onHighlight,r.refreshOnActive=s.$eval(n.refreshOnActive),o){var p=i.querySelectorAll(".ui-select-choices-group");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",p.length);p.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=i.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(r.parserResult.itemName,"$select.items",r.parserResult.trackByExp,o)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+r.parserResult.itemName+")").attr("ng-click","$select.select("+r.parserResult.itemName+",false,$event)");var h=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==h.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",h.length);h.attr("uis-transclude-append",""),l(i,a)(s),s.$watch("$select.search",function(e){e&&!r.open&&r.multiple&&r.activate(!1,!0),r.activeIndex=0,(!r.refreshOnActive||r.refreshOnActive&&r.refreshIsActive)&&r.refresh(n.refresh)}),s.$watch("$select.refreshIsActive",function(e,t){angular.isUndefined(t)&&e&&r.refresh(n.refresh)});var f=s.$eval(n.refreshDelay);r.refreshDelay=void 0!==f?f:e.refreshDelay}}}}]),c.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,c,l,s,i,n,r,a){function o(){(h.resetSearchInput||void 0===h.resetSearchInput&&a.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var c,l,s=[];for(c=0;c0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:c=!1}return c}function d(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw r("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var l=t[h.activeIndex],s=l.offsetTop+l.clientHeight-e[0].scrollTop,i=e[0].offsetHeight;s>i?e[0].scrollTop+=s-i:s=h.items.length?0:h.activeIndex,h.refreshIsActive=!0,l(function(){h.search=e||h.search,h.searchInput[0].focus()}))},h.findGroupByName=function(e){return h.groups&&h.groups.filter(function(t){return t.name===e})[0]},h.parseRepeatAttr=function(e,c,l){function s(e){var s=t.$eval(c);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(s)?s(e):e[s],c=h.findGroupByName(t);c?c.items.push(e):h.groups.push({name:t,items:[e]})}),l){var i=t.$eval(l);angular.isFunction(i)?h.groups=i(h.groups):angular.isArray(i)&&(h.groups=u(h.groups,i))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function i(e){h.items=e}h.setItemsFn=c?s:i,h.parserResult=n.parse(e),h.isGrouped=!!c,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var c=h.selected;if(h.isEmpty()||angular.isArray(c)&&!c.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var l=e.filter(function(e){return c.indexOf(e)<0});h.setItemsFn(l)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw r("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})};var v;h.refresh=function(e){void 0!==e&&(v&&l.cancel(v),v=l(function(){t.$eval(e)},h.refreshDelay))},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),c=t===h.activeIndex;return c&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),c},h.isDisabled=function(e){if(!h.open)return!1;var t,c=h.items.indexOf(e[h.itemProperty]),l=!1;return c>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[c],l=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=l),l},h.select=function(e,c,s){if(void 0===e||!e._uiSelectChoiceDisabled){if(!h.items&&!h.search)return;if(!e||!e._uiSelectChoiceDisabled){var i=function(){t.$broadcast("uis:select",e),l(function(){h.onSelectCallback(t,r)}),h.closeOnSelect&&h.close(c),s&&"click"===s.type&&(h.clickTriggeredSelect=!0)},n={};n[h.parserResult.itemName]=e;var r={$item:e,$model:h.parserResult.modelMapper(t,n)},a=h.onBeforeSelectCallback(t,r);if(angular.isDefined(a)){if(!a)return;angular.isFunction(a.then)?a.then(function(e){e&&i(e)}):a===!0?i(e):i(a)}else i(e)}}},h.close=function(e){h.open&&(h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),o(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e))},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),l(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var c,l=h.selected[t];return l&&!angular.isUndefined(h.lockChoiceExpression)&&(c=!!e.$eval(h.lockChoiceExpression),l._uiSelectChoiceLocked=c),c};var g=null;h.sizeSearchInput=function(){var e=h.searchInput[0],c=h.searchInput.parent().parent()[0],s=function(){return c.clientWidth*!!e.offsetParent},i=function(t){if(0===t)return!1;var c=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>c&&(c=t),h.searchInput.css("width",c+"px"),!0};h.searchInput.css("width","10px"),l(function(){null!==g||i(s())||(g=t.$watch(s,function(e){i(e)&&(g(),g=null)}))})},h.searchInput.on("keydown",function(c){var l=c.which;t.$apply(function(){p(l)}),e.isVerticalMovement(l)&&h.items.length>0&&d(),(l===e.ENTER||l===e.ESC)&&(c.preventDefault(),c.stopPropagation())}),h.searchInput.on("keyup",function(c){c.which===e.TAB||e.isControl(c)||e.isFunctionKey(c)||c.which===e.ESC||e.isVerticalMovement(c.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:c})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),c.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,c,l,s,i,n){return{restrict:"EA",templateUrl:function(e,c){var l=c.theme||t.theme;return l+(angular.isDefined(c.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(s,r){return angular.isDefined(r.multiple)?s.append("").removeAttr("multiple"):s.append(""),function(s,r,a,o,u){function p(e){if(f.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(r[0],e.target):r[0].contains(e.target),!t&&!f.clickTriggeredSelect){var c=["input","button","textarea"],l=angular.element(e.target).scope(),i=l&&l.$select&&l.$select!==f;i||(i=~c.indexOf(e.target.tagName.toLowerCase())),f.close(i),s.$digest()}f.clickTriggeredSelect=!1}}function d(){var t=l(r);b=angular.element('
    '),b[0].style.width=t.width+"px",b[0].style.height=t.height+"px",r.after(b),E=r[0].style.width,e.find("body").append(r),r[0].style.position="absolute",r[0].style.left=t.left+"px",r[0].style.top=t.top+"px",r[0].style.width=t.width+"px"}function h(){null!==b&&(b.replaceWith(r),b=null,r[0].style.position="",r[0].style.left="",r[0].style.top="",r[0].style.width=E)}var f=o[0],v=o[1];f.generatedId=t.generateId(),f.baseTitle=a.title||"Select box",f.focusserTitle=f.baseTitle+" focus",f.focusserId="focusser-"+f.generatedId,f.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?i(a.closeOnSelect)():t.closeOnSelect}(),f.onBeforeSelectCallback=i(a.onBeforeSelect),f.onSelectCallback=i(a.onSelect),f.onRemoveCallback=i(a.onRemove),f.onKeypressCallback=i(a.onKeypress),f.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,f.ngModel=v,f.choiceGrouped=function(e){return f.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){f.focusInput.attr("tabindex",e),r.removeAttr("tabindex")});var g=s.$eval(a.searchEnabled);f.searchEnabled=void 0!==g?g:t.searchEnabled;var m=s.$eval(a.sortable);f.sortable=void 0!==m?m:t.sortable,a.$observe("disabled",function(){f.disabled=void 0!==a.disabled?a.disabled:!1}),a.$observe("resetSearchInput",function(){var e=s.$eval(a.resetSearchInput);f.resetSearchInput=void 0!==e?e:!0}),angular.isDefined(a.autofocus)&&n(function(){f.setFocus()}),angular.isDefined(a.focusOn)&&s.$on(a.focusOn,function(){n(function(){f.setFocus()})}),e.on("click",p),s.$on("$destroy",function(){e.off("click",p)}),u(s,function(e){var t=angular.element("
    ").append(e),l=t.querySelectorAll(".ui-select-match");if(l.removeAttr("ui-select-match"),l.removeAttr("data-ui-select-match"),1!==l.length)throw c("transcluded","Expected 1 .ui-select-match but got '{0}'.",l.length);r.querySelectorAll(".ui-select-match").replaceWith(l);var s=t.querySelectorAll(".ui-select-choices");if(s.removeAttr("ui-select-choices"),s.removeAttr("data-ui-select-choices"),1!==s.length)throw c("transcluded","Expected 1 .ui-select-choices but got '{0}'.",s.length);r.querySelectorAll(".ui-select-choices").replaceWith(s)});var $=s.$eval(a.appendToBody);(void 0!==$?$:t.appendToBody)&&(s.$watch("$select.open",function(e){e?d():h()}),s.$on("$destroy",function(){h()}));var b=null,E="",w=null,y="direction-up";s.$watch("$select.open",function(t){if(t){if(w=angular.element(r).querySelectorAll(".ui-select-dropdown"),null===w)return;w[0].style.opacity=0,n(function(){var t=l(r),c=l(w);t.top+t.height+c.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&(w[0].style.position="absolute",w[0].style.top=-1*c.height+"px",r.addClass(y)),w[0].style.opacity=1})}else{if(null===w)return;w[0].style.position="",w[0].style.top="",r.removeClass(y)}})}}}}]),c.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,l=t.parent().attr("multiple");return c+(l?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,l,s){function i(e){s.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}s.lockChoiceExpression=l.uiLockChoice,l.$observe("placeholder",function(t){s.placeholder=void 0!==t?t:e.placeholder}),l.$observe("allowClear",i),i(l.allowClear),s.multiple&&s.sizeSearchInput()}}}]),c.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var c,l=this,s=e.$select;e.$evalAsync(function(){c=e.ngModel}),l.activeMatchIndex=-1,l.updateModel=function(){c.$setViewValue(Date.now()),l.refreshComponent()},l.refreshComponent=function(){s.refreshItems(),s.sizeSearchInput()},l.removeChoice=function(c){var i=s.selected[c];if(!i._uiSelectChoiceLocked){var n={};n[s.parserResult.itemName]=i,s.selected.splice(c,1),l.activeMatchIndex=-1,s.sizeSearchInput(),t(function(){s.onRemoveCallback(e,{$item:i,$model:s.parserResult.modelMapper(e,n)})}),l.updateModel()}},l.getPlaceholder=function(){return s.selected&&s.selected.length?void 0:s.placeholder}}],controllerAs:"$selectMultiple",link:function(l,s,i,n){function r(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(t){function c(){switch(t){case e.LEFT:return~p.activeMatchIndex?d:n;case e.RIGHT:return~p.activeMatchIndex&&a!==n?u:(o.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(a),d):n;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),a):!1}}var l=r(o.searchInput[0]),s=o.selected.length,i=0,n=s-1,a=p.activeMatchIndex,u=p.activeMatchIndex+1,d=p.activeMatchIndex-1,h=a;return l>0||o.search.length&&t==e.RIGHT?!1:(o.close(),h=c(),p.activeMatchIndex=o.selected.length&&h!==!1?Math.min(n,Math.max(i,h)):-1,!0)}var o=n[0],u=l.ngModel=n[1],p=l.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,u.$parsers.unshift(function(){for(var e,t={},c=[],s=o.selected.length-1;s>=0;s--)t={},t[o.parserResult.itemName]=o.selected[s],e=o.parserResult.modelMapper(l,t),c.unshift(e);return c}),u.$formatters.unshift(function(e){var t,c=o.parserResult.source(l,{$select:{search:""}}),s={};if(!c)return e;var i=[],n=function(e,c){if(e&&e.length){for(var n=e.length-1;n>=0;n--){if(s[o.parserResult.itemName]=e[n],t=o.parserResult.modelMapper(l,s),o.parserResult.trackByExp){var r=/\.(.+)/.exec(o.parserResult.trackByExp);if(r.length>0&&t[r[1]]==c[r[1]])return i.unshift(e[n]),!0}if(angular.equals(t,c))return i.unshift(e[n]),!0}return!1}};if(!e)return i;for(var r=e.length-1;r>=0;r--)n(o.selected,e[r])||n(c,e[r])||i.unshift(e[r]);return i}),l.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);o.selected=[]}o.selected=u.$viewValue,l.$evalAsync()},l.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),p.updateModel())}),l.$on("uis:activate",function(){p.activeMatchIndex=-1}),l.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(t){var c=t.which;l.$apply(function(){var t=!1;e.isHorizontalMovement(c)&&(t=a(c)),t&&c!=e.TAB})}),o.searchInput.on("blur",function(){c(function(){p.activeMatchIndex=-1})})}}}]),c.directive("uiSelectSingle",["$timeout","$compile",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(l,s,i,n){var r=n[0],a=n[1];a.$parsers.unshift(function(e){var t,c={};return c[r.parserResult.itemName]=e,t=r.parserResult.modelMapper(l,c)}),a.$formatters.unshift(function(e){var t,c=r.parserResult.source(l,{$select:{search:""}}),s={};if(c){var i=function(c){return s[r.parserResult.itemName]=c,t=r.parserResult.modelMapper(l,s),t==e};if(r.selected&&i(r.selected))return r.selected;for(var n=c.length-1;n>=0;n--)if(i(c[n]))return c[n]}return e}),l.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){r.selected=a.$viewValue},l.$on("uis:select",function(e,t){r.selected=t}),l.$on("uis:close",function(e,c){t(function(){r.focusser.prop("disabled",!1),c||r.focusser[0].focus()},0,!1)}),l.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");c(o)(l),r.focusser=o,r.focusInput=o,s.parent().append(o),o.bind("focus",function(){l.$evalAsync(function(){r.focus=!0})}),o.bind("blur",function(){l.$evalAsync(function(){r.focus=!1})}),o.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),r.select(void 0),l.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),r.activate()),l.$digest()),void 0)}),o.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(r.activate(o.val()),o.val(""),l.$digest())})}}}]),c.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var l=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!l)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:l[2],source:t(l[3]),trackByExp:l[4],modelMapper:t(l[1]||l[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,l){var s=e+" in "+(l?"$group.items":t);return c&&(s+=" track by "+c),s}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("select2/choices.tpl.html",'
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    ')}]); \ No newline at end of file +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],c=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(c.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,c=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,l,n){n(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(c){var l=c[0].getBoundingClientRect();return{width:l.width||c.prop("offsetWidth"),height:l.height||c.prop("offsetHeight"),top:l.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:l.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);c.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,c,l){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(e,n){if(!n.repeat)throw c("repeat","Expected 'repeat' expression.");return function(e,n,i,s,r){var a=i.groupBy,o=i.groupFilter;if(s.parseRepeatAttr(i.repeat,a,o),s.disableChoiceExpression=i.uiDisableChoice,s.onHighlightCallback=i.onHighlight,a){var u=n.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=n.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(s.parserResult.itemName,"$select.items",s.parserResult.trackByExp,a)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+s.parserResult.itemName+")").attr("ng-click","$select.select("+s.parserResult.itemName+",false,$event)");var d=n.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),l(n,r)(e),e.$watch("$select.search",function(e){e&&!s.open&&s.multiple&&s.activate(!1,!0),s.activeIndex=0})}}}}]),c.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,c,l,n,i,s,r,a){function o(){(h.resetSearchInput||void 0===h.resetSearchInput&&a.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var c,l,n=[];for(c=0;c0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:c=!1}return c}function d(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw r("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var l=t[h.activeIndex],n=l.offsetTop+l.clientHeight-e[0].scrollTop,i=e[0].offsetHeight;n>i?e[0].scrollTop+=n-i:n=h.items.length?0:h.activeIndex,l(function(){h.search=e||h.search,h.searchInput[0].focus()}))},h.parseRepeatAttr=function(e,c,l){function n(e){var n=t.$eval(c);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(n)?n(e):e[n],c=h.findGroupByName(t);c?c.items.push(e):h.groups.push({name:t,items:[e]})}),l){var i=t.$eval(l);angular.isFunction(i)?h.groups=i(h.groups):angular.isArray(i)&&(h.groups=u(h.groups,i))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function i(e){h.items=e}h.setItemsFn=c?n:i,h.parserResult=s.parse(e),h.isGrouped=!!c,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var c=h.selected;if(h.isEmpty()||angular.isArray(c)&&!c.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var l=e.filter(function(e){return c.indexOf(e)<0});h.setItemsFn(l)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw r("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),c=t===h.activeIndex;return c&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),c},h.isDisabled=function(e){if(!h.open)return!1;var t,c=h.items.indexOf(e[h.itemProperty]),l=!1;return c>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[c],l=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=l),l},h.select=function(e,c,n){if((void 0===e||!e._uiSelectChoiceDisabled)&&(h.items||h.search)){var i={};i[h.parserResult.itemName]=e;var s={$item:e,$model:h.parserResult.modelMapper(t,i)},r=function(){t.$broadcast("uis:select",e),l(function(){h.onSelectCallback(t,s)}),h.closeOnSelect&&h.close(c),n&&"click"===n.type&&(h.clickTriggeredSelect=!0)},a=h.onBeforeSelectCallback(t,s);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(e){e&&r(e)}):a===!0?r(e):a&&r(a):r(e)}},h.close=function(e){h.open&&(h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),o(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e))},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),l(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var c,l=h.selected[t];return l&&!angular.isUndefined(h.lockChoiceExpression)&&(c=!!e.$eval(h.lockChoiceExpression),l._uiSelectChoiceLocked=c),c};var g=null;h.sizeSearchInput=function(){var e=h.searchInput[0],c=h.searchInput.parent().parent()[0],n=function(){return c.clientWidth*!!e.offsetParent},i=function(t){if(0===t)return!1;var c=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>c&&(c=t),h.searchInput.css("width",c+"px"),!0};h.searchInput.css("width","10px"),l(function(){null!==g||i(n())||(g=t.$watch(n,function(e){i(e)&&(g(),g=null)}))})},h.searchInput.on("keydown",function(c){var l=c.which;t.$apply(function(){p(l)}),e.isVerticalMovement(l)&&h.items.length>0&&d(),(l===e.ENTER||l===e.ESC)&&(c.preventDefault(),c.stopPropagation())}),h.searchInput.on("keyup",function(c){c.which===e.TAB||e.isControl(c)||e.isFunctionKey(c)||c.which===e.ESC||e.isVerticalMovement(c.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:c})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),c.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,c,l,n,i,s){return{restrict:"EA",templateUrl:function(e,c){var l=c.theme||t.theme;return l+(angular.isDefined(c.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(n,r){return angular.isDefined(r.multiple)?n.append("").removeAttr("multiple"):n.append(""),function(n,r,a,o,u){function p(e){if(f.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(r[0],e.target):r[0].contains(e.target),!t&&!f.clickTriggeredSelect){var c=["input","button","textarea"],l=angular.element(e.target).scope(),i=l&&l.$select&&l.$select!==f;i||(i=~c.indexOf(e.target.tagName.toLowerCase())),f.close(i),n.$digest()}f.clickTriggeredSelect=!1}}function d(){var t=l(r);b=angular.element('
    '),b[0].style.width=t.width+"px",b[0].style.height=t.height+"px",r.after(b),E=r[0].style.width,e.find("body").append(r),r[0].style.position="absolute",r[0].style.left=t.left+"px",r[0].style.top=t.top+"px",r[0].style.width=t.width+"px"}function h(){null!==b&&(b.replaceWith(r),b=null,r[0].style.position="",r[0].style.left="",r[0].style.top="",r[0].style.width=E)}var f=o[0],g=o[1];f.generatedId=t.generateId(),f.baseTitle=a.title||"Select box",f.focusserTitle=f.baseTitle+" focus",f.focusserId="focusser-"+f.generatedId,f.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?i(a.closeOnSelect)():t.closeOnSelect}(),f.onSelectCallback=i(a.onSelect),f.onBeforeSelectCallback=i(a.onBeforeSelect),f.onRemoveCallback=i(a.onRemove),f.onBeforeRemoveCallback=i(a.onBeforeRemove),f.onKeypressCallback=i(a.onKeypress),f.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,f.ngModel=g,f.choiceGrouped=function(e){return f.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){f.focusInput.attr("tabindex",e),r.removeAttr("tabindex")});var v=n.$eval(a.searchEnabled);f.searchEnabled=void 0!==v?v:t.searchEnabled;var m=n.$eval(a.sortable);f.sortable=void 0!==m?m:t.sortable,a.$observe("disabled",function(){f.disabled=void 0!==a.disabled?a.disabled:!1}),angular.isDefined(a.autofocus)&&s(function(){f.setFocus()}),angular.isDefined(a.focusOn)&&n.$on(a.focusOn,function(){s(function(){f.setFocus()})}),e.on("click",p),n.$on("$destroy",function(){e.off("click",p)}),u(n,function(e){var t=angular.element("
    ").append(e),l=t.querySelectorAll(".ui-select-match");if(l.removeAttr("ui-select-match"),l.removeAttr("data-ui-select-match"),1!==l.length)throw c("transcluded","Expected 1 .ui-select-match but got '{0}'.",l.length);r.querySelectorAll(".ui-select-match").replaceWith(l);var n=t.querySelectorAll(".ui-select-choices");if(n.removeAttr("ui-select-choices"),n.removeAttr("data-ui-select-choices"),1!==n.length)throw c("transcluded","Expected 1 .ui-select-choices but got '{0}'.",n.length);r.querySelectorAll(".ui-select-choices").replaceWith(n)});var $=n.$eval(a.appendToBody);(void 0!==$?$:t.appendToBody)&&(n.$watch("$select.open",function(e){e?d():h()}),n.$on("$destroy",function(){h()}));var b=null,E="",w=null,S="direction-up";n.$watch("$select.open",function(t){if(t){if(w=angular.element(r).querySelectorAll(".ui-select-dropdown"),null===w)return;w[0].style.opacity=0,s(function(){var t=l(r),c=l(w);t.top+t.height+c.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&r.addClass(S),w[0].style.opacity=1})}else{if(null===w)return;r.removeClass(S)}})}}}}]),c.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,l=t.parent().attr("multiple");return c+(l?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,l,n){function i(e){n.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}n.lockChoiceExpression=l.uiLockChoice,l.$observe("placeholder",function(t){n.placeholder=void 0!==t?t:e.placeholder}),l.$observe("allowClear",i),i(l.allowClear),n.multiple&&n.sizeSearchInput()}}}]),c.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var c,l=this,n=e.$select;e.$evalAsync(function(){c=e.ngModel}),l.activeMatchIndex=-1,l.updateModel=function(){c.$setViewValue(Date.now()),l.refreshComponent()},l.refreshComponent=function(){n.refreshItems(),n.sizeSearchInput()},l.removeChoice=function(c){function i(){t(function(){n.onRemoveCallback(e,a)}),l.updateModel()}var s=n.selected[c];if(!s._uiSelectChoiceLocked){var r={};r[n.parserResult.itemName]=s,n.selected.splice(c,1),l.activeMatchIndex=-1,n.sizeSearchInput();var a={$item:s,$model:n.parserResult.modelMapper(e,r)},o=l.onBeforeRemoveCallback(e,a);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(e){e&&i(e)}):o===!0&&i():i()}},l.getPlaceholder=function(){return n.selected&&n.selected.length?void 0:n.placeholder}}],controllerAs:"$selectMultiple",link:function(l,n,i,s){function r(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(t){function c(){switch(t){case e.LEFT:return~p.activeMatchIndex?d:s;case e.RIGHT:return~p.activeMatchIndex&&a!==s?u:(o.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(a),d):s;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),a):!1}}var l=r(o.searchInput[0]),n=o.selected.length,i=0,s=n-1,a=p.activeMatchIndex,u=p.activeMatchIndex+1,d=p.activeMatchIndex-1,h=a;return l>0||o.search.length&&t==e.RIGHT?!1:(o.close(),h=c(),p.activeMatchIndex=o.selected.length&&h!==!1?Math.min(s,Math.max(i,h)):-1,!0)}var o=s[0],u=l.ngModel=s[1],p=l.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,u.$parsers.unshift(function(){for(var e,t={},c=[],n=o.selected.length-1;n>=0;n--)t={},t[o.parserResult.itemName]=o.selected[n],e=o.parserResult.modelMapper(l,t),c.unshift(e);return c}),u.$formatters.unshift(function(e){var t,c=o.parserResult.source(l,{$select:{search:""}}),n={};if(!c)return e;var i=[],s=function(e,c){if(e&&e.length){for(var s=e.length-1;s>=0;s--){if(n[o.parserResult.itemName]=e[s],t=o.parserResult.modelMapper(l,n),o.parserResult.trackByExp){var r=/\.(.+)/.exec(o.parserResult.trackByExp);if(r.length>0&&t[r[1]]==c[r[1]])return i.unshift(e[s]),!0}if(angular.equals(t,c))return i.unshift(e[s]),!0}return!1}};if(!e)return i;for(var r=e.length-1;r>=0;r--)s(o.selected,e[r])||s(c,e[r])||i.unshift(e[r]);return i}),l.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);o.selected=[]}o.selected=u.$viewValue,l.$evalAsync()},l.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),p.updateModel())}),l.$on("uis:activate",function(){p.activeMatchIndex=-1}),l.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(t){var c=t.which;l.$apply(function(){var t=!1;e.isHorizontalMovement(c)&&(t=a(c)),t&&c!=e.TAB})}),o.searchInput.on("blur",function(){c(function(){p.activeMatchIndex=-1})})}}}]),c.directive("uiSelectSingle",["$timeout","$compile",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(l,n,i,s){var r=s[0],a=s[1];a.$parsers.unshift(function(e){var t,c={};return c[r.parserResult.itemName]=e,t=r.parserResult.modelMapper(l,c)}),a.$formatters.unshift(function(e){var t,c=r.parserResult.source(l,{$select:{search:""}}),n={};if(c){var i=function(c){return n[r.parserResult.itemName]=c,t=r.parserResult.modelMapper(l,n),t==e};if(r.selected&&i(r.selected))return r.selected;for(var s=c.length-1;s>=0;s--)if(i(c[s]))return c[s]}return e}),l.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){r.selected=a.$viewValue},l.$on("uis:select",function(e,t){r.selected=t}),l.$on("uis:close",function(e,c){t(function(){r.focusser.prop("disabled",!1),c||r.focusser[0].focus()},0,!1)}),l.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");c(o)(l),r.focusser=o,r.focusInput=o,n.parent().append(o),o.bind("focus",function(){l.$evalAsync(function(){r.focus=!0})}),o.bind("blur",function(){l.$evalAsync(function(){r.focus=!1})}),o.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),r.select(void 0),l.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),r.activate()),l.$digest()),void 0)}),o.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(r.activate(o.val()),o.val(""),l.$digest())})}}}]),c.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var l=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!l)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:l[2],source:t(l[3]),trackByExp:l[4],modelMapper:t(l[1]||l[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,l){var n=e+" in "+(l?"$group.items":t);return c&&(n+=" track by "+c),n}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("select2/choices.tpl.html",'
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/dist/select.selectize.js b/dist/select.selectize.js index 9f10f28b6..47a335033 100644 --- a/dist/select.selectize.js +++ b/dist/select.selectize.js @@ -1,14 +1,13 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-02T20:56:31.517Z + * Version: 0.12.1 - 2015-08-04T17:24:10.073Z * License: MIT */ (function () { "use strict"; - var KEY = { TAB: 9, ENTER: 13, @@ -29,20 +28,123 @@ var KEY = { DELETE: 46, COMMAND: 91, - MAP: { 91 : "COMMAND", 8 : "BACKSPACE" , 9 : "TAB" , 13 : "ENTER" , 16 : "SHIFT" , 17 : "CTRL" , 18 : "ALT" , 19 : "PAUSEBREAK" , 20 : "CAPSLOCK" , 27 : "ESC" , 32 : "SPACE" , 33 : "PAGE_UP", 34 : "PAGE_DOWN" , 35 : "END" , 36 : "HOME" , 37 : "LEFT" , 38 : "UP" , 39 : "RIGHT" , 40 : "DOWN" , 43 : "+" , 44 : "PRINTSCREEN" , 45 : "INSERT" , 46 : "DELETE", 48 : "0" , 49 : "1" , 50 : "2" , 51 : "3" , 52 : "4" , 53 : "5" , 54 : "6" , 55 : "7" , 56 : "8" , 57 : "9" , 59 : ";", 61 : "=" , 65 : "A" , 66 : "B" , 67 : "C" , 68 : "D" , 69 : "E" , 70 : "F" , 71 : "G" , 72 : "H" , 73 : "I" , 74 : "J" , 75 : "K" , 76 : "L", 77 : "M" , 78 : "N" , 79 : "O" , 80 : "P" , 81 : "Q" , 82 : "R" , 83 : "S" , 84 : "T" , 85 : "U" , 86 : "V" , 87 : "W" , 88 : "X" , 89 : "Y" , 90 : "Z", 96 : "0" , 97 : "1" , 98 : "2" , 99 : "3" , 100 : "4" , 101 : "5" , 102 : "6" , 103 : "7" , 104 : "8" , 105 : "9", 106 : "*" , 107 : "+" , 109 : "-" , 110 : "." , 111 : "/", 112 : "F1" , 113 : "F2" , 114 : "F3" , 115 : "F4" , 116 : "F5" , 117 : "F6" , 118 : "F7" , 119 : "F8" , 120 : "F9" , 121 : "F10" , 122 : "F11" , 123 : "F12", 144 : "NUMLOCK" , 145 : "SCROLLLOCK" , 186 : ";" , 187 : "=" , 188 : "," , 189 : "-" , 190 : "." , 191 : "/" , 192 : "`" , 219 : "[" , 220 : "\\" , 221 : "]" , 222 : "'" + MAP: { + 91: "COMMAND", + 8: "BACKSPACE", + 9: "TAB", + 13: "ENTER", + 16: "SHIFT", + 17: "CTRL", + 18: "ALT", + 19: "PAUSEBREAK", + 20: "CAPSLOCK", + 27: "ESC", + 32: "SPACE", + 33: "PAGE_UP", + 34: "PAGE_DOWN", + 35: "END", + 36: "HOME", + 37: "LEFT", + 38: "UP", + 39: "RIGHT", + 40: "DOWN", + 43: "+", + 44: "PRINTSCREEN", + 45: "INSERT", + 46: "DELETE", + 48: "0", + 49: "1", + 50: "2", + 51: "3", + 52: "4", + 53: "5", + 54: "6", + 55: "7", + 56: "8", + 57: "9", + 59: ";", + 61: "=", + 65: "A", + 66: "B", + 67: "C", + 68: "D", + 69: "E", + 70: "F", + 71: "G", + 72: "H", + 73: "I", + 74: "J", + 75: "K", + 76: "L", + 77: "M", + 78: "N", + 79: "O", + 80: "P", + 81: "Q", + 82: "R", + 83: "S", + 84: "T", + 85: "U", + 86: "V", + 87: "W", + 88: "X", + 89: "Y", + 90: "Z", + 96: "0", + 97: "1", + 98: "2", + 99: "3", + 100: "4", + 101: "5", + 102: "6", + 103: "7", + 104: "8", + 105: "9", + 106: "*", + 107: "+", + 109: "-", + 110: ".", + 111: "/", + 112: "F1", + 113: "F2", + 114: "F3", + 115: "F4", + 116: "F5", + 117: "F6", + 118: "F7", + 119: "F8", + 120: "F9", + 121: "F10", + 122: "F11", + 123: "F12", + 144: "NUMLOCK", + 145: "SCROLLLOCK", + 186: ";", + 187: "=", + 188: ",", + 189: "-", + 190: ".", + 191: "/", + 192: "`", + 219: "[", + 220: "\\", + 221: "]", + 222: "'" }, isControl: function (e) { var k = e.which; switch (k) { - case KEY.COMMAND: - case KEY.SHIFT: - case KEY.CTRL: - case KEY.ALT: - return true; + case KEY.COMMAND: + case KEY.SHIFT: + case KEY.CTRL: + case KEY.ALT: + return true; } - if (e.metaKey) return true; + if (e.metaKey) { + return true; + } return false; }, @@ -50,13 +152,13 @@ var KEY = { k = k.which ? k.which : k; return k >= 112 && k <= 123; }, - isVerticalMovement: function (k){ - return ~[KEY.UP, KEY.DOWN].indexOf(k); + isVerticalMovement: function (k) { + return ~[KEY.UP, KEY.DOWN].indexOf(k); }, - isHorizontalMovement: function (k){ - return ~[KEY.LEFT,KEY.RIGHT,KEY.BACKSPACE,KEY.DELETE].indexOf(k); + isHorizontalMovement: function (k) { + return ~[KEY.LEFT, KEY.RIGHT, KEY.BACKSPACE, KEY.DELETE].indexOf(k); } - }; +}; /** * Add querySelectorAll() to jqLite. @@ -68,67 +170,67 @@ var KEY = { * See feat(jqLite): use querySelectorAll instead of getElementsByTagName in jqLite.find https://github.com/angular/angular.js/pull/3598 */ if (angular.element.prototype.querySelectorAll === undefined) { - angular.element.prototype.querySelectorAll = function(selector) { - return angular.element(this[0].querySelectorAll(selector)); - }; + angular.element.prototype.querySelectorAll = function (selector) { + return angular.element(this[0].querySelectorAll(selector)); + }; } /** * Add closest() to jqLite. */ if (angular.element.prototype.closest === undefined) { - angular.element.prototype.closest = function( selector) { - var elem = this[0]; - var matchesSelector = elem.matches || elem.webkitMatchesSelector || elem.mozMatchesSelector || elem.msMatchesSelector; - - while (elem) { - if (matchesSelector.bind(elem)(selector)) { - return elem; - } else { - elem = elem.parentElement; - } - } - return false; - }; + angular.element.prototype.closest = function (selector) { + var elem = this[0]; + var matchesSelector = elem.matches || elem.webkitMatchesSelector || elem.mozMatchesSelector || + elem.msMatchesSelector; + + while (elem) { + if (matchesSelector.bind(elem)(selector)) { + return elem; + } else { + elem = elem.parentElement; + } + } + return false; + }; } var latestId = 0; var uis = angular.module('ui.select', []) -.constant('uiSelectConfig', { - theme: 'bootstrap', - searchEnabled: true, - sortable: false, - placeholder: '', // Empty by default, like HTML tag + closeOnSelect: true, + generateId: function () { + return latestId++; + }, + appendToBody: false + }) // See Rename minErr and make it accessible from outside https://github.com/angular/angular.js/issues/6913 -.service('uiSelectMinErr', function() { - var minErr = angular.$$minErr('ui.select'); - return function() { - var error = minErr.apply(this, arguments); - var message = error.message.replace(new RegExp('\nhttp://errors.angularjs.org/.*'), ''); - return new Error(message); - }; -}) + .service('uiSelectMinErr', function () { + var minErr = angular.$$minErr('ui.select'); + return function () { + var error = minErr.apply(this, arguments); + var message = error.message.replace(new RegExp('\nhttp://errors.angularjs.org/.*'), ''); + return new Error(message); + }; + }) // Recreates old behavior of ng-transclude. Used internally. -.directive('uisTranscludeAppend', function () { - return { - link: function (scope, element, attrs, ctrl, transclude) { - transclude(scope, function (clone) { - element.append(clone); - }); - } - }; -}) + .directive('uisTranscludeAppend', function () { + return { + link: function (scope, element, attrs, ctrl, transclude) { + transclude(scope, function (clone) { + element.append(clone); + }); + } + }; + }) /** * Highlights text that matches $select.search. @@ -136,15 +238,16 @@ var uis = angular.module('ui.select', []) * Taken from AngularUI Bootstrap Typeahead * See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L340 */ -.filter('highlight', function() { - function escapeRegexp(queryToEscape) { - return queryToEscape.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1'); - } + .filter('highlight', function () { + function escapeRegexp(queryToEscape) { + return queryToEscape.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1'); + } - return function(matchItem, query) { - return query && matchItem ? matchItem.replace(new RegExp(escapeRegexp(query), 'gi'), '$&') : matchItem; - }; -}) + return function (matchItem, query) { + return query && matchItem ? matchItem.replace(new RegExp(escapeRegexp(query), 'gi'), + '$&') : matchItem; + }; + }) /** * A read-only equivalent of jQuery's offset function: http://api.jquery.com/offset/ @@ -152,96 +255,92 @@ var uis = angular.module('ui.select', []) * Taken from AngularUI Bootstrap Position: * See https://github.com/angular-ui/bootstrap/blob/master/src/position/position.js#L70 */ -.factory('uisOffset', - ['$document', '$window', - function ($document, $window) { - - return function(element) { - var boundingClientRect = element[0].getBoundingClientRect(); - return { - width: boundingClientRect.width || element.prop('offsetWidth'), - height: boundingClientRect.height || element.prop('offsetHeight'), - top: boundingClientRect.top + ($window.pageYOffset || $document[0].documentElement.scrollTop), - left: boundingClientRect.left + ($window.pageXOffset || $document[0].documentElement.scrollLeft) - }; - }; -}]); + .factory('uisOffset', + ['$document', '$window', + function ($document, $window) { + + return function (element) { + var boundingClientRect = element[0].getBoundingClientRect(); + return { + width: boundingClientRect.width || element.prop('offsetWidth'), + height: boundingClientRect.height || element.prop('offsetHeight'), + top: boundingClientRect.top + ($window.pageYOffset || $document[0].documentElement.scrollTop), + left: boundingClientRect.left + ($window.pageXOffset || $document[0].documentElement.scrollLeft) + }; + }; + }]); uis.directive('uiSelectChoices', - ['uiSelectConfig', 'uisRepeatParser', 'uiSelectMinErr', '$compile', - function(uiSelectConfig, RepeatParser, uiSelectMinErr, $compile) { - - return { - restrict: 'EA', - require: '^uiSelect', - replace: true, - transclude: true, - templateUrl: function(tElement) { - // Gets theme attribute from parent (ui-select) - var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; - return theme + '/choices.tpl.html'; - }, + ['uiSelectConfig', 'uisRepeatParser', 'uiSelectMinErr', '$compile', + function (uiSelectConfig, RepeatParser, uiSelectMinErr, $compile) { - compile: function(tElement, tAttrs) { + return { + restrict: 'EA', + require: '^uiSelect', + replace: true, + transclude: true, + templateUrl: function (tElement) { + // Gets theme attribute from parent (ui-select) + var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; + return theme + '/choices.tpl.html'; + }, - if (!tAttrs.repeat) throw uiSelectMinErr('repeat', "Expected 'repeat' expression."); + compile: function (tElement, tAttrs) { - return function link(scope, element, attrs, $select, transcludeFn) { + if (!tAttrs.repeat) { + throw uiSelectMinErr('repeat', "Expected 'repeat' expression."); + } - // var repeat = RepeatParser.parse(attrs.repeat); - var groupByExp = attrs.groupBy; - var groupFilterExp = attrs.groupFilter; + return function link(scope, element, attrs, $select, transcludeFn) { - $select.parseRepeatAttr(attrs.repeat, groupByExp, groupFilterExp); //Result ready at $select.parserResult + // var repeat = RepeatParser.parse(attrs.repeat); + var groupByExp = attrs.groupBy; + var groupFilterExp = attrs.groupFilter; - $select.disableChoiceExpression = attrs.uiDisableChoice; - $select.onHighlightCallback = attrs.onHighlight; + $select.parseRepeatAttr(attrs.repeat, groupByExp, groupFilterExp); //Result ready at $select.parserResult - $select.refreshOnActive = scope.$eval(attrs.refreshOnActive); + $select.disableChoiceExpression = attrs.uiDisableChoice; + $select.onHighlightCallback = attrs.onHighlight; - if(groupByExp) { - var groups = element.querySelectorAll('.ui-select-choices-group'); - if (groups.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-group but got '{0}'.", groups.length); - groups.attr('ng-repeat', RepeatParser.getGroupNgRepeatExpression()); - } + if (groupByExp) { + var groups = element.querySelectorAll('.ui-select-choices-group'); + if (groups.length !== 1) throw uiSelectMinErr('rows', + "Expected 1 .ui-select-choices-group but got '{0}'.", groups.length); + groups.attr('ng-repeat', RepeatParser.getGroupNgRepeatExpression()); + } - var choices = element.querySelectorAll('.ui-select-choices-row'); - if (choices.length !== 1) { - throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row but got '{0}'.", choices.length); - } + var choices = element.querySelectorAll('.ui-select-choices-row'); + if (choices.length !== 1) { + throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row but got '{0}'.", + choices.length); + } - choices.attr('ng-repeat', RepeatParser.getNgRepeatExpression($select.parserResult.itemName, '$select.items', $select.parserResult.trackByExp, groupByExp)) - .attr('ng-if', '$select.open') //Prevent unnecessary watches when dropdown is closed - .attr('ng-mouseenter', '$select.setActiveItem('+$select.parserResult.itemName +')') - .attr('ng-click', '$select.select(' + $select.parserResult.itemName + ',false,$event)'); - - var rowsInner = element.querySelectorAll('.ui-select-choices-row-inner'); - if (rowsInner.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row-inner but got '{0}'.", rowsInner.length); - rowsInner.attr('uis-transclude-append', ''); //Adding uisTranscludeAppend directive to row element after choices element has ngRepeat - - $compile(element, transcludeFn)(scope); //Passing current transcludeFn to be able to append elements correctly from uisTranscludeAppend - - scope.$watch('$select.search', function(newValue) { - if(newValue && !$select.open && $select.multiple) $select.activate(false, true); - $select.activeIndex = 0; - if(!$select.refreshOnActive || ($select.refreshOnActive && $select.refreshIsActive)) { - $select.refresh(attrs.refresh); - } - }); - - scope.$watch('$select.refreshIsActive', function(newValue, oldValue){ - if(angular.isUndefined(oldValue) && newValue){ - $select.refresh(attrs.refresh); - } - }); - - // $eval() is needed otherwise we get a string instead of a number - var refreshDelay = scope.$eval(attrs.refreshDelay); - $select.refreshDelay = refreshDelay !== undefined ? refreshDelay : uiSelectConfig.refreshDelay; - }; - } - }; -}]); + choices.attr('ng-repeat', + RepeatParser.getNgRepeatExpression($select.parserResult.itemName, '$select.items', + $select.parserResult.trackByExp, groupByExp)) + .attr('ng-if', '$select.open') //Prevent unnecessary watches when dropdown is closed + .attr('ng-mouseenter', '$select.setActiveItem(' + $select.parserResult.itemName + ')') + .attr('ng-click', '$select.select(' + $select.parserResult.itemName + ',false,$event)'); + + var rowsInner = element.querySelectorAll('.ui-select-choices-row-inner'); + if (rowsInner.length !== 1) { + throw uiSelectMinErr('rows', + "Expected 1 .ui-select-choices-row-inner but got '{0}'.", rowsInner.length); + } + rowsInner.attr('uis-transclude-append', ''); //Adding uisTranscludeAppend directive to row element after choices element has ngRepeat + + $compile(element, transcludeFn)(scope); //Passing current transcludeFn to be able to append elements correctly from uisTranscludeAppend + + scope.$watch('$select.search', function (newValue) { + if (newValue && !$select.open && $select.multiple) { + $select.activate(false, true); + } + $select.activeIndex = 0; + }); + }; + } + }; + }]); /** * Contains ui-select "intelligence". @@ -260,7 +359,6 @@ uis.controller('uiSelectCtrl', ctrl.placeholder = uiSelectConfig.placeholder; ctrl.searchEnabled = uiSelectConfig.searchEnabled; ctrl.sortable = uiSelectConfig.sortable; - ctrl.refreshDelay = uiSelectConfig.refreshDelay; ctrl.removeSelected = false; //If selected item(s) should be removed from dropdown list ctrl.closeOnSelect = true; //Initialized inside uiSelect directive link function @@ -281,8 +379,6 @@ uis.controller('uiSelectCtrl', ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelectMatch directive link function ctrl.clickTriggeredSelect = false; ctrl.$filter = $filter; - ctrl.refreshOnActive = undefined; - ctrl.refreshIsActive = undefined; ctrl.searchInput = $element.querySelectorAll('input.ui-select-search'); if (ctrl.searchInput.length !== 1) { @@ -290,6 +386,10 @@ uis.controller('uiSelectCtrl', ctrl.searchInput.length); } + /** + * Returns true if the selection is empty + * @returns {boolean|*} + */ ctrl.isEmpty = function () { return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === ''; }; @@ -305,6 +405,12 @@ uis.controller('uiSelectCtrl', } } + ctrl.findGroupByName = function (name) { + return ctrl.groups && ctrl.groups.filter(function (group) { + return group.name === name; + })[0]; + }; + function _groupsFilter(groups, groupNames) { var i, j, result = []; for (i = 0; i < groupNames.length; i++) { @@ -317,10 +423,15 @@ uis.controller('uiSelectCtrl', return result; } - // When the user clicks on ui-select, displays the dropdown list + /** + * Activates the control. + * When the user clicks on ui-select, displays the dropdown list + */ ctrl.activate = function (initSearchValue, avoidReset) { if (!ctrl.disabled && !ctrl.open) { - if (!avoidReset) _resetSearchInput(); + if (!avoidReset) { + _resetSearchInput(); + } $scope.$broadcast('uis:activate'); @@ -330,7 +441,6 @@ uis.controller('uiSelectCtrl', } ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex; - ctrl.refreshIsActive = true; // Give it time to appear before focus $timeout(function () { @@ -344,12 +454,6 @@ uis.controller('uiSelectCtrl', } }; - ctrl.findGroupByName = function (name) { - return ctrl.groups && ctrl.groups.filter(function (group) { - return group.name === name; - })[0]; - }; - ctrl.parseRepeatAttr = function (repeatAttr, groupByExp, groupFilterExp) { function updateGroups(items) { var groupFn = $scope.$eval(groupByExp); @@ -382,6 +486,7 @@ uis.controller('uiSelectCtrl', ctrl.items = items; } + // Set the function to use when displaying items - either groups or single ctrl.setItemsFn = groupByExp ? updateGroups : setPlainItems; ctrl.parserResult = RepeatParser.parse(repeatAttr); @@ -392,7 +497,7 @@ uis.controller('uiSelectCtrl', ctrl.refreshItems = function (data) { data = data || ctrl.parserResult.source($scope); var selectedItems = ctrl.selected; - //TODO should implement for single mode removeSelected + // TODO should implement for single mode removeSelected if (ctrl.isEmpty() || (angular.isArray(selectedItems) && !selectedItems.length) || !ctrl.removeSelected) { ctrl.setItemsFn(data); @@ -424,35 +529,17 @@ uis.controller('uiSelectCtrl', } } }); - - }; - - var _refreshDelayPromise; - - /** - * Typeahead mode: lets the user refresh the collection using his own function. - * - * See Expose $select.search for external / remote filtering https://github.com/angular-ui/ui-select/pull/31 - */ - ctrl.refresh = function (refreshAttr) { - if (refreshAttr !== undefined) { - - // Debounce - // See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L155 - // FYI AngularStrap typeahead does not have debouncing: https://github.com/mgcrea/angular-strap/blob/v2.0.0-rc.4/src/typeahead/typeahead.js#L177 - if (_refreshDelayPromise) { - $timeout.cancel(_refreshDelayPromise); - } - _refreshDelayPromise = $timeout(function () { - $scope.$eval(refreshAttr); - }, ctrl.refreshDelay); - } }; ctrl.setActiveItem = function (item) { ctrl.activeIndex = ctrl.items.indexOf(item); }; + /** + * Checks if the item is active + * @param itemScope the item + * @returns {boolean} true if active + */ ctrl.isActive = function (itemScope) { if (!ctrl.open) { return false; @@ -469,11 +556,14 @@ uis.controller('uiSelectCtrl', /** * Checks if the item is disabled - * @return boolean true if the item is disabled + * @param itemScope the item + * @return {boolean} true if the item is disabled */ ctrl.isDisabled = function (itemScope) { - if (!ctrl.open) return false; + if (!ctrl.open) { + return false; + } var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); var isDisabled = false; @@ -490,75 +580,81 @@ uis.controller('uiSelectCtrl', /** + * Selects an item + * * Called when the user selects an item with ENTER or clicks the dropdown */ ctrl.select = function (item, skipFocusser, $event) { - if (item === undefined || !item._uiSelectChoiceDisabled) { - - if (!ctrl.items && !ctrl.search){ - return; - } - - if (!item || !item._uiSelectChoiceDisabled) { + if (item !== undefined && item._uiSelectChoiceDisabled) { + return; + } - var completeSelection = function () { - $scope.$broadcast('uis:select', item); + // If no items in the list, and no search, then return + if (!ctrl.items && !ctrl.search) { + return; + } - $timeout(function () { - ctrl.onSelectCallback($scope, callbackContext); - }); + // Create the data used to pass to the callbacks + var locals = {}; + locals[ctrl.parserResult.itemName] = item; + var callbackContext = { + $item: item, + $model: ctrl.parserResult.modelMapper($scope, locals) + }; - if (ctrl.closeOnSelect) { - ctrl.close(skipFocusser); - } - if ($event && $event.type === 'click') { - ctrl.clickTriggeredSelect = true; - } - }; + // Local method called when we complete the select + // eg. called after the onselect callback + var completeSelection = function () { + $scope.$broadcast('uis:select', item); - var locals = {}; - locals[ctrl.parserResult.itemName] = item; + $timeout(function () { + ctrl.onSelectCallback($scope, callbackContext); + }); - var callbackContext = { - $item: item, - $model: ctrl.parserResult.modelMapper($scope, locals) - }; + if (ctrl.closeOnSelect) { + ctrl.close(skipFocusser); + } + if ($event && $event.type === 'click') { + ctrl.clickTriggeredSelect = true; + } + }; - // Call the onBeforeSelect callback - // Allowable responses are -: - // falsy: Abort the selection - // promise: Wait for response - // true: Complete selection - // object: Add the returned object - var onBeforeSelectResult = ctrl.onBeforeSelectCallback($scope, callbackContext); - if (angular.isDefined(onBeforeSelectResult)) { - if (!onBeforeSelectResult) { - return; // abort the selection in case of deliberate falsey result - } else if (angular.isFunction(onBeforeSelectResult.then)) { - onBeforeSelectResult.then(function (result) { - if (!result) { - return; - } - completeSelection(result); - }); - } else if (onBeforeSelectResult === true) { - completeSelection(item); - } else { - completeSelection(onBeforeSelectResult); + // Call the onBeforeSelect callback + // Allowable responses are -: + // falsy: Abort the selection + // promise: Wait for response + // true: Complete selection + // object: Add the returned object + var onBeforeSelectResult = ctrl.onBeforeSelectCallback($scope, callbackContext); + if (angular.isDefined(onBeforeSelectResult)) { + if (angular.isFunction(onBeforeSelectResult.then)) { + // Promise returned - wait for it to complete before completing the selection + onBeforeSelectResult.then(function (result) { + if (!result) { + return; } - } else { - completeSelection(item); - } + completeSelection(result); + }); + } else if (onBeforeSelectResult === true) { + completeSelection(item); + } else if (onBeforeSelectResult) { + completeSelection(onBeforeSelectResult); } + } else { + completeSelection(item); } }; - // Closes the dropdown + /** + * Close the dropdown + */ ctrl.close = function (skipFocusser) { if (!ctrl.open) { return; } - if (ctrl.ngModel && ctrl.ngModel.$setTouched) ctrl.ngModel.$setTouched(); + if (ctrl.ngModel && ctrl.ngModel.$setTouched) { + ctrl.ngModel.$setTouched(); + } _resetSearchInput(); ctrl.open = false; if (!ctrl.searchEnabled) { @@ -568,12 +664,19 @@ uis.controller('uiSelectCtrl', $scope.$broadcast('uis:close', skipFocusser); }; + /** + * Set focus on the control + */ ctrl.setFocus = function () { if (!ctrl.focus) { ctrl.focusInput[0].focus(); } }; + /** + * Clears the selection + * @param $event + */ ctrl.clear = function ($event) { ctrl.select(undefined); $event.stopPropagation(); @@ -582,7 +685,9 @@ uis.controller('uiSelectCtrl', }, 0, false); }; - // Toggle dropdown + /** + * Toggle the dropdown open and closed + */ ctrl.toggle = function (e) { if (ctrl.open) { ctrl.close(); @@ -606,7 +711,6 @@ uis.controller('uiSelectCtrl', var sizeWatch = null; ctrl.sizeSearchInput = function () { - var input = ctrl.searchInput[0], container = ctrl.searchInput.parent().parent()[0], calculateContainerWidth = function () { @@ -659,7 +763,9 @@ uis.controller('uiSelectCtrl', } break; case KEY.TAB: - if (!ctrl.multiple || ctrl.open) ctrl.select(ctrl.items[ctrl.activeIndex], true); + if (!ctrl.multiple || ctrl.open) { + ctrl.select(ctrl.items[ctrl.activeIndex], true); + } break; case KEY.ENTER: if (ctrl.open) { @@ -703,24 +809,6 @@ uis.controller('uiSelectCtrl', } }); - // If tagging try to split by tokens and add items - /* ctrl.searchInput.on('paste', function (e) { - var data = e.originalEvent.clipboardData.getData('text/plain'); - if (data && data.length > 0 && ctrl.taggingTokens.isActivated && ctrl.tagging.fct) { - var items = data.split(ctrl.taggingTokens.tokens[0]); // split by first token only - if (items && items.length > 0) { - angular.forEach(items, function (item) { - var newItem = ctrl.tagging.fct(item); - if (newItem) { - ctrl.select(newItem, true); - } - }); - e.preventDefault(); - e.stopPropagation(); - } - } - });*/ - ctrl.searchInput.on('keyup', function (e) { // return early with these keys if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || @@ -734,7 +822,6 @@ uis.controller('uiSelectCtrl', ctrl.onKeypressCallback($scope, {event: e}); }); - // See https://github.com/ivaynberg/select2/blob/3.4.6/select2.js#L1431 function _ensureHighlightVisible() { var container = $element.querySelectorAll('.ui-select-choices-content'); @@ -755,10 +842,13 @@ uis.controller('uiSelectCtrl', if (posY > height) { container[0].scrollTop += posY - height; } else if (posY < highlighted.clientHeight) { - if (ctrl.isGrouped && ctrl.activeIndex === 0) - container[0].scrollTop = 0; //To make group header visible when going all the way up - else + if (ctrl.isGrouped && ctrl.activeIndex === 0) { + //To make group header visible when going all the way up + container[0].scrollTop = 0; + } + else { container[0].scrollTop -= highlighted.clientHeight - posY; + } } } @@ -811,9 +901,10 @@ uis.directive('uiSelect', } }(); - $select.onBeforeSelectCallback = $parse(attrs.onBeforeSelect); $select.onSelectCallback = $parse(attrs.onSelect); + $select.onBeforeSelectCallback = $parse(attrs.onBeforeSelect); $select.onRemoveCallback = $parse(attrs.onRemove); + $select.onBeforeRemoveCallback = $parse(attrs.onBeforeRemove); $select.onKeypressCallback = $parse(attrs.onKeypress); //Limit the number of selections allowed @@ -845,11 +936,6 @@ uis.directive('uiSelect', $select.disabled = attrs.disabled !== undefined ? attrs.disabled : false; }); - attrs.$observe('resetSearchInput', function () { - // $eval() is needed otherwise we get a string instead of a boolean - var resetSearchInput = scope.$eval(attrs.resetSearchInput); - $select.resetSearchInput = resetSearchInput !== undefined ? resetSearchInput : true; - }); //Automatically gets focus when loaded if (angular.isDefined(attrs.autofocus)) { @@ -1001,6 +1087,7 @@ uis.directive('uiSelect', // Support changing the direction of the dropdown if there isn't enough space to render it. scope.$watch('$select.open', function (isOpen) { if (isOpen) { + // Get the dropdown element dropdown = angular.element(element).querySelectorAll('.ui-select-dropdown'); if (dropdown === null) { return; @@ -1018,8 +1105,6 @@ uis.directive('uiSelect', if (offset.top + offset.height + offsetDropdown.height > $document[0].documentElement.scrollTop + $document[0].documentElement.clientHeight) { - dropdown[0].style.position = 'absolute'; - dropdown[0].style.top = (offsetDropdown.height * -1) + 'px'; element.addClass(directionUpClassName); } @@ -1032,8 +1117,6 @@ uis.directive('uiSelect', } // Reset the position of the dropdown. - dropdown[0].style.position = ''; - dropdown[0].style.top = ''; element.removeClass(directionUpClassName); } }); @@ -1042,425 +1125,479 @@ uis.directive('uiSelect', }; }]); -uis.directive('uiSelectMatch', ['uiSelectConfig', function(uiSelectConfig) { - return { - restrict: 'EA', - require: '^uiSelect', - replace: true, - transclude: true, - templateUrl: function(tElement) { - // Gets theme attribute from parent (ui-select) - var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; - var multi = tElement.parent().attr('multiple'); - return theme + (multi ? '/match-multiple.tpl.html' : '/match.tpl.html'); - }, - link: function(scope, element, attrs, $select) { - $select.lockChoiceExpression = attrs.uiLockChoice; - attrs.$observe('placeholder', function(placeholder) { - $select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder; - }); - - function setAllowClear(allow) { - $select.allowClear = (angular.isDefined(allow)) ? (allow === '') ? true : (allow.toLowerCase() === 'true') : false; - } +uis.directive('uiSelectMatch', ['uiSelectConfig', function (uiSelectConfig) { + return { + restrict: 'EA', + require: '^uiSelect', + replace: true, + transclude: true, + templateUrl: function (tElement) { + // Gets theme attribute from parent (ui-select) + var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; + var multi = tElement.parent().attr('multiple'); + return theme + (multi ? '/match-multiple.tpl.html' : '/match.tpl.html'); + }, + link: function (scope, element, attrs, $select) { + $select.lockChoiceExpression = attrs.uiLockChoice; + attrs.$observe('placeholder', function (placeholder) { + $select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder; + }); - attrs.$observe('allowClear', setAllowClear); - setAllowClear(attrs.allowClear); + function setAllowClear(allow) { + $select.allowClear = + (angular.isDefined(allow)) ? (allow === '') ? true : (allow.toLowerCase() === 'true') : false; + } - if($select.multiple){ - $select.sizeSearchInput(); - } + attrs.$observe('allowClear', setAllowClear); + setAllowClear(attrs.allowClear); - } - }; + if ($select.multiple) { + $select.sizeSearchInput(); + } + } + }; }]); -uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelectMinErr, $timeout) { - return { - restrict: 'EA', - require: ['^uiSelect', '^ngModel'], +uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSelectMinErr, $timeout) { + return { + restrict: 'EA', + require: ['^uiSelect', '^ngModel'], + controller: ['$scope', '$timeout', function ($scope, $timeout) { + var ctrl = this, + $select = $scope.$select, + ngModel; + + //Wait for link fn to inject it + $scope.$evalAsync(function () { + ngModel = $scope.ngModel; + }); + + ctrl.activeMatchIndex = -1; - controller: ['$scope','$timeout', function($scope, $timeout){ + ctrl.updateModel = function () { + ngModel.$setViewValue(Date.now()); //Set timestamp as a unique string to force changes + ctrl.refreshComponent(); + }; - var ctrl = this, - $select = $scope.$select, - ngModel; + ctrl.refreshComponent = function () { + // Remove already selected items + // e.g. When user clicks on a selection, the selected array changes and + // the dropdown should remove that item + $select.refreshItems(); + $select.sizeSearchInput(); + }; - //Wait for link fn to inject it - $scope.$evalAsync(function(){ ngModel = $scope.ngModel; }); + // Remove item from multiple select + ctrl.removeChoice = function (index) { + var removedChoice = $select.selected[index]; - ctrl.activeMatchIndex = -1; + // if the choice is locked, can't remove it + if (removedChoice._uiSelectChoiceLocked) { + return; + } - ctrl.updateModel = function(){ - ngModel.$setViewValue(Date.now()); //Set timestamp as a unique string to force changes - ctrl.refreshComponent(); - }; + var locals = {}; + locals[$select.parserResult.itemName] = removedChoice; - ctrl.refreshComponent = function(){ - //Remove already selected items - //e.g. When user clicks on a selection, the selected array changes and - //the dropdown should remove that item - $select.refreshItems(); - $select.sizeSearchInput(); - }; + $select.selected.splice(index, 1); + ctrl.activeMatchIndex = -1; + $select.sizeSearchInput(); - // Remove item from multiple select - ctrl.removeChoice = function(index){ + var callbackContext = { + $item: removedChoice, + $model: $select.parserResult.modelMapper($scope, locals) + }; - var removedChoice = $select.selected[index]; + // Give some time for scope propagation. + function completeRemoval() { + $timeout(function () { + $select.onRemoveCallback($scope, callbackContext); + }); - // if the choice is locked, can't remove it - if(removedChoice._uiSelectChoiceLocked) return; + ctrl.updateModel(); + } - var locals = {}; - locals[$select.parserResult.itemName] = removedChoice; + // Call the onBeforeRemove callback + // Allowable responses are -: + // falsy: Abort the removal + // promise: Wait for response + // true: Complete removal + var onBeforeRemoveResult = ctrl.onBeforeRemoveCallback($scope, callbackContext); + if (angular.isDefined(onBeforeRemoveResult)) { + if (angular.isFunction(onBeforeRemoveResult.then)) { + // Promise returned - wait for it to complete before completing the selection + onBeforeRemoveResult.then(function (result) { + if (!result) { + return; + } + completeRemoval(result); + }); + } else if (onBeforeRemoveResult === true) { + completeRemoval(); + } + } else { + completeRemoval(); + } + }; - $select.selected.splice(index, 1); - ctrl.activeMatchIndex = -1; - $select.sizeSearchInput(); + ctrl.getPlaceholder = function () { + //Refactor single? + if ($select.selected && $select.selected.length) { + return; + } + return $select.placeholder; + }; + }], + controllerAs: '$selectMultiple', + + link: function (scope, element, attrs, ctrls) { + var $select = ctrls[0]; + var ngModel = scope.ngModel = ctrls[1]; + var $selectMultiple = scope.$selectMultiple; + + //$select.selected = raw selected objects (ignoring any property binding) + + $select.multiple = true; + $select.removeSelected = true; + + //Input that will handle focus + $select.focusInput = $select.searchInput; + + //From view --> model + ngModel.$parsers.unshift(function () { + var locals = {}, + result, + resultMultiple = []; + for (var j = $select.selected.length - 1; j >= 0; j--) { + locals = {}; + locals[$select.parserResult.itemName] = $select.selected[j]; + result = $select.parserResult.modelMapper(scope, locals); + resultMultiple.unshift(result); + } + return resultMultiple; + }); - // Give some time for scope propagation. - $timeout(function(){ - $select.onRemoveCallback($scope, { - $item: removedChoice, - $model: $select.parserResult.modelMapper($scope, locals) - }); - }); + // From model --> view + ngModel.$formatters.unshift(function (inputValue) { + var data = $select.parserResult.source(scope, {$select: {search: ''}}), //Overwrite $search + locals = {}, + result; + if (!data) { + return inputValue; + } + var resultMultiple = []; + var checkFnMultiple = function (list, value) { + if (!list || !list.length) { + return; + } + for (var p = list.length - 1; p >= 0; p--) { + locals[$select.parserResult.itemName] = list[p]; + result = $select.parserResult.modelMapper(scope, locals); + if ($select.parserResult.trackByExp) { + var matches = /\.(.+)/.exec($select.parserResult.trackByExp); + if (matches.length > 0 && result[matches[1]] == value[matches[1]]) { + resultMultiple.unshift(list[p]); + return true; + } + } + if (angular.equals(result, value)) { + resultMultiple.unshift(list[p]); + return true; + } + } + return false; + }; + if (!inputValue) return resultMultiple; //If ngModel was undefined + for (var k = inputValue.length - 1; k >= 0; k--) { + //Check model array of currently selected items + if (!checkFnMultiple($select.selected, inputValue[k])) { + //Check model array of all items available + if (!checkFnMultiple(data, inputValue[k])) { + //If not found on previous lists, just add it directly to resultMultiple + resultMultiple.unshift(inputValue[k]); + } + } + } + return resultMultiple; + }); - ctrl.updateModel(); + //Watch for external model changes + scope.$watchCollection(function () { + return ngModel.$modelValue; + }, function (newValue, oldValue) { + if (oldValue != newValue) { + ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters + $selectMultiple.refreshComponent(); + } + }); - }; + ngModel.$render = function () { + // Make sure that model value is array + if (!angular.isArray(ngModel.$viewValue)) { + // Have tolerance for null or undefined values + if (angular.isUndefined(ngModel.$viewValue) || ngModel.$viewValue === null) { + $select.selected = []; + } else { + throw uiSelectMinErr('multiarr', "Expected model value to be array but got '{0}'", + ngModel.$viewValue); + } + } + $select.selected = ngModel.$viewValue; + scope.$evalAsync(); //To force $digest + }; - ctrl.getPlaceholder = function(){ - //Refactor single? - if($select.selected && $select.selected.length) return; - return $select.placeholder; - }; + scope.$on('uis:select', function (event, item) { + if ($select.selected.length >= $select.limit) { + return; + } + $select.selected.push(item); + $selectMultiple.updateModel(); + }); + scope.$on('uis:activate', function () { + $selectMultiple.activeMatchIndex = -1; + }); - }], - controllerAs: '$selectMultiple', + scope.$watch('$select.disabled', function (newValue, oldValue) { + // As the search input field may now become visible, it may be necessary to recompute its size + if (oldValue && !newValue) { + $select.sizeSearchInput(); + } + }); - link: function(scope, element, attrs, ctrls) { + $select.searchInput.on('keydown', function (e) { + var key = e.which; + scope.$apply(function () { + var processed = false; + if (KEY.isHorizontalMovement(key)) { + processed = _handleMatchSelection(key); + } + if (processed && key != KEY.TAB) { + //TODO Check si el tab selecciona aun correctamente + //Crear test +// e.preventDefault(); + // e.stopPropagation(); + } + }); + }); + function _getCaretPosition(el) { + if (angular.isNumber(el.selectionStart)) { + return el.selectionStart; + } + // selectionStart is not supported in IE8 and we don't want hacky workarounds so we compromise + else { + return el.value.length; + } + } - var $select = ctrls[0]; - var ngModel = scope.ngModel = ctrls[1]; - var $selectMultiple = scope.$selectMultiple; + // Handles selected options in "multiple" mode + function _handleMatchSelection(key) { + var caretPosition = _getCaretPosition($select.searchInput[0]), + length = $select.selected.length, + first = 0, + last = length - 1, + curr = $selectMultiple.activeMatchIndex, + next = $selectMultiple.activeMatchIndex + 1, + prev = $selectMultiple.activeMatchIndex - 1, + newIndex = curr; + + if (caretPosition > 0 || ($select.search.length && key == KEY.RIGHT)) { + return false; + } - //$select.selected = raw selected objects (ignoring any property binding) + $select.close(); - $select.multiple = true; - $select.removeSelected = true; + function getNewActiveMatchIndex() { + switch (key) { + case KEY.LEFT: + // Select previous/first item + if (~$selectMultiple.activeMatchIndex) { + return prev; + } + // Select last item + else { + return last; + } + break; + case KEY.RIGHT: + // Open drop-down + if (!~$selectMultiple.activeMatchIndex || curr === last) { + $select.activate(); + return false; + } + // Select next/last item + else { + return next; + } + break; + case KEY.BACKSPACE: + // Remove selected item and select previous/first + if (~$selectMultiple.activeMatchIndex) { + $selectMultiple.removeChoice(curr); + return prev; + } + // Select last item + else { + return last; + } + break; + case KEY.DELETE: + // Remove selected item and select next item + if (~$selectMultiple.activeMatchIndex) { + $selectMultiple.removeChoice($selectMultiple.activeMatchIndex); + return curr; + } + else { + return false; + } + } + } - //Input that will handle focus - $select.focusInput = $select.searchInput; + newIndex = getNewActiveMatchIndex(); - //From view --> model - ngModel.$parsers.unshift(function () { - var locals = {}, - result, - resultMultiple = []; - for (var j = $select.selected.length - 1; j >= 0; j--) { - locals = {}; - locals[$select.parserResult.itemName] = $select.selected[j]; - result = $select.parserResult.modelMapper(scope, locals); - resultMultiple.unshift(result); - } - return resultMultiple; - }); - - // From model --> view - ngModel.$formatters.unshift(function (inputValue) { - var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search - locals = {}, - result; - if (!data) return inputValue; - var resultMultiple = []; - var checkFnMultiple = function(list, value){ - if (!list || !list.length) return; - for (var p = list.length - 1; p >= 0; p--) { - locals[$select.parserResult.itemName] = list[p]; - result = $select.parserResult.modelMapper(scope, locals); - if($select.parserResult.trackByExp){ - var matches = /\.(.+)/.exec($select.parserResult.trackByExp); - if(matches.length>0 && result[matches[1]] == value[matches[1]]){ - resultMultiple.unshift(list[p]); - return true; + if (!$select.selected.length || newIndex === false) { + $selectMultiple.activeMatchIndex = -1; } + else { + $selectMultiple.activeMatchIndex = Math.min(last, Math.max(first, newIndex)); + } + + return true; } - if (angular.equals(result,value)){ - resultMultiple.unshift(list[p]); - return true; - } - } - return false; - }; - if (!inputValue) return resultMultiple; //If ngModel was undefined - for (var k = inputValue.length - 1; k >= 0; k--) { - //Check model array of currently selected items - if (!checkFnMultiple($select.selected, inputValue[k])){ - //Check model array of all items available - if (!checkFnMultiple(data, inputValue[k])){ - //If not found on previous lists, just add it directly to resultMultiple - resultMultiple.unshift(inputValue[k]); - } - } - } - return resultMultiple; - }); - - //Watch for external model changes - scope.$watchCollection(function(){ return ngModel.$modelValue; }, function(newValue, oldValue) { - if (oldValue != newValue){ - ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters - $selectMultiple.refreshComponent(); - } - }); - - ngModel.$render = function() { - // Make sure that model value is array - if(!angular.isArray(ngModel.$viewValue)){ - // Have tolerance for null or undefined values - if(angular.isUndefined(ngModel.$viewValue) || ngModel.$viewValue === null){ - $select.selected = []; - } else { - throw uiSelectMinErr('multiarr', "Expected model value to be array but got '{0}'", ngModel.$viewValue); - } - } - $select.selected = ngModel.$viewValue; - scope.$evalAsync(); //To force $digest - }; - scope.$on('uis:select', function (event, item) { - if($select.selected.length >= $select.limit) { - return; - } - $select.selected.push(item); - $selectMultiple.updateModel(); - }); - - scope.$on('uis:activate', function () { - $selectMultiple.activeMatchIndex = -1; - }); - - scope.$watch('$select.disabled', function(newValue, oldValue) { - // As the search input field may now become visible, it may be necessary to recompute its size - if (oldValue && !newValue) $select.sizeSearchInput(); - }); - - $select.searchInput.on('keydown', function(e) { - var key = e.which; - scope.$apply(function() { - var processed = false; - if(KEY.isHorizontalMovement(key)){ - processed = _handleMatchSelection(key); - } - if (processed && key != KEY.TAB) { - //TODO Check si el tab selecciona aun correctamente - //Crear test -// e.preventDefault(); - // e.stopPropagation(); - } - }); - }); - function _getCaretPosition(el) { - if(angular.isNumber(el.selectionStart)) return el.selectionStart; - // selectionStart is not supported in IE8 and we don't want hacky workarounds so we compromise - else return el.value.length; - } - // Handles selected options in "multiple" mode - function _handleMatchSelection(key){ - var caretPosition = _getCaretPosition($select.searchInput[0]), - length = $select.selected.length, - // none = -1, - first = 0, - last = length-1, - curr = $selectMultiple.activeMatchIndex, - next = $selectMultiple.activeMatchIndex+1, - prev = $selectMultiple.activeMatchIndex-1, - newIndex = curr; - - if(caretPosition > 0 || ($select.search.length && key == KEY.RIGHT)) return false; - - $select.close(); - - function getNewActiveMatchIndex(){ - switch(key){ - case KEY.LEFT: - // Select previous/first item - if(~$selectMultiple.activeMatchIndex) return prev; - // Select last item - else return last; - break; - case KEY.RIGHT: - // Open drop-down - if(!~$selectMultiple.activeMatchIndex || curr === last){ - $select.activate(); - return false; - } - // Select next/last item - else return next; - break; - case KEY.BACKSPACE: - // Remove selected item and select previous/first - if(~$selectMultiple.activeMatchIndex){ - $selectMultiple.removeChoice(curr); - return prev; - } - // Select last item - else return last; - break; - case KEY.DELETE: - // Remove selected item and select next item - if(~$selectMultiple.activeMatchIndex){ - $selectMultiple.removeChoice($selectMultiple.activeMatchIndex); - return curr; - } - else return false; - } + $select.searchInput.on('blur', function () { + $timeout(function () { + $selectMultiple.activeMatchIndex = -1; + }); + }); + } + }; +}]); - newIndex = getNewActiveMatchIndex(); +uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $compile) { + return { + restrict: 'EA', + require: ['^uiSelect', '^ngModel'], + link: function (scope, element, attrs, ctrls) { + + var $select = ctrls[0]; + var ngModel = ctrls[1]; + + //From view --> model + ngModel.$parsers.unshift(function (inputValue) { + var locals = {}, + result; + locals[$select.parserResult.itemName] = inputValue; + result = $select.parserResult.modelMapper(scope, locals); + return result; + }); - if(!$select.selected.length || newIndex === false) $selectMultiple.activeMatchIndex = -1; - else $selectMultiple.activeMatchIndex = Math.min(last,Math.max(first,newIndex)); + //From model --> view + ngModel.$formatters.unshift(function (inputValue) { + var data = $select.parserResult.source(scope, {$select: {search: ''}}), //Overwrite $search + locals = {}, + result; + if (data) { + var checkFnSingle = function (d) { + locals[$select.parserResult.itemName] = d; + result = $select.parserResult.modelMapper(scope, locals); + return result == inputValue; + }; + //If possible pass same object stored in $select.selected + if ($select.selected && checkFnSingle($select.selected)) { + return $select.selected; + } + for (var i = data.length - 1; i >= 0; i--) { + if (checkFnSingle(data[i])) { + return data[i]; + } + } + } + return inputValue; + }); - return true; - } + //Update viewValue if model change + scope.$watch('$select.selected', function (newValue) { + if (ngModel.$viewValue !== newValue) { + ngModel.$setViewValue(newValue); + } + }); - $select.searchInput.on('blur', function() { - $timeout(function() { - $selectMultiple.activeMatchIndex = -1; - }); - }); + ngModel.$render = function () { + $select.selected = ngModel.$viewValue; + }; - } - }; -}]); + scope.$on('uis:select', function (event, item) { + $select.selected = item; + }); -uis.directive('uiSelectSingle', ['$timeout','$compile', function($timeout, $compile) { - return { - restrict: 'EA', - require: ['^uiSelect', '^ngModel'], - link: function(scope, element, attrs, ctrls) { - - var $select = ctrls[0]; - var ngModel = ctrls[1]; - - //From view --> model - ngModel.$parsers.unshift(function (inputValue) { - var locals = {}, - result; - locals[$select.parserResult.itemName] = inputValue; - result = $select.parserResult.modelMapper(scope, locals); - return result; - }); - - //From model --> view - ngModel.$formatters.unshift(function (inputValue) { - var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search - locals = {}, - result; - if (data){ - var checkFnSingle = function(d){ - locals[$select.parserResult.itemName] = d; - result = $select.parserResult.modelMapper(scope, locals); - return result == inputValue; - }; - //If possible pass same object stored in $select.selected - if ($select.selected && checkFnSingle($select.selected)) { - return $select.selected; - } - for (var i = data.length - 1; i >= 0; i--) { - if (checkFnSingle(data[i])) return data[i]; - } - } - return inputValue; - }); + scope.$on('uis:close', function (event, skipFocusser) { + $timeout(function () { + $select.focusser.prop('disabled', false); + if (!skipFocusser) $select.focusser[0].focus(); + }, 0, false); + }); - //Update viewValue if model change - scope.$watch('$select.selected', function(newValue) { - if (ngModel.$viewValue !== newValue) { - ngModel.$setViewValue(newValue); - } - }); - - ngModel.$render = function() { - $select.selected = ngModel.$viewValue; - }; - - scope.$on('uis:select', function (event, item) { - $select.selected = item; - }); - - scope.$on('uis:close', function (event, skipFocusser) { - $timeout(function(){ - $select.focusser.prop('disabled', false); - if (!skipFocusser) $select.focusser[0].focus(); - },0,false); - }); - - scope.$on('uis:activate', function () { - focusser.prop('disabled', true); //Will reactivate it on .close() - }); - - //Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954 - var focusser = angular.element(""); - $compile(focusser)(scope); - $select.focusser = focusser; - - //Input that will handle focus - $select.focusInput = focusser; - - element.parent().append(focusser); - focusser.bind("focus", function(){ - scope.$evalAsync(function(){ - $select.focus = true; - }); - }); - focusser.bind("blur", function(){ - scope.$evalAsync(function(){ - $select.focus = false; - }); - }); - focusser.bind("keydown", function(e){ - - if (e.which === KEY.BACKSPACE) { - e.preventDefault(); - e.stopPropagation(); - $select.select(undefined); - scope.$apply(); - return; - } + scope.$on('uis:activate', function () { + focusser.prop('disabled', true); //Will reactivate it on .close() + }); - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) { - return; - } + //Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954 + var focusser = angular.element(""); + $compile(focusser)(scope); + $select.focusser = focusser; - if (e.which == KEY.DOWN || e.which == KEY.UP || e.which == KEY.ENTER || e.which == KEY.SPACE){ - e.preventDefault(); - e.stopPropagation(); - $select.activate(); - } + //Input that will handle focus + $select.focusInput = focusser; - scope.$digest(); - }); + element.parent().append(focusser); + focusser.bind("focus", function () { + scope.$evalAsync(function () { + $select.focus = true; + }); + }); + focusser.bind("blur", function () { + scope.$evalAsync(function () { + $select.focus = false; + }); + }); + focusser.bind("keydown", function (e) { - focusser.bind("keyup input", function(e){ + if (e.which === KEY.BACKSPACE) { + e.preventDefault(); + e.stopPropagation(); + $select.select(undefined); + scope.$apply(); + return; + } - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { - return; - } + if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) { + return; + } - $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input - focusser.val(''); - scope.$digest(); + if (e.which == KEY.DOWN || e.which == KEY.UP || e.which == KEY.ENTER || e.which == KEY.SPACE) { + e.preventDefault(); + e.stopPropagation(); + $select.activate(); + } - }); + scope.$digest(); + }); + focusser.bind("keyup input", function (e) { - } - }; + if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || + e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { + return; + } + + $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input + focusser.val(''); + scope.$digest(); + }); + } + }; }]); /** * Parses "repeat" attribute. @@ -1472,45 +1609,46 @@ uis.directive('uiSelectSingle', ['$timeout','$compile', function($timeout, $comp * https://github.com/angular-ui/ui-select/commit/5dd63ad#commitcomment-5504697 */ -uis.service('uisRepeatParser', ['uiSelectMinErr','$parse', function(uiSelectMinErr, $parse) { - var self = this; +uis.service('uisRepeatParser', ['uiSelectMinErr', '$parse', function (uiSelectMinErr, $parse) { + var self = this; - /** - * Example: - * expression = "address in addresses | filter: {street: $select.search} track by $index" - * itemName = "address", - * source = "addresses | filter: {street: $select.search}", - * trackByExp = "$index", - */ - self.parse = function(expression) { + /** + * Example: + * expression = "address in addresses | filter: {street: $select.search} track by $index" + * itemName = "address", + * source = "addresses | filter: {street: $select.search}", + * trackByExp = "$index", + */ + self.parse = function (expression) { - var match = expression.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/); + var match = expression.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/); - if (!match) { - throw uiSelectMinErr('iexp', "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.", - expression); - } + if (!match) { + throw uiSelectMinErr('iexp', + "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.", + expression); + } - return { - itemName: match[2], // (lhs) Left-hand side, - source: $parse(match[3]), - trackByExp: match[4], - modelMapper: $parse(match[1] || match[2]) - }; + return { + itemName: match[2], // (lhs) Left-hand side, + source: $parse(match[3]), + trackByExp: match[4], + modelMapper: $parse(match[1] || match[2]) + }; - }; + }; - self.getGroupNgRepeatExpression = function() { - return '$group in $select.groups'; - }; + self.getGroupNgRepeatExpression = function () { + return '$group in $select.groups'; + }; - self.getNgRepeatExpression = function(itemName, source, trackByExp, grouped) { - var expression = itemName + ' in ' + (grouped ? '$group.items' : source); - if (trackByExp) { - expression += ' track by ' + trackByExp; - } - return expression; - }; + self.getNgRepeatExpression = function (itemName, source, trackByExp, grouped) { + var expression = itemName + ' in ' + (grouped ? '$group.items' : source); + if (trackByExp) { + expression += ' track by ' + trackByExp; + } + return expression; + }; }]); }()); diff --git a/dist/select.selectize.min.js b/dist/select.selectize.min.js index c02a71103..084c20608 100644 --- a/dist/select.selectize.min.js +++ b/dist/select.selectize.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-02T20:56:31.517Z + * Version: 0.12.1 - 2015-08-04T17:24:10.073Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var n=t.which;switch(n){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,n=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",refreshDelay:1e3,closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,i,r){r(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var i=n[0].getBoundingClientRect();return{width:i.width||n.prop("offsetWidth"),height:i.height||n.prop("offsetHeight"),top:i.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:i.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);n.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(r,c){if(!c.repeat)throw n("repeat","Expected 'repeat' expression.");return function(r,c,l,s,o){var a=l.groupBy,u=l.groupFilter;if(s.parseRepeatAttr(l.repeat,a,u),s.disableChoiceExpression=l.uiDisableChoice,s.onHighlightCallback=l.onHighlight,s.refreshOnActive=r.$eval(l.refreshOnActive),a){var p=c.querySelectorAll(".ui-select-choices-group");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",p.length);p.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=c.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(s.parserResult.itemName,"$select.items",s.parserResult.trackByExp,a)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+s.parserResult.itemName+")").attr("ng-click","$select.select("+s.parserResult.itemName+",false,$event)");var h=c.querySelectorAll(".ui-select-choices-row-inner");if(1!==h.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",h.length);h.attr("uis-transclude-append",""),i(c,o)(r),r.$watch("$select.search",function(e){e&&!s.open&&s.multiple&&s.activate(!1,!0),s.activeIndex=0,(!s.refreshOnActive||s.refreshOnActive&&s.refreshIsActive)&&s.refresh(l.refresh)}),r.$watch("$select.refreshIsActive",function(e,t){angular.isUndefined(t)&&e&&s.refresh(l.refresh)});var f=r.$eval(l.refreshDelay);s.refreshDelay=void 0!==f?f:e.refreshDelay}}}}]),n.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,n,i,r,c,l,s,o){function a(){(h.resetSearchInput||void 0===h.resetSearchInput&&o.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var n,i,r=[];for(n=0;n0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:n=!1}return n}function d(){var e=n.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw s("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var i=t[h.activeIndex],r=i.offsetTop+i.clientHeight-e[0].scrollTop,c=e[0].offsetHeight;r>c?e[0].scrollTop+=r-c:r=h.items.length?0:h.activeIndex,h.refreshIsActive=!0,i(function(){h.search=e||h.search,h.searchInput[0].focus()}))},h.findGroupByName=function(e){return h.groups&&h.groups.filter(function(t){return t.name===e})[0]},h.parseRepeatAttr=function(e,n,i){function r(e){var r=t.$eval(n);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(r)?r(e):e[r],n=h.findGroupByName(t);n?n.items.push(e):h.groups.push({name:t,items:[e]})}),i){var c=t.$eval(i);angular.isFunction(c)?h.groups=c(h.groups):angular.isArray(c)&&(h.groups=u(h.groups,c))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function c(e){h.items=e}h.setItemsFn=n?r:c,h.parserResult=l.parse(e),h.isGrouped=!!n,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var n=h.selected;if(h.isEmpty()||angular.isArray(n)&&!n.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var i=e.filter(function(e){return n.indexOf(e)<0});h.setItemsFn(i)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw s("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})};var v;h.refresh=function(e){void 0!==e&&(v&&i.cancel(v),v=i(function(){t.$eval(e)},h.refreshDelay))},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),n=t===h.activeIndex;return n&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),n},h.isDisabled=function(e){if(!h.open)return!1;var t,n=h.items.indexOf(e[h.itemProperty]),i=!1;return n>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[n],i=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i},h.select=function(e,n,r){if(void 0===e||!e._uiSelectChoiceDisabled){if(!h.items&&!h.search)return;if(!e||!e._uiSelectChoiceDisabled){var c=function(){t.$broadcast("uis:select",e),i(function(){h.onSelectCallback(t,s)}),h.closeOnSelect&&h.close(n),r&&"click"===r.type&&(h.clickTriggeredSelect=!0)},l={};l[h.parserResult.itemName]=e;var s={$item:e,$model:h.parserResult.modelMapper(t,l)},o=h.onBeforeSelectCallback(t,s);if(angular.isDefined(o)){if(!o)return;angular.isFunction(o.then)?o.then(function(e){e&&c(e)}):o===!0?c(e):c(o)}else c(e)}}},h.close=function(e){h.open&&(h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),a(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e))},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),i(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var n,i=h.selected[t];return i&&!angular.isUndefined(h.lockChoiceExpression)&&(n=!!e.$eval(h.lockChoiceExpression),i._uiSelectChoiceLocked=n),n};var g=null;h.sizeSearchInput=function(){var e=h.searchInput[0],n=h.searchInput.parent().parent()[0],r=function(){return n.clientWidth*!!e.offsetParent},c=function(t){if(0===t)return!1;var n=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=t),h.searchInput.css("width",n+"px"),!0};h.searchInput.css("width","10px"),i(function(){null!==g||c(r())||(g=t.$watch(r,function(e){c(e)&&(g(),g=null)}))})},h.searchInput.on("keydown",function(n){var i=n.which;t.$apply(function(){p(i)}),e.isVerticalMovement(i)&&h.items.length>0&&d(),(i===e.ENTER||i===e.ESC)&&(n.preventDefault(),n.stopPropagation())}),h.searchInput.on("keyup",function(n){n.which===e.TAB||e.isControl(n)||e.isFunctionKey(n)||n.which===e.ESC||e.isVerticalMovement(n.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:n})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),n.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,i,r,c,l){return{restrict:"EA",templateUrl:function(e,n){var i=n.theme||t.theme;return i+(angular.isDefined(n.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(r,s){return angular.isDefined(s.multiple)?r.append("").removeAttr("multiple"):r.append(""),function(r,s,o,a,u){function p(e){if(f.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(s[0],e.target):s[0].contains(e.target),!t&&!f.clickTriggeredSelect){var n=["input","button","textarea"],i=angular.element(e.target).scope(),c=i&&i.$select&&i.$select!==f;c||(c=~n.indexOf(e.target.tagName.toLowerCase())),f.close(c),r.$digest()}f.clickTriggeredSelect=!1}}function d(){var t=i(s);E=angular.element('
    '),E[0].style.width=t.width+"px",E[0].style.height=t.height+"px",s.after(E),b=s[0].style.width,e.find("body").append(s),s[0].style.position="absolute",s[0].style.left=t.left+"px",s[0].style.top=t.top+"px",s[0].style.width=t.width+"px"}function h(){null!==E&&(E.replaceWith(s),E=null,s[0].style.position="",s[0].style.left="",s[0].style.top="",s[0].style.width=b)}var f=a[0],v=a[1];f.generatedId=t.generateId(),f.baseTitle=o.title||"Select box",f.focusserTitle=f.baseTitle+" focus",f.focusserId="focusser-"+f.generatedId,f.closeOnSelect=function(){return angular.isDefined(o.closeOnSelect)?c(o.closeOnSelect)():t.closeOnSelect}(),f.onBeforeSelectCallback=c(o.onBeforeSelect),f.onSelectCallback=c(o.onSelect),f.onRemoveCallback=c(o.onRemove),f.onKeypressCallback=c(o.onKeypress),f.limit=angular.isDefined(o.limit)?parseInt(o.limit,10):void 0,f.ngModel=v,f.choiceGrouped=function(e){return f.isGrouped&&e&&e.name},o.tabindex&&o.$observe("tabindex",function(e){f.focusInput.attr("tabindex",e),s.removeAttr("tabindex")});var g=r.$eval(o.searchEnabled);f.searchEnabled=void 0!==g?g:t.searchEnabled;var m=r.$eval(o.sortable);f.sortable=void 0!==m?m:t.sortable,o.$observe("disabled",function(){f.disabled=void 0!==o.disabled?o.disabled:!1}),o.$observe("resetSearchInput",function(){var e=r.$eval(o.resetSearchInput);f.resetSearchInput=void 0!==e?e:!0}),angular.isDefined(o.autofocus)&&l(function(){f.setFocus()}),angular.isDefined(o.focusOn)&&r.$on(o.focusOn,function(){l(function(){f.setFocus()})}),e.on("click",p),r.$on("$destroy",function(){e.off("click",p)}),u(r,function(e){var t=angular.element("
    ").append(e),i=t.querySelectorAll(".ui-select-match");if(i.removeAttr("ui-select-match"),i.removeAttr("data-ui-select-match"),1!==i.length)throw n("transcluded","Expected 1 .ui-select-match but got '{0}'.",i.length);s.querySelectorAll(".ui-select-match").replaceWith(i);var r=t.querySelectorAll(".ui-select-choices");if(r.removeAttr("ui-select-choices"),r.removeAttr("data-ui-select-choices"),1!==r.length)throw n("transcluded","Expected 1 .ui-select-choices but got '{0}'.",r.length);s.querySelectorAll(".ui-select-choices").replaceWith(r)});var $=r.$eval(o.appendToBody);(void 0!==$?$:t.appendToBody)&&(r.$watch("$select.open",function(e){e?d():h()}),r.$on("$destroy",function(){h()}));var E=null,b="",S=null,y="direction-up";r.$watch("$select.open",function(t){if(t){if(S=angular.element(s).querySelectorAll(".ui-select-dropdown"),null===S)return;S[0].style.opacity=0,l(function(){var t=i(s),n=i(S);t.top+t.height+n.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&(S[0].style.position="absolute",S[0].style.top=-1*n.height+"px",s.addClass(y)),S[0].style.opacity=1})}else{if(null===S)return;S[0].style.position="",S[0].style.top="",s.removeClass(y)}})}}}}]),n.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return n+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,i,r){function c(e){r.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}r.lockChoiceExpression=i.uiLockChoice,i.$observe("placeholder",function(t){r.placeholder=void 0!==t?t:e.placeholder}),i.$observe("allowClear",c),c(i.allowClear),r.multiple&&r.sizeSearchInput()}}}]),n.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,i=this,r=e.$select;e.$evalAsync(function(){n=e.ngModel}),i.activeMatchIndex=-1,i.updateModel=function(){n.$setViewValue(Date.now()),i.refreshComponent()},i.refreshComponent=function(){r.refreshItems(),r.sizeSearchInput()},i.removeChoice=function(n){var c=r.selected[n];if(!c._uiSelectChoiceLocked){var l={};l[r.parserResult.itemName]=c,r.selected.splice(n,1),i.activeMatchIndex=-1,r.sizeSearchInput(),t(function(){r.onRemoveCallback(e,{$item:c,$model:r.parserResult.modelMapper(e,l)})}),i.updateModel()}},i.getPlaceholder=function(){return r.selected&&r.selected.length?void 0:r.placeholder}}],controllerAs:"$selectMultiple",link:function(i,r,c,l){function s(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function o(t){function n(){switch(t){case e.LEFT:return~p.activeMatchIndex?d:l;case e.RIGHT:return~p.activeMatchIndex&&o!==l?u:(a.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(o),d):l;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),o):!1}}var i=s(a.searchInput[0]),r=a.selected.length,c=0,l=r-1,o=p.activeMatchIndex,u=p.activeMatchIndex+1,d=p.activeMatchIndex-1,h=o;return i>0||a.search.length&&t==e.RIGHT?!1:(a.close(),h=n(),p.activeMatchIndex=a.selected.length&&h!==!1?Math.min(l,Math.max(c,h)):-1,!0)}var a=l[0],u=i.ngModel=l[1],p=i.$selectMultiple;a.multiple=!0,a.removeSelected=!0,a.focusInput=a.searchInput,u.$parsers.unshift(function(){for(var e,t={},n=[],r=a.selected.length-1;r>=0;r--)t={},t[a.parserResult.itemName]=a.selected[r],e=a.parserResult.modelMapper(i,t),n.unshift(e);return n}),u.$formatters.unshift(function(e){var t,n=a.parserResult.source(i,{$select:{search:""}}),r={};if(!n)return e;var c=[],l=function(e,n){if(e&&e.length){for(var l=e.length-1;l>=0;l--){if(r[a.parserResult.itemName]=e[l],t=a.parserResult.modelMapper(i,r),a.parserResult.trackByExp){var s=/\.(.+)/.exec(a.parserResult.trackByExp);if(s.length>0&&t[s[1]]==n[s[1]])return c.unshift(e[l]),!0}if(angular.equals(t,n))return c.unshift(e[l]),!0}return!1}};if(!e)return c;for(var s=e.length-1;s>=0;s--)l(a.selected,e[s])||l(n,e[s])||c.unshift(e[s]);return c}),i.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);a.selected=[]}a.selected=u.$viewValue,i.$evalAsync()},i.$on("uis:select",function(e,t){a.selected.length>=a.limit||(a.selected.push(t),p.updateModel())}),i.$on("uis:activate",function(){p.activeMatchIndex=-1}),i.$watch("$select.disabled",function(e,t){t&&!e&&a.sizeSearchInput()}),a.searchInput.on("keydown",function(t){var n=t.which;i.$apply(function(){var t=!1;e.isHorizontalMovement(n)&&(t=o(n)),t&&n!=e.TAB})}),a.searchInput.on("blur",function(){n(function(){p.activeMatchIndex=-1})})}}}]),n.directive("uiSelectSingle",["$timeout","$compile",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(i,r,c,l){var s=l[0],o=l[1];o.$parsers.unshift(function(e){var t,n={};return n[s.parserResult.itemName]=e,t=s.parserResult.modelMapper(i,n)}),o.$formatters.unshift(function(e){var t,n=s.parserResult.source(i,{$select:{search:""}}),r={};if(n){var c=function(n){return r[s.parserResult.itemName]=n,t=s.parserResult.modelMapper(i,r),t==e};if(s.selected&&c(s.selected))return s.selected;for(var l=n.length-1;l>=0;l--)if(c(n[l]))return n[l]}return e}),i.$watch("$select.selected",function(e){o.$viewValue!==e&&o.$setViewValue(e)}),o.$render=function(){s.selected=o.$viewValue},i.$on("uis:select",function(e,t){s.selected=t}),i.$on("uis:close",function(e,n){t(function(){s.focusser.prop("disabled",!1),n||s.focusser[0].focus()},0,!1)}),i.$on("uis:activate",function(){a.prop("disabled",!0)});var a=angular.element("");n(a)(i),s.focusser=a,s.focusInput=a,r.parent().append(a),a.bind("focus",function(){i.$evalAsync(function(){s.focus=!0})}),a.bind("blur",function(){i.$evalAsync(function(){s.focus=!1})}),a.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),s.select(void 0),i.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),s.activate()),i.$digest()),void 0)}),a.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(s.activate(a.val()),a.val(""),i.$digest())})}}}]),n.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var i=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!i)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:i[2],source:t(i[3]),trackByExp:i[4],modelMapper:t(i[1]||i[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,i){var r=e+" in "+(i?"$group.items":t);return n&&(r+=" track by "+n),r}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("selectize/choices.tpl.html",'
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var n=t.which;switch(n){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,n=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,i,c){c(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var i=n[0].getBoundingClientRect();return{width:i.width||n.prop("offsetWidth"),height:i.height||n.prop("offsetHeight"),top:i.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:i.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);n.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,c){if(!c.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,c,r,l,s){var o=r.groupBy,a=r.groupFilter;if(l.parseRepeatAttr(r.repeat,o,a),l.disableChoiceExpression=r.uiDisableChoice,l.onHighlightCallback=r.onHighlight,o){var u=c.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=c.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(l.parserResult.itemName,"$select.items",l.parserResult.trackByExp,o)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+l.parserResult.itemName+")").attr("ng-click","$select.select("+l.parserResult.itemName+",false,$event)");var d=c.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),i(c,s)(e),e.$watch("$select.search",function(e){e&&!l.open&&l.multiple&&l.activate(!1,!0),l.activeIndex=0})}}}}]),n.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,n,i,c,r,l,s,o){function a(){(h.resetSearchInput||void 0===h.resetSearchInput&&o.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var n,i,c=[];for(n=0;n0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:n=!1}return n}function d(){var e=n.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw s("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var i=t[h.activeIndex],c=i.offsetTop+i.clientHeight-e[0].scrollTop,r=e[0].offsetHeight;c>r?e[0].scrollTop+=c-r:c=h.items.length?0:h.activeIndex,i(function(){h.search=e||h.search,h.searchInput[0].focus()}))},h.parseRepeatAttr=function(e,n,i){function c(e){var c=t.$eval(n);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(c)?c(e):e[c],n=h.findGroupByName(t);n?n.items.push(e):h.groups.push({name:t,items:[e]})}),i){var r=t.$eval(i);angular.isFunction(r)?h.groups=r(h.groups):angular.isArray(r)&&(h.groups=u(h.groups,r))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function r(e){h.items=e}h.setItemsFn=n?c:r,h.parserResult=l.parse(e),h.isGrouped=!!n,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var n=h.selected;if(h.isEmpty()||angular.isArray(n)&&!n.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var i=e.filter(function(e){return n.indexOf(e)<0});h.setItemsFn(i)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw s("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),n=t===h.activeIndex;return n&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),n},h.isDisabled=function(e){if(!h.open)return!1;var t,n=h.items.indexOf(e[h.itemProperty]),i=!1;return n>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[n],i=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i},h.select=function(e,n,c){if((void 0===e||!e._uiSelectChoiceDisabled)&&(h.items||h.search)){var r={};r[h.parserResult.itemName]=e;var l={$item:e,$model:h.parserResult.modelMapper(t,r)},s=function(){t.$broadcast("uis:select",e),i(function(){h.onSelectCallback(t,l)}),h.closeOnSelect&&h.close(n),c&&"click"===c.type&&(h.clickTriggeredSelect=!0)},o=h.onBeforeSelectCallback(t,l);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(e){e&&s(e)}):o===!0?s(e):o&&s(o):s(e)}},h.close=function(e){h.open&&(h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),a(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e))},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),i(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var n,i=h.selected[t];return i&&!angular.isUndefined(h.lockChoiceExpression)&&(n=!!e.$eval(h.lockChoiceExpression),i._uiSelectChoiceLocked=n),n};var v=null;h.sizeSearchInput=function(){var e=h.searchInput[0],n=h.searchInput.parent().parent()[0],c=function(){return n.clientWidth*!!e.offsetParent},r=function(t){if(0===t)return!1;var n=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=t),h.searchInput.css("width",n+"px"),!0};h.searchInput.css("width","10px"),i(function(){null!==v||r(c())||(v=t.$watch(c,function(e){r(e)&&(v(),v=null)}))})},h.searchInput.on("keydown",function(n){var i=n.which;t.$apply(function(){p(i)}),e.isVerticalMovement(i)&&h.items.length>0&&d(),(i===e.ENTER||i===e.ESC)&&(n.preventDefault(),n.stopPropagation())}),h.searchInput.on("keyup",function(n){n.which===e.TAB||e.isControl(n)||e.isFunctionKey(n)||n.which===e.ESC||e.isVerticalMovement(n.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:n})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),n.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,i,c,r,l){return{restrict:"EA",templateUrl:function(e,n){var i=n.theme||t.theme;return i+(angular.isDefined(n.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(c,s){return angular.isDefined(s.multiple)?c.append("").removeAttr("multiple"):c.append(""),function(c,s,o,a,u){function p(e){if(f.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(s[0],e.target):s[0].contains(e.target),!t&&!f.clickTriggeredSelect){var n=["input","button","textarea"],i=angular.element(e.target).scope(),r=i&&i.$select&&i.$select!==f;r||(r=~n.indexOf(e.target.tagName.toLowerCase())),f.close(r),c.$digest()}f.clickTriggeredSelect=!1}}function d(){var t=i(s);E=angular.element('
    '),E[0].style.width=t.width+"px",E[0].style.height=t.height+"px",s.after(E),b=s[0].style.width,e.find("body").append(s),s[0].style.position="absolute",s[0].style.left=t.left+"px",s[0].style.top=t.top+"px",s[0].style.width=t.width+"px"}function h(){null!==E&&(E.replaceWith(s),E=null,s[0].style.position="",s[0].style.left="",s[0].style.top="",s[0].style.width=b)}var f=a[0],v=a[1];f.generatedId=t.generateId(),f.baseTitle=o.title||"Select box",f.focusserTitle=f.baseTitle+" focus",f.focusserId="focusser-"+f.generatedId,f.closeOnSelect=function(){return angular.isDefined(o.closeOnSelect)?r(o.closeOnSelect)():t.closeOnSelect}(),f.onSelectCallback=r(o.onSelect),f.onBeforeSelectCallback=r(o.onBeforeSelect),f.onRemoveCallback=r(o.onRemove),f.onBeforeRemoveCallback=r(o.onBeforeRemove),f.onKeypressCallback=r(o.onKeypress),f.limit=angular.isDefined(o.limit)?parseInt(o.limit,10):void 0,f.ngModel=v,f.choiceGrouped=function(e){return f.isGrouped&&e&&e.name},o.tabindex&&o.$observe("tabindex",function(e){f.focusInput.attr("tabindex",e),s.removeAttr("tabindex")});var g=c.$eval(o.searchEnabled);f.searchEnabled=void 0!==g?g:t.searchEnabled;var m=c.$eval(o.sortable);f.sortable=void 0!==m?m:t.sortable,o.$observe("disabled",function(){f.disabled=void 0!==o.disabled?o.disabled:!1}),angular.isDefined(o.autofocus)&&l(function(){f.setFocus()}),angular.isDefined(o.focusOn)&&c.$on(o.focusOn,function(){l(function(){f.setFocus()})}),e.on("click",p),c.$on("$destroy",function(){e.off("click",p)}),u(c,function(e){var t=angular.element("
    ").append(e),i=t.querySelectorAll(".ui-select-match");if(i.removeAttr("ui-select-match"),i.removeAttr("data-ui-select-match"),1!==i.length)throw n("transcluded","Expected 1 .ui-select-match but got '{0}'.",i.length);s.querySelectorAll(".ui-select-match").replaceWith(i);var c=t.querySelectorAll(".ui-select-choices");if(c.removeAttr("ui-select-choices"),c.removeAttr("data-ui-select-choices"),1!==c.length)throw n("transcluded","Expected 1 .ui-select-choices but got '{0}'.",c.length);s.querySelectorAll(".ui-select-choices").replaceWith(c)});var $=c.$eval(o.appendToBody);(void 0!==$?$:t.appendToBody)&&(c.$watch("$select.open",function(e){e?d():h()}),c.$on("$destroy",function(){h()}));var E=null,b="",S=null,w="direction-up";c.$watch("$select.open",function(t){if(t){if(S=angular.element(s).querySelectorAll(".ui-select-dropdown"),null===S)return;S[0].style.opacity=0,l(function(){var t=i(s),n=i(S);t.top+t.height+n.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&s.addClass(w),S[0].style.opacity=1})}else{if(null===S)return;s.removeClass(w)}})}}}}]),n.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return n+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,i,c){function r(e){c.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}c.lockChoiceExpression=i.uiLockChoice,i.$observe("placeholder",function(t){c.placeholder=void 0!==t?t:e.placeholder}),i.$observe("allowClear",r),r(i.allowClear),c.multiple&&c.sizeSearchInput()}}}]),n.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,i=this,c=e.$select;e.$evalAsync(function(){n=e.ngModel}),i.activeMatchIndex=-1,i.updateModel=function(){n.$setViewValue(Date.now()),i.refreshComponent()},i.refreshComponent=function(){c.refreshItems(),c.sizeSearchInput()},i.removeChoice=function(n){function r(){t(function(){c.onRemoveCallback(e,o)}),i.updateModel()}var l=c.selected[n];if(!l._uiSelectChoiceLocked){var s={};s[c.parserResult.itemName]=l,c.selected.splice(n,1),i.activeMatchIndex=-1,c.sizeSearchInput();var o={$item:l,$model:c.parserResult.modelMapper(e,s)},a=i.onBeforeRemoveCallback(e,o);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(e){e&&r(e)}):a===!0&&r():r()}},i.getPlaceholder=function(){return c.selected&&c.selected.length?void 0:c.placeholder}}],controllerAs:"$selectMultiple",link:function(i,c,r,l){function s(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function o(t){function n(){switch(t){case e.LEFT:return~p.activeMatchIndex?d:l;case e.RIGHT:return~p.activeMatchIndex&&o!==l?u:(a.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(o),d):l;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),o):!1}}var i=s(a.searchInput[0]),c=a.selected.length,r=0,l=c-1,o=p.activeMatchIndex,u=p.activeMatchIndex+1,d=p.activeMatchIndex-1,h=o;return i>0||a.search.length&&t==e.RIGHT?!1:(a.close(),h=n(),p.activeMatchIndex=a.selected.length&&h!==!1?Math.min(l,Math.max(r,h)):-1,!0)}var a=l[0],u=i.ngModel=l[1],p=i.$selectMultiple;a.multiple=!0,a.removeSelected=!0,a.focusInput=a.searchInput,u.$parsers.unshift(function(){for(var e,t={},n=[],c=a.selected.length-1;c>=0;c--)t={},t[a.parserResult.itemName]=a.selected[c],e=a.parserResult.modelMapper(i,t),n.unshift(e);return n}),u.$formatters.unshift(function(e){var t,n=a.parserResult.source(i,{$select:{search:""}}),c={};if(!n)return e;var r=[],l=function(e,n){if(e&&e.length){for(var l=e.length-1;l>=0;l--){if(c[a.parserResult.itemName]=e[l],t=a.parserResult.modelMapper(i,c),a.parserResult.trackByExp){var s=/\.(.+)/.exec(a.parserResult.trackByExp);if(s.length>0&&t[s[1]]==n[s[1]])return r.unshift(e[l]),!0}if(angular.equals(t,n))return r.unshift(e[l]),!0}return!1}};if(!e)return r;for(var s=e.length-1;s>=0;s--)l(a.selected,e[s])||l(n,e[s])||r.unshift(e[s]);return r}),i.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);a.selected=[]}a.selected=u.$viewValue,i.$evalAsync()},i.$on("uis:select",function(e,t){a.selected.length>=a.limit||(a.selected.push(t),p.updateModel())}),i.$on("uis:activate",function(){p.activeMatchIndex=-1}),i.$watch("$select.disabled",function(e,t){t&&!e&&a.sizeSearchInput()}),a.searchInput.on("keydown",function(t){var n=t.which;i.$apply(function(){var t=!1;e.isHorizontalMovement(n)&&(t=o(n)),t&&n!=e.TAB})}),a.searchInput.on("blur",function(){n(function(){p.activeMatchIndex=-1})})}}}]),n.directive("uiSelectSingle",["$timeout","$compile",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(i,c,r,l){var s=l[0],o=l[1];o.$parsers.unshift(function(e){var t,n={};return n[s.parserResult.itemName]=e,t=s.parserResult.modelMapper(i,n)}),o.$formatters.unshift(function(e){var t,n=s.parserResult.source(i,{$select:{search:""}}),c={};if(n){var r=function(n){return c[s.parserResult.itemName]=n,t=s.parserResult.modelMapper(i,c),t==e};if(s.selected&&r(s.selected))return s.selected;for(var l=n.length-1;l>=0;l--)if(r(n[l]))return n[l]}return e}),i.$watch("$select.selected",function(e){o.$viewValue!==e&&o.$setViewValue(e)}),o.$render=function(){s.selected=o.$viewValue},i.$on("uis:select",function(e,t){s.selected=t}),i.$on("uis:close",function(e,n){t(function(){s.focusser.prop("disabled",!1),n||s.focusser[0].focus()},0,!1)}),i.$on("uis:activate",function(){a.prop("disabled",!0)});var a=angular.element("");n(a)(i),s.focusser=a,s.focusInput=a,c.parent().append(a),a.bind("focus",function(){i.$evalAsync(function(){s.focus=!0})}),a.bind("blur",function(){i.$evalAsync(function(){s.focus=!1})}),a.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),s.select(void 0),i.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),s.activate()),i.$digest()),void 0)}),a.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(s.activate(a.val()),a.val(""),i.$digest())})}}}]),n.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var i=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!i)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:i[2],source:t(i[3]),trackByExp:i[4],modelMapper:t(i[1]||i[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,i){var c=e+" in "+(i?"$group.items":t);return n&&(c+=" track by "+n),c}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("selectize/choices.tpl.html",'
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/dist/select.tpl.js b/dist/select.tpl.js index 744e094b1..c04431faf 100644 --- a/dist/select.tpl.js +++ b/dist/select.tpl.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-02T20:56:31.470Z + * Version: 0.12.1 - 2015-08-04T17:24:10.036Z * License: MIT */ diff --git a/src/common.css b/src/common.css index 9ebdd29df..62473aab2 100644 --- a/src/common.css +++ b/src/common.css @@ -47,6 +47,10 @@ body > .select2-container.open { border-top-right-radius: 0; } .ui-select-container[theme="select2"].direction-up .ui-select-dropdown { + bottom: 100%; + top: auto; + position: absolute; + border-radius: 4px; /* FIXME hardcoded value :-/ */ border-bottom-left-radius: 0; border-bottom-right-radius: 0; @@ -89,6 +93,10 @@ body > .select2-container.open { /* Handle up direction Selectize */ .ui-select-container[theme="selectize"].direction-up .ui-select-dropdown { + bottom: 100%; + top: auto; + position: absolute; + box-shadow: 0 -4px 8px rgba(0, 0, 0, 0.25); margin-top: -2px; /* FIXME hardcoded value :-/ */ @@ -263,5 +271,9 @@ body > .ui-select-bootstrap.open { /* Handle up direction Bootstrap */ .ui-select-container[theme="bootstrap"].direction-up .ui-select-dropdown { + bottom: 100%; + top: auto; + position: absolute; + box-shadow: 0 -4px 8px rgba(0, 0, 0, 0.25); } diff --git a/src/common.js b/src/common.js index efc7a5b9f..f165d2533 100644 --- a/src/common.js +++ b/src/common.js @@ -1,4 +1,3 @@ - var KEY = { TAB: 9, ENTER: 13, @@ -19,20 +18,123 @@ var KEY = { DELETE: 46, COMMAND: 91, - MAP: { 91 : "COMMAND", 8 : "BACKSPACE" , 9 : "TAB" , 13 : "ENTER" , 16 : "SHIFT" , 17 : "CTRL" , 18 : "ALT" , 19 : "PAUSEBREAK" , 20 : "CAPSLOCK" , 27 : "ESC" , 32 : "SPACE" , 33 : "PAGE_UP", 34 : "PAGE_DOWN" , 35 : "END" , 36 : "HOME" , 37 : "LEFT" , 38 : "UP" , 39 : "RIGHT" , 40 : "DOWN" , 43 : "+" , 44 : "PRINTSCREEN" , 45 : "INSERT" , 46 : "DELETE", 48 : "0" , 49 : "1" , 50 : "2" , 51 : "3" , 52 : "4" , 53 : "5" , 54 : "6" , 55 : "7" , 56 : "8" , 57 : "9" , 59 : ";", 61 : "=" , 65 : "A" , 66 : "B" , 67 : "C" , 68 : "D" , 69 : "E" , 70 : "F" , 71 : "G" , 72 : "H" , 73 : "I" , 74 : "J" , 75 : "K" , 76 : "L", 77 : "M" , 78 : "N" , 79 : "O" , 80 : "P" , 81 : "Q" , 82 : "R" , 83 : "S" , 84 : "T" , 85 : "U" , 86 : "V" , 87 : "W" , 88 : "X" , 89 : "Y" , 90 : "Z", 96 : "0" , 97 : "1" , 98 : "2" , 99 : "3" , 100 : "4" , 101 : "5" , 102 : "6" , 103 : "7" , 104 : "8" , 105 : "9", 106 : "*" , 107 : "+" , 109 : "-" , 110 : "." , 111 : "/", 112 : "F1" , 113 : "F2" , 114 : "F3" , 115 : "F4" , 116 : "F5" , 117 : "F6" , 118 : "F7" , 119 : "F8" , 120 : "F9" , 121 : "F10" , 122 : "F11" , 123 : "F12", 144 : "NUMLOCK" , 145 : "SCROLLLOCK" , 186 : ";" , 187 : "=" , 188 : "," , 189 : "-" , 190 : "." , 191 : "/" , 192 : "`" , 219 : "[" , 220 : "\\" , 221 : "]" , 222 : "'" + MAP: { + 91: "COMMAND", + 8: "BACKSPACE", + 9: "TAB", + 13: "ENTER", + 16: "SHIFT", + 17: "CTRL", + 18: "ALT", + 19: "PAUSEBREAK", + 20: "CAPSLOCK", + 27: "ESC", + 32: "SPACE", + 33: "PAGE_UP", + 34: "PAGE_DOWN", + 35: "END", + 36: "HOME", + 37: "LEFT", + 38: "UP", + 39: "RIGHT", + 40: "DOWN", + 43: "+", + 44: "PRINTSCREEN", + 45: "INSERT", + 46: "DELETE", + 48: "0", + 49: "1", + 50: "2", + 51: "3", + 52: "4", + 53: "5", + 54: "6", + 55: "7", + 56: "8", + 57: "9", + 59: ";", + 61: "=", + 65: "A", + 66: "B", + 67: "C", + 68: "D", + 69: "E", + 70: "F", + 71: "G", + 72: "H", + 73: "I", + 74: "J", + 75: "K", + 76: "L", + 77: "M", + 78: "N", + 79: "O", + 80: "P", + 81: "Q", + 82: "R", + 83: "S", + 84: "T", + 85: "U", + 86: "V", + 87: "W", + 88: "X", + 89: "Y", + 90: "Z", + 96: "0", + 97: "1", + 98: "2", + 99: "3", + 100: "4", + 101: "5", + 102: "6", + 103: "7", + 104: "8", + 105: "9", + 106: "*", + 107: "+", + 109: "-", + 110: ".", + 111: "/", + 112: "F1", + 113: "F2", + 114: "F3", + 115: "F4", + 116: "F5", + 117: "F6", + 118: "F7", + 119: "F8", + 120: "F9", + 121: "F10", + 122: "F11", + 123: "F12", + 144: "NUMLOCK", + 145: "SCROLLLOCK", + 186: ";", + 187: "=", + 188: ",", + 189: "-", + 190: ".", + 191: "/", + 192: "`", + 219: "[", + 220: "\\", + 221: "]", + 222: "'" }, isControl: function (e) { var k = e.which; switch (k) { - case KEY.COMMAND: - case KEY.SHIFT: - case KEY.CTRL: - case KEY.ALT: - return true; + case KEY.COMMAND: + case KEY.SHIFT: + case KEY.CTRL: + case KEY.ALT: + return true; } - if (e.metaKey) return true; + if (e.metaKey) { + return true; + } return false; }, @@ -40,13 +142,13 @@ var KEY = { k = k.which ? k.which : k; return k >= 112 && k <= 123; }, - isVerticalMovement: function (k){ - return ~[KEY.UP, KEY.DOWN].indexOf(k); + isVerticalMovement: function (k) { + return ~[KEY.UP, KEY.DOWN].indexOf(k); }, - isHorizontalMovement: function (k){ - return ~[KEY.LEFT,KEY.RIGHT,KEY.BACKSPACE,KEY.DELETE].indexOf(k); + isHorizontalMovement: function (k) { + return ~[KEY.LEFT, KEY.RIGHT, KEY.BACKSPACE, KEY.DELETE].indexOf(k); } - }; +}; /** * Add querySelectorAll() to jqLite. @@ -58,67 +160,67 @@ var KEY = { * See feat(jqLite): use querySelectorAll instead of getElementsByTagName in jqLite.find https://github.com/angular/angular.js/pull/3598 */ if (angular.element.prototype.querySelectorAll === undefined) { - angular.element.prototype.querySelectorAll = function(selector) { - return angular.element(this[0].querySelectorAll(selector)); - }; + angular.element.prototype.querySelectorAll = function (selector) { + return angular.element(this[0].querySelectorAll(selector)); + }; } /** * Add closest() to jqLite. */ if (angular.element.prototype.closest === undefined) { - angular.element.prototype.closest = function( selector) { - var elem = this[0]; - var matchesSelector = elem.matches || elem.webkitMatchesSelector || elem.mozMatchesSelector || elem.msMatchesSelector; - - while (elem) { - if (matchesSelector.bind(elem)(selector)) { - return elem; - } else { - elem = elem.parentElement; - } - } - return false; - }; + angular.element.prototype.closest = function (selector) { + var elem = this[0]; + var matchesSelector = elem.matches || elem.webkitMatchesSelector || elem.mozMatchesSelector || + elem.msMatchesSelector; + + while (elem) { + if (matchesSelector.bind(elem)(selector)) { + return elem; + } else { + elem = elem.parentElement; + } + } + return false; + }; } var latestId = 0; var uis = angular.module('ui.select', []) -.constant('uiSelectConfig', { - theme: 'bootstrap', - searchEnabled: true, - sortable: false, - placeholder: '', // Empty by default, like HTML tag + closeOnSelect: true, + generateId: function () { + return latestId++; + }, + appendToBody: false + }) // See Rename minErr and make it accessible from outside https://github.com/angular/angular.js/issues/6913 -.service('uiSelectMinErr', function() { - var minErr = angular.$$minErr('ui.select'); - return function() { - var error = minErr.apply(this, arguments); - var message = error.message.replace(new RegExp('\nhttp://errors.angularjs.org/.*'), ''); - return new Error(message); - }; -}) + .service('uiSelectMinErr', function () { + var minErr = angular.$$minErr('ui.select'); + return function () { + var error = minErr.apply(this, arguments); + var message = error.message.replace(new RegExp('\nhttp://errors.angularjs.org/.*'), ''); + return new Error(message); + }; + }) // Recreates old behavior of ng-transclude. Used internally. -.directive('uisTranscludeAppend', function () { - return { - link: function (scope, element, attrs, ctrl, transclude) { - transclude(scope, function (clone) { - element.append(clone); - }); - } - }; -}) + .directive('uisTranscludeAppend', function () { + return { + link: function (scope, element, attrs, ctrl, transclude) { + transclude(scope, function (clone) { + element.append(clone); + }); + } + }; + }) /** * Highlights text that matches $select.search. @@ -126,15 +228,16 @@ var uis = angular.module('ui.select', []) * Taken from AngularUI Bootstrap Typeahead * See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L340 */ -.filter('highlight', function() { - function escapeRegexp(queryToEscape) { - return queryToEscape.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1'); - } + .filter('highlight', function () { + function escapeRegexp(queryToEscape) { + return queryToEscape.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1'); + } - return function(matchItem, query) { - return query && matchItem ? matchItem.replace(new RegExp(escapeRegexp(query), 'gi'), '$&') : matchItem; - }; -}) + return function (matchItem, query) { + return query && matchItem ? matchItem.replace(new RegExp(escapeRegexp(query), 'gi'), + '$&') : matchItem; + }; + }) /** * A read-only equivalent of jQuery's offset function: http://api.jquery.com/offset/ @@ -142,17 +245,17 @@ var uis = angular.module('ui.select', []) * Taken from AngularUI Bootstrap Position: * See https://github.com/angular-ui/bootstrap/blob/master/src/position/position.js#L70 */ -.factory('uisOffset', - ['$document', '$window', - function ($document, $window) { - - return function(element) { - var boundingClientRect = element[0].getBoundingClientRect(); - return { - width: boundingClientRect.width || element.prop('offsetWidth'), - height: boundingClientRect.height || element.prop('offsetHeight'), - top: boundingClientRect.top + ($window.pageYOffset || $document[0].documentElement.scrollTop), - left: boundingClientRect.left + ($window.pageXOffset || $document[0].documentElement.scrollLeft) - }; - }; -}]); + .factory('uisOffset', + ['$document', '$window', + function ($document, $window) { + + return function (element) { + var boundingClientRect = element[0].getBoundingClientRect(); + return { + width: boundingClientRect.width || element.prop('offsetWidth'), + height: boundingClientRect.height || element.prop('offsetHeight'), + top: boundingClientRect.top + ($window.pageYOffset || $document[0].documentElement.scrollTop), + left: boundingClientRect.left + ($window.pageXOffset || $document[0].documentElement.scrollLeft) + }; + }; + }]); diff --git a/src/uiSelectChoicesDirective.js b/src/uiSelectChoicesDirective.js index 328f99cfd..b9339beed 100644 --- a/src/uiSelectChoicesDirective.js +++ b/src/uiSelectChoicesDirective.js @@ -1,75 +1,71 @@ uis.directive('uiSelectChoices', - ['uiSelectConfig', 'uisRepeatParser', 'uiSelectMinErr', '$compile', - function(uiSelectConfig, RepeatParser, uiSelectMinErr, $compile) { - - return { - restrict: 'EA', - require: '^uiSelect', - replace: true, - transclude: true, - templateUrl: function(tElement) { - // Gets theme attribute from parent (ui-select) - var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; - return theme + '/choices.tpl.html'; - }, - - compile: function(tElement, tAttrs) { - - if (!tAttrs.repeat) throw uiSelectMinErr('repeat', "Expected 'repeat' expression."); - - return function link(scope, element, attrs, $select, transcludeFn) { - - // var repeat = RepeatParser.parse(attrs.repeat); - var groupByExp = attrs.groupBy; - var groupFilterExp = attrs.groupFilter; - - $select.parseRepeatAttr(attrs.repeat, groupByExp, groupFilterExp); //Result ready at $select.parserResult - - $select.disableChoiceExpression = attrs.uiDisableChoice; - $select.onHighlightCallback = attrs.onHighlight; - - $select.refreshOnActive = scope.$eval(attrs.refreshOnActive); - - if(groupByExp) { - var groups = element.querySelectorAll('.ui-select-choices-group'); - if (groups.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-group but got '{0}'.", groups.length); - groups.attr('ng-repeat', RepeatParser.getGroupNgRepeatExpression()); - } - - var choices = element.querySelectorAll('.ui-select-choices-row'); - if (choices.length !== 1) { - throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row but got '{0}'.", choices.length); - } - - choices.attr('ng-repeat', RepeatParser.getNgRepeatExpression($select.parserResult.itemName, '$select.items', $select.parserResult.trackByExp, groupByExp)) - .attr('ng-if', '$select.open') //Prevent unnecessary watches when dropdown is closed - .attr('ng-mouseenter', '$select.setActiveItem('+$select.parserResult.itemName +')') - .attr('ng-click', '$select.select(' + $select.parserResult.itemName + ',false,$event)'); - - var rowsInner = element.querySelectorAll('.ui-select-choices-row-inner'); - if (rowsInner.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row-inner but got '{0}'.", rowsInner.length); - rowsInner.attr('uis-transclude-append', ''); //Adding uisTranscludeAppend directive to row element after choices element has ngRepeat - - $compile(element, transcludeFn)(scope); //Passing current transcludeFn to be able to append elements correctly from uisTranscludeAppend - - scope.$watch('$select.search', function(newValue) { - if(newValue && !$select.open && $select.multiple) $select.activate(false, true); - $select.activeIndex = 0; - if(!$select.refreshOnActive || ($select.refreshOnActive && $select.refreshIsActive)) { - $select.refresh(attrs.refresh); - } - }); - - scope.$watch('$select.refreshIsActive', function(newValue, oldValue){ - if(angular.isUndefined(oldValue) && newValue){ - $select.refresh(attrs.refresh); - } - }); - - // $eval() is needed otherwise we get a string instead of a number - var refreshDelay = scope.$eval(attrs.refreshDelay); - $select.refreshDelay = refreshDelay !== undefined ? refreshDelay : uiSelectConfig.refreshDelay; - }; - } - }; -}]); + ['uiSelectConfig', 'uisRepeatParser', 'uiSelectMinErr', '$compile', + function (uiSelectConfig, RepeatParser, uiSelectMinErr, $compile) { + + return { + restrict: 'EA', + require: '^uiSelect', + replace: true, + transclude: true, + templateUrl: function (tElement) { + // Gets theme attribute from parent (ui-select) + var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; + return theme + '/choices.tpl.html'; + }, + + compile: function (tElement, tAttrs) { + + if (!tAttrs.repeat) { + throw uiSelectMinErr('repeat', "Expected 'repeat' expression."); + } + + return function link(scope, element, attrs, $select, transcludeFn) { + + // var repeat = RepeatParser.parse(attrs.repeat); + var groupByExp = attrs.groupBy; + var groupFilterExp = attrs.groupFilter; + + $select.parseRepeatAttr(attrs.repeat, groupByExp, groupFilterExp); //Result ready at $select.parserResult + + $select.disableChoiceExpression = attrs.uiDisableChoice; + $select.onHighlightCallback = attrs.onHighlight; + + if (groupByExp) { + var groups = element.querySelectorAll('.ui-select-choices-group'); + if (groups.length !== 1) throw uiSelectMinErr('rows', + "Expected 1 .ui-select-choices-group but got '{0}'.", groups.length); + groups.attr('ng-repeat', RepeatParser.getGroupNgRepeatExpression()); + } + + var choices = element.querySelectorAll('.ui-select-choices-row'); + if (choices.length !== 1) { + throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row but got '{0}'.", + choices.length); + } + + choices.attr('ng-repeat', + RepeatParser.getNgRepeatExpression($select.parserResult.itemName, '$select.items', + $select.parserResult.trackByExp, groupByExp)) + .attr('ng-if', '$select.open') //Prevent unnecessary watches when dropdown is closed + .attr('ng-mouseenter', '$select.setActiveItem(' + $select.parserResult.itemName + ')') + .attr('ng-click', '$select.select(' + $select.parserResult.itemName + ',false,$event)'); + + var rowsInner = element.querySelectorAll('.ui-select-choices-row-inner'); + if (rowsInner.length !== 1) { + throw uiSelectMinErr('rows', + "Expected 1 .ui-select-choices-row-inner but got '{0}'.", rowsInner.length); + } + rowsInner.attr('uis-transclude-append', ''); //Adding uisTranscludeAppend directive to row element after choices element has ngRepeat + + $compile(element, transcludeFn)(scope); //Passing current transcludeFn to be able to append elements correctly from uisTranscludeAppend + + scope.$watch('$select.search', function (newValue) { + if (newValue && !$select.open && $select.multiple) { + $select.activate(false, true); + } + $select.activeIndex = 0; + }); + }; + } + }; + }]); diff --git a/src/uiSelectController.js b/src/uiSelectController.js index dfb05c513..8c9716ba2 100644 --- a/src/uiSelectController.js +++ b/src/uiSelectController.js @@ -15,7 +15,6 @@ uis.controller('uiSelectCtrl', ctrl.placeholder = uiSelectConfig.placeholder; ctrl.searchEnabled = uiSelectConfig.searchEnabled; ctrl.sortable = uiSelectConfig.sortable; - ctrl.refreshDelay = uiSelectConfig.refreshDelay; ctrl.removeSelected = false; //If selected item(s) should be removed from dropdown list ctrl.closeOnSelect = true; //Initialized inside uiSelect directive link function @@ -36,8 +35,6 @@ uis.controller('uiSelectCtrl', ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelectMatch directive link function ctrl.clickTriggeredSelect = false; ctrl.$filter = $filter; - ctrl.refreshOnActive = undefined; - ctrl.refreshIsActive = undefined; ctrl.searchInput = $element.querySelectorAll('input.ui-select-search'); if (ctrl.searchInput.length !== 1) { @@ -45,6 +42,10 @@ uis.controller('uiSelectCtrl', ctrl.searchInput.length); } + /** + * Returns true if the selection is empty + * @returns {boolean|*} + */ ctrl.isEmpty = function () { return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === ''; }; @@ -60,6 +61,12 @@ uis.controller('uiSelectCtrl', } } + ctrl.findGroupByName = function (name) { + return ctrl.groups && ctrl.groups.filter(function (group) { + return group.name === name; + })[0]; + }; + function _groupsFilter(groups, groupNames) { var i, j, result = []; for (i = 0; i < groupNames.length; i++) { @@ -72,10 +79,15 @@ uis.controller('uiSelectCtrl', return result; } - // When the user clicks on ui-select, displays the dropdown list + /** + * Activates the control. + * When the user clicks on ui-select, displays the dropdown list + */ ctrl.activate = function (initSearchValue, avoidReset) { if (!ctrl.disabled && !ctrl.open) { - if (!avoidReset) _resetSearchInput(); + if (!avoidReset) { + _resetSearchInput(); + } $scope.$broadcast('uis:activate'); @@ -85,7 +97,6 @@ uis.controller('uiSelectCtrl', } ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex; - ctrl.refreshIsActive = true; // Give it time to appear before focus $timeout(function () { @@ -99,12 +110,6 @@ uis.controller('uiSelectCtrl', } }; - ctrl.findGroupByName = function (name) { - return ctrl.groups && ctrl.groups.filter(function (group) { - return group.name === name; - })[0]; - }; - ctrl.parseRepeatAttr = function (repeatAttr, groupByExp, groupFilterExp) { function updateGroups(items) { var groupFn = $scope.$eval(groupByExp); @@ -137,6 +142,7 @@ uis.controller('uiSelectCtrl', ctrl.items = items; } + // Set the function to use when displaying items - either groups or single ctrl.setItemsFn = groupByExp ? updateGroups : setPlainItems; ctrl.parserResult = RepeatParser.parse(repeatAttr); @@ -147,7 +153,7 @@ uis.controller('uiSelectCtrl', ctrl.refreshItems = function (data) { data = data || ctrl.parserResult.source($scope); var selectedItems = ctrl.selected; - //TODO should implement for single mode removeSelected + // TODO should implement for single mode removeSelected if (ctrl.isEmpty() || (angular.isArray(selectedItems) && !selectedItems.length) || !ctrl.removeSelected) { ctrl.setItemsFn(data); @@ -179,35 +185,17 @@ uis.controller('uiSelectCtrl', } } }); - - }; - - var _refreshDelayPromise; - - /** - * Typeahead mode: lets the user refresh the collection using his own function. - * - * See Expose $select.search for external / remote filtering https://github.com/angular-ui/ui-select/pull/31 - */ - ctrl.refresh = function (refreshAttr) { - if (refreshAttr !== undefined) { - - // Debounce - // See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L155 - // FYI AngularStrap typeahead does not have debouncing: https://github.com/mgcrea/angular-strap/blob/v2.0.0-rc.4/src/typeahead/typeahead.js#L177 - if (_refreshDelayPromise) { - $timeout.cancel(_refreshDelayPromise); - } - _refreshDelayPromise = $timeout(function () { - $scope.$eval(refreshAttr); - }, ctrl.refreshDelay); - } }; ctrl.setActiveItem = function (item) { ctrl.activeIndex = ctrl.items.indexOf(item); }; + /** + * Checks if the item is active + * @param itemScope the item + * @returns {boolean} true if active + */ ctrl.isActive = function (itemScope) { if (!ctrl.open) { return false; @@ -224,11 +212,14 @@ uis.controller('uiSelectCtrl', /** * Checks if the item is disabled - * @return boolean true if the item is disabled + * @param itemScope the item + * @return {boolean} true if the item is disabled */ ctrl.isDisabled = function (itemScope) { - if (!ctrl.open) return false; + if (!ctrl.open) { + return false; + } var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); var isDisabled = false; @@ -245,75 +236,81 @@ uis.controller('uiSelectCtrl', /** + * Selects an item + * * Called when the user selects an item with ENTER or clicks the dropdown */ ctrl.select = function (item, skipFocusser, $event) { - if (item === undefined || !item._uiSelectChoiceDisabled) { + if (item !== undefined && item._uiSelectChoiceDisabled) { + return; + } - if (!ctrl.items && !ctrl.search){ - return; - } + // If no items in the list, and no search, then return + if (!ctrl.items && !ctrl.search) { + return; + } - if (!item || !item._uiSelectChoiceDisabled) { + // Create the data used to pass to the callbacks + var locals = {}; + locals[ctrl.parserResult.itemName] = item; + var callbackContext = { + $item: item, + $model: ctrl.parserResult.modelMapper($scope, locals) + }; - var completeSelection = function () { - $scope.$broadcast('uis:select', item); + // Local method called when we complete the select + // eg. called after the onselect callback + var completeSelection = function () { + $scope.$broadcast('uis:select', item); - $timeout(function () { - ctrl.onSelectCallback($scope, callbackContext); - }); + $timeout(function () { + ctrl.onSelectCallback($scope, callbackContext); + }); - if (ctrl.closeOnSelect) { - ctrl.close(skipFocusser); - } - if ($event && $event.type === 'click') { - ctrl.clickTriggeredSelect = true; - } - }; - - var locals = {}; - locals[ctrl.parserResult.itemName] = item; - - var callbackContext = { - $item: item, - $model: ctrl.parserResult.modelMapper($scope, locals) - }; - - // Call the onBeforeSelect callback - // Allowable responses are -: - // falsy: Abort the selection - // promise: Wait for response - // true: Complete selection - // object: Add the returned object - var onBeforeSelectResult = ctrl.onBeforeSelectCallback($scope, callbackContext); - if (angular.isDefined(onBeforeSelectResult)) { - if (!onBeforeSelectResult) { - return; // abort the selection in case of deliberate falsey result - } else if (angular.isFunction(onBeforeSelectResult.then)) { - onBeforeSelectResult.then(function (result) { - if (!result) { - return; - } - completeSelection(result); - }); - } else if (onBeforeSelectResult === true) { - completeSelection(item); - } else { - completeSelection(onBeforeSelectResult); + if (ctrl.closeOnSelect) { + ctrl.close(skipFocusser); + } + if ($event && $event.type === 'click') { + ctrl.clickTriggeredSelect = true; + } + }; + + // Call the onBeforeSelect callback + // Allowable responses are -: + // falsy: Abort the selection + // promise: Wait for response + // true: Complete selection + // object: Add the returned object + var onBeforeSelectResult = ctrl.onBeforeSelectCallback($scope, callbackContext); + if (angular.isDefined(onBeforeSelectResult)) { + if (angular.isFunction(onBeforeSelectResult.then)) { + // Promise returned - wait for it to complete before completing the selection + onBeforeSelectResult.then(function (result) { + if (!result) { + return; } - } else { - completeSelection(item); - } + completeSelection(result); + }); + } else if (onBeforeSelectResult === true) { + completeSelection(item); + } else if (onBeforeSelectResult) { + completeSelection(onBeforeSelectResult); } + } else { + completeSelection(item); } }; - // Closes the dropdown + /** + * Close the dropdown + */ ctrl.close = function (skipFocusser) { if (!ctrl.open) { return; } - if (ctrl.ngModel && ctrl.ngModel.$setTouched) ctrl.ngModel.$setTouched(); + if (ctrl.ngModel && ctrl.ngModel.$setTouched) { + ctrl.ngModel.$setTouched(); + } _resetSearchInput(); ctrl.open = false; if (!ctrl.searchEnabled) { @@ -323,12 +320,19 @@ uis.controller('uiSelectCtrl', $scope.$broadcast('uis:close', skipFocusser); }; + /** + * Set focus on the control + */ ctrl.setFocus = function () { if (!ctrl.focus) { ctrl.focusInput[0].focus(); } }; + /** + * Clears the selection + * @param $event + */ ctrl.clear = function ($event) { ctrl.select(undefined); $event.stopPropagation(); @@ -337,7 +341,9 @@ uis.controller('uiSelectCtrl', }, 0, false); }; - // Toggle dropdown + /** + * Toggle the dropdown open and closed + */ ctrl.toggle = function (e) { if (ctrl.open) { ctrl.close(); @@ -361,7 +367,6 @@ uis.controller('uiSelectCtrl', var sizeWatch = null; ctrl.sizeSearchInput = function () { - var input = ctrl.searchInput[0], container = ctrl.searchInput.parent().parent()[0], calculateContainerWidth = function () { @@ -414,7 +419,9 @@ uis.controller('uiSelectCtrl', } break; case KEY.TAB: - if (!ctrl.multiple || ctrl.open) ctrl.select(ctrl.items[ctrl.activeIndex], true); + if (!ctrl.multiple || ctrl.open) { + ctrl.select(ctrl.items[ctrl.activeIndex], true); + } break; case KEY.ENTER: if (ctrl.open) { @@ -458,24 +465,6 @@ uis.controller('uiSelectCtrl', } }); - // If tagging try to split by tokens and add items - /* ctrl.searchInput.on('paste', function (e) { - var data = e.originalEvent.clipboardData.getData('text/plain'); - if (data && data.length > 0 && ctrl.taggingTokens.isActivated && ctrl.tagging.fct) { - var items = data.split(ctrl.taggingTokens.tokens[0]); // split by first token only - if (items && items.length > 0) { - angular.forEach(items, function (item) { - var newItem = ctrl.tagging.fct(item); - if (newItem) { - ctrl.select(newItem, true); - } - }); - e.preventDefault(); - e.stopPropagation(); - } - } - });*/ - ctrl.searchInput.on('keyup', function (e) { // return early with these keys if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || @@ -489,7 +478,6 @@ uis.controller('uiSelectCtrl', ctrl.onKeypressCallback($scope, {event: e}); }); - // See https://github.com/ivaynberg/select2/blob/3.4.6/select2.js#L1431 function _ensureHighlightVisible() { var container = $element.querySelectorAll('.ui-select-choices-content'); @@ -510,10 +498,13 @@ uis.controller('uiSelectCtrl', if (posY > height) { container[0].scrollTop += posY - height; } else if (posY < highlighted.clientHeight) { - if (ctrl.isGrouped && ctrl.activeIndex === 0) - container[0].scrollTop = 0; //To make group header visible when going all the way up - else + if (ctrl.isGrouped && ctrl.activeIndex === 0) { + //To make group header visible when going all the way up + container[0].scrollTop = 0; + } + else { container[0].scrollTop -= highlighted.clientHeight - posY; + } } } diff --git a/src/uiSelectDirective.js b/src/uiSelectDirective.js index 41e81a774..56bc6738d 100644 --- a/src/uiSelectDirective.js +++ b/src/uiSelectDirective.js @@ -41,9 +41,10 @@ uis.directive('uiSelect', } }(); - $select.onBeforeSelectCallback = $parse(attrs.onBeforeSelect); $select.onSelectCallback = $parse(attrs.onSelect); + $select.onBeforeSelectCallback = $parse(attrs.onBeforeSelect); $select.onRemoveCallback = $parse(attrs.onRemove); + $select.onBeforeRemoveCallback = $parse(attrs.onBeforeRemove); $select.onKeypressCallback = $parse(attrs.onKeypress); //Limit the number of selections allowed @@ -75,11 +76,6 @@ uis.directive('uiSelect', $select.disabled = attrs.disabled !== undefined ? attrs.disabled : false; }); - attrs.$observe('resetSearchInput', function () { - // $eval() is needed otherwise we get a string instead of a boolean - var resetSearchInput = scope.$eval(attrs.resetSearchInput); - $select.resetSearchInput = resetSearchInput !== undefined ? resetSearchInput : true; - }); //Automatically gets focus when loaded if (angular.isDefined(attrs.autofocus)) { @@ -231,6 +227,7 @@ uis.directive('uiSelect', // Support changing the direction of the dropdown if there isn't enough space to render it. scope.$watch('$select.open', function (isOpen) { if (isOpen) { + // Get the dropdown element dropdown = angular.element(element).querySelectorAll('.ui-select-dropdown'); if (dropdown === null) { return; @@ -248,8 +245,6 @@ uis.directive('uiSelect', if (offset.top + offset.height + offsetDropdown.height > $document[0].documentElement.scrollTop + $document[0].documentElement.clientHeight) { - dropdown[0].style.position = 'absolute'; - dropdown[0].style.top = (offsetDropdown.height * -1) + 'px'; element.addClass(directionUpClassName); } @@ -262,8 +257,6 @@ uis.directive('uiSelect', } // Reset the position of the dropdown. - dropdown[0].style.position = ''; - dropdown[0].style.top = ''; element.removeClass(directionUpClassName); } }); diff --git a/src/uiSelectMatchDirective.js b/src/uiSelectMatchDirective.js index b8102c7ad..bb3579df5 100644 --- a/src/uiSelectMatchDirective.js +++ b/src/uiSelectMatchDirective.js @@ -1,32 +1,32 @@ -uis.directive('uiSelectMatch', ['uiSelectConfig', function(uiSelectConfig) { - return { - restrict: 'EA', - require: '^uiSelect', - replace: true, - transclude: true, - templateUrl: function(tElement) { - // Gets theme attribute from parent (ui-select) - var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; - var multi = tElement.parent().attr('multiple'); - return theme + (multi ? '/match-multiple.tpl.html' : '/match.tpl.html'); - }, - link: function(scope, element, attrs, $select) { - $select.lockChoiceExpression = attrs.uiLockChoice; - attrs.$observe('placeholder', function(placeholder) { - $select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder; - }); +uis.directive('uiSelectMatch', ['uiSelectConfig', function (uiSelectConfig) { + return { + restrict: 'EA', + require: '^uiSelect', + replace: true, + transclude: true, + templateUrl: function (tElement) { + // Gets theme attribute from parent (ui-select) + var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; + var multi = tElement.parent().attr('multiple'); + return theme + (multi ? '/match-multiple.tpl.html' : '/match.tpl.html'); + }, + link: function (scope, element, attrs, $select) { + $select.lockChoiceExpression = attrs.uiLockChoice; + attrs.$observe('placeholder', function (placeholder) { + $select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder; + }); - function setAllowClear(allow) { - $select.allowClear = (angular.isDefined(allow)) ? (allow === '') ? true : (allow.toLowerCase() === 'true') : false; - } + function setAllowClear(allow) { + $select.allowClear = + (angular.isDefined(allow)) ? (allow === '') ? true : (allow.toLowerCase() === 'true') : false; + } - attrs.$observe('allowClear', setAllowClear); - setAllowClear(attrs.allowClear); + attrs.$observe('allowClear', setAllowClear); + setAllowClear(attrs.allowClear); - if($select.multiple){ - $select.sizeSearchInput(); - } - - } - }; + if ($select.multiple) { + $select.sizeSearchInput(); + } + } + }; }]); diff --git a/src/uiSelectMultipleDirective.js b/src/uiSelectMultipleDirective.js index 40ad28eae..f3a2599ab 100644 --- a/src/uiSelectMultipleDirective.js +++ b/src/uiSelectMultipleDirective.js @@ -1,262 +1,316 @@ -uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelectMinErr, $timeout) { - return { - restrict: 'EA', - require: ['^uiSelect', '^ngModel'], - - controller: ['$scope','$timeout', function($scope, $timeout){ - - var ctrl = this, - $select = $scope.$select, - ngModel; - - //Wait for link fn to inject it - $scope.$evalAsync(function(){ ngModel = $scope.ngModel; }); - - ctrl.activeMatchIndex = -1; - - ctrl.updateModel = function(){ - ngModel.$setViewValue(Date.now()); //Set timestamp as a unique string to force changes - ctrl.refreshComponent(); - }; - - ctrl.refreshComponent = function(){ - //Remove already selected items - //e.g. When user clicks on a selection, the selected array changes and - //the dropdown should remove that item - $select.refreshItems(); - $select.sizeSearchInput(); - }; - - // Remove item from multiple select - ctrl.removeChoice = function(index){ - - var removedChoice = $select.selected[index]; - - // if the choice is locked, can't remove it - if(removedChoice._uiSelectChoiceLocked) return; - - var locals = {}; - locals[$select.parserResult.itemName] = removedChoice; - - $select.selected.splice(index, 1); - ctrl.activeMatchIndex = -1; - $select.sizeSearchInput(); - - // Give some time for scope propagation. - $timeout(function(){ - $select.onRemoveCallback($scope, { - $item: removedChoice, - $model: $select.parserResult.modelMapper($scope, locals) - }); - }); - - ctrl.updateModel(); - - }; - - ctrl.getPlaceholder = function(){ - //Refactor single? - if($select.selected && $select.selected.length) return; - return $select.placeholder; - }; +uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSelectMinErr, $timeout) { + return { + restrict: 'EA', + require: ['^uiSelect', '^ngModel'], + controller: ['$scope', '$timeout', function ($scope, $timeout) { + var ctrl = this, + $select = $scope.$select, + ngModel; + + //Wait for link fn to inject it + $scope.$evalAsync(function () { + ngModel = $scope.ngModel; + }); + + ctrl.activeMatchIndex = -1; + + ctrl.updateModel = function () { + ngModel.$setViewValue(Date.now()); //Set timestamp as a unique string to force changes + ctrl.refreshComponent(); + }; + + ctrl.refreshComponent = function () { + // Remove already selected items + // e.g. When user clicks on a selection, the selected array changes and + // the dropdown should remove that item + $select.refreshItems(); + $select.sizeSearchInput(); + }; + + // Remove item from multiple select + ctrl.removeChoice = function (index) { + var removedChoice = $select.selected[index]; + + // if the choice is locked, can't remove it + if (removedChoice._uiSelectChoiceLocked) { + return; + } + var locals = {}; + locals[$select.parserResult.itemName] = removedChoice; - }], - controllerAs: '$selectMultiple', + $select.selected.splice(index, 1); + ctrl.activeMatchIndex = -1; + $select.sizeSearchInput(); - link: function(scope, element, attrs, ctrls) { + var callbackContext = { + $item: removedChoice, + $model: $select.parserResult.modelMapper($scope, locals) + }; - var $select = ctrls[0]; - var ngModel = scope.ngModel = ctrls[1]; - var $selectMultiple = scope.$selectMultiple; + // Give some time for scope propagation. + function completeRemoval() { + $timeout(function () { + $select.onRemoveCallback($scope, callbackContext); + }); - //$select.selected = raw selected objects (ignoring any property binding) + ctrl.updateModel(); + } - $select.multiple = true; - $select.removeSelected = true; + // Call the onBeforeRemove callback + // Allowable responses are -: + // falsy: Abort the removal + // promise: Wait for response + // true: Complete removal + var onBeforeRemoveResult = ctrl.onBeforeRemoveCallback($scope, callbackContext); + if (angular.isDefined(onBeforeRemoveResult)) { + if (angular.isFunction(onBeforeRemoveResult.then)) { + // Promise returned - wait for it to complete before completing the selection + onBeforeRemoveResult.then(function (result) { + if (!result) { + return; + } + completeRemoval(result); + }); + } else if (onBeforeRemoveResult === true) { + completeRemoval(); + } + } else { + completeRemoval(); + } + }; - //Input that will handle focus - $select.focusInput = $select.searchInput; + ctrl.getPlaceholder = function () { + //Refactor single? + if ($select.selected && $select.selected.length) { + return; + } + return $select.placeholder; + }; + }], + controllerAs: '$selectMultiple', + + link: function (scope, element, attrs, ctrls) { + var $select = ctrls[0]; + var ngModel = scope.ngModel = ctrls[1]; + var $selectMultiple = scope.$selectMultiple; + + //$select.selected = raw selected objects (ignoring any property binding) + + $select.multiple = true; + $select.removeSelected = true; + + //Input that will handle focus + $select.focusInput = $select.searchInput; + + //From view --> model + ngModel.$parsers.unshift(function () { + var locals = {}, + result, + resultMultiple = []; + for (var j = $select.selected.length - 1; j >= 0; j--) { + locals = {}; + locals[$select.parserResult.itemName] = $select.selected[j]; + result = $select.parserResult.modelMapper(scope, locals); + resultMultiple.unshift(result); + } + return resultMultiple; + }); + + // From model --> view + ngModel.$formatters.unshift(function (inputValue) { + var data = $select.parserResult.source(scope, {$select: {search: ''}}), //Overwrite $search + locals = {}, + result; + if (!data) { + return inputValue; + } + var resultMultiple = []; + var checkFnMultiple = function (list, value) { + if (!list || !list.length) { + return; + } + for (var p = list.length - 1; p >= 0; p--) { + locals[$select.parserResult.itemName] = list[p]; + result = $select.parserResult.modelMapper(scope, locals); + if ($select.parserResult.trackByExp) { + var matches = /\.(.+)/.exec($select.parserResult.trackByExp); + if (matches.length > 0 && result[matches[1]] == value[matches[1]]) { + resultMultiple.unshift(list[p]); + return true; + } + } + if (angular.equals(result, value)) { + resultMultiple.unshift(list[p]); + return true; + } + } + return false; + }; + if (!inputValue) return resultMultiple; //If ngModel was undefined + for (var k = inputValue.length - 1; k >= 0; k--) { + //Check model array of currently selected items + if (!checkFnMultiple($select.selected, inputValue[k])) { + //Check model array of all items available + if (!checkFnMultiple(data, inputValue[k])) { + //If not found on previous lists, just add it directly to resultMultiple + resultMultiple.unshift(inputValue[k]); + } + } + } + return resultMultiple; + }); + + //Watch for external model changes + scope.$watchCollection(function () { + return ngModel.$modelValue; + }, function (newValue, oldValue) { + if (oldValue != newValue) { + ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters + $selectMultiple.refreshComponent(); + } + }); + + ngModel.$render = function () { + // Make sure that model value is array + if (!angular.isArray(ngModel.$viewValue)) { + // Have tolerance for null or undefined values + if (angular.isUndefined(ngModel.$viewValue) || ngModel.$viewValue === null) { + $select.selected = []; + } else { + throw uiSelectMinErr('multiarr', "Expected model value to be array but got '{0}'", + ngModel.$viewValue); + } + } + $select.selected = ngModel.$viewValue; + scope.$evalAsync(); //To force $digest + }; - //From view --> model - ngModel.$parsers.unshift(function () { - var locals = {}, - result, - resultMultiple = []; - for (var j = $select.selected.length - 1; j >= 0; j--) { - locals = {}; - locals[$select.parserResult.itemName] = $select.selected[j]; - result = $select.parserResult.modelMapper(scope, locals); - resultMultiple.unshift(result); - } - return resultMultiple; - }); - - // From model --> view - ngModel.$formatters.unshift(function (inputValue) { - var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search - locals = {}, - result; - if (!data) return inputValue; - var resultMultiple = []; - var checkFnMultiple = function(list, value){ - if (!list || !list.length) return; - for (var p = list.length - 1; p >= 0; p--) { - locals[$select.parserResult.itemName] = list[p]; - result = $select.parserResult.modelMapper(scope, locals); - if($select.parserResult.trackByExp){ - var matches = /\.(.+)/.exec($select.parserResult.trackByExp); - if(matches.length>0 && result[matches[1]] == value[matches[1]]){ - resultMultiple.unshift(list[p]); - return true; + scope.$on('uis:select', function (event, item) { + if ($select.selected.length >= $select.limit) { + return; + } + $select.selected.push(item); + $selectMultiple.updateModel(); + }); + + scope.$on('uis:activate', function () { + $selectMultiple.activeMatchIndex = -1; + }); + + scope.$watch('$select.disabled', function (newValue, oldValue) { + // As the search input field may now become visible, it may be necessary to recompute its size + if (oldValue && !newValue) { + $select.sizeSearchInput(); + } + }); + + $select.searchInput.on('keydown', function (e) { + var key = e.which; + scope.$apply(function () { + var processed = false; + if (KEY.isHorizontalMovement(key)) { + processed = _handleMatchSelection(key); + } + if (processed && key != KEY.TAB) { + //TODO Check si el tab selecciona aun correctamente + //Crear test +// e.preventDefault(); + // e.stopPropagation(); + } + }); + }); + function _getCaretPosition(el) { + if (angular.isNumber(el.selectionStart)) { + return el.selectionStart; + } + // selectionStart is not supported in IE8 and we don't want hacky workarounds so we compromise + else { + return el.value.length; } } - if (angular.equals(result,value)){ - resultMultiple.unshift(list[p]); - return true; - } - } - return false; - }; - if (!inputValue) return resultMultiple; //If ngModel was undefined - for (var k = inputValue.length - 1; k >= 0; k--) { - //Check model array of currently selected items - if (!checkFnMultiple($select.selected, inputValue[k])){ - //Check model array of all items available - if (!checkFnMultiple(data, inputValue[k])){ - //If not found on previous lists, just add it directly to resultMultiple - resultMultiple.unshift(inputValue[k]); - } - } - } - return resultMultiple; - }); - - //Watch for external model changes - scope.$watchCollection(function(){ return ngModel.$modelValue; }, function(newValue, oldValue) { - if (oldValue != newValue){ - ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters - $selectMultiple.refreshComponent(); - } - }); - - ngModel.$render = function() { - // Make sure that model value is array - if(!angular.isArray(ngModel.$viewValue)){ - // Have tolerance for null or undefined values - if(angular.isUndefined(ngModel.$viewValue) || ngModel.$viewValue === null){ - $select.selected = []; - } else { - throw uiSelectMinErr('multiarr', "Expected model value to be array but got '{0}'", ngModel.$viewValue); - } - } - $select.selected = ngModel.$viewValue; - scope.$evalAsync(); //To force $digest - }; - scope.$on('uis:select', function (event, item) { - if($select.selected.length >= $select.limit) { - return; - } - $select.selected.push(item); - $selectMultiple.updateModel(); - }); - - scope.$on('uis:activate', function () { - $selectMultiple.activeMatchIndex = -1; - }); - - scope.$watch('$select.disabled', function(newValue, oldValue) { - // As the search input field may now become visible, it may be necessary to recompute its size - if (oldValue && !newValue) $select.sizeSearchInput(); - }); - - $select.searchInput.on('keydown', function(e) { - var key = e.which; - scope.$apply(function() { - var processed = false; - if(KEY.isHorizontalMovement(key)){ - processed = _handleMatchSelection(key); - } - if (processed && key != KEY.TAB) { - //TODO Check si el tab selecciona aun correctamente - //Crear test -// e.preventDefault(); - // e.stopPropagation(); - } - }); - }); - function _getCaretPosition(el) { - if(angular.isNumber(el.selectionStart)) return el.selectionStart; - // selectionStart is not supported in IE8 and we don't want hacky workarounds so we compromise - else return el.value.length; - } - // Handles selected options in "multiple" mode - function _handleMatchSelection(key){ - var caretPosition = _getCaretPosition($select.searchInput[0]), - length = $select.selected.length, - // none = -1, - first = 0, - last = length-1, - curr = $selectMultiple.activeMatchIndex, - next = $selectMultiple.activeMatchIndex+1, - prev = $selectMultiple.activeMatchIndex-1, - newIndex = curr; - - if(caretPosition > 0 || ($select.search.length && key == KEY.RIGHT)) return false; - - $select.close(); - - function getNewActiveMatchIndex(){ - switch(key){ - case KEY.LEFT: - // Select previous/first item - if(~$selectMultiple.activeMatchIndex) return prev; - // Select last item - else return last; - break; - case KEY.RIGHT: - // Open drop-down - if(!~$selectMultiple.activeMatchIndex || curr === last){ - $select.activate(); - return false; - } - // Select next/last item - else return next; - break; - case KEY.BACKSPACE: - // Remove selected item and select previous/first - if(~$selectMultiple.activeMatchIndex){ - $selectMultiple.removeChoice(curr); - return prev; - } - // Select last item - else return last; - break; - case KEY.DELETE: - // Remove selected item and select next item - if(~$selectMultiple.activeMatchIndex){ - $selectMultiple.removeChoice($selectMultiple.activeMatchIndex); - return curr; - } - else return false; - } - } + // Handles selected options in "multiple" mode + function _handleMatchSelection(key) { + var caretPosition = _getCaretPosition($select.searchInput[0]), + length = $select.selected.length, + first = 0, + last = length - 1, + curr = $selectMultiple.activeMatchIndex, + next = $selectMultiple.activeMatchIndex + 1, + prev = $selectMultiple.activeMatchIndex - 1, + newIndex = curr; + + if (caretPosition > 0 || ($select.search.length && key == KEY.RIGHT)) { + return false; + } - newIndex = getNewActiveMatchIndex(); + $select.close(); + + function getNewActiveMatchIndex() { + switch (key) { + case KEY.LEFT: + // Select previous/first item + if (~$selectMultiple.activeMatchIndex) { + return prev; + } + // Select last item + else { + return last; + } + break; + case KEY.RIGHT: + // Open drop-down + if (!~$selectMultiple.activeMatchIndex || curr === last) { + $select.activate(); + return false; + } + // Select next/last item + else { + return next; + } + break; + case KEY.BACKSPACE: + // Remove selected item and select previous/first + if (~$selectMultiple.activeMatchIndex) { + $selectMultiple.removeChoice(curr); + return prev; + } + // Select last item + else { + return last; + } + break; + case KEY.DELETE: + // Remove selected item and select next item + if (~$selectMultiple.activeMatchIndex) { + $selectMultiple.removeChoice($selectMultiple.activeMatchIndex); + return curr; + } + else { + return false; + } + } + } - if(!$select.selected.length || newIndex === false) $selectMultiple.activeMatchIndex = -1; - else $selectMultiple.activeMatchIndex = Math.min(last,Math.max(first,newIndex)); + newIndex = getNewActiveMatchIndex(); - return true; - } + if (!$select.selected.length || newIndex === false) { + $selectMultiple.activeMatchIndex = -1; + } + else { + $selectMultiple.activeMatchIndex = Math.min(last, Math.max(first, newIndex)); + } - $select.searchInput.on('blur', function() { - $timeout(function() { - $selectMultiple.activeMatchIndex = -1; - }); - }); + return true; + } - } - }; + $select.searchInput.on('blur', function () { + $timeout(function () { + $selectMultiple.activeMatchIndex = -1; + }); + }); + + } + }; }]); diff --git a/src/uiSelectSingleDirective.js b/src/uiSelectSingleDirective.js index bad98a7ed..b1987ee5c 100644 --- a/src/uiSelectSingleDirective.js +++ b/src/uiSelectSingleDirective.js @@ -1,124 +1,124 @@ -uis.directive('uiSelectSingle', ['$timeout','$compile', function($timeout, $compile) { - return { - restrict: 'EA', - require: ['^uiSelect', '^ngModel'], - link: function(scope, element, attrs, ctrls) { - - var $select = ctrls[0]; - var ngModel = ctrls[1]; - - //From view --> model - ngModel.$parsers.unshift(function (inputValue) { - var locals = {}, - result; - locals[$select.parserResult.itemName] = inputValue; - result = $select.parserResult.modelMapper(scope, locals); - return result; - }); - - //From model --> view - ngModel.$formatters.unshift(function (inputValue) { - var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search - locals = {}, - result; - if (data){ - var checkFnSingle = function(d){ - locals[$select.parserResult.itemName] = d; - result = $select.parserResult.modelMapper(scope, locals); - return result == inputValue; - }; - //If possible pass same object stored in $select.selected - if ($select.selected && checkFnSingle($select.selected)) { - return $select.selected; - } - for (var i = data.length - 1; i >= 0; i--) { - if (checkFnSingle(data[i])) return data[i]; - } +uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $compile) { + return { + restrict: 'EA', + require: ['^uiSelect', '^ngModel'], + link: function (scope, element, attrs, ctrls) { + + var $select = ctrls[0]; + var ngModel = ctrls[1]; + + //From view --> model + ngModel.$parsers.unshift(function (inputValue) { + var locals = {}, + result; + locals[$select.parserResult.itemName] = inputValue; + result = $select.parserResult.modelMapper(scope, locals); + return result; + }); + + //From model --> view + ngModel.$formatters.unshift(function (inputValue) { + var data = $select.parserResult.source(scope, {$select: {search: ''}}), //Overwrite $search + locals = {}, + result; + if (data) { + var checkFnSingle = function (d) { + locals[$select.parserResult.itemName] = d; + result = $select.parserResult.modelMapper(scope, locals); + return result == inputValue; + }; + //If possible pass same object stored in $select.selected + if ($select.selected && checkFnSingle($select.selected)) { + return $select.selected; + } + for (var i = data.length - 1; i >= 0; i--) { + if (checkFnSingle(data[i])) { + return data[i]; + } + } + } + return inputValue; + }); + + //Update viewValue if model change + scope.$watch('$select.selected', function (newValue) { + if (ngModel.$viewValue !== newValue) { + ngModel.$setViewValue(newValue); + } + }); + + ngModel.$render = function () { + $select.selected = ngModel.$viewValue; + }; + + scope.$on('uis:select', function (event, item) { + $select.selected = item; + }); + + scope.$on('uis:close', function (event, skipFocusser) { + $timeout(function () { + $select.focusser.prop('disabled', false); + if (!skipFocusser) $select.focusser[0].focus(); + }, 0, false); + }); + + scope.$on('uis:activate', function () { + focusser.prop('disabled', true); //Will reactivate it on .close() + }); + + //Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954 + var focusser = angular.element(""); + $compile(focusser)(scope); + $select.focusser = focusser; + + //Input that will handle focus + $select.focusInput = focusser; + + element.parent().append(focusser); + focusser.bind("focus", function () { + scope.$evalAsync(function () { + $select.focus = true; + }); + }); + focusser.bind("blur", function () { + scope.$evalAsync(function () { + $select.focus = false; + }); + }); + focusser.bind("keydown", function (e) { + + if (e.which === KEY.BACKSPACE) { + e.preventDefault(); + e.stopPropagation(); + $select.select(undefined); + scope.$apply(); + return; + } + + if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) { + return; + } + + if (e.which == KEY.DOWN || e.which == KEY.UP || e.which == KEY.ENTER || e.which == KEY.SPACE) { + e.preventDefault(); + e.stopPropagation(); + $select.activate(); + } + + scope.$digest(); + }); + + focusser.bind("keyup input", function (e) { + + if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || + e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { + return; + } + + $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input + focusser.val(''); + scope.$digest(); + }); } - return inputValue; - }); - - //Update viewValue if model change - scope.$watch('$select.selected', function(newValue) { - if (ngModel.$viewValue !== newValue) { - ngModel.$setViewValue(newValue); - } - }); - - ngModel.$render = function() { - $select.selected = ngModel.$viewValue; - }; - - scope.$on('uis:select', function (event, item) { - $select.selected = item; - }); - - scope.$on('uis:close', function (event, skipFocusser) { - $timeout(function(){ - $select.focusser.prop('disabled', false); - if (!skipFocusser) $select.focusser[0].focus(); - },0,false); - }); - - scope.$on('uis:activate', function () { - focusser.prop('disabled', true); //Will reactivate it on .close() - }); - - //Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954 - var focusser = angular.element(""); - $compile(focusser)(scope); - $select.focusser = focusser; - - //Input that will handle focus - $select.focusInput = focusser; - - element.parent().append(focusser); - focusser.bind("focus", function(){ - scope.$evalAsync(function(){ - $select.focus = true; - }); - }); - focusser.bind("blur", function(){ - scope.$evalAsync(function(){ - $select.focus = false; - }); - }); - focusser.bind("keydown", function(e){ - - if (e.which === KEY.BACKSPACE) { - e.preventDefault(); - e.stopPropagation(); - $select.select(undefined); - scope.$apply(); - return; - } - - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) { - return; - } - - if (e.which == KEY.DOWN || e.which == KEY.UP || e.which == KEY.ENTER || e.which == KEY.SPACE){ - e.preventDefault(); - e.stopPropagation(); - $select.activate(); - } - - scope.$digest(); - }); - - focusser.bind("keyup input", function(e){ - - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { - return; - } - - $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input - focusser.val(''); - scope.$digest(); - - }); - - - } - }; + }; }]); \ No newline at end of file diff --git a/src/uisRepeatParserService.js b/src/uisRepeatParserService.js index 7ed9955f1..63b7fed0e 100644 --- a/src/uisRepeatParserService.js +++ b/src/uisRepeatParserService.js @@ -8,43 +8,44 @@ * https://github.com/angular-ui/ui-select/commit/5dd63ad#commitcomment-5504697 */ -uis.service('uisRepeatParser', ['uiSelectMinErr','$parse', function(uiSelectMinErr, $parse) { - var self = this; - - /** - * Example: - * expression = "address in addresses | filter: {street: $select.search} track by $index" - * itemName = "address", - * source = "addresses | filter: {street: $select.search}", - * trackByExp = "$index", - */ - self.parse = function(expression) { - - var match = expression.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/); - - if (!match) { - throw uiSelectMinErr('iexp', "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.", - expression); - } - - return { - itemName: match[2], // (lhs) Left-hand side, - source: $parse(match[3]), - trackByExp: match[4], - modelMapper: $parse(match[1] || match[2]) - }; +uis.service('uisRepeatParser', ['uiSelectMinErr', '$parse', function (uiSelectMinErr, $parse) { + var self = this; + + /** + * Example: + * expression = "address in addresses | filter: {street: $select.search} track by $index" + * itemName = "address", + * source = "addresses | filter: {street: $select.search}", + * trackByExp = "$index", + */ + self.parse = function (expression) { + + var match = expression.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/); + + if (!match) { + throw uiSelectMinErr('iexp', + "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.", + expression); + } + + return { + itemName: match[2], // (lhs) Left-hand side, + source: $parse(match[3]), + trackByExp: match[4], + modelMapper: $parse(match[1] || match[2]) + }; - }; + }; - self.getGroupNgRepeatExpression = function() { - return '$group in $select.groups'; - }; + self.getGroupNgRepeatExpression = function () { + return '$group in $select.groups'; + }; - self.getNgRepeatExpression = function(itemName, source, trackByExp, grouped) { - var expression = itemName + ' in ' + (grouped ? '$group.items' : source); - if (trackByExp) { - expression += ' track by ' + trackByExp; - } - return expression; - }; + self.getNgRepeatExpression = function (itemName, source, trackByExp, grouped) { + var expression = itemName + ' in ' + (grouped ? '$group.items' : source); + if (trackByExp) { + expression += ' track by ' + trackByExp; + } + return expression; + }; }]); From a717820a97a578edd28bf0aa3773b2ed846c2dbb Mon Sep 17 00:00:00 2001 From: Chris Jackson Date: Wed, 5 Aug 2015 20:39:30 +0100 Subject: [PATCH 21/28] Update callback handlers --- dist/select.bootstrap.js | 228 ++++++++++++++++++++----------- dist/select.bootstrap.min.js | 4 +- dist/select.css | 2 +- dist/select.js | 228 ++++++++++++++++++++----------- dist/select.min.css | 2 +- dist/select.min.js | 4 +- dist/select.no-tpl.js | 228 ++++++++++++++++++++----------- dist/select.no-tpl.min.js | 4 +- dist/select.select2.js | 228 ++++++++++++++++++++----------- dist/select.select2.min.js | 4 +- dist/select.selectize.js | 228 ++++++++++++++++++++----------- dist/select.selectize.min.js | 4 +- dist/select.tpl.js | 2 +- examples/newdemo.html | 23 +++- examples/newdemo.js | 82 +++++++++++ src/uiSelectChoicesDirective.js | 2 +- src/uiSelectController.js | 151 +++++++++++++------- src/uiSelectDirective.js | 29 ++-- src/uiSelectMultipleDirective.js | 23 ++-- src/uiSelectSingleDirective.js | 21 +-- 20 files changed, 996 insertions(+), 501 deletions(-) diff --git a/dist/select.bootstrap.js b/dist/select.bootstrap.js index 70e90f742..18aeaa587 100644 --- a/dist/select.bootstrap.js +++ b/dist/select.bootstrap.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-04T17:24:10.062Z + * Version: 0.12.1 - 2015-08-05T18:50:43.064Z * License: MIT */ @@ -318,7 +318,7 @@ uis.directive('uiSelectChoices', choices.attr('ng-repeat', RepeatParser.getNgRepeatExpression($select.parserResult.itemName, '$select.items', $select.parserResult.trackByExp, groupByExp)) - .attr('ng-if', '$select.open') //Prevent unnecessary watches when dropdown is closed + .attr('ng-if', '$select.open') // Prevent unnecessary watches when dropdown is closed .attr('ng-mouseenter', '$select.setActiveItem(' + $select.parserResult.itemName + ')') .attr('ng-click', '$select.select(' + $select.parserResult.itemName + ',false,$event)'); @@ -360,19 +360,19 @@ uis.controller('uiSelectCtrl', ctrl.searchEnabled = uiSelectConfig.searchEnabled; ctrl.sortable = uiSelectConfig.sortable; - ctrl.removeSelected = false; //If selected item(s) should be removed from dropdown list - ctrl.closeOnSelect = true; //Initialized inside uiSelect directive link function + ctrl.removeSelected = false; // If selected item(s) should be removed from dropdown list + ctrl.closeOnSelect = true; // Initialized inside uiSelect directive link function ctrl.search = EMPTY_SEARCH; - ctrl.activeIndex = 0; //Dropdown of choices - ctrl.items = []; //All available choices + ctrl.activeIndex = 0; // Dropdown of choices + ctrl.items = []; // All available choices ctrl.open = false; ctrl.focus = false; ctrl.disabled = false; ctrl.selected = undefined; - ctrl.focusser = undefined; //Reference to input element used to handle focus events + ctrl.focusser = undefined; // Reference to input element used to handle focus events ctrl.resetSearchInput = true; ctrl.multiple = undefined; // Initialized inside uiSelect directive link function ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelectChoices directive link function @@ -398,7 +398,7 @@ uis.controller('uiSelectCtrl', function _resetSearchInput() { if (ctrl.resetSearchInput || (ctrl.resetSearchInput === undefined && uiSelectConfig.resetSearchInput)) { ctrl.search = EMPTY_SEARCH; - //reset activeIndex + // Reset activeIndex if (ctrl.selected && ctrl.items.length && !ctrl.multiple) { ctrl.activeIndex = ctrl.items.indexOf(ctrl.selected); } @@ -429,24 +429,45 @@ uis.controller('uiSelectCtrl', */ ctrl.activate = function (initSearchValue, avoidReset) { if (!ctrl.disabled && !ctrl.open) { - if (!avoidReset) { - _resetSearchInput(); - } + var completeCallback = function () { + if (!avoidReset) { + _resetSearchInput(); + } - $scope.$broadcast('uis:activate'); + $scope.$broadcast('uis:activate'); - ctrl.open = true; - if (!ctrl.searchEnabled) { - angular.element(ctrl.searchInput[0]).addClass('ui-select-offscreen'); - } + ctrl.open = true; + if (!ctrl.searchEnabled) { + angular.element(ctrl.searchInput[0]).addClass('ui-select-offscreen'); + } - ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex; + ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex; - // Give it time to appear before focus - $timeout(function () { - ctrl.search = initSearchValue || ctrl.search; - ctrl.searchInput[0].focus(); - }); + // Give it time to appear before focus + $timeout(function () { + ctrl.search = initSearchValue || ctrl.search; + ctrl.searchInput[0].focus(); + }); + }; + + var result = ctrl.onDropdownCallback($scope, {open: true}); + if (angular.isDefined(result)) { + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (result) { + if (!result) { + return; + } + completeCallback(); + }); + } else if (result === true) { + completeCallback(); + } else if (result) { + completeCallback(); + } + } else { + completeCallback(); + } } else if (ctrl.open && !ctrl.searchEnabled) { // Close the selection if we don't have search enabled, and we click on the select again @@ -522,10 +543,11 @@ uis.controller('uiSelectCtrl', if (!angular.isArray(items)) { throw uiSelectMinErr('items', "Expected an array but got '{0}'.", items); } else { - //Remove already selected items (ex: while searching) - //TODO Should add a test + // Remove already selected items (ex: while searching) + // TODO Should add a test ctrl.refreshItems(items); - ctrl.ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters + // Force scope model value and ngModel value to be out of sync to re-run formatters + ctrl.ngModel.$modelValue = null; } } }); @@ -544,9 +566,15 @@ uis.controller('uiSelectCtrl', if (!ctrl.open) { return false; } + // Get the index of this item - returns -1 if the item isn't in the current list var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); - var isActive = itemIndex === ctrl.activeIndex; + // Is this the active index? + // If the itemIndex is -1, then the item wasn't in the list so let's ensure we're not active + // otherwise we can end up with all items being selected as active! + var isActive = itemIndex === -1 ? false : itemIndex === ctrl.activeIndex; + + // If this is active, and we've defined a callback, do it! if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { itemScope.$eval(ctrl.onHighlightCallback); } @@ -604,7 +632,8 @@ uis.controller('uiSelectCtrl', // Local method called when we complete the select // eg. called after the onselect callback - var completeSelection = function () { + var completeCallback = function (item) { + callbackContext.$item = item; $scope.$broadcast('uis:select', item); $timeout(function () { @@ -625,23 +654,23 @@ uis.controller('uiSelectCtrl', // promise: Wait for response // true: Complete selection // object: Add the returned object - var onBeforeSelectResult = ctrl.onBeforeSelectCallback($scope, callbackContext); - if (angular.isDefined(onBeforeSelectResult)) { - if (angular.isFunction(onBeforeSelectResult.then)) { + var result = ctrl.onBeforeSelectCallback($scope, callbackContext); + if (angular.isDefined(result)) { + if (angular.isFunction(result.then)) { // Promise returned - wait for it to complete before completing the selection - onBeforeSelectResult.then(function (result) { + result.then(function (result) { if (!result) { return; } - completeSelection(result); + completeCallback(result); }); - } else if (onBeforeSelectResult === true) { - completeSelection(item); - } else if (onBeforeSelectResult) { - completeSelection(onBeforeSelectResult); + } else if (result === true) { + completeCallback(item); + } else if (result) { + completeCallback(result); } } else { - completeSelection(item); + completeCallback(item); } }; @@ -652,16 +681,38 @@ uis.controller('uiSelectCtrl', if (!ctrl.open) { return; } - if (ctrl.ngModel && ctrl.ngModel.$setTouched) { - ctrl.ngModel.$setTouched(); - } - _resetSearchInput(); - ctrl.open = false; - if (!ctrl.searchEnabled) { - angular.element(ctrl.searchInput[0]).removeClass('ui-select-offscreen'); + + function completeCallback() { + if (ctrl.ngModel && ctrl.ngModel.$setTouched) { + ctrl.ngModel.$setTouched(); + } + _resetSearchInput(); + ctrl.open = false; + if (!ctrl.searchEnabled) { + angular.element(ctrl.searchInput[0]).removeClass('ui-select-offscreen'); + } + + $scope.$broadcast('uis:close', skipFocusser); } - $scope.$broadcast('uis:close', skipFocusser); + var result = ctrl.onDropdownCallback($scope, {open: false}); + if (angular.isDefined(result)) { + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (result) { + if (!result) { + return; + } + completeCallback(); + }); + } else if (result === true) { + completeCallback(); + } else if (result) { + completeCallback(); + } + } else { + completeCallback(); + } }; /** @@ -702,8 +753,10 @@ uis.controller('uiSelectCtrl', var isLocked, item = ctrl.selected[itemIndex]; if (item && !angular.isUndefined(ctrl.lockChoiceExpression)) { - isLocked = !!(itemScope.$eval(ctrl.lockChoiceExpression)); // force the boolean value - item._uiSelectChoiceLocked = isLocked; // store this for later reference + // Force the boolean value + isLocked = !!(itemScope.$eval(ctrl.lockChoiceExpression)); + // Store this for later reference + item._uiSelectChoiceLocked = isLocked; } return isLocked; @@ -731,7 +784,8 @@ uis.controller('uiSelectCtrl', }; ctrl.searchInput.css('width', '10px'); - $timeout(function () { //Give time to render correctly + $timeout(function () { + // Give time to render correctly if (sizeWatch === null && !updateIfVisible(calculateContainerWidth())) { sizeWatch = $scope.$watch(calculateContainerWidth, function (containerWidth) { if (updateIfVisible(containerWidth)) { @@ -748,7 +802,8 @@ uis.controller('uiSelectCtrl', switch (key) { case KEY.DOWN: if (!ctrl.open && ctrl.multiple) { - ctrl.activate(false, true); //In case its the search input in 'multiple' mode + // In case its the search input in 'multiple' mode + ctrl.activate(false, true); } else if (ctrl.activeIndex < ctrl.items.length - 1) { ctrl.activeIndex++; @@ -843,7 +898,7 @@ uis.controller('uiSelectCtrl', container[0].scrollTop += posY - height; } else if (posY < highlighted.clientHeight) { if (ctrl.isGrouped && ctrl.activeIndex === 0) { - //To make group header visible when going all the way up + // To make group header visible when going all the way up container[0].scrollTop = 0; } else { @@ -877,14 +932,15 @@ uis.directive('uiSelect', controllerAs: '$select', compile: function (tElement, tAttrs) { - //Multiple or Single depending if multiple attribute presence - if (angular.isDefined(tAttrs.multiple)) + // Multiple or Single depending if multiple attribute presence + if (angular.isDefined(tAttrs.multiple)) { tElement.append("").removeAttr('multiple'); - else + } + else { tElement.append(""); + } return function (scope, element, attrs, ctrls, transcludeFn) { - var $select = ctrls[0]; var ngModel = ctrls[1]; @@ -906,11 +962,12 @@ uis.directive('uiSelect', $select.onRemoveCallback = $parse(attrs.onRemove); $select.onBeforeRemoveCallback = $parse(attrs.onBeforeRemove); $select.onKeypressCallback = $parse(attrs.onKeypress); + $select.onDropdownCallback = $parse(attrs.onDropdown); - //Limit the number of selections allowed + // Limit the number of selections allowed $select.limit = (angular.isDefined(attrs.limit)) ? parseInt(attrs.limit, 10) : undefined; - //Set reference to ngModel from uiSelectCtrl + // Set reference to ngModel from uiSelectCtrl $select.ngModel = ngModel; $select.choiceGrouped = function (group) { @@ -944,7 +1001,7 @@ uis.directive('uiSelect', }); } - //Gets focus based on scope event name (e.g. focus-on='SomeEventName') + // Gets focus based on scope event name (e.g. focus-on='SomeEventName') if (angular.isDefined(attrs.focusOn)) { scope.$on(attrs.focusOn, function () { $timeout(function () { @@ -954,7 +1011,10 @@ uis.directive('uiSelect', } function onDocumentClick(e) { - if (!$select.open) return; //Skip it if dropdown is close + //Skip it if dropdown is close + if (!$select.open) { + return; + } var contains = false; @@ -967,14 +1027,14 @@ uis.directive('uiSelect', } if (!contains && !$select.clickTriggeredSelect) { - //Will lose focus only with certain targets + // Will lose focus only with certain targets var focusableControls = ['input', 'button', 'textarea']; - //To check if target is other ui-select + // To check if target is other ui-select var targetScope = angular.element(e.target).scope(); - //To check if target is other ui-select + // To check if target is other ui-select var skipFocusser = targetScope && targetScope.$select && targetScope.$select !== $select; - //Check if target is input, button or textarea + // Check if target is input, button or textarea if (!skipFocusser) { skipFocusser = ~focusableControls.indexOf(e.target.tagName.toLowerCase()); } @@ -1203,13 +1263,18 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel ctrl.activeMatchIndex = -1; $select.sizeSearchInput(); + // If there's no onBeforeRemove callback, then we're done + if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { + return; + } + var callbackContext = { $item: removedChoice, $model: $select.parserResult.modelMapper($scope, locals) }; // Give some time for scope propagation. - function completeRemoval() { + function completeCallback() { $timeout(function () { $select.onRemoveCallback($scope, callbackContext); }); @@ -1222,21 +1287,21 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel // falsy: Abort the removal // promise: Wait for response // true: Complete removal - var onBeforeRemoveResult = ctrl.onBeforeRemoveCallback($scope, callbackContext); - if (angular.isDefined(onBeforeRemoveResult)) { - if (angular.isFunction(onBeforeRemoveResult.then)) { + var result = ctrl.onBeforeRemoveCallback($scope, callbackContext); + if (angular.isDefined(result)) { + if (angular.isFunction(result.then)) { // Promise returned - wait for it to complete before completing the selection - onBeforeRemoveResult.then(function (result) { + result.then(function (result) { if (!result) { return; } - completeRemoval(result); + completeCallback(result); }); - } else if (onBeforeRemoveResult === true) { - completeRemoval(); + } else if (result === true) { + completeCallback(); } } else { - completeRemoval(); + completeCallback(); } }; @@ -1484,7 +1549,7 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co var $select = ctrls[0]; var ngModel = ctrls[1]; - //From view --> model + // From view --> model ngModel.$parsers.unshift(function (inputValue) { var locals = {}, result; @@ -1493,7 +1558,7 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co return result; }); - //From model --> view + // From model --> view ngModel.$formatters.unshift(function (inputValue) { var data = $select.parserResult.source(scope, {$select: {search: ''}}), //Overwrite $search locals = {}, @@ -1504,7 +1569,7 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co result = $select.parserResult.modelMapper(scope, locals); return result == inputValue; }; - //If possible pass same object stored in $select.selected + // If possible pass same object stored in $select.selected if ($select.selected && checkFnSingle($select.selected)) { return $select.selected; } @@ -1517,7 +1582,7 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co return inputValue; }); - //Update viewValue if model change + // Update viewValue if model change scope.$watch('$select.selected', function (newValue) { if (ngModel.$viewValue !== newValue) { ngModel.$setViewValue(newValue); @@ -1540,15 +1605,16 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co }); scope.$on('uis:activate', function () { - focusser.prop('disabled', true); //Will reactivate it on .close() + // Will reactivate it on .close() + focusser.prop('disabled', true); }); - //Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954 + // Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954 var focusser = angular.element(""); $compile(focusser)(scope); $select.focusser = focusser; - //Input that will handle focus + // Input that will handle focus $select.focusInput = focusser; element.parent().append(focusser); @@ -1562,8 +1628,8 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co $select.focus = false; }); }); - focusser.bind("keydown", function (e) { + focusser.bind("keydown", function (e) { if (e.which === KEY.BACKSPACE) { e.preventDefault(); e.stopPropagation(); @@ -1586,13 +1652,13 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co }); focusser.bind("keyup input", function (e) { - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { return; } - $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input + // User pressed some regular key, so we pass it to the search input + $select.activate(focusser.val()); focusser.val(''); scope.$digest(); }); diff --git a/dist/select.bootstrap.min.js b/dist/select.bootstrap.min.js index e242f43cc..cddcf21d5 100644 --- a/dist/select.bootstrap.min.js +++ b/dist/select.bootstrap.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-04T17:24:10.062Z + * Version: 0.12.1 - 2015-08-05T18:50:43.064Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var n=t.which;switch(n){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,n=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,c,i){i(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var c=n[0].getBoundingClientRect();return{width:c.width||n.prop("offsetWidth"),height:c.height||n.prop("offsetHeight"),top:c.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:c.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);n.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,c){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,i){if(!i.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,i,l,s,r){var a=l.groupBy,o=l.groupFilter;if(s.parseRepeatAttr(l.repeat,a,o),s.disableChoiceExpression=l.uiDisableChoice,s.onHighlightCallback=l.onHighlight,a){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=i.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(s.parserResult.itemName,"$select.items",s.parserResult.trackByExp,a)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+s.parserResult.itemName+")").attr("ng-click","$select.select("+s.parserResult.itemName+",false,$event)");var d=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),c(i,r)(e),e.$watch("$select.search",function(e){e&&!s.open&&s.multiple&&s.activate(!1,!0),s.activeIndex=0})}}}}]),n.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,n,c,i,l,s,r,a){function o(){(h.resetSearchInput||void 0===h.resetSearchInput&&a.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var n,c,i=[];for(n=0;n0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:n=!1}return n}function d(){var e=n.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw r("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var c=t[h.activeIndex],i=c.offsetTop+c.clientHeight-e[0].scrollTop,l=e[0].offsetHeight;i>l?e[0].scrollTop+=i-l:i=h.items.length?0:h.activeIndex,c(function(){h.search=e||h.search,h.searchInput[0].focus()}))},h.parseRepeatAttr=function(e,n,c){function i(e){var i=t.$eval(n);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(i)?i(e):e[i],n=h.findGroupByName(t);n?n.items.push(e):h.groups.push({name:t,items:[e]})}),c){var l=t.$eval(c);angular.isFunction(l)?h.groups=l(h.groups):angular.isArray(l)&&(h.groups=u(h.groups,l))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function l(e){h.items=e}h.setItemsFn=n?i:l,h.parserResult=s.parse(e),h.isGrouped=!!n,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var n=h.selected;if(h.isEmpty()||angular.isArray(n)&&!n.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var c=e.filter(function(e){return n.indexOf(e)<0});h.setItemsFn(c)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw r("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),n=t===h.activeIndex;return n&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),n},h.isDisabled=function(e){if(!h.open)return!1;var t,n=h.items.indexOf(e[h.itemProperty]),c=!1;return n>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[n],c=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=c),c},h.select=function(e,n,i){if((void 0===e||!e._uiSelectChoiceDisabled)&&(h.items||h.search)){var l={};l[h.parserResult.itemName]=e;var s={$item:e,$model:h.parserResult.modelMapper(t,l)},r=function(){t.$broadcast("uis:select",e),c(function(){h.onSelectCallback(t,s)}),h.closeOnSelect&&h.close(n),i&&"click"===i.type&&(h.clickTriggeredSelect=!0)},a=h.onBeforeSelectCallback(t,s);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(e){e&&r(e)}):a===!0?r(e):a&&r(a):r(e)}},h.close=function(e){h.open&&(h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),o(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e))},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),c(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var n,c=h.selected[t];return c&&!angular.isUndefined(h.lockChoiceExpression)&&(n=!!e.$eval(h.lockChoiceExpression),c._uiSelectChoiceLocked=n),n};var g=null;h.sizeSearchInput=function(){var e=h.searchInput[0],n=h.searchInput.parent().parent()[0],i=function(){return n.clientWidth*!!e.offsetParent},l=function(t){if(0===t)return!1;var n=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=t),h.searchInput.css("width",n+"px"),!0};h.searchInput.css("width","10px"),c(function(){null!==g||l(i())||(g=t.$watch(i,function(e){l(e)&&(g(),g=null)}))})},h.searchInput.on("keydown",function(n){var c=n.which;t.$apply(function(){p(c)}),e.isVerticalMovement(c)&&h.items.length>0&&d(),(c===e.ENTER||c===e.ESC)&&(n.preventDefault(),n.stopPropagation())}),h.searchInput.on("keyup",function(n){n.which===e.TAB||e.isControl(n)||e.isFunctionKey(n)||n.which===e.ESC||e.isVerticalMovement(n.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:n})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),n.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,c,i,l,s){return{restrict:"EA",templateUrl:function(e,n){var c=n.theme||t.theme;return c+(angular.isDefined(n.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(i,r){return angular.isDefined(r.multiple)?i.append("").removeAttr("multiple"):i.append(""),function(i,r,a,o,u){function p(e){if(f.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(r[0],e.target):r[0].contains(e.target),!t&&!f.clickTriggeredSelect){var n=["input","button","textarea"],c=angular.element(e.target).scope(),l=c&&c.$select&&c.$select!==f;l||(l=~n.indexOf(e.target.tagName.toLowerCase())),f.close(l),i.$digest()}f.clickTriggeredSelect=!1}}function d(){var t=c(r);b=angular.element('
    '),b[0].style.width=t.width+"px",b[0].style.height=t.height+"px",r.after(b),E=r[0].style.width,e.find("body").append(r),r[0].style.position="absolute",r[0].style.left=t.left+"px",r[0].style.top=t.top+"px",r[0].style.width=t.width+"px"}function h(){null!==b&&(b.replaceWith(r),b=null,r[0].style.position="",r[0].style.left="",r[0].style.top="",r[0].style.width=E)}var f=o[0],g=o[1];f.generatedId=t.generateId(),f.baseTitle=a.title||"Select box",f.focusserTitle=f.baseTitle+" focus",f.focusserId="focusser-"+f.generatedId,f.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?l(a.closeOnSelect)():t.closeOnSelect}(),f.onSelectCallback=l(a.onSelect),f.onBeforeSelectCallback=l(a.onBeforeSelect),f.onRemoveCallback=l(a.onRemove),f.onBeforeRemoveCallback=l(a.onBeforeRemove),f.onKeypressCallback=l(a.onKeypress),f.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,f.ngModel=g,f.choiceGrouped=function(e){return f.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){f.focusInput.attr("tabindex",e),r.removeAttr("tabindex")});var m=i.$eval(a.searchEnabled);f.searchEnabled=void 0!==m?m:t.searchEnabled;var v=i.$eval(a.sortable);f.sortable=void 0!==v?v:t.sortable,a.$observe("disabled",function(){f.disabled=void 0!==a.disabled?a.disabled:!1}),angular.isDefined(a.autofocus)&&s(function(){f.setFocus()}),angular.isDefined(a.focusOn)&&i.$on(a.focusOn,function(){s(function(){f.setFocus()})}),e.on("click",p),i.$on("$destroy",function(){e.off("click",p)}),u(i,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),c.removeAttr("data-ui-select-match"),1!==c.length)throw n("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);r.querySelectorAll(".ui-select-match").replaceWith(c);var i=t.querySelectorAll(".ui-select-choices");if(i.removeAttr("ui-select-choices"),i.removeAttr("data-ui-select-choices"),1!==i.length)throw n("transcluded","Expected 1 .ui-select-choices but got '{0}'.",i.length);r.querySelectorAll(".ui-select-choices").replaceWith(i)});var $=i.$eval(a.appendToBody);(void 0!==$?$:t.appendToBody)&&(i.$watch("$select.open",function(e){e?d():h()}),i.$on("$destroy",function(){h()}));var b=null,E="",w=null,x="direction-up";i.$watch("$select.open",function(t){if(t){if(w=angular.element(r).querySelectorAll(".ui-select-dropdown"),null===w)return;w[0].style.opacity=0,s(function(){var t=c(r),n=c(w);t.top+t.height+n.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&r.addClass(x),w[0].style.opacity=1})}else{if(null===w)return;r.removeClass(x)}})}}}}]),n.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,c=t.parent().attr("multiple");return n+(c?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,c,i){function l(e){i.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}i.lockChoiceExpression=c.uiLockChoice,c.$observe("placeholder",function(t){i.placeholder=void 0!==t?t:e.placeholder}),c.$observe("allowClear",l),l(c.allowClear),i.multiple&&i.sizeSearchInput()}}}]),n.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,c=this,i=e.$select;e.$evalAsync(function(){n=e.ngModel}),c.activeMatchIndex=-1,c.updateModel=function(){n.$setViewValue(Date.now()),c.refreshComponent()},c.refreshComponent=function(){i.refreshItems(),i.sizeSearchInput()},c.removeChoice=function(n){function l(){t(function(){i.onRemoveCallback(e,a)}),c.updateModel()}var s=i.selected[n];if(!s._uiSelectChoiceLocked){var r={};r[i.parserResult.itemName]=s,i.selected.splice(n,1),c.activeMatchIndex=-1,i.sizeSearchInput();var a={$item:s,$model:i.parserResult.modelMapper(e,r)},o=c.onBeforeRemoveCallback(e,a);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(e){e&&l(e)}):o===!0&&l():l()}},c.getPlaceholder=function(){return i.selected&&i.selected.length?void 0:i.placeholder}}],controllerAs:"$selectMultiple",link:function(c,i,l,s){function r(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(t){function n(){switch(t){case e.LEFT:return~p.activeMatchIndex?d:s;case e.RIGHT:return~p.activeMatchIndex&&a!==s?u:(o.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(a),d):s;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),a):!1}}var c=r(o.searchInput[0]),i=o.selected.length,l=0,s=i-1,a=p.activeMatchIndex,u=p.activeMatchIndex+1,d=p.activeMatchIndex-1,h=a;return c>0||o.search.length&&t==e.RIGHT?!1:(o.close(),h=n(),p.activeMatchIndex=o.selected.length&&h!==!1?Math.min(s,Math.max(l,h)):-1,!0)}var o=s[0],u=c.ngModel=s[1],p=c.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,u.$parsers.unshift(function(){for(var e,t={},n=[],i=o.selected.length-1;i>=0;i--)t={},t[o.parserResult.itemName]=o.selected[i],e=o.parserResult.modelMapper(c,t),n.unshift(e);return n}),u.$formatters.unshift(function(e){var t,n=o.parserResult.source(c,{$select:{search:""}}),i={};if(!n)return e;var l=[],s=function(e,n){if(e&&e.length){for(var s=e.length-1;s>=0;s--){if(i[o.parserResult.itemName]=e[s],t=o.parserResult.modelMapper(c,i),o.parserResult.trackByExp){var r=/\.(.+)/.exec(o.parserResult.trackByExp);if(r.length>0&&t[r[1]]==n[r[1]])return l.unshift(e[s]),!0}if(angular.equals(t,n))return l.unshift(e[s]),!0}return!1}};if(!e)return l;for(var r=e.length-1;r>=0;r--)s(o.selected,e[r])||s(n,e[r])||l.unshift(e[r]);return l}),c.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);o.selected=[]}o.selected=u.$viewValue,c.$evalAsync()},c.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),p.updateModel())}),c.$on("uis:activate",function(){p.activeMatchIndex=-1}),c.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(t){var n=t.which;c.$apply(function(){var t=!1;e.isHorizontalMovement(n)&&(t=a(n)),t&&n!=e.TAB})}),o.searchInput.on("blur",function(){n(function(){p.activeMatchIndex=-1})})}}}]),n.directive("uiSelectSingle",["$timeout","$compile",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(c,i,l,s){var r=s[0],a=s[1];a.$parsers.unshift(function(e){var t,n={};return n[r.parserResult.itemName]=e,t=r.parserResult.modelMapper(c,n)}),a.$formatters.unshift(function(e){var t,n=r.parserResult.source(c,{$select:{search:""}}),i={};if(n){var l=function(n){return i[r.parserResult.itemName]=n,t=r.parserResult.modelMapper(c,i),t==e};if(r.selected&&l(r.selected))return r.selected;for(var s=n.length-1;s>=0;s--)if(l(n[s]))return n[s]}return e}),c.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){r.selected=a.$viewValue},c.$on("uis:select",function(e,t){r.selected=t}),c.$on("uis:close",function(e,n){t(function(){r.focusser.prop("disabled",!1),n||r.focusser[0].focus()},0,!1)}),c.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");n(o)(c),r.focusser=o,r.focusInput=o,i.parent().append(o),o.bind("focus",function(){c.$evalAsync(function(){r.focus=!0})}),o.bind("blur",function(){c.$evalAsync(function(){r.focus=!1})}),o.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),r.select(void 0),c.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),r.activate()),c.$digest()),void 0)}),o.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(r.activate(o.val()),o.val(""),c.$digest())})}}}]),n.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var c=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!c)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:c[2],source:t(c[3]),trackByExp:c[4],modelMapper:t(c[1]||c[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,c){var i=e+" in "+(c?"$group.items":t);return n&&(i+=" track by "+n),i}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",'
    {{$select.placeholder}}
    '),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",'')}]); \ No newline at end of file +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var n=t.which;switch(n){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,n=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,i,c){c(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var i=n[0].getBoundingClientRect();return{width:i.width||n.prop("offsetWidth"),height:i.height||n.prop("offsetHeight"),top:i.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:i.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);n.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,c){if(!c.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,c,l,s,r){var a=l.groupBy,o=l.groupFilter;if(s.parseRepeatAttr(l.repeat,a,o),s.disableChoiceExpression=l.uiDisableChoice,s.onHighlightCallback=l.onHighlight,a){var u=c.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=c.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(s.parserResult.itemName,"$select.items",s.parserResult.trackByExp,a)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+s.parserResult.itemName+")").attr("ng-click","$select.select("+s.parserResult.itemName+",false,$event)");var d=c.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),i(c,r)(e),e.$watch("$select.search",function(e){e&&!s.open&&s.multiple&&s.activate(!1,!0),s.activeIndex=0})}}}}]),n.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,n,i,c,l,s,r,a){function o(){(h.resetSearchInput||void 0===h.resetSearchInput&&a.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var n,i,c=[];for(n=0;n0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:n=!1}return n}function d(){var e=n.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw r("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var i=t[h.activeIndex],c=i.offsetTop+i.clientHeight-e[0].scrollTop,l=e[0].offsetHeight;c>l?e[0].scrollTop+=c-l:c=h.items.length?0:h.activeIndex,i(function(){h.search=e||h.search,h.searchInput[0].focus()})},l=h.onDropdownCallback(t,{open:!0});angular.isDefined(l)?angular.isFunction(l.then)?l.then(function(e){e&&c()}):l===!0?c():l&&c():c()}},h.parseRepeatAttr=function(e,n,i){function c(e){var c=t.$eval(n);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(c)?c(e):e[c],n=h.findGroupByName(t);n?n.items.push(e):h.groups.push({name:t,items:[e]})}),i){var l=t.$eval(i);angular.isFunction(l)?h.groups=l(h.groups):angular.isArray(l)&&(h.groups=u(h.groups,l))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function l(e){h.items=e}h.setItemsFn=n?c:l,h.parserResult=s.parse(e),h.isGrouped=!!n,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var n=h.selected;if(h.isEmpty()||angular.isArray(n)&&!n.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var i=e.filter(function(e){return n.indexOf(e)<0});h.setItemsFn(i)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw r("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),n=-1===t?!1:t===h.activeIndex;return n&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),n},h.isDisabled=function(e){if(!h.open)return!1;var t,n=h.items.indexOf(e[h.itemProperty]),i=!1;return n>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[n],i=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i},h.select=function(e,n,c){if((void 0===e||!e._uiSelectChoiceDisabled)&&(h.items||h.search)){var l={};l[h.parserResult.itemName]=e;var s={$item:e,$model:h.parserResult.modelMapper(t,l)},r=function(e){s.$item=e,t.$broadcast("uis:select",e),i(function(){h.onSelectCallback(t,s)}),h.closeOnSelect&&h.close(n),c&&"click"===c.type&&(h.clickTriggeredSelect=!0)},a=h.onBeforeSelectCallback(t,s);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(e){e&&r(e)}):a===!0?r(e):a&&r(a):r(e)}},h.close=function(e){function n(){h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),o(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e)}if(h.open){var i=h.onDropdownCallback(t,{open:!1});angular.isDefined(i)?angular.isFunction(i.then)?i.then(function(e){e&&n()}):i===!0?n():i&&n():n()}},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),i(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var n,i=h.selected[t];return i&&!angular.isUndefined(h.lockChoiceExpression)&&(n=!!e.$eval(h.lockChoiceExpression),i._uiSelectChoiceLocked=n),n};var g=null;h.sizeSearchInput=function(){var e=h.searchInput[0],n=h.searchInput.parent().parent()[0],c=function(){return n.clientWidth*!!e.offsetParent},l=function(t){if(0===t)return!1;var n=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=t),h.searchInput.css("width",n+"px"),!0};h.searchInput.css("width","10px"),i(function(){null!==g||l(c())||(g=t.$watch(c,function(e){l(e)&&(g(),g=null)}))})},h.searchInput.on("keydown",function(n){var i=n.which;t.$apply(function(){p(i)}),e.isVerticalMovement(i)&&h.items.length>0&&d(),(i===e.ENTER||i===e.ESC)&&(n.preventDefault(),n.stopPropagation())}),h.searchInput.on("keyup",function(n){n.which===e.TAB||e.isControl(n)||e.isFunctionKey(n)||n.which===e.ESC||e.isVerticalMovement(n.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:n})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),n.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,i,c,l,s){return{restrict:"EA",templateUrl:function(e,n){var i=n.theme||t.theme;return i+(angular.isDefined(n.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(c,r){return angular.isDefined(r.multiple)?c.append("").removeAttr("multiple"):c.append(""),function(c,r,a,o,u){function p(e){if(f.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(r[0],e.target):r[0].contains(e.target),!t&&!f.clickTriggeredSelect){var n=["input","button","textarea"],i=angular.element(e.target).scope(),l=i&&i.$select&&i.$select!==f;l||(l=~n.indexOf(e.target.tagName.toLowerCase())),f.close(l),c.$digest()}f.clickTriggeredSelect=!1}}function d(){var t=i(r);b=angular.element('
    '),b[0].style.width=t.width+"px",b[0].style.height=t.height+"px",r.after(b),E=r[0].style.width,e.find("body").append(r),r[0].style.position="absolute",r[0].style.left=t.left+"px",r[0].style.top=t.top+"px",r[0].style.width=t.width+"px"}function h(){null!==b&&(b.replaceWith(r),b=null,r[0].style.position="",r[0].style.left="",r[0].style.top="",r[0].style.width=E)}var f=o[0],g=o[1];f.generatedId=t.generateId(),f.baseTitle=a.title||"Select box",f.focusserTitle=f.baseTitle+" focus",f.focusserId="focusser-"+f.generatedId,f.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?l(a.closeOnSelect)():t.closeOnSelect}(),f.onSelectCallback=l(a.onSelect),f.onBeforeSelectCallback=l(a.onBeforeSelect),f.onRemoveCallback=l(a.onRemove),f.onBeforeRemoveCallback=l(a.onBeforeRemove),f.onKeypressCallback=l(a.onKeypress),f.onDropdownCallback=l(a.onDropdown),f.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,f.ngModel=g,f.choiceGrouped=function(e){return f.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){f.focusInput.attr("tabindex",e),r.removeAttr("tabindex")});var m=c.$eval(a.searchEnabled);f.searchEnabled=void 0!==m?m:t.searchEnabled;var v=c.$eval(a.sortable);f.sortable=void 0!==v?v:t.sortable,a.$observe("disabled",function(){f.disabled=void 0!==a.disabled?a.disabled:!1}),angular.isDefined(a.autofocus)&&s(function(){f.setFocus()}),angular.isDefined(a.focusOn)&&c.$on(a.focusOn,function(){s(function(){f.setFocus()})}),e.on("click",p),c.$on("$destroy",function(){e.off("click",p)}),u(c,function(e){var t=angular.element("
    ").append(e),i=t.querySelectorAll(".ui-select-match");if(i.removeAttr("ui-select-match"),i.removeAttr("data-ui-select-match"),1!==i.length)throw n("transcluded","Expected 1 .ui-select-match but got '{0}'.",i.length);r.querySelectorAll(".ui-select-match").replaceWith(i);var c=t.querySelectorAll(".ui-select-choices");if(c.removeAttr("ui-select-choices"),c.removeAttr("data-ui-select-choices"),1!==c.length)throw n("transcluded","Expected 1 .ui-select-choices but got '{0}'.",c.length);r.querySelectorAll(".ui-select-choices").replaceWith(c)});var $=c.$eval(a.appendToBody);(void 0!==$?$:t.appendToBody)&&(c.$watch("$select.open",function(e){e?d():h()}),c.$on("$destroy",function(){h()}));var b=null,E="",w=null,x="direction-up";c.$watch("$select.open",function(t){if(t){if(w=angular.element(r).querySelectorAll(".ui-select-dropdown"),null===w)return;w[0].style.opacity=0,s(function(){var t=i(r),n=i(w);t.top+t.height+n.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&r.addClass(x),w[0].style.opacity=1})}else{if(null===w)return;r.removeClass(x)}})}}}}]),n.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return n+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,i,c){function l(e){c.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}c.lockChoiceExpression=i.uiLockChoice,i.$observe("placeholder",function(t){c.placeholder=void 0!==t?t:e.placeholder}),i.$observe("allowClear",l),l(i.allowClear),c.multiple&&c.sizeSearchInput()}}}]),n.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,i=this,c=e.$select;e.$evalAsync(function(){n=e.ngModel}),i.activeMatchIndex=-1,i.updateModel=function(){n.$setViewValue(Date.now()),i.refreshComponent()},i.refreshComponent=function(){c.refreshItems(),c.sizeSearchInput()},i.removeChoice=function(n){function l(){t(function(){c.onRemoveCallback(e,a)}),i.updateModel()}var s=c.selected[n];if(!s._uiSelectChoiceLocked){var r={};if(r[c.parserResult.itemName]=s,c.selected.splice(n,1),i.activeMatchIndex=-1,c.sizeSearchInput(),angular.isDefined(i.onBeforeRemoveCallback)){var a={$item:s,$model:c.parserResult.modelMapper(e,r)},o=i.onBeforeRemoveCallback(e,a);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(e){e&&l(e)}):o===!0&&l():l()}}},i.getPlaceholder=function(){return c.selected&&c.selected.length?void 0:c.placeholder}}],controllerAs:"$selectMultiple",link:function(i,c,l,s){function r(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(t){function n(){switch(t){case e.LEFT:return~p.activeMatchIndex?d:s;case e.RIGHT:return~p.activeMatchIndex&&a!==s?u:(o.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(a),d):s;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),a):!1}}var i=r(o.searchInput[0]),c=o.selected.length,l=0,s=c-1,a=p.activeMatchIndex,u=p.activeMatchIndex+1,d=p.activeMatchIndex-1,h=a;return i>0||o.search.length&&t==e.RIGHT?!1:(o.close(),h=n(),p.activeMatchIndex=o.selected.length&&h!==!1?Math.min(s,Math.max(l,h)):-1,!0)}var o=s[0],u=i.ngModel=s[1],p=i.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,u.$parsers.unshift(function(){for(var e,t={},n=[],c=o.selected.length-1;c>=0;c--)t={},t[o.parserResult.itemName]=o.selected[c],e=o.parserResult.modelMapper(i,t),n.unshift(e);return n}),u.$formatters.unshift(function(e){var t,n=o.parserResult.source(i,{$select:{search:""}}),c={};if(!n)return e;var l=[],s=function(e,n){if(e&&e.length){for(var s=e.length-1;s>=0;s--){if(c[o.parserResult.itemName]=e[s],t=o.parserResult.modelMapper(i,c),o.parserResult.trackByExp){var r=/\.(.+)/.exec(o.parserResult.trackByExp);if(r.length>0&&t[r[1]]==n[r[1]])return l.unshift(e[s]),!0}if(angular.equals(t,n))return l.unshift(e[s]),!0}return!1}};if(!e)return l;for(var r=e.length-1;r>=0;r--)s(o.selected,e[r])||s(n,e[r])||l.unshift(e[r]);return l}),i.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);o.selected=[]}o.selected=u.$viewValue,i.$evalAsync()},i.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),p.updateModel())}),i.$on("uis:activate",function(){p.activeMatchIndex=-1}),i.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(t){var n=t.which;i.$apply(function(){var t=!1;e.isHorizontalMovement(n)&&(t=a(n)),t&&n!=e.TAB})}),o.searchInput.on("blur",function(){n(function(){p.activeMatchIndex=-1})})}}}]),n.directive("uiSelectSingle",["$timeout","$compile",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(i,c,l,s){var r=s[0],a=s[1];a.$parsers.unshift(function(e){var t,n={};return n[r.parserResult.itemName]=e,t=r.parserResult.modelMapper(i,n)}),a.$formatters.unshift(function(e){var t,n=r.parserResult.source(i,{$select:{search:""}}),c={};if(n){var l=function(n){return c[r.parserResult.itemName]=n,t=r.parserResult.modelMapper(i,c),t==e};if(r.selected&&l(r.selected))return r.selected;for(var s=n.length-1;s>=0;s--)if(l(n[s]))return n[s]}return e}),i.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){r.selected=a.$viewValue},i.$on("uis:select",function(e,t){r.selected=t}),i.$on("uis:close",function(e,n){t(function(){r.focusser.prop("disabled",!1),n||r.focusser[0].focus()},0,!1)}),i.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");n(o)(i),r.focusser=o,r.focusInput=o,c.parent().append(o),o.bind("focus",function(){i.$evalAsync(function(){r.focus=!0})}),o.bind("blur",function(){i.$evalAsync(function(){r.focus=!1})}),o.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),r.select(void 0),i.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),r.activate()),i.$digest()),void 0)}),o.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(r.activate(o.val()),o.val(""),i.$digest())})}}}]),n.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var i=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!i)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:i[2],source:t(i[3]),trackByExp:i[4],modelMapper:t(i[1]||i[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,i){var c=e+" in "+(i?"$group.items":t);return n&&(c+=" track by "+n),c}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",'
    {{$select.placeholder}}
    '),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",'')}]); \ No newline at end of file diff --git a/dist/select.css b/dist/select.css index c70321c5f..bd1f370f2 100644 --- a/dist/select.css +++ b/dist/select.css @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-04T17:24:10.107Z + * Version: 0.12.1 - 2015-08-05T18:50:43.115Z * License: MIT */ diff --git a/dist/select.js b/dist/select.js index 50f4297a6..cebcb13f2 100644 --- a/dist/select.js +++ b/dist/select.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-04T17:24:10.105Z + * Version: 0.12.1 - 2015-08-05T18:50:43.112Z * License: MIT */ @@ -318,7 +318,7 @@ uis.directive('uiSelectChoices', choices.attr('ng-repeat', RepeatParser.getNgRepeatExpression($select.parserResult.itemName, '$select.items', $select.parserResult.trackByExp, groupByExp)) - .attr('ng-if', '$select.open') //Prevent unnecessary watches when dropdown is closed + .attr('ng-if', '$select.open') // Prevent unnecessary watches when dropdown is closed .attr('ng-mouseenter', '$select.setActiveItem(' + $select.parserResult.itemName + ')') .attr('ng-click', '$select.select(' + $select.parserResult.itemName + ',false,$event)'); @@ -360,19 +360,19 @@ uis.controller('uiSelectCtrl', ctrl.searchEnabled = uiSelectConfig.searchEnabled; ctrl.sortable = uiSelectConfig.sortable; - ctrl.removeSelected = false; //If selected item(s) should be removed from dropdown list - ctrl.closeOnSelect = true; //Initialized inside uiSelect directive link function + ctrl.removeSelected = false; // If selected item(s) should be removed from dropdown list + ctrl.closeOnSelect = true; // Initialized inside uiSelect directive link function ctrl.search = EMPTY_SEARCH; - ctrl.activeIndex = 0; //Dropdown of choices - ctrl.items = []; //All available choices + ctrl.activeIndex = 0; // Dropdown of choices + ctrl.items = []; // All available choices ctrl.open = false; ctrl.focus = false; ctrl.disabled = false; ctrl.selected = undefined; - ctrl.focusser = undefined; //Reference to input element used to handle focus events + ctrl.focusser = undefined; // Reference to input element used to handle focus events ctrl.resetSearchInput = true; ctrl.multiple = undefined; // Initialized inside uiSelect directive link function ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelectChoices directive link function @@ -398,7 +398,7 @@ uis.controller('uiSelectCtrl', function _resetSearchInput() { if (ctrl.resetSearchInput || (ctrl.resetSearchInput === undefined && uiSelectConfig.resetSearchInput)) { ctrl.search = EMPTY_SEARCH; - //reset activeIndex + // Reset activeIndex if (ctrl.selected && ctrl.items.length && !ctrl.multiple) { ctrl.activeIndex = ctrl.items.indexOf(ctrl.selected); } @@ -429,24 +429,45 @@ uis.controller('uiSelectCtrl', */ ctrl.activate = function (initSearchValue, avoidReset) { if (!ctrl.disabled && !ctrl.open) { - if (!avoidReset) { - _resetSearchInput(); - } + var completeCallback = function () { + if (!avoidReset) { + _resetSearchInput(); + } - $scope.$broadcast('uis:activate'); + $scope.$broadcast('uis:activate'); - ctrl.open = true; - if (!ctrl.searchEnabled) { - angular.element(ctrl.searchInput[0]).addClass('ui-select-offscreen'); - } + ctrl.open = true; + if (!ctrl.searchEnabled) { + angular.element(ctrl.searchInput[0]).addClass('ui-select-offscreen'); + } - ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex; + ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex; - // Give it time to appear before focus - $timeout(function () { - ctrl.search = initSearchValue || ctrl.search; - ctrl.searchInput[0].focus(); - }); + // Give it time to appear before focus + $timeout(function () { + ctrl.search = initSearchValue || ctrl.search; + ctrl.searchInput[0].focus(); + }); + }; + + var result = ctrl.onDropdownCallback($scope, {open: true}); + if (angular.isDefined(result)) { + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (result) { + if (!result) { + return; + } + completeCallback(); + }); + } else if (result === true) { + completeCallback(); + } else if (result) { + completeCallback(); + } + } else { + completeCallback(); + } } else if (ctrl.open && !ctrl.searchEnabled) { // Close the selection if we don't have search enabled, and we click on the select again @@ -522,10 +543,11 @@ uis.controller('uiSelectCtrl', if (!angular.isArray(items)) { throw uiSelectMinErr('items', "Expected an array but got '{0}'.", items); } else { - //Remove already selected items (ex: while searching) - //TODO Should add a test + // Remove already selected items (ex: while searching) + // TODO Should add a test ctrl.refreshItems(items); - ctrl.ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters + // Force scope model value and ngModel value to be out of sync to re-run formatters + ctrl.ngModel.$modelValue = null; } } }); @@ -544,9 +566,15 @@ uis.controller('uiSelectCtrl', if (!ctrl.open) { return false; } + // Get the index of this item - returns -1 if the item isn't in the current list var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); - var isActive = itemIndex === ctrl.activeIndex; + // Is this the active index? + // If the itemIndex is -1, then the item wasn't in the list so let's ensure we're not active + // otherwise we can end up with all items being selected as active! + var isActive = itemIndex === -1 ? false : itemIndex === ctrl.activeIndex; + + // If this is active, and we've defined a callback, do it! if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { itemScope.$eval(ctrl.onHighlightCallback); } @@ -604,7 +632,8 @@ uis.controller('uiSelectCtrl', // Local method called when we complete the select // eg. called after the onselect callback - var completeSelection = function () { + var completeCallback = function (item) { + callbackContext.$item = item; $scope.$broadcast('uis:select', item); $timeout(function () { @@ -625,23 +654,23 @@ uis.controller('uiSelectCtrl', // promise: Wait for response // true: Complete selection // object: Add the returned object - var onBeforeSelectResult = ctrl.onBeforeSelectCallback($scope, callbackContext); - if (angular.isDefined(onBeforeSelectResult)) { - if (angular.isFunction(onBeforeSelectResult.then)) { + var result = ctrl.onBeforeSelectCallback($scope, callbackContext); + if (angular.isDefined(result)) { + if (angular.isFunction(result.then)) { // Promise returned - wait for it to complete before completing the selection - onBeforeSelectResult.then(function (result) { + result.then(function (result) { if (!result) { return; } - completeSelection(result); + completeCallback(result); }); - } else if (onBeforeSelectResult === true) { - completeSelection(item); - } else if (onBeforeSelectResult) { - completeSelection(onBeforeSelectResult); + } else if (result === true) { + completeCallback(item); + } else if (result) { + completeCallback(result); } } else { - completeSelection(item); + completeCallback(item); } }; @@ -652,16 +681,38 @@ uis.controller('uiSelectCtrl', if (!ctrl.open) { return; } - if (ctrl.ngModel && ctrl.ngModel.$setTouched) { - ctrl.ngModel.$setTouched(); - } - _resetSearchInput(); - ctrl.open = false; - if (!ctrl.searchEnabled) { - angular.element(ctrl.searchInput[0]).removeClass('ui-select-offscreen'); + + function completeCallback() { + if (ctrl.ngModel && ctrl.ngModel.$setTouched) { + ctrl.ngModel.$setTouched(); + } + _resetSearchInput(); + ctrl.open = false; + if (!ctrl.searchEnabled) { + angular.element(ctrl.searchInput[0]).removeClass('ui-select-offscreen'); + } + + $scope.$broadcast('uis:close', skipFocusser); } - $scope.$broadcast('uis:close', skipFocusser); + var result = ctrl.onDropdownCallback($scope, {open: false}); + if (angular.isDefined(result)) { + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (result) { + if (!result) { + return; + } + completeCallback(); + }); + } else if (result === true) { + completeCallback(); + } else if (result) { + completeCallback(); + } + } else { + completeCallback(); + } }; /** @@ -702,8 +753,10 @@ uis.controller('uiSelectCtrl', var isLocked, item = ctrl.selected[itemIndex]; if (item && !angular.isUndefined(ctrl.lockChoiceExpression)) { - isLocked = !!(itemScope.$eval(ctrl.lockChoiceExpression)); // force the boolean value - item._uiSelectChoiceLocked = isLocked; // store this for later reference + // Force the boolean value + isLocked = !!(itemScope.$eval(ctrl.lockChoiceExpression)); + // Store this for later reference + item._uiSelectChoiceLocked = isLocked; } return isLocked; @@ -731,7 +784,8 @@ uis.controller('uiSelectCtrl', }; ctrl.searchInput.css('width', '10px'); - $timeout(function () { //Give time to render correctly + $timeout(function () { + // Give time to render correctly if (sizeWatch === null && !updateIfVisible(calculateContainerWidth())) { sizeWatch = $scope.$watch(calculateContainerWidth, function (containerWidth) { if (updateIfVisible(containerWidth)) { @@ -748,7 +802,8 @@ uis.controller('uiSelectCtrl', switch (key) { case KEY.DOWN: if (!ctrl.open && ctrl.multiple) { - ctrl.activate(false, true); //In case its the search input in 'multiple' mode + // In case its the search input in 'multiple' mode + ctrl.activate(false, true); } else if (ctrl.activeIndex < ctrl.items.length - 1) { ctrl.activeIndex++; @@ -843,7 +898,7 @@ uis.controller('uiSelectCtrl', container[0].scrollTop += posY - height; } else if (posY < highlighted.clientHeight) { if (ctrl.isGrouped && ctrl.activeIndex === 0) { - //To make group header visible when going all the way up + // To make group header visible when going all the way up container[0].scrollTop = 0; } else { @@ -877,14 +932,15 @@ uis.directive('uiSelect', controllerAs: '$select', compile: function (tElement, tAttrs) { - //Multiple or Single depending if multiple attribute presence - if (angular.isDefined(tAttrs.multiple)) + // Multiple or Single depending if multiple attribute presence + if (angular.isDefined(tAttrs.multiple)) { tElement.append("").removeAttr('multiple'); - else + } + else { tElement.append(""); + } return function (scope, element, attrs, ctrls, transcludeFn) { - var $select = ctrls[0]; var ngModel = ctrls[1]; @@ -906,11 +962,12 @@ uis.directive('uiSelect', $select.onRemoveCallback = $parse(attrs.onRemove); $select.onBeforeRemoveCallback = $parse(attrs.onBeforeRemove); $select.onKeypressCallback = $parse(attrs.onKeypress); + $select.onDropdownCallback = $parse(attrs.onDropdown); - //Limit the number of selections allowed + // Limit the number of selections allowed $select.limit = (angular.isDefined(attrs.limit)) ? parseInt(attrs.limit, 10) : undefined; - //Set reference to ngModel from uiSelectCtrl + // Set reference to ngModel from uiSelectCtrl $select.ngModel = ngModel; $select.choiceGrouped = function (group) { @@ -944,7 +1001,7 @@ uis.directive('uiSelect', }); } - //Gets focus based on scope event name (e.g. focus-on='SomeEventName') + // Gets focus based on scope event name (e.g. focus-on='SomeEventName') if (angular.isDefined(attrs.focusOn)) { scope.$on(attrs.focusOn, function () { $timeout(function () { @@ -954,7 +1011,10 @@ uis.directive('uiSelect', } function onDocumentClick(e) { - if (!$select.open) return; //Skip it if dropdown is close + //Skip it if dropdown is close + if (!$select.open) { + return; + } var contains = false; @@ -967,14 +1027,14 @@ uis.directive('uiSelect', } if (!contains && !$select.clickTriggeredSelect) { - //Will lose focus only with certain targets + // Will lose focus only with certain targets var focusableControls = ['input', 'button', 'textarea']; - //To check if target is other ui-select + // To check if target is other ui-select var targetScope = angular.element(e.target).scope(); - //To check if target is other ui-select + // To check if target is other ui-select var skipFocusser = targetScope && targetScope.$select && targetScope.$select !== $select; - //Check if target is input, button or textarea + // Check if target is input, button or textarea if (!skipFocusser) { skipFocusser = ~focusableControls.indexOf(e.target.tagName.toLowerCase()); } @@ -1203,13 +1263,18 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel ctrl.activeMatchIndex = -1; $select.sizeSearchInput(); + // If there's no onBeforeRemove callback, then we're done + if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { + return; + } + var callbackContext = { $item: removedChoice, $model: $select.parserResult.modelMapper($scope, locals) }; // Give some time for scope propagation. - function completeRemoval() { + function completeCallback() { $timeout(function () { $select.onRemoveCallback($scope, callbackContext); }); @@ -1222,21 +1287,21 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel // falsy: Abort the removal // promise: Wait for response // true: Complete removal - var onBeforeRemoveResult = ctrl.onBeforeRemoveCallback($scope, callbackContext); - if (angular.isDefined(onBeforeRemoveResult)) { - if (angular.isFunction(onBeforeRemoveResult.then)) { + var result = ctrl.onBeforeRemoveCallback($scope, callbackContext); + if (angular.isDefined(result)) { + if (angular.isFunction(result.then)) { // Promise returned - wait for it to complete before completing the selection - onBeforeRemoveResult.then(function (result) { + result.then(function (result) { if (!result) { return; } - completeRemoval(result); + completeCallback(result); }); - } else if (onBeforeRemoveResult === true) { - completeRemoval(); + } else if (result === true) { + completeCallback(); } } else { - completeRemoval(); + completeCallback(); } }; @@ -1484,7 +1549,7 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co var $select = ctrls[0]; var ngModel = ctrls[1]; - //From view --> model + // From view --> model ngModel.$parsers.unshift(function (inputValue) { var locals = {}, result; @@ -1493,7 +1558,7 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co return result; }); - //From model --> view + // From model --> view ngModel.$formatters.unshift(function (inputValue) { var data = $select.parserResult.source(scope, {$select: {search: ''}}), //Overwrite $search locals = {}, @@ -1504,7 +1569,7 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co result = $select.parserResult.modelMapper(scope, locals); return result == inputValue; }; - //If possible pass same object stored in $select.selected + // If possible pass same object stored in $select.selected if ($select.selected && checkFnSingle($select.selected)) { return $select.selected; } @@ -1517,7 +1582,7 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co return inputValue; }); - //Update viewValue if model change + // Update viewValue if model change scope.$watch('$select.selected', function (newValue) { if (ngModel.$viewValue !== newValue) { ngModel.$setViewValue(newValue); @@ -1540,15 +1605,16 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co }); scope.$on('uis:activate', function () { - focusser.prop('disabled', true); //Will reactivate it on .close() + // Will reactivate it on .close() + focusser.prop('disabled', true); }); - //Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954 + // Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954 var focusser = angular.element(""); $compile(focusser)(scope); $select.focusser = focusser; - //Input that will handle focus + // Input that will handle focus $select.focusInput = focusser; element.parent().append(focusser); @@ -1562,8 +1628,8 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co $select.focus = false; }); }); - focusser.bind("keydown", function (e) { + focusser.bind("keydown", function (e) { if (e.which === KEY.BACKSPACE) { e.preventDefault(); e.stopPropagation(); @@ -1586,13 +1652,13 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co }); focusser.bind("keyup input", function (e) { - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { return; } - $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input + // User pressed some regular key, so we pass it to the search input + $select.activate(focusser.val()); focusser.val(''); scope.$digest(); }); diff --git a/dist/select.min.css b/dist/select.min.css index c53af1ab1..f90f6891a 100644 --- a/dist/select.min.css +++ b/dist/select.min.css @@ -1,6 +1,6 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-04T17:24:10.107Z + * Version: 0.12.1 - 2015-08-05T18:50:43.115Z * License: MIT */.ui-select-highlight{font-weight:700}.ui-select-offscreen{clip:rect(0 0 0 0)!important;width:1px!important;height:1px!important;border:0!important;margin:0!important;padding:0!important;overflow:hidden!important;position:absolute!important;outline:0!important;left:0!important;top:0!important}.ng-dirty.ng-invalid>a.select2-choice{border-color:#D44950}.select2-result-single{padding-left:0}.select-locked>.ui-select-match-close,.select2-locked>.select2-search-choice-close{display:none}body>.select2-container.open{z-index:9999}.ui-select-container[theme=select2].direction-up .ui-select-match{border-radius:0 0 4px 4px}.ui-select-container[theme=select2].direction-up .ui-select-dropdown{bottom:100%;top:auto;position:absolute;border-radius:4px 4px 0 0;border-top-width:1px;border-top-style:solid;box-shadow:0 -4px 8px rgba(0,0,0,.25);margin-top:-4px}.ui-select-container[theme=select2].direction-up .ui-select-dropdown .select2-search{margin-top:4px}.ui-select-container[theme=select2].direction-up.select2-dropdown-open .ui-select-match{border-bottom-color:#5897fb}.selectize-input.selectize-focus{border-color:#007FBB!important}.selectize-control>.selectize-dropdown,.selectize-control>.selectize-input>input{width:100%}.ng-dirty.ng-invalid>div.selectize-input{border-color:#D44950}.ui-select-container[theme=selectize].direction-up .ui-select-dropdown{bottom:100%;top:auto;position:absolute;box-shadow:0 -4px 8px rgba(0,0,0,.25);margin-top:-2px}.btn-default-focus{color:#333;background-color:#EBEBEB;border-color:#ADADAD;text-decoration:none;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.ui-select-bootstrap .ui-select-toggle{position:relative}.ui-select-bootstrap .ui-select-toggle>.caret{position:absolute;height:10px;top:50%;right:10px;margin-top:-2px}.input-group>.ui-select-bootstrap.dropdown{position:static}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control{border-radius:4px 0 0 4px}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control.direction-up{border-radius:4px 0 0 4px!important}.ui-select-bootstrap>.ui-select-match>.btn{text-align:left!important}.ui-select-bootstrap>.ui-select-match>.caret{position:absolute;top:45%;right:15px}.ui-select-bootstrap>.ui-select-choices{width:100%;height:auto;max-height:200px;overflow-x:hidden;margin-top:-1px}body>.ui-select-bootstrap.open{z-index:1000}.ui-select-multiple.ui-select-bootstrap{height:auto;padding:3px 3px 0}.ui-select-multiple.ui-select-bootstrap input.ui-select-search{background-color:transparent!important;border:none;outline:0;height:1.666666em;margin-bottom:3px}.ui-select-multiple.ui-select-bootstrap .ui-select-match .close{font-size:1.6em;line-height:.75}.ui-select-multiple.ui-select-bootstrap .ui-select-match-item{outline:0;margin:0 3px 3px 0}.ui-select-multiple .ui-select-match-item{position:relative}.ui-select-multiple .ui-select-match-item.dropping-before:before{content:"";position:absolute;top:0;right:100%;height:100%;margin-right:2px;border-left:1px solid #428bca}.ui-select-multiple .ui-select-match-item.dropping-after:after{content:"";position:absolute;top:0;left:100%;height:100%;margin-left:2px;border-right:1px solid #428bca}.ui-select-bootstrap .ui-select-placeholder{opacity:1;color:#999}.ui-select-bootstrap .ui-select-choices-row>a{display:block;padding:3px 20px;clear:both;font-weight:400;line-height:1.42857143;color:#333;white-space:nowrap}.ui-select-bootstrap .ui-select-choices-row>a:focus,.ui-select-bootstrap .ui-select-choices-row>a:hover{text-decoration:none;color:#262626;background-color:#f5f5f5}.ui-select-bootstrap .ui-select-choices-row.active>a{color:#fff;text-decoration:none;outline:0;background-color:#428bca}.ui-select-bootstrap .ui-select-choices-row.active.disabled>a,.ui-select-bootstrap .ui-select-choices-row.disabled>a{color:#777;cursor:not-allowed;background-color:#fff}.ui-select-match.ng-hide-add,.ui-select-search.ng-hide-add{display:none!important}.ui-select-bootstrap.ng-dirty.ng-invalid>button.btn.ui-select-match{border-color:#D44950}.ui-select-container[theme=bootstrap].direction-up .ui-select-dropdown{bottom:100%;top:auto;position:absolute;box-shadow:0 -4px 8px rgba(0,0,0,.25)} \ No newline at end of file diff --git a/dist/select.min.js b/dist/select.min.js index 5dc3376d6..076a4bd06 100644 --- a/dist/select.min.js +++ b/dist/select.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-04T17:24:10.105Z + * Version: 0.12.1 - 2015-08-05T18:50:43.112Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],c=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(c.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,c=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,l,s){s(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(c){var l=c[0].getBoundingClientRect();return{width:l.width||c.prop("offsetWidth"),height:l.height||c.prop("offsetHeight"),top:l.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:l.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);c.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,c,l){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(e,s){if(!s.repeat)throw c("repeat","Expected 'repeat' expression.");return function(e,s,i,n,a){var r=i.groupBy,o=i.groupFilter;if(n.parseRepeatAttr(i.repeat,r,o),n.disableChoiceExpression=i.uiDisableChoice,n.onHighlightCallback=i.onHighlight,r){var u=s.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=s.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(n.parserResult.itemName,"$select.items",n.parserResult.trackByExp,r)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+n.parserResult.itemName+")").attr("ng-click","$select.select("+n.parserResult.itemName+",false,$event)");var p=s.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),l(s,a)(e),e.$watch("$select.search",function(e){e&&!n.open&&n.multiple&&n.activate(!1,!0),n.activeIndex=0})}}}}]),c.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,c,l,s,i,n,a,r){function o(){(h.resetSearchInput||void 0===h.resetSearchInput&&r.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var c,l,s=[];for(c=0;c0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:c=!1}return c}function p(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw a("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var l=t[h.activeIndex],s=l.offsetTop+l.clientHeight-e[0].scrollTop,i=e[0].offsetHeight;s>i?e[0].scrollTop+=s-i:s=h.items.length?0:h.activeIndex,l(function(){h.search=e||h.search,h.searchInput[0].focus()}))},h.parseRepeatAttr=function(e,c,l){function s(e){var s=t.$eval(c);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(s)?s(e):e[s],c=h.findGroupByName(t);c?c.items.push(e):h.groups.push({name:t,items:[e]})}),l){var i=t.$eval(l);angular.isFunction(i)?h.groups=i(h.groups):angular.isArray(i)&&(h.groups=u(h.groups,i))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function i(e){h.items=e}h.setItemsFn=c?s:i,h.parserResult=n.parse(e),h.isGrouped=!!c,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var c=h.selected;if(h.isEmpty()||angular.isArray(c)&&!c.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var l=e.filter(function(e){return c.indexOf(e)<0});h.setItemsFn(l)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw a("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),c=t===h.activeIndex;return c&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),c},h.isDisabled=function(e){if(!h.open)return!1;var t,c=h.items.indexOf(e[h.itemProperty]),l=!1;return c>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[c],l=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=l),l},h.select=function(e,c,s){if((void 0===e||!e._uiSelectChoiceDisabled)&&(h.items||h.search)){var i={};i[h.parserResult.itemName]=e;var n={$item:e,$model:h.parserResult.modelMapper(t,i)},a=function(){t.$broadcast("uis:select",e),l(function(){h.onSelectCallback(t,n)}),h.closeOnSelect&&h.close(c),s&&"click"===s.type&&(h.clickTriggeredSelect=!0)},r=h.onBeforeSelectCallback(t,n);angular.isDefined(r)?angular.isFunction(r.then)?r.then(function(e){e&&a(e)}):r===!0?a(e):r&&a(r):a(e)}},h.close=function(e){h.open&&(h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),o(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e))},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),l(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var c,l=h.selected[t];return l&&!angular.isUndefined(h.lockChoiceExpression)&&(c=!!e.$eval(h.lockChoiceExpression),l._uiSelectChoiceLocked=c),c};var g=null;h.sizeSearchInput=function(){var e=h.searchInput[0],c=h.searchInput.parent().parent()[0],s=function(){return c.clientWidth*!!e.offsetParent},i=function(t){if(0===t)return!1;var c=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>c&&(c=t),h.searchInput.css("width",c+"px"),!0};h.searchInput.css("width","10px"),l(function(){null!==g||i(s())||(g=t.$watch(s,function(e){i(e)&&(g(),g=null)}))})},h.searchInput.on("keydown",function(c){var l=c.which;t.$apply(function(){d(l)}),e.isVerticalMovement(l)&&h.items.length>0&&p(),(l===e.ENTER||l===e.ESC)&&(c.preventDefault(),c.stopPropagation())}),h.searchInput.on("keyup",function(c){c.which===e.TAB||e.isControl(c)||e.isFunctionKey(c)||c.which===e.ESC||e.isVerticalMovement(c.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:c})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),c.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,c,l,s,i,n){return{restrict:"EA",templateUrl:function(e,c){var l=c.theme||t.theme;return l+(angular.isDefined(c.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(s,a){return angular.isDefined(a.multiple)?s.append("").removeAttr("multiple"):s.append(""),function(s,a,r,o,u){function d(e){if(f.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(a[0],e.target):a[0].contains(e.target),!t&&!f.clickTriggeredSelect){var c=["input","button","textarea"],l=angular.element(e.target).scope(),i=l&&l.$select&&l.$select!==f;i||(i=~c.indexOf(e.target.tagName.toLowerCase())),f.close(i),s.$digest()}f.clickTriggeredSelect=!1}}function p(){var t=l(a);b=angular.element('
    '),b[0].style.width=t.width+"px",b[0].style.height=t.height+"px",a.after(b),w=a[0].style.width,e.find("body").append(a),a[0].style.position="absolute",a[0].style.left=t.left+"px",a[0].style.top=t.top+"px",a[0].style.width=t.width+"px"}function h(){null!==b&&(b.replaceWith(a),b=null,a[0].style.position="",a[0].style.left="",a[0].style.top="",a[0].style.width=w)}var f=o[0],g=o[1];f.generatedId=t.generateId(),f.baseTitle=r.title||"Select box",f.focusserTitle=f.baseTitle+" focus",f.focusserId="focusser-"+f.generatedId,f.closeOnSelect=function(){return angular.isDefined(r.closeOnSelect)?i(r.closeOnSelect)():t.closeOnSelect}(),f.onSelectCallback=i(r.onSelect),f.onBeforeSelectCallback=i(r.onBeforeSelect),f.onRemoveCallback=i(r.onRemove),f.onBeforeRemoveCallback=i(r.onBeforeRemove),f.onKeypressCallback=i(r.onKeypress),f.limit=angular.isDefined(r.limit)?parseInt(r.limit,10):void 0,f.ngModel=g,f.choiceGrouped=function(e){return f.isGrouped&&e&&e.name},r.tabindex&&r.$observe("tabindex",function(e){f.focusInput.attr("tabindex",e),a.removeAttr("tabindex")});var v=s.$eval(r.searchEnabled);f.searchEnabled=void 0!==v?v:t.searchEnabled;var m=s.$eval(r.sortable);f.sortable=void 0!==m?m:t.sortable,r.$observe("disabled",function(){f.disabled=void 0!==r.disabled?r.disabled:!1}),angular.isDefined(r.autofocus)&&n(function(){f.setFocus()}),angular.isDefined(r.focusOn)&&s.$on(r.focusOn,function(){n(function(){f.setFocus()})}),e.on("click",d),s.$on("$destroy",function(){e.off("click",d)}),u(s,function(e){var t=angular.element("
    ").append(e),l=t.querySelectorAll(".ui-select-match");if(l.removeAttr("ui-select-match"),l.removeAttr("data-ui-select-match"),1!==l.length)throw c("transcluded","Expected 1 .ui-select-match but got '{0}'.",l.length);a.querySelectorAll(".ui-select-match").replaceWith(l);var s=t.querySelectorAll(".ui-select-choices");if(s.removeAttr("ui-select-choices"),s.removeAttr("data-ui-select-choices"),1!==s.length)throw c("transcluded","Expected 1 .ui-select-choices but got '{0}'.",s.length);a.querySelectorAll(".ui-select-choices").replaceWith(s)});var $=s.$eval(r.appendToBody);(void 0!==$?$:t.appendToBody)&&(s.$watch("$select.open",function(e){e?p():h()}),s.$on("$destroy",function(){h()}));var b=null,w="",E=null,x="direction-up";s.$watch("$select.open",function(t){if(t){if(E=angular.element(a).querySelectorAll(".ui-select-dropdown"),null===E)return;E[0].style.opacity=0,n(function(){var t=l(a),c=l(E);t.top+t.height+c.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&a.addClass(x),E[0].style.opacity=1})}else{if(null===E)return;a.removeClass(x)}})}}}}]),c.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,l=t.parent().attr("multiple");return c+(l?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,l,s){function i(e){s.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}s.lockChoiceExpression=l.uiLockChoice,l.$observe("placeholder",function(t){s.placeholder=void 0!==t?t:e.placeholder}),l.$observe("allowClear",i),i(l.allowClear),s.multiple&&s.sizeSearchInput()}}}]),c.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var c,l=this,s=e.$select;e.$evalAsync(function(){c=e.ngModel}),l.activeMatchIndex=-1,l.updateModel=function(){c.$setViewValue(Date.now()),l.refreshComponent()},l.refreshComponent=function(){s.refreshItems(),s.sizeSearchInput()},l.removeChoice=function(c){function i(){t(function(){s.onRemoveCallback(e,r)}),l.updateModel()}var n=s.selected[c];if(!n._uiSelectChoiceLocked){var a={};a[s.parserResult.itemName]=n,s.selected.splice(c,1),l.activeMatchIndex=-1,s.sizeSearchInput();var r={$item:n,$model:s.parserResult.modelMapper(e,a)},o=l.onBeforeRemoveCallback(e,r);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(e){e&&i(e)}):o===!0&&i():i()}},l.getPlaceholder=function(){return s.selected&&s.selected.length?void 0:s.placeholder}}],controllerAs:"$selectMultiple",link:function(l,s,i,n){function a(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function r(t){function c(){switch(t){case e.LEFT:return~d.activeMatchIndex?p:n;case e.RIGHT:return~d.activeMatchIndex&&r!==n?u:(o.activate(),!1);case e.BACKSPACE:return~d.activeMatchIndex?(d.removeChoice(r),p):n;case e.DELETE:return~d.activeMatchIndex?(d.removeChoice(d.activeMatchIndex),r):!1}}var l=a(o.searchInput[0]),s=o.selected.length,i=0,n=s-1,r=d.activeMatchIndex,u=d.activeMatchIndex+1,p=d.activeMatchIndex-1,h=r;return l>0||o.search.length&&t==e.RIGHT?!1:(o.close(),h=c(),d.activeMatchIndex=o.selected.length&&h!==!1?Math.min(n,Math.max(i,h)):-1,!0)}var o=n[0],u=l.ngModel=n[1],d=l.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,u.$parsers.unshift(function(){for(var e,t={},c=[],s=o.selected.length-1;s>=0;s--)t={},t[o.parserResult.itemName]=o.selected[s],e=o.parserResult.modelMapper(l,t),c.unshift(e);return c}),u.$formatters.unshift(function(e){var t,c=o.parserResult.source(l,{$select:{search:""}}),s={};if(!c)return e;var i=[],n=function(e,c){if(e&&e.length){for(var n=e.length-1;n>=0;n--){if(s[o.parserResult.itemName]=e[n],t=o.parserResult.modelMapper(l,s),o.parserResult.trackByExp){var a=/\.(.+)/.exec(o.parserResult.trackByExp);if(a.length>0&&t[a[1]]==c[a[1]])return i.unshift(e[n]),!0}if(angular.equals(t,c))return i.unshift(e[n]),!0}return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(o.selected,e[a])||n(c,e[a])||i.unshift(e[a]);return i}),l.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,d.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);o.selected=[]}o.selected=u.$viewValue,l.$evalAsync()},l.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),d.updateModel())}),l.$on("uis:activate",function(){d.activeMatchIndex=-1}),l.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(t){var c=t.which;l.$apply(function(){var t=!1;e.isHorizontalMovement(c)&&(t=r(c)),t&&c!=e.TAB})}),o.searchInput.on("blur",function(){c(function(){d.activeMatchIndex=-1})})}}}]),c.directive("uiSelectSingle",["$timeout","$compile",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(l,s,i,n){var a=n[0],r=n[1];r.$parsers.unshift(function(e){var t,c={};return c[a.parserResult.itemName]=e,t=a.parserResult.modelMapper(l,c)}),r.$formatters.unshift(function(e){var t,c=a.parserResult.source(l,{$select:{search:""}}),s={};if(c){var i=function(c){return s[a.parserResult.itemName]=c,t=a.parserResult.modelMapper(l,s),t==e};if(a.selected&&i(a.selected))return a.selected;for(var n=c.length-1;n>=0;n--)if(i(c[n]))return c[n]}return e}),l.$watch("$select.selected",function(e){r.$viewValue!==e&&r.$setViewValue(e)}),r.$render=function(){a.selected=r.$viewValue},l.$on("uis:select",function(e,t){a.selected=t}),l.$on("uis:close",function(e,c){t(function(){a.focusser.prop("disabled",!1),c||a.focusser[0].focus()},0,!1)}),l.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");c(o)(l),a.focusser=o,a.focusInput=o,s.parent().append(o),o.bind("focus",function(){l.$evalAsync(function(){a.focus=!0})}),o.bind("blur",function(){l.$evalAsync(function(){a.focus=!1})}),o.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),a.select(void 0),l.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),a.activate()),l.$digest()),void 0)}),o.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(a.activate(o.val()),o.val(""),l.$digest())})}}}]),c.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var l=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!l)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:l[2],source:t(l[3]),trackByExp:l[4],modelMapper:t(l[1]||l[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,l){var s=e+" in "+(l?"$group.items":t);return c&&(s+=" track by "+c),s}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("selectize/choices.tpl.html",'
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",'
    {{$select.placeholder}}
    '),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",'')}]),angular.module("ui.select").run(["$templateCache",function(e){e.put("select2/choices.tpl.html",'
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    ')}]); \ No newline at end of file +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],c=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(c.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,c=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,l,s){s(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(c){var l=c[0].getBoundingClientRect();return{width:l.width||c.prop("offsetWidth"),height:l.height||c.prop("offsetHeight"),top:l.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:l.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);c.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,c,l){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(e,s){if(!s.repeat)throw c("repeat","Expected 'repeat' expression.");return function(e,s,i,n,a){var o=i.groupBy,r=i.groupFilter;if(n.parseRepeatAttr(i.repeat,o,r),n.disableChoiceExpression=i.uiDisableChoice,n.onHighlightCallback=i.onHighlight,o){var u=s.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=s.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(n.parserResult.itemName,"$select.items",n.parserResult.trackByExp,o)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+n.parserResult.itemName+")").attr("ng-click","$select.select("+n.parserResult.itemName+",false,$event)");var p=s.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),l(s,a)(e),e.$watch("$select.search",function(e){e&&!n.open&&n.multiple&&n.activate(!1,!0),n.activeIndex=0})}}}}]),c.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,c,l,s,i,n,a,o){function r(){(h.resetSearchInput||void 0===h.resetSearchInput&&o.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var c,l,s=[];for(c=0;c0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:c=!1}return c}function p(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw a("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var l=t[h.activeIndex],s=l.offsetTop+l.clientHeight-e[0].scrollTop,i=e[0].offsetHeight;s>i?e[0].scrollTop+=s-i:s=h.items.length?0:h.activeIndex,l(function(){h.search=e||h.search,h.searchInput[0].focus()})},i=h.onDropdownCallback(t,{open:!0});angular.isDefined(i)?angular.isFunction(i.then)?i.then(function(e){e&&s()}):i===!0?s():i&&s():s()}},h.parseRepeatAttr=function(e,c,l){function s(e){var s=t.$eval(c);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(s)?s(e):e[s],c=h.findGroupByName(t);c?c.items.push(e):h.groups.push({name:t,items:[e]})}),l){var i=t.$eval(l);angular.isFunction(i)?h.groups=i(h.groups):angular.isArray(i)&&(h.groups=u(h.groups,i))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function i(e){h.items=e}h.setItemsFn=c?s:i,h.parserResult=n.parse(e),h.isGrouped=!!c,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var c=h.selected;if(h.isEmpty()||angular.isArray(c)&&!c.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var l=e.filter(function(e){return c.indexOf(e)<0});h.setItemsFn(l)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw a("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),c=-1===t?!1:t===h.activeIndex;return c&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),c},h.isDisabled=function(e){if(!h.open)return!1;var t,c=h.items.indexOf(e[h.itemProperty]),l=!1;return c>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[c],l=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=l),l},h.select=function(e,c,s){if((void 0===e||!e._uiSelectChoiceDisabled)&&(h.items||h.search)){var i={};i[h.parserResult.itemName]=e;var n={$item:e,$model:h.parserResult.modelMapper(t,i)},a=function(e){n.$item=e,t.$broadcast("uis:select",e),l(function(){h.onSelectCallback(t,n)}),h.closeOnSelect&&h.close(c),s&&"click"===s.type&&(h.clickTriggeredSelect=!0)},o=h.onBeforeSelectCallback(t,n);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(e){e&&a(e)}):o===!0?a(e):o&&a(o):a(e)}},h.close=function(e){function c(){h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),r(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e)}if(h.open){var l=h.onDropdownCallback(t,{open:!1});angular.isDefined(l)?angular.isFunction(l.then)?l.then(function(e){e&&c()}):l===!0?c():l&&c():c()}},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),l(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var c,l=h.selected[t];return l&&!angular.isUndefined(h.lockChoiceExpression)&&(c=!!e.$eval(h.lockChoiceExpression),l._uiSelectChoiceLocked=c),c};var g=null;h.sizeSearchInput=function(){var e=h.searchInput[0],c=h.searchInput.parent().parent()[0],s=function(){return c.clientWidth*!!e.offsetParent},i=function(t){if(0===t)return!1;var c=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>c&&(c=t),h.searchInput.css("width",c+"px"),!0};h.searchInput.css("width","10px"),l(function(){null!==g||i(s())||(g=t.$watch(s,function(e){i(e)&&(g(),g=null)}))})},h.searchInput.on("keydown",function(c){var l=c.which;t.$apply(function(){d(l)}),e.isVerticalMovement(l)&&h.items.length>0&&p(),(l===e.ENTER||l===e.ESC)&&(c.preventDefault(),c.stopPropagation())}),h.searchInput.on("keyup",function(c){c.which===e.TAB||e.isControl(c)||e.isFunctionKey(c)||c.which===e.ESC||e.isVerticalMovement(c.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:c})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),c.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,c,l,s,i,n){return{restrict:"EA",templateUrl:function(e,c){var l=c.theme||t.theme;return l+(angular.isDefined(c.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(s,a){return angular.isDefined(a.multiple)?s.append("").removeAttr("multiple"):s.append(""),function(s,a,o,r,u){function d(e){if(f.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(a[0],e.target):a[0].contains(e.target),!t&&!f.clickTriggeredSelect){var c=["input","button","textarea"],l=angular.element(e.target).scope(),i=l&&l.$select&&l.$select!==f;i||(i=~c.indexOf(e.target.tagName.toLowerCase())),f.close(i),s.$digest()}f.clickTriggeredSelect=!1}}function p(){var t=l(a);b=angular.element('
    '),b[0].style.width=t.width+"px",b[0].style.height=t.height+"px",a.after(b),w=a[0].style.width,e.find("body").append(a),a[0].style.position="absolute",a[0].style.left=t.left+"px",a[0].style.top=t.top+"px",a[0].style.width=t.width+"px"}function h(){null!==b&&(b.replaceWith(a),b=null,a[0].style.position="",a[0].style.left="",a[0].style.top="",a[0].style.width=w)}var f=r[0],g=r[1];f.generatedId=t.generateId(),f.baseTitle=o.title||"Select box",f.focusserTitle=f.baseTitle+" focus",f.focusserId="focusser-"+f.generatedId,f.closeOnSelect=function(){return angular.isDefined(o.closeOnSelect)?i(o.closeOnSelect)():t.closeOnSelect}(),f.onSelectCallback=i(o.onSelect),f.onBeforeSelectCallback=i(o.onBeforeSelect),f.onRemoveCallback=i(o.onRemove),f.onBeforeRemoveCallback=i(o.onBeforeRemove),f.onKeypressCallback=i(o.onKeypress),f.onDropdownCallback=i(o.onDropdown),f.limit=angular.isDefined(o.limit)?parseInt(o.limit,10):void 0,f.ngModel=g,f.choiceGrouped=function(e){return f.isGrouped&&e&&e.name},o.tabindex&&o.$observe("tabindex",function(e){f.focusInput.attr("tabindex",e),a.removeAttr("tabindex")});var v=s.$eval(o.searchEnabled);f.searchEnabled=void 0!==v?v:t.searchEnabled;var m=s.$eval(o.sortable);f.sortable=void 0!==m?m:t.sortable,o.$observe("disabled",function(){f.disabled=void 0!==o.disabled?o.disabled:!1}),angular.isDefined(o.autofocus)&&n(function(){f.setFocus()}),angular.isDefined(o.focusOn)&&s.$on(o.focusOn,function(){n(function(){f.setFocus()})}),e.on("click",d),s.$on("$destroy",function(){e.off("click",d)}),u(s,function(e){var t=angular.element("
    ").append(e),l=t.querySelectorAll(".ui-select-match");if(l.removeAttr("ui-select-match"),l.removeAttr("data-ui-select-match"),1!==l.length)throw c("transcluded","Expected 1 .ui-select-match but got '{0}'.",l.length);a.querySelectorAll(".ui-select-match").replaceWith(l);var s=t.querySelectorAll(".ui-select-choices");if(s.removeAttr("ui-select-choices"),s.removeAttr("data-ui-select-choices"),1!==s.length)throw c("transcluded","Expected 1 .ui-select-choices but got '{0}'.",s.length);a.querySelectorAll(".ui-select-choices").replaceWith(s)});var $=s.$eval(o.appendToBody);(void 0!==$?$:t.appendToBody)&&(s.$watch("$select.open",function(e){e?p():h()}),s.$on("$destroy",function(){h()}));var b=null,w="",E=null,x="direction-up";s.$watch("$select.open",function(t){if(t){if(E=angular.element(a).querySelectorAll(".ui-select-dropdown"),null===E)return;E[0].style.opacity=0,n(function(){var t=l(a),c=l(E);t.top+t.height+c.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&a.addClass(x),E[0].style.opacity=1})}else{if(null===E)return;a.removeClass(x)}})}}}}]),c.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,l=t.parent().attr("multiple");return c+(l?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,l,s){function i(e){s.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}s.lockChoiceExpression=l.uiLockChoice,l.$observe("placeholder",function(t){s.placeholder=void 0!==t?t:e.placeholder}),l.$observe("allowClear",i),i(l.allowClear),s.multiple&&s.sizeSearchInput()}}}]),c.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var c,l=this,s=e.$select;e.$evalAsync(function(){c=e.ngModel}),l.activeMatchIndex=-1,l.updateModel=function(){c.$setViewValue(Date.now()),l.refreshComponent()},l.refreshComponent=function(){s.refreshItems(),s.sizeSearchInput()},l.removeChoice=function(c){function i(){t(function(){s.onRemoveCallback(e,o)}),l.updateModel()}var n=s.selected[c];if(!n._uiSelectChoiceLocked){var a={};if(a[s.parserResult.itemName]=n,s.selected.splice(c,1),l.activeMatchIndex=-1,s.sizeSearchInput(),angular.isDefined(l.onBeforeRemoveCallback)){var o={$item:n,$model:s.parserResult.modelMapper(e,a)},r=l.onBeforeRemoveCallback(e,o);angular.isDefined(r)?angular.isFunction(r.then)?r.then(function(e){e&&i(e)}):r===!0&&i():i()}}},l.getPlaceholder=function(){return s.selected&&s.selected.length?void 0:s.placeholder}}],controllerAs:"$selectMultiple",link:function(l,s,i,n){function a(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function o(t){function c(){switch(t){case e.LEFT:return~d.activeMatchIndex?p:n;case e.RIGHT:return~d.activeMatchIndex&&o!==n?u:(r.activate(),!1);case e.BACKSPACE:return~d.activeMatchIndex?(d.removeChoice(o),p):n;case e.DELETE:return~d.activeMatchIndex?(d.removeChoice(d.activeMatchIndex),o):!1}}var l=a(r.searchInput[0]),s=r.selected.length,i=0,n=s-1,o=d.activeMatchIndex,u=d.activeMatchIndex+1,p=d.activeMatchIndex-1,h=o;return l>0||r.search.length&&t==e.RIGHT?!1:(r.close(),h=c(),d.activeMatchIndex=r.selected.length&&h!==!1?Math.min(n,Math.max(i,h)):-1,!0)}var r=n[0],u=l.ngModel=n[1],d=l.$selectMultiple;r.multiple=!0,r.removeSelected=!0,r.focusInput=r.searchInput,u.$parsers.unshift(function(){for(var e,t={},c=[],s=r.selected.length-1;s>=0;s--)t={},t[r.parserResult.itemName]=r.selected[s],e=r.parserResult.modelMapper(l,t),c.unshift(e);return c}),u.$formatters.unshift(function(e){var t,c=r.parserResult.source(l,{$select:{search:""}}),s={};if(!c)return e;var i=[],n=function(e,c){if(e&&e.length){for(var n=e.length-1;n>=0;n--){if(s[r.parserResult.itemName]=e[n],t=r.parserResult.modelMapper(l,s),r.parserResult.trackByExp){var a=/\.(.+)/.exec(r.parserResult.trackByExp);if(a.length>0&&t[a[1]]==c[a[1]])return i.unshift(e[n]),!0}if(angular.equals(t,c))return i.unshift(e[n]),!0}return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(r.selected,e[a])||n(c,e[a])||i.unshift(e[a]);return i}),l.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,d.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);r.selected=[]}r.selected=u.$viewValue,l.$evalAsync()},l.$on("uis:select",function(e,t){r.selected.length>=r.limit||(r.selected.push(t),d.updateModel())}),l.$on("uis:activate",function(){d.activeMatchIndex=-1}),l.$watch("$select.disabled",function(e,t){t&&!e&&r.sizeSearchInput()}),r.searchInput.on("keydown",function(t){var c=t.which;l.$apply(function(){var t=!1;e.isHorizontalMovement(c)&&(t=o(c)),t&&c!=e.TAB})}),r.searchInput.on("blur",function(){c(function(){d.activeMatchIndex=-1})})}}}]),c.directive("uiSelectSingle",["$timeout","$compile",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(l,s,i,n){var a=n[0],o=n[1];o.$parsers.unshift(function(e){var t,c={};return c[a.parserResult.itemName]=e,t=a.parserResult.modelMapper(l,c)}),o.$formatters.unshift(function(e){var t,c=a.parserResult.source(l,{$select:{search:""}}),s={};if(c){var i=function(c){return s[a.parserResult.itemName]=c,t=a.parserResult.modelMapper(l,s),t==e};if(a.selected&&i(a.selected))return a.selected;for(var n=c.length-1;n>=0;n--)if(i(c[n]))return c[n]}return e}),l.$watch("$select.selected",function(e){o.$viewValue!==e&&o.$setViewValue(e)}),o.$render=function(){a.selected=o.$viewValue},l.$on("uis:select",function(e,t){a.selected=t}),l.$on("uis:close",function(e,c){t(function(){a.focusser.prop("disabled",!1),c||a.focusser[0].focus()},0,!1)}),l.$on("uis:activate",function(){r.prop("disabled",!0)});var r=angular.element("");c(r)(l),a.focusser=r,a.focusInput=r,s.parent().append(r),r.bind("focus",function(){l.$evalAsync(function(){a.focus=!0})}),r.bind("blur",function(){l.$evalAsync(function(){a.focus=!1})}),r.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),a.select(void 0),l.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),a.activate()),l.$digest()),void 0)}),r.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(a.activate(r.val()),r.val(""),l.$digest())})}}}]),c.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var l=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!l)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:l[2],source:t(l[3]),trackByExp:l[4],modelMapper:t(l[1]||l[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,l){var s=e+" in "+(l?"$group.items":t);return c&&(s+=" track by "+c),s}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("selectize/choices.tpl.html",'
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",'
    {{$select.placeholder}}
    '),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",'')}]),angular.module("ui.select").run(["$templateCache",function(e){e.put("select2/choices.tpl.html",'
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/dist/select.no-tpl.js b/dist/select.no-tpl.js index 623d024f9..d963045e5 100644 --- a/dist/select.no-tpl.js +++ b/dist/select.no-tpl.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-04T17:24:10.054Z + * Version: 0.12.1 - 2015-08-05T18:50:43.047Z * License: MIT */ @@ -318,7 +318,7 @@ uis.directive('uiSelectChoices', choices.attr('ng-repeat', RepeatParser.getNgRepeatExpression($select.parserResult.itemName, '$select.items', $select.parserResult.trackByExp, groupByExp)) - .attr('ng-if', '$select.open') //Prevent unnecessary watches when dropdown is closed + .attr('ng-if', '$select.open') // Prevent unnecessary watches when dropdown is closed .attr('ng-mouseenter', '$select.setActiveItem(' + $select.parserResult.itemName + ')') .attr('ng-click', '$select.select(' + $select.parserResult.itemName + ',false,$event)'); @@ -360,19 +360,19 @@ uis.controller('uiSelectCtrl', ctrl.searchEnabled = uiSelectConfig.searchEnabled; ctrl.sortable = uiSelectConfig.sortable; - ctrl.removeSelected = false; //If selected item(s) should be removed from dropdown list - ctrl.closeOnSelect = true; //Initialized inside uiSelect directive link function + ctrl.removeSelected = false; // If selected item(s) should be removed from dropdown list + ctrl.closeOnSelect = true; // Initialized inside uiSelect directive link function ctrl.search = EMPTY_SEARCH; - ctrl.activeIndex = 0; //Dropdown of choices - ctrl.items = []; //All available choices + ctrl.activeIndex = 0; // Dropdown of choices + ctrl.items = []; // All available choices ctrl.open = false; ctrl.focus = false; ctrl.disabled = false; ctrl.selected = undefined; - ctrl.focusser = undefined; //Reference to input element used to handle focus events + ctrl.focusser = undefined; // Reference to input element used to handle focus events ctrl.resetSearchInput = true; ctrl.multiple = undefined; // Initialized inside uiSelect directive link function ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelectChoices directive link function @@ -398,7 +398,7 @@ uis.controller('uiSelectCtrl', function _resetSearchInput() { if (ctrl.resetSearchInput || (ctrl.resetSearchInput === undefined && uiSelectConfig.resetSearchInput)) { ctrl.search = EMPTY_SEARCH; - //reset activeIndex + // Reset activeIndex if (ctrl.selected && ctrl.items.length && !ctrl.multiple) { ctrl.activeIndex = ctrl.items.indexOf(ctrl.selected); } @@ -429,24 +429,45 @@ uis.controller('uiSelectCtrl', */ ctrl.activate = function (initSearchValue, avoidReset) { if (!ctrl.disabled && !ctrl.open) { - if (!avoidReset) { - _resetSearchInput(); - } + var completeCallback = function () { + if (!avoidReset) { + _resetSearchInput(); + } - $scope.$broadcast('uis:activate'); + $scope.$broadcast('uis:activate'); - ctrl.open = true; - if (!ctrl.searchEnabled) { - angular.element(ctrl.searchInput[0]).addClass('ui-select-offscreen'); - } + ctrl.open = true; + if (!ctrl.searchEnabled) { + angular.element(ctrl.searchInput[0]).addClass('ui-select-offscreen'); + } - ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex; + ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex; - // Give it time to appear before focus - $timeout(function () { - ctrl.search = initSearchValue || ctrl.search; - ctrl.searchInput[0].focus(); - }); + // Give it time to appear before focus + $timeout(function () { + ctrl.search = initSearchValue || ctrl.search; + ctrl.searchInput[0].focus(); + }); + }; + + var result = ctrl.onDropdownCallback($scope, {open: true}); + if (angular.isDefined(result)) { + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (result) { + if (!result) { + return; + } + completeCallback(); + }); + } else if (result === true) { + completeCallback(); + } else if (result) { + completeCallback(); + } + } else { + completeCallback(); + } } else if (ctrl.open && !ctrl.searchEnabled) { // Close the selection if we don't have search enabled, and we click on the select again @@ -522,10 +543,11 @@ uis.controller('uiSelectCtrl', if (!angular.isArray(items)) { throw uiSelectMinErr('items', "Expected an array but got '{0}'.", items); } else { - //Remove already selected items (ex: while searching) - //TODO Should add a test + // Remove already selected items (ex: while searching) + // TODO Should add a test ctrl.refreshItems(items); - ctrl.ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters + // Force scope model value and ngModel value to be out of sync to re-run formatters + ctrl.ngModel.$modelValue = null; } } }); @@ -544,9 +566,15 @@ uis.controller('uiSelectCtrl', if (!ctrl.open) { return false; } + // Get the index of this item - returns -1 if the item isn't in the current list var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); - var isActive = itemIndex === ctrl.activeIndex; + // Is this the active index? + // If the itemIndex is -1, then the item wasn't in the list so let's ensure we're not active + // otherwise we can end up with all items being selected as active! + var isActive = itemIndex === -1 ? false : itemIndex === ctrl.activeIndex; + + // If this is active, and we've defined a callback, do it! if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { itemScope.$eval(ctrl.onHighlightCallback); } @@ -604,7 +632,8 @@ uis.controller('uiSelectCtrl', // Local method called when we complete the select // eg. called after the onselect callback - var completeSelection = function () { + var completeCallback = function (item) { + callbackContext.$item = item; $scope.$broadcast('uis:select', item); $timeout(function () { @@ -625,23 +654,23 @@ uis.controller('uiSelectCtrl', // promise: Wait for response // true: Complete selection // object: Add the returned object - var onBeforeSelectResult = ctrl.onBeforeSelectCallback($scope, callbackContext); - if (angular.isDefined(onBeforeSelectResult)) { - if (angular.isFunction(onBeforeSelectResult.then)) { + var result = ctrl.onBeforeSelectCallback($scope, callbackContext); + if (angular.isDefined(result)) { + if (angular.isFunction(result.then)) { // Promise returned - wait for it to complete before completing the selection - onBeforeSelectResult.then(function (result) { + result.then(function (result) { if (!result) { return; } - completeSelection(result); + completeCallback(result); }); - } else if (onBeforeSelectResult === true) { - completeSelection(item); - } else if (onBeforeSelectResult) { - completeSelection(onBeforeSelectResult); + } else if (result === true) { + completeCallback(item); + } else if (result) { + completeCallback(result); } } else { - completeSelection(item); + completeCallback(item); } }; @@ -652,16 +681,38 @@ uis.controller('uiSelectCtrl', if (!ctrl.open) { return; } - if (ctrl.ngModel && ctrl.ngModel.$setTouched) { - ctrl.ngModel.$setTouched(); - } - _resetSearchInput(); - ctrl.open = false; - if (!ctrl.searchEnabled) { - angular.element(ctrl.searchInput[0]).removeClass('ui-select-offscreen'); + + function completeCallback() { + if (ctrl.ngModel && ctrl.ngModel.$setTouched) { + ctrl.ngModel.$setTouched(); + } + _resetSearchInput(); + ctrl.open = false; + if (!ctrl.searchEnabled) { + angular.element(ctrl.searchInput[0]).removeClass('ui-select-offscreen'); + } + + $scope.$broadcast('uis:close', skipFocusser); } - $scope.$broadcast('uis:close', skipFocusser); + var result = ctrl.onDropdownCallback($scope, {open: false}); + if (angular.isDefined(result)) { + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (result) { + if (!result) { + return; + } + completeCallback(); + }); + } else if (result === true) { + completeCallback(); + } else if (result) { + completeCallback(); + } + } else { + completeCallback(); + } }; /** @@ -702,8 +753,10 @@ uis.controller('uiSelectCtrl', var isLocked, item = ctrl.selected[itemIndex]; if (item && !angular.isUndefined(ctrl.lockChoiceExpression)) { - isLocked = !!(itemScope.$eval(ctrl.lockChoiceExpression)); // force the boolean value - item._uiSelectChoiceLocked = isLocked; // store this for later reference + // Force the boolean value + isLocked = !!(itemScope.$eval(ctrl.lockChoiceExpression)); + // Store this for later reference + item._uiSelectChoiceLocked = isLocked; } return isLocked; @@ -731,7 +784,8 @@ uis.controller('uiSelectCtrl', }; ctrl.searchInput.css('width', '10px'); - $timeout(function () { //Give time to render correctly + $timeout(function () { + // Give time to render correctly if (sizeWatch === null && !updateIfVisible(calculateContainerWidth())) { sizeWatch = $scope.$watch(calculateContainerWidth, function (containerWidth) { if (updateIfVisible(containerWidth)) { @@ -748,7 +802,8 @@ uis.controller('uiSelectCtrl', switch (key) { case KEY.DOWN: if (!ctrl.open && ctrl.multiple) { - ctrl.activate(false, true); //In case its the search input in 'multiple' mode + // In case its the search input in 'multiple' mode + ctrl.activate(false, true); } else if (ctrl.activeIndex < ctrl.items.length - 1) { ctrl.activeIndex++; @@ -843,7 +898,7 @@ uis.controller('uiSelectCtrl', container[0].scrollTop += posY - height; } else if (posY < highlighted.clientHeight) { if (ctrl.isGrouped && ctrl.activeIndex === 0) { - //To make group header visible when going all the way up + // To make group header visible when going all the way up container[0].scrollTop = 0; } else { @@ -877,14 +932,15 @@ uis.directive('uiSelect', controllerAs: '$select', compile: function (tElement, tAttrs) { - //Multiple or Single depending if multiple attribute presence - if (angular.isDefined(tAttrs.multiple)) + // Multiple or Single depending if multiple attribute presence + if (angular.isDefined(tAttrs.multiple)) { tElement.append("").removeAttr('multiple'); - else + } + else { tElement.append(""); + } return function (scope, element, attrs, ctrls, transcludeFn) { - var $select = ctrls[0]; var ngModel = ctrls[1]; @@ -906,11 +962,12 @@ uis.directive('uiSelect', $select.onRemoveCallback = $parse(attrs.onRemove); $select.onBeforeRemoveCallback = $parse(attrs.onBeforeRemove); $select.onKeypressCallback = $parse(attrs.onKeypress); + $select.onDropdownCallback = $parse(attrs.onDropdown); - //Limit the number of selections allowed + // Limit the number of selections allowed $select.limit = (angular.isDefined(attrs.limit)) ? parseInt(attrs.limit, 10) : undefined; - //Set reference to ngModel from uiSelectCtrl + // Set reference to ngModel from uiSelectCtrl $select.ngModel = ngModel; $select.choiceGrouped = function (group) { @@ -944,7 +1001,7 @@ uis.directive('uiSelect', }); } - //Gets focus based on scope event name (e.g. focus-on='SomeEventName') + // Gets focus based on scope event name (e.g. focus-on='SomeEventName') if (angular.isDefined(attrs.focusOn)) { scope.$on(attrs.focusOn, function () { $timeout(function () { @@ -954,7 +1011,10 @@ uis.directive('uiSelect', } function onDocumentClick(e) { - if (!$select.open) return; //Skip it if dropdown is close + //Skip it if dropdown is close + if (!$select.open) { + return; + } var contains = false; @@ -967,14 +1027,14 @@ uis.directive('uiSelect', } if (!contains && !$select.clickTriggeredSelect) { - //Will lose focus only with certain targets + // Will lose focus only with certain targets var focusableControls = ['input', 'button', 'textarea']; - //To check if target is other ui-select + // To check if target is other ui-select var targetScope = angular.element(e.target).scope(); - //To check if target is other ui-select + // To check if target is other ui-select var skipFocusser = targetScope && targetScope.$select && targetScope.$select !== $select; - //Check if target is input, button or textarea + // Check if target is input, button or textarea if (!skipFocusser) { skipFocusser = ~focusableControls.indexOf(e.target.tagName.toLowerCase()); } @@ -1203,13 +1263,18 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel ctrl.activeMatchIndex = -1; $select.sizeSearchInput(); + // If there's no onBeforeRemove callback, then we're done + if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { + return; + } + var callbackContext = { $item: removedChoice, $model: $select.parserResult.modelMapper($scope, locals) }; // Give some time for scope propagation. - function completeRemoval() { + function completeCallback() { $timeout(function () { $select.onRemoveCallback($scope, callbackContext); }); @@ -1222,21 +1287,21 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel // falsy: Abort the removal // promise: Wait for response // true: Complete removal - var onBeforeRemoveResult = ctrl.onBeforeRemoveCallback($scope, callbackContext); - if (angular.isDefined(onBeforeRemoveResult)) { - if (angular.isFunction(onBeforeRemoveResult.then)) { + var result = ctrl.onBeforeRemoveCallback($scope, callbackContext); + if (angular.isDefined(result)) { + if (angular.isFunction(result.then)) { // Promise returned - wait for it to complete before completing the selection - onBeforeRemoveResult.then(function (result) { + result.then(function (result) { if (!result) { return; } - completeRemoval(result); + completeCallback(result); }); - } else if (onBeforeRemoveResult === true) { - completeRemoval(); + } else if (result === true) { + completeCallback(); } } else { - completeRemoval(); + completeCallback(); } }; @@ -1484,7 +1549,7 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co var $select = ctrls[0]; var ngModel = ctrls[1]; - //From view --> model + // From view --> model ngModel.$parsers.unshift(function (inputValue) { var locals = {}, result; @@ -1493,7 +1558,7 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co return result; }); - //From model --> view + // From model --> view ngModel.$formatters.unshift(function (inputValue) { var data = $select.parserResult.source(scope, {$select: {search: ''}}), //Overwrite $search locals = {}, @@ -1504,7 +1569,7 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co result = $select.parserResult.modelMapper(scope, locals); return result == inputValue; }; - //If possible pass same object stored in $select.selected + // If possible pass same object stored in $select.selected if ($select.selected && checkFnSingle($select.selected)) { return $select.selected; } @@ -1517,7 +1582,7 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co return inputValue; }); - //Update viewValue if model change + // Update viewValue if model change scope.$watch('$select.selected', function (newValue) { if (ngModel.$viewValue !== newValue) { ngModel.$setViewValue(newValue); @@ -1540,15 +1605,16 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co }); scope.$on('uis:activate', function () { - focusser.prop('disabled', true); //Will reactivate it on .close() + // Will reactivate it on .close() + focusser.prop('disabled', true); }); - //Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954 + // Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954 var focusser = angular.element(""); $compile(focusser)(scope); $select.focusser = focusser; - //Input that will handle focus + // Input that will handle focus $select.focusInput = focusser; element.parent().append(focusser); @@ -1562,8 +1628,8 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co $select.focus = false; }); }); - focusser.bind("keydown", function (e) { + focusser.bind("keydown", function (e) { if (e.which === KEY.BACKSPACE) { e.preventDefault(); e.stopPropagation(); @@ -1586,13 +1652,13 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co }); focusser.bind("keyup input", function (e) { - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { return; } - $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input + // User pressed some regular key, so we pass it to the search input + $select.activate(focusser.val()); focusser.val(''); scope.$digest(); }); diff --git a/dist/select.no-tpl.min.js b/dist/select.no-tpl.min.js index 25bbe1be5..4367507b5 100644 --- a/dist/select.no-tpl.min.js +++ b/dist/select.no-tpl.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-04T17:24:10.054Z + * Version: 0.12.1 - 2015-08-05T18:50:43.047Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var n=t.which;switch(n){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,n=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,r,i){i(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var r=n[0].getBoundingClientRect();return{width:r.width||n.prop("offsetWidth"),height:r.height||n.prop("offsetHeight"),top:r.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:r.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);n.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,r){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,i){if(!i.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,i,c,l,o){var a=c.groupBy,s=c.groupFilter;if(l.parseRepeatAttr(c.repeat,a,s),l.disableChoiceExpression=c.uiDisableChoice,l.onHighlightCallback=c.onHighlight,a){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=i.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(l.parserResult.itemName,"$select.items",l.parserResult.trackByExp,a)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+l.parserResult.itemName+")").attr("ng-click","$select.select("+l.parserResult.itemName+",false,$event)");var f=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==f.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",f.length);f.attr("uis-transclude-append",""),r(i,o)(e),e.$watch("$select.search",function(e){e&&!l.open&&l.multiple&&l.activate(!1,!0),l.activeIndex=0})}}}}]),n.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,n,r,i,c,l,o,a){function s(){(d.resetSearchInput||void 0===d.resetSearchInput&&a.resetSearchInput)&&(d.search=h,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function u(e,t){var n,r,i=[];for(n=0;n0&&d.activeIndex--;break;case e.TAB:(!d.multiple||d.open)&&d.select(d.items[d.activeIndex],!0);break;case e.ENTER:d.open?d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case e.ESC:d.close();break;default:n=!1}return n}function f(){var e=n.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw o("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(d.activeIndex<0)){var r=t[d.activeIndex],i=r.offsetTop+r.clientHeight-e[0].scrollTop,c=e[0].offsetHeight;i>c?e[0].scrollTop+=i-c:i=d.items.length?0:d.activeIndex,r(function(){d.search=e||d.search,d.searchInput[0].focus()}))},d.parseRepeatAttr=function(e,n,r){function i(e){var i=t.$eval(n);if(d.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(i)?i(e):e[i],n=d.findGroupByName(t);n?n.items.push(e):d.groups.push({name:t,items:[e]})}),r){var c=t.$eval(r);angular.isFunction(c)?d.groups=c(d.groups):angular.isArray(c)&&(d.groups=u(d.groups,c))}d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function c(e){d.items=e}d.setItemsFn=n?i:c,d.parserResult=l.parse(e),d.isGrouped=!!n,d.itemProperty=d.parserResult.itemName,d.refreshItems=function(e){e=e||d.parserResult.source(t);var n=d.selected;if(d.isEmpty()||angular.isArray(n)&&!n.length||!d.removeSelected)d.setItemsFn(e);else if(void 0!==e){var r=e.filter(function(e){return n.indexOf(e)<0});d.setItemsFn(r)}},t.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw o("items","Expected an array but got '{0}'.",e);d.refreshItems(e),d.ngModel.$modelValue=null}})},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){if(!d.open)return!1;var t=d.items.indexOf(e[d.itemProperty]),n=t===d.activeIndex;return n&&!angular.isUndefined(d.onHighlightCallback)&&e.$eval(d.onHighlightCallback),n},d.isDisabled=function(e){if(!d.open)return!1;var t,n=d.items.indexOf(e[d.itemProperty]),r=!1;return n>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[n],r=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=r),r},d.select=function(e,n,i){if((void 0===e||!e._uiSelectChoiceDisabled)&&(d.items||d.search)){var c={};c[d.parserResult.itemName]=e;var l={$item:e,$model:d.parserResult.modelMapper(t,c)},o=function(){t.$broadcast("uis:select",e),r(function(){d.onSelectCallback(t,l)}),d.closeOnSelect&&d.close(n),i&&"click"===i.type&&(d.clickTriggeredSelect=!0)},a=d.onBeforeSelectCallback(t,l);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(e){e&&o(e)}):a===!0?o(e):a&&o(a):o(e)}},d.close=function(e){d.open&&(d.ngModel&&d.ngModel.$setTouched&&d.ngModel.$setTouched(),s(),d.open=!1,d.searchEnabled||angular.element(d.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e))},d.setFocus=function(){d.focus||d.focusInput[0].focus()},d.clear=function(e){d.select(void 0),e.stopPropagation(),r(function(){d.focusser[0].focus()},0,!1)},d.toggle=function(e){d.open?(d.close(),e.preventDefault(),e.stopPropagation()):d.activate()},d.isLocked=function(e,t){var n,r=d.selected[t];return r&&!angular.isUndefined(d.lockChoiceExpression)&&(n=!!e.$eval(d.lockChoiceExpression),r._uiSelectChoiceLocked=n),n};var v=null;d.sizeSearchInput=function(){var e=d.searchInput[0],n=d.searchInput.parent().parent()[0],i=function(){return n.clientWidth*!!e.offsetParent},c=function(t){if(0===t)return!1;var n=t-e.offsetLeft-d.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=t),d.searchInput.css("width",n+"px"),!0};d.searchInput.css("width","10px"),r(function(){null!==v||c(i())||(v=t.$watch(i,function(e){c(e)&&(v(),v=null)}))})},d.searchInput.on("keydown",function(n){var r=n.which;t.$apply(function(){p(r)}),e.isVerticalMovement(r)&&d.items.length>0&&f(),(r===e.ENTER||r===e.ESC)&&(n.preventDefault(),n.stopPropagation())}),d.searchInput.on("keyup",function(n){n.which===e.TAB||e.isControl(n)||e.isFunctionKey(n)||n.which===e.ESC||e.isVerticalMovement(n.which)||void 0!==d.onKeypressCallback&&d.onKeypressCallback(t,{event:n})}),t.$on("$destroy",function(){d.searchInput.off("keyup keydown blur paste")})}]),n.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,r,i,c,l){return{restrict:"EA",templateUrl:function(e,n){var r=n.theme||t.theme;return r+(angular.isDefined(n.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(i,o){return angular.isDefined(o.multiple)?i.append("").removeAttr("multiple"):i.append(""),function(i,o,a,s,u){function p(e){if(h.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(o[0],e.target):o[0].contains(e.target),!t&&!h.clickTriggeredSelect){var n=["input","button","textarea"],r=angular.element(e.target).scope(),c=r&&r.$select&&r.$select!==h;c||(c=~n.indexOf(e.target.tagName.toLowerCase())),h.close(c),i.$digest()}h.clickTriggeredSelect=!1}}function f(){var t=r(o);$=angular.element('
    '),$[0].style.width=t.width+"px",$[0].style.height=t.height+"px",o.after($),S=o[0].style.width,e.find("body").append(o),o[0].style.position="absolute",o[0].style.left=t.left+"px",o[0].style.top=t.top+"px",o[0].style.width=t.width+"px"}function d(){null!==$&&($.replaceWith(o),$=null,o[0].style.position="",o[0].style.left="",o[0].style.top="",o[0].style.width=S)}var h=s[0],v=s[1];h.generatedId=t.generateId(),h.baseTitle=a.title||"Select box",h.focusserTitle=h.baseTitle+" focus",h.focusserId="focusser-"+h.generatedId,h.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?c(a.closeOnSelect)():t.closeOnSelect}(),h.onSelectCallback=c(a.onSelect),h.onBeforeSelectCallback=c(a.onBeforeSelect),h.onRemoveCallback=c(a.onRemove),h.onBeforeRemoveCallback=c(a.onBeforeRemove),h.onKeypressCallback=c(a.onKeypress),h.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,h.ngModel=v,h.choiceGrouped=function(e){return h.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){h.focusInput.attr("tabindex",e),o.removeAttr("tabindex")});var m=i.$eval(a.searchEnabled);h.searchEnabled=void 0!==m?m:t.searchEnabled;var g=i.$eval(a.sortable);h.sortable=void 0!==g?g:t.sortable,a.$observe("disabled",function(){h.disabled=void 0!==a.disabled?a.disabled:!1}),angular.isDefined(a.autofocus)&&l(function(){h.setFocus()}),angular.isDefined(a.focusOn)&&i.$on(a.focusOn,function(){l(function(){h.setFocus()})}),e.on("click",p),i.$on("$destroy",function(){e.off("click",p)}),u(i,function(e){var t=angular.element("
    ").append(e),r=t.querySelectorAll(".ui-select-match");if(r.removeAttr("ui-select-match"),r.removeAttr("data-ui-select-match"),1!==r.length)throw n("transcluded","Expected 1 .ui-select-match but got '{0}'.",r.length);o.querySelectorAll(".ui-select-match").replaceWith(r);var i=t.querySelectorAll(".ui-select-choices");if(i.removeAttr("ui-select-choices"),i.removeAttr("data-ui-select-choices"),1!==i.length)throw n("transcluded","Expected 1 .ui-select-choices but got '{0}'.",i.length);o.querySelectorAll(".ui-select-choices").replaceWith(i)});var E=i.$eval(a.appendToBody);(void 0!==E?E:t.appendToBody)&&(i.$watch("$select.open",function(e){e?f():d()}),i.$on("$destroy",function(){d()}));var $=null,S="",b=null,C="direction-up";i.$watch("$select.open",function(t){if(t){if(b=angular.element(o).querySelectorAll(".ui-select-dropdown"),null===b)return;b[0].style.opacity=0,l(function(){var t=r(o),n=r(b);t.top+t.height+n.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&o.addClass(C),b[0].style.opacity=1})}else{if(null===b)return;o.removeClass(C)}})}}}}]),n.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,r=t.parent().attr("multiple");return n+(r?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,r,i){function c(e){i.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}i.lockChoiceExpression=r.uiLockChoice,r.$observe("placeholder",function(t){i.placeholder=void 0!==t?t:e.placeholder}),r.$observe("allowClear",c),c(r.allowClear),i.multiple&&i.sizeSearchInput()}}}]),n.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,r=this,i=e.$select;e.$evalAsync(function(){n=e.ngModel}),r.activeMatchIndex=-1,r.updateModel=function(){n.$setViewValue(Date.now()),r.refreshComponent()},r.refreshComponent=function(){i.refreshItems(),i.sizeSearchInput()},r.removeChoice=function(n){function c(){t(function(){i.onRemoveCallback(e,a)}),r.updateModel()}var l=i.selected[n];if(!l._uiSelectChoiceLocked){var o={};o[i.parserResult.itemName]=l,i.selected.splice(n,1),r.activeMatchIndex=-1,i.sizeSearchInput();var a={$item:l,$model:i.parserResult.modelMapper(e,o)},s=r.onBeforeRemoveCallback(e,a);angular.isDefined(s)?angular.isFunction(s.then)?s.then(function(e){e&&c(e)}):s===!0&&c():c()}},r.getPlaceholder=function(){return i.selected&&i.selected.length?void 0:i.placeholder}}],controllerAs:"$selectMultiple",link:function(r,i,c,l){function o(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(t){function n(){switch(t){case e.LEFT:return~p.activeMatchIndex?f:l;case e.RIGHT:return~p.activeMatchIndex&&a!==l?u:(s.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(a),f):l;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),a):!1}}var r=o(s.searchInput[0]),i=s.selected.length,c=0,l=i-1,a=p.activeMatchIndex,u=p.activeMatchIndex+1,f=p.activeMatchIndex-1,d=a;return r>0||s.search.length&&t==e.RIGHT?!1:(s.close(),d=n(),p.activeMatchIndex=s.selected.length&&d!==!1?Math.min(l,Math.max(c,d)):-1,!0)}var s=l[0],u=r.ngModel=l[1],p=r.$selectMultiple;s.multiple=!0,s.removeSelected=!0,s.focusInput=s.searchInput,u.$parsers.unshift(function(){for(var e,t={},n=[],i=s.selected.length-1;i>=0;i--)t={},t[s.parserResult.itemName]=s.selected[i],e=s.parserResult.modelMapper(r,t),n.unshift(e);return n}),u.$formatters.unshift(function(e){var t,n=s.parserResult.source(r,{$select:{search:""}}),i={};if(!n)return e;var c=[],l=function(e,n){if(e&&e.length){for(var l=e.length-1;l>=0;l--){if(i[s.parserResult.itemName]=e[l],t=s.parserResult.modelMapper(r,i),s.parserResult.trackByExp){var o=/\.(.+)/.exec(s.parserResult.trackByExp);if(o.length>0&&t[o[1]]==n[o[1]])return c.unshift(e[l]),!0}if(angular.equals(t,n))return c.unshift(e[l]),!0}return!1}};if(!e)return c;for(var o=e.length-1;o>=0;o--)l(s.selected,e[o])||l(n,e[o])||c.unshift(e[o]);return c}),r.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);s.selected=[]}s.selected=u.$viewValue,r.$evalAsync()},r.$on("uis:select",function(e,t){s.selected.length>=s.limit||(s.selected.push(t),p.updateModel())}),r.$on("uis:activate",function(){p.activeMatchIndex=-1}),r.$watch("$select.disabled",function(e,t){t&&!e&&s.sizeSearchInput()}),s.searchInput.on("keydown",function(t){var n=t.which;r.$apply(function(){var t=!1;e.isHorizontalMovement(n)&&(t=a(n)),t&&n!=e.TAB})}),s.searchInput.on("blur",function(){n(function(){p.activeMatchIndex=-1})})}}}]),n.directive("uiSelectSingle",["$timeout","$compile",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(r,i,c,l){var o=l[0],a=l[1];a.$parsers.unshift(function(e){var t,n={};return n[o.parserResult.itemName]=e,t=o.parserResult.modelMapper(r,n)}),a.$formatters.unshift(function(e){var t,n=o.parserResult.source(r,{$select:{search:""}}),i={};if(n){var c=function(n){return i[o.parserResult.itemName]=n,t=o.parserResult.modelMapper(r,i),t==e};if(o.selected&&c(o.selected))return o.selected;for(var l=n.length-1;l>=0;l--)if(c(n[l]))return n[l]}return e}),r.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){o.selected=a.$viewValue},r.$on("uis:select",function(e,t){o.selected=t}),r.$on("uis:close",function(e,n){t(function(){o.focusser.prop("disabled",!1),n||o.focusser[0].focus()},0,!1)}),r.$on("uis:activate",function(){s.prop("disabled",!0)});var s=angular.element("");n(s)(r),o.focusser=s,o.focusInput=s,i.parent().append(s),s.bind("focus",function(){r.$evalAsync(function(){o.focus=!0})}),s.bind("blur",function(){r.$evalAsync(function(){o.focus=!1})}),s.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),o.select(void 0),r.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),o.activate()),r.$digest()),void 0)}),s.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(o.activate(s.val()),s.val(""),r.$digest())})}}}]),n.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var r=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!r)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:r[2],source:t(r[3]),trackByExp:r[4],modelMapper:t(r[1]||r[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,r){var i=e+" in "+(r?"$group.items":t);return n&&(i+=" track by "+n),i}}])}(); \ No newline at end of file +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var n=t.which;switch(n){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,n=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,r,i){i(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var r=n[0].getBoundingClientRect();return{width:r.width||n.prop("offsetWidth"),height:r.height||n.prop("offsetHeight"),top:r.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:r.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);n.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,r){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,i){if(!i.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,i,c,l,o){var a=c.groupBy,s=c.groupFilter;if(l.parseRepeatAttr(c.repeat,a,s),l.disableChoiceExpression=c.uiDisableChoice,l.onHighlightCallback=c.onHighlight,a){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=i.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(l.parserResult.itemName,"$select.items",l.parserResult.trackByExp,a)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+l.parserResult.itemName+")").attr("ng-click","$select.select("+l.parserResult.itemName+",false,$event)");var f=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==f.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",f.length);f.attr("uis-transclude-append",""),r(i,o)(e),e.$watch("$select.search",function(e){e&&!l.open&&l.multiple&&l.activate(!1,!0),l.activeIndex=0})}}}}]),n.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,n,r,i,c,l,o,a){function s(){(d.resetSearchInput||void 0===d.resetSearchInput&&a.resetSearchInput)&&(d.search=h,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function u(e,t){var n,r,i=[];for(n=0;n0&&d.activeIndex--;break;case e.TAB:(!d.multiple||d.open)&&d.select(d.items[d.activeIndex],!0);break;case e.ENTER:d.open?d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case e.ESC:d.close();break;default:n=!1}return n}function f(){var e=n.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw o("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(d.activeIndex<0)){var r=t[d.activeIndex],i=r.offsetTop+r.clientHeight-e[0].scrollTop,c=e[0].offsetHeight;i>c?e[0].scrollTop+=i-c:i=d.items.length?0:d.activeIndex,r(function(){d.search=e||d.search,d.searchInput[0].focus()})},c=d.onDropdownCallback(t,{open:!0});angular.isDefined(c)?angular.isFunction(c.then)?c.then(function(e){e&&i()}):c===!0?i():c&&i():i()}},d.parseRepeatAttr=function(e,n,r){function i(e){var i=t.$eval(n);if(d.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(i)?i(e):e[i],n=d.findGroupByName(t);n?n.items.push(e):d.groups.push({name:t,items:[e]})}),r){var c=t.$eval(r);angular.isFunction(c)?d.groups=c(d.groups):angular.isArray(c)&&(d.groups=u(d.groups,c))}d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function c(e){d.items=e}d.setItemsFn=n?i:c,d.parserResult=l.parse(e),d.isGrouped=!!n,d.itemProperty=d.parserResult.itemName,d.refreshItems=function(e){e=e||d.parserResult.source(t);var n=d.selected;if(d.isEmpty()||angular.isArray(n)&&!n.length||!d.removeSelected)d.setItemsFn(e);else if(void 0!==e){var r=e.filter(function(e){return n.indexOf(e)<0});d.setItemsFn(r)}},t.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw o("items","Expected an array but got '{0}'.",e);d.refreshItems(e),d.ngModel.$modelValue=null}})},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){if(!d.open)return!1;var t=d.items.indexOf(e[d.itemProperty]),n=-1===t?!1:t===d.activeIndex;return n&&!angular.isUndefined(d.onHighlightCallback)&&e.$eval(d.onHighlightCallback),n},d.isDisabled=function(e){if(!d.open)return!1;var t,n=d.items.indexOf(e[d.itemProperty]),r=!1;return n>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[n],r=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=r),r},d.select=function(e,n,i){if((void 0===e||!e._uiSelectChoiceDisabled)&&(d.items||d.search)){var c={};c[d.parserResult.itemName]=e;var l={$item:e,$model:d.parserResult.modelMapper(t,c)},o=function(e){l.$item=e,t.$broadcast("uis:select",e),r(function(){d.onSelectCallback(t,l)}),d.closeOnSelect&&d.close(n),i&&"click"===i.type&&(d.clickTriggeredSelect=!0)},a=d.onBeforeSelectCallback(t,l);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(e){e&&o(e)}):a===!0?o(e):a&&o(a):o(e)}},d.close=function(e){function n(){d.ngModel&&d.ngModel.$setTouched&&d.ngModel.$setTouched(),s(),d.open=!1,d.searchEnabled||angular.element(d.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e)}if(d.open){var r=d.onDropdownCallback(t,{open:!1});angular.isDefined(r)?angular.isFunction(r.then)?r.then(function(e){e&&n()}):r===!0?n():r&&n():n()}},d.setFocus=function(){d.focus||d.focusInput[0].focus()},d.clear=function(e){d.select(void 0),e.stopPropagation(),r(function(){d.focusser[0].focus()},0,!1)},d.toggle=function(e){d.open?(d.close(),e.preventDefault(),e.stopPropagation()):d.activate()},d.isLocked=function(e,t){var n,r=d.selected[t];return r&&!angular.isUndefined(d.lockChoiceExpression)&&(n=!!e.$eval(d.lockChoiceExpression),r._uiSelectChoiceLocked=n),n};var v=null;d.sizeSearchInput=function(){var e=d.searchInput[0],n=d.searchInput.parent().parent()[0],i=function(){return n.clientWidth*!!e.offsetParent},c=function(t){if(0===t)return!1;var n=t-e.offsetLeft-d.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=t),d.searchInput.css("width",n+"px"),!0};d.searchInput.css("width","10px"),r(function(){null!==v||c(i())||(v=t.$watch(i,function(e){c(e)&&(v(),v=null)}))})},d.searchInput.on("keydown",function(n){var r=n.which;t.$apply(function(){p(r)}),e.isVerticalMovement(r)&&d.items.length>0&&f(),(r===e.ENTER||r===e.ESC)&&(n.preventDefault(),n.stopPropagation())}),d.searchInput.on("keyup",function(n){n.which===e.TAB||e.isControl(n)||e.isFunctionKey(n)||n.which===e.ESC||e.isVerticalMovement(n.which)||void 0!==d.onKeypressCallback&&d.onKeypressCallback(t,{event:n})}),t.$on("$destroy",function(){d.searchInput.off("keyup keydown blur paste")})}]),n.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,r,i,c,l){return{restrict:"EA",templateUrl:function(e,n){var r=n.theme||t.theme;return r+(angular.isDefined(n.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(i,o){return angular.isDefined(o.multiple)?i.append("").removeAttr("multiple"):i.append(""),function(i,o,a,s,u){function p(e){if(h.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(o[0],e.target):o[0].contains(e.target),!t&&!h.clickTriggeredSelect){var n=["input","button","textarea"],r=angular.element(e.target).scope(),c=r&&r.$select&&r.$select!==h;c||(c=~n.indexOf(e.target.tagName.toLowerCase())),h.close(c),i.$digest()}h.clickTriggeredSelect=!1}}function f(){var t=r(o);E=angular.element('
    '),E[0].style.width=t.width+"px",E[0].style.height=t.height+"px",o.after(E),S=o[0].style.width,e.find("body").append(o),o[0].style.position="absolute",o[0].style.left=t.left+"px",o[0].style.top=t.top+"px",o[0].style.width=t.width+"px"}function d(){null!==E&&(E.replaceWith(o),E=null,o[0].style.position="",o[0].style.left="",o[0].style.top="",o[0].style.width=S)}var h=s[0],v=s[1];h.generatedId=t.generateId(),h.baseTitle=a.title||"Select box",h.focusserTitle=h.baseTitle+" focus",h.focusserId="focusser-"+h.generatedId,h.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?c(a.closeOnSelect)():t.closeOnSelect}(),h.onSelectCallback=c(a.onSelect),h.onBeforeSelectCallback=c(a.onBeforeSelect),h.onRemoveCallback=c(a.onRemove),h.onBeforeRemoveCallback=c(a.onBeforeRemove),h.onKeypressCallback=c(a.onKeypress),h.onDropdownCallback=c(a.onDropdown),h.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,h.ngModel=v,h.choiceGrouped=function(e){return h.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){h.focusInput.attr("tabindex",e),o.removeAttr("tabindex")});var m=i.$eval(a.searchEnabled);h.searchEnabled=void 0!==m?m:t.searchEnabled;var g=i.$eval(a.sortable);h.sortable=void 0!==g?g:t.sortable,a.$observe("disabled",function(){h.disabled=void 0!==a.disabled?a.disabled:!1}),angular.isDefined(a.autofocus)&&l(function(){h.setFocus()}),angular.isDefined(a.focusOn)&&i.$on(a.focusOn,function(){l(function(){h.setFocus()})}),e.on("click",p),i.$on("$destroy",function(){e.off("click",p)}),u(i,function(e){var t=angular.element("
    ").append(e),r=t.querySelectorAll(".ui-select-match");if(r.removeAttr("ui-select-match"),r.removeAttr("data-ui-select-match"),1!==r.length)throw n("transcluded","Expected 1 .ui-select-match but got '{0}'.",r.length);o.querySelectorAll(".ui-select-match").replaceWith(r);var i=t.querySelectorAll(".ui-select-choices");if(i.removeAttr("ui-select-choices"),i.removeAttr("data-ui-select-choices"),1!==i.length)throw n("transcluded","Expected 1 .ui-select-choices but got '{0}'.",i.length);o.querySelectorAll(".ui-select-choices").replaceWith(i)});var $=i.$eval(a.appendToBody);(void 0!==$?$:t.appendToBody)&&(i.$watch("$select.open",function(e){e?f():d()}),i.$on("$destroy",function(){d()}));var E=null,S="",b=null,C="direction-up";i.$watch("$select.open",function(t){if(t){if(b=angular.element(o).querySelectorAll(".ui-select-dropdown"),null===b)return;b[0].style.opacity=0,l(function(){var t=r(o),n=r(b);t.top+t.height+n.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&o.addClass(C),b[0].style.opacity=1})}else{if(null===b)return;o.removeClass(C)}})}}}}]),n.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,r=t.parent().attr("multiple");return n+(r?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,r,i){function c(e){i.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}i.lockChoiceExpression=r.uiLockChoice,r.$observe("placeholder",function(t){i.placeholder=void 0!==t?t:e.placeholder}),r.$observe("allowClear",c),c(r.allowClear),i.multiple&&i.sizeSearchInput()}}}]),n.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,r=this,i=e.$select;e.$evalAsync(function(){n=e.ngModel}),r.activeMatchIndex=-1,r.updateModel=function(){n.$setViewValue(Date.now()),r.refreshComponent()},r.refreshComponent=function(){i.refreshItems(),i.sizeSearchInput()},r.removeChoice=function(n){function c(){t(function(){i.onRemoveCallback(e,a)}),r.updateModel()}var l=i.selected[n];if(!l._uiSelectChoiceLocked){var o={};if(o[i.parserResult.itemName]=l,i.selected.splice(n,1),r.activeMatchIndex=-1,i.sizeSearchInput(),angular.isDefined(r.onBeforeRemoveCallback)){var a={$item:l,$model:i.parserResult.modelMapper(e,o)},s=r.onBeforeRemoveCallback(e,a);angular.isDefined(s)?angular.isFunction(s.then)?s.then(function(e){e&&c(e)}):s===!0&&c():c()}}},r.getPlaceholder=function(){return i.selected&&i.selected.length?void 0:i.placeholder}}],controllerAs:"$selectMultiple",link:function(r,i,c,l){function o(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(t){function n(){switch(t){case e.LEFT:return~p.activeMatchIndex?f:l;case e.RIGHT:return~p.activeMatchIndex&&a!==l?u:(s.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(a),f):l;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),a):!1}}var r=o(s.searchInput[0]),i=s.selected.length,c=0,l=i-1,a=p.activeMatchIndex,u=p.activeMatchIndex+1,f=p.activeMatchIndex-1,d=a;return r>0||s.search.length&&t==e.RIGHT?!1:(s.close(),d=n(),p.activeMatchIndex=s.selected.length&&d!==!1?Math.min(l,Math.max(c,d)):-1,!0)}var s=l[0],u=r.ngModel=l[1],p=r.$selectMultiple;s.multiple=!0,s.removeSelected=!0,s.focusInput=s.searchInput,u.$parsers.unshift(function(){for(var e,t={},n=[],i=s.selected.length-1;i>=0;i--)t={},t[s.parserResult.itemName]=s.selected[i],e=s.parserResult.modelMapper(r,t),n.unshift(e);return n}),u.$formatters.unshift(function(e){var t,n=s.parserResult.source(r,{$select:{search:""}}),i={};if(!n)return e;var c=[],l=function(e,n){if(e&&e.length){for(var l=e.length-1;l>=0;l--){if(i[s.parserResult.itemName]=e[l],t=s.parserResult.modelMapper(r,i),s.parserResult.trackByExp){var o=/\.(.+)/.exec(s.parserResult.trackByExp);if(o.length>0&&t[o[1]]==n[o[1]])return c.unshift(e[l]),!0}if(angular.equals(t,n))return c.unshift(e[l]),!0}return!1}};if(!e)return c;for(var o=e.length-1;o>=0;o--)l(s.selected,e[o])||l(n,e[o])||c.unshift(e[o]);return c}),r.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);s.selected=[]}s.selected=u.$viewValue,r.$evalAsync()},r.$on("uis:select",function(e,t){s.selected.length>=s.limit||(s.selected.push(t),p.updateModel())}),r.$on("uis:activate",function(){p.activeMatchIndex=-1}),r.$watch("$select.disabled",function(e,t){t&&!e&&s.sizeSearchInput()}),s.searchInput.on("keydown",function(t){var n=t.which;r.$apply(function(){var t=!1;e.isHorizontalMovement(n)&&(t=a(n)),t&&n!=e.TAB})}),s.searchInput.on("blur",function(){n(function(){p.activeMatchIndex=-1})})}}}]),n.directive("uiSelectSingle",["$timeout","$compile",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(r,i,c,l){var o=l[0],a=l[1];a.$parsers.unshift(function(e){var t,n={};return n[o.parserResult.itemName]=e,t=o.parserResult.modelMapper(r,n)}),a.$formatters.unshift(function(e){var t,n=o.parserResult.source(r,{$select:{search:""}}),i={};if(n){var c=function(n){return i[o.parserResult.itemName]=n,t=o.parserResult.modelMapper(r,i),t==e};if(o.selected&&c(o.selected))return o.selected;for(var l=n.length-1;l>=0;l--)if(c(n[l]))return n[l]}return e}),r.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){o.selected=a.$viewValue},r.$on("uis:select",function(e,t){o.selected=t}),r.$on("uis:close",function(e,n){t(function(){o.focusser.prop("disabled",!1),n||o.focusser[0].focus()},0,!1)}),r.$on("uis:activate",function(){s.prop("disabled",!0)});var s=angular.element("");n(s)(r),o.focusser=s,o.focusInput=s,i.parent().append(s),s.bind("focus",function(){r.$evalAsync(function(){o.focus=!0})}),s.bind("blur",function(){r.$evalAsync(function(){o.focus=!1})}),s.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),o.select(void 0),r.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),o.activate()),r.$digest()),void 0)}),s.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(o.activate(s.val()),s.val(""),r.$digest())})}}}]),n.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var r=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!r)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:r[2],source:t(r[3]),trackByExp:r[4],modelMapper:t(r[1]||r[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,r){var i=e+" in "+(r?"$group.items":t);return n&&(i+=" track by "+n),i}}])}(); \ No newline at end of file diff --git a/dist/select.select2.js b/dist/select.select2.js index 75952de02..f5ab144b9 100644 --- a/dist/select.select2.js +++ b/dist/select.select2.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-04T17:24:10.068Z + * Version: 0.12.1 - 2015-08-05T18:50:43.070Z * License: MIT */ @@ -318,7 +318,7 @@ uis.directive('uiSelectChoices', choices.attr('ng-repeat', RepeatParser.getNgRepeatExpression($select.parserResult.itemName, '$select.items', $select.parserResult.trackByExp, groupByExp)) - .attr('ng-if', '$select.open') //Prevent unnecessary watches when dropdown is closed + .attr('ng-if', '$select.open') // Prevent unnecessary watches when dropdown is closed .attr('ng-mouseenter', '$select.setActiveItem(' + $select.parserResult.itemName + ')') .attr('ng-click', '$select.select(' + $select.parserResult.itemName + ',false,$event)'); @@ -360,19 +360,19 @@ uis.controller('uiSelectCtrl', ctrl.searchEnabled = uiSelectConfig.searchEnabled; ctrl.sortable = uiSelectConfig.sortable; - ctrl.removeSelected = false; //If selected item(s) should be removed from dropdown list - ctrl.closeOnSelect = true; //Initialized inside uiSelect directive link function + ctrl.removeSelected = false; // If selected item(s) should be removed from dropdown list + ctrl.closeOnSelect = true; // Initialized inside uiSelect directive link function ctrl.search = EMPTY_SEARCH; - ctrl.activeIndex = 0; //Dropdown of choices - ctrl.items = []; //All available choices + ctrl.activeIndex = 0; // Dropdown of choices + ctrl.items = []; // All available choices ctrl.open = false; ctrl.focus = false; ctrl.disabled = false; ctrl.selected = undefined; - ctrl.focusser = undefined; //Reference to input element used to handle focus events + ctrl.focusser = undefined; // Reference to input element used to handle focus events ctrl.resetSearchInput = true; ctrl.multiple = undefined; // Initialized inside uiSelect directive link function ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelectChoices directive link function @@ -398,7 +398,7 @@ uis.controller('uiSelectCtrl', function _resetSearchInput() { if (ctrl.resetSearchInput || (ctrl.resetSearchInput === undefined && uiSelectConfig.resetSearchInput)) { ctrl.search = EMPTY_SEARCH; - //reset activeIndex + // Reset activeIndex if (ctrl.selected && ctrl.items.length && !ctrl.multiple) { ctrl.activeIndex = ctrl.items.indexOf(ctrl.selected); } @@ -429,24 +429,45 @@ uis.controller('uiSelectCtrl', */ ctrl.activate = function (initSearchValue, avoidReset) { if (!ctrl.disabled && !ctrl.open) { - if (!avoidReset) { - _resetSearchInput(); - } + var completeCallback = function () { + if (!avoidReset) { + _resetSearchInput(); + } - $scope.$broadcast('uis:activate'); + $scope.$broadcast('uis:activate'); - ctrl.open = true; - if (!ctrl.searchEnabled) { - angular.element(ctrl.searchInput[0]).addClass('ui-select-offscreen'); - } + ctrl.open = true; + if (!ctrl.searchEnabled) { + angular.element(ctrl.searchInput[0]).addClass('ui-select-offscreen'); + } - ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex; + ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex; - // Give it time to appear before focus - $timeout(function () { - ctrl.search = initSearchValue || ctrl.search; - ctrl.searchInput[0].focus(); - }); + // Give it time to appear before focus + $timeout(function () { + ctrl.search = initSearchValue || ctrl.search; + ctrl.searchInput[0].focus(); + }); + }; + + var result = ctrl.onDropdownCallback($scope, {open: true}); + if (angular.isDefined(result)) { + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (result) { + if (!result) { + return; + } + completeCallback(); + }); + } else if (result === true) { + completeCallback(); + } else if (result) { + completeCallback(); + } + } else { + completeCallback(); + } } else if (ctrl.open && !ctrl.searchEnabled) { // Close the selection if we don't have search enabled, and we click on the select again @@ -522,10 +543,11 @@ uis.controller('uiSelectCtrl', if (!angular.isArray(items)) { throw uiSelectMinErr('items', "Expected an array but got '{0}'.", items); } else { - //Remove already selected items (ex: while searching) - //TODO Should add a test + // Remove already selected items (ex: while searching) + // TODO Should add a test ctrl.refreshItems(items); - ctrl.ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters + // Force scope model value and ngModel value to be out of sync to re-run formatters + ctrl.ngModel.$modelValue = null; } } }); @@ -544,9 +566,15 @@ uis.controller('uiSelectCtrl', if (!ctrl.open) { return false; } + // Get the index of this item - returns -1 if the item isn't in the current list var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); - var isActive = itemIndex === ctrl.activeIndex; + // Is this the active index? + // If the itemIndex is -1, then the item wasn't in the list so let's ensure we're not active + // otherwise we can end up with all items being selected as active! + var isActive = itemIndex === -1 ? false : itemIndex === ctrl.activeIndex; + + // If this is active, and we've defined a callback, do it! if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { itemScope.$eval(ctrl.onHighlightCallback); } @@ -604,7 +632,8 @@ uis.controller('uiSelectCtrl', // Local method called when we complete the select // eg. called after the onselect callback - var completeSelection = function () { + var completeCallback = function (item) { + callbackContext.$item = item; $scope.$broadcast('uis:select', item); $timeout(function () { @@ -625,23 +654,23 @@ uis.controller('uiSelectCtrl', // promise: Wait for response // true: Complete selection // object: Add the returned object - var onBeforeSelectResult = ctrl.onBeforeSelectCallback($scope, callbackContext); - if (angular.isDefined(onBeforeSelectResult)) { - if (angular.isFunction(onBeforeSelectResult.then)) { + var result = ctrl.onBeforeSelectCallback($scope, callbackContext); + if (angular.isDefined(result)) { + if (angular.isFunction(result.then)) { // Promise returned - wait for it to complete before completing the selection - onBeforeSelectResult.then(function (result) { + result.then(function (result) { if (!result) { return; } - completeSelection(result); + completeCallback(result); }); - } else if (onBeforeSelectResult === true) { - completeSelection(item); - } else if (onBeforeSelectResult) { - completeSelection(onBeforeSelectResult); + } else if (result === true) { + completeCallback(item); + } else if (result) { + completeCallback(result); } } else { - completeSelection(item); + completeCallback(item); } }; @@ -652,16 +681,38 @@ uis.controller('uiSelectCtrl', if (!ctrl.open) { return; } - if (ctrl.ngModel && ctrl.ngModel.$setTouched) { - ctrl.ngModel.$setTouched(); - } - _resetSearchInput(); - ctrl.open = false; - if (!ctrl.searchEnabled) { - angular.element(ctrl.searchInput[0]).removeClass('ui-select-offscreen'); + + function completeCallback() { + if (ctrl.ngModel && ctrl.ngModel.$setTouched) { + ctrl.ngModel.$setTouched(); + } + _resetSearchInput(); + ctrl.open = false; + if (!ctrl.searchEnabled) { + angular.element(ctrl.searchInput[0]).removeClass('ui-select-offscreen'); + } + + $scope.$broadcast('uis:close', skipFocusser); } - $scope.$broadcast('uis:close', skipFocusser); + var result = ctrl.onDropdownCallback($scope, {open: false}); + if (angular.isDefined(result)) { + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (result) { + if (!result) { + return; + } + completeCallback(); + }); + } else if (result === true) { + completeCallback(); + } else if (result) { + completeCallback(); + } + } else { + completeCallback(); + } }; /** @@ -702,8 +753,10 @@ uis.controller('uiSelectCtrl', var isLocked, item = ctrl.selected[itemIndex]; if (item && !angular.isUndefined(ctrl.lockChoiceExpression)) { - isLocked = !!(itemScope.$eval(ctrl.lockChoiceExpression)); // force the boolean value - item._uiSelectChoiceLocked = isLocked; // store this for later reference + // Force the boolean value + isLocked = !!(itemScope.$eval(ctrl.lockChoiceExpression)); + // Store this for later reference + item._uiSelectChoiceLocked = isLocked; } return isLocked; @@ -731,7 +784,8 @@ uis.controller('uiSelectCtrl', }; ctrl.searchInput.css('width', '10px'); - $timeout(function () { //Give time to render correctly + $timeout(function () { + // Give time to render correctly if (sizeWatch === null && !updateIfVisible(calculateContainerWidth())) { sizeWatch = $scope.$watch(calculateContainerWidth, function (containerWidth) { if (updateIfVisible(containerWidth)) { @@ -748,7 +802,8 @@ uis.controller('uiSelectCtrl', switch (key) { case KEY.DOWN: if (!ctrl.open && ctrl.multiple) { - ctrl.activate(false, true); //In case its the search input in 'multiple' mode + // In case its the search input in 'multiple' mode + ctrl.activate(false, true); } else if (ctrl.activeIndex < ctrl.items.length - 1) { ctrl.activeIndex++; @@ -843,7 +898,7 @@ uis.controller('uiSelectCtrl', container[0].scrollTop += posY - height; } else if (posY < highlighted.clientHeight) { if (ctrl.isGrouped && ctrl.activeIndex === 0) { - //To make group header visible when going all the way up + // To make group header visible when going all the way up container[0].scrollTop = 0; } else { @@ -877,14 +932,15 @@ uis.directive('uiSelect', controllerAs: '$select', compile: function (tElement, tAttrs) { - //Multiple or Single depending if multiple attribute presence - if (angular.isDefined(tAttrs.multiple)) + // Multiple or Single depending if multiple attribute presence + if (angular.isDefined(tAttrs.multiple)) { tElement.append("").removeAttr('multiple'); - else + } + else { tElement.append(""); + } return function (scope, element, attrs, ctrls, transcludeFn) { - var $select = ctrls[0]; var ngModel = ctrls[1]; @@ -906,11 +962,12 @@ uis.directive('uiSelect', $select.onRemoveCallback = $parse(attrs.onRemove); $select.onBeforeRemoveCallback = $parse(attrs.onBeforeRemove); $select.onKeypressCallback = $parse(attrs.onKeypress); + $select.onDropdownCallback = $parse(attrs.onDropdown); - //Limit the number of selections allowed + // Limit the number of selections allowed $select.limit = (angular.isDefined(attrs.limit)) ? parseInt(attrs.limit, 10) : undefined; - //Set reference to ngModel from uiSelectCtrl + // Set reference to ngModel from uiSelectCtrl $select.ngModel = ngModel; $select.choiceGrouped = function (group) { @@ -944,7 +1001,7 @@ uis.directive('uiSelect', }); } - //Gets focus based on scope event name (e.g. focus-on='SomeEventName') + // Gets focus based on scope event name (e.g. focus-on='SomeEventName') if (angular.isDefined(attrs.focusOn)) { scope.$on(attrs.focusOn, function () { $timeout(function () { @@ -954,7 +1011,10 @@ uis.directive('uiSelect', } function onDocumentClick(e) { - if (!$select.open) return; //Skip it if dropdown is close + //Skip it if dropdown is close + if (!$select.open) { + return; + } var contains = false; @@ -967,14 +1027,14 @@ uis.directive('uiSelect', } if (!contains && !$select.clickTriggeredSelect) { - //Will lose focus only with certain targets + // Will lose focus only with certain targets var focusableControls = ['input', 'button', 'textarea']; - //To check if target is other ui-select + // To check if target is other ui-select var targetScope = angular.element(e.target).scope(); - //To check if target is other ui-select + // To check if target is other ui-select var skipFocusser = targetScope && targetScope.$select && targetScope.$select !== $select; - //Check if target is input, button or textarea + // Check if target is input, button or textarea if (!skipFocusser) { skipFocusser = ~focusableControls.indexOf(e.target.tagName.toLowerCase()); } @@ -1203,13 +1263,18 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel ctrl.activeMatchIndex = -1; $select.sizeSearchInput(); + // If there's no onBeforeRemove callback, then we're done + if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { + return; + } + var callbackContext = { $item: removedChoice, $model: $select.parserResult.modelMapper($scope, locals) }; // Give some time for scope propagation. - function completeRemoval() { + function completeCallback() { $timeout(function () { $select.onRemoveCallback($scope, callbackContext); }); @@ -1222,21 +1287,21 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel // falsy: Abort the removal // promise: Wait for response // true: Complete removal - var onBeforeRemoveResult = ctrl.onBeforeRemoveCallback($scope, callbackContext); - if (angular.isDefined(onBeforeRemoveResult)) { - if (angular.isFunction(onBeforeRemoveResult.then)) { + var result = ctrl.onBeforeRemoveCallback($scope, callbackContext); + if (angular.isDefined(result)) { + if (angular.isFunction(result.then)) { // Promise returned - wait for it to complete before completing the selection - onBeforeRemoveResult.then(function (result) { + result.then(function (result) { if (!result) { return; } - completeRemoval(result); + completeCallback(result); }); - } else if (onBeforeRemoveResult === true) { - completeRemoval(); + } else if (result === true) { + completeCallback(); } } else { - completeRemoval(); + completeCallback(); } }; @@ -1484,7 +1549,7 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co var $select = ctrls[0]; var ngModel = ctrls[1]; - //From view --> model + // From view --> model ngModel.$parsers.unshift(function (inputValue) { var locals = {}, result; @@ -1493,7 +1558,7 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co return result; }); - //From model --> view + // From model --> view ngModel.$formatters.unshift(function (inputValue) { var data = $select.parserResult.source(scope, {$select: {search: ''}}), //Overwrite $search locals = {}, @@ -1504,7 +1569,7 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co result = $select.parserResult.modelMapper(scope, locals); return result == inputValue; }; - //If possible pass same object stored in $select.selected + // If possible pass same object stored in $select.selected if ($select.selected && checkFnSingle($select.selected)) { return $select.selected; } @@ -1517,7 +1582,7 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co return inputValue; }); - //Update viewValue if model change + // Update viewValue if model change scope.$watch('$select.selected', function (newValue) { if (ngModel.$viewValue !== newValue) { ngModel.$setViewValue(newValue); @@ -1540,15 +1605,16 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co }); scope.$on('uis:activate', function () { - focusser.prop('disabled', true); //Will reactivate it on .close() + // Will reactivate it on .close() + focusser.prop('disabled', true); }); - //Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954 + // Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954 var focusser = angular.element(""); $compile(focusser)(scope); $select.focusser = focusser; - //Input that will handle focus + // Input that will handle focus $select.focusInput = focusser; element.parent().append(focusser); @@ -1562,8 +1628,8 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co $select.focus = false; }); }); - focusser.bind("keydown", function (e) { + focusser.bind("keydown", function (e) { if (e.which === KEY.BACKSPACE) { e.preventDefault(); e.stopPropagation(); @@ -1586,13 +1652,13 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co }); focusser.bind("keyup input", function (e) { - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { return; } - $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input + // User pressed some regular key, so we pass it to the search input + $select.activate(focusser.val()); focusser.val(''); scope.$digest(); }); diff --git a/dist/select.select2.min.js b/dist/select.select2.min.js index b119c669d..a163b6f96 100644 --- a/dist/select.select2.min.js +++ b/dist/select.select2.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-04T17:24:10.068Z + * Version: 0.12.1 - 2015-08-05T18:50:43.070Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],c=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(c.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,c=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,l,n){n(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(c){var l=c[0].getBoundingClientRect();return{width:l.width||c.prop("offsetWidth"),height:l.height||c.prop("offsetHeight"),top:l.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:l.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);c.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,c,l){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(e,n){if(!n.repeat)throw c("repeat","Expected 'repeat' expression.");return function(e,n,i,s,r){var a=i.groupBy,o=i.groupFilter;if(s.parseRepeatAttr(i.repeat,a,o),s.disableChoiceExpression=i.uiDisableChoice,s.onHighlightCallback=i.onHighlight,a){var u=n.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=n.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(s.parserResult.itemName,"$select.items",s.parserResult.trackByExp,a)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+s.parserResult.itemName+")").attr("ng-click","$select.select("+s.parserResult.itemName+",false,$event)");var d=n.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),l(n,r)(e),e.$watch("$select.search",function(e){e&&!s.open&&s.multiple&&s.activate(!1,!0),s.activeIndex=0})}}}}]),c.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,c,l,n,i,s,r,a){function o(){(h.resetSearchInput||void 0===h.resetSearchInput&&a.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var c,l,n=[];for(c=0;c0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:c=!1}return c}function d(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw r("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var l=t[h.activeIndex],n=l.offsetTop+l.clientHeight-e[0].scrollTop,i=e[0].offsetHeight;n>i?e[0].scrollTop+=n-i:n=h.items.length?0:h.activeIndex,l(function(){h.search=e||h.search,h.searchInput[0].focus()}))},h.parseRepeatAttr=function(e,c,l){function n(e){var n=t.$eval(c);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(n)?n(e):e[n],c=h.findGroupByName(t);c?c.items.push(e):h.groups.push({name:t,items:[e]})}),l){var i=t.$eval(l);angular.isFunction(i)?h.groups=i(h.groups):angular.isArray(i)&&(h.groups=u(h.groups,i))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function i(e){h.items=e}h.setItemsFn=c?n:i,h.parserResult=s.parse(e),h.isGrouped=!!c,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var c=h.selected;if(h.isEmpty()||angular.isArray(c)&&!c.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var l=e.filter(function(e){return c.indexOf(e)<0});h.setItemsFn(l)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw r("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),c=t===h.activeIndex;return c&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),c},h.isDisabled=function(e){if(!h.open)return!1;var t,c=h.items.indexOf(e[h.itemProperty]),l=!1;return c>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[c],l=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=l),l},h.select=function(e,c,n){if((void 0===e||!e._uiSelectChoiceDisabled)&&(h.items||h.search)){var i={};i[h.parserResult.itemName]=e;var s={$item:e,$model:h.parserResult.modelMapper(t,i)},r=function(){t.$broadcast("uis:select",e),l(function(){h.onSelectCallback(t,s)}),h.closeOnSelect&&h.close(c),n&&"click"===n.type&&(h.clickTriggeredSelect=!0)},a=h.onBeforeSelectCallback(t,s);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(e){e&&r(e)}):a===!0?r(e):a&&r(a):r(e)}},h.close=function(e){h.open&&(h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),o(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e))},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),l(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var c,l=h.selected[t];return l&&!angular.isUndefined(h.lockChoiceExpression)&&(c=!!e.$eval(h.lockChoiceExpression),l._uiSelectChoiceLocked=c),c};var g=null;h.sizeSearchInput=function(){var e=h.searchInput[0],c=h.searchInput.parent().parent()[0],n=function(){return c.clientWidth*!!e.offsetParent},i=function(t){if(0===t)return!1;var c=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>c&&(c=t),h.searchInput.css("width",c+"px"),!0};h.searchInput.css("width","10px"),l(function(){null!==g||i(n())||(g=t.$watch(n,function(e){i(e)&&(g(),g=null)}))})},h.searchInput.on("keydown",function(c){var l=c.which;t.$apply(function(){p(l)}),e.isVerticalMovement(l)&&h.items.length>0&&d(),(l===e.ENTER||l===e.ESC)&&(c.preventDefault(),c.stopPropagation())}),h.searchInput.on("keyup",function(c){c.which===e.TAB||e.isControl(c)||e.isFunctionKey(c)||c.which===e.ESC||e.isVerticalMovement(c.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:c})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),c.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,c,l,n,i,s){return{restrict:"EA",templateUrl:function(e,c){var l=c.theme||t.theme;return l+(angular.isDefined(c.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(n,r){return angular.isDefined(r.multiple)?n.append("").removeAttr("multiple"):n.append(""),function(n,r,a,o,u){function p(e){if(f.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(r[0],e.target):r[0].contains(e.target),!t&&!f.clickTriggeredSelect){var c=["input","button","textarea"],l=angular.element(e.target).scope(),i=l&&l.$select&&l.$select!==f;i||(i=~c.indexOf(e.target.tagName.toLowerCase())),f.close(i),n.$digest()}f.clickTriggeredSelect=!1}}function d(){var t=l(r);b=angular.element('
    '),b[0].style.width=t.width+"px",b[0].style.height=t.height+"px",r.after(b),E=r[0].style.width,e.find("body").append(r),r[0].style.position="absolute",r[0].style.left=t.left+"px",r[0].style.top=t.top+"px",r[0].style.width=t.width+"px"}function h(){null!==b&&(b.replaceWith(r),b=null,r[0].style.position="",r[0].style.left="",r[0].style.top="",r[0].style.width=E)}var f=o[0],g=o[1];f.generatedId=t.generateId(),f.baseTitle=a.title||"Select box",f.focusserTitle=f.baseTitle+" focus",f.focusserId="focusser-"+f.generatedId,f.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?i(a.closeOnSelect)():t.closeOnSelect}(),f.onSelectCallback=i(a.onSelect),f.onBeforeSelectCallback=i(a.onBeforeSelect),f.onRemoveCallback=i(a.onRemove),f.onBeforeRemoveCallback=i(a.onBeforeRemove),f.onKeypressCallback=i(a.onKeypress),f.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,f.ngModel=g,f.choiceGrouped=function(e){return f.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){f.focusInput.attr("tabindex",e),r.removeAttr("tabindex")});var v=n.$eval(a.searchEnabled);f.searchEnabled=void 0!==v?v:t.searchEnabled;var m=n.$eval(a.sortable);f.sortable=void 0!==m?m:t.sortable,a.$observe("disabled",function(){f.disabled=void 0!==a.disabled?a.disabled:!1}),angular.isDefined(a.autofocus)&&s(function(){f.setFocus()}),angular.isDefined(a.focusOn)&&n.$on(a.focusOn,function(){s(function(){f.setFocus()})}),e.on("click",p),n.$on("$destroy",function(){e.off("click",p)}),u(n,function(e){var t=angular.element("
    ").append(e),l=t.querySelectorAll(".ui-select-match");if(l.removeAttr("ui-select-match"),l.removeAttr("data-ui-select-match"),1!==l.length)throw c("transcluded","Expected 1 .ui-select-match but got '{0}'.",l.length);r.querySelectorAll(".ui-select-match").replaceWith(l);var n=t.querySelectorAll(".ui-select-choices");if(n.removeAttr("ui-select-choices"),n.removeAttr("data-ui-select-choices"),1!==n.length)throw c("transcluded","Expected 1 .ui-select-choices but got '{0}'.",n.length);r.querySelectorAll(".ui-select-choices").replaceWith(n)});var $=n.$eval(a.appendToBody);(void 0!==$?$:t.appendToBody)&&(n.$watch("$select.open",function(e){e?d():h()}),n.$on("$destroy",function(){h()}));var b=null,E="",w=null,S="direction-up";n.$watch("$select.open",function(t){if(t){if(w=angular.element(r).querySelectorAll(".ui-select-dropdown"),null===w)return;w[0].style.opacity=0,s(function(){var t=l(r),c=l(w);t.top+t.height+c.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&r.addClass(S),w[0].style.opacity=1})}else{if(null===w)return;r.removeClass(S)}})}}}}]),c.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,l=t.parent().attr("multiple");return c+(l?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,l,n){function i(e){n.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}n.lockChoiceExpression=l.uiLockChoice,l.$observe("placeholder",function(t){n.placeholder=void 0!==t?t:e.placeholder}),l.$observe("allowClear",i),i(l.allowClear),n.multiple&&n.sizeSearchInput()}}}]),c.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var c,l=this,n=e.$select;e.$evalAsync(function(){c=e.ngModel}),l.activeMatchIndex=-1,l.updateModel=function(){c.$setViewValue(Date.now()),l.refreshComponent()},l.refreshComponent=function(){n.refreshItems(),n.sizeSearchInput()},l.removeChoice=function(c){function i(){t(function(){n.onRemoveCallback(e,a)}),l.updateModel()}var s=n.selected[c];if(!s._uiSelectChoiceLocked){var r={};r[n.parserResult.itemName]=s,n.selected.splice(c,1),l.activeMatchIndex=-1,n.sizeSearchInput();var a={$item:s,$model:n.parserResult.modelMapper(e,r)},o=l.onBeforeRemoveCallback(e,a);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(e){e&&i(e)}):o===!0&&i():i()}},l.getPlaceholder=function(){return n.selected&&n.selected.length?void 0:n.placeholder}}],controllerAs:"$selectMultiple",link:function(l,n,i,s){function r(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(t){function c(){switch(t){case e.LEFT:return~p.activeMatchIndex?d:s;case e.RIGHT:return~p.activeMatchIndex&&a!==s?u:(o.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(a),d):s;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),a):!1}}var l=r(o.searchInput[0]),n=o.selected.length,i=0,s=n-1,a=p.activeMatchIndex,u=p.activeMatchIndex+1,d=p.activeMatchIndex-1,h=a;return l>0||o.search.length&&t==e.RIGHT?!1:(o.close(),h=c(),p.activeMatchIndex=o.selected.length&&h!==!1?Math.min(s,Math.max(i,h)):-1,!0)}var o=s[0],u=l.ngModel=s[1],p=l.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,u.$parsers.unshift(function(){for(var e,t={},c=[],n=o.selected.length-1;n>=0;n--)t={},t[o.parserResult.itemName]=o.selected[n],e=o.parserResult.modelMapper(l,t),c.unshift(e);return c}),u.$formatters.unshift(function(e){var t,c=o.parserResult.source(l,{$select:{search:""}}),n={};if(!c)return e;var i=[],s=function(e,c){if(e&&e.length){for(var s=e.length-1;s>=0;s--){if(n[o.parserResult.itemName]=e[s],t=o.parserResult.modelMapper(l,n),o.parserResult.trackByExp){var r=/\.(.+)/.exec(o.parserResult.trackByExp);if(r.length>0&&t[r[1]]==c[r[1]])return i.unshift(e[s]),!0}if(angular.equals(t,c))return i.unshift(e[s]),!0}return!1}};if(!e)return i;for(var r=e.length-1;r>=0;r--)s(o.selected,e[r])||s(c,e[r])||i.unshift(e[r]);return i}),l.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);o.selected=[]}o.selected=u.$viewValue,l.$evalAsync()},l.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),p.updateModel())}),l.$on("uis:activate",function(){p.activeMatchIndex=-1}),l.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(t){var c=t.which;l.$apply(function(){var t=!1;e.isHorizontalMovement(c)&&(t=a(c)),t&&c!=e.TAB})}),o.searchInput.on("blur",function(){c(function(){p.activeMatchIndex=-1})})}}}]),c.directive("uiSelectSingle",["$timeout","$compile",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(l,n,i,s){var r=s[0],a=s[1];a.$parsers.unshift(function(e){var t,c={};return c[r.parserResult.itemName]=e,t=r.parserResult.modelMapper(l,c)}),a.$formatters.unshift(function(e){var t,c=r.parserResult.source(l,{$select:{search:""}}),n={};if(c){var i=function(c){return n[r.parserResult.itemName]=c,t=r.parserResult.modelMapper(l,n),t==e};if(r.selected&&i(r.selected))return r.selected;for(var s=c.length-1;s>=0;s--)if(i(c[s]))return c[s]}return e}),l.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){r.selected=a.$viewValue},l.$on("uis:select",function(e,t){r.selected=t}),l.$on("uis:close",function(e,c){t(function(){r.focusser.prop("disabled",!1),c||r.focusser[0].focus()},0,!1)}),l.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");c(o)(l),r.focusser=o,r.focusInput=o,n.parent().append(o),o.bind("focus",function(){l.$evalAsync(function(){r.focus=!0})}),o.bind("blur",function(){l.$evalAsync(function(){r.focus=!1})}),o.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),r.select(void 0),l.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),r.activate()),l.$digest()),void 0)}),o.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(r.activate(o.val()),o.val(""),l.$digest())})}}}]),c.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var l=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!l)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:l[2],source:t(l[3]),trackByExp:l[4],modelMapper:t(l[1]||l[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,l){var n=e+" in "+(l?"$group.items":t);return c&&(n+=" track by "+c),n}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("select2/choices.tpl.html",'
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    ')}]); \ No newline at end of file +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],c=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(c.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,c=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,l,n){n(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(c){var l=c[0].getBoundingClientRect();return{width:l.width||c.prop("offsetWidth"),height:l.height||c.prop("offsetHeight"),top:l.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:l.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);c.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,c,l){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(e,n){if(!n.repeat)throw c("repeat","Expected 'repeat' expression.");return function(e,n,i,s,r){var a=i.groupBy,o=i.groupFilter;if(s.parseRepeatAttr(i.repeat,a,o),s.disableChoiceExpression=i.uiDisableChoice,s.onHighlightCallback=i.onHighlight,a){var u=n.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=n.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(s.parserResult.itemName,"$select.items",s.parserResult.trackByExp,a)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+s.parserResult.itemName+")").attr("ng-click","$select.select("+s.parserResult.itemName+",false,$event)");var d=n.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),l(n,r)(e),e.$watch("$select.search",function(e){e&&!s.open&&s.multiple&&s.activate(!1,!0),s.activeIndex=0})}}}}]),c.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,c,l,n,i,s,r,a){function o(){(h.resetSearchInput||void 0===h.resetSearchInput&&a.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var c,l,n=[];for(c=0;c0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:c=!1}return c}function d(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw r("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var l=t[h.activeIndex],n=l.offsetTop+l.clientHeight-e[0].scrollTop,i=e[0].offsetHeight;n>i?e[0].scrollTop+=n-i:n=h.items.length?0:h.activeIndex,l(function(){h.search=e||h.search,h.searchInput[0].focus()})},i=h.onDropdownCallback(t,{open:!0});angular.isDefined(i)?angular.isFunction(i.then)?i.then(function(e){e&&n()}):i===!0?n():i&&n():n()}},h.parseRepeatAttr=function(e,c,l){function n(e){var n=t.$eval(c);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(n)?n(e):e[n],c=h.findGroupByName(t);c?c.items.push(e):h.groups.push({name:t,items:[e]})}),l){var i=t.$eval(l);angular.isFunction(i)?h.groups=i(h.groups):angular.isArray(i)&&(h.groups=u(h.groups,i))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function i(e){h.items=e}h.setItemsFn=c?n:i,h.parserResult=s.parse(e),h.isGrouped=!!c,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var c=h.selected;if(h.isEmpty()||angular.isArray(c)&&!c.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var l=e.filter(function(e){return c.indexOf(e)<0});h.setItemsFn(l)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw r("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),c=-1===t?!1:t===h.activeIndex;return c&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),c},h.isDisabled=function(e){if(!h.open)return!1;var t,c=h.items.indexOf(e[h.itemProperty]),l=!1;return c>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[c],l=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=l),l},h.select=function(e,c,n){if((void 0===e||!e._uiSelectChoiceDisabled)&&(h.items||h.search)){var i={};i[h.parserResult.itemName]=e;var s={$item:e,$model:h.parserResult.modelMapper(t,i)},r=function(e){s.$item=e,t.$broadcast("uis:select",e),l(function(){h.onSelectCallback(t,s)}),h.closeOnSelect&&h.close(c),n&&"click"===n.type&&(h.clickTriggeredSelect=!0)},a=h.onBeforeSelectCallback(t,s);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(e){e&&r(e)}):a===!0?r(e):a&&r(a):r(e)}},h.close=function(e){function c(){h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),o(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e)}if(h.open){var l=h.onDropdownCallback(t,{open:!1});angular.isDefined(l)?angular.isFunction(l.then)?l.then(function(e){e&&c()}):l===!0?c():l&&c():c()}},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),l(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var c,l=h.selected[t];return l&&!angular.isUndefined(h.lockChoiceExpression)&&(c=!!e.$eval(h.lockChoiceExpression),l._uiSelectChoiceLocked=c),c};var g=null;h.sizeSearchInput=function(){var e=h.searchInput[0],c=h.searchInput.parent().parent()[0],n=function(){return c.clientWidth*!!e.offsetParent},i=function(t){if(0===t)return!1;var c=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>c&&(c=t),h.searchInput.css("width",c+"px"),!0};h.searchInput.css("width","10px"),l(function(){null!==g||i(n())||(g=t.$watch(n,function(e){i(e)&&(g(),g=null)}))})},h.searchInput.on("keydown",function(c){var l=c.which;t.$apply(function(){p(l)}),e.isVerticalMovement(l)&&h.items.length>0&&d(),(l===e.ENTER||l===e.ESC)&&(c.preventDefault(),c.stopPropagation())}),h.searchInput.on("keyup",function(c){c.which===e.TAB||e.isControl(c)||e.isFunctionKey(c)||c.which===e.ESC||e.isVerticalMovement(c.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:c})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),c.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,c,l,n,i,s){return{restrict:"EA",templateUrl:function(e,c){var l=c.theme||t.theme;return l+(angular.isDefined(c.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(n,r){return angular.isDefined(r.multiple)?n.append("").removeAttr("multiple"):n.append(""),function(n,r,a,o,u){function p(e){if(f.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(r[0],e.target):r[0].contains(e.target),!t&&!f.clickTriggeredSelect){var c=["input","button","textarea"],l=angular.element(e.target).scope(),i=l&&l.$select&&l.$select!==f;i||(i=~c.indexOf(e.target.tagName.toLowerCase())),f.close(i),n.$digest()}f.clickTriggeredSelect=!1}}function d(){var t=l(r);b=angular.element('
    '),b[0].style.width=t.width+"px",b[0].style.height=t.height+"px",r.after(b),E=r[0].style.width,e.find("body").append(r),r[0].style.position="absolute",r[0].style.left=t.left+"px",r[0].style.top=t.top+"px",r[0].style.width=t.width+"px"}function h(){null!==b&&(b.replaceWith(r),b=null,r[0].style.position="",r[0].style.left="",r[0].style.top="",r[0].style.width=E)}var f=o[0],g=o[1];f.generatedId=t.generateId(),f.baseTitle=a.title||"Select box",f.focusserTitle=f.baseTitle+" focus",f.focusserId="focusser-"+f.generatedId,f.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?i(a.closeOnSelect)():t.closeOnSelect}(),f.onSelectCallback=i(a.onSelect),f.onBeforeSelectCallback=i(a.onBeforeSelect),f.onRemoveCallback=i(a.onRemove),f.onBeforeRemoveCallback=i(a.onBeforeRemove),f.onKeypressCallback=i(a.onKeypress),f.onDropdownCallback=i(a.onDropdown),f.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,f.ngModel=g,f.choiceGrouped=function(e){return f.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){f.focusInput.attr("tabindex",e),r.removeAttr("tabindex")});var v=n.$eval(a.searchEnabled);f.searchEnabled=void 0!==v?v:t.searchEnabled;var m=n.$eval(a.sortable);f.sortable=void 0!==m?m:t.sortable,a.$observe("disabled",function(){f.disabled=void 0!==a.disabled?a.disabled:!1}),angular.isDefined(a.autofocus)&&s(function(){f.setFocus()}),angular.isDefined(a.focusOn)&&n.$on(a.focusOn,function(){s(function(){f.setFocus()})}),e.on("click",p),n.$on("$destroy",function(){e.off("click",p)}),u(n,function(e){var t=angular.element("
    ").append(e),l=t.querySelectorAll(".ui-select-match");if(l.removeAttr("ui-select-match"),l.removeAttr("data-ui-select-match"),1!==l.length)throw c("transcluded","Expected 1 .ui-select-match but got '{0}'.",l.length);r.querySelectorAll(".ui-select-match").replaceWith(l);var n=t.querySelectorAll(".ui-select-choices");if(n.removeAttr("ui-select-choices"),n.removeAttr("data-ui-select-choices"),1!==n.length)throw c("transcluded","Expected 1 .ui-select-choices but got '{0}'.",n.length);r.querySelectorAll(".ui-select-choices").replaceWith(n)});var $=n.$eval(a.appendToBody);(void 0!==$?$:t.appendToBody)&&(n.$watch("$select.open",function(e){e?d():h()}),n.$on("$destroy",function(){h()}));var b=null,E="",w=null,S="direction-up";n.$watch("$select.open",function(t){if(t){if(w=angular.element(r).querySelectorAll(".ui-select-dropdown"),null===w)return;w[0].style.opacity=0,s(function(){var t=l(r),c=l(w);t.top+t.height+c.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&r.addClass(S),w[0].style.opacity=1})}else{if(null===w)return;r.removeClass(S)}})}}}}]),c.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,l=t.parent().attr("multiple");return c+(l?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,l,n){function i(e){n.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}n.lockChoiceExpression=l.uiLockChoice,l.$observe("placeholder",function(t){n.placeholder=void 0!==t?t:e.placeholder}),l.$observe("allowClear",i),i(l.allowClear),n.multiple&&n.sizeSearchInput()}}}]),c.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var c,l=this,n=e.$select;e.$evalAsync(function(){c=e.ngModel}),l.activeMatchIndex=-1,l.updateModel=function(){c.$setViewValue(Date.now()),l.refreshComponent()},l.refreshComponent=function(){n.refreshItems(),n.sizeSearchInput()},l.removeChoice=function(c){function i(){t(function(){n.onRemoveCallback(e,a)}),l.updateModel()}var s=n.selected[c];if(!s._uiSelectChoiceLocked){var r={};if(r[n.parserResult.itemName]=s,n.selected.splice(c,1),l.activeMatchIndex=-1,n.sizeSearchInput(),angular.isDefined(l.onBeforeRemoveCallback)){var a={$item:s,$model:n.parserResult.modelMapper(e,r)},o=l.onBeforeRemoveCallback(e,a);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(e){e&&i(e)}):o===!0&&i():i()}}},l.getPlaceholder=function(){return n.selected&&n.selected.length?void 0:n.placeholder}}],controllerAs:"$selectMultiple",link:function(l,n,i,s){function r(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(t){function c(){switch(t){case e.LEFT:return~p.activeMatchIndex?d:s;case e.RIGHT:return~p.activeMatchIndex&&a!==s?u:(o.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(a),d):s;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),a):!1}}var l=r(o.searchInput[0]),n=o.selected.length,i=0,s=n-1,a=p.activeMatchIndex,u=p.activeMatchIndex+1,d=p.activeMatchIndex-1,h=a;return l>0||o.search.length&&t==e.RIGHT?!1:(o.close(),h=c(),p.activeMatchIndex=o.selected.length&&h!==!1?Math.min(s,Math.max(i,h)):-1,!0)}var o=s[0],u=l.ngModel=s[1],p=l.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,u.$parsers.unshift(function(){for(var e,t={},c=[],n=o.selected.length-1;n>=0;n--)t={},t[o.parserResult.itemName]=o.selected[n],e=o.parserResult.modelMapper(l,t),c.unshift(e);return c}),u.$formatters.unshift(function(e){var t,c=o.parserResult.source(l,{$select:{search:""}}),n={};if(!c)return e;var i=[],s=function(e,c){if(e&&e.length){for(var s=e.length-1;s>=0;s--){if(n[o.parserResult.itemName]=e[s],t=o.parserResult.modelMapper(l,n),o.parserResult.trackByExp){var r=/\.(.+)/.exec(o.parserResult.trackByExp);if(r.length>0&&t[r[1]]==c[r[1]])return i.unshift(e[s]),!0}if(angular.equals(t,c))return i.unshift(e[s]),!0}return!1}};if(!e)return i;for(var r=e.length-1;r>=0;r--)s(o.selected,e[r])||s(c,e[r])||i.unshift(e[r]);return i}),l.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);o.selected=[]}o.selected=u.$viewValue,l.$evalAsync()},l.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),p.updateModel())}),l.$on("uis:activate",function(){p.activeMatchIndex=-1}),l.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(t){var c=t.which;l.$apply(function(){var t=!1;e.isHorizontalMovement(c)&&(t=a(c)),t&&c!=e.TAB})}),o.searchInput.on("blur",function(){c(function(){p.activeMatchIndex=-1})})}}}]),c.directive("uiSelectSingle",["$timeout","$compile",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(l,n,i,s){var r=s[0],a=s[1];a.$parsers.unshift(function(e){var t,c={};return c[r.parserResult.itemName]=e,t=r.parserResult.modelMapper(l,c)}),a.$formatters.unshift(function(e){var t,c=r.parserResult.source(l,{$select:{search:""}}),n={};if(c){var i=function(c){return n[r.parserResult.itemName]=c,t=r.parserResult.modelMapper(l,n),t==e};if(r.selected&&i(r.selected))return r.selected;for(var s=c.length-1;s>=0;s--)if(i(c[s]))return c[s]}return e}),l.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){r.selected=a.$viewValue},l.$on("uis:select",function(e,t){r.selected=t}),l.$on("uis:close",function(e,c){t(function(){r.focusser.prop("disabled",!1),c||r.focusser[0].focus()},0,!1)}),l.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");c(o)(l),r.focusser=o,r.focusInput=o,n.parent().append(o),o.bind("focus",function(){l.$evalAsync(function(){r.focus=!0})}),o.bind("blur",function(){l.$evalAsync(function(){r.focus=!1})}),o.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),r.select(void 0),l.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),r.activate()),l.$digest()),void 0)}),o.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(r.activate(o.val()),o.val(""),l.$digest())})}}}]),c.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var l=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!l)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:l[2],source:t(l[3]),trackByExp:l[4],modelMapper:t(l[1]||l[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,l){var n=e+" in "+(l?"$group.items":t);return c&&(n+=" track by "+c),n}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("select2/choices.tpl.html",'
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/dist/select.selectize.js b/dist/select.selectize.js index 47a335033..d88daa4b3 100644 --- a/dist/select.selectize.js +++ b/dist/select.selectize.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-04T17:24:10.073Z + * Version: 0.12.1 - 2015-08-05T18:50:43.074Z * License: MIT */ @@ -318,7 +318,7 @@ uis.directive('uiSelectChoices', choices.attr('ng-repeat', RepeatParser.getNgRepeatExpression($select.parserResult.itemName, '$select.items', $select.parserResult.trackByExp, groupByExp)) - .attr('ng-if', '$select.open') //Prevent unnecessary watches when dropdown is closed + .attr('ng-if', '$select.open') // Prevent unnecessary watches when dropdown is closed .attr('ng-mouseenter', '$select.setActiveItem(' + $select.parserResult.itemName + ')') .attr('ng-click', '$select.select(' + $select.parserResult.itemName + ',false,$event)'); @@ -360,19 +360,19 @@ uis.controller('uiSelectCtrl', ctrl.searchEnabled = uiSelectConfig.searchEnabled; ctrl.sortable = uiSelectConfig.sortable; - ctrl.removeSelected = false; //If selected item(s) should be removed from dropdown list - ctrl.closeOnSelect = true; //Initialized inside uiSelect directive link function + ctrl.removeSelected = false; // If selected item(s) should be removed from dropdown list + ctrl.closeOnSelect = true; // Initialized inside uiSelect directive link function ctrl.search = EMPTY_SEARCH; - ctrl.activeIndex = 0; //Dropdown of choices - ctrl.items = []; //All available choices + ctrl.activeIndex = 0; // Dropdown of choices + ctrl.items = []; // All available choices ctrl.open = false; ctrl.focus = false; ctrl.disabled = false; ctrl.selected = undefined; - ctrl.focusser = undefined; //Reference to input element used to handle focus events + ctrl.focusser = undefined; // Reference to input element used to handle focus events ctrl.resetSearchInput = true; ctrl.multiple = undefined; // Initialized inside uiSelect directive link function ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelectChoices directive link function @@ -398,7 +398,7 @@ uis.controller('uiSelectCtrl', function _resetSearchInput() { if (ctrl.resetSearchInput || (ctrl.resetSearchInput === undefined && uiSelectConfig.resetSearchInput)) { ctrl.search = EMPTY_SEARCH; - //reset activeIndex + // Reset activeIndex if (ctrl.selected && ctrl.items.length && !ctrl.multiple) { ctrl.activeIndex = ctrl.items.indexOf(ctrl.selected); } @@ -429,24 +429,45 @@ uis.controller('uiSelectCtrl', */ ctrl.activate = function (initSearchValue, avoidReset) { if (!ctrl.disabled && !ctrl.open) { - if (!avoidReset) { - _resetSearchInput(); - } + var completeCallback = function () { + if (!avoidReset) { + _resetSearchInput(); + } - $scope.$broadcast('uis:activate'); + $scope.$broadcast('uis:activate'); - ctrl.open = true; - if (!ctrl.searchEnabled) { - angular.element(ctrl.searchInput[0]).addClass('ui-select-offscreen'); - } + ctrl.open = true; + if (!ctrl.searchEnabled) { + angular.element(ctrl.searchInput[0]).addClass('ui-select-offscreen'); + } - ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex; + ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex; - // Give it time to appear before focus - $timeout(function () { - ctrl.search = initSearchValue || ctrl.search; - ctrl.searchInput[0].focus(); - }); + // Give it time to appear before focus + $timeout(function () { + ctrl.search = initSearchValue || ctrl.search; + ctrl.searchInput[0].focus(); + }); + }; + + var result = ctrl.onDropdownCallback($scope, {open: true}); + if (angular.isDefined(result)) { + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (result) { + if (!result) { + return; + } + completeCallback(); + }); + } else if (result === true) { + completeCallback(); + } else if (result) { + completeCallback(); + } + } else { + completeCallback(); + } } else if (ctrl.open && !ctrl.searchEnabled) { // Close the selection if we don't have search enabled, and we click on the select again @@ -522,10 +543,11 @@ uis.controller('uiSelectCtrl', if (!angular.isArray(items)) { throw uiSelectMinErr('items', "Expected an array but got '{0}'.", items); } else { - //Remove already selected items (ex: while searching) - //TODO Should add a test + // Remove already selected items (ex: while searching) + // TODO Should add a test ctrl.refreshItems(items); - ctrl.ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters + // Force scope model value and ngModel value to be out of sync to re-run formatters + ctrl.ngModel.$modelValue = null; } } }); @@ -544,9 +566,15 @@ uis.controller('uiSelectCtrl', if (!ctrl.open) { return false; } + // Get the index of this item - returns -1 if the item isn't in the current list var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); - var isActive = itemIndex === ctrl.activeIndex; + // Is this the active index? + // If the itemIndex is -1, then the item wasn't in the list so let's ensure we're not active + // otherwise we can end up with all items being selected as active! + var isActive = itemIndex === -1 ? false : itemIndex === ctrl.activeIndex; + + // If this is active, and we've defined a callback, do it! if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { itemScope.$eval(ctrl.onHighlightCallback); } @@ -604,7 +632,8 @@ uis.controller('uiSelectCtrl', // Local method called when we complete the select // eg. called after the onselect callback - var completeSelection = function () { + var completeCallback = function (item) { + callbackContext.$item = item; $scope.$broadcast('uis:select', item); $timeout(function () { @@ -625,23 +654,23 @@ uis.controller('uiSelectCtrl', // promise: Wait for response // true: Complete selection // object: Add the returned object - var onBeforeSelectResult = ctrl.onBeforeSelectCallback($scope, callbackContext); - if (angular.isDefined(onBeforeSelectResult)) { - if (angular.isFunction(onBeforeSelectResult.then)) { + var result = ctrl.onBeforeSelectCallback($scope, callbackContext); + if (angular.isDefined(result)) { + if (angular.isFunction(result.then)) { // Promise returned - wait for it to complete before completing the selection - onBeforeSelectResult.then(function (result) { + result.then(function (result) { if (!result) { return; } - completeSelection(result); + completeCallback(result); }); - } else if (onBeforeSelectResult === true) { - completeSelection(item); - } else if (onBeforeSelectResult) { - completeSelection(onBeforeSelectResult); + } else if (result === true) { + completeCallback(item); + } else if (result) { + completeCallback(result); } } else { - completeSelection(item); + completeCallback(item); } }; @@ -652,16 +681,38 @@ uis.controller('uiSelectCtrl', if (!ctrl.open) { return; } - if (ctrl.ngModel && ctrl.ngModel.$setTouched) { - ctrl.ngModel.$setTouched(); - } - _resetSearchInput(); - ctrl.open = false; - if (!ctrl.searchEnabled) { - angular.element(ctrl.searchInput[0]).removeClass('ui-select-offscreen'); + + function completeCallback() { + if (ctrl.ngModel && ctrl.ngModel.$setTouched) { + ctrl.ngModel.$setTouched(); + } + _resetSearchInput(); + ctrl.open = false; + if (!ctrl.searchEnabled) { + angular.element(ctrl.searchInput[0]).removeClass('ui-select-offscreen'); + } + + $scope.$broadcast('uis:close', skipFocusser); } - $scope.$broadcast('uis:close', skipFocusser); + var result = ctrl.onDropdownCallback($scope, {open: false}); + if (angular.isDefined(result)) { + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (result) { + if (!result) { + return; + } + completeCallback(); + }); + } else if (result === true) { + completeCallback(); + } else if (result) { + completeCallback(); + } + } else { + completeCallback(); + } }; /** @@ -702,8 +753,10 @@ uis.controller('uiSelectCtrl', var isLocked, item = ctrl.selected[itemIndex]; if (item && !angular.isUndefined(ctrl.lockChoiceExpression)) { - isLocked = !!(itemScope.$eval(ctrl.lockChoiceExpression)); // force the boolean value - item._uiSelectChoiceLocked = isLocked; // store this for later reference + // Force the boolean value + isLocked = !!(itemScope.$eval(ctrl.lockChoiceExpression)); + // Store this for later reference + item._uiSelectChoiceLocked = isLocked; } return isLocked; @@ -731,7 +784,8 @@ uis.controller('uiSelectCtrl', }; ctrl.searchInput.css('width', '10px'); - $timeout(function () { //Give time to render correctly + $timeout(function () { + // Give time to render correctly if (sizeWatch === null && !updateIfVisible(calculateContainerWidth())) { sizeWatch = $scope.$watch(calculateContainerWidth, function (containerWidth) { if (updateIfVisible(containerWidth)) { @@ -748,7 +802,8 @@ uis.controller('uiSelectCtrl', switch (key) { case KEY.DOWN: if (!ctrl.open && ctrl.multiple) { - ctrl.activate(false, true); //In case its the search input in 'multiple' mode + // In case its the search input in 'multiple' mode + ctrl.activate(false, true); } else if (ctrl.activeIndex < ctrl.items.length - 1) { ctrl.activeIndex++; @@ -843,7 +898,7 @@ uis.controller('uiSelectCtrl', container[0].scrollTop += posY - height; } else if (posY < highlighted.clientHeight) { if (ctrl.isGrouped && ctrl.activeIndex === 0) { - //To make group header visible when going all the way up + // To make group header visible when going all the way up container[0].scrollTop = 0; } else { @@ -877,14 +932,15 @@ uis.directive('uiSelect', controllerAs: '$select', compile: function (tElement, tAttrs) { - //Multiple or Single depending if multiple attribute presence - if (angular.isDefined(tAttrs.multiple)) + // Multiple or Single depending if multiple attribute presence + if (angular.isDefined(tAttrs.multiple)) { tElement.append("").removeAttr('multiple'); - else + } + else { tElement.append(""); + } return function (scope, element, attrs, ctrls, transcludeFn) { - var $select = ctrls[0]; var ngModel = ctrls[1]; @@ -906,11 +962,12 @@ uis.directive('uiSelect', $select.onRemoveCallback = $parse(attrs.onRemove); $select.onBeforeRemoveCallback = $parse(attrs.onBeforeRemove); $select.onKeypressCallback = $parse(attrs.onKeypress); + $select.onDropdownCallback = $parse(attrs.onDropdown); - //Limit the number of selections allowed + // Limit the number of selections allowed $select.limit = (angular.isDefined(attrs.limit)) ? parseInt(attrs.limit, 10) : undefined; - //Set reference to ngModel from uiSelectCtrl + // Set reference to ngModel from uiSelectCtrl $select.ngModel = ngModel; $select.choiceGrouped = function (group) { @@ -944,7 +1001,7 @@ uis.directive('uiSelect', }); } - //Gets focus based on scope event name (e.g. focus-on='SomeEventName') + // Gets focus based on scope event name (e.g. focus-on='SomeEventName') if (angular.isDefined(attrs.focusOn)) { scope.$on(attrs.focusOn, function () { $timeout(function () { @@ -954,7 +1011,10 @@ uis.directive('uiSelect', } function onDocumentClick(e) { - if (!$select.open) return; //Skip it if dropdown is close + //Skip it if dropdown is close + if (!$select.open) { + return; + } var contains = false; @@ -967,14 +1027,14 @@ uis.directive('uiSelect', } if (!contains && !$select.clickTriggeredSelect) { - //Will lose focus only with certain targets + // Will lose focus only with certain targets var focusableControls = ['input', 'button', 'textarea']; - //To check if target is other ui-select + // To check if target is other ui-select var targetScope = angular.element(e.target).scope(); - //To check if target is other ui-select + // To check if target is other ui-select var skipFocusser = targetScope && targetScope.$select && targetScope.$select !== $select; - //Check if target is input, button or textarea + // Check if target is input, button or textarea if (!skipFocusser) { skipFocusser = ~focusableControls.indexOf(e.target.tagName.toLowerCase()); } @@ -1203,13 +1263,18 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel ctrl.activeMatchIndex = -1; $select.sizeSearchInput(); + // If there's no onBeforeRemove callback, then we're done + if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { + return; + } + var callbackContext = { $item: removedChoice, $model: $select.parserResult.modelMapper($scope, locals) }; // Give some time for scope propagation. - function completeRemoval() { + function completeCallback() { $timeout(function () { $select.onRemoveCallback($scope, callbackContext); }); @@ -1222,21 +1287,21 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel // falsy: Abort the removal // promise: Wait for response // true: Complete removal - var onBeforeRemoveResult = ctrl.onBeforeRemoveCallback($scope, callbackContext); - if (angular.isDefined(onBeforeRemoveResult)) { - if (angular.isFunction(onBeforeRemoveResult.then)) { + var result = ctrl.onBeforeRemoveCallback($scope, callbackContext); + if (angular.isDefined(result)) { + if (angular.isFunction(result.then)) { // Promise returned - wait for it to complete before completing the selection - onBeforeRemoveResult.then(function (result) { + result.then(function (result) { if (!result) { return; } - completeRemoval(result); + completeCallback(result); }); - } else if (onBeforeRemoveResult === true) { - completeRemoval(); + } else if (result === true) { + completeCallback(); } } else { - completeRemoval(); + completeCallback(); } }; @@ -1484,7 +1549,7 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co var $select = ctrls[0]; var ngModel = ctrls[1]; - //From view --> model + // From view --> model ngModel.$parsers.unshift(function (inputValue) { var locals = {}, result; @@ -1493,7 +1558,7 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co return result; }); - //From model --> view + // From model --> view ngModel.$formatters.unshift(function (inputValue) { var data = $select.parserResult.source(scope, {$select: {search: ''}}), //Overwrite $search locals = {}, @@ -1504,7 +1569,7 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co result = $select.parserResult.modelMapper(scope, locals); return result == inputValue; }; - //If possible pass same object stored in $select.selected + // If possible pass same object stored in $select.selected if ($select.selected && checkFnSingle($select.selected)) { return $select.selected; } @@ -1517,7 +1582,7 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co return inputValue; }); - //Update viewValue if model change + // Update viewValue if model change scope.$watch('$select.selected', function (newValue) { if (ngModel.$viewValue !== newValue) { ngModel.$setViewValue(newValue); @@ -1540,15 +1605,16 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co }); scope.$on('uis:activate', function () { - focusser.prop('disabled', true); //Will reactivate it on .close() + // Will reactivate it on .close() + focusser.prop('disabled', true); }); - //Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954 + // Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954 var focusser = angular.element(""); $compile(focusser)(scope); $select.focusser = focusser; - //Input that will handle focus + // Input that will handle focus $select.focusInput = focusser; element.parent().append(focusser); @@ -1562,8 +1628,8 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co $select.focus = false; }); }); - focusser.bind("keydown", function (e) { + focusser.bind("keydown", function (e) { if (e.which === KEY.BACKSPACE) { e.preventDefault(); e.stopPropagation(); @@ -1586,13 +1652,13 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co }); focusser.bind("keyup input", function (e) { - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { return; } - $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input + // User pressed some regular key, so we pass it to the search input + $select.activate(focusser.val()); focusser.val(''); scope.$digest(); }); diff --git a/dist/select.selectize.min.js b/dist/select.selectize.min.js index 084c20608..dabbcdbd9 100644 --- a/dist/select.selectize.min.js +++ b/dist/select.selectize.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-04T17:24:10.073Z + * Version: 0.12.1 - 2015-08-05T18:50:43.074Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var n=t.which;switch(n){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,n=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,i,c){c(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var i=n[0].getBoundingClientRect();return{width:i.width||n.prop("offsetWidth"),height:i.height||n.prop("offsetHeight"),top:i.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:i.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);n.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,c){if(!c.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,c,r,l,s){var o=r.groupBy,a=r.groupFilter;if(l.parseRepeatAttr(r.repeat,o,a),l.disableChoiceExpression=r.uiDisableChoice,l.onHighlightCallback=r.onHighlight,o){var u=c.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=c.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(l.parserResult.itemName,"$select.items",l.parserResult.trackByExp,o)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+l.parserResult.itemName+")").attr("ng-click","$select.select("+l.parserResult.itemName+",false,$event)");var d=c.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),i(c,s)(e),e.$watch("$select.search",function(e){e&&!l.open&&l.multiple&&l.activate(!1,!0),l.activeIndex=0})}}}}]),n.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,n,i,c,r,l,s,o){function a(){(h.resetSearchInput||void 0===h.resetSearchInput&&o.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var n,i,c=[];for(n=0;n0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:n=!1}return n}function d(){var e=n.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw s("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var i=t[h.activeIndex],c=i.offsetTop+i.clientHeight-e[0].scrollTop,r=e[0].offsetHeight;c>r?e[0].scrollTop+=c-r:c=h.items.length?0:h.activeIndex,i(function(){h.search=e||h.search,h.searchInput[0].focus()}))},h.parseRepeatAttr=function(e,n,i){function c(e){var c=t.$eval(n);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(c)?c(e):e[c],n=h.findGroupByName(t);n?n.items.push(e):h.groups.push({name:t,items:[e]})}),i){var r=t.$eval(i);angular.isFunction(r)?h.groups=r(h.groups):angular.isArray(r)&&(h.groups=u(h.groups,r))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function r(e){h.items=e}h.setItemsFn=n?c:r,h.parserResult=l.parse(e),h.isGrouped=!!n,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var n=h.selected;if(h.isEmpty()||angular.isArray(n)&&!n.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var i=e.filter(function(e){return n.indexOf(e)<0});h.setItemsFn(i)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw s("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),n=t===h.activeIndex;return n&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),n},h.isDisabled=function(e){if(!h.open)return!1;var t,n=h.items.indexOf(e[h.itemProperty]),i=!1;return n>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[n],i=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i},h.select=function(e,n,c){if((void 0===e||!e._uiSelectChoiceDisabled)&&(h.items||h.search)){var r={};r[h.parserResult.itemName]=e;var l={$item:e,$model:h.parserResult.modelMapper(t,r)},s=function(){t.$broadcast("uis:select",e),i(function(){h.onSelectCallback(t,l)}),h.closeOnSelect&&h.close(n),c&&"click"===c.type&&(h.clickTriggeredSelect=!0)},o=h.onBeforeSelectCallback(t,l);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(e){e&&s(e)}):o===!0?s(e):o&&s(o):s(e)}},h.close=function(e){h.open&&(h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),a(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e))},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),i(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var n,i=h.selected[t];return i&&!angular.isUndefined(h.lockChoiceExpression)&&(n=!!e.$eval(h.lockChoiceExpression),i._uiSelectChoiceLocked=n),n};var v=null;h.sizeSearchInput=function(){var e=h.searchInput[0],n=h.searchInput.parent().parent()[0],c=function(){return n.clientWidth*!!e.offsetParent},r=function(t){if(0===t)return!1;var n=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=t),h.searchInput.css("width",n+"px"),!0};h.searchInput.css("width","10px"),i(function(){null!==v||r(c())||(v=t.$watch(c,function(e){r(e)&&(v(),v=null)}))})},h.searchInput.on("keydown",function(n){var i=n.which;t.$apply(function(){p(i)}),e.isVerticalMovement(i)&&h.items.length>0&&d(),(i===e.ENTER||i===e.ESC)&&(n.preventDefault(),n.stopPropagation())}),h.searchInput.on("keyup",function(n){n.which===e.TAB||e.isControl(n)||e.isFunctionKey(n)||n.which===e.ESC||e.isVerticalMovement(n.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:n})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),n.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,i,c,r,l){return{restrict:"EA",templateUrl:function(e,n){var i=n.theme||t.theme;return i+(angular.isDefined(n.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(c,s){return angular.isDefined(s.multiple)?c.append("").removeAttr("multiple"):c.append(""),function(c,s,o,a,u){function p(e){if(f.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(s[0],e.target):s[0].contains(e.target),!t&&!f.clickTriggeredSelect){var n=["input","button","textarea"],i=angular.element(e.target).scope(),r=i&&i.$select&&i.$select!==f;r||(r=~n.indexOf(e.target.tagName.toLowerCase())),f.close(r),c.$digest()}f.clickTriggeredSelect=!1}}function d(){var t=i(s);E=angular.element('
    '),E[0].style.width=t.width+"px",E[0].style.height=t.height+"px",s.after(E),b=s[0].style.width,e.find("body").append(s),s[0].style.position="absolute",s[0].style.left=t.left+"px",s[0].style.top=t.top+"px",s[0].style.width=t.width+"px"}function h(){null!==E&&(E.replaceWith(s),E=null,s[0].style.position="",s[0].style.left="",s[0].style.top="",s[0].style.width=b)}var f=a[0],v=a[1];f.generatedId=t.generateId(),f.baseTitle=o.title||"Select box",f.focusserTitle=f.baseTitle+" focus",f.focusserId="focusser-"+f.generatedId,f.closeOnSelect=function(){return angular.isDefined(o.closeOnSelect)?r(o.closeOnSelect)():t.closeOnSelect}(),f.onSelectCallback=r(o.onSelect),f.onBeforeSelectCallback=r(o.onBeforeSelect),f.onRemoveCallback=r(o.onRemove),f.onBeforeRemoveCallback=r(o.onBeforeRemove),f.onKeypressCallback=r(o.onKeypress),f.limit=angular.isDefined(o.limit)?parseInt(o.limit,10):void 0,f.ngModel=v,f.choiceGrouped=function(e){return f.isGrouped&&e&&e.name},o.tabindex&&o.$observe("tabindex",function(e){f.focusInput.attr("tabindex",e),s.removeAttr("tabindex")});var g=c.$eval(o.searchEnabled);f.searchEnabled=void 0!==g?g:t.searchEnabled;var m=c.$eval(o.sortable);f.sortable=void 0!==m?m:t.sortable,o.$observe("disabled",function(){f.disabled=void 0!==o.disabled?o.disabled:!1}),angular.isDefined(o.autofocus)&&l(function(){f.setFocus()}),angular.isDefined(o.focusOn)&&c.$on(o.focusOn,function(){l(function(){f.setFocus()})}),e.on("click",p),c.$on("$destroy",function(){e.off("click",p)}),u(c,function(e){var t=angular.element("
    ").append(e),i=t.querySelectorAll(".ui-select-match");if(i.removeAttr("ui-select-match"),i.removeAttr("data-ui-select-match"),1!==i.length)throw n("transcluded","Expected 1 .ui-select-match but got '{0}'.",i.length);s.querySelectorAll(".ui-select-match").replaceWith(i);var c=t.querySelectorAll(".ui-select-choices");if(c.removeAttr("ui-select-choices"),c.removeAttr("data-ui-select-choices"),1!==c.length)throw n("transcluded","Expected 1 .ui-select-choices but got '{0}'.",c.length);s.querySelectorAll(".ui-select-choices").replaceWith(c)});var $=c.$eval(o.appendToBody);(void 0!==$?$:t.appendToBody)&&(c.$watch("$select.open",function(e){e?d():h()}),c.$on("$destroy",function(){h()}));var E=null,b="",S=null,w="direction-up";c.$watch("$select.open",function(t){if(t){if(S=angular.element(s).querySelectorAll(".ui-select-dropdown"),null===S)return;S[0].style.opacity=0,l(function(){var t=i(s),n=i(S);t.top+t.height+n.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&s.addClass(w),S[0].style.opacity=1})}else{if(null===S)return;s.removeClass(w)}})}}}}]),n.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return n+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,i,c){function r(e){c.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}c.lockChoiceExpression=i.uiLockChoice,i.$observe("placeholder",function(t){c.placeholder=void 0!==t?t:e.placeholder}),i.$observe("allowClear",r),r(i.allowClear),c.multiple&&c.sizeSearchInput()}}}]),n.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,i=this,c=e.$select;e.$evalAsync(function(){n=e.ngModel}),i.activeMatchIndex=-1,i.updateModel=function(){n.$setViewValue(Date.now()),i.refreshComponent()},i.refreshComponent=function(){c.refreshItems(),c.sizeSearchInput()},i.removeChoice=function(n){function r(){t(function(){c.onRemoveCallback(e,o)}),i.updateModel()}var l=c.selected[n];if(!l._uiSelectChoiceLocked){var s={};s[c.parserResult.itemName]=l,c.selected.splice(n,1),i.activeMatchIndex=-1,c.sizeSearchInput();var o={$item:l,$model:c.parserResult.modelMapper(e,s)},a=i.onBeforeRemoveCallback(e,o);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(e){e&&r(e)}):a===!0&&r():r()}},i.getPlaceholder=function(){return c.selected&&c.selected.length?void 0:c.placeholder}}],controllerAs:"$selectMultiple",link:function(i,c,r,l){function s(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function o(t){function n(){switch(t){case e.LEFT:return~p.activeMatchIndex?d:l;case e.RIGHT:return~p.activeMatchIndex&&o!==l?u:(a.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(o),d):l;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),o):!1}}var i=s(a.searchInput[0]),c=a.selected.length,r=0,l=c-1,o=p.activeMatchIndex,u=p.activeMatchIndex+1,d=p.activeMatchIndex-1,h=o;return i>0||a.search.length&&t==e.RIGHT?!1:(a.close(),h=n(),p.activeMatchIndex=a.selected.length&&h!==!1?Math.min(l,Math.max(r,h)):-1,!0)}var a=l[0],u=i.ngModel=l[1],p=i.$selectMultiple;a.multiple=!0,a.removeSelected=!0,a.focusInput=a.searchInput,u.$parsers.unshift(function(){for(var e,t={},n=[],c=a.selected.length-1;c>=0;c--)t={},t[a.parserResult.itemName]=a.selected[c],e=a.parserResult.modelMapper(i,t),n.unshift(e);return n}),u.$formatters.unshift(function(e){var t,n=a.parserResult.source(i,{$select:{search:""}}),c={};if(!n)return e;var r=[],l=function(e,n){if(e&&e.length){for(var l=e.length-1;l>=0;l--){if(c[a.parserResult.itemName]=e[l],t=a.parserResult.modelMapper(i,c),a.parserResult.trackByExp){var s=/\.(.+)/.exec(a.parserResult.trackByExp);if(s.length>0&&t[s[1]]==n[s[1]])return r.unshift(e[l]),!0}if(angular.equals(t,n))return r.unshift(e[l]),!0}return!1}};if(!e)return r;for(var s=e.length-1;s>=0;s--)l(a.selected,e[s])||l(n,e[s])||r.unshift(e[s]);return r}),i.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);a.selected=[]}a.selected=u.$viewValue,i.$evalAsync()},i.$on("uis:select",function(e,t){a.selected.length>=a.limit||(a.selected.push(t),p.updateModel())}),i.$on("uis:activate",function(){p.activeMatchIndex=-1}),i.$watch("$select.disabled",function(e,t){t&&!e&&a.sizeSearchInput()}),a.searchInput.on("keydown",function(t){var n=t.which;i.$apply(function(){var t=!1;e.isHorizontalMovement(n)&&(t=o(n)),t&&n!=e.TAB})}),a.searchInput.on("blur",function(){n(function(){p.activeMatchIndex=-1})})}}}]),n.directive("uiSelectSingle",["$timeout","$compile",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(i,c,r,l){var s=l[0],o=l[1];o.$parsers.unshift(function(e){var t,n={};return n[s.parserResult.itemName]=e,t=s.parserResult.modelMapper(i,n)}),o.$formatters.unshift(function(e){var t,n=s.parserResult.source(i,{$select:{search:""}}),c={};if(n){var r=function(n){return c[s.parserResult.itemName]=n,t=s.parserResult.modelMapper(i,c),t==e};if(s.selected&&r(s.selected))return s.selected;for(var l=n.length-1;l>=0;l--)if(r(n[l]))return n[l]}return e}),i.$watch("$select.selected",function(e){o.$viewValue!==e&&o.$setViewValue(e)}),o.$render=function(){s.selected=o.$viewValue},i.$on("uis:select",function(e,t){s.selected=t}),i.$on("uis:close",function(e,n){t(function(){s.focusser.prop("disabled",!1),n||s.focusser[0].focus()},0,!1)}),i.$on("uis:activate",function(){a.prop("disabled",!0)});var a=angular.element("");n(a)(i),s.focusser=a,s.focusInput=a,c.parent().append(a),a.bind("focus",function(){i.$evalAsync(function(){s.focus=!0})}),a.bind("blur",function(){i.$evalAsync(function(){s.focus=!1})}),a.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),s.select(void 0),i.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),s.activate()),i.$digest()),void 0)}),a.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(s.activate(a.val()),a.val(""),i.$digest())})}}}]),n.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var i=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!i)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:i[2],source:t(i[3]),trackByExp:i[4],modelMapper:t(i[1]||i[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,i){var c=e+" in "+(i?"$group.items":t);return n&&(c+=" track by "+n),c}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("selectize/choices.tpl.html",'
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var n=t.which;switch(n){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,n=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,i,c){c(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var i=n[0].getBoundingClientRect();return{width:i.width||n.prop("offsetWidth"),height:i.height||n.prop("offsetHeight"),top:i.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:i.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);n.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,c){if(!c.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,c,r,l,s){var o=r.groupBy,a=r.groupFilter;if(l.parseRepeatAttr(r.repeat,o,a),l.disableChoiceExpression=r.uiDisableChoice,l.onHighlightCallback=r.onHighlight,o){var u=c.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=c.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(l.parserResult.itemName,"$select.items",l.parserResult.trackByExp,o)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+l.parserResult.itemName+")").attr("ng-click","$select.select("+l.parserResult.itemName+",false,$event)");var d=c.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),i(c,s)(e),e.$watch("$select.search",function(e){e&&!l.open&&l.multiple&&l.activate(!1,!0),l.activeIndex=0})}}}}]),n.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,n,i,c,r,l,s,o){function a(){(h.resetSearchInput||void 0===h.resetSearchInput&&o.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var n,i,c=[];for(n=0;n0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:n=!1}return n}function d(){var e=n.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw s("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var i=t[h.activeIndex],c=i.offsetTop+i.clientHeight-e[0].scrollTop,r=e[0].offsetHeight;c>r?e[0].scrollTop+=c-r:c=h.items.length?0:h.activeIndex,i(function(){h.search=e||h.search,h.searchInput[0].focus()})},r=h.onDropdownCallback(t,{open:!0});angular.isDefined(r)?angular.isFunction(r.then)?r.then(function(e){e&&c()}):r===!0?c():r&&c():c()}},h.parseRepeatAttr=function(e,n,i){function c(e){var c=t.$eval(n);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(c)?c(e):e[c],n=h.findGroupByName(t);n?n.items.push(e):h.groups.push({name:t,items:[e]})}),i){var r=t.$eval(i);angular.isFunction(r)?h.groups=r(h.groups):angular.isArray(r)&&(h.groups=u(h.groups,r))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function r(e){h.items=e}h.setItemsFn=n?c:r,h.parserResult=l.parse(e),h.isGrouped=!!n,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var n=h.selected;if(h.isEmpty()||angular.isArray(n)&&!n.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var i=e.filter(function(e){return n.indexOf(e)<0});h.setItemsFn(i)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw s("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),n=-1===t?!1:t===h.activeIndex;return n&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),n},h.isDisabled=function(e){if(!h.open)return!1;var t,n=h.items.indexOf(e[h.itemProperty]),i=!1;return n>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[n],i=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i},h.select=function(e,n,c){if((void 0===e||!e._uiSelectChoiceDisabled)&&(h.items||h.search)){var r={};r[h.parserResult.itemName]=e;var l={$item:e,$model:h.parserResult.modelMapper(t,r)},s=function(e){l.$item=e,t.$broadcast("uis:select",e),i(function(){h.onSelectCallback(t,l)}),h.closeOnSelect&&h.close(n),c&&"click"===c.type&&(h.clickTriggeredSelect=!0)},o=h.onBeforeSelectCallback(t,l);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(e){e&&s(e)}):o===!0?s(e):o&&s(o):s(e)}},h.close=function(e){function n(){h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),a(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e)}if(h.open){var i=h.onDropdownCallback(t,{open:!1});angular.isDefined(i)?angular.isFunction(i.then)?i.then(function(e){e&&n()}):i===!0?n():i&&n():n()}},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),i(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var n,i=h.selected[t];return i&&!angular.isUndefined(h.lockChoiceExpression)&&(n=!!e.$eval(h.lockChoiceExpression),i._uiSelectChoiceLocked=n),n};var v=null;h.sizeSearchInput=function(){var e=h.searchInput[0],n=h.searchInput.parent().parent()[0],c=function(){return n.clientWidth*!!e.offsetParent},r=function(t){if(0===t)return!1;var n=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=t),h.searchInput.css("width",n+"px"),!0};h.searchInput.css("width","10px"),i(function(){null!==v||r(c())||(v=t.$watch(c,function(e){r(e)&&(v(),v=null)}))})},h.searchInput.on("keydown",function(n){var i=n.which;t.$apply(function(){p(i)}),e.isVerticalMovement(i)&&h.items.length>0&&d(),(i===e.ENTER||i===e.ESC)&&(n.preventDefault(),n.stopPropagation())}),h.searchInput.on("keyup",function(n){n.which===e.TAB||e.isControl(n)||e.isFunctionKey(n)||n.which===e.ESC||e.isVerticalMovement(n.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:n})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),n.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,i,c,r,l){return{restrict:"EA",templateUrl:function(e,n){var i=n.theme||t.theme;return i+(angular.isDefined(n.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(c,s){return angular.isDefined(s.multiple)?c.append("").removeAttr("multiple"):c.append(""),function(c,s,o,a,u){function p(e){if(f.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(s[0],e.target):s[0].contains(e.target),!t&&!f.clickTriggeredSelect){var n=["input","button","textarea"],i=angular.element(e.target).scope(),r=i&&i.$select&&i.$select!==f;r||(r=~n.indexOf(e.target.tagName.toLowerCase())),f.close(r),c.$digest()}f.clickTriggeredSelect=!1}}function d(){var t=i(s);E=angular.element('
    '),E[0].style.width=t.width+"px",E[0].style.height=t.height+"px",s.after(E),b=s[0].style.width,e.find("body").append(s),s[0].style.position="absolute",s[0].style.left=t.left+"px",s[0].style.top=t.top+"px",s[0].style.width=t.width+"px"}function h(){null!==E&&(E.replaceWith(s),E=null,s[0].style.position="",s[0].style.left="",s[0].style.top="",s[0].style.width=b)}var f=a[0],v=a[1];f.generatedId=t.generateId(),f.baseTitle=o.title||"Select box",f.focusserTitle=f.baseTitle+" focus",f.focusserId="focusser-"+f.generatedId,f.closeOnSelect=function(){return angular.isDefined(o.closeOnSelect)?r(o.closeOnSelect)():t.closeOnSelect}(),f.onSelectCallback=r(o.onSelect),f.onBeforeSelectCallback=r(o.onBeforeSelect),f.onRemoveCallback=r(o.onRemove),f.onBeforeRemoveCallback=r(o.onBeforeRemove),f.onKeypressCallback=r(o.onKeypress),f.onDropdownCallback=r(o.onDropdown),f.limit=angular.isDefined(o.limit)?parseInt(o.limit,10):void 0,f.ngModel=v,f.choiceGrouped=function(e){return f.isGrouped&&e&&e.name},o.tabindex&&o.$observe("tabindex",function(e){f.focusInput.attr("tabindex",e),s.removeAttr("tabindex")});var g=c.$eval(o.searchEnabled);f.searchEnabled=void 0!==g?g:t.searchEnabled;var m=c.$eval(o.sortable);f.sortable=void 0!==m?m:t.sortable,o.$observe("disabled",function(){f.disabled=void 0!==o.disabled?o.disabled:!1}),angular.isDefined(o.autofocus)&&l(function(){f.setFocus()}),angular.isDefined(o.focusOn)&&c.$on(o.focusOn,function(){l(function(){f.setFocus()})}),e.on("click",p),c.$on("$destroy",function(){e.off("click",p)}),u(c,function(e){var t=angular.element("
    ").append(e),i=t.querySelectorAll(".ui-select-match");if(i.removeAttr("ui-select-match"),i.removeAttr("data-ui-select-match"),1!==i.length)throw n("transcluded","Expected 1 .ui-select-match but got '{0}'.",i.length);s.querySelectorAll(".ui-select-match").replaceWith(i);var c=t.querySelectorAll(".ui-select-choices");if(c.removeAttr("ui-select-choices"),c.removeAttr("data-ui-select-choices"),1!==c.length)throw n("transcluded","Expected 1 .ui-select-choices but got '{0}'.",c.length);s.querySelectorAll(".ui-select-choices").replaceWith(c)});var $=c.$eval(o.appendToBody);(void 0!==$?$:t.appendToBody)&&(c.$watch("$select.open",function(e){e?d():h()}),c.$on("$destroy",function(){h()}));var E=null,b="",S=null,w="direction-up";c.$watch("$select.open",function(t){if(t){if(S=angular.element(s).querySelectorAll(".ui-select-dropdown"),null===S)return;S[0].style.opacity=0,l(function(){var t=i(s),n=i(S);t.top+t.height+n.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&s.addClass(w),S[0].style.opacity=1})}else{if(null===S)return;s.removeClass(w)}})}}}}]),n.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return n+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,i,c){function r(e){c.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}c.lockChoiceExpression=i.uiLockChoice,i.$observe("placeholder",function(t){c.placeholder=void 0!==t?t:e.placeholder}),i.$observe("allowClear",r),r(i.allowClear),c.multiple&&c.sizeSearchInput()}}}]),n.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,i=this,c=e.$select;e.$evalAsync(function(){n=e.ngModel}),i.activeMatchIndex=-1,i.updateModel=function(){n.$setViewValue(Date.now()),i.refreshComponent()},i.refreshComponent=function(){c.refreshItems(),c.sizeSearchInput()},i.removeChoice=function(n){function r(){t(function(){c.onRemoveCallback(e,o)}),i.updateModel()}var l=c.selected[n];if(!l._uiSelectChoiceLocked){var s={};if(s[c.parserResult.itemName]=l,c.selected.splice(n,1),i.activeMatchIndex=-1,c.sizeSearchInput(),angular.isDefined(i.onBeforeRemoveCallback)){var o={$item:l,$model:c.parserResult.modelMapper(e,s)},a=i.onBeforeRemoveCallback(e,o);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(e){e&&r(e)}):a===!0&&r():r()}}},i.getPlaceholder=function(){return c.selected&&c.selected.length?void 0:c.placeholder}}],controllerAs:"$selectMultiple",link:function(i,c,r,l){function s(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function o(t){function n(){switch(t){case e.LEFT:return~p.activeMatchIndex?d:l;case e.RIGHT:return~p.activeMatchIndex&&o!==l?u:(a.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(o),d):l;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),o):!1}}var i=s(a.searchInput[0]),c=a.selected.length,r=0,l=c-1,o=p.activeMatchIndex,u=p.activeMatchIndex+1,d=p.activeMatchIndex-1,h=o;return i>0||a.search.length&&t==e.RIGHT?!1:(a.close(),h=n(),p.activeMatchIndex=a.selected.length&&h!==!1?Math.min(l,Math.max(r,h)):-1,!0)}var a=l[0],u=i.ngModel=l[1],p=i.$selectMultiple;a.multiple=!0,a.removeSelected=!0,a.focusInput=a.searchInput,u.$parsers.unshift(function(){for(var e,t={},n=[],c=a.selected.length-1;c>=0;c--)t={},t[a.parserResult.itemName]=a.selected[c],e=a.parserResult.modelMapper(i,t),n.unshift(e);return n}),u.$formatters.unshift(function(e){var t,n=a.parserResult.source(i,{$select:{search:""}}),c={};if(!n)return e;var r=[],l=function(e,n){if(e&&e.length){for(var l=e.length-1;l>=0;l--){if(c[a.parserResult.itemName]=e[l],t=a.parserResult.modelMapper(i,c),a.parserResult.trackByExp){var s=/\.(.+)/.exec(a.parserResult.trackByExp);if(s.length>0&&t[s[1]]==n[s[1]])return r.unshift(e[l]),!0}if(angular.equals(t,n))return r.unshift(e[l]),!0}return!1}};if(!e)return r;for(var s=e.length-1;s>=0;s--)l(a.selected,e[s])||l(n,e[s])||r.unshift(e[s]);return r}),i.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);a.selected=[]}a.selected=u.$viewValue,i.$evalAsync()},i.$on("uis:select",function(e,t){a.selected.length>=a.limit||(a.selected.push(t),p.updateModel())}),i.$on("uis:activate",function(){p.activeMatchIndex=-1}),i.$watch("$select.disabled",function(e,t){t&&!e&&a.sizeSearchInput()}),a.searchInput.on("keydown",function(t){var n=t.which;i.$apply(function(){var t=!1;e.isHorizontalMovement(n)&&(t=o(n)),t&&n!=e.TAB})}),a.searchInput.on("blur",function(){n(function(){p.activeMatchIndex=-1})})}}}]),n.directive("uiSelectSingle",["$timeout","$compile",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(i,c,r,l){var s=l[0],o=l[1];o.$parsers.unshift(function(e){var t,n={};return n[s.parserResult.itemName]=e,t=s.parserResult.modelMapper(i,n)}),o.$formatters.unshift(function(e){var t,n=s.parserResult.source(i,{$select:{search:""}}),c={};if(n){var r=function(n){return c[s.parserResult.itemName]=n,t=s.parserResult.modelMapper(i,c),t==e};if(s.selected&&r(s.selected))return s.selected;for(var l=n.length-1;l>=0;l--)if(r(n[l]))return n[l]}return e}),i.$watch("$select.selected",function(e){o.$viewValue!==e&&o.$setViewValue(e)}),o.$render=function(){s.selected=o.$viewValue},i.$on("uis:select",function(e,t){s.selected=t}),i.$on("uis:close",function(e,n){t(function(){s.focusser.prop("disabled",!1),n||s.focusser[0].focus()},0,!1)}),i.$on("uis:activate",function(){a.prop("disabled",!0)});var a=angular.element("");n(a)(i),s.focusser=a,s.focusInput=a,c.parent().append(a),a.bind("focus",function(){i.$evalAsync(function(){s.focus=!0})}),a.bind("blur",function(){i.$evalAsync(function(){s.focus=!1})}),a.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),s.select(void 0),i.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),s.activate()),i.$digest()),void 0)}),a.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(s.activate(a.val()),a.val(""),i.$digest())})}}}]),n.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var i=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!i)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:i[2],source:t(i[3]),trackByExp:i[4],modelMapper:t(i[1]||i[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,i){var c=e+" in "+(i?"$group.items":t);return n&&(c+=" track by "+n),c}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("selectize/choices.tpl.html",'
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/dist/select.tpl.js b/dist/select.tpl.js index c04431faf..472a30c5c 100644 --- a/dist/select.tpl.js +++ b/dist/select.tpl.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-04T17:24:10.036Z + * Version: 0.12.1 - 2015-08-05T18:50:43.025Z * License: MIT */ diff --git a/examples/newdemo.html b/examples/newdemo.html index ab615f67b..22fef1019 100644 --- a/examples/newdemo.html +++ b/examples/newdemo.html @@ -41,7 +41,7 @@
    ui-select inside a Bootstrap form - +
    @@ -158,7 +158,7 @@ + > {{$item}} {{color}} @@ -167,6 +167,23 @@
    +
    + + +
    + + {{$select.selected.name}} + + +
    + +
    +
    +
    +
    +
    diff --git a/examples/newdemo.js b/examples/newdemo.js index 06570658f..c1d6e7c93 100644 --- a/examples/newdemo.js +++ b/examples/newdemo.js @@ -144,6 +144,19 @@ app.controller('DemoCtrl', function ($scope, $http, $timeout, $interval) { {name: 'Nicolás', email: 'nicolas@email.com', age: 43, country: 'Colombia'} ]; + $scope.people2 = { + adam:{name: 'Adam', email: 'adam@email.com', age: 12, country: 'United States'}, + amalie: {name: 'Amalie', email: 'amalie@email.com', age: 12, country: 'Argentina'}, + estefana: {name: 'Estefanía', email: 'estefania@email.com', age: 21, country: 'Argentina'}, + adriana: {name: 'Adrian', email: 'adrian@email.com', age: 21, country: 'Ecuador'}, + vlad: {name: 'Wladimir', email: 'wladimir@email.com', age: 30, country: 'Ecuador'}, + sam: {name: 'Samantha', email: 'samantha@email.com', age: 30, country: 'United States'}, + nic: {name: 'Nicole', email: 'nicole@email.com', age: 43, country: 'Colombia'}, + nat: {name: 'Natasha', email: 'natasha@email.com', age: 54, country: 'Ecuador'}, + Mic: {name: 'Michael', email: 'michael@email.com', age: 15, country: 'Colombia'}, + nicola: {name: 'Nicolás', email: 'nicolas@email.com', age: 43, country: 'Colombia'} + }; + $scope.availableColors = ['Red', 'Green', 'Blue', 'Yellow', 'Magenta', 'Maroon', 'Umbra', 'Turquoise']; $scope.singleDemo = {}; @@ -530,5 +543,74 @@ app.controller('DemoCtrl', function ($scope, $http, $timeout, $interval) { return dupeIndex; } + $scope.onComboKeypress = function (e) { + return; + var $select = this.$select; + // Push a "create new" item into array if there is a search string + if ($select.search.length > 0) { + // always reset the activeIndex to the first item when tagging + $select.activeIndex = $select.taggingLabel === false ? -1 : 0; + + var items = angular.copy($select.items); + var stashArr = angular.copy($select.items); + var newItem; + var item; + var hasTag = false; + var dupeIndex = -1; + var tagItems; + var tagItem; + + newItem = $select.search; + dupeIndex = _findApproxDupe($select.items, newItem); + if(dupeIndex != -1) { + items = items.slice(dupeIndex + 1, items.length - 1); + } + // Verify that the tag doesn't match the value of a selected item + if (_findCaseInsensitiveDupe($select.search, stashArr.concat($select.selected))) { + $scope.$evalAsync(function () { + $select.activeIndex = 0; + $select.items = items; + }); + return; + } + + // Verify that the tag doesn't match the value of a new tag item + if (_findCaseInsensitiveDupe($select.search, stashArr)) { + $scope.$evalAsync(function () { + $select.activeIndex = 0; + $select.items = items; + }); + return; + } + + // Add the new item + stashArr = []; + stashArr.push(newItem); + stashArr = stashArr.concat(items); + + $scope.$evalAsync(function () { + $select.activeIndex = 0; + $select.items = stashArr; + }); + } + }; + + $scope.onComboBeforeSelect = function ($item) { + var $select = this.$select; + + var newItem = {name: $select.search, email: 'an email', age: 12, country: 'nowhere'}; + +// var stashArr = []; + // stashArr.push(newItem); + // stashArr = stashArr.concat($select.items); + + $scope.$evalAsync(function () { + $select.activeIndex = -2; + // $select.items = stashArr; + }); + + // For tagging, use the search if there's no item selected + return $item !== undefined ? $item : newItem; + }; }); diff --git a/src/uiSelectChoicesDirective.js b/src/uiSelectChoicesDirective.js index b9339beed..c6352e29c 100644 --- a/src/uiSelectChoicesDirective.js +++ b/src/uiSelectChoicesDirective.js @@ -46,7 +46,7 @@ uis.directive('uiSelectChoices', choices.attr('ng-repeat', RepeatParser.getNgRepeatExpression($select.parserResult.itemName, '$select.items', $select.parserResult.trackByExp, groupByExp)) - .attr('ng-if', '$select.open') //Prevent unnecessary watches when dropdown is closed + .attr('ng-if', '$select.open') // Prevent unnecessary watches when dropdown is closed .attr('ng-mouseenter', '$select.setActiveItem(' + $select.parserResult.itemName + ')') .attr('ng-click', '$select.select(' + $select.parserResult.itemName + ',false,$event)'); diff --git a/src/uiSelectController.js b/src/uiSelectController.js index 8c9716ba2..2782b74b6 100644 --- a/src/uiSelectController.js +++ b/src/uiSelectController.js @@ -16,19 +16,19 @@ uis.controller('uiSelectCtrl', ctrl.searchEnabled = uiSelectConfig.searchEnabled; ctrl.sortable = uiSelectConfig.sortable; - ctrl.removeSelected = false; //If selected item(s) should be removed from dropdown list - ctrl.closeOnSelect = true; //Initialized inside uiSelect directive link function + ctrl.removeSelected = false; // If selected item(s) should be removed from dropdown list + ctrl.closeOnSelect = true; // Initialized inside uiSelect directive link function ctrl.search = EMPTY_SEARCH; - ctrl.activeIndex = 0; //Dropdown of choices - ctrl.items = []; //All available choices + ctrl.activeIndex = 0; // Dropdown of choices + ctrl.items = []; // All available choices ctrl.open = false; ctrl.focus = false; ctrl.disabled = false; ctrl.selected = undefined; - ctrl.focusser = undefined; //Reference to input element used to handle focus events + ctrl.focusser = undefined; // Reference to input element used to handle focus events ctrl.resetSearchInput = true; ctrl.multiple = undefined; // Initialized inside uiSelect directive link function ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelectChoices directive link function @@ -54,7 +54,7 @@ uis.controller('uiSelectCtrl', function _resetSearchInput() { if (ctrl.resetSearchInput || (ctrl.resetSearchInput === undefined && uiSelectConfig.resetSearchInput)) { ctrl.search = EMPTY_SEARCH; - //reset activeIndex + // Reset activeIndex if (ctrl.selected && ctrl.items.length && !ctrl.multiple) { ctrl.activeIndex = ctrl.items.indexOf(ctrl.selected); } @@ -85,24 +85,45 @@ uis.controller('uiSelectCtrl', */ ctrl.activate = function (initSearchValue, avoidReset) { if (!ctrl.disabled && !ctrl.open) { - if (!avoidReset) { - _resetSearchInput(); - } + var completeCallback = function () { + if (!avoidReset) { + _resetSearchInput(); + } - $scope.$broadcast('uis:activate'); + $scope.$broadcast('uis:activate'); - ctrl.open = true; - if (!ctrl.searchEnabled) { - angular.element(ctrl.searchInput[0]).addClass('ui-select-offscreen'); - } + ctrl.open = true; + if (!ctrl.searchEnabled) { + angular.element(ctrl.searchInput[0]).addClass('ui-select-offscreen'); + } - ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex; + ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex; - // Give it time to appear before focus - $timeout(function () { - ctrl.search = initSearchValue || ctrl.search; - ctrl.searchInput[0].focus(); - }); + // Give it time to appear before focus + $timeout(function () { + ctrl.search = initSearchValue || ctrl.search; + ctrl.searchInput[0].focus(); + }); + }; + + var result = ctrl.onDropdownCallback($scope, {open: true}); + if (angular.isDefined(result)) { + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (result) { + if (!result) { + return; + } + completeCallback(); + }); + } else if (result === true) { + completeCallback(); + } else if (result) { + completeCallback(); + } + } else { + completeCallback(); + } } else if (ctrl.open && !ctrl.searchEnabled) { // Close the selection if we don't have search enabled, and we click on the select again @@ -178,10 +199,11 @@ uis.controller('uiSelectCtrl', if (!angular.isArray(items)) { throw uiSelectMinErr('items', "Expected an array but got '{0}'.", items); } else { - //Remove already selected items (ex: while searching) - //TODO Should add a test + // Remove already selected items (ex: while searching) + // TODO Should add a test ctrl.refreshItems(items); - ctrl.ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters + // Force scope model value and ngModel value to be out of sync to re-run formatters + ctrl.ngModel.$modelValue = null; } } }); @@ -200,9 +222,15 @@ uis.controller('uiSelectCtrl', if (!ctrl.open) { return false; } + // Get the index of this item - returns -1 if the item isn't in the current list var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); - var isActive = itemIndex === ctrl.activeIndex; + // Is this the active index? + // If the itemIndex is -1, then the item wasn't in the list so let's ensure we're not active + // otherwise we can end up with all items being selected as active! + var isActive = itemIndex === -1 ? false : itemIndex === ctrl.activeIndex; + + // If this is active, and we've defined a callback, do it! if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { itemScope.$eval(ctrl.onHighlightCallback); } @@ -260,7 +288,8 @@ uis.controller('uiSelectCtrl', // Local method called when we complete the select // eg. called after the onselect callback - var completeSelection = function () { + var completeCallback = function (item) { + callbackContext.$item = item; $scope.$broadcast('uis:select', item); $timeout(function () { @@ -281,23 +310,23 @@ uis.controller('uiSelectCtrl', // promise: Wait for response // true: Complete selection // object: Add the returned object - var onBeforeSelectResult = ctrl.onBeforeSelectCallback($scope, callbackContext); - if (angular.isDefined(onBeforeSelectResult)) { - if (angular.isFunction(onBeforeSelectResult.then)) { + var result = ctrl.onBeforeSelectCallback($scope, callbackContext); + if (angular.isDefined(result)) { + if (angular.isFunction(result.then)) { // Promise returned - wait for it to complete before completing the selection - onBeforeSelectResult.then(function (result) { + result.then(function (result) { if (!result) { return; } - completeSelection(result); + completeCallback(result); }); - } else if (onBeforeSelectResult === true) { - completeSelection(item); - } else if (onBeforeSelectResult) { - completeSelection(onBeforeSelectResult); + } else if (result === true) { + completeCallback(item); + } else if (result) { + completeCallback(result); } } else { - completeSelection(item); + completeCallback(item); } }; @@ -308,16 +337,38 @@ uis.controller('uiSelectCtrl', if (!ctrl.open) { return; } - if (ctrl.ngModel && ctrl.ngModel.$setTouched) { - ctrl.ngModel.$setTouched(); - } - _resetSearchInput(); - ctrl.open = false; - if (!ctrl.searchEnabled) { - angular.element(ctrl.searchInput[0]).removeClass('ui-select-offscreen'); + + function completeCallback() { + if (ctrl.ngModel && ctrl.ngModel.$setTouched) { + ctrl.ngModel.$setTouched(); + } + _resetSearchInput(); + ctrl.open = false; + if (!ctrl.searchEnabled) { + angular.element(ctrl.searchInput[0]).removeClass('ui-select-offscreen'); + } + + $scope.$broadcast('uis:close', skipFocusser); } - $scope.$broadcast('uis:close', skipFocusser); + var result = ctrl.onDropdownCallback($scope, {open: false}); + if (angular.isDefined(result)) { + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (result) { + if (!result) { + return; + } + completeCallback(); + }); + } else if (result === true) { + completeCallback(); + } else if (result) { + completeCallback(); + } + } else { + completeCallback(); + } }; /** @@ -358,8 +409,10 @@ uis.controller('uiSelectCtrl', var isLocked, item = ctrl.selected[itemIndex]; if (item && !angular.isUndefined(ctrl.lockChoiceExpression)) { - isLocked = !!(itemScope.$eval(ctrl.lockChoiceExpression)); // force the boolean value - item._uiSelectChoiceLocked = isLocked; // store this for later reference + // Force the boolean value + isLocked = !!(itemScope.$eval(ctrl.lockChoiceExpression)); + // Store this for later reference + item._uiSelectChoiceLocked = isLocked; } return isLocked; @@ -387,7 +440,8 @@ uis.controller('uiSelectCtrl', }; ctrl.searchInput.css('width', '10px'); - $timeout(function () { //Give time to render correctly + $timeout(function () { + // Give time to render correctly if (sizeWatch === null && !updateIfVisible(calculateContainerWidth())) { sizeWatch = $scope.$watch(calculateContainerWidth, function (containerWidth) { if (updateIfVisible(containerWidth)) { @@ -404,7 +458,8 @@ uis.controller('uiSelectCtrl', switch (key) { case KEY.DOWN: if (!ctrl.open && ctrl.multiple) { - ctrl.activate(false, true); //In case its the search input in 'multiple' mode + // In case its the search input in 'multiple' mode + ctrl.activate(false, true); } else if (ctrl.activeIndex < ctrl.items.length - 1) { ctrl.activeIndex++; @@ -499,7 +554,7 @@ uis.controller('uiSelectCtrl', container[0].scrollTop += posY - height; } else if (posY < highlighted.clientHeight) { if (ctrl.isGrouped && ctrl.activeIndex === 0) { - //To make group header visible when going all the way up + // To make group header visible when going all the way up container[0].scrollTop = 0; } else { diff --git a/src/uiSelectDirective.js b/src/uiSelectDirective.js index 56bc6738d..115d5909a 100644 --- a/src/uiSelectDirective.js +++ b/src/uiSelectDirective.js @@ -17,14 +17,15 @@ uis.directive('uiSelect', controllerAs: '$select', compile: function (tElement, tAttrs) { - //Multiple or Single depending if multiple attribute presence - if (angular.isDefined(tAttrs.multiple)) + // Multiple or Single depending if multiple attribute presence + if (angular.isDefined(tAttrs.multiple)) { tElement.append("").removeAttr('multiple'); - else + } + else { tElement.append(""); + } return function (scope, element, attrs, ctrls, transcludeFn) { - var $select = ctrls[0]; var ngModel = ctrls[1]; @@ -46,11 +47,12 @@ uis.directive('uiSelect', $select.onRemoveCallback = $parse(attrs.onRemove); $select.onBeforeRemoveCallback = $parse(attrs.onBeforeRemove); $select.onKeypressCallback = $parse(attrs.onKeypress); + $select.onDropdownCallback = $parse(attrs.onDropdown); - //Limit the number of selections allowed + // Limit the number of selections allowed $select.limit = (angular.isDefined(attrs.limit)) ? parseInt(attrs.limit, 10) : undefined; - //Set reference to ngModel from uiSelectCtrl + // Set reference to ngModel from uiSelectCtrl $select.ngModel = ngModel; $select.choiceGrouped = function (group) { @@ -84,7 +86,7 @@ uis.directive('uiSelect', }); } - //Gets focus based on scope event name (e.g. focus-on='SomeEventName') + // Gets focus based on scope event name (e.g. focus-on='SomeEventName') if (angular.isDefined(attrs.focusOn)) { scope.$on(attrs.focusOn, function () { $timeout(function () { @@ -94,7 +96,10 @@ uis.directive('uiSelect', } function onDocumentClick(e) { - if (!$select.open) return; //Skip it if dropdown is close + //Skip it if dropdown is close + if (!$select.open) { + return; + } var contains = false; @@ -107,14 +112,14 @@ uis.directive('uiSelect', } if (!contains && !$select.clickTriggeredSelect) { - //Will lose focus only with certain targets + // Will lose focus only with certain targets var focusableControls = ['input', 'button', 'textarea']; - //To check if target is other ui-select + // To check if target is other ui-select var targetScope = angular.element(e.target).scope(); - //To check if target is other ui-select + // To check if target is other ui-select var skipFocusser = targetScope && targetScope.$select && targetScope.$select !== $select; - //Check if target is input, button or textarea + // Check if target is input, button or textarea if (!skipFocusser) { skipFocusser = ~focusableControls.indexOf(e.target.tagName.toLowerCase()); } diff --git a/src/uiSelectMultipleDirective.js b/src/uiSelectMultipleDirective.js index f3a2599ab..f2c7cce37 100644 --- a/src/uiSelectMultipleDirective.js +++ b/src/uiSelectMultipleDirective.js @@ -43,13 +43,18 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel ctrl.activeMatchIndex = -1; $select.sizeSearchInput(); + // If there's no onBeforeRemove callback, then we're done + if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { + return; + } + var callbackContext = { $item: removedChoice, $model: $select.parserResult.modelMapper($scope, locals) }; // Give some time for scope propagation. - function completeRemoval() { + function completeCallback() { $timeout(function () { $select.onRemoveCallback($scope, callbackContext); }); @@ -62,21 +67,21 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel // falsy: Abort the removal // promise: Wait for response // true: Complete removal - var onBeforeRemoveResult = ctrl.onBeforeRemoveCallback($scope, callbackContext); - if (angular.isDefined(onBeforeRemoveResult)) { - if (angular.isFunction(onBeforeRemoveResult.then)) { + var result = ctrl.onBeforeRemoveCallback($scope, callbackContext); + if (angular.isDefined(result)) { + if (angular.isFunction(result.then)) { // Promise returned - wait for it to complete before completing the selection - onBeforeRemoveResult.then(function (result) { + result.then(function (result) { if (!result) { return; } - completeRemoval(result); + completeCallback(result); }); - } else if (onBeforeRemoveResult === true) { - completeRemoval(); + } else if (result === true) { + completeCallback(); } } else { - completeRemoval(); + completeCallback(); } }; diff --git a/src/uiSelectSingleDirective.js b/src/uiSelectSingleDirective.js index b1987ee5c..1b25146a4 100644 --- a/src/uiSelectSingleDirective.js +++ b/src/uiSelectSingleDirective.js @@ -7,7 +7,7 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co var $select = ctrls[0]; var ngModel = ctrls[1]; - //From view --> model + // From view --> model ngModel.$parsers.unshift(function (inputValue) { var locals = {}, result; @@ -16,7 +16,7 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co return result; }); - //From model --> view + // From model --> view ngModel.$formatters.unshift(function (inputValue) { var data = $select.parserResult.source(scope, {$select: {search: ''}}), //Overwrite $search locals = {}, @@ -27,7 +27,7 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co result = $select.parserResult.modelMapper(scope, locals); return result == inputValue; }; - //If possible pass same object stored in $select.selected + // If possible pass same object stored in $select.selected if ($select.selected && checkFnSingle($select.selected)) { return $select.selected; } @@ -40,7 +40,7 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co return inputValue; }); - //Update viewValue if model change + // Update viewValue if model change scope.$watch('$select.selected', function (newValue) { if (ngModel.$viewValue !== newValue) { ngModel.$setViewValue(newValue); @@ -63,15 +63,16 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co }); scope.$on('uis:activate', function () { - focusser.prop('disabled', true); //Will reactivate it on .close() + // Will reactivate it on .close() + focusser.prop('disabled', true); }); - //Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954 + // Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954 var focusser = angular.element(""); $compile(focusser)(scope); $select.focusser = focusser; - //Input that will handle focus + // Input that will handle focus $select.focusInput = focusser; element.parent().append(focusser); @@ -85,8 +86,8 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co $select.focus = false; }); }); - focusser.bind("keydown", function (e) { + focusser.bind("keydown", function (e) { if (e.which === KEY.BACKSPACE) { e.preventDefault(); e.stopPropagation(); @@ -109,13 +110,13 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co }); focusser.bind("keyup input", function (e) { - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { return; } - $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input + // User pressed some regular key, so we pass it to the search input + $select.activate(focusser.val()); focusser.val(''); scope.$digest(); }); From 5b3bf5c829244faa08b0c79f5d7915faeb2c987d Mon Sep 17 00:00:00 2001 From: Chris Jackson Date: Wed, 5 Aug 2015 21:15:40 +0100 Subject: [PATCH 22/28] Remove tagging tests --- test/select.spec.js | 186 -------------------------------------------- 1 file changed, 186 deletions(-) diff --git a/test/select.spec.js b/test/select.spec.js index ed73ae569..6cf932d21 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -381,55 +381,6 @@ describe('ui-select tests', function() { expect(isDropdownOpened(el3)).toEqual(true); }); - it('should allow decline tags when tagging function returns null', function() { - scope.taggingFunc = function (name) { - return null; - }; - - var el = createUiSelect({tagging: 'taggingFunc'}); - clickMatch(el); - - $(el).scope().$select.search = 'idontexist'; - $(el).scope().$select.activeIndex = 0; - $(el).scope().$select.select('idontexist'); - - expect($(el).scope().$select.selected).not.toBeDefined(); - }); - - it('should allow tagging if the attribute says so', function() { - var el = createUiSelect({tagging: true}); - clickMatch(el); - - $(el).scope().$select.select("I don't exist"); - - expect($(el).scope().$select.selected).toEqual("I don't exist"); - }); - - it('should format new items using the tagging function when the attribute is a function', function() { - scope.taggingFunc = function (name) { - return { - name: name, - email: name + '@email.com', - group: 'Foo', - age: 12 - }; - }; - - var el = createUiSelect({tagging: 'taggingFunc'}); - clickMatch(el); - - $(el).scope().$select.search = 'idontexist'; - $(el).scope().$select.activeIndex = 0; - $(el).scope().$select.select('idontexist'); - - expect($(el).scope().$select.selected).toEqual({ - name: 'idontexist', - email: 'idontexist@email.com', - group: 'Foo', - age: 12 - }); - }); - // See when an item that evaluates to false (such as "false" or "no") is selected, the placeholder is shown https://github.com/angular-ui/ui-select/pull/32 it('should not display the placeholder when item evaluates to false', function() { scope.items = ['false']; @@ -1262,58 +1213,6 @@ describe('ui-select tests', function() { expect(scope.$model).toBe(scope.$item); }); - it('should allow creating tag in single select mode with tagging enabled', function() { - - scope.taggingFunc = function (name) { - return name; - }; - - var el = compileTemplate( - ' \ - {{$select.selected.name}} \ - \ -
    \ -
    \ -
    \ -
    ' - ); - - clickMatch(el); - - var searchInput = el.find('.ui-select-search'); - - setSearchText(el, 'idontexist'); - - triggerKeydown(searchInput, Key.Enter); - - expect($(el).scope().$select.selected).toEqual('idontexist'); - }); - - it('should allow creating tag on ENTER in multiple select mode with tagging enabled, no labels', function() { - - scope.taggingFunc = function (name) { - return name; - }; - - var el = compileTemplate( - ' \ - {{$select.selected.name}} \ - \ -
    \ -
    \ -
    \ -
    ' - ); - - var searchInput = el.find('.ui-select-search'); - - setSearchText(el, 'idontexist'); - - triggerKeydown(searchInput, Key.Enter); - - expect($(el).scope().$select.selected).toEqual(['idontexist']); - }); - it('should append/transclude content (with correct scope) that users add at tag', function () { var el = compileTemplate( @@ -1357,62 +1256,6 @@ describe('ui-select tests', function() { }); - it('should call refresh function when search text changes', function () { - - var el = compileTemplate( - ' \ - \ - \ - \ -
    \ -
    \ - I should appear only once\ -
    \ -
    \ -
    ' - ); - - scope.fetchFromServer = function(){}; - - spyOn(scope, 'fetchFromServer'); - - el.scope().$select.search = 'r'; - scope.$digest(); - $timeout.flush(); - - expect(scope.fetchFromServer).toHaveBeenCalledWith('r'); - - }); - - it('should call refresh function when search text changes', function () { - - var el = compileTemplate( - ' \ - \ - \ - \ -
    \ -
    \ - I should appear only once\ -
    \ -
    \ -
    ' - ); - - scope.fetchFromServer = function(){}; - - spyOn(scope, 'fetchFromServer'); - - el.scope().$select.search = 'r'; - scope.$digest(); - $timeout.flush(); - - expect(scope.fetchFromServer).toHaveBeenCalledWith('r'); - - }); - it('should format view value correctly when using single property binding and refresh function', function () { var el = compileTemplate( @@ -2253,33 +2096,4 @@ describe('ui-select tests', function() { expect(el.css('width')).toBe(originalWidth); }); }); - - describe('with refresh on active', function(){ - it('should not refresh untill is activate', function(){ - - var el = compileTemplate( - ' \ - \ - \ - \ -
    \ -
    \ - I should appear only once\ -
    \ -
    \ -
    ' - ); - - scope.fetchFromServer = function(){}; - spyOn(scope, 'fetchFromServer'); - $timeout.flush(); - expect(scope.fetchFromServer.calls.any()).toEqual(false); - - el.scope().$select.activate(); - $timeout.flush(); - expect(scope.fetchFromServer.calls.any()).toEqual(true); - }); - - }); }); From 59ec2050762755d2fc036ecd652686161722a142 Mon Sep 17 00:00:00 2001 From: Chris Jackson Date: Thu, 6 Aug 2015 12:00:55 +0100 Subject: [PATCH 23/28] Add sort directive and update tests --- dist/select.bootstrap.js | 41 +- dist/select.bootstrap.min.js | 4 +- dist/select.css | 2 +- dist/select.js | 186 +- dist/select.min.css | 2 +- dist/select.min.js | 4 +- dist/select.no-tpl.js | 41 +- dist/select.no-tpl.min.js | 4 +- dist/select.select2.js | 41 +- dist/select.select2.min.js | 4 +- dist/select.selectize.js | 41 +- dist/select.selectize.min.js | 4 +- dist/select.sort.js | 153 ++ dist/select.sort.min.js | 7 + dist/select.tpl.js | 2 +- examples/newdemo.html | 8 +- examples/newdemo.js | 2 +- src/addons/uiSelectSortDirective.js | 275 +-- src/uiSelectController.js | 22 +- src/uiSelectDirective.js | 8 +- src/uiSelectMultipleDirective.js | 17 +- test/select.spec.js | 3277 ++++++++++++++------------- 22 files changed, 2271 insertions(+), 1874 deletions(-) create mode 100644 dist/select.sort.js create mode 100644 dist/select.sort.min.js diff --git a/dist/select.bootstrap.js b/dist/select.bootstrap.js index 18aeaa587..ca874abde 100644 --- a/dist/select.bootstrap.js +++ b/dist/select.bootstrap.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-05T18:50:43.064Z + * Version: 0.12.1 - 2015-08-06T11:06:02.027Z * License: MIT */ @@ -588,7 +588,6 @@ uis.controller('uiSelectCtrl', * @return {boolean} true if the item is disabled */ ctrl.isDisabled = function (itemScope) { - if (!ctrl.open) { return false; } @@ -608,7 +607,8 @@ uis.controller('uiSelectCtrl', /** - * Selects an item + * Selects an item. Calls the onBeforeSelect and onSelect callbacks + * onBeforeSelect can alter or abort the selection * * Called when the user selects an item with ENTER or clicks the dropdown */ @@ -648,6 +648,12 @@ uis.controller('uiSelectCtrl', } }; + // If there's no onBeforeSelect callback, then just call the completeCallback + if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { + completeCallback(item); + return; + } + // Call the onBeforeSelect callback // Allowable responses are -: // falsy: Abort the selection @@ -658,11 +664,15 @@ uis.controller('uiSelectCtrl', if (angular.isDefined(result)) { if (angular.isFunction(result.then)) { // Promise returned - wait for it to complete before completing the selection - result.then(function (result) { - if (!result) { + result.then(function (response) { + if (!response) { return; } - completeCallback(result); + if (response === true) { + completeCallback(item); + } else if (response) { + completeCallback(response); + } }); } else if (result === true) { completeCallback(item); @@ -914,8 +924,8 @@ uis.controller('uiSelectCtrl', }]); uis.directive('uiSelect', - ['$document', 'uiSelectConfig', 'uiSelectMinErr', 'uisOffset', '$compile', '$parse', '$timeout', - function ($document, uiSelectConfig, uiSelectMinErr, uisOffset, $compile, $parse, $timeout) { + ['$document', '$window', 'uiSelectConfig', 'uiSelectMinErr', 'uisOffset', '$compile', '$parse', '$timeout', + function ($document, $window, uiSelectConfig, uiSelectMinErr, uisOffset, $compile, $parse, $timeout) { return { restrict: 'EA', @@ -1162,9 +1172,7 @@ uis.directive('uiSelect', var offsetDropdown = uisOffset(dropdown); // Determine if the direction of the dropdown needs to be changed. - if (offset.top + offset.height + offsetDropdown.height > - $document[0].documentElement.scrollTop + - $document[0].documentElement.clientHeight) { + if (offset.top + offset.height + offsetDropdown.height > $window.pageYOffset + $document[0].documentElement.clientHeight) { element.addClass(directionUpClassName); } @@ -1263,11 +1271,6 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel ctrl.activeMatchIndex = -1; $select.sizeSearchInput(); - // If there's no onBeforeRemove callback, then we're done - if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { - return; - } - var callbackContext = { $item: removedChoice, $model: $select.parserResult.modelMapper($scope, locals) @@ -1282,6 +1285,12 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel ctrl.updateModel(); } + // If there's no onBeforeRemove callback, then just call the completeCallback + if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { + completeCallback(); + return; + } + // Call the onBeforeRemove callback // Allowable responses are -: // falsy: Abort the removal diff --git a/dist/select.bootstrap.min.js b/dist/select.bootstrap.min.js index cddcf21d5..a72fde445 100644 --- a/dist/select.bootstrap.min.js +++ b/dist/select.bootstrap.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-05T18:50:43.064Z + * Version: 0.12.1 - 2015-08-06T11:06:02.027Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var n=t.which;switch(n){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,n=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,i,c){c(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var i=n[0].getBoundingClientRect();return{width:i.width||n.prop("offsetWidth"),height:i.height||n.prop("offsetHeight"),top:i.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:i.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);n.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,c){if(!c.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,c,l,s,r){var a=l.groupBy,o=l.groupFilter;if(s.parseRepeatAttr(l.repeat,a,o),s.disableChoiceExpression=l.uiDisableChoice,s.onHighlightCallback=l.onHighlight,a){var u=c.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=c.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(s.parserResult.itemName,"$select.items",s.parserResult.trackByExp,a)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+s.parserResult.itemName+")").attr("ng-click","$select.select("+s.parserResult.itemName+",false,$event)");var d=c.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),i(c,r)(e),e.$watch("$select.search",function(e){e&&!s.open&&s.multiple&&s.activate(!1,!0),s.activeIndex=0})}}}}]),n.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,n,i,c,l,s,r,a){function o(){(h.resetSearchInput||void 0===h.resetSearchInput&&a.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var n,i,c=[];for(n=0;n0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:n=!1}return n}function d(){var e=n.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw r("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var i=t[h.activeIndex],c=i.offsetTop+i.clientHeight-e[0].scrollTop,l=e[0].offsetHeight;c>l?e[0].scrollTop+=c-l:c=h.items.length?0:h.activeIndex,i(function(){h.search=e||h.search,h.searchInput[0].focus()})},l=h.onDropdownCallback(t,{open:!0});angular.isDefined(l)?angular.isFunction(l.then)?l.then(function(e){e&&c()}):l===!0?c():l&&c():c()}},h.parseRepeatAttr=function(e,n,i){function c(e){var c=t.$eval(n);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(c)?c(e):e[c],n=h.findGroupByName(t);n?n.items.push(e):h.groups.push({name:t,items:[e]})}),i){var l=t.$eval(i);angular.isFunction(l)?h.groups=l(h.groups):angular.isArray(l)&&(h.groups=u(h.groups,l))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function l(e){h.items=e}h.setItemsFn=n?c:l,h.parserResult=s.parse(e),h.isGrouped=!!n,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var n=h.selected;if(h.isEmpty()||angular.isArray(n)&&!n.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var i=e.filter(function(e){return n.indexOf(e)<0});h.setItemsFn(i)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw r("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),n=-1===t?!1:t===h.activeIndex;return n&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),n},h.isDisabled=function(e){if(!h.open)return!1;var t,n=h.items.indexOf(e[h.itemProperty]),i=!1;return n>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[n],i=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i},h.select=function(e,n,c){if((void 0===e||!e._uiSelectChoiceDisabled)&&(h.items||h.search)){var l={};l[h.parserResult.itemName]=e;var s={$item:e,$model:h.parserResult.modelMapper(t,l)},r=function(e){s.$item=e,t.$broadcast("uis:select",e),i(function(){h.onSelectCallback(t,s)}),h.closeOnSelect&&h.close(n),c&&"click"===c.type&&(h.clickTriggeredSelect=!0)},a=h.onBeforeSelectCallback(t,s);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(e){e&&r(e)}):a===!0?r(e):a&&r(a):r(e)}},h.close=function(e){function n(){h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),o(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e)}if(h.open){var i=h.onDropdownCallback(t,{open:!1});angular.isDefined(i)?angular.isFunction(i.then)?i.then(function(e){e&&n()}):i===!0?n():i&&n():n()}},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),i(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var n,i=h.selected[t];return i&&!angular.isUndefined(h.lockChoiceExpression)&&(n=!!e.$eval(h.lockChoiceExpression),i._uiSelectChoiceLocked=n),n};var g=null;h.sizeSearchInput=function(){var e=h.searchInput[0],n=h.searchInput.parent().parent()[0],c=function(){return n.clientWidth*!!e.offsetParent},l=function(t){if(0===t)return!1;var n=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=t),h.searchInput.css("width",n+"px"),!0};h.searchInput.css("width","10px"),i(function(){null!==g||l(c())||(g=t.$watch(c,function(e){l(e)&&(g(),g=null)}))})},h.searchInput.on("keydown",function(n){var i=n.which;t.$apply(function(){p(i)}),e.isVerticalMovement(i)&&h.items.length>0&&d(),(i===e.ENTER||i===e.ESC)&&(n.preventDefault(),n.stopPropagation())}),h.searchInput.on("keyup",function(n){n.which===e.TAB||e.isControl(n)||e.isFunctionKey(n)||n.which===e.ESC||e.isVerticalMovement(n.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:n})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),n.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,i,c,l,s){return{restrict:"EA",templateUrl:function(e,n){var i=n.theme||t.theme;return i+(angular.isDefined(n.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(c,r){return angular.isDefined(r.multiple)?c.append("").removeAttr("multiple"):c.append(""),function(c,r,a,o,u){function p(e){if(f.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(r[0],e.target):r[0].contains(e.target),!t&&!f.clickTriggeredSelect){var n=["input","button","textarea"],i=angular.element(e.target).scope(),l=i&&i.$select&&i.$select!==f;l||(l=~n.indexOf(e.target.tagName.toLowerCase())),f.close(l),c.$digest()}f.clickTriggeredSelect=!1}}function d(){var t=i(r);b=angular.element('
    '),b[0].style.width=t.width+"px",b[0].style.height=t.height+"px",r.after(b),E=r[0].style.width,e.find("body").append(r),r[0].style.position="absolute",r[0].style.left=t.left+"px",r[0].style.top=t.top+"px",r[0].style.width=t.width+"px"}function h(){null!==b&&(b.replaceWith(r),b=null,r[0].style.position="",r[0].style.left="",r[0].style.top="",r[0].style.width=E)}var f=o[0],g=o[1];f.generatedId=t.generateId(),f.baseTitle=a.title||"Select box",f.focusserTitle=f.baseTitle+" focus",f.focusserId="focusser-"+f.generatedId,f.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?l(a.closeOnSelect)():t.closeOnSelect}(),f.onSelectCallback=l(a.onSelect),f.onBeforeSelectCallback=l(a.onBeforeSelect),f.onRemoveCallback=l(a.onRemove),f.onBeforeRemoveCallback=l(a.onBeforeRemove),f.onKeypressCallback=l(a.onKeypress),f.onDropdownCallback=l(a.onDropdown),f.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,f.ngModel=g,f.choiceGrouped=function(e){return f.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){f.focusInput.attr("tabindex",e),r.removeAttr("tabindex")});var m=c.$eval(a.searchEnabled);f.searchEnabled=void 0!==m?m:t.searchEnabled;var v=c.$eval(a.sortable);f.sortable=void 0!==v?v:t.sortable,a.$observe("disabled",function(){f.disabled=void 0!==a.disabled?a.disabled:!1}),angular.isDefined(a.autofocus)&&s(function(){f.setFocus()}),angular.isDefined(a.focusOn)&&c.$on(a.focusOn,function(){s(function(){f.setFocus()})}),e.on("click",p),c.$on("$destroy",function(){e.off("click",p)}),u(c,function(e){var t=angular.element("
    ").append(e),i=t.querySelectorAll(".ui-select-match");if(i.removeAttr("ui-select-match"),i.removeAttr("data-ui-select-match"),1!==i.length)throw n("transcluded","Expected 1 .ui-select-match but got '{0}'.",i.length);r.querySelectorAll(".ui-select-match").replaceWith(i);var c=t.querySelectorAll(".ui-select-choices");if(c.removeAttr("ui-select-choices"),c.removeAttr("data-ui-select-choices"),1!==c.length)throw n("transcluded","Expected 1 .ui-select-choices but got '{0}'.",c.length);r.querySelectorAll(".ui-select-choices").replaceWith(c)});var $=c.$eval(a.appendToBody);(void 0!==$?$:t.appendToBody)&&(c.$watch("$select.open",function(e){e?d():h()}),c.$on("$destroy",function(){h()}));var b=null,E="",w=null,x="direction-up";c.$watch("$select.open",function(t){if(t){if(w=angular.element(r).querySelectorAll(".ui-select-dropdown"),null===w)return;w[0].style.opacity=0,s(function(){var t=i(r),n=i(w);t.top+t.height+n.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&r.addClass(x),w[0].style.opacity=1})}else{if(null===w)return;r.removeClass(x)}})}}}}]),n.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return n+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,i,c){function l(e){c.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}c.lockChoiceExpression=i.uiLockChoice,i.$observe("placeholder",function(t){c.placeholder=void 0!==t?t:e.placeholder}),i.$observe("allowClear",l),l(i.allowClear),c.multiple&&c.sizeSearchInput()}}}]),n.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,i=this,c=e.$select;e.$evalAsync(function(){n=e.ngModel}),i.activeMatchIndex=-1,i.updateModel=function(){n.$setViewValue(Date.now()),i.refreshComponent()},i.refreshComponent=function(){c.refreshItems(),c.sizeSearchInput()},i.removeChoice=function(n){function l(){t(function(){c.onRemoveCallback(e,a)}),i.updateModel()}var s=c.selected[n];if(!s._uiSelectChoiceLocked){var r={};if(r[c.parserResult.itemName]=s,c.selected.splice(n,1),i.activeMatchIndex=-1,c.sizeSearchInput(),angular.isDefined(i.onBeforeRemoveCallback)){var a={$item:s,$model:c.parserResult.modelMapper(e,r)},o=i.onBeforeRemoveCallback(e,a);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(e){e&&l(e)}):o===!0&&l():l()}}},i.getPlaceholder=function(){return c.selected&&c.selected.length?void 0:c.placeholder}}],controllerAs:"$selectMultiple",link:function(i,c,l,s){function r(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(t){function n(){switch(t){case e.LEFT:return~p.activeMatchIndex?d:s;case e.RIGHT:return~p.activeMatchIndex&&a!==s?u:(o.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(a),d):s;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),a):!1}}var i=r(o.searchInput[0]),c=o.selected.length,l=0,s=c-1,a=p.activeMatchIndex,u=p.activeMatchIndex+1,d=p.activeMatchIndex-1,h=a;return i>0||o.search.length&&t==e.RIGHT?!1:(o.close(),h=n(),p.activeMatchIndex=o.selected.length&&h!==!1?Math.min(s,Math.max(l,h)):-1,!0)}var o=s[0],u=i.ngModel=s[1],p=i.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,u.$parsers.unshift(function(){for(var e,t={},n=[],c=o.selected.length-1;c>=0;c--)t={},t[o.parserResult.itemName]=o.selected[c],e=o.parserResult.modelMapper(i,t),n.unshift(e);return n}),u.$formatters.unshift(function(e){var t,n=o.parserResult.source(i,{$select:{search:""}}),c={};if(!n)return e;var l=[],s=function(e,n){if(e&&e.length){for(var s=e.length-1;s>=0;s--){if(c[o.parserResult.itemName]=e[s],t=o.parserResult.modelMapper(i,c),o.parserResult.trackByExp){var r=/\.(.+)/.exec(o.parserResult.trackByExp);if(r.length>0&&t[r[1]]==n[r[1]])return l.unshift(e[s]),!0}if(angular.equals(t,n))return l.unshift(e[s]),!0}return!1}};if(!e)return l;for(var r=e.length-1;r>=0;r--)s(o.selected,e[r])||s(n,e[r])||l.unshift(e[r]);return l}),i.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);o.selected=[]}o.selected=u.$viewValue,i.$evalAsync()},i.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),p.updateModel())}),i.$on("uis:activate",function(){p.activeMatchIndex=-1}),i.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(t){var n=t.which;i.$apply(function(){var t=!1;e.isHorizontalMovement(n)&&(t=a(n)),t&&n!=e.TAB})}),o.searchInput.on("blur",function(){n(function(){p.activeMatchIndex=-1})})}}}]),n.directive("uiSelectSingle",["$timeout","$compile",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(i,c,l,s){var r=s[0],a=s[1];a.$parsers.unshift(function(e){var t,n={};return n[r.parserResult.itemName]=e,t=r.parserResult.modelMapper(i,n)}),a.$formatters.unshift(function(e){var t,n=r.parserResult.source(i,{$select:{search:""}}),c={};if(n){var l=function(n){return c[r.parserResult.itemName]=n,t=r.parserResult.modelMapper(i,c),t==e};if(r.selected&&l(r.selected))return r.selected;for(var s=n.length-1;s>=0;s--)if(l(n[s]))return n[s]}return e}),i.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){r.selected=a.$viewValue},i.$on("uis:select",function(e,t){r.selected=t}),i.$on("uis:close",function(e,n){t(function(){r.focusser.prop("disabled",!1),n||r.focusser[0].focus()},0,!1)}),i.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");n(o)(i),r.focusser=o,r.focusInput=o,c.parent().append(o),o.bind("focus",function(){i.$evalAsync(function(){r.focus=!0})}),o.bind("blur",function(){i.$evalAsync(function(){r.focus=!1})}),o.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),r.select(void 0),i.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),r.activate()),i.$digest()),void 0)}),o.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(r.activate(o.val()),o.val(""),i.$digest())})}}}]),n.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var i=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!i)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:i[2],source:t(i[3]),trackByExp:i[4],modelMapper:t(i[1]||i[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,i){var c=e+" in "+(i?"$group.items":t);return n&&(c+=" track by "+n),c}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",'
    {{$select.placeholder}}
    '),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",'')}]); \ No newline at end of file +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var n=t.which;switch(n){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,n=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,i,c){c(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var i=n[0].getBoundingClientRect();return{width:i.width||n.prop("offsetWidth"),height:i.height||n.prop("offsetHeight"),top:i.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:i.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);n.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,c){if(!c.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,c,l,s,r){var a=l.groupBy,o=l.groupFilter;if(s.parseRepeatAttr(l.repeat,a,o),s.disableChoiceExpression=l.uiDisableChoice,s.onHighlightCallback=l.onHighlight,a){var u=c.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=c.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(s.parserResult.itemName,"$select.items",s.parserResult.trackByExp,a)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+s.parserResult.itemName+")").attr("ng-click","$select.select("+s.parserResult.itemName+",false,$event)");var d=c.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),i(c,r)(e),e.$watch("$select.search",function(e){e&&!s.open&&s.multiple&&s.activate(!1,!0),s.activeIndex=0})}}}}]),n.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,n,i,c,l,s,r,a){function o(){(h.resetSearchInput||void 0===h.resetSearchInput&&a.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var n,i,c=[];for(n=0;n0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:n=!1}return n}function d(){var e=n.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw r("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var i=t[h.activeIndex],c=i.offsetTop+i.clientHeight-e[0].scrollTop,l=e[0].offsetHeight;c>l?e[0].scrollTop+=c-l:c=h.items.length?0:h.activeIndex,i(function(){h.search=e||h.search,h.searchInput[0].focus()})},l=h.onDropdownCallback(t,{open:!0});angular.isDefined(l)?angular.isFunction(l.then)?l.then(function(e){e&&c()}):l===!0?c():l&&c():c()}},h.parseRepeatAttr=function(e,n,i){function c(e){var c=t.$eval(n);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(c)?c(e):e[c],n=h.findGroupByName(t);n?n.items.push(e):h.groups.push({name:t,items:[e]})}),i){var l=t.$eval(i);angular.isFunction(l)?h.groups=l(h.groups):angular.isArray(l)&&(h.groups=u(h.groups,l))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function l(e){h.items=e}h.setItemsFn=n?c:l,h.parserResult=s.parse(e),h.isGrouped=!!n,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var n=h.selected;if(h.isEmpty()||angular.isArray(n)&&!n.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var i=e.filter(function(e){return n.indexOf(e)<0});h.setItemsFn(i)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw r("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),n=-1===t?!1:t===h.activeIndex;return n&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),n},h.isDisabled=function(e){if(!h.open)return!1;var t,n=h.items.indexOf(e[h.itemProperty]),i=!1;return n>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[n],i=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i},h.select=function(e,n,c){if((void 0===e||!e._uiSelectChoiceDisabled)&&(h.items||h.search)){var l={};l[h.parserResult.itemName]=e;var s={$item:e,$model:h.parserResult.modelMapper(t,l)},r=function(e){s.$item=e,t.$broadcast("uis:select",e),i(function(){h.onSelectCallback(t,s)}),h.closeOnSelect&&h.close(n),c&&"click"===c.type&&(h.clickTriggeredSelect=!0)};if(!angular.isDefined(h.onBeforeRemoveCallback))return r(e),void 0;var a=h.onBeforeSelectCallback(t,s);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(t){t&&(t===!0?r(e):t&&r(t))}):a===!0?r(e):a&&r(a):r(e)}},h.close=function(e){function n(){h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),o(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e)}if(h.open){var i=h.onDropdownCallback(t,{open:!1});angular.isDefined(i)?angular.isFunction(i.then)?i.then(function(e){e&&n()}):i===!0?n():i&&n():n()}},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),i(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var n,i=h.selected[t];return i&&!angular.isUndefined(h.lockChoiceExpression)&&(n=!!e.$eval(h.lockChoiceExpression),i._uiSelectChoiceLocked=n),n};var g=null;h.sizeSearchInput=function(){var e=h.searchInput[0],n=h.searchInput.parent().parent()[0],c=function(){return n.clientWidth*!!e.offsetParent},l=function(t){if(0===t)return!1;var n=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=t),h.searchInput.css("width",n+"px"),!0};h.searchInput.css("width","10px"),i(function(){null!==g||l(c())||(g=t.$watch(c,function(e){l(e)&&(g(),g=null)}))})},h.searchInput.on("keydown",function(n){var i=n.which;t.$apply(function(){p(i)}),e.isVerticalMovement(i)&&h.items.length>0&&d(),(i===e.ENTER||i===e.ESC)&&(n.preventDefault(),n.stopPropagation())}),h.searchInput.on("keyup",function(n){n.which===e.TAB||e.isControl(n)||e.isFunctionKey(n)||n.which===e.ESC||e.isVerticalMovement(n.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:n})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),n.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,i,c,l,s,r){return{restrict:"EA",templateUrl:function(e,t){var i=t.theme||n.theme;return i+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(l,a){return angular.isDefined(a.multiple)?l.append("").removeAttr("multiple"):l.append(""),function(l,a,o,u,p){function d(e){if(g.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(a[0],e.target):a[0].contains(e.target),!t&&!g.clickTriggeredSelect){var n=["input","button","textarea"],i=angular.element(e.target).scope(),c=i&&i.$select&&i.$select!==g;c||(c=~n.indexOf(e.target.tagName.toLowerCase())),g.close(c),l.$digest()}g.clickTriggeredSelect=!1}}function h(){var t=c(a);E=angular.element('
    '),E[0].style.width=t.width+"px",E[0].style.height=t.height+"px",a.after(E),w=a[0].style.width,e.find("body").append(a),a[0].style.position="absolute",a[0].style.left=t.left+"px",a[0].style.top=t.top+"px",a[0].style.width=t.width+"px"}function f(){null!==E&&(E.replaceWith(a),E=null,a[0].style.position="",a[0].style.left="",a[0].style.top="",a[0].style.width=w)}var g=u[0],v=u[1];g.generatedId=n.generateId(),g.baseTitle=o.title||"Select box",g.focusserTitle=g.baseTitle+" focus",g.focusserId="focusser-"+g.generatedId,g.closeOnSelect=function(){return angular.isDefined(o.closeOnSelect)?s(o.closeOnSelect)():n.closeOnSelect}(),g.onSelectCallback=s(o.onSelect),g.onBeforeSelectCallback=s(o.onBeforeSelect),g.onRemoveCallback=s(o.onRemove),g.onBeforeRemoveCallback=s(o.onBeforeRemove),g.onKeypressCallback=s(o.onKeypress),g.onDropdownCallback=s(o.onDropdown),g.limit=angular.isDefined(o.limit)?parseInt(o.limit,10):void 0,g.ngModel=v,g.choiceGrouped=function(e){return g.isGrouped&&e&&e.name},o.tabindex&&o.$observe("tabindex",function(e){g.focusInput.attr("tabindex",e),a.removeAttr("tabindex")});var m=l.$eval(o.searchEnabled);g.searchEnabled=void 0!==m?m:n.searchEnabled;var $=l.$eval(o.sortable);g.sortable=void 0!==$?$:n.sortable,o.$observe("disabled",function(){g.disabled=void 0!==o.disabled?o.disabled:!1}),angular.isDefined(o.autofocus)&&r(function(){g.setFocus()}),angular.isDefined(o.focusOn)&&l.$on(o.focusOn,function(){r(function(){g.setFocus()})}),e.on("click",d),l.$on("$destroy",function(){e.off("click",d)}),p(l,function(e){var t=angular.element("
    ").append(e),n=t.querySelectorAll(".ui-select-match");if(n.removeAttr("ui-select-match"),n.removeAttr("data-ui-select-match"),1!==n.length)throw i("transcluded","Expected 1 .ui-select-match but got '{0}'.",n.length);a.querySelectorAll(".ui-select-match").replaceWith(n);var c=t.querySelectorAll(".ui-select-choices");if(c.removeAttr("ui-select-choices"),c.removeAttr("data-ui-select-choices"),1!==c.length)throw i("transcluded","Expected 1 .ui-select-choices but got '{0}'.",c.length);a.querySelectorAll(".ui-select-choices").replaceWith(c)});var b=l.$eval(o.appendToBody);(void 0!==b?b:n.appendToBody)&&(l.$watch("$select.open",function(e){e?h():f()}),l.$on("$destroy",function(){f()}));var E=null,w="",x=null,S="direction-up";l.$watch("$select.open",function(n){if(n){if(x=angular.element(a).querySelectorAll(".ui-select-dropdown"),null===x)return;x[0].style.opacity=0,r(function(){var n=c(a),i=c(x);n.top+n.height+i.height>t.pageYOffset+e[0].documentElement.clientHeight&&a.addClass(S),x[0].style.opacity=1})}else{if(null===x)return;a.removeClass(S)}})}}}}]),n.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return n+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,i,c){function l(e){c.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}c.lockChoiceExpression=i.uiLockChoice,i.$observe("placeholder",function(t){c.placeholder=void 0!==t?t:e.placeholder}),i.$observe("allowClear",l),l(i.allowClear),c.multiple&&c.sizeSearchInput()}}}]),n.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,i=this,c=e.$select;e.$evalAsync(function(){n=e.ngModel}),i.activeMatchIndex=-1,i.updateModel=function(){n.$setViewValue(Date.now()),i.refreshComponent()},i.refreshComponent=function(){c.refreshItems(),c.sizeSearchInput()},i.removeChoice=function(n){function l(){t(function(){c.onRemoveCallback(e,a)}),i.updateModel()}var s=c.selected[n];if(!s._uiSelectChoiceLocked){var r={};r[c.parserResult.itemName]=s,c.selected.splice(n,1),i.activeMatchIndex=-1,c.sizeSearchInput();var a={$item:s,$model:c.parserResult.modelMapper(e,r)};if(!angular.isDefined(i.onBeforeRemoveCallback))return l(),void 0;var o=i.onBeforeRemoveCallback(e,a);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(e){e&&l(e)}):o===!0&&l():l()}},i.getPlaceholder=function(){return c.selected&&c.selected.length?void 0:c.placeholder}}],controllerAs:"$selectMultiple",link:function(i,c,l,s){function r(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(t){function n(){switch(t){case e.LEFT:return~p.activeMatchIndex?d:s;case e.RIGHT:return~p.activeMatchIndex&&a!==s?u:(o.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(a),d):s;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),a):!1}}var i=r(o.searchInput[0]),c=o.selected.length,l=0,s=c-1,a=p.activeMatchIndex,u=p.activeMatchIndex+1,d=p.activeMatchIndex-1,h=a;return i>0||o.search.length&&t==e.RIGHT?!1:(o.close(),h=n(),p.activeMatchIndex=o.selected.length&&h!==!1?Math.min(s,Math.max(l,h)):-1,!0)}var o=s[0],u=i.ngModel=s[1],p=i.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,u.$parsers.unshift(function(){for(var e,t={},n=[],c=o.selected.length-1;c>=0;c--)t={},t[o.parserResult.itemName]=o.selected[c],e=o.parserResult.modelMapper(i,t),n.unshift(e);return n}),u.$formatters.unshift(function(e){var t,n=o.parserResult.source(i,{$select:{search:""}}),c={};if(!n)return e;var l=[],s=function(e,n){if(e&&e.length){for(var s=e.length-1;s>=0;s--){if(c[o.parserResult.itemName]=e[s],t=o.parserResult.modelMapper(i,c),o.parserResult.trackByExp){var r=/\.(.+)/.exec(o.parserResult.trackByExp);if(r.length>0&&t[r[1]]==n[r[1]])return l.unshift(e[s]),!0}if(angular.equals(t,n))return l.unshift(e[s]),!0}return!1}};if(!e)return l;for(var r=e.length-1;r>=0;r--)s(o.selected,e[r])||s(n,e[r])||l.unshift(e[r]);return l}),i.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);o.selected=[]}o.selected=u.$viewValue,i.$evalAsync()},i.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),p.updateModel())}),i.$on("uis:activate",function(){p.activeMatchIndex=-1}),i.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(t){var n=t.which;i.$apply(function(){var t=!1;e.isHorizontalMovement(n)&&(t=a(n)),t&&n!=e.TAB})}),o.searchInput.on("blur",function(){n(function(){p.activeMatchIndex=-1})})}}}]),n.directive("uiSelectSingle",["$timeout","$compile",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(i,c,l,s){var r=s[0],a=s[1];a.$parsers.unshift(function(e){var t,n={};return n[r.parserResult.itemName]=e,t=r.parserResult.modelMapper(i,n)}),a.$formatters.unshift(function(e){var t,n=r.parserResult.source(i,{$select:{search:""}}),c={};if(n){var l=function(n){return c[r.parserResult.itemName]=n,t=r.parserResult.modelMapper(i,c),t==e};if(r.selected&&l(r.selected))return r.selected;for(var s=n.length-1;s>=0;s--)if(l(n[s]))return n[s]}return e}),i.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){r.selected=a.$viewValue},i.$on("uis:select",function(e,t){r.selected=t}),i.$on("uis:close",function(e,n){t(function(){r.focusser.prop("disabled",!1),n||r.focusser[0].focus()},0,!1)}),i.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");n(o)(i),r.focusser=o,r.focusInput=o,c.parent().append(o),o.bind("focus",function(){i.$evalAsync(function(){r.focus=!0})}),o.bind("blur",function(){i.$evalAsync(function(){r.focus=!1})}),o.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),r.select(void 0),i.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),r.activate()),i.$digest()),void 0)}),o.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(r.activate(o.val()),o.val(""),i.$digest())})}}}]),n.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var i=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!i)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:i[2],source:t(i[3]),trackByExp:i[4],modelMapper:t(i[1]||i[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,i){var c=e+" in "+(i?"$group.items":t);return n&&(c+=" track by "+n),c}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",'
    {{$select.placeholder}}
    '),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",'')}]); \ No newline at end of file diff --git a/dist/select.css b/dist/select.css index bd1f370f2..13172b0c4 100644 --- a/dist/select.css +++ b/dist/select.css @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-05T18:50:43.115Z + * Version: 0.12.1 - 2015-08-06T11:06:02.064Z * License: MIT */ diff --git a/dist/select.js b/dist/select.js index cebcb13f2..262810533 100644 --- a/dist/select.js +++ b/dist/select.js @@ -1,11 +1,156 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-05T18:50:43.112Z + * Version: 0.12.1 - 2015-08-06T11:06:02.062Z * License: MIT */ +(function () { +"use strict"; +// Make multiple matches sortable +angular.module('ui.select.sort', ['ui.select']) + .directive('uiSelectSort', + ['$timeout', 'uiSelectConfig', 'uiSelectMinErr', function ($timeout, uiSelectConfig, uiSelectMinErr) { + return { + require: '^uiSelect', + link: function (scope, element, attrs, $select) { + if (scope[attrs.uiSelectSort] === null) { + throw uiSelectMinErr('sort', "Expected a list to sort"); + } + + var options = angular.extend({ + axis: 'horizontal' + }, + scope.$eval(attrs.uiSelectSortOptions)); + + var axis = options.axis, + draggingClassName = 'dragging', + droppingClassName = 'dropping', + droppingBeforeClassName = 'dropping-before', + droppingAfterClassName = 'dropping-after'; + + scope.$watch(function () { + return $select.sortable; + }, function (n) { + if (n) { + element.attr('draggable', true); + } else { + element.removeAttr('draggable'); + } + }); + + element.on('dragstart', function (e) { + element.addClass(draggingClassName); + + (e.dataTransfer || e.originalEvent.dataTransfer).setData('text/plain', scope.$index); + }); + + element.on('dragend', function () { + element.removeClass(draggingClassName); + }); + + var move = function (from, to) { + /*jshint validthis: true */ + this.splice(to, 0, this.splice(from, 1)[0]); + }; + + var dragOverHandler = function (e) { + e.preventDefault(); + + var offset = axis === 'vertical' ? + e.offsetY || e.layerY || (e.originalEvent ? e.originalEvent.offsetY : 0) : + e.offsetX || e.layerX || (e.originalEvent ? e.originalEvent.offsetX : 0); + + if (offset < (this[axis === 'vertical' ? 'offsetHeight' : 'offsetWidth'] / 2)) { + element.removeClass(droppingAfterClassName); + element.addClass(droppingBeforeClassName); + + } else { + element.removeClass(droppingBeforeClassName); + element.addClass(droppingAfterClassName); + } + }; + + var dropTimeout; + + var dropHandler = function (e) { + e.preventDefault(); + + var droppedItemIndex = parseInt((e.dataTransfer || + e.originalEvent.dataTransfer).getData('text/plain'), 10); + + // prevent event firing multiple times in firefox + $timeout.cancel(dropTimeout); + dropTimeout = $timeout(function () { + _dropHandler(droppedItemIndex); + }, 20); + }; + + var _dropHandler = function (droppedItemIndex) { + var theList = scope.$eval(attrs.uiSelectSort), + itemToMove = theList[droppedItemIndex], + newIndex = null; + + if (element.hasClass(droppingBeforeClassName)) { + if (droppedItemIndex < scope.$index) { + newIndex = scope.$index - 1; + } else { + newIndex = scope.$index; + } + } else { + if (droppedItemIndex < scope.$index) { + newIndex = scope.$index; + } else { + newIndex = scope.$index + 1; + } + } + + move.apply(theList, [droppedItemIndex, newIndex]); + + scope.$apply(function () { + scope.$emit('uiSelectSort:change', { + array: theList, + item: itemToMove, + from: droppedItemIndex, + to: newIndex + }); + }); + + element.removeClass(droppingClassName); + element.removeClass(droppingBeforeClassName); + element.removeClass(droppingAfterClassName); + + element.off('drop', dropHandler); + }; + + element.on('dragenter', function () { + if (element.hasClass(draggingClassName)) { + return; + } + + element.addClass(droppingClassName); + + element.on('dragover', dragOverHandler); + element.on('drop', dropHandler); + }); + + element.on('dragleave', function (e) { + if (e.target != element) { + return; + } + element.removeClass(droppingClassName); + element.removeClass(droppingBeforeClassName); + element.removeClass(droppingAfterClassName); + + element.off('dragover', dragOverHandler); + element.off('drop', dropHandler); + }); + } + }; + }]); + +}()); (function () { "use strict"; var KEY = { @@ -588,7 +733,6 @@ uis.controller('uiSelectCtrl', * @return {boolean} true if the item is disabled */ ctrl.isDisabled = function (itemScope) { - if (!ctrl.open) { return false; } @@ -608,7 +752,8 @@ uis.controller('uiSelectCtrl', /** - * Selects an item + * Selects an item. Calls the onBeforeSelect and onSelect callbacks + * onBeforeSelect can alter or abort the selection * * Called when the user selects an item with ENTER or clicks the dropdown */ @@ -648,6 +793,12 @@ uis.controller('uiSelectCtrl', } }; + // If there's no onBeforeSelect callback, then just call the completeCallback + if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { + completeCallback(item); + return; + } + // Call the onBeforeSelect callback // Allowable responses are -: // falsy: Abort the selection @@ -658,11 +809,15 @@ uis.controller('uiSelectCtrl', if (angular.isDefined(result)) { if (angular.isFunction(result.then)) { // Promise returned - wait for it to complete before completing the selection - result.then(function (result) { - if (!result) { + result.then(function (response) { + if (!response) { return; } - completeCallback(result); + if (response === true) { + completeCallback(item); + } else if (response) { + completeCallback(response); + } }); } else if (result === true) { completeCallback(item); @@ -914,8 +1069,8 @@ uis.controller('uiSelectCtrl', }]); uis.directive('uiSelect', - ['$document', 'uiSelectConfig', 'uiSelectMinErr', 'uisOffset', '$compile', '$parse', '$timeout', - function ($document, uiSelectConfig, uiSelectMinErr, uisOffset, $compile, $parse, $timeout) { + ['$document', '$window', 'uiSelectConfig', 'uiSelectMinErr', 'uisOffset', '$compile', '$parse', '$timeout', + function ($document, $window, uiSelectConfig, uiSelectMinErr, uisOffset, $compile, $parse, $timeout) { return { restrict: 'EA', @@ -1162,9 +1317,7 @@ uis.directive('uiSelect', var offsetDropdown = uisOffset(dropdown); // Determine if the direction of the dropdown needs to be changed. - if (offset.top + offset.height + offsetDropdown.height > - $document[0].documentElement.scrollTop + - $document[0].documentElement.clientHeight) { + if (offset.top + offset.height + offsetDropdown.height > $window.pageYOffset + $document[0].documentElement.clientHeight) { element.addClass(directionUpClassName); } @@ -1263,11 +1416,6 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel ctrl.activeMatchIndex = -1; $select.sizeSearchInput(); - // If there's no onBeforeRemove callback, then we're done - if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { - return; - } - var callbackContext = { $item: removedChoice, $model: $select.parserResult.modelMapper($scope, locals) @@ -1282,6 +1430,12 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel ctrl.updateModel(); } + // If there's no onBeforeRemove callback, then just call the completeCallback + if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { + completeCallback(); + return; + } + // Call the onBeforeRemove callback // Allowable responses are -: // falsy: Abort the removal diff --git a/dist/select.min.css b/dist/select.min.css index f90f6891a..eca8ae81e 100644 --- a/dist/select.min.css +++ b/dist/select.min.css @@ -1,6 +1,6 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-05T18:50:43.115Z + * Version: 0.12.1 - 2015-08-06T11:06:02.064Z * License: MIT */.ui-select-highlight{font-weight:700}.ui-select-offscreen{clip:rect(0 0 0 0)!important;width:1px!important;height:1px!important;border:0!important;margin:0!important;padding:0!important;overflow:hidden!important;position:absolute!important;outline:0!important;left:0!important;top:0!important}.ng-dirty.ng-invalid>a.select2-choice{border-color:#D44950}.select2-result-single{padding-left:0}.select-locked>.ui-select-match-close,.select2-locked>.select2-search-choice-close{display:none}body>.select2-container.open{z-index:9999}.ui-select-container[theme=select2].direction-up .ui-select-match{border-radius:0 0 4px 4px}.ui-select-container[theme=select2].direction-up .ui-select-dropdown{bottom:100%;top:auto;position:absolute;border-radius:4px 4px 0 0;border-top-width:1px;border-top-style:solid;box-shadow:0 -4px 8px rgba(0,0,0,.25);margin-top:-4px}.ui-select-container[theme=select2].direction-up .ui-select-dropdown .select2-search{margin-top:4px}.ui-select-container[theme=select2].direction-up.select2-dropdown-open .ui-select-match{border-bottom-color:#5897fb}.selectize-input.selectize-focus{border-color:#007FBB!important}.selectize-control>.selectize-dropdown,.selectize-control>.selectize-input>input{width:100%}.ng-dirty.ng-invalid>div.selectize-input{border-color:#D44950}.ui-select-container[theme=selectize].direction-up .ui-select-dropdown{bottom:100%;top:auto;position:absolute;box-shadow:0 -4px 8px rgba(0,0,0,.25);margin-top:-2px}.btn-default-focus{color:#333;background-color:#EBEBEB;border-color:#ADADAD;text-decoration:none;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.ui-select-bootstrap .ui-select-toggle{position:relative}.ui-select-bootstrap .ui-select-toggle>.caret{position:absolute;height:10px;top:50%;right:10px;margin-top:-2px}.input-group>.ui-select-bootstrap.dropdown{position:static}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control{border-radius:4px 0 0 4px}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control.direction-up{border-radius:4px 0 0 4px!important}.ui-select-bootstrap>.ui-select-match>.btn{text-align:left!important}.ui-select-bootstrap>.ui-select-match>.caret{position:absolute;top:45%;right:15px}.ui-select-bootstrap>.ui-select-choices{width:100%;height:auto;max-height:200px;overflow-x:hidden;margin-top:-1px}body>.ui-select-bootstrap.open{z-index:1000}.ui-select-multiple.ui-select-bootstrap{height:auto;padding:3px 3px 0}.ui-select-multiple.ui-select-bootstrap input.ui-select-search{background-color:transparent!important;border:none;outline:0;height:1.666666em;margin-bottom:3px}.ui-select-multiple.ui-select-bootstrap .ui-select-match .close{font-size:1.6em;line-height:.75}.ui-select-multiple.ui-select-bootstrap .ui-select-match-item{outline:0;margin:0 3px 3px 0}.ui-select-multiple .ui-select-match-item{position:relative}.ui-select-multiple .ui-select-match-item.dropping-before:before{content:"";position:absolute;top:0;right:100%;height:100%;margin-right:2px;border-left:1px solid #428bca}.ui-select-multiple .ui-select-match-item.dropping-after:after{content:"";position:absolute;top:0;left:100%;height:100%;margin-left:2px;border-right:1px solid #428bca}.ui-select-bootstrap .ui-select-placeholder{opacity:1;color:#999}.ui-select-bootstrap .ui-select-choices-row>a{display:block;padding:3px 20px;clear:both;font-weight:400;line-height:1.42857143;color:#333;white-space:nowrap}.ui-select-bootstrap .ui-select-choices-row>a:focus,.ui-select-bootstrap .ui-select-choices-row>a:hover{text-decoration:none;color:#262626;background-color:#f5f5f5}.ui-select-bootstrap .ui-select-choices-row.active>a{color:#fff;text-decoration:none;outline:0;background-color:#428bca}.ui-select-bootstrap .ui-select-choices-row.active.disabled>a,.ui-select-bootstrap .ui-select-choices-row.disabled>a{color:#777;cursor:not-allowed;background-color:#fff}.ui-select-match.ng-hide-add,.ui-select-search.ng-hide-add{display:none!important}.ui-select-bootstrap.ng-dirty.ng-invalid>button.btn.ui-select-match{border-color:#D44950}.ui-select-container[theme=bootstrap].direction-up .ui-select-dropdown{bottom:100%;top:auto;position:absolute;box-shadow:0 -4px 8px rgba(0,0,0,.25)} \ No newline at end of file diff --git a/dist/select.min.js b/dist/select.min.js index 076a4bd06..7190347e5 100644 --- a/dist/select.min.js +++ b/dist/select.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-05T18:50:43.112Z + * Version: 0.12.1 - 2015-08-06T11:06:02.062Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],c=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(c.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,c=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,l,s){s(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(c){var l=c[0].getBoundingClientRect();return{width:l.width||c.prop("offsetWidth"),height:l.height||c.prop("offsetHeight"),top:l.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:l.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);c.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,c,l){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(e,s){if(!s.repeat)throw c("repeat","Expected 'repeat' expression.");return function(e,s,i,n,a){var o=i.groupBy,r=i.groupFilter;if(n.parseRepeatAttr(i.repeat,o,r),n.disableChoiceExpression=i.uiDisableChoice,n.onHighlightCallback=i.onHighlight,o){var u=s.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=s.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(n.parserResult.itemName,"$select.items",n.parserResult.trackByExp,o)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+n.parserResult.itemName+")").attr("ng-click","$select.select("+n.parserResult.itemName+",false,$event)");var p=s.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),l(s,a)(e),e.$watch("$select.search",function(e){e&&!n.open&&n.multiple&&n.activate(!1,!0),n.activeIndex=0})}}}}]),c.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,c,l,s,i,n,a,o){function r(){(h.resetSearchInput||void 0===h.resetSearchInput&&o.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var c,l,s=[];for(c=0;c0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:c=!1}return c}function p(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw a("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var l=t[h.activeIndex],s=l.offsetTop+l.clientHeight-e[0].scrollTop,i=e[0].offsetHeight;s>i?e[0].scrollTop+=s-i:s=h.items.length?0:h.activeIndex,l(function(){h.search=e||h.search,h.searchInput[0].focus()})},i=h.onDropdownCallback(t,{open:!0});angular.isDefined(i)?angular.isFunction(i.then)?i.then(function(e){e&&s()}):i===!0?s():i&&s():s()}},h.parseRepeatAttr=function(e,c,l){function s(e){var s=t.$eval(c);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(s)?s(e):e[s],c=h.findGroupByName(t);c?c.items.push(e):h.groups.push({name:t,items:[e]})}),l){var i=t.$eval(l);angular.isFunction(i)?h.groups=i(h.groups):angular.isArray(i)&&(h.groups=u(h.groups,i))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function i(e){h.items=e}h.setItemsFn=c?s:i,h.parserResult=n.parse(e),h.isGrouped=!!c,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var c=h.selected;if(h.isEmpty()||angular.isArray(c)&&!c.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var l=e.filter(function(e){return c.indexOf(e)<0});h.setItemsFn(l)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw a("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),c=-1===t?!1:t===h.activeIndex;return c&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),c},h.isDisabled=function(e){if(!h.open)return!1;var t,c=h.items.indexOf(e[h.itemProperty]),l=!1;return c>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[c],l=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=l),l},h.select=function(e,c,s){if((void 0===e||!e._uiSelectChoiceDisabled)&&(h.items||h.search)){var i={};i[h.parserResult.itemName]=e;var n={$item:e,$model:h.parserResult.modelMapper(t,i)},a=function(e){n.$item=e,t.$broadcast("uis:select",e),l(function(){h.onSelectCallback(t,n)}),h.closeOnSelect&&h.close(c),s&&"click"===s.type&&(h.clickTriggeredSelect=!0)},o=h.onBeforeSelectCallback(t,n);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(e){e&&a(e)}):o===!0?a(e):o&&a(o):a(e)}},h.close=function(e){function c(){h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),r(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e)}if(h.open){var l=h.onDropdownCallback(t,{open:!1});angular.isDefined(l)?angular.isFunction(l.then)?l.then(function(e){e&&c()}):l===!0?c():l&&c():c()}},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),l(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var c,l=h.selected[t];return l&&!angular.isUndefined(h.lockChoiceExpression)&&(c=!!e.$eval(h.lockChoiceExpression),l._uiSelectChoiceLocked=c),c};var g=null;h.sizeSearchInput=function(){var e=h.searchInput[0],c=h.searchInput.parent().parent()[0],s=function(){return c.clientWidth*!!e.offsetParent},i=function(t){if(0===t)return!1;var c=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>c&&(c=t),h.searchInput.css("width",c+"px"),!0};h.searchInput.css("width","10px"),l(function(){null!==g||i(s())||(g=t.$watch(s,function(e){i(e)&&(g(),g=null)}))})},h.searchInput.on("keydown",function(c){var l=c.which;t.$apply(function(){d(l)}),e.isVerticalMovement(l)&&h.items.length>0&&p(),(l===e.ENTER||l===e.ESC)&&(c.preventDefault(),c.stopPropagation())}),h.searchInput.on("keyup",function(c){c.which===e.TAB||e.isControl(c)||e.isFunctionKey(c)||c.which===e.ESC||e.isVerticalMovement(c.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:c})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),c.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,c,l,s,i,n){return{restrict:"EA",templateUrl:function(e,c){var l=c.theme||t.theme;return l+(angular.isDefined(c.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(s,a){return angular.isDefined(a.multiple)?s.append("").removeAttr("multiple"):s.append(""),function(s,a,o,r,u){function d(e){if(f.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(a[0],e.target):a[0].contains(e.target),!t&&!f.clickTriggeredSelect){var c=["input","button","textarea"],l=angular.element(e.target).scope(),i=l&&l.$select&&l.$select!==f;i||(i=~c.indexOf(e.target.tagName.toLowerCase())),f.close(i),s.$digest()}f.clickTriggeredSelect=!1}}function p(){var t=l(a);b=angular.element('
    '),b[0].style.width=t.width+"px",b[0].style.height=t.height+"px",a.after(b),w=a[0].style.width,e.find("body").append(a),a[0].style.position="absolute",a[0].style.left=t.left+"px",a[0].style.top=t.top+"px",a[0].style.width=t.width+"px"}function h(){null!==b&&(b.replaceWith(a),b=null,a[0].style.position="",a[0].style.left="",a[0].style.top="",a[0].style.width=w)}var f=r[0],g=r[1];f.generatedId=t.generateId(),f.baseTitle=o.title||"Select box",f.focusserTitle=f.baseTitle+" focus",f.focusserId="focusser-"+f.generatedId,f.closeOnSelect=function(){return angular.isDefined(o.closeOnSelect)?i(o.closeOnSelect)():t.closeOnSelect}(),f.onSelectCallback=i(o.onSelect),f.onBeforeSelectCallback=i(o.onBeforeSelect),f.onRemoveCallback=i(o.onRemove),f.onBeforeRemoveCallback=i(o.onBeforeRemove),f.onKeypressCallback=i(o.onKeypress),f.onDropdownCallback=i(o.onDropdown),f.limit=angular.isDefined(o.limit)?parseInt(o.limit,10):void 0,f.ngModel=g,f.choiceGrouped=function(e){return f.isGrouped&&e&&e.name},o.tabindex&&o.$observe("tabindex",function(e){f.focusInput.attr("tabindex",e),a.removeAttr("tabindex")});var v=s.$eval(o.searchEnabled);f.searchEnabled=void 0!==v?v:t.searchEnabled;var m=s.$eval(o.sortable);f.sortable=void 0!==m?m:t.sortable,o.$observe("disabled",function(){f.disabled=void 0!==o.disabled?o.disabled:!1}),angular.isDefined(o.autofocus)&&n(function(){f.setFocus()}),angular.isDefined(o.focusOn)&&s.$on(o.focusOn,function(){n(function(){f.setFocus()})}),e.on("click",d),s.$on("$destroy",function(){e.off("click",d)}),u(s,function(e){var t=angular.element("
    ").append(e),l=t.querySelectorAll(".ui-select-match");if(l.removeAttr("ui-select-match"),l.removeAttr("data-ui-select-match"),1!==l.length)throw c("transcluded","Expected 1 .ui-select-match but got '{0}'.",l.length);a.querySelectorAll(".ui-select-match").replaceWith(l);var s=t.querySelectorAll(".ui-select-choices");if(s.removeAttr("ui-select-choices"),s.removeAttr("data-ui-select-choices"),1!==s.length)throw c("transcluded","Expected 1 .ui-select-choices but got '{0}'.",s.length);a.querySelectorAll(".ui-select-choices").replaceWith(s)});var $=s.$eval(o.appendToBody);(void 0!==$?$:t.appendToBody)&&(s.$watch("$select.open",function(e){e?p():h()}),s.$on("$destroy",function(){h()}));var b=null,w="",E=null,x="direction-up";s.$watch("$select.open",function(t){if(t){if(E=angular.element(a).querySelectorAll(".ui-select-dropdown"),null===E)return;E[0].style.opacity=0,n(function(){var t=l(a),c=l(E);t.top+t.height+c.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&a.addClass(x),E[0].style.opacity=1})}else{if(null===E)return;a.removeClass(x)}})}}}}]),c.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,l=t.parent().attr("multiple");return c+(l?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,l,s){function i(e){s.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}s.lockChoiceExpression=l.uiLockChoice,l.$observe("placeholder",function(t){s.placeholder=void 0!==t?t:e.placeholder}),l.$observe("allowClear",i),i(l.allowClear),s.multiple&&s.sizeSearchInput()}}}]),c.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var c,l=this,s=e.$select;e.$evalAsync(function(){c=e.ngModel}),l.activeMatchIndex=-1,l.updateModel=function(){c.$setViewValue(Date.now()),l.refreshComponent()},l.refreshComponent=function(){s.refreshItems(),s.sizeSearchInput()},l.removeChoice=function(c){function i(){t(function(){s.onRemoveCallback(e,o)}),l.updateModel()}var n=s.selected[c];if(!n._uiSelectChoiceLocked){var a={};if(a[s.parserResult.itemName]=n,s.selected.splice(c,1),l.activeMatchIndex=-1,s.sizeSearchInput(),angular.isDefined(l.onBeforeRemoveCallback)){var o={$item:n,$model:s.parserResult.modelMapper(e,a)},r=l.onBeforeRemoveCallback(e,o);angular.isDefined(r)?angular.isFunction(r.then)?r.then(function(e){e&&i(e)}):r===!0&&i():i()}}},l.getPlaceholder=function(){return s.selected&&s.selected.length?void 0:s.placeholder}}],controllerAs:"$selectMultiple",link:function(l,s,i,n){function a(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function o(t){function c(){switch(t){case e.LEFT:return~d.activeMatchIndex?p:n;case e.RIGHT:return~d.activeMatchIndex&&o!==n?u:(r.activate(),!1);case e.BACKSPACE:return~d.activeMatchIndex?(d.removeChoice(o),p):n;case e.DELETE:return~d.activeMatchIndex?(d.removeChoice(d.activeMatchIndex),o):!1}}var l=a(r.searchInput[0]),s=r.selected.length,i=0,n=s-1,o=d.activeMatchIndex,u=d.activeMatchIndex+1,p=d.activeMatchIndex-1,h=o;return l>0||r.search.length&&t==e.RIGHT?!1:(r.close(),h=c(),d.activeMatchIndex=r.selected.length&&h!==!1?Math.min(n,Math.max(i,h)):-1,!0)}var r=n[0],u=l.ngModel=n[1],d=l.$selectMultiple;r.multiple=!0,r.removeSelected=!0,r.focusInput=r.searchInput,u.$parsers.unshift(function(){for(var e,t={},c=[],s=r.selected.length-1;s>=0;s--)t={},t[r.parserResult.itemName]=r.selected[s],e=r.parserResult.modelMapper(l,t),c.unshift(e);return c}),u.$formatters.unshift(function(e){var t,c=r.parserResult.source(l,{$select:{search:""}}),s={};if(!c)return e;var i=[],n=function(e,c){if(e&&e.length){for(var n=e.length-1;n>=0;n--){if(s[r.parserResult.itemName]=e[n],t=r.parserResult.modelMapper(l,s),r.parserResult.trackByExp){var a=/\.(.+)/.exec(r.parserResult.trackByExp);if(a.length>0&&t[a[1]]==c[a[1]])return i.unshift(e[n]),!0}if(angular.equals(t,c))return i.unshift(e[n]),!0}return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(r.selected,e[a])||n(c,e[a])||i.unshift(e[a]);return i}),l.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,d.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);r.selected=[]}r.selected=u.$viewValue,l.$evalAsync()},l.$on("uis:select",function(e,t){r.selected.length>=r.limit||(r.selected.push(t),d.updateModel())}),l.$on("uis:activate",function(){d.activeMatchIndex=-1}),l.$watch("$select.disabled",function(e,t){t&&!e&&r.sizeSearchInput()}),r.searchInput.on("keydown",function(t){var c=t.which;l.$apply(function(){var t=!1;e.isHorizontalMovement(c)&&(t=o(c)),t&&c!=e.TAB})}),r.searchInput.on("blur",function(){c(function(){d.activeMatchIndex=-1})})}}}]),c.directive("uiSelectSingle",["$timeout","$compile",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(l,s,i,n){var a=n[0],o=n[1];o.$parsers.unshift(function(e){var t,c={};return c[a.parserResult.itemName]=e,t=a.parserResult.modelMapper(l,c)}),o.$formatters.unshift(function(e){var t,c=a.parserResult.source(l,{$select:{search:""}}),s={};if(c){var i=function(c){return s[a.parserResult.itemName]=c,t=a.parserResult.modelMapper(l,s),t==e};if(a.selected&&i(a.selected))return a.selected;for(var n=c.length-1;n>=0;n--)if(i(c[n]))return c[n]}return e}),l.$watch("$select.selected",function(e){o.$viewValue!==e&&o.$setViewValue(e)}),o.$render=function(){a.selected=o.$viewValue},l.$on("uis:select",function(e,t){a.selected=t}),l.$on("uis:close",function(e,c){t(function(){a.focusser.prop("disabled",!1),c||a.focusser[0].focus()},0,!1)}),l.$on("uis:activate",function(){r.prop("disabled",!0)});var r=angular.element("");c(r)(l),a.focusser=r,a.focusInput=r,s.parent().append(r),r.bind("focus",function(){l.$evalAsync(function(){a.focus=!0})}),r.bind("blur",function(){l.$evalAsync(function(){a.focus=!1})}),r.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),a.select(void 0),l.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),a.activate()),l.$digest()),void 0)}),r.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(a.activate(r.val()),r.val(""),l.$digest())})}}}]),c.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var l=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!l)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:l[2],source:t(l[3]),trackByExp:l[4],modelMapper:t(l[1]||l[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,l){var s=e+" in "+(l?"$group.items":t);return c&&(s+=" track by "+c),s}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("selectize/choices.tpl.html",'
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",'
    {{$select.placeholder}}
    '),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",'')}]),angular.module("ui.select").run(["$templateCache",function(e){e.put("select2/choices.tpl.html",'
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    ')}]); \ No newline at end of file +!function(){"use strict";angular.module("ui.select.sort",["ui.select"]).directive("uiSelectSort",["$timeout","uiSelectConfig","uiSelectMinErr",function(e,t,c){return{require:"^uiSelect",link:function(t,l,s,i){if(null===t[s.uiSelectSort])throw c("sort","Expected a list to sort");var n=angular.extend({axis:"horizontal"},t.$eval(s.uiSelectSortOptions)),a=n.axis,r="dragging",o="dropping",u="dropping-before",d="dropping-after";t.$watch(function(){return i.sortable},function(e){e?l.attr("draggable",!0):l.removeAttr("draggable")}),l.on("dragstart",function(e){l.addClass(r),(e.dataTransfer||e.originalEvent.dataTransfer).setData("text/plain",t.$index)}),l.on("dragend",function(){l.removeClass(r)});var p,h=function(e,t){this.splice(t,0,this.splice(e,1)[0])},f=function(e){e.preventDefault();var t="vertical"===a?e.offsetY||e.layerY||(e.originalEvent?e.originalEvent.offsetY:0):e.offsetX||e.layerX||(e.originalEvent?e.originalEvent.offsetX:0);t=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],c=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(c.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,c=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,l,s){s(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(c){var l=c[0].getBoundingClientRect();return{width:l.width||c.prop("offsetWidth"),height:l.height||c.prop("offsetHeight"),top:l.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:l.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);c.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,c,l){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(e,s){if(!s.repeat)throw c("repeat","Expected 'repeat' expression.");return function(e,s,i,n,a){var r=i.groupBy,o=i.groupFilter;if(n.parseRepeatAttr(i.repeat,r,o),n.disableChoiceExpression=i.uiDisableChoice,n.onHighlightCallback=i.onHighlight,r){var u=s.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=s.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(n.parserResult.itemName,"$select.items",n.parserResult.trackByExp,r)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+n.parserResult.itemName+")").attr("ng-click","$select.select("+n.parserResult.itemName+",false,$event)");var p=s.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),l(s,a)(e),e.$watch("$select.search",function(e){e&&!n.open&&n.multiple&&n.activate(!1,!0),n.activeIndex=0})}}}}]),c.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,c,l,s,i,n,a,r){function o(){(h.resetSearchInput||void 0===h.resetSearchInput&&r.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var c,l,s=[];for(c=0;c0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:c=!1}return c}function p(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw a("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var l=t[h.activeIndex],s=l.offsetTop+l.clientHeight-e[0].scrollTop,i=e[0].offsetHeight;s>i?e[0].scrollTop+=s-i:s=h.items.length?0:h.activeIndex,l(function(){h.search=e||h.search,h.searchInput[0].focus()})},i=h.onDropdownCallback(t,{open:!0});angular.isDefined(i)?angular.isFunction(i.then)?i.then(function(e){e&&s()}):i===!0?s():i&&s():s()}},h.parseRepeatAttr=function(e,c,l){function s(e){var s=t.$eval(c);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(s)?s(e):e[s],c=h.findGroupByName(t);c?c.items.push(e):h.groups.push({name:t,items:[e]})}),l){var i=t.$eval(l);angular.isFunction(i)?h.groups=i(h.groups):angular.isArray(i)&&(h.groups=u(h.groups,i))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function i(e){h.items=e}h.setItemsFn=c?s:i,h.parserResult=n.parse(e),h.isGrouped=!!c,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var c=h.selected;if(h.isEmpty()||angular.isArray(c)&&!c.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var l=e.filter(function(e){return c.indexOf(e)<0});h.setItemsFn(l)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw a("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),c=-1===t?!1:t===h.activeIndex;return c&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),c},h.isDisabled=function(e){if(!h.open)return!1;var t,c=h.items.indexOf(e[h.itemProperty]),l=!1;return c>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[c],l=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=l),l},h.select=function(e,c,s){if((void 0===e||!e._uiSelectChoiceDisabled)&&(h.items||h.search)){var i={};i[h.parserResult.itemName]=e;var n={$item:e,$model:h.parserResult.modelMapper(t,i)},a=function(e){n.$item=e,t.$broadcast("uis:select",e),l(function(){h.onSelectCallback(t,n)}),h.closeOnSelect&&h.close(c),s&&"click"===s.type&&(h.clickTriggeredSelect=!0)};if(!angular.isDefined(h.onBeforeRemoveCallback))return a(e),void 0;var r=h.onBeforeSelectCallback(t,n);angular.isDefined(r)?angular.isFunction(r.then)?r.then(function(t){t&&(t===!0?a(e):t&&a(t))}):r===!0?a(e):r&&a(r):a(e)}},h.close=function(e){function c(){h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),o(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e)}if(h.open){var l=h.onDropdownCallback(t,{open:!1});angular.isDefined(l)?angular.isFunction(l.then)?l.then(function(e){e&&c()}):l===!0?c():l&&c():c()}},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),l(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var c,l=h.selected[t];return l&&!angular.isUndefined(h.lockChoiceExpression)&&(c=!!e.$eval(h.lockChoiceExpression),l._uiSelectChoiceLocked=c),c};var g=null;h.sizeSearchInput=function(){var e=h.searchInput[0],c=h.searchInput.parent().parent()[0],s=function(){return c.clientWidth*!!e.offsetParent},i=function(t){if(0===t)return!1;var c=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>c&&(c=t),h.searchInput.css("width",c+"px"),!0};h.searchInput.css("width","10px"),l(function(){null!==g||i(s())||(g=t.$watch(s,function(e){i(e)&&(g(),g=null)}))})},h.searchInput.on("keydown",function(c){var l=c.which;t.$apply(function(){d(l)}),e.isVerticalMovement(l)&&h.items.length>0&&p(),(l===e.ENTER||l===e.ESC)&&(c.preventDefault(),c.stopPropagation())}),h.searchInput.on("keyup",function(c){c.which===e.TAB||e.isControl(c)||e.isFunctionKey(c)||c.which===e.ESC||e.isVerticalMovement(c.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:c})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),c.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,c,l,s,i,n,a){return{restrict:"EA",templateUrl:function(e,t){var l=t.theme||c.theme;return l+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(i,r){return angular.isDefined(r.multiple)?i.append("").removeAttr("multiple"):i.append(""),function(i,r,o,u,d){function p(e){if(g.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(r[0],e.target):r[0].contains(e.target),!t&&!g.clickTriggeredSelect){var c=["input","button","textarea"],l=angular.element(e.target).scope(),s=l&&l.$select&&l.$select!==g;s||(s=~c.indexOf(e.target.tagName.toLowerCase())),g.close(s),i.$digest()}g.clickTriggeredSelect=!1}}function h(){var t=s(r);w=angular.element('
    '),w[0].style.width=t.width+"px",w[0].style.height=t.height+"px",r.after(w),x=r[0].style.width,e.find("body").append(r),r[0].style.position="absolute",r[0].style.left=t.left+"px",r[0].style.top=t.top+"px",r[0].style.width=t.width+"px"}function f(){null!==w&&(w.replaceWith(r),w=null,r[0].style.position="",r[0].style.left="",r[0].style.top="",r[0].style.width=x)}var g=u[0],v=u[1];g.generatedId=c.generateId(),g.baseTitle=o.title||"Select box",g.focusserTitle=g.baseTitle+" focus",g.focusserId="focusser-"+g.generatedId,g.closeOnSelect=function(){return angular.isDefined(o.closeOnSelect)?n(o.closeOnSelect)():c.closeOnSelect}(),g.onSelectCallback=n(o.onSelect),g.onBeforeSelectCallback=n(o.onBeforeSelect),g.onRemoveCallback=n(o.onRemove),g.onBeforeRemoveCallback=n(o.onBeforeRemove),g.onKeypressCallback=n(o.onKeypress),g.onDropdownCallback=n(o.onDropdown),g.limit=angular.isDefined(o.limit)?parseInt(o.limit,10):void 0,g.ngModel=v,g.choiceGrouped=function(e){return g.isGrouped&&e&&e.name},o.tabindex&&o.$observe("tabindex",function(e){g.focusInput.attr("tabindex",e),r.removeAttr("tabindex")});var m=i.$eval(o.searchEnabled);g.searchEnabled=void 0!==m?m:c.searchEnabled;var $=i.$eval(o.sortable);g.sortable=void 0!==$?$:c.sortable,o.$observe("disabled",function(){g.disabled=void 0!==o.disabled?o.disabled:!1}),angular.isDefined(o.autofocus)&&a(function(){g.setFocus()}),angular.isDefined(o.focusOn)&&i.$on(o.focusOn,function(){a(function(){g.setFocus()})}),e.on("click",p),i.$on("$destroy",function(){e.off("click",p)}),d(i,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),c.removeAttr("data-ui-select-match"),1!==c.length)throw l("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);r.querySelectorAll(".ui-select-match").replaceWith(c);var s=t.querySelectorAll(".ui-select-choices");if(s.removeAttr("ui-select-choices"),s.removeAttr("data-ui-select-choices"),1!==s.length)throw l("transcluded","Expected 1 .ui-select-choices but got '{0}'.",s.length);r.querySelectorAll(".ui-select-choices").replaceWith(s)});var b=i.$eval(o.appendToBody);(void 0!==b?b:c.appendToBody)&&(i.$watch("$select.open",function(e){e?h():f()}),i.$on("$destroy",function(){f()}));var w=null,x="",E=null,C="direction-up";i.$watch("$select.open",function(c){if(c){if(E=angular.element(r).querySelectorAll(".ui-select-dropdown"),null===E)return;E[0].style.opacity=0,a(function(){var c=s(r),l=s(E);c.top+c.height+l.height>t.pageYOffset+e[0].documentElement.clientHeight&&r.addClass(C),E[0].style.opacity=1})}else{if(null===E)return;r.removeClass(C)}})}}}}]),c.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,l=t.parent().attr("multiple");return c+(l?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,l,s){function i(e){s.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}s.lockChoiceExpression=l.uiLockChoice,l.$observe("placeholder",function(t){s.placeholder=void 0!==t?t:e.placeholder}),l.$observe("allowClear",i),i(l.allowClear),s.multiple&&s.sizeSearchInput()}}}]),c.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var c,l=this,s=e.$select;e.$evalAsync(function(){c=e.ngModel}),l.activeMatchIndex=-1,l.updateModel=function(){c.$setViewValue(Date.now()),l.refreshComponent()},l.refreshComponent=function(){s.refreshItems(),s.sizeSearchInput()},l.removeChoice=function(c){function i(){t(function(){s.onRemoveCallback(e,r)}),l.updateModel()}var n=s.selected[c];if(!n._uiSelectChoiceLocked){var a={};a[s.parserResult.itemName]=n,s.selected.splice(c,1),l.activeMatchIndex=-1,s.sizeSearchInput();var r={$item:n,$model:s.parserResult.modelMapper(e,a)};if(!angular.isDefined(l.onBeforeRemoveCallback))return i(),void 0;var o=l.onBeforeRemoveCallback(e,r);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(e){e&&i(e)}):o===!0&&i():i()}},l.getPlaceholder=function(){return s.selected&&s.selected.length?void 0:s.placeholder}}],controllerAs:"$selectMultiple",link:function(l,s,i,n){function a(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function r(t){function c(){switch(t){case e.LEFT:return~d.activeMatchIndex?p:n;case e.RIGHT:return~d.activeMatchIndex&&r!==n?u:(o.activate(),!1);case e.BACKSPACE:return~d.activeMatchIndex?(d.removeChoice(r),p):n;case e.DELETE:return~d.activeMatchIndex?(d.removeChoice(d.activeMatchIndex),r):!1}}var l=a(o.searchInput[0]),s=o.selected.length,i=0,n=s-1,r=d.activeMatchIndex,u=d.activeMatchIndex+1,p=d.activeMatchIndex-1,h=r;return l>0||o.search.length&&t==e.RIGHT?!1:(o.close(),h=c(),d.activeMatchIndex=o.selected.length&&h!==!1?Math.min(n,Math.max(i,h)):-1,!0)}var o=n[0],u=l.ngModel=n[1],d=l.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,u.$parsers.unshift(function(){for(var e,t={},c=[],s=o.selected.length-1;s>=0;s--)t={},t[o.parserResult.itemName]=o.selected[s],e=o.parserResult.modelMapper(l,t),c.unshift(e);return c}),u.$formatters.unshift(function(e){var t,c=o.parserResult.source(l,{$select:{search:""}}),s={};if(!c)return e;var i=[],n=function(e,c){if(e&&e.length){for(var n=e.length-1;n>=0;n--){if(s[o.parserResult.itemName]=e[n],t=o.parserResult.modelMapper(l,s),o.parserResult.trackByExp){var a=/\.(.+)/.exec(o.parserResult.trackByExp);if(a.length>0&&t[a[1]]==c[a[1]])return i.unshift(e[n]),!0}if(angular.equals(t,c))return i.unshift(e[n]),!0}return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(o.selected,e[a])||n(c,e[a])||i.unshift(e[a]);return i}),l.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,d.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);o.selected=[]}o.selected=u.$viewValue,l.$evalAsync()},l.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),d.updateModel())}),l.$on("uis:activate",function(){d.activeMatchIndex=-1}),l.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(t){var c=t.which;l.$apply(function(){var t=!1;e.isHorizontalMovement(c)&&(t=r(c)),t&&c!=e.TAB})}),o.searchInput.on("blur",function(){c(function(){d.activeMatchIndex=-1})})}}}]),c.directive("uiSelectSingle",["$timeout","$compile",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(l,s,i,n){var a=n[0],r=n[1];r.$parsers.unshift(function(e){var t,c={};return c[a.parserResult.itemName]=e,t=a.parserResult.modelMapper(l,c)}),r.$formatters.unshift(function(e){var t,c=a.parserResult.source(l,{$select:{search:""}}),s={};if(c){var i=function(c){return s[a.parserResult.itemName]=c,t=a.parserResult.modelMapper(l,s),t==e};if(a.selected&&i(a.selected))return a.selected;for(var n=c.length-1;n>=0;n--)if(i(c[n]))return c[n]}return e}),l.$watch("$select.selected",function(e){r.$viewValue!==e&&r.$setViewValue(e)}),r.$render=function(){a.selected=r.$viewValue},l.$on("uis:select",function(e,t){a.selected=t}),l.$on("uis:close",function(e,c){t(function(){a.focusser.prop("disabled",!1),c||a.focusser[0].focus()},0,!1)}),l.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");c(o)(l),a.focusser=o,a.focusInput=o,s.parent().append(o),o.bind("focus",function(){l.$evalAsync(function(){a.focus=!0})}),o.bind("blur",function(){l.$evalAsync(function(){a.focus=!1})}),o.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),a.select(void 0),l.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),a.activate()),l.$digest()),void 0)}),o.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(a.activate(o.val()),o.val(""),l.$digest())})}}}]),c.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var l=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!l)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:l[2],source:t(l[3]),trackByExp:l[4],modelMapper:t(l[1]||l[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,l){var s=e+" in "+(l?"$group.items":t);return c&&(s+=" track by "+c),s}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("selectize/choices.tpl.html",'
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",'
    {{$select.placeholder}}
    '),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",'')}]),angular.module("ui.select").run(["$templateCache",function(e){e.put("select2/choices.tpl.html",'
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/dist/select.no-tpl.js b/dist/select.no-tpl.js index d963045e5..53e8ee278 100644 --- a/dist/select.no-tpl.js +++ b/dist/select.no-tpl.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-05T18:50:43.047Z + * Version: 0.12.1 - 2015-08-06T11:06:02.017Z * License: MIT */ @@ -588,7 +588,6 @@ uis.controller('uiSelectCtrl', * @return {boolean} true if the item is disabled */ ctrl.isDisabled = function (itemScope) { - if (!ctrl.open) { return false; } @@ -608,7 +607,8 @@ uis.controller('uiSelectCtrl', /** - * Selects an item + * Selects an item. Calls the onBeforeSelect and onSelect callbacks + * onBeforeSelect can alter or abort the selection * * Called when the user selects an item with ENTER or clicks the dropdown */ @@ -648,6 +648,12 @@ uis.controller('uiSelectCtrl', } }; + // If there's no onBeforeSelect callback, then just call the completeCallback + if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { + completeCallback(item); + return; + } + // Call the onBeforeSelect callback // Allowable responses are -: // falsy: Abort the selection @@ -658,11 +664,15 @@ uis.controller('uiSelectCtrl', if (angular.isDefined(result)) { if (angular.isFunction(result.then)) { // Promise returned - wait for it to complete before completing the selection - result.then(function (result) { - if (!result) { + result.then(function (response) { + if (!response) { return; } - completeCallback(result); + if (response === true) { + completeCallback(item); + } else if (response) { + completeCallback(response); + } }); } else if (result === true) { completeCallback(item); @@ -914,8 +924,8 @@ uis.controller('uiSelectCtrl', }]); uis.directive('uiSelect', - ['$document', 'uiSelectConfig', 'uiSelectMinErr', 'uisOffset', '$compile', '$parse', '$timeout', - function ($document, uiSelectConfig, uiSelectMinErr, uisOffset, $compile, $parse, $timeout) { + ['$document', '$window', 'uiSelectConfig', 'uiSelectMinErr', 'uisOffset', '$compile', '$parse', '$timeout', + function ($document, $window, uiSelectConfig, uiSelectMinErr, uisOffset, $compile, $parse, $timeout) { return { restrict: 'EA', @@ -1162,9 +1172,7 @@ uis.directive('uiSelect', var offsetDropdown = uisOffset(dropdown); // Determine if the direction of the dropdown needs to be changed. - if (offset.top + offset.height + offsetDropdown.height > - $document[0].documentElement.scrollTop + - $document[0].documentElement.clientHeight) { + if (offset.top + offset.height + offsetDropdown.height > $window.pageYOffset + $document[0].documentElement.clientHeight) { element.addClass(directionUpClassName); } @@ -1263,11 +1271,6 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel ctrl.activeMatchIndex = -1; $select.sizeSearchInput(); - // If there's no onBeforeRemove callback, then we're done - if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { - return; - } - var callbackContext = { $item: removedChoice, $model: $select.parserResult.modelMapper($scope, locals) @@ -1282,6 +1285,12 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel ctrl.updateModel(); } + // If there's no onBeforeRemove callback, then just call the completeCallback + if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { + completeCallback(); + return; + } + // Call the onBeforeRemove callback // Allowable responses are -: // falsy: Abort the removal diff --git a/dist/select.no-tpl.min.js b/dist/select.no-tpl.min.js index 4367507b5..1792cfb13 100644 --- a/dist/select.no-tpl.min.js +++ b/dist/select.no-tpl.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-05T18:50:43.047Z + * Version: 0.12.1 - 2015-08-06T11:06:02.017Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var n=t.which;switch(n){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,n=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,r,i){i(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var r=n[0].getBoundingClientRect();return{width:r.width||n.prop("offsetWidth"),height:r.height||n.prop("offsetHeight"),top:r.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:r.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);n.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,r){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,i){if(!i.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,i,c,l,o){var a=c.groupBy,s=c.groupFilter;if(l.parseRepeatAttr(c.repeat,a,s),l.disableChoiceExpression=c.uiDisableChoice,l.onHighlightCallback=c.onHighlight,a){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=i.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(l.parserResult.itemName,"$select.items",l.parserResult.trackByExp,a)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+l.parserResult.itemName+")").attr("ng-click","$select.select("+l.parserResult.itemName+",false,$event)");var f=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==f.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",f.length);f.attr("uis-transclude-append",""),r(i,o)(e),e.$watch("$select.search",function(e){e&&!l.open&&l.multiple&&l.activate(!1,!0),l.activeIndex=0})}}}}]),n.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,n,r,i,c,l,o,a){function s(){(d.resetSearchInput||void 0===d.resetSearchInput&&a.resetSearchInput)&&(d.search=h,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function u(e,t){var n,r,i=[];for(n=0;n0&&d.activeIndex--;break;case e.TAB:(!d.multiple||d.open)&&d.select(d.items[d.activeIndex],!0);break;case e.ENTER:d.open?d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case e.ESC:d.close();break;default:n=!1}return n}function f(){var e=n.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw o("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(d.activeIndex<0)){var r=t[d.activeIndex],i=r.offsetTop+r.clientHeight-e[0].scrollTop,c=e[0].offsetHeight;i>c?e[0].scrollTop+=i-c:i=d.items.length?0:d.activeIndex,r(function(){d.search=e||d.search,d.searchInput[0].focus()})},c=d.onDropdownCallback(t,{open:!0});angular.isDefined(c)?angular.isFunction(c.then)?c.then(function(e){e&&i()}):c===!0?i():c&&i():i()}},d.parseRepeatAttr=function(e,n,r){function i(e){var i=t.$eval(n);if(d.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(i)?i(e):e[i],n=d.findGroupByName(t);n?n.items.push(e):d.groups.push({name:t,items:[e]})}),r){var c=t.$eval(r);angular.isFunction(c)?d.groups=c(d.groups):angular.isArray(c)&&(d.groups=u(d.groups,c))}d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function c(e){d.items=e}d.setItemsFn=n?i:c,d.parserResult=l.parse(e),d.isGrouped=!!n,d.itemProperty=d.parserResult.itemName,d.refreshItems=function(e){e=e||d.parserResult.source(t);var n=d.selected;if(d.isEmpty()||angular.isArray(n)&&!n.length||!d.removeSelected)d.setItemsFn(e);else if(void 0!==e){var r=e.filter(function(e){return n.indexOf(e)<0});d.setItemsFn(r)}},t.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw o("items","Expected an array but got '{0}'.",e);d.refreshItems(e),d.ngModel.$modelValue=null}})},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){if(!d.open)return!1;var t=d.items.indexOf(e[d.itemProperty]),n=-1===t?!1:t===d.activeIndex;return n&&!angular.isUndefined(d.onHighlightCallback)&&e.$eval(d.onHighlightCallback),n},d.isDisabled=function(e){if(!d.open)return!1;var t,n=d.items.indexOf(e[d.itemProperty]),r=!1;return n>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[n],r=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=r),r},d.select=function(e,n,i){if((void 0===e||!e._uiSelectChoiceDisabled)&&(d.items||d.search)){var c={};c[d.parserResult.itemName]=e;var l={$item:e,$model:d.parserResult.modelMapper(t,c)},o=function(e){l.$item=e,t.$broadcast("uis:select",e),r(function(){d.onSelectCallback(t,l)}),d.closeOnSelect&&d.close(n),i&&"click"===i.type&&(d.clickTriggeredSelect=!0)},a=d.onBeforeSelectCallback(t,l);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(e){e&&o(e)}):a===!0?o(e):a&&o(a):o(e)}},d.close=function(e){function n(){d.ngModel&&d.ngModel.$setTouched&&d.ngModel.$setTouched(),s(),d.open=!1,d.searchEnabled||angular.element(d.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e)}if(d.open){var r=d.onDropdownCallback(t,{open:!1});angular.isDefined(r)?angular.isFunction(r.then)?r.then(function(e){e&&n()}):r===!0?n():r&&n():n()}},d.setFocus=function(){d.focus||d.focusInput[0].focus()},d.clear=function(e){d.select(void 0),e.stopPropagation(),r(function(){d.focusser[0].focus()},0,!1)},d.toggle=function(e){d.open?(d.close(),e.preventDefault(),e.stopPropagation()):d.activate()},d.isLocked=function(e,t){var n,r=d.selected[t];return r&&!angular.isUndefined(d.lockChoiceExpression)&&(n=!!e.$eval(d.lockChoiceExpression),r._uiSelectChoiceLocked=n),n};var v=null;d.sizeSearchInput=function(){var e=d.searchInput[0],n=d.searchInput.parent().parent()[0],i=function(){return n.clientWidth*!!e.offsetParent},c=function(t){if(0===t)return!1;var n=t-e.offsetLeft-d.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=t),d.searchInput.css("width",n+"px"),!0};d.searchInput.css("width","10px"),r(function(){null!==v||c(i())||(v=t.$watch(i,function(e){c(e)&&(v(),v=null)}))})},d.searchInput.on("keydown",function(n){var r=n.which;t.$apply(function(){p(r)}),e.isVerticalMovement(r)&&d.items.length>0&&f(),(r===e.ENTER||r===e.ESC)&&(n.preventDefault(),n.stopPropagation())}),d.searchInput.on("keyup",function(n){n.which===e.TAB||e.isControl(n)||e.isFunctionKey(n)||n.which===e.ESC||e.isVerticalMovement(n.which)||void 0!==d.onKeypressCallback&&d.onKeypressCallback(t,{event:n})}),t.$on("$destroy",function(){d.searchInput.off("keyup keydown blur paste")})}]),n.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,r,i,c,l){return{restrict:"EA",templateUrl:function(e,n){var r=n.theme||t.theme;return r+(angular.isDefined(n.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(i,o){return angular.isDefined(o.multiple)?i.append("").removeAttr("multiple"):i.append(""),function(i,o,a,s,u){function p(e){if(h.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(o[0],e.target):o[0].contains(e.target),!t&&!h.clickTriggeredSelect){var n=["input","button","textarea"],r=angular.element(e.target).scope(),c=r&&r.$select&&r.$select!==h;c||(c=~n.indexOf(e.target.tagName.toLowerCase())),h.close(c),i.$digest()}h.clickTriggeredSelect=!1}}function f(){var t=r(o);E=angular.element('
    '),E[0].style.width=t.width+"px",E[0].style.height=t.height+"px",o.after(E),S=o[0].style.width,e.find("body").append(o),o[0].style.position="absolute",o[0].style.left=t.left+"px",o[0].style.top=t.top+"px",o[0].style.width=t.width+"px"}function d(){null!==E&&(E.replaceWith(o),E=null,o[0].style.position="",o[0].style.left="",o[0].style.top="",o[0].style.width=S)}var h=s[0],v=s[1];h.generatedId=t.generateId(),h.baseTitle=a.title||"Select box",h.focusserTitle=h.baseTitle+" focus",h.focusserId="focusser-"+h.generatedId,h.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?c(a.closeOnSelect)():t.closeOnSelect}(),h.onSelectCallback=c(a.onSelect),h.onBeforeSelectCallback=c(a.onBeforeSelect),h.onRemoveCallback=c(a.onRemove),h.onBeforeRemoveCallback=c(a.onBeforeRemove),h.onKeypressCallback=c(a.onKeypress),h.onDropdownCallback=c(a.onDropdown),h.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,h.ngModel=v,h.choiceGrouped=function(e){return h.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){h.focusInput.attr("tabindex",e),o.removeAttr("tabindex")});var m=i.$eval(a.searchEnabled);h.searchEnabled=void 0!==m?m:t.searchEnabled;var g=i.$eval(a.sortable);h.sortable=void 0!==g?g:t.sortable,a.$observe("disabled",function(){h.disabled=void 0!==a.disabled?a.disabled:!1}),angular.isDefined(a.autofocus)&&l(function(){h.setFocus()}),angular.isDefined(a.focusOn)&&i.$on(a.focusOn,function(){l(function(){h.setFocus()})}),e.on("click",p),i.$on("$destroy",function(){e.off("click",p)}),u(i,function(e){var t=angular.element("
    ").append(e),r=t.querySelectorAll(".ui-select-match");if(r.removeAttr("ui-select-match"),r.removeAttr("data-ui-select-match"),1!==r.length)throw n("transcluded","Expected 1 .ui-select-match but got '{0}'.",r.length);o.querySelectorAll(".ui-select-match").replaceWith(r);var i=t.querySelectorAll(".ui-select-choices");if(i.removeAttr("ui-select-choices"),i.removeAttr("data-ui-select-choices"),1!==i.length)throw n("transcluded","Expected 1 .ui-select-choices but got '{0}'.",i.length);o.querySelectorAll(".ui-select-choices").replaceWith(i)});var $=i.$eval(a.appendToBody);(void 0!==$?$:t.appendToBody)&&(i.$watch("$select.open",function(e){e?f():d()}),i.$on("$destroy",function(){d()}));var E=null,S="",b=null,C="direction-up";i.$watch("$select.open",function(t){if(t){if(b=angular.element(o).querySelectorAll(".ui-select-dropdown"),null===b)return;b[0].style.opacity=0,l(function(){var t=r(o),n=r(b);t.top+t.height+n.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&o.addClass(C),b[0].style.opacity=1})}else{if(null===b)return;o.removeClass(C)}})}}}}]),n.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,r=t.parent().attr("multiple");return n+(r?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,r,i){function c(e){i.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}i.lockChoiceExpression=r.uiLockChoice,r.$observe("placeholder",function(t){i.placeholder=void 0!==t?t:e.placeholder}),r.$observe("allowClear",c),c(r.allowClear),i.multiple&&i.sizeSearchInput()}}}]),n.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,r=this,i=e.$select;e.$evalAsync(function(){n=e.ngModel}),r.activeMatchIndex=-1,r.updateModel=function(){n.$setViewValue(Date.now()),r.refreshComponent()},r.refreshComponent=function(){i.refreshItems(),i.sizeSearchInput()},r.removeChoice=function(n){function c(){t(function(){i.onRemoveCallback(e,a)}),r.updateModel()}var l=i.selected[n];if(!l._uiSelectChoiceLocked){var o={};if(o[i.parserResult.itemName]=l,i.selected.splice(n,1),r.activeMatchIndex=-1,i.sizeSearchInput(),angular.isDefined(r.onBeforeRemoveCallback)){var a={$item:l,$model:i.parserResult.modelMapper(e,o)},s=r.onBeforeRemoveCallback(e,a);angular.isDefined(s)?angular.isFunction(s.then)?s.then(function(e){e&&c(e)}):s===!0&&c():c()}}},r.getPlaceholder=function(){return i.selected&&i.selected.length?void 0:i.placeholder}}],controllerAs:"$selectMultiple",link:function(r,i,c,l){function o(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(t){function n(){switch(t){case e.LEFT:return~p.activeMatchIndex?f:l;case e.RIGHT:return~p.activeMatchIndex&&a!==l?u:(s.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(a),f):l;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),a):!1}}var r=o(s.searchInput[0]),i=s.selected.length,c=0,l=i-1,a=p.activeMatchIndex,u=p.activeMatchIndex+1,f=p.activeMatchIndex-1,d=a;return r>0||s.search.length&&t==e.RIGHT?!1:(s.close(),d=n(),p.activeMatchIndex=s.selected.length&&d!==!1?Math.min(l,Math.max(c,d)):-1,!0)}var s=l[0],u=r.ngModel=l[1],p=r.$selectMultiple;s.multiple=!0,s.removeSelected=!0,s.focusInput=s.searchInput,u.$parsers.unshift(function(){for(var e,t={},n=[],i=s.selected.length-1;i>=0;i--)t={},t[s.parserResult.itemName]=s.selected[i],e=s.parserResult.modelMapper(r,t),n.unshift(e);return n}),u.$formatters.unshift(function(e){var t,n=s.parserResult.source(r,{$select:{search:""}}),i={};if(!n)return e;var c=[],l=function(e,n){if(e&&e.length){for(var l=e.length-1;l>=0;l--){if(i[s.parserResult.itemName]=e[l],t=s.parserResult.modelMapper(r,i),s.parserResult.trackByExp){var o=/\.(.+)/.exec(s.parserResult.trackByExp);if(o.length>0&&t[o[1]]==n[o[1]])return c.unshift(e[l]),!0}if(angular.equals(t,n))return c.unshift(e[l]),!0}return!1}};if(!e)return c;for(var o=e.length-1;o>=0;o--)l(s.selected,e[o])||l(n,e[o])||c.unshift(e[o]);return c}),r.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);s.selected=[]}s.selected=u.$viewValue,r.$evalAsync()},r.$on("uis:select",function(e,t){s.selected.length>=s.limit||(s.selected.push(t),p.updateModel())}),r.$on("uis:activate",function(){p.activeMatchIndex=-1}),r.$watch("$select.disabled",function(e,t){t&&!e&&s.sizeSearchInput()}),s.searchInput.on("keydown",function(t){var n=t.which;r.$apply(function(){var t=!1;e.isHorizontalMovement(n)&&(t=a(n)),t&&n!=e.TAB})}),s.searchInput.on("blur",function(){n(function(){p.activeMatchIndex=-1})})}}}]),n.directive("uiSelectSingle",["$timeout","$compile",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(r,i,c,l){var o=l[0],a=l[1];a.$parsers.unshift(function(e){var t,n={};return n[o.parserResult.itemName]=e,t=o.parserResult.modelMapper(r,n)}),a.$formatters.unshift(function(e){var t,n=o.parserResult.source(r,{$select:{search:""}}),i={};if(n){var c=function(n){return i[o.parserResult.itemName]=n,t=o.parserResult.modelMapper(r,i),t==e};if(o.selected&&c(o.selected))return o.selected;for(var l=n.length-1;l>=0;l--)if(c(n[l]))return n[l]}return e}),r.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){o.selected=a.$viewValue},r.$on("uis:select",function(e,t){o.selected=t}),r.$on("uis:close",function(e,n){t(function(){o.focusser.prop("disabled",!1),n||o.focusser[0].focus()},0,!1)}),r.$on("uis:activate",function(){s.prop("disabled",!0)});var s=angular.element("");n(s)(r),o.focusser=s,o.focusInput=s,i.parent().append(s),s.bind("focus",function(){r.$evalAsync(function(){o.focus=!0})}),s.bind("blur",function(){r.$evalAsync(function(){o.focus=!1})}),s.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),o.select(void 0),r.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),o.activate()),r.$digest()),void 0)}),s.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(o.activate(s.val()),s.val(""),r.$digest())})}}}]),n.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var r=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!r)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:r[2],source:t(r[3]),trackByExp:r[4],modelMapper:t(r[1]||r[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,r){var i=e+" in "+(r?"$group.items":t);return n&&(i+=" track by "+n),i}}])}(); \ No newline at end of file +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var n=t.which;switch(n){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,n=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,r,i){i(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var r=n[0].getBoundingClientRect();return{width:r.width||n.prop("offsetWidth"),height:r.height||n.prop("offsetHeight"),top:r.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:r.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);n.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,r){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,i){if(!i.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,i,c,l,o){var a=c.groupBy,s=c.groupFilter;if(l.parseRepeatAttr(c.repeat,a,s),l.disableChoiceExpression=c.uiDisableChoice,l.onHighlightCallback=c.onHighlight,a){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=i.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(l.parserResult.itemName,"$select.items",l.parserResult.trackByExp,a)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+l.parserResult.itemName+")").attr("ng-click","$select.select("+l.parserResult.itemName+",false,$event)");var f=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==f.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",f.length);f.attr("uis-transclude-append",""),r(i,o)(e),e.$watch("$select.search",function(e){e&&!l.open&&l.multiple&&l.activate(!1,!0),l.activeIndex=0})}}}}]),n.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,n,r,i,c,l,o,a){function s(){(d.resetSearchInput||void 0===d.resetSearchInput&&a.resetSearchInput)&&(d.search=h,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function u(e,t){var n,r,i=[];for(n=0;n0&&d.activeIndex--;break;case e.TAB:(!d.multiple||d.open)&&d.select(d.items[d.activeIndex],!0);break;case e.ENTER:d.open?d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case e.ESC:d.close();break;default:n=!1}return n}function f(){var e=n.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw o("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(d.activeIndex<0)){var r=t[d.activeIndex],i=r.offsetTop+r.clientHeight-e[0].scrollTop,c=e[0].offsetHeight;i>c?e[0].scrollTop+=i-c:i=d.items.length?0:d.activeIndex,r(function(){d.search=e||d.search,d.searchInput[0].focus()})},c=d.onDropdownCallback(t,{open:!0});angular.isDefined(c)?angular.isFunction(c.then)?c.then(function(e){e&&i()}):c===!0?i():c&&i():i()}},d.parseRepeatAttr=function(e,n,r){function i(e){var i=t.$eval(n);if(d.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(i)?i(e):e[i],n=d.findGroupByName(t);n?n.items.push(e):d.groups.push({name:t,items:[e]})}),r){var c=t.$eval(r);angular.isFunction(c)?d.groups=c(d.groups):angular.isArray(c)&&(d.groups=u(d.groups,c))}d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function c(e){d.items=e}d.setItemsFn=n?i:c,d.parserResult=l.parse(e),d.isGrouped=!!n,d.itemProperty=d.parserResult.itemName,d.refreshItems=function(e){e=e||d.parserResult.source(t);var n=d.selected;if(d.isEmpty()||angular.isArray(n)&&!n.length||!d.removeSelected)d.setItemsFn(e);else if(void 0!==e){var r=e.filter(function(e){return n.indexOf(e)<0});d.setItemsFn(r)}},t.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw o("items","Expected an array but got '{0}'.",e);d.refreshItems(e),d.ngModel.$modelValue=null}})},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){if(!d.open)return!1;var t=d.items.indexOf(e[d.itemProperty]),n=-1===t?!1:t===d.activeIndex;return n&&!angular.isUndefined(d.onHighlightCallback)&&e.$eval(d.onHighlightCallback),n},d.isDisabled=function(e){if(!d.open)return!1;var t,n=d.items.indexOf(e[d.itemProperty]),r=!1;return n>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[n],r=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=r),r},d.select=function(e,n,i){if((void 0===e||!e._uiSelectChoiceDisabled)&&(d.items||d.search)){var c={};c[d.parserResult.itemName]=e;var l={$item:e,$model:d.parserResult.modelMapper(t,c)},o=function(e){l.$item=e,t.$broadcast("uis:select",e),r(function(){d.onSelectCallback(t,l)}),d.closeOnSelect&&d.close(n),i&&"click"===i.type&&(d.clickTriggeredSelect=!0)};if(!angular.isDefined(d.onBeforeRemoveCallback))return o(e),void 0;var a=d.onBeforeSelectCallback(t,l);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(t){t&&(t===!0?o(e):t&&o(t))}):a===!0?o(e):a&&o(a):o(e)}},d.close=function(e){function n(){d.ngModel&&d.ngModel.$setTouched&&d.ngModel.$setTouched(),s(),d.open=!1,d.searchEnabled||angular.element(d.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e)}if(d.open){var r=d.onDropdownCallback(t,{open:!1});angular.isDefined(r)?angular.isFunction(r.then)?r.then(function(e){e&&n()}):r===!0?n():r&&n():n()}},d.setFocus=function(){d.focus||d.focusInput[0].focus()},d.clear=function(e){d.select(void 0),e.stopPropagation(),r(function(){d.focusser[0].focus()},0,!1)},d.toggle=function(e){d.open?(d.close(),e.preventDefault(),e.stopPropagation()):d.activate()},d.isLocked=function(e,t){var n,r=d.selected[t];return r&&!angular.isUndefined(d.lockChoiceExpression)&&(n=!!e.$eval(d.lockChoiceExpression),r._uiSelectChoiceLocked=n),n};var v=null;d.sizeSearchInput=function(){var e=d.searchInput[0],n=d.searchInput.parent().parent()[0],i=function(){return n.clientWidth*!!e.offsetParent},c=function(t){if(0===t)return!1;var n=t-e.offsetLeft-d.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=t),d.searchInput.css("width",n+"px"),!0};d.searchInput.css("width","10px"),r(function(){null!==v||c(i())||(v=t.$watch(i,function(e){c(e)&&(v(),v=null)}))})},d.searchInput.on("keydown",function(n){var r=n.which;t.$apply(function(){p(r)}),e.isVerticalMovement(r)&&d.items.length>0&&f(),(r===e.ENTER||r===e.ESC)&&(n.preventDefault(),n.stopPropagation())}),d.searchInput.on("keyup",function(n){n.which===e.TAB||e.isControl(n)||e.isFunctionKey(n)||n.which===e.ESC||e.isVerticalMovement(n.which)||void 0!==d.onKeypressCallback&&d.onKeypressCallback(t,{event:n})}),t.$on("$destroy",function(){d.searchInput.off("keyup keydown blur paste")})}]),n.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,r,i,c,l,o){return{restrict:"EA",templateUrl:function(e,t){var r=t.theme||n.theme;return r+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(c,a){return angular.isDefined(a.multiple)?c.append("").removeAttr("multiple"):c.append(""),function(c,a,s,u,p){function f(e){if(v.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(a[0],e.target):a[0].contains(e.target),!t&&!v.clickTriggeredSelect){var n=["input","button","textarea"],r=angular.element(e.target).scope(),i=r&&r.$select&&r.$select!==v;i||(i=~n.indexOf(e.target.tagName.toLowerCase())),v.close(i),c.$digest()}v.clickTriggeredSelect=!1}}function d(){var t=i(a);S=angular.element('
    '),S[0].style.width=t.width+"px",S[0].style.height=t.height+"px",a.after(S),b=a[0].style.width,e.find("body").append(a),a[0].style.position="absolute",a[0].style.left=t.left+"px",a[0].style.top=t.top+"px",a[0].style.width=t.width+"px"}function h(){null!==S&&(S.replaceWith(a),S=null,a[0].style.position="",a[0].style.left="",a[0].style.top="",a[0].style.width=b)}var v=u[0],m=u[1];v.generatedId=n.generateId(),v.baseTitle=s.title||"Select box",v.focusserTitle=v.baseTitle+" focus",v.focusserId="focusser-"+v.generatedId,v.closeOnSelect=function(){return angular.isDefined(s.closeOnSelect)?l(s.closeOnSelect)():n.closeOnSelect}(),v.onSelectCallback=l(s.onSelect),v.onBeforeSelectCallback=l(s.onBeforeSelect),v.onRemoveCallback=l(s.onRemove),v.onBeforeRemoveCallback=l(s.onBeforeRemove),v.onKeypressCallback=l(s.onKeypress),v.onDropdownCallback=l(s.onDropdown),v.limit=angular.isDefined(s.limit)?parseInt(s.limit,10):void 0,v.ngModel=m,v.choiceGrouped=function(e){return v.isGrouped&&e&&e.name},s.tabindex&&s.$observe("tabindex",function(e){v.focusInput.attr("tabindex",e),a.removeAttr("tabindex")});var g=c.$eval(s.searchEnabled);v.searchEnabled=void 0!==g?g:n.searchEnabled;var $=c.$eval(s.sortable);v.sortable=void 0!==$?$:n.sortable,s.$observe("disabled",function(){v.disabled=void 0!==s.disabled?s.disabled:!1}),angular.isDefined(s.autofocus)&&o(function(){v.setFocus()}),angular.isDefined(s.focusOn)&&c.$on(s.focusOn,function(){o(function(){v.setFocus()})}),e.on("click",f),c.$on("$destroy",function(){e.off("click",f)}),p(c,function(e){var t=angular.element("
    ").append(e),n=t.querySelectorAll(".ui-select-match");if(n.removeAttr("ui-select-match"),n.removeAttr("data-ui-select-match"),1!==n.length)throw r("transcluded","Expected 1 .ui-select-match but got '{0}'.",n.length);a.querySelectorAll(".ui-select-match").replaceWith(n);var i=t.querySelectorAll(".ui-select-choices");if(i.removeAttr("ui-select-choices"),i.removeAttr("data-ui-select-choices"),1!==i.length)throw r("transcluded","Expected 1 .ui-select-choices but got '{0}'.",i.length);a.querySelectorAll(".ui-select-choices").replaceWith(i)});var E=c.$eval(s.appendToBody);(void 0!==E?E:n.appendToBody)&&(c.$watch("$select.open",function(e){e?d():h()}),c.$on("$destroy",function(){h()}));var S=null,b="",C=null,w="direction-up";c.$watch("$select.open",function(n){if(n){if(C=angular.element(a).querySelectorAll(".ui-select-dropdown"),null===C)return;C[0].style.opacity=0,o(function(){var n=i(a),r=i(C);n.top+n.height+r.height>t.pageYOffset+e[0].documentElement.clientHeight&&a.addClass(w),C[0].style.opacity=1})}else{if(null===C)return;a.removeClass(w)}})}}}}]),n.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,r=t.parent().attr("multiple");return n+(r?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,r,i){function c(e){i.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}i.lockChoiceExpression=r.uiLockChoice,r.$observe("placeholder",function(t){i.placeholder=void 0!==t?t:e.placeholder}),r.$observe("allowClear",c),c(r.allowClear),i.multiple&&i.sizeSearchInput()}}}]),n.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,r=this,i=e.$select;e.$evalAsync(function(){n=e.ngModel}),r.activeMatchIndex=-1,r.updateModel=function(){n.$setViewValue(Date.now()),r.refreshComponent()},r.refreshComponent=function(){i.refreshItems(),i.sizeSearchInput()},r.removeChoice=function(n){function c(){t(function(){i.onRemoveCallback(e,a)}),r.updateModel()}var l=i.selected[n];if(!l._uiSelectChoiceLocked){var o={};o[i.parserResult.itemName]=l,i.selected.splice(n,1),r.activeMatchIndex=-1,i.sizeSearchInput();var a={$item:l,$model:i.parserResult.modelMapper(e,o)};if(!angular.isDefined(r.onBeforeRemoveCallback))return c(),void 0;var s=r.onBeforeRemoveCallback(e,a);angular.isDefined(s)?angular.isFunction(s.then)?s.then(function(e){e&&c(e)}):s===!0&&c():c()}},r.getPlaceholder=function(){return i.selected&&i.selected.length?void 0:i.placeholder}}],controllerAs:"$selectMultiple",link:function(r,i,c,l){function o(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(t){function n(){switch(t){case e.LEFT:return~p.activeMatchIndex?f:l;case e.RIGHT:return~p.activeMatchIndex&&a!==l?u:(s.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(a),f):l;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),a):!1}}var r=o(s.searchInput[0]),i=s.selected.length,c=0,l=i-1,a=p.activeMatchIndex,u=p.activeMatchIndex+1,f=p.activeMatchIndex-1,d=a;return r>0||s.search.length&&t==e.RIGHT?!1:(s.close(),d=n(),p.activeMatchIndex=s.selected.length&&d!==!1?Math.min(l,Math.max(c,d)):-1,!0)}var s=l[0],u=r.ngModel=l[1],p=r.$selectMultiple;s.multiple=!0,s.removeSelected=!0,s.focusInput=s.searchInput,u.$parsers.unshift(function(){for(var e,t={},n=[],i=s.selected.length-1;i>=0;i--)t={},t[s.parserResult.itemName]=s.selected[i],e=s.parserResult.modelMapper(r,t),n.unshift(e);return n}),u.$formatters.unshift(function(e){var t,n=s.parserResult.source(r,{$select:{search:""}}),i={};if(!n)return e;var c=[],l=function(e,n){if(e&&e.length){for(var l=e.length-1;l>=0;l--){if(i[s.parserResult.itemName]=e[l],t=s.parserResult.modelMapper(r,i),s.parserResult.trackByExp){var o=/\.(.+)/.exec(s.parserResult.trackByExp);if(o.length>0&&t[o[1]]==n[o[1]])return c.unshift(e[l]),!0}if(angular.equals(t,n))return c.unshift(e[l]),!0}return!1}};if(!e)return c;for(var o=e.length-1;o>=0;o--)l(s.selected,e[o])||l(n,e[o])||c.unshift(e[o]);return c}),r.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);s.selected=[]}s.selected=u.$viewValue,r.$evalAsync()},r.$on("uis:select",function(e,t){s.selected.length>=s.limit||(s.selected.push(t),p.updateModel())}),r.$on("uis:activate",function(){p.activeMatchIndex=-1}),r.$watch("$select.disabled",function(e,t){t&&!e&&s.sizeSearchInput()}),s.searchInput.on("keydown",function(t){var n=t.which;r.$apply(function(){var t=!1;e.isHorizontalMovement(n)&&(t=a(n)),t&&n!=e.TAB})}),s.searchInput.on("blur",function(){n(function(){p.activeMatchIndex=-1})})}}}]),n.directive("uiSelectSingle",["$timeout","$compile",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(r,i,c,l){var o=l[0],a=l[1];a.$parsers.unshift(function(e){var t,n={};return n[o.parserResult.itemName]=e,t=o.parserResult.modelMapper(r,n)}),a.$formatters.unshift(function(e){var t,n=o.parserResult.source(r,{$select:{search:""}}),i={};if(n){var c=function(n){return i[o.parserResult.itemName]=n,t=o.parserResult.modelMapper(r,i),t==e};if(o.selected&&c(o.selected))return o.selected;for(var l=n.length-1;l>=0;l--)if(c(n[l]))return n[l]}return e}),r.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){o.selected=a.$viewValue},r.$on("uis:select",function(e,t){o.selected=t}),r.$on("uis:close",function(e,n){t(function(){o.focusser.prop("disabled",!1),n||o.focusser[0].focus()},0,!1)}),r.$on("uis:activate",function(){s.prop("disabled",!0)});var s=angular.element("");n(s)(r),o.focusser=s,o.focusInput=s,i.parent().append(s),s.bind("focus",function(){r.$evalAsync(function(){o.focus=!0})}),s.bind("blur",function(){r.$evalAsync(function(){o.focus=!1})}),s.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),o.select(void 0),r.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),o.activate()),r.$digest()),void 0)}),s.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(o.activate(s.val()),s.val(""),r.$digest())})}}}]),n.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var r=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!r)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:r[2],source:t(r[3]),trackByExp:r[4],modelMapper:t(r[1]||r[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,r){var i=e+" in "+(r?"$group.items":t);return n&&(i+=" track by "+n),i}}])}(); \ No newline at end of file diff --git a/dist/select.select2.js b/dist/select.select2.js index f5ab144b9..b41ee5e15 100644 --- a/dist/select.select2.js +++ b/dist/select.select2.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-05T18:50:43.070Z + * Version: 0.12.1 - 2015-08-06T11:06:02.035Z * License: MIT */ @@ -588,7 +588,6 @@ uis.controller('uiSelectCtrl', * @return {boolean} true if the item is disabled */ ctrl.isDisabled = function (itemScope) { - if (!ctrl.open) { return false; } @@ -608,7 +607,8 @@ uis.controller('uiSelectCtrl', /** - * Selects an item + * Selects an item. Calls the onBeforeSelect and onSelect callbacks + * onBeforeSelect can alter or abort the selection * * Called when the user selects an item with ENTER or clicks the dropdown */ @@ -648,6 +648,12 @@ uis.controller('uiSelectCtrl', } }; + // If there's no onBeforeSelect callback, then just call the completeCallback + if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { + completeCallback(item); + return; + } + // Call the onBeforeSelect callback // Allowable responses are -: // falsy: Abort the selection @@ -658,11 +664,15 @@ uis.controller('uiSelectCtrl', if (angular.isDefined(result)) { if (angular.isFunction(result.then)) { // Promise returned - wait for it to complete before completing the selection - result.then(function (result) { - if (!result) { + result.then(function (response) { + if (!response) { return; } - completeCallback(result); + if (response === true) { + completeCallback(item); + } else if (response) { + completeCallback(response); + } }); } else if (result === true) { completeCallback(item); @@ -914,8 +924,8 @@ uis.controller('uiSelectCtrl', }]); uis.directive('uiSelect', - ['$document', 'uiSelectConfig', 'uiSelectMinErr', 'uisOffset', '$compile', '$parse', '$timeout', - function ($document, uiSelectConfig, uiSelectMinErr, uisOffset, $compile, $parse, $timeout) { + ['$document', '$window', 'uiSelectConfig', 'uiSelectMinErr', 'uisOffset', '$compile', '$parse', '$timeout', + function ($document, $window, uiSelectConfig, uiSelectMinErr, uisOffset, $compile, $parse, $timeout) { return { restrict: 'EA', @@ -1162,9 +1172,7 @@ uis.directive('uiSelect', var offsetDropdown = uisOffset(dropdown); // Determine if the direction of the dropdown needs to be changed. - if (offset.top + offset.height + offsetDropdown.height > - $document[0].documentElement.scrollTop + - $document[0].documentElement.clientHeight) { + if (offset.top + offset.height + offsetDropdown.height > $window.pageYOffset + $document[0].documentElement.clientHeight) { element.addClass(directionUpClassName); } @@ -1263,11 +1271,6 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel ctrl.activeMatchIndex = -1; $select.sizeSearchInput(); - // If there's no onBeforeRemove callback, then we're done - if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { - return; - } - var callbackContext = { $item: removedChoice, $model: $select.parserResult.modelMapper($scope, locals) @@ -1282,6 +1285,12 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel ctrl.updateModel(); } + // If there's no onBeforeRemove callback, then just call the completeCallback + if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { + completeCallback(); + return; + } + // Call the onBeforeRemove callback // Allowable responses are -: // falsy: Abort the removal diff --git a/dist/select.select2.min.js b/dist/select.select2.min.js index a163b6f96..92625e944 100644 --- a/dist/select.select2.min.js +++ b/dist/select.select2.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-05T18:50:43.070Z + * Version: 0.12.1 - 2015-08-06T11:06:02.035Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],c=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(c.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,c=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,l,n){n(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(c){var l=c[0].getBoundingClientRect();return{width:l.width||c.prop("offsetWidth"),height:l.height||c.prop("offsetHeight"),top:l.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:l.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);c.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,c,l){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(e,n){if(!n.repeat)throw c("repeat","Expected 'repeat' expression.");return function(e,n,i,s,r){var a=i.groupBy,o=i.groupFilter;if(s.parseRepeatAttr(i.repeat,a,o),s.disableChoiceExpression=i.uiDisableChoice,s.onHighlightCallback=i.onHighlight,a){var u=n.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=n.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(s.parserResult.itemName,"$select.items",s.parserResult.trackByExp,a)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+s.parserResult.itemName+")").attr("ng-click","$select.select("+s.parserResult.itemName+",false,$event)");var d=n.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),l(n,r)(e),e.$watch("$select.search",function(e){e&&!s.open&&s.multiple&&s.activate(!1,!0),s.activeIndex=0})}}}}]),c.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,c,l,n,i,s,r,a){function o(){(h.resetSearchInput||void 0===h.resetSearchInput&&a.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var c,l,n=[];for(c=0;c0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:c=!1}return c}function d(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw r("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var l=t[h.activeIndex],n=l.offsetTop+l.clientHeight-e[0].scrollTop,i=e[0].offsetHeight;n>i?e[0].scrollTop+=n-i:n=h.items.length?0:h.activeIndex,l(function(){h.search=e||h.search,h.searchInput[0].focus()})},i=h.onDropdownCallback(t,{open:!0});angular.isDefined(i)?angular.isFunction(i.then)?i.then(function(e){e&&n()}):i===!0?n():i&&n():n()}},h.parseRepeatAttr=function(e,c,l){function n(e){var n=t.$eval(c);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(n)?n(e):e[n],c=h.findGroupByName(t);c?c.items.push(e):h.groups.push({name:t,items:[e]})}),l){var i=t.$eval(l);angular.isFunction(i)?h.groups=i(h.groups):angular.isArray(i)&&(h.groups=u(h.groups,i))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function i(e){h.items=e}h.setItemsFn=c?n:i,h.parserResult=s.parse(e),h.isGrouped=!!c,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var c=h.selected;if(h.isEmpty()||angular.isArray(c)&&!c.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var l=e.filter(function(e){return c.indexOf(e)<0});h.setItemsFn(l)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw r("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),c=-1===t?!1:t===h.activeIndex;return c&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),c},h.isDisabled=function(e){if(!h.open)return!1;var t,c=h.items.indexOf(e[h.itemProperty]),l=!1;return c>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[c],l=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=l),l},h.select=function(e,c,n){if((void 0===e||!e._uiSelectChoiceDisabled)&&(h.items||h.search)){var i={};i[h.parserResult.itemName]=e;var s={$item:e,$model:h.parserResult.modelMapper(t,i)},r=function(e){s.$item=e,t.$broadcast("uis:select",e),l(function(){h.onSelectCallback(t,s)}),h.closeOnSelect&&h.close(c),n&&"click"===n.type&&(h.clickTriggeredSelect=!0)},a=h.onBeforeSelectCallback(t,s);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(e){e&&r(e)}):a===!0?r(e):a&&r(a):r(e)}},h.close=function(e){function c(){h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),o(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e)}if(h.open){var l=h.onDropdownCallback(t,{open:!1});angular.isDefined(l)?angular.isFunction(l.then)?l.then(function(e){e&&c()}):l===!0?c():l&&c():c()}},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),l(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var c,l=h.selected[t];return l&&!angular.isUndefined(h.lockChoiceExpression)&&(c=!!e.$eval(h.lockChoiceExpression),l._uiSelectChoiceLocked=c),c};var g=null;h.sizeSearchInput=function(){var e=h.searchInput[0],c=h.searchInput.parent().parent()[0],n=function(){return c.clientWidth*!!e.offsetParent},i=function(t){if(0===t)return!1;var c=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>c&&(c=t),h.searchInput.css("width",c+"px"),!0};h.searchInput.css("width","10px"),l(function(){null!==g||i(n())||(g=t.$watch(n,function(e){i(e)&&(g(),g=null)}))})},h.searchInput.on("keydown",function(c){var l=c.which;t.$apply(function(){p(l)}),e.isVerticalMovement(l)&&h.items.length>0&&d(),(l===e.ENTER||l===e.ESC)&&(c.preventDefault(),c.stopPropagation())}),h.searchInput.on("keyup",function(c){c.which===e.TAB||e.isControl(c)||e.isFunctionKey(c)||c.which===e.ESC||e.isVerticalMovement(c.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:c})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),c.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,c,l,n,i,s){return{restrict:"EA",templateUrl:function(e,c){var l=c.theme||t.theme;return l+(angular.isDefined(c.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(n,r){return angular.isDefined(r.multiple)?n.append("").removeAttr("multiple"):n.append(""),function(n,r,a,o,u){function p(e){if(f.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(r[0],e.target):r[0].contains(e.target),!t&&!f.clickTriggeredSelect){var c=["input","button","textarea"],l=angular.element(e.target).scope(),i=l&&l.$select&&l.$select!==f;i||(i=~c.indexOf(e.target.tagName.toLowerCase())),f.close(i),n.$digest()}f.clickTriggeredSelect=!1}}function d(){var t=l(r);b=angular.element('
    '),b[0].style.width=t.width+"px",b[0].style.height=t.height+"px",r.after(b),E=r[0].style.width,e.find("body").append(r),r[0].style.position="absolute",r[0].style.left=t.left+"px",r[0].style.top=t.top+"px",r[0].style.width=t.width+"px"}function h(){null!==b&&(b.replaceWith(r),b=null,r[0].style.position="",r[0].style.left="",r[0].style.top="",r[0].style.width=E)}var f=o[0],g=o[1];f.generatedId=t.generateId(),f.baseTitle=a.title||"Select box",f.focusserTitle=f.baseTitle+" focus",f.focusserId="focusser-"+f.generatedId,f.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?i(a.closeOnSelect)():t.closeOnSelect}(),f.onSelectCallback=i(a.onSelect),f.onBeforeSelectCallback=i(a.onBeforeSelect),f.onRemoveCallback=i(a.onRemove),f.onBeforeRemoveCallback=i(a.onBeforeRemove),f.onKeypressCallback=i(a.onKeypress),f.onDropdownCallback=i(a.onDropdown),f.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,f.ngModel=g,f.choiceGrouped=function(e){return f.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){f.focusInput.attr("tabindex",e),r.removeAttr("tabindex")});var v=n.$eval(a.searchEnabled);f.searchEnabled=void 0!==v?v:t.searchEnabled;var m=n.$eval(a.sortable);f.sortable=void 0!==m?m:t.sortable,a.$observe("disabled",function(){f.disabled=void 0!==a.disabled?a.disabled:!1}),angular.isDefined(a.autofocus)&&s(function(){f.setFocus()}),angular.isDefined(a.focusOn)&&n.$on(a.focusOn,function(){s(function(){f.setFocus()})}),e.on("click",p),n.$on("$destroy",function(){e.off("click",p)}),u(n,function(e){var t=angular.element("
    ").append(e),l=t.querySelectorAll(".ui-select-match");if(l.removeAttr("ui-select-match"),l.removeAttr("data-ui-select-match"),1!==l.length)throw c("transcluded","Expected 1 .ui-select-match but got '{0}'.",l.length);r.querySelectorAll(".ui-select-match").replaceWith(l);var n=t.querySelectorAll(".ui-select-choices");if(n.removeAttr("ui-select-choices"),n.removeAttr("data-ui-select-choices"),1!==n.length)throw c("transcluded","Expected 1 .ui-select-choices but got '{0}'.",n.length);r.querySelectorAll(".ui-select-choices").replaceWith(n)});var $=n.$eval(a.appendToBody);(void 0!==$?$:t.appendToBody)&&(n.$watch("$select.open",function(e){e?d():h()}),n.$on("$destroy",function(){h()}));var b=null,E="",w=null,S="direction-up";n.$watch("$select.open",function(t){if(t){if(w=angular.element(r).querySelectorAll(".ui-select-dropdown"),null===w)return;w[0].style.opacity=0,s(function(){var t=l(r),c=l(w);t.top+t.height+c.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&r.addClass(S),w[0].style.opacity=1})}else{if(null===w)return;r.removeClass(S)}})}}}}]),c.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,l=t.parent().attr("multiple");return c+(l?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,l,n){function i(e){n.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}n.lockChoiceExpression=l.uiLockChoice,l.$observe("placeholder",function(t){n.placeholder=void 0!==t?t:e.placeholder}),l.$observe("allowClear",i),i(l.allowClear),n.multiple&&n.sizeSearchInput()}}}]),c.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var c,l=this,n=e.$select;e.$evalAsync(function(){c=e.ngModel}),l.activeMatchIndex=-1,l.updateModel=function(){c.$setViewValue(Date.now()),l.refreshComponent()},l.refreshComponent=function(){n.refreshItems(),n.sizeSearchInput()},l.removeChoice=function(c){function i(){t(function(){n.onRemoveCallback(e,a)}),l.updateModel()}var s=n.selected[c];if(!s._uiSelectChoiceLocked){var r={};if(r[n.parserResult.itemName]=s,n.selected.splice(c,1),l.activeMatchIndex=-1,n.sizeSearchInput(),angular.isDefined(l.onBeforeRemoveCallback)){var a={$item:s,$model:n.parserResult.modelMapper(e,r)},o=l.onBeforeRemoveCallback(e,a);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(e){e&&i(e)}):o===!0&&i():i()}}},l.getPlaceholder=function(){return n.selected&&n.selected.length?void 0:n.placeholder}}],controllerAs:"$selectMultiple",link:function(l,n,i,s){function r(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(t){function c(){switch(t){case e.LEFT:return~p.activeMatchIndex?d:s;case e.RIGHT:return~p.activeMatchIndex&&a!==s?u:(o.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(a),d):s;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),a):!1}}var l=r(o.searchInput[0]),n=o.selected.length,i=0,s=n-1,a=p.activeMatchIndex,u=p.activeMatchIndex+1,d=p.activeMatchIndex-1,h=a;return l>0||o.search.length&&t==e.RIGHT?!1:(o.close(),h=c(),p.activeMatchIndex=o.selected.length&&h!==!1?Math.min(s,Math.max(i,h)):-1,!0)}var o=s[0],u=l.ngModel=s[1],p=l.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,u.$parsers.unshift(function(){for(var e,t={},c=[],n=o.selected.length-1;n>=0;n--)t={},t[o.parserResult.itemName]=o.selected[n],e=o.parserResult.modelMapper(l,t),c.unshift(e);return c}),u.$formatters.unshift(function(e){var t,c=o.parserResult.source(l,{$select:{search:""}}),n={};if(!c)return e;var i=[],s=function(e,c){if(e&&e.length){for(var s=e.length-1;s>=0;s--){if(n[o.parserResult.itemName]=e[s],t=o.parserResult.modelMapper(l,n),o.parserResult.trackByExp){var r=/\.(.+)/.exec(o.parserResult.trackByExp);if(r.length>0&&t[r[1]]==c[r[1]])return i.unshift(e[s]),!0}if(angular.equals(t,c))return i.unshift(e[s]),!0}return!1}};if(!e)return i;for(var r=e.length-1;r>=0;r--)s(o.selected,e[r])||s(c,e[r])||i.unshift(e[r]);return i}),l.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);o.selected=[]}o.selected=u.$viewValue,l.$evalAsync()},l.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),p.updateModel())}),l.$on("uis:activate",function(){p.activeMatchIndex=-1}),l.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(t){var c=t.which;l.$apply(function(){var t=!1;e.isHorizontalMovement(c)&&(t=a(c)),t&&c!=e.TAB})}),o.searchInput.on("blur",function(){c(function(){p.activeMatchIndex=-1})})}}}]),c.directive("uiSelectSingle",["$timeout","$compile",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(l,n,i,s){var r=s[0],a=s[1];a.$parsers.unshift(function(e){var t,c={};return c[r.parserResult.itemName]=e,t=r.parserResult.modelMapper(l,c)}),a.$formatters.unshift(function(e){var t,c=r.parserResult.source(l,{$select:{search:""}}),n={};if(c){var i=function(c){return n[r.parserResult.itemName]=c,t=r.parserResult.modelMapper(l,n),t==e};if(r.selected&&i(r.selected))return r.selected;for(var s=c.length-1;s>=0;s--)if(i(c[s]))return c[s]}return e}),l.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){r.selected=a.$viewValue},l.$on("uis:select",function(e,t){r.selected=t}),l.$on("uis:close",function(e,c){t(function(){r.focusser.prop("disabled",!1),c||r.focusser[0].focus()},0,!1)}),l.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");c(o)(l),r.focusser=o,r.focusInput=o,n.parent().append(o),o.bind("focus",function(){l.$evalAsync(function(){r.focus=!0})}),o.bind("blur",function(){l.$evalAsync(function(){r.focus=!1})}),o.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),r.select(void 0),l.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),r.activate()),l.$digest()),void 0)}),o.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(r.activate(o.val()),o.val(""),l.$digest())})}}}]),c.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var l=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!l)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:l[2],source:t(l[3]),trackByExp:l[4],modelMapper:t(l[1]||l[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,l){var n=e+" in "+(l?"$group.items":t);return c&&(n+=" track by "+c),n}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("select2/choices.tpl.html",'
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    ')}]); \ No newline at end of file +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],c=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(c.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,c=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,l,n){n(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(c){var l=c[0].getBoundingClientRect();return{width:l.width||c.prop("offsetWidth"),height:l.height||c.prop("offsetHeight"),top:l.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:l.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);c.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,c,l){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(e,n){if(!n.repeat)throw c("repeat","Expected 'repeat' expression.");return function(e,n,i,s,r){var a=i.groupBy,o=i.groupFilter;if(s.parseRepeatAttr(i.repeat,a,o),s.disableChoiceExpression=i.uiDisableChoice,s.onHighlightCallback=i.onHighlight,a){var u=n.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=n.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(s.parserResult.itemName,"$select.items",s.parserResult.trackByExp,a)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+s.parserResult.itemName+")").attr("ng-click","$select.select("+s.parserResult.itemName+",false,$event)");var d=n.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),l(n,r)(e),e.$watch("$select.search",function(e){e&&!s.open&&s.multiple&&s.activate(!1,!0),s.activeIndex=0})}}}}]),c.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,c,l,n,i,s,r,a){function o(){(h.resetSearchInput||void 0===h.resetSearchInput&&a.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var c,l,n=[];for(c=0;c0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:c=!1}return c}function d(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw r("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var l=t[h.activeIndex],n=l.offsetTop+l.clientHeight-e[0].scrollTop,i=e[0].offsetHeight;n>i?e[0].scrollTop+=n-i:n=h.items.length?0:h.activeIndex,l(function(){h.search=e||h.search,h.searchInput[0].focus()})},i=h.onDropdownCallback(t,{open:!0});angular.isDefined(i)?angular.isFunction(i.then)?i.then(function(e){e&&n()}):i===!0?n():i&&n():n()}},h.parseRepeatAttr=function(e,c,l){function n(e){var n=t.$eval(c);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(n)?n(e):e[n],c=h.findGroupByName(t);c?c.items.push(e):h.groups.push({name:t,items:[e]})}),l){var i=t.$eval(l);angular.isFunction(i)?h.groups=i(h.groups):angular.isArray(i)&&(h.groups=u(h.groups,i))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function i(e){h.items=e}h.setItemsFn=c?n:i,h.parserResult=s.parse(e),h.isGrouped=!!c,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var c=h.selected;if(h.isEmpty()||angular.isArray(c)&&!c.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var l=e.filter(function(e){return c.indexOf(e)<0});h.setItemsFn(l)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw r("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),c=-1===t?!1:t===h.activeIndex;return c&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),c},h.isDisabled=function(e){if(!h.open)return!1;var t,c=h.items.indexOf(e[h.itemProperty]),l=!1;return c>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[c],l=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=l),l},h.select=function(e,c,n){if((void 0===e||!e._uiSelectChoiceDisabled)&&(h.items||h.search)){var i={};i[h.parserResult.itemName]=e;var s={$item:e,$model:h.parserResult.modelMapper(t,i)},r=function(e){s.$item=e,t.$broadcast("uis:select",e),l(function(){h.onSelectCallback(t,s)}),h.closeOnSelect&&h.close(c),n&&"click"===n.type&&(h.clickTriggeredSelect=!0)};if(!angular.isDefined(h.onBeforeRemoveCallback))return r(e),void 0;var a=h.onBeforeSelectCallback(t,s);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(t){t&&(t===!0?r(e):t&&r(t))}):a===!0?r(e):a&&r(a):r(e)}},h.close=function(e){function c(){h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),o(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e)}if(h.open){var l=h.onDropdownCallback(t,{open:!1});angular.isDefined(l)?angular.isFunction(l.then)?l.then(function(e){e&&c()}):l===!0?c():l&&c():c()}},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),l(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var c,l=h.selected[t];return l&&!angular.isUndefined(h.lockChoiceExpression)&&(c=!!e.$eval(h.lockChoiceExpression),l._uiSelectChoiceLocked=c),c};var v=null;h.sizeSearchInput=function(){var e=h.searchInput[0],c=h.searchInput.parent().parent()[0],n=function(){return c.clientWidth*!!e.offsetParent},i=function(t){if(0===t)return!1;var c=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>c&&(c=t),h.searchInput.css("width",c+"px"),!0};h.searchInput.css("width","10px"),l(function(){null!==v||i(n())||(v=t.$watch(n,function(e){i(e)&&(v(),v=null)}))})},h.searchInput.on("keydown",function(c){var l=c.which;t.$apply(function(){p(l)}),e.isVerticalMovement(l)&&h.items.length>0&&d(),(l===e.ENTER||l===e.ESC)&&(c.preventDefault(),c.stopPropagation())}),h.searchInput.on("keyup",function(c){c.which===e.TAB||e.isControl(c)||e.isFunctionKey(c)||c.which===e.ESC||e.isVerticalMovement(c.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:c})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),c.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,c,l,n,i,s,r){return{restrict:"EA",templateUrl:function(e,t){var l=t.theme||c.theme;return l+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(i,a){return angular.isDefined(a.multiple)?i.append("").removeAttr("multiple"):i.append(""),function(i,a,o,u,p){function d(e){if(v.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(a[0],e.target):a[0].contains(e.target),!t&&!v.clickTriggeredSelect){var c=["input","button","textarea"],l=angular.element(e.target).scope(),n=l&&l.$select&&l.$select!==v;n||(n=~c.indexOf(e.target.tagName.toLowerCase())),v.close(n),i.$digest()}v.clickTriggeredSelect=!1}}function h(){var t=n(a);E=angular.element('
    '),E[0].style.width=t.width+"px",E[0].style.height=t.height+"px",a.after(E),w=a[0].style.width,e.find("body").append(a),a[0].style.position="absolute",a[0].style.left=t.left+"px",a[0].style.top=t.top+"px",a[0].style.width=t.width+"px"}function f(){null!==E&&(E.replaceWith(a),E=null,a[0].style.position="",a[0].style.left="",a[0].style.top="",a[0].style.width=w)}var v=u[0],g=u[1];v.generatedId=c.generateId(),v.baseTitle=o.title||"Select box",v.focusserTitle=v.baseTitle+" focus",v.focusserId="focusser-"+v.generatedId,v.closeOnSelect=function(){return angular.isDefined(o.closeOnSelect)?s(o.closeOnSelect)():c.closeOnSelect}(),v.onSelectCallback=s(o.onSelect),v.onBeforeSelectCallback=s(o.onBeforeSelect),v.onRemoveCallback=s(o.onRemove),v.onBeforeRemoveCallback=s(o.onBeforeRemove),v.onKeypressCallback=s(o.onKeypress),v.onDropdownCallback=s(o.onDropdown),v.limit=angular.isDefined(o.limit)?parseInt(o.limit,10):void 0,v.ngModel=g,v.choiceGrouped=function(e){return v.isGrouped&&e&&e.name},o.tabindex&&o.$observe("tabindex",function(e){v.focusInput.attr("tabindex",e),a.removeAttr("tabindex")});var m=i.$eval(o.searchEnabled);v.searchEnabled=void 0!==m?m:c.searchEnabled;var $=i.$eval(o.sortable);v.sortable=void 0!==$?$:c.sortable,o.$observe("disabled",function(){v.disabled=void 0!==o.disabled?o.disabled:!1}),angular.isDefined(o.autofocus)&&r(function(){v.setFocus()}),angular.isDefined(o.focusOn)&&i.$on(o.focusOn,function(){r(function(){v.setFocus()})}),e.on("click",d),i.$on("$destroy",function(){e.off("click",d)}),p(i,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),c.removeAttr("data-ui-select-match"),1!==c.length)throw l("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);a.querySelectorAll(".ui-select-match").replaceWith(c);var n=t.querySelectorAll(".ui-select-choices");if(n.removeAttr("ui-select-choices"),n.removeAttr("data-ui-select-choices"),1!==n.length)throw l("transcluded","Expected 1 .ui-select-choices but got '{0}'.",n.length);a.querySelectorAll(".ui-select-choices").replaceWith(n)});var b=i.$eval(o.appendToBody);(void 0!==b?b:c.appendToBody)&&(i.$watch("$select.open",function(e){e?h():f()}),i.$on("$destroy",function(){f()}));var E=null,w="",S=null,x="direction-up";i.$watch("$select.open",function(c){if(c){if(S=angular.element(a).querySelectorAll(".ui-select-dropdown"),null===S)return;S[0].style.opacity=0,r(function(){var c=n(a),l=n(S);c.top+c.height+l.height>t.pageYOffset+e[0].documentElement.clientHeight&&a.addClass(x),S[0].style.opacity=1})}else{if(null===S)return;a.removeClass(x)}})}}}}]),c.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,l=t.parent().attr("multiple");return c+(l?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,l,n){function i(e){n.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}n.lockChoiceExpression=l.uiLockChoice,l.$observe("placeholder",function(t){n.placeholder=void 0!==t?t:e.placeholder}),l.$observe("allowClear",i),i(l.allowClear),n.multiple&&n.sizeSearchInput()}}}]),c.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var c,l=this,n=e.$select;e.$evalAsync(function(){c=e.ngModel}),l.activeMatchIndex=-1,l.updateModel=function(){c.$setViewValue(Date.now()),l.refreshComponent()},l.refreshComponent=function(){n.refreshItems(),n.sizeSearchInput()},l.removeChoice=function(c){function i(){t(function(){n.onRemoveCallback(e,a)}),l.updateModel()}var s=n.selected[c];if(!s._uiSelectChoiceLocked){var r={};r[n.parserResult.itemName]=s,n.selected.splice(c,1),l.activeMatchIndex=-1,n.sizeSearchInput();var a={$item:s,$model:n.parserResult.modelMapper(e,r)};if(!angular.isDefined(l.onBeforeRemoveCallback))return i(),void 0;var o=l.onBeforeRemoveCallback(e,a);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(e){e&&i(e)}):o===!0&&i():i()}},l.getPlaceholder=function(){return n.selected&&n.selected.length?void 0:n.placeholder}}],controllerAs:"$selectMultiple",link:function(l,n,i,s){function r(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(t){function c(){switch(t){case e.LEFT:return~p.activeMatchIndex?d:s;case e.RIGHT:return~p.activeMatchIndex&&a!==s?u:(o.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(a),d):s;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),a):!1}}var l=r(o.searchInput[0]),n=o.selected.length,i=0,s=n-1,a=p.activeMatchIndex,u=p.activeMatchIndex+1,d=p.activeMatchIndex-1,h=a;return l>0||o.search.length&&t==e.RIGHT?!1:(o.close(),h=c(),p.activeMatchIndex=o.selected.length&&h!==!1?Math.min(s,Math.max(i,h)):-1,!0)}var o=s[0],u=l.ngModel=s[1],p=l.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,u.$parsers.unshift(function(){for(var e,t={},c=[],n=o.selected.length-1;n>=0;n--)t={},t[o.parserResult.itemName]=o.selected[n],e=o.parserResult.modelMapper(l,t),c.unshift(e);return c}),u.$formatters.unshift(function(e){var t,c=o.parserResult.source(l,{$select:{search:""}}),n={};if(!c)return e;var i=[],s=function(e,c){if(e&&e.length){for(var s=e.length-1;s>=0;s--){if(n[o.parserResult.itemName]=e[s],t=o.parserResult.modelMapper(l,n),o.parserResult.trackByExp){var r=/\.(.+)/.exec(o.parserResult.trackByExp);if(r.length>0&&t[r[1]]==c[r[1]])return i.unshift(e[s]),!0}if(angular.equals(t,c))return i.unshift(e[s]),!0}return!1}};if(!e)return i;for(var r=e.length-1;r>=0;r--)s(o.selected,e[r])||s(c,e[r])||i.unshift(e[r]);return i}),l.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);o.selected=[]}o.selected=u.$viewValue,l.$evalAsync()},l.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),p.updateModel())}),l.$on("uis:activate",function(){p.activeMatchIndex=-1}),l.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(t){var c=t.which;l.$apply(function(){var t=!1;e.isHorizontalMovement(c)&&(t=a(c)),t&&c!=e.TAB})}),o.searchInput.on("blur",function(){c(function(){p.activeMatchIndex=-1})})}}}]),c.directive("uiSelectSingle",["$timeout","$compile",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(l,n,i,s){var r=s[0],a=s[1];a.$parsers.unshift(function(e){var t,c={};return c[r.parserResult.itemName]=e,t=r.parserResult.modelMapper(l,c)}),a.$formatters.unshift(function(e){var t,c=r.parserResult.source(l,{$select:{search:""}}),n={};if(c){var i=function(c){return n[r.parserResult.itemName]=c,t=r.parserResult.modelMapper(l,n),t==e};if(r.selected&&i(r.selected))return r.selected;for(var s=c.length-1;s>=0;s--)if(i(c[s]))return c[s]}return e}),l.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){r.selected=a.$viewValue},l.$on("uis:select",function(e,t){r.selected=t}),l.$on("uis:close",function(e,c){t(function(){r.focusser.prop("disabled",!1),c||r.focusser[0].focus()},0,!1)}),l.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");c(o)(l),r.focusser=o,r.focusInput=o,n.parent().append(o),o.bind("focus",function(){l.$evalAsync(function(){r.focus=!0})}),o.bind("blur",function(){l.$evalAsync(function(){r.focus=!1})}),o.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),r.select(void 0),l.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),r.activate()),l.$digest()),void 0)}),o.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(r.activate(o.val()),o.val(""),l.$digest())})}}}]),c.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var l=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!l)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:l[2],source:t(l[3]),trackByExp:l[4],modelMapper:t(l[1]||l[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,l){var n=e+" in "+(l?"$group.items":t);return c&&(n+=" track by "+c),n}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("select2/choices.tpl.html",'
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/dist/select.selectize.js b/dist/select.selectize.js index d88daa4b3..9317ad0b2 100644 --- a/dist/select.selectize.js +++ b/dist/select.selectize.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-05T18:50:43.074Z + * Version: 0.12.1 - 2015-08-06T11:06:02.044Z * License: MIT */ @@ -588,7 +588,6 @@ uis.controller('uiSelectCtrl', * @return {boolean} true if the item is disabled */ ctrl.isDisabled = function (itemScope) { - if (!ctrl.open) { return false; } @@ -608,7 +607,8 @@ uis.controller('uiSelectCtrl', /** - * Selects an item + * Selects an item. Calls the onBeforeSelect and onSelect callbacks + * onBeforeSelect can alter or abort the selection * * Called when the user selects an item with ENTER or clicks the dropdown */ @@ -648,6 +648,12 @@ uis.controller('uiSelectCtrl', } }; + // If there's no onBeforeSelect callback, then just call the completeCallback + if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { + completeCallback(item); + return; + } + // Call the onBeforeSelect callback // Allowable responses are -: // falsy: Abort the selection @@ -658,11 +664,15 @@ uis.controller('uiSelectCtrl', if (angular.isDefined(result)) { if (angular.isFunction(result.then)) { // Promise returned - wait for it to complete before completing the selection - result.then(function (result) { - if (!result) { + result.then(function (response) { + if (!response) { return; } - completeCallback(result); + if (response === true) { + completeCallback(item); + } else if (response) { + completeCallback(response); + } }); } else if (result === true) { completeCallback(item); @@ -914,8 +924,8 @@ uis.controller('uiSelectCtrl', }]); uis.directive('uiSelect', - ['$document', 'uiSelectConfig', 'uiSelectMinErr', 'uisOffset', '$compile', '$parse', '$timeout', - function ($document, uiSelectConfig, uiSelectMinErr, uisOffset, $compile, $parse, $timeout) { + ['$document', '$window', 'uiSelectConfig', 'uiSelectMinErr', 'uisOffset', '$compile', '$parse', '$timeout', + function ($document, $window, uiSelectConfig, uiSelectMinErr, uisOffset, $compile, $parse, $timeout) { return { restrict: 'EA', @@ -1162,9 +1172,7 @@ uis.directive('uiSelect', var offsetDropdown = uisOffset(dropdown); // Determine if the direction of the dropdown needs to be changed. - if (offset.top + offset.height + offsetDropdown.height > - $document[0].documentElement.scrollTop + - $document[0].documentElement.clientHeight) { + if (offset.top + offset.height + offsetDropdown.height > $window.pageYOffset + $document[0].documentElement.clientHeight) { element.addClass(directionUpClassName); } @@ -1263,11 +1271,6 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel ctrl.activeMatchIndex = -1; $select.sizeSearchInput(); - // If there's no onBeforeRemove callback, then we're done - if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { - return; - } - var callbackContext = { $item: removedChoice, $model: $select.parserResult.modelMapper($scope, locals) @@ -1282,6 +1285,12 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel ctrl.updateModel(); } + // If there's no onBeforeRemove callback, then just call the completeCallback + if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { + completeCallback(); + return; + } + // Call the onBeforeRemove callback // Allowable responses are -: // falsy: Abort the removal diff --git a/dist/select.selectize.min.js b/dist/select.selectize.min.js index dabbcdbd9..7d4fa1486 100644 --- a/dist/select.selectize.min.js +++ b/dist/select.selectize.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-05T18:50:43.074Z + * Version: 0.12.1 - 2015-08-06T11:06:02.044Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var n=t.which;switch(n){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,n=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,i,c){c(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var i=n[0].getBoundingClientRect();return{width:i.width||n.prop("offsetWidth"),height:i.height||n.prop("offsetHeight"),top:i.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:i.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);n.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,c){if(!c.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,c,r,l,s){var o=r.groupBy,a=r.groupFilter;if(l.parseRepeatAttr(r.repeat,o,a),l.disableChoiceExpression=r.uiDisableChoice,l.onHighlightCallback=r.onHighlight,o){var u=c.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=c.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(l.parserResult.itemName,"$select.items",l.parserResult.trackByExp,o)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+l.parserResult.itemName+")").attr("ng-click","$select.select("+l.parserResult.itemName+",false,$event)");var d=c.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),i(c,s)(e),e.$watch("$select.search",function(e){e&&!l.open&&l.multiple&&l.activate(!1,!0),l.activeIndex=0})}}}}]),n.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,n,i,c,r,l,s,o){function a(){(h.resetSearchInput||void 0===h.resetSearchInput&&o.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var n,i,c=[];for(n=0;n0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:n=!1}return n}function d(){var e=n.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw s("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var i=t[h.activeIndex],c=i.offsetTop+i.clientHeight-e[0].scrollTop,r=e[0].offsetHeight;c>r?e[0].scrollTop+=c-r:c=h.items.length?0:h.activeIndex,i(function(){h.search=e||h.search,h.searchInput[0].focus()})},r=h.onDropdownCallback(t,{open:!0});angular.isDefined(r)?angular.isFunction(r.then)?r.then(function(e){e&&c()}):r===!0?c():r&&c():c()}},h.parseRepeatAttr=function(e,n,i){function c(e){var c=t.$eval(n);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(c)?c(e):e[c],n=h.findGroupByName(t);n?n.items.push(e):h.groups.push({name:t,items:[e]})}),i){var r=t.$eval(i);angular.isFunction(r)?h.groups=r(h.groups):angular.isArray(r)&&(h.groups=u(h.groups,r))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function r(e){h.items=e}h.setItemsFn=n?c:r,h.parserResult=l.parse(e),h.isGrouped=!!n,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var n=h.selected;if(h.isEmpty()||angular.isArray(n)&&!n.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var i=e.filter(function(e){return n.indexOf(e)<0});h.setItemsFn(i)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw s("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),n=-1===t?!1:t===h.activeIndex;return n&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),n},h.isDisabled=function(e){if(!h.open)return!1;var t,n=h.items.indexOf(e[h.itemProperty]),i=!1;return n>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[n],i=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i},h.select=function(e,n,c){if((void 0===e||!e._uiSelectChoiceDisabled)&&(h.items||h.search)){var r={};r[h.parserResult.itemName]=e;var l={$item:e,$model:h.parserResult.modelMapper(t,r)},s=function(e){l.$item=e,t.$broadcast("uis:select",e),i(function(){h.onSelectCallback(t,l)}),h.closeOnSelect&&h.close(n),c&&"click"===c.type&&(h.clickTriggeredSelect=!0)},o=h.onBeforeSelectCallback(t,l);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(e){e&&s(e)}):o===!0?s(e):o&&s(o):s(e)}},h.close=function(e){function n(){h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),a(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e)}if(h.open){var i=h.onDropdownCallback(t,{open:!1});angular.isDefined(i)?angular.isFunction(i.then)?i.then(function(e){e&&n()}):i===!0?n():i&&n():n()}},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),i(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var n,i=h.selected[t];return i&&!angular.isUndefined(h.lockChoiceExpression)&&(n=!!e.$eval(h.lockChoiceExpression),i._uiSelectChoiceLocked=n),n};var v=null;h.sizeSearchInput=function(){var e=h.searchInput[0],n=h.searchInput.parent().parent()[0],c=function(){return n.clientWidth*!!e.offsetParent},r=function(t){if(0===t)return!1;var n=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=t),h.searchInput.css("width",n+"px"),!0};h.searchInput.css("width","10px"),i(function(){null!==v||r(c())||(v=t.$watch(c,function(e){r(e)&&(v(),v=null)}))})},h.searchInput.on("keydown",function(n){var i=n.which;t.$apply(function(){p(i)}),e.isVerticalMovement(i)&&h.items.length>0&&d(),(i===e.ENTER||i===e.ESC)&&(n.preventDefault(),n.stopPropagation())}),h.searchInput.on("keyup",function(n){n.which===e.TAB||e.isControl(n)||e.isFunctionKey(n)||n.which===e.ESC||e.isVerticalMovement(n.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:n})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),n.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,i,c,r,l){return{restrict:"EA",templateUrl:function(e,n){var i=n.theme||t.theme;return i+(angular.isDefined(n.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(c,s){return angular.isDefined(s.multiple)?c.append("").removeAttr("multiple"):c.append(""),function(c,s,o,a,u){function p(e){if(f.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(s[0],e.target):s[0].contains(e.target),!t&&!f.clickTriggeredSelect){var n=["input","button","textarea"],i=angular.element(e.target).scope(),r=i&&i.$select&&i.$select!==f;r||(r=~n.indexOf(e.target.tagName.toLowerCase())),f.close(r),c.$digest()}f.clickTriggeredSelect=!1}}function d(){var t=i(s);E=angular.element('
    '),E[0].style.width=t.width+"px",E[0].style.height=t.height+"px",s.after(E),b=s[0].style.width,e.find("body").append(s),s[0].style.position="absolute",s[0].style.left=t.left+"px",s[0].style.top=t.top+"px",s[0].style.width=t.width+"px"}function h(){null!==E&&(E.replaceWith(s),E=null,s[0].style.position="",s[0].style.left="",s[0].style.top="",s[0].style.width=b)}var f=a[0],v=a[1];f.generatedId=t.generateId(),f.baseTitle=o.title||"Select box",f.focusserTitle=f.baseTitle+" focus",f.focusserId="focusser-"+f.generatedId,f.closeOnSelect=function(){return angular.isDefined(o.closeOnSelect)?r(o.closeOnSelect)():t.closeOnSelect}(),f.onSelectCallback=r(o.onSelect),f.onBeforeSelectCallback=r(o.onBeforeSelect),f.onRemoveCallback=r(o.onRemove),f.onBeforeRemoveCallback=r(o.onBeforeRemove),f.onKeypressCallback=r(o.onKeypress),f.onDropdownCallback=r(o.onDropdown),f.limit=angular.isDefined(o.limit)?parseInt(o.limit,10):void 0,f.ngModel=v,f.choiceGrouped=function(e){return f.isGrouped&&e&&e.name},o.tabindex&&o.$observe("tabindex",function(e){f.focusInput.attr("tabindex",e),s.removeAttr("tabindex")});var g=c.$eval(o.searchEnabled);f.searchEnabled=void 0!==g?g:t.searchEnabled;var m=c.$eval(o.sortable);f.sortable=void 0!==m?m:t.sortable,o.$observe("disabled",function(){f.disabled=void 0!==o.disabled?o.disabled:!1}),angular.isDefined(o.autofocus)&&l(function(){f.setFocus()}),angular.isDefined(o.focusOn)&&c.$on(o.focusOn,function(){l(function(){f.setFocus()})}),e.on("click",p),c.$on("$destroy",function(){e.off("click",p)}),u(c,function(e){var t=angular.element("
    ").append(e),i=t.querySelectorAll(".ui-select-match");if(i.removeAttr("ui-select-match"),i.removeAttr("data-ui-select-match"),1!==i.length)throw n("transcluded","Expected 1 .ui-select-match but got '{0}'.",i.length);s.querySelectorAll(".ui-select-match").replaceWith(i);var c=t.querySelectorAll(".ui-select-choices");if(c.removeAttr("ui-select-choices"),c.removeAttr("data-ui-select-choices"),1!==c.length)throw n("transcluded","Expected 1 .ui-select-choices but got '{0}'.",c.length);s.querySelectorAll(".ui-select-choices").replaceWith(c)});var $=c.$eval(o.appendToBody);(void 0!==$?$:t.appendToBody)&&(c.$watch("$select.open",function(e){e?d():h()}),c.$on("$destroy",function(){h()}));var E=null,b="",S=null,w="direction-up";c.$watch("$select.open",function(t){if(t){if(S=angular.element(s).querySelectorAll(".ui-select-dropdown"),null===S)return;S[0].style.opacity=0,l(function(){var t=i(s),n=i(S);t.top+t.height+n.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&s.addClass(w),S[0].style.opacity=1})}else{if(null===S)return;s.removeClass(w)}})}}}}]),n.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return n+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,i,c){function r(e){c.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}c.lockChoiceExpression=i.uiLockChoice,i.$observe("placeholder",function(t){c.placeholder=void 0!==t?t:e.placeholder}),i.$observe("allowClear",r),r(i.allowClear),c.multiple&&c.sizeSearchInput()}}}]),n.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,i=this,c=e.$select;e.$evalAsync(function(){n=e.ngModel}),i.activeMatchIndex=-1,i.updateModel=function(){n.$setViewValue(Date.now()),i.refreshComponent()},i.refreshComponent=function(){c.refreshItems(),c.sizeSearchInput()},i.removeChoice=function(n){function r(){t(function(){c.onRemoveCallback(e,o)}),i.updateModel()}var l=c.selected[n];if(!l._uiSelectChoiceLocked){var s={};if(s[c.parserResult.itemName]=l,c.selected.splice(n,1),i.activeMatchIndex=-1,c.sizeSearchInput(),angular.isDefined(i.onBeforeRemoveCallback)){var o={$item:l,$model:c.parserResult.modelMapper(e,s)},a=i.onBeforeRemoveCallback(e,o);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(e){e&&r(e)}):a===!0&&r():r()}}},i.getPlaceholder=function(){return c.selected&&c.selected.length?void 0:c.placeholder}}],controllerAs:"$selectMultiple",link:function(i,c,r,l){function s(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function o(t){function n(){switch(t){case e.LEFT:return~p.activeMatchIndex?d:l;case e.RIGHT:return~p.activeMatchIndex&&o!==l?u:(a.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(o),d):l;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),o):!1}}var i=s(a.searchInput[0]),c=a.selected.length,r=0,l=c-1,o=p.activeMatchIndex,u=p.activeMatchIndex+1,d=p.activeMatchIndex-1,h=o;return i>0||a.search.length&&t==e.RIGHT?!1:(a.close(),h=n(),p.activeMatchIndex=a.selected.length&&h!==!1?Math.min(l,Math.max(r,h)):-1,!0)}var a=l[0],u=i.ngModel=l[1],p=i.$selectMultiple;a.multiple=!0,a.removeSelected=!0,a.focusInput=a.searchInput,u.$parsers.unshift(function(){for(var e,t={},n=[],c=a.selected.length-1;c>=0;c--)t={},t[a.parserResult.itemName]=a.selected[c],e=a.parserResult.modelMapper(i,t),n.unshift(e);return n}),u.$formatters.unshift(function(e){var t,n=a.parserResult.source(i,{$select:{search:""}}),c={};if(!n)return e;var r=[],l=function(e,n){if(e&&e.length){for(var l=e.length-1;l>=0;l--){if(c[a.parserResult.itemName]=e[l],t=a.parserResult.modelMapper(i,c),a.parserResult.trackByExp){var s=/\.(.+)/.exec(a.parserResult.trackByExp);if(s.length>0&&t[s[1]]==n[s[1]])return r.unshift(e[l]),!0}if(angular.equals(t,n))return r.unshift(e[l]),!0}return!1}};if(!e)return r;for(var s=e.length-1;s>=0;s--)l(a.selected,e[s])||l(n,e[s])||r.unshift(e[s]);return r}),i.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);a.selected=[]}a.selected=u.$viewValue,i.$evalAsync()},i.$on("uis:select",function(e,t){a.selected.length>=a.limit||(a.selected.push(t),p.updateModel())}),i.$on("uis:activate",function(){p.activeMatchIndex=-1}),i.$watch("$select.disabled",function(e,t){t&&!e&&a.sizeSearchInput()}),a.searchInput.on("keydown",function(t){var n=t.which;i.$apply(function(){var t=!1;e.isHorizontalMovement(n)&&(t=o(n)),t&&n!=e.TAB})}),a.searchInput.on("blur",function(){n(function(){p.activeMatchIndex=-1})})}}}]),n.directive("uiSelectSingle",["$timeout","$compile",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(i,c,r,l){var s=l[0],o=l[1];o.$parsers.unshift(function(e){var t,n={};return n[s.parserResult.itemName]=e,t=s.parserResult.modelMapper(i,n)}),o.$formatters.unshift(function(e){var t,n=s.parserResult.source(i,{$select:{search:""}}),c={};if(n){var r=function(n){return c[s.parserResult.itemName]=n,t=s.parserResult.modelMapper(i,c),t==e};if(s.selected&&r(s.selected))return s.selected;for(var l=n.length-1;l>=0;l--)if(r(n[l]))return n[l]}return e}),i.$watch("$select.selected",function(e){o.$viewValue!==e&&o.$setViewValue(e)}),o.$render=function(){s.selected=o.$viewValue},i.$on("uis:select",function(e,t){s.selected=t}),i.$on("uis:close",function(e,n){t(function(){s.focusser.prop("disabled",!1),n||s.focusser[0].focus()},0,!1)}),i.$on("uis:activate",function(){a.prop("disabled",!0)});var a=angular.element("");n(a)(i),s.focusser=a,s.focusInput=a,c.parent().append(a),a.bind("focus",function(){i.$evalAsync(function(){s.focus=!0})}),a.bind("blur",function(){i.$evalAsync(function(){s.focus=!1})}),a.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),s.select(void 0),i.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),s.activate()),i.$digest()),void 0)}),a.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(s.activate(a.val()),a.val(""),i.$digest())})}}}]),n.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var i=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!i)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:i[2],source:t(i[3]),trackByExp:i[4],modelMapper:t(i[1]||i[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,i){var c=e+" in "+(i?"$group.items":t);return n&&(c+=" track by "+n),c}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("selectize/choices.tpl.html",'
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var n=t.which;switch(n){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,n=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,i,c){c(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var i=n[0].getBoundingClientRect();return{width:i.width||n.prop("offsetWidth"),height:i.height||n.prop("offsetHeight"),top:i.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:i.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);n.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,c){if(!c.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,c,r,l,s){var o=r.groupBy,a=r.groupFilter;if(l.parseRepeatAttr(r.repeat,o,a),l.disableChoiceExpression=r.uiDisableChoice,l.onHighlightCallback=r.onHighlight,o){var u=c.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=c.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(l.parserResult.itemName,"$select.items",l.parserResult.trackByExp,o)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+l.parserResult.itemName+")").attr("ng-click","$select.select("+l.parserResult.itemName+",false,$event)");var d=c.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),i(c,s)(e),e.$watch("$select.search",function(e){e&&!l.open&&l.multiple&&l.activate(!1,!0),l.activeIndex=0})}}}}]),n.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,n,i,c,r,l,s,o){function a(){(f.resetSearchInput||void 0===f.resetSearchInput&&o.resetSearchInput)&&(f.search=h,f.selected&&f.items.length&&!f.multiple&&(f.activeIndex=f.items.indexOf(f.selected)))}function u(e,t){var n,i,c=[];for(n=0;n0&&f.activeIndex--;break;case e.TAB:(!f.multiple||f.open)&&f.select(f.items[f.activeIndex],!0);break;case e.ENTER:f.open?f.select(f.items[f.activeIndex]):f.activate(!1,!0);break;case e.ESC:f.close();break;default:n=!1}return n}function d(){var e=n.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw s("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(f.activeIndex<0)){var i=t[f.activeIndex],c=i.offsetTop+i.clientHeight-e[0].scrollTop,r=e[0].offsetHeight;c>r?e[0].scrollTop+=c-r:c=f.items.length?0:f.activeIndex,i(function(){f.search=e||f.search,f.searchInput[0].focus()})},r=f.onDropdownCallback(t,{open:!0});angular.isDefined(r)?angular.isFunction(r.then)?r.then(function(e){e&&c()}):r===!0?c():r&&c():c()}},f.parseRepeatAttr=function(e,n,i){function c(e){var c=t.$eval(n);if(f.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(c)?c(e):e[c],n=f.findGroupByName(t);n?n.items.push(e):f.groups.push({name:t,items:[e]})}),i){var r=t.$eval(i);angular.isFunction(r)?f.groups=r(f.groups):angular.isArray(r)&&(f.groups=u(f.groups,r))}f.items=[],f.groups.forEach(function(e){f.items=f.items.concat(e.items)})}function r(e){f.items=e}f.setItemsFn=n?c:r,f.parserResult=l.parse(e),f.isGrouped=!!n,f.itemProperty=f.parserResult.itemName,f.refreshItems=function(e){e=e||f.parserResult.source(t);var n=f.selected;if(f.isEmpty()||angular.isArray(n)&&!n.length||!f.removeSelected)f.setItemsFn(e);else if(void 0!==e){var i=e.filter(function(e){return n.indexOf(e)<0});f.setItemsFn(i)}},t.$watchCollection(f.parserResult.source,function(e){if(void 0===e||null===e)f.items=[];else{if(!angular.isArray(e))throw s("items","Expected an array but got '{0}'.",e);f.refreshItems(e),f.ngModel.$modelValue=null}})},f.setActiveItem=function(e){f.activeIndex=f.items.indexOf(e)},f.isActive=function(e){if(!f.open)return!1;var t=f.items.indexOf(e[f.itemProperty]),n=-1===t?!1:t===f.activeIndex;return n&&!angular.isUndefined(f.onHighlightCallback)&&e.$eval(f.onHighlightCallback),n},f.isDisabled=function(e){if(!f.open)return!1;var t,n=f.items.indexOf(e[f.itemProperty]),i=!1;return n>=0&&!angular.isUndefined(f.disableChoiceExpression)&&(t=f.items[n],i=!!e.$eval(f.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i},f.select=function(e,n,c){if((void 0===e||!e._uiSelectChoiceDisabled)&&(f.items||f.search)){var r={};r[f.parserResult.itemName]=e;var l={$item:e,$model:f.parserResult.modelMapper(t,r)},s=function(e){l.$item=e,t.$broadcast("uis:select",e),i(function(){f.onSelectCallback(t,l)}),f.closeOnSelect&&f.close(n),c&&"click"===c.type&&(f.clickTriggeredSelect=!0)};if(!angular.isDefined(f.onBeforeRemoveCallback))return s(e),void 0;var o=f.onBeforeSelectCallback(t,l);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(t){t&&(t===!0?s(e):t&&s(t))}):o===!0?s(e):o&&s(o):s(e)}},f.close=function(e){function n(){f.ngModel&&f.ngModel.$setTouched&&f.ngModel.$setTouched(),a(),f.open=!1,f.searchEnabled||angular.element(f.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e)}if(f.open){var i=f.onDropdownCallback(t,{open:!1});angular.isDefined(i)?angular.isFunction(i.then)?i.then(function(e){e&&n()}):i===!0?n():i&&n():n()}},f.setFocus=function(){f.focus||f.focusInput[0].focus()},f.clear=function(e){f.select(void 0),e.stopPropagation(),i(function(){f.focusser[0].focus()},0,!1)},f.toggle=function(e){f.open?(f.close(),e.preventDefault(),e.stopPropagation()):f.activate()},f.isLocked=function(e,t){var n,i=f.selected[t];return i&&!angular.isUndefined(f.lockChoiceExpression)&&(n=!!e.$eval(f.lockChoiceExpression),i._uiSelectChoiceLocked=n),n};var v=null;f.sizeSearchInput=function(){var e=f.searchInput[0],n=f.searchInput.parent().parent()[0],c=function(){return n.clientWidth*!!e.offsetParent},r=function(t){if(0===t)return!1;var n=t-e.offsetLeft-f.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=t),f.searchInput.css("width",n+"px"),!0};f.searchInput.css("width","10px"),i(function(){null!==v||r(c())||(v=t.$watch(c,function(e){r(e)&&(v(),v=null)}))})},f.searchInput.on("keydown",function(n){var i=n.which;t.$apply(function(){p(i)}),e.isVerticalMovement(i)&&f.items.length>0&&d(),(i===e.ENTER||i===e.ESC)&&(n.preventDefault(),n.stopPropagation())}),f.searchInput.on("keyup",function(n){n.which===e.TAB||e.isControl(n)||e.isFunctionKey(n)||n.which===e.ESC||e.isVerticalMovement(n.which)||void 0!==f.onKeypressCallback&&f.onKeypressCallback(t,{event:n})}),t.$on("$destroy",function(){f.searchInput.off("keyup keydown blur paste")})}]),n.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,i,c,r,l,s){return{restrict:"EA",templateUrl:function(e,t){var i=t.theme||n.theme;return i+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(r,o){return angular.isDefined(o.multiple)?r.append("").removeAttr("multiple"):r.append(""),function(r,o,a,u,p){function d(e){if(v.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(o[0],e.target):o[0].contains(e.target),!t&&!v.clickTriggeredSelect){var n=["input","button","textarea"],i=angular.element(e.target).scope(),c=i&&i.$select&&i.$select!==v;c||(c=~n.indexOf(e.target.tagName.toLowerCase())),v.close(c),r.$digest()}v.clickTriggeredSelect=!1}}function f(){var t=c(o);b=angular.element('
    '),b[0].style.width=t.width+"px",b[0].style.height=t.height+"px",o.after(b),S=o[0].style.width,e.find("body").append(o),o[0].style.position="absolute",o[0].style.left=t.left+"px",o[0].style.top=t.top+"px",o[0].style.width=t.width+"px"}function h(){null!==b&&(b.replaceWith(o),b=null,o[0].style.position="",o[0].style.left="",o[0].style.top="",o[0].style.width=S)}var v=u[0],g=u[1];v.generatedId=n.generateId(),v.baseTitle=a.title||"Select box",v.focusserTitle=v.baseTitle+" focus",v.focusserId="focusser-"+v.generatedId,v.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?l(a.closeOnSelect)():n.closeOnSelect}(),v.onSelectCallback=l(a.onSelect),v.onBeforeSelectCallback=l(a.onBeforeSelect),v.onRemoveCallback=l(a.onRemove),v.onBeforeRemoveCallback=l(a.onBeforeRemove),v.onKeypressCallback=l(a.onKeypress),v.onDropdownCallback=l(a.onDropdown),v.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,v.ngModel=g,v.choiceGrouped=function(e){return v.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){v.focusInput.attr("tabindex",e),o.removeAttr("tabindex")});var m=r.$eval(a.searchEnabled);v.searchEnabled=void 0!==m?m:n.searchEnabled;var $=r.$eval(a.sortable);v.sortable=void 0!==$?$:n.sortable,a.$observe("disabled",function(){v.disabled=void 0!==a.disabled?a.disabled:!1}),angular.isDefined(a.autofocus)&&s(function(){v.setFocus()}),angular.isDefined(a.focusOn)&&r.$on(a.focusOn,function(){s(function(){v.setFocus()})}),e.on("click",d),r.$on("$destroy",function(){e.off("click",d)}),p(r,function(e){var t=angular.element("
    ").append(e),n=t.querySelectorAll(".ui-select-match");if(n.removeAttr("ui-select-match"),n.removeAttr("data-ui-select-match"),1!==n.length)throw i("transcluded","Expected 1 .ui-select-match but got '{0}'.",n.length);o.querySelectorAll(".ui-select-match").replaceWith(n);var c=t.querySelectorAll(".ui-select-choices");if(c.removeAttr("ui-select-choices"),c.removeAttr("data-ui-select-choices"),1!==c.length)throw i("transcluded","Expected 1 .ui-select-choices but got '{0}'.",c.length);o.querySelectorAll(".ui-select-choices").replaceWith(c)});var E=r.$eval(a.appendToBody);(void 0!==E?E:n.appendToBody)&&(r.$watch("$select.open",function(e){e?f():h()}),r.$on("$destroy",function(){h()}));var b=null,S="",w=null,C="direction-up";r.$watch("$select.open",function(n){if(n){if(w=angular.element(o).querySelectorAll(".ui-select-dropdown"),null===w)return;w[0].style.opacity=0,s(function(){var n=c(o),i=c(w);n.top+n.height+i.height>t.pageYOffset+e[0].documentElement.clientHeight&&o.addClass(C),w[0].style.opacity=1})}else{if(null===w)return;o.removeClass(C)}})}}}}]),n.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return n+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,i,c){function r(e){c.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}c.lockChoiceExpression=i.uiLockChoice,i.$observe("placeholder",function(t){c.placeholder=void 0!==t?t:e.placeholder}),i.$observe("allowClear",r),r(i.allowClear),c.multiple&&c.sizeSearchInput()}}}]),n.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,i=this,c=e.$select;e.$evalAsync(function(){n=e.ngModel}),i.activeMatchIndex=-1,i.updateModel=function(){n.$setViewValue(Date.now()),i.refreshComponent()},i.refreshComponent=function(){c.refreshItems(),c.sizeSearchInput()},i.removeChoice=function(n){function r(){t(function(){c.onRemoveCallback(e,o)}),i.updateModel()}var l=c.selected[n];if(!l._uiSelectChoiceLocked){var s={};s[c.parserResult.itemName]=l,c.selected.splice(n,1),i.activeMatchIndex=-1,c.sizeSearchInput();var o={$item:l,$model:c.parserResult.modelMapper(e,s)};if(!angular.isDefined(i.onBeforeRemoveCallback))return r(),void 0;var a=i.onBeforeRemoveCallback(e,o);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(e){e&&r(e)}):a===!0&&r():r()}},i.getPlaceholder=function(){return c.selected&&c.selected.length?void 0:c.placeholder}}],controllerAs:"$selectMultiple",link:function(i,c,r,l){function s(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function o(t){function n(){switch(t){case e.LEFT:return~p.activeMatchIndex?d:l;case e.RIGHT:return~p.activeMatchIndex&&o!==l?u:(a.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(o),d):l;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),o):!1}}var i=s(a.searchInput[0]),c=a.selected.length,r=0,l=c-1,o=p.activeMatchIndex,u=p.activeMatchIndex+1,d=p.activeMatchIndex-1,f=o;return i>0||a.search.length&&t==e.RIGHT?!1:(a.close(),f=n(),p.activeMatchIndex=a.selected.length&&f!==!1?Math.min(l,Math.max(r,f)):-1,!0)}var a=l[0],u=i.ngModel=l[1],p=i.$selectMultiple;a.multiple=!0,a.removeSelected=!0,a.focusInput=a.searchInput,u.$parsers.unshift(function(){for(var e,t={},n=[],c=a.selected.length-1;c>=0;c--)t={},t[a.parserResult.itemName]=a.selected[c],e=a.parserResult.modelMapper(i,t),n.unshift(e);return n}),u.$formatters.unshift(function(e){var t,n=a.parserResult.source(i,{$select:{search:""}}),c={};if(!n)return e;var r=[],l=function(e,n){if(e&&e.length){for(var l=e.length-1;l>=0;l--){if(c[a.parserResult.itemName]=e[l],t=a.parserResult.modelMapper(i,c),a.parserResult.trackByExp){var s=/\.(.+)/.exec(a.parserResult.trackByExp);if(s.length>0&&t[s[1]]==n[s[1]])return r.unshift(e[l]),!0}if(angular.equals(t,n))return r.unshift(e[l]),!0}return!1}};if(!e)return r;for(var s=e.length-1;s>=0;s--)l(a.selected,e[s])||l(n,e[s])||r.unshift(e[s]);return r}),i.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);a.selected=[]}a.selected=u.$viewValue,i.$evalAsync()},i.$on("uis:select",function(e,t){a.selected.length>=a.limit||(a.selected.push(t),p.updateModel())}),i.$on("uis:activate",function(){p.activeMatchIndex=-1}),i.$watch("$select.disabled",function(e,t){t&&!e&&a.sizeSearchInput()}),a.searchInput.on("keydown",function(t){var n=t.which;i.$apply(function(){var t=!1;e.isHorizontalMovement(n)&&(t=o(n)),t&&n!=e.TAB})}),a.searchInput.on("blur",function(){n(function(){p.activeMatchIndex=-1})})}}}]),n.directive("uiSelectSingle",["$timeout","$compile",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(i,c,r,l){var s=l[0],o=l[1];o.$parsers.unshift(function(e){var t,n={};return n[s.parserResult.itemName]=e,t=s.parserResult.modelMapper(i,n)}),o.$formatters.unshift(function(e){var t,n=s.parserResult.source(i,{$select:{search:""}}),c={};if(n){var r=function(n){return c[s.parserResult.itemName]=n,t=s.parserResult.modelMapper(i,c),t==e};if(s.selected&&r(s.selected))return s.selected;for(var l=n.length-1;l>=0;l--)if(r(n[l]))return n[l]}return e}),i.$watch("$select.selected",function(e){o.$viewValue!==e&&o.$setViewValue(e)}),o.$render=function(){s.selected=o.$viewValue},i.$on("uis:select",function(e,t){s.selected=t}),i.$on("uis:close",function(e,n){t(function(){s.focusser.prop("disabled",!1),n||s.focusser[0].focus()},0,!1)}),i.$on("uis:activate",function(){a.prop("disabled",!0)});var a=angular.element("");n(a)(i),s.focusser=a,s.focusInput=a,c.parent().append(a),a.bind("focus",function(){i.$evalAsync(function(){s.focus=!0})}),a.bind("blur",function(){i.$evalAsync(function(){s.focus=!1})}),a.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),s.select(void 0),i.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),s.activate()),i.$digest()),void 0)}),a.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(s.activate(a.val()),a.val(""),i.$digest())})}}}]),n.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var i=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!i)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:i[2],source:t(i[3]),trackByExp:i[4],modelMapper:t(i[1]||i[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,i){var c=e+" in "+(i?"$group.items":t);return n&&(c+=" track by "+n),c}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("selectize/choices.tpl.html",'
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/dist/select.sort.js b/dist/select.sort.js new file mode 100644 index 000000000..f0097c436 --- /dev/null +++ b/dist/select.sort.js @@ -0,0 +1,153 @@ +/*! + * ui-select + * http://github.com/angular-ui/ui-select + * Version: 0.12.1 - 2015-08-06T11:06:02.049Z + * License: MIT + */ + + +(function () { +"use strict"; +// Make multiple matches sortable +angular.module('ui.select.sort', ['ui.select']) + .directive('uiSelectSort', + ['$timeout', 'uiSelectConfig', 'uiSelectMinErr', function ($timeout, uiSelectConfig, uiSelectMinErr) { + return { + require: '^uiSelect', + link: function (scope, element, attrs, $select) { + if (scope[attrs.uiSelectSort] === null) { + throw uiSelectMinErr('sort', "Expected a list to sort"); + } + + var options = angular.extend({ + axis: 'horizontal' + }, + scope.$eval(attrs.uiSelectSortOptions)); + + var axis = options.axis, + draggingClassName = 'dragging', + droppingClassName = 'dropping', + droppingBeforeClassName = 'dropping-before', + droppingAfterClassName = 'dropping-after'; + + scope.$watch(function () { + return $select.sortable; + }, function (n) { + if (n) { + element.attr('draggable', true); + } else { + element.removeAttr('draggable'); + } + }); + + element.on('dragstart', function (e) { + element.addClass(draggingClassName); + + (e.dataTransfer || e.originalEvent.dataTransfer).setData('text/plain', scope.$index); + }); + + element.on('dragend', function () { + element.removeClass(draggingClassName); + }); + + var move = function (from, to) { + /*jshint validthis: true */ + this.splice(to, 0, this.splice(from, 1)[0]); + }; + + var dragOverHandler = function (e) { + e.preventDefault(); + + var offset = axis === 'vertical' ? + e.offsetY || e.layerY || (e.originalEvent ? e.originalEvent.offsetY : 0) : + e.offsetX || e.layerX || (e.originalEvent ? e.originalEvent.offsetX : 0); + + if (offset < (this[axis === 'vertical' ? 'offsetHeight' : 'offsetWidth'] / 2)) { + element.removeClass(droppingAfterClassName); + element.addClass(droppingBeforeClassName); + + } else { + element.removeClass(droppingBeforeClassName); + element.addClass(droppingAfterClassName); + } + }; + + var dropTimeout; + + var dropHandler = function (e) { + e.preventDefault(); + + var droppedItemIndex = parseInt((e.dataTransfer || + e.originalEvent.dataTransfer).getData('text/plain'), 10); + + // prevent event firing multiple times in firefox + $timeout.cancel(dropTimeout); + dropTimeout = $timeout(function () { + _dropHandler(droppedItemIndex); + }, 20); + }; + + var _dropHandler = function (droppedItemIndex) { + var theList = scope.$eval(attrs.uiSelectSort), + itemToMove = theList[droppedItemIndex], + newIndex = null; + + if (element.hasClass(droppingBeforeClassName)) { + if (droppedItemIndex < scope.$index) { + newIndex = scope.$index - 1; + } else { + newIndex = scope.$index; + } + } else { + if (droppedItemIndex < scope.$index) { + newIndex = scope.$index; + } else { + newIndex = scope.$index + 1; + } + } + + move.apply(theList, [droppedItemIndex, newIndex]); + + scope.$apply(function () { + scope.$emit('uiSelectSort:change', { + array: theList, + item: itemToMove, + from: droppedItemIndex, + to: newIndex + }); + }); + + element.removeClass(droppingClassName); + element.removeClass(droppingBeforeClassName); + element.removeClass(droppingAfterClassName); + + element.off('drop', dropHandler); + }; + + element.on('dragenter', function () { + if (element.hasClass(draggingClassName)) { + return; + } + + element.addClass(droppingClassName); + + element.on('dragover', dragOverHandler); + element.on('drop', dropHandler); + }); + + element.on('dragleave', function (e) { + if (e.target != element) { + return; + } + element.removeClass(droppingClassName); + element.removeClass(droppingBeforeClassName); + element.removeClass(droppingAfterClassName); + + element.off('dragover', dragOverHandler); + element.off('drop', dropHandler); + }); + } + }; + }]); + +}()); \ No newline at end of file diff --git a/dist/select.sort.min.js b/dist/select.sort.min.js new file mode 100644 index 000000000..5a1148a3c --- /dev/null +++ b/dist/select.sort.min.js @@ -0,0 +1,7 @@ +/*! + * ui-select + * http://github.com/angular-ui/ui-select + * Version: 0.12.1 - 2015-08-06T11:06:02.049Z + * License: MIT + */ +!function(){"use strict";angular.module("ui.select.sort",["ui.select"]).directive("uiSelectSort",["$timeout","uiSelectConfig","uiSelectMinErr",function(e,t,a){return{require:"^uiSelect",link:function(t,r,n,i){if(null===t[n.uiSelectSort])throw a("sort","Expected a list to sort");var o=angular.extend({axis:"horizontal"},t.$eval(n.uiSelectSortOptions)),s=o.axis,l="dragging",f="dropping",d="dropping-before",u="dropping-after";t.$watch(function(){return i.sortable},function(e){e?r.attr("draggable",!0):r.removeAttr("draggable")}),r.on("dragstart",function(e){r.addClass(l),(e.dataTransfer||e.originalEvent.dataTransfer).setData("text/plain",t.$index)}),r.on("dragend",function(){r.removeClass(l)});var c,v=function(e,t){this.splice(t,0,this.splice(e,1)[0])},g=function(e){e.preventDefault();var t="vertical"===s?e.offsetY||e.layerY||(e.originalEvent?e.originalEvent.offsetY:0):e.offsetX||e.layerX||(e.originalEvent?e.originalEvent.offsetX:0);t
    ui-select inside a Bootstrap form - +
    diff --git a/examples/newdemo.js b/examples/newdemo.js index c1d6e7c93..7cd42bdb4 100644 --- a/examples/newdemo.js +++ b/examples/newdemo.js @@ -1,6 +1,6 @@ 'use strict'; -var app = angular.module('demo', ['ngSanitize', 'ui.select']); +var app = angular.module('demo', ['ngSanitize', 'ui.select', 'ui.select.sort']); /** * AngularJS default filter with the following expression: diff --git a/src/addons/uiSelectSortDirective.js b/src/addons/uiSelectSortDirective.js index b01b21a9f..ec13136a6 100644 --- a/src/addons/uiSelectSortDirective.js +++ b/src/addons/uiSelectSortDirective.js @@ -1,136 +1,141 @@ // Make multiple matches sortable -uis.directive('uiSelectSort', ['$timeout', 'uiSelectConfig', 'uiSelectMinErr', function($timeout, uiSelectConfig, uiSelectMinErr) { - return { - require: '^uiSelect', - link: function(scope, element, attrs, $select) { - if (scope[attrs.uiSelectSort] === null) { - throw uiSelectMinErr('sort', "Expected a list to sort"); - } - - var options = angular.extend({ - axis: 'horizontal' - }, - scope.$eval(attrs.uiSelectSortOptions)); - - var axis = options.axis, - draggingClassName = 'dragging', - droppingClassName = 'dropping', - droppingBeforeClassName = 'dropping-before', - droppingAfterClassName = 'dropping-after'; - - scope.$watch(function(){ - return $select.sortable; - }, function(n){ - if (n) { - element.attr('draggable', true); - } else { - element.removeAttr('draggable'); - } - }); - - element.on('dragstart', function(e) { - element.addClass(draggingClassName); - - (e.dataTransfer || e.originalEvent.dataTransfer).setData('text/plain', scope.$index); - }); - - element.on('dragend', function() { - element.removeClass(draggingClassName); - }); - - var move = function(from, to) { - /*jshint validthis: true */ - this.splice(to, 0, this.splice(from, 1)[0]); - }; - - var dragOverHandler = function(e) { - e.preventDefault(); - - var offset = axis === 'vertical' ? e.offsetY || e.layerY || (e.originalEvent ? e.originalEvent.offsetY : 0) : e.offsetX || e.layerX || (e.originalEvent ? e.originalEvent.offsetX : 0); - - if (offset < (this[axis === 'vertical' ? 'offsetHeight' : 'offsetWidth'] / 2)) { - element.removeClass(droppingAfterClassName); - element.addClass(droppingBeforeClassName); - - } else { - element.removeClass(droppingBeforeClassName); - element.addClass(droppingAfterClassName); - } - }; - - var dropTimeout; - - var dropHandler = function(e) { - e.preventDefault(); - - var droppedItemIndex = parseInt((e.dataTransfer || e.originalEvent.dataTransfer).getData('text/plain'), 10); - - // prevent event firing multiple times in firefox - $timeout.cancel(dropTimeout); - dropTimeout = $timeout(function() { - _dropHandler(droppedItemIndex); - }, 20); - }; - - var _dropHandler = function(droppedItemIndex) { - var theList = scope.$eval(attrs.uiSelectSort), - itemToMove = theList[droppedItemIndex], - newIndex = null; - - if (element.hasClass(droppingBeforeClassName)) { - if (droppedItemIndex < scope.$index) { - newIndex = scope.$index - 1; - } else { - newIndex = scope.$index; - } - } else { - if (droppedItemIndex < scope.$index) { - newIndex = scope.$index; - } else { - newIndex = scope.$index + 1; - } - } - - move.apply(theList, [droppedItemIndex, newIndex]); - - scope.$apply(function() { - scope.$emit('uiSelectSort:change', { - array: theList, - item: itemToMove, - from: droppedItemIndex, - to: newIndex - }); - }); - - element.removeClass(droppingClassName); - element.removeClass(droppingBeforeClassName); - element.removeClass(droppingAfterClassName); - - element.off('drop', dropHandler); - }; - - element.on('dragenter', function() { - if (element.hasClass(draggingClassName)) { - return; - } - - element.addClass(droppingClassName); - - element.on('dragover', dragOverHandler); - element.on('drop', dropHandler); - }); - - element.on('dragleave', function(e) { - if (e.target != element) { - return; - } - element.removeClass(droppingClassName); - element.removeClass(droppingBeforeClassName); - element.removeClass(droppingAfterClassName); - - element.off('dragover', dragOverHandler); - element.off('drop', dropHandler); - }); - } - }; -}]); +angular.module('ui.select.sort', ['ui.select']) + .directive('uiSelectSort', + ['$timeout', 'uiSelectConfig', 'uiSelectMinErr', function ($timeout, uiSelectConfig, uiSelectMinErr) { + return { + require: '^uiSelect', + link: function (scope, element, attrs, $select) { + if (scope[attrs.uiSelectSort] === null) { + throw uiSelectMinErr('sort', "Expected a list to sort"); + } + + var options = angular.extend({ + axis: 'horizontal' + }, + scope.$eval(attrs.uiSelectSortOptions)); + + var axis = options.axis, + draggingClassName = 'dragging', + droppingClassName = 'dropping', + droppingBeforeClassName = 'dropping-before', + droppingAfterClassName = 'dropping-after'; + + scope.$watch(function () { + return $select.sortable; + }, function (n) { + if (n) { + element.attr('draggable', true); + } else { + element.removeAttr('draggable'); + } + }); + + element.on('dragstart', function (e) { + element.addClass(draggingClassName); + + (e.dataTransfer || e.originalEvent.dataTransfer).setData('text/plain', scope.$index); + }); + + element.on('dragend', function () { + element.removeClass(draggingClassName); + }); + + var move = function (from, to) { + /*jshint validthis: true */ + this.splice(to, 0, this.splice(from, 1)[0]); + }; + + var dragOverHandler = function (e) { + e.preventDefault(); + + var offset = axis === 'vertical' ? + e.offsetY || e.layerY || (e.originalEvent ? e.originalEvent.offsetY : 0) : + e.offsetX || e.layerX || (e.originalEvent ? e.originalEvent.offsetX : 0); + + if (offset < (this[axis === 'vertical' ? 'offsetHeight' : 'offsetWidth'] / 2)) { + element.removeClass(droppingAfterClassName); + element.addClass(droppingBeforeClassName); + + } else { + element.removeClass(droppingBeforeClassName); + element.addClass(droppingAfterClassName); + } + }; + + var dropTimeout; + + var dropHandler = function (e) { + e.preventDefault(); + + var droppedItemIndex = parseInt((e.dataTransfer || + e.originalEvent.dataTransfer).getData('text/plain'), 10); + + // prevent event firing multiple times in firefox + $timeout.cancel(dropTimeout); + dropTimeout = $timeout(function () { + _dropHandler(droppedItemIndex); + }, 20); + }; + + var _dropHandler = function (droppedItemIndex) { + var theList = scope.$eval(attrs.uiSelectSort), + itemToMove = theList[droppedItemIndex], + newIndex = null; + + if (element.hasClass(droppingBeforeClassName)) { + if (droppedItemIndex < scope.$index) { + newIndex = scope.$index - 1; + } else { + newIndex = scope.$index; + } + } else { + if (droppedItemIndex < scope.$index) { + newIndex = scope.$index; + } else { + newIndex = scope.$index + 1; + } + } + + move.apply(theList, [droppedItemIndex, newIndex]); + + scope.$apply(function () { + scope.$emit('uiSelectSort:change', { + array: theList, + item: itemToMove, + from: droppedItemIndex, + to: newIndex + }); + }); + + element.removeClass(droppingClassName); + element.removeClass(droppingBeforeClassName); + element.removeClass(droppingAfterClassName); + + element.off('drop', dropHandler); + }; + + element.on('dragenter', function () { + if (element.hasClass(draggingClassName)) { + return; + } + + element.addClass(droppingClassName); + + element.on('dragover', dragOverHandler); + element.on('drop', dropHandler); + }); + + element.on('dragleave', function (e) { + if (e.target != element) { + return; + } + element.removeClass(droppingClassName); + element.removeClass(droppingBeforeClassName); + element.removeClass(droppingAfterClassName); + + element.off('dragover', dragOverHandler); + element.off('drop', dropHandler); + }); + } + }; + }]); diff --git a/src/uiSelectController.js b/src/uiSelectController.js index 2782b74b6..13b810b32 100644 --- a/src/uiSelectController.js +++ b/src/uiSelectController.js @@ -244,7 +244,6 @@ uis.controller('uiSelectCtrl', * @return {boolean} true if the item is disabled */ ctrl.isDisabled = function (itemScope) { - if (!ctrl.open) { return false; } @@ -262,9 +261,10 @@ uis.controller('uiSelectCtrl', return isDisabled; }; - /** - * Selects an item + * Selects an item. Calls the onBeforeSelect and onSelect callbacks + * onBeforeSelect is called to allow the user to alter or abort the selection + * onSelect is called to notify the user of the selection * * Called when the user selects an item with ENTER or clicks the dropdown */ @@ -304,6 +304,12 @@ uis.controller('uiSelectCtrl', } }; + // If there's no onBeforeSelect callback, then just call the completeCallback + if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { + completeCallback(item); + return; + } + // Call the onBeforeSelect callback // Allowable responses are -: // falsy: Abort the selection @@ -314,11 +320,15 @@ uis.controller('uiSelectCtrl', if (angular.isDefined(result)) { if (angular.isFunction(result.then)) { // Promise returned - wait for it to complete before completing the selection - result.then(function (result) { - if (!result) { + result.then(function (response) { + if (!response) { return; } - completeCallback(result); + if (response === true) { + completeCallback(item); + } else if (response) { + completeCallback(response); + } }); } else if (result === true) { completeCallback(item); diff --git a/src/uiSelectDirective.js b/src/uiSelectDirective.js index 115d5909a..6c0b5487d 100644 --- a/src/uiSelectDirective.js +++ b/src/uiSelectDirective.js @@ -1,6 +1,6 @@ uis.directive('uiSelect', - ['$document', 'uiSelectConfig', 'uiSelectMinErr', 'uisOffset', '$compile', '$parse', '$timeout', - function ($document, uiSelectConfig, uiSelectMinErr, uisOffset, $compile, $parse, $timeout) { + ['$document', '$window', 'uiSelectConfig', 'uiSelectMinErr', 'uisOffset', '$compile', '$parse', '$timeout', + function ($document, $window, uiSelectConfig, uiSelectMinErr, uisOffset, $compile, $parse, $timeout) { return { restrict: 'EA', @@ -247,9 +247,7 @@ uis.directive('uiSelect', var offsetDropdown = uisOffset(dropdown); // Determine if the direction of the dropdown needs to be changed. - if (offset.top + offset.height + offsetDropdown.height > - $document[0].documentElement.scrollTop + - $document[0].documentElement.clientHeight) { + if (offset.top + offset.height + offsetDropdown.height > $window.pageYOffset + $document[0].documentElement.clientHeight) { element.addClass(directionUpClassName); } diff --git a/src/uiSelectMultipleDirective.js b/src/uiSelectMultipleDirective.js index f2c7cce37..cb480e71a 100644 --- a/src/uiSelectMultipleDirective.js +++ b/src/uiSelectMultipleDirective.js @@ -27,7 +27,11 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel $select.sizeSearchInput(); }; - // Remove item from multiple select + /** + * Remove item from multiple select + * Calls onBeforeRemove to allow the user to prevent the removal of the item + * Then calls onRemove to notify the user the item has been removed + */ ctrl.removeChoice = function (index) { var removedChoice = $select.selected[index]; @@ -43,11 +47,6 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel ctrl.activeMatchIndex = -1; $select.sizeSearchInput(); - // If there's no onBeforeRemove callback, then we're done - if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { - return; - } - var callbackContext = { $item: removedChoice, $model: $select.parserResult.modelMapper($scope, locals) @@ -62,6 +61,12 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel ctrl.updateModel(); } + // If there's no onBeforeRemove callback, then just call the completeCallback + if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { + completeCallback(); + return; + } + // Call the onBeforeRemove callback // Allowable responses are -: // falsy: Abort the removal diff --git a/test/select.spec.js b/test/select.spec.js index 6cf932d21..91e806606 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -1,687 +1,711 @@ 'use strict'; -describe('ui-select tests', function() { - var scope, $rootScope, $compile, $timeout, $injector; - - var Key = { - Enter: 13, - Tab: 9, - Up: 38, - Down: 40, - Left: 37, - Right: 39, - Backspace: 8, - Delete: 46, - Escape: 27 - }; - - //create a directive that wraps ui-select - angular.module('wrapperDirective',['ui.select']); - angular.module('wrapperDirective').directive('wrapperUiSelect', function(){ - return { - restrict: 'EA', - template: ' \ +describe('ui-select tests', function () { + var scope, $rootScope, $compile, $timeout, $injector; + + var Key = { + Enter: 13, + Tab: 9, + Up: 38, + Down: 40, + Left: 37, + Right: 39, + Backspace: 8, + Delete: 46, + Escape: 27 + }; + + //create a directive that wraps ui-select + angular.module('wrapperDirective', ['ui.select']); + angular.module('wrapperDirective').directive('wrapperUiSelect', function () { + return { + restrict: 'EA', + template: ' \ {{$select.selected.name}} \ \
    \
    \
    ', - require: 'ngModel', - scope: true, + require: 'ngModel', + scope: true, - link: function (scope, element, attrs, ctrl) { + link: function (scope, element, attrs, ctrl) { - } - }; + } + }; - }); + }); - beforeEach(module('ngSanitize', 'ui.select', 'wrapperDirective')); + beforeEach(module('ngSanitize', 'ui.select', 'wrapperDirective')); - beforeEach(function() { - module(function($provide) { - $provide.factory('uisOffset', function() { - return function(el) { - return {top: 100, left: 200, width: 300, height: 400}; - }; - }); + beforeEach(function () { + module(function ($provide) { + $provide.factory('uisOffset', function () { + return function (el) { + return {top: 100, left: 200, width: 300, height: 400}; + }; + }); + }); }); - }); - - beforeEach(inject(function(_$rootScope_, _$compile_, _$timeout_, _$injector_) { - $rootScope = _$rootScope_; - scope = $rootScope.$new(); - $compile = _$compile_; - $timeout = _$timeout_; - $injector = _$injector_; - scope.selection = {}; - - scope.getGroupLabel = function(person) { - return person.age % 2 ? 'even' : 'odd'; - }; - scope.filterInvertOrder = function(groups) { - return groups.sort(function(groupA, groupB){ - return groupA.name.toLocaleLowerCase() < groupB.name.toLocaleLowerCase(); - }); - }; + beforeEach(inject(function (_$rootScope_, _$compile_, _$timeout_, _$injector_) { + $rootScope = _$rootScope_; + scope = $rootScope.$new(); + $compile = _$compile_; + $timeout = _$timeout_; + $injector = _$injector_; + scope.selection = {}; + + scope.getGroupLabel = function (person) { + return person.age % 2 ? 'even' : 'odd'; + }; + + scope.filterInvertOrder = function (groups) { + return groups.sort(function (groupA, groupB) { + return groupA.name.toLocaleLowerCase() < groupB.name.toLocaleLowerCase(); + }); + }; + + + scope.people = [ + {name: 'Adam', email: 'adam@email.com', group: 'Foo', age: 12}, + {name: 'Amalie', email: 'amalie@email.com', group: 'Foo', age: 12}, + {name: 'Estefanía', email: 'estefanía@email.com', group: 'Foo', age: 21}, + {name: 'Adrian', email: 'adrian@email.com', group: 'Foo', age: 21}, + {name: 'Wladimir', email: 'wladimir@email.com', group: 'Foo', age: 30}, + {name: 'Samantha', email: 'samantha@email.com', group: 'bar', age: 30}, + {name: 'Nicole', email: 'nicole@email.com', group: 'bar', age: 43}, + {name: 'Natasha', email: 'natasha@email.com', group: 'Baz', age: 54} + ]; + + scope.someObject = {}; + scope.someObject.people = [ + {name: 'Adam', email: 'adam@email.com', group: 'Foo', age: 12}, + {name: 'Amalie', email: 'amalie@email.com', group: 'Foo', age: 12}, + {name: 'Estefanía', email: 'estefanía@email.com', group: 'Foo', age: 21}, + {name: 'Adrian', email: 'adrian@email.com', group: 'Foo', age: 21}, + {name: 'Wladimir', email: 'wladimir@email.com', group: 'Foo', age: 30}, + {name: 'Samantha', email: 'samantha@email.com', group: 'bar', age: 30}, + {name: 'Nicole', email: 'nicole@email.com', group: 'bar', age: 43}, + {name: 'Natasha', email: 'natasha@email.com', group: 'Baz', age: 54} + ]; + })); - scope.people = [ - { name: 'Adam', email: 'adam@email.com', group: 'Foo', age: 12 }, - { name: 'Amalie', email: 'amalie@email.com', group: 'Foo', age: 12 }, - { name: 'Estefanía', email: 'estefanía@email.com', group: 'Foo', age: 21 }, - { name: 'Adrian', email: 'adrian@email.com', group: 'Foo', age: 21 }, - { name: 'Wladimir', email: 'wladimir@email.com', group: 'Foo', age: 30 }, - { name: 'Samantha', email: 'samantha@email.com', group: 'bar', age: 30 }, - { name: 'Nicole', email: 'nicole@email.com', group: 'bar', age: 43 }, - { name: 'Natasha', email: 'natasha@email.com', group: 'Baz', age: 54 } - ]; - - scope.someObject = {}; - scope.someObject.people = [ - { name: 'Adam', email: 'adam@email.com', group: 'Foo', age: 12 }, - { name: 'Amalie', email: 'amalie@email.com', group: 'Foo', age: 12 }, - { name: 'Estefanía', email: 'estefanía@email.com', group: 'Foo', age: 21 }, - { name: 'Adrian', email: 'adrian@email.com', group: 'Foo', age: 21 }, - { name: 'Wladimir', email: 'wladimir@email.com', group: 'Foo', age: 30 }, - { name: 'Samantha', email: 'samantha@email.com', group: 'bar', age: 30 }, - { name: 'Nicole', email: 'nicole@email.com', group: 'bar', age: 43 }, - { name: 'Natasha', email: 'natasha@email.com', group: 'Baz', age: 54 } - ]; - })); - - - // DSL (domain-specific language) - - function compileTemplate(template) { - var el = $compile(angular.element(template))(scope); - scope.$digest(); - return el; - } - - function createUiSelect(attrs) { - var attrsHtml = '', - matchAttrsHtml = ''; - if (attrs !== undefined) { - if (attrs.disabled !== undefined) { attrsHtml += ' ng-disabled="' + attrs.disabled + '"'; } - if (attrs.required !== undefined) { attrsHtml += ' ng-required="' + attrs.required + '"'; } - if (attrs.theme !== undefined) { attrsHtml += ' theme="' + attrs.theme + '"'; } - if (attrs.tabindex !== undefined) { attrsHtml += ' tabindex="' + attrs.tabindex + '"'; } - if (attrs.tagging !== undefined) { attrsHtml += ' tagging="' + attrs.tagging + '"'; } - if (attrs.taggingTokens !== undefined) { attrsHtml += ' tagging-tokens="' + attrs.taggingTokens + '"'; } - if (attrs.title !== undefined) { attrsHtml += ' title="' + attrs.title + '"'; } - if (attrs.appendToBody !== undefined) { attrsHtml += ' append-to-body="' + attrs.appendToBody + '"'; } - if (attrs.allowClear !== undefined) { matchAttrsHtml += ' allow-clear="' + attrs.allowClear + '"';} + // DSL (domain-specific language) + + function compileTemplate(template) { + var el = $compile(angular.element(template))(scope); + scope.$digest(); + return el; } - return compileTemplate( - ' \ + function createUiSelect(attrs) { + var attrsHtml = '', + matchAttrsHtml = ''; + if (attrs !== undefined) { + if (attrs.disabled !== undefined) { + attrsHtml += ' ng-disabled="' + attrs.disabled + '"'; + } + if (attrs.required !== undefined) { + attrsHtml += ' ng-required="' + attrs.required + '"'; + } + if (attrs.theme !== undefined) { + attrsHtml += ' theme="' + attrs.theme + '"'; + } + if (attrs.tabindex !== undefined) { + attrsHtml += ' tabindex="' + attrs.tabindex + '"'; + } + if (attrs.tagging !== undefined) { + attrsHtml += ' tagging="' + attrs.tagging + '"'; + } + if (attrs.taggingTokens !== undefined) { + attrsHtml += ' tagging-tokens="' + attrs.taggingTokens + '"'; + } + if (attrs.title !== undefined) { + attrsHtml += ' title="' + attrs.title + '"'; + } + if (attrs.appendToBody !== undefined) { + attrsHtml += ' append-to-body="' + attrs.appendToBody + '"'; + } + if (attrs.allowClear !== undefined) { + matchAttrsHtml += ' allow-clear="' + attrs.allowClear + '"'; + } + } + + return compileTemplate( + ' \ {{$select.selected.name}} \ \
    \
    \
    \
    ' - ); - } + ); + } - function getMatchLabel(el) { - return $(el).find('.ui-select-match > span:first > span[ng-transclude]:not(.ng-hide)').text(); - } + function getMatchLabel(el) { + return $(el).find('.ui-select-match > span:first > span[ng-transclude]:not(.ng-hide)').text(); + } + + function clickItem(el, text) { + + if (!isDropdownOpened(el)) { + openDropdown(el); + } - function clickItem(el, text) { + $(el).find('.ui-select-choices-row div:contains("' + text + '")').click(); + scope.$digest(); + } + + function clickMatch(el) { + $(el).find('.ui-select-match > span:first').click(); + scope.$digest(); + } + + function isDropdownOpened(el) { + // Does not work with jQuery 2.*, have to use jQuery 1.11.* + // This will be fixed in AngularJS 1.3 + // See issue with unit-testing directive using karma https://github.com/angular/angular.js/issues/4640#issuecomment-35002427 + return el.scope().$select.open && el.hasClass('open'); + } - if (!isDropdownOpened(el)){ - openDropdown(el); + function triggerKeydown(element, keyCode) { + var e = jQuery.Event("keydown"); + e.which = keyCode; + e.keyCode = keyCode; + element.trigger(e); } - $(el).find('.ui-select-choices-row div:contains("' + text + '")').click(); - scope.$digest(); - } - - function clickMatch(el) { - $(el).find('.ui-select-match > span:first').click(); - scope.$digest(); - } - - function isDropdownOpened(el) { - // Does not work with jQuery 2.*, have to use jQuery 1.11.* - // This will be fixed in AngularJS 1.3 - // See issue with unit-testing directive using karma https://github.com/angular/angular.js/issues/4640#issuecomment-35002427 - return el.scope().$select.open && el.hasClass('open'); - } - - function triggerKeydown(element, keyCode) { - var e = jQuery.Event("keydown"); - e.which = keyCode; - e.keyCode = keyCode; - element.trigger(e); - } - function triggerPaste(element, text) { - var e = jQuery.Event("paste"); - e.originalEvent = { - clipboardData : { - getData : function() { - return text; + function triggerPaste(element, text) { + var e = jQuery.Event("paste"); + e.originalEvent = { + clipboardData: { + getData: function () { + return text; + } } - } - }; - element.trigger(e); - } + }; + element.trigger(e); + } - function setSearchText(el, text) { - el.scope().$select.search = text; - scope.$digest(); - $timeout.flush(); - } + function setSearchText(el, text) { + el.scope().$select.search = text; + scope.$digest(); + $timeout.flush(); + } - function openDropdown(el) { - var $select = el.scope().$select; - $select.open = true; - scope.$digest(); - } + function openDropdown(el) { + var $select = el.scope().$select; + $select.open = true; + scope.$digest(); + } - function closeDropdown(el) { - var $select = el.scope().$select; - $select.open = false; - scope.$digest(); - } + function closeDropdown(el) { + var $select = el.scope().$select; + $select.open = false; + scope.$digest(); + } - // Tests + // Tests - it('should compile child directives', function() { - var el = createUiSelect(); + it('should compile child directives', function () { + var el = createUiSelect(); - var searchEl = $(el).find('.ui-select-search'); - expect(searchEl.length).toEqual(1); + var searchEl = $(el).find('.ui-select-search'); + expect(searchEl.length).toEqual(1); - var matchEl = $(el).find('.ui-select-match'); - expect(matchEl.length).toEqual(1); + var matchEl = $(el).find('.ui-select-match'); + expect(matchEl.length).toEqual(1); - var choicesContentEl = $(el).find('.ui-select-choices-content'); - expect(choicesContentEl.length).toEqual(1); + var choicesContentEl = $(el).find('.ui-select-choices-content'); + expect(choicesContentEl.length).toEqual(1); - var choicesContainerEl = $(el).find('.ui-select-choices'); - expect(choicesContainerEl.length).toEqual(1); + var choicesContainerEl = $(el).find('.ui-select-choices'); + expect(choicesContainerEl.length).toEqual(1); - openDropdown(el); - var choicesEls = $(el).find('.ui-select-choices-row'); - expect(choicesEls.length).toEqual(8); - }); + openDropdown(el); + var choicesEls = $(el).find('.ui-select-choices-row'); + expect(choicesEls.length).toEqual(8); + }); - it('should correctly render initial state', function() { - scope.selection.selected = scope.people[0]; + it('should correctly render initial state', function () { + scope.selection.selected = scope.people[0]; - var el = createUiSelect(); + var el = createUiSelect(); - expect(getMatchLabel(el)).toEqual('Adam'); - }); - - it('should correctly render initial state with track by feature', function() { - var el = compileTemplate( - ' \ - {{$select.selected.name}} \ - \ -
    \ -
    \ -
    \ -
    ' - ); - scope.selection.selected = { name: 'Samantha', email: 'something different than array source', group: 'bar', age: 30 }; - scope.$digest(); - expect(getMatchLabel(el)).toEqual('Samantha'); - }); + expect(getMatchLabel(el)).toEqual('Adam'); + }); - it('should utilize wrapper directive ng-model', function() { - var el = compileTemplate(''); - scope.selection.selected = { name: 'Samantha', email: 'something different than array source', group: 'bar', age: 30 }; - scope.$digest(); - expect($(el).find('.ui-select-container > .ui-select-match > span:first > span[ng-transclude]:not(.ng-hide)').text()).toEqual('Samantha'); - }); + it('should correctly render initial state with track by feature', function () { + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
    \ +
    \ +
    \ +
    ' + ); + scope.selection.selected = + {name: 'Samantha', email: 'something different than array source', group: 'bar', age: 30}; + scope.$digest(); + expect(getMatchLabel(el)).toEqual('Samantha'); + }); - it('should display the choices when activated', function() { - var el = createUiSelect(); + it('should utilize wrapper directive ng-model', function () { + var el = compileTemplate(''); + scope.selection.selected = + {name: 'Samantha', email: 'something different than array source', group: 'bar', age: 30}; + scope.$digest(); + expect($(el).find('.ui-select-container > .ui-select-match > span:first > span[ng-transclude]:not(.ng-hide)').text()).toEqual('Samantha'); + }); - expect(isDropdownOpened(el)).toEqual(false); + it('should display the choices when activated', function () { + var el = createUiSelect(); - clickMatch(el); + expect(isDropdownOpened(el)).toEqual(false); - expect(isDropdownOpened(el)).toEqual(true); - }); + clickMatch(el); - it('should select an item', function() { - var el = createUiSelect(); + expect(isDropdownOpened(el)).toEqual(true); + }); - clickItem(el, 'Samantha'); + it('should select an item', function () { + var el = createUiSelect(); - expect(getMatchLabel(el)).toEqual('Samantha'); - }); + clickItem(el, 'Samantha'); - it('should select an item (controller)', function() { - var el = createUiSelect(); + expect(getMatchLabel(el)).toEqual('Samantha'); + }); - el.scope().$select.select(scope.people[1]); - scope.$digest(); + it('should select an item (controller)', function () { + var el = createUiSelect(); - expect(getMatchLabel(el)).toEqual('Amalie'); - }); + el.scope().$select.select(scope.people[1]); + scope.$digest(); - it('should not select a non existing item', function() { - var el = createUiSelect(); + expect(getMatchLabel(el)).toEqual('Amalie'); + }); - clickItem(el, "I don't exist"); + it('should not select a non existing item', function () { + var el = createUiSelect(); - expect(getMatchLabel(el)).toEqual(''); - }); + clickItem(el, "I don't exist"); - it('should close the choices when an item is selected', function() { - var el = createUiSelect(); + expect(getMatchLabel(el)).toEqual(''); + }); - clickMatch(el); + it('should close the choices when an item is selected', function () { + var el = createUiSelect(); - expect(isDropdownOpened(el)).toEqual(true); + clickMatch(el); - clickItem(el, 'Samantha'); + expect(isDropdownOpened(el)).toEqual(true); - expect(isDropdownOpened(el)).toEqual(false); - }); + clickItem(el, 'Samantha'); + expect(isDropdownOpened(el)).toEqual(false); + }); - it('should open/close dropdown when clicking caret icon', function() { - var el = createUiSelect({theme : 'select2'}); - var searchInput = el.find('.ui-select-search'); - var $select = el.scope().$select; + it('should open/close dropdown when clicking caret icon', function () { - expect($select.open).toEqual(false); + var el = createUiSelect({theme: 'select2'}); + var searchInput = el.find('.ui-select-search'); + var $select = el.scope().$select; - el.find(".ui-select-toggle").click(); - expect($select.open).toEqual(true); + expect($select.open).toEqual(false); + el.find(".ui-select-toggle").click(); + expect($select.open).toEqual(true); - el.find(".ui-select-toggle").click(); - expect($select.open).toEqual(false); - }); - it('should clear selection', function() { - scope.selection.selected = scope.people[0]; + el.find(".ui-select-toggle").click(); + expect($select.open).toEqual(false); + }); - var el = createUiSelect({theme : 'select2', allowClear: 'true'}); - var $select = el.scope().$select; + it('should clear selection', function () { + scope.selection.selected = scope.people[0]; - // allowClear should be true. - expect($select.allowClear).toEqual(true); + var el = createUiSelect({theme: 'select2', allowClear: 'true'}); + var $select = el.scope().$select; - // Trigger clear. - el.find('.select2-search-choice-close').click(); - expect(scope.selection.selected).toEqual(undefined); + // allowClear should be true. + expect($select.allowClear).toEqual(true); - // If there is no selection it the X icon should be gone. - expect(el.find('.select2-search-choice-close').length).toEqual(0); + // Trigger clear. + el.find('.select2-search-choice-close').click(); + expect(scope.selection.selected).toEqual(undefined); - }); + // If there is no selection it the X icon should be gone. + expect(el.find('.select2-search-choice-close').length).toEqual(0); - it('should toggle allow-clear directive', function() { - scope.selection.selected = scope.people[0]; - scope.isClearAllowed = false; - - var el = createUiSelect({theme : 'select2', allowClear: '{{isClearAllowed}}'}); - var $select = el.scope().$select; + }); - expect($select.allowClear).toEqual(false); - expect(el.find('.select2-search-choice-close').length).toEqual(0); - - // Turn clear on - scope.isClearAllowed = true; - scope.$digest(); + it('should toggle allow-clear directive', function () { + scope.selection.selected = scope.people[0]; + scope.isClearAllowed = false; - expect($select.allowClear).toEqual(true); - expect(el.find('.select2-search-choice-close').length).toEqual(1); - }); + var el = createUiSelect({theme: 'select2', allowClear: '{{isClearAllowed}}'}); + var $select = el.scope().$select; + expect($select.allowClear).toEqual(false); + expect(el.find('.select2-search-choice-close').length).toEqual(0); - it('should pass tabindex to focusser', function() { - var el = createUiSelect({tabindex: 5}); + // Turn clear on + scope.isClearAllowed = true; + scope.$digest(); - expect($(el).find('.ui-select-focusser').attr('tabindex')).toEqual('5'); - expect($(el).attr('tabindex')).toEqual(undefined); - }); + expect($select.allowClear).toEqual(true); + expect(el.find('.select2-search-choice-close').length).toEqual(1); + }); - it('should pass tabindex to focusser when tabindex is an expression', function() { - scope.tabValue = 22; - var el = createUiSelect({tabindex: '{{tabValue + 10}}'}); - expect($(el).find('.ui-select-focusser').attr('tabindex')).toEqual('32'); - expect($(el).attr('tabindex')).toEqual(undefined); - }); + it('should pass tabindex to focusser', function () { + var el = createUiSelect({tabindex: 5}); - it('should not give focusser a tabindex when ui-select does not have one', function() { - var el = createUiSelect(); + expect($(el).find('.ui-select-focusser').attr('tabindex')).toEqual('5'); + expect($(el).attr('tabindex')).toEqual(undefined); + }); - expect($(el).find('.ui-select-focusser').attr('tabindex')).toEqual(undefined); - expect($(el).attr('tabindex')).toEqual(undefined); - }); + it('should pass tabindex to focusser when tabindex is an expression', function () { + scope.tabValue = 22; + var el = createUiSelect({tabindex: '{{tabValue + 10}}'}); - it('should be disabled if the attribute says so', function() { - var el1 = createUiSelect({disabled: true}); - expect(el1.scope().$select.disabled).toEqual(true); - clickMatch(el1); - expect(isDropdownOpened(el1)).toEqual(false); + expect($(el).find('.ui-select-focusser').attr('tabindex')).toEqual('32'); + expect($(el).attr('tabindex')).toEqual(undefined); + }); - var el2 = createUiSelect({disabled: false}); - expect(el2.scope().$select.disabled).toEqual(false); - clickMatch(el2); - expect(isDropdownOpened(el2)).toEqual(true); + it('should not give focusser a tabindex when ui-select does not have one', function () { + var el = createUiSelect(); - var el3 = createUiSelect(); - expect(el3.scope().$select.disabled).toBeFalsy(); - clickMatch(el3); - expect(isDropdownOpened(el3)).toEqual(true); - }); + expect($(el).find('.ui-select-focusser').attr('tabindex')).toEqual(undefined); + expect($(el).attr('tabindex')).toEqual(undefined); + }); - // See when an item that evaluates to false (such as "false" or "no") is selected, the placeholder is shown https://github.com/angular-ui/ui-select/pull/32 - it('should not display the placeholder when item evaluates to false', function() { - scope.items = ['false']; + it('should be disabled if the attribute says so', function () { + var el1 = createUiSelect({disabled: true}); + expect(el1.scope().$select.disabled).toEqual(true); + clickMatch(el1); + expect(isDropdownOpened(el1)).toEqual(false); + + var el2 = createUiSelect({disabled: false}); + expect(el2.scope().$select.disabled).toEqual(false); + clickMatch(el2); + expect(isDropdownOpened(el2)).toEqual(true); + + var el3 = createUiSelect(); + expect(el3.scope().$select.disabled).toBeFalsy(); + clickMatch(el3); + expect(isDropdownOpened(el3)).toEqual(true); + }); - var el = compileTemplate( - ' \ - {{$select.selected}} \ - \ -
    \ -
    \ -
    ' - ); - expect(el.scope().$select.selected).toEqual(undefined); - - clickItem(el, 'false'); - - expect(el.scope().$select.selected).toEqual('false'); - expect(getMatchLabel(el)).toEqual('false'); - }); - - it('should close an opened select when another one is opened', function() { - var el1 = createUiSelect(); - var el2 = createUiSelect(); - el1.appendTo(document.body); - el2.appendTo(document.body); - - expect(isDropdownOpened(el1)).toEqual(false); - expect(isDropdownOpened(el2)).toEqual(false); - clickMatch(el1); - expect(isDropdownOpened(el1)).toEqual(true); - expect(isDropdownOpened(el2)).toEqual(false); - clickMatch(el2); - expect(isDropdownOpened(el1)).toEqual(false); - expect(isDropdownOpened(el2)).toEqual(true); - - el1.remove(); - el2.remove(); - }); - - describe('disabled options', function() { - function createUiSelect(attrs) { - var attrsDisabled = ''; - if (attrs !== undefined) { - if (attrs.disabled !== undefined) { - attrsDisabled = ' ui-disable-choice="' + attrs.disabled + '"'; - } else { - attrsDisabled = ''; - } - } + // See when an item that evaluates to false (such as "false" or "no") is selected, the placeholder is shown https://github.com/angular-ui/ui-select/pull/32 + it('should not display the placeholder when item evaluates to false', function () { + scope.items = ['false']; - return compileTemplate( - ' \ - {{$select.selected.name}} \ - \ + var el = compileTemplate( + ' \ + {{$select.selected}} \ + \ +
    \ +
    \ +
    ' + ); + expect(el.scope().$select.selected).toEqual(undefined); + + clickItem(el, 'false'); + + expect(el.scope().$select.selected).toEqual('false'); + expect(getMatchLabel(el)).toEqual('false'); + }); + + it('should close an opened select when another one is opened', function () { + var el1 = createUiSelect(); + var el2 = createUiSelect(); + el1.appendTo(document.body); + el2.appendTo(document.body); + + expect(isDropdownOpened(el1)).toEqual(false); + expect(isDropdownOpened(el2)).toEqual(false); + clickMatch(el1); + expect(isDropdownOpened(el1)).toEqual(true); + expect(isDropdownOpened(el2)).toEqual(false); + clickMatch(el2); + expect(isDropdownOpened(el1)).toEqual(false); + expect(isDropdownOpened(el2)).toEqual(true); + + el1.remove(); + el2.remove(); + }); + + describe('disabled options', function () { + function createUiSelect(attrs) { + var attrsDisabled = ''; + if (attrs !== undefined) { + if (attrs.disabled !== undefined) { + attrsDisabled = ' ui-disable-choice="' + attrs.disabled + '"'; + } else { + attrsDisabled = ''; + } + } + + return compileTemplate( + ' \ + {{$select.selected.name}} \ + \
    \
    \
    \
    ' - ); - } - - function disablePerson(opts) { - opts = opts || {}; - - var key = opts.key || 'people', - disableAttr = opts.disableAttr || 'disabled', - disableBool = opts.disableBool === undefined ? true : opts.disableBool, - matchAttr = opts.match || 'name', - matchVal = opts.matchVal || 'Wladimir'; - - scope['_' + key] = angular.copy(scope[key]); - scope[key].map(function (model) { - if (model[matchAttr] == matchVal) { - model[disableAttr] = disableBool; + ); } - return model; - }); - } - function resetScope(opts) { - opts = opts || {}; - var key = opts.key || 'people'; - scope[key] = angular.copy(scope['_' + key]); - } + function disablePerson(opts) { + opts = opts || {}; + + var key = opts.key || 'people', + disableAttr = opts.disableAttr || 'disabled', + disableBool = opts.disableBool === undefined ? true : opts.disableBool, + matchAttr = opts.match || 'name', + matchVal = opts.matchVal || 'Wladimir'; + + scope['_' + key] = angular.copy(scope[key]); + scope[key].map(function (model) { + if (model[matchAttr] == matchVal) { + model[disableAttr] = disableBool; + } + return model; + }); + } - describe('without disabling expression', function () { - beforeEach(function() { - disablePerson(); - this.el = createUiSelect(); - }); + function resetScope(opts) { + opts = opts || {}; + var key = opts.key || 'people'; + scope[key] = angular.copy(scope['_' + key]); + } - it('should not allow disabled options to be selected', function() { - clickItem(this.el, 'Wladimir'); + describe('without disabling expression', function () { + beforeEach(function () { + disablePerson(); + this.el = createUiSelect(); + }); - expect(getMatchLabel(this.el)).toEqual('Wladimir'); - }); + it('should not allow disabled options to be selected', function () { + clickItem(this.el, 'Wladimir'); - it('should set a disabled class on the option', function() { - var option = $(this.el).find('.ui-select-choices-row div:contains("Wladimir")'); - var container = option.closest('.ui-select-choices-row'); + expect(getMatchLabel(this.el)).toEqual('Wladimir'); + }); - expect(container.hasClass('disabled')).toBeFalsy(); - }); - }); + it('should set a disabled class on the option', function () { + var option = $(this.el).find('.ui-select-choices-row div:contains("Wladimir")'); + var container = option.closest('.ui-select-choices-row'); - describe('disable on truthy property', function () { - beforeEach(function() { - disablePerson({ - disableAttr : 'inactive', - disableBool : true + expect(container.hasClass('disabled')).toBeFalsy(); + }); }); - this.el = createUiSelect({ - disabled: 'person.inactive' - }); - }); - it('should allow the user to define the selected option', function () { - expect($(this.el).find('.ui-select-choices').attr('ui-disable-choice')).toBe('person.inactive'); - }); + describe('disable on truthy property', function () { + beforeEach(function () { + disablePerson({ + disableAttr: 'inactive', + disableBool: true + }); + this.el = createUiSelect({ + disabled: 'person.inactive' + }); + }); - it('should not allow disabled options to be selected', function() { - clickItem(this.el, 'Wladimir'); + it('should allow the user to define the selected option', function () { + expect($(this.el).find('.ui-select-choices').attr('ui-disable-choice')).toBe('person.inactive'); + }); - expect(getMatchLabel(this.el)).not.toEqual('Wladimir'); - }); + it('should not allow disabled options to be selected', function () { + clickItem(this.el, 'Wladimir'); - it('should set a disabled class on the option', function() { + expect(getMatchLabel(this.el)).not.toEqual('Wladimir'); + }); - openDropdown(this.el); + it('should set a disabled class on the option', function () { - var option = $(this.el).find('.ui-select-choices-row div:contains("Wladimir")'); - var container = option.closest('.ui-select-choices-row'); + openDropdown(this.el); - expect(container.hasClass('disabled')).toBeTruthy(); + var option = $(this.el).find('.ui-select-choices-row div:contains("Wladimir")'); + var container = option.closest('.ui-select-choices-row'); - }); - }); + expect(container.hasClass('disabled')).toBeTruthy(); - describe('disable on inverse property check', function () { - beforeEach(function() { - disablePerson({ - disableAttr : 'active', - disableBool : false - }); - this.el = createUiSelect({ - disabled: '!person.active' + }); }); - }); - it('should allow the user to define the selected option', function () { - expect($(this.el).find('.ui-select-choices').attr('ui-disable-choice')).toBe('!person.active'); - }); + describe('disable on inverse property check', function () { + beforeEach(function () { + disablePerson({ + disableAttr: 'active', + disableBool: false + }); + this.el = createUiSelect({ + disabled: '!person.active' + }); + }); - it('should not allow disabled options to be selected', function() { - clickItem(this.el, 'Wladimir'); + it('should allow the user to define the selected option', function () { + expect($(this.el).find('.ui-select-choices').attr('ui-disable-choice')).toBe('!person.active'); + }); - expect(getMatchLabel(this.el)).not.toEqual('Wladimir'); - }); + it('should not allow disabled options to be selected', function () { + clickItem(this.el, 'Wladimir'); - it('should set a disabled class on the option', function() { - openDropdown(this.el); + expect(getMatchLabel(this.el)).not.toEqual('Wladimir'); + }); - var option = $(this.el).find('.ui-select-choices-row div:contains("Wladimir")'); - var container = option.closest('.ui-select-choices-row'); + it('should set a disabled class on the option', function () { + openDropdown(this.el); - expect(container.hasClass('disabled')).toBeTruthy(); - }); - }); + var option = $(this.el).find('.ui-select-choices-row div:contains("Wladimir")'); + var container = option.closest('.ui-select-choices-row'); - describe('disable on expression', function () { - beforeEach(function() { - disablePerson({ - disableAttr : 'status', - disableBool : 'inactive' - }); - this.el = createUiSelect({ - disabled: "person.status == 'inactive'" + expect(container.hasClass('disabled')).toBeTruthy(); + }); }); - }); - it('should allow the user to define the selected option', function () { - expect($(this.el).find('.ui-select-choices').attr('ui-disable-choice')).toBe("person.status == 'inactive'"); - }); + describe('disable on expression', function () { + beforeEach(function () { + disablePerson({ + disableAttr: 'status', + disableBool: 'inactive' + }); + this.el = createUiSelect({ + disabled: "person.status == 'inactive'" + }); + }); - it('should not allow disabled options to be selected', function() { - clickItem(this.el, 'Wladimir'); + it('should allow the user to define the selected option', function () { + expect($(this.el).find('.ui-select-choices').attr('ui-disable-choice')).toBe("person.status == 'inactive'"); + }); - expect(getMatchLabel(this.el)).not.toEqual('Wladimir'); - }); + it('should not allow disabled options to be selected', function () { + clickItem(this.el, 'Wladimir'); - it('should set a disabled class on the option', function() { - openDropdown(this.el); + expect(getMatchLabel(this.el)).not.toEqual('Wladimir'); + }); - var option = $(this.el).find('.ui-select-choices-row div:contains("Wladimir")'); - var container = option.closest('.ui-select-choices-row'); + it('should set a disabled class on the option', function () { + openDropdown(this.el); - expect(container.hasClass('disabled')).toBeTruthy(); - }); - }); + var option = $(this.el).find('.ui-select-choices-row div:contains("Wladimir")'); + var container = option.closest('.ui-select-choices-row'); - afterEach(function() { - resetScope(); + expect(container.hasClass('disabled')).toBeTruthy(); + }); + }); + + afterEach(function () { + resetScope(); + }); }); - }); - describe('choices group', function() { - function getGroupLabel(item) { - return item.parent('.ui-select-choices-group').find('.ui-select-choices-group-label'); - } - function createUiSelect() { - return compileTemplate( - ' \ - {{$select.selected.name}} \ - \ -
    \ -
    \ -
    \ -
    ' - ); - } + describe('choices group', function () { + function getGroupLabel(item) { + return item.parent('.ui-select-choices-group').find('.ui-select-choices-group-label'); + } - it('should create items group', function() { - var el = createUiSelect(); - expect(el.find('.ui-select-choices-group').length).toBe(3); - }); + function createUiSelect() { + return compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
    \ +
    \ +
    \ +
    ' + ); + } - it('should show label before each group', function() { - var el = createUiSelect(); - expect(el.find('.ui-select-choices-group .ui-select-choices-group-label').map(function() { - return this.textContent; - }).toArray()).toEqual(['Foo', 'bar', 'Baz']); - }); + it('should create items group', function () { + var el = createUiSelect(); + expect(el.find('.ui-select-choices-group').length).toBe(3); + }); - it('should hide empty groups', function() { - var el = createUiSelect(); - el.scope().$select.search = 'd'; - scope.$digest(); + it('should show label before each group', function () { + var el = createUiSelect(); + expect(el.find('.ui-select-choices-group .ui-select-choices-group-label').map(function () { + return this.textContent; + }).toArray()).toEqual(['Foo', 'bar', 'Baz']); + }); - expect(el.find('.ui-select-choices-group .ui-select-choices-group-label').map(function() { - return this.textContent; - }).toArray()).toEqual(['Foo']); - }); + it('should hide empty groups', function () { + var el = createUiSelect(); + el.scope().$select.search = 'd'; + scope.$digest(); - it('should change activeItem through groups', function() { - var el = createUiSelect(); - el.scope().$select.search = 't'; - scope.$digest(); - openDropdown(el); - var choices = el.find('.ui-select-choices-row'); + expect(el.find('.ui-select-choices-group .ui-select-choices-group-label').map(function () { + return this.textContent; + }).toArray()).toEqual(['Foo']); + }); + + it('should change activeItem through groups', function () { + var el = createUiSelect(); + el.scope().$select.search = 't'; + scope.$digest(); + openDropdown(el); + var choices = el.find('.ui-select-choices-row'); - expect(choices.eq(0)).toHaveClass('active'); - expect(getGroupLabel(choices.eq(0)).text()).toBe('Foo'); + expect(choices.eq(0)).toHaveClass('active'); + expect(getGroupLabel(choices.eq(0)).text()).toBe('Foo'); - triggerKeydown(el.find('input'), 40 /*Down*/); - scope.$digest(); - expect(choices.eq(1)).toHaveClass('active'); - expect(getGroupLabel(choices.eq(1)).text()).toBe('bar'); + triggerKeydown(el.find('input'), 40 /*Down*/); + scope.$digest(); + expect(choices.eq(1)).toHaveClass('active'); + expect(getGroupLabel(choices.eq(1)).text()).toBe('bar'); + }); }); - }); - - describe('choices group by function', function() { - function createUiSelect() { - return compileTemplate( - ' \ - {{$select.selected.name}} \ - \ -
    \ -
    \ -
    ' - ); - } - it("should extract group value through function", function () { - var el = createUiSelect(); - expect(el.find('.ui-select-choices-group .ui-select-choices-group-label').map(function() { - return this.textContent; - }).toArray()).toEqual(['odd', 'even']); + + describe('choices group by function', function () { + function createUiSelect() { + return compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
    \ +
    \ +
    ' + ); + } + + it("should extract group value through function", function () { + var el = createUiSelect(); + expect(el.find('.ui-select-choices-group .ui-select-choices-group-label').map(function () { + return this.textContent; + }).toArray()).toEqual(['odd', 'even']); + }); }); - }); - describe('choices group filter function', function() { - function createUiSelect() { - return compileTemplate('\ + describe('choices group filter function', function () { + function createUiSelect() { + return compileTemplate('\ \ {{$select.selected.name}} \ \
    \
    \
    ' - ); - } - it("should sort groups using filter", function () { - var el = createUiSelect(); - expect(el.find('.ui-select-choices-group .ui-select-choices-group-label').map(function() { - return this.textContent; - }).toArray()).toEqual(["Foo", "Baz", "bar"]); + ); + } + + it("should sort groups using filter", function () { + var el = createUiSelect(); + expect(el.find('.ui-select-choices-group .ui-select-choices-group-label').map(function () { + return this.textContent; + }).toArray()).toEqual(["Foo", "Baz", "bar"]); + }); }); - }); - describe('choices group filter array', function() { - function createUiSelect() { - return compileTemplate('\ + describe('choices group filter array', function () { + function createUiSelect() { + return compileTemplate('\ \ {{$select.selected.name}} \
    \ \ ' - ); - } - it("should sort groups using filter", function () { - var el = createUiSelect(); - expect(el.find('.ui-select-choices-group .ui-select-choices-group-label').map(function() { - return this.textContent; - }).toArray()).toEqual(["Foo"]); + ); + } + + it("should sort groups using filter", function () { + var el = createUiSelect(); + expect(el.find('.ui-select-choices-group .ui-select-choices-group-label').map(function () { + return this.textContent; + }).toArray()).toEqual(["Foo"]); + }); }); - }); - it('should throw when no ui-select-choices found', function() { - expect(function() { - compileTemplate( - ' \ - \ - ' - ); - }).toThrow(new Error('[ui.select:transcluded] Expected 1 .ui-select-choices but got \'0\'.')); - }); - - it('should throw when no repeat attribute is provided to ui-select-choices', function() { - expect(function() { - compileTemplate( - ' \ - \ - ' - ); - }).toThrow(new Error('[ui.select:repeat] Expected \'repeat\' expression.')); - }); - - it('should throw when repeat attribute has incorrect format ', function() { - expect(function() { - compileTemplate( - ' \ - \ - \ - ' - ); - }).toThrow(new Error('[ui.select:iexp] Expected expression in form of \'_item_ in _collection_[ track by _id_]\' but got \'incorrect format people\'.')); - }); - - it('should throw when no ui-select-match found', function() { - expect(function() { - compileTemplate( - ' \ - \ - ' - ); - }).toThrow(new Error('[ui.select:transcluded] Expected 1 .ui-select-match but got \'0\'.')); - }); - - it('should format the model correctly using alias', function() { - var el = compileTemplate( - ' \ - {{$select.selected.name}} \ - \ -
    \ -
    \ -
    \ -
    ' - ); - clickItem(el, 'Samantha'); - expect(scope.selection.selected).toBe(scope.people[5]); - }); - - it('should parse the model correctly using alias', function() { - var el = compileTemplate( - ' \ - {{$select.selected.name}} \ - \ -
    \ -
    \ -
    \ -
    ' - ); - scope.selection.selected = scope.people[5]; - scope.$digest(); - expect(getMatchLabel(el)).toEqual('Samantha'); - }); - - it('should format the model correctly using property of alias', function() { - var el = compileTemplate( - ' \ - {{$select.selected.name}} \ - \ -
    \ -
    \ -
    \ -
    ' - ); - clickItem(el, 'Samantha'); - expect(scope.selection.selected).toBe('Samantha'); - }); - - it('should parse the model correctly using property of alias', function() { - var el = compileTemplate( - ' \ - {{$select.selected.name}} \ - \ -
    \ -
    \ -
    \ -
    ' - ); - scope.selection.selected = 'Samantha'; - scope.$digest(); - expect(getMatchLabel(el)).toEqual('Samantha'); - }); - - it('should parse the model correctly using property of alias with async choices data', function() { - var el = compileTemplate( - ' \ - {{$select.selected.name}} \ - \ -
    \ -
    \ -
    \ -
    ' - ); - $timeout(function() { - scope.peopleAsync = scope.people; + it('should throw when no ui-select-choices found', function () { + expect(function () { + compileTemplate( + ' \ + \ + ' + ); + }).toThrow(new Error('[ui.select:transcluded] Expected 1 .ui-select-choices but got \'0\'.')); }); - scope.selection.selected = 'Samantha'; - scope.$digest(); - expect(getMatchLabel(el)).toEqual(''); - - $timeout.flush(); //After choices populated (async), it should show match correctly - expect(getMatchLabel(el)).toEqual('Samantha'); + it('should throw when no repeat attribute is provided to ui-select-choices', function () { + expect(function () { + compileTemplate( + ' \ + \ + ' + ); + }).toThrow(new Error('[ui.select:repeat] Expected \'repeat\' expression.')); + }); - }); + it('should throw when repeat attribute has incorrect format ', function () { + expect(function () { + compileTemplate( + ' \ + \ + \ + ' + ); + }).toThrow(new Error('[ui.select:iexp] Expected expression in form of \'_item_ in _collection_[ track by _id_]\' but got \'incorrect format people\'.')); + }); - //TODO Is this really something we should expect? - it('should parse the model correctly using property of alias but passed whole object', function() { - var el = compileTemplate( - ' \ - {{$select.selected.name}} \ - \ -
    \ -
    \ -
    \ -
    ' - ); - scope.selection.selected = scope.people[5]; - scope.$digest(); - expect(getMatchLabel(el)).toEqual('Samantha'); - }); - - it('should format the model correctly without alias', function() { - var el = createUiSelect(); - clickItem(el, 'Samantha'); - expect(scope.selection.selected).toBe(scope.people[5]); - }); - - it('should parse the model correctly without alias', function() { - var el = createUiSelect(); - scope.selection.selected = scope.people[5]; - scope.$digest(); - expect(getMatchLabel(el)).toEqual('Samantha'); - }); - - it('should display choices correctly with child array', function() { - var el = compileTemplate( - ' \ - {{$select.selected.name}} \ - \ -
    \ -
    \ -
    \ -
    ' - ); - scope.selection.selected = scope.people[5]; - scope.$digest(); - expect(getMatchLabel(el)).toEqual('Samantha'); - }); - - it('should format the model correctly using property of alias and when using child array for choices', function() { - var el = compileTemplate( - ' \ - {{$select.selected.name}} \ - \ -
    \ -
    \ -
    \ -
    ' - ); - clickItem(el, 'Samantha'); - expect(scope.selection.selected).toBe('Samantha'); - }); + it('should throw when no ui-select-match found', function () { + expect(function () { + compileTemplate( + ' \ + \ + ' + ); + }).toThrow(new Error('[ui.select:transcluded] Expected 1 .ui-select-match but got \'0\'.')); + }); - it('should invoke select callback on select', function () { + it('should format the model correctly using alias', function () { + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
    \ +
    \ +
    \ +
    ' + ); + clickItem(el, 'Samantha'); + expect(scope.selection.selected).toBe(scope.people[5]); + }); - scope.onSelectFn = function ($item, $model, $label) { - scope.$item = $item; - scope.$model = $model; - }; - var el = compileTemplate( - ' \ - {{$select.selected.name}} \ - \ -
    \ -
    \ -
    \ -
    ' - ); + it('should parse the model correctly using alias', function () { + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
    \ +
    \ +
    \ +
    ' + ); + scope.selection.selected = scope.people[5]; + scope.$digest(); + expect(getMatchLabel(el)).toEqual('Samantha'); + }); - expect(scope.$item).toBeFalsy(); - expect(scope.$model).toBeFalsy(); + it('should format the model correctly using property of alias', function () { + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
    \ +
    \ +
    \ +
    ' + ); + clickItem(el, 'Samantha'); + expect(scope.selection.selected).toBe('Samantha'); + }); - clickItem(el, 'Samantha'); - $timeout.flush(); + it('should parse the model correctly using property of alias', function () { + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
    \ +
    \ +
    \ +
    ' + ); + scope.selection.selected = 'Samantha'; + scope.$digest(); + expect(getMatchLabel(el)).toEqual('Samantha'); + }); + it('should parse the model correctly using property of alias with async choices data', function () { + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
    \ +
    \ +
    \ +
    ' + ); + $timeout(function () { + scope.peopleAsync = scope.people; + }); - expect(scope.selection.selected).toBe('Samantha'); + scope.selection.selected = 'Samantha'; + scope.$digest(); + expect(getMatchLabel(el)).toEqual(''); - expect(scope.$item).toEqual(scope.people[5]); - expect(scope.$model).toEqual('Samantha'); + $timeout.flush(); //After choices populated (async), it should show match correctly + expect(getMatchLabel(el)).toEqual('Samantha'); - }); + }); - it('should invoke before-select callback before select callback synchronously', function () { + //TODO Is this really something we should expect? + it('should parse the model correctly using property of alias but passed whole object', function () { + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
    \ +
    \ +
    \ +
    ' + ); + scope.selection.selected = scope.people[5]; + scope.$digest(); + expect(getMatchLabel(el)).toEqual('Samantha'); + }); - var order = []; - scope.onBeforeSelectFn = function ($item, $model, $label) { - order.push('onBeforeSelectFn'); - }; - scope.onSelectFn = function ($item, $model, $label) { - order.push('onSelectFn'); - }; - var el = compileTemplate( - ' \ - {{$select.selected.name}} \ - \ -
    \ -
    \ -
    \ -
    ' - ); + it('should format the model correctly without alias', function () { + var el = createUiSelect(); + clickItem(el, 'Samantha'); + expect(scope.selection.selected).toBe(scope.people[5]); + }); - clickItem(el, 'Samantha'); - $timeout.flush(); + it('should parse the model correctly without alias', function () { + var el = createUiSelect(); + scope.selection.selected = scope.people[5]; + scope.$digest(); + expect(getMatchLabel(el)).toEqual('Samantha'); + }); - expect(order[0]).toEqual('onBeforeSelectFn'); - expect(order[1]).toEqual('onSelectFn'); + it('should display choices correctly with child array', function () { + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
    \ +
    \ +
    \ +
    ' + ); + scope.selection.selected = scope.people[5]; + scope.$digest(); + expect(getMatchLabel(el)).toEqual('Samantha'); + }); - }); + it('should format the model correctly using property of alias and when using child array for choices', function () { + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
    \ +
    \ +
    \ +
    ' + ); + clickItem(el, 'Samantha'); + expect(scope.selection.selected).toBe('Samantha'); + }); - it('should invoke before-select callback before select callback when promised', inject(function ($q) { + it('should invoke select callback on select', function () { - var order = []; - scope.onBeforeSelectFn = function ($item, $model, $label) { - var deferred = $q.defer(); - $timeout(function () { - order.push('onBeforeSelectFn'); - deferred.resolve(order); - }); - return deferred.promise; - }; - scope.onSelectFn = function ($item, $model, $label) { - order.push('onSelectFn'); - }; - var el = compileTemplate( - ' \ - {{$select.selected.name}} \ - \ -
    \ -
    \ -
    \ -
    ' - ); + scope.onSelectFn = function ($item, $model, $label) { + scope.$item = $item; + scope.$model = $model; + }; + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
    \ +
    \ +
    \ +
    ' + ); - clickItem(el, 'Samantha'); - $timeout.flush(); + expect(scope.$item).toBeFalsy(); + expect(scope.$model).toBeFalsy(); - expect(order[0]).toEqual('onBeforeSelectFn'); - expect(order[1]).toEqual('onSelectFn'); + clickItem(el, 'Samantha'); + $timeout.flush(); - })); - it('should complete on-select if before-select callback promise is resolved', inject(function ($q) { + expect(scope.selection.selected).toBe('Samantha'); - scope.onBeforeSelectFn = function ($item, $model, $label) { - var deferred = $q.defer(); - $timeout(function () { - deferred.resolve(); - }); - return deferred.promise; - }; - scope.onSelectFn = function ($item, $model, $label) { - scope.$item = $item; - scope.$model = $model; - }; - var el = compileTemplate( - ' \ - {{$select.selected.name}} \ - \ -
    \ -
    \ -
    \ -
    ' - ); + expect(scope.$item).toEqual(scope.people[5]); + expect(scope.$model).toEqual('Samantha'); - expect(scope.$item).toBeFalsy(); - expect(scope.$model).toBeFalsy(); + }); - clickItem(el, 'Samantha'); - $timeout.flush(); + it('should invoke before-select callback before select callback synchronously', function () { + var order = []; + scope.onBeforeSelectFn = function ($item, $model, $label) { + order.push('onBeforeSelectFn'); + }; + scope.onSelectFn = function ($item, $model, $label) { + order.push('onSelectFn'); + }; + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
    \ +
    \ +
    \ +
    ' + ); - expect(scope.selection.selected).toBe('Samantha'); + clickItem(el, 'Samantha'); + $timeout.flush(); - expect(scope.$item).toEqual(scope.people[5]); - expect(scope.$model).toEqual('Samantha'); + expect(order[0]).toEqual('onBeforeSelectFn'); + expect(order[1]).toEqual('onSelectFn'); - })); + }); - it('should abort selection if before-select callback returns falsy', function () { + it('should invoke before-select callback before select callback when promised', inject(function ($q) { + var order = []; + scope.onBeforeSelectFn = function ($item, $model, $label) { + var deferred = $q.defer(); + $timeout(function () { + order.push('onBeforeSelectFn'); + deferred.resolve(order); + }); + return deferred.promise; + }; + scope.onSelectFn = function ($item, $model, $label) { + order.push('onSelectFn'); + }; + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
    \ +
    \ +
    \ +
    ' + ); - scope.onBeforeSelectFn = function ($item, $model, $label) { - return false; - }; - scope.onSelectFn = function ($item, $model, $label) { - scope.$item = $item; - scope.$model = $model; - }; - var el = compileTemplate( - ' \ - {{$select.selected.name}} \ - \ -
    \ -
    \ -
    \ -
    ' - ); + clickItem(el, 'Samantha'); + $timeout.flush(); - expect(scope.$item).toBeFalsy(); - expect(scope.$model).toBeFalsy(); + expect(order[0]).toEqual('onBeforeSelectFn'); + expect(order[1]).toEqual('onSelectFn'); + })); - clickItem(el, 'Samantha'); - $timeout.flush(); + it('should complete on-select if before-select callback promise is resolved', inject(function ($q) { + scope.onBeforeSelectFn = function ($item, $model, $label) { + var deferred = $q.defer(); + $timeout(function () { + deferred.resolve(true); + }); + return deferred.promise; + }; + scope.onSelectFn = function ($item, $model, $label) { + scope.$item = $item; + scope.$model = $model; + }; + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
    \ +
    \ +
    \ +
    ' + ); - expect(scope.$item).toBeFalsy(); - expect(scope.$model).toBeFalsy(); + expect(scope.$item).toBeFalsy(); + expect(scope.$model).toBeFalsy(); - }); + clickItem(el, 'Samantha'); + $timeout.flush(); - it('should abort selection if before-select callback rejects promise', inject(function ($q) { + expect(scope.selection.selected).toBe('Samantha'); - scope.onBeforeSelectFn = function ($item, $model, $label) { - var deferred = $q.defer(); - $timeout(function () { - deferred.reject(); - }); - return deferred.promise; - }; - scope.onSelectFn = function ($item, $model, $label) { - scope.$item = $item; - scope.$model = $model; - }; - var el = compileTemplate( - ' \ - {{$select.selected.name}} \ - \ -
    \ -
    \ -
    \ -
    ' - ); + expect(scope.$item).toEqual(scope.people[5]); + expect(scope.$model).toEqual('Samantha'); + })); - expect(scope.$item).toBeFalsy(); - expect(scope.$model).toBeFalsy(); + it('should abort selection if before-select callback returns falsy', function () { + scope.onBeforeSelectFn = function ($item, $model, $label) { + return false; + }; + scope.onSelectFn = function ($item, $model, $label) { + scope.$item = $item; + scope.$model = $model; + }; + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
    \ +
    \ +
    \ +
    ' + ); - clickItem(el, 'Samantha'); - $timeout.flush(); + expect(scope.$item).toBeFalsy(); + expect(scope.$model).toBeFalsy(); - expect(scope.$item).toBeFalsy(); - expect(scope.$model).toBeFalsy(); + clickItem(el, 'Samantha'); + $timeout.flush(); - })); + expect(scope.$item).toBeFalsy(); + expect(scope.$model).toBeFalsy(); + }); - it('should keep reference to current selection and incoming selection within before-select callback', function () { + it('should abort selection if before-select callback rejects promise', inject(function ($q) { + scope.onBeforeSelectFn = function ($item, $model, $label) { + var deferred = $q.defer(); + $timeout(function () { + deferred.reject(); + }); + return deferred.promise; + }; + scope.onSelectFn = function ($item, $model, $label) { + scope.$item = $item; + scope.$model = $model; + }; + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
    \ +
    \ +
    \ +
    ' + ); - var currentSelection, incomingSelection; - scope.onBeforeSelectFn = function ($item, $model, $label) { - incomingSelection = $item; - currentSelection = scope.selection.selected; - }; - var el = compileTemplate( - ' \ - {{$select.selected.name}} \ - \ -
    \ -
    \ -
    \ -
    ' - ); + expect(scope.$item).toBeFalsy(); + expect(scope.$model).toBeFalsy(); - clickItem(el, 'Samantha'); - $timeout.flush(); + clickItem(el, 'Samantha'); + $timeout.flush(); - expect(currentSelection).toBeFalsy(); - expect(incomingSelection.name).toBe('Samantha'); + expect(scope.$item).toBeFalsy(); + expect(scope.$model).toBeFalsy(); - clickItem(el, 'Adam'); - $timeout.flush(); + })); - expect(currentSelection).toBe('Samantha'); - expect(incomingSelection.name).toBe('Adam'); + it('should keep reference to current selection and incoming selection within before-select callback', function () { + var currentSelection, incomingSelection; + scope.onBeforeSelectFn = function ($item, $model, $label) { + incomingSelection = $item; + currentSelection = scope.selection.selected; + }; + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
    \ +
    \ +
    \ +
    ' + ); - }); + clickItem(el, 'Samantha'); + $timeout.flush(); - it('should invoke hover callback', function(){ + expect(currentSelection).toBeFalsy(); + expect(incomingSelection.name).toBe('Samantha'); - var highlighted; - scope.onHighlightFn = function ($item) { - highlighted = $item; - }; + clickItem(el, 'Adam'); + $timeout.flush(); - var el = compileTemplate( - ' \ - {{$select.selected.name}} \ - \ -
    \ -
    \ -
    \ -
    ' - ); + expect(currentSelection).toBe('Samantha'); + expect(incomingSelection.name).toBe('Adam'); - expect(highlighted).toBeFalsy(); + }); - if (!isDropdownOpened(el)){ - openDropdown(el); - } + it('should invoke hover callback', function () { - $(el).find('.ui-select-choices-row div:contains("Samantha")').trigger('mouseover'); - scope.$digest(); + var highlighted; + scope.onHighlightFn = function ($item) { + highlighted = $item; + }; - expect(highlighted).toBe(scope.people[5]); - }); + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
    \ +
    \ +
    \ +
    ' + ); - it('should set $item & $model correctly when invoking callback on select and no single prop. binding', function () { + expect(highlighted).toBeFalsy(); - scope.onSelectFn = function ($item, $model, $label) { - scope.$item = $item; - scope.$model = $model; - }; + if (!isDropdownOpened(el)) { + openDropdown(el); + } - var el = compileTemplate( - ' \ - {{$select.selected.name}} \ - \ -
    \ -
    \ -
    \ -
    ' - ); + $(el).find('.ui-select-choices-row div:contains("Samantha")').trigger('mouseover'); + scope.$digest(); - expect(scope.$item).toBeFalsy(); - expect(scope.$model).toBeFalsy(); + expect(highlighted).toBe(scope.people[5]); + }); - clickItem(el, 'Samantha'); - expect(scope.$item).toEqual(scope.$model); + it('should set $item & $model correctly when invoking callback on select and no single prop. binding', function () { - }); + scope.onSelectFn = function ($item, $model, $label) { + scope.$item = $item; + scope.$model = $model; + }; - it('should invoke remove callback on remove', function () { + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
    \ +
    \ +
    \ +
    ' + ); - scope.onRemoveFn = function ($item, $model, $label) { - scope.$item = $item; - scope.$model = $model; - }; + expect(scope.$item).toBeFalsy(); + expect(scope.$model).toBeFalsy(); - var el = compileTemplate( - ' \ - {{$select.selected.name}} \ - \ -
    \ -
    \ -
    \ -
    ' - ); + clickItem(el, 'Samantha'); + expect(scope.$item).toEqual(scope.$model); - expect(scope.$item).toBeFalsy(); - expect(scope.$model).toBeFalsy(); + }); - clickItem(el, 'Samantha'); - clickItem(el, 'Adrian'); - el.find('.ui-select-match-item').first().find('.ui-select-match-close').click(); - $timeout.flush(); + it('should invoke remove callback on remove', function () { + scope.onRemoveFn = function ($item, $model, $label) { + scope.$item = $item; + scope.$model = $model; + }; - expect(scope.$item).toBe(scope.people[5]); - expect(scope.$model).toBe('Samantha'); + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
    \ +
    \ +
    \ +
    ' + ); - }); + expect(scope.$item).toBeFalsy(); + expect(scope.$model).toBeFalsy(); - it('should set $item & $model correctly when invoking callback on remove and no single prop. binding', function () { + clickItem(el, 'Samantha'); + clickItem(el, 'Adrian'); + el.find('.ui-select-match-item').first().find('.ui-select-match-close').click(); + $timeout.flush(); - scope.onRemoveFn = function ($item, $model, $label) { - scope.$item = $item; - scope.$model = $model; - }; + expect(scope.$item).toBe(scope.people[5]); + expect(scope.$model).toBe('Samantha'); + }); - var el = compileTemplate( - ' \ - {{$select.selected.name}} \ - \ -
    \ -
    \ -
    \ -
    ' - ); + it('should set $item & $model correctly when invoking callback on remove and no single prop. binding', function () { - expect(scope.$item).toBeFalsy(); - expect(scope.$model).toBeFalsy(); + scope.onRemoveFn = function ($item, $model, $label) { + scope.$item = $item; + scope.$model = $model; + }; - clickItem(el, 'Samantha'); - clickItem(el, 'Adrian'); - el.find('.ui-select-match-item').first().find('.ui-select-match-close').click(); - $timeout.flush(); + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
    \ +
    \ +
    \ +
    ' + ); - expect(scope.$item).toBe(scope.people[5]); - expect(scope.$model).toBe(scope.$item); - }); + expect(scope.$item).toBeFalsy(); + expect(scope.$model).toBeFalsy(); - it('should append/transclude content (with correct scope) that users add at tag', function () { + clickItem(el, 'Samantha'); + clickItem(el, 'Adrian'); + el.find('.ui-select-match-item').first().find('.ui-select-match-close').click(); + $timeout.flush(); - var el = compileTemplate( - ' \ - \ - {{$select.selected.name}}\ - {{$select.selected.name | uppercase}}\ - \ - \ -
    \ -
    \ -
    ' - ); + expect(scope.$item).toBe(scope.people[5]); + expect(scope.$model).toBe(scope.$item); + }); - clickItem(el, 'Samantha'); - expect(getMatchLabel(el).trim()).toEqual('Samantha'); + it('should append/transclude content (with correct scope) that users add at tag', function () { - clickItem(el, 'Wladimir'); - expect(getMatchLabel(el).trim()).not.toEqual('Wladimir'); - expect(getMatchLabel(el).trim()).toEqual('WLADIMIR'); + var el = compileTemplate( + ' \ + \ + {{$select.selected.name}}\ + {{$select.selected.name | uppercase}}\ + \ + \ +
    \ +
    \ +
    ' + ); - }); - it('should append/transclude content (with correct scope) that users add at tag', function () { + clickItem(el, 'Samantha'); + expect(getMatchLabel(el).trim()).toEqual('Samantha'); - var el = compileTemplate( - ' \ - \ - \ - \ -
    \ -
    \ - I should appear only once\ -
    \ -
    \ -
    ' - ); + clickItem(el, 'Wladimir'); + expect(getMatchLabel(el).trim()).not.toEqual('Wladimir'); + expect(getMatchLabel(el).trim()).toEqual('WLADIMIR'); + + }); + it('should append/transclude content (with correct scope) that users add at tag', function () { + + var el = compileTemplate( + ' \ + \ + \ + \ +
    \ +
    \ + I should appear only once\ +
    \ +
    \ +
    ' + ); - openDropdown(el); - expect($(el).find('.only-once').length).toEqual(1); + openDropdown(el); + expect($(el).find('.only-once').length).toEqual(1); - }); + }); - it('should format view value correctly when using single property binding and refresh function', function () { + it('should format view value correctly when using single property binding and refresh function', function () { - var el = compileTemplate( - ' \ - {{$select.selected.name}} \ - \ -
    \ -
    \ - I should appear only once\ -
    \ -
    \ -
    ' - ); + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
    \ +
    \ + I should appear only once\ +
    \ +
    \ +
    ' + ); - scope.fetchFromServer = function(searching){ + scope.fetchFromServer = function (searching) { - if (searching == 's') - return scope.people; + if (searching == 's') + return scope.people; - if (searching == 'o'){ - scope.people = []; //To simulate cases were previously selected item isnt in the list anymore - } + if (searching == 'o') { + scope.people = []; //To simulate cases were previously selected item isnt in the list anymore + } - }; + }; - setSearchText(el, 'r'); - clickItem(el, 'Samantha'); - expect(getMatchLabel(el)).toBe('Samantha'); + setSearchText(el, 'r'); + clickItem(el, 'Samantha'); + expect(getMatchLabel(el)).toBe('Samantha'); - setSearchText(el, 'o'); - expect(getMatchLabel(el)).toBe('Samantha'); + setSearchText(el, 'o'); + expect(getMatchLabel(el)).toBe('Samantha'); - }); + }); - describe('search-enabled option', function() { + describe('search-enabled option', function () { - var el; + var el; - function setupSelectComponent(searchEnabled, theme) { - el = compileTemplate( - ' \ + function setupSelectComponent(searchEnabled, theme) { + el = compileTemplate( + ' \ {{$select.selected.name}} \ \
    \
    \
    \
    ' - ); - } - - describe('selectize theme', function() { + ); + } - it('should show search input when true', function() { - setupSelectComponent(true, 'selectize'); - expect($(el).find('.ui-select-search')).not.toHaveClass('ng-hide'); - }); + describe('selectize theme', function () { - it('should hide search input when false', function() { - setupSelectComponent(false, 'selectize'); - expect($(el).find('.ui-select-search')).toHaveClass('ng-hide'); - }); + it('should show search input when true', function () { + setupSelectComponent(true, 'selectize'); + expect($(el).find('.ui-select-search')).not.toHaveClass('ng-hide'); + }); - }); + it('should hide search input when false', function () { + setupSelectComponent(false, 'selectize'); + expect($(el).find('.ui-select-search')).toHaveClass('ng-hide'); + }); - describe('select2 theme', function() { + }); - it('should show search input when true', function() { - setupSelectComponent('true', 'select2'); - expect($(el).find('.select2-search')).not.toHaveClass('ng-hide'); - }); + describe('select2 theme', function () { - it('should hide search input when false', function() { - setupSelectComponent('false', 'select2'); - expect($(el).find('.select2-search')).toHaveClass('ng-hide'); - }); + it('should show search input when true', function () { + setupSelectComponent('true', 'select2'); + expect($(el).find('.select2-search')).not.toHaveClass('ng-hide'); + }); - }); + it('should hide search input when false', function () { + setupSelectComponent('false', 'select2'); + expect($(el).find('.select2-search')).toHaveClass('ng-hide'); + }); - describe('bootstrap theme', function() { + }); - it('should show search input when true', function() { - setupSelectComponent('true', 'bootstrap'); - clickMatch(el); - expect($(el).find('.ui-select-search')).not.toHaveClass('ui-select-offscreen'); - }); + describe('bootstrap theme', function () { - it('should hide search input when false', function() { - setupSelectComponent('false', 'bootstrap'); - clickMatch(el); - expect($(el).find('.ui-select-search')).toHaveClass('ui-select-offscreen'); - }); + it('should show search input when true', function () { + setupSelectComponent('true', 'bootstrap'); + clickMatch(el); + expect($(el).find('.ui-select-search')).not.toHaveClass('ui-select-offscreen'); + }); - }); + it('should hide search input when false', function () { + setupSelectComponent('false', 'bootstrap'); + clickMatch(el); + expect($(el).find('.ui-select-search')).toHaveClass('ui-select-offscreen'); + }); - }); + }); + }); - describe('multi selection', function() { - function createUiSelectMultiple(attrs) { - var attrsHtml = ''; - if (attrs !== undefined) { - if (attrs.disabled !== undefined) { attrsHtml += ' ng-disabled="' + attrs.disabled + '"'; } - if (attrs.required !== undefined) { attrsHtml += ' ng-required="' + attrs.required + '"'; } - if (attrs.tabindex !== undefined) { attrsHtml += ' tabindex="' + attrs.tabindex + '"'; } - if (attrs.closeOnSelect !== undefined) { attrsHtml += ' close-on-select="' + attrs.closeOnSelect + '"'; } - if (attrs.tagging !== undefined) { attrsHtml += ' tagging="' + attrs.tagging + '"'; } - if (attrs.taggingTokens !== undefined) { attrsHtml += ' tagging-tokens="' + attrs.taggingTokens + '"'; } - } + describe('multi selection', function () { + + function createUiSelectMultiple(attrs) { + var attrsHtml = ''; + if (attrs !== undefined) { + if (attrs.disabled !== undefined) { + attrsHtml += ' ng-disabled="' + attrs.disabled + '"'; + } + if (attrs.required !== undefined) { + attrsHtml += ' ng-required="' + attrs.required + '"'; + } + if (attrs.tabindex !== undefined) { + attrsHtml += ' tabindex="' + attrs.tabindex + '"'; + } + if (attrs.closeOnSelect !== undefined) { + attrsHtml += ' close-on-select="' + attrs.closeOnSelect + '"'; + } + if (attrs.tagging !== undefined) { + attrsHtml += ' tagging="' + attrs.tagging + '"'; + } + if (attrs.taggingTokens !== undefined) { + attrsHtml += ' tagging-tokens="' + attrs.taggingTokens + '"'; + } + } - return compileTemplate( - ' \ + return compileTemplate( + ' \ {{$item.name}} <{{$item.email}}> \ \
    \
    \
    \
    ' - ); - } - - it('should render initial state', function() { - var el = createUiSelectMultiple(); - expect(el).toHaveClass('ui-select-multiple'); - expect(el.scope().$select.selected.length).toBe(0); - expect(el.find('.ui-select-match-item').length).toBe(0); - }); - - it('should set model as an empty array if ngModel isnt defined after an item is selected', function () { + ); + } - // scope.selection.selectedMultiple = []; - var el = createUiSelectMultiple(); - expect(scope.selection.selectedMultiple instanceof Array).toBe(false); - clickItem(el, 'Samantha'); - expect(scope.selection.selectedMultiple instanceof Array).toBe(true); - }); + it('should render initial state', function () { + var el = createUiSelectMultiple(); + expect(el).toHaveClass('ui-select-multiple'); + expect(el.scope().$select.selected.length).toBe(0); + expect(el.find('.ui-select-match-item').length).toBe(0); + }); - it('should render initial selected items', function() { - scope.selection.selectedMultiple = [scope.people[4], scope.people[5]]; //Wladimir & Samantha - var el = createUiSelectMultiple(); - expect(el.scope().$select.selected.length).toBe(2); - expect(el.find('.ui-select-match-item').length).toBe(2); - }); + it('should set model as an empty array if ngModel isnt defined after an item is selected', function () { - it('should remove item by pressing X icon', function() { - scope.selection.selectedMultiple = [scope.people[4], scope.people[5]]; //Wladimir & Samantha - var el = createUiSelectMultiple(); - expect(el.scope().$select.selected.length).toBe(2); - el.find('.ui-select-match-item').first().find('.ui-select-match-close').click(); - expect(el.scope().$select.selected.length).toBe(1); - // $timeout.flush(); - }); + // scope.selection.selectedMultiple = []; + var el = createUiSelectMultiple(); + expect(scope.selection.selectedMultiple instanceof Array).toBe(false); + clickItem(el, 'Samantha'); + expect(scope.selection.selectedMultiple instanceof Array).toBe(true); + }); - it('should pass tabindex to searchInput', function() { - var el = createUiSelectMultiple({tabindex: 5}); - var searchInput = el.find('.ui-select-search'); + it('should render initial selected items', function () { + scope.selection.selectedMultiple = [scope.people[4], scope.people[5]]; //Wladimir & Samantha + var el = createUiSelectMultiple(); + expect(el.scope().$select.selected.length).toBe(2); + expect(el.find('.ui-select-match-item').length).toBe(2); + }); - expect(searchInput.attr('tabindex')).toEqual('5'); - expect($(el).attr('tabindex')).toEqual(undefined); - }); + it('should remove item by pressing X icon', function () { + scope.selection.selectedMultiple = [scope.people[4], scope.people[5]]; //Wladimir & Samantha + var el = createUiSelectMultiple(); + expect(el.scope().$select.selected.length).toBe(2); + el.find('.ui-select-match-item').first().find('.ui-select-match-close').click(); + expect(el.scope().$select.selected.length).toBe(1); + // $timeout.flush(); + }); - it('should pass tabindex to searchInput when tabindex is an expression', function() { - scope.tabValue = 22; - var el = createUiSelectMultiple({tabindex: '{{tabValue + 10}}'}); - var searchInput = el.find('.ui-select-search'); + it('should pass tabindex to searchInput', function () { + var el = createUiSelectMultiple({tabindex: 5}); + var searchInput = el.find('.ui-select-search'); - expect(searchInput.attr('tabindex')).toEqual('32'); - expect($(el).attr('tabindex')).toEqual(undefined); - }); + expect(searchInput.attr('tabindex')).toEqual('5'); + expect($(el).attr('tabindex')).toEqual(undefined); + }); - it('should not give searchInput a tabindex when ui-select does not have one', function() { - var el = createUiSelectMultiple(); - var searchInput = el.find('.ui-select-search'); + it('should pass tabindex to searchInput when tabindex is an expression', function () { + scope.tabValue = 22; + var el = createUiSelectMultiple({tabindex: '{{tabValue + 10}}'}); + var searchInput = el.find('.ui-select-search'); - expect(searchInput.attr('tabindex')).toEqual(undefined); - expect($(el).attr('tabindex')).toEqual(undefined); - }); + expect(searchInput.attr('tabindex')).toEqual('32'); + expect($(el).attr('tabindex')).toEqual(undefined); + }); - it('should update size of search input after removing an item', function() { - scope.selection.selectedMultiple = [scope.people[4], scope.people[5]]; //Wladimir & Samantha - var el = createUiSelectMultiple(); + it('should not give searchInput a tabindex when ui-select does not have one', function () { + var el = createUiSelectMultiple(); + var searchInput = el.find('.ui-select-search'); - spyOn(el.scope().$select, 'sizeSearchInput'); + expect(searchInput.attr('tabindex')).toEqual(undefined); + expect($(el).attr('tabindex')).toEqual(undefined); + }); - var searchInput = el.find('.ui-select-search'); - var oldWidth = searchInput.css('width'); + it('should update size of search input after removing an item', function () { + scope.selection.selectedMultiple = [scope.people[4], scope.people[5]]; //Wladimir & Samantha + var el = createUiSelectMultiple(); - el.find('.ui-select-match-item').first().find('.ui-select-match-close').click(); - expect(el.scope().$select.sizeSearchInput).toHaveBeenCalled(); + spyOn(el.scope().$select, 'sizeSearchInput'); - }); + var searchInput = el.find('.ui-select-search'); + var oldWidth = searchInput.css('width'); - it('should move to last match when pressing BACKSPACE key from search', function() { + el.find('.ui-select-match-item').first().find('.ui-select-match-close').click(); + expect(el.scope().$select.sizeSearchInput).toHaveBeenCalled(); - var el = createUiSelectMultiple(); - var searchInput = el.find('.ui-select-search'); + }); - expect(isDropdownOpened(el)).toEqual(false); - triggerKeydown(searchInput, Key.Backspace); - expect(isDropdownOpened(el)).toEqual(false); - expect(el.scope().$selectMultiple.activeMatchIndex).toBe(el.scope().$select.selected.length - 1); + it('should move to last match when pressing BACKSPACE key from search', function () { - }); + var el = createUiSelectMultiple(); + var searchInput = el.find('.ui-select-search'); - it('should remove highlighted match when pressing BACKSPACE key from search and decrease activeMatchIndex', function() { + expect(isDropdownOpened(el)).toEqual(false); + triggerKeydown(searchInput, Key.Backspace); + expect(isDropdownOpened(el)).toEqual(false); + expect(el.scope().$selectMultiple.activeMatchIndex).toBe(el.scope().$select.selected.length - 1); - scope.selection.selectedMultiple = [scope.people[4], scope.people[5], scope.people[6]]; //Wladimir, Samantha & Nicole - var el = createUiSelectMultiple(); - var searchInput = el.find('.ui-select-search'); + }); - expect(isDropdownOpened(el)).toEqual(false); - triggerKeydown(searchInput, Key.Left); - triggerKeydown(searchInput, Key.Left); - triggerKeydown(searchInput, Key.Backspace); - expect(el.scope().$select.selected).toEqual([scope.people[4], scope.people[6]]); //Wladimir & Nicole + it('should remove highlighted match when pressing BACKSPACE key from search and decrease activeMatchIndex', + function () { - expect(el.scope().$selectMultiple.activeMatchIndex).toBe(0); + scope.selection.selectedMultiple = [scope.people[4], scope.people[5], scope.people[6]]; //Wladimir, Samantha & Nicole + var el = createUiSelectMultiple(); + var searchInput = el.find('.ui-select-search'); - }); + expect(isDropdownOpened(el)).toEqual(false); + triggerKeydown(searchInput, Key.Left); + triggerKeydown(searchInput, Key.Left); + triggerKeydown(searchInput, Key.Backspace); + expect(el.scope().$select.selected).toEqual([scope.people[4], scope.people[6]]); //Wladimir & Nicole - it('should remove highlighted match when pressing DELETE key from search and keep same activeMatchIndex', function() { + expect(el.scope().$selectMultiple.activeMatchIndex).toBe(0); - scope.selection.selectedMultiple = [scope.people[4], scope.people[5], scope.people[6]]; //Wladimir, Samantha & Nicole - var el = createUiSelectMultiple(); - var searchInput = el.find('.ui-select-search'); + }); - expect(isDropdownOpened(el)).toEqual(false); - triggerKeydown(searchInput, Key.Left); - triggerKeydown(searchInput, Key.Left); - triggerKeydown(searchInput, Key.Delete); - expect(el.scope().$select.selected).toEqual([scope.people[4], scope.people[6]]); //Wladimir & Nicole + it('should remove highlighted match when pressing DELETE key from search and keep same activeMatchIndex', + function () { - expect(el.scope().$selectMultiple.activeMatchIndex).toBe(1); + scope.selection.selectedMultiple = [scope.people[4], scope.people[5], scope.people[6]]; //Wladimir, Samantha & Nicole + var el = createUiSelectMultiple(); + var searchInput = el.find('.ui-select-search'); - }); + expect(isDropdownOpened(el)).toEqual(false); + triggerKeydown(searchInput, Key.Left); + triggerKeydown(searchInput, Key.Left); + triggerKeydown(searchInput, Key.Delete); + expect(el.scope().$select.selected).toEqual([scope.people[4], scope.people[6]]); //Wladimir & Nicole - it('should move to last match when pressing LEFT key from search', function() { + expect(el.scope().$selectMultiple.activeMatchIndex).toBe(1); - var el = createUiSelectMultiple(); - var searchInput = el.find('.ui-select-search'); + }); - expect(isDropdownOpened(el)).toEqual(false); - triggerKeydown(searchInput, Key.Left); - expect(isDropdownOpened(el)).toEqual(false); - expect(el.scope().$selectMultiple.activeMatchIndex).toBe(el.scope().$select.selected.length - 1); + it('should move to last match when pressing LEFT key from search', function () { - }); + var el = createUiSelectMultiple(); + var searchInput = el.find('.ui-select-search'); - it('should move between matches when pressing LEFT key from search', function() { + expect(isDropdownOpened(el)).toEqual(false); + triggerKeydown(searchInput, Key.Left); + expect(isDropdownOpened(el)).toEqual(false); + expect(el.scope().$selectMultiple.activeMatchIndex).toBe(el.scope().$select.selected.length - 1); - scope.selection.selectedMultiple = [scope.people[4], scope.people[5], scope.people[6]]; //Wladimir, Samantha & Nicole - var el = createUiSelectMultiple(); - var searchInput = el.find('.ui-select-search'); + }); - expect(isDropdownOpened(el)).toEqual(false); - triggerKeydown(searchInput, Key.Left); - triggerKeydown(searchInput, Key.Left); - expect(isDropdownOpened(el)).toEqual(false); - expect(el.scope().$selectMultiple.activeMatchIndex).toBe(el.scope().$select.selected.length - 2); - triggerKeydown(searchInput, Key.Left); - triggerKeydown(searchInput, Key.Left); - triggerKeydown(searchInput, Key.Left); - expect(el.scope().$selectMultiple.activeMatchIndex).toBe(0); + it('should move between matches when pressing LEFT key from search', function () { - }); + scope.selection.selectedMultiple = [scope.people[4], scope.people[5], scope.people[6]]; //Wladimir, Samantha & Nicole + var el = createUiSelectMultiple(); + var searchInput = el.find('.ui-select-search'); - it('should decrease $selectMultiple.activeMatchIndex when pressing LEFT key', function() { + expect(isDropdownOpened(el)).toEqual(false); + triggerKeydown(searchInput, Key.Left); + triggerKeydown(searchInput, Key.Left); + expect(isDropdownOpened(el)).toEqual(false); + expect(el.scope().$selectMultiple.activeMatchIndex).toBe(el.scope().$select.selected.length - 2); + triggerKeydown(searchInput, Key.Left); + triggerKeydown(searchInput, Key.Left); + triggerKeydown(searchInput, Key.Left); + expect(el.scope().$selectMultiple.activeMatchIndex).toBe(0); - scope.selection.selectedMultiple = [scope.people[4], scope.people[5], scope.people[6]]; //Wladimir, Samantha & Nicole - var el = createUiSelectMultiple(); - var searchInput = el.find('.ui-select-search'); + }); - el.scope().$selectMultiple.activeMatchIndex = 3; - triggerKeydown(searchInput, Key.Left); - triggerKeydown(searchInput, Key.Left); - expect(el.scope().$selectMultiple.activeMatchIndex).toBe(1); + it('should decrease $selectMultiple.activeMatchIndex when pressing LEFT key', function () { - }); + scope.selection.selectedMultiple = [scope.people[4], scope.people[5], scope.people[6]]; //Wladimir, Samantha & Nicole + var el = createUiSelectMultiple(); + var searchInput = el.find('.ui-select-search'); - it('should increase $selectMultiple.activeMatchIndex when pressing RIGHT key', function() { + el.scope().$selectMultiple.activeMatchIndex = 3; + triggerKeydown(searchInput, Key.Left); + triggerKeydown(searchInput, Key.Left); + expect(el.scope().$selectMultiple.activeMatchIndex).toBe(1); - scope.selection.selectedMultiple = [scope.people[4], scope.people[5], scope.people[6]]; //Wladimir, Samantha & Nicole - var el = createUiSelectMultiple(); - var searchInput = el.find('.ui-select-search'); + }); - el.scope().$selectMultiple.activeMatchIndex = 0; - triggerKeydown(searchInput, Key.Right); - triggerKeydown(searchInput, Key.Right); - expect(el.scope().$selectMultiple.activeMatchIndex).toBe(2); + it('should increase $selectMultiple.activeMatchIndex when pressing RIGHT key', function () { - }); + scope.selection.selectedMultiple = [scope.people[4], scope.people[5], scope.people[6]]; //Wladimir, Samantha & Nicole + var el = createUiSelectMultiple(); + var searchInput = el.find('.ui-select-search'); - it('should open dropdown when pressing DOWN key', function() { + el.scope().$selectMultiple.activeMatchIndex = 0; + triggerKeydown(searchInput, Key.Right); + triggerKeydown(searchInput, Key.Right); + expect(el.scope().$selectMultiple.activeMatchIndex).toBe(2); - scope.selection.selectedMultiple = [scope.people[4], scope.people[5]]; //Wladimir & Samantha - var el = createUiSelectMultiple(); - var searchInput = el.find('.ui-select-search'); + }); - expect(isDropdownOpened(el)).toEqual(false); - triggerKeydown(searchInput, Key.Down); - expect(isDropdownOpened(el)).toEqual(true); + it('should open dropdown when pressing DOWN key', function () { - }); + scope.selection.selectedMultiple = [scope.people[4], scope.people[5]]; //Wladimir & Samantha + var el = createUiSelectMultiple(); + var searchInput = el.find('.ui-select-search'); - it('should search/open dropdown when writing to search input', function() { + expect(isDropdownOpened(el)).toEqual(false); + triggerKeydown(searchInput, Key.Down); + expect(isDropdownOpened(el)).toEqual(true); - scope.selection.selectedMultiple = [scope.people[5]]; //Wladimir & Samantha - var el = createUiSelectMultiple(); - var searchInput = el.find('.ui-select-search'); + }); - el.scope().$select.search = 'r'; - scope.$digest(); - expect(isDropdownOpened(el)).toEqual(true); + it('should search/open dropdown when writing to search input', function () { - }); + scope.selection.selectedMultiple = [scope.people[5]]; //Wladimir & Samantha + var el = createUiSelectMultiple(); + var searchInput = el.find('.ui-select-search'); - it('should add selected match to selection array', function() { + el.scope().$select.search = 'r'; + scope.$digest(); + expect(isDropdownOpened(el)).toEqual(true); - scope.selection.selectedMultiple = [scope.people[5]]; //Samantha - var el = createUiSelectMultiple(); - var searchInput = el.find('.ui-select-search'); + }); - clickItem(el, 'Wladimir'); - expect(scope.selection.selectedMultiple).toEqual([scope.people[5], scope.people[4]]); //Samantha & Wladimir + it('should add selected match to selection array', function () { - }); + scope.selection.selectedMultiple = [scope.people[5]]; //Samantha + var el = createUiSelectMultiple(); + var searchInput = el.find('.ui-select-search'); - it('should close dropdown after selecting', function() { + clickItem(el, 'Wladimir'); + expect(scope.selection.selectedMultiple).toEqual([scope.people[5], scope.people[4]]); //Samantha & Wladimir - scope.selection.selectedMultiple = [scope.people[5]]; //Samantha - var el = createUiSelectMultiple(); - var searchInput = el.find('.ui-select-search'); + }); - expect(isDropdownOpened(el)).toEqual(false); - triggerKeydown(searchInput, Key.Down); - expect(isDropdownOpened(el)).toEqual(true); + it('should close dropdown after selecting', function () { - clickItem(el, 'Wladimir'); + scope.selection.selectedMultiple = [scope.people[5]]; //Samantha + var el = createUiSelectMultiple(); + var searchInput = el.find('.ui-select-search'); - expect(isDropdownOpened(el)).toEqual(false); + expect(isDropdownOpened(el)).toEqual(false); + triggerKeydown(searchInput, Key.Down); + expect(isDropdownOpened(el)).toEqual(true); - }); + clickItem(el, 'Wladimir'); - it('should not close dropdown after selecting if closeOnSelect=false', function() { + expect(isDropdownOpened(el)).toEqual(false); - scope.selection.selectedMultiple = [scope.people[5]]; //Samantha - var el = createUiSelectMultiple({closeOnSelect: false}); - var searchInput = el.find('.ui-select-search'); + }); - expect(isDropdownOpened(el)).toEqual(false); - triggerKeydown(searchInput, Key.Down); - expect(isDropdownOpened(el)).toEqual(true); + it('should not close dropdown after selecting if closeOnSelect=false', function () { - clickItem(el, 'Wladimir'); + scope.selection.selectedMultiple = [scope.people[5]]; //Samantha + var el = createUiSelectMultiple({closeOnSelect: false}); + var searchInput = el.find('.ui-select-search'); - expect(isDropdownOpened(el)).toEqual(true); + expect(isDropdownOpened(el)).toEqual(false); + triggerKeydown(searchInput, Key.Down); + expect(isDropdownOpened(el)).toEqual(true); - }); + clickItem(el, 'Wladimir'); - it('should closes dropdown when pressing ESC key from search input', function() { + expect(isDropdownOpened(el)).toEqual(true); - scope.selection.selectedMultiple = [scope.people[4], scope.people[5], scope.people[6]]; //Wladimir, Samantha & Nicole - var el = createUiSelectMultiple(); - var searchInput = el.find('.ui-select-search'); + }); - expect(isDropdownOpened(el)).toEqual(false); - triggerKeydown(searchInput, Key.Down); - expect(isDropdownOpened(el)).toEqual(true); - triggerKeydown(searchInput, Key.Escape); - expect(isDropdownOpened(el)).toEqual(false); + it('should closes dropdown when pressing ESC key from search input', function () { - }); + scope.selection.selectedMultiple = [scope.people[4], scope.people[5], scope.people[6]]; //Wladimir, Samantha & Nicole + var el = createUiSelectMultiple(); + var searchInput = el.find('.ui-select-search'); - it('should select highlighted match when pressing ENTER key from dropdown', function() { + expect(isDropdownOpened(el)).toEqual(false); + triggerKeydown(searchInput, Key.Down); + expect(isDropdownOpened(el)).toEqual(true); + triggerKeydown(searchInput, Key.Escape); + expect(isDropdownOpened(el)).toEqual(false); - scope.selection.selectedMultiple = [scope.people[5]]; //Samantha - var el = createUiSelectMultiple(); - var searchInput = el.find('.ui-select-search'); + }); - triggerKeydown(searchInput, Key.Down); - triggerKeydown(searchInput, Key.Enter); - expect(scope.selection.selectedMultiple.length).toEqual(2); + it('should select highlighted match when pressing ENTER key from dropdown', function () { - }); + scope.selection.selectedMultiple = [scope.people[5]]; //Samantha + var el = createUiSelectMultiple(); + var searchInput = el.find('.ui-select-search'); - it('should stop the propagation when pressing ENTER key from dropdown', function() { + triggerKeydown(searchInput, Key.Down); + triggerKeydown(searchInput, Key.Enter); + expect(scope.selection.selectedMultiple.length).toEqual(2); - var el = createUiSelectMultiple(); - var searchInput = el.find('.ui-select-search'); - spyOn(jQuery.Event.prototype, 'preventDefault'); - spyOn(jQuery.Event.prototype, 'stopPropagation'); + }); - triggerKeydown(searchInput, Key.Down); - triggerKeydown(searchInput, Key.Enter); - expect(jQuery.Event.prototype.preventDefault).toHaveBeenCalled(); - expect(jQuery.Event.prototype.stopPropagation).toHaveBeenCalled(); + it('should stop the propagation when pressing ENTER key from dropdown', function () { - }); + var el = createUiSelectMultiple(); + var searchInput = el.find('.ui-select-search'); + spyOn(jQuery.Event.prototype, 'preventDefault'); + spyOn(jQuery.Event.prototype, 'stopPropagation'); - it('should stop the propagation when pressing ESC key from dropdown', function() { + triggerKeydown(searchInput, Key.Down); + triggerKeydown(searchInput, Key.Enter); + expect(jQuery.Event.prototype.preventDefault).toHaveBeenCalled(); + expect(jQuery.Event.prototype.stopPropagation).toHaveBeenCalled(); - var el = createUiSelectMultiple(); - var searchInput = el.find('.ui-select-search'); - spyOn(jQuery.Event.prototype, 'preventDefault'); - spyOn(jQuery.Event.prototype, 'stopPropagation'); + }); - triggerKeydown(searchInput, Key.Down); - triggerKeydown(searchInput, Key.Escape); - expect(jQuery.Event.prototype.preventDefault).toHaveBeenCalled(); - expect(jQuery.Event.prototype.stopPropagation).toHaveBeenCalled(); + it('should stop the propagation when pressing ESC key from dropdown', function () { - }); + var el = createUiSelectMultiple(); + var searchInput = el.find('.ui-select-search'); + spyOn(jQuery.Event.prototype, 'preventDefault'); + spyOn(jQuery.Event.prototype, 'stopPropagation'); - it('should increase $select.activeIndex when pressing DOWN key from dropdown', function() { + triggerKeydown(searchInput, Key.Down); + triggerKeydown(searchInput, Key.Escape); + expect(jQuery.Event.prototype.preventDefault).toHaveBeenCalled(); + expect(jQuery.Event.prototype.stopPropagation).toHaveBeenCalled(); - var el = createUiSelectMultiple(); - var searchInput = el.find('.ui-select-search'); + }); - triggerKeydown(searchInput, Key.Down); //Open dropdown + it('should increase $select.activeIndex when pressing DOWN key from dropdown', function () { - el.scope().$select.activeIndex = 0; - triggerKeydown(searchInput, Key.Down); - triggerKeydown(searchInput, Key.Down); - expect(el.scope().$select.activeIndex).toBe(2); + var el = createUiSelectMultiple(); + var searchInput = el.find('.ui-select-search'); - }); + triggerKeydown(searchInput, Key.Down); //Open dropdown - it('should decrease $select.activeIndex when pressing UP key from dropdown', function() { + el.scope().$select.activeIndex = 0; + triggerKeydown(searchInput, Key.Down); + triggerKeydown(searchInput, Key.Down); + expect(el.scope().$select.activeIndex).toBe(2); - var el = createUiSelectMultiple(); - var searchInput = el.find('.ui-select-search'); + }); - triggerKeydown(searchInput, Key.Down); //Open dropdown + it('should decrease $select.activeIndex when pressing UP key from dropdown', function () { - el.scope().$select.activeIndex = 5; - triggerKeydown(searchInput, Key.Up); - triggerKeydown(searchInput, Key.Up); - expect(el.scope().$select.activeIndex).toBe(3); + var el = createUiSelectMultiple(); + var searchInput = el.find('.ui-select-search'); - }); + triggerKeydown(searchInput, Key.Down); //Open dropdown - it('should render initial selected items', function() { - scope.selection.selectedMultiple = [scope.people[4], scope.people[5]]; //Wladimir & Samantha - var el = createUiSelectMultiple(); - expect(el.scope().$select.selected.length).toBe(2); - expect(el.find('.ui-select-match-item').length).toBe(2); - }); + el.scope().$select.activeIndex = 5; + triggerKeydown(searchInput, Key.Up); + triggerKeydown(searchInput, Key.Up); + expect(el.scope().$select.activeIndex).toBe(3); - it('should parse the items correctly using single property binding', function() { + }); - scope.selection.selectedMultiple = ['wladimir@email.com', 'samantha@email.com']; + it('should render initial selected items', function () { + scope.selection.selectedMultiple = [scope.people[4], scope.people[5]]; //Wladimir & Samantha + var el = createUiSelectMultiple(); + expect(el.scope().$select.selected.length).toBe(2); + expect(el.find('.ui-select-match-item').length).toBe(2); + }); - var el = compileTemplate( - ' \ - {{$item.name}} <{{$item.email}}> \ - \ -
    \ -
    \ -
    \ -
    ' - ); + it('should parse the items correctly using single property binding', function () { - expect(el.scope().$select.selected).toEqual([scope.people[4], scope.people[5]]); + scope.selection.selectedMultiple = ['wladimir@email.com', 'samantha@email.com']; - }); + var el = compileTemplate( + ' \ + {{$item.name}} <{{$item.email}}> \ + \ +
    \ +
    \ +
    \ +
    ' + ); - it('should add selected match to selection array using single property binding', function() { + expect(el.scope().$select.selected).toEqual([scope.people[4], scope.people[5]]); - scope.selection.selectedMultiple = ['wladimir@email.com', 'samantha@email.com']; + }); - var el = compileTemplate( - ' \ - {{$item.name}} <{{$item.email}}> \ - \ -
    \ -
    \ -
    \ -
    ' - ); + it('should add selected match to selection array using single property binding', function () { - var searchInput = el.find('.ui-select-search'); + scope.selection.selectedMultiple = ['wladimir@email.com', 'samantha@email.com']; - clickItem(el, 'Natasha'); + var el = compileTemplate( + ' \ + {{$item.name}} <{{$item.email}}> \ + \ +
    \ +
    \ +
    \ +
    ' + ); - expect(el.scope().$select.selected).toEqual([scope.people[4], scope.people[5], scope.people[7]]); - scope.selection.selectedMultiple = ['wladimir@email.com', 'samantha@email.com', 'natasha@email.com']; + var searchInput = el.find('.ui-select-search'); - }); + clickItem(el, 'Natasha'); - it('should format view value correctly when using single property binding and refresh function', function () { + expect(el.scope().$select.selected).toEqual([scope.people[4], scope.people[5], scope.people[7]]); + scope.selection.selectedMultiple = ['wladimir@email.com', 'samantha@email.com', 'natasha@email.com']; - scope.selection.selectedMultiple = ['wladimir@email.com', 'samantha@email.com']; + }); - var el = compileTemplate( - ' \ - {{$item.name}} <{{$item.email}}> \ - \ -
    \ -
    \ -
    \ -
    ' - ); + it('should format view value correctly when using single property binding and refresh function', function () { - var searchInput = el.find('.ui-select-search'); + scope.selection.selectedMultiple = ['wladimir@email.com', 'samantha@email.com']; - scope.fetchFromServer = function(searching){ + var el = compileTemplate( + ' \ + {{$item.name}} <{{$item.email}}> \ + \ +
    \ +
    \ +
    \ +
    ' + ); - if (searching == 'n') - return scope.people; + var searchInput = el.find('.ui-select-search'); - if (searching == 'o'){ - scope.people = []; //To simulate cases were previously selected item isnt in the list anymore - } + scope.fetchFromServer = function (searching) { - }; + if (searching == 'n') + return scope.people; - setSearchText(el, 'n'); - clickItem(el, 'Nicole'); + if (searching == 'o') { + scope.people = []; //To simulate cases were previously selected item isnt in the list anymore + } - expect(el.find('.ui-select-match-item [uis-transclude-append]:not(.ng-hide)').text()) - .toBe("Wladimir Samantha Nicole "); + }; - setSearchText(el, 'o'); + setSearchText(el, 'n'); + clickItem(el, 'Nicole'); - expect(el.find('.ui-select-match-item [uis-transclude-append]:not(.ng-hide)').text()) - .toBe("Wladimir Samantha Nicole "); + expect(el.find('.ui-select-match-item [uis-transclude-append]:not(.ng-hide)').text()) + .toBe("Wladimir Samantha Nicole "); - }); + setSearchText(el, 'o'); - it('should watch changes for $select.selected and update formatted value correctly', function () { + expect(el.find('.ui-select-match-item [uis-transclude-append]:not(.ng-hide)').text()) + .toBe("Wladimir Samantha Nicole "); - scope.selection.selectedMultiple = ['wladimir@email.com', 'samantha@email.com']; + }); - var el = compileTemplate( - ' \ - {{$item.name}} <{{$item.email}}> \ - \ -
    \ -
    \ -
    \ -
    \ - ' - ); + it('should watch changes for $select.selected and update formatted value correctly', function () { - var el2 = compileTemplate(''); + scope.selection.selectedMultiple = ['wladimir@email.com', 'samantha@email.com']; - expect(el.find('.ui-select-match-item [uis-transclude-append]:not(.ng-hide)').text()) - .toBe("Wladimir Samantha "); + var el = compileTemplate( + ' \ + {{$item.name}} <{{$item.email}}> \ + \ +
    \ +
    \ +
    \ +
    \ + ' + ); - clickItem(el, 'Nicole'); + var el2 = compileTemplate(''); - expect(el.find('.ui-select-match-item [uis-transclude-append]:not(.ng-hide)').text()) - .toBe("Wladimir Samantha Nicole "); + expect(el.find('.ui-select-match-item [uis-transclude-append]:not(.ng-hide)').text()) + .toBe("Wladimir Samantha "); - expect(scope.selection.selectedMultiple.length).toBe(3); + clickItem(el, 'Nicole'); - }); + expect(el.find('.ui-select-match-item [uis-transclude-append]:not(.ng-hide)').text()) + .toBe("Wladimir Samantha Nicole "); - it('should ensure the multiple selection limit is respected', function () { + expect(scope.selection.selectedMultiple.length).toBe(3); - scope.selection.selectedMultiple = ['wladimir@email.com']; + }); - var el = compileTemplate( - ' \ - {{$item.name}} <{{$item.email}}> \ - \ -
    \ -
    \ -
    \ -
    \ - ' - ); + it('should ensure the multiple selection limit is respected', function () { - var el2 = compileTemplate(''); + scope.selection.selectedMultiple = ['wladimir@email.com']; - expect(el.find('.ui-select-match-item [uis-transclude-append]:not(.ng-hide)').text()) - .toBe("Wladimir "); + var el = compileTemplate( + ' \ + {{$item.name}} <{{$item.email}}> \ + \ +
    \ +
    \ +
    \ +
    \ + ' + ); - clickItem(el, 'Samantha'); - expect(el.find('.ui-select-match-item [uis-transclude-append]:not(.ng-hide)').text()) - .toBe("Wladimir Samantha "); + var el2 = compileTemplate(''); - clickItem(el, 'Nicole'); + expect(el.find('.ui-select-match-item [uis-transclude-append]:not(.ng-hide)').text()) + .toBe("Wladimir "); - expect(el.find('.ui-select-match-item [uis-transclude-append]:not(.ng-hide)').text()) - .toBe("Wladimir Samantha "); + clickItem(el, 'Samantha'); + expect(el.find('.ui-select-match-item [uis-transclude-append]:not(.ng-hide)').text()) + .toBe("Wladimir Samantha "); - expect(scope.selection.selectedMultiple.length).toBe(2); + clickItem(el, 'Nicole'); - }); + expect(el.find('.ui-select-match-item [uis-transclude-append]:not(.ng-hide)').text()) + .toBe("Wladimir Samantha "); - it('should change viewvalue only once when updating modelvalue', function () { + expect(scope.selection.selectedMultiple.length).toBe(2); - scope.selection.selectedMultiple = ['wladimir@email.com', 'samantha@email.com']; + }); - var el = compileTemplate( - ' \ - {{$item.name}} <{{$item.email}}> \ - \ -
    \ -
    \ -
    \ -
    \ - ' - ); + it('should change viewvalue only once when updating modelvalue', function () { - scope.counter = 0; - scope.onlyOnce = function(){ - scope.counter++; - }; + scope.selection.selectedMultiple = ['wladimir@email.com', 'samantha@email.com']; - clickItem(el, 'Nicole'); + var el = compileTemplate( + ' \ + {{$item.name}} <{{$item.email}}> \ + \ +
    \ +
    \ +
    \ +
    \ + ' + ); - expect(scope.counter).toBe(1); + scope.counter = 0; + scope.onlyOnce = function () { + scope.counter++; + }; - }); + clickItem(el, 'Nicole'); + expect(scope.counter).toBe(1); - it('should run $formatters when changing model directly', function () { + }); - scope.selection.selectedMultiple = ['wladimir@email.com', 'samantha@email.com']; - var el = compileTemplate( - ' \ - {{$item.name}} <{{$item.email}}> \ - \ -
    \ -
    \ -
    \ -
    \ - ' - ); + it('should run $formatters when changing model directly', function () { - // var el2 = compileTemplate(''); + scope.selection.selectedMultiple = ['wladimir@email.com', 'samantha@email.com']; - scope.selection.selectedMultiple.push("nicole@email.com"); + var el = compileTemplate( + ' \ + {{$item.name}} <{{$item.email}}> \ + \ +
    \ +
    \ +
    \ +
    \ + ' + ); - scope.$digest(); - scope.$digest(); //2nd $digest needed when using angular 1.3.0-rc.1+, might be related with the fact that the value is an array + // var el2 = compileTemplate(''); - expect(el.find('.ui-select-match-item [uis-transclude-append]:not(.ng-hide)').text()) - .toBe("Wladimir Samantha Nicole "); + scope.selection.selectedMultiple.push("nicole@email.com"); - }); + scope.$digest(); + scope.$digest(); //2nd $digest needed when using angular 1.3.0-rc.1+, might be related with the fact that the value is an array - it('should support multiple="multiple" attribute', function() { + expect(el.find('.ui-select-match-item [uis-transclude-append]:not(.ng-hide)').text()) + .toBe("Wladimir Samantha Nicole "); - var el = compileTemplate( - ' \ - {{$item.name}} <{{$item.email}}> \ - \ -
    \ -
    \ -
    \ -
    \ - ' - ); + }); - expect(el.scope().$select.multiple).toBe(true); - }); + it('should support multiple="multiple" attribute', function () { - it('should allow paste tag from clipboard', function() { - scope.taggingFunc = function (name) { - return { - name: name, - email: name + '@email.com', - group: 'Foo', - age: 12 - }; - }; - - var el = createUiSelectMultiple({tagging: 'taggingFunc', taggingTokens: ",|ENTER"}); - clickMatch(el); - triggerPaste(el.find('input'), 'tag1'); - - expect($(el).scope().$select.selected.length).toBe(1); - }); + var el = compileTemplate( + ' \ + {{$item.name}} <{{$item.email}}> \ + \ +
    \ +
    \ +
    \ +
    \ + ' + ); - it('should allow paste multiple tags', function() { - scope.taggingFunc = function (name) { - return { - name: name, - email: name + '@email.com', - group: 'Foo', - age: 12 - }; - }; + expect(el.scope().$select.multiple).toBe(true); + }); - var el = createUiSelectMultiple({tagging: 'taggingFunc', taggingTokens: ",|ENTER"}); - clickMatch(el); - triggerPaste(el.find('input'), ',tag1,tag2,tag3,,tag5,'); + it('should allow paste tag from clipboard', function () { + scope.taggingFunc = function (name) { + return { + name: name, + email: name + '@email.com', + group: 'Foo', + age: 12 + }; + }; + + var el = createUiSelectMultiple({tagging: 'taggingFunc', taggingTokens: ",|ENTER"}); + clickMatch(el); + triggerPaste(el.find('input'), 'tag1'); + + expect($(el).scope().$select.selected.length).toBe(1); + }); - expect($(el).scope().$select.selected.length).toBe(5); + it('should allow paste multiple tags', function () { + scope.taggingFunc = function (name) { + return { + name: name, + email: name + '@email.com', + group: 'Foo', + age: 12 + }; + }; + + var el = createUiSelectMultiple({tagging: 'taggingFunc', taggingTokens: ",|ENTER"}); + clickMatch(el); + triggerPaste(el.find('input'), ',tag1,tag2,tag3,,tag5,'); + + expect($(el).scope().$select.selected.length).toBe(5); + }); }); - }); - describe('default configuration via uiSelectConfig', function() { + describe('default configuration via uiSelectConfig', function () { - describe('searchEnabled option', function() { + describe('searchEnabled option', function () { - function setupWithoutAttr(){ - return compileTemplate( - ' \ - {{$select.selected.name}} \ - \ -
    \ -
    \ -
    \ -
    ' - ); - } + function setupWithoutAttr() { + return compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
    \ +
    \ +
    \ +
    ' + ); + } - function setupWithAttr(searchEnabled){ - return compileTemplate( - ' \ + function setupWithAttr(searchEnabled) { + return compileTemplate( + ' \ {{$select.selected.name}} \ \
    \
    \
    \
    ' - ); - } - - it('should be true by default', function(){ - var el = setupWithoutAttr(); - expect(el.scope().$select.searchEnabled).toBe(true); - }); + ); + } - it('should disable search if default set to false', function(){ - var uiSelectConfig = $injector.get('uiSelectConfig'); - uiSelectConfig.searchEnabled = false; + it('should be true by default', function () { + var el = setupWithoutAttr(); + expect(el.scope().$select.searchEnabled).toBe(true); + }); - var el = setupWithoutAttr(); - expect(el.scope().$select.searchEnabled).not.toBe(true); - }); + it('should disable search if default set to false', function () { + var uiSelectConfig = $injector.get('uiSelectConfig'); + uiSelectConfig.searchEnabled = false; - it('should be overridden by inline option search-enabled=true', function(){ - var uiSelectConfig = $injector.get('uiSelectConfig'); - uiSelectConfig.searchEnabled = false; + var el = setupWithoutAttr(); + expect(el.scope().$select.searchEnabled).not.toBe(true); + }); - var el = setupWithAttr(true); - expect(el.scope().$select.searchEnabled).toBe(true); - }); + it('should be overridden by inline option search-enabled=true', function () { + var uiSelectConfig = $injector.get('uiSelectConfig'); + uiSelectConfig.searchEnabled = false; - it('should be overridden by inline option search-enabled=false', function(){ - var uiSelectConfig = $injector.get('uiSelectConfig'); - uiSelectConfig.searchEnabled = true; + var el = setupWithAttr(true); + expect(el.scope().$select.searchEnabled).toBe(true); + }); - var el = setupWithAttr(false); - expect(el.scope().$select.searchEnabled).not.toBe(true); - }); - }); + it('should be overridden by inline option search-enabled=false', function () { + var uiSelectConfig = $injector.get('uiSelectConfig'); + uiSelectConfig.searchEnabled = true; - }); + var el = setupWithAttr(false); + expect(el.scope().$select.searchEnabled).not.toBe(true); + }); + }); - describe('accessibility', function() { - it('should have baseTitle in scope', function() { - expect(createUiSelect().scope().$select.baseTitle).toBe('Select box'); - expect(createUiSelect().scope().$select.focusserTitle).toBe('Select box focus'); - expect(createUiSelect({ title: 'Choose a person' }).scope().$select.baseTitle).toBe('Choose a person'); - expect(createUiSelect({ title: 'Choose a person' }).scope().$select.focusserTitle).toBe('Choose a person focus'); }); - it('should have aria-label on all input and button elements', function() { - checkTheme(); - checkTheme('select2'); - checkTheme('selectize'); - checkTheme('bootstrap'); - - function checkTheme(theme) { - var el = createUiSelect({ theme: theme}); - checkElements(el.find('input')); - checkElements(el.find('button')); - - function checkElements(els) { - for (var i = 0; i < els.length; i++) { - expect(els[i].attributes['aria-label']).toBeTruthy(); - } - } - } - }); - }); + describe('accessibility', function () { + it('should have baseTitle in scope', function () { + expect(createUiSelect().scope().$select.baseTitle).toBe('Select box'); + expect(createUiSelect().scope().$select.focusserTitle).toBe('Select box focus'); + expect(createUiSelect({title: 'Choose a person'}).scope().$select.baseTitle).toBe('Choose a person'); + expect(createUiSelect({title: 'Choose a person'}).scope().$select.focusserTitle).toBe('Choose a person focus'); + }); - describe('select with the append to body option', function() { - var body; + it('should have aria-label on all input and button elements', function () { + checkTheme(); + checkTheme('select2'); + checkTheme('selectize'); + checkTheme('bootstrap'); + + function checkTheme(theme) { + var el = createUiSelect({theme: theme}); + checkElements(el.find('input')); + checkElements(el.find('button')); + + function checkElements(els) { + for (var i = 0; i < els.length; i++) { + expect(els[i].attributes['aria-label']).toBeTruthy(); + } + } + } + }); + }); - beforeEach(inject(function($document) { - body = $document.find('body')[0]; - })); + describe('select with the append to body option', function () { + var body; - it('should only be moved to the body when the appendToBody option is true', function() { - var el = createUiSelect({appendToBody: false}); - openDropdown(el); - expect(el.parent()[0]).not.toBe(body); - }); + beforeEach(inject(function ($document) { + body = $document.find('body')[0]; + })); - it('should be moved to the body when the appendToBody is true in uiSelectConfig', inject(function(uiSelectConfig) { - uiSelectConfig.appendToBody = true; - var el = createUiSelect(); - openDropdown(el); - expect(el.parent()[0]).toBe(body); - })); + it('should only be moved to the body when the appendToBody option is true', function () { + var el = createUiSelect({appendToBody: false}); + openDropdown(el); + expect(el.parent()[0]).not.toBe(body); + }); - it('should be moved to the body when opened', function() { - var el = createUiSelect({appendToBody: true}); - openDropdown(el); - expect(el.parent()[0]).toBe(body); - closeDropdown(el); - expect(el.parent()[0]).not.toBe(body); - }); + it('should be moved to the body when the appendToBody is true in uiSelectConfig', + inject(function (uiSelectConfig) { + uiSelectConfig.appendToBody = true; + var el = createUiSelect(); + openDropdown(el); + expect(el.parent()[0]).toBe(body); + })); + + it('should be moved to the body when opened', function () { + var el = createUiSelect({appendToBody: true}); + openDropdown(el); + expect(el.parent()[0]).toBe(body); + closeDropdown(el); + expect(el.parent()[0]).not.toBe(body); + }); - it('should remove itself from the body when the scope is destroyed', function() { - var el = createUiSelect({appendToBody: true}); - openDropdown(el); - expect(el.parent()[0]).toBe(body); - el.scope().$destroy(); - expect(el.parent()[0]).not.toBe(body); - }); + it('should remove itself from the body when the scope is destroyed', function () { + var el = createUiSelect({appendToBody: true}); + openDropdown(el); + expect(el.parent()[0]).toBe(body); + el.scope().$destroy(); + expect(el.parent()[0]).not.toBe(body); + }); - it('should have specific position and dimensions', function() { - var el = createUiSelect({appendToBody: true}); - var originalPosition = el.css('position'); - var originalTop = el.css('top'); - var originalLeft = el.css('left'); - var originalWidth = el.css('width'); - openDropdown(el); - expect(el.css('position')).toBe('absolute'); - expect(el.css('top')).toBe('100px'); - expect(el.css('left')).toBe('200px'); - expect(el.css('width')).toBe('300px'); - closeDropdown(el); - expect(el.css('position')).toBe(originalPosition); - expect(el.css('top')).toBe(originalTop); - expect(el.css('left')).toBe(originalLeft); - expect(el.css('width')).toBe(originalWidth); + it('should have specific position and dimensions', function () { + var el = createUiSelect({appendToBody: true}); + var originalPosition = el.css('position'); + var originalTop = el.css('top'); + var originalLeft = el.css('left'); + var originalWidth = el.css('width'); + openDropdown(el); + expect(el.css('position')).toBe('absolute'); + expect(el.css('top')).toBe('100px'); + expect(el.css('left')).toBe('200px'); + expect(el.css('width')).toBe('300px'); + closeDropdown(el); + expect(el.css('position')).toBe(originalPosition); + expect(el.css('top')).toBe(originalTop); + expect(el.css('left')).toBe(originalLeft); + expect(el.css('width')).toBe(originalWidth); + }); }); - }); }); From 4e852916ba2ec4d22e46cc4caac49482e246877d Mon Sep 17 00:00:00 2001 From: Chris Jackson Date: Thu, 6 Aug 2015 14:31:15 +0100 Subject: [PATCH 24/28] Remove keymap as not used --- dist/select.bootstrap.js | 116 +++-------------------------------- dist/select.bootstrap.min.js | 4 +- dist/select.css | 2 +- dist/select.js | 116 +++-------------------------------- dist/select.min.css | 2 +- dist/select.min.js | 4 +- dist/select.no-tpl.js | 116 +++-------------------------------- dist/select.no-tpl.min.js | 4 +- dist/select.select2.js | 116 +++-------------------------------- dist/select.select2.min.js | 4 +- dist/select.selectize.js | 116 +++-------------------------------- dist/select.selectize.min.js | 4 +- dist/select.sort.js | 2 +- dist/select.sort.min.js | 2 +- dist/select.tpl.js | 2 +- src/common.js | 104 ------------------------------- 16 files changed, 55 insertions(+), 659 deletions(-) diff --git a/dist/select.bootstrap.js b/dist/select.bootstrap.js index ca874abde..db80cc9fb 100644 --- a/dist/select.bootstrap.js +++ b/dist/select.bootstrap.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-06T11:06:02.027Z + * Version: 0.12.1 - 2015-08-06T13:28:34.955Z * License: MIT */ @@ -28,110 +28,6 @@ var KEY = { DELETE: 46, COMMAND: 91, - MAP: { - 91: "COMMAND", - 8: "BACKSPACE", - 9: "TAB", - 13: "ENTER", - 16: "SHIFT", - 17: "CTRL", - 18: "ALT", - 19: "PAUSEBREAK", - 20: "CAPSLOCK", - 27: "ESC", - 32: "SPACE", - 33: "PAGE_UP", - 34: "PAGE_DOWN", - 35: "END", - 36: "HOME", - 37: "LEFT", - 38: "UP", - 39: "RIGHT", - 40: "DOWN", - 43: "+", - 44: "PRINTSCREEN", - 45: "INSERT", - 46: "DELETE", - 48: "0", - 49: "1", - 50: "2", - 51: "3", - 52: "4", - 53: "5", - 54: "6", - 55: "7", - 56: "8", - 57: "9", - 59: ";", - 61: "=", - 65: "A", - 66: "B", - 67: "C", - 68: "D", - 69: "E", - 70: "F", - 71: "G", - 72: "H", - 73: "I", - 74: "J", - 75: "K", - 76: "L", - 77: "M", - 78: "N", - 79: "O", - 80: "P", - 81: "Q", - 82: "R", - 83: "S", - 84: "T", - 85: "U", - 86: "V", - 87: "W", - 88: "X", - 89: "Y", - 90: "Z", - 96: "0", - 97: "1", - 98: "2", - 99: "3", - 100: "4", - 101: "5", - 102: "6", - 103: "7", - 104: "8", - 105: "9", - 106: "*", - 107: "+", - 109: "-", - 110: ".", - 111: "/", - 112: "F1", - 113: "F2", - 114: "F3", - 115: "F4", - 116: "F5", - 117: "F6", - 118: "F7", - 119: "F8", - 120: "F9", - 121: "F10", - 122: "F11", - 123: "F12", - 144: "NUMLOCK", - 145: "SCROLLLOCK", - 186: ";", - 187: "=", - 188: ",", - 189: "-", - 190: ".", - 191: "/", - 192: "`", - 219: "[", - 220: "\\", - 221: "]", - 222: "'" - }, - isControl: function (e) { var k = e.which; switch (k) { @@ -605,10 +501,10 @@ uis.controller('uiSelectCtrl', return isDisabled; }; - /** * Selects an item. Calls the onBeforeSelect and onSelect callbacks - * onBeforeSelect can alter or abort the selection + * onBeforeSelect is called to allow the user to alter or abort the selection + * onSelect is called to notify the user of the selection * * Called when the user selects an item with ENTER or clicks the dropdown */ @@ -1255,7 +1151,11 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel $select.sizeSearchInput(); }; - // Remove item from multiple select + /** + * Remove item from multiple select + * Calls onBeforeRemove to allow the user to prevent the removal of the item + * Then calls onRemove to notify the user the item has been removed + */ ctrl.removeChoice = function (index) { var removedChoice = $select.selected[index]; diff --git a/dist/select.bootstrap.min.js b/dist/select.bootstrap.min.js index a72fde445..a77b8ca17 100644 --- a/dist/select.bootstrap.min.js +++ b/dist/select.bootstrap.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-06T11:06:02.027Z + * Version: 0.12.1 - 2015-08-06T13:28:34.955Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var n=t.which;switch(n){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,n=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,i,c){c(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var i=n[0].getBoundingClientRect();return{width:i.width||n.prop("offsetWidth"),height:i.height||n.prop("offsetHeight"),top:i.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:i.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);n.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,c){if(!c.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,c,l,s,r){var a=l.groupBy,o=l.groupFilter;if(s.parseRepeatAttr(l.repeat,a,o),s.disableChoiceExpression=l.uiDisableChoice,s.onHighlightCallback=l.onHighlight,a){var u=c.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=c.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(s.parserResult.itemName,"$select.items",s.parserResult.trackByExp,a)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+s.parserResult.itemName+")").attr("ng-click","$select.select("+s.parserResult.itemName+",false,$event)");var d=c.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),i(c,r)(e),e.$watch("$select.search",function(e){e&&!s.open&&s.multiple&&s.activate(!1,!0),s.activeIndex=0})}}}}]),n.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,n,i,c,l,s,r,a){function o(){(h.resetSearchInput||void 0===h.resetSearchInput&&a.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var n,i,c=[];for(n=0;n0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:n=!1}return n}function d(){var e=n.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw r("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var i=t[h.activeIndex],c=i.offsetTop+i.clientHeight-e[0].scrollTop,l=e[0].offsetHeight;c>l?e[0].scrollTop+=c-l:c=h.items.length?0:h.activeIndex,i(function(){h.search=e||h.search,h.searchInput[0].focus()})},l=h.onDropdownCallback(t,{open:!0});angular.isDefined(l)?angular.isFunction(l.then)?l.then(function(e){e&&c()}):l===!0?c():l&&c():c()}},h.parseRepeatAttr=function(e,n,i){function c(e){var c=t.$eval(n);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(c)?c(e):e[c],n=h.findGroupByName(t);n?n.items.push(e):h.groups.push({name:t,items:[e]})}),i){var l=t.$eval(i);angular.isFunction(l)?h.groups=l(h.groups):angular.isArray(l)&&(h.groups=u(h.groups,l))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function l(e){h.items=e}h.setItemsFn=n?c:l,h.parserResult=s.parse(e),h.isGrouped=!!n,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var n=h.selected;if(h.isEmpty()||angular.isArray(n)&&!n.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var i=e.filter(function(e){return n.indexOf(e)<0});h.setItemsFn(i)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw r("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),n=-1===t?!1:t===h.activeIndex;return n&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),n},h.isDisabled=function(e){if(!h.open)return!1;var t,n=h.items.indexOf(e[h.itemProperty]),i=!1;return n>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[n],i=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i},h.select=function(e,n,c){if((void 0===e||!e._uiSelectChoiceDisabled)&&(h.items||h.search)){var l={};l[h.parserResult.itemName]=e;var s={$item:e,$model:h.parserResult.modelMapper(t,l)},r=function(e){s.$item=e,t.$broadcast("uis:select",e),i(function(){h.onSelectCallback(t,s)}),h.closeOnSelect&&h.close(n),c&&"click"===c.type&&(h.clickTriggeredSelect=!0)};if(!angular.isDefined(h.onBeforeRemoveCallback))return r(e),void 0;var a=h.onBeforeSelectCallback(t,s);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(t){t&&(t===!0?r(e):t&&r(t))}):a===!0?r(e):a&&r(a):r(e)}},h.close=function(e){function n(){h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),o(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e)}if(h.open){var i=h.onDropdownCallback(t,{open:!1});angular.isDefined(i)?angular.isFunction(i.then)?i.then(function(e){e&&n()}):i===!0?n():i&&n():n()}},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),i(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var n,i=h.selected[t];return i&&!angular.isUndefined(h.lockChoiceExpression)&&(n=!!e.$eval(h.lockChoiceExpression),i._uiSelectChoiceLocked=n),n};var g=null;h.sizeSearchInput=function(){var e=h.searchInput[0],n=h.searchInput.parent().parent()[0],c=function(){return n.clientWidth*!!e.offsetParent},l=function(t){if(0===t)return!1;var n=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=t),h.searchInput.css("width",n+"px"),!0};h.searchInput.css("width","10px"),i(function(){null!==g||l(c())||(g=t.$watch(c,function(e){l(e)&&(g(),g=null)}))})},h.searchInput.on("keydown",function(n){var i=n.which;t.$apply(function(){p(i)}),e.isVerticalMovement(i)&&h.items.length>0&&d(),(i===e.ENTER||i===e.ESC)&&(n.preventDefault(),n.stopPropagation())}),h.searchInput.on("keyup",function(n){n.which===e.TAB||e.isControl(n)||e.isFunctionKey(n)||n.which===e.ESC||e.isVerticalMovement(n.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:n})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),n.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,i,c,l,s,r){return{restrict:"EA",templateUrl:function(e,t){var i=t.theme||n.theme;return i+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(l,a){return angular.isDefined(a.multiple)?l.append("").removeAttr("multiple"):l.append(""),function(l,a,o,u,p){function d(e){if(g.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(a[0],e.target):a[0].contains(e.target),!t&&!g.clickTriggeredSelect){var n=["input","button","textarea"],i=angular.element(e.target).scope(),c=i&&i.$select&&i.$select!==g;c||(c=~n.indexOf(e.target.tagName.toLowerCase())),g.close(c),l.$digest()}g.clickTriggeredSelect=!1}}function h(){var t=c(a);E=angular.element('
    '),E[0].style.width=t.width+"px",E[0].style.height=t.height+"px",a.after(E),w=a[0].style.width,e.find("body").append(a),a[0].style.position="absolute",a[0].style.left=t.left+"px",a[0].style.top=t.top+"px",a[0].style.width=t.width+"px"}function f(){null!==E&&(E.replaceWith(a),E=null,a[0].style.position="",a[0].style.left="",a[0].style.top="",a[0].style.width=w)}var g=u[0],v=u[1];g.generatedId=n.generateId(),g.baseTitle=o.title||"Select box",g.focusserTitle=g.baseTitle+" focus",g.focusserId="focusser-"+g.generatedId,g.closeOnSelect=function(){return angular.isDefined(o.closeOnSelect)?s(o.closeOnSelect)():n.closeOnSelect}(),g.onSelectCallback=s(o.onSelect),g.onBeforeSelectCallback=s(o.onBeforeSelect),g.onRemoveCallback=s(o.onRemove),g.onBeforeRemoveCallback=s(o.onBeforeRemove),g.onKeypressCallback=s(o.onKeypress),g.onDropdownCallback=s(o.onDropdown),g.limit=angular.isDefined(o.limit)?parseInt(o.limit,10):void 0,g.ngModel=v,g.choiceGrouped=function(e){return g.isGrouped&&e&&e.name},o.tabindex&&o.$observe("tabindex",function(e){g.focusInput.attr("tabindex",e),a.removeAttr("tabindex")});var m=l.$eval(o.searchEnabled);g.searchEnabled=void 0!==m?m:n.searchEnabled;var $=l.$eval(o.sortable);g.sortable=void 0!==$?$:n.sortable,o.$observe("disabled",function(){g.disabled=void 0!==o.disabled?o.disabled:!1}),angular.isDefined(o.autofocus)&&r(function(){g.setFocus()}),angular.isDefined(o.focusOn)&&l.$on(o.focusOn,function(){r(function(){g.setFocus()})}),e.on("click",d),l.$on("$destroy",function(){e.off("click",d)}),p(l,function(e){var t=angular.element("
    ").append(e),n=t.querySelectorAll(".ui-select-match");if(n.removeAttr("ui-select-match"),n.removeAttr("data-ui-select-match"),1!==n.length)throw i("transcluded","Expected 1 .ui-select-match but got '{0}'.",n.length);a.querySelectorAll(".ui-select-match").replaceWith(n);var c=t.querySelectorAll(".ui-select-choices");if(c.removeAttr("ui-select-choices"),c.removeAttr("data-ui-select-choices"),1!==c.length)throw i("transcluded","Expected 1 .ui-select-choices but got '{0}'.",c.length);a.querySelectorAll(".ui-select-choices").replaceWith(c)});var b=l.$eval(o.appendToBody);(void 0!==b?b:n.appendToBody)&&(l.$watch("$select.open",function(e){e?h():f()}),l.$on("$destroy",function(){f()}));var E=null,w="",x=null,S="direction-up";l.$watch("$select.open",function(n){if(n){if(x=angular.element(a).querySelectorAll(".ui-select-dropdown"),null===x)return;x[0].style.opacity=0,r(function(){var n=c(a),i=c(x);n.top+n.height+i.height>t.pageYOffset+e[0].documentElement.clientHeight&&a.addClass(S),x[0].style.opacity=1})}else{if(null===x)return;a.removeClass(S)}})}}}}]),n.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return n+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,i,c){function l(e){c.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}c.lockChoiceExpression=i.uiLockChoice,i.$observe("placeholder",function(t){c.placeholder=void 0!==t?t:e.placeholder}),i.$observe("allowClear",l),l(i.allowClear),c.multiple&&c.sizeSearchInput()}}}]),n.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,i=this,c=e.$select;e.$evalAsync(function(){n=e.ngModel}),i.activeMatchIndex=-1,i.updateModel=function(){n.$setViewValue(Date.now()),i.refreshComponent()},i.refreshComponent=function(){c.refreshItems(),c.sizeSearchInput()},i.removeChoice=function(n){function l(){t(function(){c.onRemoveCallback(e,a)}),i.updateModel()}var s=c.selected[n];if(!s._uiSelectChoiceLocked){var r={};r[c.parserResult.itemName]=s,c.selected.splice(n,1),i.activeMatchIndex=-1,c.sizeSearchInput();var a={$item:s,$model:c.parserResult.modelMapper(e,r)};if(!angular.isDefined(i.onBeforeRemoveCallback))return l(),void 0;var o=i.onBeforeRemoveCallback(e,a);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(e){e&&l(e)}):o===!0&&l():l()}},i.getPlaceholder=function(){return c.selected&&c.selected.length?void 0:c.placeholder}}],controllerAs:"$selectMultiple",link:function(i,c,l,s){function r(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(t){function n(){switch(t){case e.LEFT:return~p.activeMatchIndex?d:s;case e.RIGHT:return~p.activeMatchIndex&&a!==s?u:(o.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(a),d):s;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),a):!1}}var i=r(o.searchInput[0]),c=o.selected.length,l=0,s=c-1,a=p.activeMatchIndex,u=p.activeMatchIndex+1,d=p.activeMatchIndex-1,h=a;return i>0||o.search.length&&t==e.RIGHT?!1:(o.close(),h=n(),p.activeMatchIndex=o.selected.length&&h!==!1?Math.min(s,Math.max(l,h)):-1,!0)}var o=s[0],u=i.ngModel=s[1],p=i.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,u.$parsers.unshift(function(){for(var e,t={},n=[],c=o.selected.length-1;c>=0;c--)t={},t[o.parserResult.itemName]=o.selected[c],e=o.parserResult.modelMapper(i,t),n.unshift(e);return n}),u.$formatters.unshift(function(e){var t,n=o.parserResult.source(i,{$select:{search:""}}),c={};if(!n)return e;var l=[],s=function(e,n){if(e&&e.length){for(var s=e.length-1;s>=0;s--){if(c[o.parserResult.itemName]=e[s],t=o.parserResult.modelMapper(i,c),o.parserResult.trackByExp){var r=/\.(.+)/.exec(o.parserResult.trackByExp);if(r.length>0&&t[r[1]]==n[r[1]])return l.unshift(e[s]),!0}if(angular.equals(t,n))return l.unshift(e[s]),!0}return!1}};if(!e)return l;for(var r=e.length-1;r>=0;r--)s(o.selected,e[r])||s(n,e[r])||l.unshift(e[r]);return l}),i.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);o.selected=[]}o.selected=u.$viewValue,i.$evalAsync()},i.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),p.updateModel())}),i.$on("uis:activate",function(){p.activeMatchIndex=-1}),i.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(t){var n=t.which;i.$apply(function(){var t=!1;e.isHorizontalMovement(n)&&(t=a(n)),t&&n!=e.TAB})}),o.searchInput.on("blur",function(){n(function(){p.activeMatchIndex=-1})})}}}]),n.directive("uiSelectSingle",["$timeout","$compile",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(i,c,l,s){var r=s[0],a=s[1];a.$parsers.unshift(function(e){var t,n={};return n[r.parserResult.itemName]=e,t=r.parserResult.modelMapper(i,n)}),a.$formatters.unshift(function(e){var t,n=r.parserResult.source(i,{$select:{search:""}}),c={};if(n){var l=function(n){return c[r.parserResult.itemName]=n,t=r.parserResult.modelMapper(i,c),t==e};if(r.selected&&l(r.selected))return r.selected;for(var s=n.length-1;s>=0;s--)if(l(n[s]))return n[s]}return e}),i.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){r.selected=a.$viewValue},i.$on("uis:select",function(e,t){r.selected=t}),i.$on("uis:close",function(e,n){t(function(){r.focusser.prop("disabled",!1),n||r.focusser[0].focus()},0,!1)}),i.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");n(o)(i),r.focusser=o,r.focusInput=o,c.parent().append(o),o.bind("focus",function(){i.$evalAsync(function(){r.focus=!0})}),o.bind("blur",function(){i.$evalAsync(function(){r.focus=!1})}),o.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),r.select(void 0),i.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),r.activate()),i.$digest()),void 0)}),o.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(r.activate(o.val()),o.val(""),i.$digest())})}}}]),n.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var i=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!i)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:i[2],source:t(i[3]),trackByExp:i[4],modelMapper:t(i[1]||i[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,i){var c=e+" in "+(i?"$group.items":t);return n&&(c+=" track by "+n),c}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",'
    {{$select.placeholder}}
    '),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",'')}]); \ No newline at end of file +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,isControl:function(t){var n=t.which;switch(n){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,n=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,i,c){c(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var i=n[0].getBoundingClientRect();return{width:i.width||n.prop("offsetWidth"),height:i.height||n.prop("offsetHeight"),top:i.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:i.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);n.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,c){if(!c.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,c,l,s,r){var a=l.groupBy,o=l.groupFilter;if(s.parseRepeatAttr(l.repeat,a,o),s.disableChoiceExpression=l.uiDisableChoice,s.onHighlightCallback=l.onHighlight,a){var u=c.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=c.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(s.parserResult.itemName,"$select.items",s.parserResult.trackByExp,a)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+s.parserResult.itemName+")").attr("ng-click","$select.select("+s.parserResult.itemName+",false,$event)");var d=c.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),i(c,r)(e),e.$watch("$select.search",function(e){e&&!s.open&&s.multiple&&s.activate(!1,!0),s.activeIndex=0})}}}}]),n.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,n,i,c,l,s,r,a){function o(){(h.resetSearchInput||void 0===h.resetSearchInput&&a.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var n,i,c=[];for(n=0;n0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:n=!1}return n}function d(){var e=n.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw r("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var i=t[h.activeIndex],c=i.offsetTop+i.clientHeight-e[0].scrollTop,l=e[0].offsetHeight;c>l?e[0].scrollTop+=c-l:c=h.items.length?0:h.activeIndex,i(function(){h.search=e||h.search,h.searchInput[0].focus()})},l=h.onDropdownCallback(t,{open:!0});angular.isDefined(l)?angular.isFunction(l.then)?l.then(function(e){e&&c()}):l===!0?c():l&&c():c()}},h.parseRepeatAttr=function(e,n,i){function c(e){var c=t.$eval(n);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(c)?c(e):e[c],n=h.findGroupByName(t);n?n.items.push(e):h.groups.push({name:t,items:[e]})}),i){var l=t.$eval(i);angular.isFunction(l)?h.groups=l(h.groups):angular.isArray(l)&&(h.groups=u(h.groups,l))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function l(e){h.items=e}h.setItemsFn=n?c:l,h.parserResult=s.parse(e),h.isGrouped=!!n,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var n=h.selected;if(h.isEmpty()||angular.isArray(n)&&!n.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var i=e.filter(function(e){return n.indexOf(e)<0});h.setItemsFn(i)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw r("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),n=-1===t?!1:t===h.activeIndex;return n&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),n},h.isDisabled=function(e){if(!h.open)return!1;var t,n=h.items.indexOf(e[h.itemProperty]),i=!1;return n>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[n],i=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i},h.select=function(e,n,c){if((void 0===e||!e._uiSelectChoiceDisabled)&&(h.items||h.search)){var l={};l[h.parserResult.itemName]=e;var s={$item:e,$model:h.parserResult.modelMapper(t,l)},r=function(e){s.$item=e,t.$broadcast("uis:select",e),i(function(){h.onSelectCallback(t,s)}),h.closeOnSelect&&h.close(n),c&&"click"===c.type&&(h.clickTriggeredSelect=!0)};if(!angular.isDefined(h.onBeforeRemoveCallback))return r(e),void 0;var a=h.onBeforeSelectCallback(t,s);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(t){t&&(t===!0?r(e):t&&r(t))}):a===!0?r(e):a&&r(a):r(e)}},h.close=function(e){function n(){h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),o(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e)}if(h.open){var i=h.onDropdownCallback(t,{open:!1});angular.isDefined(i)?angular.isFunction(i.then)?i.then(function(e){e&&n()}):i===!0?n():i&&n():n()}},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),i(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var n,i=h.selected[t];return i&&!angular.isUndefined(h.lockChoiceExpression)&&(n=!!e.$eval(h.lockChoiceExpression),i._uiSelectChoiceLocked=n),n};var g=null;h.sizeSearchInput=function(){var e=h.searchInput[0],n=h.searchInput.parent().parent()[0],c=function(){return n.clientWidth*!!e.offsetParent},l=function(t){if(0===t)return!1;var n=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=t),h.searchInput.css("width",n+"px"),!0};h.searchInput.css("width","10px"),i(function(){null!==g||l(c())||(g=t.$watch(c,function(e){l(e)&&(g(),g=null)}))})},h.searchInput.on("keydown",function(n){var i=n.which;t.$apply(function(){p(i)}),e.isVerticalMovement(i)&&h.items.length>0&&d(),(i===e.ENTER||i===e.ESC)&&(n.preventDefault(),n.stopPropagation())}),h.searchInput.on("keyup",function(n){n.which===e.TAB||e.isControl(n)||e.isFunctionKey(n)||n.which===e.ESC||e.isVerticalMovement(n.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:n})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),n.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,i,c,l,s,r){return{restrict:"EA",templateUrl:function(e,t){var i=t.theme||n.theme;return i+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(l,a){return angular.isDefined(a.multiple)?l.append("").removeAttr("multiple"):l.append(""),function(l,a,o,u,p){function d(e){if(g.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(a[0],e.target):a[0].contains(e.target),!t&&!g.clickTriggeredSelect){var n=["input","button","textarea"],i=angular.element(e.target).scope(),c=i&&i.$select&&i.$select!==g;c||(c=~n.indexOf(e.target.tagName.toLowerCase())),g.close(c),l.$digest()}g.clickTriggeredSelect=!1}}function h(){var t=c(a);w=angular.element('
    '),w[0].style.width=t.width+"px",w[0].style.height=t.height+"px",a.after(w),x=a[0].style.width,e.find("body").append(a),a[0].style.position="absolute",a[0].style.left=t.left+"px",a[0].style.top=t.top+"px",a[0].style.width=t.width+"px"}function f(){null!==w&&(w.replaceWith(a),w=null,a[0].style.position="",a[0].style.left="",a[0].style.top="",a[0].style.width=x)}var g=u[0],v=u[1];g.generatedId=n.generateId(),g.baseTitle=o.title||"Select box",g.focusserTitle=g.baseTitle+" focus",g.focusserId="focusser-"+g.generatedId,g.closeOnSelect=function(){return angular.isDefined(o.closeOnSelect)?s(o.closeOnSelect)():n.closeOnSelect}(),g.onSelectCallback=s(o.onSelect),g.onBeforeSelectCallback=s(o.onBeforeSelect),g.onRemoveCallback=s(o.onRemove),g.onBeforeRemoveCallback=s(o.onBeforeRemove),g.onKeypressCallback=s(o.onKeypress),g.onDropdownCallback=s(o.onDropdown),g.limit=angular.isDefined(o.limit)?parseInt(o.limit,10):void 0,g.ngModel=v,g.choiceGrouped=function(e){return g.isGrouped&&e&&e.name},o.tabindex&&o.$observe("tabindex",function(e){g.focusInput.attr("tabindex",e),a.removeAttr("tabindex")});var m=l.$eval(o.searchEnabled);g.searchEnabled=void 0!==m?m:n.searchEnabled;var $=l.$eval(o.sortable);g.sortable=void 0!==$?$:n.sortable,o.$observe("disabled",function(){g.disabled=void 0!==o.disabled?o.disabled:!1}),angular.isDefined(o.autofocus)&&r(function(){g.setFocus()}),angular.isDefined(o.focusOn)&&l.$on(o.focusOn,function(){r(function(){g.setFocus()})}),e.on("click",d),l.$on("$destroy",function(){e.off("click",d)}),p(l,function(e){var t=angular.element("
    ").append(e),n=t.querySelectorAll(".ui-select-match");if(n.removeAttr("ui-select-match"),n.removeAttr("data-ui-select-match"),1!==n.length)throw i("transcluded","Expected 1 .ui-select-match but got '{0}'.",n.length);a.querySelectorAll(".ui-select-match").replaceWith(n);var c=t.querySelectorAll(".ui-select-choices");if(c.removeAttr("ui-select-choices"),c.removeAttr("data-ui-select-choices"),1!==c.length)throw i("transcluded","Expected 1 .ui-select-choices but got '{0}'.",c.length);a.querySelectorAll(".ui-select-choices").replaceWith(c)});var b=l.$eval(o.appendToBody);(void 0!==b?b:n.appendToBody)&&(l.$watch("$select.open",function(e){e?h():f()}),l.$on("$destroy",function(){f()}));var w=null,x="",E=null,y="direction-up";l.$watch("$select.open",function(n){if(n){if(E=angular.element(a).querySelectorAll(".ui-select-dropdown"),null===E)return;E[0].style.opacity=0,r(function(){var n=c(a),i=c(E);n.top+n.height+i.height>t.pageYOffset+e[0].documentElement.clientHeight&&a.addClass(y),E[0].style.opacity=1})}else{if(null===E)return;a.removeClass(y)}})}}}}]),n.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return n+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,i,c){function l(e){c.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}c.lockChoiceExpression=i.uiLockChoice,i.$observe("placeholder",function(t){c.placeholder=void 0!==t?t:e.placeholder}),i.$observe("allowClear",l),l(i.allowClear),c.multiple&&c.sizeSearchInput()}}}]),n.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,i=this,c=e.$select;e.$evalAsync(function(){n=e.ngModel}),i.activeMatchIndex=-1,i.updateModel=function(){n.$setViewValue(Date.now()),i.refreshComponent()},i.refreshComponent=function(){c.refreshItems(),c.sizeSearchInput()},i.removeChoice=function(n){function l(){t(function(){c.onRemoveCallback(e,a)}),i.updateModel()}var s=c.selected[n];if(!s._uiSelectChoiceLocked){var r={};r[c.parserResult.itemName]=s,c.selected.splice(n,1),i.activeMatchIndex=-1,c.sizeSearchInput();var a={$item:s,$model:c.parserResult.modelMapper(e,r)};if(!angular.isDefined(i.onBeforeRemoveCallback))return l(),void 0;var o=i.onBeforeRemoveCallback(e,a);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(e){e&&l(e)}):o===!0&&l():l()}},i.getPlaceholder=function(){return c.selected&&c.selected.length?void 0:c.placeholder}}],controllerAs:"$selectMultiple",link:function(i,c,l,s){function r(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(t){function n(){switch(t){case e.LEFT:return~p.activeMatchIndex?d:s;case e.RIGHT:return~p.activeMatchIndex&&a!==s?u:(o.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(a),d):s;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),a):!1}}var i=r(o.searchInput[0]),c=o.selected.length,l=0,s=c-1,a=p.activeMatchIndex,u=p.activeMatchIndex+1,d=p.activeMatchIndex-1,h=a;return i>0||o.search.length&&t==e.RIGHT?!1:(o.close(),h=n(),p.activeMatchIndex=o.selected.length&&h!==!1?Math.min(s,Math.max(l,h)):-1,!0)}var o=s[0],u=i.ngModel=s[1],p=i.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,u.$parsers.unshift(function(){for(var e,t={},n=[],c=o.selected.length-1;c>=0;c--)t={},t[o.parserResult.itemName]=o.selected[c],e=o.parserResult.modelMapper(i,t),n.unshift(e);return n}),u.$formatters.unshift(function(e){var t,n=o.parserResult.source(i,{$select:{search:""}}),c={};if(!n)return e;var l=[],s=function(e,n){if(e&&e.length){for(var s=e.length-1;s>=0;s--){if(c[o.parserResult.itemName]=e[s],t=o.parserResult.modelMapper(i,c),o.parserResult.trackByExp){var r=/\.(.+)/.exec(o.parserResult.trackByExp);if(r.length>0&&t[r[1]]==n[r[1]])return l.unshift(e[s]),!0}if(angular.equals(t,n))return l.unshift(e[s]),!0}return!1}};if(!e)return l;for(var r=e.length-1;r>=0;r--)s(o.selected,e[r])||s(n,e[r])||l.unshift(e[r]);return l}),i.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);o.selected=[]}o.selected=u.$viewValue,i.$evalAsync()},i.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),p.updateModel())}),i.$on("uis:activate",function(){p.activeMatchIndex=-1}),i.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(t){var n=t.which;i.$apply(function(){var t=!1;e.isHorizontalMovement(n)&&(t=a(n)),t&&n!=e.TAB})}),o.searchInput.on("blur",function(){n(function(){p.activeMatchIndex=-1})})}}}]),n.directive("uiSelectSingle",["$timeout","$compile",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(i,c,l,s){var r=s[0],a=s[1];a.$parsers.unshift(function(e){var t,n={};return n[r.parserResult.itemName]=e,t=r.parserResult.modelMapper(i,n)}),a.$formatters.unshift(function(e){var t,n=r.parserResult.source(i,{$select:{search:""}}),c={};if(n){var l=function(n){return c[r.parserResult.itemName]=n,t=r.parserResult.modelMapper(i,c),t==e};if(r.selected&&l(r.selected))return r.selected;for(var s=n.length-1;s>=0;s--)if(l(n[s]))return n[s]}return e}),i.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){r.selected=a.$viewValue},i.$on("uis:select",function(e,t){r.selected=t}),i.$on("uis:close",function(e,n){t(function(){r.focusser.prop("disabled",!1),n||r.focusser[0].focus()},0,!1)}),i.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");n(o)(i),r.focusser=o,r.focusInput=o,c.parent().append(o),o.bind("focus",function(){i.$evalAsync(function(){r.focus=!0})}),o.bind("blur",function(){i.$evalAsync(function(){r.focus=!1})}),o.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),r.select(void 0),i.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),r.activate()),i.$digest()),void 0)}),o.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(r.activate(o.val()),o.val(""),i.$digest())})}}}]),n.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var i=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!i)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:i[2],source:t(i[3]),trackByExp:i[4],modelMapper:t(i[1]||i[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,i){var c=e+" in "+(i?"$group.items":t);return n&&(c+=" track by "+n),c}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",'
    {{$select.placeholder}}
    '),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",'')}]); \ No newline at end of file diff --git a/dist/select.css b/dist/select.css index 13172b0c4..dc3621f62 100644 --- a/dist/select.css +++ b/dist/select.css @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-06T11:06:02.064Z + * Version: 0.12.1 - 2015-08-06T13:28:34.992Z * License: MIT */ diff --git a/dist/select.js b/dist/select.js index 262810533..58cfbfac6 100644 --- a/dist/select.js +++ b/dist/select.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-06T11:06:02.062Z + * Version: 0.12.1 - 2015-08-06T13:28:34.991Z * License: MIT */ @@ -173,110 +173,6 @@ var KEY = { DELETE: 46, COMMAND: 91, - MAP: { - 91: "COMMAND", - 8: "BACKSPACE", - 9: "TAB", - 13: "ENTER", - 16: "SHIFT", - 17: "CTRL", - 18: "ALT", - 19: "PAUSEBREAK", - 20: "CAPSLOCK", - 27: "ESC", - 32: "SPACE", - 33: "PAGE_UP", - 34: "PAGE_DOWN", - 35: "END", - 36: "HOME", - 37: "LEFT", - 38: "UP", - 39: "RIGHT", - 40: "DOWN", - 43: "+", - 44: "PRINTSCREEN", - 45: "INSERT", - 46: "DELETE", - 48: "0", - 49: "1", - 50: "2", - 51: "3", - 52: "4", - 53: "5", - 54: "6", - 55: "7", - 56: "8", - 57: "9", - 59: ";", - 61: "=", - 65: "A", - 66: "B", - 67: "C", - 68: "D", - 69: "E", - 70: "F", - 71: "G", - 72: "H", - 73: "I", - 74: "J", - 75: "K", - 76: "L", - 77: "M", - 78: "N", - 79: "O", - 80: "P", - 81: "Q", - 82: "R", - 83: "S", - 84: "T", - 85: "U", - 86: "V", - 87: "W", - 88: "X", - 89: "Y", - 90: "Z", - 96: "0", - 97: "1", - 98: "2", - 99: "3", - 100: "4", - 101: "5", - 102: "6", - 103: "7", - 104: "8", - 105: "9", - 106: "*", - 107: "+", - 109: "-", - 110: ".", - 111: "/", - 112: "F1", - 113: "F2", - 114: "F3", - 115: "F4", - 116: "F5", - 117: "F6", - 118: "F7", - 119: "F8", - 120: "F9", - 121: "F10", - 122: "F11", - 123: "F12", - 144: "NUMLOCK", - 145: "SCROLLLOCK", - 186: ";", - 187: "=", - 188: ",", - 189: "-", - 190: ".", - 191: "/", - 192: "`", - 219: "[", - 220: "\\", - 221: "]", - 222: "'" - }, - isControl: function (e) { var k = e.which; switch (k) { @@ -750,10 +646,10 @@ uis.controller('uiSelectCtrl', return isDisabled; }; - /** * Selects an item. Calls the onBeforeSelect and onSelect callbacks - * onBeforeSelect can alter or abort the selection + * onBeforeSelect is called to allow the user to alter or abort the selection + * onSelect is called to notify the user of the selection * * Called when the user selects an item with ENTER or clicks the dropdown */ @@ -1400,7 +1296,11 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel $select.sizeSearchInput(); }; - // Remove item from multiple select + /** + * Remove item from multiple select + * Calls onBeforeRemove to allow the user to prevent the removal of the item + * Then calls onRemove to notify the user the item has been removed + */ ctrl.removeChoice = function (index) { var removedChoice = $select.selected[index]; diff --git a/dist/select.min.css b/dist/select.min.css index eca8ae81e..577716b16 100644 --- a/dist/select.min.css +++ b/dist/select.min.css @@ -1,6 +1,6 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-06T11:06:02.064Z + * Version: 0.12.1 - 2015-08-06T13:28:34.992Z * License: MIT */.ui-select-highlight{font-weight:700}.ui-select-offscreen{clip:rect(0 0 0 0)!important;width:1px!important;height:1px!important;border:0!important;margin:0!important;padding:0!important;overflow:hidden!important;position:absolute!important;outline:0!important;left:0!important;top:0!important}.ng-dirty.ng-invalid>a.select2-choice{border-color:#D44950}.select2-result-single{padding-left:0}.select-locked>.ui-select-match-close,.select2-locked>.select2-search-choice-close{display:none}body>.select2-container.open{z-index:9999}.ui-select-container[theme=select2].direction-up .ui-select-match{border-radius:0 0 4px 4px}.ui-select-container[theme=select2].direction-up .ui-select-dropdown{bottom:100%;top:auto;position:absolute;border-radius:4px 4px 0 0;border-top-width:1px;border-top-style:solid;box-shadow:0 -4px 8px rgba(0,0,0,.25);margin-top:-4px}.ui-select-container[theme=select2].direction-up .ui-select-dropdown .select2-search{margin-top:4px}.ui-select-container[theme=select2].direction-up.select2-dropdown-open .ui-select-match{border-bottom-color:#5897fb}.selectize-input.selectize-focus{border-color:#007FBB!important}.selectize-control>.selectize-dropdown,.selectize-control>.selectize-input>input{width:100%}.ng-dirty.ng-invalid>div.selectize-input{border-color:#D44950}.ui-select-container[theme=selectize].direction-up .ui-select-dropdown{bottom:100%;top:auto;position:absolute;box-shadow:0 -4px 8px rgba(0,0,0,.25);margin-top:-2px}.btn-default-focus{color:#333;background-color:#EBEBEB;border-color:#ADADAD;text-decoration:none;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.ui-select-bootstrap .ui-select-toggle{position:relative}.ui-select-bootstrap .ui-select-toggle>.caret{position:absolute;height:10px;top:50%;right:10px;margin-top:-2px}.input-group>.ui-select-bootstrap.dropdown{position:static}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control{border-radius:4px 0 0 4px}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control.direction-up{border-radius:4px 0 0 4px!important}.ui-select-bootstrap>.ui-select-match>.btn{text-align:left!important}.ui-select-bootstrap>.ui-select-match>.caret{position:absolute;top:45%;right:15px}.ui-select-bootstrap>.ui-select-choices{width:100%;height:auto;max-height:200px;overflow-x:hidden;margin-top:-1px}body>.ui-select-bootstrap.open{z-index:1000}.ui-select-multiple.ui-select-bootstrap{height:auto;padding:3px 3px 0}.ui-select-multiple.ui-select-bootstrap input.ui-select-search{background-color:transparent!important;border:none;outline:0;height:1.666666em;margin-bottom:3px}.ui-select-multiple.ui-select-bootstrap .ui-select-match .close{font-size:1.6em;line-height:.75}.ui-select-multiple.ui-select-bootstrap .ui-select-match-item{outline:0;margin:0 3px 3px 0}.ui-select-multiple .ui-select-match-item{position:relative}.ui-select-multiple .ui-select-match-item.dropping-before:before{content:"";position:absolute;top:0;right:100%;height:100%;margin-right:2px;border-left:1px solid #428bca}.ui-select-multiple .ui-select-match-item.dropping-after:after{content:"";position:absolute;top:0;left:100%;height:100%;margin-left:2px;border-right:1px solid #428bca}.ui-select-bootstrap .ui-select-placeholder{opacity:1;color:#999}.ui-select-bootstrap .ui-select-choices-row>a{display:block;padding:3px 20px;clear:both;font-weight:400;line-height:1.42857143;color:#333;white-space:nowrap}.ui-select-bootstrap .ui-select-choices-row>a:focus,.ui-select-bootstrap .ui-select-choices-row>a:hover{text-decoration:none;color:#262626;background-color:#f5f5f5}.ui-select-bootstrap .ui-select-choices-row.active>a{color:#fff;text-decoration:none;outline:0;background-color:#428bca}.ui-select-bootstrap .ui-select-choices-row.active.disabled>a,.ui-select-bootstrap .ui-select-choices-row.disabled>a{color:#777;cursor:not-allowed;background-color:#fff}.ui-select-match.ng-hide-add,.ui-select-search.ng-hide-add{display:none!important}.ui-select-bootstrap.ng-dirty.ng-invalid>button.btn.ui-select-match{border-color:#D44950}.ui-select-container[theme=bootstrap].direction-up .ui-select-dropdown{bottom:100%;top:auto;position:absolute;box-shadow:0 -4px 8px rgba(0,0,0,.25)} \ No newline at end of file diff --git a/dist/select.min.js b/dist/select.min.js index 7190347e5..385a28898 100644 --- a/dist/select.min.js +++ b/dist/select.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-06T11:06:02.062Z + * Version: 0.12.1 - 2015-08-06T13:28:34.991Z * License: MIT */ -!function(){"use strict";angular.module("ui.select.sort",["ui.select"]).directive("uiSelectSort",["$timeout","uiSelectConfig","uiSelectMinErr",function(e,t,c){return{require:"^uiSelect",link:function(t,l,s,i){if(null===t[s.uiSelectSort])throw c("sort","Expected a list to sort");var n=angular.extend({axis:"horizontal"},t.$eval(s.uiSelectSortOptions)),a=n.axis,r="dragging",o="dropping",u="dropping-before",d="dropping-after";t.$watch(function(){return i.sortable},function(e){e?l.attr("draggable",!0):l.removeAttr("draggable")}),l.on("dragstart",function(e){l.addClass(r),(e.dataTransfer||e.originalEvent.dataTransfer).setData("text/plain",t.$index)}),l.on("dragend",function(){l.removeClass(r)});var p,h=function(e,t){this.splice(t,0,this.splice(e,1)[0])},f=function(e){e.preventDefault();var t="vertical"===a?e.offsetY||e.layerY||(e.originalEvent?e.originalEvent.offsetY:0):e.offsetX||e.layerX||(e.originalEvent?e.originalEvent.offsetX:0);t=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],c=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(c.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,c=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,l,s){s(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(c){var l=c[0].getBoundingClientRect();return{width:l.width||c.prop("offsetWidth"),height:l.height||c.prop("offsetHeight"),top:l.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:l.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);c.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,c,l){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(e,s){if(!s.repeat)throw c("repeat","Expected 'repeat' expression.");return function(e,s,i,n,a){var r=i.groupBy,o=i.groupFilter;if(n.parseRepeatAttr(i.repeat,r,o),n.disableChoiceExpression=i.uiDisableChoice,n.onHighlightCallback=i.onHighlight,r){var u=s.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=s.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(n.parserResult.itemName,"$select.items",n.parserResult.trackByExp,r)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+n.parserResult.itemName+")").attr("ng-click","$select.select("+n.parserResult.itemName+",false,$event)");var p=s.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),l(s,a)(e),e.$watch("$select.search",function(e){e&&!n.open&&n.multiple&&n.activate(!1,!0),n.activeIndex=0})}}}}]),c.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,c,l,s,i,n,a,r){function o(){(h.resetSearchInput||void 0===h.resetSearchInput&&r.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var c,l,s=[];for(c=0;c0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:c=!1}return c}function p(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw a("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var l=t[h.activeIndex],s=l.offsetTop+l.clientHeight-e[0].scrollTop,i=e[0].offsetHeight;s>i?e[0].scrollTop+=s-i:s=h.items.length?0:h.activeIndex,l(function(){h.search=e||h.search,h.searchInput[0].focus()})},i=h.onDropdownCallback(t,{open:!0});angular.isDefined(i)?angular.isFunction(i.then)?i.then(function(e){e&&s()}):i===!0?s():i&&s():s()}},h.parseRepeatAttr=function(e,c,l){function s(e){var s=t.$eval(c);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(s)?s(e):e[s],c=h.findGroupByName(t);c?c.items.push(e):h.groups.push({name:t,items:[e]})}),l){var i=t.$eval(l);angular.isFunction(i)?h.groups=i(h.groups):angular.isArray(i)&&(h.groups=u(h.groups,i))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function i(e){h.items=e}h.setItemsFn=c?s:i,h.parserResult=n.parse(e),h.isGrouped=!!c,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var c=h.selected;if(h.isEmpty()||angular.isArray(c)&&!c.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var l=e.filter(function(e){return c.indexOf(e)<0});h.setItemsFn(l)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw a("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),c=-1===t?!1:t===h.activeIndex;return c&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),c},h.isDisabled=function(e){if(!h.open)return!1;var t,c=h.items.indexOf(e[h.itemProperty]),l=!1;return c>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[c],l=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=l),l},h.select=function(e,c,s){if((void 0===e||!e._uiSelectChoiceDisabled)&&(h.items||h.search)){var i={};i[h.parserResult.itemName]=e;var n={$item:e,$model:h.parserResult.modelMapper(t,i)},a=function(e){n.$item=e,t.$broadcast("uis:select",e),l(function(){h.onSelectCallback(t,n)}),h.closeOnSelect&&h.close(c),s&&"click"===s.type&&(h.clickTriggeredSelect=!0)};if(!angular.isDefined(h.onBeforeRemoveCallback))return a(e),void 0;var r=h.onBeforeSelectCallback(t,n);angular.isDefined(r)?angular.isFunction(r.then)?r.then(function(t){t&&(t===!0?a(e):t&&a(t))}):r===!0?a(e):r&&a(r):a(e)}},h.close=function(e){function c(){h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),o(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e)}if(h.open){var l=h.onDropdownCallback(t,{open:!1});angular.isDefined(l)?angular.isFunction(l.then)?l.then(function(e){e&&c()}):l===!0?c():l&&c():c()}},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),l(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var c,l=h.selected[t];return l&&!angular.isUndefined(h.lockChoiceExpression)&&(c=!!e.$eval(h.lockChoiceExpression),l._uiSelectChoiceLocked=c),c};var g=null;h.sizeSearchInput=function(){var e=h.searchInput[0],c=h.searchInput.parent().parent()[0],s=function(){return c.clientWidth*!!e.offsetParent},i=function(t){if(0===t)return!1;var c=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>c&&(c=t),h.searchInput.css("width",c+"px"),!0};h.searchInput.css("width","10px"),l(function(){null!==g||i(s())||(g=t.$watch(s,function(e){i(e)&&(g(),g=null)}))})},h.searchInput.on("keydown",function(c){var l=c.which;t.$apply(function(){d(l)}),e.isVerticalMovement(l)&&h.items.length>0&&p(),(l===e.ENTER||l===e.ESC)&&(c.preventDefault(),c.stopPropagation())}),h.searchInput.on("keyup",function(c){c.which===e.TAB||e.isControl(c)||e.isFunctionKey(c)||c.which===e.ESC||e.isVerticalMovement(c.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:c})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),c.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,c,l,s,i,n,a){return{restrict:"EA",templateUrl:function(e,t){var l=t.theme||c.theme;return l+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(i,r){return angular.isDefined(r.multiple)?i.append("").removeAttr("multiple"):i.append(""),function(i,r,o,u,d){function p(e){if(g.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(r[0],e.target):r[0].contains(e.target),!t&&!g.clickTriggeredSelect){var c=["input","button","textarea"],l=angular.element(e.target).scope(),s=l&&l.$select&&l.$select!==g;s||(s=~c.indexOf(e.target.tagName.toLowerCase())),g.close(s),i.$digest()}g.clickTriggeredSelect=!1}}function h(){var t=s(r);w=angular.element('
    '),w[0].style.width=t.width+"px",w[0].style.height=t.height+"px",r.after(w),x=r[0].style.width,e.find("body").append(r),r[0].style.position="absolute",r[0].style.left=t.left+"px",r[0].style.top=t.top+"px",r[0].style.width=t.width+"px"}function f(){null!==w&&(w.replaceWith(r),w=null,r[0].style.position="",r[0].style.left="",r[0].style.top="",r[0].style.width=x)}var g=u[0],v=u[1];g.generatedId=c.generateId(),g.baseTitle=o.title||"Select box",g.focusserTitle=g.baseTitle+" focus",g.focusserId="focusser-"+g.generatedId,g.closeOnSelect=function(){return angular.isDefined(o.closeOnSelect)?n(o.closeOnSelect)():c.closeOnSelect}(),g.onSelectCallback=n(o.onSelect),g.onBeforeSelectCallback=n(o.onBeforeSelect),g.onRemoveCallback=n(o.onRemove),g.onBeforeRemoveCallback=n(o.onBeforeRemove),g.onKeypressCallback=n(o.onKeypress),g.onDropdownCallback=n(o.onDropdown),g.limit=angular.isDefined(o.limit)?parseInt(o.limit,10):void 0,g.ngModel=v,g.choiceGrouped=function(e){return g.isGrouped&&e&&e.name},o.tabindex&&o.$observe("tabindex",function(e){g.focusInput.attr("tabindex",e),r.removeAttr("tabindex")});var m=i.$eval(o.searchEnabled);g.searchEnabled=void 0!==m?m:c.searchEnabled;var $=i.$eval(o.sortable);g.sortable=void 0!==$?$:c.sortable,o.$observe("disabled",function(){g.disabled=void 0!==o.disabled?o.disabled:!1}),angular.isDefined(o.autofocus)&&a(function(){g.setFocus()}),angular.isDefined(o.focusOn)&&i.$on(o.focusOn,function(){a(function(){g.setFocus()})}),e.on("click",p),i.$on("$destroy",function(){e.off("click",p)}),d(i,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),c.removeAttr("data-ui-select-match"),1!==c.length)throw l("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);r.querySelectorAll(".ui-select-match").replaceWith(c);var s=t.querySelectorAll(".ui-select-choices");if(s.removeAttr("ui-select-choices"),s.removeAttr("data-ui-select-choices"),1!==s.length)throw l("transcluded","Expected 1 .ui-select-choices but got '{0}'.",s.length);r.querySelectorAll(".ui-select-choices").replaceWith(s)});var b=i.$eval(o.appendToBody);(void 0!==b?b:c.appendToBody)&&(i.$watch("$select.open",function(e){e?h():f()}),i.$on("$destroy",function(){f()}));var w=null,x="",E=null,C="direction-up";i.$watch("$select.open",function(c){if(c){if(E=angular.element(r).querySelectorAll(".ui-select-dropdown"),null===E)return;E[0].style.opacity=0,a(function(){var c=s(r),l=s(E);c.top+c.height+l.height>t.pageYOffset+e[0].documentElement.clientHeight&&r.addClass(C),E[0].style.opacity=1})}else{if(null===E)return;r.removeClass(C)}})}}}}]),c.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,l=t.parent().attr("multiple");return c+(l?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,l,s){function i(e){s.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}s.lockChoiceExpression=l.uiLockChoice,l.$observe("placeholder",function(t){s.placeholder=void 0!==t?t:e.placeholder}),l.$observe("allowClear",i),i(l.allowClear),s.multiple&&s.sizeSearchInput()}}}]),c.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var c,l=this,s=e.$select;e.$evalAsync(function(){c=e.ngModel}),l.activeMatchIndex=-1,l.updateModel=function(){c.$setViewValue(Date.now()),l.refreshComponent()},l.refreshComponent=function(){s.refreshItems(),s.sizeSearchInput()},l.removeChoice=function(c){function i(){t(function(){s.onRemoveCallback(e,r)}),l.updateModel()}var n=s.selected[c];if(!n._uiSelectChoiceLocked){var a={};a[s.parserResult.itemName]=n,s.selected.splice(c,1),l.activeMatchIndex=-1,s.sizeSearchInput();var r={$item:n,$model:s.parserResult.modelMapper(e,a)};if(!angular.isDefined(l.onBeforeRemoveCallback))return i(),void 0;var o=l.onBeforeRemoveCallback(e,r);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(e){e&&i(e)}):o===!0&&i():i()}},l.getPlaceholder=function(){return s.selected&&s.selected.length?void 0:s.placeholder}}],controllerAs:"$selectMultiple",link:function(l,s,i,n){function a(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function r(t){function c(){switch(t){case e.LEFT:return~d.activeMatchIndex?p:n;case e.RIGHT:return~d.activeMatchIndex&&r!==n?u:(o.activate(),!1);case e.BACKSPACE:return~d.activeMatchIndex?(d.removeChoice(r),p):n;case e.DELETE:return~d.activeMatchIndex?(d.removeChoice(d.activeMatchIndex),r):!1}}var l=a(o.searchInput[0]),s=o.selected.length,i=0,n=s-1,r=d.activeMatchIndex,u=d.activeMatchIndex+1,p=d.activeMatchIndex-1,h=r;return l>0||o.search.length&&t==e.RIGHT?!1:(o.close(),h=c(),d.activeMatchIndex=o.selected.length&&h!==!1?Math.min(n,Math.max(i,h)):-1,!0)}var o=n[0],u=l.ngModel=n[1],d=l.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,u.$parsers.unshift(function(){for(var e,t={},c=[],s=o.selected.length-1;s>=0;s--)t={},t[o.parserResult.itemName]=o.selected[s],e=o.parserResult.modelMapper(l,t),c.unshift(e);return c}),u.$formatters.unshift(function(e){var t,c=o.parserResult.source(l,{$select:{search:""}}),s={};if(!c)return e;var i=[],n=function(e,c){if(e&&e.length){for(var n=e.length-1;n>=0;n--){if(s[o.parserResult.itemName]=e[n],t=o.parserResult.modelMapper(l,s),o.parserResult.trackByExp){var a=/\.(.+)/.exec(o.parserResult.trackByExp);if(a.length>0&&t[a[1]]==c[a[1]])return i.unshift(e[n]),!0}if(angular.equals(t,c))return i.unshift(e[n]),!0}return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(o.selected,e[a])||n(c,e[a])||i.unshift(e[a]);return i}),l.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,d.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);o.selected=[]}o.selected=u.$viewValue,l.$evalAsync()},l.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),d.updateModel())}),l.$on("uis:activate",function(){d.activeMatchIndex=-1}),l.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(t){var c=t.which;l.$apply(function(){var t=!1;e.isHorizontalMovement(c)&&(t=r(c)),t&&c!=e.TAB})}),o.searchInput.on("blur",function(){c(function(){d.activeMatchIndex=-1})})}}}]),c.directive("uiSelectSingle",["$timeout","$compile",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(l,s,i,n){var a=n[0],r=n[1];r.$parsers.unshift(function(e){var t,c={};return c[a.parserResult.itemName]=e,t=a.parserResult.modelMapper(l,c)}),r.$formatters.unshift(function(e){var t,c=a.parserResult.source(l,{$select:{search:""}}),s={};if(c){var i=function(c){return s[a.parserResult.itemName]=c,t=a.parserResult.modelMapper(l,s),t==e};if(a.selected&&i(a.selected))return a.selected;for(var n=c.length-1;n>=0;n--)if(i(c[n]))return c[n]}return e}),l.$watch("$select.selected",function(e){r.$viewValue!==e&&r.$setViewValue(e)}),r.$render=function(){a.selected=r.$viewValue},l.$on("uis:select",function(e,t){a.selected=t}),l.$on("uis:close",function(e,c){t(function(){a.focusser.prop("disabled",!1),c||a.focusser[0].focus()},0,!1)}),l.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");c(o)(l),a.focusser=o,a.focusInput=o,s.parent().append(o),o.bind("focus",function(){l.$evalAsync(function(){a.focus=!0})}),o.bind("blur",function(){l.$evalAsync(function(){a.focus=!1})}),o.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),a.select(void 0),l.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),a.activate()),l.$digest()),void 0)}),o.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(a.activate(o.val()),o.val(""),l.$digest())})}}}]),c.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var l=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!l)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:l[2],source:t(l[3]),trackByExp:l[4],modelMapper:t(l[1]||l[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,l){var s=e+" in "+(l?"$group.items":t);return c&&(s+=" track by "+c),s}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("selectize/choices.tpl.html",'
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",'
    {{$select.placeholder}}
    '),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",'')}]),angular.module("ui.select").run(["$templateCache",function(e){e.put("select2/choices.tpl.html",'
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    ')}]); \ No newline at end of file +!function(){"use strict";angular.module("ui.select.sort",["ui.select"]).directive("uiSelectSort",["$timeout","uiSelectConfig","uiSelectMinErr",function(e,t,c){return{require:"^uiSelect",link:function(t,l,s,i){if(null===t[s.uiSelectSort])throw c("sort","Expected a list to sort");var n=angular.extend({axis:"horizontal"},t.$eval(s.uiSelectSortOptions)),a=n.axis,r="dragging",o="dropping",u="dropping-before",d="dropping-after";t.$watch(function(){return i.sortable},function(e){e?l.attr("draggable",!0):l.removeAttr("draggable")}),l.on("dragstart",function(e){l.addClass(r),(e.dataTransfer||e.originalEvent.dataTransfer).setData("text/plain",t.$index)}),l.on("dragend",function(){l.removeClass(r)});var p,h=function(e,t){this.splice(t,0,this.splice(e,1)[0])},f=function(e){e.preventDefault();var t="vertical"===a?e.offsetY||e.layerY||(e.originalEvent?e.originalEvent.offsetY:0):e.offsetX||e.layerX||(e.originalEvent?e.originalEvent.offsetX:0);t=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],c=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(c.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,c=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,l,s){s(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(c){var l=c[0].getBoundingClientRect();return{width:l.width||c.prop("offsetWidth"),height:l.height||c.prop("offsetHeight"),top:l.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:l.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);c.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,c,l){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(e,s){if(!s.repeat)throw c("repeat","Expected 'repeat' expression.");return function(e,s,i,n,a){var r=i.groupBy,o=i.groupFilter;if(n.parseRepeatAttr(i.repeat,r,o),n.disableChoiceExpression=i.uiDisableChoice,n.onHighlightCallback=i.onHighlight,r){var u=s.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=s.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(n.parserResult.itemName,"$select.items",n.parserResult.trackByExp,r)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+n.parserResult.itemName+")").attr("ng-click","$select.select("+n.parserResult.itemName+",false,$event)");var p=s.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),l(s,a)(e),e.$watch("$select.search",function(e){e&&!n.open&&n.multiple&&n.activate(!1,!0),n.activeIndex=0})}}}}]),c.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,c,l,s,i,n,a,r){function o(){(h.resetSearchInput||void 0===h.resetSearchInput&&r.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var c,l,s=[];for(c=0;c0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:c=!1}return c}function p(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw a("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var l=t[h.activeIndex],s=l.offsetTop+l.clientHeight-e[0].scrollTop,i=e[0].offsetHeight;s>i?e[0].scrollTop+=s-i:s=h.items.length?0:h.activeIndex,l(function(){h.search=e||h.search,h.searchInput[0].focus()})},i=h.onDropdownCallback(t,{open:!0});angular.isDefined(i)?angular.isFunction(i.then)?i.then(function(e){e&&s()}):i===!0?s():i&&s():s()}},h.parseRepeatAttr=function(e,c,l){function s(e){var s=t.$eval(c);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(s)?s(e):e[s],c=h.findGroupByName(t);c?c.items.push(e):h.groups.push({name:t,items:[e]})}),l){var i=t.$eval(l);angular.isFunction(i)?h.groups=i(h.groups):angular.isArray(i)&&(h.groups=u(h.groups,i))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function i(e){h.items=e}h.setItemsFn=c?s:i,h.parserResult=n.parse(e),h.isGrouped=!!c,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var c=h.selected;if(h.isEmpty()||angular.isArray(c)&&!c.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var l=e.filter(function(e){return c.indexOf(e)<0});h.setItemsFn(l)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw a("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),c=-1===t?!1:t===h.activeIndex;return c&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),c},h.isDisabled=function(e){if(!h.open)return!1;var t,c=h.items.indexOf(e[h.itemProperty]),l=!1;return c>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[c],l=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=l),l},h.select=function(e,c,s){if((void 0===e||!e._uiSelectChoiceDisabled)&&(h.items||h.search)){var i={};i[h.parserResult.itemName]=e;var n={$item:e,$model:h.parserResult.modelMapper(t,i)},a=function(e){n.$item=e,t.$broadcast("uis:select",e),l(function(){h.onSelectCallback(t,n)}),h.closeOnSelect&&h.close(c),s&&"click"===s.type&&(h.clickTriggeredSelect=!0)};if(!angular.isDefined(h.onBeforeRemoveCallback))return a(e),void 0;var r=h.onBeforeSelectCallback(t,n);angular.isDefined(r)?angular.isFunction(r.then)?r.then(function(t){t&&(t===!0?a(e):t&&a(t))}):r===!0?a(e):r&&a(r):a(e)}},h.close=function(e){function c(){h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),o(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e)}if(h.open){var l=h.onDropdownCallback(t,{open:!1});angular.isDefined(l)?angular.isFunction(l.then)?l.then(function(e){e&&c()}):l===!0?c():l&&c():c()}},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),l(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var c,l=h.selected[t];return l&&!angular.isUndefined(h.lockChoiceExpression)&&(c=!!e.$eval(h.lockChoiceExpression),l._uiSelectChoiceLocked=c),c};var g=null;h.sizeSearchInput=function(){var e=h.searchInput[0],c=h.searchInput.parent().parent()[0],s=function(){return c.clientWidth*!!e.offsetParent},i=function(t){if(0===t)return!1;var c=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>c&&(c=t),h.searchInput.css("width",c+"px"),!0};h.searchInput.css("width","10px"),l(function(){null!==g||i(s())||(g=t.$watch(s,function(e){i(e)&&(g(),g=null)}))})},h.searchInput.on("keydown",function(c){var l=c.which;t.$apply(function(){d(l)}),e.isVerticalMovement(l)&&h.items.length>0&&p(),(l===e.ENTER||l===e.ESC)&&(c.preventDefault(),c.stopPropagation())}),h.searchInput.on("keyup",function(c){c.which===e.TAB||e.isControl(c)||e.isFunctionKey(c)||c.which===e.ESC||e.isVerticalMovement(c.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:c})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),c.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,c,l,s,i,n,a){return{restrict:"EA",templateUrl:function(e,t){var l=t.theme||c.theme;return l+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(i,r){return angular.isDefined(r.multiple)?i.append("").removeAttr("multiple"):i.append(""),function(i,r,o,u,d){function p(e){if(g.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(r[0],e.target):r[0].contains(e.target),!t&&!g.clickTriggeredSelect){var c=["input","button","textarea"],l=angular.element(e.target).scope(),s=l&&l.$select&&l.$select!==g;s||(s=~c.indexOf(e.target.tagName.toLowerCase())),g.close(s),i.$digest()}g.clickTriggeredSelect=!1}}function h(){var t=s(r);w=angular.element('
    '),w[0].style.width=t.width+"px",w[0].style.height=t.height+"px",r.after(w),x=r[0].style.width,e.find("body").append(r),r[0].style.position="absolute",r[0].style.left=t.left+"px",r[0].style.top=t.top+"px",r[0].style.width=t.width+"px"}function f(){null!==w&&(w.replaceWith(r),w=null,r[0].style.position="",r[0].style.left="",r[0].style.top="",r[0].style.width=x)}var g=u[0],v=u[1];g.generatedId=c.generateId(),g.baseTitle=o.title||"Select box",g.focusserTitle=g.baseTitle+" focus",g.focusserId="focusser-"+g.generatedId,g.closeOnSelect=function(){return angular.isDefined(o.closeOnSelect)?n(o.closeOnSelect)():c.closeOnSelect}(),g.onSelectCallback=n(o.onSelect),g.onBeforeSelectCallback=n(o.onBeforeSelect),g.onRemoveCallback=n(o.onRemove),g.onBeforeRemoveCallback=n(o.onBeforeRemove),g.onKeypressCallback=n(o.onKeypress),g.onDropdownCallback=n(o.onDropdown),g.limit=angular.isDefined(o.limit)?parseInt(o.limit,10):void 0,g.ngModel=v,g.choiceGrouped=function(e){return g.isGrouped&&e&&e.name},o.tabindex&&o.$observe("tabindex",function(e){g.focusInput.attr("tabindex",e),r.removeAttr("tabindex")});var m=i.$eval(o.searchEnabled);g.searchEnabled=void 0!==m?m:c.searchEnabled;var $=i.$eval(o.sortable);g.sortable=void 0!==$?$:c.sortable,o.$observe("disabled",function(){g.disabled=void 0!==o.disabled?o.disabled:!1}),angular.isDefined(o.autofocus)&&a(function(){g.setFocus()}),angular.isDefined(o.focusOn)&&i.$on(o.focusOn,function(){a(function(){g.setFocus()})}),e.on("click",p),i.$on("$destroy",function(){e.off("click",p)}),d(i,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),c.removeAttr("data-ui-select-match"),1!==c.length)throw l("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);r.querySelectorAll(".ui-select-match").replaceWith(c);var s=t.querySelectorAll(".ui-select-choices");if(s.removeAttr("ui-select-choices"),s.removeAttr("data-ui-select-choices"),1!==s.length)throw l("transcluded","Expected 1 .ui-select-choices but got '{0}'.",s.length);r.querySelectorAll(".ui-select-choices").replaceWith(s)});var b=i.$eval(o.appendToBody);(void 0!==b?b:c.appendToBody)&&(i.$watch("$select.open",function(e){e?h():f()}),i.$on("$destroy",function(){f()}));var w=null,x="",y=null,E="direction-up";i.$watch("$select.open",function(c){if(c){if(y=angular.element(r).querySelectorAll(".ui-select-dropdown"),null===y)return;y[0].style.opacity=0,a(function(){var c=s(r),l=s(y);c.top+c.height+l.height>t.pageYOffset+e[0].documentElement.clientHeight&&r.addClass(E),y[0].style.opacity=1})}else{if(null===y)return;r.removeClass(E)}})}}}}]),c.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,l=t.parent().attr("multiple");return c+(l?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,l,s){function i(e){s.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}s.lockChoiceExpression=l.uiLockChoice,l.$observe("placeholder",function(t){s.placeholder=void 0!==t?t:e.placeholder}),l.$observe("allowClear",i),i(l.allowClear),s.multiple&&s.sizeSearchInput()}}}]),c.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var c,l=this,s=e.$select;e.$evalAsync(function(){c=e.ngModel}),l.activeMatchIndex=-1,l.updateModel=function(){c.$setViewValue(Date.now()),l.refreshComponent()},l.refreshComponent=function(){s.refreshItems(),s.sizeSearchInput()},l.removeChoice=function(c){function i(){t(function(){s.onRemoveCallback(e,r)}),l.updateModel()}var n=s.selected[c];if(!n._uiSelectChoiceLocked){var a={};a[s.parserResult.itemName]=n,s.selected.splice(c,1),l.activeMatchIndex=-1,s.sizeSearchInput();var r={$item:n,$model:s.parserResult.modelMapper(e,a)};if(!angular.isDefined(l.onBeforeRemoveCallback))return i(),void 0;var o=l.onBeforeRemoveCallback(e,r);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(e){e&&i(e)}):o===!0&&i():i()}},l.getPlaceholder=function(){return s.selected&&s.selected.length?void 0:s.placeholder}}],controllerAs:"$selectMultiple",link:function(l,s,i,n){function a(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function r(t){function c(){switch(t){case e.LEFT:return~d.activeMatchIndex?p:n;case e.RIGHT:return~d.activeMatchIndex&&r!==n?u:(o.activate(),!1);case e.BACKSPACE:return~d.activeMatchIndex?(d.removeChoice(r),p):n;case e.DELETE:return~d.activeMatchIndex?(d.removeChoice(d.activeMatchIndex),r):!1}}var l=a(o.searchInput[0]),s=o.selected.length,i=0,n=s-1,r=d.activeMatchIndex,u=d.activeMatchIndex+1,p=d.activeMatchIndex-1,h=r;return l>0||o.search.length&&t==e.RIGHT?!1:(o.close(),h=c(),d.activeMatchIndex=o.selected.length&&h!==!1?Math.min(n,Math.max(i,h)):-1,!0)}var o=n[0],u=l.ngModel=n[1],d=l.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,u.$parsers.unshift(function(){for(var e,t={},c=[],s=o.selected.length-1;s>=0;s--)t={},t[o.parserResult.itemName]=o.selected[s],e=o.parserResult.modelMapper(l,t),c.unshift(e);return c}),u.$formatters.unshift(function(e){var t,c=o.parserResult.source(l,{$select:{search:""}}),s={};if(!c)return e;var i=[],n=function(e,c){if(e&&e.length){for(var n=e.length-1;n>=0;n--){if(s[o.parserResult.itemName]=e[n],t=o.parserResult.modelMapper(l,s),o.parserResult.trackByExp){var a=/\.(.+)/.exec(o.parserResult.trackByExp);if(a.length>0&&t[a[1]]==c[a[1]])return i.unshift(e[n]),!0}if(angular.equals(t,c))return i.unshift(e[n]),!0}return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(o.selected,e[a])||n(c,e[a])||i.unshift(e[a]);return i}),l.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,d.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);o.selected=[]}o.selected=u.$viewValue,l.$evalAsync()},l.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),d.updateModel())}),l.$on("uis:activate",function(){d.activeMatchIndex=-1}),l.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(t){var c=t.which;l.$apply(function(){var t=!1;e.isHorizontalMovement(c)&&(t=r(c)),t&&c!=e.TAB})}),o.searchInput.on("blur",function(){c(function(){d.activeMatchIndex=-1})})}}}]),c.directive("uiSelectSingle",["$timeout","$compile",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(l,s,i,n){var a=n[0],r=n[1];r.$parsers.unshift(function(e){var t,c={};return c[a.parserResult.itemName]=e,t=a.parserResult.modelMapper(l,c)}),r.$formatters.unshift(function(e){var t,c=a.parserResult.source(l,{$select:{search:""}}),s={};if(c){var i=function(c){return s[a.parserResult.itemName]=c,t=a.parserResult.modelMapper(l,s),t==e};if(a.selected&&i(a.selected))return a.selected;for(var n=c.length-1;n>=0;n--)if(i(c[n]))return c[n]}return e}),l.$watch("$select.selected",function(e){r.$viewValue!==e&&r.$setViewValue(e)}),r.$render=function(){a.selected=r.$viewValue},l.$on("uis:select",function(e,t){a.selected=t}),l.$on("uis:close",function(e,c){t(function(){a.focusser.prop("disabled",!1),c||a.focusser[0].focus()},0,!1)}),l.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");c(o)(l),a.focusser=o,a.focusInput=o,s.parent().append(o),o.bind("focus",function(){l.$evalAsync(function(){a.focus=!0})}),o.bind("blur",function(){l.$evalAsync(function(){a.focus=!1})}),o.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),a.select(void 0),l.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),a.activate()),l.$digest()),void 0)}),o.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(a.activate(o.val()),o.val(""),l.$digest())})}}}]),c.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var l=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!l)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:l[2],source:t(l[3]),trackByExp:l[4],modelMapper:t(l[1]||l[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,l){var s=e+" in "+(l?"$group.items":t);return c&&(s+=" track by "+c),s}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("selectize/choices.tpl.html",'
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",'
    {{$select.placeholder}}
    '),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",'')}]),angular.module("ui.select").run(["$templateCache",function(e){e.put("select2/choices.tpl.html",'
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/dist/select.no-tpl.js b/dist/select.no-tpl.js index 53e8ee278..43e0d31a6 100644 --- a/dist/select.no-tpl.js +++ b/dist/select.no-tpl.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-06T11:06:02.017Z + * Version: 0.12.1 - 2015-08-06T13:28:34.948Z * License: MIT */ @@ -28,110 +28,6 @@ var KEY = { DELETE: 46, COMMAND: 91, - MAP: { - 91: "COMMAND", - 8: "BACKSPACE", - 9: "TAB", - 13: "ENTER", - 16: "SHIFT", - 17: "CTRL", - 18: "ALT", - 19: "PAUSEBREAK", - 20: "CAPSLOCK", - 27: "ESC", - 32: "SPACE", - 33: "PAGE_UP", - 34: "PAGE_DOWN", - 35: "END", - 36: "HOME", - 37: "LEFT", - 38: "UP", - 39: "RIGHT", - 40: "DOWN", - 43: "+", - 44: "PRINTSCREEN", - 45: "INSERT", - 46: "DELETE", - 48: "0", - 49: "1", - 50: "2", - 51: "3", - 52: "4", - 53: "5", - 54: "6", - 55: "7", - 56: "8", - 57: "9", - 59: ";", - 61: "=", - 65: "A", - 66: "B", - 67: "C", - 68: "D", - 69: "E", - 70: "F", - 71: "G", - 72: "H", - 73: "I", - 74: "J", - 75: "K", - 76: "L", - 77: "M", - 78: "N", - 79: "O", - 80: "P", - 81: "Q", - 82: "R", - 83: "S", - 84: "T", - 85: "U", - 86: "V", - 87: "W", - 88: "X", - 89: "Y", - 90: "Z", - 96: "0", - 97: "1", - 98: "2", - 99: "3", - 100: "4", - 101: "5", - 102: "6", - 103: "7", - 104: "8", - 105: "9", - 106: "*", - 107: "+", - 109: "-", - 110: ".", - 111: "/", - 112: "F1", - 113: "F2", - 114: "F3", - 115: "F4", - 116: "F5", - 117: "F6", - 118: "F7", - 119: "F8", - 120: "F9", - 121: "F10", - 122: "F11", - 123: "F12", - 144: "NUMLOCK", - 145: "SCROLLLOCK", - 186: ";", - 187: "=", - 188: ",", - 189: "-", - 190: ".", - 191: "/", - 192: "`", - 219: "[", - 220: "\\", - 221: "]", - 222: "'" - }, - isControl: function (e) { var k = e.which; switch (k) { @@ -605,10 +501,10 @@ uis.controller('uiSelectCtrl', return isDisabled; }; - /** * Selects an item. Calls the onBeforeSelect and onSelect callbacks - * onBeforeSelect can alter or abort the selection + * onBeforeSelect is called to allow the user to alter or abort the selection + * onSelect is called to notify the user of the selection * * Called when the user selects an item with ENTER or clicks the dropdown */ @@ -1255,7 +1151,11 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel $select.sizeSearchInput(); }; - // Remove item from multiple select + /** + * Remove item from multiple select + * Calls onBeforeRemove to allow the user to prevent the removal of the item + * Then calls onRemove to notify the user the item has been removed + */ ctrl.removeChoice = function (index) { var removedChoice = $select.selected[index]; diff --git a/dist/select.no-tpl.min.js b/dist/select.no-tpl.min.js index 1792cfb13..619fcd138 100644 --- a/dist/select.no-tpl.min.js +++ b/dist/select.no-tpl.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-06T11:06:02.017Z + * Version: 0.12.1 - 2015-08-06T13:28:34.948Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var n=t.which;switch(n){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,n=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,r,i){i(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var r=n[0].getBoundingClientRect();return{width:r.width||n.prop("offsetWidth"),height:r.height||n.prop("offsetHeight"),top:r.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:r.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);n.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,r){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,i){if(!i.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,i,c,l,o){var a=c.groupBy,s=c.groupFilter;if(l.parseRepeatAttr(c.repeat,a,s),l.disableChoiceExpression=c.uiDisableChoice,l.onHighlightCallback=c.onHighlight,a){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=i.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(l.parserResult.itemName,"$select.items",l.parserResult.trackByExp,a)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+l.parserResult.itemName+")").attr("ng-click","$select.select("+l.parserResult.itemName+",false,$event)");var f=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==f.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",f.length);f.attr("uis-transclude-append",""),r(i,o)(e),e.$watch("$select.search",function(e){e&&!l.open&&l.multiple&&l.activate(!1,!0),l.activeIndex=0})}}}}]),n.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,n,r,i,c,l,o,a){function s(){(d.resetSearchInput||void 0===d.resetSearchInput&&a.resetSearchInput)&&(d.search=h,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function u(e,t){var n,r,i=[];for(n=0;n0&&d.activeIndex--;break;case e.TAB:(!d.multiple||d.open)&&d.select(d.items[d.activeIndex],!0);break;case e.ENTER:d.open?d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case e.ESC:d.close();break;default:n=!1}return n}function f(){var e=n.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw o("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(d.activeIndex<0)){var r=t[d.activeIndex],i=r.offsetTop+r.clientHeight-e[0].scrollTop,c=e[0].offsetHeight;i>c?e[0].scrollTop+=i-c:i=d.items.length?0:d.activeIndex,r(function(){d.search=e||d.search,d.searchInput[0].focus()})},c=d.onDropdownCallback(t,{open:!0});angular.isDefined(c)?angular.isFunction(c.then)?c.then(function(e){e&&i()}):c===!0?i():c&&i():i()}},d.parseRepeatAttr=function(e,n,r){function i(e){var i=t.$eval(n);if(d.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(i)?i(e):e[i],n=d.findGroupByName(t);n?n.items.push(e):d.groups.push({name:t,items:[e]})}),r){var c=t.$eval(r);angular.isFunction(c)?d.groups=c(d.groups):angular.isArray(c)&&(d.groups=u(d.groups,c))}d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function c(e){d.items=e}d.setItemsFn=n?i:c,d.parserResult=l.parse(e),d.isGrouped=!!n,d.itemProperty=d.parserResult.itemName,d.refreshItems=function(e){e=e||d.parserResult.source(t);var n=d.selected;if(d.isEmpty()||angular.isArray(n)&&!n.length||!d.removeSelected)d.setItemsFn(e);else if(void 0!==e){var r=e.filter(function(e){return n.indexOf(e)<0});d.setItemsFn(r)}},t.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw o("items","Expected an array but got '{0}'.",e);d.refreshItems(e),d.ngModel.$modelValue=null}})},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){if(!d.open)return!1;var t=d.items.indexOf(e[d.itemProperty]),n=-1===t?!1:t===d.activeIndex;return n&&!angular.isUndefined(d.onHighlightCallback)&&e.$eval(d.onHighlightCallback),n},d.isDisabled=function(e){if(!d.open)return!1;var t,n=d.items.indexOf(e[d.itemProperty]),r=!1;return n>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[n],r=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=r),r},d.select=function(e,n,i){if((void 0===e||!e._uiSelectChoiceDisabled)&&(d.items||d.search)){var c={};c[d.parserResult.itemName]=e;var l={$item:e,$model:d.parserResult.modelMapper(t,c)},o=function(e){l.$item=e,t.$broadcast("uis:select",e),r(function(){d.onSelectCallback(t,l)}),d.closeOnSelect&&d.close(n),i&&"click"===i.type&&(d.clickTriggeredSelect=!0)};if(!angular.isDefined(d.onBeforeRemoveCallback))return o(e),void 0;var a=d.onBeforeSelectCallback(t,l);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(t){t&&(t===!0?o(e):t&&o(t))}):a===!0?o(e):a&&o(a):o(e)}},d.close=function(e){function n(){d.ngModel&&d.ngModel.$setTouched&&d.ngModel.$setTouched(),s(),d.open=!1,d.searchEnabled||angular.element(d.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e)}if(d.open){var r=d.onDropdownCallback(t,{open:!1});angular.isDefined(r)?angular.isFunction(r.then)?r.then(function(e){e&&n()}):r===!0?n():r&&n():n()}},d.setFocus=function(){d.focus||d.focusInput[0].focus()},d.clear=function(e){d.select(void 0),e.stopPropagation(),r(function(){d.focusser[0].focus()},0,!1)},d.toggle=function(e){d.open?(d.close(),e.preventDefault(),e.stopPropagation()):d.activate()},d.isLocked=function(e,t){var n,r=d.selected[t];return r&&!angular.isUndefined(d.lockChoiceExpression)&&(n=!!e.$eval(d.lockChoiceExpression),r._uiSelectChoiceLocked=n),n};var v=null;d.sizeSearchInput=function(){var e=d.searchInput[0],n=d.searchInput.parent().parent()[0],i=function(){return n.clientWidth*!!e.offsetParent},c=function(t){if(0===t)return!1;var n=t-e.offsetLeft-d.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=t),d.searchInput.css("width",n+"px"),!0};d.searchInput.css("width","10px"),r(function(){null!==v||c(i())||(v=t.$watch(i,function(e){c(e)&&(v(),v=null)}))})},d.searchInput.on("keydown",function(n){var r=n.which;t.$apply(function(){p(r)}),e.isVerticalMovement(r)&&d.items.length>0&&f(),(r===e.ENTER||r===e.ESC)&&(n.preventDefault(),n.stopPropagation())}),d.searchInput.on("keyup",function(n){n.which===e.TAB||e.isControl(n)||e.isFunctionKey(n)||n.which===e.ESC||e.isVerticalMovement(n.which)||void 0!==d.onKeypressCallback&&d.onKeypressCallback(t,{event:n})}),t.$on("$destroy",function(){d.searchInput.off("keyup keydown blur paste")})}]),n.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,r,i,c,l,o){return{restrict:"EA",templateUrl:function(e,t){var r=t.theme||n.theme;return r+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(c,a){return angular.isDefined(a.multiple)?c.append("").removeAttr("multiple"):c.append(""),function(c,a,s,u,p){function f(e){if(v.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(a[0],e.target):a[0].contains(e.target),!t&&!v.clickTriggeredSelect){var n=["input","button","textarea"],r=angular.element(e.target).scope(),i=r&&r.$select&&r.$select!==v;i||(i=~n.indexOf(e.target.tagName.toLowerCase())),v.close(i),c.$digest()}v.clickTriggeredSelect=!1}}function d(){var t=i(a);S=angular.element('
    '),S[0].style.width=t.width+"px",S[0].style.height=t.height+"px",a.after(S),b=a[0].style.width,e.find("body").append(a),a[0].style.position="absolute",a[0].style.left=t.left+"px",a[0].style.top=t.top+"px",a[0].style.width=t.width+"px"}function h(){null!==S&&(S.replaceWith(a),S=null,a[0].style.position="",a[0].style.left="",a[0].style.top="",a[0].style.width=b)}var v=u[0],m=u[1];v.generatedId=n.generateId(),v.baseTitle=s.title||"Select box",v.focusserTitle=v.baseTitle+" focus",v.focusserId="focusser-"+v.generatedId,v.closeOnSelect=function(){return angular.isDefined(s.closeOnSelect)?l(s.closeOnSelect)():n.closeOnSelect}(),v.onSelectCallback=l(s.onSelect),v.onBeforeSelectCallback=l(s.onBeforeSelect),v.onRemoveCallback=l(s.onRemove),v.onBeforeRemoveCallback=l(s.onBeforeRemove),v.onKeypressCallback=l(s.onKeypress),v.onDropdownCallback=l(s.onDropdown),v.limit=angular.isDefined(s.limit)?parseInt(s.limit,10):void 0,v.ngModel=m,v.choiceGrouped=function(e){return v.isGrouped&&e&&e.name},s.tabindex&&s.$observe("tabindex",function(e){v.focusInput.attr("tabindex",e),a.removeAttr("tabindex")});var g=c.$eval(s.searchEnabled);v.searchEnabled=void 0!==g?g:n.searchEnabled;var $=c.$eval(s.sortable);v.sortable=void 0!==$?$:n.sortable,s.$observe("disabled",function(){v.disabled=void 0!==s.disabled?s.disabled:!1}),angular.isDefined(s.autofocus)&&o(function(){v.setFocus()}),angular.isDefined(s.focusOn)&&c.$on(s.focusOn,function(){o(function(){v.setFocus()})}),e.on("click",f),c.$on("$destroy",function(){e.off("click",f)}),p(c,function(e){var t=angular.element("
    ").append(e),n=t.querySelectorAll(".ui-select-match");if(n.removeAttr("ui-select-match"),n.removeAttr("data-ui-select-match"),1!==n.length)throw r("transcluded","Expected 1 .ui-select-match but got '{0}'.",n.length);a.querySelectorAll(".ui-select-match").replaceWith(n);var i=t.querySelectorAll(".ui-select-choices");if(i.removeAttr("ui-select-choices"),i.removeAttr("data-ui-select-choices"),1!==i.length)throw r("transcluded","Expected 1 .ui-select-choices but got '{0}'.",i.length);a.querySelectorAll(".ui-select-choices").replaceWith(i)});var E=c.$eval(s.appendToBody);(void 0!==E?E:n.appendToBody)&&(c.$watch("$select.open",function(e){e?d():h()}),c.$on("$destroy",function(){h()}));var S=null,b="",C=null,w="direction-up";c.$watch("$select.open",function(n){if(n){if(C=angular.element(a).querySelectorAll(".ui-select-dropdown"),null===C)return;C[0].style.opacity=0,o(function(){var n=i(a),r=i(C);n.top+n.height+r.height>t.pageYOffset+e[0].documentElement.clientHeight&&a.addClass(w),C[0].style.opacity=1})}else{if(null===C)return;a.removeClass(w)}})}}}}]),n.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,r=t.parent().attr("multiple");return n+(r?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,r,i){function c(e){i.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}i.lockChoiceExpression=r.uiLockChoice,r.$observe("placeholder",function(t){i.placeholder=void 0!==t?t:e.placeholder}),r.$observe("allowClear",c),c(r.allowClear),i.multiple&&i.sizeSearchInput()}}}]),n.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,r=this,i=e.$select;e.$evalAsync(function(){n=e.ngModel}),r.activeMatchIndex=-1,r.updateModel=function(){n.$setViewValue(Date.now()),r.refreshComponent()},r.refreshComponent=function(){i.refreshItems(),i.sizeSearchInput()},r.removeChoice=function(n){function c(){t(function(){i.onRemoveCallback(e,a)}),r.updateModel()}var l=i.selected[n];if(!l._uiSelectChoiceLocked){var o={};o[i.parserResult.itemName]=l,i.selected.splice(n,1),r.activeMatchIndex=-1,i.sizeSearchInput();var a={$item:l,$model:i.parserResult.modelMapper(e,o)};if(!angular.isDefined(r.onBeforeRemoveCallback))return c(),void 0;var s=r.onBeforeRemoveCallback(e,a);angular.isDefined(s)?angular.isFunction(s.then)?s.then(function(e){e&&c(e)}):s===!0&&c():c()}},r.getPlaceholder=function(){return i.selected&&i.selected.length?void 0:i.placeholder}}],controllerAs:"$selectMultiple",link:function(r,i,c,l){function o(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(t){function n(){switch(t){case e.LEFT:return~p.activeMatchIndex?f:l;case e.RIGHT:return~p.activeMatchIndex&&a!==l?u:(s.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(a),f):l;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),a):!1}}var r=o(s.searchInput[0]),i=s.selected.length,c=0,l=i-1,a=p.activeMatchIndex,u=p.activeMatchIndex+1,f=p.activeMatchIndex-1,d=a;return r>0||s.search.length&&t==e.RIGHT?!1:(s.close(),d=n(),p.activeMatchIndex=s.selected.length&&d!==!1?Math.min(l,Math.max(c,d)):-1,!0)}var s=l[0],u=r.ngModel=l[1],p=r.$selectMultiple;s.multiple=!0,s.removeSelected=!0,s.focusInput=s.searchInput,u.$parsers.unshift(function(){for(var e,t={},n=[],i=s.selected.length-1;i>=0;i--)t={},t[s.parserResult.itemName]=s.selected[i],e=s.parserResult.modelMapper(r,t),n.unshift(e);return n}),u.$formatters.unshift(function(e){var t,n=s.parserResult.source(r,{$select:{search:""}}),i={};if(!n)return e;var c=[],l=function(e,n){if(e&&e.length){for(var l=e.length-1;l>=0;l--){if(i[s.parserResult.itemName]=e[l],t=s.parserResult.modelMapper(r,i),s.parserResult.trackByExp){var o=/\.(.+)/.exec(s.parserResult.trackByExp);if(o.length>0&&t[o[1]]==n[o[1]])return c.unshift(e[l]),!0}if(angular.equals(t,n))return c.unshift(e[l]),!0}return!1}};if(!e)return c;for(var o=e.length-1;o>=0;o--)l(s.selected,e[o])||l(n,e[o])||c.unshift(e[o]);return c}),r.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);s.selected=[]}s.selected=u.$viewValue,r.$evalAsync()},r.$on("uis:select",function(e,t){s.selected.length>=s.limit||(s.selected.push(t),p.updateModel())}),r.$on("uis:activate",function(){p.activeMatchIndex=-1}),r.$watch("$select.disabled",function(e,t){t&&!e&&s.sizeSearchInput()}),s.searchInput.on("keydown",function(t){var n=t.which;r.$apply(function(){var t=!1;e.isHorizontalMovement(n)&&(t=a(n)),t&&n!=e.TAB})}),s.searchInput.on("blur",function(){n(function(){p.activeMatchIndex=-1})})}}}]),n.directive("uiSelectSingle",["$timeout","$compile",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(r,i,c,l){var o=l[0],a=l[1];a.$parsers.unshift(function(e){var t,n={};return n[o.parserResult.itemName]=e,t=o.parserResult.modelMapper(r,n)}),a.$formatters.unshift(function(e){var t,n=o.parserResult.source(r,{$select:{search:""}}),i={};if(n){var c=function(n){return i[o.parserResult.itemName]=n,t=o.parserResult.modelMapper(r,i),t==e};if(o.selected&&c(o.selected))return o.selected;for(var l=n.length-1;l>=0;l--)if(c(n[l]))return n[l]}return e}),r.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){o.selected=a.$viewValue},r.$on("uis:select",function(e,t){o.selected=t}),r.$on("uis:close",function(e,n){t(function(){o.focusser.prop("disabled",!1),n||o.focusser[0].focus()},0,!1)}),r.$on("uis:activate",function(){s.prop("disabled",!0)});var s=angular.element("");n(s)(r),o.focusser=s,o.focusInput=s,i.parent().append(s),s.bind("focus",function(){r.$evalAsync(function(){o.focus=!0})}),s.bind("blur",function(){r.$evalAsync(function(){o.focus=!1})}),s.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),o.select(void 0),r.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),o.activate()),r.$digest()),void 0)}),s.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(o.activate(s.val()),s.val(""),r.$digest())})}}}]),n.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var r=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!r)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:r[2],source:t(r[3]),trackByExp:r[4],modelMapper:t(r[1]||r[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,r){var i=e+" in "+(r?"$group.items":t);return n&&(i+=" track by "+n),i}}])}(); \ No newline at end of file +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,isControl:function(t){var n=t.which;switch(n){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,n=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,r,i){i(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var r=n[0].getBoundingClientRect();return{width:r.width||n.prop("offsetWidth"),height:r.height||n.prop("offsetHeight"),top:r.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:r.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);n.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,r){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,i){if(!i.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,i,c,l,o){var a=c.groupBy,s=c.groupFilter;if(l.parseRepeatAttr(c.repeat,a,s),l.disableChoiceExpression=c.uiDisableChoice,l.onHighlightCallback=c.onHighlight,a){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=i.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(l.parserResult.itemName,"$select.items",l.parserResult.trackByExp,a)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+l.parserResult.itemName+")").attr("ng-click","$select.select("+l.parserResult.itemName+",false,$event)");var f=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==f.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",f.length);f.attr("uis-transclude-append",""),r(i,o)(e),e.$watch("$select.search",function(e){e&&!l.open&&l.multiple&&l.activate(!1,!0),l.activeIndex=0})}}}}]),n.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,n,r,i,c,l,o,a){function s(){(d.resetSearchInput||void 0===d.resetSearchInput&&a.resetSearchInput)&&(d.search=h,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function u(e,t){var n,r,i=[];for(n=0;n0&&d.activeIndex--;break;case e.TAB:(!d.multiple||d.open)&&d.select(d.items[d.activeIndex],!0);break;case e.ENTER:d.open?d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case e.ESC:d.close();break;default:n=!1}return n}function f(){var e=n.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw o("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(d.activeIndex<0)){var r=t[d.activeIndex],i=r.offsetTop+r.clientHeight-e[0].scrollTop,c=e[0].offsetHeight;i>c?e[0].scrollTop+=i-c:i=d.items.length?0:d.activeIndex,r(function(){d.search=e||d.search,d.searchInput[0].focus()})},c=d.onDropdownCallback(t,{open:!0});angular.isDefined(c)?angular.isFunction(c.then)?c.then(function(e){e&&i()}):c===!0?i():c&&i():i()}},d.parseRepeatAttr=function(e,n,r){function i(e){var i=t.$eval(n);if(d.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(i)?i(e):e[i],n=d.findGroupByName(t);n?n.items.push(e):d.groups.push({name:t,items:[e]})}),r){var c=t.$eval(r);angular.isFunction(c)?d.groups=c(d.groups):angular.isArray(c)&&(d.groups=u(d.groups,c))}d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function c(e){d.items=e}d.setItemsFn=n?i:c,d.parserResult=l.parse(e),d.isGrouped=!!n,d.itemProperty=d.parserResult.itemName,d.refreshItems=function(e){e=e||d.parserResult.source(t);var n=d.selected;if(d.isEmpty()||angular.isArray(n)&&!n.length||!d.removeSelected)d.setItemsFn(e);else if(void 0!==e){var r=e.filter(function(e){return n.indexOf(e)<0});d.setItemsFn(r)}},t.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw o("items","Expected an array but got '{0}'.",e);d.refreshItems(e),d.ngModel.$modelValue=null}})},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){if(!d.open)return!1;var t=d.items.indexOf(e[d.itemProperty]),n=-1===t?!1:t===d.activeIndex;return n&&!angular.isUndefined(d.onHighlightCallback)&&e.$eval(d.onHighlightCallback),n},d.isDisabled=function(e){if(!d.open)return!1;var t,n=d.items.indexOf(e[d.itemProperty]),r=!1;return n>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[n],r=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=r),r},d.select=function(e,n,i){if((void 0===e||!e._uiSelectChoiceDisabled)&&(d.items||d.search)){var c={};c[d.parserResult.itemName]=e;var l={$item:e,$model:d.parserResult.modelMapper(t,c)},o=function(e){l.$item=e,t.$broadcast("uis:select",e),r(function(){d.onSelectCallback(t,l)}),d.closeOnSelect&&d.close(n),i&&"click"===i.type&&(d.clickTriggeredSelect=!0)};if(!angular.isDefined(d.onBeforeRemoveCallback))return o(e),void 0;var a=d.onBeforeSelectCallback(t,l);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(t){t&&(t===!0?o(e):t&&o(t))}):a===!0?o(e):a&&o(a):o(e)}},d.close=function(e){function n(){d.ngModel&&d.ngModel.$setTouched&&d.ngModel.$setTouched(),s(),d.open=!1,d.searchEnabled||angular.element(d.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e)}if(d.open){var r=d.onDropdownCallback(t,{open:!1});angular.isDefined(r)?angular.isFunction(r.then)?r.then(function(e){e&&n()}):r===!0?n():r&&n():n()}},d.setFocus=function(){d.focus||d.focusInput[0].focus()},d.clear=function(e){d.select(void 0),e.stopPropagation(),r(function(){d.focusser[0].focus()},0,!1)},d.toggle=function(e){d.open?(d.close(),e.preventDefault(),e.stopPropagation()):d.activate()},d.isLocked=function(e,t){var n,r=d.selected[t];return r&&!angular.isUndefined(d.lockChoiceExpression)&&(n=!!e.$eval(d.lockChoiceExpression),r._uiSelectChoiceLocked=n),n};var v=null;d.sizeSearchInput=function(){var e=d.searchInput[0],n=d.searchInput.parent().parent()[0],i=function(){return n.clientWidth*!!e.offsetParent},c=function(t){if(0===t)return!1;var n=t-e.offsetLeft-d.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=t),d.searchInput.css("width",n+"px"),!0};d.searchInput.css("width","10px"),r(function(){null!==v||c(i())||(v=t.$watch(i,function(e){c(e)&&(v(),v=null)}))})},d.searchInput.on("keydown",function(n){var r=n.which;t.$apply(function(){p(r)}),e.isVerticalMovement(r)&&d.items.length>0&&f(),(r===e.ENTER||r===e.ESC)&&(n.preventDefault(),n.stopPropagation())}),d.searchInput.on("keyup",function(n){n.which===e.TAB||e.isControl(n)||e.isFunctionKey(n)||n.which===e.ESC||e.isVerticalMovement(n.which)||void 0!==d.onKeypressCallback&&d.onKeypressCallback(t,{event:n})}),t.$on("$destroy",function(){d.searchInput.off("keyup keydown blur paste")})}]),n.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,r,i,c,l,o){return{restrict:"EA",templateUrl:function(e,t){var r=t.theme||n.theme;return r+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(c,a){return angular.isDefined(a.multiple)?c.append("").removeAttr("multiple"):c.append(""),function(c,a,s,u,p){function f(e){if(v.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(a[0],e.target):a[0].contains(e.target),!t&&!v.clickTriggeredSelect){var n=["input","button","textarea"],r=angular.element(e.target).scope(),i=r&&r.$select&&r.$select!==v;i||(i=~n.indexOf(e.target.tagName.toLowerCase())),v.close(i),c.$digest()}v.clickTriggeredSelect=!1}}function d(){var t=i(a);E=angular.element('
    '),E[0].style.width=t.width+"px",E[0].style.height=t.height+"px",a.after(E),w=a[0].style.width,e.find("body").append(a),a[0].style.position="absolute",a[0].style.left=t.left+"px",a[0].style.top=t.top+"px",a[0].style.width=t.width+"px"}function h(){null!==E&&(E.replaceWith(a),E=null,a[0].style.position="",a[0].style.left="",a[0].style.top="",a[0].style.width=w)}var v=u[0],m=u[1];v.generatedId=n.generateId(),v.baseTitle=s.title||"Select box",v.focusserTitle=v.baseTitle+" focus",v.focusserId="focusser-"+v.generatedId,v.closeOnSelect=function(){return angular.isDefined(s.closeOnSelect)?l(s.closeOnSelect)():n.closeOnSelect}(),v.onSelectCallback=l(s.onSelect),v.onBeforeSelectCallback=l(s.onBeforeSelect),v.onRemoveCallback=l(s.onRemove),v.onBeforeRemoveCallback=l(s.onBeforeRemove),v.onKeypressCallback=l(s.onKeypress),v.onDropdownCallback=l(s.onDropdown),v.limit=angular.isDefined(s.limit)?parseInt(s.limit,10):void 0,v.ngModel=m,v.choiceGrouped=function(e){return v.isGrouped&&e&&e.name},s.tabindex&&s.$observe("tabindex",function(e){v.focusInput.attr("tabindex",e),a.removeAttr("tabindex")});var g=c.$eval(s.searchEnabled);v.searchEnabled=void 0!==g?g:n.searchEnabled;var $=c.$eval(s.sortable);v.sortable=void 0!==$?$:n.sortable,s.$observe("disabled",function(){v.disabled=void 0!==s.disabled?s.disabled:!1}),angular.isDefined(s.autofocus)&&o(function(){v.setFocus()}),angular.isDefined(s.focusOn)&&c.$on(s.focusOn,function(){o(function(){v.setFocus()})}),e.on("click",f),c.$on("$destroy",function(){e.off("click",f)}),p(c,function(e){var t=angular.element("
    ").append(e),n=t.querySelectorAll(".ui-select-match");if(n.removeAttr("ui-select-match"),n.removeAttr("data-ui-select-match"),1!==n.length)throw r("transcluded","Expected 1 .ui-select-match but got '{0}'.",n.length);a.querySelectorAll(".ui-select-match").replaceWith(n);var i=t.querySelectorAll(".ui-select-choices");if(i.removeAttr("ui-select-choices"),i.removeAttr("data-ui-select-choices"),1!==i.length)throw r("transcluded","Expected 1 .ui-select-choices but got '{0}'.",i.length);a.querySelectorAll(".ui-select-choices").replaceWith(i)});var b=c.$eval(s.appendToBody);(void 0!==b?b:n.appendToBody)&&(c.$watch("$select.open",function(e){e?d():h()}),c.$on("$destroy",function(){h()}));var E=null,w="",S=null,y="direction-up";c.$watch("$select.open",function(n){if(n){if(S=angular.element(a).querySelectorAll(".ui-select-dropdown"),null===S)return;S[0].style.opacity=0,o(function(){var n=i(a),r=i(S);n.top+n.height+r.height>t.pageYOffset+e[0].documentElement.clientHeight&&a.addClass(y),S[0].style.opacity=1})}else{if(null===S)return;a.removeClass(y)}})}}}}]),n.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,r=t.parent().attr("multiple");return n+(r?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,r,i){function c(e){i.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}i.lockChoiceExpression=r.uiLockChoice,r.$observe("placeholder",function(t){i.placeholder=void 0!==t?t:e.placeholder}),r.$observe("allowClear",c),c(r.allowClear),i.multiple&&i.sizeSearchInput()}}}]),n.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,r=this,i=e.$select;e.$evalAsync(function(){n=e.ngModel}),r.activeMatchIndex=-1,r.updateModel=function(){n.$setViewValue(Date.now()),r.refreshComponent()},r.refreshComponent=function(){i.refreshItems(),i.sizeSearchInput()},r.removeChoice=function(n){function c(){t(function(){i.onRemoveCallback(e,a)}),r.updateModel()}var l=i.selected[n];if(!l._uiSelectChoiceLocked){var o={};o[i.parserResult.itemName]=l,i.selected.splice(n,1),r.activeMatchIndex=-1,i.sizeSearchInput();var a={$item:l,$model:i.parserResult.modelMapper(e,o)};if(!angular.isDefined(r.onBeforeRemoveCallback))return c(),void 0;var s=r.onBeforeRemoveCallback(e,a);angular.isDefined(s)?angular.isFunction(s.then)?s.then(function(e){e&&c(e)}):s===!0&&c():c()}},r.getPlaceholder=function(){return i.selected&&i.selected.length?void 0:i.placeholder}}],controllerAs:"$selectMultiple",link:function(r,i,c,l){function o(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(t){function n(){switch(t){case e.LEFT:return~p.activeMatchIndex?f:l;case e.RIGHT:return~p.activeMatchIndex&&a!==l?u:(s.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(a),f):l;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),a):!1}}var r=o(s.searchInput[0]),i=s.selected.length,c=0,l=i-1,a=p.activeMatchIndex,u=p.activeMatchIndex+1,f=p.activeMatchIndex-1,d=a;return r>0||s.search.length&&t==e.RIGHT?!1:(s.close(),d=n(),p.activeMatchIndex=s.selected.length&&d!==!1?Math.min(l,Math.max(c,d)):-1,!0)}var s=l[0],u=r.ngModel=l[1],p=r.$selectMultiple;s.multiple=!0,s.removeSelected=!0,s.focusInput=s.searchInput,u.$parsers.unshift(function(){for(var e,t={},n=[],i=s.selected.length-1;i>=0;i--)t={},t[s.parserResult.itemName]=s.selected[i],e=s.parserResult.modelMapper(r,t),n.unshift(e);return n}),u.$formatters.unshift(function(e){var t,n=s.parserResult.source(r,{$select:{search:""}}),i={};if(!n)return e;var c=[],l=function(e,n){if(e&&e.length){for(var l=e.length-1;l>=0;l--){if(i[s.parserResult.itemName]=e[l],t=s.parserResult.modelMapper(r,i),s.parserResult.trackByExp){var o=/\.(.+)/.exec(s.parserResult.trackByExp);if(o.length>0&&t[o[1]]==n[o[1]])return c.unshift(e[l]),!0}if(angular.equals(t,n))return c.unshift(e[l]),!0}return!1}};if(!e)return c;for(var o=e.length-1;o>=0;o--)l(s.selected,e[o])||l(n,e[o])||c.unshift(e[o]);return c}),r.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);s.selected=[]}s.selected=u.$viewValue,r.$evalAsync()},r.$on("uis:select",function(e,t){s.selected.length>=s.limit||(s.selected.push(t),p.updateModel())}),r.$on("uis:activate",function(){p.activeMatchIndex=-1}),r.$watch("$select.disabled",function(e,t){t&&!e&&s.sizeSearchInput()}),s.searchInput.on("keydown",function(t){var n=t.which;r.$apply(function(){var t=!1;e.isHorizontalMovement(n)&&(t=a(n)),t&&n!=e.TAB})}),s.searchInput.on("blur",function(){n(function(){p.activeMatchIndex=-1})})}}}]),n.directive("uiSelectSingle",["$timeout","$compile",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(r,i,c,l){var o=l[0],a=l[1];a.$parsers.unshift(function(e){var t,n={};return n[o.parserResult.itemName]=e,t=o.parserResult.modelMapper(r,n)}),a.$formatters.unshift(function(e){var t,n=o.parserResult.source(r,{$select:{search:""}}),i={};if(n){var c=function(n){return i[o.parserResult.itemName]=n,t=o.parserResult.modelMapper(r,i),t==e};if(o.selected&&c(o.selected))return o.selected;for(var l=n.length-1;l>=0;l--)if(c(n[l]))return n[l]}return e}),r.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){o.selected=a.$viewValue},r.$on("uis:select",function(e,t){o.selected=t}),r.$on("uis:close",function(e,n){t(function(){o.focusser.prop("disabled",!1),n||o.focusser[0].focus()},0,!1)}),r.$on("uis:activate",function(){s.prop("disabled",!0)});var s=angular.element("");n(s)(r),o.focusser=s,o.focusInput=s,i.parent().append(s),s.bind("focus",function(){r.$evalAsync(function(){o.focus=!0})}),s.bind("blur",function(){r.$evalAsync(function(){o.focus=!1})}),s.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),o.select(void 0),r.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),o.activate()),r.$digest()),void 0)}),s.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(o.activate(s.val()),s.val(""),r.$digest())})}}}]),n.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var r=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!r)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:r[2],source:t(r[3]),trackByExp:r[4],modelMapper:t(r[1]||r[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,r){var i=e+" in "+(r?"$group.items":t);return n&&(i+=" track by "+n),i}}])}(); \ No newline at end of file diff --git a/dist/select.select2.js b/dist/select.select2.js index b41ee5e15..134178a8f 100644 --- a/dist/select.select2.js +++ b/dist/select.select2.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-06T11:06:02.035Z + * Version: 0.12.1 - 2015-08-06T13:28:34.961Z * License: MIT */ @@ -28,110 +28,6 @@ var KEY = { DELETE: 46, COMMAND: 91, - MAP: { - 91: "COMMAND", - 8: "BACKSPACE", - 9: "TAB", - 13: "ENTER", - 16: "SHIFT", - 17: "CTRL", - 18: "ALT", - 19: "PAUSEBREAK", - 20: "CAPSLOCK", - 27: "ESC", - 32: "SPACE", - 33: "PAGE_UP", - 34: "PAGE_DOWN", - 35: "END", - 36: "HOME", - 37: "LEFT", - 38: "UP", - 39: "RIGHT", - 40: "DOWN", - 43: "+", - 44: "PRINTSCREEN", - 45: "INSERT", - 46: "DELETE", - 48: "0", - 49: "1", - 50: "2", - 51: "3", - 52: "4", - 53: "5", - 54: "6", - 55: "7", - 56: "8", - 57: "9", - 59: ";", - 61: "=", - 65: "A", - 66: "B", - 67: "C", - 68: "D", - 69: "E", - 70: "F", - 71: "G", - 72: "H", - 73: "I", - 74: "J", - 75: "K", - 76: "L", - 77: "M", - 78: "N", - 79: "O", - 80: "P", - 81: "Q", - 82: "R", - 83: "S", - 84: "T", - 85: "U", - 86: "V", - 87: "W", - 88: "X", - 89: "Y", - 90: "Z", - 96: "0", - 97: "1", - 98: "2", - 99: "3", - 100: "4", - 101: "5", - 102: "6", - 103: "7", - 104: "8", - 105: "9", - 106: "*", - 107: "+", - 109: "-", - 110: ".", - 111: "/", - 112: "F1", - 113: "F2", - 114: "F3", - 115: "F4", - 116: "F5", - 117: "F6", - 118: "F7", - 119: "F8", - 120: "F9", - 121: "F10", - 122: "F11", - 123: "F12", - 144: "NUMLOCK", - 145: "SCROLLLOCK", - 186: ";", - 187: "=", - 188: ",", - 189: "-", - 190: ".", - 191: "/", - 192: "`", - 219: "[", - 220: "\\", - 221: "]", - 222: "'" - }, - isControl: function (e) { var k = e.which; switch (k) { @@ -605,10 +501,10 @@ uis.controller('uiSelectCtrl', return isDisabled; }; - /** * Selects an item. Calls the onBeforeSelect and onSelect callbacks - * onBeforeSelect can alter or abort the selection + * onBeforeSelect is called to allow the user to alter or abort the selection + * onSelect is called to notify the user of the selection * * Called when the user selects an item with ENTER or clicks the dropdown */ @@ -1255,7 +1151,11 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel $select.sizeSearchInput(); }; - // Remove item from multiple select + /** + * Remove item from multiple select + * Calls onBeforeRemove to allow the user to prevent the removal of the item + * Then calls onRemove to notify the user the item has been removed + */ ctrl.removeChoice = function (index) { var removedChoice = $select.selected[index]; diff --git a/dist/select.select2.min.js b/dist/select.select2.min.js index 92625e944..0bda3eb56 100644 --- a/dist/select.select2.min.js +++ b/dist/select.select2.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-06T11:06:02.035Z + * Version: 0.12.1 - 2015-08-06T13:28:34.961Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],c=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(c.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,c=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,l,n){n(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(c){var l=c[0].getBoundingClientRect();return{width:l.width||c.prop("offsetWidth"),height:l.height||c.prop("offsetHeight"),top:l.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:l.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);c.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,c,l){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(e,n){if(!n.repeat)throw c("repeat","Expected 'repeat' expression.");return function(e,n,i,s,r){var a=i.groupBy,o=i.groupFilter;if(s.parseRepeatAttr(i.repeat,a,o),s.disableChoiceExpression=i.uiDisableChoice,s.onHighlightCallback=i.onHighlight,a){var u=n.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=n.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(s.parserResult.itemName,"$select.items",s.parserResult.trackByExp,a)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+s.parserResult.itemName+")").attr("ng-click","$select.select("+s.parserResult.itemName+",false,$event)");var d=n.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),l(n,r)(e),e.$watch("$select.search",function(e){e&&!s.open&&s.multiple&&s.activate(!1,!0),s.activeIndex=0})}}}}]),c.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,c,l,n,i,s,r,a){function o(){(h.resetSearchInput||void 0===h.resetSearchInput&&a.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var c,l,n=[];for(c=0;c0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:c=!1}return c}function d(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw r("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var l=t[h.activeIndex],n=l.offsetTop+l.clientHeight-e[0].scrollTop,i=e[0].offsetHeight;n>i?e[0].scrollTop+=n-i:n=h.items.length?0:h.activeIndex,l(function(){h.search=e||h.search,h.searchInput[0].focus()})},i=h.onDropdownCallback(t,{open:!0});angular.isDefined(i)?angular.isFunction(i.then)?i.then(function(e){e&&n()}):i===!0?n():i&&n():n()}},h.parseRepeatAttr=function(e,c,l){function n(e){var n=t.$eval(c);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(n)?n(e):e[n],c=h.findGroupByName(t);c?c.items.push(e):h.groups.push({name:t,items:[e]})}),l){var i=t.$eval(l);angular.isFunction(i)?h.groups=i(h.groups):angular.isArray(i)&&(h.groups=u(h.groups,i))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function i(e){h.items=e}h.setItemsFn=c?n:i,h.parserResult=s.parse(e),h.isGrouped=!!c,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var c=h.selected;if(h.isEmpty()||angular.isArray(c)&&!c.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var l=e.filter(function(e){return c.indexOf(e)<0});h.setItemsFn(l)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw r("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),c=-1===t?!1:t===h.activeIndex;return c&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),c},h.isDisabled=function(e){if(!h.open)return!1;var t,c=h.items.indexOf(e[h.itemProperty]),l=!1;return c>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[c],l=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=l),l},h.select=function(e,c,n){if((void 0===e||!e._uiSelectChoiceDisabled)&&(h.items||h.search)){var i={};i[h.parserResult.itemName]=e;var s={$item:e,$model:h.parserResult.modelMapper(t,i)},r=function(e){s.$item=e,t.$broadcast("uis:select",e),l(function(){h.onSelectCallback(t,s)}),h.closeOnSelect&&h.close(c),n&&"click"===n.type&&(h.clickTriggeredSelect=!0)};if(!angular.isDefined(h.onBeforeRemoveCallback))return r(e),void 0;var a=h.onBeforeSelectCallback(t,s);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(t){t&&(t===!0?r(e):t&&r(t))}):a===!0?r(e):a&&r(a):r(e)}},h.close=function(e){function c(){h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),o(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e)}if(h.open){var l=h.onDropdownCallback(t,{open:!1});angular.isDefined(l)?angular.isFunction(l.then)?l.then(function(e){e&&c()}):l===!0?c():l&&c():c()}},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),l(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var c,l=h.selected[t];return l&&!angular.isUndefined(h.lockChoiceExpression)&&(c=!!e.$eval(h.lockChoiceExpression),l._uiSelectChoiceLocked=c),c};var v=null;h.sizeSearchInput=function(){var e=h.searchInput[0],c=h.searchInput.parent().parent()[0],n=function(){return c.clientWidth*!!e.offsetParent},i=function(t){if(0===t)return!1;var c=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>c&&(c=t),h.searchInput.css("width",c+"px"),!0};h.searchInput.css("width","10px"),l(function(){null!==v||i(n())||(v=t.$watch(n,function(e){i(e)&&(v(),v=null)}))})},h.searchInput.on("keydown",function(c){var l=c.which;t.$apply(function(){p(l)}),e.isVerticalMovement(l)&&h.items.length>0&&d(),(l===e.ENTER||l===e.ESC)&&(c.preventDefault(),c.stopPropagation())}),h.searchInput.on("keyup",function(c){c.which===e.TAB||e.isControl(c)||e.isFunctionKey(c)||c.which===e.ESC||e.isVerticalMovement(c.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:c})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),c.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,c,l,n,i,s,r){return{restrict:"EA",templateUrl:function(e,t){var l=t.theme||c.theme;return l+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(i,a){return angular.isDefined(a.multiple)?i.append("").removeAttr("multiple"):i.append(""),function(i,a,o,u,p){function d(e){if(v.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(a[0],e.target):a[0].contains(e.target),!t&&!v.clickTriggeredSelect){var c=["input","button","textarea"],l=angular.element(e.target).scope(),n=l&&l.$select&&l.$select!==v;n||(n=~c.indexOf(e.target.tagName.toLowerCase())),v.close(n),i.$digest()}v.clickTriggeredSelect=!1}}function h(){var t=n(a);E=angular.element('
    '),E[0].style.width=t.width+"px",E[0].style.height=t.height+"px",a.after(E),w=a[0].style.width,e.find("body").append(a),a[0].style.position="absolute",a[0].style.left=t.left+"px",a[0].style.top=t.top+"px",a[0].style.width=t.width+"px"}function f(){null!==E&&(E.replaceWith(a),E=null,a[0].style.position="",a[0].style.left="",a[0].style.top="",a[0].style.width=w)}var v=u[0],g=u[1];v.generatedId=c.generateId(),v.baseTitle=o.title||"Select box",v.focusserTitle=v.baseTitle+" focus",v.focusserId="focusser-"+v.generatedId,v.closeOnSelect=function(){return angular.isDefined(o.closeOnSelect)?s(o.closeOnSelect)():c.closeOnSelect}(),v.onSelectCallback=s(o.onSelect),v.onBeforeSelectCallback=s(o.onBeforeSelect),v.onRemoveCallback=s(o.onRemove),v.onBeforeRemoveCallback=s(o.onBeforeRemove),v.onKeypressCallback=s(o.onKeypress),v.onDropdownCallback=s(o.onDropdown),v.limit=angular.isDefined(o.limit)?parseInt(o.limit,10):void 0,v.ngModel=g,v.choiceGrouped=function(e){return v.isGrouped&&e&&e.name},o.tabindex&&o.$observe("tabindex",function(e){v.focusInput.attr("tabindex",e),a.removeAttr("tabindex")});var m=i.$eval(o.searchEnabled);v.searchEnabled=void 0!==m?m:c.searchEnabled;var $=i.$eval(o.sortable);v.sortable=void 0!==$?$:c.sortable,o.$observe("disabled",function(){v.disabled=void 0!==o.disabled?o.disabled:!1}),angular.isDefined(o.autofocus)&&r(function(){v.setFocus()}),angular.isDefined(o.focusOn)&&i.$on(o.focusOn,function(){r(function(){v.setFocus()})}),e.on("click",d),i.$on("$destroy",function(){e.off("click",d)}),p(i,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),c.removeAttr("data-ui-select-match"),1!==c.length)throw l("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);a.querySelectorAll(".ui-select-match").replaceWith(c);var n=t.querySelectorAll(".ui-select-choices");if(n.removeAttr("ui-select-choices"),n.removeAttr("data-ui-select-choices"),1!==n.length)throw l("transcluded","Expected 1 .ui-select-choices but got '{0}'.",n.length);a.querySelectorAll(".ui-select-choices").replaceWith(n)});var b=i.$eval(o.appendToBody);(void 0!==b?b:c.appendToBody)&&(i.$watch("$select.open",function(e){e?h():f()}),i.$on("$destroy",function(){f()}));var E=null,w="",S=null,x="direction-up";i.$watch("$select.open",function(c){if(c){if(S=angular.element(a).querySelectorAll(".ui-select-dropdown"),null===S)return;S[0].style.opacity=0,r(function(){var c=n(a),l=n(S);c.top+c.height+l.height>t.pageYOffset+e[0].documentElement.clientHeight&&a.addClass(x),S[0].style.opacity=1})}else{if(null===S)return;a.removeClass(x)}})}}}}]),c.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,l=t.parent().attr("multiple");return c+(l?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,l,n){function i(e){n.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}n.lockChoiceExpression=l.uiLockChoice,l.$observe("placeholder",function(t){n.placeholder=void 0!==t?t:e.placeholder}),l.$observe("allowClear",i),i(l.allowClear),n.multiple&&n.sizeSearchInput()}}}]),c.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var c,l=this,n=e.$select;e.$evalAsync(function(){c=e.ngModel}),l.activeMatchIndex=-1,l.updateModel=function(){c.$setViewValue(Date.now()),l.refreshComponent()},l.refreshComponent=function(){n.refreshItems(),n.sizeSearchInput()},l.removeChoice=function(c){function i(){t(function(){n.onRemoveCallback(e,a)}),l.updateModel()}var s=n.selected[c];if(!s._uiSelectChoiceLocked){var r={};r[n.parserResult.itemName]=s,n.selected.splice(c,1),l.activeMatchIndex=-1,n.sizeSearchInput();var a={$item:s,$model:n.parserResult.modelMapper(e,r)};if(!angular.isDefined(l.onBeforeRemoveCallback))return i(),void 0;var o=l.onBeforeRemoveCallback(e,a);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(e){e&&i(e)}):o===!0&&i():i()}},l.getPlaceholder=function(){return n.selected&&n.selected.length?void 0:n.placeholder}}],controllerAs:"$selectMultiple",link:function(l,n,i,s){function r(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(t){function c(){switch(t){case e.LEFT:return~p.activeMatchIndex?d:s;case e.RIGHT:return~p.activeMatchIndex&&a!==s?u:(o.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(a),d):s;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),a):!1}}var l=r(o.searchInput[0]),n=o.selected.length,i=0,s=n-1,a=p.activeMatchIndex,u=p.activeMatchIndex+1,d=p.activeMatchIndex-1,h=a;return l>0||o.search.length&&t==e.RIGHT?!1:(o.close(),h=c(),p.activeMatchIndex=o.selected.length&&h!==!1?Math.min(s,Math.max(i,h)):-1,!0)}var o=s[0],u=l.ngModel=s[1],p=l.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,u.$parsers.unshift(function(){for(var e,t={},c=[],n=o.selected.length-1;n>=0;n--)t={},t[o.parserResult.itemName]=o.selected[n],e=o.parserResult.modelMapper(l,t),c.unshift(e);return c}),u.$formatters.unshift(function(e){var t,c=o.parserResult.source(l,{$select:{search:""}}),n={};if(!c)return e;var i=[],s=function(e,c){if(e&&e.length){for(var s=e.length-1;s>=0;s--){if(n[o.parserResult.itemName]=e[s],t=o.parserResult.modelMapper(l,n),o.parserResult.trackByExp){var r=/\.(.+)/.exec(o.parserResult.trackByExp);if(r.length>0&&t[r[1]]==c[r[1]])return i.unshift(e[s]),!0}if(angular.equals(t,c))return i.unshift(e[s]),!0}return!1}};if(!e)return i;for(var r=e.length-1;r>=0;r--)s(o.selected,e[r])||s(c,e[r])||i.unshift(e[r]);return i}),l.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);o.selected=[]}o.selected=u.$viewValue,l.$evalAsync()},l.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),p.updateModel())}),l.$on("uis:activate",function(){p.activeMatchIndex=-1}),l.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(t){var c=t.which;l.$apply(function(){var t=!1;e.isHorizontalMovement(c)&&(t=a(c)),t&&c!=e.TAB})}),o.searchInput.on("blur",function(){c(function(){p.activeMatchIndex=-1})})}}}]),c.directive("uiSelectSingle",["$timeout","$compile",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(l,n,i,s){var r=s[0],a=s[1];a.$parsers.unshift(function(e){var t,c={};return c[r.parserResult.itemName]=e,t=r.parserResult.modelMapper(l,c)}),a.$formatters.unshift(function(e){var t,c=r.parserResult.source(l,{$select:{search:""}}),n={};if(c){var i=function(c){return n[r.parserResult.itemName]=c,t=r.parserResult.modelMapper(l,n),t==e};if(r.selected&&i(r.selected))return r.selected;for(var s=c.length-1;s>=0;s--)if(i(c[s]))return c[s]}return e}),l.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){r.selected=a.$viewValue},l.$on("uis:select",function(e,t){r.selected=t}),l.$on("uis:close",function(e,c){t(function(){r.focusser.prop("disabled",!1),c||r.focusser[0].focus()},0,!1)}),l.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");c(o)(l),r.focusser=o,r.focusInput=o,n.parent().append(o),o.bind("focus",function(){l.$evalAsync(function(){r.focus=!0})}),o.bind("blur",function(){l.$evalAsync(function(){r.focus=!1})}),o.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),r.select(void 0),l.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),r.activate()),l.$digest()),void 0)}),o.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(r.activate(o.val()),o.val(""),l.$digest())})}}}]),c.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var l=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!l)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:l[2],source:t(l[3]),trackByExp:l[4],modelMapper:t(l[1]||l[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,l){var n=e+" in "+(l?"$group.items":t);return c&&(n+=" track by "+c),n}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("select2/choices.tpl.html",'
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    ')}]); \ No newline at end of file +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],c=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(c.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,c=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,l,n){n(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(c){var l=c[0].getBoundingClientRect();return{width:l.width||c.prop("offsetWidth"),height:l.height||c.prop("offsetHeight"),top:l.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:l.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);c.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,c,l){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(e,n){if(!n.repeat)throw c("repeat","Expected 'repeat' expression.");return function(e,n,i,s,r){var a=i.groupBy,o=i.groupFilter;if(s.parseRepeatAttr(i.repeat,a,o),s.disableChoiceExpression=i.uiDisableChoice,s.onHighlightCallback=i.onHighlight,a){var u=n.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=n.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(s.parserResult.itemName,"$select.items",s.parserResult.trackByExp,a)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+s.parserResult.itemName+")").attr("ng-click","$select.select("+s.parserResult.itemName+",false,$event)");var d=n.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),l(n,r)(e),e.$watch("$select.search",function(e){e&&!s.open&&s.multiple&&s.activate(!1,!0),s.activeIndex=0})}}}}]),c.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,c,l,n,i,s,r,a){function o(){(h.resetSearchInput||void 0===h.resetSearchInput&&a.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var c,l,n=[];for(c=0;c0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:c=!1}return c}function d(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw r("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var l=t[h.activeIndex],n=l.offsetTop+l.clientHeight-e[0].scrollTop,i=e[0].offsetHeight;n>i?e[0].scrollTop+=n-i:n=h.items.length?0:h.activeIndex,l(function(){h.search=e||h.search,h.searchInput[0].focus()})},i=h.onDropdownCallback(t,{open:!0});angular.isDefined(i)?angular.isFunction(i.then)?i.then(function(e){e&&n()}):i===!0?n():i&&n():n()}},h.parseRepeatAttr=function(e,c,l){function n(e){var n=t.$eval(c);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(n)?n(e):e[n],c=h.findGroupByName(t);c?c.items.push(e):h.groups.push({name:t,items:[e]})}),l){var i=t.$eval(l);angular.isFunction(i)?h.groups=i(h.groups):angular.isArray(i)&&(h.groups=u(h.groups,i))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function i(e){h.items=e}h.setItemsFn=c?n:i,h.parserResult=s.parse(e),h.isGrouped=!!c,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var c=h.selected;if(h.isEmpty()||angular.isArray(c)&&!c.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var l=e.filter(function(e){return c.indexOf(e)<0});h.setItemsFn(l)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw r("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),c=-1===t?!1:t===h.activeIndex;return c&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),c},h.isDisabled=function(e){if(!h.open)return!1;var t,c=h.items.indexOf(e[h.itemProperty]),l=!1;return c>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[c],l=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=l),l},h.select=function(e,c,n){if((void 0===e||!e._uiSelectChoiceDisabled)&&(h.items||h.search)){var i={};i[h.parserResult.itemName]=e;var s={$item:e,$model:h.parserResult.modelMapper(t,i)},r=function(e){s.$item=e,t.$broadcast("uis:select",e),l(function(){h.onSelectCallback(t,s)}),h.closeOnSelect&&h.close(c),n&&"click"===n.type&&(h.clickTriggeredSelect=!0)};if(!angular.isDefined(h.onBeforeRemoveCallback))return r(e),void 0;var a=h.onBeforeSelectCallback(t,s);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(t){t&&(t===!0?r(e):t&&r(t))}):a===!0?r(e):a&&r(a):r(e)}},h.close=function(e){function c(){h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),o(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e)}if(h.open){var l=h.onDropdownCallback(t,{open:!1});angular.isDefined(l)?angular.isFunction(l.then)?l.then(function(e){e&&c()}):l===!0?c():l&&c():c()}},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),l(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var c,l=h.selected[t];return l&&!angular.isUndefined(h.lockChoiceExpression)&&(c=!!e.$eval(h.lockChoiceExpression),l._uiSelectChoiceLocked=c),c};var v=null;h.sizeSearchInput=function(){var e=h.searchInput[0],c=h.searchInput.parent().parent()[0],n=function(){return c.clientWidth*!!e.offsetParent},i=function(t){if(0===t)return!1;var c=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>c&&(c=t),h.searchInput.css("width",c+"px"),!0};h.searchInput.css("width","10px"),l(function(){null!==v||i(n())||(v=t.$watch(n,function(e){i(e)&&(v(),v=null)}))})},h.searchInput.on("keydown",function(c){var l=c.which;t.$apply(function(){p(l)}),e.isVerticalMovement(l)&&h.items.length>0&&d(),(l===e.ENTER||l===e.ESC)&&(c.preventDefault(),c.stopPropagation())}),h.searchInput.on("keyup",function(c){c.which===e.TAB||e.isControl(c)||e.isFunctionKey(c)||c.which===e.ESC||e.isVerticalMovement(c.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:c})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),c.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,c,l,n,i,s,r){return{restrict:"EA",templateUrl:function(e,t){var l=t.theme||c.theme;return l+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(i,a){return angular.isDefined(a.multiple)?i.append("").removeAttr("multiple"):i.append(""),function(i,a,o,u,p){function d(e){if(v.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(a[0],e.target):a[0].contains(e.target),!t&&!v.clickTriggeredSelect){var c=["input","button","textarea"],l=angular.element(e.target).scope(),n=l&&l.$select&&l.$select!==v;n||(n=~c.indexOf(e.target.tagName.toLowerCase())),v.close(n),i.$digest()}v.clickTriggeredSelect=!1}}function h(){var t=n(a);w=angular.element('
    '),w[0].style.width=t.width+"px",w[0].style.height=t.height+"px",a.after(w),x=a[0].style.width,e.find("body").append(a),a[0].style.position="absolute",a[0].style.left=t.left+"px",a[0].style.top=t.top+"px",a[0].style.width=t.width+"px"}function f(){null!==w&&(w.replaceWith(a),w=null,a[0].style.position="",a[0].style.left="",a[0].style.top="",a[0].style.width=x)}var v=u[0],g=u[1];v.generatedId=c.generateId(),v.baseTitle=o.title||"Select box",v.focusserTitle=v.baseTitle+" focus",v.focusserId="focusser-"+v.generatedId,v.closeOnSelect=function(){return angular.isDefined(o.closeOnSelect)?s(o.closeOnSelect)():c.closeOnSelect}(),v.onSelectCallback=s(o.onSelect),v.onBeforeSelectCallback=s(o.onBeforeSelect),v.onRemoveCallback=s(o.onRemove),v.onBeforeRemoveCallback=s(o.onBeforeRemove),v.onKeypressCallback=s(o.onKeypress),v.onDropdownCallback=s(o.onDropdown),v.limit=angular.isDefined(o.limit)?parseInt(o.limit,10):void 0,v.ngModel=g,v.choiceGrouped=function(e){return v.isGrouped&&e&&e.name},o.tabindex&&o.$observe("tabindex",function(e){v.focusInput.attr("tabindex",e),a.removeAttr("tabindex")});var m=i.$eval(o.searchEnabled);v.searchEnabled=void 0!==m?m:c.searchEnabled;var $=i.$eval(o.sortable);v.sortable=void 0!==$?$:c.sortable,o.$observe("disabled",function(){v.disabled=void 0!==o.disabled?o.disabled:!1}),angular.isDefined(o.autofocus)&&r(function(){v.setFocus()}),angular.isDefined(o.focusOn)&&i.$on(o.focusOn,function(){r(function(){v.setFocus()})}),e.on("click",d),i.$on("$destroy",function(){e.off("click",d)}),p(i,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),c.removeAttr("data-ui-select-match"),1!==c.length)throw l("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);a.querySelectorAll(".ui-select-match").replaceWith(c);var n=t.querySelectorAll(".ui-select-choices");if(n.removeAttr("ui-select-choices"),n.removeAttr("data-ui-select-choices"),1!==n.length)throw l("transcluded","Expected 1 .ui-select-choices but got '{0}'.",n.length);a.querySelectorAll(".ui-select-choices").replaceWith(n)});var b=i.$eval(o.appendToBody);(void 0!==b?b:c.appendToBody)&&(i.$watch("$select.open",function(e){e?h():f()}),i.$on("$destroy",function(){f()}));var w=null,x="",E=null,y="direction-up";i.$watch("$select.open",function(c){if(c){if(E=angular.element(a).querySelectorAll(".ui-select-dropdown"),null===E)return;E[0].style.opacity=0,r(function(){var c=n(a),l=n(E);c.top+c.height+l.height>t.pageYOffset+e[0].documentElement.clientHeight&&a.addClass(y),E[0].style.opacity=1})}else{if(null===E)return;a.removeClass(y)}})}}}}]),c.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,l=t.parent().attr("multiple");return c+(l?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,l,n){function i(e){n.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}n.lockChoiceExpression=l.uiLockChoice,l.$observe("placeholder",function(t){n.placeholder=void 0!==t?t:e.placeholder}),l.$observe("allowClear",i),i(l.allowClear),n.multiple&&n.sizeSearchInput()}}}]),c.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var c,l=this,n=e.$select;e.$evalAsync(function(){c=e.ngModel}),l.activeMatchIndex=-1,l.updateModel=function(){c.$setViewValue(Date.now()),l.refreshComponent()},l.refreshComponent=function(){n.refreshItems(),n.sizeSearchInput()},l.removeChoice=function(c){function i(){t(function(){n.onRemoveCallback(e,a)}),l.updateModel()}var s=n.selected[c];if(!s._uiSelectChoiceLocked){var r={};r[n.parserResult.itemName]=s,n.selected.splice(c,1),l.activeMatchIndex=-1,n.sizeSearchInput();var a={$item:s,$model:n.parserResult.modelMapper(e,r)};if(!angular.isDefined(l.onBeforeRemoveCallback))return i(),void 0;var o=l.onBeforeRemoveCallback(e,a);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(e){e&&i(e)}):o===!0&&i():i()}},l.getPlaceholder=function(){return n.selected&&n.selected.length?void 0:n.placeholder}}],controllerAs:"$selectMultiple",link:function(l,n,i,s){function r(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(t){function c(){switch(t){case e.LEFT:return~p.activeMatchIndex?d:s;case e.RIGHT:return~p.activeMatchIndex&&a!==s?u:(o.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(a),d):s;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),a):!1}}var l=r(o.searchInput[0]),n=o.selected.length,i=0,s=n-1,a=p.activeMatchIndex,u=p.activeMatchIndex+1,d=p.activeMatchIndex-1,h=a;return l>0||o.search.length&&t==e.RIGHT?!1:(o.close(),h=c(),p.activeMatchIndex=o.selected.length&&h!==!1?Math.min(s,Math.max(i,h)):-1,!0)}var o=s[0],u=l.ngModel=s[1],p=l.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,u.$parsers.unshift(function(){for(var e,t={},c=[],n=o.selected.length-1;n>=0;n--)t={},t[o.parserResult.itemName]=o.selected[n],e=o.parserResult.modelMapper(l,t),c.unshift(e);return c}),u.$formatters.unshift(function(e){var t,c=o.parserResult.source(l,{$select:{search:""}}),n={};if(!c)return e;var i=[],s=function(e,c){if(e&&e.length){for(var s=e.length-1;s>=0;s--){if(n[o.parserResult.itemName]=e[s],t=o.parserResult.modelMapper(l,n),o.parserResult.trackByExp){var r=/\.(.+)/.exec(o.parserResult.trackByExp);if(r.length>0&&t[r[1]]==c[r[1]])return i.unshift(e[s]),!0}if(angular.equals(t,c))return i.unshift(e[s]),!0}return!1}};if(!e)return i;for(var r=e.length-1;r>=0;r--)s(o.selected,e[r])||s(c,e[r])||i.unshift(e[r]);return i}),l.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);o.selected=[]}o.selected=u.$viewValue,l.$evalAsync()},l.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),p.updateModel())}),l.$on("uis:activate",function(){p.activeMatchIndex=-1}),l.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(t){var c=t.which;l.$apply(function(){var t=!1;e.isHorizontalMovement(c)&&(t=a(c)),t&&c!=e.TAB})}),o.searchInput.on("blur",function(){c(function(){p.activeMatchIndex=-1})})}}}]),c.directive("uiSelectSingle",["$timeout","$compile",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(l,n,i,s){var r=s[0],a=s[1];a.$parsers.unshift(function(e){var t,c={};return c[r.parserResult.itemName]=e,t=r.parserResult.modelMapper(l,c)}),a.$formatters.unshift(function(e){var t,c=r.parserResult.source(l,{$select:{search:""}}),n={};if(c){var i=function(c){return n[r.parserResult.itemName]=c,t=r.parserResult.modelMapper(l,n),t==e};if(r.selected&&i(r.selected))return r.selected;for(var s=c.length-1;s>=0;s--)if(i(c[s]))return c[s]}return e}),l.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){r.selected=a.$viewValue},l.$on("uis:select",function(e,t){r.selected=t}),l.$on("uis:close",function(e,c){t(function(){r.focusser.prop("disabled",!1),c||r.focusser[0].focus()},0,!1)}),l.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");c(o)(l),r.focusser=o,r.focusInput=o,n.parent().append(o),o.bind("focus",function(){l.$evalAsync(function(){r.focus=!0})}),o.bind("blur",function(){l.$evalAsync(function(){r.focus=!1})}),o.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),r.select(void 0),l.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),r.activate()),l.$digest()),void 0)}),o.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(r.activate(o.val()),o.val(""),l.$digest())})}}}]),c.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var l=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!l)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:l[2],source:t(l[3]),trackByExp:l[4],modelMapper:t(l[1]||l[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,l){var n=e+" in "+(l?"$group.items":t);return c&&(n+=" track by "+c),n}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("select2/choices.tpl.html",'
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/dist/select.selectize.js b/dist/select.selectize.js index 9317ad0b2..54352dac1 100644 --- a/dist/select.selectize.js +++ b/dist/select.selectize.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-06T11:06:02.044Z + * Version: 0.12.1 - 2015-08-06T13:28:34.967Z * License: MIT */ @@ -28,110 +28,6 @@ var KEY = { DELETE: 46, COMMAND: 91, - MAP: { - 91: "COMMAND", - 8: "BACKSPACE", - 9: "TAB", - 13: "ENTER", - 16: "SHIFT", - 17: "CTRL", - 18: "ALT", - 19: "PAUSEBREAK", - 20: "CAPSLOCK", - 27: "ESC", - 32: "SPACE", - 33: "PAGE_UP", - 34: "PAGE_DOWN", - 35: "END", - 36: "HOME", - 37: "LEFT", - 38: "UP", - 39: "RIGHT", - 40: "DOWN", - 43: "+", - 44: "PRINTSCREEN", - 45: "INSERT", - 46: "DELETE", - 48: "0", - 49: "1", - 50: "2", - 51: "3", - 52: "4", - 53: "5", - 54: "6", - 55: "7", - 56: "8", - 57: "9", - 59: ";", - 61: "=", - 65: "A", - 66: "B", - 67: "C", - 68: "D", - 69: "E", - 70: "F", - 71: "G", - 72: "H", - 73: "I", - 74: "J", - 75: "K", - 76: "L", - 77: "M", - 78: "N", - 79: "O", - 80: "P", - 81: "Q", - 82: "R", - 83: "S", - 84: "T", - 85: "U", - 86: "V", - 87: "W", - 88: "X", - 89: "Y", - 90: "Z", - 96: "0", - 97: "1", - 98: "2", - 99: "3", - 100: "4", - 101: "5", - 102: "6", - 103: "7", - 104: "8", - 105: "9", - 106: "*", - 107: "+", - 109: "-", - 110: ".", - 111: "/", - 112: "F1", - 113: "F2", - 114: "F3", - 115: "F4", - 116: "F5", - 117: "F6", - 118: "F7", - 119: "F8", - 120: "F9", - 121: "F10", - 122: "F11", - 123: "F12", - 144: "NUMLOCK", - 145: "SCROLLLOCK", - 186: ";", - 187: "=", - 188: ",", - 189: "-", - 190: ".", - 191: "/", - 192: "`", - 219: "[", - 220: "\\", - 221: "]", - 222: "'" - }, - isControl: function (e) { var k = e.which; switch (k) { @@ -605,10 +501,10 @@ uis.controller('uiSelectCtrl', return isDisabled; }; - /** * Selects an item. Calls the onBeforeSelect and onSelect callbacks - * onBeforeSelect can alter or abort the selection + * onBeforeSelect is called to allow the user to alter or abort the selection + * onSelect is called to notify the user of the selection * * Called when the user selects an item with ENTER or clicks the dropdown */ @@ -1255,7 +1151,11 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel $select.sizeSearchInput(); }; - // Remove item from multiple select + /** + * Remove item from multiple select + * Calls onBeforeRemove to allow the user to prevent the removal of the item + * Then calls onRemove to notify the user the item has been removed + */ ctrl.removeChoice = function (index) { var removedChoice = $select.selected[index]; diff --git a/dist/select.selectize.min.js b/dist/select.selectize.min.js index 7d4fa1486..8fd8b5aa7 100644 --- a/dist/select.selectize.min.js +++ b/dist/select.selectize.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-06T11:06:02.044Z + * Version: 0.12.1 - 2015-08-06T13:28:34.967Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var n=t.which;switch(n){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,n=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,i,c){c(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var i=n[0].getBoundingClientRect();return{width:i.width||n.prop("offsetWidth"),height:i.height||n.prop("offsetHeight"),top:i.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:i.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);n.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,c){if(!c.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,c,r,l,s){var o=r.groupBy,a=r.groupFilter;if(l.parseRepeatAttr(r.repeat,o,a),l.disableChoiceExpression=r.uiDisableChoice,l.onHighlightCallback=r.onHighlight,o){var u=c.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=c.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(l.parserResult.itemName,"$select.items",l.parserResult.trackByExp,o)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+l.parserResult.itemName+")").attr("ng-click","$select.select("+l.parserResult.itemName+",false,$event)");var d=c.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),i(c,s)(e),e.$watch("$select.search",function(e){e&&!l.open&&l.multiple&&l.activate(!1,!0),l.activeIndex=0})}}}}]),n.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,n,i,c,r,l,s,o){function a(){(f.resetSearchInput||void 0===f.resetSearchInput&&o.resetSearchInput)&&(f.search=h,f.selected&&f.items.length&&!f.multiple&&(f.activeIndex=f.items.indexOf(f.selected)))}function u(e,t){var n,i,c=[];for(n=0;n0&&f.activeIndex--;break;case e.TAB:(!f.multiple||f.open)&&f.select(f.items[f.activeIndex],!0);break;case e.ENTER:f.open?f.select(f.items[f.activeIndex]):f.activate(!1,!0);break;case e.ESC:f.close();break;default:n=!1}return n}function d(){var e=n.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw s("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(f.activeIndex<0)){var i=t[f.activeIndex],c=i.offsetTop+i.clientHeight-e[0].scrollTop,r=e[0].offsetHeight;c>r?e[0].scrollTop+=c-r:c=f.items.length?0:f.activeIndex,i(function(){f.search=e||f.search,f.searchInput[0].focus()})},r=f.onDropdownCallback(t,{open:!0});angular.isDefined(r)?angular.isFunction(r.then)?r.then(function(e){e&&c()}):r===!0?c():r&&c():c()}},f.parseRepeatAttr=function(e,n,i){function c(e){var c=t.$eval(n);if(f.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(c)?c(e):e[c],n=f.findGroupByName(t);n?n.items.push(e):f.groups.push({name:t,items:[e]})}),i){var r=t.$eval(i);angular.isFunction(r)?f.groups=r(f.groups):angular.isArray(r)&&(f.groups=u(f.groups,r))}f.items=[],f.groups.forEach(function(e){f.items=f.items.concat(e.items)})}function r(e){f.items=e}f.setItemsFn=n?c:r,f.parserResult=l.parse(e),f.isGrouped=!!n,f.itemProperty=f.parserResult.itemName,f.refreshItems=function(e){e=e||f.parserResult.source(t);var n=f.selected;if(f.isEmpty()||angular.isArray(n)&&!n.length||!f.removeSelected)f.setItemsFn(e);else if(void 0!==e){var i=e.filter(function(e){return n.indexOf(e)<0});f.setItemsFn(i)}},t.$watchCollection(f.parserResult.source,function(e){if(void 0===e||null===e)f.items=[];else{if(!angular.isArray(e))throw s("items","Expected an array but got '{0}'.",e);f.refreshItems(e),f.ngModel.$modelValue=null}})},f.setActiveItem=function(e){f.activeIndex=f.items.indexOf(e)},f.isActive=function(e){if(!f.open)return!1;var t=f.items.indexOf(e[f.itemProperty]),n=-1===t?!1:t===f.activeIndex;return n&&!angular.isUndefined(f.onHighlightCallback)&&e.$eval(f.onHighlightCallback),n},f.isDisabled=function(e){if(!f.open)return!1;var t,n=f.items.indexOf(e[f.itemProperty]),i=!1;return n>=0&&!angular.isUndefined(f.disableChoiceExpression)&&(t=f.items[n],i=!!e.$eval(f.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i},f.select=function(e,n,c){if((void 0===e||!e._uiSelectChoiceDisabled)&&(f.items||f.search)){var r={};r[f.parserResult.itemName]=e;var l={$item:e,$model:f.parserResult.modelMapper(t,r)},s=function(e){l.$item=e,t.$broadcast("uis:select",e),i(function(){f.onSelectCallback(t,l)}),f.closeOnSelect&&f.close(n),c&&"click"===c.type&&(f.clickTriggeredSelect=!0)};if(!angular.isDefined(f.onBeforeRemoveCallback))return s(e),void 0;var o=f.onBeforeSelectCallback(t,l);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(t){t&&(t===!0?s(e):t&&s(t))}):o===!0?s(e):o&&s(o):s(e)}},f.close=function(e){function n(){f.ngModel&&f.ngModel.$setTouched&&f.ngModel.$setTouched(),a(),f.open=!1,f.searchEnabled||angular.element(f.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e)}if(f.open){var i=f.onDropdownCallback(t,{open:!1});angular.isDefined(i)?angular.isFunction(i.then)?i.then(function(e){e&&n()}):i===!0?n():i&&n():n()}},f.setFocus=function(){f.focus||f.focusInput[0].focus()},f.clear=function(e){f.select(void 0),e.stopPropagation(),i(function(){f.focusser[0].focus()},0,!1)},f.toggle=function(e){f.open?(f.close(),e.preventDefault(),e.stopPropagation()):f.activate()},f.isLocked=function(e,t){var n,i=f.selected[t];return i&&!angular.isUndefined(f.lockChoiceExpression)&&(n=!!e.$eval(f.lockChoiceExpression),i._uiSelectChoiceLocked=n),n};var v=null;f.sizeSearchInput=function(){var e=f.searchInput[0],n=f.searchInput.parent().parent()[0],c=function(){return n.clientWidth*!!e.offsetParent},r=function(t){if(0===t)return!1;var n=t-e.offsetLeft-f.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=t),f.searchInput.css("width",n+"px"),!0};f.searchInput.css("width","10px"),i(function(){null!==v||r(c())||(v=t.$watch(c,function(e){r(e)&&(v(),v=null)}))})},f.searchInput.on("keydown",function(n){var i=n.which;t.$apply(function(){p(i)}),e.isVerticalMovement(i)&&f.items.length>0&&d(),(i===e.ENTER||i===e.ESC)&&(n.preventDefault(),n.stopPropagation())}),f.searchInput.on("keyup",function(n){n.which===e.TAB||e.isControl(n)||e.isFunctionKey(n)||n.which===e.ESC||e.isVerticalMovement(n.which)||void 0!==f.onKeypressCallback&&f.onKeypressCallback(t,{event:n})}),t.$on("$destroy",function(){f.searchInput.off("keyup keydown blur paste")})}]),n.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,i,c,r,l,s){return{restrict:"EA",templateUrl:function(e,t){var i=t.theme||n.theme;return i+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(r,o){return angular.isDefined(o.multiple)?r.append("").removeAttr("multiple"):r.append(""),function(r,o,a,u,p){function d(e){if(v.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(o[0],e.target):o[0].contains(e.target),!t&&!v.clickTriggeredSelect){var n=["input","button","textarea"],i=angular.element(e.target).scope(),c=i&&i.$select&&i.$select!==v;c||(c=~n.indexOf(e.target.tagName.toLowerCase())),v.close(c),r.$digest()}v.clickTriggeredSelect=!1}}function f(){var t=c(o);b=angular.element('
    '),b[0].style.width=t.width+"px",b[0].style.height=t.height+"px",o.after(b),S=o[0].style.width,e.find("body").append(o),o[0].style.position="absolute",o[0].style.left=t.left+"px",o[0].style.top=t.top+"px",o[0].style.width=t.width+"px"}function h(){null!==b&&(b.replaceWith(o),b=null,o[0].style.position="",o[0].style.left="",o[0].style.top="",o[0].style.width=S)}var v=u[0],g=u[1];v.generatedId=n.generateId(),v.baseTitle=a.title||"Select box",v.focusserTitle=v.baseTitle+" focus",v.focusserId="focusser-"+v.generatedId,v.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?l(a.closeOnSelect)():n.closeOnSelect}(),v.onSelectCallback=l(a.onSelect),v.onBeforeSelectCallback=l(a.onBeforeSelect),v.onRemoveCallback=l(a.onRemove),v.onBeforeRemoveCallback=l(a.onBeforeRemove),v.onKeypressCallback=l(a.onKeypress),v.onDropdownCallback=l(a.onDropdown),v.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,v.ngModel=g,v.choiceGrouped=function(e){return v.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){v.focusInput.attr("tabindex",e),o.removeAttr("tabindex")});var m=r.$eval(a.searchEnabled);v.searchEnabled=void 0!==m?m:n.searchEnabled;var $=r.$eval(a.sortable);v.sortable=void 0!==$?$:n.sortable,a.$observe("disabled",function(){v.disabled=void 0!==a.disabled?a.disabled:!1}),angular.isDefined(a.autofocus)&&s(function(){v.setFocus()}),angular.isDefined(a.focusOn)&&r.$on(a.focusOn,function(){s(function(){v.setFocus()})}),e.on("click",d),r.$on("$destroy",function(){e.off("click",d)}),p(r,function(e){var t=angular.element("
    ").append(e),n=t.querySelectorAll(".ui-select-match");if(n.removeAttr("ui-select-match"),n.removeAttr("data-ui-select-match"),1!==n.length)throw i("transcluded","Expected 1 .ui-select-match but got '{0}'.",n.length);o.querySelectorAll(".ui-select-match").replaceWith(n);var c=t.querySelectorAll(".ui-select-choices");if(c.removeAttr("ui-select-choices"),c.removeAttr("data-ui-select-choices"),1!==c.length)throw i("transcluded","Expected 1 .ui-select-choices but got '{0}'.",c.length);o.querySelectorAll(".ui-select-choices").replaceWith(c)});var E=r.$eval(a.appendToBody);(void 0!==E?E:n.appendToBody)&&(r.$watch("$select.open",function(e){e?f():h()}),r.$on("$destroy",function(){h()}));var b=null,S="",w=null,C="direction-up";r.$watch("$select.open",function(n){if(n){if(w=angular.element(o).querySelectorAll(".ui-select-dropdown"),null===w)return;w[0].style.opacity=0,s(function(){var n=c(o),i=c(w);n.top+n.height+i.height>t.pageYOffset+e[0].documentElement.clientHeight&&o.addClass(C),w[0].style.opacity=1})}else{if(null===w)return;o.removeClass(C)}})}}}}]),n.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return n+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,i,c){function r(e){c.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}c.lockChoiceExpression=i.uiLockChoice,i.$observe("placeholder",function(t){c.placeholder=void 0!==t?t:e.placeholder}),i.$observe("allowClear",r),r(i.allowClear),c.multiple&&c.sizeSearchInput()}}}]),n.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,i=this,c=e.$select;e.$evalAsync(function(){n=e.ngModel}),i.activeMatchIndex=-1,i.updateModel=function(){n.$setViewValue(Date.now()),i.refreshComponent()},i.refreshComponent=function(){c.refreshItems(),c.sizeSearchInput()},i.removeChoice=function(n){function r(){t(function(){c.onRemoveCallback(e,o)}),i.updateModel()}var l=c.selected[n];if(!l._uiSelectChoiceLocked){var s={};s[c.parserResult.itemName]=l,c.selected.splice(n,1),i.activeMatchIndex=-1,c.sizeSearchInput();var o={$item:l,$model:c.parserResult.modelMapper(e,s)};if(!angular.isDefined(i.onBeforeRemoveCallback))return r(),void 0;var a=i.onBeforeRemoveCallback(e,o);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(e){e&&r(e)}):a===!0&&r():r()}},i.getPlaceholder=function(){return c.selected&&c.selected.length?void 0:c.placeholder}}],controllerAs:"$selectMultiple",link:function(i,c,r,l){function s(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function o(t){function n(){switch(t){case e.LEFT:return~p.activeMatchIndex?d:l;case e.RIGHT:return~p.activeMatchIndex&&o!==l?u:(a.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(o),d):l;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),o):!1}}var i=s(a.searchInput[0]),c=a.selected.length,r=0,l=c-1,o=p.activeMatchIndex,u=p.activeMatchIndex+1,d=p.activeMatchIndex-1,f=o;return i>0||a.search.length&&t==e.RIGHT?!1:(a.close(),f=n(),p.activeMatchIndex=a.selected.length&&f!==!1?Math.min(l,Math.max(r,f)):-1,!0)}var a=l[0],u=i.ngModel=l[1],p=i.$selectMultiple;a.multiple=!0,a.removeSelected=!0,a.focusInput=a.searchInput,u.$parsers.unshift(function(){for(var e,t={},n=[],c=a.selected.length-1;c>=0;c--)t={},t[a.parserResult.itemName]=a.selected[c],e=a.parserResult.modelMapper(i,t),n.unshift(e);return n}),u.$formatters.unshift(function(e){var t,n=a.parserResult.source(i,{$select:{search:""}}),c={};if(!n)return e;var r=[],l=function(e,n){if(e&&e.length){for(var l=e.length-1;l>=0;l--){if(c[a.parserResult.itemName]=e[l],t=a.parserResult.modelMapper(i,c),a.parserResult.trackByExp){var s=/\.(.+)/.exec(a.parserResult.trackByExp);if(s.length>0&&t[s[1]]==n[s[1]])return r.unshift(e[l]),!0}if(angular.equals(t,n))return r.unshift(e[l]),!0}return!1}};if(!e)return r;for(var s=e.length-1;s>=0;s--)l(a.selected,e[s])||l(n,e[s])||r.unshift(e[s]);return r}),i.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);a.selected=[]}a.selected=u.$viewValue,i.$evalAsync()},i.$on("uis:select",function(e,t){a.selected.length>=a.limit||(a.selected.push(t),p.updateModel())}),i.$on("uis:activate",function(){p.activeMatchIndex=-1}),i.$watch("$select.disabled",function(e,t){t&&!e&&a.sizeSearchInput()}),a.searchInput.on("keydown",function(t){var n=t.which;i.$apply(function(){var t=!1;e.isHorizontalMovement(n)&&(t=o(n)),t&&n!=e.TAB})}),a.searchInput.on("blur",function(){n(function(){p.activeMatchIndex=-1})})}}}]),n.directive("uiSelectSingle",["$timeout","$compile",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(i,c,r,l){var s=l[0],o=l[1];o.$parsers.unshift(function(e){var t,n={};return n[s.parserResult.itemName]=e,t=s.parserResult.modelMapper(i,n)}),o.$formatters.unshift(function(e){var t,n=s.parserResult.source(i,{$select:{search:""}}),c={};if(n){var r=function(n){return c[s.parserResult.itemName]=n,t=s.parserResult.modelMapper(i,c),t==e};if(s.selected&&r(s.selected))return s.selected;for(var l=n.length-1;l>=0;l--)if(r(n[l]))return n[l]}return e}),i.$watch("$select.selected",function(e){o.$viewValue!==e&&o.$setViewValue(e)}),o.$render=function(){s.selected=o.$viewValue},i.$on("uis:select",function(e,t){s.selected=t}),i.$on("uis:close",function(e,n){t(function(){s.focusser.prop("disabled",!1),n||s.focusser[0].focus()},0,!1)}),i.$on("uis:activate",function(){a.prop("disabled",!0)});var a=angular.element("");n(a)(i),s.focusser=a,s.focusInput=a,c.parent().append(a),a.bind("focus",function(){i.$evalAsync(function(){s.focus=!0})}),a.bind("blur",function(){i.$evalAsync(function(){s.focus=!1})}),a.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),s.select(void 0),i.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),s.activate()),i.$digest()),void 0)}),a.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(s.activate(a.val()),a.val(""),i.$digest())})}}}]),n.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var i=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!i)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:i[2],source:t(i[3]),trackByExp:i[4],modelMapper:t(i[1]||i[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,i){var c=e+" in "+(i?"$group.items":t);return n&&(c+=" track by "+n),c}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("selectize/choices.tpl.html",'
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,isControl:function(t){var n=t.which;switch(n){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,n=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,i,c){c(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var i=n[0].getBoundingClientRect();return{width:i.width||n.prop("offsetWidth"),height:i.height||n.prop("offsetHeight"),top:i.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:i.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);n.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,c){if(!c.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,c,r,l,s){var o=r.groupBy,a=r.groupFilter;if(l.parseRepeatAttr(r.repeat,o,a),l.disableChoiceExpression=r.uiDisableChoice,l.onHighlightCallback=r.onHighlight,o){var u=c.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=c.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(l.parserResult.itemName,"$select.items",l.parserResult.trackByExp,o)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+l.parserResult.itemName+")").attr("ng-click","$select.select("+l.parserResult.itemName+",false,$event)");var d=c.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),i(c,s)(e),e.$watch("$select.search",function(e){e&&!l.open&&l.multiple&&l.activate(!1,!0),l.activeIndex=0})}}}}]),n.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,n,i,c,r,l,s,o){function a(){(f.resetSearchInput||void 0===f.resetSearchInput&&o.resetSearchInput)&&(f.search=h,f.selected&&f.items.length&&!f.multiple&&(f.activeIndex=f.items.indexOf(f.selected)))}function u(e,t){var n,i,c=[];for(n=0;n0&&f.activeIndex--;break;case e.TAB:(!f.multiple||f.open)&&f.select(f.items[f.activeIndex],!0);break;case e.ENTER:f.open?f.select(f.items[f.activeIndex]):f.activate(!1,!0);break;case e.ESC:f.close();break;default:n=!1}return n}function d(){var e=n.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw s("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(f.activeIndex<0)){var i=t[f.activeIndex],c=i.offsetTop+i.clientHeight-e[0].scrollTop,r=e[0].offsetHeight;c>r?e[0].scrollTop+=c-r:c=f.items.length?0:f.activeIndex,i(function(){f.search=e||f.search,f.searchInput[0].focus()})},r=f.onDropdownCallback(t,{open:!0});angular.isDefined(r)?angular.isFunction(r.then)?r.then(function(e){e&&c()}):r===!0?c():r&&c():c()}},f.parseRepeatAttr=function(e,n,i){function c(e){var c=t.$eval(n);if(f.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(c)?c(e):e[c],n=f.findGroupByName(t);n?n.items.push(e):f.groups.push({name:t,items:[e]})}),i){var r=t.$eval(i);angular.isFunction(r)?f.groups=r(f.groups):angular.isArray(r)&&(f.groups=u(f.groups,r))}f.items=[],f.groups.forEach(function(e){f.items=f.items.concat(e.items)})}function r(e){f.items=e}f.setItemsFn=n?c:r,f.parserResult=l.parse(e),f.isGrouped=!!n,f.itemProperty=f.parserResult.itemName,f.refreshItems=function(e){e=e||f.parserResult.source(t);var n=f.selected;if(f.isEmpty()||angular.isArray(n)&&!n.length||!f.removeSelected)f.setItemsFn(e);else if(void 0!==e){var i=e.filter(function(e){return n.indexOf(e)<0});f.setItemsFn(i)}},t.$watchCollection(f.parserResult.source,function(e){if(void 0===e||null===e)f.items=[];else{if(!angular.isArray(e))throw s("items","Expected an array but got '{0}'.",e);f.refreshItems(e),f.ngModel.$modelValue=null}})},f.setActiveItem=function(e){f.activeIndex=f.items.indexOf(e)},f.isActive=function(e){if(!f.open)return!1;var t=f.items.indexOf(e[f.itemProperty]),n=-1===t?!1:t===f.activeIndex;return n&&!angular.isUndefined(f.onHighlightCallback)&&e.$eval(f.onHighlightCallback),n},f.isDisabled=function(e){if(!f.open)return!1;var t,n=f.items.indexOf(e[f.itemProperty]),i=!1;return n>=0&&!angular.isUndefined(f.disableChoiceExpression)&&(t=f.items[n],i=!!e.$eval(f.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i},f.select=function(e,n,c){if((void 0===e||!e._uiSelectChoiceDisabled)&&(f.items||f.search)){var r={};r[f.parserResult.itemName]=e;var l={$item:e,$model:f.parserResult.modelMapper(t,r)},s=function(e){l.$item=e,t.$broadcast("uis:select",e),i(function(){f.onSelectCallback(t,l)}),f.closeOnSelect&&f.close(n),c&&"click"===c.type&&(f.clickTriggeredSelect=!0)};if(!angular.isDefined(f.onBeforeRemoveCallback))return s(e),void 0;var o=f.onBeforeSelectCallback(t,l);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(t){t&&(t===!0?s(e):t&&s(t))}):o===!0?s(e):o&&s(o):s(e)}},f.close=function(e){function n(){f.ngModel&&f.ngModel.$setTouched&&f.ngModel.$setTouched(),a(),f.open=!1,f.searchEnabled||angular.element(f.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e)}if(f.open){var i=f.onDropdownCallback(t,{open:!1});angular.isDefined(i)?angular.isFunction(i.then)?i.then(function(e){e&&n()}):i===!0?n():i&&n():n()}},f.setFocus=function(){f.focus||f.focusInput[0].focus()},f.clear=function(e){f.select(void 0),e.stopPropagation(),i(function(){f.focusser[0].focus()},0,!1)},f.toggle=function(e){f.open?(f.close(),e.preventDefault(),e.stopPropagation()):f.activate()},f.isLocked=function(e,t){var n,i=f.selected[t];return i&&!angular.isUndefined(f.lockChoiceExpression)&&(n=!!e.$eval(f.lockChoiceExpression),i._uiSelectChoiceLocked=n),n};var v=null;f.sizeSearchInput=function(){var e=f.searchInput[0],n=f.searchInput.parent().parent()[0],c=function(){return n.clientWidth*!!e.offsetParent},r=function(t){if(0===t)return!1;var n=t-e.offsetLeft-f.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=t),f.searchInput.css("width",n+"px"),!0};f.searchInput.css("width","10px"),i(function(){null!==v||r(c())||(v=t.$watch(c,function(e){r(e)&&(v(),v=null)}))})},f.searchInput.on("keydown",function(n){var i=n.which;t.$apply(function(){p(i)}),e.isVerticalMovement(i)&&f.items.length>0&&d(),(i===e.ENTER||i===e.ESC)&&(n.preventDefault(),n.stopPropagation())}),f.searchInput.on("keyup",function(n){n.which===e.TAB||e.isControl(n)||e.isFunctionKey(n)||n.which===e.ESC||e.isVerticalMovement(n.which)||void 0!==f.onKeypressCallback&&f.onKeypressCallback(t,{event:n})}),t.$on("$destroy",function(){f.searchInput.off("keyup keydown blur paste")})}]),n.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,i,c,r,l,s){return{restrict:"EA",templateUrl:function(e,t){var i=t.theme||n.theme;return i+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(r,o){return angular.isDefined(o.multiple)?r.append("").removeAttr("multiple"):r.append(""),function(r,o,a,u,p){function d(e){if(v.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(o[0],e.target):o[0].contains(e.target),!t&&!v.clickTriggeredSelect){var n=["input","button","textarea"],i=angular.element(e.target).scope(),c=i&&i.$select&&i.$select!==v;c||(c=~n.indexOf(e.target.tagName.toLowerCase())),v.close(c),r.$digest()}v.clickTriggeredSelect=!1}}function f(){var t=c(o);w=angular.element('
    '),w[0].style.width=t.width+"px",w[0].style.height=t.height+"px",o.after(w),E=o[0].style.width,e.find("body").append(o),o[0].style.position="absolute",o[0].style.left=t.left+"px",o[0].style.top=t.top+"px",o[0].style.width=t.width+"px"}function h(){null!==w&&(w.replaceWith(o),w=null,o[0].style.position="",o[0].style.left="",o[0].style.top="",o[0].style.width=E)}var v=u[0],g=u[1];v.generatedId=n.generateId(),v.baseTitle=a.title||"Select box",v.focusserTitle=v.baseTitle+" focus",v.focusserId="focusser-"+v.generatedId,v.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?l(a.closeOnSelect)():n.closeOnSelect}(),v.onSelectCallback=l(a.onSelect),v.onBeforeSelectCallback=l(a.onBeforeSelect),v.onRemoveCallback=l(a.onRemove),v.onBeforeRemoveCallback=l(a.onBeforeRemove),v.onKeypressCallback=l(a.onKeypress),v.onDropdownCallback=l(a.onDropdown),v.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,v.ngModel=g,v.choiceGrouped=function(e){return v.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){v.focusInput.attr("tabindex",e),o.removeAttr("tabindex")});var m=r.$eval(a.searchEnabled);v.searchEnabled=void 0!==m?m:n.searchEnabled;var $=r.$eval(a.sortable);v.sortable=void 0!==$?$:n.sortable,a.$observe("disabled",function(){v.disabled=void 0!==a.disabled?a.disabled:!1}),angular.isDefined(a.autofocus)&&s(function(){v.setFocus()}),angular.isDefined(a.focusOn)&&r.$on(a.focusOn,function(){s(function(){v.setFocus()})}),e.on("click",d),r.$on("$destroy",function(){e.off("click",d)}),p(r,function(e){var t=angular.element("
    ").append(e),n=t.querySelectorAll(".ui-select-match");if(n.removeAttr("ui-select-match"),n.removeAttr("data-ui-select-match"),1!==n.length)throw i("transcluded","Expected 1 .ui-select-match but got '{0}'.",n.length);o.querySelectorAll(".ui-select-match").replaceWith(n);var c=t.querySelectorAll(".ui-select-choices");if(c.removeAttr("ui-select-choices"),c.removeAttr("data-ui-select-choices"),1!==c.length)throw i("transcluded","Expected 1 .ui-select-choices but got '{0}'.",c.length);o.querySelectorAll(".ui-select-choices").replaceWith(c)});var b=r.$eval(a.appendToBody);(void 0!==b?b:n.appendToBody)&&(r.$watch("$select.open",function(e){e?f():h()}),r.$on("$destroy",function(){h()}));var w=null,E="",S=null,y="direction-up";r.$watch("$select.open",function(n){if(n){if(S=angular.element(o).querySelectorAll(".ui-select-dropdown"),null===S)return;S[0].style.opacity=0,s(function(){var n=c(o),i=c(S);n.top+n.height+i.height>t.pageYOffset+e[0].documentElement.clientHeight&&o.addClass(y),S[0].style.opacity=1})}else{if(null===S)return;o.removeClass(y)}})}}}}]),n.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return n+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,i,c){function r(e){c.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}c.lockChoiceExpression=i.uiLockChoice,i.$observe("placeholder",function(t){c.placeholder=void 0!==t?t:e.placeholder}),i.$observe("allowClear",r),r(i.allowClear),c.multiple&&c.sizeSearchInput()}}}]),n.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,i=this,c=e.$select;e.$evalAsync(function(){n=e.ngModel}),i.activeMatchIndex=-1,i.updateModel=function(){n.$setViewValue(Date.now()),i.refreshComponent()},i.refreshComponent=function(){c.refreshItems(),c.sizeSearchInput()},i.removeChoice=function(n){function r(){t(function(){c.onRemoveCallback(e,o)}),i.updateModel()}var l=c.selected[n];if(!l._uiSelectChoiceLocked){var s={};s[c.parserResult.itemName]=l,c.selected.splice(n,1),i.activeMatchIndex=-1,c.sizeSearchInput();var o={$item:l,$model:c.parserResult.modelMapper(e,s)};if(!angular.isDefined(i.onBeforeRemoveCallback))return r(),void 0;var a=i.onBeforeRemoveCallback(e,o);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(e){e&&r(e)}):a===!0&&r():r()}},i.getPlaceholder=function(){return c.selected&&c.selected.length?void 0:c.placeholder}}],controllerAs:"$selectMultiple",link:function(i,c,r,l){function s(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function o(t){function n(){switch(t){case e.LEFT:return~p.activeMatchIndex?d:l;case e.RIGHT:return~p.activeMatchIndex&&o!==l?u:(a.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(o),d):l;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),o):!1}}var i=s(a.searchInput[0]),c=a.selected.length,r=0,l=c-1,o=p.activeMatchIndex,u=p.activeMatchIndex+1,d=p.activeMatchIndex-1,f=o;return i>0||a.search.length&&t==e.RIGHT?!1:(a.close(),f=n(),p.activeMatchIndex=a.selected.length&&f!==!1?Math.min(l,Math.max(r,f)):-1,!0)}var a=l[0],u=i.ngModel=l[1],p=i.$selectMultiple;a.multiple=!0,a.removeSelected=!0,a.focusInput=a.searchInput,u.$parsers.unshift(function(){for(var e,t={},n=[],c=a.selected.length-1;c>=0;c--)t={},t[a.parserResult.itemName]=a.selected[c],e=a.parserResult.modelMapper(i,t),n.unshift(e);return n}),u.$formatters.unshift(function(e){var t,n=a.parserResult.source(i,{$select:{search:""}}),c={};if(!n)return e;var r=[],l=function(e,n){if(e&&e.length){for(var l=e.length-1;l>=0;l--){if(c[a.parserResult.itemName]=e[l],t=a.parserResult.modelMapper(i,c),a.parserResult.trackByExp){var s=/\.(.+)/.exec(a.parserResult.trackByExp);if(s.length>0&&t[s[1]]==n[s[1]])return r.unshift(e[l]),!0}if(angular.equals(t,n))return r.unshift(e[l]),!0}return!1}};if(!e)return r;for(var s=e.length-1;s>=0;s--)l(a.selected,e[s])||l(n,e[s])||r.unshift(e[s]);return r}),i.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);a.selected=[]}a.selected=u.$viewValue,i.$evalAsync()},i.$on("uis:select",function(e,t){a.selected.length>=a.limit||(a.selected.push(t),p.updateModel())}),i.$on("uis:activate",function(){p.activeMatchIndex=-1}),i.$watch("$select.disabled",function(e,t){t&&!e&&a.sizeSearchInput()}),a.searchInput.on("keydown",function(t){var n=t.which;i.$apply(function(){var t=!1;e.isHorizontalMovement(n)&&(t=o(n)),t&&n!=e.TAB})}),a.searchInput.on("blur",function(){n(function(){p.activeMatchIndex=-1})})}}}]),n.directive("uiSelectSingle",["$timeout","$compile",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(i,c,r,l){var s=l[0],o=l[1];o.$parsers.unshift(function(e){var t,n={};return n[s.parserResult.itemName]=e,t=s.parserResult.modelMapper(i,n)}),o.$formatters.unshift(function(e){var t,n=s.parserResult.source(i,{$select:{search:""}}),c={};if(n){var r=function(n){return c[s.parserResult.itemName]=n,t=s.parserResult.modelMapper(i,c),t==e};if(s.selected&&r(s.selected))return s.selected;for(var l=n.length-1;l>=0;l--)if(r(n[l]))return n[l]}return e}),i.$watch("$select.selected",function(e){o.$viewValue!==e&&o.$setViewValue(e)}),o.$render=function(){s.selected=o.$viewValue},i.$on("uis:select",function(e,t){s.selected=t}),i.$on("uis:close",function(e,n){t(function(){s.focusser.prop("disabled",!1),n||s.focusser[0].focus()},0,!1)}),i.$on("uis:activate",function(){a.prop("disabled",!0)});var a=angular.element("");n(a)(i),s.focusser=a,s.focusInput=a,c.parent().append(a),a.bind("focus",function(){i.$evalAsync(function(){s.focus=!0})}),a.bind("blur",function(){i.$evalAsync(function(){s.focus=!1})}),a.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),s.select(void 0),i.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),s.activate()),i.$digest()),void 0)}),a.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(s.activate(a.val()),a.val(""),i.$digest())})}}}]),n.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var i=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!i)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:i[2],source:t(i[3]),trackByExp:i[4],modelMapper:t(i[1]||i[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,i){var c=e+" in "+(i?"$group.items":t);return n&&(c+=" track by "+n),c}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("selectize/choices.tpl.html",'
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/dist/select.sort.js b/dist/select.sort.js index f0097c436..c3a106d9e 100644 --- a/dist/select.sort.js +++ b/dist/select.sort.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-06T11:06:02.049Z + * Version: 0.12.1 - 2015-08-06T13:28:34.975Z * License: MIT */ diff --git a/dist/select.sort.min.js b/dist/select.sort.min.js index 5a1148a3c..c71dab5ea 100644 --- a/dist/select.sort.min.js +++ b/dist/select.sort.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-06T11:06:02.049Z + * Version: 0.12.1 - 2015-08-06T13:28:34.975Z * License: MIT */ !function(){"use strict";angular.module("ui.select.sort",["ui.select"]).directive("uiSelectSort",["$timeout","uiSelectConfig","uiSelectMinErr",function(e,t,a){return{require:"^uiSelect",link:function(t,r,n,i){if(null===t[n.uiSelectSort])throw a("sort","Expected a list to sort");var o=angular.extend({axis:"horizontal"},t.$eval(n.uiSelectSortOptions)),s=o.axis,l="dragging",f="dropping",d="dropping-before",u="dropping-after";t.$watch(function(){return i.sortable},function(e){e?r.attr("draggable",!0):r.removeAttr("draggable")}),r.on("dragstart",function(e){r.addClass(l),(e.dataTransfer||e.originalEvent.dataTransfer).setData("text/plain",t.$index)}),r.on("dragend",function(){r.removeClass(l)});var c,v=function(e,t){this.splice(t,0,this.splice(e,1)[0])},g=function(e){e.preventDefault();var t="vertical"===s?e.offsetY||e.layerY||(e.originalEvent?e.originalEvent.offsetY:0):e.offsetX||e.layerX||(e.originalEvent?e.originalEvent.offsetX:0);t Date: Sun, 9 Aug 2015 10:28:26 +0100 Subject: [PATCH 25/28] Update to fix "typing goes on last focused component" https://github.com/angular-ui/ui-select/pull/1131 https://github.com/angular-ui/ui-select/issues/872 --- src/uiSelectDirective.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/uiSelectDirective.js b/src/uiSelectDirective.js index 6c0b5487d..7c4c68352 100644 --- a/src/uiSelectDirective.js +++ b/src/uiSelectDirective.js @@ -115,10 +115,9 @@ uis.directive('uiSelect', // Will lose focus only with certain targets var focusableControls = ['input', 'button', 'textarea']; // To check if target is other ui-select - var targetScope = angular.element(e.target).scope(); + var targetController = angular.element(e.target).controller('uiSelect'); // To check if target is other ui-select - var skipFocusser = targetScope && targetScope.$select && - targetScope.$select !== $select; + var skipFocusser = targetController && targetController !== $select; // Check if target is input, button or textarea if (!skipFocusser) { skipFocusser = ~focusableControls.indexOf(e.target.tagName.toLowerCase()); From cbea928a336c7ff749a37dfead80a8ba29832965 Mon Sep 17 00:00:00 2001 From: Chris Jackson Date: Sun, 9 Aug 2015 14:51:28 +0100 Subject: [PATCH 26/28] Update callbacks and tests --- dist/select.bootstrap.js | 595 ++++++++++++------- dist/select.bootstrap.min.js | 4 +- dist/select.css | 2 +- dist/select.js | 793 ++++++++++++++++++------- dist/select.min.css | 2 +- dist/select.min.js | 5 +- dist/select.no-tpl.js | 595 ++++++++++++------- dist/select.no-tpl.min.js | 4 +- dist/select.select2.js | 595 ++++++++++++------- dist/select.select2.min.js | 4 +- dist/select.selectize.js | 595 ++++++++++++------- dist/select.selectize.min.js | 4 +- dist/select.sort.js | 84 ++- dist/select.sort.min.js | 4 +- dist/select.tpl.js | 2 +- examples/bootstrap.html | 7 +- examples/newdemo.html | 13 +- examples/newdemo.js | 2 +- gulpfile.js | 29 +- src/addons/uiSelectTaggingDirective.js | 194 ++++++ src/common.js | 76 +-- src/uiSelectController.js | 412 +++++++++---- src/uiSelectDirective.js | 10 +- src/uiSelectMatchDirective.js | 3 + src/uiSelectMultipleDirective.js | 77 +-- src/uiSelectSingleDirective.js | 10 +- test/select.spec.js | 239 ++++---- 27 files changed, 2853 insertions(+), 1507 deletions(-) create mode 100644 src/addons/uiSelectTaggingDirective.js diff --git a/dist/select.bootstrap.js b/dist/select.bootstrap.js index db80cc9fb..fd69b191d 100644 --- a/dist/select.bootstrap.js +++ b/dist/select.bootstrap.js @@ -1,60 +1,13 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-06T13:28:34.955Z + * Version: 0.12.1 - 2015-08-09T18:09:19.169Z * License: MIT */ (function () { "use strict"; -var KEY = { - TAB: 9, - ENTER: 13, - ESC: 27, - SPACE: 32, - LEFT: 37, - UP: 38, - RIGHT: 39, - DOWN: 40, - SHIFT: 16, - CTRL: 17, - ALT: 18, - PAGE_UP: 33, - PAGE_DOWN: 34, - HOME: 36, - END: 35, - BACKSPACE: 8, - DELETE: 46, - COMMAND: 91, - - isControl: function (e) { - var k = e.which; - switch (k) { - case KEY.COMMAND: - case KEY.SHIFT: - case KEY.CTRL: - case KEY.ALT: - return true; - } - - if (e.metaKey) { - return true; - } - - return false; - }, - isFunctionKey: function (k) { - k = k.which ? k.which : k; - return k >= 112 && k <= 123; - }, - isVerticalMovement: function (k) { - return ~[KEY.UP, KEY.DOWN].indexOf(k); - }, - isHorizontalMovement: function (k) { - return ~[KEY.LEFT, KEY.RIGHT, KEY.BACKSPACE, KEY.DELETE].indexOf(k); - } -}; /** * Add querySelectorAll() to jqLite. @@ -107,7 +60,7 @@ var uis = angular.module('ui.select', []) appendToBody: false }) -// See Rename minErr and make it accessible from outside https://github.com/angular/angular.js/issues/6913 + // See Rename minErr and make it accessible from outside https://github.com/angular/angular.js/issues/6913 .service('uiSelectMinErr', function () { var minErr = angular.$$minErr('ui.select'); return function () { @@ -117,7 +70,7 @@ var uis = angular.module('ui.select', []) }; }) -// Recreates old behavior of ng-transclude. Used internally. + // Recreates old behavior of ng-transclude. Used internally. .directive('uisTranscludeAppend', function () { return { link: function (scope, element, attrs, ctrl, transclude) { @@ -128,29 +81,30 @@ var uis = angular.module('ui.select', []) }; }) -/** - * Highlights text that matches $select.search. - * - * Taken from AngularUI Bootstrap Typeahead - * See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L340 - */ + /** + * Highlights text that matches $select.search. + * + * Taken from AngularUI Bootstrap Typeahead + * See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L340 + */ .filter('highlight', function () { function escapeRegexp(queryToEscape) { return queryToEscape.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1'); } return function (matchItem, query) { + matchItem = String(matchItem); return query && matchItem ? matchItem.replace(new RegExp(escapeRegexp(query), 'gi'), '$&') : matchItem; }; }) -/** - * A read-only equivalent of jQuery's offset function: http://api.jquery.com/offset/ - * - * Taken from AngularUI Bootstrap Position: - * See https://github.com/angular-ui/bootstrap/blob/master/src/position/position.js#L70 - */ + /** + * A read-only equivalent of jQuery's offset function: http://api.jquery.com/offset/ + * + * Taken from AngularUI Bootstrap Position: + * See https://github.com/angular-ui/bootstrap/blob/master/src/position/position.js#L70 + */ .factory('uisOffset', ['$document', '$window', function ($document, $window) { @@ -247,7 +201,6 @@ uis.directive('uiSelectChoices', uis.controller('uiSelectCtrl', ['$scope', '$element', '$timeout', '$filter', '$q', 'uisRepeatParser', 'uiSelectMinErr', 'uiSelectConfig', function ($scope, $element, $timeout, $filter, $q, RepeatParser, uiSelectMinErr, uiSelectConfig) { - var ctrl = this; var EMPTY_SEARCH = ''; @@ -256,23 +209,23 @@ uis.controller('uiSelectCtrl', ctrl.searchEnabled = uiSelectConfig.searchEnabled; ctrl.sortable = uiSelectConfig.sortable; - ctrl.removeSelected = false; // If selected item(s) should be removed from dropdown list - ctrl.closeOnSelect = true; // Initialized inside uiSelect directive link function + ctrl.removeSelected = false; // If selected item(s) should be removed from dropdown list + ctrl.closeOnSelect = true; // Initialized inside uiSelect directive link function ctrl.search = EMPTY_SEARCH; - ctrl.activeIndex = 0; // Dropdown of choices - ctrl.items = []; // All available choices + ctrl.activeIndex = 0; // Dropdown of choices + ctrl.items = []; // All available choices ctrl.open = false; ctrl.focus = false; ctrl.disabled = false; ctrl.selected = undefined; - ctrl.focusser = undefined; // Reference to input element used to handle focus events + ctrl.focusser = undefined; // Reference to input element used to handle focus events ctrl.resetSearchInput = true; - ctrl.multiple = undefined; // Initialized inside uiSelect directive link function - ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelectChoices directive link function - ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelectMatch directive link function + ctrl.multiple = undefined; // Initialized inside uiSelect directive link function + ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelectChoices directive link function + ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelectMatch directive link function ctrl.clickTriggeredSelect = false; ctrl.$filter = $filter; @@ -282,6 +235,158 @@ uis.controller('uiSelectCtrl', ctrl.searchInput.length); } + // TODO: Maybe make these methods in KEY directly in the controller? + ctrl.KEY = { + TAB: 9, + ENTER: 13, + ESC: 27, + SPACE: 32, + LEFT: 37, + UP: 38, + RIGHT: 39, + DOWN: 40, + SHIFT: 16, + CTRL: 17, + ALT: 18, + PAGE_UP: 33, + PAGE_DOWN: 34, + HOME: 36, + END: 35, + BACKSPACE: 8, + DELETE: 46, + COMMAND: 91, + MAP: { + 91: "COMMAND", + 8: "BACKSPACE", + 9: "TAB", + 13: "ENTER", + 16: "SHIFT", + 17: "CTRL", + 18: "ALT", + 19: "PAUSEBREAK", + 20: "CAPSLOCK", + 27: "ESC", + 32: "SPACE", + 33: "PAGE_UP", + 34: "PAGE_DOWN", + 35: "END", + 36: "HOME", + 37: "LEFT", + 38: "UP", + 39: "RIGHT", + 40: "DOWN", + 43: "+", + 44: "PRINTSCREEN", + 45: "INSERT", + 46: "DELETE", + 48: "0", + 49: "1", + 50: "2", + 51: "3", + 52: "4", + 53: "5", + 54: "6", + 55: "7", + 56: "8", + 57: "9", + 59: ";", + 61: "=", + 65: "A", + 66: "B", + 67: "C", + 68: "D", + 69: "E", + 70: "F", + 71: "G", + 72: "H", + 73: "I", + 74: "J", + 75: "K", + 76: "L", + 77: "M", + 78: "N", + 79: "O", + 80: "P", + 81: "Q", + 82: "R", + 83: "S", + 84: "T", + 85: "U", + 86: "V", + 87: "W", + 88: "X", + 89: "Y", + 90: "Z", + 96: "0", + 97: "1", + 98: "2", + 99: "3", + 100: "4", + 101: "5", + 102: "6", + 103: "7", + 104: "8", + 105: "9", + 106: "*", + 107: "+", + 109: "-", + 110: ".", + 111: "/", + 112: "F1", + 113: "F2", + 114: "F3", + 115: "F4", + 116: "F5", + 117: "F6", + 118: "F7", + 119: "F8", + 120: "F9", + 121: "F10", + 122: "F11", + 123: "F12", + 144: "NUMLOCK", + 145: "SCROLLLOCK", + 186: ";", + 187: "=", + 188: ",", + 189: "-", + 190: ".", + 191: "/", + 192: "`", + 219: "[", + 220: "\\", + 221: "]", + 222: "'" + }, + + isControl: function (e) { + var k = e.which; + switch (k) { + case ctrl.KEY.COMMAND: + case ctrl.KEY.SHIFT: + case ctrl.KEY.CTRL: + case ctrl.KEY.ALT: + return true; + } + + if (e.metaKey) { + return true; + } + + return false; + }, + isFunctionKey: function (k) { + k = k.which ? k.which : k; + return k >= 112 && k <= 123; + }, + isVerticalMovement: function (k) { + return ~[ctrl.KEY.UP, ctrl.KEY.DOWN].indexOf(k); + }, + isHorizontalMovement: function (k) { + return ~[ctrl.KEY.LEFT, ctrl.KEY.RIGHT, ctrl.KEY.BACKSPACE, ctrl.KEY.DELETE].indexOf(k); + } + }; + /** * Returns true if the selection is empty * @returns {boolean|*} @@ -322,6 +427,7 @@ uis.controller('uiSelectCtrl', /** * Activates the control. * When the user clicks on ui-select, displays the dropdown list + * Also called following keyboard input to the search box */ ctrl.activate = function (initSearchValue, avoidReset) { if (!ctrl.disabled && !ctrl.open) { @@ -346,22 +452,15 @@ uis.controller('uiSelectCtrl', }); }; - var result = ctrl.onDropdownCallback($scope, {open: true}); - if (angular.isDefined(result)) { - if (angular.isFunction(result.then)) { - // Promise returned - wait for it to complete before completing the selection - result.then(function (result) { - if (!result) { - return; - } + var result = ctrl.beforeDropdownOpen(); + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (result) { + if (result === true) { completeCallback(); - }); - } else if (result === true) { - completeCallback(); - } else if (result) { - completeCallback(); - } - } else { + } + }); + } else if (result === true) { completeCallback(); } } @@ -471,9 +570,10 @@ uis.controller('uiSelectCtrl', var isActive = itemIndex === -1 ? false : itemIndex === ctrl.activeIndex; // If this is active, and we've defined a callback, do it! - if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { - itemScope.$eval(ctrl.onHighlightCallback); - } + // TODO: Needed? +// if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { +// itemScope.$eval(ctrl.onHighlightCallback); +// } return isActive; }; @@ -518,22 +618,11 @@ uis.controller('uiSelectCtrl', return; } - // Create the data used to pass to the callbacks - var locals = {}; - locals[ctrl.parserResult.itemName] = item; - var callbackContext = { - $item: item, - $model: ctrl.parserResult.modelMapper($scope, locals) - }; - - // Local method called when we complete the select - // eg. called after the onselect callback - var completeCallback = function (item) { - callbackContext.$item = item; + function completeCallback() { $scope.$broadcast('uis:select', item); $timeout(function () { - ctrl.onSelectCallback($scope, callbackContext); + ctrl.afterSelect(item); }); if (ctrl.closeOnSelect) { @@ -542,41 +631,31 @@ uis.controller('uiSelectCtrl', if ($event && $event.type === 'click') { ctrl.clickTriggeredSelect = true; } - }; - - // If there's no onBeforeSelect callback, then just call the completeCallback - if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { - completeCallback(item); - return; } - // Call the onBeforeSelect callback + // Call the beforeSelect method // Allowable responses are -: - // falsy: Abort the selection - // promise: Wait for response + // false: Abort the selection // true: Complete selection + // promise: Wait for response // object: Add the returned object - var result = ctrl.onBeforeSelectCallback($scope, callbackContext); - if (angular.isDefined(result)) { - if (angular.isFunction(result.then)) { - // Promise returned - wait for it to complete before completing the selection - result.then(function (response) { - if (!response) { - return; - } - if (response === true) { - completeCallback(item); - } else if (response) { - completeCallback(response); - } - }); - } else if (result === true) { - completeCallback(item); - } else if (result) { - completeCallback(result); - } - } else { + var result = ctrl.beforeSelect(item); + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (response) { + if (!response) { + return; + } + if (response === true) { + completeCallback(item); + } else if (response) { + completeCallback(response); + } + }); + } else if (result === true) { completeCallback(item); + } else if (result) { + completeCallback(result); } }; @@ -601,22 +680,15 @@ uis.controller('uiSelectCtrl', $scope.$broadcast('uis:close', skipFocusser); } - var result = ctrl.onDropdownCallback($scope, {open: false}); - if (angular.isDefined(result)) { - if (angular.isFunction(result.then)) { - // Promise returned - wait for it to complete before completing the selection - result.then(function (result) { - if (!result) { - return; - } + var result = ctrl.beforeDropdownClose(); + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (result) { + if (result === true) { completeCallback(); - }); - } else if (result === true) { - completeCallback(); - } else if (result) { - completeCallback(); - } - } else { + } + }); + } else if (result === true) { completeCallback(); } }; @@ -706,7 +778,7 @@ uis.controller('uiSelectCtrl', function _handleDropDownSelection(key) { var processed = true; switch (key) { - case KEY.DOWN: + case ctrl.KEY.DOWN: if (!ctrl.open && ctrl.multiple) { // In case its the search input in 'multiple' mode ctrl.activate(false, true); @@ -715,7 +787,7 @@ uis.controller('uiSelectCtrl', ctrl.activeIndex++; } break; - case KEY.UP: + case ctrl.KEY.UP: if (!ctrl.open && ctrl.multiple) { ctrl.activate(false, true); } //In case its the search input in 'multiple' mode @@ -723,21 +795,23 @@ uis.controller('uiSelectCtrl', ctrl.activeIndex--; } break; - case KEY.TAB: + case ctrl.KEY.TAB: if (!ctrl.multiple || ctrl.open) { ctrl.select(ctrl.items[ctrl.activeIndex], true); } break; - case KEY.ENTER: + case ctrl.KEY.ENTER: if (ctrl.open) { // Make sure at least one dropdown item is highlighted before adding - ctrl.select(ctrl.items[ctrl.activeIndex]); + if (ctrl.items[ctrl.activeIndex] !== undefined) { + ctrl.select(ctrl.items[ctrl.activeIndex]); + } } else { // In case its the search input in 'multiple' mode ctrl.activate(false, true); } break; - case KEY.ESC: + case ctrl.KEY.ESC: ctrl.close(); break; default: @@ -748,39 +822,42 @@ uis.controller('uiSelectCtrl', // Bind to keyboard shortcuts ctrl.searchInput.on('keydown', function (e) { - var key = e.which; - // if(~[KEY.ESC,KEY.TAB].indexOf(key)){ - // //TODO: SEGURO? - // ctrl.close(); - // } + if (~[ctrl.KEY.ESC, ctrl.KEY.TAB].indexOf(key)) { + // TODO: SEGURO? + ctrl.close(); + } $scope.$apply(function () { _handleDropDownSelection(key); }); - if (KEY.isVerticalMovement(key) && ctrl.items.length > 0) { + if (ctrl.KEY.isVerticalMovement(key) && ctrl.items.length > 0) { _ensureHighlightVisible(); } - if (key === KEY.ENTER || key === KEY.ESC) { + if (key === ctrl.KEY.ENTER || key === ctrl.KEY.ESC) { e.preventDefault(); e.stopPropagation(); } + + // Let the users process the data + // TODO: Is this needed, or just let the user bind to the event themselves! +// ctrl.afterKeypress(e); }); ctrl.searchInput.on('keyup', function (e) { // return early with these keys - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || - KEY.isVerticalMovement(e.which)) { + if (e.which === ctrl.KEY.TAB || ctrl.KEY.isControl(e) || ctrl.KEY.isFunctionKey(e) || + e.which === ctrl.KEY.ESC || + ctrl.KEY.isVerticalMovement(e.which)) { return; } - if (ctrl.onKeypressCallback === undefined) { - return; - } - ctrl.onKeypressCallback($scope, {event: e}); + // Let the users process the data + // TODO: Is this needed, or just let the user bind to the event themselves! + ctrl.afterKeypress(e); }); // See https://github.com/ivaynberg/select2/blob/3.4.6/select2.js#L1431 @@ -817,6 +894,89 @@ uis.controller('uiSelectCtrl', ctrl.searchInput.off('keyup keydown blur paste'); }); + /** + * Keypress callback. Overridable. + * @param event the keypress event + */ + /* jshint unused:false */ + ctrl.afterKeypress = function (event) { + }; + + /** + * Method called before a selection is made. This can be overridden to allow + * the selection to be aborted, or a modified version of the selected item to be + * returned. + * + * Allowable responses are -: + * false: Abort the selection + * true: Complete selection with the selected object + * object: Complete the selection with the returned object + * promise: Wait for response - response from promise is as above + * + * @param item the item that has been selected + * @returns {*} + */ + ctrl.beforeSelect = function (item) { + return true; + }; + + /** + * Method called after a selection is confirmed. This can be overridden to allow + * the application to be notified of a newly selected item. + * No return is required. + * + * @param item the item that has been selected + */ + ctrl.afterSelect = function (item) { + }; + + /** + * Method called before an item is removed from the selected list. This can be overridden + * to allow the removal to be aborted + * + * Allowable responses are -: + * false: Abort the selection + * true: Complete selection with the selected object + * object: Complete the selection with the returned object + * promise: Wait for response - response from promise is as above + * + * @param item the item that has been selected + * @returns {*} + */ + ctrl.beforeRemove = function (item) { + return true; + }; + + /** + * Method called after a item is removed. This can be overridden to allow + * the application to be notified of a removed item. + * No return is required. + * + * @param item the item that has been removed + */ + ctrl.afterRemove = function (item) { + }; + + /** + * Method called before the dropdown is opened. This can be overridden to allow + * the application to process data before the dropdown is displayed. + * The method may return a promise, or true to allow the dropdown, or false to abort. + * @returns {boolean} + */ + ctrl.beforeDropdownOpen = function () { + return true; + }; + + /** + * Method called before the dropdown is closed. This can be overridden to allow + * the application to prevent the dropdown from closing. + * The method may return a promise, or true to allow the dropdown to close, or false to abort. + * @returns {boolean} + */ + ctrl.beforeDropdownClose = function () { + return true; + }; + }]); uis.directive('uiSelect', @@ -863,13 +1023,6 @@ uis.directive('uiSelect', } }(); - $select.onSelectCallback = $parse(attrs.onSelect); - $select.onBeforeSelectCallback = $parse(attrs.onBeforeSelect); - $select.onRemoveCallback = $parse(attrs.onRemove); - $select.onBeforeRemoveCallback = $parse(attrs.onBeforeRemove); - $select.onKeypressCallback = $parse(attrs.onKeypress); - $select.onDropdownCallback = $parse(attrs.onDropdown); - // Limit the number of selections allowed $select.limit = (angular.isDefined(attrs.limit)) ? parseInt(attrs.limit, 10) : undefined; @@ -936,10 +1089,9 @@ uis.directive('uiSelect', // Will lose focus only with certain targets var focusableControls = ['input', 'button', 'textarea']; // To check if target is other ui-select - var targetScope = angular.element(e.target).scope(); + var targetController = angular.element(e.target).controller('uiSelect'); // To check if target is other ui-select - var skipFocusser = targetScope && targetScope.$select && - targetScope.$select !== $select; + var skipFocusser = targetController && targetController !== $select; // Check if target is input, button or textarea if (!skipFocusser) { skipFocusser = ~focusableControls.indexOf(e.target.tagName.toLowerCase()); @@ -1068,7 +1220,8 @@ uis.directive('uiSelect', var offsetDropdown = uisOffset(dropdown); // Determine if the direction of the dropdown needs to be changed. - if (offset.top + offset.height + offsetDropdown.height > $window.pageYOffset + $document[0].documentElement.clientHeight) { + if (offset.top + offset.height + offsetDropdown.height > + $window.pageYOffset + $document[0].documentElement.clientHeight) { element.addClass(directionUpClassName); } @@ -1103,6 +1256,8 @@ uis.directive('uiSelectMatch', ['uiSelectConfig', function (uiSelectConfig) { }, link: function (scope, element, attrs, $select) { $select.lockChoiceExpression = attrs.uiLockChoice; + + // TODO: observe required? attrs.$observe('placeholder', function (placeholder) { $select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder; }); @@ -1112,6 +1267,7 @@ uis.directive('uiSelectMatch', ['uiSelectConfig', function (uiSelectConfig) { (angular.isDefined(allow)) ? (allow === '') ? true : (allow.toLowerCase() === 'true') : false; } + // TODO: observe required? attrs.$observe('allowClear', setAllowClear); setAllowClear(attrs.allowClear); @@ -1157,65 +1313,47 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel * Then calls onRemove to notify the user the item has been removed */ ctrl.removeChoice = function (index) { + // Get the removed choice var removedChoice = $select.selected[index]; - // if the choice is locked, can't remove it + // If the choice is locked, can't remove it if (removedChoice._uiSelectChoiceLocked) { return; } - var locals = {}; - locals[$select.parserResult.itemName] = removedChoice; - - $select.selected.splice(index, 1); - ctrl.activeMatchIndex = -1; - $select.sizeSearchInput(); - - var callbackContext = { - $item: removedChoice, - $model: $select.parserResult.modelMapper($scope, locals) - }; - // Give some time for scope propagation. function completeCallback() { + $select.selected.splice(index, 1); + ctrl.activeMatchIndex = -1; + $select.sizeSearchInput(); + $timeout(function () { - $select.onRemoveCallback($scope, callbackContext); + $select.afterRemove(removedChoice); }); ctrl.updateModel(); } - // If there's no onBeforeRemove callback, then just call the completeCallback - if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { - completeCallback(); - return; - } - - // Call the onBeforeRemove callback + // Call the beforeRemove callback // Allowable responses are -: - // falsy: Abort the removal - // promise: Wait for response + // false: Abort the removal // true: Complete removal - var result = ctrl.onBeforeRemoveCallback($scope, callbackContext); - if (angular.isDefined(result)) { - if (angular.isFunction(result.then)) { - // Promise returned - wait for it to complete before completing the selection - result.then(function (result) { - if (!result) { - return; - } - completeCallback(result); - }); - } else if (result === true) { - completeCallback(); - } - } else { + // promise: Wait for response + var result = $select.beforeRemove(removedChoice); + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (result) { + if (result === true) { + completeCallback(); + } + }); + } else if (result === true) { completeCallback(); } }; ctrl.getPlaceholder = function () { - //Refactor single? + // Refactor single? if ($select.selected && $select.selected.length) { return; } @@ -1343,17 +1481,18 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel var key = e.which; scope.$apply(function () { var processed = false; - if (KEY.isHorizontalMovement(key)) { + if ($select.KEY.isHorizontalMovement(key)) { processed = _handleMatchSelection(key); } - if (processed && key != KEY.TAB) { - //TODO Check si el tab selecciona aun correctamente - //Crear test + if (processed && key != $select.KEY.TAB) { + // TODO Check si el tab selecciona aun correctamente + //Creat test // e.preventDefault(); // e.stopPropagation(); } }); }); + function _getCaretPosition(el) { if (angular.isNumber(el.selectionStart)) { return el.selectionStart; @@ -1375,7 +1514,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel prev = $selectMultiple.activeMatchIndex - 1, newIndex = curr; - if (caretPosition > 0 || ($select.search.length && key == KEY.RIGHT)) { + if (caretPosition > 0 || ($select.search.length && key == $select.KEY.RIGHT)) { return false; } @@ -1383,7 +1522,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel function getNewActiveMatchIndex() { switch (key) { - case KEY.LEFT: + case $select.KEY.LEFT: // Select previous/first item if (~$selectMultiple.activeMatchIndex) { return prev; @@ -1393,7 +1532,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel return last; } break; - case KEY.RIGHT: + case $select.KEY.RIGHT: // Open drop-down if (!~$selectMultiple.activeMatchIndex || curr === last) { $select.activate(); @@ -1404,7 +1543,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel return next; } break; - case KEY.BACKSPACE: + case $select.KEY.BACKSPACE: // Remove selected item and select previous/first if (~$selectMultiple.activeMatchIndex) { $selectMultiple.removeChoice(curr); @@ -1415,7 +1554,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel return last; } break; - case KEY.DELETE: + case $select.KEY.DELETE: // Remove selected item and select next item if (~$selectMultiple.activeMatchIndex) { $selectMultiple.removeChoice($selectMultiple.activeMatchIndex); @@ -1539,7 +1678,7 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co }); focusser.bind("keydown", function (e) { - if (e.which === KEY.BACKSPACE) { + if (e.which === $select.KEY.BACKSPACE) { e.preventDefault(); e.stopPropagation(); $select.select(undefined); @@ -1547,11 +1686,11 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co return; } - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) { + if (e.which === $select.KEY.TAB || $select.KEY.isControl(e) || $select.KEY.isFunctionKey(e) || e.which === $select.KEY.ESC) { return; } - if (e.which == KEY.DOWN || e.which == KEY.UP || e.which == KEY.ENTER || e.which == KEY.SPACE) { + if (e.which == $select.KEY.DOWN || e.which == $select.KEY.UP || e.which == $select.KEY.ENTER || e.which == $select.KEY.SPACE) { e.preventDefault(); e.stopPropagation(); $select.activate(); @@ -1561,8 +1700,8 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co }); focusser.bind("keyup input", function (e) { - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || - e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { + if (e.which === $select.KEY.TAB || $select.KEY.isControl(e) || $select.KEY.isFunctionKey(e) || e.which === $select.KEY.ESC || + e.which == $select.KEY.ENTER || e.which === $select.KEY.BACKSPACE) { return; } diff --git a/dist/select.bootstrap.min.js b/dist/select.bootstrap.min.js index a77b8ca17..f8f2afb28 100644 --- a/dist/select.bootstrap.min.js +++ b/dist/select.bootstrap.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-06T13:28:34.955Z + * Version: 0.12.1 - 2015-08-09T18:09:19.169Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,isControl:function(t){var n=t.which;switch(n){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,n=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,i,c){c(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var i=n[0].getBoundingClientRect();return{width:i.width||n.prop("offsetWidth"),height:i.height||n.prop("offsetHeight"),top:i.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:i.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);n.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,c){if(!c.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,c,l,s,r){var a=l.groupBy,o=l.groupFilter;if(s.parseRepeatAttr(l.repeat,a,o),s.disableChoiceExpression=l.uiDisableChoice,s.onHighlightCallback=l.onHighlight,a){var u=c.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=c.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(s.parserResult.itemName,"$select.items",s.parserResult.trackByExp,a)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+s.parserResult.itemName+")").attr("ng-click","$select.select("+s.parserResult.itemName+",false,$event)");var d=c.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),i(c,r)(e),e.$watch("$select.search",function(e){e&&!s.open&&s.multiple&&s.activate(!1,!0),s.activeIndex=0})}}}}]),n.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,n,i,c,l,s,r,a){function o(){(h.resetSearchInput||void 0===h.resetSearchInput&&a.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var n,i,c=[];for(n=0;n0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:n=!1}return n}function d(){var e=n.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw r("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var i=t[h.activeIndex],c=i.offsetTop+i.clientHeight-e[0].scrollTop,l=e[0].offsetHeight;c>l?e[0].scrollTop+=c-l:c=h.items.length?0:h.activeIndex,i(function(){h.search=e||h.search,h.searchInput[0].focus()})},l=h.onDropdownCallback(t,{open:!0});angular.isDefined(l)?angular.isFunction(l.then)?l.then(function(e){e&&c()}):l===!0?c():l&&c():c()}},h.parseRepeatAttr=function(e,n,i){function c(e){var c=t.$eval(n);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(c)?c(e):e[c],n=h.findGroupByName(t);n?n.items.push(e):h.groups.push({name:t,items:[e]})}),i){var l=t.$eval(i);angular.isFunction(l)?h.groups=l(h.groups):angular.isArray(l)&&(h.groups=u(h.groups,l))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function l(e){h.items=e}h.setItemsFn=n?c:l,h.parserResult=s.parse(e),h.isGrouped=!!n,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var n=h.selected;if(h.isEmpty()||angular.isArray(n)&&!n.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var i=e.filter(function(e){return n.indexOf(e)<0});h.setItemsFn(i)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw r("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),n=-1===t?!1:t===h.activeIndex;return n&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),n},h.isDisabled=function(e){if(!h.open)return!1;var t,n=h.items.indexOf(e[h.itemProperty]),i=!1;return n>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[n],i=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i},h.select=function(e,n,c){if((void 0===e||!e._uiSelectChoiceDisabled)&&(h.items||h.search)){var l={};l[h.parserResult.itemName]=e;var s={$item:e,$model:h.parserResult.modelMapper(t,l)},r=function(e){s.$item=e,t.$broadcast("uis:select",e),i(function(){h.onSelectCallback(t,s)}),h.closeOnSelect&&h.close(n),c&&"click"===c.type&&(h.clickTriggeredSelect=!0)};if(!angular.isDefined(h.onBeforeRemoveCallback))return r(e),void 0;var a=h.onBeforeSelectCallback(t,s);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(t){t&&(t===!0?r(e):t&&r(t))}):a===!0?r(e):a&&r(a):r(e)}},h.close=function(e){function n(){h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),o(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e)}if(h.open){var i=h.onDropdownCallback(t,{open:!1});angular.isDefined(i)?angular.isFunction(i.then)?i.then(function(e){e&&n()}):i===!0?n():i&&n():n()}},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),i(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var n,i=h.selected[t];return i&&!angular.isUndefined(h.lockChoiceExpression)&&(n=!!e.$eval(h.lockChoiceExpression),i._uiSelectChoiceLocked=n),n};var g=null;h.sizeSearchInput=function(){var e=h.searchInput[0],n=h.searchInput.parent().parent()[0],c=function(){return n.clientWidth*!!e.offsetParent},l=function(t){if(0===t)return!1;var n=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=t),h.searchInput.css("width",n+"px"),!0};h.searchInput.css("width","10px"),i(function(){null!==g||l(c())||(g=t.$watch(c,function(e){l(e)&&(g(),g=null)}))})},h.searchInput.on("keydown",function(n){var i=n.which;t.$apply(function(){p(i)}),e.isVerticalMovement(i)&&h.items.length>0&&d(),(i===e.ENTER||i===e.ESC)&&(n.preventDefault(),n.stopPropagation())}),h.searchInput.on("keyup",function(n){n.which===e.TAB||e.isControl(n)||e.isFunctionKey(n)||n.which===e.ESC||e.isVerticalMovement(n.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:n})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),n.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,i,c,l,s,r){return{restrict:"EA",templateUrl:function(e,t){var i=t.theme||n.theme;return i+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(l,a){return angular.isDefined(a.multiple)?l.append("").removeAttr("multiple"):l.append(""),function(l,a,o,u,p){function d(e){if(g.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(a[0],e.target):a[0].contains(e.target),!t&&!g.clickTriggeredSelect){var n=["input","button","textarea"],i=angular.element(e.target).scope(),c=i&&i.$select&&i.$select!==g;c||(c=~n.indexOf(e.target.tagName.toLowerCase())),g.close(c),l.$digest()}g.clickTriggeredSelect=!1}}function h(){var t=c(a);w=angular.element('
    '),w[0].style.width=t.width+"px",w[0].style.height=t.height+"px",a.after(w),x=a[0].style.width,e.find("body").append(a),a[0].style.position="absolute",a[0].style.left=t.left+"px",a[0].style.top=t.top+"px",a[0].style.width=t.width+"px"}function f(){null!==w&&(w.replaceWith(a),w=null,a[0].style.position="",a[0].style.left="",a[0].style.top="",a[0].style.width=x)}var g=u[0],v=u[1];g.generatedId=n.generateId(),g.baseTitle=o.title||"Select box",g.focusserTitle=g.baseTitle+" focus",g.focusserId="focusser-"+g.generatedId,g.closeOnSelect=function(){return angular.isDefined(o.closeOnSelect)?s(o.closeOnSelect)():n.closeOnSelect}(),g.onSelectCallback=s(o.onSelect),g.onBeforeSelectCallback=s(o.onBeforeSelect),g.onRemoveCallback=s(o.onRemove),g.onBeforeRemoveCallback=s(o.onBeforeRemove),g.onKeypressCallback=s(o.onKeypress),g.onDropdownCallback=s(o.onDropdown),g.limit=angular.isDefined(o.limit)?parseInt(o.limit,10):void 0,g.ngModel=v,g.choiceGrouped=function(e){return g.isGrouped&&e&&e.name},o.tabindex&&o.$observe("tabindex",function(e){g.focusInput.attr("tabindex",e),a.removeAttr("tabindex")});var m=l.$eval(o.searchEnabled);g.searchEnabled=void 0!==m?m:n.searchEnabled;var $=l.$eval(o.sortable);g.sortable=void 0!==$?$:n.sortable,o.$observe("disabled",function(){g.disabled=void 0!==o.disabled?o.disabled:!1}),angular.isDefined(o.autofocus)&&r(function(){g.setFocus()}),angular.isDefined(o.focusOn)&&l.$on(o.focusOn,function(){r(function(){g.setFocus()})}),e.on("click",d),l.$on("$destroy",function(){e.off("click",d)}),p(l,function(e){var t=angular.element("
    ").append(e),n=t.querySelectorAll(".ui-select-match");if(n.removeAttr("ui-select-match"),n.removeAttr("data-ui-select-match"),1!==n.length)throw i("transcluded","Expected 1 .ui-select-match but got '{0}'.",n.length);a.querySelectorAll(".ui-select-match").replaceWith(n);var c=t.querySelectorAll(".ui-select-choices");if(c.removeAttr("ui-select-choices"),c.removeAttr("data-ui-select-choices"),1!==c.length)throw i("transcluded","Expected 1 .ui-select-choices but got '{0}'.",c.length);a.querySelectorAll(".ui-select-choices").replaceWith(c)});var b=l.$eval(o.appendToBody);(void 0!==b?b:n.appendToBody)&&(l.$watch("$select.open",function(e){e?h():f()}),l.$on("$destroy",function(){f()}));var w=null,x="",E=null,y="direction-up";l.$watch("$select.open",function(n){if(n){if(E=angular.element(a).querySelectorAll(".ui-select-dropdown"),null===E)return;E[0].style.opacity=0,r(function(){var n=c(a),i=c(E);n.top+n.height+i.height>t.pageYOffset+e[0].documentElement.clientHeight&&a.addClass(y),E[0].style.opacity=1})}else{if(null===E)return;a.removeClass(y)}})}}}}]),n.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return n+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,i,c){function l(e){c.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}c.lockChoiceExpression=i.uiLockChoice,i.$observe("placeholder",function(t){c.placeholder=void 0!==t?t:e.placeholder}),i.$observe("allowClear",l),l(i.allowClear),c.multiple&&c.sizeSearchInput()}}}]),n.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,i=this,c=e.$select;e.$evalAsync(function(){n=e.ngModel}),i.activeMatchIndex=-1,i.updateModel=function(){n.$setViewValue(Date.now()),i.refreshComponent()},i.refreshComponent=function(){c.refreshItems(),c.sizeSearchInput()},i.removeChoice=function(n){function l(){t(function(){c.onRemoveCallback(e,a)}),i.updateModel()}var s=c.selected[n];if(!s._uiSelectChoiceLocked){var r={};r[c.parserResult.itemName]=s,c.selected.splice(n,1),i.activeMatchIndex=-1,c.sizeSearchInput();var a={$item:s,$model:c.parserResult.modelMapper(e,r)};if(!angular.isDefined(i.onBeforeRemoveCallback))return l(),void 0;var o=i.onBeforeRemoveCallback(e,a);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(e){e&&l(e)}):o===!0&&l():l()}},i.getPlaceholder=function(){return c.selected&&c.selected.length?void 0:c.placeholder}}],controllerAs:"$selectMultiple",link:function(i,c,l,s){function r(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(t){function n(){switch(t){case e.LEFT:return~p.activeMatchIndex?d:s;case e.RIGHT:return~p.activeMatchIndex&&a!==s?u:(o.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(a),d):s;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),a):!1}}var i=r(o.searchInput[0]),c=o.selected.length,l=0,s=c-1,a=p.activeMatchIndex,u=p.activeMatchIndex+1,d=p.activeMatchIndex-1,h=a;return i>0||o.search.length&&t==e.RIGHT?!1:(o.close(),h=n(),p.activeMatchIndex=o.selected.length&&h!==!1?Math.min(s,Math.max(l,h)):-1,!0)}var o=s[0],u=i.ngModel=s[1],p=i.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,u.$parsers.unshift(function(){for(var e,t={},n=[],c=o.selected.length-1;c>=0;c--)t={},t[o.parserResult.itemName]=o.selected[c],e=o.parserResult.modelMapper(i,t),n.unshift(e);return n}),u.$formatters.unshift(function(e){var t,n=o.parserResult.source(i,{$select:{search:""}}),c={};if(!n)return e;var l=[],s=function(e,n){if(e&&e.length){for(var s=e.length-1;s>=0;s--){if(c[o.parserResult.itemName]=e[s],t=o.parserResult.modelMapper(i,c),o.parserResult.trackByExp){var r=/\.(.+)/.exec(o.parserResult.trackByExp);if(r.length>0&&t[r[1]]==n[r[1]])return l.unshift(e[s]),!0}if(angular.equals(t,n))return l.unshift(e[s]),!0}return!1}};if(!e)return l;for(var r=e.length-1;r>=0;r--)s(o.selected,e[r])||s(n,e[r])||l.unshift(e[r]);return l}),i.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);o.selected=[]}o.selected=u.$viewValue,i.$evalAsync()},i.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),p.updateModel())}),i.$on("uis:activate",function(){p.activeMatchIndex=-1}),i.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(t){var n=t.which;i.$apply(function(){var t=!1;e.isHorizontalMovement(n)&&(t=a(n)),t&&n!=e.TAB})}),o.searchInput.on("blur",function(){n(function(){p.activeMatchIndex=-1})})}}}]),n.directive("uiSelectSingle",["$timeout","$compile",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(i,c,l,s){var r=s[0],a=s[1];a.$parsers.unshift(function(e){var t,n={};return n[r.parserResult.itemName]=e,t=r.parserResult.modelMapper(i,n)}),a.$formatters.unshift(function(e){var t,n=r.parserResult.source(i,{$select:{search:""}}),c={};if(n){var l=function(n){return c[r.parserResult.itemName]=n,t=r.parserResult.modelMapper(i,c),t==e};if(r.selected&&l(r.selected))return r.selected;for(var s=n.length-1;s>=0;s--)if(l(n[s]))return n[s]}return e}),i.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){r.selected=a.$viewValue},i.$on("uis:select",function(e,t){r.selected=t}),i.$on("uis:close",function(e,n){t(function(){r.focusser.prop("disabled",!1),n||r.focusser[0].focus()},0,!1)}),i.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");n(o)(i),r.focusser=o,r.focusInput=o,c.parent().append(o),o.bind("focus",function(){i.$evalAsync(function(){r.focus=!0})}),o.bind("blur",function(){i.$evalAsync(function(){r.focus=!1})}),o.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),r.select(void 0),i.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),r.activate()),i.$digest()),void 0)}),o.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(r.activate(o.val()),o.val(""),i.$digest())})}}}]),n.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var i=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!i)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:i[2],source:t(i[3]),trackByExp:i[4],modelMapper:t(i[1]||i[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,i){var c=e+" in "+(i?"$group.items":t);return n&&(c+=" track by "+n),c}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",'
    {{$select.placeholder}}
    '),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",'')}]); \ No newline at end of file +!function(){"use strict";void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var e=0,t=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return e++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,i,c){c(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return t=String(t),n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var i=n[0].getBoundingClientRect();return{width:i.width||n.prop("offsetWidth"),height:i.height||n.prop("offsetHeight"),top:i.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:i.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);t.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,c){if(!c.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,c,l,r,s){var o=l.groupBy,a=l.groupFilter;if(r.parseRepeatAttr(l.repeat,o,a),r.disableChoiceExpression=l.uiDisableChoice,r.onHighlightCallback=l.onHighlight,o){var u=c.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=c.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(r.parserResult.itemName,"$select.items",r.parserResult.trackByExp,o)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+r.parserResult.itemName+")").attr("ng-click","$select.select("+r.parserResult.itemName+",false,$event)");var d=c.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),i(c,s)(e),e.$watch("$select.search",function(e){e&&!r.open&&r.multiple&&r.activate(!1,!0),r.activeIndex=0})}}}}]),t.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(e,t,n,i,c,l,r,s){function o(){(d.resetSearchInput||void 0===d.resetSearchInput&&s.resetSearchInput)&&(d.search=h,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function a(e,t){var n,i,c=[];for(n=0;n0&&d.activeIndex--;break;case d.KEY.TAB:(!d.multiple||d.open)&&d.select(d.items[d.activeIndex],!0);break;case d.KEY.ENTER:d.open?void 0!==d.items[d.activeIndex]&&d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case d.KEY.ESC:d.close();break;default:t=!1}return t}function p(){var e=t.querySelectorAll(".ui-select-choices-content"),n=e.querySelectorAll(".ui-select-choices-row");if(n.length<1)throw r("choices","Expected multiple .ui-select-choices-row but got '{0}'.",n.length);if(!(d.activeIndex<0)){var i=n[d.activeIndex],c=i.offsetTop+i.clientHeight-e[0].scrollTop,l=e[0].offsetHeight;c>l?e[0].scrollTop+=c-l:c=112&&123>=e},isVerticalMovement:function(e){return~[d.KEY.UP,d.KEY.DOWN].indexOf(e)},isHorizontalMovement:function(e){return~[d.KEY.LEFT,d.KEY.RIGHT,d.KEY.BACKSPACE,d.KEY.DELETE].indexOf(e)}},d.isEmpty=function(){return angular.isUndefined(d.selected)||null===d.selected||""===d.selected},d.findGroupByName=function(e){return d.groups&&d.groups.filter(function(t){return t.name===e})[0]},d.activate=function(t,i){if(d.disabled||d.open)d.open&&!d.searchEnabled&&d.close();else{var c=function(){i||o(),e.$broadcast("uis:activate"),d.open=!0,d.searchEnabled||angular.element(d.searchInput[0]).addClass("ui-select-offscreen"),d.activeIndex=d.activeIndex>=d.items.length?0:d.activeIndex,n(function(){d.search=t||d.search,d.searchInput[0].focus()})},l=d.beforeDropdownOpen();angular.isFunction(l.then)?l.then(function(e){e===!0&&c()}):l===!0&&c()}},d.parseRepeatAttr=function(t,n,i){function c(t){var c=e.$eval(n);if(d.groups=[],angular.forEach(t,function(e){var t=angular.isFunction(c)?c(e):e[c],n=d.findGroupByName(t);n?n.items.push(e):d.groups.push({name:t,items:[e]})}),i){var l=e.$eval(i);angular.isFunction(l)?d.groups=l(d.groups):angular.isArray(l)&&(d.groups=a(d.groups,l))}d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function s(e){d.items=e}d.setItemsFn=n?c:s,d.parserResult=l.parse(t),d.isGrouped=!!n,d.itemProperty=d.parserResult.itemName,d.refreshItems=function(t){t=t||d.parserResult.source(e);var n=d.selected;if(d.isEmpty()||angular.isArray(n)&&!n.length||!d.removeSelected)d.setItemsFn(t);else if(void 0!==t){var i=t.filter(function(e){return n.indexOf(e)<0});d.setItemsFn(i)}},e.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw r("items","Expected an array but got '{0}'.",e);d.refreshItems(e),d.ngModel.$modelValue=null}})},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){if(!d.open)return!1;var t=d.items.indexOf(e[d.itemProperty]),n=-1===t?!1:t===d.activeIndex;return n},d.isDisabled=function(e){if(!d.open)return!1;var t,n=d.items.indexOf(e[d.itemProperty]),i=!1;return n>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[n],i=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i},d.select=function(t,i,c){function l(){e.$broadcast("uis:select",t),n(function(){d.afterSelect(t)}),d.closeOnSelect&&d.close(i),c&&"click"===c.type&&(d.clickTriggeredSelect=!0)}if((void 0===t||!t._uiSelectChoiceDisabled)&&(d.items||d.search)){var r=d.beforeSelect(t);angular.isFunction(r.then)?r.then(function(e){e&&(e===!0?l(t):e&&l(e))}):r===!0?l(t):r&&l(r)}},d.close=function(t){function n(){d.ngModel&&d.ngModel.$setTouched&&d.ngModel.$setTouched(),o(),d.open=!1,d.searchEnabled||angular.element(d.searchInput[0]).removeClass("ui-select-offscreen"),e.$broadcast("uis:close",t)}if(d.open){var i=d.beforeDropdownClose();angular.isFunction(i.then)?i.then(function(e){e===!0&&n()}):i===!0&&n()}},d.setFocus=function(){d.focus||d.focusInput[0].focus()},d.clear=function(e){d.select(void 0),e.stopPropagation(),n(function(){d.focusser[0].focus()},0,!1)},d.toggle=function(e){d.open?(d.close(),e.preventDefault(),e.stopPropagation()):d.activate()},d.isLocked=function(e,t){var n,i=d.selected[t];return i&&!angular.isUndefined(d.lockChoiceExpression)&&(n=!!e.$eval(d.lockChoiceExpression),i._uiSelectChoiceLocked=n),n};var f=null;d.sizeSearchInput=function(){var t=d.searchInput[0],i=d.searchInput.parent().parent()[0],c=function(){return i.clientWidth*!!t.offsetParent},l=function(e){if(0===e)return!1;var n=e-t.offsetLeft-d.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=e),d.searchInput.css("width",n+"px"),!0};d.searchInput.css("width","10px"),n(function(){null!==f||l(c())||(f=e.$watch(c,function(e){l(e)&&(f(),f=null)}))})},d.searchInput.on("keydown",function(t){var n=t.which;~[d.KEY.ESC,d.KEY.TAB].indexOf(n)&&d.close(),e.$apply(function(){u(n)}),d.KEY.isVerticalMovement(n)&&d.items.length>0&&p(),(n===d.KEY.ENTER||n===d.KEY.ESC)&&(t.preventDefault(),t.stopPropagation())}),d.searchInput.on("keyup",function(e){e.which===d.KEY.TAB||d.KEY.isControl(e)||d.KEY.isFunctionKey(e)||e.which===d.KEY.ESC||d.KEY.isVerticalMovement(e.which)||d.afterKeypress(e)}),e.$on("$destroy",function(){d.searchInput.off("keyup keydown blur paste")}),d.afterKeypress=function(){},d.beforeSelect=function(){return!0},d.afterSelect=function(){},d.beforeRemove=function(){return!0},d.afterRemove=function(){},d.beforeDropdownOpen=function(){return!0},d.beforeDropdownClose=function(){return!0}}]),t.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,i,c,l,r,s){return{restrict:"EA",templateUrl:function(e,t){var i=t.theme||n.theme;return i+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(l,o){return angular.isDefined(o.multiple)?l.append("").removeAttr("multiple"):l.append(""),function(l,o,a,u,p){function d(e){if(g.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(o[0],e.target):o[0].contains(e.target),!t&&!g.clickTriggeredSelect){var n=["input","button","textarea"],i=angular.element(e.target).controller("uiSelect"),c=i&&i!==g;c||(c=~n.indexOf(e.target.tagName.toLowerCase())),g.close(c),l.$digest()}g.clickTriggeredSelect=!1}}function h(){var t=c(o);b=angular.element('
    '),b[0].style.width=t.width+"px",b[0].style.height=t.height+"px",o.after(b),w=o[0].style.width,e.find("body").append(o),o[0].style.position="absolute",o[0].style.left=t.left+"px",o[0].style.top=t.top+"px",o[0].style.width=t.width+"px"}function f(){null!==b&&(b.replaceWith(o),b=null,o[0].style.position="",o[0].style.left="",o[0].style.top="",o[0].style.width=w)}var g=u[0],v=u[1];g.generatedId=n.generateId(),g.baseTitle=a.title||"Select box",g.focusserTitle=g.baseTitle+" focus",g.focusserId="focusser-"+g.generatedId,g.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?r(a.closeOnSelect)():n.closeOnSelect}(),g.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,g.ngModel=v,g.choiceGrouped=function(e){return g.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){g.focusInput.attr("tabindex",e),o.removeAttr("tabindex")});var m=l.$eval(a.searchEnabled);g.searchEnabled=void 0!==m?m:n.searchEnabled;var E=l.$eval(a.sortable);g.sortable=void 0!==E?E:n.sortable,a.$observe("disabled",function(){g.disabled=void 0!==a.disabled?a.disabled:!1}),angular.isDefined(a.autofocus)&&s(function(){g.setFocus()}),angular.isDefined(a.focusOn)&&l.$on(a.focusOn,function(){s(function(){g.setFocus()})}),e.on("click",d),l.$on("$destroy",function(){e.off("click",d)}),p(l,function(e){var t=angular.element("
    ").append(e),n=t.querySelectorAll(".ui-select-match");if(n.removeAttr("ui-select-match"),n.removeAttr("data-ui-select-match"),1!==n.length)throw i("transcluded","Expected 1 .ui-select-match but got '{0}'.",n.length);o.querySelectorAll(".ui-select-match").replaceWith(n);var c=t.querySelectorAll(".ui-select-choices");if(c.removeAttr("ui-select-choices"),c.removeAttr("data-ui-select-choices"),1!==c.length)throw i("transcluded","Expected 1 .ui-select-choices but got '{0}'.",c.length);o.querySelectorAll(".ui-select-choices").replaceWith(c)});var $=l.$eval(a.appendToBody);(void 0!==$?$:n.appendToBody)&&(l.$watch("$select.open",function(e){e?h():f()}),l.$on("$destroy",function(){f()}));var b=null,w="",x=null,S="direction-up";l.$watch("$select.open",function(n){if(n){if(x=angular.element(o).querySelectorAll(".ui-select-dropdown"),null===x)return;x[0].style.opacity=0,s(function(){var n=c(o),i=c(x);n.top+n.height+i.height>t.pageYOffset+e[0].documentElement.clientHeight&&o.addClass(S),x[0].style.opacity=1})}else{if(null===x)return;o.removeClass(S)}})}}}}]),t.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return n+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,i,c){function l(e){c.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}c.lockChoiceExpression=i.uiLockChoice,i.$observe("placeholder",function(t){c.placeholder=void 0!==t?t:e.placeholder}),i.$observe("allowClear",l),l(i.allowClear),c.multiple&&c.sizeSearchInput()}}}]),t.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,i=this,c=e.$select;e.$evalAsync(function(){n=e.ngModel}),i.activeMatchIndex=-1,i.updateModel=function(){n.$setViewValue(Date.now()),i.refreshComponent()},i.refreshComponent=function(){c.refreshItems(),c.sizeSearchInput()},i.removeChoice=function(e){function n(){c.selected.splice(e,1),i.activeMatchIndex=-1,c.sizeSearchInput(),t(function(){c.afterRemove(l)}),i.updateModel()}var l=c.selected[e];if(!l._uiSelectChoiceLocked){var r=c.beforeRemove(l);angular.isFunction(r.then)?r.then(function(e){e===!0&&n()}):r===!0&&n()}},i.getPlaceholder=function(){return c.selected&&c.selected.length?void 0:c.placeholder}}],controllerAs:"$selectMultiple",link:function(n,i,c,l){function r(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function s(e){function t(){switch(e){case o.KEY.LEFT:return~u.activeMatchIndex?p:l;case o.KEY.RIGHT:return~u.activeMatchIndex&&s!==l?a:(o.activate(),!1);case o.KEY.BACKSPACE:return~u.activeMatchIndex?(u.removeChoice(s),p):l;case o.KEY.DELETE:return~u.activeMatchIndex?(u.removeChoice(u.activeMatchIndex),s):!1}}var n=r(o.searchInput[0]),i=o.selected.length,c=0,l=i-1,s=u.activeMatchIndex,a=u.activeMatchIndex+1,p=u.activeMatchIndex-1,d=s;return n>0||o.search.length&&e==o.KEY.RIGHT?!1:(o.close(),d=t(),u.activeMatchIndex=o.selected.length&&d!==!1?Math.min(l,Math.max(c,d)):-1,!0)}var o=l[0],a=n.ngModel=l[1],u=n.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,a.$parsers.unshift(function(){for(var e,t={},i=[],c=o.selected.length-1;c>=0;c--)t={},t[o.parserResult.itemName]=o.selected[c],e=o.parserResult.modelMapper(n,t),i.unshift(e);return i}),a.$formatters.unshift(function(e){var t,i=o.parserResult.source(n,{$select:{search:""}}),c={};if(!i)return e;var l=[],r=function(e,i){if(e&&e.length){for(var r=e.length-1;r>=0;r--){if(c[o.parserResult.itemName]=e[r],t=o.parserResult.modelMapper(n,c),o.parserResult.trackByExp){var s=/\.(.+)/.exec(o.parserResult.trackByExp);if(s.length>0&&t[s[1]]==i[s[1]])return l.unshift(e[r]),!0}if(angular.equals(t,i))return l.unshift(e[r]),!0}return!1}};if(!e)return l;for(var s=e.length-1;s>=0;s--)r(o.selected,e[s])||r(i,e[s])||l.unshift(e[s]);return l}),n.$watchCollection(function(){return a.$modelValue},function(e,t){t!=e&&(a.$modelValue=null,u.refreshComponent())}),a.$render=function(){if(!angular.isArray(a.$viewValue)){if(!angular.isUndefined(a.$viewValue)&&null!==a.$viewValue)throw e("multiarr","Expected model value to be array but got '{0}'",a.$viewValue);o.selected=[]}o.selected=a.$viewValue,n.$evalAsync()},n.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),u.updateModel())}),n.$on("uis:activate",function(){u.activeMatchIndex=-1}),n.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(e){var t=e.which;n.$apply(function(){var e=!1;o.KEY.isHorizontalMovement(t)&&(e=s(t)),e&&t!=o.KEY.TAB})}),o.searchInput.on("blur",function(){t(function(){u.activeMatchIndex=-1})})}}}]),t.directive("uiSelectSingle",["$timeout","$compile",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(n,i,c,l){var r=l[0],s=l[1];s.$parsers.unshift(function(e){var t,i={};return i[r.parserResult.itemName]=e,t=r.parserResult.modelMapper(n,i)}),s.$formatters.unshift(function(e){var t,i=r.parserResult.source(n,{$select:{search:""}}),c={};if(i){var l=function(i){return c[r.parserResult.itemName]=i,t=r.parserResult.modelMapper(n,c),t==e};if(r.selected&&l(r.selected))return r.selected;for(var s=i.length-1;s>=0;s--)if(l(i[s]))return i[s]}return e}),n.$watch("$select.selected",function(e){s.$viewValue!==e&&s.$setViewValue(e)}),s.$render=function(){r.selected=s.$viewValue},n.$on("uis:select",function(e,t){r.selected=t}),n.$on("uis:close",function(t,n){e(function(){r.focusser.prop("disabled",!1),n||r.focusser[0].focus()},0,!1)}),n.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");t(o)(n),r.focusser=o,r.focusInput=o,i.parent().append(o),o.bind("focus",function(){n.$evalAsync(function(){r.focus=!0})}),o.bind("blur",function(){n.$evalAsync(function(){r.focus=!1})}),o.bind("keydown",function(e){return e.which===r.KEY.BACKSPACE?(e.preventDefault(),e.stopPropagation(),r.select(void 0),n.$apply(),void 0):(e.which===r.KEY.TAB||r.KEY.isControl(e)||r.KEY.isFunctionKey(e)||e.which===r.KEY.ESC||((e.which==r.KEY.DOWN||e.which==r.KEY.UP||e.which==r.KEY.ENTER||e.which==r.KEY.SPACE)&&(e.preventDefault(),e.stopPropagation(),r.activate()),n.$digest()),void 0)}),o.bind("keyup input",function(e){e.which===r.KEY.TAB||r.KEY.isControl(e)||r.KEY.isFunctionKey(e)||e.which===r.KEY.ESC||e.which==r.KEY.ENTER||e.which===r.KEY.BACKSPACE||(r.activate(o.val()),o.val(""),n.$digest())})}}}]),t.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var i=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!i)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:i[2],source:t(i[3]),trackByExp:i[4],modelMapper:t(i[1]||i[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,i){var c=e+" in "+(i?"$group.items":t);return n&&(c+=" track by "+n),c}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",'
    {{$select.placeholder}}
    '),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",'')}]); \ No newline at end of file diff --git a/dist/select.css b/dist/select.css index dc3621f62..fa4d630f8 100644 --- a/dist/select.css +++ b/dist/select.css @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-06T13:28:34.992Z + * Version: 0.12.1 - 2015-08-09T18:09:19.231Z * License: MIT */ diff --git a/dist/select.js b/dist/select.js index 58cfbfac6..94d70c573 100644 --- a/dist/select.js +++ b/dist/select.js @@ -1,11 +1,209 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-06T13:28:34.991Z + * Version: 0.12.1 - 2015-08-09T18:09:19.229Z * License: MIT */ +(function () { +"use strict"; +angular.module('ui.select.tagging', ['ui.select']) + .directive('uiSelectTagging', + ['$parse', '$timeout', function () { + return { + require: '^uiSelect', + link: function (scope, element, attrs, $select) { + var ctrl = $select; + ctrl.taggingLabel = attrs.taggingLabel !== undefined ? attrs.taggingLabel : false; + ctrl.taggingTokens = + attrs.taggingTokens !== undefined ? attrs.taggingTokens.split('|') : [',', 'ENTER']; + + // If tagging try to split by tokens and add items + ctrl.searchInput.on('paste', function (e) { + var data = e.clipboardData.getData('text/plain'); + if (data && data.length > 0) { + var items = data.split(ctrl.taggingTokens[0]); // Split by first token only + if (items && items.length > 0) { + angular.forEach(items, function (item) { + var newItem = ctrl.beforeTagging(item); + if (newItem) { + ctrl.select(newItem, true); + } + }); + e.preventDefault(); + e.stopPropagation(); + } + } + }); + + // Define the default callback into the controller + ctrl.beforeTagging = function (item) { + return item; + }; + + + // Override the keypress callback + ctrl.afterKeypress = function (e) { + + +// if ( ! ctrl.KEY.isVerticalMovement(e.which) ) { +// scope.$evalAsync( function () { +// $select.activeIndex = $select.taggingLabel === false ? -1 : 0; +// }); +// } + + // Push a "create new" item into array if there is a search string + if ($select.search.length > 0) { + // Return early with these keys + if (e.which === ctrl.KEY.TAB || ctrl.KEY.isControl(e) || ctrl.KEY.isFunctionKey(e) || + e.which === ctrl.KEY.ESC || + ctrl.KEY.isVerticalMovement(e.which)) { + return; + } + + // Check for end of tagging + var tagged = false; +// if (e.which === ctrl.KEY.ENTER) { +// tagged = true; +// } + for (var i = 0; i < ctrl.taggingTokens.length; i++) { + if (ctrl.taggingTokens[i] === ctrl.KEY.MAP[e.keyCode]) { + // Make sure there is a new value to push via tagging + if (ctrl.search.length > 0) { + tagged = true; + if ($select.search.substr($select.search.length - 1) == ctrl.KEY.MAP[e.keyCode]) { + + $select.search = $select.search.substr(0, $select.search.length - 1); + } + } + } + } + if (tagged === true) { + ctrl.select(ctrl.beforeTagging($select.search)); + return; + } + + + $select.activeIndex = $select.taggingLabel === false ? -1 : 0; + // If taggingLabel === false bypasses all of this + if ($select.taggingLabel === false) { + return; + } + + var items = angular.copy($select.items); + var stashArr = angular.copy($select.items); + var newItem; + var item; + var hasTag = false; + var dupeIndex = -1; + var tagItems; + var tagItem; + + + // Find any tagging items already in the $select.items array and store them + tagItems = $select.$filter('filter')(items, function (item) { + return item.match($select.taggingLabel); + }); + if (tagItems.length > 0) { + tagItem = tagItems[0]; + } + item = items[0]; + // Remove existing tag item if found (should only ever be one tag item) + if (item !== undefined && items.length > 0 && tagItem) { + hasTag = true; + items = items.slice(1, items.length); + stashArr = stashArr.slice(1, stashArr.length); + } + newItem = $select.search + ' ' + $select.taggingLabel; + if (_findApproxDupe($select.selected, $select.search) > -1) { + return; + } + // Verify the the tag doesn't match the value of an existing item from + // the searched data set or the items already selected + if (_findCaseInsensitiveDupe(stashArr.concat($select.selected))) { + // if there is a tag from prev iteration, strip it / queue the change + // and return early + if (hasTag) { + items = stashArr; + scope.$evalAsync(function () { + $select.activeIndex = 0; + $select.items = items; + }); + } + return; + } + if (_findCaseInsensitiveDupe(stashArr)) { + // If there is a tag from prev iteration, strip it + if (hasTag) { + $select.items = stashArr.slice(1, stashArr.length); + } + return; + } +// } + if (hasTag) { + dupeIndex = _findApproxDupe($select.selected, newItem); + } + // dupe found, shave the first item + if (dupeIndex > -1) { + items = items.slice(dupeIndex + 1, items.length - 1); + } else { + items = []; + items.push(newItem); + items = items.concat(stashArr); + } + scope.$evalAsync(function () { + $select.activeIndex = 0; + $select.items = items; + }); + } + }; + + + function _findCaseInsensitiveDupe(arr) { + if (arr === undefined || $select.search === undefined) { + return false; + } + var hasDupe = arr.filter(function (origItem) { + if ($select.search.toUpperCase() === undefined || origItem === undefined) { + return false; + } + return origItem.toUpperCase() === $select.search.toUpperCase(); + }).length > 0; + + return hasDupe; + } + + function _findApproxDupe(haystack, needle) { + var dupeIndex = -1; + if (angular.isArray(haystack)) { + var tempArr = angular.copy(haystack); + for (var i = 0; i < tempArr.length; i++) { + // handle the simple string version of tagging +// if ($select.tagging.fct === undefined) { + // search the array for the match + if (tempArr[i] + ' ' + $select.taggingLabel === needle) { + dupeIndex = i; + } + // handle the object tagging implementation + /* } else { + var mockObj = tempArr[i]; + mockObj.isTag = true; + if (angular.equals(mockObj, needle)) { + dupeIndex = i; + } + }*/ + } + } + return dupeIndex; + } + + + } + }; + }]); + +}()); (function () { "use strict"; // Make multiple matches sortable @@ -153,53 +351,6 @@ angular.module('ui.select.sort', ['ui.select']) }()); (function () { "use strict"; -var KEY = { - TAB: 9, - ENTER: 13, - ESC: 27, - SPACE: 32, - LEFT: 37, - UP: 38, - RIGHT: 39, - DOWN: 40, - SHIFT: 16, - CTRL: 17, - ALT: 18, - PAGE_UP: 33, - PAGE_DOWN: 34, - HOME: 36, - END: 35, - BACKSPACE: 8, - DELETE: 46, - COMMAND: 91, - - isControl: function (e) { - var k = e.which; - switch (k) { - case KEY.COMMAND: - case KEY.SHIFT: - case KEY.CTRL: - case KEY.ALT: - return true; - } - - if (e.metaKey) { - return true; - } - - return false; - }, - isFunctionKey: function (k) { - k = k.which ? k.which : k; - return k >= 112 && k <= 123; - }, - isVerticalMovement: function (k) { - return ~[KEY.UP, KEY.DOWN].indexOf(k); - }, - isHorizontalMovement: function (k) { - return ~[KEY.LEFT, KEY.RIGHT, KEY.BACKSPACE, KEY.DELETE].indexOf(k); - } -}; /** * Add querySelectorAll() to jqLite. @@ -252,7 +403,7 @@ var uis = angular.module('ui.select', []) appendToBody: false }) -// See Rename minErr and make it accessible from outside https://github.com/angular/angular.js/issues/6913 + // See Rename minErr and make it accessible from outside https://github.com/angular/angular.js/issues/6913 .service('uiSelectMinErr', function () { var minErr = angular.$$minErr('ui.select'); return function () { @@ -262,7 +413,7 @@ var uis = angular.module('ui.select', []) }; }) -// Recreates old behavior of ng-transclude. Used internally. + // Recreates old behavior of ng-transclude. Used internally. .directive('uisTranscludeAppend', function () { return { link: function (scope, element, attrs, ctrl, transclude) { @@ -273,29 +424,30 @@ var uis = angular.module('ui.select', []) }; }) -/** - * Highlights text that matches $select.search. - * - * Taken from AngularUI Bootstrap Typeahead - * See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L340 - */ + /** + * Highlights text that matches $select.search. + * + * Taken from AngularUI Bootstrap Typeahead + * See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L340 + */ .filter('highlight', function () { function escapeRegexp(queryToEscape) { return queryToEscape.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1'); } return function (matchItem, query) { + matchItem = String(matchItem); return query && matchItem ? matchItem.replace(new RegExp(escapeRegexp(query), 'gi'), '$&') : matchItem; }; }) -/** - * A read-only equivalent of jQuery's offset function: http://api.jquery.com/offset/ - * - * Taken from AngularUI Bootstrap Position: - * See https://github.com/angular-ui/bootstrap/blob/master/src/position/position.js#L70 - */ + /** + * A read-only equivalent of jQuery's offset function: http://api.jquery.com/offset/ + * + * Taken from AngularUI Bootstrap Position: + * See https://github.com/angular-ui/bootstrap/blob/master/src/position/position.js#L70 + */ .factory('uisOffset', ['$document', '$window', function ($document, $window) { @@ -392,7 +544,6 @@ uis.directive('uiSelectChoices', uis.controller('uiSelectCtrl', ['$scope', '$element', '$timeout', '$filter', '$q', 'uisRepeatParser', 'uiSelectMinErr', 'uiSelectConfig', function ($scope, $element, $timeout, $filter, $q, RepeatParser, uiSelectMinErr, uiSelectConfig) { - var ctrl = this; var EMPTY_SEARCH = ''; @@ -401,23 +552,23 @@ uis.controller('uiSelectCtrl', ctrl.searchEnabled = uiSelectConfig.searchEnabled; ctrl.sortable = uiSelectConfig.sortable; - ctrl.removeSelected = false; // If selected item(s) should be removed from dropdown list - ctrl.closeOnSelect = true; // Initialized inside uiSelect directive link function + ctrl.removeSelected = false; // If selected item(s) should be removed from dropdown list + ctrl.closeOnSelect = true; // Initialized inside uiSelect directive link function ctrl.search = EMPTY_SEARCH; - ctrl.activeIndex = 0; // Dropdown of choices - ctrl.items = []; // All available choices + ctrl.activeIndex = 0; // Dropdown of choices + ctrl.items = []; // All available choices ctrl.open = false; ctrl.focus = false; ctrl.disabled = false; ctrl.selected = undefined; - ctrl.focusser = undefined; // Reference to input element used to handle focus events + ctrl.focusser = undefined; // Reference to input element used to handle focus events ctrl.resetSearchInput = true; - ctrl.multiple = undefined; // Initialized inside uiSelect directive link function - ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelectChoices directive link function - ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelectMatch directive link function + ctrl.multiple = undefined; // Initialized inside uiSelect directive link function + ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelectChoices directive link function + ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelectMatch directive link function ctrl.clickTriggeredSelect = false; ctrl.$filter = $filter; @@ -427,6 +578,158 @@ uis.controller('uiSelectCtrl', ctrl.searchInput.length); } + // TODO: Maybe make these methods in KEY directly in the controller? + ctrl.KEY = { + TAB: 9, + ENTER: 13, + ESC: 27, + SPACE: 32, + LEFT: 37, + UP: 38, + RIGHT: 39, + DOWN: 40, + SHIFT: 16, + CTRL: 17, + ALT: 18, + PAGE_UP: 33, + PAGE_DOWN: 34, + HOME: 36, + END: 35, + BACKSPACE: 8, + DELETE: 46, + COMMAND: 91, + MAP: { + 91: "COMMAND", + 8: "BACKSPACE", + 9: "TAB", + 13: "ENTER", + 16: "SHIFT", + 17: "CTRL", + 18: "ALT", + 19: "PAUSEBREAK", + 20: "CAPSLOCK", + 27: "ESC", + 32: "SPACE", + 33: "PAGE_UP", + 34: "PAGE_DOWN", + 35: "END", + 36: "HOME", + 37: "LEFT", + 38: "UP", + 39: "RIGHT", + 40: "DOWN", + 43: "+", + 44: "PRINTSCREEN", + 45: "INSERT", + 46: "DELETE", + 48: "0", + 49: "1", + 50: "2", + 51: "3", + 52: "4", + 53: "5", + 54: "6", + 55: "7", + 56: "8", + 57: "9", + 59: ";", + 61: "=", + 65: "A", + 66: "B", + 67: "C", + 68: "D", + 69: "E", + 70: "F", + 71: "G", + 72: "H", + 73: "I", + 74: "J", + 75: "K", + 76: "L", + 77: "M", + 78: "N", + 79: "O", + 80: "P", + 81: "Q", + 82: "R", + 83: "S", + 84: "T", + 85: "U", + 86: "V", + 87: "W", + 88: "X", + 89: "Y", + 90: "Z", + 96: "0", + 97: "1", + 98: "2", + 99: "3", + 100: "4", + 101: "5", + 102: "6", + 103: "7", + 104: "8", + 105: "9", + 106: "*", + 107: "+", + 109: "-", + 110: ".", + 111: "/", + 112: "F1", + 113: "F2", + 114: "F3", + 115: "F4", + 116: "F5", + 117: "F6", + 118: "F7", + 119: "F8", + 120: "F9", + 121: "F10", + 122: "F11", + 123: "F12", + 144: "NUMLOCK", + 145: "SCROLLLOCK", + 186: ";", + 187: "=", + 188: ",", + 189: "-", + 190: ".", + 191: "/", + 192: "`", + 219: "[", + 220: "\\", + 221: "]", + 222: "'" + }, + + isControl: function (e) { + var k = e.which; + switch (k) { + case ctrl.KEY.COMMAND: + case ctrl.KEY.SHIFT: + case ctrl.KEY.CTRL: + case ctrl.KEY.ALT: + return true; + } + + if (e.metaKey) { + return true; + } + + return false; + }, + isFunctionKey: function (k) { + k = k.which ? k.which : k; + return k >= 112 && k <= 123; + }, + isVerticalMovement: function (k) { + return ~[ctrl.KEY.UP, ctrl.KEY.DOWN].indexOf(k); + }, + isHorizontalMovement: function (k) { + return ~[ctrl.KEY.LEFT, ctrl.KEY.RIGHT, ctrl.KEY.BACKSPACE, ctrl.KEY.DELETE].indexOf(k); + } + }; + /** * Returns true if the selection is empty * @returns {boolean|*} @@ -467,6 +770,7 @@ uis.controller('uiSelectCtrl', /** * Activates the control. * When the user clicks on ui-select, displays the dropdown list + * Also called following keyboard input to the search box */ ctrl.activate = function (initSearchValue, avoidReset) { if (!ctrl.disabled && !ctrl.open) { @@ -491,22 +795,15 @@ uis.controller('uiSelectCtrl', }); }; - var result = ctrl.onDropdownCallback($scope, {open: true}); - if (angular.isDefined(result)) { - if (angular.isFunction(result.then)) { - // Promise returned - wait for it to complete before completing the selection - result.then(function (result) { - if (!result) { - return; - } + var result = ctrl.beforeDropdownOpen(); + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (result) { + if (result === true) { completeCallback(); - }); - } else if (result === true) { - completeCallback(); - } else if (result) { - completeCallback(); - } - } else { + } + }); + } else if (result === true) { completeCallback(); } } @@ -616,9 +913,10 @@ uis.controller('uiSelectCtrl', var isActive = itemIndex === -1 ? false : itemIndex === ctrl.activeIndex; // If this is active, and we've defined a callback, do it! - if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { - itemScope.$eval(ctrl.onHighlightCallback); - } + // TODO: Needed? +// if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { +// itemScope.$eval(ctrl.onHighlightCallback); +// } return isActive; }; @@ -663,22 +961,11 @@ uis.controller('uiSelectCtrl', return; } - // Create the data used to pass to the callbacks - var locals = {}; - locals[ctrl.parserResult.itemName] = item; - var callbackContext = { - $item: item, - $model: ctrl.parserResult.modelMapper($scope, locals) - }; - - // Local method called when we complete the select - // eg. called after the onselect callback - var completeCallback = function (item) { - callbackContext.$item = item; + function completeCallback() { $scope.$broadcast('uis:select', item); $timeout(function () { - ctrl.onSelectCallback($scope, callbackContext); + ctrl.afterSelect(item); }); if (ctrl.closeOnSelect) { @@ -687,41 +974,31 @@ uis.controller('uiSelectCtrl', if ($event && $event.type === 'click') { ctrl.clickTriggeredSelect = true; } - }; - - // If there's no onBeforeSelect callback, then just call the completeCallback - if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { - completeCallback(item); - return; } - // Call the onBeforeSelect callback + // Call the beforeSelect method // Allowable responses are -: - // falsy: Abort the selection - // promise: Wait for response + // false: Abort the selection // true: Complete selection + // promise: Wait for response // object: Add the returned object - var result = ctrl.onBeforeSelectCallback($scope, callbackContext); - if (angular.isDefined(result)) { - if (angular.isFunction(result.then)) { - // Promise returned - wait for it to complete before completing the selection - result.then(function (response) { - if (!response) { - return; - } - if (response === true) { - completeCallback(item); - } else if (response) { - completeCallback(response); - } - }); - } else if (result === true) { - completeCallback(item); - } else if (result) { - completeCallback(result); - } - } else { + var result = ctrl.beforeSelect(item); + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (response) { + if (!response) { + return; + } + if (response === true) { + completeCallback(item); + } else if (response) { + completeCallback(response); + } + }); + } else if (result === true) { completeCallback(item); + } else if (result) { + completeCallback(result); } }; @@ -746,22 +1023,15 @@ uis.controller('uiSelectCtrl', $scope.$broadcast('uis:close', skipFocusser); } - var result = ctrl.onDropdownCallback($scope, {open: false}); - if (angular.isDefined(result)) { - if (angular.isFunction(result.then)) { - // Promise returned - wait for it to complete before completing the selection - result.then(function (result) { - if (!result) { - return; - } + var result = ctrl.beforeDropdownClose(); + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (result) { + if (result === true) { completeCallback(); - }); - } else if (result === true) { - completeCallback(); - } else if (result) { - completeCallback(); - } - } else { + } + }); + } else if (result === true) { completeCallback(); } }; @@ -851,7 +1121,7 @@ uis.controller('uiSelectCtrl', function _handleDropDownSelection(key) { var processed = true; switch (key) { - case KEY.DOWN: + case ctrl.KEY.DOWN: if (!ctrl.open && ctrl.multiple) { // In case its the search input in 'multiple' mode ctrl.activate(false, true); @@ -860,7 +1130,7 @@ uis.controller('uiSelectCtrl', ctrl.activeIndex++; } break; - case KEY.UP: + case ctrl.KEY.UP: if (!ctrl.open && ctrl.multiple) { ctrl.activate(false, true); } //In case its the search input in 'multiple' mode @@ -868,21 +1138,23 @@ uis.controller('uiSelectCtrl', ctrl.activeIndex--; } break; - case KEY.TAB: + case ctrl.KEY.TAB: if (!ctrl.multiple || ctrl.open) { ctrl.select(ctrl.items[ctrl.activeIndex], true); } break; - case KEY.ENTER: + case ctrl.KEY.ENTER: if (ctrl.open) { // Make sure at least one dropdown item is highlighted before adding - ctrl.select(ctrl.items[ctrl.activeIndex]); + if (ctrl.items[ctrl.activeIndex] !== undefined) { + ctrl.select(ctrl.items[ctrl.activeIndex]); + } } else { // In case its the search input in 'multiple' mode ctrl.activate(false, true); } break; - case KEY.ESC: + case ctrl.KEY.ESC: ctrl.close(); break; default: @@ -893,39 +1165,42 @@ uis.controller('uiSelectCtrl', // Bind to keyboard shortcuts ctrl.searchInput.on('keydown', function (e) { - var key = e.which; - // if(~[KEY.ESC,KEY.TAB].indexOf(key)){ - // //TODO: SEGURO? - // ctrl.close(); - // } + if (~[ctrl.KEY.ESC, ctrl.KEY.TAB].indexOf(key)) { + // TODO: SEGURO? + ctrl.close(); + } $scope.$apply(function () { _handleDropDownSelection(key); }); - if (KEY.isVerticalMovement(key) && ctrl.items.length > 0) { + if (ctrl.KEY.isVerticalMovement(key) && ctrl.items.length > 0) { _ensureHighlightVisible(); } - if (key === KEY.ENTER || key === KEY.ESC) { + if (key === ctrl.KEY.ENTER || key === ctrl.KEY.ESC) { e.preventDefault(); e.stopPropagation(); } + + // Let the users process the data + // TODO: Is this needed, or just let the user bind to the event themselves! +// ctrl.afterKeypress(e); }); ctrl.searchInput.on('keyup', function (e) { // return early with these keys - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || - KEY.isVerticalMovement(e.which)) { + if (e.which === ctrl.KEY.TAB || ctrl.KEY.isControl(e) || ctrl.KEY.isFunctionKey(e) || + e.which === ctrl.KEY.ESC || + ctrl.KEY.isVerticalMovement(e.which)) { return; } - if (ctrl.onKeypressCallback === undefined) { - return; - } - ctrl.onKeypressCallback($scope, {event: e}); + // Let the users process the data + // TODO: Is this needed, or just let the user bind to the event themselves! + ctrl.afterKeypress(e); }); // See https://github.com/ivaynberg/select2/blob/3.4.6/select2.js#L1431 @@ -962,6 +1237,89 @@ uis.controller('uiSelectCtrl', ctrl.searchInput.off('keyup keydown blur paste'); }); + /** + * Keypress callback. Overridable. + * @param event the keypress event + */ + /* jshint unused:false */ + ctrl.afterKeypress = function (event) { + }; + + /** + * Method called before a selection is made. This can be overridden to allow + * the selection to be aborted, or a modified version of the selected item to be + * returned. + * + * Allowable responses are -: + * false: Abort the selection + * true: Complete selection with the selected object + * object: Complete the selection with the returned object + * promise: Wait for response - response from promise is as above + * + * @param item the item that has been selected + * @returns {*} + */ + ctrl.beforeSelect = function (item) { + return true; + }; + + /** + * Method called after a selection is confirmed. This can be overridden to allow + * the application to be notified of a newly selected item. + * No return is required. + * + * @param item the item that has been selected + */ + ctrl.afterSelect = function (item) { + }; + + /** + * Method called before an item is removed from the selected list. This can be overridden + * to allow the removal to be aborted + * + * Allowable responses are -: + * false: Abort the selection + * true: Complete selection with the selected object + * object: Complete the selection with the returned object + * promise: Wait for response - response from promise is as above + * + * @param item the item that has been selected + * @returns {*} + */ + ctrl.beforeRemove = function (item) { + return true; + }; + + /** + * Method called after a item is removed. This can be overridden to allow + * the application to be notified of a removed item. + * No return is required. + * + * @param item the item that has been removed + */ + ctrl.afterRemove = function (item) { + }; + + /** + * Method called before the dropdown is opened. This can be overridden to allow + * the application to process data before the dropdown is displayed. + * The method may return a promise, or true to allow the dropdown, or false to abort. + * @returns {boolean} + */ + ctrl.beforeDropdownOpen = function () { + return true; + }; + + /** + * Method called before the dropdown is closed. This can be overridden to allow + * the application to prevent the dropdown from closing. + * The method may return a promise, or true to allow the dropdown to close, or false to abort. + * @returns {boolean} + */ + ctrl.beforeDropdownClose = function () { + return true; + }; + }]); uis.directive('uiSelect', @@ -1008,13 +1366,6 @@ uis.directive('uiSelect', } }(); - $select.onSelectCallback = $parse(attrs.onSelect); - $select.onBeforeSelectCallback = $parse(attrs.onBeforeSelect); - $select.onRemoveCallback = $parse(attrs.onRemove); - $select.onBeforeRemoveCallback = $parse(attrs.onBeforeRemove); - $select.onKeypressCallback = $parse(attrs.onKeypress); - $select.onDropdownCallback = $parse(attrs.onDropdown); - // Limit the number of selections allowed $select.limit = (angular.isDefined(attrs.limit)) ? parseInt(attrs.limit, 10) : undefined; @@ -1081,10 +1432,9 @@ uis.directive('uiSelect', // Will lose focus only with certain targets var focusableControls = ['input', 'button', 'textarea']; // To check if target is other ui-select - var targetScope = angular.element(e.target).scope(); + var targetController = angular.element(e.target).controller('uiSelect'); // To check if target is other ui-select - var skipFocusser = targetScope && targetScope.$select && - targetScope.$select !== $select; + var skipFocusser = targetController && targetController !== $select; // Check if target is input, button or textarea if (!skipFocusser) { skipFocusser = ~focusableControls.indexOf(e.target.tagName.toLowerCase()); @@ -1213,7 +1563,8 @@ uis.directive('uiSelect', var offsetDropdown = uisOffset(dropdown); // Determine if the direction of the dropdown needs to be changed. - if (offset.top + offset.height + offsetDropdown.height > $window.pageYOffset + $document[0].documentElement.clientHeight) { + if (offset.top + offset.height + offsetDropdown.height > + $window.pageYOffset + $document[0].documentElement.clientHeight) { element.addClass(directionUpClassName); } @@ -1248,6 +1599,8 @@ uis.directive('uiSelectMatch', ['uiSelectConfig', function (uiSelectConfig) { }, link: function (scope, element, attrs, $select) { $select.lockChoiceExpression = attrs.uiLockChoice; + + // TODO: observe required? attrs.$observe('placeholder', function (placeholder) { $select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder; }); @@ -1257,6 +1610,7 @@ uis.directive('uiSelectMatch', ['uiSelectConfig', function (uiSelectConfig) { (angular.isDefined(allow)) ? (allow === '') ? true : (allow.toLowerCase() === 'true') : false; } + // TODO: observe required? attrs.$observe('allowClear', setAllowClear); setAllowClear(attrs.allowClear); @@ -1302,65 +1656,47 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel * Then calls onRemove to notify the user the item has been removed */ ctrl.removeChoice = function (index) { + // Get the removed choice var removedChoice = $select.selected[index]; - // if the choice is locked, can't remove it + // If the choice is locked, can't remove it if (removedChoice._uiSelectChoiceLocked) { return; } - var locals = {}; - locals[$select.parserResult.itemName] = removedChoice; - - $select.selected.splice(index, 1); - ctrl.activeMatchIndex = -1; - $select.sizeSearchInput(); - - var callbackContext = { - $item: removedChoice, - $model: $select.parserResult.modelMapper($scope, locals) - }; - // Give some time for scope propagation. function completeCallback() { + $select.selected.splice(index, 1); + ctrl.activeMatchIndex = -1; + $select.sizeSearchInput(); + $timeout(function () { - $select.onRemoveCallback($scope, callbackContext); + $select.afterRemove(removedChoice); }); ctrl.updateModel(); } - // If there's no onBeforeRemove callback, then just call the completeCallback - if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { - completeCallback(); - return; - } - - // Call the onBeforeRemove callback + // Call the beforeRemove callback // Allowable responses are -: - // falsy: Abort the removal - // promise: Wait for response + // false: Abort the removal // true: Complete removal - var result = ctrl.onBeforeRemoveCallback($scope, callbackContext); - if (angular.isDefined(result)) { - if (angular.isFunction(result.then)) { - // Promise returned - wait for it to complete before completing the selection - result.then(function (result) { - if (!result) { - return; - } - completeCallback(result); - }); - } else if (result === true) { - completeCallback(); - } - } else { + // promise: Wait for response + var result = $select.beforeRemove(removedChoice); + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (result) { + if (result === true) { + completeCallback(); + } + }); + } else if (result === true) { completeCallback(); } }; ctrl.getPlaceholder = function () { - //Refactor single? + // Refactor single? if ($select.selected && $select.selected.length) { return; } @@ -1488,17 +1824,18 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel var key = e.which; scope.$apply(function () { var processed = false; - if (KEY.isHorizontalMovement(key)) { + if ($select.KEY.isHorizontalMovement(key)) { processed = _handleMatchSelection(key); } - if (processed && key != KEY.TAB) { - //TODO Check si el tab selecciona aun correctamente - //Crear test + if (processed && key != $select.KEY.TAB) { + // TODO Check si el tab selecciona aun correctamente + //Creat test // e.preventDefault(); // e.stopPropagation(); } }); }); + function _getCaretPosition(el) { if (angular.isNumber(el.selectionStart)) { return el.selectionStart; @@ -1520,7 +1857,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel prev = $selectMultiple.activeMatchIndex - 1, newIndex = curr; - if (caretPosition > 0 || ($select.search.length && key == KEY.RIGHT)) { + if (caretPosition > 0 || ($select.search.length && key == $select.KEY.RIGHT)) { return false; } @@ -1528,7 +1865,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel function getNewActiveMatchIndex() { switch (key) { - case KEY.LEFT: + case $select.KEY.LEFT: // Select previous/first item if (~$selectMultiple.activeMatchIndex) { return prev; @@ -1538,7 +1875,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel return last; } break; - case KEY.RIGHT: + case $select.KEY.RIGHT: // Open drop-down if (!~$selectMultiple.activeMatchIndex || curr === last) { $select.activate(); @@ -1549,7 +1886,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel return next; } break; - case KEY.BACKSPACE: + case $select.KEY.BACKSPACE: // Remove selected item and select previous/first if (~$selectMultiple.activeMatchIndex) { $selectMultiple.removeChoice(curr); @@ -1560,7 +1897,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel return last; } break; - case KEY.DELETE: + case $select.KEY.DELETE: // Remove selected item and select next item if (~$selectMultiple.activeMatchIndex) { $selectMultiple.removeChoice($selectMultiple.activeMatchIndex); @@ -1684,7 +2021,7 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co }); focusser.bind("keydown", function (e) { - if (e.which === KEY.BACKSPACE) { + if (e.which === $select.KEY.BACKSPACE) { e.preventDefault(); e.stopPropagation(); $select.select(undefined); @@ -1692,11 +2029,11 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co return; } - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) { + if (e.which === $select.KEY.TAB || $select.KEY.isControl(e) || $select.KEY.isFunctionKey(e) || e.which === $select.KEY.ESC) { return; } - if (e.which == KEY.DOWN || e.which == KEY.UP || e.which == KEY.ENTER || e.which == KEY.SPACE) { + if (e.which == $select.KEY.DOWN || e.which == $select.KEY.UP || e.which == $select.KEY.ENTER || e.which == $select.KEY.SPACE) { e.preventDefault(); e.stopPropagation(); $select.activate(); @@ -1706,8 +2043,8 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co }); focusser.bind("keyup input", function (e) { - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || - e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { + if (e.which === $select.KEY.TAB || $select.KEY.isControl(e) || $select.KEY.isFunctionKey(e) || e.which === $select.KEY.ESC || + e.which == $select.KEY.ENTER || e.which === $select.KEY.BACKSPACE) { return; } diff --git a/dist/select.min.css b/dist/select.min.css index 577716b16..9370167ce 100644 --- a/dist/select.min.css +++ b/dist/select.min.css @@ -1,6 +1,6 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-06T13:28:34.992Z + * Version: 0.12.1 - 2015-08-09T18:09:19.231Z * License: MIT */.ui-select-highlight{font-weight:700}.ui-select-offscreen{clip:rect(0 0 0 0)!important;width:1px!important;height:1px!important;border:0!important;margin:0!important;padding:0!important;overflow:hidden!important;position:absolute!important;outline:0!important;left:0!important;top:0!important}.ng-dirty.ng-invalid>a.select2-choice{border-color:#D44950}.select2-result-single{padding-left:0}.select-locked>.ui-select-match-close,.select2-locked>.select2-search-choice-close{display:none}body>.select2-container.open{z-index:9999}.ui-select-container[theme=select2].direction-up .ui-select-match{border-radius:0 0 4px 4px}.ui-select-container[theme=select2].direction-up .ui-select-dropdown{bottom:100%;top:auto;position:absolute;border-radius:4px 4px 0 0;border-top-width:1px;border-top-style:solid;box-shadow:0 -4px 8px rgba(0,0,0,.25);margin-top:-4px}.ui-select-container[theme=select2].direction-up .ui-select-dropdown .select2-search{margin-top:4px}.ui-select-container[theme=select2].direction-up.select2-dropdown-open .ui-select-match{border-bottom-color:#5897fb}.selectize-input.selectize-focus{border-color:#007FBB!important}.selectize-control>.selectize-dropdown,.selectize-control>.selectize-input>input{width:100%}.ng-dirty.ng-invalid>div.selectize-input{border-color:#D44950}.ui-select-container[theme=selectize].direction-up .ui-select-dropdown{bottom:100%;top:auto;position:absolute;box-shadow:0 -4px 8px rgba(0,0,0,.25);margin-top:-2px}.btn-default-focus{color:#333;background-color:#EBEBEB;border-color:#ADADAD;text-decoration:none;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.ui-select-bootstrap .ui-select-toggle{position:relative}.ui-select-bootstrap .ui-select-toggle>.caret{position:absolute;height:10px;top:50%;right:10px;margin-top:-2px}.input-group>.ui-select-bootstrap.dropdown{position:static}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control{border-radius:4px 0 0 4px}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control.direction-up{border-radius:4px 0 0 4px!important}.ui-select-bootstrap>.ui-select-match>.btn{text-align:left!important}.ui-select-bootstrap>.ui-select-match>.caret{position:absolute;top:45%;right:15px}.ui-select-bootstrap>.ui-select-choices{width:100%;height:auto;max-height:200px;overflow-x:hidden;margin-top:-1px}body>.ui-select-bootstrap.open{z-index:1000}.ui-select-multiple.ui-select-bootstrap{height:auto;padding:3px 3px 0}.ui-select-multiple.ui-select-bootstrap input.ui-select-search{background-color:transparent!important;border:none;outline:0;height:1.666666em;margin-bottom:3px}.ui-select-multiple.ui-select-bootstrap .ui-select-match .close{font-size:1.6em;line-height:.75}.ui-select-multiple.ui-select-bootstrap .ui-select-match-item{outline:0;margin:0 3px 3px 0}.ui-select-multiple .ui-select-match-item{position:relative}.ui-select-multiple .ui-select-match-item.dropping-before:before{content:"";position:absolute;top:0;right:100%;height:100%;margin-right:2px;border-left:1px solid #428bca}.ui-select-multiple .ui-select-match-item.dropping-after:after{content:"";position:absolute;top:0;left:100%;height:100%;margin-left:2px;border-right:1px solid #428bca}.ui-select-bootstrap .ui-select-placeholder{opacity:1;color:#999}.ui-select-bootstrap .ui-select-choices-row>a{display:block;padding:3px 20px;clear:both;font-weight:400;line-height:1.42857143;color:#333;white-space:nowrap}.ui-select-bootstrap .ui-select-choices-row>a:focus,.ui-select-bootstrap .ui-select-choices-row>a:hover{text-decoration:none;color:#262626;background-color:#f5f5f5}.ui-select-bootstrap .ui-select-choices-row.active>a{color:#fff;text-decoration:none;outline:0;background-color:#428bca}.ui-select-bootstrap .ui-select-choices-row.active.disabled>a,.ui-select-bootstrap .ui-select-choices-row.disabled>a{color:#777;cursor:not-allowed;background-color:#fff}.ui-select-match.ng-hide-add,.ui-select-search.ng-hide-add{display:none!important}.ui-select-bootstrap.ng-dirty.ng-invalid>button.btn.ui-select-match{border-color:#D44950}.ui-select-container[theme=bootstrap].direction-up .ui-select-dropdown{bottom:100%;top:auto;position:absolute;box-shadow:0 -4px 8px rgba(0,0,0,.25)} \ No newline at end of file diff --git a/dist/select.min.js b/dist/select.min.js index 385a28898..027944561 100644 --- a/dist/select.min.js +++ b/dist/select.min.js @@ -1,7 +1,8 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-06T13:28:34.991Z + * Version: 0.12.1 - 2015-08-09T18:09:19.229Z * License: MIT */ -!function(){"use strict";angular.module("ui.select.sort",["ui.select"]).directive("uiSelectSort",["$timeout","uiSelectConfig","uiSelectMinErr",function(e,t,c){return{require:"^uiSelect",link:function(t,l,s,i){if(null===t[s.uiSelectSort])throw c("sort","Expected a list to sort");var n=angular.extend({axis:"horizontal"},t.$eval(s.uiSelectSortOptions)),a=n.axis,r="dragging",o="dropping",u="dropping-before",d="dropping-after";t.$watch(function(){return i.sortable},function(e){e?l.attr("draggable",!0):l.removeAttr("draggable")}),l.on("dragstart",function(e){l.addClass(r),(e.dataTransfer||e.originalEvent.dataTransfer).setData("text/plain",t.$index)}),l.on("dragend",function(){l.removeClass(r)});var p,h=function(e,t){this.splice(t,0,this.splice(e,1)[0])},f=function(e){e.preventDefault();var t="vertical"===a?e.offsetY||e.layerY||(e.originalEvent?e.originalEvent.offsetY:0):e.offsetX||e.layerX||(e.originalEvent?e.originalEvent.offsetX:0);t=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],c=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(c.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,c=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,l,s){s(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(c){var l=c[0].getBoundingClientRect();return{width:l.width||c.prop("offsetWidth"),height:l.height||c.prop("offsetHeight"),top:l.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:l.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);c.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,c,l){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(e,s){if(!s.repeat)throw c("repeat","Expected 'repeat' expression.");return function(e,s,i,n,a){var r=i.groupBy,o=i.groupFilter;if(n.parseRepeatAttr(i.repeat,r,o),n.disableChoiceExpression=i.uiDisableChoice,n.onHighlightCallback=i.onHighlight,r){var u=s.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=s.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(n.parserResult.itemName,"$select.items",n.parserResult.trackByExp,r)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+n.parserResult.itemName+")").attr("ng-click","$select.select("+n.parserResult.itemName+",false,$event)");var p=s.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),l(s,a)(e),e.$watch("$select.search",function(e){e&&!n.open&&n.multiple&&n.activate(!1,!0),n.activeIndex=0})}}}}]),c.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,c,l,s,i,n,a,r){function o(){(h.resetSearchInput||void 0===h.resetSearchInput&&r.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var c,l,s=[];for(c=0;c0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:c=!1}return c}function p(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw a("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var l=t[h.activeIndex],s=l.offsetTop+l.clientHeight-e[0].scrollTop,i=e[0].offsetHeight;s>i?e[0].scrollTop+=s-i:s=h.items.length?0:h.activeIndex,l(function(){h.search=e||h.search,h.searchInput[0].focus()})},i=h.onDropdownCallback(t,{open:!0});angular.isDefined(i)?angular.isFunction(i.then)?i.then(function(e){e&&s()}):i===!0?s():i&&s():s()}},h.parseRepeatAttr=function(e,c,l){function s(e){var s=t.$eval(c);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(s)?s(e):e[s],c=h.findGroupByName(t);c?c.items.push(e):h.groups.push({name:t,items:[e]})}),l){var i=t.$eval(l);angular.isFunction(i)?h.groups=i(h.groups):angular.isArray(i)&&(h.groups=u(h.groups,i))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function i(e){h.items=e}h.setItemsFn=c?s:i,h.parserResult=n.parse(e),h.isGrouped=!!c,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var c=h.selected;if(h.isEmpty()||angular.isArray(c)&&!c.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var l=e.filter(function(e){return c.indexOf(e)<0});h.setItemsFn(l)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw a("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),c=-1===t?!1:t===h.activeIndex;return c&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),c},h.isDisabled=function(e){if(!h.open)return!1;var t,c=h.items.indexOf(e[h.itemProperty]),l=!1;return c>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[c],l=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=l),l},h.select=function(e,c,s){if((void 0===e||!e._uiSelectChoiceDisabled)&&(h.items||h.search)){var i={};i[h.parserResult.itemName]=e;var n={$item:e,$model:h.parserResult.modelMapper(t,i)},a=function(e){n.$item=e,t.$broadcast("uis:select",e),l(function(){h.onSelectCallback(t,n)}),h.closeOnSelect&&h.close(c),s&&"click"===s.type&&(h.clickTriggeredSelect=!0)};if(!angular.isDefined(h.onBeforeRemoveCallback))return a(e),void 0;var r=h.onBeforeSelectCallback(t,n);angular.isDefined(r)?angular.isFunction(r.then)?r.then(function(t){t&&(t===!0?a(e):t&&a(t))}):r===!0?a(e):r&&a(r):a(e)}},h.close=function(e){function c(){h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),o(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e)}if(h.open){var l=h.onDropdownCallback(t,{open:!1});angular.isDefined(l)?angular.isFunction(l.then)?l.then(function(e){e&&c()}):l===!0?c():l&&c():c()}},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),l(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var c,l=h.selected[t];return l&&!angular.isUndefined(h.lockChoiceExpression)&&(c=!!e.$eval(h.lockChoiceExpression),l._uiSelectChoiceLocked=c),c};var g=null;h.sizeSearchInput=function(){var e=h.searchInput[0],c=h.searchInput.parent().parent()[0],s=function(){return c.clientWidth*!!e.offsetParent},i=function(t){if(0===t)return!1;var c=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>c&&(c=t),h.searchInput.css("width",c+"px"),!0};h.searchInput.css("width","10px"),l(function(){null!==g||i(s())||(g=t.$watch(s,function(e){i(e)&&(g(),g=null)}))})},h.searchInput.on("keydown",function(c){var l=c.which;t.$apply(function(){d(l)}),e.isVerticalMovement(l)&&h.items.length>0&&p(),(l===e.ENTER||l===e.ESC)&&(c.preventDefault(),c.stopPropagation())}),h.searchInput.on("keyup",function(c){c.which===e.TAB||e.isControl(c)||e.isFunctionKey(c)||c.which===e.ESC||e.isVerticalMovement(c.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:c})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),c.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,c,l,s,i,n,a){return{restrict:"EA",templateUrl:function(e,t){var l=t.theme||c.theme;return l+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(i,r){return angular.isDefined(r.multiple)?i.append("").removeAttr("multiple"):i.append(""),function(i,r,o,u,d){function p(e){if(g.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(r[0],e.target):r[0].contains(e.target),!t&&!g.clickTriggeredSelect){var c=["input","button","textarea"],l=angular.element(e.target).scope(),s=l&&l.$select&&l.$select!==g;s||(s=~c.indexOf(e.target.tagName.toLowerCase())),g.close(s),i.$digest()}g.clickTriggeredSelect=!1}}function h(){var t=s(r);w=angular.element('
    '),w[0].style.width=t.width+"px",w[0].style.height=t.height+"px",r.after(w),x=r[0].style.width,e.find("body").append(r),r[0].style.position="absolute",r[0].style.left=t.left+"px",r[0].style.top=t.top+"px",r[0].style.width=t.width+"px"}function f(){null!==w&&(w.replaceWith(r),w=null,r[0].style.position="",r[0].style.left="",r[0].style.top="",r[0].style.width=x)}var g=u[0],v=u[1];g.generatedId=c.generateId(),g.baseTitle=o.title||"Select box",g.focusserTitle=g.baseTitle+" focus",g.focusserId="focusser-"+g.generatedId,g.closeOnSelect=function(){return angular.isDefined(o.closeOnSelect)?n(o.closeOnSelect)():c.closeOnSelect}(),g.onSelectCallback=n(o.onSelect),g.onBeforeSelectCallback=n(o.onBeforeSelect),g.onRemoveCallback=n(o.onRemove),g.onBeforeRemoveCallback=n(o.onBeforeRemove),g.onKeypressCallback=n(o.onKeypress),g.onDropdownCallback=n(o.onDropdown),g.limit=angular.isDefined(o.limit)?parseInt(o.limit,10):void 0,g.ngModel=v,g.choiceGrouped=function(e){return g.isGrouped&&e&&e.name},o.tabindex&&o.$observe("tabindex",function(e){g.focusInput.attr("tabindex",e),r.removeAttr("tabindex")});var m=i.$eval(o.searchEnabled);g.searchEnabled=void 0!==m?m:c.searchEnabled;var $=i.$eval(o.sortable);g.sortable=void 0!==$?$:c.sortable,o.$observe("disabled",function(){g.disabled=void 0!==o.disabled?o.disabled:!1}),angular.isDefined(o.autofocus)&&a(function(){g.setFocus()}),angular.isDefined(o.focusOn)&&i.$on(o.focusOn,function(){a(function(){g.setFocus()})}),e.on("click",p),i.$on("$destroy",function(){e.off("click",p)}),d(i,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),c.removeAttr("data-ui-select-match"),1!==c.length)throw l("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);r.querySelectorAll(".ui-select-match").replaceWith(c);var s=t.querySelectorAll(".ui-select-choices");if(s.removeAttr("ui-select-choices"),s.removeAttr("data-ui-select-choices"),1!==s.length)throw l("transcluded","Expected 1 .ui-select-choices but got '{0}'.",s.length);r.querySelectorAll(".ui-select-choices").replaceWith(s)});var b=i.$eval(o.appendToBody);(void 0!==b?b:c.appendToBody)&&(i.$watch("$select.open",function(e){e?h():f()}),i.$on("$destroy",function(){f()}));var w=null,x="",y=null,E="direction-up";i.$watch("$select.open",function(c){if(c){if(y=angular.element(r).querySelectorAll(".ui-select-dropdown"),null===y)return;y[0].style.opacity=0,a(function(){var c=s(r),l=s(y);c.top+c.height+l.height>t.pageYOffset+e[0].documentElement.clientHeight&&r.addClass(E),y[0].style.opacity=1})}else{if(null===y)return;r.removeClass(E)}})}}}}]),c.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,l=t.parent().attr("multiple");return c+(l?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,l,s){function i(e){s.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}s.lockChoiceExpression=l.uiLockChoice,l.$observe("placeholder",function(t){s.placeholder=void 0!==t?t:e.placeholder}),l.$observe("allowClear",i),i(l.allowClear),s.multiple&&s.sizeSearchInput()}}}]),c.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var c,l=this,s=e.$select;e.$evalAsync(function(){c=e.ngModel}),l.activeMatchIndex=-1,l.updateModel=function(){c.$setViewValue(Date.now()),l.refreshComponent()},l.refreshComponent=function(){s.refreshItems(),s.sizeSearchInput()},l.removeChoice=function(c){function i(){t(function(){s.onRemoveCallback(e,r)}),l.updateModel()}var n=s.selected[c];if(!n._uiSelectChoiceLocked){var a={};a[s.parserResult.itemName]=n,s.selected.splice(c,1),l.activeMatchIndex=-1,s.sizeSearchInput();var r={$item:n,$model:s.parserResult.modelMapper(e,a)};if(!angular.isDefined(l.onBeforeRemoveCallback))return i(),void 0;var o=l.onBeforeRemoveCallback(e,r);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(e){e&&i(e)}):o===!0&&i():i()}},l.getPlaceholder=function(){return s.selected&&s.selected.length?void 0:s.placeholder}}],controllerAs:"$selectMultiple",link:function(l,s,i,n){function a(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function r(t){function c(){switch(t){case e.LEFT:return~d.activeMatchIndex?p:n;case e.RIGHT:return~d.activeMatchIndex&&r!==n?u:(o.activate(),!1);case e.BACKSPACE:return~d.activeMatchIndex?(d.removeChoice(r),p):n;case e.DELETE:return~d.activeMatchIndex?(d.removeChoice(d.activeMatchIndex),r):!1}}var l=a(o.searchInput[0]),s=o.selected.length,i=0,n=s-1,r=d.activeMatchIndex,u=d.activeMatchIndex+1,p=d.activeMatchIndex-1,h=r;return l>0||o.search.length&&t==e.RIGHT?!1:(o.close(),h=c(),d.activeMatchIndex=o.selected.length&&h!==!1?Math.min(n,Math.max(i,h)):-1,!0)}var o=n[0],u=l.ngModel=n[1],d=l.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,u.$parsers.unshift(function(){for(var e,t={},c=[],s=o.selected.length-1;s>=0;s--)t={},t[o.parserResult.itemName]=o.selected[s],e=o.parserResult.modelMapper(l,t),c.unshift(e);return c}),u.$formatters.unshift(function(e){var t,c=o.parserResult.source(l,{$select:{search:""}}),s={};if(!c)return e;var i=[],n=function(e,c){if(e&&e.length){for(var n=e.length-1;n>=0;n--){if(s[o.parserResult.itemName]=e[n],t=o.parserResult.modelMapper(l,s),o.parserResult.trackByExp){var a=/\.(.+)/.exec(o.parserResult.trackByExp);if(a.length>0&&t[a[1]]==c[a[1]])return i.unshift(e[n]),!0}if(angular.equals(t,c))return i.unshift(e[n]),!0}return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(o.selected,e[a])||n(c,e[a])||i.unshift(e[a]);return i}),l.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,d.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);o.selected=[]}o.selected=u.$viewValue,l.$evalAsync()},l.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),d.updateModel())}),l.$on("uis:activate",function(){d.activeMatchIndex=-1}),l.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(t){var c=t.which;l.$apply(function(){var t=!1;e.isHorizontalMovement(c)&&(t=r(c)),t&&c!=e.TAB})}),o.searchInput.on("blur",function(){c(function(){d.activeMatchIndex=-1})})}}}]),c.directive("uiSelectSingle",["$timeout","$compile",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(l,s,i,n){var a=n[0],r=n[1];r.$parsers.unshift(function(e){var t,c={};return c[a.parserResult.itemName]=e,t=a.parserResult.modelMapper(l,c)}),r.$formatters.unshift(function(e){var t,c=a.parserResult.source(l,{$select:{search:""}}),s={};if(c){var i=function(c){return s[a.parserResult.itemName]=c,t=a.parserResult.modelMapper(l,s),t==e};if(a.selected&&i(a.selected))return a.selected;for(var n=c.length-1;n>=0;n--)if(i(c[n]))return c[n]}return e}),l.$watch("$select.selected",function(e){r.$viewValue!==e&&r.$setViewValue(e)}),r.$render=function(){a.selected=r.$viewValue},l.$on("uis:select",function(e,t){a.selected=t}),l.$on("uis:close",function(e,c){t(function(){a.focusser.prop("disabled",!1),c||a.focusser[0].focus()},0,!1)}),l.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");c(o)(l),a.focusser=o,a.focusInput=o,s.parent().append(o),o.bind("focus",function(){l.$evalAsync(function(){a.focus=!0})}),o.bind("blur",function(){l.$evalAsync(function(){a.focus=!1})}),o.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),a.select(void 0),l.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),a.activate()),l.$digest()),void 0)}),o.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(a.activate(o.val()),o.val(""),l.$digest())})}}}]),c.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var l=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!l)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:l[2],source:t(l[3]),trackByExp:l[4],modelMapper:t(l[1]||l[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,l){var s=e+" in "+(l?"$group.items":t);return c&&(s+=" track by "+c),s}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("selectize/choices.tpl.html",'
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",'
    {{$select.placeholder}}
    '),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",'')}]),angular.module("ui.select").run(["$templateCache",function(e){e.put("select2/choices.tpl.html",'
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    ')}]); \ No newline at end of file +!function(){"use strict";angular.module("ui.select.tagging",["ui.select"]).directive("uiSelectTagging",["$parse","$timeout",function(){return{require:"^uiSelect",link:function(e,t,c,l){function s(e){if(void 0===e||void 0===l.search)return!1;var t=e.filter(function(e){return void 0===l.search.toUpperCase()||void 0===e?!1:e.toUpperCase()===l.search.toUpperCase()}).length>0;return t}function i(e,t){var c=-1;if(angular.isArray(e))for(var s=angular.copy(e),i=0;i0){var c=t.split(n.taggingTokens[0]);c&&c.length>0&&(angular.forEach(c,function(e){var t=n.beforeTagging(e);t&&n.select(t,!0)}),e.preventDefault(),e.stopPropagation())}}),n.beforeTagging=function(e){return e},n.afterKeypress=function(t){if(l.search.length>0){if(t.which===n.KEY.TAB||n.KEY.isControl(t)||n.KEY.isFunctionKey(t)||t.which===n.KEY.ESC||n.KEY.isVerticalMovement(t.which))return;for(var c=!1,a=0;a0&&(c=!0,l.search.substr(l.search.length-1)==n.KEY.MAP[t.keyCode]&&(l.search=l.search.substr(0,l.search.length-1)));if(c===!0)return n.select(n.beforeTagging(l.search)),void 0;if(l.activeIndex=l.taggingLabel===!1?-1:0,l.taggingLabel===!1)return;var r,o,u,d,p=angular.copy(l.items),h=angular.copy(l.items),f=!1,g=-1;if(u=l.$filter("filter")(p,function(e){return e.match(l.taggingLabel)}),u.length>0&&(d=u[0]),o=p[0],void 0!==o&&p.length>0&&d&&(f=!0,p=p.slice(1,p.length),h=h.slice(1,h.length)),r=l.search+" "+l.taggingLabel,i(l.selected,l.search)>-1)return;if(s(h.concat(l.selected)))return f&&(p=h,e.$evalAsync(function(){l.activeIndex=0,l.items=p})),void 0;if(s(h))return f&&(l.items=h.slice(1,h.length)),void 0;f&&(g=i(l.selected,r)),g>-1?p=p.slice(g+1,p.length-1):(p=[],p.push(r),p=p.concat(h)),e.$evalAsync(function(){l.activeIndex=0,l.items=p})}}}}}])}(),function(){"use strict";angular.module("ui.select.sort",["ui.select"]).directive("uiSelectSort",["$timeout","uiSelectConfig","uiSelectMinErr",function(e,t,c){return{require:"^uiSelect",link:function(t,l,s,i){if(null===t[s.uiSelectSort])throw c("sort","Expected a list to sort");var n=angular.extend({axis:"horizontal"},t.$eval(s.uiSelectSortOptions)),a=n.axis,r="dragging",o="dropping",u="dropping-before",d="dropping-after";t.$watch(function(){return i.sortable},function(e){e?l.attr("draggable",!0):l.removeAttr("draggable")}),l.on("dragstart",function(e){l.addClass(r),(e.dataTransfer||e.originalEvent.dataTransfer).setData("text/plain",t.$index)}),l.on("dragend",function(){l.removeClass(r)});var p,h=function(e,t){this.splice(t,0,this.splice(e,1)[0])},f=function(e){e.preventDefault();var t="vertical"===a?e.offsetY||e.layerY||(e.originalEvent?e.originalEvent.offsetY:0):e.offsetX||e.layerX||(e.originalEvent?e.originalEvent.offsetX:0);t$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(c){var l=c[0].getBoundingClientRect();return{width:l.width||c.prop("offsetWidth"),height:l.height||c.prop("offsetHeight"),top:l.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:l.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);t.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,c,l){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(e,s){if(!s.repeat)throw c("repeat","Expected 'repeat' expression.");return function(e,s,i,n,a){var r=i.groupBy,o=i.groupFilter;if(n.parseRepeatAttr(i.repeat,r,o),n.disableChoiceExpression=i.uiDisableChoice,n.onHighlightCallback=i.onHighlight,r){var u=s.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=s.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(n.parserResult.itemName,"$select.items",n.parserResult.trackByExp,r)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+n.parserResult.itemName+")").attr("ng-click","$select.select("+n.parserResult.itemName+",false,$event)");var p=s.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),l(s,a)(e),e.$watch("$select.search",function(e){e&&!n.open&&n.multiple&&n.activate(!1,!0),n.activeIndex=0})}}}}]),t.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(e,t,c,l,s,i,n,a){function r(){(p.resetSearchInput||void 0===p.resetSearchInput&&a.resetSearchInput)&&(p.search=h,p.selected&&p.items.length&&!p.multiple&&(p.activeIndex=p.items.indexOf(p.selected)))}function o(e,t){var c,l,s=[];for(c=0;c0&&p.activeIndex--;break;case p.KEY.TAB:(!p.multiple||p.open)&&p.select(p.items[p.activeIndex],!0);break;case p.KEY.ENTER:p.open?void 0!==p.items[p.activeIndex]&&p.select(p.items[p.activeIndex]):p.activate(!1,!0);break;case p.KEY.ESC:p.close();break;default:t=!1}return t}function d(){var e=t.querySelectorAll(".ui-select-choices-content"),c=e.querySelectorAll(".ui-select-choices-row");if(c.length<1)throw n("choices","Expected multiple .ui-select-choices-row but got '{0}'.",c.length);if(!(p.activeIndex<0)){var l=c[p.activeIndex],s=l.offsetTop+l.clientHeight-e[0].scrollTop,i=e[0].offsetHeight;s>i?e[0].scrollTop+=s-i:s=112&&123>=e},isVerticalMovement:function(e){return~[p.KEY.UP,p.KEY.DOWN].indexOf(e)},isHorizontalMovement:function(e){return~[p.KEY.LEFT,p.KEY.RIGHT,p.KEY.BACKSPACE,p.KEY.DELETE].indexOf(e)}},p.isEmpty=function(){return angular.isUndefined(p.selected)||null===p.selected||""===p.selected},p.findGroupByName=function(e){return p.groups&&p.groups.filter(function(t){return t.name===e})[0]},p.activate=function(t,l){if(p.disabled||p.open)p.open&&!p.searchEnabled&&p.close();else{var s=function(){l||r(),e.$broadcast("uis:activate"),p.open=!0,p.searchEnabled||angular.element(p.searchInput[0]).addClass("ui-select-offscreen"),p.activeIndex=p.activeIndex>=p.items.length?0:p.activeIndex,c(function(){p.search=t||p.search,p.searchInput[0].focus()})},i=p.beforeDropdownOpen();angular.isFunction(i.then)?i.then(function(e){e===!0&&s()}):i===!0&&s()}},p.parseRepeatAttr=function(t,c,l){function s(t){var s=e.$eval(c);if(p.groups=[],angular.forEach(t,function(e){var t=angular.isFunction(s)?s(e):e[s],c=p.findGroupByName(t);c?c.items.push(e):p.groups.push({name:t,items:[e]})}),l){var i=e.$eval(l);angular.isFunction(i)?p.groups=i(p.groups):angular.isArray(i)&&(p.groups=o(p.groups,i))}p.items=[],p.groups.forEach(function(e){p.items=p.items.concat(e.items)})}function a(e){p.items=e}p.setItemsFn=c?s:a,p.parserResult=i.parse(t),p.isGrouped=!!c,p.itemProperty=p.parserResult.itemName,p.refreshItems=function(t){t=t||p.parserResult.source(e);var c=p.selected;if(p.isEmpty()||angular.isArray(c)&&!c.length||!p.removeSelected)p.setItemsFn(t);else if(void 0!==t){var l=t.filter(function(e){return c.indexOf(e)<0});p.setItemsFn(l)}},e.$watchCollection(p.parserResult.source,function(e){if(void 0===e||null===e)p.items=[];else{if(!angular.isArray(e))throw n("items","Expected an array but got '{0}'.",e);p.refreshItems(e),p.ngModel.$modelValue=null}})},p.setActiveItem=function(e){p.activeIndex=p.items.indexOf(e)},p.isActive=function(e){if(!p.open)return!1;var t=p.items.indexOf(e[p.itemProperty]),c=-1===t?!1:t===p.activeIndex;return c},p.isDisabled=function(e){if(!p.open)return!1;var t,c=p.items.indexOf(e[p.itemProperty]),l=!1;return c>=0&&!angular.isUndefined(p.disableChoiceExpression)&&(t=p.items[c],l=!!e.$eval(p.disableChoiceExpression),t._uiSelectChoiceDisabled=l),l},p.select=function(t,l,s){function i(){e.$broadcast("uis:select",t),c(function(){p.afterSelect(t)}),p.closeOnSelect&&p.close(l),s&&"click"===s.type&&(p.clickTriggeredSelect=!0)}if((void 0===t||!t._uiSelectChoiceDisabled)&&(p.items||p.search)){var n=p.beforeSelect(t);angular.isFunction(n.then)?n.then(function(e){e&&(e===!0?i(t):e&&i(e))}):n===!0?i(t):n&&i(n)}},p.close=function(t){function c(){p.ngModel&&p.ngModel.$setTouched&&p.ngModel.$setTouched(),r(),p.open=!1,p.searchEnabled||angular.element(p.searchInput[0]).removeClass("ui-select-offscreen"),e.$broadcast("uis:close",t)}if(p.open){var l=p.beforeDropdownClose();angular.isFunction(l.then)?l.then(function(e){e===!0&&c()}):l===!0&&c()}},p.setFocus=function(){p.focus||p.focusInput[0].focus()},p.clear=function(e){p.select(void 0),e.stopPropagation(),c(function(){p.focusser[0].focus()},0,!1)},p.toggle=function(e){p.open?(p.close(),e.preventDefault(),e.stopPropagation()):p.activate()},p.isLocked=function(e,t){var c,l=p.selected[t];return l&&!angular.isUndefined(p.lockChoiceExpression)&&(c=!!e.$eval(p.lockChoiceExpression),l._uiSelectChoiceLocked=c),c};var f=null;p.sizeSearchInput=function(){var t=p.searchInput[0],l=p.searchInput.parent().parent()[0],s=function(){return l.clientWidth*!!t.offsetParent},i=function(e){if(0===e)return!1;var c=e-t.offsetLeft-p.searchInput.parent()[0].offsetLeft-5;return 50>c&&(c=e),p.searchInput.css("width",c+"px"),!0};p.searchInput.css("width","10px"),c(function(){null!==f||i(s())||(f=e.$watch(s,function(e){i(e)&&(f(),f=null)}))})},p.searchInput.on("keydown",function(t){var c=t.which;~[p.KEY.ESC,p.KEY.TAB].indexOf(c)&&p.close(),e.$apply(function(){u(c)}),p.KEY.isVerticalMovement(c)&&p.items.length>0&&d(),(c===p.KEY.ENTER||c===p.KEY.ESC)&&(t.preventDefault(),t.stopPropagation())}),p.searchInput.on("keyup",function(e){e.which===p.KEY.TAB||p.KEY.isControl(e)||p.KEY.isFunctionKey(e)||e.which===p.KEY.ESC||p.KEY.isVerticalMovement(e.which)||p.afterKeypress(e)}),e.$on("$destroy",function(){p.searchInput.off("keyup keydown blur paste")}),p.afterKeypress=function(){},p.beforeSelect=function(){return!0},p.afterSelect=function(){},p.beforeRemove=function(){return!0},p.afterRemove=function(){},p.beforeDropdownOpen=function(){return!0},p.beforeDropdownClose=function(){return!0}}]),t.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,c,l,s,i,n,a){return{restrict:"EA",templateUrl:function(e,t){var l=t.theme||c.theme;return l+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(i,r){return angular.isDefined(r.multiple)?i.append("").removeAttr("multiple"):i.append(""),function(i,r,o,u,d){function p(e){if(g.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(r[0],e.target):r[0].contains(e.target),!t&&!g.clickTriggeredSelect){var c=["input","button","textarea"],l=angular.element(e.target).controller("uiSelect"),s=l&&l!==g;s||(s=~c.indexOf(e.target.tagName.toLowerCase())),g.close(s),i.$digest()}g.clickTriggeredSelect=!1}}function h(){var t=s(r);E=angular.element('
    '),E[0].style.width=t.width+"px",E[0].style.height=t.height+"px",r.after(E),w=r[0].style.width,e.find("body").append(r),r[0].style.position="absolute",r[0].style.left=t.left+"px",r[0].style.top=t.top+"px",r[0].style.width=t.width+"px"}function f(){null!==E&&(E.replaceWith(r),E=null,r[0].style.position="",r[0].style.left="",r[0].style.top="",r[0].style.width=w)}var g=u[0],v=u[1];g.generatedId=c.generateId(),g.baseTitle=o.title||"Select box",g.focusserTitle=g.baseTitle+" focus",g.focusserId="focusser-"+g.generatedId,g.closeOnSelect=function(){return angular.isDefined(o.closeOnSelect)?n(o.closeOnSelect)():c.closeOnSelect}(),g.limit=angular.isDefined(o.limit)?parseInt(o.limit,10):void 0,g.ngModel=v,g.choiceGrouped=function(e){return g.isGrouped&&e&&e.name},o.tabindex&&o.$observe("tabindex",function(e){g.focusInput.attr("tabindex",e),r.removeAttr("tabindex")});var m=i.$eval(o.searchEnabled);g.searchEnabled=void 0!==m?m:c.searchEnabled;var $=i.$eval(o.sortable);g.sortable=void 0!==$?$:c.sortable,o.$observe("disabled",function(){g.disabled=void 0!==o.disabled?o.disabled:!1}),angular.isDefined(o.autofocus)&&a(function(){g.setFocus()}),angular.isDefined(o.focusOn)&&i.$on(o.focusOn,function(){a(function(){g.setFocus()})}),e.on("click",p),i.$on("$destroy",function(){e.off("click",p)}),d(i,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),c.removeAttr("data-ui-select-match"),1!==c.length)throw l("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);r.querySelectorAll(".ui-select-match").replaceWith(c);var s=t.querySelectorAll(".ui-select-choices");if(s.removeAttr("ui-select-choices"),s.removeAttr("data-ui-select-choices"),1!==s.length)throw l("transcluded","Expected 1 .ui-select-choices but got '{0}'.",s.length);r.querySelectorAll(".ui-select-choices").replaceWith(s)});var b=i.$eval(o.appendToBody);(void 0!==b?b:c.appendToBody)&&(i.$watch("$select.open",function(e){e?h():f()}),i.$on("$destroy",function(){f()}));var E=null,w="",x=null,y="direction-up";i.$watch("$select.open",function(c){if(c){if(x=angular.element(r).querySelectorAll(".ui-select-dropdown"),null===x)return;x[0].style.opacity=0,a(function(){var c=s(r),l=s(x);c.top+c.height+l.height>t.pageYOffset+e[0].documentElement.clientHeight&&r.addClass(y),x[0].style.opacity=1})}else{if(null===x)return;r.removeClass(y)}})}}}}]),t.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,l=t.parent().attr("multiple");return c+(l?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,l,s){function i(e){s.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}s.lockChoiceExpression=l.uiLockChoice,l.$observe("placeholder",function(t){s.placeholder=void 0!==t?t:e.placeholder}),l.$observe("allowClear",i),i(l.allowClear),s.multiple&&s.sizeSearchInput()}}}]),t.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var c,l=this,s=e.$select;e.$evalAsync(function(){c=e.ngModel}),l.activeMatchIndex=-1,l.updateModel=function(){c.$setViewValue(Date.now()),l.refreshComponent()},l.refreshComponent=function(){s.refreshItems(),s.sizeSearchInput()},l.removeChoice=function(e){function c(){s.selected.splice(e,1),l.activeMatchIndex=-1,s.sizeSearchInput(),t(function(){s.afterRemove(i)}),l.updateModel()}var i=s.selected[e];if(!i._uiSelectChoiceLocked){var n=s.beforeRemove(i);angular.isFunction(n.then)?n.then(function(e){e===!0&&c()}):n===!0&&c()}},l.getPlaceholder=function(){return s.selected&&s.selected.length?void 0:s.placeholder}}],controllerAs:"$selectMultiple",link:function(c,l,s,i){function n(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(e){function t(){switch(e){case r.KEY.LEFT:return~u.activeMatchIndex?d:i;case r.KEY.RIGHT:return~u.activeMatchIndex&&a!==i?o:(r.activate(),!1);case r.KEY.BACKSPACE:return~u.activeMatchIndex?(u.removeChoice(a),d):i;case r.KEY.DELETE:return~u.activeMatchIndex?(u.removeChoice(u.activeMatchIndex),a):!1}}var c=n(r.searchInput[0]),l=r.selected.length,s=0,i=l-1,a=u.activeMatchIndex,o=u.activeMatchIndex+1,d=u.activeMatchIndex-1,p=a;return c>0||r.search.length&&e==r.KEY.RIGHT?!1:(r.close(),p=t(),u.activeMatchIndex=r.selected.length&&p!==!1?Math.min(i,Math.max(s,p)):-1,!0)}var r=i[0],o=c.ngModel=i[1],u=c.$selectMultiple;r.multiple=!0,r.removeSelected=!0,r.focusInput=r.searchInput,o.$parsers.unshift(function(){for(var e,t={},l=[],s=r.selected.length-1;s>=0;s--)t={},t[r.parserResult.itemName]=r.selected[s],e=r.parserResult.modelMapper(c,t),l.unshift(e);return l}),o.$formatters.unshift(function(e){var t,l=r.parserResult.source(c,{$select:{search:""}}),s={};if(!l)return e;var i=[],n=function(e,l){if(e&&e.length){for(var n=e.length-1;n>=0;n--){if(s[r.parserResult.itemName]=e[n],t=r.parserResult.modelMapper(c,s),r.parserResult.trackByExp){var a=/\.(.+)/.exec(r.parserResult.trackByExp);if(a.length>0&&t[a[1]]==l[a[1]])return i.unshift(e[n]),!0}if(angular.equals(t,l))return i.unshift(e[n]),!0}return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(r.selected,e[a])||n(l,e[a])||i.unshift(e[a]);return i}),c.$watchCollection(function(){return o.$modelValue},function(e,t){t!=e&&(o.$modelValue=null,u.refreshComponent())}),o.$render=function(){if(!angular.isArray(o.$viewValue)){if(!angular.isUndefined(o.$viewValue)&&null!==o.$viewValue)throw e("multiarr","Expected model value to be array but got '{0}'",o.$viewValue);r.selected=[]}r.selected=o.$viewValue,c.$evalAsync()},c.$on("uis:select",function(e,t){r.selected.length>=r.limit||(r.selected.push(t),u.updateModel())}),c.$on("uis:activate",function(){u.activeMatchIndex=-1}),c.$watch("$select.disabled",function(e,t){t&&!e&&r.sizeSearchInput()}),r.searchInput.on("keydown",function(e){var t=e.which;c.$apply(function(){var e=!1;r.KEY.isHorizontalMovement(t)&&(e=a(t)),e&&t!=r.KEY.TAB})}),r.searchInput.on("blur",function(){t(function(){u.activeMatchIndex=-1})})}}}]),t.directive("uiSelectSingle",["$timeout","$compile",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(c,l,s,i){var n=i[0],a=i[1];a.$parsers.unshift(function(e){var t,l={};return l[n.parserResult.itemName]=e,t=n.parserResult.modelMapper(c,l)}),a.$formatters.unshift(function(e){var t,l=n.parserResult.source(c,{$select:{search:""}}),s={};if(l){var i=function(l){return s[n.parserResult.itemName]=l,t=n.parserResult.modelMapper(c,s),t==e};if(n.selected&&i(n.selected))return n.selected;for(var a=l.length-1;a>=0;a--)if(i(l[a]))return l[a]}return e}),c.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){n.selected=a.$viewValue},c.$on("uis:select",function(e,t){n.selected=t}),c.$on("uis:close",function(t,c){e(function(){n.focusser.prop("disabled",!1),c||n.focusser[0].focus()},0,!1)}),c.$on("uis:activate",function(){r.prop("disabled",!0)});var r=angular.element("");t(r)(c),n.focusser=r,n.focusInput=r,l.parent().append(r),r.bind("focus",function(){c.$evalAsync(function(){n.focus=!0})}),r.bind("blur",function(){c.$evalAsync(function(){n.focus=!1})}),r.bind("keydown",function(e){return e.which===n.KEY.BACKSPACE?(e.preventDefault(),e.stopPropagation(),n.select(void 0),c.$apply(),void 0):(e.which===n.KEY.TAB||n.KEY.isControl(e)||n.KEY.isFunctionKey(e)||e.which===n.KEY.ESC||((e.which==n.KEY.DOWN||e.which==n.KEY.UP||e.which==n.KEY.ENTER||e.which==n.KEY.SPACE)&&(e.preventDefault(),e.stopPropagation(),n.activate()),c.$digest()),void 0)}),r.bind("keyup input",function(e){e.which===n.KEY.TAB||n.KEY.isControl(e)||n.KEY.isFunctionKey(e)||e.which===n.KEY.ESC||e.which==n.KEY.ENTER||e.which===n.KEY.BACKSPACE||(n.activate(r.val()),r.val(""),c.$digest())})}}}]),t.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var l=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!l)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:l[2],source:t(l[3]),trackByExp:l[4],modelMapper:t(l[1]||l[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,l){var s=e+" in "+(l?"$group.items":t);return c&&(s+=" track by "+c),s}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("selectize/choices.tpl.html",'
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",'
    {{$select.placeholder}}
    '),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",'')}]),angular.module("ui.select").run(["$templateCache",function(e){e.put("select2/choices.tpl.html",'
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    ') +}]); \ No newline at end of file diff --git a/dist/select.no-tpl.js b/dist/select.no-tpl.js index 43e0d31a6..5aadbe8ed 100644 --- a/dist/select.no-tpl.js +++ b/dist/select.no-tpl.js @@ -1,60 +1,13 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-06T13:28:34.948Z + * Version: 0.12.1 - 2015-08-09T18:09:19.159Z * License: MIT */ (function () { "use strict"; -var KEY = { - TAB: 9, - ENTER: 13, - ESC: 27, - SPACE: 32, - LEFT: 37, - UP: 38, - RIGHT: 39, - DOWN: 40, - SHIFT: 16, - CTRL: 17, - ALT: 18, - PAGE_UP: 33, - PAGE_DOWN: 34, - HOME: 36, - END: 35, - BACKSPACE: 8, - DELETE: 46, - COMMAND: 91, - - isControl: function (e) { - var k = e.which; - switch (k) { - case KEY.COMMAND: - case KEY.SHIFT: - case KEY.CTRL: - case KEY.ALT: - return true; - } - - if (e.metaKey) { - return true; - } - - return false; - }, - isFunctionKey: function (k) { - k = k.which ? k.which : k; - return k >= 112 && k <= 123; - }, - isVerticalMovement: function (k) { - return ~[KEY.UP, KEY.DOWN].indexOf(k); - }, - isHorizontalMovement: function (k) { - return ~[KEY.LEFT, KEY.RIGHT, KEY.BACKSPACE, KEY.DELETE].indexOf(k); - } -}; /** * Add querySelectorAll() to jqLite. @@ -107,7 +60,7 @@ var uis = angular.module('ui.select', []) appendToBody: false }) -// See Rename minErr and make it accessible from outside https://github.com/angular/angular.js/issues/6913 + // See Rename minErr and make it accessible from outside https://github.com/angular/angular.js/issues/6913 .service('uiSelectMinErr', function () { var minErr = angular.$$minErr('ui.select'); return function () { @@ -117,7 +70,7 @@ var uis = angular.module('ui.select', []) }; }) -// Recreates old behavior of ng-transclude. Used internally. + // Recreates old behavior of ng-transclude. Used internally. .directive('uisTranscludeAppend', function () { return { link: function (scope, element, attrs, ctrl, transclude) { @@ -128,29 +81,30 @@ var uis = angular.module('ui.select', []) }; }) -/** - * Highlights text that matches $select.search. - * - * Taken from AngularUI Bootstrap Typeahead - * See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L340 - */ + /** + * Highlights text that matches $select.search. + * + * Taken from AngularUI Bootstrap Typeahead + * See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L340 + */ .filter('highlight', function () { function escapeRegexp(queryToEscape) { return queryToEscape.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1'); } return function (matchItem, query) { + matchItem = String(matchItem); return query && matchItem ? matchItem.replace(new RegExp(escapeRegexp(query), 'gi'), '$&') : matchItem; }; }) -/** - * A read-only equivalent of jQuery's offset function: http://api.jquery.com/offset/ - * - * Taken from AngularUI Bootstrap Position: - * See https://github.com/angular-ui/bootstrap/blob/master/src/position/position.js#L70 - */ + /** + * A read-only equivalent of jQuery's offset function: http://api.jquery.com/offset/ + * + * Taken from AngularUI Bootstrap Position: + * See https://github.com/angular-ui/bootstrap/blob/master/src/position/position.js#L70 + */ .factory('uisOffset', ['$document', '$window', function ($document, $window) { @@ -247,7 +201,6 @@ uis.directive('uiSelectChoices', uis.controller('uiSelectCtrl', ['$scope', '$element', '$timeout', '$filter', '$q', 'uisRepeatParser', 'uiSelectMinErr', 'uiSelectConfig', function ($scope, $element, $timeout, $filter, $q, RepeatParser, uiSelectMinErr, uiSelectConfig) { - var ctrl = this; var EMPTY_SEARCH = ''; @@ -256,23 +209,23 @@ uis.controller('uiSelectCtrl', ctrl.searchEnabled = uiSelectConfig.searchEnabled; ctrl.sortable = uiSelectConfig.sortable; - ctrl.removeSelected = false; // If selected item(s) should be removed from dropdown list - ctrl.closeOnSelect = true; // Initialized inside uiSelect directive link function + ctrl.removeSelected = false; // If selected item(s) should be removed from dropdown list + ctrl.closeOnSelect = true; // Initialized inside uiSelect directive link function ctrl.search = EMPTY_SEARCH; - ctrl.activeIndex = 0; // Dropdown of choices - ctrl.items = []; // All available choices + ctrl.activeIndex = 0; // Dropdown of choices + ctrl.items = []; // All available choices ctrl.open = false; ctrl.focus = false; ctrl.disabled = false; ctrl.selected = undefined; - ctrl.focusser = undefined; // Reference to input element used to handle focus events + ctrl.focusser = undefined; // Reference to input element used to handle focus events ctrl.resetSearchInput = true; - ctrl.multiple = undefined; // Initialized inside uiSelect directive link function - ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelectChoices directive link function - ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelectMatch directive link function + ctrl.multiple = undefined; // Initialized inside uiSelect directive link function + ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelectChoices directive link function + ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelectMatch directive link function ctrl.clickTriggeredSelect = false; ctrl.$filter = $filter; @@ -282,6 +235,158 @@ uis.controller('uiSelectCtrl', ctrl.searchInput.length); } + // TODO: Maybe make these methods in KEY directly in the controller? + ctrl.KEY = { + TAB: 9, + ENTER: 13, + ESC: 27, + SPACE: 32, + LEFT: 37, + UP: 38, + RIGHT: 39, + DOWN: 40, + SHIFT: 16, + CTRL: 17, + ALT: 18, + PAGE_UP: 33, + PAGE_DOWN: 34, + HOME: 36, + END: 35, + BACKSPACE: 8, + DELETE: 46, + COMMAND: 91, + MAP: { + 91: "COMMAND", + 8: "BACKSPACE", + 9: "TAB", + 13: "ENTER", + 16: "SHIFT", + 17: "CTRL", + 18: "ALT", + 19: "PAUSEBREAK", + 20: "CAPSLOCK", + 27: "ESC", + 32: "SPACE", + 33: "PAGE_UP", + 34: "PAGE_DOWN", + 35: "END", + 36: "HOME", + 37: "LEFT", + 38: "UP", + 39: "RIGHT", + 40: "DOWN", + 43: "+", + 44: "PRINTSCREEN", + 45: "INSERT", + 46: "DELETE", + 48: "0", + 49: "1", + 50: "2", + 51: "3", + 52: "4", + 53: "5", + 54: "6", + 55: "7", + 56: "8", + 57: "9", + 59: ";", + 61: "=", + 65: "A", + 66: "B", + 67: "C", + 68: "D", + 69: "E", + 70: "F", + 71: "G", + 72: "H", + 73: "I", + 74: "J", + 75: "K", + 76: "L", + 77: "M", + 78: "N", + 79: "O", + 80: "P", + 81: "Q", + 82: "R", + 83: "S", + 84: "T", + 85: "U", + 86: "V", + 87: "W", + 88: "X", + 89: "Y", + 90: "Z", + 96: "0", + 97: "1", + 98: "2", + 99: "3", + 100: "4", + 101: "5", + 102: "6", + 103: "7", + 104: "8", + 105: "9", + 106: "*", + 107: "+", + 109: "-", + 110: ".", + 111: "/", + 112: "F1", + 113: "F2", + 114: "F3", + 115: "F4", + 116: "F5", + 117: "F6", + 118: "F7", + 119: "F8", + 120: "F9", + 121: "F10", + 122: "F11", + 123: "F12", + 144: "NUMLOCK", + 145: "SCROLLLOCK", + 186: ";", + 187: "=", + 188: ",", + 189: "-", + 190: ".", + 191: "/", + 192: "`", + 219: "[", + 220: "\\", + 221: "]", + 222: "'" + }, + + isControl: function (e) { + var k = e.which; + switch (k) { + case ctrl.KEY.COMMAND: + case ctrl.KEY.SHIFT: + case ctrl.KEY.CTRL: + case ctrl.KEY.ALT: + return true; + } + + if (e.metaKey) { + return true; + } + + return false; + }, + isFunctionKey: function (k) { + k = k.which ? k.which : k; + return k >= 112 && k <= 123; + }, + isVerticalMovement: function (k) { + return ~[ctrl.KEY.UP, ctrl.KEY.DOWN].indexOf(k); + }, + isHorizontalMovement: function (k) { + return ~[ctrl.KEY.LEFT, ctrl.KEY.RIGHT, ctrl.KEY.BACKSPACE, ctrl.KEY.DELETE].indexOf(k); + } + }; + /** * Returns true if the selection is empty * @returns {boolean|*} @@ -322,6 +427,7 @@ uis.controller('uiSelectCtrl', /** * Activates the control. * When the user clicks on ui-select, displays the dropdown list + * Also called following keyboard input to the search box */ ctrl.activate = function (initSearchValue, avoidReset) { if (!ctrl.disabled && !ctrl.open) { @@ -346,22 +452,15 @@ uis.controller('uiSelectCtrl', }); }; - var result = ctrl.onDropdownCallback($scope, {open: true}); - if (angular.isDefined(result)) { - if (angular.isFunction(result.then)) { - // Promise returned - wait for it to complete before completing the selection - result.then(function (result) { - if (!result) { - return; - } + var result = ctrl.beforeDropdownOpen(); + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (result) { + if (result === true) { completeCallback(); - }); - } else if (result === true) { - completeCallback(); - } else if (result) { - completeCallback(); - } - } else { + } + }); + } else if (result === true) { completeCallback(); } } @@ -471,9 +570,10 @@ uis.controller('uiSelectCtrl', var isActive = itemIndex === -1 ? false : itemIndex === ctrl.activeIndex; // If this is active, and we've defined a callback, do it! - if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { - itemScope.$eval(ctrl.onHighlightCallback); - } + // TODO: Needed? +// if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { +// itemScope.$eval(ctrl.onHighlightCallback); +// } return isActive; }; @@ -518,22 +618,11 @@ uis.controller('uiSelectCtrl', return; } - // Create the data used to pass to the callbacks - var locals = {}; - locals[ctrl.parserResult.itemName] = item; - var callbackContext = { - $item: item, - $model: ctrl.parserResult.modelMapper($scope, locals) - }; - - // Local method called when we complete the select - // eg. called after the onselect callback - var completeCallback = function (item) { - callbackContext.$item = item; + function completeCallback() { $scope.$broadcast('uis:select', item); $timeout(function () { - ctrl.onSelectCallback($scope, callbackContext); + ctrl.afterSelect(item); }); if (ctrl.closeOnSelect) { @@ -542,41 +631,31 @@ uis.controller('uiSelectCtrl', if ($event && $event.type === 'click') { ctrl.clickTriggeredSelect = true; } - }; - - // If there's no onBeforeSelect callback, then just call the completeCallback - if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { - completeCallback(item); - return; } - // Call the onBeforeSelect callback + // Call the beforeSelect method // Allowable responses are -: - // falsy: Abort the selection - // promise: Wait for response + // false: Abort the selection // true: Complete selection + // promise: Wait for response // object: Add the returned object - var result = ctrl.onBeforeSelectCallback($scope, callbackContext); - if (angular.isDefined(result)) { - if (angular.isFunction(result.then)) { - // Promise returned - wait for it to complete before completing the selection - result.then(function (response) { - if (!response) { - return; - } - if (response === true) { - completeCallback(item); - } else if (response) { - completeCallback(response); - } - }); - } else if (result === true) { - completeCallback(item); - } else if (result) { - completeCallback(result); - } - } else { + var result = ctrl.beforeSelect(item); + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (response) { + if (!response) { + return; + } + if (response === true) { + completeCallback(item); + } else if (response) { + completeCallback(response); + } + }); + } else if (result === true) { completeCallback(item); + } else if (result) { + completeCallback(result); } }; @@ -601,22 +680,15 @@ uis.controller('uiSelectCtrl', $scope.$broadcast('uis:close', skipFocusser); } - var result = ctrl.onDropdownCallback($scope, {open: false}); - if (angular.isDefined(result)) { - if (angular.isFunction(result.then)) { - // Promise returned - wait for it to complete before completing the selection - result.then(function (result) { - if (!result) { - return; - } + var result = ctrl.beforeDropdownClose(); + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (result) { + if (result === true) { completeCallback(); - }); - } else if (result === true) { - completeCallback(); - } else if (result) { - completeCallback(); - } - } else { + } + }); + } else if (result === true) { completeCallback(); } }; @@ -706,7 +778,7 @@ uis.controller('uiSelectCtrl', function _handleDropDownSelection(key) { var processed = true; switch (key) { - case KEY.DOWN: + case ctrl.KEY.DOWN: if (!ctrl.open && ctrl.multiple) { // In case its the search input in 'multiple' mode ctrl.activate(false, true); @@ -715,7 +787,7 @@ uis.controller('uiSelectCtrl', ctrl.activeIndex++; } break; - case KEY.UP: + case ctrl.KEY.UP: if (!ctrl.open && ctrl.multiple) { ctrl.activate(false, true); } //In case its the search input in 'multiple' mode @@ -723,21 +795,23 @@ uis.controller('uiSelectCtrl', ctrl.activeIndex--; } break; - case KEY.TAB: + case ctrl.KEY.TAB: if (!ctrl.multiple || ctrl.open) { ctrl.select(ctrl.items[ctrl.activeIndex], true); } break; - case KEY.ENTER: + case ctrl.KEY.ENTER: if (ctrl.open) { // Make sure at least one dropdown item is highlighted before adding - ctrl.select(ctrl.items[ctrl.activeIndex]); + if (ctrl.items[ctrl.activeIndex] !== undefined) { + ctrl.select(ctrl.items[ctrl.activeIndex]); + } } else { // In case its the search input in 'multiple' mode ctrl.activate(false, true); } break; - case KEY.ESC: + case ctrl.KEY.ESC: ctrl.close(); break; default: @@ -748,39 +822,42 @@ uis.controller('uiSelectCtrl', // Bind to keyboard shortcuts ctrl.searchInput.on('keydown', function (e) { - var key = e.which; - // if(~[KEY.ESC,KEY.TAB].indexOf(key)){ - // //TODO: SEGURO? - // ctrl.close(); - // } + if (~[ctrl.KEY.ESC, ctrl.KEY.TAB].indexOf(key)) { + // TODO: SEGURO? + ctrl.close(); + } $scope.$apply(function () { _handleDropDownSelection(key); }); - if (KEY.isVerticalMovement(key) && ctrl.items.length > 0) { + if (ctrl.KEY.isVerticalMovement(key) && ctrl.items.length > 0) { _ensureHighlightVisible(); } - if (key === KEY.ENTER || key === KEY.ESC) { + if (key === ctrl.KEY.ENTER || key === ctrl.KEY.ESC) { e.preventDefault(); e.stopPropagation(); } + + // Let the users process the data + // TODO: Is this needed, or just let the user bind to the event themselves! +// ctrl.afterKeypress(e); }); ctrl.searchInput.on('keyup', function (e) { // return early with these keys - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || - KEY.isVerticalMovement(e.which)) { + if (e.which === ctrl.KEY.TAB || ctrl.KEY.isControl(e) || ctrl.KEY.isFunctionKey(e) || + e.which === ctrl.KEY.ESC || + ctrl.KEY.isVerticalMovement(e.which)) { return; } - if (ctrl.onKeypressCallback === undefined) { - return; - } - ctrl.onKeypressCallback($scope, {event: e}); + // Let the users process the data + // TODO: Is this needed, or just let the user bind to the event themselves! + ctrl.afterKeypress(e); }); // See https://github.com/ivaynberg/select2/blob/3.4.6/select2.js#L1431 @@ -817,6 +894,89 @@ uis.controller('uiSelectCtrl', ctrl.searchInput.off('keyup keydown blur paste'); }); + /** + * Keypress callback. Overridable. + * @param event the keypress event + */ + /* jshint unused:false */ + ctrl.afterKeypress = function (event) { + }; + + /** + * Method called before a selection is made. This can be overridden to allow + * the selection to be aborted, or a modified version of the selected item to be + * returned. + * + * Allowable responses are -: + * false: Abort the selection + * true: Complete selection with the selected object + * object: Complete the selection with the returned object + * promise: Wait for response - response from promise is as above + * + * @param item the item that has been selected + * @returns {*} + */ + ctrl.beforeSelect = function (item) { + return true; + }; + + /** + * Method called after a selection is confirmed. This can be overridden to allow + * the application to be notified of a newly selected item. + * No return is required. + * + * @param item the item that has been selected + */ + ctrl.afterSelect = function (item) { + }; + + /** + * Method called before an item is removed from the selected list. This can be overridden + * to allow the removal to be aborted + * + * Allowable responses are -: + * false: Abort the selection + * true: Complete selection with the selected object + * object: Complete the selection with the returned object + * promise: Wait for response - response from promise is as above + * + * @param item the item that has been selected + * @returns {*} + */ + ctrl.beforeRemove = function (item) { + return true; + }; + + /** + * Method called after a item is removed. This can be overridden to allow + * the application to be notified of a removed item. + * No return is required. + * + * @param item the item that has been removed + */ + ctrl.afterRemove = function (item) { + }; + + /** + * Method called before the dropdown is opened. This can be overridden to allow + * the application to process data before the dropdown is displayed. + * The method may return a promise, or true to allow the dropdown, or false to abort. + * @returns {boolean} + */ + ctrl.beforeDropdownOpen = function () { + return true; + }; + + /** + * Method called before the dropdown is closed. This can be overridden to allow + * the application to prevent the dropdown from closing. + * The method may return a promise, or true to allow the dropdown to close, or false to abort. + * @returns {boolean} + */ + ctrl.beforeDropdownClose = function () { + return true; + }; + }]); uis.directive('uiSelect', @@ -863,13 +1023,6 @@ uis.directive('uiSelect', } }(); - $select.onSelectCallback = $parse(attrs.onSelect); - $select.onBeforeSelectCallback = $parse(attrs.onBeforeSelect); - $select.onRemoveCallback = $parse(attrs.onRemove); - $select.onBeforeRemoveCallback = $parse(attrs.onBeforeRemove); - $select.onKeypressCallback = $parse(attrs.onKeypress); - $select.onDropdownCallback = $parse(attrs.onDropdown); - // Limit the number of selections allowed $select.limit = (angular.isDefined(attrs.limit)) ? parseInt(attrs.limit, 10) : undefined; @@ -936,10 +1089,9 @@ uis.directive('uiSelect', // Will lose focus only with certain targets var focusableControls = ['input', 'button', 'textarea']; // To check if target is other ui-select - var targetScope = angular.element(e.target).scope(); + var targetController = angular.element(e.target).controller('uiSelect'); // To check if target is other ui-select - var skipFocusser = targetScope && targetScope.$select && - targetScope.$select !== $select; + var skipFocusser = targetController && targetController !== $select; // Check if target is input, button or textarea if (!skipFocusser) { skipFocusser = ~focusableControls.indexOf(e.target.tagName.toLowerCase()); @@ -1068,7 +1220,8 @@ uis.directive('uiSelect', var offsetDropdown = uisOffset(dropdown); // Determine if the direction of the dropdown needs to be changed. - if (offset.top + offset.height + offsetDropdown.height > $window.pageYOffset + $document[0].documentElement.clientHeight) { + if (offset.top + offset.height + offsetDropdown.height > + $window.pageYOffset + $document[0].documentElement.clientHeight) { element.addClass(directionUpClassName); } @@ -1103,6 +1256,8 @@ uis.directive('uiSelectMatch', ['uiSelectConfig', function (uiSelectConfig) { }, link: function (scope, element, attrs, $select) { $select.lockChoiceExpression = attrs.uiLockChoice; + + // TODO: observe required? attrs.$observe('placeholder', function (placeholder) { $select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder; }); @@ -1112,6 +1267,7 @@ uis.directive('uiSelectMatch', ['uiSelectConfig', function (uiSelectConfig) { (angular.isDefined(allow)) ? (allow === '') ? true : (allow.toLowerCase() === 'true') : false; } + // TODO: observe required? attrs.$observe('allowClear', setAllowClear); setAllowClear(attrs.allowClear); @@ -1157,65 +1313,47 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel * Then calls onRemove to notify the user the item has been removed */ ctrl.removeChoice = function (index) { + // Get the removed choice var removedChoice = $select.selected[index]; - // if the choice is locked, can't remove it + // If the choice is locked, can't remove it if (removedChoice._uiSelectChoiceLocked) { return; } - var locals = {}; - locals[$select.parserResult.itemName] = removedChoice; - - $select.selected.splice(index, 1); - ctrl.activeMatchIndex = -1; - $select.sizeSearchInput(); - - var callbackContext = { - $item: removedChoice, - $model: $select.parserResult.modelMapper($scope, locals) - }; - // Give some time for scope propagation. function completeCallback() { + $select.selected.splice(index, 1); + ctrl.activeMatchIndex = -1; + $select.sizeSearchInput(); + $timeout(function () { - $select.onRemoveCallback($scope, callbackContext); + $select.afterRemove(removedChoice); }); ctrl.updateModel(); } - // If there's no onBeforeRemove callback, then just call the completeCallback - if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { - completeCallback(); - return; - } - - // Call the onBeforeRemove callback + // Call the beforeRemove callback // Allowable responses are -: - // falsy: Abort the removal - // promise: Wait for response + // false: Abort the removal // true: Complete removal - var result = ctrl.onBeforeRemoveCallback($scope, callbackContext); - if (angular.isDefined(result)) { - if (angular.isFunction(result.then)) { - // Promise returned - wait for it to complete before completing the selection - result.then(function (result) { - if (!result) { - return; - } - completeCallback(result); - }); - } else if (result === true) { - completeCallback(); - } - } else { + // promise: Wait for response + var result = $select.beforeRemove(removedChoice); + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (result) { + if (result === true) { + completeCallback(); + } + }); + } else if (result === true) { completeCallback(); } }; ctrl.getPlaceholder = function () { - //Refactor single? + // Refactor single? if ($select.selected && $select.selected.length) { return; } @@ -1343,17 +1481,18 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel var key = e.which; scope.$apply(function () { var processed = false; - if (KEY.isHorizontalMovement(key)) { + if ($select.KEY.isHorizontalMovement(key)) { processed = _handleMatchSelection(key); } - if (processed && key != KEY.TAB) { - //TODO Check si el tab selecciona aun correctamente - //Crear test + if (processed && key != $select.KEY.TAB) { + // TODO Check si el tab selecciona aun correctamente + //Creat test // e.preventDefault(); // e.stopPropagation(); } }); }); + function _getCaretPosition(el) { if (angular.isNumber(el.selectionStart)) { return el.selectionStart; @@ -1375,7 +1514,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel prev = $selectMultiple.activeMatchIndex - 1, newIndex = curr; - if (caretPosition > 0 || ($select.search.length && key == KEY.RIGHT)) { + if (caretPosition > 0 || ($select.search.length && key == $select.KEY.RIGHT)) { return false; } @@ -1383,7 +1522,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel function getNewActiveMatchIndex() { switch (key) { - case KEY.LEFT: + case $select.KEY.LEFT: // Select previous/first item if (~$selectMultiple.activeMatchIndex) { return prev; @@ -1393,7 +1532,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel return last; } break; - case KEY.RIGHT: + case $select.KEY.RIGHT: // Open drop-down if (!~$selectMultiple.activeMatchIndex || curr === last) { $select.activate(); @@ -1404,7 +1543,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel return next; } break; - case KEY.BACKSPACE: + case $select.KEY.BACKSPACE: // Remove selected item and select previous/first if (~$selectMultiple.activeMatchIndex) { $selectMultiple.removeChoice(curr); @@ -1415,7 +1554,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel return last; } break; - case KEY.DELETE: + case $select.KEY.DELETE: // Remove selected item and select next item if (~$selectMultiple.activeMatchIndex) { $selectMultiple.removeChoice($selectMultiple.activeMatchIndex); @@ -1539,7 +1678,7 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co }); focusser.bind("keydown", function (e) { - if (e.which === KEY.BACKSPACE) { + if (e.which === $select.KEY.BACKSPACE) { e.preventDefault(); e.stopPropagation(); $select.select(undefined); @@ -1547,11 +1686,11 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co return; } - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) { + if (e.which === $select.KEY.TAB || $select.KEY.isControl(e) || $select.KEY.isFunctionKey(e) || e.which === $select.KEY.ESC) { return; } - if (e.which == KEY.DOWN || e.which == KEY.UP || e.which == KEY.ENTER || e.which == KEY.SPACE) { + if (e.which == $select.KEY.DOWN || e.which == $select.KEY.UP || e.which == $select.KEY.ENTER || e.which == $select.KEY.SPACE) { e.preventDefault(); e.stopPropagation(); $select.activate(); @@ -1561,8 +1700,8 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co }); focusser.bind("keyup input", function (e) { - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || - e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { + if (e.which === $select.KEY.TAB || $select.KEY.isControl(e) || $select.KEY.isFunctionKey(e) || e.which === $select.KEY.ESC || + e.which == $select.KEY.ENTER || e.which === $select.KEY.BACKSPACE) { return; } diff --git a/dist/select.no-tpl.min.js b/dist/select.no-tpl.min.js index 619fcd138..84a0d2d92 100644 --- a/dist/select.no-tpl.min.js +++ b/dist/select.no-tpl.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-06T13:28:34.948Z + * Version: 0.12.1 - 2015-08-09T18:09:19.159Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,isControl:function(t){var n=t.which;switch(n){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,n=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,r,i){i(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var r=n[0].getBoundingClientRect();return{width:r.width||n.prop("offsetWidth"),height:r.height||n.prop("offsetHeight"),top:r.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:r.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);n.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,r){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,i){if(!i.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,i,c,l,o){var a=c.groupBy,s=c.groupFilter;if(l.parseRepeatAttr(c.repeat,a,s),l.disableChoiceExpression=c.uiDisableChoice,l.onHighlightCallback=c.onHighlight,a){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=i.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(l.parserResult.itemName,"$select.items",l.parserResult.trackByExp,a)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+l.parserResult.itemName+")").attr("ng-click","$select.select("+l.parserResult.itemName+",false,$event)");var f=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==f.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",f.length);f.attr("uis-transclude-append",""),r(i,o)(e),e.$watch("$select.search",function(e){e&&!l.open&&l.multiple&&l.activate(!1,!0),l.activeIndex=0})}}}}]),n.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,n,r,i,c,l,o,a){function s(){(d.resetSearchInput||void 0===d.resetSearchInput&&a.resetSearchInput)&&(d.search=h,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function u(e,t){var n,r,i=[];for(n=0;n0&&d.activeIndex--;break;case e.TAB:(!d.multiple||d.open)&&d.select(d.items[d.activeIndex],!0);break;case e.ENTER:d.open?d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case e.ESC:d.close();break;default:n=!1}return n}function f(){var e=n.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw o("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(d.activeIndex<0)){var r=t[d.activeIndex],i=r.offsetTop+r.clientHeight-e[0].scrollTop,c=e[0].offsetHeight;i>c?e[0].scrollTop+=i-c:i=d.items.length?0:d.activeIndex,r(function(){d.search=e||d.search,d.searchInput[0].focus()})},c=d.onDropdownCallback(t,{open:!0});angular.isDefined(c)?angular.isFunction(c.then)?c.then(function(e){e&&i()}):c===!0?i():c&&i():i()}},d.parseRepeatAttr=function(e,n,r){function i(e){var i=t.$eval(n);if(d.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(i)?i(e):e[i],n=d.findGroupByName(t);n?n.items.push(e):d.groups.push({name:t,items:[e]})}),r){var c=t.$eval(r);angular.isFunction(c)?d.groups=c(d.groups):angular.isArray(c)&&(d.groups=u(d.groups,c))}d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function c(e){d.items=e}d.setItemsFn=n?i:c,d.parserResult=l.parse(e),d.isGrouped=!!n,d.itemProperty=d.parserResult.itemName,d.refreshItems=function(e){e=e||d.parserResult.source(t);var n=d.selected;if(d.isEmpty()||angular.isArray(n)&&!n.length||!d.removeSelected)d.setItemsFn(e);else if(void 0!==e){var r=e.filter(function(e){return n.indexOf(e)<0});d.setItemsFn(r)}},t.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw o("items","Expected an array but got '{0}'.",e);d.refreshItems(e),d.ngModel.$modelValue=null}})},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){if(!d.open)return!1;var t=d.items.indexOf(e[d.itemProperty]),n=-1===t?!1:t===d.activeIndex;return n&&!angular.isUndefined(d.onHighlightCallback)&&e.$eval(d.onHighlightCallback),n},d.isDisabled=function(e){if(!d.open)return!1;var t,n=d.items.indexOf(e[d.itemProperty]),r=!1;return n>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[n],r=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=r),r},d.select=function(e,n,i){if((void 0===e||!e._uiSelectChoiceDisabled)&&(d.items||d.search)){var c={};c[d.parserResult.itemName]=e;var l={$item:e,$model:d.parserResult.modelMapper(t,c)},o=function(e){l.$item=e,t.$broadcast("uis:select",e),r(function(){d.onSelectCallback(t,l)}),d.closeOnSelect&&d.close(n),i&&"click"===i.type&&(d.clickTriggeredSelect=!0)};if(!angular.isDefined(d.onBeforeRemoveCallback))return o(e),void 0;var a=d.onBeforeSelectCallback(t,l);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(t){t&&(t===!0?o(e):t&&o(t))}):a===!0?o(e):a&&o(a):o(e)}},d.close=function(e){function n(){d.ngModel&&d.ngModel.$setTouched&&d.ngModel.$setTouched(),s(),d.open=!1,d.searchEnabled||angular.element(d.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e)}if(d.open){var r=d.onDropdownCallback(t,{open:!1});angular.isDefined(r)?angular.isFunction(r.then)?r.then(function(e){e&&n()}):r===!0?n():r&&n():n()}},d.setFocus=function(){d.focus||d.focusInput[0].focus()},d.clear=function(e){d.select(void 0),e.stopPropagation(),r(function(){d.focusser[0].focus()},0,!1)},d.toggle=function(e){d.open?(d.close(),e.preventDefault(),e.stopPropagation()):d.activate()},d.isLocked=function(e,t){var n,r=d.selected[t];return r&&!angular.isUndefined(d.lockChoiceExpression)&&(n=!!e.$eval(d.lockChoiceExpression),r._uiSelectChoiceLocked=n),n};var v=null;d.sizeSearchInput=function(){var e=d.searchInput[0],n=d.searchInput.parent().parent()[0],i=function(){return n.clientWidth*!!e.offsetParent},c=function(t){if(0===t)return!1;var n=t-e.offsetLeft-d.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=t),d.searchInput.css("width",n+"px"),!0};d.searchInput.css("width","10px"),r(function(){null!==v||c(i())||(v=t.$watch(i,function(e){c(e)&&(v(),v=null)}))})},d.searchInput.on("keydown",function(n){var r=n.which;t.$apply(function(){p(r)}),e.isVerticalMovement(r)&&d.items.length>0&&f(),(r===e.ENTER||r===e.ESC)&&(n.preventDefault(),n.stopPropagation())}),d.searchInput.on("keyup",function(n){n.which===e.TAB||e.isControl(n)||e.isFunctionKey(n)||n.which===e.ESC||e.isVerticalMovement(n.which)||void 0!==d.onKeypressCallback&&d.onKeypressCallback(t,{event:n})}),t.$on("$destroy",function(){d.searchInput.off("keyup keydown blur paste")})}]),n.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,r,i,c,l,o){return{restrict:"EA",templateUrl:function(e,t){var r=t.theme||n.theme;return r+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(c,a){return angular.isDefined(a.multiple)?c.append("").removeAttr("multiple"):c.append(""),function(c,a,s,u,p){function f(e){if(v.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(a[0],e.target):a[0].contains(e.target),!t&&!v.clickTriggeredSelect){var n=["input","button","textarea"],r=angular.element(e.target).scope(),i=r&&r.$select&&r.$select!==v;i||(i=~n.indexOf(e.target.tagName.toLowerCase())),v.close(i),c.$digest()}v.clickTriggeredSelect=!1}}function d(){var t=i(a);E=angular.element('
    '),E[0].style.width=t.width+"px",E[0].style.height=t.height+"px",a.after(E),w=a[0].style.width,e.find("body").append(a),a[0].style.position="absolute",a[0].style.left=t.left+"px",a[0].style.top=t.top+"px",a[0].style.width=t.width+"px"}function h(){null!==E&&(E.replaceWith(a),E=null,a[0].style.position="",a[0].style.left="",a[0].style.top="",a[0].style.width=w)}var v=u[0],m=u[1];v.generatedId=n.generateId(),v.baseTitle=s.title||"Select box",v.focusserTitle=v.baseTitle+" focus",v.focusserId="focusser-"+v.generatedId,v.closeOnSelect=function(){return angular.isDefined(s.closeOnSelect)?l(s.closeOnSelect)():n.closeOnSelect}(),v.onSelectCallback=l(s.onSelect),v.onBeforeSelectCallback=l(s.onBeforeSelect),v.onRemoveCallback=l(s.onRemove),v.onBeforeRemoveCallback=l(s.onBeforeRemove),v.onKeypressCallback=l(s.onKeypress),v.onDropdownCallback=l(s.onDropdown),v.limit=angular.isDefined(s.limit)?parseInt(s.limit,10):void 0,v.ngModel=m,v.choiceGrouped=function(e){return v.isGrouped&&e&&e.name},s.tabindex&&s.$observe("tabindex",function(e){v.focusInput.attr("tabindex",e),a.removeAttr("tabindex")});var g=c.$eval(s.searchEnabled);v.searchEnabled=void 0!==g?g:n.searchEnabled;var $=c.$eval(s.sortable);v.sortable=void 0!==$?$:n.sortable,s.$observe("disabled",function(){v.disabled=void 0!==s.disabled?s.disabled:!1}),angular.isDefined(s.autofocus)&&o(function(){v.setFocus()}),angular.isDefined(s.focusOn)&&c.$on(s.focusOn,function(){o(function(){v.setFocus()})}),e.on("click",f),c.$on("$destroy",function(){e.off("click",f)}),p(c,function(e){var t=angular.element("
    ").append(e),n=t.querySelectorAll(".ui-select-match");if(n.removeAttr("ui-select-match"),n.removeAttr("data-ui-select-match"),1!==n.length)throw r("transcluded","Expected 1 .ui-select-match but got '{0}'.",n.length);a.querySelectorAll(".ui-select-match").replaceWith(n);var i=t.querySelectorAll(".ui-select-choices");if(i.removeAttr("ui-select-choices"),i.removeAttr("data-ui-select-choices"),1!==i.length)throw r("transcluded","Expected 1 .ui-select-choices but got '{0}'.",i.length);a.querySelectorAll(".ui-select-choices").replaceWith(i)});var b=c.$eval(s.appendToBody);(void 0!==b?b:n.appendToBody)&&(c.$watch("$select.open",function(e){e?d():h()}),c.$on("$destroy",function(){h()}));var E=null,w="",S=null,y="direction-up";c.$watch("$select.open",function(n){if(n){if(S=angular.element(a).querySelectorAll(".ui-select-dropdown"),null===S)return;S[0].style.opacity=0,o(function(){var n=i(a),r=i(S);n.top+n.height+r.height>t.pageYOffset+e[0].documentElement.clientHeight&&a.addClass(y),S[0].style.opacity=1})}else{if(null===S)return;a.removeClass(y)}})}}}}]),n.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,r=t.parent().attr("multiple");return n+(r?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,r,i){function c(e){i.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}i.lockChoiceExpression=r.uiLockChoice,r.$observe("placeholder",function(t){i.placeholder=void 0!==t?t:e.placeholder}),r.$observe("allowClear",c),c(r.allowClear),i.multiple&&i.sizeSearchInput()}}}]),n.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,r=this,i=e.$select;e.$evalAsync(function(){n=e.ngModel}),r.activeMatchIndex=-1,r.updateModel=function(){n.$setViewValue(Date.now()),r.refreshComponent()},r.refreshComponent=function(){i.refreshItems(),i.sizeSearchInput()},r.removeChoice=function(n){function c(){t(function(){i.onRemoveCallback(e,a)}),r.updateModel()}var l=i.selected[n];if(!l._uiSelectChoiceLocked){var o={};o[i.parserResult.itemName]=l,i.selected.splice(n,1),r.activeMatchIndex=-1,i.sizeSearchInput();var a={$item:l,$model:i.parserResult.modelMapper(e,o)};if(!angular.isDefined(r.onBeforeRemoveCallback))return c(),void 0;var s=r.onBeforeRemoveCallback(e,a);angular.isDefined(s)?angular.isFunction(s.then)?s.then(function(e){e&&c(e)}):s===!0&&c():c()}},r.getPlaceholder=function(){return i.selected&&i.selected.length?void 0:i.placeholder}}],controllerAs:"$selectMultiple",link:function(r,i,c,l){function o(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(t){function n(){switch(t){case e.LEFT:return~p.activeMatchIndex?f:l;case e.RIGHT:return~p.activeMatchIndex&&a!==l?u:(s.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(a),f):l;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),a):!1}}var r=o(s.searchInput[0]),i=s.selected.length,c=0,l=i-1,a=p.activeMatchIndex,u=p.activeMatchIndex+1,f=p.activeMatchIndex-1,d=a;return r>0||s.search.length&&t==e.RIGHT?!1:(s.close(),d=n(),p.activeMatchIndex=s.selected.length&&d!==!1?Math.min(l,Math.max(c,d)):-1,!0)}var s=l[0],u=r.ngModel=l[1],p=r.$selectMultiple;s.multiple=!0,s.removeSelected=!0,s.focusInput=s.searchInput,u.$parsers.unshift(function(){for(var e,t={},n=[],i=s.selected.length-1;i>=0;i--)t={},t[s.parserResult.itemName]=s.selected[i],e=s.parserResult.modelMapper(r,t),n.unshift(e);return n}),u.$formatters.unshift(function(e){var t,n=s.parserResult.source(r,{$select:{search:""}}),i={};if(!n)return e;var c=[],l=function(e,n){if(e&&e.length){for(var l=e.length-1;l>=0;l--){if(i[s.parserResult.itemName]=e[l],t=s.parserResult.modelMapper(r,i),s.parserResult.trackByExp){var o=/\.(.+)/.exec(s.parserResult.trackByExp);if(o.length>0&&t[o[1]]==n[o[1]])return c.unshift(e[l]),!0}if(angular.equals(t,n))return c.unshift(e[l]),!0}return!1}};if(!e)return c;for(var o=e.length-1;o>=0;o--)l(s.selected,e[o])||l(n,e[o])||c.unshift(e[o]);return c}),r.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);s.selected=[]}s.selected=u.$viewValue,r.$evalAsync()},r.$on("uis:select",function(e,t){s.selected.length>=s.limit||(s.selected.push(t),p.updateModel())}),r.$on("uis:activate",function(){p.activeMatchIndex=-1}),r.$watch("$select.disabled",function(e,t){t&&!e&&s.sizeSearchInput()}),s.searchInput.on("keydown",function(t){var n=t.which;r.$apply(function(){var t=!1;e.isHorizontalMovement(n)&&(t=a(n)),t&&n!=e.TAB})}),s.searchInput.on("blur",function(){n(function(){p.activeMatchIndex=-1})})}}}]),n.directive("uiSelectSingle",["$timeout","$compile",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(r,i,c,l){var o=l[0],a=l[1];a.$parsers.unshift(function(e){var t,n={};return n[o.parserResult.itemName]=e,t=o.parserResult.modelMapper(r,n)}),a.$formatters.unshift(function(e){var t,n=o.parserResult.source(r,{$select:{search:""}}),i={};if(n){var c=function(n){return i[o.parserResult.itemName]=n,t=o.parserResult.modelMapper(r,i),t==e};if(o.selected&&c(o.selected))return o.selected;for(var l=n.length-1;l>=0;l--)if(c(n[l]))return n[l]}return e}),r.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){o.selected=a.$viewValue},r.$on("uis:select",function(e,t){o.selected=t}),r.$on("uis:close",function(e,n){t(function(){o.focusser.prop("disabled",!1),n||o.focusser[0].focus()},0,!1)}),r.$on("uis:activate",function(){s.prop("disabled",!0)});var s=angular.element("");n(s)(r),o.focusser=s,o.focusInput=s,i.parent().append(s),s.bind("focus",function(){r.$evalAsync(function(){o.focus=!0})}),s.bind("blur",function(){r.$evalAsync(function(){o.focus=!1})}),s.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),o.select(void 0),r.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),o.activate()),r.$digest()),void 0)}),s.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(o.activate(s.val()),s.val(""),r.$digest())})}}}]),n.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var r=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!r)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:r[2],source:t(r[3]),trackByExp:r[4],modelMapper:t(r[1]||r[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,r){var i=e+" in "+(r?"$group.items":t);return n&&(i+=" track by "+n),i}}])}(); \ No newline at end of file +!function(){"use strict";void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var e=0,t=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return e++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,r,i){i(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return t=String(t),n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var r=n[0].getBoundingClientRect();return{width:r.width||n.prop("offsetWidth"),height:r.height||n.prop("offsetHeight"),top:r.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:r.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);t.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,r){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,i){if(!i.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,i,c,o,l){var s=c.groupBy,a=c.groupFilter;if(o.parseRepeatAttr(c.repeat,s,a),o.disableChoiceExpression=c.uiDisableChoice,o.onHighlightCallback=c.onHighlight,s){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=i.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(o.parserResult.itemName,"$select.items",o.parserResult.trackByExp,s)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+o.parserResult.itemName+")").attr("ng-click","$select.select("+o.parserResult.itemName+",false,$event)");var f=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==f.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",f.length);f.attr("uis-transclude-append",""),r(i,l)(e),e.$watch("$select.search",function(e){e&&!o.open&&o.multiple&&o.activate(!1,!0),o.activeIndex=0})}}}}]),t.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(e,t,n,r,i,c,o,l){function s(){(f.resetSearchInput||void 0===f.resetSearchInput&&l.resetSearchInput)&&(f.search=d,f.selected&&f.items.length&&!f.multiple&&(f.activeIndex=f.items.indexOf(f.selected)))}function a(e,t){var n,r,i=[];for(n=0;n0&&f.activeIndex--;break;case f.KEY.TAB:(!f.multiple||f.open)&&f.select(f.items[f.activeIndex],!0);break;case f.KEY.ENTER:f.open?void 0!==f.items[f.activeIndex]&&f.select(f.items[f.activeIndex]):f.activate(!1,!0);break;case f.KEY.ESC:f.close();break;default:t=!1}return t}function p(){var e=t.querySelectorAll(".ui-select-choices-content"),n=e.querySelectorAll(".ui-select-choices-row");if(n.length<1)throw o("choices","Expected multiple .ui-select-choices-row but got '{0}'.",n.length);if(!(f.activeIndex<0)){var r=n[f.activeIndex],i=r.offsetTop+r.clientHeight-e[0].scrollTop,c=e[0].offsetHeight;i>c?e[0].scrollTop+=i-c:i=112&&123>=e},isVerticalMovement:function(e){return~[f.KEY.UP,f.KEY.DOWN].indexOf(e)},isHorizontalMovement:function(e){return~[f.KEY.LEFT,f.KEY.RIGHT,f.KEY.BACKSPACE,f.KEY.DELETE].indexOf(e)}},f.isEmpty=function(){return angular.isUndefined(f.selected)||null===f.selected||""===f.selected},f.findGroupByName=function(e){return f.groups&&f.groups.filter(function(t){return t.name===e})[0]},f.activate=function(t,r){if(f.disabled||f.open)f.open&&!f.searchEnabled&&f.close();else{var i=function(){r||s(),e.$broadcast("uis:activate"),f.open=!0,f.searchEnabled||angular.element(f.searchInput[0]).addClass("ui-select-offscreen"),f.activeIndex=f.activeIndex>=f.items.length?0:f.activeIndex,n(function(){f.search=t||f.search,f.searchInput[0].focus()})},c=f.beforeDropdownOpen();angular.isFunction(c.then)?c.then(function(e){e===!0&&i()}):c===!0&&i()}},f.parseRepeatAttr=function(t,n,r){function i(t){var i=e.$eval(n);if(f.groups=[],angular.forEach(t,function(e){var t=angular.isFunction(i)?i(e):e[i],n=f.findGroupByName(t);n?n.items.push(e):f.groups.push({name:t,items:[e]})}),r){var c=e.$eval(r);angular.isFunction(c)?f.groups=c(f.groups):angular.isArray(c)&&(f.groups=a(f.groups,c))}f.items=[],f.groups.forEach(function(e){f.items=f.items.concat(e.items)})}function l(e){f.items=e}f.setItemsFn=n?i:l,f.parserResult=c.parse(t),f.isGrouped=!!n,f.itemProperty=f.parserResult.itemName,f.refreshItems=function(t){t=t||f.parserResult.source(e);var n=f.selected;if(f.isEmpty()||angular.isArray(n)&&!n.length||!f.removeSelected)f.setItemsFn(t);else if(void 0!==t){var r=t.filter(function(e){return n.indexOf(e)<0});f.setItemsFn(r)}},e.$watchCollection(f.parserResult.source,function(e){if(void 0===e||null===e)f.items=[];else{if(!angular.isArray(e))throw o("items","Expected an array but got '{0}'.",e);f.refreshItems(e),f.ngModel.$modelValue=null}})},f.setActiveItem=function(e){f.activeIndex=f.items.indexOf(e)},f.isActive=function(e){if(!f.open)return!1;var t=f.items.indexOf(e[f.itemProperty]),n=-1===t?!1:t===f.activeIndex;return n},f.isDisabled=function(e){if(!f.open)return!1;var t,n=f.items.indexOf(e[f.itemProperty]),r=!1;return n>=0&&!angular.isUndefined(f.disableChoiceExpression)&&(t=f.items[n],r=!!e.$eval(f.disableChoiceExpression),t._uiSelectChoiceDisabled=r),r},f.select=function(t,r,i){function c(){e.$broadcast("uis:select",t),n(function(){f.afterSelect(t)}),f.closeOnSelect&&f.close(r),i&&"click"===i.type&&(f.clickTriggeredSelect=!0)}if((void 0===t||!t._uiSelectChoiceDisabled)&&(f.items||f.search)){var o=f.beforeSelect(t);angular.isFunction(o.then)?o.then(function(e){e&&(e===!0?c(t):e&&c(e))}):o===!0?c(t):o&&c(o)}},f.close=function(t){function n(){f.ngModel&&f.ngModel.$setTouched&&f.ngModel.$setTouched(),s(),f.open=!1,f.searchEnabled||angular.element(f.searchInput[0]).removeClass("ui-select-offscreen"),e.$broadcast("uis:close",t)}if(f.open){var r=f.beforeDropdownClose();angular.isFunction(r.then)?r.then(function(e){e===!0&&n()}):r===!0&&n()}},f.setFocus=function(){f.focus||f.focusInput[0].focus()},f.clear=function(e){f.select(void 0),e.stopPropagation(),n(function(){f.focusser[0].focus()},0,!1)},f.toggle=function(e){f.open?(f.close(),e.preventDefault(),e.stopPropagation()):f.activate()},f.isLocked=function(e,t){var n,r=f.selected[t];return r&&!angular.isUndefined(f.lockChoiceExpression)&&(n=!!e.$eval(f.lockChoiceExpression),r._uiSelectChoiceLocked=n),n};var h=null;f.sizeSearchInput=function(){var t=f.searchInput[0],r=f.searchInput.parent().parent()[0],i=function(){return r.clientWidth*!!t.offsetParent},c=function(e){if(0===e)return!1;var n=e-t.offsetLeft-f.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=e),f.searchInput.css("width",n+"px"),!0};f.searchInput.css("width","10px"),n(function(){null!==h||c(i())||(h=e.$watch(i,function(e){c(e)&&(h(),h=null)}))})},f.searchInput.on("keydown",function(t){var n=t.which;~[f.KEY.ESC,f.KEY.TAB].indexOf(n)&&f.close(),e.$apply(function(){u(n)}),f.KEY.isVerticalMovement(n)&&f.items.length>0&&p(),(n===f.KEY.ENTER||n===f.KEY.ESC)&&(t.preventDefault(),t.stopPropagation())}),f.searchInput.on("keyup",function(e){e.which===f.KEY.TAB||f.KEY.isControl(e)||f.KEY.isFunctionKey(e)||e.which===f.KEY.ESC||f.KEY.isVerticalMovement(e.which)||f.afterKeypress(e)}),e.$on("$destroy",function(){f.searchInput.off("keyup keydown blur paste")}),f.afterKeypress=function(){},f.beforeSelect=function(){return!0},f.afterSelect=function(){},f.beforeRemove=function(){return!0},f.afterRemove=function(){},f.beforeDropdownOpen=function(){return!0},f.beforeDropdownClose=function(){return!0}}]),t.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,r,i,c,o,l){return{restrict:"EA",templateUrl:function(e,t){var r=t.theme||n.theme;return r+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(c,s){return angular.isDefined(s.multiple)?c.append("").removeAttr("multiple"):c.append(""),function(c,s,a,u,p){function f(e){if(v.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(s[0],e.target):s[0].contains(e.target),!t&&!v.clickTriggeredSelect){var n=["input","button","textarea"],r=angular.element(e.target).controller("uiSelect"),i=r&&r!==v;i||(i=~n.indexOf(e.target.tagName.toLowerCase())),v.close(i),c.$digest()}v.clickTriggeredSelect=!1}}function d(){var t=i(s);S=angular.element('
    '),S[0].style.width=t.width+"px",S[0].style.height=t.height+"px",s.after(S),w=s[0].style.width,e.find("body").append(s),s[0].style.position="absolute",s[0].style.left=t.left+"px",s[0].style.top=t.top+"px",s[0].style.width=t.width+"px"}function h(){null!==S&&(S.replaceWith(s),S=null,s[0].style.position="",s[0].style.left="",s[0].style.top="",s[0].style.width=w)}var v=u[0],g=u[1];v.generatedId=n.generateId(),v.baseTitle=a.title||"Select box",v.focusserTitle=v.baseTitle+" focus",v.focusserId="focusser-"+v.generatedId,v.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?o(a.closeOnSelect)():n.closeOnSelect}(),v.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,v.ngModel=g,v.choiceGrouped=function(e){return v.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){v.focusInput.attr("tabindex",e),s.removeAttr("tabindex")});var m=c.$eval(a.searchEnabled);v.searchEnabled=void 0!==m?m:n.searchEnabled;var E=c.$eval(a.sortable);v.sortable=void 0!==E?E:n.sortable,a.$observe("disabled",function(){v.disabled=void 0!==a.disabled?a.disabled:!1}),angular.isDefined(a.autofocus)&&l(function(){v.setFocus()}),angular.isDefined(a.focusOn)&&c.$on(a.focusOn,function(){l(function(){v.setFocus()})}),e.on("click",f),c.$on("$destroy",function(){e.off("click",f)}),p(c,function(e){var t=angular.element("
    ").append(e),n=t.querySelectorAll(".ui-select-match");if(n.removeAttr("ui-select-match"),n.removeAttr("data-ui-select-match"),1!==n.length)throw r("transcluded","Expected 1 .ui-select-match but got '{0}'.",n.length);s.querySelectorAll(".ui-select-match").replaceWith(n);var i=t.querySelectorAll(".ui-select-choices");if(i.removeAttr("ui-select-choices"),i.removeAttr("data-ui-select-choices"),1!==i.length)throw r("transcluded","Expected 1 .ui-select-choices but got '{0}'.",i.length);s.querySelectorAll(".ui-select-choices").replaceWith(i)});var $=c.$eval(a.appendToBody);(void 0!==$?$:n.appendToBody)&&(c.$watch("$select.open",function(e){e?d():h()}),c.$on("$destroy",function(){h()}));var S=null,w="",b=null,I="direction-up";c.$watch("$select.open",function(n){if(n){if(b=angular.element(s).querySelectorAll(".ui-select-dropdown"),null===b)return;b[0].style.opacity=0,l(function(){var n=i(s),r=i(b);n.top+n.height+r.height>t.pageYOffset+e[0].documentElement.clientHeight&&s.addClass(I),b[0].style.opacity=1})}else{if(null===b)return;s.removeClass(I)}})}}}}]),t.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,r=t.parent().attr("multiple");return n+(r?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,r,i){function c(e){i.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}i.lockChoiceExpression=r.uiLockChoice,r.$observe("placeholder",function(t){i.placeholder=void 0!==t?t:e.placeholder}),r.$observe("allowClear",c),c(r.allowClear),i.multiple&&i.sizeSearchInput()}}}]),t.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,r=this,i=e.$select;e.$evalAsync(function(){n=e.ngModel}),r.activeMatchIndex=-1,r.updateModel=function(){n.$setViewValue(Date.now()),r.refreshComponent()},r.refreshComponent=function(){i.refreshItems(),i.sizeSearchInput()},r.removeChoice=function(e){function n(){i.selected.splice(e,1),r.activeMatchIndex=-1,i.sizeSearchInput(),t(function(){i.afterRemove(c)}),r.updateModel()}var c=i.selected[e];if(!c._uiSelectChoiceLocked){var o=i.beforeRemove(c);angular.isFunction(o.then)?o.then(function(e){e===!0&&n()}):o===!0&&n()}},r.getPlaceholder=function(){return i.selected&&i.selected.length?void 0:i.placeholder}}],controllerAs:"$selectMultiple",link:function(n,r,i,c){function o(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function l(e){function t(){switch(e){case s.KEY.LEFT:return~u.activeMatchIndex?p:c;case s.KEY.RIGHT:return~u.activeMatchIndex&&l!==c?a:(s.activate(),!1);case s.KEY.BACKSPACE:return~u.activeMatchIndex?(u.removeChoice(l),p):c;case s.KEY.DELETE:return~u.activeMatchIndex?(u.removeChoice(u.activeMatchIndex),l):!1}}var n=o(s.searchInput[0]),r=s.selected.length,i=0,c=r-1,l=u.activeMatchIndex,a=u.activeMatchIndex+1,p=u.activeMatchIndex-1,f=l;return n>0||s.search.length&&e==s.KEY.RIGHT?!1:(s.close(),f=t(),u.activeMatchIndex=s.selected.length&&f!==!1?Math.min(c,Math.max(i,f)):-1,!0)}var s=c[0],a=n.ngModel=c[1],u=n.$selectMultiple;s.multiple=!0,s.removeSelected=!0,s.focusInput=s.searchInput,a.$parsers.unshift(function(){for(var e,t={},r=[],i=s.selected.length-1;i>=0;i--)t={},t[s.parserResult.itemName]=s.selected[i],e=s.parserResult.modelMapper(n,t),r.unshift(e);return r}),a.$formatters.unshift(function(e){var t,r=s.parserResult.source(n,{$select:{search:""}}),i={};if(!r)return e;var c=[],o=function(e,r){if(e&&e.length){for(var o=e.length-1;o>=0;o--){if(i[s.parserResult.itemName]=e[o],t=s.parserResult.modelMapper(n,i),s.parserResult.trackByExp){var l=/\.(.+)/.exec(s.parserResult.trackByExp);if(l.length>0&&t[l[1]]==r[l[1]])return c.unshift(e[o]),!0}if(angular.equals(t,r))return c.unshift(e[o]),!0}return!1}};if(!e)return c;for(var l=e.length-1;l>=0;l--)o(s.selected,e[l])||o(r,e[l])||c.unshift(e[l]);return c}),n.$watchCollection(function(){return a.$modelValue},function(e,t){t!=e&&(a.$modelValue=null,u.refreshComponent())}),a.$render=function(){if(!angular.isArray(a.$viewValue)){if(!angular.isUndefined(a.$viewValue)&&null!==a.$viewValue)throw e("multiarr","Expected model value to be array but got '{0}'",a.$viewValue);s.selected=[]}s.selected=a.$viewValue,n.$evalAsync()},n.$on("uis:select",function(e,t){s.selected.length>=s.limit||(s.selected.push(t),u.updateModel())}),n.$on("uis:activate",function(){u.activeMatchIndex=-1}),n.$watch("$select.disabled",function(e,t){t&&!e&&s.sizeSearchInput()}),s.searchInput.on("keydown",function(e){var t=e.which;n.$apply(function(){var e=!1;s.KEY.isHorizontalMovement(t)&&(e=l(t)),e&&t!=s.KEY.TAB})}),s.searchInput.on("blur",function(){t(function(){u.activeMatchIndex=-1})})}}}]),t.directive("uiSelectSingle",["$timeout","$compile",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(n,r,i,c){var o=c[0],l=c[1];l.$parsers.unshift(function(e){var t,r={};return r[o.parserResult.itemName]=e,t=o.parserResult.modelMapper(n,r)}),l.$formatters.unshift(function(e){var t,r=o.parserResult.source(n,{$select:{search:""}}),i={};if(r){var c=function(r){return i[o.parserResult.itemName]=r,t=o.parserResult.modelMapper(n,i),t==e};if(o.selected&&c(o.selected))return o.selected;for(var l=r.length-1;l>=0;l--)if(c(r[l]))return r[l]}return e}),n.$watch("$select.selected",function(e){l.$viewValue!==e&&l.$setViewValue(e)}),l.$render=function(){o.selected=l.$viewValue},n.$on("uis:select",function(e,t){o.selected=t}),n.$on("uis:close",function(t,n){e(function(){o.focusser.prop("disabled",!1),n||o.focusser[0].focus()},0,!1)}),n.$on("uis:activate",function(){s.prop("disabled",!0)});var s=angular.element("");t(s)(n),o.focusser=s,o.focusInput=s,r.parent().append(s),s.bind("focus",function(){n.$evalAsync(function(){o.focus=!0})}),s.bind("blur",function(){n.$evalAsync(function(){o.focus=!1})}),s.bind("keydown",function(e){return e.which===o.KEY.BACKSPACE?(e.preventDefault(),e.stopPropagation(),o.select(void 0),n.$apply(),void 0):(e.which===o.KEY.TAB||o.KEY.isControl(e)||o.KEY.isFunctionKey(e)||e.which===o.KEY.ESC||((e.which==o.KEY.DOWN||e.which==o.KEY.UP||e.which==o.KEY.ENTER||e.which==o.KEY.SPACE)&&(e.preventDefault(),e.stopPropagation(),o.activate()),n.$digest()),void 0)}),s.bind("keyup input",function(e){e.which===o.KEY.TAB||o.KEY.isControl(e)||o.KEY.isFunctionKey(e)||e.which===o.KEY.ESC||e.which==o.KEY.ENTER||e.which===o.KEY.BACKSPACE||(o.activate(s.val()),s.val(""),n.$digest())})}}}]),t.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var r=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!r)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:r[2],source:t(r[3]),trackByExp:r[4],modelMapper:t(r[1]||r[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,r){var i=e+" in "+(r?"$group.items":t);return n&&(i+=" track by "+n),i}}])}(); \ No newline at end of file diff --git a/dist/select.select2.js b/dist/select.select2.js index 134178a8f..1ec45937d 100644 --- a/dist/select.select2.js +++ b/dist/select.select2.js @@ -1,60 +1,13 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-06T13:28:34.961Z + * Version: 0.12.1 - 2015-08-09T18:09:19.177Z * License: MIT */ (function () { "use strict"; -var KEY = { - TAB: 9, - ENTER: 13, - ESC: 27, - SPACE: 32, - LEFT: 37, - UP: 38, - RIGHT: 39, - DOWN: 40, - SHIFT: 16, - CTRL: 17, - ALT: 18, - PAGE_UP: 33, - PAGE_DOWN: 34, - HOME: 36, - END: 35, - BACKSPACE: 8, - DELETE: 46, - COMMAND: 91, - - isControl: function (e) { - var k = e.which; - switch (k) { - case KEY.COMMAND: - case KEY.SHIFT: - case KEY.CTRL: - case KEY.ALT: - return true; - } - - if (e.metaKey) { - return true; - } - - return false; - }, - isFunctionKey: function (k) { - k = k.which ? k.which : k; - return k >= 112 && k <= 123; - }, - isVerticalMovement: function (k) { - return ~[KEY.UP, KEY.DOWN].indexOf(k); - }, - isHorizontalMovement: function (k) { - return ~[KEY.LEFT, KEY.RIGHT, KEY.BACKSPACE, KEY.DELETE].indexOf(k); - } -}; /** * Add querySelectorAll() to jqLite. @@ -107,7 +60,7 @@ var uis = angular.module('ui.select', []) appendToBody: false }) -// See Rename minErr and make it accessible from outside https://github.com/angular/angular.js/issues/6913 + // See Rename minErr and make it accessible from outside https://github.com/angular/angular.js/issues/6913 .service('uiSelectMinErr', function () { var minErr = angular.$$minErr('ui.select'); return function () { @@ -117,7 +70,7 @@ var uis = angular.module('ui.select', []) }; }) -// Recreates old behavior of ng-transclude. Used internally. + // Recreates old behavior of ng-transclude. Used internally. .directive('uisTranscludeAppend', function () { return { link: function (scope, element, attrs, ctrl, transclude) { @@ -128,29 +81,30 @@ var uis = angular.module('ui.select', []) }; }) -/** - * Highlights text that matches $select.search. - * - * Taken from AngularUI Bootstrap Typeahead - * See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L340 - */ + /** + * Highlights text that matches $select.search. + * + * Taken from AngularUI Bootstrap Typeahead + * See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L340 + */ .filter('highlight', function () { function escapeRegexp(queryToEscape) { return queryToEscape.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1'); } return function (matchItem, query) { + matchItem = String(matchItem); return query && matchItem ? matchItem.replace(new RegExp(escapeRegexp(query), 'gi'), '$&') : matchItem; }; }) -/** - * A read-only equivalent of jQuery's offset function: http://api.jquery.com/offset/ - * - * Taken from AngularUI Bootstrap Position: - * See https://github.com/angular-ui/bootstrap/blob/master/src/position/position.js#L70 - */ + /** + * A read-only equivalent of jQuery's offset function: http://api.jquery.com/offset/ + * + * Taken from AngularUI Bootstrap Position: + * See https://github.com/angular-ui/bootstrap/blob/master/src/position/position.js#L70 + */ .factory('uisOffset', ['$document', '$window', function ($document, $window) { @@ -247,7 +201,6 @@ uis.directive('uiSelectChoices', uis.controller('uiSelectCtrl', ['$scope', '$element', '$timeout', '$filter', '$q', 'uisRepeatParser', 'uiSelectMinErr', 'uiSelectConfig', function ($scope, $element, $timeout, $filter, $q, RepeatParser, uiSelectMinErr, uiSelectConfig) { - var ctrl = this; var EMPTY_SEARCH = ''; @@ -256,23 +209,23 @@ uis.controller('uiSelectCtrl', ctrl.searchEnabled = uiSelectConfig.searchEnabled; ctrl.sortable = uiSelectConfig.sortable; - ctrl.removeSelected = false; // If selected item(s) should be removed from dropdown list - ctrl.closeOnSelect = true; // Initialized inside uiSelect directive link function + ctrl.removeSelected = false; // If selected item(s) should be removed from dropdown list + ctrl.closeOnSelect = true; // Initialized inside uiSelect directive link function ctrl.search = EMPTY_SEARCH; - ctrl.activeIndex = 0; // Dropdown of choices - ctrl.items = []; // All available choices + ctrl.activeIndex = 0; // Dropdown of choices + ctrl.items = []; // All available choices ctrl.open = false; ctrl.focus = false; ctrl.disabled = false; ctrl.selected = undefined; - ctrl.focusser = undefined; // Reference to input element used to handle focus events + ctrl.focusser = undefined; // Reference to input element used to handle focus events ctrl.resetSearchInput = true; - ctrl.multiple = undefined; // Initialized inside uiSelect directive link function - ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelectChoices directive link function - ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelectMatch directive link function + ctrl.multiple = undefined; // Initialized inside uiSelect directive link function + ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelectChoices directive link function + ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelectMatch directive link function ctrl.clickTriggeredSelect = false; ctrl.$filter = $filter; @@ -282,6 +235,158 @@ uis.controller('uiSelectCtrl', ctrl.searchInput.length); } + // TODO: Maybe make these methods in KEY directly in the controller? + ctrl.KEY = { + TAB: 9, + ENTER: 13, + ESC: 27, + SPACE: 32, + LEFT: 37, + UP: 38, + RIGHT: 39, + DOWN: 40, + SHIFT: 16, + CTRL: 17, + ALT: 18, + PAGE_UP: 33, + PAGE_DOWN: 34, + HOME: 36, + END: 35, + BACKSPACE: 8, + DELETE: 46, + COMMAND: 91, + MAP: { + 91: "COMMAND", + 8: "BACKSPACE", + 9: "TAB", + 13: "ENTER", + 16: "SHIFT", + 17: "CTRL", + 18: "ALT", + 19: "PAUSEBREAK", + 20: "CAPSLOCK", + 27: "ESC", + 32: "SPACE", + 33: "PAGE_UP", + 34: "PAGE_DOWN", + 35: "END", + 36: "HOME", + 37: "LEFT", + 38: "UP", + 39: "RIGHT", + 40: "DOWN", + 43: "+", + 44: "PRINTSCREEN", + 45: "INSERT", + 46: "DELETE", + 48: "0", + 49: "1", + 50: "2", + 51: "3", + 52: "4", + 53: "5", + 54: "6", + 55: "7", + 56: "8", + 57: "9", + 59: ";", + 61: "=", + 65: "A", + 66: "B", + 67: "C", + 68: "D", + 69: "E", + 70: "F", + 71: "G", + 72: "H", + 73: "I", + 74: "J", + 75: "K", + 76: "L", + 77: "M", + 78: "N", + 79: "O", + 80: "P", + 81: "Q", + 82: "R", + 83: "S", + 84: "T", + 85: "U", + 86: "V", + 87: "W", + 88: "X", + 89: "Y", + 90: "Z", + 96: "0", + 97: "1", + 98: "2", + 99: "3", + 100: "4", + 101: "5", + 102: "6", + 103: "7", + 104: "8", + 105: "9", + 106: "*", + 107: "+", + 109: "-", + 110: ".", + 111: "/", + 112: "F1", + 113: "F2", + 114: "F3", + 115: "F4", + 116: "F5", + 117: "F6", + 118: "F7", + 119: "F8", + 120: "F9", + 121: "F10", + 122: "F11", + 123: "F12", + 144: "NUMLOCK", + 145: "SCROLLLOCK", + 186: ";", + 187: "=", + 188: ",", + 189: "-", + 190: ".", + 191: "/", + 192: "`", + 219: "[", + 220: "\\", + 221: "]", + 222: "'" + }, + + isControl: function (e) { + var k = e.which; + switch (k) { + case ctrl.KEY.COMMAND: + case ctrl.KEY.SHIFT: + case ctrl.KEY.CTRL: + case ctrl.KEY.ALT: + return true; + } + + if (e.metaKey) { + return true; + } + + return false; + }, + isFunctionKey: function (k) { + k = k.which ? k.which : k; + return k >= 112 && k <= 123; + }, + isVerticalMovement: function (k) { + return ~[ctrl.KEY.UP, ctrl.KEY.DOWN].indexOf(k); + }, + isHorizontalMovement: function (k) { + return ~[ctrl.KEY.LEFT, ctrl.KEY.RIGHT, ctrl.KEY.BACKSPACE, ctrl.KEY.DELETE].indexOf(k); + } + }; + /** * Returns true if the selection is empty * @returns {boolean|*} @@ -322,6 +427,7 @@ uis.controller('uiSelectCtrl', /** * Activates the control. * When the user clicks on ui-select, displays the dropdown list + * Also called following keyboard input to the search box */ ctrl.activate = function (initSearchValue, avoidReset) { if (!ctrl.disabled && !ctrl.open) { @@ -346,22 +452,15 @@ uis.controller('uiSelectCtrl', }); }; - var result = ctrl.onDropdownCallback($scope, {open: true}); - if (angular.isDefined(result)) { - if (angular.isFunction(result.then)) { - // Promise returned - wait for it to complete before completing the selection - result.then(function (result) { - if (!result) { - return; - } + var result = ctrl.beforeDropdownOpen(); + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (result) { + if (result === true) { completeCallback(); - }); - } else if (result === true) { - completeCallback(); - } else if (result) { - completeCallback(); - } - } else { + } + }); + } else if (result === true) { completeCallback(); } } @@ -471,9 +570,10 @@ uis.controller('uiSelectCtrl', var isActive = itemIndex === -1 ? false : itemIndex === ctrl.activeIndex; // If this is active, and we've defined a callback, do it! - if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { - itemScope.$eval(ctrl.onHighlightCallback); - } + // TODO: Needed? +// if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { +// itemScope.$eval(ctrl.onHighlightCallback); +// } return isActive; }; @@ -518,22 +618,11 @@ uis.controller('uiSelectCtrl', return; } - // Create the data used to pass to the callbacks - var locals = {}; - locals[ctrl.parserResult.itemName] = item; - var callbackContext = { - $item: item, - $model: ctrl.parserResult.modelMapper($scope, locals) - }; - - // Local method called when we complete the select - // eg. called after the onselect callback - var completeCallback = function (item) { - callbackContext.$item = item; + function completeCallback() { $scope.$broadcast('uis:select', item); $timeout(function () { - ctrl.onSelectCallback($scope, callbackContext); + ctrl.afterSelect(item); }); if (ctrl.closeOnSelect) { @@ -542,41 +631,31 @@ uis.controller('uiSelectCtrl', if ($event && $event.type === 'click') { ctrl.clickTriggeredSelect = true; } - }; - - // If there's no onBeforeSelect callback, then just call the completeCallback - if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { - completeCallback(item); - return; } - // Call the onBeforeSelect callback + // Call the beforeSelect method // Allowable responses are -: - // falsy: Abort the selection - // promise: Wait for response + // false: Abort the selection // true: Complete selection + // promise: Wait for response // object: Add the returned object - var result = ctrl.onBeforeSelectCallback($scope, callbackContext); - if (angular.isDefined(result)) { - if (angular.isFunction(result.then)) { - // Promise returned - wait for it to complete before completing the selection - result.then(function (response) { - if (!response) { - return; - } - if (response === true) { - completeCallback(item); - } else if (response) { - completeCallback(response); - } - }); - } else if (result === true) { - completeCallback(item); - } else if (result) { - completeCallback(result); - } - } else { + var result = ctrl.beforeSelect(item); + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (response) { + if (!response) { + return; + } + if (response === true) { + completeCallback(item); + } else if (response) { + completeCallback(response); + } + }); + } else if (result === true) { completeCallback(item); + } else if (result) { + completeCallback(result); } }; @@ -601,22 +680,15 @@ uis.controller('uiSelectCtrl', $scope.$broadcast('uis:close', skipFocusser); } - var result = ctrl.onDropdownCallback($scope, {open: false}); - if (angular.isDefined(result)) { - if (angular.isFunction(result.then)) { - // Promise returned - wait for it to complete before completing the selection - result.then(function (result) { - if (!result) { - return; - } + var result = ctrl.beforeDropdownClose(); + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (result) { + if (result === true) { completeCallback(); - }); - } else if (result === true) { - completeCallback(); - } else if (result) { - completeCallback(); - } - } else { + } + }); + } else if (result === true) { completeCallback(); } }; @@ -706,7 +778,7 @@ uis.controller('uiSelectCtrl', function _handleDropDownSelection(key) { var processed = true; switch (key) { - case KEY.DOWN: + case ctrl.KEY.DOWN: if (!ctrl.open && ctrl.multiple) { // In case its the search input in 'multiple' mode ctrl.activate(false, true); @@ -715,7 +787,7 @@ uis.controller('uiSelectCtrl', ctrl.activeIndex++; } break; - case KEY.UP: + case ctrl.KEY.UP: if (!ctrl.open && ctrl.multiple) { ctrl.activate(false, true); } //In case its the search input in 'multiple' mode @@ -723,21 +795,23 @@ uis.controller('uiSelectCtrl', ctrl.activeIndex--; } break; - case KEY.TAB: + case ctrl.KEY.TAB: if (!ctrl.multiple || ctrl.open) { ctrl.select(ctrl.items[ctrl.activeIndex], true); } break; - case KEY.ENTER: + case ctrl.KEY.ENTER: if (ctrl.open) { // Make sure at least one dropdown item is highlighted before adding - ctrl.select(ctrl.items[ctrl.activeIndex]); + if (ctrl.items[ctrl.activeIndex] !== undefined) { + ctrl.select(ctrl.items[ctrl.activeIndex]); + } } else { // In case its the search input in 'multiple' mode ctrl.activate(false, true); } break; - case KEY.ESC: + case ctrl.KEY.ESC: ctrl.close(); break; default: @@ -748,39 +822,42 @@ uis.controller('uiSelectCtrl', // Bind to keyboard shortcuts ctrl.searchInput.on('keydown', function (e) { - var key = e.which; - // if(~[KEY.ESC,KEY.TAB].indexOf(key)){ - // //TODO: SEGURO? - // ctrl.close(); - // } + if (~[ctrl.KEY.ESC, ctrl.KEY.TAB].indexOf(key)) { + // TODO: SEGURO? + ctrl.close(); + } $scope.$apply(function () { _handleDropDownSelection(key); }); - if (KEY.isVerticalMovement(key) && ctrl.items.length > 0) { + if (ctrl.KEY.isVerticalMovement(key) && ctrl.items.length > 0) { _ensureHighlightVisible(); } - if (key === KEY.ENTER || key === KEY.ESC) { + if (key === ctrl.KEY.ENTER || key === ctrl.KEY.ESC) { e.preventDefault(); e.stopPropagation(); } + + // Let the users process the data + // TODO: Is this needed, or just let the user bind to the event themselves! +// ctrl.afterKeypress(e); }); ctrl.searchInput.on('keyup', function (e) { // return early with these keys - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || - KEY.isVerticalMovement(e.which)) { + if (e.which === ctrl.KEY.TAB || ctrl.KEY.isControl(e) || ctrl.KEY.isFunctionKey(e) || + e.which === ctrl.KEY.ESC || + ctrl.KEY.isVerticalMovement(e.which)) { return; } - if (ctrl.onKeypressCallback === undefined) { - return; - } - ctrl.onKeypressCallback($scope, {event: e}); + // Let the users process the data + // TODO: Is this needed, or just let the user bind to the event themselves! + ctrl.afterKeypress(e); }); // See https://github.com/ivaynberg/select2/blob/3.4.6/select2.js#L1431 @@ -817,6 +894,89 @@ uis.controller('uiSelectCtrl', ctrl.searchInput.off('keyup keydown blur paste'); }); + /** + * Keypress callback. Overridable. + * @param event the keypress event + */ + /* jshint unused:false */ + ctrl.afterKeypress = function (event) { + }; + + /** + * Method called before a selection is made. This can be overridden to allow + * the selection to be aborted, or a modified version of the selected item to be + * returned. + * + * Allowable responses are -: + * false: Abort the selection + * true: Complete selection with the selected object + * object: Complete the selection with the returned object + * promise: Wait for response - response from promise is as above + * + * @param item the item that has been selected + * @returns {*} + */ + ctrl.beforeSelect = function (item) { + return true; + }; + + /** + * Method called after a selection is confirmed. This can be overridden to allow + * the application to be notified of a newly selected item. + * No return is required. + * + * @param item the item that has been selected + */ + ctrl.afterSelect = function (item) { + }; + + /** + * Method called before an item is removed from the selected list. This can be overridden + * to allow the removal to be aborted + * + * Allowable responses are -: + * false: Abort the selection + * true: Complete selection with the selected object + * object: Complete the selection with the returned object + * promise: Wait for response - response from promise is as above + * + * @param item the item that has been selected + * @returns {*} + */ + ctrl.beforeRemove = function (item) { + return true; + }; + + /** + * Method called after a item is removed. This can be overridden to allow + * the application to be notified of a removed item. + * No return is required. + * + * @param item the item that has been removed + */ + ctrl.afterRemove = function (item) { + }; + + /** + * Method called before the dropdown is opened. This can be overridden to allow + * the application to process data before the dropdown is displayed. + * The method may return a promise, or true to allow the dropdown, or false to abort. + * @returns {boolean} + */ + ctrl.beforeDropdownOpen = function () { + return true; + }; + + /** + * Method called before the dropdown is closed. This can be overridden to allow + * the application to prevent the dropdown from closing. + * The method may return a promise, or true to allow the dropdown to close, or false to abort. + * @returns {boolean} + */ + ctrl.beforeDropdownClose = function () { + return true; + }; + }]); uis.directive('uiSelect', @@ -863,13 +1023,6 @@ uis.directive('uiSelect', } }(); - $select.onSelectCallback = $parse(attrs.onSelect); - $select.onBeforeSelectCallback = $parse(attrs.onBeforeSelect); - $select.onRemoveCallback = $parse(attrs.onRemove); - $select.onBeforeRemoveCallback = $parse(attrs.onBeforeRemove); - $select.onKeypressCallback = $parse(attrs.onKeypress); - $select.onDropdownCallback = $parse(attrs.onDropdown); - // Limit the number of selections allowed $select.limit = (angular.isDefined(attrs.limit)) ? parseInt(attrs.limit, 10) : undefined; @@ -936,10 +1089,9 @@ uis.directive('uiSelect', // Will lose focus only with certain targets var focusableControls = ['input', 'button', 'textarea']; // To check if target is other ui-select - var targetScope = angular.element(e.target).scope(); + var targetController = angular.element(e.target).controller('uiSelect'); // To check if target is other ui-select - var skipFocusser = targetScope && targetScope.$select && - targetScope.$select !== $select; + var skipFocusser = targetController && targetController !== $select; // Check if target is input, button or textarea if (!skipFocusser) { skipFocusser = ~focusableControls.indexOf(e.target.tagName.toLowerCase()); @@ -1068,7 +1220,8 @@ uis.directive('uiSelect', var offsetDropdown = uisOffset(dropdown); // Determine if the direction of the dropdown needs to be changed. - if (offset.top + offset.height + offsetDropdown.height > $window.pageYOffset + $document[0].documentElement.clientHeight) { + if (offset.top + offset.height + offsetDropdown.height > + $window.pageYOffset + $document[0].documentElement.clientHeight) { element.addClass(directionUpClassName); } @@ -1103,6 +1256,8 @@ uis.directive('uiSelectMatch', ['uiSelectConfig', function (uiSelectConfig) { }, link: function (scope, element, attrs, $select) { $select.lockChoiceExpression = attrs.uiLockChoice; + + // TODO: observe required? attrs.$observe('placeholder', function (placeholder) { $select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder; }); @@ -1112,6 +1267,7 @@ uis.directive('uiSelectMatch', ['uiSelectConfig', function (uiSelectConfig) { (angular.isDefined(allow)) ? (allow === '') ? true : (allow.toLowerCase() === 'true') : false; } + // TODO: observe required? attrs.$observe('allowClear', setAllowClear); setAllowClear(attrs.allowClear); @@ -1157,65 +1313,47 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel * Then calls onRemove to notify the user the item has been removed */ ctrl.removeChoice = function (index) { + // Get the removed choice var removedChoice = $select.selected[index]; - // if the choice is locked, can't remove it + // If the choice is locked, can't remove it if (removedChoice._uiSelectChoiceLocked) { return; } - var locals = {}; - locals[$select.parserResult.itemName] = removedChoice; - - $select.selected.splice(index, 1); - ctrl.activeMatchIndex = -1; - $select.sizeSearchInput(); - - var callbackContext = { - $item: removedChoice, - $model: $select.parserResult.modelMapper($scope, locals) - }; - // Give some time for scope propagation. function completeCallback() { + $select.selected.splice(index, 1); + ctrl.activeMatchIndex = -1; + $select.sizeSearchInput(); + $timeout(function () { - $select.onRemoveCallback($scope, callbackContext); + $select.afterRemove(removedChoice); }); ctrl.updateModel(); } - // If there's no onBeforeRemove callback, then just call the completeCallback - if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { - completeCallback(); - return; - } - - // Call the onBeforeRemove callback + // Call the beforeRemove callback // Allowable responses are -: - // falsy: Abort the removal - // promise: Wait for response + // false: Abort the removal // true: Complete removal - var result = ctrl.onBeforeRemoveCallback($scope, callbackContext); - if (angular.isDefined(result)) { - if (angular.isFunction(result.then)) { - // Promise returned - wait for it to complete before completing the selection - result.then(function (result) { - if (!result) { - return; - } - completeCallback(result); - }); - } else if (result === true) { - completeCallback(); - } - } else { + // promise: Wait for response + var result = $select.beforeRemove(removedChoice); + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (result) { + if (result === true) { + completeCallback(); + } + }); + } else if (result === true) { completeCallback(); } }; ctrl.getPlaceholder = function () { - //Refactor single? + // Refactor single? if ($select.selected && $select.selected.length) { return; } @@ -1343,17 +1481,18 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel var key = e.which; scope.$apply(function () { var processed = false; - if (KEY.isHorizontalMovement(key)) { + if ($select.KEY.isHorizontalMovement(key)) { processed = _handleMatchSelection(key); } - if (processed && key != KEY.TAB) { - //TODO Check si el tab selecciona aun correctamente - //Crear test + if (processed && key != $select.KEY.TAB) { + // TODO Check si el tab selecciona aun correctamente + //Creat test // e.preventDefault(); // e.stopPropagation(); } }); }); + function _getCaretPosition(el) { if (angular.isNumber(el.selectionStart)) { return el.selectionStart; @@ -1375,7 +1514,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel prev = $selectMultiple.activeMatchIndex - 1, newIndex = curr; - if (caretPosition > 0 || ($select.search.length && key == KEY.RIGHT)) { + if (caretPosition > 0 || ($select.search.length && key == $select.KEY.RIGHT)) { return false; } @@ -1383,7 +1522,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel function getNewActiveMatchIndex() { switch (key) { - case KEY.LEFT: + case $select.KEY.LEFT: // Select previous/first item if (~$selectMultiple.activeMatchIndex) { return prev; @@ -1393,7 +1532,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel return last; } break; - case KEY.RIGHT: + case $select.KEY.RIGHT: // Open drop-down if (!~$selectMultiple.activeMatchIndex || curr === last) { $select.activate(); @@ -1404,7 +1543,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel return next; } break; - case KEY.BACKSPACE: + case $select.KEY.BACKSPACE: // Remove selected item and select previous/first if (~$selectMultiple.activeMatchIndex) { $selectMultiple.removeChoice(curr); @@ -1415,7 +1554,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel return last; } break; - case KEY.DELETE: + case $select.KEY.DELETE: // Remove selected item and select next item if (~$selectMultiple.activeMatchIndex) { $selectMultiple.removeChoice($selectMultiple.activeMatchIndex); @@ -1539,7 +1678,7 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co }); focusser.bind("keydown", function (e) { - if (e.which === KEY.BACKSPACE) { + if (e.which === $select.KEY.BACKSPACE) { e.preventDefault(); e.stopPropagation(); $select.select(undefined); @@ -1547,11 +1686,11 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co return; } - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) { + if (e.which === $select.KEY.TAB || $select.KEY.isControl(e) || $select.KEY.isFunctionKey(e) || e.which === $select.KEY.ESC) { return; } - if (e.which == KEY.DOWN || e.which == KEY.UP || e.which == KEY.ENTER || e.which == KEY.SPACE) { + if (e.which == $select.KEY.DOWN || e.which == $select.KEY.UP || e.which == $select.KEY.ENTER || e.which == $select.KEY.SPACE) { e.preventDefault(); e.stopPropagation(); $select.activate(); @@ -1561,8 +1700,8 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co }); focusser.bind("keyup input", function (e) { - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || - e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { + if (e.which === $select.KEY.TAB || $select.KEY.isControl(e) || $select.KEY.isFunctionKey(e) || e.which === $select.KEY.ESC || + e.which == $select.KEY.ENTER || e.which === $select.KEY.BACKSPACE) { return; } diff --git a/dist/select.select2.min.js b/dist/select.select2.min.js index 0bda3eb56..abc351134 100644 --- a/dist/select.select2.min.js +++ b/dist/select.select2.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-06T13:28:34.961Z + * Version: 0.12.1 - 2015-08-09T18:09:19.177Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],c=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(c.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,c=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,l,n){n(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(c){var l=c[0].getBoundingClientRect();return{width:l.width||c.prop("offsetWidth"),height:l.height||c.prop("offsetHeight"),top:l.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:l.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);c.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,c,l){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(e,n){if(!n.repeat)throw c("repeat","Expected 'repeat' expression.");return function(e,n,i,s,r){var a=i.groupBy,o=i.groupFilter;if(s.parseRepeatAttr(i.repeat,a,o),s.disableChoiceExpression=i.uiDisableChoice,s.onHighlightCallback=i.onHighlight,a){var u=n.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=n.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(s.parserResult.itemName,"$select.items",s.parserResult.trackByExp,a)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+s.parserResult.itemName+")").attr("ng-click","$select.select("+s.parserResult.itemName+",false,$event)");var d=n.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),l(n,r)(e),e.$watch("$select.search",function(e){e&&!s.open&&s.multiple&&s.activate(!1,!0),s.activeIndex=0})}}}}]),c.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,c,l,n,i,s,r,a){function o(){(h.resetSearchInput||void 0===h.resetSearchInput&&a.resetSearchInput)&&(h.search=f,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function u(e,t){var c,l,n=[];for(c=0;c0&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:c=!1}return c}function d(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw r("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(h.activeIndex<0)){var l=t[h.activeIndex],n=l.offsetTop+l.clientHeight-e[0].scrollTop,i=e[0].offsetHeight;n>i?e[0].scrollTop+=n-i:n=h.items.length?0:h.activeIndex,l(function(){h.search=e||h.search,h.searchInput[0].focus()})},i=h.onDropdownCallback(t,{open:!0});angular.isDefined(i)?angular.isFunction(i.then)?i.then(function(e){e&&n()}):i===!0?n():i&&n():n()}},h.parseRepeatAttr=function(e,c,l){function n(e){var n=t.$eval(c);if(h.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(n)?n(e):e[n],c=h.findGroupByName(t);c?c.items.push(e):h.groups.push({name:t,items:[e]})}),l){var i=t.$eval(l);angular.isFunction(i)?h.groups=i(h.groups):angular.isArray(i)&&(h.groups=u(h.groups,i))}h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function i(e){h.items=e}h.setItemsFn=c?n:i,h.parserResult=s.parse(e),h.isGrouped=!!c,h.itemProperty=h.parserResult.itemName,h.refreshItems=function(e){e=e||h.parserResult.source(t);var c=h.selected;if(h.isEmpty()||angular.isArray(c)&&!c.length||!h.removeSelected)h.setItemsFn(e);else if(void 0!==e){var l=e.filter(function(e){return c.indexOf(e)<0});h.setItemsFn(l)}},t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw r("items","Expected an array but got '{0}'.",e);h.refreshItems(e),h.ngModel.$modelValue=null}})},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){if(!h.open)return!1;var t=h.items.indexOf(e[h.itemProperty]),c=-1===t?!1:t===h.activeIndex;return c&&!angular.isUndefined(h.onHighlightCallback)&&e.$eval(h.onHighlightCallback),c},h.isDisabled=function(e){if(!h.open)return!1;var t,c=h.items.indexOf(e[h.itemProperty]),l=!1;return c>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[c],l=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=l),l},h.select=function(e,c,n){if((void 0===e||!e._uiSelectChoiceDisabled)&&(h.items||h.search)){var i={};i[h.parserResult.itemName]=e;var s={$item:e,$model:h.parserResult.modelMapper(t,i)},r=function(e){s.$item=e,t.$broadcast("uis:select",e),l(function(){h.onSelectCallback(t,s)}),h.closeOnSelect&&h.close(c),n&&"click"===n.type&&(h.clickTriggeredSelect=!0)};if(!angular.isDefined(h.onBeforeRemoveCallback))return r(e),void 0;var a=h.onBeforeSelectCallback(t,s);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(t){t&&(t===!0?r(e):t&&r(t))}):a===!0?r(e):a&&r(a):r(e)}},h.close=function(e){function c(){h.ngModel&&h.ngModel.$setTouched&&h.ngModel.$setTouched(),o(),h.open=!1,h.searchEnabled||angular.element(h.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e)}if(h.open){var l=h.onDropdownCallback(t,{open:!1});angular.isDefined(l)?angular.isFunction(l.then)?l.then(function(e){e&&c()}):l===!0?c():l&&c():c()}},h.setFocus=function(){h.focus||h.focusInput[0].focus()},h.clear=function(e){h.select(void 0),e.stopPropagation(),l(function(){h.focusser[0].focus()},0,!1)},h.toggle=function(e){h.open?(h.close(),e.preventDefault(),e.stopPropagation()):h.activate()},h.isLocked=function(e,t){var c,l=h.selected[t];return l&&!angular.isUndefined(h.lockChoiceExpression)&&(c=!!e.$eval(h.lockChoiceExpression),l._uiSelectChoiceLocked=c),c};var v=null;h.sizeSearchInput=function(){var e=h.searchInput[0],c=h.searchInput.parent().parent()[0],n=function(){return c.clientWidth*!!e.offsetParent},i=function(t){if(0===t)return!1;var c=t-e.offsetLeft-h.searchInput.parent()[0].offsetLeft-5;return 50>c&&(c=t),h.searchInput.css("width",c+"px"),!0};h.searchInput.css("width","10px"),l(function(){null!==v||i(n())||(v=t.$watch(n,function(e){i(e)&&(v(),v=null)}))})},h.searchInput.on("keydown",function(c){var l=c.which;t.$apply(function(){p(l)}),e.isVerticalMovement(l)&&h.items.length>0&&d(),(l===e.ENTER||l===e.ESC)&&(c.preventDefault(),c.stopPropagation())}),h.searchInput.on("keyup",function(c){c.which===e.TAB||e.isControl(c)||e.isFunctionKey(c)||c.which===e.ESC||e.isVerticalMovement(c.which)||void 0!==h.onKeypressCallback&&h.onKeypressCallback(t,{event:c})}),t.$on("$destroy",function(){h.searchInput.off("keyup keydown blur paste")})}]),c.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,c,l,n,i,s,r){return{restrict:"EA",templateUrl:function(e,t){var l=t.theme||c.theme;return l+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(i,a){return angular.isDefined(a.multiple)?i.append("").removeAttr("multiple"):i.append(""),function(i,a,o,u,p){function d(e){if(v.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(a[0],e.target):a[0].contains(e.target),!t&&!v.clickTriggeredSelect){var c=["input","button","textarea"],l=angular.element(e.target).scope(),n=l&&l.$select&&l.$select!==v;n||(n=~c.indexOf(e.target.tagName.toLowerCase())),v.close(n),i.$digest()}v.clickTriggeredSelect=!1}}function h(){var t=n(a);w=angular.element('
    '),w[0].style.width=t.width+"px",w[0].style.height=t.height+"px",a.after(w),x=a[0].style.width,e.find("body").append(a),a[0].style.position="absolute",a[0].style.left=t.left+"px",a[0].style.top=t.top+"px",a[0].style.width=t.width+"px"}function f(){null!==w&&(w.replaceWith(a),w=null,a[0].style.position="",a[0].style.left="",a[0].style.top="",a[0].style.width=x)}var v=u[0],g=u[1];v.generatedId=c.generateId(),v.baseTitle=o.title||"Select box",v.focusserTitle=v.baseTitle+" focus",v.focusserId="focusser-"+v.generatedId,v.closeOnSelect=function(){return angular.isDefined(o.closeOnSelect)?s(o.closeOnSelect)():c.closeOnSelect}(),v.onSelectCallback=s(o.onSelect),v.onBeforeSelectCallback=s(o.onBeforeSelect),v.onRemoveCallback=s(o.onRemove),v.onBeforeRemoveCallback=s(o.onBeforeRemove),v.onKeypressCallback=s(o.onKeypress),v.onDropdownCallback=s(o.onDropdown),v.limit=angular.isDefined(o.limit)?parseInt(o.limit,10):void 0,v.ngModel=g,v.choiceGrouped=function(e){return v.isGrouped&&e&&e.name},o.tabindex&&o.$observe("tabindex",function(e){v.focusInput.attr("tabindex",e),a.removeAttr("tabindex")});var m=i.$eval(o.searchEnabled);v.searchEnabled=void 0!==m?m:c.searchEnabled;var $=i.$eval(o.sortable);v.sortable=void 0!==$?$:c.sortable,o.$observe("disabled",function(){v.disabled=void 0!==o.disabled?o.disabled:!1}),angular.isDefined(o.autofocus)&&r(function(){v.setFocus()}),angular.isDefined(o.focusOn)&&i.$on(o.focusOn,function(){r(function(){v.setFocus()})}),e.on("click",d),i.$on("$destroy",function(){e.off("click",d)}),p(i,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),c.removeAttr("data-ui-select-match"),1!==c.length)throw l("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);a.querySelectorAll(".ui-select-match").replaceWith(c);var n=t.querySelectorAll(".ui-select-choices");if(n.removeAttr("ui-select-choices"),n.removeAttr("data-ui-select-choices"),1!==n.length)throw l("transcluded","Expected 1 .ui-select-choices but got '{0}'.",n.length);a.querySelectorAll(".ui-select-choices").replaceWith(n)});var b=i.$eval(o.appendToBody);(void 0!==b?b:c.appendToBody)&&(i.$watch("$select.open",function(e){e?h():f()}),i.$on("$destroy",function(){f()}));var w=null,x="",E=null,y="direction-up";i.$watch("$select.open",function(c){if(c){if(E=angular.element(a).querySelectorAll(".ui-select-dropdown"),null===E)return;E[0].style.opacity=0,r(function(){var c=n(a),l=n(E);c.top+c.height+l.height>t.pageYOffset+e[0].documentElement.clientHeight&&a.addClass(y),E[0].style.opacity=1})}else{if(null===E)return;a.removeClass(y)}})}}}}]),c.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,l=t.parent().attr("multiple");return c+(l?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,l,n){function i(e){n.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}n.lockChoiceExpression=l.uiLockChoice,l.$observe("placeholder",function(t){n.placeholder=void 0!==t?t:e.placeholder}),l.$observe("allowClear",i),i(l.allowClear),n.multiple&&n.sizeSearchInput()}}}]),c.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var c,l=this,n=e.$select;e.$evalAsync(function(){c=e.ngModel}),l.activeMatchIndex=-1,l.updateModel=function(){c.$setViewValue(Date.now()),l.refreshComponent()},l.refreshComponent=function(){n.refreshItems(),n.sizeSearchInput()},l.removeChoice=function(c){function i(){t(function(){n.onRemoveCallback(e,a)}),l.updateModel()}var s=n.selected[c];if(!s._uiSelectChoiceLocked){var r={};r[n.parserResult.itemName]=s,n.selected.splice(c,1),l.activeMatchIndex=-1,n.sizeSearchInput();var a={$item:s,$model:n.parserResult.modelMapper(e,r)};if(!angular.isDefined(l.onBeforeRemoveCallback))return i(),void 0;var o=l.onBeforeRemoveCallback(e,a);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(e){e&&i(e)}):o===!0&&i():i()}},l.getPlaceholder=function(){return n.selected&&n.selected.length?void 0:n.placeholder}}],controllerAs:"$selectMultiple",link:function(l,n,i,s){function r(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(t){function c(){switch(t){case e.LEFT:return~p.activeMatchIndex?d:s;case e.RIGHT:return~p.activeMatchIndex&&a!==s?u:(o.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(a),d):s;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),a):!1}}var l=r(o.searchInput[0]),n=o.selected.length,i=0,s=n-1,a=p.activeMatchIndex,u=p.activeMatchIndex+1,d=p.activeMatchIndex-1,h=a;return l>0||o.search.length&&t==e.RIGHT?!1:(o.close(),h=c(),p.activeMatchIndex=o.selected.length&&h!==!1?Math.min(s,Math.max(i,h)):-1,!0)}var o=s[0],u=l.ngModel=s[1],p=l.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,u.$parsers.unshift(function(){for(var e,t={},c=[],n=o.selected.length-1;n>=0;n--)t={},t[o.parserResult.itemName]=o.selected[n],e=o.parserResult.modelMapper(l,t),c.unshift(e);return c}),u.$formatters.unshift(function(e){var t,c=o.parserResult.source(l,{$select:{search:""}}),n={};if(!c)return e;var i=[],s=function(e,c){if(e&&e.length){for(var s=e.length-1;s>=0;s--){if(n[o.parserResult.itemName]=e[s],t=o.parserResult.modelMapper(l,n),o.parserResult.trackByExp){var r=/\.(.+)/.exec(o.parserResult.trackByExp);if(r.length>0&&t[r[1]]==c[r[1]])return i.unshift(e[s]),!0}if(angular.equals(t,c))return i.unshift(e[s]),!0}return!1}};if(!e)return i;for(var r=e.length-1;r>=0;r--)s(o.selected,e[r])||s(c,e[r])||i.unshift(e[r]);return i}),l.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);o.selected=[]}o.selected=u.$viewValue,l.$evalAsync()},l.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),p.updateModel())}),l.$on("uis:activate",function(){p.activeMatchIndex=-1}),l.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(t){var c=t.which;l.$apply(function(){var t=!1;e.isHorizontalMovement(c)&&(t=a(c)),t&&c!=e.TAB})}),o.searchInput.on("blur",function(){c(function(){p.activeMatchIndex=-1})})}}}]),c.directive("uiSelectSingle",["$timeout","$compile",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(l,n,i,s){var r=s[0],a=s[1];a.$parsers.unshift(function(e){var t,c={};return c[r.parserResult.itemName]=e,t=r.parserResult.modelMapper(l,c)}),a.$formatters.unshift(function(e){var t,c=r.parserResult.source(l,{$select:{search:""}}),n={};if(c){var i=function(c){return n[r.parserResult.itemName]=c,t=r.parserResult.modelMapper(l,n),t==e};if(r.selected&&i(r.selected))return r.selected;for(var s=c.length-1;s>=0;s--)if(i(c[s]))return c[s]}return e}),l.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){r.selected=a.$viewValue},l.$on("uis:select",function(e,t){r.selected=t}),l.$on("uis:close",function(e,c){t(function(){r.focusser.prop("disabled",!1),c||r.focusser[0].focus()},0,!1)}),l.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");c(o)(l),r.focusser=o,r.focusInput=o,n.parent().append(o),o.bind("focus",function(){l.$evalAsync(function(){r.focus=!0})}),o.bind("blur",function(){l.$evalAsync(function(){r.focus=!1})}),o.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),r.select(void 0),l.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),r.activate()),l.$digest()),void 0)}),o.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(r.activate(o.val()),o.val(""),l.$digest())})}}}]),c.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var l=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!l)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:l[2],source:t(l[3]),trackByExp:l[4],modelMapper:t(l[1]||l[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,l){var n=e+" in "+(l?"$group.items":t);return c&&(n+=" track by "+c),n}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("select2/choices.tpl.html",'
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    ')}]); \ No newline at end of file +!function(){"use strict";void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],c=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(c.bind(t)(e))return t;t=t.parentElement}return!1});var e=0,t=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return e++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,n,i){i(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return t=String(t),c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(c){var n=c[0].getBoundingClientRect();return{width:n.width||c.prop("offsetWidth"),height:n.height||c.prop("offsetHeight"),top:n.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:n.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);t.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,c,n){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(e,i){if(!i.repeat)throw c("repeat","Expected 'repeat' expression.");return function(e,i,l,s,r){var o=l.groupBy,a=l.groupFilter;if(s.parseRepeatAttr(l.repeat,o,a),s.disableChoiceExpression=l.uiDisableChoice,s.onHighlightCallback=l.onHighlight,o){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=i.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(s.parserResult.itemName,"$select.items",s.parserResult.trackByExp,o)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+s.parserResult.itemName+")").attr("ng-click","$select.select("+s.parserResult.itemName+",false,$event)");var d=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),n(i,r)(e),e.$watch("$select.search",function(e){e&&!s.open&&s.multiple&&s.activate(!1,!0),s.activeIndex=0})}}}}]),t.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(e,t,c,n,i,l,s,r){function o(){(d.resetSearchInput||void 0===d.resetSearchInput&&r.resetSearchInput)&&(d.search=h,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function a(e,t){var c,n,i=[];for(c=0;c0&&d.activeIndex--;break;case d.KEY.TAB:(!d.multiple||d.open)&&d.select(d.items[d.activeIndex],!0);break;case d.KEY.ENTER:d.open?void 0!==d.items[d.activeIndex]&&d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case d.KEY.ESC:d.close();break;default:t=!1}return t}function p(){var e=t.querySelectorAll(".ui-select-choices-content"),c=e.querySelectorAll(".ui-select-choices-row");if(c.length<1)throw s("choices","Expected multiple .ui-select-choices-row but got '{0}'.",c.length);if(!(d.activeIndex<0)){var n=c[d.activeIndex],i=n.offsetTop+n.clientHeight-e[0].scrollTop,l=e[0].offsetHeight;i>l?e[0].scrollTop+=i-l:i=112&&123>=e},isVerticalMovement:function(e){return~[d.KEY.UP,d.KEY.DOWN].indexOf(e)},isHorizontalMovement:function(e){return~[d.KEY.LEFT,d.KEY.RIGHT,d.KEY.BACKSPACE,d.KEY.DELETE].indexOf(e)}},d.isEmpty=function(){return angular.isUndefined(d.selected)||null===d.selected||""===d.selected},d.findGroupByName=function(e){return d.groups&&d.groups.filter(function(t){return t.name===e})[0]},d.activate=function(t,n){if(d.disabled||d.open)d.open&&!d.searchEnabled&&d.close();else{var i=function(){n||o(),e.$broadcast("uis:activate"),d.open=!0,d.searchEnabled||angular.element(d.searchInput[0]).addClass("ui-select-offscreen"),d.activeIndex=d.activeIndex>=d.items.length?0:d.activeIndex,c(function(){d.search=t||d.search,d.searchInput[0].focus()})},l=d.beforeDropdownOpen();angular.isFunction(l.then)?l.then(function(e){e===!0&&i()}):l===!0&&i()}},d.parseRepeatAttr=function(t,c,n){function i(t){var i=e.$eval(c);if(d.groups=[],angular.forEach(t,function(e){var t=angular.isFunction(i)?i(e):e[i],c=d.findGroupByName(t);c?c.items.push(e):d.groups.push({name:t,items:[e]})}),n){var l=e.$eval(n);angular.isFunction(l)?d.groups=l(d.groups):angular.isArray(l)&&(d.groups=a(d.groups,l))}d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function r(e){d.items=e}d.setItemsFn=c?i:r,d.parserResult=l.parse(t),d.isGrouped=!!c,d.itemProperty=d.parserResult.itemName,d.refreshItems=function(t){t=t||d.parserResult.source(e);var c=d.selected;if(d.isEmpty()||angular.isArray(c)&&!c.length||!d.removeSelected)d.setItemsFn(t);else if(void 0!==t){var n=t.filter(function(e){return c.indexOf(e)<0});d.setItemsFn(n)}},e.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw s("items","Expected an array but got '{0}'.",e);d.refreshItems(e),d.ngModel.$modelValue=null}})},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){if(!d.open)return!1;var t=d.items.indexOf(e[d.itemProperty]),c=-1===t?!1:t===d.activeIndex;return c},d.isDisabled=function(e){if(!d.open)return!1;var t,c=d.items.indexOf(e[d.itemProperty]),n=!1;return c>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[c],n=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=n),n},d.select=function(t,n,i){function l(){e.$broadcast("uis:select",t),c(function(){d.afterSelect(t)}),d.closeOnSelect&&d.close(n),i&&"click"===i.type&&(d.clickTriggeredSelect=!0)}if((void 0===t||!t._uiSelectChoiceDisabled)&&(d.items||d.search)){var s=d.beforeSelect(t);angular.isFunction(s.then)?s.then(function(e){e&&(e===!0?l(t):e&&l(e))}):s===!0?l(t):s&&l(s)}},d.close=function(t){function c(){d.ngModel&&d.ngModel.$setTouched&&d.ngModel.$setTouched(),o(),d.open=!1,d.searchEnabled||angular.element(d.searchInput[0]).removeClass("ui-select-offscreen"),e.$broadcast("uis:close",t)}if(d.open){var n=d.beforeDropdownClose();angular.isFunction(n.then)?n.then(function(e){e===!0&&c()}):n===!0&&c()}},d.setFocus=function(){d.focus||d.focusInput[0].focus()},d.clear=function(e){d.select(void 0),e.stopPropagation(),c(function(){d.focusser[0].focus()},0,!1)},d.toggle=function(e){d.open?(d.close(),e.preventDefault(),e.stopPropagation()):d.activate()},d.isLocked=function(e,t){var c,n=d.selected[t];return n&&!angular.isUndefined(d.lockChoiceExpression)&&(c=!!e.$eval(d.lockChoiceExpression),n._uiSelectChoiceLocked=c),c};var f=null;d.sizeSearchInput=function(){var t=d.searchInput[0],n=d.searchInput.parent().parent()[0],i=function(){return n.clientWidth*!!t.offsetParent},l=function(e){if(0===e)return!1;var c=e-t.offsetLeft-d.searchInput.parent()[0].offsetLeft-5;return 50>c&&(c=e),d.searchInput.css("width",c+"px"),!0};d.searchInput.css("width","10px"),c(function(){null!==f||l(i())||(f=e.$watch(i,function(e){l(e)&&(f(),f=null)}))})},d.searchInput.on("keydown",function(t){var c=t.which;~[d.KEY.ESC,d.KEY.TAB].indexOf(c)&&d.close(),e.$apply(function(){u(c)}),d.KEY.isVerticalMovement(c)&&d.items.length>0&&p(),(c===d.KEY.ENTER||c===d.KEY.ESC)&&(t.preventDefault(),t.stopPropagation())}),d.searchInput.on("keyup",function(e){e.which===d.KEY.TAB||d.KEY.isControl(e)||d.KEY.isFunctionKey(e)||e.which===d.KEY.ESC||d.KEY.isVerticalMovement(e.which)||d.afterKeypress(e)}),e.$on("$destroy",function(){d.searchInput.off("keyup keydown blur paste")}),d.afterKeypress=function(){},d.beforeSelect=function(){return!0},d.afterSelect=function(){},d.beforeRemove=function(){return!0},d.afterRemove=function(){},d.beforeDropdownOpen=function(){return!0},d.beforeDropdownClose=function(){return!0}}]),t.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,c,n,i,l,s,r){return{restrict:"EA",templateUrl:function(e,t){var n=t.theme||c.theme;return n+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(l,o){return angular.isDefined(o.multiple)?l.append("").removeAttr("multiple"):l.append(""),function(l,o,a,u,p){function d(e){if(g.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(o[0],e.target):o[0].contains(e.target),!t&&!g.clickTriggeredSelect){var c=["input","button","textarea"],n=angular.element(e.target).controller("uiSelect"),i=n&&n!==g;i||(i=~c.indexOf(e.target.tagName.toLowerCase())),g.close(i),l.$digest()}g.clickTriggeredSelect=!1}}function h(){var t=i(o);b=angular.element('
    '),b[0].style.width=t.width+"px",b[0].style.height=t.height+"px",o.after(b),w=o[0].style.width,e.find("body").append(o),o[0].style.position="absolute",o[0].style.left=t.left+"px",o[0].style.top=t.top+"px",o[0].style.width=t.width+"px"}function f(){null!==b&&(b.replaceWith(o),b=null,o[0].style.position="",o[0].style.left="",o[0].style.top="",o[0].style.width=w)}var g=u[0],v=u[1];g.generatedId=c.generateId(),g.baseTitle=a.title||"Select box",g.focusserTitle=g.baseTitle+" focus",g.focusserId="focusser-"+g.generatedId,g.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?s(a.closeOnSelect)():c.closeOnSelect}(),g.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,g.ngModel=v,g.choiceGrouped=function(e){return g.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){g.focusInput.attr("tabindex",e),o.removeAttr("tabindex")});var m=l.$eval(a.searchEnabled);g.searchEnabled=void 0!==m?m:c.searchEnabled;var E=l.$eval(a.sortable);g.sortable=void 0!==E?E:c.sortable,a.$observe("disabled",function(){g.disabled=void 0!==a.disabled?a.disabled:!1}),angular.isDefined(a.autofocus)&&r(function(){g.setFocus()}),angular.isDefined(a.focusOn)&&l.$on(a.focusOn,function(){r(function(){g.setFocus()})}),e.on("click",d),l.$on("$destroy",function(){e.off("click",d)}),p(l,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),c.removeAttr("data-ui-select-match"),1!==c.length)throw n("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);o.querySelectorAll(".ui-select-match").replaceWith(c);var i=t.querySelectorAll(".ui-select-choices");if(i.removeAttr("ui-select-choices"),i.removeAttr("data-ui-select-choices"),1!==i.length)throw n("transcluded","Expected 1 .ui-select-choices but got '{0}'.",i.length);o.querySelectorAll(".ui-select-choices").replaceWith(i)});var $=l.$eval(a.appendToBody);(void 0!==$?$:c.appendToBody)&&(l.$watch("$select.open",function(e){e?h():f()}),l.$on("$destroy",function(){f()}));var b=null,w="",S=null,x="direction-up";l.$watch("$select.open",function(c){if(c){if(S=angular.element(o).querySelectorAll(".ui-select-dropdown"),null===S)return;S[0].style.opacity=0,r(function(){var c=i(o),n=i(S);c.top+c.height+n.height>t.pageYOffset+e[0].documentElement.clientHeight&&o.addClass(x),S[0].style.opacity=1})}else{if(null===S)return;o.removeClass(x)}})}}}}]),t.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,n=t.parent().attr("multiple");return c+(n?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,n,i){function l(e){i.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}i.lockChoiceExpression=n.uiLockChoice,n.$observe("placeholder",function(t){i.placeholder=void 0!==t?t:e.placeholder}),n.$observe("allowClear",l),l(n.allowClear),i.multiple&&i.sizeSearchInput()}}}]),t.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var c,n=this,i=e.$select;e.$evalAsync(function(){c=e.ngModel}),n.activeMatchIndex=-1,n.updateModel=function(){c.$setViewValue(Date.now()),n.refreshComponent()},n.refreshComponent=function(){i.refreshItems(),i.sizeSearchInput()},n.removeChoice=function(e){function c(){i.selected.splice(e,1),n.activeMatchIndex=-1,i.sizeSearchInput(),t(function(){i.afterRemove(l)}),n.updateModel()}var l=i.selected[e];if(!l._uiSelectChoiceLocked){var s=i.beforeRemove(l);angular.isFunction(s.then)?s.then(function(e){e===!0&&c()}):s===!0&&c()}},n.getPlaceholder=function(){return i.selected&&i.selected.length?void 0:i.placeholder}}],controllerAs:"$selectMultiple",link:function(c,n,i,l){function s(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function r(e){function t(){switch(e){case o.KEY.LEFT:return~u.activeMatchIndex?p:l;case o.KEY.RIGHT:return~u.activeMatchIndex&&r!==l?a:(o.activate(),!1);case o.KEY.BACKSPACE:return~u.activeMatchIndex?(u.removeChoice(r),p):l;case o.KEY.DELETE:return~u.activeMatchIndex?(u.removeChoice(u.activeMatchIndex),r):!1}}var c=s(o.searchInput[0]),n=o.selected.length,i=0,l=n-1,r=u.activeMatchIndex,a=u.activeMatchIndex+1,p=u.activeMatchIndex-1,d=r;return c>0||o.search.length&&e==o.KEY.RIGHT?!1:(o.close(),d=t(),u.activeMatchIndex=o.selected.length&&d!==!1?Math.min(l,Math.max(i,d)):-1,!0)}var o=l[0],a=c.ngModel=l[1],u=c.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,a.$parsers.unshift(function(){for(var e,t={},n=[],i=o.selected.length-1;i>=0;i--)t={},t[o.parserResult.itemName]=o.selected[i],e=o.parserResult.modelMapper(c,t),n.unshift(e);return n}),a.$formatters.unshift(function(e){var t,n=o.parserResult.source(c,{$select:{search:""}}),i={};if(!n)return e;var l=[],s=function(e,n){if(e&&e.length){for(var s=e.length-1;s>=0;s--){if(i[o.parserResult.itemName]=e[s],t=o.parserResult.modelMapper(c,i),o.parserResult.trackByExp){var r=/\.(.+)/.exec(o.parserResult.trackByExp);if(r.length>0&&t[r[1]]==n[r[1]])return l.unshift(e[s]),!0}if(angular.equals(t,n))return l.unshift(e[s]),!0}return!1}};if(!e)return l;for(var r=e.length-1;r>=0;r--)s(o.selected,e[r])||s(n,e[r])||l.unshift(e[r]);return l}),c.$watchCollection(function(){return a.$modelValue},function(e,t){t!=e&&(a.$modelValue=null,u.refreshComponent())}),a.$render=function(){if(!angular.isArray(a.$viewValue)){if(!angular.isUndefined(a.$viewValue)&&null!==a.$viewValue)throw e("multiarr","Expected model value to be array but got '{0}'",a.$viewValue);o.selected=[]}o.selected=a.$viewValue,c.$evalAsync()},c.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),u.updateModel())}),c.$on("uis:activate",function(){u.activeMatchIndex=-1}),c.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(e){var t=e.which;c.$apply(function(){var e=!1;o.KEY.isHorizontalMovement(t)&&(e=r(t)),e&&t!=o.KEY.TAB})}),o.searchInput.on("blur",function(){t(function(){u.activeMatchIndex=-1})})}}}]),t.directive("uiSelectSingle",["$timeout","$compile",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(c,n,i,l){var s=l[0],r=l[1];r.$parsers.unshift(function(e){var t,n={};return n[s.parserResult.itemName]=e,t=s.parserResult.modelMapper(c,n)}),r.$formatters.unshift(function(e){var t,n=s.parserResult.source(c,{$select:{search:""}}),i={};if(n){var l=function(n){return i[s.parserResult.itemName]=n,t=s.parserResult.modelMapper(c,i),t==e};if(s.selected&&l(s.selected))return s.selected;for(var r=n.length-1;r>=0;r--)if(l(n[r]))return n[r]}return e}),c.$watch("$select.selected",function(e){r.$viewValue!==e&&r.$setViewValue(e)}),r.$render=function(){s.selected=r.$viewValue},c.$on("uis:select",function(e,t){s.selected=t}),c.$on("uis:close",function(t,c){e(function(){s.focusser.prop("disabled",!1),c||s.focusser[0].focus()},0,!1)}),c.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");t(o)(c),s.focusser=o,s.focusInput=o,n.parent().append(o),o.bind("focus",function(){c.$evalAsync(function(){s.focus=!0})}),o.bind("blur",function(){c.$evalAsync(function(){s.focus=!1})}),o.bind("keydown",function(e){return e.which===s.KEY.BACKSPACE?(e.preventDefault(),e.stopPropagation(),s.select(void 0),c.$apply(),void 0):(e.which===s.KEY.TAB||s.KEY.isControl(e)||s.KEY.isFunctionKey(e)||e.which===s.KEY.ESC||((e.which==s.KEY.DOWN||e.which==s.KEY.UP||e.which==s.KEY.ENTER||e.which==s.KEY.SPACE)&&(e.preventDefault(),e.stopPropagation(),s.activate()),c.$digest()),void 0)}),o.bind("keyup input",function(e){e.which===s.KEY.TAB||s.KEY.isControl(e)||s.KEY.isFunctionKey(e)||e.which===s.KEY.ESC||e.which==s.KEY.ENTER||e.which===s.KEY.BACKSPACE||(s.activate(o.val()),o.val(""),c.$digest())})}}}]),t.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var n=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!n)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:n[2],source:t(n[3]),trackByExp:n[4],modelMapper:t(n[1]||n[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,n){var i=e+" in "+(n?"$group.items":t);return c&&(i+=" track by "+c),i}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("select2/choices.tpl.html",'
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/dist/select.selectize.js b/dist/select.selectize.js index 54352dac1..437ba94d3 100644 --- a/dist/select.selectize.js +++ b/dist/select.selectize.js @@ -1,60 +1,13 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-06T13:28:34.967Z + * Version: 0.12.1 - 2015-08-09T18:09:19.185Z * License: MIT */ (function () { "use strict"; -var KEY = { - TAB: 9, - ENTER: 13, - ESC: 27, - SPACE: 32, - LEFT: 37, - UP: 38, - RIGHT: 39, - DOWN: 40, - SHIFT: 16, - CTRL: 17, - ALT: 18, - PAGE_UP: 33, - PAGE_DOWN: 34, - HOME: 36, - END: 35, - BACKSPACE: 8, - DELETE: 46, - COMMAND: 91, - - isControl: function (e) { - var k = e.which; - switch (k) { - case KEY.COMMAND: - case KEY.SHIFT: - case KEY.CTRL: - case KEY.ALT: - return true; - } - - if (e.metaKey) { - return true; - } - - return false; - }, - isFunctionKey: function (k) { - k = k.which ? k.which : k; - return k >= 112 && k <= 123; - }, - isVerticalMovement: function (k) { - return ~[KEY.UP, KEY.DOWN].indexOf(k); - }, - isHorizontalMovement: function (k) { - return ~[KEY.LEFT, KEY.RIGHT, KEY.BACKSPACE, KEY.DELETE].indexOf(k); - } -}; /** * Add querySelectorAll() to jqLite. @@ -107,7 +60,7 @@ var uis = angular.module('ui.select', []) appendToBody: false }) -// See Rename minErr and make it accessible from outside https://github.com/angular/angular.js/issues/6913 + // See Rename minErr and make it accessible from outside https://github.com/angular/angular.js/issues/6913 .service('uiSelectMinErr', function () { var minErr = angular.$$minErr('ui.select'); return function () { @@ -117,7 +70,7 @@ var uis = angular.module('ui.select', []) }; }) -// Recreates old behavior of ng-transclude. Used internally. + // Recreates old behavior of ng-transclude. Used internally. .directive('uisTranscludeAppend', function () { return { link: function (scope, element, attrs, ctrl, transclude) { @@ -128,29 +81,30 @@ var uis = angular.module('ui.select', []) }; }) -/** - * Highlights text that matches $select.search. - * - * Taken from AngularUI Bootstrap Typeahead - * See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L340 - */ + /** + * Highlights text that matches $select.search. + * + * Taken from AngularUI Bootstrap Typeahead + * See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L340 + */ .filter('highlight', function () { function escapeRegexp(queryToEscape) { return queryToEscape.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1'); } return function (matchItem, query) { + matchItem = String(matchItem); return query && matchItem ? matchItem.replace(new RegExp(escapeRegexp(query), 'gi'), '$&') : matchItem; }; }) -/** - * A read-only equivalent of jQuery's offset function: http://api.jquery.com/offset/ - * - * Taken from AngularUI Bootstrap Position: - * See https://github.com/angular-ui/bootstrap/blob/master/src/position/position.js#L70 - */ + /** + * A read-only equivalent of jQuery's offset function: http://api.jquery.com/offset/ + * + * Taken from AngularUI Bootstrap Position: + * See https://github.com/angular-ui/bootstrap/blob/master/src/position/position.js#L70 + */ .factory('uisOffset', ['$document', '$window', function ($document, $window) { @@ -247,7 +201,6 @@ uis.directive('uiSelectChoices', uis.controller('uiSelectCtrl', ['$scope', '$element', '$timeout', '$filter', '$q', 'uisRepeatParser', 'uiSelectMinErr', 'uiSelectConfig', function ($scope, $element, $timeout, $filter, $q, RepeatParser, uiSelectMinErr, uiSelectConfig) { - var ctrl = this; var EMPTY_SEARCH = ''; @@ -256,23 +209,23 @@ uis.controller('uiSelectCtrl', ctrl.searchEnabled = uiSelectConfig.searchEnabled; ctrl.sortable = uiSelectConfig.sortable; - ctrl.removeSelected = false; // If selected item(s) should be removed from dropdown list - ctrl.closeOnSelect = true; // Initialized inside uiSelect directive link function + ctrl.removeSelected = false; // If selected item(s) should be removed from dropdown list + ctrl.closeOnSelect = true; // Initialized inside uiSelect directive link function ctrl.search = EMPTY_SEARCH; - ctrl.activeIndex = 0; // Dropdown of choices - ctrl.items = []; // All available choices + ctrl.activeIndex = 0; // Dropdown of choices + ctrl.items = []; // All available choices ctrl.open = false; ctrl.focus = false; ctrl.disabled = false; ctrl.selected = undefined; - ctrl.focusser = undefined; // Reference to input element used to handle focus events + ctrl.focusser = undefined; // Reference to input element used to handle focus events ctrl.resetSearchInput = true; - ctrl.multiple = undefined; // Initialized inside uiSelect directive link function - ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelectChoices directive link function - ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelectMatch directive link function + ctrl.multiple = undefined; // Initialized inside uiSelect directive link function + ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelectChoices directive link function + ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelectMatch directive link function ctrl.clickTriggeredSelect = false; ctrl.$filter = $filter; @@ -282,6 +235,158 @@ uis.controller('uiSelectCtrl', ctrl.searchInput.length); } + // TODO: Maybe make these methods in KEY directly in the controller? + ctrl.KEY = { + TAB: 9, + ENTER: 13, + ESC: 27, + SPACE: 32, + LEFT: 37, + UP: 38, + RIGHT: 39, + DOWN: 40, + SHIFT: 16, + CTRL: 17, + ALT: 18, + PAGE_UP: 33, + PAGE_DOWN: 34, + HOME: 36, + END: 35, + BACKSPACE: 8, + DELETE: 46, + COMMAND: 91, + MAP: { + 91: "COMMAND", + 8: "BACKSPACE", + 9: "TAB", + 13: "ENTER", + 16: "SHIFT", + 17: "CTRL", + 18: "ALT", + 19: "PAUSEBREAK", + 20: "CAPSLOCK", + 27: "ESC", + 32: "SPACE", + 33: "PAGE_UP", + 34: "PAGE_DOWN", + 35: "END", + 36: "HOME", + 37: "LEFT", + 38: "UP", + 39: "RIGHT", + 40: "DOWN", + 43: "+", + 44: "PRINTSCREEN", + 45: "INSERT", + 46: "DELETE", + 48: "0", + 49: "1", + 50: "2", + 51: "3", + 52: "4", + 53: "5", + 54: "6", + 55: "7", + 56: "8", + 57: "9", + 59: ";", + 61: "=", + 65: "A", + 66: "B", + 67: "C", + 68: "D", + 69: "E", + 70: "F", + 71: "G", + 72: "H", + 73: "I", + 74: "J", + 75: "K", + 76: "L", + 77: "M", + 78: "N", + 79: "O", + 80: "P", + 81: "Q", + 82: "R", + 83: "S", + 84: "T", + 85: "U", + 86: "V", + 87: "W", + 88: "X", + 89: "Y", + 90: "Z", + 96: "0", + 97: "1", + 98: "2", + 99: "3", + 100: "4", + 101: "5", + 102: "6", + 103: "7", + 104: "8", + 105: "9", + 106: "*", + 107: "+", + 109: "-", + 110: ".", + 111: "/", + 112: "F1", + 113: "F2", + 114: "F3", + 115: "F4", + 116: "F5", + 117: "F6", + 118: "F7", + 119: "F8", + 120: "F9", + 121: "F10", + 122: "F11", + 123: "F12", + 144: "NUMLOCK", + 145: "SCROLLLOCK", + 186: ";", + 187: "=", + 188: ",", + 189: "-", + 190: ".", + 191: "/", + 192: "`", + 219: "[", + 220: "\\", + 221: "]", + 222: "'" + }, + + isControl: function (e) { + var k = e.which; + switch (k) { + case ctrl.KEY.COMMAND: + case ctrl.KEY.SHIFT: + case ctrl.KEY.CTRL: + case ctrl.KEY.ALT: + return true; + } + + if (e.metaKey) { + return true; + } + + return false; + }, + isFunctionKey: function (k) { + k = k.which ? k.which : k; + return k >= 112 && k <= 123; + }, + isVerticalMovement: function (k) { + return ~[ctrl.KEY.UP, ctrl.KEY.DOWN].indexOf(k); + }, + isHorizontalMovement: function (k) { + return ~[ctrl.KEY.LEFT, ctrl.KEY.RIGHT, ctrl.KEY.BACKSPACE, ctrl.KEY.DELETE].indexOf(k); + } + }; + /** * Returns true if the selection is empty * @returns {boolean|*} @@ -322,6 +427,7 @@ uis.controller('uiSelectCtrl', /** * Activates the control. * When the user clicks on ui-select, displays the dropdown list + * Also called following keyboard input to the search box */ ctrl.activate = function (initSearchValue, avoidReset) { if (!ctrl.disabled && !ctrl.open) { @@ -346,22 +452,15 @@ uis.controller('uiSelectCtrl', }); }; - var result = ctrl.onDropdownCallback($scope, {open: true}); - if (angular.isDefined(result)) { - if (angular.isFunction(result.then)) { - // Promise returned - wait for it to complete before completing the selection - result.then(function (result) { - if (!result) { - return; - } + var result = ctrl.beforeDropdownOpen(); + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (result) { + if (result === true) { completeCallback(); - }); - } else if (result === true) { - completeCallback(); - } else if (result) { - completeCallback(); - } - } else { + } + }); + } else if (result === true) { completeCallback(); } } @@ -471,9 +570,10 @@ uis.controller('uiSelectCtrl', var isActive = itemIndex === -1 ? false : itemIndex === ctrl.activeIndex; // If this is active, and we've defined a callback, do it! - if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { - itemScope.$eval(ctrl.onHighlightCallback); - } + // TODO: Needed? +// if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { +// itemScope.$eval(ctrl.onHighlightCallback); +// } return isActive; }; @@ -518,22 +618,11 @@ uis.controller('uiSelectCtrl', return; } - // Create the data used to pass to the callbacks - var locals = {}; - locals[ctrl.parserResult.itemName] = item; - var callbackContext = { - $item: item, - $model: ctrl.parserResult.modelMapper($scope, locals) - }; - - // Local method called when we complete the select - // eg. called after the onselect callback - var completeCallback = function (item) { - callbackContext.$item = item; + function completeCallback() { $scope.$broadcast('uis:select', item); $timeout(function () { - ctrl.onSelectCallback($scope, callbackContext); + ctrl.afterSelect(item); }); if (ctrl.closeOnSelect) { @@ -542,41 +631,31 @@ uis.controller('uiSelectCtrl', if ($event && $event.type === 'click') { ctrl.clickTriggeredSelect = true; } - }; - - // If there's no onBeforeSelect callback, then just call the completeCallback - if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { - completeCallback(item); - return; } - // Call the onBeforeSelect callback + // Call the beforeSelect method // Allowable responses are -: - // falsy: Abort the selection - // promise: Wait for response + // false: Abort the selection // true: Complete selection + // promise: Wait for response // object: Add the returned object - var result = ctrl.onBeforeSelectCallback($scope, callbackContext); - if (angular.isDefined(result)) { - if (angular.isFunction(result.then)) { - // Promise returned - wait for it to complete before completing the selection - result.then(function (response) { - if (!response) { - return; - } - if (response === true) { - completeCallback(item); - } else if (response) { - completeCallback(response); - } - }); - } else if (result === true) { - completeCallback(item); - } else if (result) { - completeCallback(result); - } - } else { + var result = ctrl.beforeSelect(item); + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (response) { + if (!response) { + return; + } + if (response === true) { + completeCallback(item); + } else if (response) { + completeCallback(response); + } + }); + } else if (result === true) { completeCallback(item); + } else if (result) { + completeCallback(result); } }; @@ -601,22 +680,15 @@ uis.controller('uiSelectCtrl', $scope.$broadcast('uis:close', skipFocusser); } - var result = ctrl.onDropdownCallback($scope, {open: false}); - if (angular.isDefined(result)) { - if (angular.isFunction(result.then)) { - // Promise returned - wait for it to complete before completing the selection - result.then(function (result) { - if (!result) { - return; - } + var result = ctrl.beforeDropdownClose(); + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (result) { + if (result === true) { completeCallback(); - }); - } else if (result === true) { - completeCallback(); - } else if (result) { - completeCallback(); - } - } else { + } + }); + } else if (result === true) { completeCallback(); } }; @@ -706,7 +778,7 @@ uis.controller('uiSelectCtrl', function _handleDropDownSelection(key) { var processed = true; switch (key) { - case KEY.DOWN: + case ctrl.KEY.DOWN: if (!ctrl.open && ctrl.multiple) { // In case its the search input in 'multiple' mode ctrl.activate(false, true); @@ -715,7 +787,7 @@ uis.controller('uiSelectCtrl', ctrl.activeIndex++; } break; - case KEY.UP: + case ctrl.KEY.UP: if (!ctrl.open && ctrl.multiple) { ctrl.activate(false, true); } //In case its the search input in 'multiple' mode @@ -723,21 +795,23 @@ uis.controller('uiSelectCtrl', ctrl.activeIndex--; } break; - case KEY.TAB: + case ctrl.KEY.TAB: if (!ctrl.multiple || ctrl.open) { ctrl.select(ctrl.items[ctrl.activeIndex], true); } break; - case KEY.ENTER: + case ctrl.KEY.ENTER: if (ctrl.open) { // Make sure at least one dropdown item is highlighted before adding - ctrl.select(ctrl.items[ctrl.activeIndex]); + if (ctrl.items[ctrl.activeIndex] !== undefined) { + ctrl.select(ctrl.items[ctrl.activeIndex]); + } } else { // In case its the search input in 'multiple' mode ctrl.activate(false, true); } break; - case KEY.ESC: + case ctrl.KEY.ESC: ctrl.close(); break; default: @@ -748,39 +822,42 @@ uis.controller('uiSelectCtrl', // Bind to keyboard shortcuts ctrl.searchInput.on('keydown', function (e) { - var key = e.which; - // if(~[KEY.ESC,KEY.TAB].indexOf(key)){ - // //TODO: SEGURO? - // ctrl.close(); - // } + if (~[ctrl.KEY.ESC, ctrl.KEY.TAB].indexOf(key)) { + // TODO: SEGURO? + ctrl.close(); + } $scope.$apply(function () { _handleDropDownSelection(key); }); - if (KEY.isVerticalMovement(key) && ctrl.items.length > 0) { + if (ctrl.KEY.isVerticalMovement(key) && ctrl.items.length > 0) { _ensureHighlightVisible(); } - if (key === KEY.ENTER || key === KEY.ESC) { + if (key === ctrl.KEY.ENTER || key === ctrl.KEY.ESC) { e.preventDefault(); e.stopPropagation(); } + + // Let the users process the data + // TODO: Is this needed, or just let the user bind to the event themselves! +// ctrl.afterKeypress(e); }); ctrl.searchInput.on('keyup', function (e) { // return early with these keys - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || - KEY.isVerticalMovement(e.which)) { + if (e.which === ctrl.KEY.TAB || ctrl.KEY.isControl(e) || ctrl.KEY.isFunctionKey(e) || + e.which === ctrl.KEY.ESC || + ctrl.KEY.isVerticalMovement(e.which)) { return; } - if (ctrl.onKeypressCallback === undefined) { - return; - } - ctrl.onKeypressCallback($scope, {event: e}); + // Let the users process the data + // TODO: Is this needed, or just let the user bind to the event themselves! + ctrl.afterKeypress(e); }); // See https://github.com/ivaynberg/select2/blob/3.4.6/select2.js#L1431 @@ -817,6 +894,89 @@ uis.controller('uiSelectCtrl', ctrl.searchInput.off('keyup keydown blur paste'); }); + /** + * Keypress callback. Overridable. + * @param event the keypress event + */ + /* jshint unused:false */ + ctrl.afterKeypress = function (event) { + }; + + /** + * Method called before a selection is made. This can be overridden to allow + * the selection to be aborted, or a modified version of the selected item to be + * returned. + * + * Allowable responses are -: + * false: Abort the selection + * true: Complete selection with the selected object + * object: Complete the selection with the returned object + * promise: Wait for response - response from promise is as above + * + * @param item the item that has been selected + * @returns {*} + */ + ctrl.beforeSelect = function (item) { + return true; + }; + + /** + * Method called after a selection is confirmed. This can be overridden to allow + * the application to be notified of a newly selected item. + * No return is required. + * + * @param item the item that has been selected + */ + ctrl.afterSelect = function (item) { + }; + + /** + * Method called before an item is removed from the selected list. This can be overridden + * to allow the removal to be aborted + * + * Allowable responses are -: + * false: Abort the selection + * true: Complete selection with the selected object + * object: Complete the selection with the returned object + * promise: Wait for response - response from promise is as above + * + * @param item the item that has been selected + * @returns {*} + */ + ctrl.beforeRemove = function (item) { + return true; + }; + + /** + * Method called after a item is removed. This can be overridden to allow + * the application to be notified of a removed item. + * No return is required. + * + * @param item the item that has been removed + */ + ctrl.afterRemove = function (item) { + }; + + /** + * Method called before the dropdown is opened. This can be overridden to allow + * the application to process data before the dropdown is displayed. + * The method may return a promise, or true to allow the dropdown, or false to abort. + * @returns {boolean} + */ + ctrl.beforeDropdownOpen = function () { + return true; + }; + + /** + * Method called before the dropdown is closed. This can be overridden to allow + * the application to prevent the dropdown from closing. + * The method may return a promise, or true to allow the dropdown to close, or false to abort. + * @returns {boolean} + */ + ctrl.beforeDropdownClose = function () { + return true; + }; + }]); uis.directive('uiSelect', @@ -863,13 +1023,6 @@ uis.directive('uiSelect', } }(); - $select.onSelectCallback = $parse(attrs.onSelect); - $select.onBeforeSelectCallback = $parse(attrs.onBeforeSelect); - $select.onRemoveCallback = $parse(attrs.onRemove); - $select.onBeforeRemoveCallback = $parse(attrs.onBeforeRemove); - $select.onKeypressCallback = $parse(attrs.onKeypress); - $select.onDropdownCallback = $parse(attrs.onDropdown); - // Limit the number of selections allowed $select.limit = (angular.isDefined(attrs.limit)) ? parseInt(attrs.limit, 10) : undefined; @@ -936,10 +1089,9 @@ uis.directive('uiSelect', // Will lose focus only with certain targets var focusableControls = ['input', 'button', 'textarea']; // To check if target is other ui-select - var targetScope = angular.element(e.target).scope(); + var targetController = angular.element(e.target).controller('uiSelect'); // To check if target is other ui-select - var skipFocusser = targetScope && targetScope.$select && - targetScope.$select !== $select; + var skipFocusser = targetController && targetController !== $select; // Check if target is input, button or textarea if (!skipFocusser) { skipFocusser = ~focusableControls.indexOf(e.target.tagName.toLowerCase()); @@ -1068,7 +1220,8 @@ uis.directive('uiSelect', var offsetDropdown = uisOffset(dropdown); // Determine if the direction of the dropdown needs to be changed. - if (offset.top + offset.height + offsetDropdown.height > $window.pageYOffset + $document[0].documentElement.clientHeight) { + if (offset.top + offset.height + offsetDropdown.height > + $window.pageYOffset + $document[0].documentElement.clientHeight) { element.addClass(directionUpClassName); } @@ -1103,6 +1256,8 @@ uis.directive('uiSelectMatch', ['uiSelectConfig', function (uiSelectConfig) { }, link: function (scope, element, attrs, $select) { $select.lockChoiceExpression = attrs.uiLockChoice; + + // TODO: observe required? attrs.$observe('placeholder', function (placeholder) { $select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder; }); @@ -1112,6 +1267,7 @@ uis.directive('uiSelectMatch', ['uiSelectConfig', function (uiSelectConfig) { (angular.isDefined(allow)) ? (allow === '') ? true : (allow.toLowerCase() === 'true') : false; } + // TODO: observe required? attrs.$observe('allowClear', setAllowClear); setAllowClear(attrs.allowClear); @@ -1157,65 +1313,47 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel * Then calls onRemove to notify the user the item has been removed */ ctrl.removeChoice = function (index) { + // Get the removed choice var removedChoice = $select.selected[index]; - // if the choice is locked, can't remove it + // If the choice is locked, can't remove it if (removedChoice._uiSelectChoiceLocked) { return; } - var locals = {}; - locals[$select.parserResult.itemName] = removedChoice; - - $select.selected.splice(index, 1); - ctrl.activeMatchIndex = -1; - $select.sizeSearchInput(); - - var callbackContext = { - $item: removedChoice, - $model: $select.parserResult.modelMapper($scope, locals) - }; - // Give some time for scope propagation. function completeCallback() { + $select.selected.splice(index, 1); + ctrl.activeMatchIndex = -1; + $select.sizeSearchInput(); + $timeout(function () { - $select.onRemoveCallback($scope, callbackContext); + $select.afterRemove(removedChoice); }); ctrl.updateModel(); } - // If there's no onBeforeRemove callback, then just call the completeCallback - if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { - completeCallback(); - return; - } - - // Call the onBeforeRemove callback + // Call the beforeRemove callback // Allowable responses are -: - // falsy: Abort the removal - // promise: Wait for response + // false: Abort the removal // true: Complete removal - var result = ctrl.onBeforeRemoveCallback($scope, callbackContext); - if (angular.isDefined(result)) { - if (angular.isFunction(result.then)) { - // Promise returned - wait for it to complete before completing the selection - result.then(function (result) { - if (!result) { - return; - } - completeCallback(result); - }); - } else if (result === true) { - completeCallback(); - } - } else { + // promise: Wait for response + var result = $select.beforeRemove(removedChoice); + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (result) { + if (result === true) { + completeCallback(); + } + }); + } else if (result === true) { completeCallback(); } }; ctrl.getPlaceholder = function () { - //Refactor single? + // Refactor single? if ($select.selected && $select.selected.length) { return; } @@ -1343,17 +1481,18 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel var key = e.which; scope.$apply(function () { var processed = false; - if (KEY.isHorizontalMovement(key)) { + if ($select.KEY.isHorizontalMovement(key)) { processed = _handleMatchSelection(key); } - if (processed && key != KEY.TAB) { - //TODO Check si el tab selecciona aun correctamente - //Crear test + if (processed && key != $select.KEY.TAB) { + // TODO Check si el tab selecciona aun correctamente + //Creat test // e.preventDefault(); // e.stopPropagation(); } }); }); + function _getCaretPosition(el) { if (angular.isNumber(el.selectionStart)) { return el.selectionStart; @@ -1375,7 +1514,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel prev = $selectMultiple.activeMatchIndex - 1, newIndex = curr; - if (caretPosition > 0 || ($select.search.length && key == KEY.RIGHT)) { + if (caretPosition > 0 || ($select.search.length && key == $select.KEY.RIGHT)) { return false; } @@ -1383,7 +1522,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel function getNewActiveMatchIndex() { switch (key) { - case KEY.LEFT: + case $select.KEY.LEFT: // Select previous/first item if (~$selectMultiple.activeMatchIndex) { return prev; @@ -1393,7 +1532,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel return last; } break; - case KEY.RIGHT: + case $select.KEY.RIGHT: // Open drop-down if (!~$selectMultiple.activeMatchIndex || curr === last) { $select.activate(); @@ -1404,7 +1543,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel return next; } break; - case KEY.BACKSPACE: + case $select.KEY.BACKSPACE: // Remove selected item and select previous/first if (~$selectMultiple.activeMatchIndex) { $selectMultiple.removeChoice(curr); @@ -1415,7 +1554,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel return last; } break; - case KEY.DELETE: + case $select.KEY.DELETE: // Remove selected item and select next item if (~$selectMultiple.activeMatchIndex) { $selectMultiple.removeChoice($selectMultiple.activeMatchIndex); @@ -1539,7 +1678,7 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co }); focusser.bind("keydown", function (e) { - if (e.which === KEY.BACKSPACE) { + if (e.which === $select.KEY.BACKSPACE) { e.preventDefault(); e.stopPropagation(); $select.select(undefined); @@ -1547,11 +1686,11 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co return; } - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) { + if (e.which === $select.KEY.TAB || $select.KEY.isControl(e) || $select.KEY.isFunctionKey(e) || e.which === $select.KEY.ESC) { return; } - if (e.which == KEY.DOWN || e.which == KEY.UP || e.which == KEY.ENTER || e.which == KEY.SPACE) { + if (e.which == $select.KEY.DOWN || e.which == $select.KEY.UP || e.which == $select.KEY.ENTER || e.which == $select.KEY.SPACE) { e.preventDefault(); e.stopPropagation(); $select.activate(); @@ -1561,8 +1700,8 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co }); focusser.bind("keyup input", function (e) { - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || - e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { + if (e.which === $select.KEY.TAB || $select.KEY.isControl(e) || $select.KEY.isFunctionKey(e) || e.which === $select.KEY.ESC || + e.which == $select.KEY.ENTER || e.which === $select.KEY.BACKSPACE) { return; } diff --git a/dist/select.selectize.min.js b/dist/select.selectize.min.js index 8fd8b5aa7..6f025c33c 100644 --- a/dist/select.selectize.min.js +++ b/dist/select.selectize.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-06T13:28:34.967Z + * Version: 0.12.1 - 2015-08-09T18:09:19.185Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,isControl:function(t){var n=t.which;switch(n){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,n=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,i,c){c(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var i=n[0].getBoundingClientRect();return{width:i.width||n.prop("offsetWidth"),height:i.height||n.prop("offsetHeight"),top:i.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:i.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);n.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,c){if(!c.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,c,r,l,s){var o=r.groupBy,a=r.groupFilter;if(l.parseRepeatAttr(r.repeat,o,a),l.disableChoiceExpression=r.uiDisableChoice,l.onHighlightCallback=r.onHighlight,o){var u=c.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=c.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(l.parserResult.itemName,"$select.items",l.parserResult.trackByExp,o)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+l.parserResult.itemName+")").attr("ng-click","$select.select("+l.parserResult.itemName+",false,$event)");var d=c.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),i(c,s)(e),e.$watch("$select.search",function(e){e&&!l.open&&l.multiple&&l.activate(!1,!0),l.activeIndex=0})}}}}]),n.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,n,i,c,r,l,s,o){function a(){(f.resetSearchInput||void 0===f.resetSearchInput&&o.resetSearchInput)&&(f.search=h,f.selected&&f.items.length&&!f.multiple&&(f.activeIndex=f.items.indexOf(f.selected)))}function u(e,t){var n,i,c=[];for(n=0;n0&&f.activeIndex--;break;case e.TAB:(!f.multiple||f.open)&&f.select(f.items[f.activeIndex],!0);break;case e.ENTER:f.open?f.select(f.items[f.activeIndex]):f.activate(!1,!0);break;case e.ESC:f.close();break;default:n=!1}return n}function d(){var e=n.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw s("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(f.activeIndex<0)){var i=t[f.activeIndex],c=i.offsetTop+i.clientHeight-e[0].scrollTop,r=e[0].offsetHeight;c>r?e[0].scrollTop+=c-r:c=f.items.length?0:f.activeIndex,i(function(){f.search=e||f.search,f.searchInput[0].focus()})},r=f.onDropdownCallback(t,{open:!0});angular.isDefined(r)?angular.isFunction(r.then)?r.then(function(e){e&&c()}):r===!0?c():r&&c():c()}},f.parseRepeatAttr=function(e,n,i){function c(e){var c=t.$eval(n);if(f.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(c)?c(e):e[c],n=f.findGroupByName(t);n?n.items.push(e):f.groups.push({name:t,items:[e]})}),i){var r=t.$eval(i);angular.isFunction(r)?f.groups=r(f.groups):angular.isArray(r)&&(f.groups=u(f.groups,r))}f.items=[],f.groups.forEach(function(e){f.items=f.items.concat(e.items)})}function r(e){f.items=e}f.setItemsFn=n?c:r,f.parserResult=l.parse(e),f.isGrouped=!!n,f.itemProperty=f.parserResult.itemName,f.refreshItems=function(e){e=e||f.parserResult.source(t);var n=f.selected;if(f.isEmpty()||angular.isArray(n)&&!n.length||!f.removeSelected)f.setItemsFn(e);else if(void 0!==e){var i=e.filter(function(e){return n.indexOf(e)<0});f.setItemsFn(i)}},t.$watchCollection(f.parserResult.source,function(e){if(void 0===e||null===e)f.items=[];else{if(!angular.isArray(e))throw s("items","Expected an array but got '{0}'.",e);f.refreshItems(e),f.ngModel.$modelValue=null}})},f.setActiveItem=function(e){f.activeIndex=f.items.indexOf(e)},f.isActive=function(e){if(!f.open)return!1;var t=f.items.indexOf(e[f.itemProperty]),n=-1===t?!1:t===f.activeIndex;return n&&!angular.isUndefined(f.onHighlightCallback)&&e.$eval(f.onHighlightCallback),n},f.isDisabled=function(e){if(!f.open)return!1;var t,n=f.items.indexOf(e[f.itemProperty]),i=!1;return n>=0&&!angular.isUndefined(f.disableChoiceExpression)&&(t=f.items[n],i=!!e.$eval(f.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i},f.select=function(e,n,c){if((void 0===e||!e._uiSelectChoiceDisabled)&&(f.items||f.search)){var r={};r[f.parserResult.itemName]=e;var l={$item:e,$model:f.parserResult.modelMapper(t,r)},s=function(e){l.$item=e,t.$broadcast("uis:select",e),i(function(){f.onSelectCallback(t,l)}),f.closeOnSelect&&f.close(n),c&&"click"===c.type&&(f.clickTriggeredSelect=!0)};if(!angular.isDefined(f.onBeforeRemoveCallback))return s(e),void 0;var o=f.onBeforeSelectCallback(t,l);angular.isDefined(o)?angular.isFunction(o.then)?o.then(function(t){t&&(t===!0?s(e):t&&s(t))}):o===!0?s(e):o&&s(o):s(e)}},f.close=function(e){function n(){f.ngModel&&f.ngModel.$setTouched&&f.ngModel.$setTouched(),a(),f.open=!1,f.searchEnabled||angular.element(f.searchInput[0]).removeClass("ui-select-offscreen"),t.$broadcast("uis:close",e)}if(f.open){var i=f.onDropdownCallback(t,{open:!1});angular.isDefined(i)?angular.isFunction(i.then)?i.then(function(e){e&&n()}):i===!0?n():i&&n():n()}},f.setFocus=function(){f.focus||f.focusInput[0].focus()},f.clear=function(e){f.select(void 0),e.stopPropagation(),i(function(){f.focusser[0].focus()},0,!1)},f.toggle=function(e){f.open?(f.close(),e.preventDefault(),e.stopPropagation()):f.activate()},f.isLocked=function(e,t){var n,i=f.selected[t];return i&&!angular.isUndefined(f.lockChoiceExpression)&&(n=!!e.$eval(f.lockChoiceExpression),i._uiSelectChoiceLocked=n),n};var v=null;f.sizeSearchInput=function(){var e=f.searchInput[0],n=f.searchInput.parent().parent()[0],c=function(){return n.clientWidth*!!e.offsetParent},r=function(t){if(0===t)return!1;var n=t-e.offsetLeft-f.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=t),f.searchInput.css("width",n+"px"),!0};f.searchInput.css("width","10px"),i(function(){null!==v||r(c())||(v=t.$watch(c,function(e){r(e)&&(v(),v=null)}))})},f.searchInput.on("keydown",function(n){var i=n.which;t.$apply(function(){p(i)}),e.isVerticalMovement(i)&&f.items.length>0&&d(),(i===e.ENTER||i===e.ESC)&&(n.preventDefault(),n.stopPropagation())}),f.searchInput.on("keyup",function(n){n.which===e.TAB||e.isControl(n)||e.isFunctionKey(n)||n.which===e.ESC||e.isVerticalMovement(n.which)||void 0!==f.onKeypressCallback&&f.onKeypressCallback(t,{event:n})}),t.$on("$destroy",function(){f.searchInput.off("keyup keydown blur paste")})}]),n.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,i,c,r,l,s){return{restrict:"EA",templateUrl:function(e,t){var i=t.theme||n.theme;return i+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(r,o){return angular.isDefined(o.multiple)?r.append("").removeAttr("multiple"):r.append(""),function(r,o,a,u,p){function d(e){if(v.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(o[0],e.target):o[0].contains(e.target),!t&&!v.clickTriggeredSelect){var n=["input","button","textarea"],i=angular.element(e.target).scope(),c=i&&i.$select&&i.$select!==v;c||(c=~n.indexOf(e.target.tagName.toLowerCase())),v.close(c),r.$digest()}v.clickTriggeredSelect=!1}}function f(){var t=c(o);w=angular.element('
    '),w[0].style.width=t.width+"px",w[0].style.height=t.height+"px",o.after(w),E=o[0].style.width,e.find("body").append(o),o[0].style.position="absolute",o[0].style.left=t.left+"px",o[0].style.top=t.top+"px",o[0].style.width=t.width+"px"}function h(){null!==w&&(w.replaceWith(o),w=null,o[0].style.position="",o[0].style.left="",o[0].style.top="",o[0].style.width=E)}var v=u[0],g=u[1];v.generatedId=n.generateId(),v.baseTitle=a.title||"Select box",v.focusserTitle=v.baseTitle+" focus",v.focusserId="focusser-"+v.generatedId,v.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?l(a.closeOnSelect)():n.closeOnSelect}(),v.onSelectCallback=l(a.onSelect),v.onBeforeSelectCallback=l(a.onBeforeSelect),v.onRemoveCallback=l(a.onRemove),v.onBeforeRemoveCallback=l(a.onBeforeRemove),v.onKeypressCallback=l(a.onKeypress),v.onDropdownCallback=l(a.onDropdown),v.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,v.ngModel=g,v.choiceGrouped=function(e){return v.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){v.focusInput.attr("tabindex",e),o.removeAttr("tabindex")});var m=r.$eval(a.searchEnabled);v.searchEnabled=void 0!==m?m:n.searchEnabled;var $=r.$eval(a.sortable);v.sortable=void 0!==$?$:n.sortable,a.$observe("disabled",function(){v.disabled=void 0!==a.disabled?a.disabled:!1}),angular.isDefined(a.autofocus)&&s(function(){v.setFocus()}),angular.isDefined(a.focusOn)&&r.$on(a.focusOn,function(){s(function(){v.setFocus()})}),e.on("click",d),r.$on("$destroy",function(){e.off("click",d)}),p(r,function(e){var t=angular.element("
    ").append(e),n=t.querySelectorAll(".ui-select-match");if(n.removeAttr("ui-select-match"),n.removeAttr("data-ui-select-match"),1!==n.length)throw i("transcluded","Expected 1 .ui-select-match but got '{0}'.",n.length);o.querySelectorAll(".ui-select-match").replaceWith(n);var c=t.querySelectorAll(".ui-select-choices");if(c.removeAttr("ui-select-choices"),c.removeAttr("data-ui-select-choices"),1!==c.length)throw i("transcluded","Expected 1 .ui-select-choices but got '{0}'.",c.length);o.querySelectorAll(".ui-select-choices").replaceWith(c)});var b=r.$eval(a.appendToBody);(void 0!==b?b:n.appendToBody)&&(r.$watch("$select.open",function(e){e?f():h()}),r.$on("$destroy",function(){h()}));var w=null,E="",S=null,y="direction-up";r.$watch("$select.open",function(n){if(n){if(S=angular.element(o).querySelectorAll(".ui-select-dropdown"),null===S)return;S[0].style.opacity=0,s(function(){var n=c(o),i=c(S);n.top+n.height+i.height>t.pageYOffset+e[0].documentElement.clientHeight&&o.addClass(y),S[0].style.opacity=1})}else{if(null===S)return;o.removeClass(y)}})}}}}]),n.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return n+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,i,c){function r(e){c.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}c.lockChoiceExpression=i.uiLockChoice,i.$observe("placeholder",function(t){c.placeholder=void 0!==t?t:e.placeholder}),i.$observe("allowClear",r),r(i.allowClear),c.multiple&&c.sizeSearchInput()}}}]),n.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,i=this,c=e.$select;e.$evalAsync(function(){n=e.ngModel}),i.activeMatchIndex=-1,i.updateModel=function(){n.$setViewValue(Date.now()),i.refreshComponent()},i.refreshComponent=function(){c.refreshItems(),c.sizeSearchInput()},i.removeChoice=function(n){function r(){t(function(){c.onRemoveCallback(e,o)}),i.updateModel()}var l=c.selected[n];if(!l._uiSelectChoiceLocked){var s={};s[c.parserResult.itemName]=l,c.selected.splice(n,1),i.activeMatchIndex=-1,c.sizeSearchInput();var o={$item:l,$model:c.parserResult.modelMapper(e,s)};if(!angular.isDefined(i.onBeforeRemoveCallback))return r(),void 0;var a=i.onBeforeRemoveCallback(e,o);angular.isDefined(a)?angular.isFunction(a.then)?a.then(function(e){e&&r(e)}):a===!0&&r():r()}},i.getPlaceholder=function(){return c.selected&&c.selected.length?void 0:c.placeholder}}],controllerAs:"$selectMultiple",link:function(i,c,r,l){function s(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function o(t){function n(){switch(t){case e.LEFT:return~p.activeMatchIndex?d:l;case e.RIGHT:return~p.activeMatchIndex&&o!==l?u:(a.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(o),d):l;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),o):!1}}var i=s(a.searchInput[0]),c=a.selected.length,r=0,l=c-1,o=p.activeMatchIndex,u=p.activeMatchIndex+1,d=p.activeMatchIndex-1,f=o;return i>0||a.search.length&&t==e.RIGHT?!1:(a.close(),f=n(),p.activeMatchIndex=a.selected.length&&f!==!1?Math.min(l,Math.max(r,f)):-1,!0)}var a=l[0],u=i.ngModel=l[1],p=i.$selectMultiple;a.multiple=!0,a.removeSelected=!0,a.focusInput=a.searchInput,u.$parsers.unshift(function(){for(var e,t={},n=[],c=a.selected.length-1;c>=0;c--)t={},t[a.parserResult.itemName]=a.selected[c],e=a.parserResult.modelMapper(i,t),n.unshift(e);return n}),u.$formatters.unshift(function(e){var t,n=a.parserResult.source(i,{$select:{search:""}}),c={};if(!n)return e;var r=[],l=function(e,n){if(e&&e.length){for(var l=e.length-1;l>=0;l--){if(c[a.parserResult.itemName]=e[l],t=a.parserResult.modelMapper(i,c),a.parserResult.trackByExp){var s=/\.(.+)/.exec(a.parserResult.trackByExp);if(s.length>0&&t[s[1]]==n[s[1]])return r.unshift(e[l]),!0}if(angular.equals(t,n))return r.unshift(e[l]),!0}return!1}};if(!e)return r;for(var s=e.length-1;s>=0;s--)l(a.selected,e[s])||l(n,e[s])||r.unshift(e[s]);return r}),i.$watchCollection(function(){return u.$modelValue},function(e,t){t!=e&&(u.$modelValue=null,p.refreshComponent())}),u.$render=function(){if(!angular.isArray(u.$viewValue)){if(!angular.isUndefined(u.$viewValue)&&null!==u.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",u.$viewValue);a.selected=[]}a.selected=u.$viewValue,i.$evalAsync()},i.$on("uis:select",function(e,t){a.selected.length>=a.limit||(a.selected.push(t),p.updateModel())}),i.$on("uis:activate",function(){p.activeMatchIndex=-1}),i.$watch("$select.disabled",function(e,t){t&&!e&&a.sizeSearchInput()}),a.searchInput.on("keydown",function(t){var n=t.which;i.$apply(function(){var t=!1;e.isHorizontalMovement(n)&&(t=o(n)),t&&n!=e.TAB})}),a.searchInput.on("blur",function(){n(function(){p.activeMatchIndex=-1})})}}}]),n.directive("uiSelectSingle",["$timeout","$compile",function(t,n){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(i,c,r,l){var s=l[0],o=l[1];o.$parsers.unshift(function(e){var t,n={};return n[s.parserResult.itemName]=e,t=s.parserResult.modelMapper(i,n)}),o.$formatters.unshift(function(e){var t,n=s.parserResult.source(i,{$select:{search:""}}),c={};if(n){var r=function(n){return c[s.parserResult.itemName]=n,t=s.parserResult.modelMapper(i,c),t==e};if(s.selected&&r(s.selected))return s.selected;for(var l=n.length-1;l>=0;l--)if(r(n[l]))return n[l]}return e}),i.$watch("$select.selected",function(e){o.$viewValue!==e&&o.$setViewValue(e)}),o.$render=function(){s.selected=o.$viewValue},i.$on("uis:select",function(e,t){s.selected=t}),i.$on("uis:close",function(e,n){t(function(){s.focusser.prop("disabled",!1),n||s.focusser[0].focus()},0,!1)}),i.$on("uis:activate",function(){a.prop("disabled",!0)});var a=angular.element("");n(a)(i),s.focusser=a,s.focusInput=a,c.parent().append(a),a.bind("focus",function(){i.$evalAsync(function(){s.focus=!0})}),a.bind("blur",function(){i.$evalAsync(function(){s.focus=!1})}),a.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),s.select(void 0),i.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),s.activate()),i.$digest()),void 0)}),a.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(s.activate(a.val()),a.val(""),i.$digest())})}}}]),n.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var i=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!i)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:i[2],source:t(i[3]),trackByExp:i[4],modelMapper:t(i[1]||i[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,i){var c=e+" in "+(i?"$group.items":t);return n&&(c+=" track by "+n),c}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("selectize/choices.tpl.html",'
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file +!function(){"use strict";void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var e=0,t=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return e++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,i,c){c(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return t=String(t),n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var i=n[0].getBoundingClientRect();return{width:i.width||n.prop("offsetWidth"),height:i.height||n.prop("offsetHeight"),top:i.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:i.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);t.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,c){if(!c.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,c,r,l,s){var o=r.groupBy,a=r.groupFilter;if(l.parseRepeatAttr(r.repeat,o,a),l.disableChoiceExpression=r.uiDisableChoice,l.onHighlightCallback=r.onHighlight,o){var u=c.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=c.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(l.parserResult.itemName,"$select.items",l.parserResult.trackByExp,o)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+l.parserResult.itemName+")").attr("ng-click","$select.select("+l.parserResult.itemName+",false,$event)");var d=c.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),i(c,s)(e),e.$watch("$select.search",function(e){e&&!l.open&&l.multiple&&l.activate(!1,!0),l.activeIndex=0})}}}}]),t.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(e,t,n,i,c,r,l,s){function o(){(d.resetSearchInput||void 0===d.resetSearchInput&&s.resetSearchInput)&&(d.search=f,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function a(e,t){var n,i,c=[];for(n=0;n0&&d.activeIndex--;break;case d.KEY.TAB:(!d.multiple||d.open)&&d.select(d.items[d.activeIndex],!0);break;case d.KEY.ENTER:d.open?void 0!==d.items[d.activeIndex]&&d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case d.KEY.ESC:d.close();break;default:t=!1}return t}function p(){var e=t.querySelectorAll(".ui-select-choices-content"),n=e.querySelectorAll(".ui-select-choices-row");if(n.length<1)throw l("choices","Expected multiple .ui-select-choices-row but got '{0}'.",n.length);if(!(d.activeIndex<0)){var i=n[d.activeIndex],c=i.offsetTop+i.clientHeight-e[0].scrollTop,r=e[0].offsetHeight;c>r?e[0].scrollTop+=c-r:c=112&&123>=e},isVerticalMovement:function(e){return~[d.KEY.UP,d.KEY.DOWN].indexOf(e)},isHorizontalMovement:function(e){return~[d.KEY.LEFT,d.KEY.RIGHT,d.KEY.BACKSPACE,d.KEY.DELETE].indexOf(e)}},d.isEmpty=function(){return angular.isUndefined(d.selected)||null===d.selected||""===d.selected},d.findGroupByName=function(e){return d.groups&&d.groups.filter(function(t){return t.name===e})[0]},d.activate=function(t,i){if(d.disabled||d.open)d.open&&!d.searchEnabled&&d.close();else{var c=function(){i||o(),e.$broadcast("uis:activate"),d.open=!0,d.searchEnabled||angular.element(d.searchInput[0]).addClass("ui-select-offscreen"),d.activeIndex=d.activeIndex>=d.items.length?0:d.activeIndex,n(function(){d.search=t||d.search,d.searchInput[0].focus()})},r=d.beforeDropdownOpen();angular.isFunction(r.then)?r.then(function(e){e===!0&&c()}):r===!0&&c()}},d.parseRepeatAttr=function(t,n,i){function c(t){var c=e.$eval(n);if(d.groups=[],angular.forEach(t,function(e){var t=angular.isFunction(c)?c(e):e[c],n=d.findGroupByName(t);n?n.items.push(e):d.groups.push({name:t,items:[e]})}),i){var r=e.$eval(i);angular.isFunction(r)?d.groups=r(d.groups):angular.isArray(r)&&(d.groups=a(d.groups,r))}d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function s(e){d.items=e}d.setItemsFn=n?c:s,d.parserResult=r.parse(t),d.isGrouped=!!n,d.itemProperty=d.parserResult.itemName,d.refreshItems=function(t){t=t||d.parserResult.source(e);var n=d.selected;if(d.isEmpty()||angular.isArray(n)&&!n.length||!d.removeSelected)d.setItemsFn(t);else if(void 0!==t){var i=t.filter(function(e){return n.indexOf(e)<0});d.setItemsFn(i)}},e.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw l("items","Expected an array but got '{0}'.",e);d.refreshItems(e),d.ngModel.$modelValue=null}})},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){if(!d.open)return!1;var t=d.items.indexOf(e[d.itemProperty]),n=-1===t?!1:t===d.activeIndex;return n},d.isDisabled=function(e){if(!d.open)return!1;var t,n=d.items.indexOf(e[d.itemProperty]),i=!1;return n>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[n],i=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i},d.select=function(t,i,c){function r(){e.$broadcast("uis:select",t),n(function(){d.afterSelect(t)}),d.closeOnSelect&&d.close(i),c&&"click"===c.type&&(d.clickTriggeredSelect=!0)}if((void 0===t||!t._uiSelectChoiceDisabled)&&(d.items||d.search)){var l=d.beforeSelect(t);angular.isFunction(l.then)?l.then(function(e){e&&(e===!0?r(t):e&&r(e))}):l===!0?r(t):l&&r(l)}},d.close=function(t){function n(){d.ngModel&&d.ngModel.$setTouched&&d.ngModel.$setTouched(),o(),d.open=!1,d.searchEnabled||angular.element(d.searchInput[0]).removeClass("ui-select-offscreen"),e.$broadcast("uis:close",t)}if(d.open){var i=d.beforeDropdownClose();angular.isFunction(i.then)?i.then(function(e){e===!0&&n()}):i===!0&&n()}},d.setFocus=function(){d.focus||d.focusInput[0].focus()},d.clear=function(e){d.select(void 0),e.stopPropagation(),n(function(){d.focusser[0].focus()},0,!1)},d.toggle=function(e){d.open?(d.close(),e.preventDefault(),e.stopPropagation()):d.activate()},d.isLocked=function(e,t){var n,i=d.selected[t];return i&&!angular.isUndefined(d.lockChoiceExpression)&&(n=!!e.$eval(d.lockChoiceExpression),i._uiSelectChoiceLocked=n),n};var h=null;d.sizeSearchInput=function(){var t=d.searchInput[0],i=d.searchInput.parent().parent()[0],c=function(){return i.clientWidth*!!t.offsetParent},r=function(e){if(0===e)return!1;var n=e-t.offsetLeft-d.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=e),d.searchInput.css("width",n+"px"),!0};d.searchInput.css("width","10px"),n(function(){null!==h||r(c())||(h=e.$watch(c,function(e){r(e)&&(h(),h=null)}))})},d.searchInput.on("keydown",function(t){var n=t.which;~[d.KEY.ESC,d.KEY.TAB].indexOf(n)&&d.close(),e.$apply(function(){u(n)}),d.KEY.isVerticalMovement(n)&&d.items.length>0&&p(),(n===d.KEY.ENTER||n===d.KEY.ESC)&&(t.preventDefault(),t.stopPropagation())}),d.searchInput.on("keyup",function(e){e.which===d.KEY.TAB||d.KEY.isControl(e)||d.KEY.isFunctionKey(e)||e.which===d.KEY.ESC||d.KEY.isVerticalMovement(e.which)||d.afterKeypress(e)}),e.$on("$destroy",function(){d.searchInput.off("keyup keydown blur paste")}),d.afterKeypress=function(){},d.beforeSelect=function(){return!0},d.afterSelect=function(){},d.beforeRemove=function(){return!0},d.afterRemove=function(){},d.beforeDropdownOpen=function(){return!0},d.beforeDropdownClose=function(){return!0}}]),t.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,i,c,r,l,s){return{restrict:"EA",templateUrl:function(e,t){var i=t.theme||n.theme;return i+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(r,o){return angular.isDefined(o.multiple)?r.append("").removeAttr("multiple"):r.append(""),function(r,o,a,u,p){function d(e){if(v.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(o[0],e.target):o[0].contains(e.target),!t&&!v.clickTriggeredSelect){var n=["input","button","textarea"],i=angular.element(e.target).controller("uiSelect"),c=i&&i!==v;c||(c=~n.indexOf(e.target.tagName.toLowerCase())),v.close(c),r.$digest()}v.clickTriggeredSelect=!1}}function f(){var t=c(o);S=angular.element('
    '),S[0].style.width=t.width+"px",S[0].style.height=t.height+"px",o.after(S),b=o[0].style.width,e.find("body").append(o),o[0].style.position="absolute",o[0].style.left=t.left+"px",o[0].style.top=t.top+"px",o[0].style.width=t.width+"px"}function h(){null!==S&&(S.replaceWith(o),S=null,o[0].style.position="",o[0].style.left="",o[0].style.top="",o[0].style.width=b)}var v=u[0],g=u[1];v.generatedId=n.generateId(),v.baseTitle=a.title||"Select box",v.focusserTitle=v.baseTitle+" focus",v.focusserId="focusser-"+v.generatedId,v.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?l(a.closeOnSelect)():n.closeOnSelect}(),v.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,v.ngModel=g,v.choiceGrouped=function(e){return v.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){v.focusInput.attr("tabindex",e),o.removeAttr("tabindex")});var m=r.$eval(a.searchEnabled);v.searchEnabled=void 0!==m?m:n.searchEnabled;var E=r.$eval(a.sortable);v.sortable=void 0!==E?E:n.sortable,a.$observe("disabled",function(){v.disabled=void 0!==a.disabled?a.disabled:!1}),angular.isDefined(a.autofocus)&&s(function(){v.setFocus()}),angular.isDefined(a.focusOn)&&r.$on(a.focusOn,function(){s(function(){v.setFocus()})}),e.on("click",d),r.$on("$destroy",function(){e.off("click",d)}),p(r,function(e){var t=angular.element("
    ").append(e),n=t.querySelectorAll(".ui-select-match");if(n.removeAttr("ui-select-match"),n.removeAttr("data-ui-select-match"),1!==n.length)throw i("transcluded","Expected 1 .ui-select-match but got '{0}'.",n.length);o.querySelectorAll(".ui-select-match").replaceWith(n);var c=t.querySelectorAll(".ui-select-choices");if(c.removeAttr("ui-select-choices"),c.removeAttr("data-ui-select-choices"),1!==c.length)throw i("transcluded","Expected 1 .ui-select-choices but got '{0}'.",c.length);o.querySelectorAll(".ui-select-choices").replaceWith(c)});var $=r.$eval(a.appendToBody);(void 0!==$?$:n.appendToBody)&&(r.$watch("$select.open",function(e){e?f():h()}),r.$on("$destroy",function(){h()}));var S=null,b="",w=null,x="direction-up";r.$watch("$select.open",function(n){if(n){if(w=angular.element(o).querySelectorAll(".ui-select-dropdown"),null===w)return;w[0].style.opacity=0,s(function(){var n=c(o),i=c(w);n.top+n.height+i.height>t.pageYOffset+e[0].documentElement.clientHeight&&o.addClass(x),w[0].style.opacity=1})}else{if(null===w)return;o.removeClass(x)}})}}}}]),t.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return n+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,i,c){function r(e){c.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}c.lockChoiceExpression=i.uiLockChoice,i.$observe("placeholder",function(t){c.placeholder=void 0!==t?t:e.placeholder}),i.$observe("allowClear",r),r(i.allowClear),c.multiple&&c.sizeSearchInput()}}}]),t.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,i=this,c=e.$select;e.$evalAsync(function(){n=e.ngModel}),i.activeMatchIndex=-1,i.updateModel=function(){n.$setViewValue(Date.now()),i.refreshComponent()},i.refreshComponent=function(){c.refreshItems(),c.sizeSearchInput()},i.removeChoice=function(e){function n(){c.selected.splice(e,1),i.activeMatchIndex=-1,c.sizeSearchInput(),t(function(){c.afterRemove(r)}),i.updateModel()}var r=c.selected[e];if(!r._uiSelectChoiceLocked){var l=c.beforeRemove(r);angular.isFunction(l.then)?l.then(function(e){e===!0&&n()}):l===!0&&n()}},i.getPlaceholder=function(){return c.selected&&c.selected.length?void 0:c.placeholder}}],controllerAs:"$selectMultiple",link:function(n,i,c,r){function l(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function s(e){function t(){switch(e){case o.KEY.LEFT:return~u.activeMatchIndex?p:r;case o.KEY.RIGHT:return~u.activeMatchIndex&&s!==r?a:(o.activate(),!1);case o.KEY.BACKSPACE:return~u.activeMatchIndex?(u.removeChoice(s),p):r;case o.KEY.DELETE:return~u.activeMatchIndex?(u.removeChoice(u.activeMatchIndex),s):!1}}var n=l(o.searchInput[0]),i=o.selected.length,c=0,r=i-1,s=u.activeMatchIndex,a=u.activeMatchIndex+1,p=u.activeMatchIndex-1,d=s;return n>0||o.search.length&&e==o.KEY.RIGHT?!1:(o.close(),d=t(),u.activeMatchIndex=o.selected.length&&d!==!1?Math.min(r,Math.max(c,d)):-1,!0)}var o=r[0],a=n.ngModel=r[1],u=n.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,a.$parsers.unshift(function(){for(var e,t={},i=[],c=o.selected.length-1;c>=0;c--)t={},t[o.parserResult.itemName]=o.selected[c],e=o.parserResult.modelMapper(n,t),i.unshift(e);return i}),a.$formatters.unshift(function(e){var t,i=o.parserResult.source(n,{$select:{search:""}}),c={};if(!i)return e;var r=[],l=function(e,i){if(e&&e.length){for(var l=e.length-1;l>=0;l--){if(c[o.parserResult.itemName]=e[l],t=o.parserResult.modelMapper(n,c),o.parserResult.trackByExp){var s=/\.(.+)/.exec(o.parserResult.trackByExp);if(s.length>0&&t[s[1]]==i[s[1]])return r.unshift(e[l]),!0}if(angular.equals(t,i))return r.unshift(e[l]),!0}return!1}};if(!e)return r;for(var s=e.length-1;s>=0;s--)l(o.selected,e[s])||l(i,e[s])||r.unshift(e[s]);return r}),n.$watchCollection(function(){return a.$modelValue},function(e,t){t!=e&&(a.$modelValue=null,u.refreshComponent())}),a.$render=function(){if(!angular.isArray(a.$viewValue)){if(!angular.isUndefined(a.$viewValue)&&null!==a.$viewValue)throw e("multiarr","Expected model value to be array but got '{0}'",a.$viewValue);o.selected=[]}o.selected=a.$viewValue,n.$evalAsync()},n.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),u.updateModel())}),n.$on("uis:activate",function(){u.activeMatchIndex=-1}),n.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(e){var t=e.which;n.$apply(function(){var e=!1;o.KEY.isHorizontalMovement(t)&&(e=s(t)),e&&t!=o.KEY.TAB})}),o.searchInput.on("blur",function(){t(function(){u.activeMatchIndex=-1})})}}}]),t.directive("uiSelectSingle",["$timeout","$compile",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(n,i,c,r){var l=r[0],s=r[1];s.$parsers.unshift(function(e){var t,i={};return i[l.parserResult.itemName]=e,t=l.parserResult.modelMapper(n,i)}),s.$formatters.unshift(function(e){var t,i=l.parserResult.source(n,{$select:{search:""}}),c={};if(i){var r=function(i){return c[l.parserResult.itemName]=i,t=l.parserResult.modelMapper(n,c),t==e};if(l.selected&&r(l.selected))return l.selected;for(var s=i.length-1;s>=0;s--)if(r(i[s]))return i[s]}return e}),n.$watch("$select.selected",function(e){s.$viewValue!==e&&s.$setViewValue(e)}),s.$render=function(){l.selected=s.$viewValue},n.$on("uis:select",function(e,t){l.selected=t}),n.$on("uis:close",function(t,n){e(function(){l.focusser.prop("disabled",!1),n||l.focusser[0].focus()},0,!1)}),n.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");t(o)(n),l.focusser=o,l.focusInput=o,i.parent().append(o),o.bind("focus",function(){n.$evalAsync(function(){l.focus=!0})}),o.bind("blur",function(){n.$evalAsync(function(){l.focus=!1})}),o.bind("keydown",function(e){return e.which===l.KEY.BACKSPACE?(e.preventDefault(),e.stopPropagation(),l.select(void 0),n.$apply(),void 0):(e.which===l.KEY.TAB||l.KEY.isControl(e)||l.KEY.isFunctionKey(e)||e.which===l.KEY.ESC||((e.which==l.KEY.DOWN||e.which==l.KEY.UP||e.which==l.KEY.ENTER||e.which==l.KEY.SPACE)&&(e.preventDefault(),e.stopPropagation(),l.activate()),n.$digest()),void 0)}),o.bind("keyup input",function(e){e.which===l.KEY.TAB||l.KEY.isControl(e)||l.KEY.isFunctionKey(e)||e.which===l.KEY.ESC||e.which==l.KEY.ENTER||e.which===l.KEY.BACKSPACE||(l.activate(o.val()),o.val(""),n.$digest())})}}}]),t.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var i=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!i)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:i[2],source:t(i[3]),trackByExp:i[4],modelMapper:t(i[1]||i[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,i){var c=e+" in "+(i?"$group.items":t);return n&&(c+=" track by "+n),c}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("selectize/choices.tpl.html",'
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/dist/select.sort.js b/dist/select.sort.js index c3a106d9e..dbf8c15e1 100644 --- a/dist/select.sort.js +++ b/dist/select.sort.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-06T13:28:34.975Z + * Version: 0.12.1 - 2015-08-09T18:09:19.204Z * License: MIT */ @@ -150,4 +150,86 @@ angular.module('ui.select.sort', ['ui.select']) }; }]); +}());ted))) { + // if there is a tag from prev iteration, strip it / queue the change + // and return early + if (hasTag) { + items = stashArr; + scope.$evalAsync(function () { + $select.activeIndex = 0; + $select.items = items; + }); + } + return; + } + if (_findCaseInsensitiveDupe(stashArr)) { + // If there is a tag from prev iteration, strip it + if (hasTag) { + $select.items = stashArr.slice(1, stashArr.length); + } + return; + } +// } + if (hasTag) { + dupeIndex = _findApproxDupe($select.selected, newItem); + } + // dupe found, shave the first item + if (dupeIndex > -1) { + items = items.slice(dupeIndex + 1, items.length - 1); + } else { + items = []; + items.push(newItem); + items = items.concat(stashArr); + } + scope.$evalAsync(function () { + $select.activeIndex = 0; + $select.items = items; + }); + } + }; + + + function _findCaseInsensitiveDupe(arr) { + if (arr === undefined || $select.search === undefined) { + return false; + } + var hasDupe = arr.filter(function (origItem) { + if ($select.search.toUpperCase() === undefined || origItem === undefined) { + return false; + } + return origItem.toUpperCase() === $select.search.toUpperCase(); + }).length > 0; + + return hasDupe; + } + + function _findApproxDupe(haystack, needle) { + var dupeIndex = -1; + if (angular.isArray(haystack)) { + var tempArr = angular.copy(haystack); + for (var i = 0; i < tempArr.length; i++) { + // handle the simple string version of tagging +// if ($select.tagging.fct === undefined) { + // search the array for the match + if (tempArr[i] + ' ' + $select.taggingLabel === needle) { + dupeIndex = i; + } + // handle the object tagging implementation + /* } else { + var mockObj = tempArr[i]; + mockObj.isTag = true; + if (angular.equals(mockObj, needle)) { + dupeIndex = i; + } + }*/ + } + } + return dupeIndex; + } + + + } + }; + }]); + }()); \ No newline at end of file diff --git a/dist/select.sort.min.js b/dist/select.sort.min.js index c71dab5ea..bd24072ca 100644 --- a/dist/select.sort.min.js +++ b/dist/select.sort.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-06T13:28:34.975Z + * Version: 0.12.1 - 2015-08-09T18:09:19.204Z * License: MIT */ -!function(){"use strict";angular.module("ui.select.sort",["ui.select"]).directive("uiSelectSort",["$timeout","uiSelectConfig","uiSelectMinErr",function(e,t,a){return{require:"^uiSelect",link:function(t,r,n,i){if(null===t[n.uiSelectSort])throw a("sort","Expected a list to sort");var o=angular.extend({axis:"horizontal"},t.$eval(n.uiSelectSortOptions)),s=o.axis,l="dragging",f="dropping",d="dropping-before",u="dropping-after";t.$watch(function(){return i.sortable},function(e){e?r.attr("draggable",!0):r.removeAttr("draggable")}),r.on("dragstart",function(e){r.addClass(l),(e.dataTransfer||e.originalEvent.dataTransfer).setData("text/plain",t.$index)}),r.on("dragend",function(){r.removeClass(l)});var c,v=function(e,t){this.splice(t,0,this.splice(e,1)[0])},g=function(e){e.preventDefault();var t="vertical"===s?e.offsetY||e.layerY||(e.originalEvent?e.originalEvent.offsetY:0):e.offsetX||e.layerX||(e.originalEvent?e.originalEvent.offsetX:0);t-1)return;if(a(f.concat(i.selected)))return v&&(h=f,e.$evalAsync(function(){i.activeIndex=0,i.items=h})),void 0;if(a(f))return v&&(i.items=f.slice(1,f.length)),void 0;v&&(d=r(i.selected,s)),d>-1?h=h.slice(d+1,h.length-1):(h=[],h.push(s),h=h.concat(f)),e.$evalAsync(function(){i.activeIndex=0,i.items=h})}}}}}])}(); \ No newline at end of file diff --git a/dist/select.tpl.js b/dist/select.tpl.js index d5a34d03e..d7568c1e8 100644 --- a/dist/select.tpl.js +++ b/dist/select.tpl.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-06T13:28:34.932Z + * Version: 0.12.1 - 2015-08-09T18:09:19.140Z * License: MIT */ diff --git a/examples/bootstrap.html b/examples/bootstrap.html index 75735f9fe..bdca6874e 100644 --- a/examples/bootstrap.html +++ b/examples/bootstrap.html @@ -36,7 +36,12 @@ -

    Selected: {{person.selected.name}}

    +

    Selected: + + , + {{p.name}} + +

    diff --git a/examples/newdemo.html b/examples/newdemo.html index 94090348b..f461a54ac 100644 --- a/examples/newdemo.html +++ b/examples/newdemo.html @@ -41,7 +41,7 @@
    ui-select inside a Bootstrap form - +
    {{$item}} @@ -166,14 +166,15 @@
    - +
    diff --git a/examples/newdemo.js b/examples/newdemo.js index 7cd42bdb4..7c2b32f83 100644 --- a/examples/newdemo.js +++ b/examples/newdemo.js @@ -1,6 +1,6 @@ 'use strict'; -var app = angular.module('demo', ['ngSanitize', 'ui.select', 'ui.select.sort']); +var app = angular.module('demo', ['ngSanitize', 'ui.select', 'ui.select.sort', 'ui.select.tagging']); /** * AngularJS default filter with the following expression: diff --git a/gulpfile.js b/gulpfile.js index 96f71c295..8d170b740 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -96,6 +96,20 @@ gulp.task('scripts', ['clean'], function () { ); }; + var buildTagging = function () { + return gulp.src(['src/addons/uiSelectTaggingDirective.js']) + .pipe(plumber({ + errorHandler: handleError + })) + .pipe(concat('select.tagging.js')) + .pipe(header('(function () { \n"use strict";\n')) + .pipe(footer('\n}());')) + .pipe(jshint()) + .pipe(jshint.reporter('jshint-stylish')) + .pipe(jshint.reporter('fail') + ); + }; + es.merge(buildTplBootstrap(), buildTplSelect2(), buildTplSelectize()) .pipe(plumber({ errorHandler: handleError @@ -173,7 +187,20 @@ gulp.task('scripts', ['clean'], function () { .pipe(rename({ext: '.sort.min.js'})) .pipe(gulp.dest('dist')); - return es.merge(buildLib(), buildSort(), buildTplBootstrap(), buildTplSelect2(), buildTplSelectize()) + es.merge(buildTagging()) + .pipe(plumber({ + errorHandler: handleError + })) + .pipe(concat('select.sort.js')) + .pipe(header(config.banner, { + timestamp: (new Date()).toISOString(), pkg: config.pkg + })) + .pipe(gulp.dest('dist')) + .pipe(uglify({preserveComments: 'some'})) + .pipe(rename({ext: '.sort.min.js'})) + .pipe(gulp.dest('dist')); + + return es.merge(buildLib(), buildTagging(), buildSort(), buildTplBootstrap(), buildTplSelect2(), buildTplSelectize()) .pipe(plumber({ errorHandler: handleError })) diff --git a/src/addons/uiSelectTaggingDirective.js b/src/addons/uiSelectTaggingDirective.js new file mode 100644 index 000000000..cd5f426a4 --- /dev/null +++ b/src/addons/uiSelectTaggingDirective.js @@ -0,0 +1,194 @@ +angular.module('ui.select.tagging', ['ui.select']) + .directive('uiSelectTagging', + ['$parse', '$timeout', function () { + return { + require: '^uiSelect', + link: function (scope, element, attrs, $select) { + var ctrl = $select; + ctrl.taggingLabel = attrs.taggingLabel !== undefined ? attrs.taggingLabel : false; + ctrl.taggingTokens = + attrs.taggingTokens !== undefined ? attrs.taggingTokens.split('|') : [',', 'ENTER']; + + // If tagging try to split by tokens and add items + ctrl.searchInput.on('paste', function (e) { + var data = e.clipboardData.getData('text/plain'); + if (data && data.length > 0) { + var items = data.split(ctrl.taggingTokens[0]); // Split by first token only + if (items && items.length > 0) { + angular.forEach(items, function (item) { + var newItem = ctrl.beforeTagging(item); + if (newItem) { + ctrl.select(newItem, true); + } + }); + e.preventDefault(); + e.stopPropagation(); + } + } + }); + + // Define the default callback into the controller + ctrl.beforeTagging = function (item) { + return item; + }; + + + // Override the keypress callback + ctrl.afterKeypress = function (e) { + + +// if ( ! ctrl.KEY.isVerticalMovement(e.which) ) { +// scope.$evalAsync( function () { +// $select.activeIndex = $select.taggingLabel === false ? -1 : 0; +// }); +// } + + // Push a "create new" item into array if there is a search string + if ($select.search.length > 0) { + // Return early with these keys + if (e.which === ctrl.KEY.TAB || ctrl.KEY.isControl(e) || ctrl.KEY.isFunctionKey(e) || + e.which === ctrl.KEY.ESC || + ctrl.KEY.isVerticalMovement(e.which)) { + return; + } + + // Check for end of tagging + var tagged = false; +// if (e.which === ctrl.KEY.ENTER) { +// tagged = true; +// } + for (var i = 0; i < ctrl.taggingTokens.length; i++) { + if (ctrl.taggingTokens[i] === ctrl.KEY.MAP[e.keyCode]) { + // Make sure there is a new value to push via tagging + if (ctrl.search.length > 0) { + tagged = true; + if ($select.search.substr($select.search.length - 1) == ctrl.KEY.MAP[e.keyCode]) { + + $select.search = $select.search.substr(0, $select.search.length - 1); + } + } + } + } + if (tagged === true) { + ctrl.select(ctrl.beforeTagging($select.search)); + return; + } + + + $select.activeIndex = $select.taggingLabel === false ? -1 : 0; + // If taggingLabel === false bypasses all of this + if ($select.taggingLabel === false) { + return; + } + + var items = angular.copy($select.items); + var stashArr = angular.copy($select.items); + var newItem; + var item; + var hasTag = false; + var dupeIndex = -1; + var tagItems; + var tagItem; + + + // Find any tagging items already in the $select.items array and store them + tagItems = $select.$filter('filter')(items, function (item) { + return item.match($select.taggingLabel); + }); + if (tagItems.length > 0) { + tagItem = tagItems[0]; + } + item = items[0]; + // Remove existing tag item if found (should only ever be one tag item) + if (item !== undefined && items.length > 0 && tagItem) { + hasTag = true; + items = items.slice(1, items.length); + stashArr = stashArr.slice(1, stashArr.length); + } + newItem = $select.search + ' ' + $select.taggingLabel; + if (_findApproxDupe($select.selected, $select.search) > -1) { + return; + } + // Verify the the tag doesn't match the value of an existing item from + // the searched data set or the items already selected + if (_findCaseInsensitiveDupe(stashArr.concat($select.selected))) { + // if there is a tag from prev iteration, strip it / queue the change + // and return early + if (hasTag) { + items = stashArr; + scope.$evalAsync(function () { + $select.activeIndex = 0; + $select.items = items; + }); + } + return; + } + if (_findCaseInsensitiveDupe(stashArr)) { + // If there is a tag from prev iteration, strip it + if (hasTag) { + $select.items = stashArr.slice(1, stashArr.length); + } + return; + } +// } + if (hasTag) { + dupeIndex = _findApproxDupe($select.selected, newItem); + } + // dupe found, shave the first item + if (dupeIndex > -1) { + items = items.slice(dupeIndex + 1, items.length - 1); + } else { + items = []; + items.push(newItem); + items = items.concat(stashArr); + } + scope.$evalAsync(function () { + $select.activeIndex = 0; + $select.items = items; + }); + } + }; + + + function _findCaseInsensitiveDupe(arr) { + if (arr === undefined || $select.search === undefined) { + return false; + } + var hasDupe = arr.filter(function (origItem) { + if ($select.search.toUpperCase() === undefined || origItem === undefined) { + return false; + } + return origItem.toUpperCase() === $select.search.toUpperCase(); + }).length > 0; + + return hasDupe; + } + + function _findApproxDupe(haystack, needle) { + var dupeIndex = -1; + if (angular.isArray(haystack)) { + var tempArr = angular.copy(haystack); + for (var i = 0; i < tempArr.length; i++) { + // handle the simple string version of tagging +// if ($select.tagging.fct === undefined) { + // search the array for the match + if (tempArr[i] + ' ' + $select.taggingLabel === needle) { + dupeIndex = i; + } + // handle the object tagging implementation + /* } else { + var mockObj = tempArr[i]; + mockObj.isTag = true; + if (angular.equals(mockObj, needle)) { + dupeIndex = i; + } + }*/ + } + } + return dupeIndex; + } + + + } + }; + }]); diff --git a/src/common.js b/src/common.js index 912e3880e..1d1ecb188 100644 --- a/src/common.js +++ b/src/common.js @@ -1,50 +1,3 @@ -var KEY = { - TAB: 9, - ENTER: 13, - ESC: 27, - SPACE: 32, - LEFT: 37, - UP: 38, - RIGHT: 39, - DOWN: 40, - SHIFT: 16, - CTRL: 17, - ALT: 18, - PAGE_UP: 33, - PAGE_DOWN: 34, - HOME: 36, - END: 35, - BACKSPACE: 8, - DELETE: 46, - COMMAND: 91, - - isControl: function (e) { - var k = e.which; - switch (k) { - case KEY.COMMAND: - case KEY.SHIFT: - case KEY.CTRL: - case KEY.ALT: - return true; - } - - if (e.metaKey) { - return true; - } - - return false; - }, - isFunctionKey: function (k) { - k = k.which ? k.which : k; - return k >= 112 && k <= 123; - }, - isVerticalMovement: function (k) { - return ~[KEY.UP, KEY.DOWN].indexOf(k); - }, - isHorizontalMovement: function (k) { - return ~[KEY.LEFT, KEY.RIGHT, KEY.BACKSPACE, KEY.DELETE].indexOf(k); - } -}; /** * Add querySelectorAll() to jqLite. @@ -97,7 +50,7 @@ var uis = angular.module('ui.select', []) appendToBody: false }) -// See Rename minErr and make it accessible from outside https://github.com/angular/angular.js/issues/6913 + // See Rename minErr and make it accessible from outside https://github.com/angular/angular.js/issues/6913 .service('uiSelectMinErr', function () { var minErr = angular.$$minErr('ui.select'); return function () { @@ -107,7 +60,7 @@ var uis = angular.module('ui.select', []) }; }) -// Recreates old behavior of ng-transclude. Used internally. + // Recreates old behavior of ng-transclude. Used internally. .directive('uisTranscludeAppend', function () { return { link: function (scope, element, attrs, ctrl, transclude) { @@ -118,29 +71,30 @@ var uis = angular.module('ui.select', []) }; }) -/** - * Highlights text that matches $select.search. - * - * Taken from AngularUI Bootstrap Typeahead - * See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L340 - */ + /** + * Highlights text that matches $select.search. + * + * Taken from AngularUI Bootstrap Typeahead + * See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L340 + */ .filter('highlight', function () { function escapeRegexp(queryToEscape) { return queryToEscape.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1'); } return function (matchItem, query) { + matchItem = String(matchItem); return query && matchItem ? matchItem.replace(new RegExp(escapeRegexp(query), 'gi'), '$&') : matchItem; }; }) -/** - * A read-only equivalent of jQuery's offset function: http://api.jquery.com/offset/ - * - * Taken from AngularUI Bootstrap Position: - * See https://github.com/angular-ui/bootstrap/blob/master/src/position/position.js#L70 - */ + /** + * A read-only equivalent of jQuery's offset function: http://api.jquery.com/offset/ + * + * Taken from AngularUI Bootstrap Position: + * See https://github.com/angular-ui/bootstrap/blob/master/src/position/position.js#L70 + */ .factory('uisOffset', ['$document', '$window', function ($document, $window) { diff --git a/src/uiSelectController.js b/src/uiSelectController.js index 13b810b32..5f5e805e7 100644 --- a/src/uiSelectController.js +++ b/src/uiSelectController.js @@ -7,7 +7,6 @@ uis.controller('uiSelectCtrl', ['$scope', '$element', '$timeout', '$filter', '$q', 'uisRepeatParser', 'uiSelectMinErr', 'uiSelectConfig', function ($scope, $element, $timeout, $filter, $q, RepeatParser, uiSelectMinErr, uiSelectConfig) { - var ctrl = this; var EMPTY_SEARCH = ''; @@ -16,23 +15,23 @@ uis.controller('uiSelectCtrl', ctrl.searchEnabled = uiSelectConfig.searchEnabled; ctrl.sortable = uiSelectConfig.sortable; - ctrl.removeSelected = false; // If selected item(s) should be removed from dropdown list - ctrl.closeOnSelect = true; // Initialized inside uiSelect directive link function + ctrl.removeSelected = false; // If selected item(s) should be removed from dropdown list + ctrl.closeOnSelect = true; // Initialized inside uiSelect directive link function ctrl.search = EMPTY_SEARCH; - ctrl.activeIndex = 0; // Dropdown of choices - ctrl.items = []; // All available choices + ctrl.activeIndex = 0; // Dropdown of choices + ctrl.items = []; // All available choices ctrl.open = false; ctrl.focus = false; ctrl.disabled = false; ctrl.selected = undefined; - ctrl.focusser = undefined; // Reference to input element used to handle focus events + ctrl.focusser = undefined; // Reference to input element used to handle focus events ctrl.resetSearchInput = true; - ctrl.multiple = undefined; // Initialized inside uiSelect directive link function - ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelectChoices directive link function - ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelectMatch directive link function + ctrl.multiple = undefined; // Initialized inside uiSelect directive link function + ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelectChoices directive link function + ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelectMatch directive link function ctrl.clickTriggeredSelect = false; ctrl.$filter = $filter; @@ -42,6 +41,158 @@ uis.controller('uiSelectCtrl', ctrl.searchInput.length); } + // TODO: Maybe make these methods in KEY directly in the controller? + ctrl.KEY = { + TAB: 9, + ENTER: 13, + ESC: 27, + SPACE: 32, + LEFT: 37, + UP: 38, + RIGHT: 39, + DOWN: 40, + SHIFT: 16, + CTRL: 17, + ALT: 18, + PAGE_UP: 33, + PAGE_DOWN: 34, + HOME: 36, + END: 35, + BACKSPACE: 8, + DELETE: 46, + COMMAND: 91, + MAP: { + 91: "COMMAND", + 8: "BACKSPACE", + 9: "TAB", + 13: "ENTER", + 16: "SHIFT", + 17: "CTRL", + 18: "ALT", + 19: "PAUSEBREAK", + 20: "CAPSLOCK", + 27: "ESC", + 32: "SPACE", + 33: "PAGE_UP", + 34: "PAGE_DOWN", + 35: "END", + 36: "HOME", + 37: "LEFT", + 38: "UP", + 39: "RIGHT", + 40: "DOWN", + 43: "+", + 44: "PRINTSCREEN", + 45: "INSERT", + 46: "DELETE", + 48: "0", + 49: "1", + 50: "2", + 51: "3", + 52: "4", + 53: "5", + 54: "6", + 55: "7", + 56: "8", + 57: "9", + 59: ";", + 61: "=", + 65: "A", + 66: "B", + 67: "C", + 68: "D", + 69: "E", + 70: "F", + 71: "G", + 72: "H", + 73: "I", + 74: "J", + 75: "K", + 76: "L", + 77: "M", + 78: "N", + 79: "O", + 80: "P", + 81: "Q", + 82: "R", + 83: "S", + 84: "T", + 85: "U", + 86: "V", + 87: "W", + 88: "X", + 89: "Y", + 90: "Z", + 96: "0", + 97: "1", + 98: "2", + 99: "3", + 100: "4", + 101: "5", + 102: "6", + 103: "7", + 104: "8", + 105: "9", + 106: "*", + 107: "+", + 109: "-", + 110: ".", + 111: "/", + 112: "F1", + 113: "F2", + 114: "F3", + 115: "F4", + 116: "F5", + 117: "F6", + 118: "F7", + 119: "F8", + 120: "F9", + 121: "F10", + 122: "F11", + 123: "F12", + 144: "NUMLOCK", + 145: "SCROLLLOCK", + 186: ";", + 187: "=", + 188: ",", + 189: "-", + 190: ".", + 191: "/", + 192: "`", + 219: "[", + 220: "\\", + 221: "]", + 222: "'" + }, + + isControl: function (e) { + var k = e.which; + switch (k) { + case ctrl.KEY.COMMAND: + case ctrl.KEY.SHIFT: + case ctrl.KEY.CTRL: + case ctrl.KEY.ALT: + return true; + } + + if (e.metaKey) { + return true; + } + + return false; + }, + isFunctionKey: function (k) { + k = k.which ? k.which : k; + return k >= 112 && k <= 123; + }, + isVerticalMovement: function (k) { + return ~[ctrl.KEY.UP, ctrl.KEY.DOWN].indexOf(k); + }, + isHorizontalMovement: function (k) { + return ~[ctrl.KEY.LEFT, ctrl.KEY.RIGHT, ctrl.KEY.BACKSPACE, ctrl.KEY.DELETE].indexOf(k); + } + }; + /** * Returns true if the selection is empty * @returns {boolean|*} @@ -82,6 +233,7 @@ uis.controller('uiSelectCtrl', /** * Activates the control. * When the user clicks on ui-select, displays the dropdown list + * Also called following keyboard input to the search box */ ctrl.activate = function (initSearchValue, avoidReset) { if (!ctrl.disabled && !ctrl.open) { @@ -106,22 +258,15 @@ uis.controller('uiSelectCtrl', }); }; - var result = ctrl.onDropdownCallback($scope, {open: true}); - if (angular.isDefined(result)) { - if (angular.isFunction(result.then)) { - // Promise returned - wait for it to complete before completing the selection - result.then(function (result) { - if (!result) { - return; - } + var result = ctrl.beforeDropdownOpen(); + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (result) { + if (result === true) { completeCallback(); - }); - } else if (result === true) { - completeCallback(); - } else if (result) { - completeCallback(); - } - } else { + } + }); + } else if (result === true) { completeCallback(); } } @@ -231,9 +376,10 @@ uis.controller('uiSelectCtrl', var isActive = itemIndex === -1 ? false : itemIndex === ctrl.activeIndex; // If this is active, and we've defined a callback, do it! - if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { - itemScope.$eval(ctrl.onHighlightCallback); - } + // TODO: Needed? +// if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { +// itemScope.$eval(ctrl.onHighlightCallback); +// } return isActive; }; @@ -278,22 +424,11 @@ uis.controller('uiSelectCtrl', return; } - // Create the data used to pass to the callbacks - var locals = {}; - locals[ctrl.parserResult.itemName] = item; - var callbackContext = { - $item: item, - $model: ctrl.parserResult.modelMapper($scope, locals) - }; - - // Local method called when we complete the select - // eg. called after the onselect callback - var completeCallback = function (item) { - callbackContext.$item = item; + function completeCallback() { $scope.$broadcast('uis:select', item); $timeout(function () { - ctrl.onSelectCallback($scope, callbackContext); + ctrl.afterSelect(item); }); if (ctrl.closeOnSelect) { @@ -302,41 +437,31 @@ uis.controller('uiSelectCtrl', if ($event && $event.type === 'click') { ctrl.clickTriggeredSelect = true; } - }; - - // If there's no onBeforeSelect callback, then just call the completeCallback - if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { - completeCallback(item); - return; } - // Call the onBeforeSelect callback + // Call the beforeSelect method // Allowable responses are -: - // falsy: Abort the selection - // promise: Wait for response + // false: Abort the selection // true: Complete selection + // promise: Wait for response // object: Add the returned object - var result = ctrl.onBeforeSelectCallback($scope, callbackContext); - if (angular.isDefined(result)) { - if (angular.isFunction(result.then)) { - // Promise returned - wait for it to complete before completing the selection - result.then(function (response) { - if (!response) { - return; - } - if (response === true) { - completeCallback(item); - } else if (response) { - completeCallback(response); - } - }); - } else if (result === true) { - completeCallback(item); - } else if (result) { - completeCallback(result); - } - } else { + var result = ctrl.beforeSelect(item); + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (response) { + if (!response) { + return; + } + if (response === true) { + completeCallback(item); + } else if (response) { + completeCallback(response); + } + }); + } else if (result === true) { completeCallback(item); + } else if (result) { + completeCallback(result); } }; @@ -361,22 +486,15 @@ uis.controller('uiSelectCtrl', $scope.$broadcast('uis:close', skipFocusser); } - var result = ctrl.onDropdownCallback($scope, {open: false}); - if (angular.isDefined(result)) { - if (angular.isFunction(result.then)) { - // Promise returned - wait for it to complete before completing the selection - result.then(function (result) { - if (!result) { - return; - } + var result = ctrl.beforeDropdownClose(); + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (result) { + if (result === true) { completeCallback(); - }); - } else if (result === true) { - completeCallback(); - } else if (result) { - completeCallback(); - } - } else { + } + }); + } else if (result === true) { completeCallback(); } }; @@ -466,7 +584,7 @@ uis.controller('uiSelectCtrl', function _handleDropDownSelection(key) { var processed = true; switch (key) { - case KEY.DOWN: + case ctrl.KEY.DOWN: if (!ctrl.open && ctrl.multiple) { // In case its the search input in 'multiple' mode ctrl.activate(false, true); @@ -475,7 +593,7 @@ uis.controller('uiSelectCtrl', ctrl.activeIndex++; } break; - case KEY.UP: + case ctrl.KEY.UP: if (!ctrl.open && ctrl.multiple) { ctrl.activate(false, true); } //In case its the search input in 'multiple' mode @@ -483,21 +601,23 @@ uis.controller('uiSelectCtrl', ctrl.activeIndex--; } break; - case KEY.TAB: + case ctrl.KEY.TAB: if (!ctrl.multiple || ctrl.open) { ctrl.select(ctrl.items[ctrl.activeIndex], true); } break; - case KEY.ENTER: + case ctrl.KEY.ENTER: if (ctrl.open) { // Make sure at least one dropdown item is highlighted before adding - ctrl.select(ctrl.items[ctrl.activeIndex]); + if (ctrl.items[ctrl.activeIndex] !== undefined) { + ctrl.select(ctrl.items[ctrl.activeIndex]); + } } else { // In case its the search input in 'multiple' mode ctrl.activate(false, true); } break; - case KEY.ESC: + case ctrl.KEY.ESC: ctrl.close(); break; default: @@ -508,39 +628,42 @@ uis.controller('uiSelectCtrl', // Bind to keyboard shortcuts ctrl.searchInput.on('keydown', function (e) { - var key = e.which; - // if(~[KEY.ESC,KEY.TAB].indexOf(key)){ - // //TODO: SEGURO? - // ctrl.close(); - // } + if (~[ctrl.KEY.ESC, ctrl.KEY.TAB].indexOf(key)) { + // TODO: SEGURO? + ctrl.close(); + } $scope.$apply(function () { _handleDropDownSelection(key); }); - if (KEY.isVerticalMovement(key) && ctrl.items.length > 0) { + if (ctrl.KEY.isVerticalMovement(key) && ctrl.items.length > 0) { _ensureHighlightVisible(); } - if (key === KEY.ENTER || key === KEY.ESC) { + if (key === ctrl.KEY.ENTER || key === ctrl.KEY.ESC) { e.preventDefault(); e.stopPropagation(); } + + // Let the users process the data + // TODO: Is this needed, or just let the user bind to the event themselves! +// ctrl.afterKeypress(e); }); ctrl.searchInput.on('keyup', function (e) { // return early with these keys - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || - KEY.isVerticalMovement(e.which)) { + if (e.which === ctrl.KEY.TAB || ctrl.KEY.isControl(e) || ctrl.KEY.isFunctionKey(e) || + e.which === ctrl.KEY.ESC || + ctrl.KEY.isVerticalMovement(e.which)) { return; } - if (ctrl.onKeypressCallback === undefined) { - return; - } - ctrl.onKeypressCallback($scope, {event: e}); + // Let the users process the data + // TODO: Is this needed, or just let the user bind to the event themselves! + ctrl.afterKeypress(e); }); // See https://github.com/ivaynberg/select2/blob/3.4.6/select2.js#L1431 @@ -577,4 +700,87 @@ uis.controller('uiSelectCtrl', ctrl.searchInput.off('keyup keydown blur paste'); }); + /** + * Keypress callback. Overridable. + * @param event the keypress event + */ + /* jshint unused:false */ + ctrl.afterKeypress = function (event) { + }; + + /** + * Method called before a selection is made. This can be overridden to allow + * the selection to be aborted, or a modified version of the selected item to be + * returned. + * + * Allowable responses are -: + * false: Abort the selection + * true: Complete selection with the selected object + * object: Complete the selection with the returned object + * promise: Wait for response - response from promise is as above + * + * @param item the item that has been selected + * @returns {*} + */ + ctrl.beforeSelect = function (item) { + return true; + }; + + /** + * Method called after a selection is confirmed. This can be overridden to allow + * the application to be notified of a newly selected item. + * No return is required. + * + * @param item the item that has been selected + */ + ctrl.afterSelect = function (item) { + }; + + /** + * Method called before an item is removed from the selected list. This can be overridden + * to allow the removal to be aborted + * + * Allowable responses are -: + * false: Abort the selection + * true: Complete selection with the selected object + * object: Complete the selection with the returned object + * promise: Wait for response - response from promise is as above + * + * @param item the item that has been selected + * @returns {*} + */ + ctrl.beforeRemove = function (item) { + return true; + }; + + /** + * Method called after a item is removed. This can be overridden to allow + * the application to be notified of a removed item. + * No return is required. + * + * @param item the item that has been removed + */ + ctrl.afterRemove = function (item) { + }; + + /** + * Method called before the dropdown is opened. This can be overridden to allow + * the application to process data before the dropdown is displayed. + * The method may return a promise, or true to allow the dropdown, or false to abort. + * @returns {boolean} + */ + ctrl.beforeDropdownOpen = function () { + return true; + }; + + /** + * Method called before the dropdown is closed. This can be overridden to allow + * the application to prevent the dropdown from closing. + * The method may return a promise, or true to allow the dropdown to close, or false to abort. + * @returns {boolean} + */ + ctrl.beforeDropdownClose = function () { + return true; + }; + }]); diff --git a/src/uiSelectDirective.js b/src/uiSelectDirective.js index 7c4c68352..903794476 100644 --- a/src/uiSelectDirective.js +++ b/src/uiSelectDirective.js @@ -42,13 +42,6 @@ uis.directive('uiSelect', } }(); - $select.onSelectCallback = $parse(attrs.onSelect); - $select.onBeforeSelectCallback = $parse(attrs.onBeforeSelect); - $select.onRemoveCallback = $parse(attrs.onRemove); - $select.onBeforeRemoveCallback = $parse(attrs.onBeforeRemove); - $select.onKeypressCallback = $parse(attrs.onKeypress); - $select.onDropdownCallback = $parse(attrs.onDropdown); - // Limit the number of selections allowed $select.limit = (angular.isDefined(attrs.limit)) ? parseInt(attrs.limit, 10) : undefined; @@ -246,7 +239,8 @@ uis.directive('uiSelect', var offsetDropdown = uisOffset(dropdown); // Determine if the direction of the dropdown needs to be changed. - if (offset.top + offset.height + offsetDropdown.height > $window.pageYOffset + $document[0].documentElement.clientHeight) { + if (offset.top + offset.height + offsetDropdown.height > + $window.pageYOffset + $document[0].documentElement.clientHeight) { element.addClass(directionUpClassName); } diff --git a/src/uiSelectMatchDirective.js b/src/uiSelectMatchDirective.js index bb3579df5..9dbfec7d8 100644 --- a/src/uiSelectMatchDirective.js +++ b/src/uiSelectMatchDirective.js @@ -12,6 +12,8 @@ uis.directive('uiSelectMatch', ['uiSelectConfig', function (uiSelectConfig) { }, link: function (scope, element, attrs, $select) { $select.lockChoiceExpression = attrs.uiLockChoice; + + // TODO: observe required? attrs.$observe('placeholder', function (placeholder) { $select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder; }); @@ -21,6 +23,7 @@ uis.directive('uiSelectMatch', ['uiSelectConfig', function (uiSelectConfig) { (angular.isDefined(allow)) ? (allow === '') ? true : (allow.toLowerCase() === 'true') : false; } + // TODO: observe required? attrs.$observe('allowClear', setAllowClear); setAllowClear(attrs.allowClear); diff --git a/src/uiSelectMultipleDirective.js b/src/uiSelectMultipleDirective.js index cb480e71a..3784a5568 100644 --- a/src/uiSelectMultipleDirective.js +++ b/src/uiSelectMultipleDirective.js @@ -33,65 +33,47 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel * Then calls onRemove to notify the user the item has been removed */ ctrl.removeChoice = function (index) { + // Get the removed choice var removedChoice = $select.selected[index]; - // if the choice is locked, can't remove it + // If the choice is locked, can't remove it if (removedChoice._uiSelectChoiceLocked) { return; } - var locals = {}; - locals[$select.parserResult.itemName] = removedChoice; - - $select.selected.splice(index, 1); - ctrl.activeMatchIndex = -1; - $select.sizeSearchInput(); - - var callbackContext = { - $item: removedChoice, - $model: $select.parserResult.modelMapper($scope, locals) - }; - // Give some time for scope propagation. function completeCallback() { + $select.selected.splice(index, 1); + ctrl.activeMatchIndex = -1; + $select.sizeSearchInput(); + $timeout(function () { - $select.onRemoveCallback($scope, callbackContext); + $select.afterRemove(removedChoice); }); ctrl.updateModel(); } - // If there's no onBeforeRemove callback, then just call the completeCallback - if(!angular.isDefined(ctrl.onBeforeRemoveCallback)) { - completeCallback(); - return; - } - - // Call the onBeforeRemove callback + // Call the beforeRemove callback // Allowable responses are -: - // falsy: Abort the removal - // promise: Wait for response + // false: Abort the removal // true: Complete removal - var result = ctrl.onBeforeRemoveCallback($scope, callbackContext); - if (angular.isDefined(result)) { - if (angular.isFunction(result.then)) { - // Promise returned - wait for it to complete before completing the selection - result.then(function (result) { - if (!result) { - return; - } - completeCallback(result); - }); - } else if (result === true) { - completeCallback(); - } - } else { + // promise: Wait for response + var result = $select.beforeRemove(removedChoice); + if (angular.isFunction(result.then)) { + // Promise returned - wait for it to complete before completing the selection + result.then(function (result) { + if (result === true) { + completeCallback(); + } + }); + } else if (result === true) { completeCallback(); } }; ctrl.getPlaceholder = function () { - //Refactor single? + // Refactor single? if ($select.selected && $select.selected.length) { return; } @@ -219,17 +201,18 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel var key = e.which; scope.$apply(function () { var processed = false; - if (KEY.isHorizontalMovement(key)) { + if ($select.KEY.isHorizontalMovement(key)) { processed = _handleMatchSelection(key); } - if (processed && key != KEY.TAB) { - //TODO Check si el tab selecciona aun correctamente - //Crear test + if (processed && key != $select.KEY.TAB) { + // TODO Check si el tab selecciona aun correctamente + //Creat test // e.preventDefault(); // e.stopPropagation(); } }); }); + function _getCaretPosition(el) { if (angular.isNumber(el.selectionStart)) { return el.selectionStart; @@ -251,7 +234,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel prev = $selectMultiple.activeMatchIndex - 1, newIndex = curr; - if (caretPosition > 0 || ($select.search.length && key == KEY.RIGHT)) { + if (caretPosition > 0 || ($select.search.length && key == $select.KEY.RIGHT)) { return false; } @@ -259,7 +242,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel function getNewActiveMatchIndex() { switch (key) { - case KEY.LEFT: + case $select.KEY.LEFT: // Select previous/first item if (~$selectMultiple.activeMatchIndex) { return prev; @@ -269,7 +252,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel return last; } break; - case KEY.RIGHT: + case $select.KEY.RIGHT: // Open drop-down if (!~$selectMultiple.activeMatchIndex || curr === last) { $select.activate(); @@ -280,7 +263,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel return next; } break; - case KEY.BACKSPACE: + case $select.KEY.BACKSPACE: // Remove selected item and select previous/first if (~$selectMultiple.activeMatchIndex) { $selectMultiple.removeChoice(curr); @@ -291,7 +274,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSel return last; } break; - case KEY.DELETE: + case $select.KEY.DELETE: // Remove selected item and select next item if (~$selectMultiple.activeMatchIndex) { $selectMultiple.removeChoice($selectMultiple.activeMatchIndex); diff --git a/src/uiSelectSingleDirective.js b/src/uiSelectSingleDirective.js index 1b25146a4..787faaa69 100644 --- a/src/uiSelectSingleDirective.js +++ b/src/uiSelectSingleDirective.js @@ -88,7 +88,7 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co }); focusser.bind("keydown", function (e) { - if (e.which === KEY.BACKSPACE) { + if (e.which === $select.KEY.BACKSPACE) { e.preventDefault(); e.stopPropagation(); $select.select(undefined); @@ -96,11 +96,11 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co return; } - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) { + if (e.which === $select.KEY.TAB || $select.KEY.isControl(e) || $select.KEY.isFunctionKey(e) || e.which === $select.KEY.ESC) { return; } - if (e.which == KEY.DOWN || e.which == KEY.UP || e.which == KEY.ENTER || e.which == KEY.SPACE) { + if (e.which == $select.KEY.DOWN || e.which == $select.KEY.UP || e.which == $select.KEY.ENTER || e.which == $select.KEY.SPACE) { e.preventDefault(); e.stopPropagation(); $select.activate(); @@ -110,8 +110,8 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co }); focusser.bind("keyup input", function (e) { - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || - e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { + if (e.which === $select.KEY.TAB || $select.KEY.isControl(e) || $select.KEY.isFunctionKey(e) || e.which === $select.KEY.ESC || + e.which == $select.KEY.ENTER || e.which === $select.KEY.BACKSPACE) { return; } diff --git a/test/select.spec.js b/test/select.spec.js index 91e806606..bcfb646f3 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -907,12 +907,8 @@ describe('ui-select tests', function () { it('should invoke select callback on select', function () { - scope.onSelectFn = function ($item, $model, $label) { - scope.$item = $item; - scope.$model = $model; - }; var el = compileTemplate( - ' \ + ' \ {{$select.selected.name}} \ \
    \ @@ -921,30 +917,45 @@ describe('ui-select tests', function () {
    ' ); + el.scope().$select.afterSelect = function ($item) { + scope.$item = $item; + }; + expect(scope.$item).toBeFalsy(); expect(scope.$model).toBeFalsy(); clickItem(el, 'Samantha'); $timeout.flush(); - expect(scope.selection.selected).toBe('Samantha'); expect(scope.$item).toEqual(scope.people[5]); - expect(scope.$model).toEqual('Samantha'); }); + it('should highlight matched value correctly when it is a number', function () { + var el = compileTemplate( + ' \ + {{$select.selected.age}} \ + \ +
    \ +
    \ +
    ' + ); + openDropdown(el); + setSearchText(el, '43'); + + var choices = $(el).find('.ui-select-choices-row'); + expect(choices.length).toEqual(1); + + clickItem(el, '43'); + expect(scope.selection.selected).toBe(43); + }); + it('should invoke before-select callback before select callback synchronously', function () { var order = []; - scope.onBeforeSelectFn = function ($item, $model, $label) { - order.push('onBeforeSelectFn'); - }; - scope.onSelectFn = function ($item, $model, $label) { - order.push('onSelectFn'); - }; var el = compileTemplate( - ' \ + ' \ {{$select.selected.name}} \ \
    \ @@ -953,29 +964,55 @@ describe('ui-select tests', function () {
    ' ); + el.scope().$select.beforeSelect = function ($item) { + order.push('beforeSelectFn'); + return true; + }; + el.scope().$select.afterSelect = function ($item) { + order.push('afterSelectFn'); + }; + clickItem(el, 'Samantha'); $timeout.flush(); - expect(order[0]).toEqual('onBeforeSelectFn'); - expect(order[1]).toEqual('onSelectFn'); - + expect(order[0]).toEqual('beforeSelectFn'); + expect(order[1]).toEqual('afterSelectFn'); }); it('should invoke before-select callback before select callback when promised', inject(function ($q) { var order = []; - scope.onBeforeSelectFn = function ($item, $model, $label) { + var el = compileTemplate( + ' \ + {{$select.selected.name}} \ + \ +
    \ +
    \ +
    \ +
    ' + ); + + el.scope().$select.beforeSelect = function ($item) { var deferred = $q.defer(); $timeout(function () { - order.push('onBeforeSelectFn'); + order.push('beforeSelectFn'); deferred.resolve(order); }); return deferred.promise; }; - scope.onSelectFn = function ($item, $model, $label) { - order.push('onSelectFn'); + el.scope().$select.afterSelect = function ($item) { + order.push('afterSelectFn'); }; + + clickItem(el, 'Samantha'); + $timeout.flush(); + + expect(order[0]).toEqual('beforeSelectFn'); + expect(order[1]).toEqual('afterSelectFn'); + })); + + it('should complete on-select if before-select callback promise is resolved', inject(function ($q) { var el = compileTemplate( - ' \ + ' \ {{$select.selected.name}} \ \
    \ @@ -984,37 +1021,19 @@ describe('ui-select tests', function () {
    ' ); - clickItem(el, 'Samantha'); - $timeout.flush(); - - expect(order[0]).toEqual('onBeforeSelectFn'); - expect(order[1]).toEqual('onSelectFn'); - })); - - it('should complete on-select if before-select callback promise is resolved', inject(function ($q) { - scope.onBeforeSelectFn = function ($item, $model, $label) { + el.scope().$select.beforeSelect = function ($item) { var deferred = $q.defer(); $timeout(function () { deferred.resolve(true); }); return deferred.promise; }; - scope.onSelectFn = function ($item, $model, $label) { + el.scope().$select.afterSelect = function ($item) { scope.$item = $item; - scope.$model = $model; }; - var el = compileTemplate( - ' \ - {{$select.selected.name}} \ - \ -
    \ -
    \ -
    \ -
    ' - ); expect(scope.$item).toBeFalsy(); - expect(scope.$model).toBeFalsy(); +// expect(scope.$model).toBeFalsy(); clickItem(el, 'Samantha'); $timeout.flush(); @@ -1022,19 +1041,12 @@ describe('ui-select tests', function () { expect(scope.selection.selected).toBe('Samantha'); expect(scope.$item).toEqual(scope.people[5]); - expect(scope.$model).toEqual('Samantha'); +// expect(scope.$model).toEqual('Samantha'); })); it('should abort selection if before-select callback returns falsy', function () { - scope.onBeforeSelectFn = function ($item, $model, $label) { - return false; - }; - scope.onSelectFn = function ($item, $model, $label) { - scope.$item = $item; - scope.$model = $model; - }; var el = compileTemplate( - ' \ + ' \ {{$select.selected.name}} \ \
    \ @@ -1043,30 +1055,26 @@ describe('ui-select tests', function () {
    ' ); + el.scope().$select.beforeSelect = function ($item) { + return false; + }; + el.scope().$select.afterSelect = function ($item) { + scope.$item = $item; + }; + expect(scope.$item).toBeFalsy(); - expect(scope.$model).toBeFalsy(); +// expect(scope.$model).toBeFalsy(); clickItem(el, 'Samantha'); $timeout.flush(); expect(scope.$item).toBeFalsy(); - expect(scope.$model).toBeFalsy(); +// expect(scope.$model).toBeFalsy(); }); it('should abort selection if before-select callback rejects promise', inject(function ($q) { - scope.onBeforeSelectFn = function ($item, $model, $label) { - var deferred = $q.defer(); - $timeout(function () { - deferred.reject(); - }); - return deferred.promise; - }; - scope.onSelectFn = function ($item, $model, $label) { - scope.$item = $item; - scope.$model = $model; - }; var el = compileTemplate( - ' \ + ' \ {{$select.selected.name}} \ \
    \ @@ -1075,25 +1083,31 @@ describe('ui-select tests', function () {
    ' ); + el.scope().$select.beforeSelect = function ($item) { + var deferred = $q.defer(); + $timeout(function () { + deferred.reject(); + }); + return deferred.promise; + }; + el.scope().$select.afterSelect = function ($item) { + scope.$item = $item; + }; + expect(scope.$item).toBeFalsy(); - expect(scope.$model).toBeFalsy(); clickItem(el, 'Samantha'); $timeout.flush(); expect(scope.$item).toBeFalsy(); - expect(scope.$model).toBeFalsy(); })); it('should keep reference to current selection and incoming selection within before-select callback', function () { var currentSelection, incomingSelection; - scope.onBeforeSelectFn = function ($item, $model, $label) { - incomingSelection = $item; - currentSelection = scope.selection.selected; - }; + var el = compileTemplate( - ' \ + ' \ {{$select.selected.name}} \ \
    \ @@ -1102,6 +1116,12 @@ describe('ui-select tests', function () {
    ' ); + el.scope().$select.beforeSelect = function ($item) { + incomingSelection = $item; + currentSelection = scope.selection.selected; + return true; + }; + clickItem(el, 'Samantha'); $timeout.flush(); @@ -1116,15 +1136,14 @@ describe('ui-select tests', function () { }); - it('should invoke hover callback', function () { - + it('should invoke highlight callback', function () { var highlighted; scope.onHighlightFn = function ($item) { highlighted = $item; }; var el = compileTemplate( - ' \ + ' \ {{$select.selected.name}} \ \
    \ @@ -1146,14 +1165,8 @@ describe('ui-select tests', function () { }); it('should set $item & $model correctly when invoking callback on select and no single prop. binding', function () { - - scope.onSelectFn = function ($item, $model, $label) { - scope.$item = $item; - scope.$model = $model; - }; - var el = compileTemplate( - ' \ + ' \ {{$select.selected.name}} \ \
    \ @@ -1162,22 +1175,20 @@ describe('ui-select tests', function () {
    ' ); + el.scope().$select.beforeSelect = function ($item) { + scope.$item = $item; + return true; + }; + expect(scope.$item).toBeFalsy(); - expect(scope.$model).toBeFalsy(); clickItem(el, 'Samantha'); - expect(scope.$item).toEqual(scope.$model); - + expect(scope.$item).toEqual(scope.selection.selected); }); it('should invoke remove callback on remove', function () { - scope.onRemoveFn = function ($item, $model, $label) { - scope.$item = $item; - scope.$model = $model; - }; - var el = compileTemplate( - ' \ + ' \ {{$select.selected.name}} \ \
    \ @@ -1186,8 +1197,11 @@ describe('ui-select tests', function () {
    ' ); + el.scope().$select.afterRemove = function ($item) { + scope.$item = $item; + }; + expect(scope.$item).toBeFalsy(); - expect(scope.$model).toBeFalsy(); clickItem(el, 'Samantha'); clickItem(el, 'Adrian'); @@ -1195,18 +1209,12 @@ describe('ui-select tests', function () { $timeout.flush(); expect(scope.$item).toBe(scope.people[5]); - expect(scope.$model).toBe('Samantha'); + expect(scope.selection.selected).toBe('Samantha'); }); it('should set $item & $model correctly when invoking callback on remove and no single prop. binding', function () { - - scope.onRemoveFn = function ($item, $model, $label) { - scope.$item = $item; - scope.$model = $model; - }; - var el = compileTemplate( - ' \ + ' \ {{$select.selected.name}} \ \
    \ @@ -1215,8 +1223,11 @@ describe('ui-select tests', function () {
    ' ); + el.scope().$select.afterRemove = function ($item) { + scope.$item = $item; + }; + expect(scope.$item).toBeFalsy(); - expect(scope.$model).toBeFalsy(); clickItem(el, 'Samantha'); clickItem(el, 'Adrian'); @@ -1224,7 +1235,7 @@ describe('ui-select tests', function () { $timeout.flush(); expect(scope.$item).toBe(scope.people[5]); - expect(scope.$model).toBe(scope.$item); + expect(scope.selection.selected).toBe(scope.$item); }); it('should append/transclude content (with correct scope) that users add at tag', function () { @@ -1247,10 +1258,9 @@ describe('ui-select tests', function () { clickItem(el, 'Wladimir'); expect(getMatchLabel(el).trim()).not.toEqual('Wladimir'); expect(getMatchLabel(el).trim()).toEqual('WLADIMIR'); - }); - it('should append/transclude content (with correct scope) that users add at tag', function () { + it('should append/transclude content (with correct scope) that users add at tag', function () { var el = compileTemplate( ' \ \ @@ -1266,12 +1276,9 @@ describe('ui-select tests', function () { openDropdown(el); expect($(el).find('.only-once').length).toEqual(1); - - }); it('should format view value correctly when using single property binding and refresh function', function () { - var el = compileTemplate( ' \ {{$select.selected.name}} \ @@ -1302,7 +1309,6 @@ describe('ui-select tests', function () { setSearchText(el, 'o'); expect(getMatchLabel(el)).toBe('Samantha'); - }); describe('search-enabled option', function () { @@ -1878,7 +1884,6 @@ describe('ui-select tests', function () { }); it('should change viewvalue only once when updating modelvalue', function () { - scope.selection.selectedMultiple = ['wladimir@email.com', 'samantha@email.com']; var el = compileTemplate( @@ -1900,12 +1905,10 @@ describe('ui-select tests', function () { clickItem(el, 'Nicole'); expect(scope.counter).toBe(1); - }); it('should run $formatters when changing model directly', function () { - scope.selection.selectedMultiple = ['wladimir@email.com', 'samantha@email.com']; var el = compileTemplate( @@ -1932,7 +1935,6 @@ describe('ui-select tests', function () { }); it('should support multiple="multiple" attribute', function () { - var el = compileTemplate( ' \ {{$item.name}} <{{$item.email}}> \ @@ -1948,7 +1950,9 @@ describe('ui-select tests', function () { }); it('should allow paste tag from clipboard', function () { - scope.taggingFunc = function (name) { + var el = createUiSelectMultiple({taggingTokens: ",|ENTER"}); + + el.scope().$select.beforeTagging = function (item) { return { name: name, email: name + '@email.com', @@ -1957,7 +1961,6 @@ describe('ui-select tests', function () { }; }; - var el = createUiSelectMultiple({tagging: 'taggingFunc', taggingTokens: ",|ENTER"}); clickMatch(el); triggerPaste(el.find('input'), 'tag1'); @@ -1965,7 +1968,9 @@ describe('ui-select tests', function () { }); it('should allow paste multiple tags', function () { - scope.taggingFunc = function (name) { + var el = createUiSelectMultiple({taggingTokens: ",|ENTER"}); + + el.scope().$select.beforeTagging = function (item) { return { name: name, email: name + '@email.com', @@ -1973,8 +1978,6 @@ describe('ui-select tests', function () { age: 12 }; }; - - var el = createUiSelectMultiple({tagging: 'taggingFunc', taggingTokens: ",|ENTER"}); clickMatch(el); triggerPaste(el.find('input'), ',tag1,tag2,tag3,,tag5,'); From 91473268ddffca24de1700d29391dac07681b082 Mon Sep 17 00:00:00 2001 From: Chris Jackson Date: Tue, 11 Aug 2015 20:09:23 +0100 Subject: [PATCH 27/28] Update tagging paste and tests --- dist/select.bootstrap.js | 14 +- dist/select.bootstrap.min.js | 2 +- dist/select.css | 2 +- dist/select.js | 334 ++++++++++++------------- dist/select.min.css | 2 +- dist/select.min.js | 4 +- dist/select.no-tpl.js | 14 +- dist/select.no-tpl.min.js | 2 +- dist/select.select2.js | 14 +- dist/select.select2.min.js | 2 +- dist/select.selectize.js | 14 +- dist/select.selectize.min.js | 2 +- dist/select.sort.js | 11 +- dist/select.sort.min.js | 4 +- dist/select.tpl.js | 2 +- src/addons/uiSelectTaggingDirective.js | 30 +-- src/uiSelectController.js | 12 +- test/select.spec.js | 45 ++-- 18 files changed, 241 insertions(+), 269 deletions(-) diff --git a/dist/select.bootstrap.js b/dist/select.bootstrap.js index fd69b191d..38189760e 100644 --- a/dist/select.bootstrap.js +++ b/dist/select.bootstrap.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-09T18:09:19.169Z + * Version: 0.12.1 - 2015-08-11T18:41:59.467Z * License: MIT */ @@ -570,7 +570,7 @@ uis.controller('uiSelectCtrl', var isActive = itemIndex === -1 ? false : itemIndex === ctrl.activeIndex; // If this is active, and we've defined a callback, do it! - // TODO: Needed? + // TODO: Is this needed? If it is, then implement properly. // if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { // itemScope.$eval(ctrl.onHighlightCallback); // } @@ -594,8 +594,10 @@ uis.controller('uiSelectCtrl', if (itemIndex >= 0 && !angular.isUndefined(ctrl.disableChoiceExpression)) { item = ctrl.items[itemIndex]; - isDisabled = !!(itemScope.$eval(ctrl.disableChoiceExpression)); // force the boolean value - item._uiSelectChoiceDisabled = isDisabled; // store this for later reference + // Force the boolean value + isDisabled = !!(itemScope.$eval(ctrl.disableChoiceExpression)); + // Store this for later reference + item._uiSelectChoiceDisabled = isDisabled; } return isDisabled; @@ -841,10 +843,6 @@ uis.controller('uiSelectCtrl', e.preventDefault(); e.stopPropagation(); } - - // Let the users process the data - // TODO: Is this needed, or just let the user bind to the event themselves! -// ctrl.afterKeypress(e); }); ctrl.searchInput.on('keyup', function (e) { diff --git a/dist/select.bootstrap.min.js b/dist/select.bootstrap.min.js index f8f2afb28..6a1439d19 100644 --- a/dist/select.bootstrap.min.js +++ b/dist/select.bootstrap.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-09T18:09:19.169Z + * Version: 0.12.1 - 2015-08-11T18:41:59.467Z * License: MIT */ !function(){"use strict";void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var e=0,t=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return e++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,i,c){c(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return t=String(t),n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var i=n[0].getBoundingClientRect();return{width:i.width||n.prop("offsetWidth"),height:i.height||n.prop("offsetHeight"),top:i.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:i.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);t.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,c){if(!c.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,c,l,r,s){var o=l.groupBy,a=l.groupFilter;if(r.parseRepeatAttr(l.repeat,o,a),r.disableChoiceExpression=l.uiDisableChoice,r.onHighlightCallback=l.onHighlight,o){var u=c.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=c.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(r.parserResult.itemName,"$select.items",r.parserResult.trackByExp,o)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+r.parserResult.itemName+")").attr("ng-click","$select.select("+r.parserResult.itemName+",false,$event)");var d=c.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),i(c,s)(e),e.$watch("$select.search",function(e){e&&!r.open&&r.multiple&&r.activate(!1,!0),r.activeIndex=0})}}}}]),t.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(e,t,n,i,c,l,r,s){function o(){(d.resetSearchInput||void 0===d.resetSearchInput&&s.resetSearchInput)&&(d.search=h,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function a(e,t){var n,i,c=[];for(n=0;n0&&d.activeIndex--;break;case d.KEY.TAB:(!d.multiple||d.open)&&d.select(d.items[d.activeIndex],!0);break;case d.KEY.ENTER:d.open?void 0!==d.items[d.activeIndex]&&d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case d.KEY.ESC:d.close();break;default:t=!1}return t}function p(){var e=t.querySelectorAll(".ui-select-choices-content"),n=e.querySelectorAll(".ui-select-choices-row");if(n.length<1)throw r("choices","Expected multiple .ui-select-choices-row but got '{0}'.",n.length);if(!(d.activeIndex<0)){var i=n[d.activeIndex],c=i.offsetTop+i.clientHeight-e[0].scrollTop,l=e[0].offsetHeight;c>l?e[0].scrollTop+=c-l:c=112&&123>=e},isVerticalMovement:function(e){return~[d.KEY.UP,d.KEY.DOWN].indexOf(e)},isHorizontalMovement:function(e){return~[d.KEY.LEFT,d.KEY.RIGHT,d.KEY.BACKSPACE,d.KEY.DELETE].indexOf(e)}},d.isEmpty=function(){return angular.isUndefined(d.selected)||null===d.selected||""===d.selected},d.findGroupByName=function(e){return d.groups&&d.groups.filter(function(t){return t.name===e})[0]},d.activate=function(t,i){if(d.disabled||d.open)d.open&&!d.searchEnabled&&d.close();else{var c=function(){i||o(),e.$broadcast("uis:activate"),d.open=!0,d.searchEnabled||angular.element(d.searchInput[0]).addClass("ui-select-offscreen"),d.activeIndex=d.activeIndex>=d.items.length?0:d.activeIndex,n(function(){d.search=t||d.search,d.searchInput[0].focus()})},l=d.beforeDropdownOpen();angular.isFunction(l.then)?l.then(function(e){e===!0&&c()}):l===!0&&c()}},d.parseRepeatAttr=function(t,n,i){function c(t){var c=e.$eval(n);if(d.groups=[],angular.forEach(t,function(e){var t=angular.isFunction(c)?c(e):e[c],n=d.findGroupByName(t);n?n.items.push(e):d.groups.push({name:t,items:[e]})}),i){var l=e.$eval(i);angular.isFunction(l)?d.groups=l(d.groups):angular.isArray(l)&&(d.groups=a(d.groups,l))}d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function s(e){d.items=e}d.setItemsFn=n?c:s,d.parserResult=l.parse(t),d.isGrouped=!!n,d.itemProperty=d.parserResult.itemName,d.refreshItems=function(t){t=t||d.parserResult.source(e);var n=d.selected;if(d.isEmpty()||angular.isArray(n)&&!n.length||!d.removeSelected)d.setItemsFn(t);else if(void 0!==t){var i=t.filter(function(e){return n.indexOf(e)<0});d.setItemsFn(i)}},e.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw r("items","Expected an array but got '{0}'.",e);d.refreshItems(e),d.ngModel.$modelValue=null}})},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){if(!d.open)return!1;var t=d.items.indexOf(e[d.itemProperty]),n=-1===t?!1:t===d.activeIndex;return n},d.isDisabled=function(e){if(!d.open)return!1;var t,n=d.items.indexOf(e[d.itemProperty]),i=!1;return n>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[n],i=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i},d.select=function(t,i,c){function l(){e.$broadcast("uis:select",t),n(function(){d.afterSelect(t)}),d.closeOnSelect&&d.close(i),c&&"click"===c.type&&(d.clickTriggeredSelect=!0)}if((void 0===t||!t._uiSelectChoiceDisabled)&&(d.items||d.search)){var r=d.beforeSelect(t);angular.isFunction(r.then)?r.then(function(e){e&&(e===!0?l(t):e&&l(e))}):r===!0?l(t):r&&l(r)}},d.close=function(t){function n(){d.ngModel&&d.ngModel.$setTouched&&d.ngModel.$setTouched(),o(),d.open=!1,d.searchEnabled||angular.element(d.searchInput[0]).removeClass("ui-select-offscreen"),e.$broadcast("uis:close",t)}if(d.open){var i=d.beforeDropdownClose();angular.isFunction(i.then)?i.then(function(e){e===!0&&n()}):i===!0&&n()}},d.setFocus=function(){d.focus||d.focusInput[0].focus()},d.clear=function(e){d.select(void 0),e.stopPropagation(),n(function(){d.focusser[0].focus()},0,!1)},d.toggle=function(e){d.open?(d.close(),e.preventDefault(),e.stopPropagation()):d.activate()},d.isLocked=function(e,t){var n,i=d.selected[t];return i&&!angular.isUndefined(d.lockChoiceExpression)&&(n=!!e.$eval(d.lockChoiceExpression),i._uiSelectChoiceLocked=n),n};var f=null;d.sizeSearchInput=function(){var t=d.searchInput[0],i=d.searchInput.parent().parent()[0],c=function(){return i.clientWidth*!!t.offsetParent},l=function(e){if(0===e)return!1;var n=e-t.offsetLeft-d.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=e),d.searchInput.css("width",n+"px"),!0};d.searchInput.css("width","10px"),n(function(){null!==f||l(c())||(f=e.$watch(c,function(e){l(e)&&(f(),f=null)}))})},d.searchInput.on("keydown",function(t){var n=t.which;~[d.KEY.ESC,d.KEY.TAB].indexOf(n)&&d.close(),e.$apply(function(){u(n)}),d.KEY.isVerticalMovement(n)&&d.items.length>0&&p(),(n===d.KEY.ENTER||n===d.KEY.ESC)&&(t.preventDefault(),t.stopPropagation())}),d.searchInput.on("keyup",function(e){e.which===d.KEY.TAB||d.KEY.isControl(e)||d.KEY.isFunctionKey(e)||e.which===d.KEY.ESC||d.KEY.isVerticalMovement(e.which)||d.afterKeypress(e)}),e.$on("$destroy",function(){d.searchInput.off("keyup keydown blur paste")}),d.afterKeypress=function(){},d.beforeSelect=function(){return!0},d.afterSelect=function(){},d.beforeRemove=function(){return!0},d.afterRemove=function(){},d.beforeDropdownOpen=function(){return!0},d.beforeDropdownClose=function(){return!0}}]),t.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,i,c,l,r,s){return{restrict:"EA",templateUrl:function(e,t){var i=t.theme||n.theme;return i+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(l,o){return angular.isDefined(o.multiple)?l.append("").removeAttr("multiple"):l.append(""),function(l,o,a,u,p){function d(e){if(g.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(o[0],e.target):o[0].contains(e.target),!t&&!g.clickTriggeredSelect){var n=["input","button","textarea"],i=angular.element(e.target).controller("uiSelect"),c=i&&i!==g;c||(c=~n.indexOf(e.target.tagName.toLowerCase())),g.close(c),l.$digest()}g.clickTriggeredSelect=!1}}function h(){var t=c(o);b=angular.element('
    '),b[0].style.width=t.width+"px",b[0].style.height=t.height+"px",o.after(b),w=o[0].style.width,e.find("body").append(o),o[0].style.position="absolute",o[0].style.left=t.left+"px",o[0].style.top=t.top+"px",o[0].style.width=t.width+"px"}function f(){null!==b&&(b.replaceWith(o),b=null,o[0].style.position="",o[0].style.left="",o[0].style.top="",o[0].style.width=w)}var g=u[0],v=u[1];g.generatedId=n.generateId(),g.baseTitle=a.title||"Select box",g.focusserTitle=g.baseTitle+" focus",g.focusserId="focusser-"+g.generatedId,g.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?r(a.closeOnSelect)():n.closeOnSelect}(),g.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,g.ngModel=v,g.choiceGrouped=function(e){return g.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){g.focusInput.attr("tabindex",e),o.removeAttr("tabindex")});var m=l.$eval(a.searchEnabled);g.searchEnabled=void 0!==m?m:n.searchEnabled;var E=l.$eval(a.sortable);g.sortable=void 0!==E?E:n.sortable,a.$observe("disabled",function(){g.disabled=void 0!==a.disabled?a.disabled:!1}),angular.isDefined(a.autofocus)&&s(function(){g.setFocus()}),angular.isDefined(a.focusOn)&&l.$on(a.focusOn,function(){s(function(){g.setFocus()})}),e.on("click",d),l.$on("$destroy",function(){e.off("click",d)}),p(l,function(e){var t=angular.element("
    ").append(e),n=t.querySelectorAll(".ui-select-match");if(n.removeAttr("ui-select-match"),n.removeAttr("data-ui-select-match"),1!==n.length)throw i("transcluded","Expected 1 .ui-select-match but got '{0}'.",n.length);o.querySelectorAll(".ui-select-match").replaceWith(n);var c=t.querySelectorAll(".ui-select-choices");if(c.removeAttr("ui-select-choices"),c.removeAttr("data-ui-select-choices"),1!==c.length)throw i("transcluded","Expected 1 .ui-select-choices but got '{0}'.",c.length);o.querySelectorAll(".ui-select-choices").replaceWith(c)});var $=l.$eval(a.appendToBody);(void 0!==$?$:n.appendToBody)&&(l.$watch("$select.open",function(e){e?h():f()}),l.$on("$destroy",function(){f()}));var b=null,w="",x=null,S="direction-up";l.$watch("$select.open",function(n){if(n){if(x=angular.element(o).querySelectorAll(".ui-select-dropdown"),null===x)return;x[0].style.opacity=0,s(function(){var n=c(o),i=c(x);n.top+n.height+i.height>t.pageYOffset+e[0].documentElement.clientHeight&&o.addClass(S),x[0].style.opacity=1})}else{if(null===x)return;o.removeClass(S)}})}}}}]),t.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return n+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,i,c){function l(e){c.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}c.lockChoiceExpression=i.uiLockChoice,i.$observe("placeholder",function(t){c.placeholder=void 0!==t?t:e.placeholder}),i.$observe("allowClear",l),l(i.allowClear),c.multiple&&c.sizeSearchInput()}}}]),t.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,i=this,c=e.$select;e.$evalAsync(function(){n=e.ngModel}),i.activeMatchIndex=-1,i.updateModel=function(){n.$setViewValue(Date.now()),i.refreshComponent()},i.refreshComponent=function(){c.refreshItems(),c.sizeSearchInput()},i.removeChoice=function(e){function n(){c.selected.splice(e,1),i.activeMatchIndex=-1,c.sizeSearchInput(),t(function(){c.afterRemove(l)}),i.updateModel()}var l=c.selected[e];if(!l._uiSelectChoiceLocked){var r=c.beforeRemove(l);angular.isFunction(r.then)?r.then(function(e){e===!0&&n()}):r===!0&&n()}},i.getPlaceholder=function(){return c.selected&&c.selected.length?void 0:c.placeholder}}],controllerAs:"$selectMultiple",link:function(n,i,c,l){function r(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function s(e){function t(){switch(e){case o.KEY.LEFT:return~u.activeMatchIndex?p:l;case o.KEY.RIGHT:return~u.activeMatchIndex&&s!==l?a:(o.activate(),!1);case o.KEY.BACKSPACE:return~u.activeMatchIndex?(u.removeChoice(s),p):l;case o.KEY.DELETE:return~u.activeMatchIndex?(u.removeChoice(u.activeMatchIndex),s):!1}}var n=r(o.searchInput[0]),i=o.selected.length,c=0,l=i-1,s=u.activeMatchIndex,a=u.activeMatchIndex+1,p=u.activeMatchIndex-1,d=s;return n>0||o.search.length&&e==o.KEY.RIGHT?!1:(o.close(),d=t(),u.activeMatchIndex=o.selected.length&&d!==!1?Math.min(l,Math.max(c,d)):-1,!0)}var o=l[0],a=n.ngModel=l[1],u=n.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,a.$parsers.unshift(function(){for(var e,t={},i=[],c=o.selected.length-1;c>=0;c--)t={},t[o.parserResult.itemName]=o.selected[c],e=o.parserResult.modelMapper(n,t),i.unshift(e);return i}),a.$formatters.unshift(function(e){var t,i=o.parserResult.source(n,{$select:{search:""}}),c={};if(!i)return e;var l=[],r=function(e,i){if(e&&e.length){for(var r=e.length-1;r>=0;r--){if(c[o.parserResult.itemName]=e[r],t=o.parserResult.modelMapper(n,c),o.parserResult.trackByExp){var s=/\.(.+)/.exec(o.parserResult.trackByExp);if(s.length>0&&t[s[1]]==i[s[1]])return l.unshift(e[r]),!0}if(angular.equals(t,i))return l.unshift(e[r]),!0}return!1}};if(!e)return l;for(var s=e.length-1;s>=0;s--)r(o.selected,e[s])||r(i,e[s])||l.unshift(e[s]);return l}),n.$watchCollection(function(){return a.$modelValue},function(e,t){t!=e&&(a.$modelValue=null,u.refreshComponent())}),a.$render=function(){if(!angular.isArray(a.$viewValue)){if(!angular.isUndefined(a.$viewValue)&&null!==a.$viewValue)throw e("multiarr","Expected model value to be array but got '{0}'",a.$viewValue);o.selected=[]}o.selected=a.$viewValue,n.$evalAsync()},n.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),u.updateModel())}),n.$on("uis:activate",function(){u.activeMatchIndex=-1}),n.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(e){var t=e.which;n.$apply(function(){var e=!1;o.KEY.isHorizontalMovement(t)&&(e=s(t)),e&&t!=o.KEY.TAB})}),o.searchInput.on("blur",function(){t(function(){u.activeMatchIndex=-1})})}}}]),t.directive("uiSelectSingle",["$timeout","$compile",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(n,i,c,l){var r=l[0],s=l[1];s.$parsers.unshift(function(e){var t,i={};return i[r.parserResult.itemName]=e,t=r.parserResult.modelMapper(n,i)}),s.$formatters.unshift(function(e){var t,i=r.parserResult.source(n,{$select:{search:""}}),c={};if(i){var l=function(i){return c[r.parserResult.itemName]=i,t=r.parserResult.modelMapper(n,c),t==e};if(r.selected&&l(r.selected))return r.selected;for(var s=i.length-1;s>=0;s--)if(l(i[s]))return i[s]}return e}),n.$watch("$select.selected",function(e){s.$viewValue!==e&&s.$setViewValue(e)}),s.$render=function(){r.selected=s.$viewValue},n.$on("uis:select",function(e,t){r.selected=t}),n.$on("uis:close",function(t,n){e(function(){r.focusser.prop("disabled",!1),n||r.focusser[0].focus()},0,!1)}),n.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");t(o)(n),r.focusser=o,r.focusInput=o,i.parent().append(o),o.bind("focus",function(){n.$evalAsync(function(){r.focus=!0})}),o.bind("blur",function(){n.$evalAsync(function(){r.focus=!1})}),o.bind("keydown",function(e){return e.which===r.KEY.BACKSPACE?(e.preventDefault(),e.stopPropagation(),r.select(void 0),n.$apply(),void 0):(e.which===r.KEY.TAB||r.KEY.isControl(e)||r.KEY.isFunctionKey(e)||e.which===r.KEY.ESC||((e.which==r.KEY.DOWN||e.which==r.KEY.UP||e.which==r.KEY.ENTER||e.which==r.KEY.SPACE)&&(e.preventDefault(),e.stopPropagation(),r.activate()),n.$digest()),void 0)}),o.bind("keyup input",function(e){e.which===r.KEY.TAB||r.KEY.isControl(e)||r.KEY.isFunctionKey(e)||e.which===r.KEY.ESC||e.which==r.KEY.ENTER||e.which===r.KEY.BACKSPACE||(r.activate(o.val()),o.val(""),n.$digest())})}}}]),t.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var i=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!i)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:i[2],source:t(i[3]),trackByExp:i[4],modelMapper:t(i[1]||i[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,i){var c=e+" in "+(i?"$group.items":t);return n&&(c+=" track by "+n),c}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",'
    {{$select.placeholder}}
    '),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",'')}]); \ No newline at end of file diff --git a/dist/select.css b/dist/select.css index fa4d630f8..09cc8d2b6 100644 --- a/dist/select.css +++ b/dist/select.css @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-09T18:09:19.231Z + * Version: 0.12.1 - 2015-08-11T18:41:59.534Z * License: MIT */ diff --git a/dist/select.js b/dist/select.js index 94d70c573..035b189a2 100644 --- a/dist/select.js +++ b/dist/select.js @@ -1,11 +1,156 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-09T18:09:19.229Z + * Version: 0.12.1 - 2015-08-11T18:41:59.532Z * License: MIT */ +(function () { +"use strict"; +// Make multiple matches sortable +angular.module('ui.select.sort', ['ui.select']) + .directive('uiSelectSort', + ['$timeout', 'uiSelectConfig', 'uiSelectMinErr', function ($timeout, uiSelectConfig, uiSelectMinErr) { + return { + require: '^uiSelect', + link: function (scope, element, attrs, $select) { + if (scope[attrs.uiSelectSort] === null) { + throw uiSelectMinErr('sort', "Expected a list to sort"); + } + + var options = angular.extend({ + axis: 'horizontal' + }, + scope.$eval(attrs.uiSelectSortOptions)); + + var axis = options.axis, + draggingClassName = 'dragging', + droppingClassName = 'dropping', + droppingBeforeClassName = 'dropping-before', + droppingAfterClassName = 'dropping-after'; + + scope.$watch(function () { + return $select.sortable; + }, function (n) { + if (n) { + element.attr('draggable', true); + } else { + element.removeAttr('draggable'); + } + }); + + element.on('dragstart', function (e) { + element.addClass(draggingClassName); + + (e.dataTransfer || e.originalEvent.dataTransfer).setData('text/plain', scope.$index); + }); + + element.on('dragend', function () { + element.removeClass(draggingClassName); + }); + + var move = function (from, to) { + /*jshint validthis: true */ + this.splice(to, 0, this.splice(from, 1)[0]); + }; + + var dragOverHandler = function (e) { + e.preventDefault(); + + var offset = axis === 'vertical' ? + e.offsetY || e.layerY || (e.originalEvent ? e.originalEvent.offsetY : 0) : + e.offsetX || e.layerX || (e.originalEvent ? e.originalEvent.offsetX : 0); + + if (offset < (this[axis === 'vertical' ? 'offsetHeight' : 'offsetWidth'] / 2)) { + element.removeClass(droppingAfterClassName); + element.addClass(droppingBeforeClassName); + + } else { + element.removeClass(droppingBeforeClassName); + element.addClass(droppingAfterClassName); + } + }; + + var dropTimeout; + + var dropHandler = function (e) { + e.preventDefault(); + + var droppedItemIndex = parseInt((e.dataTransfer || + e.originalEvent.dataTransfer).getData('text/plain'), 10); + + // prevent event firing multiple times in firefox + $timeout.cancel(dropTimeout); + dropTimeout = $timeout(function () { + _dropHandler(droppedItemIndex); + }, 20); + }; + + var _dropHandler = function (droppedItemIndex) { + var theList = scope.$eval(attrs.uiSelectSort), + itemToMove = theList[droppedItemIndex], + newIndex = null; + + if (element.hasClass(droppingBeforeClassName)) { + if (droppedItemIndex < scope.$index) { + newIndex = scope.$index - 1; + } else { + newIndex = scope.$index; + } + } else { + if (droppedItemIndex < scope.$index) { + newIndex = scope.$index; + } else { + newIndex = scope.$index + 1; + } + } + + move.apply(theList, [droppedItemIndex, newIndex]); + + scope.$apply(function () { + scope.$emit('uiSelectSort:change', { + array: theList, + item: itemToMove, + from: droppedItemIndex, + to: newIndex + }); + }); + + element.removeClass(droppingClassName); + element.removeClass(droppingBeforeClassName); + element.removeClass(droppingAfterClassName); + + element.off('drop', dropHandler); + }; + + element.on('dragenter', function () { + if (element.hasClass(draggingClassName)) { + return; + } + + element.addClass(droppingClassName); + + element.on('dragover', dragOverHandler); + element.on('drop', dropHandler); + }); + + element.on('dragleave', function (e) { + if (e.target != element) { + return; + } + element.removeClass(droppingClassName); + element.removeClass(droppingBeforeClassName); + element.removeClass(droppingAfterClassName); + + element.off('dragover', dragOverHandler); + element.off('drop', dropHandler); + }); + } + }; + }]); + +}()); (function () { "use strict"; angular.module('ui.select.tagging', ['ui.select']) @@ -23,9 +168,13 @@ angular.module('ui.select.tagging', ['ui.select']) ctrl.searchInput.on('paste', function (e) { var data = e.clipboardData.getData('text/plain'); if (data && data.length > 0) { - var items = data.split(ctrl.taggingTokens[0]); // Split by first token only + // Split by first token only + var items = data.split(ctrl.taggingTokens[0]); if (items && items.length > 0) { angular.forEach(items, function (item) { + if(item === null || item.length === 0) { + return; + } var newItem = ctrl.beforeTagging(item); if (newItem) { ctrl.select(newItem, true); @@ -63,27 +212,21 @@ angular.module('ui.select.tagging', ['ui.select']) } // Check for end of tagging - var tagged = false; -// if (e.which === ctrl.KEY.ENTER) { -// tagged = true; -// } for (var i = 0; i < ctrl.taggingTokens.length; i++) { if (ctrl.taggingTokens[i] === ctrl.KEY.MAP[e.keyCode]) { // Make sure there is a new value to push via tagging if (ctrl.search.length > 0) { - tagged = true; + // Make sure that we don't leave the tagging character on the end of the item label if ($select.search.substr($select.search.length - 1) == ctrl.KEY.MAP[e.keyCode]) { + $select.search = $select.search.substr(0, $select.search.length - 1); + } - $select.search = $select.search.substr(0, $select.search.length - 1); - } + // Select this item and return + ctrl.select(ctrl.beforeTagging($select.search)); + return; } } } - if (tagged === true) { - ctrl.select(ctrl.beforeTagging($select.search)); - return; - } - $select.activeIndex = $select.taggingLabel === false ? -1 : 0; // If taggingLabel === false bypasses all of this @@ -140,7 +283,7 @@ angular.module('ui.select.tagging', ['ui.select']) } return; } -// } + if (hasTag) { dupeIndex = _findApproxDupe($select.selected, newItem); } @@ -164,14 +307,12 @@ angular.module('ui.select.tagging', ['ui.select']) if (arr === undefined || $select.search === undefined) { return false; } - var hasDupe = arr.filter(function (origItem) { + return arr.filter(function (origItem) { if ($select.search.toUpperCase() === undefined || origItem === undefined) { return false; } return origItem.toUpperCase() === $select.search.toUpperCase(); }).length > 0; - - return hasDupe; } function _findApproxDupe(haystack, needle) { @@ -203,151 +344,6 @@ angular.module('ui.select.tagging', ['ui.select']) }; }]); -}()); -(function () { -"use strict"; -// Make multiple matches sortable -angular.module('ui.select.sort', ['ui.select']) - .directive('uiSelectSort', - ['$timeout', 'uiSelectConfig', 'uiSelectMinErr', function ($timeout, uiSelectConfig, uiSelectMinErr) { - return { - require: '^uiSelect', - link: function (scope, element, attrs, $select) { - if (scope[attrs.uiSelectSort] === null) { - throw uiSelectMinErr('sort', "Expected a list to sort"); - } - - var options = angular.extend({ - axis: 'horizontal' - }, - scope.$eval(attrs.uiSelectSortOptions)); - - var axis = options.axis, - draggingClassName = 'dragging', - droppingClassName = 'dropping', - droppingBeforeClassName = 'dropping-before', - droppingAfterClassName = 'dropping-after'; - - scope.$watch(function () { - return $select.sortable; - }, function (n) { - if (n) { - element.attr('draggable', true); - } else { - element.removeAttr('draggable'); - } - }); - - element.on('dragstart', function (e) { - element.addClass(draggingClassName); - - (e.dataTransfer || e.originalEvent.dataTransfer).setData('text/plain', scope.$index); - }); - - element.on('dragend', function () { - element.removeClass(draggingClassName); - }); - - var move = function (from, to) { - /*jshint validthis: true */ - this.splice(to, 0, this.splice(from, 1)[0]); - }; - - var dragOverHandler = function (e) { - e.preventDefault(); - - var offset = axis === 'vertical' ? - e.offsetY || e.layerY || (e.originalEvent ? e.originalEvent.offsetY : 0) : - e.offsetX || e.layerX || (e.originalEvent ? e.originalEvent.offsetX : 0); - - if (offset < (this[axis === 'vertical' ? 'offsetHeight' : 'offsetWidth'] / 2)) { - element.removeClass(droppingAfterClassName); - element.addClass(droppingBeforeClassName); - - } else { - element.removeClass(droppingBeforeClassName); - element.addClass(droppingAfterClassName); - } - }; - - var dropTimeout; - - var dropHandler = function (e) { - e.preventDefault(); - - var droppedItemIndex = parseInt((e.dataTransfer || - e.originalEvent.dataTransfer).getData('text/plain'), 10); - - // prevent event firing multiple times in firefox - $timeout.cancel(dropTimeout); - dropTimeout = $timeout(function () { - _dropHandler(droppedItemIndex); - }, 20); - }; - - var _dropHandler = function (droppedItemIndex) { - var theList = scope.$eval(attrs.uiSelectSort), - itemToMove = theList[droppedItemIndex], - newIndex = null; - - if (element.hasClass(droppingBeforeClassName)) { - if (droppedItemIndex < scope.$index) { - newIndex = scope.$index - 1; - } else { - newIndex = scope.$index; - } - } else { - if (droppedItemIndex < scope.$index) { - newIndex = scope.$index; - } else { - newIndex = scope.$index + 1; - } - } - - move.apply(theList, [droppedItemIndex, newIndex]); - - scope.$apply(function () { - scope.$emit('uiSelectSort:change', { - array: theList, - item: itemToMove, - from: droppedItemIndex, - to: newIndex - }); - }); - - element.removeClass(droppingClassName); - element.removeClass(droppingBeforeClassName); - element.removeClass(droppingAfterClassName); - - element.off('drop', dropHandler); - }; - - element.on('dragenter', function () { - if (element.hasClass(draggingClassName)) { - return; - } - - element.addClass(droppingClassName); - - element.on('dragover', dragOverHandler); - element.on('drop', dropHandler); - }); - - element.on('dragleave', function (e) { - if (e.target != element) { - return; - } - element.removeClass(droppingClassName); - element.removeClass(droppingBeforeClassName); - element.removeClass(droppingAfterClassName); - - element.off('dragover', dragOverHandler); - element.off('drop', dropHandler); - }); - } - }; - }]); - }()); (function () { "use strict"; @@ -913,7 +909,7 @@ uis.controller('uiSelectCtrl', var isActive = itemIndex === -1 ? false : itemIndex === ctrl.activeIndex; // If this is active, and we've defined a callback, do it! - // TODO: Needed? + // TODO: Is this needed? If it is, then implement properly. // if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { // itemScope.$eval(ctrl.onHighlightCallback); // } @@ -937,8 +933,10 @@ uis.controller('uiSelectCtrl', if (itemIndex >= 0 && !angular.isUndefined(ctrl.disableChoiceExpression)) { item = ctrl.items[itemIndex]; - isDisabled = !!(itemScope.$eval(ctrl.disableChoiceExpression)); // force the boolean value - item._uiSelectChoiceDisabled = isDisabled; // store this for later reference + // Force the boolean value + isDisabled = !!(itemScope.$eval(ctrl.disableChoiceExpression)); + // Store this for later reference + item._uiSelectChoiceDisabled = isDisabled; } return isDisabled; @@ -1184,10 +1182,6 @@ uis.controller('uiSelectCtrl', e.preventDefault(); e.stopPropagation(); } - - // Let the users process the data - // TODO: Is this needed, or just let the user bind to the event themselves! -// ctrl.afterKeypress(e); }); ctrl.searchInput.on('keyup', function (e) { diff --git a/dist/select.min.css b/dist/select.min.css index 9370167ce..34ce51d03 100644 --- a/dist/select.min.css +++ b/dist/select.min.css @@ -1,6 +1,6 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-09T18:09:19.231Z + * Version: 0.12.1 - 2015-08-11T18:41:59.534Z * License: MIT */.ui-select-highlight{font-weight:700}.ui-select-offscreen{clip:rect(0 0 0 0)!important;width:1px!important;height:1px!important;border:0!important;margin:0!important;padding:0!important;overflow:hidden!important;position:absolute!important;outline:0!important;left:0!important;top:0!important}.ng-dirty.ng-invalid>a.select2-choice{border-color:#D44950}.select2-result-single{padding-left:0}.select-locked>.ui-select-match-close,.select2-locked>.select2-search-choice-close{display:none}body>.select2-container.open{z-index:9999}.ui-select-container[theme=select2].direction-up .ui-select-match{border-radius:0 0 4px 4px}.ui-select-container[theme=select2].direction-up .ui-select-dropdown{bottom:100%;top:auto;position:absolute;border-radius:4px 4px 0 0;border-top-width:1px;border-top-style:solid;box-shadow:0 -4px 8px rgba(0,0,0,.25);margin-top:-4px}.ui-select-container[theme=select2].direction-up .ui-select-dropdown .select2-search{margin-top:4px}.ui-select-container[theme=select2].direction-up.select2-dropdown-open .ui-select-match{border-bottom-color:#5897fb}.selectize-input.selectize-focus{border-color:#007FBB!important}.selectize-control>.selectize-dropdown,.selectize-control>.selectize-input>input{width:100%}.ng-dirty.ng-invalid>div.selectize-input{border-color:#D44950}.ui-select-container[theme=selectize].direction-up .ui-select-dropdown{bottom:100%;top:auto;position:absolute;box-shadow:0 -4px 8px rgba(0,0,0,.25);margin-top:-2px}.btn-default-focus{color:#333;background-color:#EBEBEB;border-color:#ADADAD;text-decoration:none;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.ui-select-bootstrap .ui-select-toggle{position:relative}.ui-select-bootstrap .ui-select-toggle>.caret{position:absolute;height:10px;top:50%;right:10px;margin-top:-2px}.input-group>.ui-select-bootstrap.dropdown{position:static}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control{border-radius:4px 0 0 4px}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control.direction-up{border-radius:4px 0 0 4px!important}.ui-select-bootstrap>.ui-select-match>.btn{text-align:left!important}.ui-select-bootstrap>.ui-select-match>.caret{position:absolute;top:45%;right:15px}.ui-select-bootstrap>.ui-select-choices{width:100%;height:auto;max-height:200px;overflow-x:hidden;margin-top:-1px}body>.ui-select-bootstrap.open{z-index:1000}.ui-select-multiple.ui-select-bootstrap{height:auto;padding:3px 3px 0}.ui-select-multiple.ui-select-bootstrap input.ui-select-search{background-color:transparent!important;border:none;outline:0;height:1.666666em;margin-bottom:3px}.ui-select-multiple.ui-select-bootstrap .ui-select-match .close{font-size:1.6em;line-height:.75}.ui-select-multiple.ui-select-bootstrap .ui-select-match-item{outline:0;margin:0 3px 3px 0}.ui-select-multiple .ui-select-match-item{position:relative}.ui-select-multiple .ui-select-match-item.dropping-before:before{content:"";position:absolute;top:0;right:100%;height:100%;margin-right:2px;border-left:1px solid #428bca}.ui-select-multiple .ui-select-match-item.dropping-after:after{content:"";position:absolute;top:0;left:100%;height:100%;margin-left:2px;border-right:1px solid #428bca}.ui-select-bootstrap .ui-select-placeholder{opacity:1;color:#999}.ui-select-bootstrap .ui-select-choices-row>a{display:block;padding:3px 20px;clear:both;font-weight:400;line-height:1.42857143;color:#333;white-space:nowrap}.ui-select-bootstrap .ui-select-choices-row>a:focus,.ui-select-bootstrap .ui-select-choices-row>a:hover{text-decoration:none;color:#262626;background-color:#f5f5f5}.ui-select-bootstrap .ui-select-choices-row.active>a{color:#fff;text-decoration:none;outline:0;background-color:#428bca}.ui-select-bootstrap .ui-select-choices-row.active.disabled>a,.ui-select-bootstrap .ui-select-choices-row.disabled>a{color:#777;cursor:not-allowed;background-color:#fff}.ui-select-match.ng-hide-add,.ui-select-search.ng-hide-add{display:none!important}.ui-select-bootstrap.ng-dirty.ng-invalid>button.btn.ui-select-match{border-color:#D44950}.ui-select-container[theme=bootstrap].direction-up .ui-select-dropdown{bottom:100%;top:auto;position:absolute;box-shadow:0 -4px 8px rgba(0,0,0,.25)} \ No newline at end of file diff --git a/dist/select.min.js b/dist/select.min.js index 027944561..0e5a5dec6 100644 --- a/dist/select.min.js +++ b/dist/select.min.js @@ -1,8 +1,8 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-09T18:09:19.229Z + * Version: 0.12.1 - 2015-08-11T18:41:59.532Z * License: MIT */ -!function(){"use strict";angular.module("ui.select.tagging",["ui.select"]).directive("uiSelectTagging",["$parse","$timeout",function(){return{require:"^uiSelect",link:function(e,t,c,l){function s(e){if(void 0===e||void 0===l.search)return!1;var t=e.filter(function(e){return void 0===l.search.toUpperCase()||void 0===e?!1:e.toUpperCase()===l.search.toUpperCase()}).length>0;return t}function i(e,t){var c=-1;if(angular.isArray(e))for(var s=angular.copy(e),i=0;i0){var c=t.split(n.taggingTokens[0]);c&&c.length>0&&(angular.forEach(c,function(e){var t=n.beforeTagging(e);t&&n.select(t,!0)}),e.preventDefault(),e.stopPropagation())}}),n.beforeTagging=function(e){return e},n.afterKeypress=function(t){if(l.search.length>0){if(t.which===n.KEY.TAB||n.KEY.isControl(t)||n.KEY.isFunctionKey(t)||t.which===n.KEY.ESC||n.KEY.isVerticalMovement(t.which))return;for(var c=!1,a=0;a0&&(c=!0,l.search.substr(l.search.length-1)==n.KEY.MAP[t.keyCode]&&(l.search=l.search.substr(0,l.search.length-1)));if(c===!0)return n.select(n.beforeTagging(l.search)),void 0;if(l.activeIndex=l.taggingLabel===!1?-1:0,l.taggingLabel===!1)return;var r,o,u,d,p=angular.copy(l.items),h=angular.copy(l.items),f=!1,g=-1;if(u=l.$filter("filter")(p,function(e){return e.match(l.taggingLabel)}),u.length>0&&(d=u[0]),o=p[0],void 0!==o&&p.length>0&&d&&(f=!0,p=p.slice(1,p.length),h=h.slice(1,h.length)),r=l.search+" "+l.taggingLabel,i(l.selected,l.search)>-1)return;if(s(h.concat(l.selected)))return f&&(p=h,e.$evalAsync(function(){l.activeIndex=0,l.items=p})),void 0;if(s(h))return f&&(l.items=h.slice(1,h.length)),void 0;f&&(g=i(l.selected,r)),g>-1?p=p.slice(g+1,p.length-1):(p=[],p.push(r),p=p.concat(h)),e.$evalAsync(function(){l.activeIndex=0,l.items=p})}}}}}])}(),function(){"use strict";angular.module("ui.select.sort",["ui.select"]).directive("uiSelectSort",["$timeout","uiSelectConfig","uiSelectMinErr",function(e,t,c){return{require:"^uiSelect",link:function(t,l,s,i){if(null===t[s.uiSelectSort])throw c("sort","Expected a list to sort");var n=angular.extend({axis:"horizontal"},t.$eval(s.uiSelectSortOptions)),a=n.axis,r="dragging",o="dropping",u="dropping-before",d="dropping-after";t.$watch(function(){return i.sortable},function(e){e?l.attr("draggable",!0):l.removeAttr("draggable")}),l.on("dragstart",function(e){l.addClass(r),(e.dataTransfer||e.originalEvent.dataTransfer).setData("text/plain",t.$index)}),l.on("dragend",function(){l.removeClass(r)});var p,h=function(e,t){this.splice(t,0,this.splice(e,1)[0])},f=function(e){e.preventDefault();var t="vertical"===a?e.offsetY||e.layerY||(e.originalEvent?e.originalEvent.offsetY:0):e.offsetX||e.layerX||(e.originalEvent?e.originalEvent.offsetX:0);t$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(c){var l=c[0].getBoundingClientRect();return{width:l.width||c.prop("offsetWidth"),height:l.height||c.prop("offsetHeight"),top:l.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:l.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);t.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,c,l){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(e,s){if(!s.repeat)throw c("repeat","Expected 'repeat' expression.");return function(e,s,i,n,a){var r=i.groupBy,o=i.groupFilter;if(n.parseRepeatAttr(i.repeat,r,o),n.disableChoiceExpression=i.uiDisableChoice,n.onHighlightCallback=i.onHighlight,r){var u=s.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=s.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(n.parserResult.itemName,"$select.items",n.parserResult.trackByExp,r)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+n.parserResult.itemName+")").attr("ng-click","$select.select("+n.parserResult.itemName+",false,$event)");var p=s.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),l(s,a)(e),e.$watch("$select.search",function(e){e&&!n.open&&n.multiple&&n.activate(!1,!0),n.activeIndex=0})}}}}]),t.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(e,t,c,l,s,i,n,a){function r(){(p.resetSearchInput||void 0===p.resetSearchInput&&a.resetSearchInput)&&(p.search=h,p.selected&&p.items.length&&!p.multiple&&(p.activeIndex=p.items.indexOf(p.selected)))}function o(e,t){var c,l,s=[];for(c=0;c0&&p.activeIndex--;break;case p.KEY.TAB:(!p.multiple||p.open)&&p.select(p.items[p.activeIndex],!0);break;case p.KEY.ENTER:p.open?void 0!==p.items[p.activeIndex]&&p.select(p.items[p.activeIndex]):p.activate(!1,!0);break;case p.KEY.ESC:p.close();break;default:t=!1}return t}function d(){var e=t.querySelectorAll(".ui-select-choices-content"),c=e.querySelectorAll(".ui-select-choices-row");if(c.length<1)throw n("choices","Expected multiple .ui-select-choices-row but got '{0}'.",c.length);if(!(p.activeIndex<0)){var l=c[p.activeIndex],s=l.offsetTop+l.clientHeight-e[0].scrollTop,i=e[0].offsetHeight;s>i?e[0].scrollTop+=s-i:s=112&&123>=e},isVerticalMovement:function(e){return~[p.KEY.UP,p.KEY.DOWN].indexOf(e)},isHorizontalMovement:function(e){return~[p.KEY.LEFT,p.KEY.RIGHT,p.KEY.BACKSPACE,p.KEY.DELETE].indexOf(e)}},p.isEmpty=function(){return angular.isUndefined(p.selected)||null===p.selected||""===p.selected},p.findGroupByName=function(e){return p.groups&&p.groups.filter(function(t){return t.name===e})[0]},p.activate=function(t,l){if(p.disabled||p.open)p.open&&!p.searchEnabled&&p.close();else{var s=function(){l||r(),e.$broadcast("uis:activate"),p.open=!0,p.searchEnabled||angular.element(p.searchInput[0]).addClass("ui-select-offscreen"),p.activeIndex=p.activeIndex>=p.items.length?0:p.activeIndex,c(function(){p.search=t||p.search,p.searchInput[0].focus()})},i=p.beforeDropdownOpen();angular.isFunction(i.then)?i.then(function(e){e===!0&&s()}):i===!0&&s()}},p.parseRepeatAttr=function(t,c,l){function s(t){var s=e.$eval(c);if(p.groups=[],angular.forEach(t,function(e){var t=angular.isFunction(s)?s(e):e[s],c=p.findGroupByName(t);c?c.items.push(e):p.groups.push({name:t,items:[e]})}),l){var i=e.$eval(l);angular.isFunction(i)?p.groups=i(p.groups):angular.isArray(i)&&(p.groups=o(p.groups,i))}p.items=[],p.groups.forEach(function(e){p.items=p.items.concat(e.items)})}function a(e){p.items=e}p.setItemsFn=c?s:a,p.parserResult=i.parse(t),p.isGrouped=!!c,p.itemProperty=p.parserResult.itemName,p.refreshItems=function(t){t=t||p.parserResult.source(e);var c=p.selected;if(p.isEmpty()||angular.isArray(c)&&!c.length||!p.removeSelected)p.setItemsFn(t);else if(void 0!==t){var l=t.filter(function(e){return c.indexOf(e)<0});p.setItemsFn(l)}},e.$watchCollection(p.parserResult.source,function(e){if(void 0===e||null===e)p.items=[];else{if(!angular.isArray(e))throw n("items","Expected an array but got '{0}'.",e);p.refreshItems(e),p.ngModel.$modelValue=null}})},p.setActiveItem=function(e){p.activeIndex=p.items.indexOf(e)},p.isActive=function(e){if(!p.open)return!1;var t=p.items.indexOf(e[p.itemProperty]),c=-1===t?!1:t===p.activeIndex;return c},p.isDisabled=function(e){if(!p.open)return!1;var t,c=p.items.indexOf(e[p.itemProperty]),l=!1;return c>=0&&!angular.isUndefined(p.disableChoiceExpression)&&(t=p.items[c],l=!!e.$eval(p.disableChoiceExpression),t._uiSelectChoiceDisabled=l),l},p.select=function(t,l,s){function i(){e.$broadcast("uis:select",t),c(function(){p.afterSelect(t)}),p.closeOnSelect&&p.close(l),s&&"click"===s.type&&(p.clickTriggeredSelect=!0)}if((void 0===t||!t._uiSelectChoiceDisabled)&&(p.items||p.search)){var n=p.beforeSelect(t);angular.isFunction(n.then)?n.then(function(e){e&&(e===!0?i(t):e&&i(e))}):n===!0?i(t):n&&i(n)}},p.close=function(t){function c(){p.ngModel&&p.ngModel.$setTouched&&p.ngModel.$setTouched(),r(),p.open=!1,p.searchEnabled||angular.element(p.searchInput[0]).removeClass("ui-select-offscreen"),e.$broadcast("uis:close",t)}if(p.open){var l=p.beforeDropdownClose();angular.isFunction(l.then)?l.then(function(e){e===!0&&c()}):l===!0&&c()}},p.setFocus=function(){p.focus||p.focusInput[0].focus()},p.clear=function(e){p.select(void 0),e.stopPropagation(),c(function(){p.focusser[0].focus()},0,!1)},p.toggle=function(e){p.open?(p.close(),e.preventDefault(),e.stopPropagation()):p.activate()},p.isLocked=function(e,t){var c,l=p.selected[t];return l&&!angular.isUndefined(p.lockChoiceExpression)&&(c=!!e.$eval(p.lockChoiceExpression),l._uiSelectChoiceLocked=c),c};var f=null;p.sizeSearchInput=function(){var t=p.searchInput[0],l=p.searchInput.parent().parent()[0],s=function(){return l.clientWidth*!!t.offsetParent},i=function(e){if(0===e)return!1;var c=e-t.offsetLeft-p.searchInput.parent()[0].offsetLeft-5;return 50>c&&(c=e),p.searchInput.css("width",c+"px"),!0};p.searchInput.css("width","10px"),c(function(){null!==f||i(s())||(f=e.$watch(s,function(e){i(e)&&(f(),f=null)}))})},p.searchInput.on("keydown",function(t){var c=t.which;~[p.KEY.ESC,p.KEY.TAB].indexOf(c)&&p.close(),e.$apply(function(){u(c)}),p.KEY.isVerticalMovement(c)&&p.items.length>0&&d(),(c===p.KEY.ENTER||c===p.KEY.ESC)&&(t.preventDefault(),t.stopPropagation())}),p.searchInput.on("keyup",function(e){e.which===p.KEY.TAB||p.KEY.isControl(e)||p.KEY.isFunctionKey(e)||e.which===p.KEY.ESC||p.KEY.isVerticalMovement(e.which)||p.afterKeypress(e)}),e.$on("$destroy",function(){p.searchInput.off("keyup keydown blur paste")}),p.afterKeypress=function(){},p.beforeSelect=function(){return!0},p.afterSelect=function(){},p.beforeRemove=function(){return!0},p.afterRemove=function(){},p.beforeDropdownOpen=function(){return!0},p.beforeDropdownClose=function(){return!0}}]),t.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,c,l,s,i,n,a){return{restrict:"EA",templateUrl:function(e,t){var l=t.theme||c.theme;return l+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(i,r){return angular.isDefined(r.multiple)?i.append("").removeAttr("multiple"):i.append(""),function(i,r,o,u,d){function p(e){if(g.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(r[0],e.target):r[0].contains(e.target),!t&&!g.clickTriggeredSelect){var c=["input","button","textarea"],l=angular.element(e.target).controller("uiSelect"),s=l&&l!==g;s||(s=~c.indexOf(e.target.tagName.toLowerCase())),g.close(s),i.$digest()}g.clickTriggeredSelect=!1}}function h(){var t=s(r);E=angular.element('
    '),E[0].style.width=t.width+"px",E[0].style.height=t.height+"px",r.after(E),w=r[0].style.width,e.find("body").append(r),r[0].style.position="absolute",r[0].style.left=t.left+"px",r[0].style.top=t.top+"px",r[0].style.width=t.width+"px"}function f(){null!==E&&(E.replaceWith(r),E=null,r[0].style.position="",r[0].style.left="",r[0].style.top="",r[0].style.width=w)}var g=u[0],v=u[1];g.generatedId=c.generateId(),g.baseTitle=o.title||"Select box",g.focusserTitle=g.baseTitle+" focus",g.focusserId="focusser-"+g.generatedId,g.closeOnSelect=function(){return angular.isDefined(o.closeOnSelect)?n(o.closeOnSelect)():c.closeOnSelect}(),g.limit=angular.isDefined(o.limit)?parseInt(o.limit,10):void 0,g.ngModel=v,g.choiceGrouped=function(e){return g.isGrouped&&e&&e.name},o.tabindex&&o.$observe("tabindex",function(e){g.focusInput.attr("tabindex",e),r.removeAttr("tabindex")});var m=i.$eval(o.searchEnabled);g.searchEnabled=void 0!==m?m:c.searchEnabled;var $=i.$eval(o.sortable);g.sortable=void 0!==$?$:c.sortable,o.$observe("disabled",function(){g.disabled=void 0!==o.disabled?o.disabled:!1}),angular.isDefined(o.autofocus)&&a(function(){g.setFocus()}),angular.isDefined(o.focusOn)&&i.$on(o.focusOn,function(){a(function(){g.setFocus()})}),e.on("click",p),i.$on("$destroy",function(){e.off("click",p)}),d(i,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),c.removeAttr("data-ui-select-match"),1!==c.length)throw l("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);r.querySelectorAll(".ui-select-match").replaceWith(c);var s=t.querySelectorAll(".ui-select-choices");if(s.removeAttr("ui-select-choices"),s.removeAttr("data-ui-select-choices"),1!==s.length)throw l("transcluded","Expected 1 .ui-select-choices but got '{0}'.",s.length);r.querySelectorAll(".ui-select-choices").replaceWith(s)});var b=i.$eval(o.appendToBody);(void 0!==b?b:c.appendToBody)&&(i.$watch("$select.open",function(e){e?h():f()}),i.$on("$destroy",function(){f()}));var E=null,w="",x=null,y="direction-up";i.$watch("$select.open",function(c){if(c){if(x=angular.element(r).querySelectorAll(".ui-select-dropdown"),null===x)return;x[0].style.opacity=0,a(function(){var c=s(r),l=s(x);c.top+c.height+l.height>t.pageYOffset+e[0].documentElement.clientHeight&&r.addClass(y),x[0].style.opacity=1})}else{if(null===x)return;r.removeClass(y)}})}}}}]),t.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,l=t.parent().attr("multiple");return c+(l?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,l,s){function i(e){s.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}s.lockChoiceExpression=l.uiLockChoice,l.$observe("placeholder",function(t){s.placeholder=void 0!==t?t:e.placeholder}),l.$observe("allowClear",i),i(l.allowClear),s.multiple&&s.sizeSearchInput()}}}]),t.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var c,l=this,s=e.$select;e.$evalAsync(function(){c=e.ngModel}),l.activeMatchIndex=-1,l.updateModel=function(){c.$setViewValue(Date.now()),l.refreshComponent()},l.refreshComponent=function(){s.refreshItems(),s.sizeSearchInput()},l.removeChoice=function(e){function c(){s.selected.splice(e,1),l.activeMatchIndex=-1,s.sizeSearchInput(),t(function(){s.afterRemove(i)}),l.updateModel()}var i=s.selected[e];if(!i._uiSelectChoiceLocked){var n=s.beforeRemove(i);angular.isFunction(n.then)?n.then(function(e){e===!0&&c()}):n===!0&&c()}},l.getPlaceholder=function(){return s.selected&&s.selected.length?void 0:s.placeholder}}],controllerAs:"$selectMultiple",link:function(c,l,s,i){function n(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(e){function t(){switch(e){case r.KEY.LEFT:return~u.activeMatchIndex?d:i;case r.KEY.RIGHT:return~u.activeMatchIndex&&a!==i?o:(r.activate(),!1);case r.KEY.BACKSPACE:return~u.activeMatchIndex?(u.removeChoice(a),d):i;case r.KEY.DELETE:return~u.activeMatchIndex?(u.removeChoice(u.activeMatchIndex),a):!1}}var c=n(r.searchInput[0]),l=r.selected.length,s=0,i=l-1,a=u.activeMatchIndex,o=u.activeMatchIndex+1,d=u.activeMatchIndex-1,p=a;return c>0||r.search.length&&e==r.KEY.RIGHT?!1:(r.close(),p=t(),u.activeMatchIndex=r.selected.length&&p!==!1?Math.min(i,Math.max(s,p)):-1,!0)}var r=i[0],o=c.ngModel=i[1],u=c.$selectMultiple;r.multiple=!0,r.removeSelected=!0,r.focusInput=r.searchInput,o.$parsers.unshift(function(){for(var e,t={},l=[],s=r.selected.length-1;s>=0;s--)t={},t[r.parserResult.itemName]=r.selected[s],e=r.parserResult.modelMapper(c,t),l.unshift(e);return l}),o.$formatters.unshift(function(e){var t,l=r.parserResult.source(c,{$select:{search:""}}),s={};if(!l)return e;var i=[],n=function(e,l){if(e&&e.length){for(var n=e.length-1;n>=0;n--){if(s[r.parserResult.itemName]=e[n],t=r.parserResult.modelMapper(c,s),r.parserResult.trackByExp){var a=/\.(.+)/.exec(r.parserResult.trackByExp);if(a.length>0&&t[a[1]]==l[a[1]])return i.unshift(e[n]),!0}if(angular.equals(t,l))return i.unshift(e[n]),!0}return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(r.selected,e[a])||n(l,e[a])||i.unshift(e[a]);return i}),c.$watchCollection(function(){return o.$modelValue},function(e,t){t!=e&&(o.$modelValue=null,u.refreshComponent())}),o.$render=function(){if(!angular.isArray(o.$viewValue)){if(!angular.isUndefined(o.$viewValue)&&null!==o.$viewValue)throw e("multiarr","Expected model value to be array but got '{0}'",o.$viewValue);r.selected=[]}r.selected=o.$viewValue,c.$evalAsync()},c.$on("uis:select",function(e,t){r.selected.length>=r.limit||(r.selected.push(t),u.updateModel())}),c.$on("uis:activate",function(){u.activeMatchIndex=-1}),c.$watch("$select.disabled",function(e,t){t&&!e&&r.sizeSearchInput()}),r.searchInput.on("keydown",function(e){var t=e.which;c.$apply(function(){var e=!1;r.KEY.isHorizontalMovement(t)&&(e=a(t)),e&&t!=r.KEY.TAB})}),r.searchInput.on("blur",function(){t(function(){u.activeMatchIndex=-1})})}}}]),t.directive("uiSelectSingle",["$timeout","$compile",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(c,l,s,i){var n=i[0],a=i[1];a.$parsers.unshift(function(e){var t,l={};return l[n.parserResult.itemName]=e,t=n.parserResult.modelMapper(c,l)}),a.$formatters.unshift(function(e){var t,l=n.parserResult.source(c,{$select:{search:""}}),s={};if(l){var i=function(l){return s[n.parserResult.itemName]=l,t=n.parserResult.modelMapper(c,s),t==e};if(n.selected&&i(n.selected))return n.selected;for(var a=l.length-1;a>=0;a--)if(i(l[a]))return l[a]}return e}),c.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){n.selected=a.$viewValue},c.$on("uis:select",function(e,t){n.selected=t}),c.$on("uis:close",function(t,c){e(function(){n.focusser.prop("disabled",!1),c||n.focusser[0].focus()},0,!1)}),c.$on("uis:activate",function(){r.prop("disabled",!0)});var r=angular.element("");t(r)(c),n.focusser=r,n.focusInput=r,l.parent().append(r),r.bind("focus",function(){c.$evalAsync(function(){n.focus=!0})}),r.bind("blur",function(){c.$evalAsync(function(){n.focus=!1})}),r.bind("keydown",function(e){return e.which===n.KEY.BACKSPACE?(e.preventDefault(),e.stopPropagation(),n.select(void 0),c.$apply(),void 0):(e.which===n.KEY.TAB||n.KEY.isControl(e)||n.KEY.isFunctionKey(e)||e.which===n.KEY.ESC||((e.which==n.KEY.DOWN||e.which==n.KEY.UP||e.which==n.KEY.ENTER||e.which==n.KEY.SPACE)&&(e.preventDefault(),e.stopPropagation(),n.activate()),c.$digest()),void 0)}),r.bind("keyup input",function(e){e.which===n.KEY.TAB||n.KEY.isControl(e)||n.KEY.isFunctionKey(e)||e.which===n.KEY.ESC||e.which==n.KEY.ENTER||e.which===n.KEY.BACKSPACE||(n.activate(r.val()),r.val(""),c.$digest())})}}}]),t.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var l=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!l)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:l[2],source:t(l[3]),trackByExp:l[4],modelMapper:t(l[1]||l[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,l){var s=e+" in "+(l?"$group.items":t);return c&&(s+=" track by "+c),s}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("selectize/choices.tpl.html",'
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",'
    {{$select.placeholder}}
    '),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",'')}]),angular.module("ui.select").run(["$templateCache",function(e){e.put("select2/choices.tpl.html",'
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    ') +!function(){"use strict";angular.module("ui.select.sort",["ui.select"]).directive("uiSelectSort",["$timeout","uiSelectConfig","uiSelectMinErr",function(e,t,c){return{require:"^uiSelect",link:function(t,l,s,i){if(null===t[s.uiSelectSort])throw c("sort","Expected a list to sort");var n=angular.extend({axis:"horizontal"},t.$eval(s.uiSelectSortOptions)),a=n.axis,r="dragging",o="dropping",u="dropping-before",d="dropping-after";t.$watch(function(){return i.sortable},function(e){e?l.attr("draggable",!0):l.removeAttr("draggable")}),l.on("dragstart",function(e){l.addClass(r),(e.dataTransfer||e.originalEvent.dataTransfer).setData("text/plain",t.$index)}),l.on("dragend",function(){l.removeClass(r)});var p,h=function(e,t){this.splice(t,0,this.splice(e,1)[0])},f=function(e){e.preventDefault();var t="vertical"===a?e.offsetY||e.layerY||(e.originalEvent?e.originalEvent.offsetY:0):e.offsetX||e.layerX||(e.originalEvent?e.originalEvent.offsetX:0);t0}function i(e,t){var c=-1;if(angular.isArray(e))for(var s=angular.copy(e),i=0;i0){var c=t.split(n.taggingTokens[0]);c&&c.length>0&&(angular.forEach(c,function(e){if(null!==e&&0!==e.length){var t=n.beforeTagging(e);t&&n.select(t,!0)}}),e.preventDefault(),e.stopPropagation())}}),n.beforeTagging=function(e){return e},n.afterKeypress=function(t){if(l.search.length>0){if(t.which===n.KEY.TAB||n.KEY.isControl(t)||n.KEY.isFunctionKey(t)||t.which===n.KEY.ESC||n.KEY.isVerticalMovement(t.which))return;for(var c=0;c0)return l.search.substr(l.search.length-1)==n.KEY.MAP[t.keyCode]&&(l.search=l.search.substr(0,l.search.length-1)),n.select(n.beforeTagging(l.search)),void 0;if(l.activeIndex=l.taggingLabel===!1?-1:0,l.taggingLabel===!1)return;var a,r,o,u,d=angular.copy(l.items),p=angular.copy(l.items),h=!1,f=-1;if(o=l.$filter("filter")(d,function(e){return e.match(l.taggingLabel)}),o.length>0&&(u=o[0]),r=d[0],void 0!==r&&d.length>0&&u&&(h=!0,d=d.slice(1,d.length),p=p.slice(1,p.length)),a=l.search+" "+l.taggingLabel,i(l.selected,l.search)>-1)return;if(s(p.concat(l.selected)))return h&&(d=p,e.$evalAsync(function(){l.activeIndex=0,l.items=d})),void 0;if(s(p))return h&&(l.items=p.slice(1,p.length)),void 0;h&&(f=i(l.selected,a)),f>-1?d=d.slice(f+1,d.length-1):(d=[],d.push(a),d=d.concat(p)),e.$evalAsync(function(){l.activeIndex=0,l.items=d})}}}}}])}(),function(){"use strict";void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],c=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(c.bind(t)(e))return t;t=t.parentElement}return!1});var e=0,t=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return e++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,l,s){s(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return t=String(t),c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(c){var l=c[0].getBoundingClientRect();return{width:l.width||c.prop("offsetWidth"),height:l.height||c.prop("offsetHeight"),top:l.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:l.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);t.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,c,l){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(e,s){if(!s.repeat)throw c("repeat","Expected 'repeat' expression.");return function(e,s,i,n,a){var r=i.groupBy,o=i.groupFilter;if(n.parseRepeatAttr(i.repeat,r,o),n.disableChoiceExpression=i.uiDisableChoice,n.onHighlightCallback=i.onHighlight,r){var u=s.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=s.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(n.parserResult.itemName,"$select.items",n.parserResult.trackByExp,r)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+n.parserResult.itemName+")").attr("ng-click","$select.select("+n.parserResult.itemName+",false,$event)");var p=s.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),l(s,a)(e),e.$watch("$select.search",function(e){e&&!n.open&&n.multiple&&n.activate(!1,!0),n.activeIndex=0})}}}}]),t.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(e,t,c,l,s,i,n,a){function r(){(p.resetSearchInput||void 0===p.resetSearchInput&&a.resetSearchInput)&&(p.search=h,p.selected&&p.items.length&&!p.multiple&&(p.activeIndex=p.items.indexOf(p.selected)))}function o(e,t){var c,l,s=[];for(c=0;c0&&p.activeIndex--;break;case p.KEY.TAB:(!p.multiple||p.open)&&p.select(p.items[p.activeIndex],!0);break;case p.KEY.ENTER:p.open?void 0!==p.items[p.activeIndex]&&p.select(p.items[p.activeIndex]):p.activate(!1,!0);break;case p.KEY.ESC:p.close();break;default:t=!1}return t}function d(){var e=t.querySelectorAll(".ui-select-choices-content"),c=e.querySelectorAll(".ui-select-choices-row");if(c.length<1)throw n("choices","Expected multiple .ui-select-choices-row but got '{0}'.",c.length);if(!(p.activeIndex<0)){var l=c[p.activeIndex],s=l.offsetTop+l.clientHeight-e[0].scrollTop,i=e[0].offsetHeight;s>i?e[0].scrollTop+=s-i:s=112&&123>=e},isVerticalMovement:function(e){return~[p.KEY.UP,p.KEY.DOWN].indexOf(e)},isHorizontalMovement:function(e){return~[p.KEY.LEFT,p.KEY.RIGHT,p.KEY.BACKSPACE,p.KEY.DELETE].indexOf(e)}},p.isEmpty=function(){return angular.isUndefined(p.selected)||null===p.selected||""===p.selected},p.findGroupByName=function(e){return p.groups&&p.groups.filter(function(t){return t.name===e})[0]},p.activate=function(t,l){if(p.disabled||p.open)p.open&&!p.searchEnabled&&p.close();else{var s=function(){l||r(),e.$broadcast("uis:activate"),p.open=!0,p.searchEnabled||angular.element(p.searchInput[0]).addClass("ui-select-offscreen"),p.activeIndex=p.activeIndex>=p.items.length?0:p.activeIndex,c(function(){p.search=t||p.search,p.searchInput[0].focus()})},i=p.beforeDropdownOpen();angular.isFunction(i.then)?i.then(function(e){e===!0&&s()}):i===!0&&s()}},p.parseRepeatAttr=function(t,c,l){function s(t){var s=e.$eval(c);if(p.groups=[],angular.forEach(t,function(e){var t=angular.isFunction(s)?s(e):e[s],c=p.findGroupByName(t);c?c.items.push(e):p.groups.push({name:t,items:[e]})}),l){var i=e.$eval(l);angular.isFunction(i)?p.groups=i(p.groups):angular.isArray(i)&&(p.groups=o(p.groups,i))}p.items=[],p.groups.forEach(function(e){p.items=p.items.concat(e.items)})}function a(e){p.items=e}p.setItemsFn=c?s:a,p.parserResult=i.parse(t),p.isGrouped=!!c,p.itemProperty=p.parserResult.itemName,p.refreshItems=function(t){t=t||p.parserResult.source(e);var c=p.selected;if(p.isEmpty()||angular.isArray(c)&&!c.length||!p.removeSelected)p.setItemsFn(t);else if(void 0!==t){var l=t.filter(function(e){return c.indexOf(e)<0});p.setItemsFn(l)}},e.$watchCollection(p.parserResult.source,function(e){if(void 0===e||null===e)p.items=[];else{if(!angular.isArray(e))throw n("items","Expected an array but got '{0}'.",e);p.refreshItems(e),p.ngModel.$modelValue=null}})},p.setActiveItem=function(e){p.activeIndex=p.items.indexOf(e)},p.isActive=function(e){if(!p.open)return!1;var t=p.items.indexOf(e[p.itemProperty]),c=-1===t?!1:t===p.activeIndex;return c},p.isDisabled=function(e){if(!p.open)return!1;var t,c=p.items.indexOf(e[p.itemProperty]),l=!1;return c>=0&&!angular.isUndefined(p.disableChoiceExpression)&&(t=p.items[c],l=!!e.$eval(p.disableChoiceExpression),t._uiSelectChoiceDisabled=l),l},p.select=function(t,l,s){function i(){e.$broadcast("uis:select",t),c(function(){p.afterSelect(t)}),p.closeOnSelect&&p.close(l),s&&"click"===s.type&&(p.clickTriggeredSelect=!0)}if((void 0===t||!t._uiSelectChoiceDisabled)&&(p.items||p.search)){var n=p.beforeSelect(t);angular.isFunction(n.then)?n.then(function(e){e&&(e===!0?i(t):e&&i(e))}):n===!0?i(t):n&&i(n)}},p.close=function(t){function c(){p.ngModel&&p.ngModel.$setTouched&&p.ngModel.$setTouched(),r(),p.open=!1,p.searchEnabled||angular.element(p.searchInput[0]).removeClass("ui-select-offscreen"),e.$broadcast("uis:close",t)}if(p.open){var l=p.beforeDropdownClose();angular.isFunction(l.then)?l.then(function(e){e===!0&&c()}):l===!0&&c()}},p.setFocus=function(){p.focus||p.focusInput[0].focus()},p.clear=function(e){p.select(void 0),e.stopPropagation(),c(function(){p.focusser[0].focus()},0,!1)},p.toggle=function(e){p.open?(p.close(),e.preventDefault(),e.stopPropagation()):p.activate()},p.isLocked=function(e,t){var c,l=p.selected[t];return l&&!angular.isUndefined(p.lockChoiceExpression)&&(c=!!e.$eval(p.lockChoiceExpression),l._uiSelectChoiceLocked=c),c};var f=null;p.sizeSearchInput=function(){var t=p.searchInput[0],l=p.searchInput.parent().parent()[0],s=function(){return l.clientWidth*!!t.offsetParent},i=function(e){if(0===e)return!1;var c=e-t.offsetLeft-p.searchInput.parent()[0].offsetLeft-5;return 50>c&&(c=e),p.searchInput.css("width",c+"px"),!0};p.searchInput.css("width","10px"),c(function(){null!==f||i(s())||(f=e.$watch(s,function(e){i(e)&&(f(),f=null)}))})},p.searchInput.on("keydown",function(t){var c=t.which;~[p.KEY.ESC,p.KEY.TAB].indexOf(c)&&p.close(),e.$apply(function(){u(c)}),p.KEY.isVerticalMovement(c)&&p.items.length>0&&d(),(c===p.KEY.ENTER||c===p.KEY.ESC)&&(t.preventDefault(),t.stopPropagation())}),p.searchInput.on("keyup",function(e){e.which===p.KEY.TAB||p.KEY.isControl(e)||p.KEY.isFunctionKey(e)||e.which===p.KEY.ESC||p.KEY.isVerticalMovement(e.which)||p.afterKeypress(e)}),e.$on("$destroy",function(){p.searchInput.off("keyup keydown blur paste")}),p.afterKeypress=function(){},p.beforeSelect=function(){return!0},p.afterSelect=function(){},p.beforeRemove=function(){return!0},p.afterRemove=function(){},p.beforeDropdownOpen=function(){return!0},p.beforeDropdownClose=function(){return!0}}]),t.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,c,l,s,i,n,a){return{restrict:"EA",templateUrl:function(e,t){var l=t.theme||c.theme;return l+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(i,r){return angular.isDefined(r.multiple)?i.append("").removeAttr("multiple"):i.append(""),function(i,r,o,u,d){function p(e){if(g.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(r[0],e.target):r[0].contains(e.target),!t&&!g.clickTriggeredSelect){var c=["input","button","textarea"],l=angular.element(e.target).controller("uiSelect"),s=l&&l!==g;s||(s=~c.indexOf(e.target.tagName.toLowerCase())),g.close(s),i.$digest()}g.clickTriggeredSelect=!1}}function h(){var t=s(r);E=angular.element('
    '),E[0].style.width=t.width+"px",E[0].style.height=t.height+"px",r.after(E),w=r[0].style.width,e.find("body").append(r),r[0].style.position="absolute",r[0].style.left=t.left+"px",r[0].style.top=t.top+"px",r[0].style.width=t.width+"px"}function f(){null!==E&&(E.replaceWith(r),E=null,r[0].style.position="",r[0].style.left="",r[0].style.top="",r[0].style.width=w)}var g=u[0],v=u[1];g.generatedId=c.generateId(),g.baseTitle=o.title||"Select box",g.focusserTitle=g.baseTitle+" focus",g.focusserId="focusser-"+g.generatedId,g.closeOnSelect=function(){return angular.isDefined(o.closeOnSelect)?n(o.closeOnSelect)():c.closeOnSelect}(),g.limit=angular.isDefined(o.limit)?parseInt(o.limit,10):void 0,g.ngModel=v,g.choiceGrouped=function(e){return g.isGrouped&&e&&e.name},o.tabindex&&o.$observe("tabindex",function(e){g.focusInput.attr("tabindex",e),r.removeAttr("tabindex")});var m=i.$eval(o.searchEnabled);g.searchEnabled=void 0!==m?m:c.searchEnabled;var $=i.$eval(o.sortable);g.sortable=void 0!==$?$:c.sortable,o.$observe("disabled",function(){g.disabled=void 0!==o.disabled?o.disabled:!1}),angular.isDefined(o.autofocus)&&a(function(){g.setFocus()}),angular.isDefined(o.focusOn)&&i.$on(o.focusOn,function(){a(function(){g.setFocus()})}),e.on("click",p),i.$on("$destroy",function(){e.off("click",p)}),d(i,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),c.removeAttr("data-ui-select-match"),1!==c.length)throw l("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);r.querySelectorAll(".ui-select-match").replaceWith(c);var s=t.querySelectorAll(".ui-select-choices");if(s.removeAttr("ui-select-choices"),s.removeAttr("data-ui-select-choices"),1!==s.length)throw l("transcluded","Expected 1 .ui-select-choices but got '{0}'.",s.length);r.querySelectorAll(".ui-select-choices").replaceWith(s)});var b=i.$eval(o.appendToBody);(void 0!==b?b:c.appendToBody)&&(i.$watch("$select.open",function(e){e?h():f()}),i.$on("$destroy",function(){f()}));var E=null,w="",x=null,y="direction-up";i.$watch("$select.open",function(c){if(c){if(x=angular.element(r).querySelectorAll(".ui-select-dropdown"),null===x)return;x[0].style.opacity=0,a(function(){var c=s(r),l=s(x);c.top+c.height+l.height>t.pageYOffset+e[0].documentElement.clientHeight&&r.addClass(y),x[0].style.opacity=1})}else{if(null===x)return;r.removeClass(y)}})}}}}]),t.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,l=t.parent().attr("multiple");return c+(l?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,l,s){function i(e){s.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}s.lockChoiceExpression=l.uiLockChoice,l.$observe("placeholder",function(t){s.placeholder=void 0!==t?t:e.placeholder}),l.$observe("allowClear",i),i(l.allowClear),s.multiple&&s.sizeSearchInput()}}}]),t.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var c,l=this,s=e.$select;e.$evalAsync(function(){c=e.ngModel}),l.activeMatchIndex=-1,l.updateModel=function(){c.$setViewValue(Date.now()),l.refreshComponent()},l.refreshComponent=function(){s.refreshItems(),s.sizeSearchInput()},l.removeChoice=function(e){function c(){s.selected.splice(e,1),l.activeMatchIndex=-1,s.sizeSearchInput(),t(function(){s.afterRemove(i)}),l.updateModel()}var i=s.selected[e];if(!i._uiSelectChoiceLocked){var n=s.beforeRemove(i);angular.isFunction(n.then)?n.then(function(e){e===!0&&c()}):n===!0&&c()}},l.getPlaceholder=function(){return s.selected&&s.selected.length?void 0:s.placeholder}}],controllerAs:"$selectMultiple",link:function(c,l,s,i){function n(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(e){function t(){switch(e){case r.KEY.LEFT:return~u.activeMatchIndex?d:i;case r.KEY.RIGHT:return~u.activeMatchIndex&&a!==i?o:(r.activate(),!1);case r.KEY.BACKSPACE:return~u.activeMatchIndex?(u.removeChoice(a),d):i;case r.KEY.DELETE:return~u.activeMatchIndex?(u.removeChoice(u.activeMatchIndex),a):!1}}var c=n(r.searchInput[0]),l=r.selected.length,s=0,i=l-1,a=u.activeMatchIndex,o=u.activeMatchIndex+1,d=u.activeMatchIndex-1,p=a;return c>0||r.search.length&&e==r.KEY.RIGHT?!1:(r.close(),p=t(),u.activeMatchIndex=r.selected.length&&p!==!1?Math.min(i,Math.max(s,p)):-1,!0)}var r=i[0],o=c.ngModel=i[1],u=c.$selectMultiple;r.multiple=!0,r.removeSelected=!0,r.focusInput=r.searchInput,o.$parsers.unshift(function(){for(var e,t={},l=[],s=r.selected.length-1;s>=0;s--)t={},t[r.parserResult.itemName]=r.selected[s],e=r.parserResult.modelMapper(c,t),l.unshift(e);return l}),o.$formatters.unshift(function(e){var t,l=r.parserResult.source(c,{$select:{search:""}}),s={};if(!l)return e;var i=[],n=function(e,l){if(e&&e.length){for(var n=e.length-1;n>=0;n--){if(s[r.parserResult.itemName]=e[n],t=r.parserResult.modelMapper(c,s),r.parserResult.trackByExp){var a=/\.(.+)/.exec(r.parserResult.trackByExp);if(a.length>0&&t[a[1]]==l[a[1]])return i.unshift(e[n]),!0}if(angular.equals(t,l))return i.unshift(e[n]),!0}return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(r.selected,e[a])||n(l,e[a])||i.unshift(e[a]);return i}),c.$watchCollection(function(){return o.$modelValue},function(e,t){t!=e&&(o.$modelValue=null,u.refreshComponent())}),o.$render=function(){if(!angular.isArray(o.$viewValue)){if(!angular.isUndefined(o.$viewValue)&&null!==o.$viewValue)throw e("multiarr","Expected model value to be array but got '{0}'",o.$viewValue);r.selected=[]}r.selected=o.$viewValue,c.$evalAsync()},c.$on("uis:select",function(e,t){r.selected.length>=r.limit||(r.selected.push(t),u.updateModel())}),c.$on("uis:activate",function(){u.activeMatchIndex=-1}),c.$watch("$select.disabled",function(e,t){t&&!e&&r.sizeSearchInput()}),r.searchInput.on("keydown",function(e){var t=e.which;c.$apply(function(){var e=!1;r.KEY.isHorizontalMovement(t)&&(e=a(t)),e&&t!=r.KEY.TAB})}),r.searchInput.on("blur",function(){t(function(){u.activeMatchIndex=-1})})}}}]),t.directive("uiSelectSingle",["$timeout","$compile",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(c,l,s,i){var n=i[0],a=i[1];a.$parsers.unshift(function(e){var t,l={};return l[n.parserResult.itemName]=e,t=n.parserResult.modelMapper(c,l)}),a.$formatters.unshift(function(e){var t,l=n.parserResult.source(c,{$select:{search:""}}),s={};if(l){var i=function(l){return s[n.parserResult.itemName]=l,t=n.parserResult.modelMapper(c,s),t==e};if(n.selected&&i(n.selected))return n.selected;for(var a=l.length-1;a>=0;a--)if(i(l[a]))return l[a]}return e}),c.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){n.selected=a.$viewValue},c.$on("uis:select",function(e,t){n.selected=t}),c.$on("uis:close",function(t,c){e(function(){n.focusser.prop("disabled",!1),c||n.focusser[0].focus()},0,!1)}),c.$on("uis:activate",function(){r.prop("disabled",!0)});var r=angular.element("");t(r)(c),n.focusser=r,n.focusInput=r,l.parent().append(r),r.bind("focus",function(){c.$evalAsync(function(){n.focus=!0})}),r.bind("blur",function(){c.$evalAsync(function(){n.focus=!1})}),r.bind("keydown",function(e){return e.which===n.KEY.BACKSPACE?(e.preventDefault(),e.stopPropagation(),n.select(void 0),c.$apply(),void 0):(e.which===n.KEY.TAB||n.KEY.isControl(e)||n.KEY.isFunctionKey(e)||e.which===n.KEY.ESC||((e.which==n.KEY.DOWN||e.which==n.KEY.UP||e.which==n.KEY.ENTER||e.which==n.KEY.SPACE)&&(e.preventDefault(),e.stopPropagation(),n.activate()),c.$digest()),void 0)}),r.bind("keyup input",function(e){e.which===n.KEY.TAB||n.KEY.isControl(e)||n.KEY.isFunctionKey(e)||e.which===n.KEY.ESC||e.which==n.KEY.ENTER||e.which===n.KEY.BACKSPACE||(n.activate(r.val()),r.val(""),c.$digest())})}}}]),t.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var l=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!l)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:l[2],source:t(l[3]),trackByExp:l[4],modelMapper:t(l[1]||l[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,l){var s=e+" in "+(l?"$group.items":t);return c&&(s+=" track by "+c),s}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("selectize/choices.tpl.html",'
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",'
    {{$select.placeholder}}
    '),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",'')}]),angular.module("ui.select").run(["$templateCache",function(e){e.put("select2/choices.tpl.html",'
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    ') }]); \ No newline at end of file diff --git a/dist/select.no-tpl.js b/dist/select.no-tpl.js index 5aadbe8ed..713a3c84b 100644 --- a/dist/select.no-tpl.js +++ b/dist/select.no-tpl.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-09T18:09:19.159Z + * Version: 0.12.1 - 2015-08-11T18:41:59.459Z * License: MIT */ @@ -570,7 +570,7 @@ uis.controller('uiSelectCtrl', var isActive = itemIndex === -1 ? false : itemIndex === ctrl.activeIndex; // If this is active, and we've defined a callback, do it! - // TODO: Needed? + // TODO: Is this needed? If it is, then implement properly. // if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { // itemScope.$eval(ctrl.onHighlightCallback); // } @@ -594,8 +594,10 @@ uis.controller('uiSelectCtrl', if (itemIndex >= 0 && !angular.isUndefined(ctrl.disableChoiceExpression)) { item = ctrl.items[itemIndex]; - isDisabled = !!(itemScope.$eval(ctrl.disableChoiceExpression)); // force the boolean value - item._uiSelectChoiceDisabled = isDisabled; // store this for later reference + // Force the boolean value + isDisabled = !!(itemScope.$eval(ctrl.disableChoiceExpression)); + // Store this for later reference + item._uiSelectChoiceDisabled = isDisabled; } return isDisabled; @@ -841,10 +843,6 @@ uis.controller('uiSelectCtrl', e.preventDefault(); e.stopPropagation(); } - - // Let the users process the data - // TODO: Is this needed, or just let the user bind to the event themselves! -// ctrl.afterKeypress(e); }); ctrl.searchInput.on('keyup', function (e) { diff --git a/dist/select.no-tpl.min.js b/dist/select.no-tpl.min.js index 84a0d2d92..290734e4c 100644 --- a/dist/select.no-tpl.min.js +++ b/dist/select.no-tpl.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-09T18:09:19.159Z + * Version: 0.12.1 - 2015-08-11T18:41:59.459Z * License: MIT */ !function(){"use strict";void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var e=0,t=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return e++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,r,i){i(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return t=String(t),n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var r=n[0].getBoundingClientRect();return{width:r.width||n.prop("offsetWidth"),height:r.height||n.prop("offsetHeight"),top:r.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:r.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);t.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,r){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,i){if(!i.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,i,c,o,l){var s=c.groupBy,a=c.groupFilter;if(o.parseRepeatAttr(c.repeat,s,a),o.disableChoiceExpression=c.uiDisableChoice,o.onHighlightCallback=c.onHighlight,s){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=i.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(o.parserResult.itemName,"$select.items",o.parserResult.trackByExp,s)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+o.parserResult.itemName+")").attr("ng-click","$select.select("+o.parserResult.itemName+",false,$event)");var f=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==f.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",f.length);f.attr("uis-transclude-append",""),r(i,l)(e),e.$watch("$select.search",function(e){e&&!o.open&&o.multiple&&o.activate(!1,!0),o.activeIndex=0})}}}}]),t.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(e,t,n,r,i,c,o,l){function s(){(f.resetSearchInput||void 0===f.resetSearchInput&&l.resetSearchInput)&&(f.search=d,f.selected&&f.items.length&&!f.multiple&&(f.activeIndex=f.items.indexOf(f.selected)))}function a(e,t){var n,r,i=[];for(n=0;n0&&f.activeIndex--;break;case f.KEY.TAB:(!f.multiple||f.open)&&f.select(f.items[f.activeIndex],!0);break;case f.KEY.ENTER:f.open?void 0!==f.items[f.activeIndex]&&f.select(f.items[f.activeIndex]):f.activate(!1,!0);break;case f.KEY.ESC:f.close();break;default:t=!1}return t}function p(){var e=t.querySelectorAll(".ui-select-choices-content"),n=e.querySelectorAll(".ui-select-choices-row");if(n.length<1)throw o("choices","Expected multiple .ui-select-choices-row but got '{0}'.",n.length);if(!(f.activeIndex<0)){var r=n[f.activeIndex],i=r.offsetTop+r.clientHeight-e[0].scrollTop,c=e[0].offsetHeight;i>c?e[0].scrollTop+=i-c:i=112&&123>=e},isVerticalMovement:function(e){return~[f.KEY.UP,f.KEY.DOWN].indexOf(e)},isHorizontalMovement:function(e){return~[f.KEY.LEFT,f.KEY.RIGHT,f.KEY.BACKSPACE,f.KEY.DELETE].indexOf(e)}},f.isEmpty=function(){return angular.isUndefined(f.selected)||null===f.selected||""===f.selected},f.findGroupByName=function(e){return f.groups&&f.groups.filter(function(t){return t.name===e})[0]},f.activate=function(t,r){if(f.disabled||f.open)f.open&&!f.searchEnabled&&f.close();else{var i=function(){r||s(),e.$broadcast("uis:activate"),f.open=!0,f.searchEnabled||angular.element(f.searchInput[0]).addClass("ui-select-offscreen"),f.activeIndex=f.activeIndex>=f.items.length?0:f.activeIndex,n(function(){f.search=t||f.search,f.searchInput[0].focus()})},c=f.beforeDropdownOpen();angular.isFunction(c.then)?c.then(function(e){e===!0&&i()}):c===!0&&i()}},f.parseRepeatAttr=function(t,n,r){function i(t){var i=e.$eval(n);if(f.groups=[],angular.forEach(t,function(e){var t=angular.isFunction(i)?i(e):e[i],n=f.findGroupByName(t);n?n.items.push(e):f.groups.push({name:t,items:[e]})}),r){var c=e.$eval(r);angular.isFunction(c)?f.groups=c(f.groups):angular.isArray(c)&&(f.groups=a(f.groups,c))}f.items=[],f.groups.forEach(function(e){f.items=f.items.concat(e.items)})}function l(e){f.items=e}f.setItemsFn=n?i:l,f.parserResult=c.parse(t),f.isGrouped=!!n,f.itemProperty=f.parserResult.itemName,f.refreshItems=function(t){t=t||f.parserResult.source(e);var n=f.selected;if(f.isEmpty()||angular.isArray(n)&&!n.length||!f.removeSelected)f.setItemsFn(t);else if(void 0!==t){var r=t.filter(function(e){return n.indexOf(e)<0});f.setItemsFn(r)}},e.$watchCollection(f.parserResult.source,function(e){if(void 0===e||null===e)f.items=[];else{if(!angular.isArray(e))throw o("items","Expected an array but got '{0}'.",e);f.refreshItems(e),f.ngModel.$modelValue=null}})},f.setActiveItem=function(e){f.activeIndex=f.items.indexOf(e)},f.isActive=function(e){if(!f.open)return!1;var t=f.items.indexOf(e[f.itemProperty]),n=-1===t?!1:t===f.activeIndex;return n},f.isDisabled=function(e){if(!f.open)return!1;var t,n=f.items.indexOf(e[f.itemProperty]),r=!1;return n>=0&&!angular.isUndefined(f.disableChoiceExpression)&&(t=f.items[n],r=!!e.$eval(f.disableChoiceExpression),t._uiSelectChoiceDisabled=r),r},f.select=function(t,r,i){function c(){e.$broadcast("uis:select",t),n(function(){f.afterSelect(t)}),f.closeOnSelect&&f.close(r),i&&"click"===i.type&&(f.clickTriggeredSelect=!0)}if((void 0===t||!t._uiSelectChoiceDisabled)&&(f.items||f.search)){var o=f.beforeSelect(t);angular.isFunction(o.then)?o.then(function(e){e&&(e===!0?c(t):e&&c(e))}):o===!0?c(t):o&&c(o)}},f.close=function(t){function n(){f.ngModel&&f.ngModel.$setTouched&&f.ngModel.$setTouched(),s(),f.open=!1,f.searchEnabled||angular.element(f.searchInput[0]).removeClass("ui-select-offscreen"),e.$broadcast("uis:close",t)}if(f.open){var r=f.beforeDropdownClose();angular.isFunction(r.then)?r.then(function(e){e===!0&&n()}):r===!0&&n()}},f.setFocus=function(){f.focus||f.focusInput[0].focus()},f.clear=function(e){f.select(void 0),e.stopPropagation(),n(function(){f.focusser[0].focus()},0,!1)},f.toggle=function(e){f.open?(f.close(),e.preventDefault(),e.stopPropagation()):f.activate()},f.isLocked=function(e,t){var n,r=f.selected[t];return r&&!angular.isUndefined(f.lockChoiceExpression)&&(n=!!e.$eval(f.lockChoiceExpression),r._uiSelectChoiceLocked=n),n};var h=null;f.sizeSearchInput=function(){var t=f.searchInput[0],r=f.searchInput.parent().parent()[0],i=function(){return r.clientWidth*!!t.offsetParent},c=function(e){if(0===e)return!1;var n=e-t.offsetLeft-f.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=e),f.searchInput.css("width",n+"px"),!0};f.searchInput.css("width","10px"),n(function(){null!==h||c(i())||(h=e.$watch(i,function(e){c(e)&&(h(),h=null)}))})},f.searchInput.on("keydown",function(t){var n=t.which;~[f.KEY.ESC,f.KEY.TAB].indexOf(n)&&f.close(),e.$apply(function(){u(n)}),f.KEY.isVerticalMovement(n)&&f.items.length>0&&p(),(n===f.KEY.ENTER||n===f.KEY.ESC)&&(t.preventDefault(),t.stopPropagation())}),f.searchInput.on("keyup",function(e){e.which===f.KEY.TAB||f.KEY.isControl(e)||f.KEY.isFunctionKey(e)||e.which===f.KEY.ESC||f.KEY.isVerticalMovement(e.which)||f.afterKeypress(e)}),e.$on("$destroy",function(){f.searchInput.off("keyup keydown blur paste")}),f.afterKeypress=function(){},f.beforeSelect=function(){return!0},f.afterSelect=function(){},f.beforeRemove=function(){return!0},f.afterRemove=function(){},f.beforeDropdownOpen=function(){return!0},f.beforeDropdownClose=function(){return!0}}]),t.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,r,i,c,o,l){return{restrict:"EA",templateUrl:function(e,t){var r=t.theme||n.theme;return r+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(c,s){return angular.isDefined(s.multiple)?c.append("").removeAttr("multiple"):c.append(""),function(c,s,a,u,p){function f(e){if(v.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(s[0],e.target):s[0].contains(e.target),!t&&!v.clickTriggeredSelect){var n=["input","button","textarea"],r=angular.element(e.target).controller("uiSelect"),i=r&&r!==v;i||(i=~n.indexOf(e.target.tagName.toLowerCase())),v.close(i),c.$digest()}v.clickTriggeredSelect=!1}}function d(){var t=i(s);S=angular.element('
    '),S[0].style.width=t.width+"px",S[0].style.height=t.height+"px",s.after(S),w=s[0].style.width,e.find("body").append(s),s[0].style.position="absolute",s[0].style.left=t.left+"px",s[0].style.top=t.top+"px",s[0].style.width=t.width+"px"}function h(){null!==S&&(S.replaceWith(s),S=null,s[0].style.position="",s[0].style.left="",s[0].style.top="",s[0].style.width=w)}var v=u[0],g=u[1];v.generatedId=n.generateId(),v.baseTitle=a.title||"Select box",v.focusserTitle=v.baseTitle+" focus",v.focusserId="focusser-"+v.generatedId,v.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?o(a.closeOnSelect)():n.closeOnSelect}(),v.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,v.ngModel=g,v.choiceGrouped=function(e){return v.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){v.focusInput.attr("tabindex",e),s.removeAttr("tabindex")});var m=c.$eval(a.searchEnabled);v.searchEnabled=void 0!==m?m:n.searchEnabled;var E=c.$eval(a.sortable);v.sortable=void 0!==E?E:n.sortable,a.$observe("disabled",function(){v.disabled=void 0!==a.disabled?a.disabled:!1}),angular.isDefined(a.autofocus)&&l(function(){v.setFocus()}),angular.isDefined(a.focusOn)&&c.$on(a.focusOn,function(){l(function(){v.setFocus()})}),e.on("click",f),c.$on("$destroy",function(){e.off("click",f)}),p(c,function(e){var t=angular.element("
    ").append(e),n=t.querySelectorAll(".ui-select-match");if(n.removeAttr("ui-select-match"),n.removeAttr("data-ui-select-match"),1!==n.length)throw r("transcluded","Expected 1 .ui-select-match but got '{0}'.",n.length);s.querySelectorAll(".ui-select-match").replaceWith(n);var i=t.querySelectorAll(".ui-select-choices");if(i.removeAttr("ui-select-choices"),i.removeAttr("data-ui-select-choices"),1!==i.length)throw r("transcluded","Expected 1 .ui-select-choices but got '{0}'.",i.length);s.querySelectorAll(".ui-select-choices").replaceWith(i)});var $=c.$eval(a.appendToBody);(void 0!==$?$:n.appendToBody)&&(c.$watch("$select.open",function(e){e?d():h()}),c.$on("$destroy",function(){h()}));var S=null,w="",b=null,I="direction-up";c.$watch("$select.open",function(n){if(n){if(b=angular.element(s).querySelectorAll(".ui-select-dropdown"),null===b)return;b[0].style.opacity=0,l(function(){var n=i(s),r=i(b);n.top+n.height+r.height>t.pageYOffset+e[0].documentElement.clientHeight&&s.addClass(I),b[0].style.opacity=1})}else{if(null===b)return;s.removeClass(I)}})}}}}]),t.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,r=t.parent().attr("multiple");return n+(r?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,r,i){function c(e){i.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}i.lockChoiceExpression=r.uiLockChoice,r.$observe("placeholder",function(t){i.placeholder=void 0!==t?t:e.placeholder}),r.$observe("allowClear",c),c(r.allowClear),i.multiple&&i.sizeSearchInput()}}}]),t.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,r=this,i=e.$select;e.$evalAsync(function(){n=e.ngModel}),r.activeMatchIndex=-1,r.updateModel=function(){n.$setViewValue(Date.now()),r.refreshComponent()},r.refreshComponent=function(){i.refreshItems(),i.sizeSearchInput()},r.removeChoice=function(e){function n(){i.selected.splice(e,1),r.activeMatchIndex=-1,i.sizeSearchInput(),t(function(){i.afterRemove(c)}),r.updateModel()}var c=i.selected[e];if(!c._uiSelectChoiceLocked){var o=i.beforeRemove(c);angular.isFunction(o.then)?o.then(function(e){e===!0&&n()}):o===!0&&n()}},r.getPlaceholder=function(){return i.selected&&i.selected.length?void 0:i.placeholder}}],controllerAs:"$selectMultiple",link:function(n,r,i,c){function o(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function l(e){function t(){switch(e){case s.KEY.LEFT:return~u.activeMatchIndex?p:c;case s.KEY.RIGHT:return~u.activeMatchIndex&&l!==c?a:(s.activate(),!1);case s.KEY.BACKSPACE:return~u.activeMatchIndex?(u.removeChoice(l),p):c;case s.KEY.DELETE:return~u.activeMatchIndex?(u.removeChoice(u.activeMatchIndex),l):!1}}var n=o(s.searchInput[0]),r=s.selected.length,i=0,c=r-1,l=u.activeMatchIndex,a=u.activeMatchIndex+1,p=u.activeMatchIndex-1,f=l;return n>0||s.search.length&&e==s.KEY.RIGHT?!1:(s.close(),f=t(),u.activeMatchIndex=s.selected.length&&f!==!1?Math.min(c,Math.max(i,f)):-1,!0)}var s=c[0],a=n.ngModel=c[1],u=n.$selectMultiple;s.multiple=!0,s.removeSelected=!0,s.focusInput=s.searchInput,a.$parsers.unshift(function(){for(var e,t={},r=[],i=s.selected.length-1;i>=0;i--)t={},t[s.parserResult.itemName]=s.selected[i],e=s.parserResult.modelMapper(n,t),r.unshift(e);return r}),a.$formatters.unshift(function(e){var t,r=s.parserResult.source(n,{$select:{search:""}}),i={};if(!r)return e;var c=[],o=function(e,r){if(e&&e.length){for(var o=e.length-1;o>=0;o--){if(i[s.parserResult.itemName]=e[o],t=s.parserResult.modelMapper(n,i),s.parserResult.trackByExp){var l=/\.(.+)/.exec(s.parserResult.trackByExp);if(l.length>0&&t[l[1]]==r[l[1]])return c.unshift(e[o]),!0}if(angular.equals(t,r))return c.unshift(e[o]),!0}return!1}};if(!e)return c;for(var l=e.length-1;l>=0;l--)o(s.selected,e[l])||o(r,e[l])||c.unshift(e[l]);return c}),n.$watchCollection(function(){return a.$modelValue},function(e,t){t!=e&&(a.$modelValue=null,u.refreshComponent())}),a.$render=function(){if(!angular.isArray(a.$viewValue)){if(!angular.isUndefined(a.$viewValue)&&null!==a.$viewValue)throw e("multiarr","Expected model value to be array but got '{0}'",a.$viewValue);s.selected=[]}s.selected=a.$viewValue,n.$evalAsync()},n.$on("uis:select",function(e,t){s.selected.length>=s.limit||(s.selected.push(t),u.updateModel())}),n.$on("uis:activate",function(){u.activeMatchIndex=-1}),n.$watch("$select.disabled",function(e,t){t&&!e&&s.sizeSearchInput()}),s.searchInput.on("keydown",function(e){var t=e.which;n.$apply(function(){var e=!1;s.KEY.isHorizontalMovement(t)&&(e=l(t)),e&&t!=s.KEY.TAB})}),s.searchInput.on("blur",function(){t(function(){u.activeMatchIndex=-1})})}}}]),t.directive("uiSelectSingle",["$timeout","$compile",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(n,r,i,c){var o=c[0],l=c[1];l.$parsers.unshift(function(e){var t,r={};return r[o.parserResult.itemName]=e,t=o.parserResult.modelMapper(n,r)}),l.$formatters.unshift(function(e){var t,r=o.parserResult.source(n,{$select:{search:""}}),i={};if(r){var c=function(r){return i[o.parserResult.itemName]=r,t=o.parserResult.modelMapper(n,i),t==e};if(o.selected&&c(o.selected))return o.selected;for(var l=r.length-1;l>=0;l--)if(c(r[l]))return r[l]}return e}),n.$watch("$select.selected",function(e){l.$viewValue!==e&&l.$setViewValue(e)}),l.$render=function(){o.selected=l.$viewValue},n.$on("uis:select",function(e,t){o.selected=t}),n.$on("uis:close",function(t,n){e(function(){o.focusser.prop("disabled",!1),n||o.focusser[0].focus()},0,!1)}),n.$on("uis:activate",function(){s.prop("disabled",!0)});var s=angular.element("");t(s)(n),o.focusser=s,o.focusInput=s,r.parent().append(s),s.bind("focus",function(){n.$evalAsync(function(){o.focus=!0})}),s.bind("blur",function(){n.$evalAsync(function(){o.focus=!1})}),s.bind("keydown",function(e){return e.which===o.KEY.BACKSPACE?(e.preventDefault(),e.stopPropagation(),o.select(void 0),n.$apply(),void 0):(e.which===o.KEY.TAB||o.KEY.isControl(e)||o.KEY.isFunctionKey(e)||e.which===o.KEY.ESC||((e.which==o.KEY.DOWN||e.which==o.KEY.UP||e.which==o.KEY.ENTER||e.which==o.KEY.SPACE)&&(e.preventDefault(),e.stopPropagation(),o.activate()),n.$digest()),void 0)}),s.bind("keyup input",function(e){e.which===o.KEY.TAB||o.KEY.isControl(e)||o.KEY.isFunctionKey(e)||e.which===o.KEY.ESC||e.which==o.KEY.ENTER||e.which===o.KEY.BACKSPACE||(o.activate(s.val()),s.val(""),n.$digest())})}}}]),t.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var r=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!r)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:r[2],source:t(r[3]),trackByExp:r[4],modelMapper:t(r[1]||r[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,r){var i=e+" in "+(r?"$group.items":t);return n&&(i+=" track by "+n),i}}])}(); \ No newline at end of file diff --git a/dist/select.select2.js b/dist/select.select2.js index 1ec45937d..d432cdf72 100644 --- a/dist/select.select2.js +++ b/dist/select.select2.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-09T18:09:19.177Z + * Version: 0.12.1 - 2015-08-11T18:41:59.476Z * License: MIT */ @@ -570,7 +570,7 @@ uis.controller('uiSelectCtrl', var isActive = itemIndex === -1 ? false : itemIndex === ctrl.activeIndex; // If this is active, and we've defined a callback, do it! - // TODO: Needed? + // TODO: Is this needed? If it is, then implement properly. // if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { // itemScope.$eval(ctrl.onHighlightCallback); // } @@ -594,8 +594,10 @@ uis.controller('uiSelectCtrl', if (itemIndex >= 0 && !angular.isUndefined(ctrl.disableChoiceExpression)) { item = ctrl.items[itemIndex]; - isDisabled = !!(itemScope.$eval(ctrl.disableChoiceExpression)); // force the boolean value - item._uiSelectChoiceDisabled = isDisabled; // store this for later reference + // Force the boolean value + isDisabled = !!(itemScope.$eval(ctrl.disableChoiceExpression)); + // Store this for later reference + item._uiSelectChoiceDisabled = isDisabled; } return isDisabled; @@ -841,10 +843,6 @@ uis.controller('uiSelectCtrl', e.preventDefault(); e.stopPropagation(); } - - // Let the users process the data - // TODO: Is this needed, or just let the user bind to the event themselves! -// ctrl.afterKeypress(e); }); ctrl.searchInput.on('keyup', function (e) { diff --git a/dist/select.select2.min.js b/dist/select.select2.min.js index abc351134..ebf8f433f 100644 --- a/dist/select.select2.min.js +++ b/dist/select.select2.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-09T18:09:19.177Z + * Version: 0.12.1 - 2015-08-11T18:41:59.476Z * License: MIT */ !function(){"use strict";void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],c=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(c.bind(t)(e))return t;t=t.parentElement}return!1});var e=0,t=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return e++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,n,i){i(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return t=String(t),c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(c){var n=c[0].getBoundingClientRect();return{width:n.width||c.prop("offsetWidth"),height:n.height||c.prop("offsetHeight"),top:n.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:n.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);t.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,c,n){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(e,i){if(!i.repeat)throw c("repeat","Expected 'repeat' expression.");return function(e,i,l,s,r){var o=l.groupBy,a=l.groupFilter;if(s.parseRepeatAttr(l.repeat,o,a),s.disableChoiceExpression=l.uiDisableChoice,s.onHighlightCallback=l.onHighlight,o){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=i.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(s.parserResult.itemName,"$select.items",s.parserResult.trackByExp,o)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+s.parserResult.itemName+")").attr("ng-click","$select.select("+s.parserResult.itemName+",false,$event)");var d=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),n(i,r)(e),e.$watch("$select.search",function(e){e&&!s.open&&s.multiple&&s.activate(!1,!0),s.activeIndex=0})}}}}]),t.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(e,t,c,n,i,l,s,r){function o(){(d.resetSearchInput||void 0===d.resetSearchInput&&r.resetSearchInput)&&(d.search=h,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function a(e,t){var c,n,i=[];for(c=0;c0&&d.activeIndex--;break;case d.KEY.TAB:(!d.multiple||d.open)&&d.select(d.items[d.activeIndex],!0);break;case d.KEY.ENTER:d.open?void 0!==d.items[d.activeIndex]&&d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case d.KEY.ESC:d.close();break;default:t=!1}return t}function p(){var e=t.querySelectorAll(".ui-select-choices-content"),c=e.querySelectorAll(".ui-select-choices-row");if(c.length<1)throw s("choices","Expected multiple .ui-select-choices-row but got '{0}'.",c.length);if(!(d.activeIndex<0)){var n=c[d.activeIndex],i=n.offsetTop+n.clientHeight-e[0].scrollTop,l=e[0].offsetHeight;i>l?e[0].scrollTop+=i-l:i=112&&123>=e},isVerticalMovement:function(e){return~[d.KEY.UP,d.KEY.DOWN].indexOf(e)},isHorizontalMovement:function(e){return~[d.KEY.LEFT,d.KEY.RIGHT,d.KEY.BACKSPACE,d.KEY.DELETE].indexOf(e)}},d.isEmpty=function(){return angular.isUndefined(d.selected)||null===d.selected||""===d.selected},d.findGroupByName=function(e){return d.groups&&d.groups.filter(function(t){return t.name===e})[0]},d.activate=function(t,n){if(d.disabled||d.open)d.open&&!d.searchEnabled&&d.close();else{var i=function(){n||o(),e.$broadcast("uis:activate"),d.open=!0,d.searchEnabled||angular.element(d.searchInput[0]).addClass("ui-select-offscreen"),d.activeIndex=d.activeIndex>=d.items.length?0:d.activeIndex,c(function(){d.search=t||d.search,d.searchInput[0].focus()})},l=d.beforeDropdownOpen();angular.isFunction(l.then)?l.then(function(e){e===!0&&i()}):l===!0&&i()}},d.parseRepeatAttr=function(t,c,n){function i(t){var i=e.$eval(c);if(d.groups=[],angular.forEach(t,function(e){var t=angular.isFunction(i)?i(e):e[i],c=d.findGroupByName(t);c?c.items.push(e):d.groups.push({name:t,items:[e]})}),n){var l=e.$eval(n);angular.isFunction(l)?d.groups=l(d.groups):angular.isArray(l)&&(d.groups=a(d.groups,l))}d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function r(e){d.items=e}d.setItemsFn=c?i:r,d.parserResult=l.parse(t),d.isGrouped=!!c,d.itemProperty=d.parserResult.itemName,d.refreshItems=function(t){t=t||d.parserResult.source(e);var c=d.selected;if(d.isEmpty()||angular.isArray(c)&&!c.length||!d.removeSelected)d.setItemsFn(t);else if(void 0!==t){var n=t.filter(function(e){return c.indexOf(e)<0});d.setItemsFn(n)}},e.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw s("items","Expected an array but got '{0}'.",e);d.refreshItems(e),d.ngModel.$modelValue=null}})},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){if(!d.open)return!1;var t=d.items.indexOf(e[d.itemProperty]),c=-1===t?!1:t===d.activeIndex;return c},d.isDisabled=function(e){if(!d.open)return!1;var t,c=d.items.indexOf(e[d.itemProperty]),n=!1;return c>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[c],n=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=n),n},d.select=function(t,n,i){function l(){e.$broadcast("uis:select",t),c(function(){d.afterSelect(t)}),d.closeOnSelect&&d.close(n),i&&"click"===i.type&&(d.clickTriggeredSelect=!0)}if((void 0===t||!t._uiSelectChoiceDisabled)&&(d.items||d.search)){var s=d.beforeSelect(t);angular.isFunction(s.then)?s.then(function(e){e&&(e===!0?l(t):e&&l(e))}):s===!0?l(t):s&&l(s)}},d.close=function(t){function c(){d.ngModel&&d.ngModel.$setTouched&&d.ngModel.$setTouched(),o(),d.open=!1,d.searchEnabled||angular.element(d.searchInput[0]).removeClass("ui-select-offscreen"),e.$broadcast("uis:close",t)}if(d.open){var n=d.beforeDropdownClose();angular.isFunction(n.then)?n.then(function(e){e===!0&&c()}):n===!0&&c()}},d.setFocus=function(){d.focus||d.focusInput[0].focus()},d.clear=function(e){d.select(void 0),e.stopPropagation(),c(function(){d.focusser[0].focus()},0,!1)},d.toggle=function(e){d.open?(d.close(),e.preventDefault(),e.stopPropagation()):d.activate()},d.isLocked=function(e,t){var c,n=d.selected[t];return n&&!angular.isUndefined(d.lockChoiceExpression)&&(c=!!e.$eval(d.lockChoiceExpression),n._uiSelectChoiceLocked=c),c};var f=null;d.sizeSearchInput=function(){var t=d.searchInput[0],n=d.searchInput.parent().parent()[0],i=function(){return n.clientWidth*!!t.offsetParent},l=function(e){if(0===e)return!1;var c=e-t.offsetLeft-d.searchInput.parent()[0].offsetLeft-5;return 50>c&&(c=e),d.searchInput.css("width",c+"px"),!0};d.searchInput.css("width","10px"),c(function(){null!==f||l(i())||(f=e.$watch(i,function(e){l(e)&&(f(),f=null)}))})},d.searchInput.on("keydown",function(t){var c=t.which;~[d.KEY.ESC,d.KEY.TAB].indexOf(c)&&d.close(),e.$apply(function(){u(c)}),d.KEY.isVerticalMovement(c)&&d.items.length>0&&p(),(c===d.KEY.ENTER||c===d.KEY.ESC)&&(t.preventDefault(),t.stopPropagation())}),d.searchInput.on("keyup",function(e){e.which===d.KEY.TAB||d.KEY.isControl(e)||d.KEY.isFunctionKey(e)||e.which===d.KEY.ESC||d.KEY.isVerticalMovement(e.which)||d.afterKeypress(e)}),e.$on("$destroy",function(){d.searchInput.off("keyup keydown blur paste")}),d.afterKeypress=function(){},d.beforeSelect=function(){return!0},d.afterSelect=function(){},d.beforeRemove=function(){return!0},d.afterRemove=function(){},d.beforeDropdownOpen=function(){return!0},d.beforeDropdownClose=function(){return!0}}]),t.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,c,n,i,l,s,r){return{restrict:"EA",templateUrl:function(e,t){var n=t.theme||c.theme;return n+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(l,o){return angular.isDefined(o.multiple)?l.append("").removeAttr("multiple"):l.append(""),function(l,o,a,u,p){function d(e){if(g.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(o[0],e.target):o[0].contains(e.target),!t&&!g.clickTriggeredSelect){var c=["input","button","textarea"],n=angular.element(e.target).controller("uiSelect"),i=n&&n!==g;i||(i=~c.indexOf(e.target.tagName.toLowerCase())),g.close(i),l.$digest()}g.clickTriggeredSelect=!1}}function h(){var t=i(o);b=angular.element('
    '),b[0].style.width=t.width+"px",b[0].style.height=t.height+"px",o.after(b),w=o[0].style.width,e.find("body").append(o),o[0].style.position="absolute",o[0].style.left=t.left+"px",o[0].style.top=t.top+"px",o[0].style.width=t.width+"px"}function f(){null!==b&&(b.replaceWith(o),b=null,o[0].style.position="",o[0].style.left="",o[0].style.top="",o[0].style.width=w)}var g=u[0],v=u[1];g.generatedId=c.generateId(),g.baseTitle=a.title||"Select box",g.focusserTitle=g.baseTitle+" focus",g.focusserId="focusser-"+g.generatedId,g.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?s(a.closeOnSelect)():c.closeOnSelect}(),g.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,g.ngModel=v,g.choiceGrouped=function(e){return g.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){g.focusInput.attr("tabindex",e),o.removeAttr("tabindex")});var m=l.$eval(a.searchEnabled);g.searchEnabled=void 0!==m?m:c.searchEnabled;var E=l.$eval(a.sortable);g.sortable=void 0!==E?E:c.sortable,a.$observe("disabled",function(){g.disabled=void 0!==a.disabled?a.disabled:!1}),angular.isDefined(a.autofocus)&&r(function(){g.setFocus()}),angular.isDefined(a.focusOn)&&l.$on(a.focusOn,function(){r(function(){g.setFocus()})}),e.on("click",d),l.$on("$destroy",function(){e.off("click",d)}),p(l,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),c.removeAttr("data-ui-select-match"),1!==c.length)throw n("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);o.querySelectorAll(".ui-select-match").replaceWith(c);var i=t.querySelectorAll(".ui-select-choices");if(i.removeAttr("ui-select-choices"),i.removeAttr("data-ui-select-choices"),1!==i.length)throw n("transcluded","Expected 1 .ui-select-choices but got '{0}'.",i.length);o.querySelectorAll(".ui-select-choices").replaceWith(i)});var $=l.$eval(a.appendToBody);(void 0!==$?$:c.appendToBody)&&(l.$watch("$select.open",function(e){e?h():f()}),l.$on("$destroy",function(){f()}));var b=null,w="",S=null,x="direction-up";l.$watch("$select.open",function(c){if(c){if(S=angular.element(o).querySelectorAll(".ui-select-dropdown"),null===S)return;S[0].style.opacity=0,r(function(){var c=i(o),n=i(S);c.top+c.height+n.height>t.pageYOffset+e[0].documentElement.clientHeight&&o.addClass(x),S[0].style.opacity=1})}else{if(null===S)return;o.removeClass(x)}})}}}}]),t.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,n=t.parent().attr("multiple");return c+(n?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,n,i){function l(e){i.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}i.lockChoiceExpression=n.uiLockChoice,n.$observe("placeholder",function(t){i.placeholder=void 0!==t?t:e.placeholder}),n.$observe("allowClear",l),l(n.allowClear),i.multiple&&i.sizeSearchInput()}}}]),t.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var c,n=this,i=e.$select;e.$evalAsync(function(){c=e.ngModel}),n.activeMatchIndex=-1,n.updateModel=function(){c.$setViewValue(Date.now()),n.refreshComponent()},n.refreshComponent=function(){i.refreshItems(),i.sizeSearchInput()},n.removeChoice=function(e){function c(){i.selected.splice(e,1),n.activeMatchIndex=-1,i.sizeSearchInput(),t(function(){i.afterRemove(l)}),n.updateModel()}var l=i.selected[e];if(!l._uiSelectChoiceLocked){var s=i.beforeRemove(l);angular.isFunction(s.then)?s.then(function(e){e===!0&&c()}):s===!0&&c()}},n.getPlaceholder=function(){return i.selected&&i.selected.length?void 0:i.placeholder}}],controllerAs:"$selectMultiple",link:function(c,n,i,l){function s(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function r(e){function t(){switch(e){case o.KEY.LEFT:return~u.activeMatchIndex?p:l;case o.KEY.RIGHT:return~u.activeMatchIndex&&r!==l?a:(o.activate(),!1);case o.KEY.BACKSPACE:return~u.activeMatchIndex?(u.removeChoice(r),p):l;case o.KEY.DELETE:return~u.activeMatchIndex?(u.removeChoice(u.activeMatchIndex),r):!1}}var c=s(o.searchInput[0]),n=o.selected.length,i=0,l=n-1,r=u.activeMatchIndex,a=u.activeMatchIndex+1,p=u.activeMatchIndex-1,d=r;return c>0||o.search.length&&e==o.KEY.RIGHT?!1:(o.close(),d=t(),u.activeMatchIndex=o.selected.length&&d!==!1?Math.min(l,Math.max(i,d)):-1,!0)}var o=l[0],a=c.ngModel=l[1],u=c.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,a.$parsers.unshift(function(){for(var e,t={},n=[],i=o.selected.length-1;i>=0;i--)t={},t[o.parserResult.itemName]=o.selected[i],e=o.parserResult.modelMapper(c,t),n.unshift(e);return n}),a.$formatters.unshift(function(e){var t,n=o.parserResult.source(c,{$select:{search:""}}),i={};if(!n)return e;var l=[],s=function(e,n){if(e&&e.length){for(var s=e.length-1;s>=0;s--){if(i[o.parserResult.itemName]=e[s],t=o.parserResult.modelMapper(c,i),o.parserResult.trackByExp){var r=/\.(.+)/.exec(o.parserResult.trackByExp);if(r.length>0&&t[r[1]]==n[r[1]])return l.unshift(e[s]),!0}if(angular.equals(t,n))return l.unshift(e[s]),!0}return!1}};if(!e)return l;for(var r=e.length-1;r>=0;r--)s(o.selected,e[r])||s(n,e[r])||l.unshift(e[r]);return l}),c.$watchCollection(function(){return a.$modelValue},function(e,t){t!=e&&(a.$modelValue=null,u.refreshComponent())}),a.$render=function(){if(!angular.isArray(a.$viewValue)){if(!angular.isUndefined(a.$viewValue)&&null!==a.$viewValue)throw e("multiarr","Expected model value to be array but got '{0}'",a.$viewValue);o.selected=[]}o.selected=a.$viewValue,c.$evalAsync()},c.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),u.updateModel())}),c.$on("uis:activate",function(){u.activeMatchIndex=-1}),c.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(e){var t=e.which;c.$apply(function(){var e=!1;o.KEY.isHorizontalMovement(t)&&(e=r(t)),e&&t!=o.KEY.TAB})}),o.searchInput.on("blur",function(){t(function(){u.activeMatchIndex=-1})})}}}]),t.directive("uiSelectSingle",["$timeout","$compile",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(c,n,i,l){var s=l[0],r=l[1];r.$parsers.unshift(function(e){var t,n={};return n[s.parserResult.itemName]=e,t=s.parserResult.modelMapper(c,n)}),r.$formatters.unshift(function(e){var t,n=s.parserResult.source(c,{$select:{search:""}}),i={};if(n){var l=function(n){return i[s.parserResult.itemName]=n,t=s.parserResult.modelMapper(c,i),t==e};if(s.selected&&l(s.selected))return s.selected;for(var r=n.length-1;r>=0;r--)if(l(n[r]))return n[r]}return e}),c.$watch("$select.selected",function(e){r.$viewValue!==e&&r.$setViewValue(e)}),r.$render=function(){s.selected=r.$viewValue},c.$on("uis:select",function(e,t){s.selected=t}),c.$on("uis:close",function(t,c){e(function(){s.focusser.prop("disabled",!1),c||s.focusser[0].focus()},0,!1)}),c.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");t(o)(c),s.focusser=o,s.focusInput=o,n.parent().append(o),o.bind("focus",function(){c.$evalAsync(function(){s.focus=!0})}),o.bind("blur",function(){c.$evalAsync(function(){s.focus=!1})}),o.bind("keydown",function(e){return e.which===s.KEY.BACKSPACE?(e.preventDefault(),e.stopPropagation(),s.select(void 0),c.$apply(),void 0):(e.which===s.KEY.TAB||s.KEY.isControl(e)||s.KEY.isFunctionKey(e)||e.which===s.KEY.ESC||((e.which==s.KEY.DOWN||e.which==s.KEY.UP||e.which==s.KEY.ENTER||e.which==s.KEY.SPACE)&&(e.preventDefault(),e.stopPropagation(),s.activate()),c.$digest()),void 0)}),o.bind("keyup input",function(e){e.which===s.KEY.TAB||s.KEY.isControl(e)||s.KEY.isFunctionKey(e)||e.which===s.KEY.ESC||e.which==s.KEY.ENTER||e.which===s.KEY.BACKSPACE||(s.activate(o.val()),o.val(""),c.$digest())})}}}]),t.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var n=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!n)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:n[2],source:t(n[3]),trackByExp:n[4],modelMapper:t(n[1]||n[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,n){var i=e+" in "+(n?"$group.items":t);return c&&(i+=" track by "+c),i}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("select2/choices.tpl.html",'
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/dist/select.selectize.js b/dist/select.selectize.js index 437ba94d3..86910b9f0 100644 --- a/dist/select.selectize.js +++ b/dist/select.selectize.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-09T18:09:19.185Z + * Version: 0.12.1 - 2015-08-11T18:41:59.483Z * License: MIT */ @@ -570,7 +570,7 @@ uis.controller('uiSelectCtrl', var isActive = itemIndex === -1 ? false : itemIndex === ctrl.activeIndex; // If this is active, and we've defined a callback, do it! - // TODO: Needed? + // TODO: Is this needed? If it is, then implement properly. // if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { // itemScope.$eval(ctrl.onHighlightCallback); // } @@ -594,8 +594,10 @@ uis.controller('uiSelectCtrl', if (itemIndex >= 0 && !angular.isUndefined(ctrl.disableChoiceExpression)) { item = ctrl.items[itemIndex]; - isDisabled = !!(itemScope.$eval(ctrl.disableChoiceExpression)); // force the boolean value - item._uiSelectChoiceDisabled = isDisabled; // store this for later reference + // Force the boolean value + isDisabled = !!(itemScope.$eval(ctrl.disableChoiceExpression)); + // Store this for later reference + item._uiSelectChoiceDisabled = isDisabled; } return isDisabled; @@ -841,10 +843,6 @@ uis.controller('uiSelectCtrl', e.preventDefault(); e.stopPropagation(); } - - // Let the users process the data - // TODO: Is this needed, or just let the user bind to the event themselves! -// ctrl.afterKeypress(e); }); ctrl.searchInput.on('keyup', function (e) { diff --git a/dist/select.selectize.min.js b/dist/select.selectize.min.js index 6f025c33c..059169712 100644 --- a/dist/select.selectize.min.js +++ b/dist/select.selectize.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-09T18:09:19.185Z + * Version: 0.12.1 - 2015-08-11T18:41:59.483Z * License: MIT */ !function(){"use strict";void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var e=0,t=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return e++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,i,c){c(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return t=String(t),n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var i=n[0].getBoundingClientRect();return{width:i.width||n.prop("offsetWidth"),height:i.height||n.prop("offsetHeight"),top:i.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:i.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);t.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,c){if(!c.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,c,r,l,s){var o=r.groupBy,a=r.groupFilter;if(l.parseRepeatAttr(r.repeat,o,a),l.disableChoiceExpression=r.uiDisableChoice,l.onHighlightCallback=r.onHighlight,o){var u=c.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=c.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(l.parserResult.itemName,"$select.items",l.parserResult.trackByExp,o)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+l.parserResult.itemName+")").attr("ng-click","$select.select("+l.parserResult.itemName+",false,$event)");var d=c.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),i(c,s)(e),e.$watch("$select.search",function(e){e&&!l.open&&l.multiple&&l.activate(!1,!0),l.activeIndex=0})}}}}]),t.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(e,t,n,i,c,r,l,s){function o(){(d.resetSearchInput||void 0===d.resetSearchInput&&s.resetSearchInput)&&(d.search=f,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function a(e,t){var n,i,c=[];for(n=0;n0&&d.activeIndex--;break;case d.KEY.TAB:(!d.multiple||d.open)&&d.select(d.items[d.activeIndex],!0);break;case d.KEY.ENTER:d.open?void 0!==d.items[d.activeIndex]&&d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case d.KEY.ESC:d.close();break;default:t=!1}return t}function p(){var e=t.querySelectorAll(".ui-select-choices-content"),n=e.querySelectorAll(".ui-select-choices-row");if(n.length<1)throw l("choices","Expected multiple .ui-select-choices-row but got '{0}'.",n.length);if(!(d.activeIndex<0)){var i=n[d.activeIndex],c=i.offsetTop+i.clientHeight-e[0].scrollTop,r=e[0].offsetHeight;c>r?e[0].scrollTop+=c-r:c=112&&123>=e},isVerticalMovement:function(e){return~[d.KEY.UP,d.KEY.DOWN].indexOf(e)},isHorizontalMovement:function(e){return~[d.KEY.LEFT,d.KEY.RIGHT,d.KEY.BACKSPACE,d.KEY.DELETE].indexOf(e)}},d.isEmpty=function(){return angular.isUndefined(d.selected)||null===d.selected||""===d.selected},d.findGroupByName=function(e){return d.groups&&d.groups.filter(function(t){return t.name===e})[0]},d.activate=function(t,i){if(d.disabled||d.open)d.open&&!d.searchEnabled&&d.close();else{var c=function(){i||o(),e.$broadcast("uis:activate"),d.open=!0,d.searchEnabled||angular.element(d.searchInput[0]).addClass("ui-select-offscreen"),d.activeIndex=d.activeIndex>=d.items.length?0:d.activeIndex,n(function(){d.search=t||d.search,d.searchInput[0].focus()})},r=d.beforeDropdownOpen();angular.isFunction(r.then)?r.then(function(e){e===!0&&c()}):r===!0&&c()}},d.parseRepeatAttr=function(t,n,i){function c(t){var c=e.$eval(n);if(d.groups=[],angular.forEach(t,function(e){var t=angular.isFunction(c)?c(e):e[c],n=d.findGroupByName(t);n?n.items.push(e):d.groups.push({name:t,items:[e]})}),i){var r=e.$eval(i);angular.isFunction(r)?d.groups=r(d.groups):angular.isArray(r)&&(d.groups=a(d.groups,r))}d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function s(e){d.items=e}d.setItemsFn=n?c:s,d.parserResult=r.parse(t),d.isGrouped=!!n,d.itemProperty=d.parserResult.itemName,d.refreshItems=function(t){t=t||d.parserResult.source(e);var n=d.selected;if(d.isEmpty()||angular.isArray(n)&&!n.length||!d.removeSelected)d.setItemsFn(t);else if(void 0!==t){var i=t.filter(function(e){return n.indexOf(e)<0});d.setItemsFn(i)}},e.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw l("items","Expected an array but got '{0}'.",e);d.refreshItems(e),d.ngModel.$modelValue=null}})},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){if(!d.open)return!1;var t=d.items.indexOf(e[d.itemProperty]),n=-1===t?!1:t===d.activeIndex;return n},d.isDisabled=function(e){if(!d.open)return!1;var t,n=d.items.indexOf(e[d.itemProperty]),i=!1;return n>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[n],i=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i},d.select=function(t,i,c){function r(){e.$broadcast("uis:select",t),n(function(){d.afterSelect(t)}),d.closeOnSelect&&d.close(i),c&&"click"===c.type&&(d.clickTriggeredSelect=!0)}if((void 0===t||!t._uiSelectChoiceDisabled)&&(d.items||d.search)){var l=d.beforeSelect(t);angular.isFunction(l.then)?l.then(function(e){e&&(e===!0?r(t):e&&r(e))}):l===!0?r(t):l&&r(l)}},d.close=function(t){function n(){d.ngModel&&d.ngModel.$setTouched&&d.ngModel.$setTouched(),o(),d.open=!1,d.searchEnabled||angular.element(d.searchInput[0]).removeClass("ui-select-offscreen"),e.$broadcast("uis:close",t)}if(d.open){var i=d.beforeDropdownClose();angular.isFunction(i.then)?i.then(function(e){e===!0&&n()}):i===!0&&n()}},d.setFocus=function(){d.focus||d.focusInput[0].focus()},d.clear=function(e){d.select(void 0),e.stopPropagation(),n(function(){d.focusser[0].focus()},0,!1)},d.toggle=function(e){d.open?(d.close(),e.preventDefault(),e.stopPropagation()):d.activate()},d.isLocked=function(e,t){var n,i=d.selected[t];return i&&!angular.isUndefined(d.lockChoiceExpression)&&(n=!!e.$eval(d.lockChoiceExpression),i._uiSelectChoiceLocked=n),n};var h=null;d.sizeSearchInput=function(){var t=d.searchInput[0],i=d.searchInput.parent().parent()[0],c=function(){return i.clientWidth*!!t.offsetParent},r=function(e){if(0===e)return!1;var n=e-t.offsetLeft-d.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=e),d.searchInput.css("width",n+"px"),!0};d.searchInput.css("width","10px"),n(function(){null!==h||r(c())||(h=e.$watch(c,function(e){r(e)&&(h(),h=null)}))})},d.searchInput.on("keydown",function(t){var n=t.which;~[d.KEY.ESC,d.KEY.TAB].indexOf(n)&&d.close(),e.$apply(function(){u(n)}),d.KEY.isVerticalMovement(n)&&d.items.length>0&&p(),(n===d.KEY.ENTER||n===d.KEY.ESC)&&(t.preventDefault(),t.stopPropagation())}),d.searchInput.on("keyup",function(e){e.which===d.KEY.TAB||d.KEY.isControl(e)||d.KEY.isFunctionKey(e)||e.which===d.KEY.ESC||d.KEY.isVerticalMovement(e.which)||d.afterKeypress(e)}),e.$on("$destroy",function(){d.searchInput.off("keyup keydown blur paste")}),d.afterKeypress=function(){},d.beforeSelect=function(){return!0},d.afterSelect=function(){},d.beforeRemove=function(){return!0},d.afterRemove=function(){},d.beforeDropdownOpen=function(){return!0},d.beforeDropdownClose=function(){return!0}}]),t.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,i,c,r,l,s){return{restrict:"EA",templateUrl:function(e,t){var i=t.theme||n.theme;return i+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(r,o){return angular.isDefined(o.multiple)?r.append("").removeAttr("multiple"):r.append(""),function(r,o,a,u,p){function d(e){if(v.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(o[0],e.target):o[0].contains(e.target),!t&&!v.clickTriggeredSelect){var n=["input","button","textarea"],i=angular.element(e.target).controller("uiSelect"),c=i&&i!==v;c||(c=~n.indexOf(e.target.tagName.toLowerCase())),v.close(c),r.$digest()}v.clickTriggeredSelect=!1}}function f(){var t=c(o);S=angular.element('
    '),S[0].style.width=t.width+"px",S[0].style.height=t.height+"px",o.after(S),b=o[0].style.width,e.find("body").append(o),o[0].style.position="absolute",o[0].style.left=t.left+"px",o[0].style.top=t.top+"px",o[0].style.width=t.width+"px"}function h(){null!==S&&(S.replaceWith(o),S=null,o[0].style.position="",o[0].style.left="",o[0].style.top="",o[0].style.width=b)}var v=u[0],g=u[1];v.generatedId=n.generateId(),v.baseTitle=a.title||"Select box",v.focusserTitle=v.baseTitle+" focus",v.focusserId="focusser-"+v.generatedId,v.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?l(a.closeOnSelect)():n.closeOnSelect}(),v.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,v.ngModel=g,v.choiceGrouped=function(e){return v.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){v.focusInput.attr("tabindex",e),o.removeAttr("tabindex")});var m=r.$eval(a.searchEnabled);v.searchEnabled=void 0!==m?m:n.searchEnabled;var E=r.$eval(a.sortable);v.sortable=void 0!==E?E:n.sortable,a.$observe("disabled",function(){v.disabled=void 0!==a.disabled?a.disabled:!1}),angular.isDefined(a.autofocus)&&s(function(){v.setFocus()}),angular.isDefined(a.focusOn)&&r.$on(a.focusOn,function(){s(function(){v.setFocus()})}),e.on("click",d),r.$on("$destroy",function(){e.off("click",d)}),p(r,function(e){var t=angular.element("
    ").append(e),n=t.querySelectorAll(".ui-select-match");if(n.removeAttr("ui-select-match"),n.removeAttr("data-ui-select-match"),1!==n.length)throw i("transcluded","Expected 1 .ui-select-match but got '{0}'.",n.length);o.querySelectorAll(".ui-select-match").replaceWith(n);var c=t.querySelectorAll(".ui-select-choices");if(c.removeAttr("ui-select-choices"),c.removeAttr("data-ui-select-choices"),1!==c.length)throw i("transcluded","Expected 1 .ui-select-choices but got '{0}'.",c.length);o.querySelectorAll(".ui-select-choices").replaceWith(c)});var $=r.$eval(a.appendToBody);(void 0!==$?$:n.appendToBody)&&(r.$watch("$select.open",function(e){e?f():h()}),r.$on("$destroy",function(){h()}));var S=null,b="",w=null,x="direction-up";r.$watch("$select.open",function(n){if(n){if(w=angular.element(o).querySelectorAll(".ui-select-dropdown"),null===w)return;w[0].style.opacity=0,s(function(){var n=c(o),i=c(w);n.top+n.height+i.height>t.pageYOffset+e[0].documentElement.clientHeight&&o.addClass(x),w[0].style.opacity=1})}else{if(null===w)return;o.removeClass(x)}})}}}}]),t.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return n+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,i,c){function r(e){c.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}c.lockChoiceExpression=i.uiLockChoice,i.$observe("placeholder",function(t){c.placeholder=void 0!==t?t:e.placeholder}),i.$observe("allowClear",r),r(i.allowClear),c.multiple&&c.sizeSearchInput()}}}]),t.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,i=this,c=e.$select;e.$evalAsync(function(){n=e.ngModel}),i.activeMatchIndex=-1,i.updateModel=function(){n.$setViewValue(Date.now()),i.refreshComponent()},i.refreshComponent=function(){c.refreshItems(),c.sizeSearchInput()},i.removeChoice=function(e){function n(){c.selected.splice(e,1),i.activeMatchIndex=-1,c.sizeSearchInput(),t(function(){c.afterRemove(r)}),i.updateModel()}var r=c.selected[e];if(!r._uiSelectChoiceLocked){var l=c.beforeRemove(r);angular.isFunction(l.then)?l.then(function(e){e===!0&&n()}):l===!0&&n()}},i.getPlaceholder=function(){return c.selected&&c.selected.length?void 0:c.placeholder}}],controllerAs:"$selectMultiple",link:function(n,i,c,r){function l(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function s(e){function t(){switch(e){case o.KEY.LEFT:return~u.activeMatchIndex?p:r;case o.KEY.RIGHT:return~u.activeMatchIndex&&s!==r?a:(o.activate(),!1);case o.KEY.BACKSPACE:return~u.activeMatchIndex?(u.removeChoice(s),p):r;case o.KEY.DELETE:return~u.activeMatchIndex?(u.removeChoice(u.activeMatchIndex),s):!1}}var n=l(o.searchInput[0]),i=o.selected.length,c=0,r=i-1,s=u.activeMatchIndex,a=u.activeMatchIndex+1,p=u.activeMatchIndex-1,d=s;return n>0||o.search.length&&e==o.KEY.RIGHT?!1:(o.close(),d=t(),u.activeMatchIndex=o.selected.length&&d!==!1?Math.min(r,Math.max(c,d)):-1,!0)}var o=r[0],a=n.ngModel=r[1],u=n.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,a.$parsers.unshift(function(){for(var e,t={},i=[],c=o.selected.length-1;c>=0;c--)t={},t[o.parserResult.itemName]=o.selected[c],e=o.parserResult.modelMapper(n,t),i.unshift(e);return i}),a.$formatters.unshift(function(e){var t,i=o.parserResult.source(n,{$select:{search:""}}),c={};if(!i)return e;var r=[],l=function(e,i){if(e&&e.length){for(var l=e.length-1;l>=0;l--){if(c[o.parserResult.itemName]=e[l],t=o.parserResult.modelMapper(n,c),o.parserResult.trackByExp){var s=/\.(.+)/.exec(o.parserResult.trackByExp);if(s.length>0&&t[s[1]]==i[s[1]])return r.unshift(e[l]),!0}if(angular.equals(t,i))return r.unshift(e[l]),!0}return!1}};if(!e)return r;for(var s=e.length-1;s>=0;s--)l(o.selected,e[s])||l(i,e[s])||r.unshift(e[s]);return r}),n.$watchCollection(function(){return a.$modelValue},function(e,t){t!=e&&(a.$modelValue=null,u.refreshComponent())}),a.$render=function(){if(!angular.isArray(a.$viewValue)){if(!angular.isUndefined(a.$viewValue)&&null!==a.$viewValue)throw e("multiarr","Expected model value to be array but got '{0}'",a.$viewValue);o.selected=[]}o.selected=a.$viewValue,n.$evalAsync()},n.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),u.updateModel())}),n.$on("uis:activate",function(){u.activeMatchIndex=-1}),n.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(e){var t=e.which;n.$apply(function(){var e=!1;o.KEY.isHorizontalMovement(t)&&(e=s(t)),e&&t!=o.KEY.TAB})}),o.searchInput.on("blur",function(){t(function(){u.activeMatchIndex=-1})})}}}]),t.directive("uiSelectSingle",["$timeout","$compile",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(n,i,c,r){var l=r[0],s=r[1];s.$parsers.unshift(function(e){var t,i={};return i[l.parserResult.itemName]=e,t=l.parserResult.modelMapper(n,i)}),s.$formatters.unshift(function(e){var t,i=l.parserResult.source(n,{$select:{search:""}}),c={};if(i){var r=function(i){return c[l.parserResult.itemName]=i,t=l.parserResult.modelMapper(n,c),t==e};if(l.selected&&r(l.selected))return l.selected;for(var s=i.length-1;s>=0;s--)if(r(i[s]))return i[s]}return e}),n.$watch("$select.selected",function(e){s.$viewValue!==e&&s.$setViewValue(e)}),s.$render=function(){l.selected=s.$viewValue},n.$on("uis:select",function(e,t){l.selected=t}),n.$on("uis:close",function(t,n){e(function(){l.focusser.prop("disabled",!1),n||l.focusser[0].focus()},0,!1)}),n.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");t(o)(n),l.focusser=o,l.focusInput=o,i.parent().append(o),o.bind("focus",function(){n.$evalAsync(function(){l.focus=!0})}),o.bind("blur",function(){n.$evalAsync(function(){l.focus=!1})}),o.bind("keydown",function(e){return e.which===l.KEY.BACKSPACE?(e.preventDefault(),e.stopPropagation(),l.select(void 0),n.$apply(),void 0):(e.which===l.KEY.TAB||l.KEY.isControl(e)||l.KEY.isFunctionKey(e)||e.which===l.KEY.ESC||((e.which==l.KEY.DOWN||e.which==l.KEY.UP||e.which==l.KEY.ENTER||e.which==l.KEY.SPACE)&&(e.preventDefault(),e.stopPropagation(),l.activate()),n.$digest()),void 0)}),o.bind("keyup input",function(e){e.which===l.KEY.TAB||l.KEY.isControl(e)||l.KEY.isFunctionKey(e)||e.which===l.KEY.ESC||e.which==l.KEY.ENTER||e.which===l.KEY.BACKSPACE||(l.activate(o.val()),o.val(""),n.$digest())})}}}]),t.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var i=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!i)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:i[2],source:t(i[3]),trackByExp:i[4],modelMapper:t(i[1]||i[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,i){var c=e+" in "+(i?"$group.items":t);return n&&(c+=" track by "+n),c}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("selectize/choices.tpl.html",'
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/dist/select.sort.js b/dist/select.sort.js index dbf8c15e1..be9742d9c 100644 --- a/dist/select.sort.js +++ b/dist/select.sort.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-09T18:09:19.204Z + * Version: 0.12.1 - 2015-08-11T18:41:59.488Z * License: MIT */ @@ -150,7 +150,8 @@ angular.module('ui.select.sort', ['ui.select']) }; }]); -}());ted))) { +}());d + if (_findCaseInsensitiveDupe(stashArr.concat($select.selected))) { // if there is a tag from prev iteration, strip it / queue the change // and return early if (hasTag) { @@ -169,7 +170,7 @@ angular.module('ui.select.sort', ['ui.select']) } return; } -// } + if (hasTag) { dupeIndex = _findApproxDupe($select.selected, newItem); } @@ -193,14 +194,12 @@ angular.module('ui.select.sort', ['ui.select']) if (arr === undefined || $select.search === undefined) { return false; } - var hasDupe = arr.filter(function (origItem) { + return arr.filter(function (origItem) { if ($select.search.toUpperCase() === undefined || origItem === undefined) { return false; } return origItem.toUpperCase() === $select.search.toUpperCase(); }).length > 0; - - return hasDupe; } function _findApproxDupe(haystack, needle) { diff --git a/dist/select.sort.min.js b/dist/select.sort.min.js index bd24072ca..61358e531 100644 --- a/dist/select.sort.min.js +++ b/dist/select.sort.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-09T18:09:19.204Z + * Version: 0.12.1 - 2015-08-11T18:41:59.488Z * License: MIT */ -!function(){"use strict";angular.module("ui.select.sort",["ui.select"]).directive("uiSelectSort",["$timeout","uiSelectConfig","uiSelectMinErr",function(e,t,a){return{require:"^uiSelect",link:function(t,r,n,i){if(null===t[n.uiSelectSort])throw a("sort","Expected a list to sort");var o=angular.extend({axis:"horizontal"},t.$eval(n.uiSelectSortOptions)),s=o.axis,l="dragging",f="dropping",d="dropping-before",u="dropping-after";t.$watch(function(){return i.sortable},function(e){e?r.attr("draggable",!0):r.removeAttr("draggable")}),r.on("dragstart",function(e){r.addClass(l),(e.dataTransfer||e.originalEvent.dataTransfer).setData("text/plain",t.$index)}),r.on("dragend",function(){r.removeClass(l)});var c,v=function(e,t){this.splice(t,0,this.splice(e,1)[0])},g=function(e){e.preventDefault();var t="vertical"===s?e.offsetY||e.layerY||(e.originalEvent?e.originalEvent.offsetY:0):e.offsetX||e.layerX||(e.originalEvent?e.originalEvent.offsetX:0);t-1)return;if(a(f.concat(i.selected)))return v&&(h=f,e.$evalAsync(function(){i.activeIndex=0,i.items=h})),void 0;if(a(f))return v&&(i.items=f.slice(1,f.length)),void 0;v&&(d=r(i.selected,s)),d>-1?h=h.slice(d+1,h.length-1):(h=[],h.push(s),h=h.concat(f)),e.$evalAsync(function(){i.activeIndex=0,i.items=h})}}}}}])}(); \ No newline at end of file +!function(){"use strict";angular.module("ui.select.sort",["ui.select"]).directive("uiSelectSort",["$timeout","uiSelectConfig","uiSelectMinErr",function(e,t,a){return{require:"^uiSelect",link:function(t,r,n,i){if(null===t[n.uiSelectSort])throw a("sort","Expected a list to sort");var o=angular.extend({axis:"horizontal"},t.$eval(n.uiSelectSortOptions)),s=o.axis,l="dragging",f="dropping",d="dropping-before",u="dropping-after";t.$watch(function(){return i.sortable},function(e){e?r.attr("draggable",!0):r.removeAttr("draggable")}),r.on("dragstart",function(e){r.addClass(l),(e.dataTransfer||e.originalEvent.dataTransfer).setData("text/plain",t.$index)}),r.on("dragend",function(){r.removeClass(l)});var c,v=function(e,t){this.splice(t,0,this.splice(e,1)[0])},g=function(e){e.preventDefault();var t="vertical"===s?e.offsetY||e.layerY||(e.originalEvent?e.originalEvent.offsetY:0):e.offsetX||e.layerX||(e.originalEvent?e.originalEvent.offsetX:0);t-1)return;if(a(h.concat(i.selected)))return f&&(u=h,e.$evalAsync(function(){i.activeIndex=0,i.items=u})),void 0;if(a(h))return f&&(i.items=h.slice(1,h.length)),void 0;f&&(v=g(i.selected,c)),v>-1?u=u.slice(v+1,u.length-1):(u=[],u.push(c),u=u.concat(h)),e.$evalAsync(function(){i.activeIndex=0,i.items=u})}}}}}])}(); \ No newline at end of file diff --git a/dist/select.tpl.js b/dist/select.tpl.js index d7568c1e8..f6ef70af6 100644 --- a/dist/select.tpl.js +++ b/dist/select.tpl.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-09T18:09:19.140Z + * Version: 0.12.1 - 2015-08-11T18:41:59.440Z * License: MIT */ diff --git a/src/addons/uiSelectTaggingDirective.js b/src/addons/uiSelectTaggingDirective.js index cd5f426a4..33ab84331 100644 --- a/src/addons/uiSelectTaggingDirective.js +++ b/src/addons/uiSelectTaggingDirective.js @@ -13,9 +13,13 @@ angular.module('ui.select.tagging', ['ui.select']) ctrl.searchInput.on('paste', function (e) { var data = e.clipboardData.getData('text/plain'); if (data && data.length > 0) { - var items = data.split(ctrl.taggingTokens[0]); // Split by first token only + // Split by first token only + var items = data.split(ctrl.taggingTokens[0]); if (items && items.length > 0) { angular.forEach(items, function (item) { + if(item === null || item.length === 0) { + return; + } var newItem = ctrl.beforeTagging(item); if (newItem) { ctrl.select(newItem, true); @@ -53,27 +57,21 @@ angular.module('ui.select.tagging', ['ui.select']) } // Check for end of tagging - var tagged = false; -// if (e.which === ctrl.KEY.ENTER) { -// tagged = true; -// } for (var i = 0; i < ctrl.taggingTokens.length; i++) { if (ctrl.taggingTokens[i] === ctrl.KEY.MAP[e.keyCode]) { // Make sure there is a new value to push via tagging if (ctrl.search.length > 0) { - tagged = true; + // Make sure that we don't leave the tagging character on the end of the item label if ($select.search.substr($select.search.length - 1) == ctrl.KEY.MAP[e.keyCode]) { + $select.search = $select.search.substr(0, $select.search.length - 1); + } - $select.search = $select.search.substr(0, $select.search.length - 1); - } + // Select this item and return + ctrl.select(ctrl.beforeTagging($select.search)); + return; } } } - if (tagged === true) { - ctrl.select(ctrl.beforeTagging($select.search)); - return; - } - $select.activeIndex = $select.taggingLabel === false ? -1 : 0; // If taggingLabel === false bypasses all of this @@ -130,7 +128,7 @@ angular.module('ui.select.tagging', ['ui.select']) } return; } -// } + if (hasTag) { dupeIndex = _findApproxDupe($select.selected, newItem); } @@ -154,14 +152,12 @@ angular.module('ui.select.tagging', ['ui.select']) if (arr === undefined || $select.search === undefined) { return false; } - var hasDupe = arr.filter(function (origItem) { + return arr.filter(function (origItem) { if ($select.search.toUpperCase() === undefined || origItem === undefined) { return false; } return origItem.toUpperCase() === $select.search.toUpperCase(); }).length > 0; - - return hasDupe; } function _findApproxDupe(haystack, needle) { diff --git a/src/uiSelectController.js b/src/uiSelectController.js index 5f5e805e7..5a42e2459 100644 --- a/src/uiSelectController.js +++ b/src/uiSelectController.js @@ -376,7 +376,7 @@ uis.controller('uiSelectCtrl', var isActive = itemIndex === -1 ? false : itemIndex === ctrl.activeIndex; // If this is active, and we've defined a callback, do it! - // TODO: Needed? + // TODO: Is this needed? If it is, then implement properly. // if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { // itemScope.$eval(ctrl.onHighlightCallback); // } @@ -400,8 +400,10 @@ uis.controller('uiSelectCtrl', if (itemIndex >= 0 && !angular.isUndefined(ctrl.disableChoiceExpression)) { item = ctrl.items[itemIndex]; - isDisabled = !!(itemScope.$eval(ctrl.disableChoiceExpression)); // force the boolean value - item._uiSelectChoiceDisabled = isDisabled; // store this for later reference + // Force the boolean value + isDisabled = !!(itemScope.$eval(ctrl.disableChoiceExpression)); + // Store this for later reference + item._uiSelectChoiceDisabled = isDisabled; } return isDisabled; @@ -647,10 +649,6 @@ uis.controller('uiSelectCtrl', e.preventDefault(); e.stopPropagation(); } - - // Let the users process the data - // TODO: Is this needed, or just let the user bind to the event themselves! -// ctrl.afterKeypress(e); }); ctrl.searchInput.on('keyup', function (e) { diff --git a/test/select.spec.js b/test/select.spec.js index bcfb646f3..8b2541589 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -36,7 +36,7 @@ describe('ui-select tests', function () { }); - beforeEach(module('ngSanitize', 'ui.select', 'wrapperDirective')); + beforeEach(module('ngSanitize', 'ui.select', 'ui.select.tagging', 'wrapperDirective')); beforeEach(function () { module(function ($provide) { @@ -117,7 +117,7 @@ describe('ui-select tests', function () { attrsHtml += ' tabindex="' + attrs.tabindex + '"'; } if (attrs.tagging !== undefined) { - attrsHtml += ' tagging="' + attrs.tagging + '"'; + attrsHtml += ' ui-select-tagging="' + attrs.tagging + '"'; } if (attrs.taggingTokens !== undefined) { attrsHtml += ' tagging-tokens="' + attrs.taggingTokens + '"'; @@ -179,12 +179,11 @@ describe('ui-select tests', function () { function triggerPaste(element, text) { var e = jQuery.Event("paste"); - e.originalEvent = { - clipboardData: { - getData: function () { - return text; - } + e.clipboardData = { + getData: function () { + return text; } + }; element.trigger(e); } @@ -1208,11 +1207,11 @@ describe('ui-select tests', function () { el.find('.ui-select-match-item').first().find('.ui-select-match-close').click(); $timeout.flush(); - expect(scope.$item).toBe(scope.people[5]); - expect(scope.selection.selected).toBe('Samantha'); + expect(scope.$item.name).toBe(scope.people[5].name); + expect(scope.selection.selected[0]).toBe(scope.people[3].name); }); - it('should set $item & $model correctly when invoking callback on remove and no single prop. binding', function () { + it('should set $item correctly when invoking callback on remove and no single prop. binding', function () { var el = compileTemplate( ' \ {{$select.selected.name}} \ @@ -1234,12 +1233,11 @@ describe('ui-select tests', function () { el.find('.ui-select-match-item').first().find('.ui-select-match-close').click(); $timeout.flush(); - expect(scope.$item).toBe(scope.people[5]); - expect(scope.selection.selected).toBe(scope.$item); + expect(scope.$item.name).toBe(scope.people[5].name); + expect(scope.selection.selected[0].name).toBe(scope.people[3].name); }); it('should append/transclude content (with correct scope) that users add at tag', function () { - var el = compileTemplate( ' \ \ @@ -1328,7 +1326,6 @@ describe('ui-select tests', function () { } describe('selectize theme', function () { - it('should show search input when true', function () { setupSelectComponent(true, 'selectize'); expect($(el).find('.ui-select-search')).not.toHaveClass('ng-hide'); @@ -1342,7 +1339,6 @@ describe('ui-select tests', function () { }); describe('select2 theme', function () { - it('should show search input when true', function () { setupSelectComponent('true', 'select2'); expect($(el).find('.select2-search')).not.toHaveClass('ng-hide'); @@ -1356,7 +1352,6 @@ describe('ui-select tests', function () { }); describe('bootstrap theme', function () { - it('should show search input when true', function () { setupSelectComponent('true', 'bootstrap'); clickMatch(el); @@ -1375,7 +1370,6 @@ describe('ui-select tests', function () { describe('multi selection', function () { - function createUiSelectMultiple(attrs) { var attrsHtml = ''; if (attrs !== undefined) { @@ -1392,7 +1386,7 @@ describe('ui-select tests', function () { attrsHtml += ' close-on-select="' + attrs.closeOnSelect + '"'; } if (attrs.tagging !== undefined) { - attrsHtml += ' tagging="' + attrs.tagging + '"'; + attrsHtml += ' ui-select-tagging="' + attrs.tagging + '"'; } if (attrs.taggingTokens !== undefined) { attrsHtml += ' tagging-tokens="' + attrs.taggingTokens + '"'; @@ -1418,7 +1412,6 @@ describe('ui-select tests', function () { }); it('should set model as an empty array if ngModel isnt defined after an item is selected', function () { - // scope.selection.selectedMultiple = []; var el = createUiSelectMultiple(); expect(scope.selection.selectedMultiple instanceof Array).toBe(false); @@ -1950,12 +1943,12 @@ describe('ui-select tests', function () { }); it('should allow paste tag from clipboard', function () { - var el = createUiSelectMultiple({taggingTokens: ",|ENTER"}); + var el = createUiSelectMultiple({tagging: true, taggingTokens: ",|ENTER"}); el.scope().$select.beforeTagging = function (item) { return { - name: name, - email: name + '@email.com', + name: item, + email: item + '@email.com', group: 'Foo', age: 12 }; @@ -1968,12 +1961,12 @@ describe('ui-select tests', function () { }); it('should allow paste multiple tags', function () { - var el = createUiSelectMultiple({taggingTokens: ",|ENTER"}); + var el = createUiSelectMultiple({tagging: true, taggingTokens: ",|ENTER"}); el.scope().$select.beforeTagging = function (item) { return { - name: name, - email: name + '@email.com', + name: item, + email: item + '@email.com', group: 'Foo', age: 12 }; @@ -1981,7 +1974,7 @@ describe('ui-select tests', function () { clickMatch(el); triggerPaste(el.find('input'), ',tag1,tag2,tag3,,tag5,'); - expect($(el).scope().$select.selected.length).toBe(5); + expect($(el).scope().$select.selected.length).toBe(4); }); }); From 14a5789f68f2663ed1fe3f508d9bd0985694f469 Mon Sep 17 00:00:00 2001 From: Chris Jackson Date: Wed, 12 Aug 2015 21:30:46 +0100 Subject: [PATCH 28/28] Update dist folder --- dist/select.bootstrap.js | 1771 ----------------- dist/select.bootstrap.min.js | 7 - dist/select.css | 27 +- dist/select.js | 3624 ++++++++++++++++------------------ dist/select.min.css | 4 +- dist/select.min.js | 4 +- dist/select.no-tpl.js | 1766 ----------------- dist/select.no-tpl.min.js | 7 - dist/select.select2.js | 1771 ----------------- dist/select.select2.min.js | 7 - dist/select.selectize.js | 1769 ----------------- dist/select.selectize.min.js | 7 - dist/select.sort.js | 234 --- dist/select.sort.min.js | 7 - dist/select.tpl.js | 21 - 15 files changed, 1666 insertions(+), 9360 deletions(-) delete mode 100644 dist/select.bootstrap.js delete mode 100644 dist/select.bootstrap.min.js delete mode 100644 dist/select.no-tpl.js delete mode 100644 dist/select.no-tpl.min.js delete mode 100644 dist/select.select2.js delete mode 100644 dist/select.select2.min.js delete mode 100644 dist/select.selectize.js delete mode 100644 dist/select.selectize.min.js delete mode 100644 dist/select.sort.js delete mode 100644 dist/select.sort.min.js delete mode 100644 dist/select.tpl.js diff --git a/dist/select.bootstrap.js b/dist/select.bootstrap.js deleted file mode 100644 index 38189760e..000000000 --- a/dist/select.bootstrap.js +++ /dev/null @@ -1,1771 +0,0 @@ -/*! - * ui-select - * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-11T18:41:59.467Z - * License: MIT - */ - - -(function () { -"use strict"; - -/** - * Add querySelectorAll() to jqLite. - * - * jqLite find() is limited to lookups by tag name. - * TODO This will change with future versions of AngularJS, to be removed when this happens - * - * See jqLite.find - why not use querySelectorAll? https://github.com/angular/angular.js/issues/3586 - * See feat(jqLite): use querySelectorAll instead of getElementsByTagName in jqLite.find https://github.com/angular/angular.js/pull/3598 - */ -if (angular.element.prototype.querySelectorAll === undefined) { - angular.element.prototype.querySelectorAll = function (selector) { - return angular.element(this[0].querySelectorAll(selector)); - }; -} - -/** - * Add closest() to jqLite. - */ -if (angular.element.prototype.closest === undefined) { - angular.element.prototype.closest = function (selector) { - var elem = this[0]; - var matchesSelector = elem.matches || elem.webkitMatchesSelector || elem.mozMatchesSelector || - elem.msMatchesSelector; - - while (elem) { - if (matchesSelector.bind(elem)(selector)) { - return elem; - } else { - elem = elem.parentElement; - } - } - return false; - }; -} - -var latestId = 0; - -var uis = angular.module('ui.select', []) - - .constant('uiSelectConfig', { - theme: 'bootstrap', - searchEnabled: true, - sortable: false, - placeholder: '', // Empty by default, like HTML tag "); - $compile(focusser)(scope); - $select.focusser = focusser; - - // Input that will handle focus - $select.focusInput = focusser; - - element.parent().append(focusser); - focusser.bind("focus", function () { - scope.$evalAsync(function () { - $select.focus = true; - }); - }); - focusser.bind("blur", function () { - scope.$evalAsync(function () { - $select.focus = false; - }); - }); - - focusser.bind("keydown", function (e) { - if (e.which === $select.KEY.BACKSPACE) { - e.preventDefault(); - e.stopPropagation(); - $select.select(undefined); - scope.$apply(); - return; - } - - if (e.which === $select.KEY.TAB || $select.KEY.isControl(e) || $select.KEY.isFunctionKey(e) || e.which === $select.KEY.ESC) { - return; - } - - if (e.which == $select.KEY.DOWN || e.which == $select.KEY.UP || e.which == $select.KEY.ENTER || e.which == $select.KEY.SPACE) { - e.preventDefault(); - e.stopPropagation(); - $select.activate(); - } - - scope.$digest(); - }); - - focusser.bind("keyup input", function (e) { - if (e.which === $select.KEY.TAB || $select.KEY.isControl(e) || $select.KEY.isFunctionKey(e) || e.which === $select.KEY.ESC || - e.which == $select.KEY.ENTER || e.which === $select.KEY.BACKSPACE) { - return; - } - - // User pressed some regular key, so we pass it to the search input - $select.activate(focusser.val()); - focusser.val(''); - scope.$digest(); - }); - } - }; -}]); -/** - * Parses "repeat" attribute. - * - * Taken from AngularJS ngRepeat source code - * See https://github.com/angular/angular.js/blob/v1.2.15/src/ng/directive/ngRepeat.js#L211 - * - * Original discussion about parsing "repeat" attribute instead of fully relying on ng-repeat: - * https://github.com/angular-ui/ui-select/commit/5dd63ad#commitcomment-5504697 - */ - -uis.service('uisRepeatParser', ['uiSelectMinErr', '$parse', function (uiSelectMinErr, $parse) { - var self = this; - - /** - * Example: - * expression = "address in addresses | filter: {street: $select.search} track by $index" - * itemName = "address", - * source = "addresses | filter: {street: $select.search}", - * trackByExp = "$index", - */ - self.parse = function (expression) { - - var match = expression.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/); - - if (!match) { - throw uiSelectMinErr('iexp', - "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.", - expression); - } - - return { - itemName: match[2], // (lhs) Left-hand side, - source: $parse(match[3]), - trackByExp: match[4], - modelMapper: $parse(match[1] || match[2]) - }; - - }; - - self.getGroupNgRepeatExpression = function () { - return '$group in $select.groups'; - }; - - self.getNgRepeatExpression = function (itemName, source, trackByExp, grouped) { - var expression = itemName + ' in ' + (grouped ? '$group.items' : source); - if (trackByExp) { - expression += ' track by ' + trackByExp; - } - return expression; - }; -}]); - -}()); -angular.module("ui.select").run(["$templateCache", function($templateCache) {$templateCache.put("bootstrap/choices.tpl.html","
      0\">
    • 0\">
    "); -$templateCache.put("bootstrap/match-multiple.tpl.html"," × "); -$templateCache.put("bootstrap/match.tpl.html","
    {{$select.placeholder}}
    "); -$templateCache.put("bootstrap/select-multiple.tpl.html","
    "); -$templateCache.put("bootstrap/select.tpl.html","
    ");}]); \ No newline at end of file diff --git a/dist/select.bootstrap.min.js b/dist/select.bootstrap.min.js deleted file mode 100644 index 6a1439d19..000000000 --- a/dist/select.bootstrap.min.js +++ /dev/null @@ -1,7 +0,0 @@ -/*! - * ui-select - * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-11T18:41:59.467Z - * License: MIT - */ -!function(){"use strict";void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var e=0,t=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return e++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,i,c){c(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return t=String(t),n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var i=n[0].getBoundingClientRect();return{width:i.width||n.prop("offsetWidth"),height:i.height||n.prop("offsetHeight"),top:i.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:i.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);t.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,c){if(!c.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,c,l,r,s){var o=l.groupBy,a=l.groupFilter;if(r.parseRepeatAttr(l.repeat,o,a),r.disableChoiceExpression=l.uiDisableChoice,r.onHighlightCallback=l.onHighlight,o){var u=c.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=c.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(r.parserResult.itemName,"$select.items",r.parserResult.trackByExp,o)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+r.parserResult.itemName+")").attr("ng-click","$select.select("+r.parserResult.itemName+",false,$event)");var d=c.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),i(c,s)(e),e.$watch("$select.search",function(e){e&&!r.open&&r.multiple&&r.activate(!1,!0),r.activeIndex=0})}}}}]),t.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(e,t,n,i,c,l,r,s){function o(){(d.resetSearchInput||void 0===d.resetSearchInput&&s.resetSearchInput)&&(d.search=h,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function a(e,t){var n,i,c=[];for(n=0;n0&&d.activeIndex--;break;case d.KEY.TAB:(!d.multiple||d.open)&&d.select(d.items[d.activeIndex],!0);break;case d.KEY.ENTER:d.open?void 0!==d.items[d.activeIndex]&&d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case d.KEY.ESC:d.close();break;default:t=!1}return t}function p(){var e=t.querySelectorAll(".ui-select-choices-content"),n=e.querySelectorAll(".ui-select-choices-row");if(n.length<1)throw r("choices","Expected multiple .ui-select-choices-row but got '{0}'.",n.length);if(!(d.activeIndex<0)){var i=n[d.activeIndex],c=i.offsetTop+i.clientHeight-e[0].scrollTop,l=e[0].offsetHeight;c>l?e[0].scrollTop+=c-l:c=112&&123>=e},isVerticalMovement:function(e){return~[d.KEY.UP,d.KEY.DOWN].indexOf(e)},isHorizontalMovement:function(e){return~[d.KEY.LEFT,d.KEY.RIGHT,d.KEY.BACKSPACE,d.KEY.DELETE].indexOf(e)}},d.isEmpty=function(){return angular.isUndefined(d.selected)||null===d.selected||""===d.selected},d.findGroupByName=function(e){return d.groups&&d.groups.filter(function(t){return t.name===e})[0]},d.activate=function(t,i){if(d.disabled||d.open)d.open&&!d.searchEnabled&&d.close();else{var c=function(){i||o(),e.$broadcast("uis:activate"),d.open=!0,d.searchEnabled||angular.element(d.searchInput[0]).addClass("ui-select-offscreen"),d.activeIndex=d.activeIndex>=d.items.length?0:d.activeIndex,n(function(){d.search=t||d.search,d.searchInput[0].focus()})},l=d.beforeDropdownOpen();angular.isFunction(l.then)?l.then(function(e){e===!0&&c()}):l===!0&&c()}},d.parseRepeatAttr=function(t,n,i){function c(t){var c=e.$eval(n);if(d.groups=[],angular.forEach(t,function(e){var t=angular.isFunction(c)?c(e):e[c],n=d.findGroupByName(t);n?n.items.push(e):d.groups.push({name:t,items:[e]})}),i){var l=e.$eval(i);angular.isFunction(l)?d.groups=l(d.groups):angular.isArray(l)&&(d.groups=a(d.groups,l))}d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function s(e){d.items=e}d.setItemsFn=n?c:s,d.parserResult=l.parse(t),d.isGrouped=!!n,d.itemProperty=d.parserResult.itemName,d.refreshItems=function(t){t=t||d.parserResult.source(e);var n=d.selected;if(d.isEmpty()||angular.isArray(n)&&!n.length||!d.removeSelected)d.setItemsFn(t);else if(void 0!==t){var i=t.filter(function(e){return n.indexOf(e)<0});d.setItemsFn(i)}},e.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw r("items","Expected an array but got '{0}'.",e);d.refreshItems(e),d.ngModel.$modelValue=null}})},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){if(!d.open)return!1;var t=d.items.indexOf(e[d.itemProperty]),n=-1===t?!1:t===d.activeIndex;return n},d.isDisabled=function(e){if(!d.open)return!1;var t,n=d.items.indexOf(e[d.itemProperty]),i=!1;return n>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[n],i=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i},d.select=function(t,i,c){function l(){e.$broadcast("uis:select",t),n(function(){d.afterSelect(t)}),d.closeOnSelect&&d.close(i),c&&"click"===c.type&&(d.clickTriggeredSelect=!0)}if((void 0===t||!t._uiSelectChoiceDisabled)&&(d.items||d.search)){var r=d.beforeSelect(t);angular.isFunction(r.then)?r.then(function(e){e&&(e===!0?l(t):e&&l(e))}):r===!0?l(t):r&&l(r)}},d.close=function(t){function n(){d.ngModel&&d.ngModel.$setTouched&&d.ngModel.$setTouched(),o(),d.open=!1,d.searchEnabled||angular.element(d.searchInput[0]).removeClass("ui-select-offscreen"),e.$broadcast("uis:close",t)}if(d.open){var i=d.beforeDropdownClose();angular.isFunction(i.then)?i.then(function(e){e===!0&&n()}):i===!0&&n()}},d.setFocus=function(){d.focus||d.focusInput[0].focus()},d.clear=function(e){d.select(void 0),e.stopPropagation(),n(function(){d.focusser[0].focus()},0,!1)},d.toggle=function(e){d.open?(d.close(),e.preventDefault(),e.stopPropagation()):d.activate()},d.isLocked=function(e,t){var n,i=d.selected[t];return i&&!angular.isUndefined(d.lockChoiceExpression)&&(n=!!e.$eval(d.lockChoiceExpression),i._uiSelectChoiceLocked=n),n};var f=null;d.sizeSearchInput=function(){var t=d.searchInput[0],i=d.searchInput.parent().parent()[0],c=function(){return i.clientWidth*!!t.offsetParent},l=function(e){if(0===e)return!1;var n=e-t.offsetLeft-d.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=e),d.searchInput.css("width",n+"px"),!0};d.searchInput.css("width","10px"),n(function(){null!==f||l(c())||(f=e.$watch(c,function(e){l(e)&&(f(),f=null)}))})},d.searchInput.on("keydown",function(t){var n=t.which;~[d.KEY.ESC,d.KEY.TAB].indexOf(n)&&d.close(),e.$apply(function(){u(n)}),d.KEY.isVerticalMovement(n)&&d.items.length>0&&p(),(n===d.KEY.ENTER||n===d.KEY.ESC)&&(t.preventDefault(),t.stopPropagation())}),d.searchInput.on("keyup",function(e){e.which===d.KEY.TAB||d.KEY.isControl(e)||d.KEY.isFunctionKey(e)||e.which===d.KEY.ESC||d.KEY.isVerticalMovement(e.which)||d.afterKeypress(e)}),e.$on("$destroy",function(){d.searchInput.off("keyup keydown blur paste")}),d.afterKeypress=function(){},d.beforeSelect=function(){return!0},d.afterSelect=function(){},d.beforeRemove=function(){return!0},d.afterRemove=function(){},d.beforeDropdownOpen=function(){return!0},d.beforeDropdownClose=function(){return!0}}]),t.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,i,c,l,r,s){return{restrict:"EA",templateUrl:function(e,t){var i=t.theme||n.theme;return i+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(l,o){return angular.isDefined(o.multiple)?l.append("").removeAttr("multiple"):l.append(""),function(l,o,a,u,p){function d(e){if(g.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(o[0],e.target):o[0].contains(e.target),!t&&!g.clickTriggeredSelect){var n=["input","button","textarea"],i=angular.element(e.target).controller("uiSelect"),c=i&&i!==g;c||(c=~n.indexOf(e.target.tagName.toLowerCase())),g.close(c),l.$digest()}g.clickTriggeredSelect=!1}}function h(){var t=c(o);b=angular.element('
    '),b[0].style.width=t.width+"px",b[0].style.height=t.height+"px",o.after(b),w=o[0].style.width,e.find("body").append(o),o[0].style.position="absolute",o[0].style.left=t.left+"px",o[0].style.top=t.top+"px",o[0].style.width=t.width+"px"}function f(){null!==b&&(b.replaceWith(o),b=null,o[0].style.position="",o[0].style.left="",o[0].style.top="",o[0].style.width=w)}var g=u[0],v=u[1];g.generatedId=n.generateId(),g.baseTitle=a.title||"Select box",g.focusserTitle=g.baseTitle+" focus",g.focusserId="focusser-"+g.generatedId,g.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?r(a.closeOnSelect)():n.closeOnSelect}(),g.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,g.ngModel=v,g.choiceGrouped=function(e){return g.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){g.focusInput.attr("tabindex",e),o.removeAttr("tabindex")});var m=l.$eval(a.searchEnabled);g.searchEnabled=void 0!==m?m:n.searchEnabled;var E=l.$eval(a.sortable);g.sortable=void 0!==E?E:n.sortable,a.$observe("disabled",function(){g.disabled=void 0!==a.disabled?a.disabled:!1}),angular.isDefined(a.autofocus)&&s(function(){g.setFocus()}),angular.isDefined(a.focusOn)&&l.$on(a.focusOn,function(){s(function(){g.setFocus()})}),e.on("click",d),l.$on("$destroy",function(){e.off("click",d)}),p(l,function(e){var t=angular.element("
    ").append(e),n=t.querySelectorAll(".ui-select-match");if(n.removeAttr("ui-select-match"),n.removeAttr("data-ui-select-match"),1!==n.length)throw i("transcluded","Expected 1 .ui-select-match but got '{0}'.",n.length);o.querySelectorAll(".ui-select-match").replaceWith(n);var c=t.querySelectorAll(".ui-select-choices");if(c.removeAttr("ui-select-choices"),c.removeAttr("data-ui-select-choices"),1!==c.length)throw i("transcluded","Expected 1 .ui-select-choices but got '{0}'.",c.length);o.querySelectorAll(".ui-select-choices").replaceWith(c)});var $=l.$eval(a.appendToBody);(void 0!==$?$:n.appendToBody)&&(l.$watch("$select.open",function(e){e?h():f()}),l.$on("$destroy",function(){f()}));var b=null,w="",x=null,S="direction-up";l.$watch("$select.open",function(n){if(n){if(x=angular.element(o).querySelectorAll(".ui-select-dropdown"),null===x)return;x[0].style.opacity=0,s(function(){var n=c(o),i=c(x);n.top+n.height+i.height>t.pageYOffset+e[0].documentElement.clientHeight&&o.addClass(S),x[0].style.opacity=1})}else{if(null===x)return;o.removeClass(S)}})}}}}]),t.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return n+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,i,c){function l(e){c.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}c.lockChoiceExpression=i.uiLockChoice,i.$observe("placeholder",function(t){c.placeholder=void 0!==t?t:e.placeholder}),i.$observe("allowClear",l),l(i.allowClear),c.multiple&&c.sizeSearchInput()}}}]),t.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,i=this,c=e.$select;e.$evalAsync(function(){n=e.ngModel}),i.activeMatchIndex=-1,i.updateModel=function(){n.$setViewValue(Date.now()),i.refreshComponent()},i.refreshComponent=function(){c.refreshItems(),c.sizeSearchInput()},i.removeChoice=function(e){function n(){c.selected.splice(e,1),i.activeMatchIndex=-1,c.sizeSearchInput(),t(function(){c.afterRemove(l)}),i.updateModel()}var l=c.selected[e];if(!l._uiSelectChoiceLocked){var r=c.beforeRemove(l);angular.isFunction(r.then)?r.then(function(e){e===!0&&n()}):r===!0&&n()}},i.getPlaceholder=function(){return c.selected&&c.selected.length?void 0:c.placeholder}}],controllerAs:"$selectMultiple",link:function(n,i,c,l){function r(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function s(e){function t(){switch(e){case o.KEY.LEFT:return~u.activeMatchIndex?p:l;case o.KEY.RIGHT:return~u.activeMatchIndex&&s!==l?a:(o.activate(),!1);case o.KEY.BACKSPACE:return~u.activeMatchIndex?(u.removeChoice(s),p):l;case o.KEY.DELETE:return~u.activeMatchIndex?(u.removeChoice(u.activeMatchIndex),s):!1}}var n=r(o.searchInput[0]),i=o.selected.length,c=0,l=i-1,s=u.activeMatchIndex,a=u.activeMatchIndex+1,p=u.activeMatchIndex-1,d=s;return n>0||o.search.length&&e==o.KEY.RIGHT?!1:(o.close(),d=t(),u.activeMatchIndex=o.selected.length&&d!==!1?Math.min(l,Math.max(c,d)):-1,!0)}var o=l[0],a=n.ngModel=l[1],u=n.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,a.$parsers.unshift(function(){for(var e,t={},i=[],c=o.selected.length-1;c>=0;c--)t={},t[o.parserResult.itemName]=o.selected[c],e=o.parserResult.modelMapper(n,t),i.unshift(e);return i}),a.$formatters.unshift(function(e){var t,i=o.parserResult.source(n,{$select:{search:""}}),c={};if(!i)return e;var l=[],r=function(e,i){if(e&&e.length){for(var r=e.length-1;r>=0;r--){if(c[o.parserResult.itemName]=e[r],t=o.parserResult.modelMapper(n,c),o.parserResult.trackByExp){var s=/\.(.+)/.exec(o.parserResult.trackByExp);if(s.length>0&&t[s[1]]==i[s[1]])return l.unshift(e[r]),!0}if(angular.equals(t,i))return l.unshift(e[r]),!0}return!1}};if(!e)return l;for(var s=e.length-1;s>=0;s--)r(o.selected,e[s])||r(i,e[s])||l.unshift(e[s]);return l}),n.$watchCollection(function(){return a.$modelValue},function(e,t){t!=e&&(a.$modelValue=null,u.refreshComponent())}),a.$render=function(){if(!angular.isArray(a.$viewValue)){if(!angular.isUndefined(a.$viewValue)&&null!==a.$viewValue)throw e("multiarr","Expected model value to be array but got '{0}'",a.$viewValue);o.selected=[]}o.selected=a.$viewValue,n.$evalAsync()},n.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),u.updateModel())}),n.$on("uis:activate",function(){u.activeMatchIndex=-1}),n.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(e){var t=e.which;n.$apply(function(){var e=!1;o.KEY.isHorizontalMovement(t)&&(e=s(t)),e&&t!=o.KEY.TAB})}),o.searchInput.on("blur",function(){t(function(){u.activeMatchIndex=-1})})}}}]),t.directive("uiSelectSingle",["$timeout","$compile",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(n,i,c,l){var r=l[0],s=l[1];s.$parsers.unshift(function(e){var t,i={};return i[r.parserResult.itemName]=e,t=r.parserResult.modelMapper(n,i)}),s.$formatters.unshift(function(e){var t,i=r.parserResult.source(n,{$select:{search:""}}),c={};if(i){var l=function(i){return c[r.parserResult.itemName]=i,t=r.parserResult.modelMapper(n,c),t==e};if(r.selected&&l(r.selected))return r.selected;for(var s=i.length-1;s>=0;s--)if(l(i[s]))return i[s]}return e}),n.$watch("$select.selected",function(e){s.$viewValue!==e&&s.$setViewValue(e)}),s.$render=function(){r.selected=s.$viewValue},n.$on("uis:select",function(e,t){r.selected=t}),n.$on("uis:close",function(t,n){e(function(){r.focusser.prop("disabled",!1),n||r.focusser[0].focus()},0,!1)}),n.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");t(o)(n),r.focusser=o,r.focusInput=o,i.parent().append(o),o.bind("focus",function(){n.$evalAsync(function(){r.focus=!0})}),o.bind("blur",function(){n.$evalAsync(function(){r.focus=!1})}),o.bind("keydown",function(e){return e.which===r.KEY.BACKSPACE?(e.preventDefault(),e.stopPropagation(),r.select(void 0),n.$apply(),void 0):(e.which===r.KEY.TAB||r.KEY.isControl(e)||r.KEY.isFunctionKey(e)||e.which===r.KEY.ESC||((e.which==r.KEY.DOWN||e.which==r.KEY.UP||e.which==r.KEY.ENTER||e.which==r.KEY.SPACE)&&(e.preventDefault(),e.stopPropagation(),r.activate()),n.$digest()),void 0)}),o.bind("keyup input",function(e){e.which===r.KEY.TAB||r.KEY.isControl(e)||r.KEY.isFunctionKey(e)||e.which===r.KEY.ESC||e.which==r.KEY.ENTER||e.which===r.KEY.BACKSPACE||(r.activate(o.val()),o.val(""),n.$digest())})}}}]),t.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var i=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!i)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:i[2],source:t(i[3]),trackByExp:i[4],modelMapper:t(i[1]||i[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,i){var c=e+" in "+(i?"$group.items":t);return n&&(c+=" track by "+n),c}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",'
    {{$select.placeholder}}
    '),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",'')}]); \ No newline at end of file diff --git a/dist/select.css b/dist/select.css index 09cc8d2b6..fe2b1da3b 100644 --- a/dist/select.css +++ b/dist/select.css @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-11T18:41:59.534Z + * Version: 0.12.1 - 2015-07-28T03:50:59.080Z * License: MIT */ @@ -55,10 +55,6 @@ body > .select2-container.open { border-top-right-radius: 0; } .ui-select-container[theme="select2"].direction-up .ui-select-dropdown { - bottom: 100%; - top: auto; - position: absolute; - border-radius: 4px; /* FIXME hardcoded value :-/ */ border-bottom-left-radius: 0; border-bottom-right-radius: 0; @@ -101,10 +97,6 @@ body > .select2-container.open { /* Handle up direction Selectize */ .ui-select-container[theme="selectize"].direction-up .ui-select-dropdown { - bottom: 100%; - top: auto; - position: absolute; - box-shadow: 0 -4px 8px rgba(0, 0, 0, 0.25); margin-top: -2px; /* FIXME hardcoded value :-/ */ @@ -223,19 +215,6 @@ body > .ui-select-bootstrap.open { border-right: 1px solid #428bca; } -.ui-select-bootstrap .ui-select-placeholder { - color: #999; - opacity: 1; -} - -.ui-select-bootstrap .ui-select-placeholder { - color: #999; -} - -.ui-select-bootstrap .ui-select-placeholder { - color: #999; -} - .ui-select-bootstrap .ui-select-choices-row>a { display: block; padding: 3px 20px; @@ -279,9 +258,5 @@ body > .ui-select-bootstrap.open { /* Handle up direction Bootstrap */ .ui-select-container[theme="bootstrap"].direction-up .ui-select-dropdown { - bottom: 100%; - top: auto; - position: absolute; - box-shadow: 0 -4px 8px rgba(0, 0, 0, 0.25); } diff --git a/dist/select.js b/dist/select.js index 035b189a2..8ba040885 100644 --- a/dist/select.js +++ b/dist/select.js @@ -1,352 +1,62 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-11T18:41:59.532Z + * Version: 0.12.1 - 2015-07-28T03:50:59.076Z * License: MIT */ (function () { "use strict"; -// Make multiple matches sortable -angular.module('ui.select.sort', ['ui.select']) - .directive('uiSelectSort', - ['$timeout', 'uiSelectConfig', 'uiSelectMinErr', function ($timeout, uiSelectConfig, uiSelectMinErr) { - return { - require: '^uiSelect', - link: function (scope, element, attrs, $select) { - if (scope[attrs.uiSelectSort] === null) { - throw uiSelectMinErr('sort', "Expected a list to sort"); - } - - var options = angular.extend({ - axis: 'horizontal' - }, - scope.$eval(attrs.uiSelectSortOptions)); - - var axis = options.axis, - draggingClassName = 'dragging', - droppingClassName = 'dropping', - droppingBeforeClassName = 'dropping-before', - droppingAfterClassName = 'dropping-after'; - - scope.$watch(function () { - return $select.sortable; - }, function (n) { - if (n) { - element.attr('draggable', true); - } else { - element.removeAttr('draggable'); - } - }); - - element.on('dragstart', function (e) { - element.addClass(draggingClassName); - - (e.dataTransfer || e.originalEvent.dataTransfer).setData('text/plain', scope.$index); - }); - - element.on('dragend', function () { - element.removeClass(draggingClassName); - }); - - var move = function (from, to) { - /*jshint validthis: true */ - this.splice(to, 0, this.splice(from, 1)[0]); - }; - - var dragOverHandler = function (e) { - e.preventDefault(); - - var offset = axis === 'vertical' ? - e.offsetY || e.layerY || (e.originalEvent ? e.originalEvent.offsetY : 0) : - e.offsetX || e.layerX || (e.originalEvent ? e.originalEvent.offsetX : 0); - - if (offset < (this[axis === 'vertical' ? 'offsetHeight' : 'offsetWidth'] / 2)) { - element.removeClass(droppingAfterClassName); - element.addClass(droppingBeforeClassName); - - } else { - element.removeClass(droppingBeforeClassName); - element.addClass(droppingAfterClassName); - } - }; - - var dropTimeout; - - var dropHandler = function (e) { - e.preventDefault(); - - var droppedItemIndex = parseInt((e.dataTransfer || - e.originalEvent.dataTransfer).getData('text/plain'), 10); - - // prevent event firing multiple times in firefox - $timeout.cancel(dropTimeout); - dropTimeout = $timeout(function () { - _dropHandler(droppedItemIndex); - }, 20); - }; - - var _dropHandler = function (droppedItemIndex) { - var theList = scope.$eval(attrs.uiSelectSort), - itemToMove = theList[droppedItemIndex], - newIndex = null; - - if (element.hasClass(droppingBeforeClassName)) { - if (droppedItemIndex < scope.$index) { - newIndex = scope.$index - 1; - } else { - newIndex = scope.$index; - } - } else { - if (droppedItemIndex < scope.$index) { - newIndex = scope.$index; - } else { - newIndex = scope.$index + 1; - } - } - - move.apply(theList, [droppedItemIndex, newIndex]); - - scope.$apply(function () { - scope.$emit('uiSelectSort:change', { - array: theList, - item: itemToMove, - from: droppedItemIndex, - to: newIndex - }); - }); - - element.removeClass(droppingClassName); - element.removeClass(droppingBeforeClassName); - element.removeClass(droppingAfterClassName); - - element.off('drop', dropHandler); - }; - - element.on('dragenter', function () { - if (element.hasClass(draggingClassName)) { - return; - } - - element.addClass(droppingClassName); - - element.on('dragover', dragOverHandler); - element.on('drop', dropHandler); - }); - - element.on('dragleave', function (e) { - if (e.target != element) { - return; - } - element.removeClass(droppingClassName); - element.removeClass(droppingBeforeClassName); - element.removeClass(droppingAfterClassName); - - element.off('dragover', dragOverHandler); - element.off('drop', dropHandler); - }); - } - }; - }]); - -}()); -(function () { -"use strict"; -angular.module('ui.select.tagging', ['ui.select']) - .directive('uiSelectTagging', - ['$parse', '$timeout', function () { - return { - require: '^uiSelect', - link: function (scope, element, attrs, $select) { - var ctrl = $select; - ctrl.taggingLabel = attrs.taggingLabel !== undefined ? attrs.taggingLabel : false; - ctrl.taggingTokens = - attrs.taggingTokens !== undefined ? attrs.taggingTokens.split('|') : [',', 'ENTER']; - - // If tagging try to split by tokens and add items - ctrl.searchInput.on('paste', function (e) { - var data = e.clipboardData.getData('text/plain'); - if (data && data.length > 0) { - // Split by first token only - var items = data.split(ctrl.taggingTokens[0]); - if (items && items.length > 0) { - angular.forEach(items, function (item) { - if(item === null || item.length === 0) { - return; - } - var newItem = ctrl.beforeTagging(item); - if (newItem) { - ctrl.select(newItem, true); - } - }); - e.preventDefault(); - e.stopPropagation(); - } - } - }); - - // Define the default callback into the controller - ctrl.beforeTagging = function (item) { - return item; - }; - - - // Override the keypress callback - ctrl.afterKeypress = function (e) { - - -// if ( ! ctrl.KEY.isVerticalMovement(e.which) ) { -// scope.$evalAsync( function () { -// $select.activeIndex = $select.taggingLabel === false ? -1 : 0; -// }); -// } - - // Push a "create new" item into array if there is a search string - if ($select.search.length > 0) { - // Return early with these keys - if (e.which === ctrl.KEY.TAB || ctrl.KEY.isControl(e) || ctrl.KEY.isFunctionKey(e) || - e.which === ctrl.KEY.ESC || - ctrl.KEY.isVerticalMovement(e.which)) { - return; - } - - // Check for end of tagging - for (var i = 0; i < ctrl.taggingTokens.length; i++) { - if (ctrl.taggingTokens[i] === ctrl.KEY.MAP[e.keyCode]) { - // Make sure there is a new value to push via tagging - if (ctrl.search.length > 0) { - // Make sure that we don't leave the tagging character on the end of the item label - if ($select.search.substr($select.search.length - 1) == ctrl.KEY.MAP[e.keyCode]) { - $select.search = $select.search.substr(0, $select.search.length - 1); - } - - // Select this item and return - ctrl.select(ctrl.beforeTagging($select.search)); - return; - } - } - } - - $select.activeIndex = $select.taggingLabel === false ? -1 : 0; - // If taggingLabel === false bypasses all of this - if ($select.taggingLabel === false) { - return; - } - - var items = angular.copy($select.items); - var stashArr = angular.copy($select.items); - var newItem; - var item; - var hasTag = false; - var dupeIndex = -1; - var tagItems; - var tagItem; - - - // Find any tagging items already in the $select.items array and store them - tagItems = $select.$filter('filter')(items, function (item) { - return item.match($select.taggingLabel); - }); - if (tagItems.length > 0) { - tagItem = tagItems[0]; - } - item = items[0]; - // Remove existing tag item if found (should only ever be one tag item) - if (item !== undefined && items.length > 0 && tagItem) { - hasTag = true; - items = items.slice(1, items.length); - stashArr = stashArr.slice(1, stashArr.length); - } - newItem = $select.search + ' ' + $select.taggingLabel; - if (_findApproxDupe($select.selected, $select.search) > -1) { - return; - } - // Verify the the tag doesn't match the value of an existing item from - // the searched data set or the items already selected - if (_findCaseInsensitiveDupe(stashArr.concat($select.selected))) { - // if there is a tag from prev iteration, strip it / queue the change - // and return early - if (hasTag) { - items = stashArr; - scope.$evalAsync(function () { - $select.activeIndex = 0; - $select.items = items; - }); - } - return; - } - if (_findCaseInsensitiveDupe(stashArr)) { - // If there is a tag from prev iteration, strip it - if (hasTag) { - $select.items = stashArr.slice(1, stashArr.length); - } - return; - } - - if (hasTag) { - dupeIndex = _findApproxDupe($select.selected, newItem); - } - // dupe found, shave the first item - if (dupeIndex > -1) { - items = items.slice(dupeIndex + 1, items.length - 1); - } else { - items = []; - items.push(newItem); - items = items.concat(stashArr); - } - scope.$evalAsync(function () { - $select.activeIndex = 0; - $select.items = items; - }); - } - }; - - - function _findCaseInsensitiveDupe(arr) { - if (arr === undefined || $select.search === undefined) { - return false; - } - return arr.filter(function (origItem) { - if ($select.search.toUpperCase() === undefined || origItem === undefined) { - return false; - } - return origItem.toUpperCase() === $select.search.toUpperCase(); - }).length > 0; - } - - function _findApproxDupe(haystack, needle) { - var dupeIndex = -1; - if (angular.isArray(haystack)) { - var tempArr = angular.copy(haystack); - for (var i = 0; i < tempArr.length; i++) { - // handle the simple string version of tagging -// if ($select.tagging.fct === undefined) { - // search the array for the match - if (tempArr[i] + ' ' + $select.taggingLabel === needle) { - dupeIndex = i; - } - // handle the object tagging implementation - /* } else { - var mockObj = tempArr[i]; - mockObj.isTag = true; - if (angular.equals(mockObj, needle)) { - dupeIndex = i; - } - }*/ - } - } - return dupeIndex; - } +var KEY = { + TAB: 9, + ENTER: 13, + ESC: 27, + SPACE: 32, + LEFT: 37, + UP: 38, + RIGHT: 39, + DOWN: 40, + SHIFT: 16, + CTRL: 17, + ALT: 18, + PAGE_UP: 33, + PAGE_DOWN: 34, + HOME: 36, + END: 35, + BACKSPACE: 8, + DELETE: 46, + COMMAND: 91, + + MAP: { 91 : "COMMAND", 8 : "BACKSPACE" , 9 : "TAB" , 13 : "ENTER" , 16 : "SHIFT" , 17 : "CTRL" , 18 : "ALT" , 19 : "PAUSEBREAK" , 20 : "CAPSLOCK" , 27 : "ESC" , 32 : "SPACE" , 33 : "PAGE_UP", 34 : "PAGE_DOWN" , 35 : "END" , 36 : "HOME" , 37 : "LEFT" , 38 : "UP" , 39 : "RIGHT" , 40 : "DOWN" , 43 : "+" , 44 : "PRINTSCREEN" , 45 : "INSERT" , 46 : "DELETE", 48 : "0" , 49 : "1" , 50 : "2" , 51 : "3" , 52 : "4" , 53 : "5" , 54 : "6" , 55 : "7" , 56 : "8" , 57 : "9" , 59 : ";", 61 : "=" , 65 : "A" , 66 : "B" , 67 : "C" , 68 : "D" , 69 : "E" , 70 : "F" , 71 : "G" , 72 : "H" , 73 : "I" , 74 : "J" , 75 : "K" , 76 : "L", 77 : "M" , 78 : "N" , 79 : "O" , 80 : "P" , 81 : "Q" , 82 : "R" , 83 : "S" , 84 : "T" , 85 : "U" , 86 : "V" , 87 : "W" , 88 : "X" , 89 : "Y" , 90 : "Z", 96 : "0" , 97 : "1" , 98 : "2" , 99 : "3" , 100 : "4" , 101 : "5" , 102 : "6" , 103 : "7" , 104 : "8" , 105 : "9", 106 : "*" , 107 : "+" , 109 : "-" , 110 : "." , 111 : "/", 112 : "F1" , 113 : "F2" , 114 : "F3" , 115 : "F4" , 116 : "F5" , 117 : "F6" , 118 : "F7" , 119 : "F8" , 120 : "F9" , 121 : "F10" , 122 : "F11" , 123 : "F12", 144 : "NUMLOCK" , 145 : "SCROLLLOCK" , 186 : ";" , 187 : "=" , 188 : "," , 189 : "-" , 190 : "." , 191 : "/" , 192 : "`" , 219 : "[" , 220 : "\\" , 221 : "]" , 222 : "'" + }, + + isControl: function (e) { + var k = e.which; + switch (k) { + case KEY.COMMAND: + case KEY.SHIFT: + case KEY.CTRL: + case KEY.ALT: + return true; + } - } - }; - }]); + if (e.metaKey) return true; -}()); -(function () { -"use strict"; + return false; + }, + isFunctionKey: function (k) { + k = k.which ? k.which : k; + return k >= 112 && k <= 123; + }, + isVerticalMovement: function (k){ + return ~[KEY.UP, KEY.DOWN].indexOf(k); + }, + isHorizontalMovement: function (k){ + return ~[KEY.LEFT,KEY.RIGHT,KEY.BACKSPACE,KEY.DELETE].indexOf(k); + } + }; /** * Add querySelectorAll() to jqLite. @@ -358,178 +68,172 @@ angular.module('ui.select.tagging', ['ui.select']) * See feat(jqLite): use querySelectorAll instead of getElementsByTagName in jqLite.find https://github.com/angular/angular.js/pull/3598 */ if (angular.element.prototype.querySelectorAll === undefined) { - angular.element.prototype.querySelectorAll = function (selector) { - return angular.element(this[0].querySelectorAll(selector)); - }; + angular.element.prototype.querySelectorAll = function(selector) { + return angular.element(this[0].querySelectorAll(selector)); + }; } /** * Add closest() to jqLite. */ if (angular.element.prototype.closest === undefined) { - angular.element.prototype.closest = function (selector) { - var elem = this[0]; - var matchesSelector = elem.matches || elem.webkitMatchesSelector || elem.mozMatchesSelector || - elem.msMatchesSelector; - - while (elem) { - if (matchesSelector.bind(elem)(selector)) { - return elem; - } else { - elem = elem.parentElement; - } - } - return false; - }; + angular.element.prototype.closest = function( selector) { + var elem = this[0]; + var matchesSelector = elem.matches || elem.webkitMatchesSelector || elem.mozMatchesSelector || elem.msMatchesSelector; + + while (elem) { + if (matchesSelector.bind(elem)(selector)) { + return elem; + } else { + elem = elem.parentElement; + } + } + return false; + }; } var latestId = 0; var uis = angular.module('ui.select', []) - .constant('uiSelectConfig', { - theme: 'bootstrap', - searchEnabled: true, - sortable: false, - placeholder: '', // Empty by default, like HTML tag + refreshDelay: 1000, // In milliseconds + closeOnSelect: true, + generateId: function() { + return latestId++; + }, + appendToBody: false +}) + +// See Rename minErr and make it accessible from outside https://github.com/angular/angular.js/issues/6913 +.service('uiSelectMinErr', function() { + var minErr = angular.$$minErr('ui.select'); + return function() { + var error = minErr.apply(this, arguments); + var message = error.message.replace(new RegExp('\nhttp://errors.angularjs.org/.*'), ''); + return new Error(message); + }; +}) + +// Recreates old behavior of ng-transclude. Used internally. +.directive('uisTranscludeAppend', function () { + return { + link: function (scope, element, attrs, ctrl, transclude) { + transclude(scope, function (clone) { + element.append(clone); + }); + } + }; +}) - return function (matchItem, query) { - matchItem = String(matchItem); - return query && matchItem ? matchItem.replace(new RegExp(escapeRegexp(query), 'gi'), - '$&') : matchItem; - }; - }) - - /** - * A read-only equivalent of jQuery's offset function: http://api.jquery.com/offset/ - * - * Taken from AngularUI Bootstrap Position: - * See https://github.com/angular-ui/bootstrap/blob/master/src/position/position.js#L70 - */ - .factory('uisOffset', - ['$document', '$window', - function ($document, $window) { - - return function (element) { - var boundingClientRect = element[0].getBoundingClientRect(); - return { - width: boundingClientRect.width || element.prop('offsetWidth'), - height: boundingClientRect.height || element.prop('offsetHeight'), - top: boundingClientRect.top + ($window.pageYOffset || $document[0].documentElement.scrollTop), - left: boundingClientRect.left + ($window.pageXOffset || $document[0].documentElement.scrollLeft) - }; - }; - }]); +/** + * Highlights text that matches $select.search. + * + * Taken from AngularUI Bootstrap Typeahead + * See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L340 + */ +.filter('highlight', function() { + function escapeRegexp(queryToEscape) { + return queryToEscape.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1'); + } + + return function(matchItem, query) { + return query && matchItem ? matchItem.replace(new RegExp(escapeRegexp(query), 'gi'), '$&') : matchItem; + }; +}) + +/** + * A read-only equivalent of jQuery's offset function: http://api.jquery.com/offset/ + * + * Taken from AngularUI Bootstrap Position: + * See https://github.com/angular-ui/bootstrap/blob/master/src/position/position.js#L70 + */ +.factory('uisOffset', + ['$document', '$window', + function ($document, $window) { + + return function(element) { + var boundingClientRect = element[0].getBoundingClientRect(); + return { + width: boundingClientRect.width || element.prop('offsetWidth'), + height: boundingClientRect.height || element.prop('offsetHeight'), + top: boundingClientRect.top + ($window.pageYOffset || $document[0].documentElement.scrollTop), + left: boundingClientRect.left + ($window.pageXOffset || $document[0].documentElement.scrollLeft) + }; + }; +}]); uis.directive('uiSelectChoices', - ['uiSelectConfig', 'uisRepeatParser', 'uiSelectMinErr', '$compile', - function (uiSelectConfig, RepeatParser, uiSelectMinErr, $compile) { - - return { - restrict: 'EA', - require: '^uiSelect', - replace: true, - transclude: true, - templateUrl: function (tElement) { - // Gets theme attribute from parent (ui-select) - var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; - return theme + '/choices.tpl.html'; - }, - - compile: function (tElement, tAttrs) { - - if (!tAttrs.repeat) { - throw uiSelectMinErr('repeat', "Expected 'repeat' expression."); - } - - return function link(scope, element, attrs, $select, transcludeFn) { - - // var repeat = RepeatParser.parse(attrs.repeat); - var groupByExp = attrs.groupBy; - var groupFilterExp = attrs.groupFilter; - - $select.parseRepeatAttr(attrs.repeat, groupByExp, groupFilterExp); //Result ready at $select.parserResult - - $select.disableChoiceExpression = attrs.uiDisableChoice; - $select.onHighlightCallback = attrs.onHighlight; - - if (groupByExp) { - var groups = element.querySelectorAll('.ui-select-choices-group'); - if (groups.length !== 1) throw uiSelectMinErr('rows', - "Expected 1 .ui-select-choices-group but got '{0}'.", groups.length); - groups.attr('ng-repeat', RepeatParser.getGroupNgRepeatExpression()); - } - - var choices = element.querySelectorAll('.ui-select-choices-row'); - if (choices.length !== 1) { - throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row but got '{0}'.", - choices.length); - } - - choices.attr('ng-repeat', - RepeatParser.getNgRepeatExpression($select.parserResult.itemName, '$select.items', - $select.parserResult.trackByExp, groupByExp)) - .attr('ng-if', '$select.open') // Prevent unnecessary watches when dropdown is closed - .attr('ng-mouseenter', '$select.setActiveItem(' + $select.parserResult.itemName + ')') - .attr('ng-click', '$select.select(' + $select.parserResult.itemName + ',false,$event)'); - - var rowsInner = element.querySelectorAll('.ui-select-choices-row-inner'); - if (rowsInner.length !== 1) { - throw uiSelectMinErr('rows', - "Expected 1 .ui-select-choices-row-inner but got '{0}'.", rowsInner.length); - } - rowsInner.attr('uis-transclude-append', ''); //Adding uisTranscludeAppend directive to row element after choices element has ngRepeat - - $compile(element, transcludeFn)(scope); //Passing current transcludeFn to be able to append elements correctly from uisTranscludeAppend - - scope.$watch('$select.search', function (newValue) { - if (newValue && !$select.open && $select.multiple) { - $select.activate(false, true); - } - $select.activeIndex = 0; - }); - }; - } - }; - }]); + ['uiSelectConfig', 'uisRepeatParser', 'uiSelectMinErr', '$compile', + function(uiSelectConfig, RepeatParser, uiSelectMinErr, $compile) { + + return { + restrict: 'EA', + require: '^uiSelect', + replace: true, + transclude: true, + templateUrl: function(tElement) { + // Gets theme attribute from parent (ui-select) + var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; + return theme + '/choices.tpl.html'; + }, + + compile: function(tElement, tAttrs) { + + if (!tAttrs.repeat) throw uiSelectMinErr('repeat', "Expected 'repeat' expression."); + + return function link(scope, element, attrs, $select, transcludeFn) { + + // var repeat = RepeatParser.parse(attrs.repeat); + var groupByExp = attrs.groupBy; + var groupFilterExp = attrs.groupFilter; + + $select.parseRepeatAttr(attrs.repeat, groupByExp, groupFilterExp); //Result ready at $select.parserResult + + $select.disableChoiceExpression = attrs.uiDisableChoice; + $select.onHighlightCallback = attrs.onHighlight; + + if(groupByExp) { + var groups = element.querySelectorAll('.ui-select-choices-group'); + if (groups.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-group but got '{0}'.", groups.length); + groups.attr('ng-repeat', RepeatParser.getGroupNgRepeatExpression()); + } + + var choices = element.querySelectorAll('.ui-select-choices-row'); + if (choices.length !== 1) { + throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row but got '{0}'.", choices.length); + } + + choices.attr('ng-repeat', RepeatParser.getNgRepeatExpression($select.parserResult.itemName, '$select.items', $select.parserResult.trackByExp, groupByExp)) + .attr('ng-if', '$select.open') //Prevent unnecessary watches when dropdown is closed + .attr('ng-mouseenter', '$select.setActiveItem('+$select.parserResult.itemName +')') + .attr('ng-click', '$select.select(' + $select.parserResult.itemName + ',false,$event)'); + + var rowsInner = element.querySelectorAll('.ui-select-choices-row-inner'); + if (rowsInner.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row-inner but got '{0}'.", rowsInner.length); + rowsInner.attr('uis-transclude-append', ''); //Adding uisTranscludeAppend directive to row element after choices element has ngRepeat + + $compile(element, transcludeFn)(scope); //Passing current transcludeFn to be able to append elements correctly from uisTranscludeAppend + + scope.$watch('$select.search', function(newValue) { + if(newValue && !$select.open && $select.multiple) $select.activate(false, true); + $select.activeIndex = $select.tagging.isActivated ? -1 : 0; + $select.refresh(attrs.refresh); + }); + + attrs.$observe('refreshDelay', function() { + // $eval() is needed otherwise we get a string instead of a number + var refreshDelay = scope.$eval(attrs.refreshDelay); + $select.refreshDelay = refreshDelay !== undefined ? refreshDelay : uiSelectConfig.refreshDelay; + }); + }; + } + }; +}]); /** * Contains ui-select "intelligence". @@ -538,1518 +242,1513 @@ uis.directive('uiSelectChoices', * put as much logic in the controller (instead of the link functions) as possible so it can be easily tested. */ uis.controller('uiSelectCtrl', - ['$scope', '$element', '$timeout', '$filter', '$q', 'uisRepeatParser', 'uiSelectMinErr', 'uiSelectConfig', - function ($scope, $element, $timeout, $filter, $q, RepeatParser, uiSelectMinErr, uiSelectConfig) { - var ctrl = this; - - var EMPTY_SEARCH = ''; - - ctrl.placeholder = uiSelectConfig.placeholder; - ctrl.searchEnabled = uiSelectConfig.searchEnabled; - ctrl.sortable = uiSelectConfig.sortable; - - ctrl.removeSelected = false; // If selected item(s) should be removed from dropdown list - ctrl.closeOnSelect = true; // Initialized inside uiSelect directive link function - ctrl.search = EMPTY_SEARCH; - - ctrl.activeIndex = 0; // Dropdown of choices - ctrl.items = []; // All available choices - - ctrl.open = false; - ctrl.focus = false; - ctrl.disabled = false; - ctrl.selected = undefined; - - ctrl.focusser = undefined; // Reference to input element used to handle focus events - ctrl.resetSearchInput = true; - ctrl.multiple = undefined; // Initialized inside uiSelect directive link function - ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelectChoices directive link function - ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelectMatch directive link function - ctrl.clickTriggeredSelect = false; - ctrl.$filter = $filter; - - ctrl.searchInput = $element.querySelectorAll('input.ui-select-search'); - if (ctrl.searchInput.length !== 1) { - throw uiSelectMinErr('searchInput', "Expected 1 input.ui-select-search but got '{0}'.", - ctrl.searchInput.length); - } + ['$scope', '$element', '$timeout', '$filter', 'uisRepeatParser', 'uiSelectMinErr', 'uiSelectConfig', + function($scope, $element, $timeout, $filter, RepeatParser, uiSelectMinErr, uiSelectConfig) { + + var ctrl = this; + + var EMPTY_SEARCH = ''; + + ctrl.placeholder = uiSelectConfig.placeholder; + ctrl.searchEnabled = uiSelectConfig.searchEnabled; + ctrl.sortable = uiSelectConfig.sortable; + ctrl.refreshDelay = uiSelectConfig.refreshDelay; + + ctrl.removeSelected = false; //If selected item(s) should be removed from dropdown list + ctrl.closeOnSelect = true; //Initialized inside uiSelect directive link function + ctrl.search = EMPTY_SEARCH; + + ctrl.activeIndex = 0; //Dropdown of choices + ctrl.items = []; //All available choices + + ctrl.open = false; + ctrl.focus = false; + ctrl.disabled = false; + ctrl.selected = undefined; + + ctrl.focusser = undefined; //Reference to input element used to handle focus events + ctrl.resetSearchInput = true; + ctrl.multiple = undefined; // Initialized inside uiSelect directive link function + ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelectChoices directive link function + ctrl.tagging = {isActivated: false, fct: undefined}; + ctrl.taggingTokens = {isActivated: false, tokens: undefined}; + ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelectMatch directive link function + ctrl.clickTriggeredSelect = false; + ctrl.$filter = $filter; + + ctrl.searchInput = $element.querySelectorAll('input.ui-select-search'); + if (ctrl.searchInput.length !== 1) { + throw uiSelectMinErr('searchInput', "Expected 1 input.ui-select-search but got '{0}'.", ctrl.searchInput.length); + } + + ctrl.isEmpty = function() { + return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === ''; + }; + + // Most of the time the user does not want to empty the search input when in typeahead mode + function _resetSearchInput() { + if (ctrl.resetSearchInput || (ctrl.resetSearchInput === undefined && uiSelectConfig.resetSearchInput)) { + ctrl.search = EMPTY_SEARCH; + //reset activeIndex + if (ctrl.selected && ctrl.items.length && !ctrl.multiple) { + ctrl.activeIndex = ctrl.items.indexOf(ctrl.selected); + } + } + } + + function _groupsFilter(groups, groupNames) { + var i, j, result = []; + for(i = 0; i < groupNames.length ;i++){ + for(j = 0; j < groups.length ;j++){ + if(groups[j].name == [groupNames[i]]){ + result.push(groups[j]); + } + } + } + return result; + } + + // When the user clicks on ui-select, displays the dropdown list + ctrl.activate = function(initSearchValue, avoidReset) { + if (!ctrl.disabled && !ctrl.open) { + if(!avoidReset) _resetSearchInput(); + + $scope.$broadcast('uis:activate'); + + ctrl.open = true; + + ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex; + + // ensure that the index is set to zero for tagging variants + // that where first option is auto-selected + if ( ctrl.activeIndex === -1 && ctrl.taggingLabel !== false ) { + ctrl.activeIndex = 0; + } + + // Give it time to appear before focus + $timeout(function() { + ctrl.search = initSearchValue || ctrl.search; + ctrl.searchInput[0].focus(); + }); + } + }; + + ctrl.findGroupByName = function(name) { + return ctrl.groups && ctrl.groups.filter(function(group) { + return group.name === name; + })[0]; + }; + + ctrl.parseRepeatAttr = function(repeatAttr, groupByExp, groupFilterExp) { + function updateGroups(items) { + var groupFn = $scope.$eval(groupByExp); + ctrl.groups = []; + angular.forEach(items, function(item) { + var groupName = angular.isFunction(groupFn) ? groupFn(item) : item[groupFn]; + var group = ctrl.findGroupByName(groupName); + if(group) { + group.items.push(item); + } + else { + ctrl.groups.push({name: groupName, items: [item]}); + } + }); + if(groupFilterExp){ + var groupFilterFn = $scope.$eval(groupFilterExp); + if( angular.isFunction(groupFilterFn)){ + ctrl.groups = groupFilterFn(ctrl.groups); + } else if(angular.isArray(groupFilterFn)){ + ctrl.groups = _groupsFilter(ctrl.groups, groupFilterFn); + } + } + ctrl.items = []; + ctrl.groups.forEach(function(group) { + ctrl.items = ctrl.items.concat(group.items); + }); + } + + function setPlainItems(items) { + ctrl.items = items; + } + + ctrl.setItemsFn = groupByExp ? updateGroups : setPlainItems; + + ctrl.parserResult = RepeatParser.parse(repeatAttr); + + ctrl.isGrouped = !!groupByExp; + ctrl.itemProperty = ctrl.parserResult.itemName; + + ctrl.refreshItems = function (data){ + data = data || ctrl.parserResult.source($scope); + var selectedItems = ctrl.selected; + //TODO should implement for single mode removeSelected + if ((angular.isArray(selectedItems) && !selectedItems.length) || !ctrl.removeSelected) { + ctrl.setItemsFn(data); + }else{ + if ( data !== undefined ) { + var filteredItems = data.filter(function(i) {return selectedItems.indexOf(i) < 0;}); + ctrl.setItemsFn(filteredItems); + } + } + }; - // TODO: Maybe make these methods in KEY directly in the controller? - ctrl.KEY = { - TAB: 9, - ENTER: 13, - ESC: 27, - SPACE: 32, - LEFT: 37, - UP: 38, - RIGHT: 39, - DOWN: 40, - SHIFT: 16, - CTRL: 17, - ALT: 18, - PAGE_UP: 33, - PAGE_DOWN: 34, - HOME: 36, - END: 35, - BACKSPACE: 8, - DELETE: 46, - COMMAND: 91, - MAP: { - 91: "COMMAND", - 8: "BACKSPACE", - 9: "TAB", - 13: "ENTER", - 16: "SHIFT", - 17: "CTRL", - 18: "ALT", - 19: "PAUSEBREAK", - 20: "CAPSLOCK", - 27: "ESC", - 32: "SPACE", - 33: "PAGE_UP", - 34: "PAGE_DOWN", - 35: "END", - 36: "HOME", - 37: "LEFT", - 38: "UP", - 39: "RIGHT", - 40: "DOWN", - 43: "+", - 44: "PRINTSCREEN", - 45: "INSERT", - 46: "DELETE", - 48: "0", - 49: "1", - 50: "2", - 51: "3", - 52: "4", - 53: "5", - 54: "6", - 55: "7", - 56: "8", - 57: "9", - 59: ";", - 61: "=", - 65: "A", - 66: "B", - 67: "C", - 68: "D", - 69: "E", - 70: "F", - 71: "G", - 72: "H", - 73: "I", - 74: "J", - 75: "K", - 76: "L", - 77: "M", - 78: "N", - 79: "O", - 80: "P", - 81: "Q", - 82: "R", - 83: "S", - 84: "T", - 85: "U", - 86: "V", - 87: "W", - 88: "X", - 89: "Y", - 90: "Z", - 96: "0", - 97: "1", - 98: "2", - 99: "3", - 100: "4", - 101: "5", - 102: "6", - 103: "7", - 104: "8", - 105: "9", - 106: "*", - 107: "+", - 109: "-", - 110: ".", - 111: "/", - 112: "F1", - 113: "F2", - 114: "F3", - 115: "F4", - 116: "F5", - 117: "F6", - 118: "F7", - 119: "F8", - 120: "F9", - 121: "F10", - 122: "F11", - 123: "F12", - 144: "NUMLOCK", - 145: "SCROLLLOCK", - 186: ";", - 187: "=", - 188: ",", - 189: "-", - 190: ".", - 191: "/", - 192: "`", - 219: "[", - 220: "\\", - 221: "]", - 222: "'" - }, - - isControl: function (e) { - var k = e.which; - switch (k) { - case ctrl.KEY.COMMAND: - case ctrl.KEY.SHIFT: - case ctrl.KEY.CTRL: - case ctrl.KEY.ALT: - return true; - } - - if (e.metaKey) { - return true; - } - - return false; - }, - isFunctionKey: function (k) { - k = k.which ? k.which : k; - return k >= 112 && k <= 123; - }, - isVerticalMovement: function (k) { - return ~[ctrl.KEY.UP, ctrl.KEY.DOWN].indexOf(k); - }, - isHorizontalMovement: function (k) { - return ~[ctrl.KEY.LEFT, ctrl.KEY.RIGHT, ctrl.KEY.BACKSPACE, ctrl.KEY.DELETE].indexOf(k); - } - }; - - /** - * Returns true if the selection is empty - * @returns {boolean|*} - */ - ctrl.isEmpty = function () { - return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === ''; - }; - - // Most of the time the user does not want to empty the search input when in typeahead mode - function _resetSearchInput() { - if (ctrl.resetSearchInput || (ctrl.resetSearchInput === undefined && uiSelectConfig.resetSearchInput)) { - ctrl.search = EMPTY_SEARCH; - // Reset activeIndex - if (ctrl.selected && ctrl.items.length && !ctrl.multiple) { - ctrl.activeIndex = ctrl.items.indexOf(ctrl.selected); - } - } + // See https://github.com/angular/angular.js/blob/v1.2.15/src/ng/directive/ngRepeat.js#L259 + $scope.$watchCollection(ctrl.parserResult.source, function(items) { + if (items === undefined || items === null) { + // If the user specifies undefined or null => reset the collection + // Special case: items can be undefined if the user did not initialized the collection on the scope + // i.e $scope.addresses = [] is missing + ctrl.items = []; + } else { + if (!angular.isArray(items)) { + throw uiSelectMinErr('items', "Expected an array but got '{0}'.", items); + } else { + //Remove already selected items (ex: while searching) + //TODO Should add a test + ctrl.refreshItems(items); + ctrl.ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters + } + } + }); + + }; + + var _refreshDelayPromise; + + /** + * Typeahead mode: lets the user refresh the collection using his own function. + * + * See Expose $select.search for external / remote filtering https://github.com/angular-ui/ui-select/pull/31 + */ + ctrl.refresh = function(refreshAttr) { + if (refreshAttr !== undefined) { + + // Debounce + // See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L155 + // FYI AngularStrap typeahead does not have debouncing: https://github.com/mgcrea/angular-strap/blob/v2.0.0-rc.4/src/typeahead/typeahead.js#L177 + if (_refreshDelayPromise) { + $timeout.cancel(_refreshDelayPromise); + } + _refreshDelayPromise = $timeout(function() { + $scope.$eval(refreshAttr); + }, ctrl.refreshDelay); + } + }; + + ctrl.setActiveItem = function(item) { + ctrl.activeIndex = ctrl.items.indexOf(item); + }; + + ctrl.isActive = function(itemScope) { + if ( !ctrl.open ) { + return false; + } + var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); + var isActive = itemIndex === ctrl.activeIndex; + + if ( !isActive || ( itemIndex < 0 && ctrl.taggingLabel !== false ) ||( itemIndex < 0 && ctrl.taggingLabel === false) ) { + return false; + } + + if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { + itemScope.$eval(ctrl.onHighlightCallback); + } + + return isActive; + }; + + ctrl.isDisabled = function(itemScope) { + + if (!ctrl.open) return; + + var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); + var isDisabled = false; + var item; + + if (itemIndex >= 0 && !angular.isUndefined(ctrl.disableChoiceExpression)) { + item = ctrl.items[itemIndex]; + isDisabled = !!(itemScope.$eval(ctrl.disableChoiceExpression)); // force the boolean value + item._uiSelectChoiceDisabled = isDisabled; // store this for later reference + } + + return isDisabled; + }; + + + // When the user selects an item with ENTER or clicks the dropdown + ctrl.select = function(item, skipFocusser, $event) { + if (item === undefined || !item._uiSelectChoiceDisabled) { + + if ( ! ctrl.items && ! ctrl.search ) return; + + if (!item || !item._uiSelectChoiceDisabled) { + if(ctrl.tagging.isActivated) { + // if taggingLabel is disabled, we pull from ctrl.search val + if ( ctrl.taggingLabel === false ) { + if ( ctrl.activeIndex < 0 ) { + item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : ctrl.search; + if (!item || angular.equals( ctrl.items[0], item ) ) { + return; + } + } else { + // keyboard nav happened first, user selected from dropdown + item = ctrl.items[ctrl.activeIndex]; } - - ctrl.findGroupByName = function (name) { - return ctrl.groups && ctrl.groups.filter(function (group) { - return group.name === name; - })[0]; - }; - - function _groupsFilter(groups, groupNames) { - var i, j, result = []; - for (i = 0; i < groupNames.length; i++) { - for (j = 0; j < groups.length; j++) { - if (groups[j].name == [groupNames[i]]) { - result.push(groups[j]); - } - } - } - return result; + } else { + // tagging always operates at index zero, taggingLabel === false pushes + // the ctrl.search value without having it injected + if ( ctrl.activeIndex === 0 ) { + // ctrl.tagging pushes items to ctrl.items, so we only have empty val + // for `item` if it is a detected duplicate + if ( item === undefined ) return; + + // create new item on the fly if we don't already have one; + // use tagging function if we have one + if ( ctrl.tagging.fct !== undefined && typeof item === 'string' ) { + item = ctrl.tagging.fct(ctrl.search); + if (!item) return; + // if item type is 'string', apply the tagging label + } else if ( typeof item === 'string' ) { + // trim the trailing space + item = item.replace(ctrl.taggingLabel,'').trim(); + } } + } + // search ctrl.selected for dupes potentially caused by tagging and return early if found + if ( ctrl.selected && angular.isArray(ctrl.selected) && ctrl.selected.filter( function (selection) { return angular.equals(selection, item); }).length > 0 ) { + ctrl.close(skipFocusser); + return; + } + } - /** - * Activates the control. - * When the user clicks on ui-select, displays the dropdown list - * Also called following keyboard input to the search box - */ - ctrl.activate = function (initSearchValue, avoidReset) { - if (!ctrl.disabled && !ctrl.open) { - var completeCallback = function () { - if (!avoidReset) { - _resetSearchInput(); - } - - $scope.$broadcast('uis:activate'); - - ctrl.open = true; - if (!ctrl.searchEnabled) { - angular.element(ctrl.searchInput[0]).addClass('ui-select-offscreen'); - } - - ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex; - - // Give it time to appear before focus - $timeout(function () { - ctrl.search = initSearchValue || ctrl.search; - ctrl.searchInput[0].focus(); - }); - }; - - var result = ctrl.beforeDropdownOpen(); - if (angular.isFunction(result.then)) { - // Promise returned - wait for it to complete before completing the selection - result.then(function (result) { - if (result === true) { - completeCallback(); - } - }); - } else if (result === true) { - completeCallback(); - } - } - else if (ctrl.open && !ctrl.searchEnabled) { - // Close the selection if we don't have search enabled, and we click on the select again - ctrl.close(); - } - }; - - ctrl.parseRepeatAttr = function (repeatAttr, groupByExp, groupFilterExp) { - function updateGroups(items) { - var groupFn = $scope.$eval(groupByExp); - ctrl.groups = []; - angular.forEach(items, function (item) { - var groupName = angular.isFunction(groupFn) ? groupFn(item) : item[groupFn]; - var group = ctrl.findGroupByName(groupName); - if (group) { - group.items.push(item); - } - else { - ctrl.groups.push({name: groupName, items: [item]}); - } - }); - if (groupFilterExp) { - var groupFilterFn = $scope.$eval(groupFilterExp); - if (angular.isFunction(groupFilterFn)) { - ctrl.groups = groupFilterFn(ctrl.groups); - } else if (angular.isArray(groupFilterFn)) { - ctrl.groups = _groupsFilter(ctrl.groups, groupFilterFn); - } - } - ctrl.items = []; - ctrl.groups.forEach(function (group) { - ctrl.items = ctrl.items.concat(group.items); - }); - } + $scope.$broadcast('uis:select', item); - function setPlainItems(items) { - ctrl.items = items; - } + var locals = {}; + locals[ctrl.parserResult.itemName] = item; - // Set the function to use when displaying items - either groups or single - ctrl.setItemsFn = groupByExp ? updateGroups : setPlainItems; - - ctrl.parserResult = RepeatParser.parse(repeatAttr); - - ctrl.isGrouped = !!groupByExp; - ctrl.itemProperty = ctrl.parserResult.itemName; - - ctrl.refreshItems = function (data) { - data = data || ctrl.parserResult.source($scope); - var selectedItems = ctrl.selected; - // TODO should implement for single mode removeSelected - if (ctrl.isEmpty() || (angular.isArray(selectedItems) && !selectedItems.length) || - !ctrl.removeSelected) { - ctrl.setItemsFn(data); - } else { - if (data !== undefined) { - var filteredItems = data.filter(function (i) { - return selectedItems.indexOf(i) < 0; - }); - ctrl.setItemsFn(filteredItems); - } - } - }; - - // See https://github.com/angular/angular.js/blob/v1.2.15/src/ng/directive/ngRepeat.js#L259 - $scope.$watchCollection(ctrl.parserResult.source, function (items) { - if (items === undefined || items === null) { - // If the user specifies undefined or null => reset the collection - // Special case: items can be undefined if the user did not initialized the collection on the scope - // i.e $scope.addresses = [] is missing - ctrl.items = []; - } else { - if (!angular.isArray(items)) { - throw uiSelectMinErr('items', "Expected an array but got '{0}'.", items); - } else { - // Remove already selected items (ex: while searching) - // TODO Should add a test - ctrl.refreshItems(items); - // Force scope model value and ngModel value to be out of sync to re-run formatters - ctrl.ngModel.$modelValue = null; - } - } - }); - }; - - ctrl.setActiveItem = function (item) { - ctrl.activeIndex = ctrl.items.indexOf(item); - }; - - /** - * Checks if the item is active - * @param itemScope the item - * @returns {boolean} true if active - */ - ctrl.isActive = function (itemScope) { - if (!ctrl.open) { - return false; - } - // Get the index of this item - returns -1 if the item isn't in the current list - var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); - - // Is this the active index? - // If the itemIndex is -1, then the item wasn't in the list so let's ensure we're not active - // otherwise we can end up with all items being selected as active! - var isActive = itemIndex === -1 ? false : itemIndex === ctrl.activeIndex; - - // If this is active, and we've defined a callback, do it! - // TODO: Is this needed? If it is, then implement properly. -// if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { -// itemScope.$eval(ctrl.onHighlightCallback); -// } - - return isActive; - }; - - /** - * Checks if the item is disabled - * @param itemScope the item - * @return {boolean} true if the item is disabled - */ - ctrl.isDisabled = function (itemScope) { - if (!ctrl.open) { - return false; - } + $timeout(function(){ + ctrl.onSelectCallback($scope, { + $item: item, + $model: ctrl.parserResult.modelMapper($scope, locals) + }); + }); - var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); - var isDisabled = false; - var item; + if (ctrl.closeOnSelect) { + ctrl.close(skipFocusser); + } + if ($event && $event.type === 'click') { + ctrl.clickTriggeredSelect = true; + } + } + } + }; + + // Closes the dropdown + ctrl.close = function(skipFocusser) { + if (!ctrl.open) return; + if (ctrl.ngModel && ctrl.ngModel.$setTouched) ctrl.ngModel.$setTouched(); + _resetSearchInput(); + ctrl.open = false; + + $scope.$broadcast('uis:close', skipFocusser); + + }; + + ctrl.setFocus = function(){ + if (!ctrl.focus) ctrl.focusInput[0].focus(); + }; + + ctrl.clear = function($event) { + ctrl.select(undefined); + $event.stopPropagation(); + $timeout(function() { + ctrl.focusser[0].focus(); + }, 0, false); + }; + + // Toggle dropdown + ctrl.toggle = function(e) { + if (ctrl.open) { + ctrl.close(); + e.preventDefault(); + e.stopPropagation(); + } else { + ctrl.activate(); + } + }; + + ctrl.isLocked = function(itemScope, itemIndex) { + var isLocked, item = ctrl.selected[itemIndex]; + + if (item && !angular.isUndefined(ctrl.lockChoiceExpression)) { + isLocked = !!(itemScope.$eval(ctrl.lockChoiceExpression)); // force the boolean value + item._uiSelectChoiceLocked = isLocked; // store this for later reference + } + + return isLocked; + }; + + var sizeWatch = null; + ctrl.sizeSearchInput = function() { + + var input = ctrl.searchInput[0], + container = ctrl.searchInput.parent().parent()[0], + calculateContainerWidth = function() { + // Return the container width only if the search input is visible + return container.clientWidth * !!input.offsetParent; + }, + updateIfVisible = function(containerWidth) { + if (containerWidth === 0) { + return false; + } + var inputWidth = containerWidth - input.offsetLeft - 10; + if (inputWidth < 50) inputWidth = containerWidth; + ctrl.searchInput.css('width', inputWidth+'px'); + return true; + }; - if (itemIndex >= 0 && !angular.isUndefined(ctrl.disableChoiceExpression)) { - item = ctrl.items[itemIndex]; - // Force the boolean value - isDisabled = !!(itemScope.$eval(ctrl.disableChoiceExpression)); - // Store this for later reference - item._uiSelectChoiceDisabled = isDisabled; - } + ctrl.searchInput.css('width', '10px'); + $timeout(function() { //Give tags time to render correctly + if (sizeWatch === null && !updateIfVisible(calculateContainerWidth())) { + sizeWatch = $scope.$watch(calculateContainerWidth, function(containerWidth) { + if (updateIfVisible(containerWidth)) { + sizeWatch(); + sizeWatch = null; + } + }); + } + }); + }; + + function _handleDropDownSelection(key) { + var processed = true; + switch (key) { + case KEY.DOWN: + if (!ctrl.open && ctrl.multiple) ctrl.activate(false, true); //In case its the search input in 'multiple' mode + else if (ctrl.activeIndex < ctrl.items.length - 1) { ctrl.activeIndex++; } + break; + case KEY.UP: + if (!ctrl.open && ctrl.multiple) ctrl.activate(false, true); //In case its the search input in 'multiple' mode + else if (ctrl.activeIndex > 0 || (ctrl.search.length === 0 && ctrl.tagging.isActivated && ctrl.activeIndex > -1)) { ctrl.activeIndex--; } + break; + case KEY.TAB: + if (!ctrl.multiple || ctrl.open) ctrl.select(ctrl.items[ctrl.activeIndex], true); + break; + case KEY.ENTER: + if(ctrl.open && (ctrl.tagging.isActivated || ctrl.activeIndex >= 0)){ + ctrl.select(ctrl.items[ctrl.activeIndex]); // Make sure at least one dropdown item is highlighted before adding if not in tagging mode + } else { + ctrl.activate(false, true); //In case its the search input in 'multiple' mode + } + break; + case KEY.ESC: + ctrl.close(); + break; + default: + processed = false; + } + return processed; + } + + // Bind to keyboard shortcuts + ctrl.searchInput.on('keydown', function(e) { + + var key = e.which; + + // if(~[KEY.ESC,KEY.TAB].indexOf(key)){ + // //TODO: SEGURO? + // ctrl.close(); + // } + + $scope.$apply(function() { + + var tagged = false; + + if (ctrl.items.length > 0 || ctrl.tagging.isActivated) { + _handleDropDownSelection(key); + if ( ctrl.taggingTokens.isActivated ) { + for (var i = 0; i < ctrl.taggingTokens.tokens.length; i++) { + if ( ctrl.taggingTokens.tokens[i] === KEY.MAP[e.keyCode] ) { + // make sure there is a new value to push via tagging + if ( ctrl.search.length > 0 ) { + tagged = true; + } + } + } + if ( tagged ) { + $timeout(function() { + ctrl.searchInput.triggerHandler('tagged'); + var newItem = ctrl.search.replace(KEY.MAP[e.keyCode],'').trim(); + if ( ctrl.tagging.fct ) { + newItem = ctrl.tagging.fct( newItem ); + } + if (newItem) ctrl.select(newItem, true); + }); + } + } + } + + }); + + if(KEY.isVerticalMovement(key) && ctrl.items.length > 0){ + _ensureHighlightVisible(); + } + + if (key === KEY.ENTER || key === KEY.ESC) { + e.preventDefault(); + e.stopPropagation(); + } + + }); + + // If tagging try to split by tokens and add items + ctrl.searchInput.on('paste', function (e) { + var data = e.originalEvent.clipboardData.getData('text/plain'); + if (data && data.length > 0 && ctrl.taggingTokens.isActivated && ctrl.tagging.fct) { + var items = data.split(ctrl.taggingTokens.tokens[0]); // split by first token only + if (items && items.length > 0) { + angular.forEach(items, function (item) { + var newItem = ctrl.tagging.fct(item); + if (newItem) { + ctrl.select(newItem, true); + } + }); + e.preventDefault(); + e.stopPropagation(); + } + } + }); + + ctrl.searchInput.on('tagged', function() { + $timeout(function() { + _resetSearchInput(); + }); + }); + + // See https://github.com/ivaynberg/select2/blob/3.4.6/select2.js#L1431 + function _ensureHighlightVisible() { + var container = $element.querySelectorAll('.ui-select-choices-content'); + var choices = container.querySelectorAll('.ui-select-choices-row'); + if (choices.length < 1) { + throw uiSelectMinErr('choices', "Expected multiple .ui-select-choices-row but got '{0}'.", choices.length); + } + + if (ctrl.activeIndex < 0) { + return; + } + + var highlighted = choices[ctrl.activeIndex]; + var posY = highlighted.offsetTop + highlighted.clientHeight - container[0].scrollTop; + var height = container[0].offsetHeight; + + if (posY > height) { + container[0].scrollTop += posY - height; + } else if (posY < highlighted.clientHeight) { + if (ctrl.isGrouped && ctrl.activeIndex === 0) + container[0].scrollTop = 0; //To make group header visible when going all the way up + else + container[0].scrollTop -= highlighted.clientHeight - posY; + } + } + + $scope.$on('$destroy', function() { + ctrl.searchInput.off('keyup keydown tagged blur paste'); + }); - return isDisabled; - }; - - /** - * Selects an item. Calls the onBeforeSelect and onSelect callbacks - * onBeforeSelect is called to allow the user to alter or abort the selection - * onSelect is called to notify the user of the selection - * - * Called when the user selects an item with ENTER or clicks the dropdown - */ - ctrl.select = function (item, skipFocusser, $event) { - if (item !== undefined && item._uiSelectChoiceDisabled) { - return; - } +}]); - // If no items in the list, and no search, then return - if (!ctrl.items && !ctrl.search) { - return; - } +uis.directive('uiSelect', + ['$document', 'uiSelectConfig', 'uiSelectMinErr', 'uisOffset', '$compile', '$parse', '$timeout', + function($document, uiSelectConfig, uiSelectMinErr, uisOffset, $compile, $parse, $timeout) { + + return { + restrict: 'EA', + templateUrl: function(tElement, tAttrs) { + var theme = tAttrs.theme || uiSelectConfig.theme; + return theme + (angular.isDefined(tAttrs.multiple) ? '/select-multiple.tpl.html' : '/select.tpl.html'); + }, + replace: true, + transclude: true, + require: ['uiSelect', '^ngModel'], + scope: true, + + controller: 'uiSelectCtrl', + controllerAs: '$select', + compile: function(tElement, tAttrs) { + + //Multiple or Single depending if multiple attribute presence + if (angular.isDefined(tAttrs.multiple)) + tElement.append("").removeAttr('multiple'); + else + tElement.append(""); + + return function(scope, element, attrs, ctrls, transcludeFn) { + + var $select = ctrls[0]; + var ngModel = ctrls[1]; + + $select.generatedId = uiSelectConfig.generateId(); + $select.baseTitle = attrs.title || 'Select box'; + $select.focusserTitle = $select.baseTitle + ' focus'; + $select.focusserId = 'focusser-' + $select.generatedId; + + $select.closeOnSelect = function() { + if (angular.isDefined(attrs.closeOnSelect)) { + return $parse(attrs.closeOnSelect)(); + } else { + return uiSelectConfig.closeOnSelect; + } + }(); + + $select.onSelectCallback = $parse(attrs.onSelect); + $select.onRemoveCallback = $parse(attrs.onRemove); + + //Set reference to ngModel from uiSelectCtrl + $select.ngModel = ngModel; + + $select.choiceGrouped = function(group){ + return $select.isGrouped && group && group.name; + }; - function completeCallback() { - $scope.$broadcast('uis:select', item); + if(attrs.tabindex){ + attrs.$observe('tabindex', function(value) { + $select.focusInput.attr("tabindex", value); + element.removeAttr("tabindex"); + }); + } - $timeout(function () { - ctrl.afterSelect(item); - }); + scope.$watch('searchEnabled', function() { + var searchEnabled = scope.$eval(attrs.searchEnabled); + $select.searchEnabled = searchEnabled !== undefined ? searchEnabled : uiSelectConfig.searchEnabled; + }); + + scope.$watch('sortable', function() { + var sortable = scope.$eval(attrs.sortable); + $select.sortable = sortable !== undefined ? sortable : uiSelectConfig.sortable; + }); + + attrs.$observe('disabled', function() { + // No need to use $eval() (thanks to ng-disabled) since we already get a boolean instead of a string + $select.disabled = attrs.disabled !== undefined ? attrs.disabled : false; + }); + + attrs.$observe('resetSearchInput', function() { + // $eval() is needed otherwise we get a string instead of a boolean + var resetSearchInput = scope.$eval(attrs.resetSearchInput); + $select.resetSearchInput = resetSearchInput !== undefined ? resetSearchInput : true; + }); + + attrs.$observe('tagging', function() { + if(attrs.tagging !== undefined) + { + // $eval() is needed otherwise we get a string instead of a boolean + var taggingEval = scope.$eval(attrs.tagging); + $select.tagging = {isActivated: true, fct: taggingEval !== true ? taggingEval : undefined}; + } + else + { + $select.tagging = {isActivated: false, fct: undefined}; + } + }); + + attrs.$observe('taggingLabel', function() { + if(attrs.tagging !== undefined ) + { + // check eval for FALSE, in this case, we disable the labels + // associated with tagging + if ( attrs.taggingLabel === 'false' ) { + $select.taggingLabel = false; + } + else + { + $select.taggingLabel = attrs.taggingLabel !== undefined ? attrs.taggingLabel : '(new)'; + } + } + }); + + attrs.$observe('taggingTokens', function() { + if (attrs.tagging !== undefined) { + var tokens = attrs.taggingTokens !== undefined ? attrs.taggingTokens.split('|') : [',','ENTER']; + $select.taggingTokens = {isActivated: true, tokens: tokens }; + } + }); + + //Automatically gets focus when loaded + if (angular.isDefined(attrs.autofocus)){ + $timeout(function(){ + $select.setFocus(); + }); + } - if (ctrl.closeOnSelect) { - ctrl.close(skipFocusser); - } - if ($event && $event.type === 'click') { - ctrl.clickTriggeredSelect = true; - } - } + //Gets focus based on scope event name (e.g. focus-on='SomeEventName') + if (angular.isDefined(attrs.focusOn)){ + scope.$on(attrs.focusOn, function() { + $timeout(function(){ + $select.setFocus(); + }); + }); + } - // Call the beforeSelect method - // Allowable responses are -: - // false: Abort the selection - // true: Complete selection - // promise: Wait for response - // object: Add the returned object - var result = ctrl.beforeSelect(item); - if (angular.isFunction(result.then)) { - // Promise returned - wait for it to complete before completing the selection - result.then(function (response) { - if (!response) { - return; - } - if (response === true) { - completeCallback(item); - } else if (response) { - completeCallback(response); - } - }); - } else if (result === true) { - completeCallback(item); - } else if (result) { - completeCallback(result); - } - }; - - /** - * Close the dropdown - */ - ctrl.close = function (skipFocusser) { - if (!ctrl.open) { - return; - } + function onDocumentClick(e) { + if (!$select.open) return; //Skip it if dropdown is close + + var contains = false; + + if (window.jQuery) { + // Firefox 3.6 does not support element.contains() + // See Node.contains https://developer.mozilla.org/en-US/docs/Web/API/Node.contains + contains = window.jQuery.contains(element[0], e.target); + } else { + contains = element[0].contains(e.target); + } + + if (!contains && !$select.clickTriggeredSelect) { + //Will lose focus only with certain targets + var focusableControls = ['input','button','textarea']; + var targetScope = angular.element(e.target).scope(); //To check if target is other ui-select + var skipFocusser = targetScope && targetScope.$select && targetScope.$select !== $select; //To check if target is other ui-select + if (!skipFocusser) skipFocusser = ~focusableControls.indexOf(e.target.tagName.toLowerCase()); //Check if target is input, button or textarea + $select.close(skipFocusser); + scope.$digest(); + } + $select.clickTriggeredSelect = false; + } - function completeCallback() { - if (ctrl.ngModel && ctrl.ngModel.$setTouched) { - ctrl.ngModel.$setTouched(); - } - _resetSearchInput(); - ctrl.open = false; - if (!ctrl.searchEnabled) { - angular.element(ctrl.searchInput[0]).removeClass('ui-select-offscreen'); - } - - $scope.$broadcast('uis:close', skipFocusser); - } + // See Click everywhere but here event http://stackoverflow.com/questions/12931369 + $document.on('click', onDocumentClick); + + scope.$on('$destroy', function() { + $document.off('click', onDocumentClick); + }); + + // Move transcluded elements to their correct position in main template + transcludeFn(scope, function(clone) { + // See Transclude in AngularJS http://blog.omkarpatil.com/2012/11/transclude-in-angularjs.html + + // One day jqLite will be replaced by jQuery and we will be able to write: + // var transcludedElement = clone.filter('.my-class') + // instead of creating a hackish DOM element: + var transcluded = angular.element('
    ').append(clone); + + var transcludedMatch = transcluded.querySelectorAll('.ui-select-match'); + transcludedMatch.removeAttr('ui-select-match'); //To avoid loop in case directive as attr + transcludedMatch.removeAttr('data-ui-select-match'); // Properly handle HTML5 data-attributes + if (transcludedMatch.length !== 1) { + throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-match but got '{0}'.", transcludedMatch.length); + } + element.querySelectorAll('.ui-select-match').replaceWith(transcludedMatch); + + var transcludedChoices = transcluded.querySelectorAll('.ui-select-choices'); + transcludedChoices.removeAttr('ui-select-choices'); //To avoid loop in case directive as attr + transcludedChoices.removeAttr('data-ui-select-choices'); // Properly handle HTML5 data-attributes + if (transcludedChoices.length !== 1) { + throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-choices but got '{0}'.", transcludedChoices.length); + } + element.querySelectorAll('.ui-select-choices').replaceWith(transcludedChoices); + }); + + // Support for appending the select field to the body when its open + var appendToBody = scope.$eval(attrs.appendToBody); + if (appendToBody !== undefined ? appendToBody : uiSelectConfig.appendToBody) { + scope.$watch('$select.open', function(isOpen) { + if (isOpen) { + positionDropdown(); + } else { + resetDropdown(); + } + }); - var result = ctrl.beforeDropdownClose(); - if (angular.isFunction(result.then)) { - // Promise returned - wait for it to complete before completing the selection - result.then(function (result) { - if (result === true) { - completeCallback(); - } - }); - } else if (result === true) { - completeCallback(); - } - }; - - /** - * Set focus on the control - */ - ctrl.setFocus = function () { - if (!ctrl.focus) { - ctrl.focusInput[0].focus(); - } - }; - - /** - * Clears the selection - * @param $event - */ - ctrl.clear = function ($event) { - ctrl.select(undefined); - $event.stopPropagation(); - $timeout(function () { - ctrl.focusser[0].focus(); - }, 0, false); - }; - - /** - * Toggle the dropdown open and closed - */ - ctrl.toggle = function (e) { - if (ctrl.open) { - ctrl.close(); - e.preventDefault(); - e.stopPropagation(); - } else { - ctrl.activate(); - } - }; + // Move the dropdown back to its original location when the scope is destroyed. Otherwise + // it might stick around when the user routes away or the select field is otherwise removed + scope.$on('$destroy', function() { + resetDropdown(); + }); + } - ctrl.isLocked = function (itemScope, itemIndex) { - var isLocked, item = ctrl.selected[itemIndex]; + // Hold on to a reference to the .ui-select-container element for appendToBody support + var placeholder = null, + originalWidth = ''; - if (item && !angular.isUndefined(ctrl.lockChoiceExpression)) { - // Force the boolean value - isLocked = !!(itemScope.$eval(ctrl.lockChoiceExpression)); - // Store this for later reference - item._uiSelectChoiceLocked = isLocked; - } + function positionDropdown() { + // Remember the absolute position of the element + var offset = uisOffset(element); - return isLocked; - }; - - var sizeWatch = null; - ctrl.sizeSearchInput = function () { - var input = ctrl.searchInput[0], - container = ctrl.searchInput.parent().parent()[0], - calculateContainerWidth = function () { - // Return the container width only if the search input is visible - return container.clientWidth * !!input.offsetParent; - }, - updateIfVisible = function (containerWidth) { - if (containerWidth === 0) { - return false; - } - var inputWidth = containerWidth - input.offsetLeft - ctrl.searchInput.parent()[0].offsetLeft - - 5; - if (inputWidth < 50) { - inputWidth = containerWidth; - } - ctrl.searchInput.css('width', inputWidth + 'px'); - return true; - }; - - ctrl.searchInput.css('width', '10px'); - $timeout(function () { - // Give time to render correctly - if (sizeWatch === null && !updateIfVisible(calculateContainerWidth())) { - sizeWatch = $scope.$watch(calculateContainerWidth, function (containerWidth) { - if (updateIfVisible(containerWidth)) { - sizeWatch(); - sizeWatch = null; - } - }); - } - }); - }; - - function _handleDropDownSelection(key) { - var processed = true; - switch (key) { - case ctrl.KEY.DOWN: - if (!ctrl.open && ctrl.multiple) { - // In case its the search input in 'multiple' mode - ctrl.activate(false, true); - } - else if (ctrl.activeIndex < ctrl.items.length - 1) { - ctrl.activeIndex++; - } - break; - case ctrl.KEY.UP: - if (!ctrl.open && ctrl.multiple) { - ctrl.activate(false, true); - } //In case its the search input in 'multiple' mode - else if (ctrl.activeIndex > 0) { - ctrl.activeIndex--; - } - break; - case ctrl.KEY.TAB: - if (!ctrl.multiple || ctrl.open) { - ctrl.select(ctrl.items[ctrl.activeIndex], true); - } - break; - case ctrl.KEY.ENTER: - if (ctrl.open) { - // Make sure at least one dropdown item is highlighted before adding - if (ctrl.items[ctrl.activeIndex] !== undefined) { - ctrl.select(ctrl.items[ctrl.activeIndex]); - } - } else { - // In case its the search input in 'multiple' mode - ctrl.activate(false, true); - } - break; - case ctrl.KEY.ESC: - ctrl.close(); - break; - default: - processed = false; - } - return processed; - } + // Clone the element into a placeholder element to take its original place in the DOM + placeholder = angular.element('
    '); + placeholder[0].style.width = offset.width + 'px'; + placeholder[0].style.height = offset.height + 'px'; + element.after(placeholder); - // Bind to keyboard shortcuts - ctrl.searchInput.on('keydown', function (e) { - var key = e.which; + // Remember the original value of the element width inline style, so it can be restored + // when the dropdown is closed + originalWidth = element[0].style.width; - if (~[ctrl.KEY.ESC, ctrl.KEY.TAB].indexOf(key)) { - // TODO: SEGURO? - ctrl.close(); - } + // Now move the actual dropdown element to the end of the body + $document.find('body').append(element); - $scope.$apply(function () { - _handleDropDownSelection(key); - }); + element[0].style.position = 'absolute'; + element[0].style.left = offset.left + 'px'; + element[0].style.top = offset.top + 'px'; + element[0].style.width = offset.width + 'px'; + } - if (ctrl.KEY.isVerticalMovement(key) && ctrl.items.length > 0) { - _ensureHighlightVisible(); - } + function resetDropdown() { + if (placeholder === null) { + // The dropdown has not actually been display yet, so there's nothing to reset + return; + } - if (key === ctrl.KEY.ENTER || key === ctrl.KEY.ESC) { - e.preventDefault(); - e.stopPropagation(); - } - }); + // Move the dropdown element back to its original location in the DOM + placeholder.replaceWith(element); + placeholder = null; - ctrl.searchInput.on('keyup', function (e) { - // return early with these keys - if (e.which === ctrl.KEY.TAB || ctrl.KEY.isControl(e) || ctrl.KEY.isFunctionKey(e) || - e.which === ctrl.KEY.ESC || - ctrl.KEY.isVerticalMovement(e.which)) { - return; - } + element[0].style.position = ''; + element[0].style.left = ''; + element[0].style.top = ''; + element[0].style.width = originalWidth; + } - // Let the users process the data - // TODO: Is this needed, or just let the user bind to the event themselves! - ctrl.afterKeypress(e); - }); + // Hold on to a reference to the .ui-select-dropdown element for direction support. + var dropdown = null, + directionUpClassName = 'direction-up'; - // See https://github.com/ivaynberg/select2/blob/3.4.6/select2.js#L1431 - function _ensureHighlightVisible() { - var container = $element.querySelectorAll('.ui-select-choices-content'); - var choices = container.querySelectorAll('.ui-select-choices-row'); - if (choices.length < 1) { - throw uiSelectMinErr('choices', "Expected multiple .ui-select-choices-row but got '{0}'.", - choices.length); - } + // Support changing the direction of the dropdown if there isn't enough space to render it. + scope.$watch('$select.open', function(isOpen) { + if (isOpen) { + dropdown = angular.element(element).querySelectorAll('.ui-select-dropdown'); + if (dropdown === null) { + return; + } - if (ctrl.activeIndex < 0) { - return; - } + // Hide the dropdown so there is no flicker until $timeout is done executing. + dropdown[0].style.opacity = 0; - var highlighted = choices[ctrl.activeIndex]; - var posY = highlighted.offsetTop + highlighted.clientHeight - container[0].scrollTop; - var height = container[0].offsetHeight; - - if (posY > height) { - container[0].scrollTop += posY - height; - } else if (posY < highlighted.clientHeight) { - if (ctrl.isGrouped && ctrl.activeIndex === 0) { - // To make group header visible when going all the way up - container[0].scrollTop = 0; - } - else { - container[0].scrollTop -= highlighted.clientHeight - posY; - } - } - } + // Delay positioning the dropdown until all choices have been added so its height is correct. + $timeout(function(){ + var offset = uisOffset(element); + var offsetDropdown = uisOffset(dropdown); + + // Determine if the direction of the dropdown needs to be changed. + if (offset.top + offset.height + offsetDropdown.height > $document[0].documentElement.scrollTop + $document[0].documentElement.clientHeight) { + dropdown[0].style.position = 'absolute'; + dropdown[0].style.top = (offsetDropdown.height * -1) + 'px'; + element.addClass(directionUpClassName); + } - $scope.$on('$destroy', function () { - ctrl.searchInput.off('keyup keydown blur paste'); + // Display the dropdown once it has been positioned. + dropdown[0].style.opacity = 1; }); + } else { + if (dropdown === null) { + return; + } + + // Reset the position of the dropdown. + dropdown[0].style.position = ''; + dropdown[0].style.top = ''; + element.removeClass(directionUpClassName); + } + }); + }; + } + }; +}]); - /** - * Keypress callback. Overridable. - * @param event the keypress event - */ - /* jshint unused:false */ - ctrl.afterKeypress = function (event) { - }; - - /** - * Method called before a selection is made. This can be overridden to allow - * the selection to be aborted, or a modified version of the selected item to be - * returned. - * - * Allowable responses are -: - * false: Abort the selection - * true: Complete selection with the selected object - * object: Complete the selection with the returned object - * promise: Wait for response - response from promise is as above - * - * @param item the item that has been selected - * @returns {*} - */ - ctrl.beforeSelect = function (item) { - return true; - }; - - /** - * Method called after a selection is confirmed. This can be overridden to allow - * the application to be notified of a newly selected item. - * No return is required. - * - * @param item the item that has been selected - */ - ctrl.afterSelect = function (item) { - }; - - /** - * Method called before an item is removed from the selected list. This can be overridden - * to allow the removal to be aborted - * - * Allowable responses are -: - * false: Abort the selection - * true: Complete selection with the selected object - * object: Complete the selection with the returned object - * promise: Wait for response - response from promise is as above - * - * @param item the item that has been selected - * @returns {*} - */ - ctrl.beforeRemove = function (item) { - return true; - }; - - /** - * Method called after a item is removed. This can be overridden to allow - * the application to be notified of a removed item. - * No return is required. - * - * @param item the item that has been removed - */ - ctrl.afterRemove = function (item) { - }; - - /** - * Method called before the dropdown is opened. This can be overridden to allow - * the application to process data before the dropdown is displayed. - * The method may return a promise, or true to allow the dropdown, or false to abort. - * @returns {boolean} - */ - ctrl.beforeDropdownOpen = function () { - return true; - }; - - /** - * Method called before the dropdown is closed. This can be overridden to allow - * the application to prevent the dropdown from closing. - * The method may return a promise, or true to allow the dropdown to close, or false to abort. - * @returns {boolean} - */ - ctrl.beforeDropdownClose = function () { - return true; - }; - - }]); +uis.directive('uiSelectMatch', ['uiSelectConfig', function(uiSelectConfig) { + return { + restrict: 'EA', + require: '^uiSelect', + replace: true, + transclude: true, + templateUrl: function(tElement) { + // Gets theme attribute from parent (ui-select) + var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; + var multi = tElement.parent().attr('multiple'); + return theme + (multi ? '/match-multiple.tpl.html' : '/match.tpl.html'); + }, + link: function(scope, element, attrs, $select) { + $select.lockChoiceExpression = attrs.uiLockChoice; + attrs.$observe('placeholder', function(placeholder) { + $select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder; + }); + + function setAllowClear(allow) { + $select.allowClear = (angular.isDefined(allow)) ? (allow === '') ? true : (allow.toLowerCase() === 'true') : false; + } + + attrs.$observe('allowClear', setAllowClear); + setAllowClear(attrs.allowClear); + + if($select.multiple){ + $select.sizeSearchInput(); + } + + } + }; +}]); -uis.directive('uiSelect', - ['$document', '$window', 'uiSelectConfig', 'uiSelectMinErr', 'uisOffset', '$compile', '$parse', '$timeout', - function ($document, $window, uiSelectConfig, uiSelectMinErr, uisOffset, $compile, $parse, $timeout) { - - return { - restrict: 'EA', - templateUrl: function (tElement, tAttrs) { - var theme = tAttrs.theme || uiSelectConfig.theme; - return theme + - (angular.isDefined(tAttrs.multiple) ? '/select-multiple.tpl.html' : '/select.tpl.html'); - }, - replace: true, - transclude: true, - require: ['uiSelect', '^ngModel'], - scope: true, - controller: 'uiSelectCtrl', - controllerAs: '$select', - compile: function (tElement, tAttrs) { - - // Multiple or Single depending if multiple attribute presence - if (angular.isDefined(tAttrs.multiple)) { - tElement.append("").removeAttr('multiple'); - } - else { - tElement.append(""); - } - - return function (scope, element, attrs, ctrls, transcludeFn) { - var $select = ctrls[0]; - var ngModel = ctrls[1]; - - $select.generatedId = uiSelectConfig.generateId(); - $select.baseTitle = attrs.title || 'Select box'; - $select.focusserTitle = $select.baseTitle + ' focus'; - $select.focusserId = 'focusser-' + $select.generatedId; - - $select.closeOnSelect = function () { - if (angular.isDefined(attrs.closeOnSelect)) { - return $parse(attrs.closeOnSelect)(); - } else { - return uiSelectConfig.closeOnSelect; - } - }(); - - // Limit the number of selections allowed - $select.limit = (angular.isDefined(attrs.limit)) ? parseInt(attrs.limit, 10) : undefined; - - // Set reference to ngModel from uiSelectCtrl - $select.ngModel = ngModel; - - $select.choiceGrouped = function (group) { - return $select.isGrouped && group && group.name; - }; - - if (attrs.tabindex) { - attrs.$observe('tabindex', function (value) { - $select.focusInput.attr("tabindex", value); - element.removeAttr("tabindex"); - }); - } - - var searchEnabled = scope.$eval(attrs.searchEnabled); - $select.searchEnabled = - searchEnabled !== undefined ? searchEnabled : uiSelectConfig.searchEnabled; - - var sortable = scope.$eval(attrs.sortable); - $select.sortable = sortable !== undefined ? sortable : uiSelectConfig.sortable; - - attrs.$observe('disabled', function () { - // No need to use $eval() (thanks to ng-disabled) since we already get a boolean instead of a string - $select.disabled = attrs.disabled !== undefined ? attrs.disabled : false; - }); - - - //Automatically gets focus when loaded - if (angular.isDefined(attrs.autofocus)) { - $timeout(function () { - $select.setFocus(); - }); - } - - // Gets focus based on scope event name (e.g. focus-on='SomeEventName') - if (angular.isDefined(attrs.focusOn)) { - scope.$on(attrs.focusOn, function () { - $timeout(function () { - $select.setFocus(); - }); - }); - } - - function onDocumentClick(e) { - //Skip it if dropdown is close - if (!$select.open) { - return; - } - - var contains = false; - - if (window.jQuery) { - // Firefox 3.6 does not support element.contains() - // See Node.contains https://developer.mozilla.org/en-US/docs/Web/API/Node.contains - contains = window.jQuery.contains(element[0], e.target); - } else { - contains = element[0].contains(e.target); - } - - if (!contains && !$select.clickTriggeredSelect) { - // Will lose focus only with certain targets - var focusableControls = ['input', 'button', 'textarea']; - // To check if target is other ui-select - var targetController = angular.element(e.target).controller('uiSelect'); - // To check if target is other ui-select - var skipFocusser = targetController && targetController !== $select; - // Check if target is input, button or textarea - if (!skipFocusser) { - skipFocusser = ~focusableControls.indexOf(e.target.tagName.toLowerCase()); - } - $select.close(skipFocusser); - scope.$digest(); - } - $select.clickTriggeredSelect = false; - } - - // See Click everywhere but here event http://stackoverflow.com/questions/12931369 - $document.on('click', onDocumentClick); - - scope.$on('$destroy', function () { - $document.off('click', onDocumentClick); - }); - - // Move transcluded elements to their correct position in main template - transcludeFn(scope, function (clone) { - // See Transclude in AngularJS http://blog.omkarpatil.com/2012/11/transclude-in-angularjs.html - - // One day jqLite will be replaced by jQuery and we will be able to write: - // var transcludedElement = clone.filter('.my-class') - // instead of creating a hackish DOM element: - var transcluded = angular.element('
    ').append(clone); - - var transcludedMatch = transcluded.querySelectorAll('.ui-select-match'); - transcludedMatch.removeAttr('ui-select-match'); //To avoid loop in case directive as attr - transcludedMatch.removeAttr('data-ui-select-match'); // Properly handle HTML5 data-attributes - if (transcludedMatch.length !== 1) { - throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-match but got '{0}'.", - transcludedMatch.length); - } - element.querySelectorAll('.ui-select-match').replaceWith(transcludedMatch); - - var transcludedChoices = transcluded.querySelectorAll('.ui-select-choices'); - transcludedChoices.removeAttr('ui-select-choices'); //To avoid loop in case directive as attr - transcludedChoices.removeAttr('data-ui-select-choices'); // Properly handle HTML5 data-attributes - if (transcludedChoices.length !== 1) { - throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-choices but got '{0}'.", - transcludedChoices.length); - } - element.querySelectorAll('.ui-select-choices').replaceWith(transcludedChoices); - }); - - // Support for appending the select field to the body when its open - var appendToBody = scope.$eval(attrs.appendToBody); - if (appendToBody !== undefined ? appendToBody : uiSelectConfig.appendToBody) { - scope.$watch('$select.open', function (isOpen) { - if (isOpen) { - positionDropdown(); - } else { - resetDropdown(); - } - }); - - // Move the dropdown back to its original location when the scope is destroyed. Otherwise - // it might stick around when the user routes away or the select field is otherwise removed - scope.$on('$destroy', function () { - resetDropdown(); - }); - } - - // Hold on to a reference to the .ui-select-container element for appendToBody support - var placeholder = null, - originalWidth = ''; - - function positionDropdown() { - // Remember the absolute position of the element - var offset = uisOffset(element); - - // Clone the element into a placeholder element to take its original place in the DOM - placeholder = angular.element('
    '); - placeholder[0].style.width = offset.width + 'px'; - placeholder[0].style.height = offset.height + 'px'; - element.after(placeholder); - - // Remember the original value of the element width inline style, so it can be restored - // when the dropdown is closed - originalWidth = element[0].style.width; - - // Now move the actual dropdown element to the end of the body - $document.find('body').append(element); - - element[0].style.position = 'absolute'; - element[0].style.left = offset.left + 'px'; - element[0].style.top = offset.top + 'px'; - element[0].style.width = offset.width + 'px'; - } - - function resetDropdown() { - if (placeholder === null) { - // The dropdown has not actually been display yet, so there's nothing to reset - return; - } - - // Move the dropdown element back to its original location in the DOM - placeholder.replaceWith(element); - placeholder = null; - - element[0].style.position = ''; - element[0].style.left = ''; - element[0].style.top = ''; - element[0].style.width = originalWidth; - } - - // Hold on to a reference to the .ui-select-dropdown element for direction support. - var dropdown = null, - directionUpClassName = 'direction-up'; - - // Support changing the direction of the dropdown if there isn't enough space to render it. - scope.$watch('$select.open', function (isOpen) { - if (isOpen) { - // Get the dropdown element - dropdown = angular.element(element).querySelectorAll('.ui-select-dropdown'); - if (dropdown === null) { - return; - } - - // Hide the dropdown so there is no flicker until $timeout is done executing. - dropdown[0].style.opacity = 0; - - // Delay positioning the dropdown until all choices have been added so its height is correct. - $timeout(function () { - var offset = uisOffset(element); - var offsetDropdown = uisOffset(dropdown); - - // Determine if the direction of the dropdown needs to be changed. - if (offset.top + offset.height + offsetDropdown.height > - $window.pageYOffset + $document[0].documentElement.clientHeight) { - element.addClass(directionUpClassName); - } - - // Display the dropdown once it has been positioned. - dropdown[0].style.opacity = 1; - }); - } else { - if (dropdown === null) { - return; - } - - // Reset the position of the dropdown. - element.removeClass(directionUpClassName); - } - }); - }; - } - }; - }]); +uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelectMinErr, $timeout) { + return { + restrict: 'EA', + require: ['^uiSelect', '^ngModel'], -uis.directive('uiSelectMatch', ['uiSelectConfig', function (uiSelectConfig) { - return { - restrict: 'EA', - require: '^uiSelect', - replace: true, - transclude: true, - templateUrl: function (tElement) { - // Gets theme attribute from parent (ui-select) - var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; - var multi = tElement.parent().attr('multiple'); - return theme + (multi ? '/match-multiple.tpl.html' : '/match.tpl.html'); - }, - link: function (scope, element, attrs, $select) { - $select.lockChoiceExpression = attrs.uiLockChoice; + controller: ['$scope','$timeout', function($scope, $timeout){ - // TODO: observe required? - attrs.$observe('placeholder', function (placeholder) { - $select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder; - }); + var ctrl = this, + $select = $scope.$select, + ngModel; - function setAllowClear(allow) { - $select.allowClear = - (angular.isDefined(allow)) ? (allow === '') ? true : (allow.toLowerCase() === 'true') : false; - } + //Wait for link fn to inject it + $scope.$evalAsync(function(){ ngModel = $scope.ngModel; }); - // TODO: observe required? - attrs.$observe('allowClear', setAllowClear); - setAllowClear(attrs.allowClear); + ctrl.activeMatchIndex = -1; - if ($select.multiple) { - $select.sizeSearchInput(); - } - } - }; -}]); + ctrl.updateModel = function(){ + ngModel.$setViewValue(Date.now()); //Set timestamp as a unique string to force changes + ctrl.refreshComponent(); + }; -uis.directive('uiSelectMultiple', ['uiSelectMinErr', '$timeout', function (uiSelectMinErr, $timeout) { - return { - restrict: 'EA', - require: ['^uiSelect', '^ngModel'], - controller: ['$scope', '$timeout', function ($scope, $timeout) { - var ctrl = this, - $select = $scope.$select, - ngModel; - - //Wait for link fn to inject it - $scope.$evalAsync(function () { - ngModel = $scope.ngModel; - }); + ctrl.refreshComponent = function(){ + //Remove already selected items + //e.g. When user clicks on a selection, the selected array changes and + //the dropdown should remove that item + $select.refreshItems(); + $select.sizeSearchInput(); + }; - ctrl.activeMatchIndex = -1; - - ctrl.updateModel = function () { - ngModel.$setViewValue(Date.now()); //Set timestamp as a unique string to force changes - ctrl.refreshComponent(); - }; - - ctrl.refreshComponent = function () { - // Remove already selected items - // e.g. When user clicks on a selection, the selected array changes and - // the dropdown should remove that item - $select.refreshItems(); - $select.sizeSearchInput(); - }; - - /** - * Remove item from multiple select - * Calls onBeforeRemove to allow the user to prevent the removal of the item - * Then calls onRemove to notify the user the item has been removed - */ - ctrl.removeChoice = function (index) { - // Get the removed choice - var removedChoice = $select.selected[index]; - - // If the choice is locked, can't remove it - if (removedChoice._uiSelectChoiceLocked) { - return; - } + // Remove item from multiple select + ctrl.removeChoice = function(index){ - // Give some time for scope propagation. - function completeCallback() { - $select.selected.splice(index, 1); - ctrl.activeMatchIndex = -1; - $select.sizeSearchInput(); + var removedChoice = $select.selected[index]; - $timeout(function () { - $select.afterRemove(removedChoice); - }); + // if the choice is locked, can't remove it + if(removedChoice._uiSelectChoiceLocked) return; - ctrl.updateModel(); - } + var locals = {}; + locals[$select.parserResult.itemName] = removedChoice; - // Call the beforeRemove callback - // Allowable responses are -: - // false: Abort the removal - // true: Complete removal - // promise: Wait for response - var result = $select.beforeRemove(removedChoice); - if (angular.isFunction(result.then)) { - // Promise returned - wait for it to complete before completing the selection - result.then(function (result) { - if (result === true) { - completeCallback(); - } - }); - } else if (result === true) { - completeCallback(); - } - }; + $select.selected.splice(index, 1); + ctrl.activeMatchIndex = -1; + $select.sizeSearchInput(); - ctrl.getPlaceholder = function () { - // Refactor single? - if ($select.selected && $select.selected.length) { - return; - } - return $select.placeholder; - }; - }], - controllerAs: '$selectMultiple', - - link: function (scope, element, attrs, ctrls) { - var $select = ctrls[0]; - var ngModel = scope.ngModel = ctrls[1]; - var $selectMultiple = scope.$selectMultiple; - - //$select.selected = raw selected objects (ignoring any property binding) - - $select.multiple = true; - $select.removeSelected = true; - - //Input that will handle focus - $select.focusInput = $select.searchInput; - - //From view --> model - ngModel.$parsers.unshift(function () { - var locals = {}, - result, - resultMultiple = []; - for (var j = $select.selected.length - 1; j >= 0; j--) { - locals = {}; - locals[$select.parserResult.itemName] = $select.selected[j]; - result = $select.parserResult.modelMapper(scope, locals); - resultMultiple.unshift(result); - } - return resultMultiple; - }); + // Give some time for scope propagation. + $timeout(function(){ + $select.onRemoveCallback($scope, { + $item: removedChoice, + $model: $select.parserResult.modelMapper($scope, locals) + }); + }); - // From model --> view - ngModel.$formatters.unshift(function (inputValue) { - var data = $select.parserResult.source(scope, {$select: {search: ''}}), //Overwrite $search - locals = {}, - result; - if (!data) { - return inputValue; - } - var resultMultiple = []; - var checkFnMultiple = function (list, value) { - if (!list || !list.length) { - return; - } - for (var p = list.length - 1; p >= 0; p--) { - locals[$select.parserResult.itemName] = list[p]; - result = $select.parserResult.modelMapper(scope, locals); - if ($select.parserResult.trackByExp) { - var matches = /\.(.+)/.exec($select.parserResult.trackByExp); - if (matches.length > 0 && result[matches[1]] == value[matches[1]]) { - resultMultiple.unshift(list[p]); - return true; - } - } - if (angular.equals(result, value)) { - resultMultiple.unshift(list[p]); - return true; - } - } - return false; - }; - if (!inputValue) return resultMultiple; //If ngModel was undefined - for (var k = inputValue.length - 1; k >= 0; k--) { - //Check model array of currently selected items - if (!checkFnMultiple($select.selected, inputValue[k])) { - //Check model array of all items available - if (!checkFnMultiple(data, inputValue[k])) { - //If not found on previous lists, just add it directly to resultMultiple - resultMultiple.unshift(inputValue[k]); - } - } - } - return resultMultiple; - }); + ctrl.updateModel(); - //Watch for external model changes - scope.$watchCollection(function () { - return ngModel.$modelValue; - }, function (newValue, oldValue) { - if (oldValue != newValue) { - ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters - $selectMultiple.refreshComponent(); - } - }); + }; - ngModel.$render = function () { - // Make sure that model value is array - if (!angular.isArray(ngModel.$viewValue)) { - // Have tolerance for null or undefined values - if (angular.isUndefined(ngModel.$viewValue) || ngModel.$viewValue === null) { - $select.selected = []; - } else { - throw uiSelectMinErr('multiarr', "Expected model value to be array but got '{0}'", - ngModel.$viewValue); - } - } - $select.selected = ngModel.$viewValue; - scope.$evalAsync(); //To force $digest - }; + ctrl.getPlaceholder = function(){ + //Refactor single? + if($select.selected.length) return; + return $select.placeholder; + }; - scope.$on('uis:select', function (event, item) { - if ($select.selected.length >= $select.limit) { - return; - } - $select.selected.push(item); - $selectMultiple.updateModel(); - }); - scope.$on('uis:activate', function () { - $selectMultiple.activeMatchIndex = -1; - }); + }], + controllerAs: '$selectMultiple', - scope.$watch('$select.disabled', function (newValue, oldValue) { - // As the search input field may now become visible, it may be necessary to recompute its size - if (oldValue && !newValue) { - $select.sizeSearchInput(); - } - }); + link: function(scope, element, attrs, ctrls) { - $select.searchInput.on('keydown', function (e) { - var key = e.which; - scope.$apply(function () { - var processed = false; - if ($select.KEY.isHorizontalMovement(key)) { - processed = _handleMatchSelection(key); - } - if (processed && key != $select.KEY.TAB) { - // TODO Check si el tab selecciona aun correctamente - //Creat test -// e.preventDefault(); - // e.stopPropagation(); - } - }); - }); + var $select = ctrls[0]; + var ngModel = scope.ngModel = ctrls[1]; + var $selectMultiple = scope.$selectMultiple; - function _getCaretPosition(el) { - if (angular.isNumber(el.selectionStart)) { - return el.selectionStart; - } - // selectionStart is not supported in IE8 and we don't want hacky workarounds so we compromise - else { - return el.value.length; + //$select.selected = raw selected objects (ignoring any property binding) + + $select.multiple = true; + $select.removeSelected = true; + + //Input that will handle focus + $select.focusInput = $select.searchInput; + + //From view --> model + ngModel.$parsers.unshift(function () { + var locals = {}, + result, + resultMultiple = []; + for (var j = $select.selected.length - 1; j >= 0; j--) { + locals = {}; + locals[$select.parserResult.itemName] = $select.selected[j]; + result = $select.parserResult.modelMapper(scope, locals); + resultMultiple.unshift(result); + } + return resultMultiple; + }); + + // From model --> view + ngModel.$formatters.unshift(function (inputValue) { + var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search + locals = {}, + result; + if (!data) return inputValue; + var resultMultiple = []; + var checkFnMultiple = function(list, value){ + if (!list || !list.length) return; + for (var p = list.length - 1; p >= 0; p--) { + locals[$select.parserResult.itemName] = list[p]; + result = $select.parserResult.modelMapper(scope, locals); + if($select.parserResult.trackByExp){ + var matches = /\.(.+)/.exec($select.parserResult.trackByExp); + if(matches.length>0 && result[matches[1]] == value[matches[1]]){ + resultMultiple.unshift(list[p]); + return true; } } + if (angular.equals(result,value)){ + resultMultiple.unshift(list[p]); + return true; + } + } + return false; + }; + if (!inputValue) return resultMultiple; //If ngModel was undefined + for (var k = inputValue.length - 1; k >= 0; k--) { + //Check model array of currently selected items + if (!checkFnMultiple($select.selected, inputValue[k])){ + //Check model array of all items available + if (!checkFnMultiple(data, inputValue[k])){ + //If not found on previous lists, just add it directly to resultMultiple + resultMultiple.unshift(inputValue[k]); + } + } + } + return resultMultiple; + }); + + //Watch for external model changes + scope.$watchCollection(function(){ return ngModel.$modelValue; }, function(newValue, oldValue) { + if (oldValue != newValue){ + ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters + $selectMultiple.refreshComponent(); + } + }); + + ngModel.$render = function() { + // Make sure that model value is array + if(!angular.isArray(ngModel.$viewValue)){ + // Have tolerance for null or undefined values + if(angular.isUndefined(ngModel.$viewValue) || ngModel.$viewValue === null){ + $select.selected = []; + } else { + throw uiSelectMinErr('multiarr', "Expected model value to be array but got '{0}'", ngModel.$viewValue); + } + } + $select.selected = ngModel.$viewValue; + scope.$evalAsync(); //To force $digest + }; + + scope.$on('uis:select', function (event, item) { + $select.selected.push(item); + $selectMultiple.updateModel(); + }); + + scope.$on('uis:activate', function () { + $selectMultiple.activeMatchIndex = -1; + }); + + scope.$watch('$select.disabled', function(newValue, oldValue) { + // As the search input field may now become visible, it may be necessary to recompute its size + if (oldValue && !newValue) $select.sizeSearchInput(); + }); + + $select.searchInput.on('keydown', function(e) { + var key = e.which; + scope.$apply(function() { + var processed = false; + // var tagged = false; //Checkme + if(KEY.isHorizontalMovement(key)){ + processed = _handleMatchSelection(key); + } + if (processed && key != KEY.TAB) { + //TODO Check si el tab selecciona aun correctamente + //Crear test + e.preventDefault(); + e.stopPropagation(); + } + }); + }); + function _getCaretPosition(el) { + if(angular.isNumber(el.selectionStart)) return el.selectionStart; + // selectionStart is not supported in IE8 and we don't want hacky workarounds so we compromise + else return el.value.length; + } + // Handles selected options in "multiple" mode + function _handleMatchSelection(key){ + var caretPosition = _getCaretPosition($select.searchInput[0]), + length = $select.selected.length, + // none = -1, + first = 0, + last = length-1, + curr = $selectMultiple.activeMatchIndex, + next = $selectMultiple.activeMatchIndex+1, + prev = $selectMultiple.activeMatchIndex-1, + newIndex = curr; + + if(caretPosition > 0 || ($select.search.length && key == KEY.RIGHT)) return false; + + $select.close(); + + function getNewActiveMatchIndex(){ + switch(key){ + case KEY.LEFT: + // Select previous/first item + if(~$selectMultiple.activeMatchIndex) return prev; + // Select last item + else return last; + break; + case KEY.RIGHT: + // Open drop-down + if(!~$selectMultiple.activeMatchIndex || curr === last){ + $select.activate(); + return false; + } + // Select next/last item + else return next; + break; + case KEY.BACKSPACE: + // Remove selected item and select previous/first + if(~$selectMultiple.activeMatchIndex){ + $selectMultiple.removeChoice(curr); + return prev; + } + // Select last item + else return last; + break; + case KEY.DELETE: + // Remove selected item and select next item + if(~$selectMultiple.activeMatchIndex){ + $selectMultiple.removeChoice($selectMultiple.activeMatchIndex); + return curr; + } + else return false; + } + } - // Handles selected options in "multiple" mode - function _handleMatchSelection(key) { - var caretPosition = _getCaretPosition($select.searchInput[0]), - length = $select.selected.length, - first = 0, - last = length - 1, - curr = $selectMultiple.activeMatchIndex, - next = $selectMultiple.activeMatchIndex + 1, - prev = $selectMultiple.activeMatchIndex - 1, - newIndex = curr; - - if (caretPosition > 0 || ($select.search.length && key == $select.KEY.RIGHT)) { - return false; - } + newIndex = getNewActiveMatchIndex(); - $select.close(); - - function getNewActiveMatchIndex() { - switch (key) { - case $select.KEY.LEFT: - // Select previous/first item - if (~$selectMultiple.activeMatchIndex) { - return prev; - } - // Select last item - else { - return last; - } - break; - case $select.KEY.RIGHT: - // Open drop-down - if (!~$selectMultiple.activeMatchIndex || curr === last) { - $select.activate(); - return false; - } - // Select next/last item - else { - return next; - } - break; - case $select.KEY.BACKSPACE: - // Remove selected item and select previous/first - if (~$selectMultiple.activeMatchIndex) { - $selectMultiple.removeChoice(curr); - return prev; - } - // Select last item - else { - return last; - } - break; - case $select.KEY.DELETE: - // Remove selected item and select next item - if (~$selectMultiple.activeMatchIndex) { - $selectMultiple.removeChoice($selectMultiple.activeMatchIndex); - return curr; - } - else { - return false; - } - } - } + if(!$select.selected.length || newIndex === false) $selectMultiple.activeMatchIndex = -1; + else $selectMultiple.activeMatchIndex = Math.min(last,Math.max(first,newIndex)); - newIndex = getNewActiveMatchIndex(); + return true; + } - if (!$select.selected.length || newIndex === false) { - $selectMultiple.activeMatchIndex = -1; - } - else { - $selectMultiple.activeMatchIndex = Math.min(last, Math.max(first, newIndex)); - } + $select.searchInput.on('keyup', function(e) { - return true; + if ( ! KEY.isVerticalMovement(e.which) ) { + scope.$evalAsync( function () { + $select.activeIndex = $select.taggingLabel === false ? -1 : 0; + }); + } + // Push a "create new" item into array if there is a search string + if ( $select.tagging.isActivated && $select.search.length > 0 ) { + + // return early with these keys + if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || KEY.isVerticalMovement(e.which) ) { + return; + } + // always reset the activeIndex to the first item when tagging + $select.activeIndex = $select.taggingLabel === false ? -1 : 0; + // taggingLabel === false bypasses all of this + if ($select.taggingLabel === false) return; + + var items = angular.copy( $select.items ); + var stashArr = angular.copy( $select.items ); + var newItem; + var item; + var hasTag = false; + var dupeIndex = -1; + var tagItems; + var tagItem; + + // case for object tagging via transform `$select.tagging.fct` function + if ( $select.tagging.fct !== undefined) { + tagItems = $select.$filter('filter')(items,{'isTag': true}); + if ( tagItems.length > 0 ) { + tagItem = tagItems[0]; } - - $select.searchInput.on('blur', function () { - $timeout(function () { - $selectMultiple.activeMatchIndex = -1; - }); + // remove the first element, if it has the `isTag` prop we generate a new one with each keyup, shaving the previous + if ( items.length > 0 && tagItem ) { + hasTag = true; + items = items.slice(1,items.length); + stashArr = stashArr.slice(1,stashArr.length); + } + newItem = $select.tagging.fct($select.search); + newItem.isTag = true; + // verify the the tag doesn't match the value of an existing item + if ( stashArr.filter( function (origItem) { return angular.equals( origItem, $select.tagging.fct($select.search) ); } ).length > 0 ) { + return; + } + newItem.isTag = true; + // handle newItem string and stripping dupes in tagging string context + } else { + // find any tagging items already in the $select.items array and store them + tagItems = $select.$filter('filter')(items,function (item) { + return item.match($select.taggingLabel); }); + if ( tagItems.length > 0 ) { + tagItem = tagItems[0]; + } + item = items[0]; + // remove existing tag item if found (should only ever be one tag item) + if ( item !== undefined && items.length > 0 && tagItem ) { + hasTag = true; + items = items.slice(1,items.length); + stashArr = stashArr.slice(1,stashArr.length); + } + newItem = $select.search+' '+$select.taggingLabel; + if ( _findApproxDupe($select.selected, $select.search) > -1 ) { + return; + } + // verify the the tag doesn't match the value of an existing item from + // the searched data set or the items already selected + if ( _findCaseInsensitiveDupe(stashArr.concat($select.selected)) ) { + // if there is a tag from prev iteration, strip it / queue the change + // and return early + if ( hasTag ) { + items = stashArr; + scope.$evalAsync( function () { + $select.activeIndex = 0; + $select.items = items; + }); + } + return; + } + if ( _findCaseInsensitiveDupe(stashArr) ) { + // if there is a tag from prev iteration, strip it + if ( hasTag ) { + $select.items = stashArr.slice(1,stashArr.length); + } + return; + } + } + if ( hasTag ) dupeIndex = _findApproxDupe($select.selected, newItem); + // dupe found, shave the first item + if ( dupeIndex > -1 ) { + items = items.slice(dupeIndex+1,items.length-1); + } else { + items = []; + items.push(newItem); + items = items.concat(stashArr); + } + scope.$evalAsync( function () { + $select.activeIndex = 0; + $select.items = items; + }); + } + }); + function _findCaseInsensitiveDupe(arr) { + if ( arr === undefined || $select.search === undefined ) { + return false; + } + var hasDupe = arr.filter( function (origItem) { + if ( $select.search.toUpperCase() === undefined || origItem === undefined ) { + return false; + } + return origItem.toUpperCase() === $select.search.toUpperCase(); + }).length > 0; + + return hasDupe; + } + function _findApproxDupe(haystack, needle) { + var dupeIndex = -1; + if(angular.isArray(haystack)) { + var tempArr = angular.copy(haystack); + for (var i = 0; i model + ngModel.$parsers.unshift(function (inputValue) { + var locals = {}, + result; + locals[$select.parserResult.itemName] = inputValue; + result = $select.parserResult.modelMapper(scope, locals); + return result; + }); + + //From model --> view + ngModel.$formatters.unshift(function (inputValue) { + var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search + locals = {}, + result; + if (data){ + var checkFnSingle = function(d){ + locals[$select.parserResult.itemName] = d; + result = $select.parserResult.modelMapper(scope, locals); + return result == inputValue; + }; + //If possible pass same object stored in $select.selected + if ($select.selected && checkFnSingle($select.selected)) { + return $select.selected; + } + for (var i = data.length - 1; i >= 0; i--) { + if (checkFnSingle(data[i])) return data[i]; + } } - }; + return inputValue; + }); + + //Update viewValue if model change + scope.$watch('$select.selected', function(newValue) { + if (ngModel.$viewValue !== newValue) { + ngModel.$setViewValue(newValue); + } + }); + + ngModel.$render = function() { + $select.selected = ngModel.$viewValue; + }; + + scope.$on('uis:select', function (event, item) { + $select.selected = item; + }); + + scope.$on('uis:close', function (event, skipFocusser) { + $timeout(function(){ + $select.focusser.prop('disabled', false); + if (!skipFocusser) $select.focusser[0].focus(); + },0,false); + }); + + scope.$on('uis:activate', function () { + focusser.prop('disabled', true); //Will reactivate it on .close() + }); + + //Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954 + var focusser = angular.element(""); + $compile(focusser)(scope); + $select.focusser = focusser; + + //Input that will handle focus + $select.focusInput = focusser; + + element.parent().append(focusser); + focusser.bind("focus", function(){ + scope.$evalAsync(function(){ + $select.focus = true; + }); + }); + focusser.bind("blur", function(){ + scope.$evalAsync(function(){ + $select.focus = false; + }); + }); + focusser.bind("keydown", function(e){ + + if (e.which === KEY.BACKSPACE) { + e.preventDefault(); + e.stopPropagation(); + $select.select(undefined); + scope.$apply(); + return; + } + + if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) { + return; + } + + if (e.which == KEY.DOWN || e.which == KEY.UP || e.which == KEY.ENTER || e.which == KEY.SPACE){ + e.preventDefault(); + e.stopPropagation(); + $select.activate(); + } + + scope.$digest(); + }); + + focusser.bind("keyup input", function(e){ + + if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { + return; + } + + $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input + focusser.val(''); + scope.$digest(); + + }); + + + } + }; }]); +// Make multiple matches sortable +uis.directive('uiSelectSort', ['$timeout', 'uiSelectConfig', 'uiSelectMinErr', function($timeout, uiSelectConfig, uiSelectMinErr) { + return { + require: '^uiSelect', + link: function(scope, element, attrs, $select) { + if (scope[attrs.uiSelectSort] === null) { + throw uiSelectMinErr('sort', "Expected a list to sort"); + } + + var options = angular.extend({ + axis: 'horizontal' + }, + scope.$eval(attrs.uiSelectSortOptions)); + + var axis = options.axis, + draggingClassName = 'dragging', + droppingClassName = 'dropping', + droppingBeforeClassName = 'dropping-before', + droppingAfterClassName = 'dropping-after'; + + scope.$watch(function(){ + return $select.sortable; + }, function(n){ + if (n) { + element.attr('draggable', true); + } else { + element.removeAttr('draggable'); + } + }); -uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $compile) { - return { - restrict: 'EA', - require: ['^uiSelect', '^ngModel'], - link: function (scope, element, attrs, ctrls) { - - var $select = ctrls[0]; - var ngModel = ctrls[1]; - - // From view --> model - ngModel.$parsers.unshift(function (inputValue) { - var locals = {}, - result; - locals[$select.parserResult.itemName] = inputValue; - result = $select.parserResult.modelMapper(scope, locals); - return result; - }); + element.on('dragstart', function(e) { + element.addClass(draggingClassName); - // From model --> view - ngModel.$formatters.unshift(function (inputValue) { - var data = $select.parserResult.source(scope, {$select: {search: ''}}), //Overwrite $search - locals = {}, - result; - if (data) { - var checkFnSingle = function (d) { - locals[$select.parserResult.itemName] = d; - result = $select.parserResult.modelMapper(scope, locals); - return result == inputValue; - }; - // If possible pass same object stored in $select.selected - if ($select.selected && checkFnSingle($select.selected)) { - return $select.selected; - } - for (var i = data.length - 1; i >= 0; i--) { - if (checkFnSingle(data[i])) { - return data[i]; - } - } - } - return inputValue; - }); + (e.dataTransfer || e.originalEvent.dataTransfer).setData('text/plain', scope.$index); + }); - // Update viewValue if model change - scope.$watch('$select.selected', function (newValue) { - if (ngModel.$viewValue !== newValue) { - ngModel.$setViewValue(newValue); - } - }); + element.on('dragend', function() { + element.removeClass(draggingClassName); + }); - ngModel.$render = function () { - $select.selected = ngModel.$viewValue; - }; + var move = function(from, to) { + /*jshint validthis: true */ + this.splice(to, 0, this.splice(from, 1)[0]); + }; - scope.$on('uis:select', function (event, item) { - $select.selected = item; - }); + var dragOverHandler = function(e) { + e.preventDefault(); - scope.$on('uis:close', function (event, skipFocusser) { - $timeout(function () { - $select.focusser.prop('disabled', false); - if (!skipFocusser) $select.focusser[0].focus(); - }, 0, false); - }); + var offset = axis === 'vertical' ? e.offsetY || e.layerY || (e.originalEvent ? e.originalEvent.offsetY : 0) : e.offsetX || e.layerX || (e.originalEvent ? e.originalEvent.offsetX : 0); - scope.$on('uis:activate', function () { - // Will reactivate it on .close() - focusser.prop('disabled', true); - }); + if (offset < (this[axis === 'vertical' ? 'offsetHeight' : 'offsetWidth'] / 2)) { + element.removeClass(droppingAfterClassName); + element.addClass(droppingBeforeClassName); - // Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954 - var focusser = angular.element(""); - $compile(focusser)(scope); - $select.focusser = focusser; + } else { + element.removeClass(droppingBeforeClassName); + element.addClass(droppingAfterClassName); + } + }; + + var dropTimeout; + + var dropHandler = function(e) { + e.preventDefault(); + + var droppedItemIndex = parseInt((e.dataTransfer || e.originalEvent.dataTransfer).getData('text/plain'), 10); + + // prevent event firing multiple times in firefox + $timeout.cancel(dropTimeout); + dropTimeout = $timeout(function() { + _dropHandler(droppedItemIndex); + }, 20); + }; + + var _dropHandler = function(droppedItemIndex) { + var theList = scope.$eval(attrs.uiSelectSort), + itemToMove = theList[droppedItemIndex], + newIndex = null; + + if (element.hasClass(droppingBeforeClassName)) { + if (droppedItemIndex < scope.$index) { + newIndex = scope.$index - 1; + } else { + newIndex = scope.$index; + } + } else { + if (droppedItemIndex < scope.$index) { + newIndex = scope.$index; + } else { + newIndex = scope.$index + 1; + } + } - // Input that will handle focus - $select.focusInput = focusser; + move.apply(theList, [droppedItemIndex, newIndex]); - element.parent().append(focusser); - focusser.bind("focus", function () { - scope.$evalAsync(function () { - $select.focus = true; - }); - }); - focusser.bind("blur", function () { - scope.$evalAsync(function () { - $select.focus = false; - }); - }); + scope.$apply(function() { + scope.$emit('uiSelectSort:change', { + array: theList, + item: itemToMove, + from: droppedItemIndex, + to: newIndex + }); + }); - focusser.bind("keydown", function (e) { - if (e.which === $select.KEY.BACKSPACE) { - e.preventDefault(); - e.stopPropagation(); - $select.select(undefined); - scope.$apply(); - return; - } + element.removeClass(droppingClassName); + element.removeClass(droppingBeforeClassName); + element.removeClass(droppingAfterClassName); - if (e.which === $select.KEY.TAB || $select.KEY.isControl(e) || $select.KEY.isFunctionKey(e) || e.which === $select.KEY.ESC) { - return; - } + element.off('drop', dropHandler); + }; - if (e.which == $select.KEY.DOWN || e.which == $select.KEY.UP || e.which == $select.KEY.ENTER || e.which == $select.KEY.SPACE) { - e.preventDefault(); - e.stopPropagation(); - $select.activate(); - } + element.on('dragenter', function() { + if (element.hasClass(draggingClassName)) { + return; + } - scope.$digest(); - }); + element.addClass(droppingClassName); - focusser.bind("keyup input", function (e) { - if (e.which === $select.KEY.TAB || $select.KEY.isControl(e) || $select.KEY.isFunctionKey(e) || e.which === $select.KEY.ESC || - e.which == $select.KEY.ENTER || e.which === $select.KEY.BACKSPACE) { - return; - } + element.on('dragover', dragOverHandler); + element.on('drop', dropHandler); + }); - // User pressed some regular key, so we pass it to the search input - $select.activate(focusser.val()); - focusser.val(''); - scope.$digest(); - }); + element.on('dragleave', function(e) { + if (e.target != element) { + return; } - }; + element.removeClass(droppingClassName); + element.removeClass(droppingBeforeClassName); + element.removeClass(droppingAfterClassName); + + element.off('dragover', dragOverHandler); + element.off('drop', dropHandler); + }); + } + }; }]); + /** * Parses "repeat" attribute. * @@ -2060,59 +1759,58 @@ uis.directive('uiSelectSingle', ['$timeout', '$compile', function ($timeout, $co * https://github.com/angular-ui/ui-select/commit/5dd63ad#commitcomment-5504697 */ -uis.service('uisRepeatParser', ['uiSelectMinErr', '$parse', function (uiSelectMinErr, $parse) { - var self = this; +uis.service('uisRepeatParser', ['uiSelectMinErr','$parse', function(uiSelectMinErr, $parse) { + var self = this; - /** - * Example: - * expression = "address in addresses | filter: {street: $select.search} track by $index" - * itemName = "address", - * source = "addresses | filter: {street: $select.search}", - * trackByExp = "$index", - */ - self.parse = function (expression) { + /** + * Example: + * expression = "address in addresses | filter: {street: $select.search} track by $index" + * itemName = "address", + * source = "addresses | filter: {street: $select.search}", + * trackByExp = "$index", + */ + self.parse = function(expression) { - var match = expression.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/); - - if (!match) { - throw uiSelectMinErr('iexp', - "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.", - expression); - } + var match = expression.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/); - return { - itemName: match[2], // (lhs) Left-hand side, - source: $parse(match[3]), - trackByExp: match[4], - modelMapper: $parse(match[1] || match[2]) - }; + if (!match) { + throw uiSelectMinErr('iexp', "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.", + expression); + } + return { + itemName: match[2], // (lhs) Left-hand side, + source: $parse(match[3]), + trackByExp: match[4], + modelMapper: $parse(match[1] || match[2]) }; - self.getGroupNgRepeatExpression = function () { - return '$group in $select.groups'; - }; + }; - self.getNgRepeatExpression = function (itemName, source, trackByExp, grouped) { - var expression = itemName + ' in ' + (grouped ? '$group.items' : source); - if (trackByExp) { - expression += ' track by ' + trackByExp; - } - return expression; - }; + self.getGroupNgRepeatExpression = function() { + return '$group in $select.groups'; + }; + + self.getNgRepeatExpression = function(itemName, source, trackByExp, grouped) { + var expression = itemName + ' in ' + (grouped ? '$group.items' : source); + if (trackByExp) { + expression += ' track by ' + trackByExp; + } + return expression; + }; }]); }()); -angular.module("ui.select").run(["$templateCache", function($templateCache) {$templateCache.put("selectize/choices.tpl.html","
    "); -$templateCache.put("selectize/match.tpl.html","
    "); -$templateCache.put("selectize/select.tpl.html","
    ");}]); angular.module("ui.select").run(["$templateCache", function($templateCache) {$templateCache.put("bootstrap/choices.tpl.html","
      0\">
    • 0\">
    "); $templateCache.put("bootstrap/match-multiple.tpl.html"," × "); -$templateCache.put("bootstrap/match.tpl.html","
    {{$select.placeholder}}
    "); +$templateCache.put("bootstrap/match.tpl.html","
    {{$select.placeholder}}
    "); $templateCache.put("bootstrap/select-multiple.tpl.html","
    "); -$templateCache.put("bootstrap/select.tpl.html","
    ");}]); -angular.module("ui.select").run(["$templateCache", function($templateCache) {$templateCache.put("select2/choices.tpl.html","
    "); +$templateCache.put("bootstrap/select.tpl.html","
    "); +$templateCache.put("select2/choices.tpl.html","
    "); $templateCache.put("select2/match-multiple.tpl.html","
  • "); $templateCache.put("select2/match.tpl.html","{{$select.placeholder}} "); $templateCache.put("select2/select-multiple.tpl.html","
    "); -$templateCache.put("select2/select.tpl.html","
    ");}]); \ No newline at end of file +$templateCache.put("select2/select.tpl.html","
    "); +$templateCache.put("selectize/choices.tpl.html","
    "); +$templateCache.put("selectize/match.tpl.html","
    "); +$templateCache.put("selectize/select.tpl.html","
    ");}]); \ No newline at end of file diff --git a/dist/select.min.css b/dist/select.min.css index 34ce51d03..31d2e6935 100644 --- a/dist/select.min.css +++ b/dist/select.min.css @@ -1,6 +1,6 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-11T18:41:59.534Z + * Version: 0.12.1 - 2015-07-28T03:50:59.080Z * License: MIT - */.ui-select-highlight{font-weight:700}.ui-select-offscreen{clip:rect(0 0 0 0)!important;width:1px!important;height:1px!important;border:0!important;margin:0!important;padding:0!important;overflow:hidden!important;position:absolute!important;outline:0!important;left:0!important;top:0!important}.ng-dirty.ng-invalid>a.select2-choice{border-color:#D44950}.select2-result-single{padding-left:0}.select-locked>.ui-select-match-close,.select2-locked>.select2-search-choice-close{display:none}body>.select2-container.open{z-index:9999}.ui-select-container[theme=select2].direction-up .ui-select-match{border-radius:0 0 4px 4px}.ui-select-container[theme=select2].direction-up .ui-select-dropdown{bottom:100%;top:auto;position:absolute;border-radius:4px 4px 0 0;border-top-width:1px;border-top-style:solid;box-shadow:0 -4px 8px rgba(0,0,0,.25);margin-top:-4px}.ui-select-container[theme=select2].direction-up .ui-select-dropdown .select2-search{margin-top:4px}.ui-select-container[theme=select2].direction-up.select2-dropdown-open .ui-select-match{border-bottom-color:#5897fb}.selectize-input.selectize-focus{border-color:#007FBB!important}.selectize-control>.selectize-dropdown,.selectize-control>.selectize-input>input{width:100%}.ng-dirty.ng-invalid>div.selectize-input{border-color:#D44950}.ui-select-container[theme=selectize].direction-up .ui-select-dropdown{bottom:100%;top:auto;position:absolute;box-shadow:0 -4px 8px rgba(0,0,0,.25);margin-top:-2px}.btn-default-focus{color:#333;background-color:#EBEBEB;border-color:#ADADAD;text-decoration:none;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.ui-select-bootstrap .ui-select-toggle{position:relative}.ui-select-bootstrap .ui-select-toggle>.caret{position:absolute;height:10px;top:50%;right:10px;margin-top:-2px}.input-group>.ui-select-bootstrap.dropdown{position:static}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control{border-radius:4px 0 0 4px}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control.direction-up{border-radius:4px 0 0 4px!important}.ui-select-bootstrap>.ui-select-match>.btn{text-align:left!important}.ui-select-bootstrap>.ui-select-match>.caret{position:absolute;top:45%;right:15px}.ui-select-bootstrap>.ui-select-choices{width:100%;height:auto;max-height:200px;overflow-x:hidden;margin-top:-1px}body>.ui-select-bootstrap.open{z-index:1000}.ui-select-multiple.ui-select-bootstrap{height:auto;padding:3px 3px 0}.ui-select-multiple.ui-select-bootstrap input.ui-select-search{background-color:transparent!important;border:none;outline:0;height:1.666666em;margin-bottom:3px}.ui-select-multiple.ui-select-bootstrap .ui-select-match .close{font-size:1.6em;line-height:.75}.ui-select-multiple.ui-select-bootstrap .ui-select-match-item{outline:0;margin:0 3px 3px 0}.ui-select-multiple .ui-select-match-item{position:relative}.ui-select-multiple .ui-select-match-item.dropping-before:before{content:"";position:absolute;top:0;right:100%;height:100%;margin-right:2px;border-left:1px solid #428bca}.ui-select-multiple .ui-select-match-item.dropping-after:after{content:"";position:absolute;top:0;left:100%;height:100%;margin-left:2px;border-right:1px solid #428bca}.ui-select-bootstrap .ui-select-placeholder{opacity:1;color:#999}.ui-select-bootstrap .ui-select-choices-row>a{display:block;padding:3px 20px;clear:both;font-weight:400;line-height:1.42857143;color:#333;white-space:nowrap}.ui-select-bootstrap .ui-select-choices-row>a:focus,.ui-select-bootstrap .ui-select-choices-row>a:hover{text-decoration:none;color:#262626;background-color:#f5f5f5}.ui-select-bootstrap .ui-select-choices-row.active>a{color:#fff;text-decoration:none;outline:0;background-color:#428bca}.ui-select-bootstrap .ui-select-choices-row.active.disabled>a,.ui-select-bootstrap .ui-select-choices-row.disabled>a{color:#777;cursor:not-allowed;background-color:#fff}.ui-select-match.ng-hide-add,.ui-select-search.ng-hide-add{display:none!important}.ui-select-bootstrap.ng-dirty.ng-invalid>button.btn.ui-select-match{border-color:#D44950}.ui-select-container[theme=bootstrap].direction-up .ui-select-dropdown{bottom:100%;top:auto;position:absolute;box-shadow:0 -4px 8px rgba(0,0,0,.25)} \ No newline at end of file + */.ui-select-highlight{font-weight:700}.ui-select-offscreen{clip:rect(0 0 0 0)!important;width:1px!important;height:1px!important;border:0!important;margin:0!important;padding:0!important;overflow:hidden!important;position:absolute!important;outline:0!important;left:0!important;top:0!important}.ng-dirty.ng-invalid>a.select2-choice{border-color:#D44950}.select2-result-single{padding-left:0}.select-locked>.ui-select-match-close,.select2-locked>.select2-search-choice-close{display:none}body>.select2-container.open{z-index:9999}.ui-select-container[theme=select2].direction-up .ui-select-match{border-radius:0 0 4px 4px}.ui-select-container[theme=select2].direction-up .ui-select-dropdown{border-radius:4px 4px 0 0;border-top-width:1px;border-top-style:solid;box-shadow:0 -4px 8px rgba(0,0,0,.25);margin-top:-4px}.ui-select-container[theme=select2].direction-up .ui-select-dropdown .select2-search{margin-top:4px}.ui-select-container[theme=select2].direction-up.select2-dropdown-open .ui-select-match{border-bottom-color:#5897fb}.selectize-input.selectize-focus{border-color:#007FBB!important}.selectize-control>.selectize-dropdown,.selectize-control>.selectize-input>input{width:100%}.ng-dirty.ng-invalid>div.selectize-input{border-color:#D44950}.ui-select-container[theme=selectize].direction-up .ui-select-dropdown{box-shadow:0 -4px 8px rgba(0,0,0,.25);margin-top:-2px}.btn-default-focus{color:#333;background-color:#EBEBEB;border-color:#ADADAD;text-decoration:none;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.ui-select-bootstrap .ui-select-toggle{position:relative}.ui-select-bootstrap .ui-select-toggle>.caret{position:absolute;height:10px;top:50%;right:10px;margin-top:-2px}.input-group>.ui-select-bootstrap.dropdown{position:static}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control{border-radius:4px 0 0 4px}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control.direction-up{border-radius:4px 0 0 4px!important}.ui-select-bootstrap>.ui-select-match>.btn{text-align:left!important}.ui-select-bootstrap>.ui-select-match>.caret{position:absolute;top:45%;right:15px}.ui-select-bootstrap>.ui-select-choices{width:100%;height:auto;max-height:200px;overflow-x:hidden;margin-top:-1px}body>.ui-select-bootstrap.open{z-index:1000}.ui-select-multiple.ui-select-bootstrap{height:auto;padding:3px 3px 0}.ui-select-multiple.ui-select-bootstrap input.ui-select-search{background-color:transparent!important;border:none;outline:0;height:1.666666em;margin-bottom:3px}.ui-select-multiple.ui-select-bootstrap .ui-select-match .close{font-size:1.6em;line-height:.75}.ui-select-multiple.ui-select-bootstrap .ui-select-match-item{outline:0;margin:0 3px 3px 0}.ui-select-multiple .ui-select-match-item{position:relative}.ui-select-multiple .ui-select-match-item.dropping-before:before{content:"";position:absolute;top:0;right:100%;height:100%;margin-right:2px;border-left:1px solid #428bca}.ui-select-multiple .ui-select-match-item.dropping-after:after{content:"";position:absolute;top:0;left:100%;height:100%;margin-left:2px;border-right:1px solid #428bca}.ui-select-bootstrap .ui-select-choices-row>a{display:block;padding:3px 20px;clear:both;font-weight:400;line-height:1.42857143;color:#333;white-space:nowrap}.ui-select-bootstrap .ui-select-choices-row>a:focus,.ui-select-bootstrap .ui-select-choices-row>a:hover{text-decoration:none;color:#262626;background-color:#f5f5f5}.ui-select-bootstrap .ui-select-choices-row.active>a{color:#fff;text-decoration:none;outline:0;background-color:#428bca}.ui-select-bootstrap .ui-select-choices-row.active.disabled>a,.ui-select-bootstrap .ui-select-choices-row.disabled>a{color:#777;cursor:not-allowed;background-color:#fff}.ui-select-match.ng-hide-add,.ui-select-search.ng-hide-add{display:none!important}.ui-select-bootstrap.ng-dirty.ng-invalid>button.btn.ui-select-match{border-color:#D44950}.ui-select-container[theme=bootstrap].direction-up .ui-select-dropdown{box-shadow:0 -4px 8px rgba(0,0,0,.25)} \ No newline at end of file diff --git a/dist/select.min.js b/dist/select.min.js index 0e5a5dec6..3e7e81052 100644 --- a/dist/select.min.js +++ b/dist/select.min.js @@ -1,8 +1,8 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-11T18:41:59.532Z + * Version: 0.12.1 - 2015-07-28T03:50:59.076Z * License: MIT */ -!function(){"use strict";angular.module("ui.select.sort",["ui.select"]).directive("uiSelectSort",["$timeout","uiSelectConfig","uiSelectMinErr",function(e,t,c){return{require:"^uiSelect",link:function(t,l,s,i){if(null===t[s.uiSelectSort])throw c("sort","Expected a list to sort");var n=angular.extend({axis:"horizontal"},t.$eval(s.uiSelectSortOptions)),a=n.axis,r="dragging",o="dropping",u="dropping-before",d="dropping-after";t.$watch(function(){return i.sortable},function(e){e?l.attr("draggable",!0):l.removeAttr("draggable")}),l.on("dragstart",function(e){l.addClass(r),(e.dataTransfer||e.originalEvent.dataTransfer).setData("text/plain",t.$index)}),l.on("dragend",function(){l.removeClass(r)});var p,h=function(e,t){this.splice(t,0,this.splice(e,1)[0])},f=function(e){e.preventDefault();var t="vertical"===a?e.offsetY||e.layerY||(e.originalEvent?e.originalEvent.offsetY:0):e.offsetX||e.layerX||(e.originalEvent?e.originalEvent.offsetX:0);t0}function i(e,t){var c=-1;if(angular.isArray(e))for(var s=angular.copy(e),i=0;i0){var c=t.split(n.taggingTokens[0]);c&&c.length>0&&(angular.forEach(c,function(e){if(null!==e&&0!==e.length){var t=n.beforeTagging(e);t&&n.select(t,!0)}}),e.preventDefault(),e.stopPropagation())}}),n.beforeTagging=function(e){return e},n.afterKeypress=function(t){if(l.search.length>0){if(t.which===n.KEY.TAB||n.KEY.isControl(t)||n.KEY.isFunctionKey(t)||t.which===n.KEY.ESC||n.KEY.isVerticalMovement(t.which))return;for(var c=0;c0)return l.search.substr(l.search.length-1)==n.KEY.MAP[t.keyCode]&&(l.search=l.search.substr(0,l.search.length-1)),n.select(n.beforeTagging(l.search)),void 0;if(l.activeIndex=l.taggingLabel===!1?-1:0,l.taggingLabel===!1)return;var a,r,o,u,d=angular.copy(l.items),p=angular.copy(l.items),h=!1,f=-1;if(o=l.$filter("filter")(d,function(e){return e.match(l.taggingLabel)}),o.length>0&&(u=o[0]),r=d[0],void 0!==r&&d.length>0&&u&&(h=!0,d=d.slice(1,d.length),p=p.slice(1,p.length)),a=l.search+" "+l.taggingLabel,i(l.selected,l.search)>-1)return;if(s(p.concat(l.selected)))return h&&(d=p,e.$evalAsync(function(){l.activeIndex=0,l.items=d})),void 0;if(s(p))return h&&(l.items=p.slice(1,p.length)),void 0;h&&(f=i(l.selected,a)),f>-1?d=d.slice(f+1,d.length-1):(d=[],d.push(a),d=d.concat(p)),e.$evalAsync(function(){l.activeIndex=0,l.items=d})}}}}}])}(),function(){"use strict";void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],c=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(c.bind(t)(e))return t;t=t.parentElement}return!1});var e=0,t=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return e++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,l,s){s(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return t=String(t),c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(c){var l=c[0].getBoundingClientRect();return{width:l.width||c.prop("offsetWidth"),height:l.height||c.prop("offsetHeight"),top:l.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:l.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);t.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,c,l){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(e,s){if(!s.repeat)throw c("repeat","Expected 'repeat' expression.");return function(e,s,i,n,a){var r=i.groupBy,o=i.groupFilter;if(n.parseRepeatAttr(i.repeat,r,o),n.disableChoiceExpression=i.uiDisableChoice,n.onHighlightCallback=i.onHighlight,r){var u=s.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=s.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(n.parserResult.itemName,"$select.items",n.parserResult.trackByExp,r)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+n.parserResult.itemName+")").attr("ng-click","$select.select("+n.parserResult.itemName+",false,$event)");var p=s.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),l(s,a)(e),e.$watch("$select.search",function(e){e&&!n.open&&n.multiple&&n.activate(!1,!0),n.activeIndex=0})}}}}]),t.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(e,t,c,l,s,i,n,a){function r(){(p.resetSearchInput||void 0===p.resetSearchInput&&a.resetSearchInput)&&(p.search=h,p.selected&&p.items.length&&!p.multiple&&(p.activeIndex=p.items.indexOf(p.selected)))}function o(e,t){var c,l,s=[];for(c=0;c0&&p.activeIndex--;break;case p.KEY.TAB:(!p.multiple||p.open)&&p.select(p.items[p.activeIndex],!0);break;case p.KEY.ENTER:p.open?void 0!==p.items[p.activeIndex]&&p.select(p.items[p.activeIndex]):p.activate(!1,!0);break;case p.KEY.ESC:p.close();break;default:t=!1}return t}function d(){var e=t.querySelectorAll(".ui-select-choices-content"),c=e.querySelectorAll(".ui-select-choices-row");if(c.length<1)throw n("choices","Expected multiple .ui-select-choices-row but got '{0}'.",c.length);if(!(p.activeIndex<0)){var l=c[p.activeIndex],s=l.offsetTop+l.clientHeight-e[0].scrollTop,i=e[0].offsetHeight;s>i?e[0].scrollTop+=s-i:s=112&&123>=e},isVerticalMovement:function(e){return~[p.KEY.UP,p.KEY.DOWN].indexOf(e)},isHorizontalMovement:function(e){return~[p.KEY.LEFT,p.KEY.RIGHT,p.KEY.BACKSPACE,p.KEY.DELETE].indexOf(e)}},p.isEmpty=function(){return angular.isUndefined(p.selected)||null===p.selected||""===p.selected},p.findGroupByName=function(e){return p.groups&&p.groups.filter(function(t){return t.name===e})[0]},p.activate=function(t,l){if(p.disabled||p.open)p.open&&!p.searchEnabled&&p.close();else{var s=function(){l||r(),e.$broadcast("uis:activate"),p.open=!0,p.searchEnabled||angular.element(p.searchInput[0]).addClass("ui-select-offscreen"),p.activeIndex=p.activeIndex>=p.items.length?0:p.activeIndex,c(function(){p.search=t||p.search,p.searchInput[0].focus()})},i=p.beforeDropdownOpen();angular.isFunction(i.then)?i.then(function(e){e===!0&&s()}):i===!0&&s()}},p.parseRepeatAttr=function(t,c,l){function s(t){var s=e.$eval(c);if(p.groups=[],angular.forEach(t,function(e){var t=angular.isFunction(s)?s(e):e[s],c=p.findGroupByName(t);c?c.items.push(e):p.groups.push({name:t,items:[e]})}),l){var i=e.$eval(l);angular.isFunction(i)?p.groups=i(p.groups):angular.isArray(i)&&(p.groups=o(p.groups,i))}p.items=[],p.groups.forEach(function(e){p.items=p.items.concat(e.items)})}function a(e){p.items=e}p.setItemsFn=c?s:a,p.parserResult=i.parse(t),p.isGrouped=!!c,p.itemProperty=p.parserResult.itemName,p.refreshItems=function(t){t=t||p.parserResult.source(e);var c=p.selected;if(p.isEmpty()||angular.isArray(c)&&!c.length||!p.removeSelected)p.setItemsFn(t);else if(void 0!==t){var l=t.filter(function(e){return c.indexOf(e)<0});p.setItemsFn(l)}},e.$watchCollection(p.parserResult.source,function(e){if(void 0===e||null===e)p.items=[];else{if(!angular.isArray(e))throw n("items","Expected an array but got '{0}'.",e);p.refreshItems(e),p.ngModel.$modelValue=null}})},p.setActiveItem=function(e){p.activeIndex=p.items.indexOf(e)},p.isActive=function(e){if(!p.open)return!1;var t=p.items.indexOf(e[p.itemProperty]),c=-1===t?!1:t===p.activeIndex;return c},p.isDisabled=function(e){if(!p.open)return!1;var t,c=p.items.indexOf(e[p.itemProperty]),l=!1;return c>=0&&!angular.isUndefined(p.disableChoiceExpression)&&(t=p.items[c],l=!!e.$eval(p.disableChoiceExpression),t._uiSelectChoiceDisabled=l),l},p.select=function(t,l,s){function i(){e.$broadcast("uis:select",t),c(function(){p.afterSelect(t)}),p.closeOnSelect&&p.close(l),s&&"click"===s.type&&(p.clickTriggeredSelect=!0)}if((void 0===t||!t._uiSelectChoiceDisabled)&&(p.items||p.search)){var n=p.beforeSelect(t);angular.isFunction(n.then)?n.then(function(e){e&&(e===!0?i(t):e&&i(e))}):n===!0?i(t):n&&i(n)}},p.close=function(t){function c(){p.ngModel&&p.ngModel.$setTouched&&p.ngModel.$setTouched(),r(),p.open=!1,p.searchEnabled||angular.element(p.searchInput[0]).removeClass("ui-select-offscreen"),e.$broadcast("uis:close",t)}if(p.open){var l=p.beforeDropdownClose();angular.isFunction(l.then)?l.then(function(e){e===!0&&c()}):l===!0&&c()}},p.setFocus=function(){p.focus||p.focusInput[0].focus()},p.clear=function(e){p.select(void 0),e.stopPropagation(),c(function(){p.focusser[0].focus()},0,!1)},p.toggle=function(e){p.open?(p.close(),e.preventDefault(),e.stopPropagation()):p.activate()},p.isLocked=function(e,t){var c,l=p.selected[t];return l&&!angular.isUndefined(p.lockChoiceExpression)&&(c=!!e.$eval(p.lockChoiceExpression),l._uiSelectChoiceLocked=c),c};var f=null;p.sizeSearchInput=function(){var t=p.searchInput[0],l=p.searchInput.parent().parent()[0],s=function(){return l.clientWidth*!!t.offsetParent},i=function(e){if(0===e)return!1;var c=e-t.offsetLeft-p.searchInput.parent()[0].offsetLeft-5;return 50>c&&(c=e),p.searchInput.css("width",c+"px"),!0};p.searchInput.css("width","10px"),c(function(){null!==f||i(s())||(f=e.$watch(s,function(e){i(e)&&(f(),f=null)}))})},p.searchInput.on("keydown",function(t){var c=t.which;~[p.KEY.ESC,p.KEY.TAB].indexOf(c)&&p.close(),e.$apply(function(){u(c)}),p.KEY.isVerticalMovement(c)&&p.items.length>0&&d(),(c===p.KEY.ENTER||c===p.KEY.ESC)&&(t.preventDefault(),t.stopPropagation())}),p.searchInput.on("keyup",function(e){e.which===p.KEY.TAB||p.KEY.isControl(e)||p.KEY.isFunctionKey(e)||e.which===p.KEY.ESC||p.KEY.isVerticalMovement(e.which)||p.afterKeypress(e)}),e.$on("$destroy",function(){p.searchInput.off("keyup keydown blur paste")}),p.afterKeypress=function(){},p.beforeSelect=function(){return!0},p.afterSelect=function(){},p.beforeRemove=function(){return!0},p.afterRemove=function(){},p.beforeDropdownOpen=function(){return!0},p.beforeDropdownClose=function(){return!0}}]),t.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,c,l,s,i,n,a){return{restrict:"EA",templateUrl:function(e,t){var l=t.theme||c.theme;return l+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(i,r){return angular.isDefined(r.multiple)?i.append("").removeAttr("multiple"):i.append(""),function(i,r,o,u,d){function p(e){if(g.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(r[0],e.target):r[0].contains(e.target),!t&&!g.clickTriggeredSelect){var c=["input","button","textarea"],l=angular.element(e.target).controller("uiSelect"),s=l&&l!==g;s||(s=~c.indexOf(e.target.tagName.toLowerCase())),g.close(s),i.$digest()}g.clickTriggeredSelect=!1}}function h(){var t=s(r);E=angular.element('
    '),E[0].style.width=t.width+"px",E[0].style.height=t.height+"px",r.after(E),w=r[0].style.width,e.find("body").append(r),r[0].style.position="absolute",r[0].style.left=t.left+"px",r[0].style.top=t.top+"px",r[0].style.width=t.width+"px"}function f(){null!==E&&(E.replaceWith(r),E=null,r[0].style.position="",r[0].style.left="",r[0].style.top="",r[0].style.width=w)}var g=u[0],v=u[1];g.generatedId=c.generateId(),g.baseTitle=o.title||"Select box",g.focusserTitle=g.baseTitle+" focus",g.focusserId="focusser-"+g.generatedId,g.closeOnSelect=function(){return angular.isDefined(o.closeOnSelect)?n(o.closeOnSelect)():c.closeOnSelect}(),g.limit=angular.isDefined(o.limit)?parseInt(o.limit,10):void 0,g.ngModel=v,g.choiceGrouped=function(e){return g.isGrouped&&e&&e.name},o.tabindex&&o.$observe("tabindex",function(e){g.focusInput.attr("tabindex",e),r.removeAttr("tabindex")});var m=i.$eval(o.searchEnabled);g.searchEnabled=void 0!==m?m:c.searchEnabled;var $=i.$eval(o.sortable);g.sortable=void 0!==$?$:c.sortable,o.$observe("disabled",function(){g.disabled=void 0!==o.disabled?o.disabled:!1}),angular.isDefined(o.autofocus)&&a(function(){g.setFocus()}),angular.isDefined(o.focusOn)&&i.$on(o.focusOn,function(){a(function(){g.setFocus()})}),e.on("click",p),i.$on("$destroy",function(){e.off("click",p)}),d(i,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),c.removeAttr("data-ui-select-match"),1!==c.length)throw l("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);r.querySelectorAll(".ui-select-match").replaceWith(c);var s=t.querySelectorAll(".ui-select-choices");if(s.removeAttr("ui-select-choices"),s.removeAttr("data-ui-select-choices"),1!==s.length)throw l("transcluded","Expected 1 .ui-select-choices but got '{0}'.",s.length);r.querySelectorAll(".ui-select-choices").replaceWith(s)});var b=i.$eval(o.appendToBody);(void 0!==b?b:c.appendToBody)&&(i.$watch("$select.open",function(e){e?h():f()}),i.$on("$destroy",function(){f()}));var E=null,w="",x=null,y="direction-up";i.$watch("$select.open",function(c){if(c){if(x=angular.element(r).querySelectorAll(".ui-select-dropdown"),null===x)return;x[0].style.opacity=0,a(function(){var c=s(r),l=s(x);c.top+c.height+l.height>t.pageYOffset+e[0].documentElement.clientHeight&&r.addClass(y),x[0].style.opacity=1})}else{if(null===x)return;r.removeClass(y)}})}}}}]),t.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,l=t.parent().attr("multiple");return c+(l?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,l,s){function i(e){s.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}s.lockChoiceExpression=l.uiLockChoice,l.$observe("placeholder",function(t){s.placeholder=void 0!==t?t:e.placeholder}),l.$observe("allowClear",i),i(l.allowClear),s.multiple&&s.sizeSearchInput()}}}]),t.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var c,l=this,s=e.$select;e.$evalAsync(function(){c=e.ngModel}),l.activeMatchIndex=-1,l.updateModel=function(){c.$setViewValue(Date.now()),l.refreshComponent()},l.refreshComponent=function(){s.refreshItems(),s.sizeSearchInput()},l.removeChoice=function(e){function c(){s.selected.splice(e,1),l.activeMatchIndex=-1,s.sizeSearchInput(),t(function(){s.afterRemove(i)}),l.updateModel()}var i=s.selected[e];if(!i._uiSelectChoiceLocked){var n=s.beforeRemove(i);angular.isFunction(n.then)?n.then(function(e){e===!0&&c()}):n===!0&&c()}},l.getPlaceholder=function(){return s.selected&&s.selected.length?void 0:s.placeholder}}],controllerAs:"$selectMultiple",link:function(c,l,s,i){function n(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function a(e){function t(){switch(e){case r.KEY.LEFT:return~u.activeMatchIndex?d:i;case r.KEY.RIGHT:return~u.activeMatchIndex&&a!==i?o:(r.activate(),!1);case r.KEY.BACKSPACE:return~u.activeMatchIndex?(u.removeChoice(a),d):i;case r.KEY.DELETE:return~u.activeMatchIndex?(u.removeChoice(u.activeMatchIndex),a):!1}}var c=n(r.searchInput[0]),l=r.selected.length,s=0,i=l-1,a=u.activeMatchIndex,o=u.activeMatchIndex+1,d=u.activeMatchIndex-1,p=a;return c>0||r.search.length&&e==r.KEY.RIGHT?!1:(r.close(),p=t(),u.activeMatchIndex=r.selected.length&&p!==!1?Math.min(i,Math.max(s,p)):-1,!0)}var r=i[0],o=c.ngModel=i[1],u=c.$selectMultiple;r.multiple=!0,r.removeSelected=!0,r.focusInput=r.searchInput,o.$parsers.unshift(function(){for(var e,t={},l=[],s=r.selected.length-1;s>=0;s--)t={},t[r.parserResult.itemName]=r.selected[s],e=r.parserResult.modelMapper(c,t),l.unshift(e);return l}),o.$formatters.unshift(function(e){var t,l=r.parserResult.source(c,{$select:{search:""}}),s={};if(!l)return e;var i=[],n=function(e,l){if(e&&e.length){for(var n=e.length-1;n>=0;n--){if(s[r.parserResult.itemName]=e[n],t=r.parserResult.modelMapper(c,s),r.parserResult.trackByExp){var a=/\.(.+)/.exec(r.parserResult.trackByExp);if(a.length>0&&t[a[1]]==l[a[1]])return i.unshift(e[n]),!0}if(angular.equals(t,l))return i.unshift(e[n]),!0}return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(r.selected,e[a])||n(l,e[a])||i.unshift(e[a]);return i}),c.$watchCollection(function(){return o.$modelValue},function(e,t){t!=e&&(o.$modelValue=null,u.refreshComponent())}),o.$render=function(){if(!angular.isArray(o.$viewValue)){if(!angular.isUndefined(o.$viewValue)&&null!==o.$viewValue)throw e("multiarr","Expected model value to be array but got '{0}'",o.$viewValue);r.selected=[]}r.selected=o.$viewValue,c.$evalAsync()},c.$on("uis:select",function(e,t){r.selected.length>=r.limit||(r.selected.push(t),u.updateModel())}),c.$on("uis:activate",function(){u.activeMatchIndex=-1}),c.$watch("$select.disabled",function(e,t){t&&!e&&r.sizeSearchInput()}),r.searchInput.on("keydown",function(e){var t=e.which;c.$apply(function(){var e=!1;r.KEY.isHorizontalMovement(t)&&(e=a(t)),e&&t!=r.KEY.TAB})}),r.searchInput.on("blur",function(){t(function(){u.activeMatchIndex=-1})})}}}]),t.directive("uiSelectSingle",["$timeout","$compile",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(c,l,s,i){var n=i[0],a=i[1];a.$parsers.unshift(function(e){var t,l={};return l[n.parserResult.itemName]=e,t=n.parserResult.modelMapper(c,l)}),a.$formatters.unshift(function(e){var t,l=n.parserResult.source(c,{$select:{search:""}}),s={};if(l){var i=function(l){return s[n.parserResult.itemName]=l,t=n.parserResult.modelMapper(c,s),t==e};if(n.selected&&i(n.selected))return n.selected;for(var a=l.length-1;a>=0;a--)if(i(l[a]))return l[a]}return e}),c.$watch("$select.selected",function(e){a.$viewValue!==e&&a.$setViewValue(e)}),a.$render=function(){n.selected=a.$viewValue},c.$on("uis:select",function(e,t){n.selected=t}),c.$on("uis:close",function(t,c){e(function(){n.focusser.prop("disabled",!1),c||n.focusser[0].focus()},0,!1)}),c.$on("uis:activate",function(){r.prop("disabled",!0)});var r=angular.element("");t(r)(c),n.focusser=r,n.focusInput=r,l.parent().append(r),r.bind("focus",function(){c.$evalAsync(function(){n.focus=!0})}),r.bind("blur",function(){c.$evalAsync(function(){n.focus=!1})}),r.bind("keydown",function(e){return e.which===n.KEY.BACKSPACE?(e.preventDefault(),e.stopPropagation(),n.select(void 0),c.$apply(),void 0):(e.which===n.KEY.TAB||n.KEY.isControl(e)||n.KEY.isFunctionKey(e)||e.which===n.KEY.ESC||((e.which==n.KEY.DOWN||e.which==n.KEY.UP||e.which==n.KEY.ENTER||e.which==n.KEY.SPACE)&&(e.preventDefault(),e.stopPropagation(),n.activate()),c.$digest()),void 0)}),r.bind("keyup input",function(e){e.which===n.KEY.TAB||n.KEY.isControl(e)||n.KEY.isFunctionKey(e)||e.which===n.KEY.ESC||e.which==n.KEY.ENTER||e.which===n.KEY.BACKSPACE||(n.activate(r.val()),r.val(""),c.$digest())})}}}]),t.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var l=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!l)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:l[2],source:t(l[3]),trackByExp:l[4],modelMapper:t(l[1]||l[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,l){var s=e+" in "+(l?"$group.items":t);return c&&(s+=" track by "+c),s}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("selectize/choices.tpl.html",'
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",'
    {{$select.placeholder}}
    '),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",'')}]),angular.module("ui.select").run(["$templateCache",function(e){e.put("select2/choices.tpl.html",'
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    ') +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],c=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(c.bind(t)(e))return t;t=t.parentElement}return!1});var t=0,c=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",refreshDelay:1e3,closeOnSelect:!0,generateId:function(){return t++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,i,l){l(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(c){var i=c[0].getBoundingClientRect();return{width:i.width||c.prop("offsetWidth"),height:i.height||c.prop("offsetHeight"),top:i.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:i.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);c.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,c,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(l,s){if(!s.repeat)throw c("repeat","Expected 'repeat' expression.");return function(l,s,n,a,r){var o=n.groupBy,u=n.groupFilter;if(a.parseRepeatAttr(n.repeat,o,u),a.disableChoiceExpression=n.uiDisableChoice,a.onHighlightCallback=n.onHighlight,o){var d=s.querySelectorAll(".ui-select-choices-group");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",d.length);d.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=s.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(a.parserResult.itemName,"$select.items",a.parserResult.trackByExp,o)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+a.parserResult.itemName+")").attr("ng-click","$select.select("+a.parserResult.itemName+",false,$event)");var g=s.querySelectorAll(".ui-select-choices-row-inner");if(1!==g.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",g.length);g.attr("uis-transclude-append",""),i(s,r)(l),l.$watch("$select.search",function(e){e&&!a.open&&a.multiple&&a.activate(!1,!0),a.activeIndex=a.tagging.isActivated?-1:0,a.refresh(n.refresh)}),n.$observe("refreshDelay",function(){var t=l.$eval(n.refreshDelay);a.refreshDelay=void 0!==t?t:e.refreshDelay})}}}}]),c.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(t,c,i,l,s,n,a){function r(){(p.resetSearchInput||void 0===p.resetSearchInput&&a.resetSearchInput)&&(p.search=g,p.selected&&p.items.length&&!p.multiple&&(p.activeIndex=p.items.indexOf(p.selected)))}function o(e,t){var c,i,l=[];for(c=0;c0||0===p.search.length&&p.tagging.isActivated&&p.activeIndex>-1)&&p.activeIndex--;break;case e.TAB:(!p.multiple||p.open)&&p.select(p.items[p.activeIndex],!0);break;case e.ENTER:p.open&&(p.tagging.isActivated||p.activeIndex>=0)?p.select(p.items[p.activeIndex]):p.activate(!1,!0);break;case e.ESC:p.close();break;default:c=!1}return c}function d(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw n("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);if(!(p.activeIndex<0)){var i=t[p.activeIndex],l=i.offsetTop+i.clientHeight-e[0].scrollTop,s=e[0].offsetHeight;l>s?e[0].scrollTop+=l-s:l=p.items.length?0:p.activeIndex,-1===p.activeIndex&&p.taggingLabel!==!1&&(p.activeIndex=0),i(function(){p.search=e||p.search,p.searchInput[0].focus()}))},p.findGroupByName=function(e){return p.groups&&p.groups.filter(function(t){return t.name===e})[0]},p.parseRepeatAttr=function(e,c,i){function l(e){var l=t.$eval(c);if(p.groups=[],angular.forEach(e,function(e){var t=angular.isFunction(l)?l(e):e[l],c=p.findGroupByName(t);c?c.items.push(e):p.groups.push({name:t,items:[e]})}),i){var s=t.$eval(i);angular.isFunction(s)?p.groups=s(p.groups):angular.isArray(s)&&(p.groups=o(p.groups,s))}p.items=[],p.groups.forEach(function(e){p.items=p.items.concat(e.items)})}function a(e){p.items=e}p.setItemsFn=c?l:a,p.parserResult=s.parse(e),p.isGrouped=!!c,p.itemProperty=p.parserResult.itemName,p.refreshItems=function(e){e=e||p.parserResult.source(t);var c=p.selected;if(angular.isArray(c)&&!c.length||!p.removeSelected)p.setItemsFn(e);else if(void 0!==e){var i=e.filter(function(e){return c.indexOf(e)<0});p.setItemsFn(i)}},t.$watchCollection(p.parserResult.source,function(e){if(void 0===e||null===e)p.items=[];else{if(!angular.isArray(e))throw n("items","Expected an array but got '{0}'.",e);p.refreshItems(e),p.ngModel.$modelValue=null}})};var h;p.refresh=function(e){void 0!==e&&(h&&i.cancel(h),h=i(function(){t.$eval(e)},p.refreshDelay))},p.setActiveItem=function(e){p.activeIndex=p.items.indexOf(e)},p.isActive=function(e){if(!p.open)return!1;var t=p.items.indexOf(e[p.itemProperty]),c=t===p.activeIndex;return!c||0>t&&p.taggingLabel!==!1||0>t&&p.taggingLabel===!1?!1:(c&&!angular.isUndefined(p.onHighlightCallback)&&e.$eval(p.onHighlightCallback),c)},p.isDisabled=function(e){if(p.open){var t,c=p.items.indexOf(e[p.itemProperty]),i=!1;return c>=0&&!angular.isUndefined(p.disableChoiceExpression)&&(t=p.items[c],i=!!e.$eval(p.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i}},p.select=function(e,c,l){if(void 0===e||!e._uiSelectChoiceDisabled){if(!p.items&&!p.search)return;if(!e||!e._uiSelectChoiceDisabled){if(p.tagging.isActivated){if(p.taggingLabel===!1)if(p.activeIndex<0){if(e=void 0!==p.tagging.fct?p.tagging.fct(p.search):p.search,!e||angular.equals(p.items[0],e))return}else e=p.items[p.activeIndex];else if(0===p.activeIndex){if(void 0===e)return;if(void 0!==p.tagging.fct&&"string"==typeof e){if(e=p.tagging.fct(p.search),!e)return}else"string"==typeof e&&(e=e.replace(p.taggingLabel,"").trim())}if(p.selected&&angular.isArray(p.selected)&&p.selected.filter(function(t){return angular.equals(t,e)}).length>0)return p.close(c),void 0}t.$broadcast("uis:select",e);var s={};s[p.parserResult.itemName]=e,i(function(){p.onSelectCallback(t,{$item:e,$model:p.parserResult.modelMapper(t,s)})}),p.closeOnSelect&&p.close(c),l&&"click"===l.type&&(p.clickTriggeredSelect=!0)}}},p.close=function(e){p.open&&(p.ngModel&&p.ngModel.$setTouched&&p.ngModel.$setTouched(),r(),p.open=!1,t.$broadcast("uis:close",e))},p.setFocus=function(){p.focus||p.focusInput[0].focus()},p.clear=function(e){p.select(void 0),e.stopPropagation(),i(function(){p.focusser[0].focus()},0,!1)},p.toggle=function(e){p.open?(p.close(),e.preventDefault(),e.stopPropagation()):p.activate()},p.isLocked=function(e,t){var c,i=p.selected[t];return i&&!angular.isUndefined(p.lockChoiceExpression)&&(c=!!e.$eval(p.lockChoiceExpression),i._uiSelectChoiceLocked=c),c};var f=null;p.sizeSearchInput=function(){var e=p.searchInput[0],c=p.searchInput.parent().parent()[0],l=function(){return c.clientWidth*!!e.offsetParent},s=function(t){if(0===t)return!1;var c=t-e.offsetLeft-10;return 50>c&&(c=t),p.searchInput.css("width",c+"px"),!0};p.searchInput.css("width","10px"),i(function(){null!==f||s(l())||(f=t.$watch(l,function(e){s(e)&&(f(),f=null)}))})},p.searchInput.on("keydown",function(c){var l=c.which;t.$apply(function(){var t=!1;if((p.items.length>0||p.tagging.isActivated)&&(u(l),p.taggingTokens.isActivated)){for(var s=0;s0&&(t=!0);t&&i(function(){p.searchInput.triggerHandler("tagged");var t=p.search.replace(e.MAP[c.keyCode],"").trim();p.tagging.fct&&(t=p.tagging.fct(t)),t&&p.select(t,!0)})}}),e.isVerticalMovement(l)&&p.items.length>0&&d(),(l===e.ENTER||l===e.ESC)&&(c.preventDefault(),c.stopPropagation())}),p.searchInput.on("paste",function(e){var t=e.originalEvent.clipboardData.getData("text/plain");if(t&&t.length>0&&p.taggingTokens.isActivated&&p.tagging.fct){var c=t.split(p.taggingTokens.tokens[0]);c&&c.length>0&&(angular.forEach(c,function(e){var t=p.tagging.fct(e);t&&p.select(t,!0)}),e.preventDefault(),e.stopPropagation())}}),p.searchInput.on("tagged",function(){i(function(){r()})}),t.$on("$destroy",function(){p.searchInput.off("keyup keydown tagged blur paste")})}]),c.directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,c,i,l,s,n){return{restrict:"EA",templateUrl:function(e,c){var i=c.theme||t.theme;return i+(angular.isDefined(c.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(l,a){return angular.isDefined(a.multiple)?l.append("").removeAttr("multiple"):l.append(""),function(l,a,r,o,u){function d(e){if(h.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(a[0],e.target):a[0].contains(e.target),!t&&!h.clickTriggeredSelect){var c=["input","button","textarea"],i=angular.element(e.target).scope(),s=i&&i.$select&&i.$select!==h;s||(s=~c.indexOf(e.target.tagName.toLowerCase())),h.close(s),l.$digest()}h.clickTriggeredSelect=!1}}function p(){var t=i(a);m=angular.element('
    '),m[0].style.width=t.width+"px",m[0].style.height=t.height+"px",a.after(m),$=a[0].style.width,e.find("body").append(a),a[0].style.position="absolute",a[0].style.left=t.left+"px",a[0].style.top=t.top+"px",a[0].style.width=t.width+"px"}function g(){null!==m&&(m.replaceWith(a),m=null,a[0].style.position="",a[0].style.left="",a[0].style.top="",a[0].style.width=$)}var h=o[0],f=o[1];h.generatedId=t.generateId(),h.baseTitle=r.title||"Select box",h.focusserTitle=h.baseTitle+" focus",h.focusserId="focusser-"+h.generatedId,h.closeOnSelect=function(){return angular.isDefined(r.closeOnSelect)?s(r.closeOnSelect)():t.closeOnSelect}(),h.onSelectCallback=s(r.onSelect),h.onRemoveCallback=s(r.onRemove),h.ngModel=f,h.choiceGrouped=function(e){return h.isGrouped&&e&&e.name},r.tabindex&&r.$observe("tabindex",function(e){h.focusInput.attr("tabindex",e),a.removeAttr("tabindex")}),l.$watch("searchEnabled",function(){var e=l.$eval(r.searchEnabled);h.searchEnabled=void 0!==e?e:t.searchEnabled}),l.$watch("sortable",function(){var e=l.$eval(r.sortable);h.sortable=void 0!==e?e:t.sortable}),r.$observe("disabled",function(){h.disabled=void 0!==r.disabled?r.disabled:!1}),r.$observe("resetSearchInput",function(){var e=l.$eval(r.resetSearchInput);h.resetSearchInput=void 0!==e?e:!0}),r.$observe("tagging",function(){if(void 0!==r.tagging){var e=l.$eval(r.tagging);h.tagging={isActivated:!0,fct:e!==!0?e:void 0}}else h.tagging={isActivated:!1,fct:void 0}}),r.$observe("taggingLabel",function(){void 0!==r.tagging&&(h.taggingLabel="false"===r.taggingLabel?!1:void 0!==r.taggingLabel?r.taggingLabel:"(new)")}),r.$observe("taggingTokens",function(){if(void 0!==r.tagging){var e=void 0!==r.taggingTokens?r.taggingTokens.split("|"):[",","ENTER"];h.taggingTokens={isActivated:!0,tokens:e}}}),angular.isDefined(r.autofocus)&&n(function(){h.setFocus()}),angular.isDefined(r.focusOn)&&l.$on(r.focusOn,function(){n(function(){h.setFocus()})}),e.on("click",d),l.$on("$destroy",function(){e.off("click",d)}),u(l,function(e){var t=angular.element("
    ").append(e),i=t.querySelectorAll(".ui-select-match");if(i.removeAttr("ui-select-match"),i.removeAttr("data-ui-select-match"),1!==i.length)throw c("transcluded","Expected 1 .ui-select-match but got '{0}'.",i.length);a.querySelectorAll(".ui-select-match").replaceWith(i);var l=t.querySelectorAll(".ui-select-choices");if(l.removeAttr("ui-select-choices"),l.removeAttr("data-ui-select-choices"),1!==l.length)throw c("transcluded","Expected 1 .ui-select-choices but got '{0}'.",l.length);a.querySelectorAll(".ui-select-choices").replaceWith(l)});var v=l.$eval(r.appendToBody);(void 0!==v?v:t.appendToBody)&&(l.$watch("$select.open",function(e){e?p():g()}),l.$on("$destroy",function(){g()}));var m=null,$="",b=null,x="direction-up";l.$watch("$select.open",function(t){if(t){if(b=angular.element(a).querySelectorAll(".ui-select-dropdown"),null===b)return;b[0].style.opacity=0,n(function(){var t=i(a),c=i(b);t.top+t.height+c.height>e[0].documentElement.scrollTop+e[0].documentElement.clientHeight&&(b[0].style.position="absolute",b[0].style.top=-1*c.height+"px",a.addClass(x)),b[0].style.opacity=1})}else{if(null===b)return;b[0].style.position="",b[0].style.top="",a.removeClass(x)}})}}}}]),c.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return c+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,i,l){function s(e){l.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}l.lockChoiceExpression=i.uiLockChoice,i.$observe("placeholder",function(t){l.placeholder=void 0!==t?t:e.placeholder}),i.$observe("allowClear",s),s(i.allowClear),l.multiple&&l.sizeSearchInput()}}}]),c.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var c,i=this,l=e.$select;e.$evalAsync(function(){c=e.ngModel}),i.activeMatchIndex=-1,i.updateModel=function(){c.$setViewValue(Date.now()),i.refreshComponent()},i.refreshComponent=function(){l.refreshItems(),l.sizeSearchInput()},i.removeChoice=function(c){var s=l.selected[c];if(!s._uiSelectChoiceLocked){var n={};n[l.parserResult.itemName]=s,l.selected.splice(c,1),i.activeMatchIndex=-1,l.sizeSearchInput(),t(function(){l.onRemoveCallback(e,{$item:s,$model:l.parserResult.modelMapper(e,n)})}),i.updateModel()}},i.getPlaceholder=function(){return l.selected.length?void 0:l.placeholder}}],controllerAs:"$selectMultiple",link:function(i,l,s,n){function a(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function r(t){function c(){switch(t){case e.LEFT:return~g.activeMatchIndex?u:n;case e.RIGHT:return~g.activeMatchIndex&&r!==n?o:(d.activate(),!1);case e.BACKSPACE:return~g.activeMatchIndex?(g.removeChoice(r),u):n;case e.DELETE:return~g.activeMatchIndex?(g.removeChoice(g.activeMatchIndex),r):!1}}var i=a(d.searchInput[0]),l=d.selected.length,s=0,n=l-1,r=g.activeMatchIndex,o=g.activeMatchIndex+1,u=g.activeMatchIndex-1,p=r;return i>0||d.search.length&&t==e.RIGHT?!1:(d.close(),p=c(),g.activeMatchIndex=d.selected.length&&p!==!1?Math.min(n,Math.max(s,p)):-1,!0)}function o(e){if(void 0===e||void 0===d.search)return!1;var t=e.filter(function(e){return void 0===d.search.toUpperCase()||void 0===e?!1:e.toUpperCase()===d.search.toUpperCase()}).length>0;return t}function u(e,t){var c=-1;if(angular.isArray(e))for(var i=angular.copy(e),l=0;l=0;l--)t={},t[d.parserResult.itemName]=d.selected[l],e=d.parserResult.modelMapper(i,t),c.unshift(e);return c}),p.$formatters.unshift(function(e){var t,c=d.parserResult.source(i,{$select:{search:""}}),l={};if(!c)return e;var s=[],n=function(e,c){if(e&&e.length){for(var n=e.length-1;n>=0;n--){if(l[d.parserResult.itemName]=e[n],t=d.parserResult.modelMapper(i,l),d.parserResult.trackByExp){var a=/\.(.+)/.exec(d.parserResult.trackByExp);if(a.length>0&&t[a[1]]==c[a[1]])return s.unshift(e[n]),!0}if(angular.equals(t,c))return s.unshift(e[n]),!0}return!1}};if(!e)return s;for(var a=e.length-1;a>=0;a--)n(d.selected,e[a])||n(c,e[a])||s.unshift(e[a]);return s}),i.$watchCollection(function(){return p.$modelValue},function(e,t){t!=e&&(p.$modelValue=null,g.refreshComponent())}),p.$render=function(){if(!angular.isArray(p.$viewValue)){if(!angular.isUndefined(p.$viewValue)&&null!==p.$viewValue)throw t("multiarr","Expected model value to be array but got '{0}'",p.$viewValue);d.selected=[]}d.selected=p.$viewValue,i.$evalAsync()},i.$on("uis:select",function(e,t){d.selected.push(t),g.updateModel()}),i.$on("uis:activate",function(){g.activeMatchIndex=-1}),i.$watch("$select.disabled",function(e,t){t&&!e&&d.sizeSearchInput()}),d.searchInput.on("keydown",function(t){var c=t.which;i.$apply(function(){var i=!1;e.isHorizontalMovement(c)&&(i=r(c)),i&&c!=e.TAB&&(t.preventDefault(),t.stopPropagation())})}),d.searchInput.on("keyup",function(t){if(e.isVerticalMovement(t.which)||i.$evalAsync(function(){d.activeIndex=d.taggingLabel===!1?-1:0}),d.tagging.isActivated&&d.search.length>0){if(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||e.isVerticalMovement(t.which))return;if(d.activeIndex=d.taggingLabel===!1?-1:0,d.taggingLabel===!1)return;var c,l,s,n,a=angular.copy(d.items),r=angular.copy(d.items),p=!1,g=-1;if(void 0!==d.tagging.fct){if(s=d.$filter("filter")(a,{isTag:!0}),s.length>0&&(n=s[0]),a.length>0&&n&&(p=!0,a=a.slice(1,a.length),r=r.slice(1,r.length)),c=d.tagging.fct(d.search),c.isTag=!0,r.filter(function(e){return angular.equals(e,d.tagging.fct(d.search))}).length>0)return;c.isTag=!0}else{if(s=d.$filter("filter")(a,function(e){return e.match(d.taggingLabel)}),s.length>0&&(n=s[0]),l=a[0],void 0!==l&&a.length>0&&n&&(p=!0,a=a.slice(1,a.length),r=r.slice(1,r.length)),c=d.search+" "+d.taggingLabel,u(d.selected,d.search)>-1)return;if(o(r.concat(d.selected)))return p&&(a=r,i.$evalAsync(function(){d.activeIndex=0,d.items=a})),void 0;if(o(r))return p&&(d.items=r.slice(1,r.length)),void 0}p&&(g=u(d.selected,c)),g>-1?a=a.slice(g+1,a.length-1):(a=[],a.push(c),a=a.concat(r)),i.$evalAsync(function(){d.activeIndex=0,d.items=a})}}),d.searchInput.on("blur",function(){c(function(){g.activeMatchIndex=-1})})}}}]),c.directive("uiSelectSingle",["$timeout","$compile",function(t,c){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(i,l,s,n){var a=n[0],r=n[1];r.$parsers.unshift(function(e){var t,c={};return c[a.parserResult.itemName]=e,t=a.parserResult.modelMapper(i,c)}),r.$formatters.unshift(function(e){var t,c=a.parserResult.source(i,{$select:{search:""}}),l={};if(c){var s=function(c){return l[a.parserResult.itemName]=c,t=a.parserResult.modelMapper(i,l),t==e};if(a.selected&&s(a.selected))return a.selected;for(var n=c.length-1;n>=0;n--)if(s(c[n]))return c[n]}return e}),i.$watch("$select.selected",function(e){r.$viewValue!==e&&r.$setViewValue(e)}),r.$render=function(){a.selected=r.$viewValue},i.$on("uis:select",function(e,t){a.selected=t}),i.$on("uis:close",function(e,c){t(function(){a.focusser.prop("disabled",!1),c||a.focusser[0].focus()},0,!1)}),i.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");c(o)(i),a.focusser=o,a.focusInput=o,l.parent().append(o),o.bind("focus",function(){i.$evalAsync(function(){a.focus=!0})}),o.bind("blur",function(){i.$evalAsync(function(){a.focus=!1})}),o.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),a.select(void 0),i.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),a.activate()),i.$digest()),void 0)}),o.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(a.activate(o.val()),o.val(""),i.$digest())})}}}]),c.directive("uiSelectSort",["$timeout","uiSelectConfig","uiSelectMinErr",function(e,t,c){return{require:"^uiSelect",link:function(t,i,l,s){if(null===t[l.uiSelectSort])throw c("sort","Expected a list to sort");var n=angular.extend({axis:"horizontal"},t.$eval(l.uiSelectSortOptions)),a=n.axis,r="dragging",o="dropping",u="dropping-before",d="dropping-after";t.$watch(function(){return s.sortable},function(e){e?i.attr("draggable",!0):i.removeAttr("draggable")}),i.on("dragstart",function(e){i.addClass(r),(e.dataTransfer||e.originalEvent.dataTransfer).setData("text/plain",t.$index)}),i.on("dragend",function(){i.removeClass(r)});var p,g=function(e,t){this.splice(t,0,this.splice(e,1)[0])},h=function(e){e.preventDefault();var t="vertical"===a?e.offsetY||e.layerY||(e.originalEvent?e.originalEvent.offsetY:0):e.offsetX||e.layerX||(e.originalEvent?e.originalEvent.offsetX:0);t
  • '),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",'
    {{$select.placeholder}}
    '),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("select2/choices.tpl.html",'
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    '),e.put("selectize/choices.tpl.html",'
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ') }]); \ No newline at end of file diff --git a/dist/select.no-tpl.js b/dist/select.no-tpl.js deleted file mode 100644 index 713a3c84b..000000000 --- a/dist/select.no-tpl.js +++ /dev/null @@ -1,1766 +0,0 @@ -/*! - * ui-select - * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-11T18:41:59.459Z - * License: MIT - */ - - -(function () { -"use strict"; - -/** - * Add querySelectorAll() to jqLite. - * - * jqLite find() is limited to lookups by tag name. - * TODO This will change with future versions of AngularJS, to be removed when this happens - * - * See jqLite.find - why not use querySelectorAll? https://github.com/angular/angular.js/issues/3586 - * See feat(jqLite): use querySelectorAll instead of getElementsByTagName in jqLite.find https://github.com/angular/angular.js/pull/3598 - */ -if (angular.element.prototype.querySelectorAll === undefined) { - angular.element.prototype.querySelectorAll = function (selector) { - return angular.element(this[0].querySelectorAll(selector)); - }; -} - -/** - * Add closest() to jqLite. - */ -if (angular.element.prototype.closest === undefined) { - angular.element.prototype.closest = function (selector) { - var elem = this[0]; - var matchesSelector = elem.matches || elem.webkitMatchesSelector || elem.mozMatchesSelector || - elem.msMatchesSelector; - - while (elem) { - if (matchesSelector.bind(elem)(selector)) { - return elem; - } else { - elem = elem.parentElement; - } - } - return false; - }; -} - -var latestId = 0; - -var uis = angular.module('ui.select', []) - - .constant('uiSelectConfig', { - theme: 'bootstrap', - searchEnabled: true, - sortable: false, - placeholder: '', // Empty by default, like HTML tag "); - $compile(focusser)(scope); - $select.focusser = focusser; - - // Input that will handle focus - $select.focusInput = focusser; - - element.parent().append(focusser); - focusser.bind("focus", function () { - scope.$evalAsync(function () { - $select.focus = true; - }); - }); - focusser.bind("blur", function () { - scope.$evalAsync(function () { - $select.focus = false; - }); - }); - - focusser.bind("keydown", function (e) { - if (e.which === $select.KEY.BACKSPACE) { - e.preventDefault(); - e.stopPropagation(); - $select.select(undefined); - scope.$apply(); - return; - } - - if (e.which === $select.KEY.TAB || $select.KEY.isControl(e) || $select.KEY.isFunctionKey(e) || e.which === $select.KEY.ESC) { - return; - } - - if (e.which == $select.KEY.DOWN || e.which == $select.KEY.UP || e.which == $select.KEY.ENTER || e.which == $select.KEY.SPACE) { - e.preventDefault(); - e.stopPropagation(); - $select.activate(); - } - - scope.$digest(); - }); - - focusser.bind("keyup input", function (e) { - if (e.which === $select.KEY.TAB || $select.KEY.isControl(e) || $select.KEY.isFunctionKey(e) || e.which === $select.KEY.ESC || - e.which == $select.KEY.ENTER || e.which === $select.KEY.BACKSPACE) { - return; - } - - // User pressed some regular key, so we pass it to the search input - $select.activate(focusser.val()); - focusser.val(''); - scope.$digest(); - }); - } - }; -}]); -/** - * Parses "repeat" attribute. - * - * Taken from AngularJS ngRepeat source code - * See https://github.com/angular/angular.js/blob/v1.2.15/src/ng/directive/ngRepeat.js#L211 - * - * Original discussion about parsing "repeat" attribute instead of fully relying on ng-repeat: - * https://github.com/angular-ui/ui-select/commit/5dd63ad#commitcomment-5504697 - */ - -uis.service('uisRepeatParser', ['uiSelectMinErr', '$parse', function (uiSelectMinErr, $parse) { - var self = this; - - /** - * Example: - * expression = "address in addresses | filter: {street: $select.search} track by $index" - * itemName = "address", - * source = "addresses | filter: {street: $select.search}", - * trackByExp = "$index", - */ - self.parse = function (expression) { - - var match = expression.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/); - - if (!match) { - throw uiSelectMinErr('iexp', - "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.", - expression); - } - - return { - itemName: match[2], // (lhs) Left-hand side, - source: $parse(match[3]), - trackByExp: match[4], - modelMapper: $parse(match[1] || match[2]) - }; - - }; - - self.getGroupNgRepeatExpression = function () { - return '$group in $select.groups'; - }; - - self.getNgRepeatExpression = function (itemName, source, trackByExp, grouped) { - var expression = itemName + ' in ' + (grouped ? '$group.items' : source); - if (trackByExp) { - expression += ' track by ' + trackByExp; - } - return expression; - }; -}]); - -}()); \ No newline at end of file diff --git a/dist/select.no-tpl.min.js b/dist/select.no-tpl.min.js deleted file mode 100644 index 290734e4c..000000000 --- a/dist/select.no-tpl.min.js +++ /dev/null @@ -1,7 +0,0 @@ -/*! - * ui-select - * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-11T18:41:59.459Z - * License: MIT - */ -!function(){"use strict";void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var e=0,t=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return e++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,r,i){i(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return t=String(t),n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var r=n[0].getBoundingClientRect();return{width:r.width||n.prop("offsetWidth"),height:r.height||n.prop("offsetHeight"),top:r.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:r.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);t.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,r){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,i){if(!i.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,i,c,o,l){var s=c.groupBy,a=c.groupFilter;if(o.parseRepeatAttr(c.repeat,s,a),o.disableChoiceExpression=c.uiDisableChoice,o.onHighlightCallback=c.onHighlight,s){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=i.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(o.parserResult.itemName,"$select.items",o.parserResult.trackByExp,s)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+o.parserResult.itemName+")").attr("ng-click","$select.select("+o.parserResult.itemName+",false,$event)");var f=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==f.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",f.length);f.attr("uis-transclude-append",""),r(i,l)(e),e.$watch("$select.search",function(e){e&&!o.open&&o.multiple&&o.activate(!1,!0),o.activeIndex=0})}}}}]),t.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(e,t,n,r,i,c,o,l){function s(){(f.resetSearchInput||void 0===f.resetSearchInput&&l.resetSearchInput)&&(f.search=d,f.selected&&f.items.length&&!f.multiple&&(f.activeIndex=f.items.indexOf(f.selected)))}function a(e,t){var n,r,i=[];for(n=0;n0&&f.activeIndex--;break;case f.KEY.TAB:(!f.multiple||f.open)&&f.select(f.items[f.activeIndex],!0);break;case f.KEY.ENTER:f.open?void 0!==f.items[f.activeIndex]&&f.select(f.items[f.activeIndex]):f.activate(!1,!0);break;case f.KEY.ESC:f.close();break;default:t=!1}return t}function p(){var e=t.querySelectorAll(".ui-select-choices-content"),n=e.querySelectorAll(".ui-select-choices-row");if(n.length<1)throw o("choices","Expected multiple .ui-select-choices-row but got '{0}'.",n.length);if(!(f.activeIndex<0)){var r=n[f.activeIndex],i=r.offsetTop+r.clientHeight-e[0].scrollTop,c=e[0].offsetHeight;i>c?e[0].scrollTop+=i-c:i=112&&123>=e},isVerticalMovement:function(e){return~[f.KEY.UP,f.KEY.DOWN].indexOf(e)},isHorizontalMovement:function(e){return~[f.KEY.LEFT,f.KEY.RIGHT,f.KEY.BACKSPACE,f.KEY.DELETE].indexOf(e)}},f.isEmpty=function(){return angular.isUndefined(f.selected)||null===f.selected||""===f.selected},f.findGroupByName=function(e){return f.groups&&f.groups.filter(function(t){return t.name===e})[0]},f.activate=function(t,r){if(f.disabled||f.open)f.open&&!f.searchEnabled&&f.close();else{var i=function(){r||s(),e.$broadcast("uis:activate"),f.open=!0,f.searchEnabled||angular.element(f.searchInput[0]).addClass("ui-select-offscreen"),f.activeIndex=f.activeIndex>=f.items.length?0:f.activeIndex,n(function(){f.search=t||f.search,f.searchInput[0].focus()})},c=f.beforeDropdownOpen();angular.isFunction(c.then)?c.then(function(e){e===!0&&i()}):c===!0&&i()}},f.parseRepeatAttr=function(t,n,r){function i(t){var i=e.$eval(n);if(f.groups=[],angular.forEach(t,function(e){var t=angular.isFunction(i)?i(e):e[i],n=f.findGroupByName(t);n?n.items.push(e):f.groups.push({name:t,items:[e]})}),r){var c=e.$eval(r);angular.isFunction(c)?f.groups=c(f.groups):angular.isArray(c)&&(f.groups=a(f.groups,c))}f.items=[],f.groups.forEach(function(e){f.items=f.items.concat(e.items)})}function l(e){f.items=e}f.setItemsFn=n?i:l,f.parserResult=c.parse(t),f.isGrouped=!!n,f.itemProperty=f.parserResult.itemName,f.refreshItems=function(t){t=t||f.parserResult.source(e);var n=f.selected;if(f.isEmpty()||angular.isArray(n)&&!n.length||!f.removeSelected)f.setItemsFn(t);else if(void 0!==t){var r=t.filter(function(e){return n.indexOf(e)<0});f.setItemsFn(r)}},e.$watchCollection(f.parserResult.source,function(e){if(void 0===e||null===e)f.items=[];else{if(!angular.isArray(e))throw o("items","Expected an array but got '{0}'.",e);f.refreshItems(e),f.ngModel.$modelValue=null}})},f.setActiveItem=function(e){f.activeIndex=f.items.indexOf(e)},f.isActive=function(e){if(!f.open)return!1;var t=f.items.indexOf(e[f.itemProperty]),n=-1===t?!1:t===f.activeIndex;return n},f.isDisabled=function(e){if(!f.open)return!1;var t,n=f.items.indexOf(e[f.itemProperty]),r=!1;return n>=0&&!angular.isUndefined(f.disableChoiceExpression)&&(t=f.items[n],r=!!e.$eval(f.disableChoiceExpression),t._uiSelectChoiceDisabled=r),r},f.select=function(t,r,i){function c(){e.$broadcast("uis:select",t),n(function(){f.afterSelect(t)}),f.closeOnSelect&&f.close(r),i&&"click"===i.type&&(f.clickTriggeredSelect=!0)}if((void 0===t||!t._uiSelectChoiceDisabled)&&(f.items||f.search)){var o=f.beforeSelect(t);angular.isFunction(o.then)?o.then(function(e){e&&(e===!0?c(t):e&&c(e))}):o===!0?c(t):o&&c(o)}},f.close=function(t){function n(){f.ngModel&&f.ngModel.$setTouched&&f.ngModel.$setTouched(),s(),f.open=!1,f.searchEnabled||angular.element(f.searchInput[0]).removeClass("ui-select-offscreen"),e.$broadcast("uis:close",t)}if(f.open){var r=f.beforeDropdownClose();angular.isFunction(r.then)?r.then(function(e){e===!0&&n()}):r===!0&&n()}},f.setFocus=function(){f.focus||f.focusInput[0].focus()},f.clear=function(e){f.select(void 0),e.stopPropagation(),n(function(){f.focusser[0].focus()},0,!1)},f.toggle=function(e){f.open?(f.close(),e.preventDefault(),e.stopPropagation()):f.activate()},f.isLocked=function(e,t){var n,r=f.selected[t];return r&&!angular.isUndefined(f.lockChoiceExpression)&&(n=!!e.$eval(f.lockChoiceExpression),r._uiSelectChoiceLocked=n),n};var h=null;f.sizeSearchInput=function(){var t=f.searchInput[0],r=f.searchInput.parent().parent()[0],i=function(){return r.clientWidth*!!t.offsetParent},c=function(e){if(0===e)return!1;var n=e-t.offsetLeft-f.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=e),f.searchInput.css("width",n+"px"),!0};f.searchInput.css("width","10px"),n(function(){null!==h||c(i())||(h=e.$watch(i,function(e){c(e)&&(h(),h=null)}))})},f.searchInput.on("keydown",function(t){var n=t.which;~[f.KEY.ESC,f.KEY.TAB].indexOf(n)&&f.close(),e.$apply(function(){u(n)}),f.KEY.isVerticalMovement(n)&&f.items.length>0&&p(),(n===f.KEY.ENTER||n===f.KEY.ESC)&&(t.preventDefault(),t.stopPropagation())}),f.searchInput.on("keyup",function(e){e.which===f.KEY.TAB||f.KEY.isControl(e)||f.KEY.isFunctionKey(e)||e.which===f.KEY.ESC||f.KEY.isVerticalMovement(e.which)||f.afterKeypress(e)}),e.$on("$destroy",function(){f.searchInput.off("keyup keydown blur paste")}),f.afterKeypress=function(){},f.beforeSelect=function(){return!0},f.afterSelect=function(){},f.beforeRemove=function(){return!0},f.afterRemove=function(){},f.beforeDropdownOpen=function(){return!0},f.beforeDropdownClose=function(){return!0}}]),t.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,r,i,c,o,l){return{restrict:"EA",templateUrl:function(e,t){var r=t.theme||n.theme;return r+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(c,s){return angular.isDefined(s.multiple)?c.append("").removeAttr("multiple"):c.append(""),function(c,s,a,u,p){function f(e){if(v.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(s[0],e.target):s[0].contains(e.target),!t&&!v.clickTriggeredSelect){var n=["input","button","textarea"],r=angular.element(e.target).controller("uiSelect"),i=r&&r!==v;i||(i=~n.indexOf(e.target.tagName.toLowerCase())),v.close(i),c.$digest()}v.clickTriggeredSelect=!1}}function d(){var t=i(s);S=angular.element('
    '),S[0].style.width=t.width+"px",S[0].style.height=t.height+"px",s.after(S),w=s[0].style.width,e.find("body").append(s),s[0].style.position="absolute",s[0].style.left=t.left+"px",s[0].style.top=t.top+"px",s[0].style.width=t.width+"px"}function h(){null!==S&&(S.replaceWith(s),S=null,s[0].style.position="",s[0].style.left="",s[0].style.top="",s[0].style.width=w)}var v=u[0],g=u[1];v.generatedId=n.generateId(),v.baseTitle=a.title||"Select box",v.focusserTitle=v.baseTitle+" focus",v.focusserId="focusser-"+v.generatedId,v.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?o(a.closeOnSelect)():n.closeOnSelect}(),v.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,v.ngModel=g,v.choiceGrouped=function(e){return v.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){v.focusInput.attr("tabindex",e),s.removeAttr("tabindex")});var m=c.$eval(a.searchEnabled);v.searchEnabled=void 0!==m?m:n.searchEnabled;var E=c.$eval(a.sortable);v.sortable=void 0!==E?E:n.sortable,a.$observe("disabled",function(){v.disabled=void 0!==a.disabled?a.disabled:!1}),angular.isDefined(a.autofocus)&&l(function(){v.setFocus()}),angular.isDefined(a.focusOn)&&c.$on(a.focusOn,function(){l(function(){v.setFocus()})}),e.on("click",f),c.$on("$destroy",function(){e.off("click",f)}),p(c,function(e){var t=angular.element("
    ").append(e),n=t.querySelectorAll(".ui-select-match");if(n.removeAttr("ui-select-match"),n.removeAttr("data-ui-select-match"),1!==n.length)throw r("transcluded","Expected 1 .ui-select-match but got '{0}'.",n.length);s.querySelectorAll(".ui-select-match").replaceWith(n);var i=t.querySelectorAll(".ui-select-choices");if(i.removeAttr("ui-select-choices"),i.removeAttr("data-ui-select-choices"),1!==i.length)throw r("transcluded","Expected 1 .ui-select-choices but got '{0}'.",i.length);s.querySelectorAll(".ui-select-choices").replaceWith(i)});var $=c.$eval(a.appendToBody);(void 0!==$?$:n.appendToBody)&&(c.$watch("$select.open",function(e){e?d():h()}),c.$on("$destroy",function(){h()}));var S=null,w="",b=null,I="direction-up";c.$watch("$select.open",function(n){if(n){if(b=angular.element(s).querySelectorAll(".ui-select-dropdown"),null===b)return;b[0].style.opacity=0,l(function(){var n=i(s),r=i(b);n.top+n.height+r.height>t.pageYOffset+e[0].documentElement.clientHeight&&s.addClass(I),b[0].style.opacity=1})}else{if(null===b)return;s.removeClass(I)}})}}}}]),t.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,r=t.parent().attr("multiple");return n+(r?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,r,i){function c(e){i.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}i.lockChoiceExpression=r.uiLockChoice,r.$observe("placeholder",function(t){i.placeholder=void 0!==t?t:e.placeholder}),r.$observe("allowClear",c),c(r.allowClear),i.multiple&&i.sizeSearchInput()}}}]),t.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,r=this,i=e.$select;e.$evalAsync(function(){n=e.ngModel}),r.activeMatchIndex=-1,r.updateModel=function(){n.$setViewValue(Date.now()),r.refreshComponent()},r.refreshComponent=function(){i.refreshItems(),i.sizeSearchInput()},r.removeChoice=function(e){function n(){i.selected.splice(e,1),r.activeMatchIndex=-1,i.sizeSearchInput(),t(function(){i.afterRemove(c)}),r.updateModel()}var c=i.selected[e];if(!c._uiSelectChoiceLocked){var o=i.beforeRemove(c);angular.isFunction(o.then)?o.then(function(e){e===!0&&n()}):o===!0&&n()}},r.getPlaceholder=function(){return i.selected&&i.selected.length?void 0:i.placeholder}}],controllerAs:"$selectMultiple",link:function(n,r,i,c){function o(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function l(e){function t(){switch(e){case s.KEY.LEFT:return~u.activeMatchIndex?p:c;case s.KEY.RIGHT:return~u.activeMatchIndex&&l!==c?a:(s.activate(),!1);case s.KEY.BACKSPACE:return~u.activeMatchIndex?(u.removeChoice(l),p):c;case s.KEY.DELETE:return~u.activeMatchIndex?(u.removeChoice(u.activeMatchIndex),l):!1}}var n=o(s.searchInput[0]),r=s.selected.length,i=0,c=r-1,l=u.activeMatchIndex,a=u.activeMatchIndex+1,p=u.activeMatchIndex-1,f=l;return n>0||s.search.length&&e==s.KEY.RIGHT?!1:(s.close(),f=t(),u.activeMatchIndex=s.selected.length&&f!==!1?Math.min(c,Math.max(i,f)):-1,!0)}var s=c[0],a=n.ngModel=c[1],u=n.$selectMultiple;s.multiple=!0,s.removeSelected=!0,s.focusInput=s.searchInput,a.$parsers.unshift(function(){for(var e,t={},r=[],i=s.selected.length-1;i>=0;i--)t={},t[s.parserResult.itemName]=s.selected[i],e=s.parserResult.modelMapper(n,t),r.unshift(e);return r}),a.$formatters.unshift(function(e){var t,r=s.parserResult.source(n,{$select:{search:""}}),i={};if(!r)return e;var c=[],o=function(e,r){if(e&&e.length){for(var o=e.length-1;o>=0;o--){if(i[s.parserResult.itemName]=e[o],t=s.parserResult.modelMapper(n,i),s.parserResult.trackByExp){var l=/\.(.+)/.exec(s.parserResult.trackByExp);if(l.length>0&&t[l[1]]==r[l[1]])return c.unshift(e[o]),!0}if(angular.equals(t,r))return c.unshift(e[o]),!0}return!1}};if(!e)return c;for(var l=e.length-1;l>=0;l--)o(s.selected,e[l])||o(r,e[l])||c.unshift(e[l]);return c}),n.$watchCollection(function(){return a.$modelValue},function(e,t){t!=e&&(a.$modelValue=null,u.refreshComponent())}),a.$render=function(){if(!angular.isArray(a.$viewValue)){if(!angular.isUndefined(a.$viewValue)&&null!==a.$viewValue)throw e("multiarr","Expected model value to be array but got '{0}'",a.$viewValue);s.selected=[]}s.selected=a.$viewValue,n.$evalAsync()},n.$on("uis:select",function(e,t){s.selected.length>=s.limit||(s.selected.push(t),u.updateModel())}),n.$on("uis:activate",function(){u.activeMatchIndex=-1}),n.$watch("$select.disabled",function(e,t){t&&!e&&s.sizeSearchInput()}),s.searchInput.on("keydown",function(e){var t=e.which;n.$apply(function(){var e=!1;s.KEY.isHorizontalMovement(t)&&(e=l(t)),e&&t!=s.KEY.TAB})}),s.searchInput.on("blur",function(){t(function(){u.activeMatchIndex=-1})})}}}]),t.directive("uiSelectSingle",["$timeout","$compile",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(n,r,i,c){var o=c[0],l=c[1];l.$parsers.unshift(function(e){var t,r={};return r[o.parserResult.itemName]=e,t=o.parserResult.modelMapper(n,r)}),l.$formatters.unshift(function(e){var t,r=o.parserResult.source(n,{$select:{search:""}}),i={};if(r){var c=function(r){return i[o.parserResult.itemName]=r,t=o.parserResult.modelMapper(n,i),t==e};if(o.selected&&c(o.selected))return o.selected;for(var l=r.length-1;l>=0;l--)if(c(r[l]))return r[l]}return e}),n.$watch("$select.selected",function(e){l.$viewValue!==e&&l.$setViewValue(e)}),l.$render=function(){o.selected=l.$viewValue},n.$on("uis:select",function(e,t){o.selected=t}),n.$on("uis:close",function(t,n){e(function(){o.focusser.prop("disabled",!1),n||o.focusser[0].focus()},0,!1)}),n.$on("uis:activate",function(){s.prop("disabled",!0)});var s=angular.element("");t(s)(n),o.focusser=s,o.focusInput=s,r.parent().append(s),s.bind("focus",function(){n.$evalAsync(function(){o.focus=!0})}),s.bind("blur",function(){n.$evalAsync(function(){o.focus=!1})}),s.bind("keydown",function(e){return e.which===o.KEY.BACKSPACE?(e.preventDefault(),e.stopPropagation(),o.select(void 0),n.$apply(),void 0):(e.which===o.KEY.TAB||o.KEY.isControl(e)||o.KEY.isFunctionKey(e)||e.which===o.KEY.ESC||((e.which==o.KEY.DOWN||e.which==o.KEY.UP||e.which==o.KEY.ENTER||e.which==o.KEY.SPACE)&&(e.preventDefault(),e.stopPropagation(),o.activate()),n.$digest()),void 0)}),s.bind("keyup input",function(e){e.which===o.KEY.TAB||o.KEY.isControl(e)||o.KEY.isFunctionKey(e)||e.which===o.KEY.ESC||e.which==o.KEY.ENTER||e.which===o.KEY.BACKSPACE||(o.activate(s.val()),s.val(""),n.$digest())})}}}]),t.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var r=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!r)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:r[2],source:t(r[3]),trackByExp:r[4],modelMapper:t(r[1]||r[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,r){var i=e+" in "+(r?"$group.items":t);return n&&(i+=" track by "+n),i}}])}(); \ No newline at end of file diff --git a/dist/select.select2.js b/dist/select.select2.js deleted file mode 100644 index d432cdf72..000000000 --- a/dist/select.select2.js +++ /dev/null @@ -1,1771 +0,0 @@ -/*! - * ui-select - * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-11T18:41:59.476Z - * License: MIT - */ - - -(function () { -"use strict"; - -/** - * Add querySelectorAll() to jqLite. - * - * jqLite find() is limited to lookups by tag name. - * TODO This will change with future versions of AngularJS, to be removed when this happens - * - * See jqLite.find - why not use querySelectorAll? https://github.com/angular/angular.js/issues/3586 - * See feat(jqLite): use querySelectorAll instead of getElementsByTagName in jqLite.find https://github.com/angular/angular.js/pull/3598 - */ -if (angular.element.prototype.querySelectorAll === undefined) { - angular.element.prototype.querySelectorAll = function (selector) { - return angular.element(this[0].querySelectorAll(selector)); - }; -} - -/** - * Add closest() to jqLite. - */ -if (angular.element.prototype.closest === undefined) { - angular.element.prototype.closest = function (selector) { - var elem = this[0]; - var matchesSelector = elem.matches || elem.webkitMatchesSelector || elem.mozMatchesSelector || - elem.msMatchesSelector; - - while (elem) { - if (matchesSelector.bind(elem)(selector)) { - return elem; - } else { - elem = elem.parentElement; - } - } - return false; - }; -} - -var latestId = 0; - -var uis = angular.module('ui.select', []) - - .constant('uiSelectConfig', { - theme: 'bootstrap', - searchEnabled: true, - sortable: false, - placeholder: '', // Empty by default, like HTML tag "); - $compile(focusser)(scope); - $select.focusser = focusser; - - // Input that will handle focus - $select.focusInput = focusser; - - element.parent().append(focusser); - focusser.bind("focus", function () { - scope.$evalAsync(function () { - $select.focus = true; - }); - }); - focusser.bind("blur", function () { - scope.$evalAsync(function () { - $select.focus = false; - }); - }); - - focusser.bind("keydown", function (e) { - if (e.which === $select.KEY.BACKSPACE) { - e.preventDefault(); - e.stopPropagation(); - $select.select(undefined); - scope.$apply(); - return; - } - - if (e.which === $select.KEY.TAB || $select.KEY.isControl(e) || $select.KEY.isFunctionKey(e) || e.which === $select.KEY.ESC) { - return; - } - - if (e.which == $select.KEY.DOWN || e.which == $select.KEY.UP || e.which == $select.KEY.ENTER || e.which == $select.KEY.SPACE) { - e.preventDefault(); - e.stopPropagation(); - $select.activate(); - } - - scope.$digest(); - }); - - focusser.bind("keyup input", function (e) { - if (e.which === $select.KEY.TAB || $select.KEY.isControl(e) || $select.KEY.isFunctionKey(e) || e.which === $select.KEY.ESC || - e.which == $select.KEY.ENTER || e.which === $select.KEY.BACKSPACE) { - return; - } - - // User pressed some regular key, so we pass it to the search input - $select.activate(focusser.val()); - focusser.val(''); - scope.$digest(); - }); - } - }; -}]); -/** - * Parses "repeat" attribute. - * - * Taken from AngularJS ngRepeat source code - * See https://github.com/angular/angular.js/blob/v1.2.15/src/ng/directive/ngRepeat.js#L211 - * - * Original discussion about parsing "repeat" attribute instead of fully relying on ng-repeat: - * https://github.com/angular-ui/ui-select/commit/5dd63ad#commitcomment-5504697 - */ - -uis.service('uisRepeatParser', ['uiSelectMinErr', '$parse', function (uiSelectMinErr, $parse) { - var self = this; - - /** - * Example: - * expression = "address in addresses | filter: {street: $select.search} track by $index" - * itemName = "address", - * source = "addresses | filter: {street: $select.search}", - * trackByExp = "$index", - */ - self.parse = function (expression) { - - var match = expression.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/); - - if (!match) { - throw uiSelectMinErr('iexp', - "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.", - expression); - } - - return { - itemName: match[2], // (lhs) Left-hand side, - source: $parse(match[3]), - trackByExp: match[4], - modelMapper: $parse(match[1] || match[2]) - }; - - }; - - self.getGroupNgRepeatExpression = function () { - return '$group in $select.groups'; - }; - - self.getNgRepeatExpression = function (itemName, source, trackByExp, grouped) { - var expression = itemName + ' in ' + (grouped ? '$group.items' : source); - if (trackByExp) { - expression += ' track by ' + trackByExp; - } - return expression; - }; -}]); - -}()); -angular.module("ui.select").run(["$templateCache", function($templateCache) {$templateCache.put("select2/choices.tpl.html","
    "); -$templateCache.put("select2/match-multiple.tpl.html","
  • "); -$templateCache.put("select2/match.tpl.html","{{$select.placeholder}} "); -$templateCache.put("select2/select-multiple.tpl.html","
    "); -$templateCache.put("select2/select.tpl.html","
    ");}]); \ No newline at end of file diff --git a/dist/select.select2.min.js b/dist/select.select2.min.js deleted file mode 100644 index ebf8f433f..000000000 --- a/dist/select.select2.min.js +++ /dev/null @@ -1,7 +0,0 @@ -/*! - * ui-select - * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-11T18:41:59.476Z - * License: MIT - */ -!function(){"use strict";void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],c=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(c.bind(t)(e))return t;t=t.parentElement}return!1});var e=0,t=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return e++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,n,i){i(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return t=String(t),c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(c){var n=c[0].getBoundingClientRect();return{width:n.width||c.prop("offsetWidth"),height:n.height||c.prop("offsetHeight"),top:n.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:n.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);t.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,c,n){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(e,i){if(!i.repeat)throw c("repeat","Expected 'repeat' expression.");return function(e,i,l,s,r){var o=l.groupBy,a=l.groupFilter;if(s.parseRepeatAttr(l.repeat,o,a),s.disableChoiceExpression=l.uiDisableChoice,s.onHighlightCallback=l.onHighlight,o){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=i.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(s.parserResult.itemName,"$select.items",s.parserResult.trackByExp,o)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+s.parserResult.itemName+")").attr("ng-click","$select.select("+s.parserResult.itemName+",false,$event)");var d=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),n(i,r)(e),e.$watch("$select.search",function(e){e&&!s.open&&s.multiple&&s.activate(!1,!0),s.activeIndex=0})}}}}]),t.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(e,t,c,n,i,l,s,r){function o(){(d.resetSearchInput||void 0===d.resetSearchInput&&r.resetSearchInput)&&(d.search=h,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function a(e,t){var c,n,i=[];for(c=0;c0&&d.activeIndex--;break;case d.KEY.TAB:(!d.multiple||d.open)&&d.select(d.items[d.activeIndex],!0);break;case d.KEY.ENTER:d.open?void 0!==d.items[d.activeIndex]&&d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case d.KEY.ESC:d.close();break;default:t=!1}return t}function p(){var e=t.querySelectorAll(".ui-select-choices-content"),c=e.querySelectorAll(".ui-select-choices-row");if(c.length<1)throw s("choices","Expected multiple .ui-select-choices-row but got '{0}'.",c.length);if(!(d.activeIndex<0)){var n=c[d.activeIndex],i=n.offsetTop+n.clientHeight-e[0].scrollTop,l=e[0].offsetHeight;i>l?e[0].scrollTop+=i-l:i=112&&123>=e},isVerticalMovement:function(e){return~[d.KEY.UP,d.KEY.DOWN].indexOf(e)},isHorizontalMovement:function(e){return~[d.KEY.LEFT,d.KEY.RIGHT,d.KEY.BACKSPACE,d.KEY.DELETE].indexOf(e)}},d.isEmpty=function(){return angular.isUndefined(d.selected)||null===d.selected||""===d.selected},d.findGroupByName=function(e){return d.groups&&d.groups.filter(function(t){return t.name===e})[0]},d.activate=function(t,n){if(d.disabled||d.open)d.open&&!d.searchEnabled&&d.close();else{var i=function(){n||o(),e.$broadcast("uis:activate"),d.open=!0,d.searchEnabled||angular.element(d.searchInput[0]).addClass("ui-select-offscreen"),d.activeIndex=d.activeIndex>=d.items.length?0:d.activeIndex,c(function(){d.search=t||d.search,d.searchInput[0].focus()})},l=d.beforeDropdownOpen();angular.isFunction(l.then)?l.then(function(e){e===!0&&i()}):l===!0&&i()}},d.parseRepeatAttr=function(t,c,n){function i(t){var i=e.$eval(c);if(d.groups=[],angular.forEach(t,function(e){var t=angular.isFunction(i)?i(e):e[i],c=d.findGroupByName(t);c?c.items.push(e):d.groups.push({name:t,items:[e]})}),n){var l=e.$eval(n);angular.isFunction(l)?d.groups=l(d.groups):angular.isArray(l)&&(d.groups=a(d.groups,l))}d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function r(e){d.items=e}d.setItemsFn=c?i:r,d.parserResult=l.parse(t),d.isGrouped=!!c,d.itemProperty=d.parserResult.itemName,d.refreshItems=function(t){t=t||d.parserResult.source(e);var c=d.selected;if(d.isEmpty()||angular.isArray(c)&&!c.length||!d.removeSelected)d.setItemsFn(t);else if(void 0!==t){var n=t.filter(function(e){return c.indexOf(e)<0});d.setItemsFn(n)}},e.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw s("items","Expected an array but got '{0}'.",e);d.refreshItems(e),d.ngModel.$modelValue=null}})},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){if(!d.open)return!1;var t=d.items.indexOf(e[d.itemProperty]),c=-1===t?!1:t===d.activeIndex;return c},d.isDisabled=function(e){if(!d.open)return!1;var t,c=d.items.indexOf(e[d.itemProperty]),n=!1;return c>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[c],n=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=n),n},d.select=function(t,n,i){function l(){e.$broadcast("uis:select",t),c(function(){d.afterSelect(t)}),d.closeOnSelect&&d.close(n),i&&"click"===i.type&&(d.clickTriggeredSelect=!0)}if((void 0===t||!t._uiSelectChoiceDisabled)&&(d.items||d.search)){var s=d.beforeSelect(t);angular.isFunction(s.then)?s.then(function(e){e&&(e===!0?l(t):e&&l(e))}):s===!0?l(t):s&&l(s)}},d.close=function(t){function c(){d.ngModel&&d.ngModel.$setTouched&&d.ngModel.$setTouched(),o(),d.open=!1,d.searchEnabled||angular.element(d.searchInput[0]).removeClass("ui-select-offscreen"),e.$broadcast("uis:close",t)}if(d.open){var n=d.beforeDropdownClose();angular.isFunction(n.then)?n.then(function(e){e===!0&&c()}):n===!0&&c()}},d.setFocus=function(){d.focus||d.focusInput[0].focus()},d.clear=function(e){d.select(void 0),e.stopPropagation(),c(function(){d.focusser[0].focus()},0,!1)},d.toggle=function(e){d.open?(d.close(),e.preventDefault(),e.stopPropagation()):d.activate()},d.isLocked=function(e,t){var c,n=d.selected[t];return n&&!angular.isUndefined(d.lockChoiceExpression)&&(c=!!e.$eval(d.lockChoiceExpression),n._uiSelectChoiceLocked=c),c};var f=null;d.sizeSearchInput=function(){var t=d.searchInput[0],n=d.searchInput.parent().parent()[0],i=function(){return n.clientWidth*!!t.offsetParent},l=function(e){if(0===e)return!1;var c=e-t.offsetLeft-d.searchInput.parent()[0].offsetLeft-5;return 50>c&&(c=e),d.searchInput.css("width",c+"px"),!0};d.searchInput.css("width","10px"),c(function(){null!==f||l(i())||(f=e.$watch(i,function(e){l(e)&&(f(),f=null)}))})},d.searchInput.on("keydown",function(t){var c=t.which;~[d.KEY.ESC,d.KEY.TAB].indexOf(c)&&d.close(),e.$apply(function(){u(c)}),d.KEY.isVerticalMovement(c)&&d.items.length>0&&p(),(c===d.KEY.ENTER||c===d.KEY.ESC)&&(t.preventDefault(),t.stopPropagation())}),d.searchInput.on("keyup",function(e){e.which===d.KEY.TAB||d.KEY.isControl(e)||d.KEY.isFunctionKey(e)||e.which===d.KEY.ESC||d.KEY.isVerticalMovement(e.which)||d.afterKeypress(e)}),e.$on("$destroy",function(){d.searchInput.off("keyup keydown blur paste")}),d.afterKeypress=function(){},d.beforeSelect=function(){return!0},d.afterSelect=function(){},d.beforeRemove=function(){return!0},d.afterRemove=function(){},d.beforeDropdownOpen=function(){return!0},d.beforeDropdownClose=function(){return!0}}]),t.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,c,n,i,l,s,r){return{restrict:"EA",templateUrl:function(e,t){var n=t.theme||c.theme;return n+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(l,o){return angular.isDefined(o.multiple)?l.append("").removeAttr("multiple"):l.append(""),function(l,o,a,u,p){function d(e){if(g.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(o[0],e.target):o[0].contains(e.target),!t&&!g.clickTriggeredSelect){var c=["input","button","textarea"],n=angular.element(e.target).controller("uiSelect"),i=n&&n!==g;i||(i=~c.indexOf(e.target.tagName.toLowerCase())),g.close(i),l.$digest()}g.clickTriggeredSelect=!1}}function h(){var t=i(o);b=angular.element('
    '),b[0].style.width=t.width+"px",b[0].style.height=t.height+"px",o.after(b),w=o[0].style.width,e.find("body").append(o),o[0].style.position="absolute",o[0].style.left=t.left+"px",o[0].style.top=t.top+"px",o[0].style.width=t.width+"px"}function f(){null!==b&&(b.replaceWith(o),b=null,o[0].style.position="",o[0].style.left="",o[0].style.top="",o[0].style.width=w)}var g=u[0],v=u[1];g.generatedId=c.generateId(),g.baseTitle=a.title||"Select box",g.focusserTitle=g.baseTitle+" focus",g.focusserId="focusser-"+g.generatedId,g.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?s(a.closeOnSelect)():c.closeOnSelect}(),g.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,g.ngModel=v,g.choiceGrouped=function(e){return g.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){g.focusInput.attr("tabindex",e),o.removeAttr("tabindex")});var m=l.$eval(a.searchEnabled);g.searchEnabled=void 0!==m?m:c.searchEnabled;var E=l.$eval(a.sortable);g.sortable=void 0!==E?E:c.sortable,a.$observe("disabled",function(){g.disabled=void 0!==a.disabled?a.disabled:!1}),angular.isDefined(a.autofocus)&&r(function(){g.setFocus()}),angular.isDefined(a.focusOn)&&l.$on(a.focusOn,function(){r(function(){g.setFocus()})}),e.on("click",d),l.$on("$destroy",function(){e.off("click",d)}),p(l,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),c.removeAttr("data-ui-select-match"),1!==c.length)throw n("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);o.querySelectorAll(".ui-select-match").replaceWith(c);var i=t.querySelectorAll(".ui-select-choices");if(i.removeAttr("ui-select-choices"),i.removeAttr("data-ui-select-choices"),1!==i.length)throw n("transcluded","Expected 1 .ui-select-choices but got '{0}'.",i.length);o.querySelectorAll(".ui-select-choices").replaceWith(i)});var $=l.$eval(a.appendToBody);(void 0!==$?$:c.appendToBody)&&(l.$watch("$select.open",function(e){e?h():f()}),l.$on("$destroy",function(){f()}));var b=null,w="",S=null,x="direction-up";l.$watch("$select.open",function(c){if(c){if(S=angular.element(o).querySelectorAll(".ui-select-dropdown"),null===S)return;S[0].style.opacity=0,r(function(){var c=i(o),n=i(S);c.top+c.height+n.height>t.pageYOffset+e[0].documentElement.clientHeight&&o.addClass(x),S[0].style.opacity=1})}else{if(null===S)return;o.removeClass(x)}})}}}}]),t.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,n=t.parent().attr("multiple");return c+(n?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,n,i){function l(e){i.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}i.lockChoiceExpression=n.uiLockChoice,n.$observe("placeholder",function(t){i.placeholder=void 0!==t?t:e.placeholder}),n.$observe("allowClear",l),l(n.allowClear),i.multiple&&i.sizeSearchInput()}}}]),t.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var c,n=this,i=e.$select;e.$evalAsync(function(){c=e.ngModel}),n.activeMatchIndex=-1,n.updateModel=function(){c.$setViewValue(Date.now()),n.refreshComponent()},n.refreshComponent=function(){i.refreshItems(),i.sizeSearchInput()},n.removeChoice=function(e){function c(){i.selected.splice(e,1),n.activeMatchIndex=-1,i.sizeSearchInput(),t(function(){i.afterRemove(l)}),n.updateModel()}var l=i.selected[e];if(!l._uiSelectChoiceLocked){var s=i.beforeRemove(l);angular.isFunction(s.then)?s.then(function(e){e===!0&&c()}):s===!0&&c()}},n.getPlaceholder=function(){return i.selected&&i.selected.length?void 0:i.placeholder}}],controllerAs:"$selectMultiple",link:function(c,n,i,l){function s(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function r(e){function t(){switch(e){case o.KEY.LEFT:return~u.activeMatchIndex?p:l;case o.KEY.RIGHT:return~u.activeMatchIndex&&r!==l?a:(o.activate(),!1);case o.KEY.BACKSPACE:return~u.activeMatchIndex?(u.removeChoice(r),p):l;case o.KEY.DELETE:return~u.activeMatchIndex?(u.removeChoice(u.activeMatchIndex),r):!1}}var c=s(o.searchInput[0]),n=o.selected.length,i=0,l=n-1,r=u.activeMatchIndex,a=u.activeMatchIndex+1,p=u.activeMatchIndex-1,d=r;return c>0||o.search.length&&e==o.KEY.RIGHT?!1:(o.close(),d=t(),u.activeMatchIndex=o.selected.length&&d!==!1?Math.min(l,Math.max(i,d)):-1,!0)}var o=l[0],a=c.ngModel=l[1],u=c.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,a.$parsers.unshift(function(){for(var e,t={},n=[],i=o.selected.length-1;i>=0;i--)t={},t[o.parserResult.itemName]=o.selected[i],e=o.parserResult.modelMapper(c,t),n.unshift(e);return n}),a.$formatters.unshift(function(e){var t,n=o.parserResult.source(c,{$select:{search:""}}),i={};if(!n)return e;var l=[],s=function(e,n){if(e&&e.length){for(var s=e.length-1;s>=0;s--){if(i[o.parserResult.itemName]=e[s],t=o.parserResult.modelMapper(c,i),o.parserResult.trackByExp){var r=/\.(.+)/.exec(o.parserResult.trackByExp);if(r.length>0&&t[r[1]]==n[r[1]])return l.unshift(e[s]),!0}if(angular.equals(t,n))return l.unshift(e[s]),!0}return!1}};if(!e)return l;for(var r=e.length-1;r>=0;r--)s(o.selected,e[r])||s(n,e[r])||l.unshift(e[r]);return l}),c.$watchCollection(function(){return a.$modelValue},function(e,t){t!=e&&(a.$modelValue=null,u.refreshComponent())}),a.$render=function(){if(!angular.isArray(a.$viewValue)){if(!angular.isUndefined(a.$viewValue)&&null!==a.$viewValue)throw e("multiarr","Expected model value to be array but got '{0}'",a.$viewValue);o.selected=[]}o.selected=a.$viewValue,c.$evalAsync()},c.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),u.updateModel())}),c.$on("uis:activate",function(){u.activeMatchIndex=-1}),c.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(e){var t=e.which;c.$apply(function(){var e=!1;o.KEY.isHorizontalMovement(t)&&(e=r(t)),e&&t!=o.KEY.TAB})}),o.searchInput.on("blur",function(){t(function(){u.activeMatchIndex=-1})})}}}]),t.directive("uiSelectSingle",["$timeout","$compile",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(c,n,i,l){var s=l[0],r=l[1];r.$parsers.unshift(function(e){var t,n={};return n[s.parserResult.itemName]=e,t=s.parserResult.modelMapper(c,n)}),r.$formatters.unshift(function(e){var t,n=s.parserResult.source(c,{$select:{search:""}}),i={};if(n){var l=function(n){return i[s.parserResult.itemName]=n,t=s.parserResult.modelMapper(c,i),t==e};if(s.selected&&l(s.selected))return s.selected;for(var r=n.length-1;r>=0;r--)if(l(n[r]))return n[r]}return e}),c.$watch("$select.selected",function(e){r.$viewValue!==e&&r.$setViewValue(e)}),r.$render=function(){s.selected=r.$viewValue},c.$on("uis:select",function(e,t){s.selected=t}),c.$on("uis:close",function(t,c){e(function(){s.focusser.prop("disabled",!1),c||s.focusser[0].focus()},0,!1)}),c.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");t(o)(c),s.focusser=o,s.focusInput=o,n.parent().append(o),o.bind("focus",function(){c.$evalAsync(function(){s.focus=!0})}),o.bind("blur",function(){c.$evalAsync(function(){s.focus=!1})}),o.bind("keydown",function(e){return e.which===s.KEY.BACKSPACE?(e.preventDefault(),e.stopPropagation(),s.select(void 0),c.$apply(),void 0):(e.which===s.KEY.TAB||s.KEY.isControl(e)||s.KEY.isFunctionKey(e)||e.which===s.KEY.ESC||((e.which==s.KEY.DOWN||e.which==s.KEY.UP||e.which==s.KEY.ENTER||e.which==s.KEY.SPACE)&&(e.preventDefault(),e.stopPropagation(),s.activate()),c.$digest()),void 0)}),o.bind("keyup input",function(e){e.which===s.KEY.TAB||s.KEY.isControl(e)||s.KEY.isFunctionKey(e)||e.which===s.KEY.ESC||e.which==s.KEY.ENTER||e.which===s.KEY.BACKSPACE||(s.activate(o.val()),o.val(""),c.$digest())})}}}]),t.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var n=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!n)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:n[2],source:t(n[3]),trackByExp:n[4],modelMapper:t(n[1]||n[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,n){var i=e+" in "+(n?"$group.items":t);return c&&(i+=" track by "+c),i}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("select2/choices.tpl.html",'
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/dist/select.selectize.js b/dist/select.selectize.js deleted file mode 100644 index 86910b9f0..000000000 --- a/dist/select.selectize.js +++ /dev/null @@ -1,1769 +0,0 @@ -/*! - * ui-select - * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-11T18:41:59.483Z - * License: MIT - */ - - -(function () { -"use strict"; - -/** - * Add querySelectorAll() to jqLite. - * - * jqLite find() is limited to lookups by tag name. - * TODO This will change with future versions of AngularJS, to be removed when this happens - * - * See jqLite.find - why not use querySelectorAll? https://github.com/angular/angular.js/issues/3586 - * See feat(jqLite): use querySelectorAll instead of getElementsByTagName in jqLite.find https://github.com/angular/angular.js/pull/3598 - */ -if (angular.element.prototype.querySelectorAll === undefined) { - angular.element.prototype.querySelectorAll = function (selector) { - return angular.element(this[0].querySelectorAll(selector)); - }; -} - -/** - * Add closest() to jqLite. - */ -if (angular.element.prototype.closest === undefined) { - angular.element.prototype.closest = function (selector) { - var elem = this[0]; - var matchesSelector = elem.matches || elem.webkitMatchesSelector || elem.mozMatchesSelector || - elem.msMatchesSelector; - - while (elem) { - if (matchesSelector.bind(elem)(selector)) { - return elem; - } else { - elem = elem.parentElement; - } - } - return false; - }; -} - -var latestId = 0; - -var uis = angular.module('ui.select', []) - - .constant('uiSelectConfig', { - theme: 'bootstrap', - searchEnabled: true, - sortable: false, - placeholder: '', // Empty by default, like HTML tag "); - $compile(focusser)(scope); - $select.focusser = focusser; - - // Input that will handle focus - $select.focusInput = focusser; - - element.parent().append(focusser); - focusser.bind("focus", function () { - scope.$evalAsync(function () { - $select.focus = true; - }); - }); - focusser.bind("blur", function () { - scope.$evalAsync(function () { - $select.focus = false; - }); - }); - - focusser.bind("keydown", function (e) { - if (e.which === $select.KEY.BACKSPACE) { - e.preventDefault(); - e.stopPropagation(); - $select.select(undefined); - scope.$apply(); - return; - } - - if (e.which === $select.KEY.TAB || $select.KEY.isControl(e) || $select.KEY.isFunctionKey(e) || e.which === $select.KEY.ESC) { - return; - } - - if (e.which == $select.KEY.DOWN || e.which == $select.KEY.UP || e.which == $select.KEY.ENTER || e.which == $select.KEY.SPACE) { - e.preventDefault(); - e.stopPropagation(); - $select.activate(); - } - - scope.$digest(); - }); - - focusser.bind("keyup input", function (e) { - if (e.which === $select.KEY.TAB || $select.KEY.isControl(e) || $select.KEY.isFunctionKey(e) || e.which === $select.KEY.ESC || - e.which == $select.KEY.ENTER || e.which === $select.KEY.BACKSPACE) { - return; - } - - // User pressed some regular key, so we pass it to the search input - $select.activate(focusser.val()); - focusser.val(''); - scope.$digest(); - }); - } - }; -}]); -/** - * Parses "repeat" attribute. - * - * Taken from AngularJS ngRepeat source code - * See https://github.com/angular/angular.js/blob/v1.2.15/src/ng/directive/ngRepeat.js#L211 - * - * Original discussion about parsing "repeat" attribute instead of fully relying on ng-repeat: - * https://github.com/angular-ui/ui-select/commit/5dd63ad#commitcomment-5504697 - */ - -uis.service('uisRepeatParser', ['uiSelectMinErr', '$parse', function (uiSelectMinErr, $parse) { - var self = this; - - /** - * Example: - * expression = "address in addresses | filter: {street: $select.search} track by $index" - * itemName = "address", - * source = "addresses | filter: {street: $select.search}", - * trackByExp = "$index", - */ - self.parse = function (expression) { - - var match = expression.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/); - - if (!match) { - throw uiSelectMinErr('iexp', - "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.", - expression); - } - - return { - itemName: match[2], // (lhs) Left-hand side, - source: $parse(match[3]), - trackByExp: match[4], - modelMapper: $parse(match[1] || match[2]) - }; - - }; - - self.getGroupNgRepeatExpression = function () { - return '$group in $select.groups'; - }; - - self.getNgRepeatExpression = function (itemName, source, trackByExp, grouped) { - var expression = itemName + ' in ' + (grouped ? '$group.items' : source); - if (trackByExp) { - expression += ' track by ' + trackByExp; - } - return expression; - }; -}]); - -}()); -angular.module("ui.select").run(["$templateCache", function($templateCache) {$templateCache.put("selectize/choices.tpl.html","
    "); -$templateCache.put("selectize/match.tpl.html","
    "); -$templateCache.put("selectize/select.tpl.html","
    ");}]); \ No newline at end of file diff --git a/dist/select.selectize.min.js b/dist/select.selectize.min.js deleted file mode 100644 index 059169712..000000000 --- a/dist/select.selectize.min.js +++ /dev/null @@ -1,7 +0,0 @@ -/*! - * ui-select - * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-11T18:41:59.483Z - * License: MIT - */ -!function(){"use strict";void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),void 0===angular.element.prototype.closest&&(angular.element.prototype.closest=function(e){for(var t=this[0],n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;t;){if(n.bind(t)(e))return t;t=t.parentElement}return!1});var e=0,t=angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,sortable:!1,placeholder:"",closeOnSelect:!0,generateId:function(){return e++},appendToBody:!1}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),n=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(n)}}).directive("uisTranscludeAppend",function(){return{link:function(e,t,n,i,c){c(e,function(e){t.append(e)})}}}).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n){return t=String(t),n&&t?t.replace(new RegExp(e(n),"gi"),'$&'):t}}).factory("uisOffset",["$document","$window",function(e,t){return function(n){var i=n[0].getBoundingClientRect();return{width:i.width||n.prop("offsetWidth"),height:i.height||n.prop("offsetHeight"),top:i.top+(t.pageYOffset||e[0].documentElement.scrollTop),left:i.left+(t.pageXOffset||e[0].documentElement.scrollLeft)}}}]);t.directive("uiSelectChoices",["uiSelectConfig","uisRepeatParser","uiSelectMinErr","$compile",function(e,t,n,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme;return n+"/choices.tpl.html"},compile:function(e,c){if(!c.repeat)throw n("repeat","Expected 'repeat' expression.");return function(e,c,r,l,s){var o=r.groupBy,a=r.groupFilter;if(l.parseRepeatAttr(r.repeat,o,a),l.disableChoiceExpression=r.uiDisableChoice,l.onHighlightCallback=r.onHighlight,o){var u=c.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw n("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=c.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw n("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(l.parserResult.itemName,"$select.items",l.parserResult.trackByExp,o)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+l.parserResult.itemName+")").attr("ng-click","$select.select("+l.parserResult.itemName+",false,$event)");var d=c.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw n("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),i(c,s)(e),e.$watch("$select.search",function(e){e&&!l.open&&l.multiple&&l.activate(!1,!0),l.activeIndex=0})}}}}]),t.controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","$q","uisRepeatParser","uiSelectMinErr","uiSelectConfig",function(e,t,n,i,c,r,l,s){function o(){(d.resetSearchInput||void 0===d.resetSearchInput&&s.resetSearchInput)&&(d.search=f,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function a(e,t){var n,i,c=[];for(n=0;n0&&d.activeIndex--;break;case d.KEY.TAB:(!d.multiple||d.open)&&d.select(d.items[d.activeIndex],!0);break;case d.KEY.ENTER:d.open?void 0!==d.items[d.activeIndex]&&d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case d.KEY.ESC:d.close();break;default:t=!1}return t}function p(){var e=t.querySelectorAll(".ui-select-choices-content"),n=e.querySelectorAll(".ui-select-choices-row");if(n.length<1)throw l("choices","Expected multiple .ui-select-choices-row but got '{0}'.",n.length);if(!(d.activeIndex<0)){var i=n[d.activeIndex],c=i.offsetTop+i.clientHeight-e[0].scrollTop,r=e[0].offsetHeight;c>r?e[0].scrollTop+=c-r:c=112&&123>=e},isVerticalMovement:function(e){return~[d.KEY.UP,d.KEY.DOWN].indexOf(e)},isHorizontalMovement:function(e){return~[d.KEY.LEFT,d.KEY.RIGHT,d.KEY.BACKSPACE,d.KEY.DELETE].indexOf(e)}},d.isEmpty=function(){return angular.isUndefined(d.selected)||null===d.selected||""===d.selected},d.findGroupByName=function(e){return d.groups&&d.groups.filter(function(t){return t.name===e})[0]},d.activate=function(t,i){if(d.disabled||d.open)d.open&&!d.searchEnabled&&d.close();else{var c=function(){i||o(),e.$broadcast("uis:activate"),d.open=!0,d.searchEnabled||angular.element(d.searchInput[0]).addClass("ui-select-offscreen"),d.activeIndex=d.activeIndex>=d.items.length?0:d.activeIndex,n(function(){d.search=t||d.search,d.searchInput[0].focus()})},r=d.beforeDropdownOpen();angular.isFunction(r.then)?r.then(function(e){e===!0&&c()}):r===!0&&c()}},d.parseRepeatAttr=function(t,n,i){function c(t){var c=e.$eval(n);if(d.groups=[],angular.forEach(t,function(e){var t=angular.isFunction(c)?c(e):e[c],n=d.findGroupByName(t);n?n.items.push(e):d.groups.push({name:t,items:[e]})}),i){var r=e.$eval(i);angular.isFunction(r)?d.groups=r(d.groups):angular.isArray(r)&&(d.groups=a(d.groups,r))}d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function s(e){d.items=e}d.setItemsFn=n?c:s,d.parserResult=r.parse(t),d.isGrouped=!!n,d.itemProperty=d.parserResult.itemName,d.refreshItems=function(t){t=t||d.parserResult.source(e);var n=d.selected;if(d.isEmpty()||angular.isArray(n)&&!n.length||!d.removeSelected)d.setItemsFn(t);else if(void 0!==t){var i=t.filter(function(e){return n.indexOf(e)<0});d.setItemsFn(i)}},e.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw l("items","Expected an array but got '{0}'.",e);d.refreshItems(e),d.ngModel.$modelValue=null}})},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){if(!d.open)return!1;var t=d.items.indexOf(e[d.itemProperty]),n=-1===t?!1:t===d.activeIndex;return n},d.isDisabled=function(e){if(!d.open)return!1;var t,n=d.items.indexOf(e[d.itemProperty]),i=!1;return n>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[n],i=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i},d.select=function(t,i,c){function r(){e.$broadcast("uis:select",t),n(function(){d.afterSelect(t)}),d.closeOnSelect&&d.close(i),c&&"click"===c.type&&(d.clickTriggeredSelect=!0)}if((void 0===t||!t._uiSelectChoiceDisabled)&&(d.items||d.search)){var l=d.beforeSelect(t);angular.isFunction(l.then)?l.then(function(e){e&&(e===!0?r(t):e&&r(e))}):l===!0?r(t):l&&r(l)}},d.close=function(t){function n(){d.ngModel&&d.ngModel.$setTouched&&d.ngModel.$setTouched(),o(),d.open=!1,d.searchEnabled||angular.element(d.searchInput[0]).removeClass("ui-select-offscreen"),e.$broadcast("uis:close",t)}if(d.open){var i=d.beforeDropdownClose();angular.isFunction(i.then)?i.then(function(e){e===!0&&n()}):i===!0&&n()}},d.setFocus=function(){d.focus||d.focusInput[0].focus()},d.clear=function(e){d.select(void 0),e.stopPropagation(),n(function(){d.focusser[0].focus()},0,!1)},d.toggle=function(e){d.open?(d.close(),e.preventDefault(),e.stopPropagation()):d.activate()},d.isLocked=function(e,t){var n,i=d.selected[t];return i&&!angular.isUndefined(d.lockChoiceExpression)&&(n=!!e.$eval(d.lockChoiceExpression),i._uiSelectChoiceLocked=n),n};var h=null;d.sizeSearchInput=function(){var t=d.searchInput[0],i=d.searchInput.parent().parent()[0],c=function(){return i.clientWidth*!!t.offsetParent},r=function(e){if(0===e)return!1;var n=e-t.offsetLeft-d.searchInput.parent()[0].offsetLeft-5;return 50>n&&(n=e),d.searchInput.css("width",n+"px"),!0};d.searchInput.css("width","10px"),n(function(){null!==h||r(c())||(h=e.$watch(c,function(e){r(e)&&(h(),h=null)}))})},d.searchInput.on("keydown",function(t){var n=t.which;~[d.KEY.ESC,d.KEY.TAB].indexOf(n)&&d.close(),e.$apply(function(){u(n)}),d.KEY.isVerticalMovement(n)&&d.items.length>0&&p(),(n===d.KEY.ENTER||n===d.KEY.ESC)&&(t.preventDefault(),t.stopPropagation())}),d.searchInput.on("keyup",function(e){e.which===d.KEY.TAB||d.KEY.isControl(e)||d.KEY.isFunctionKey(e)||e.which===d.KEY.ESC||d.KEY.isVerticalMovement(e.which)||d.afterKeypress(e)}),e.$on("$destroy",function(){d.searchInput.off("keyup keydown blur paste")}),d.afterKeypress=function(){},d.beforeSelect=function(){return!0},d.afterSelect=function(){},d.beforeRemove=function(){return!0},d.afterRemove=function(){},d.beforeDropdownOpen=function(){return!0},d.beforeDropdownClose=function(){return!0}}]),t.directive("uiSelect",["$document","$window","uiSelectConfig","uiSelectMinErr","uisOffset","$compile","$parse","$timeout",function(e,t,n,i,c,r,l,s){return{restrict:"EA",templateUrl:function(e,t){var i=t.theme||n.theme;return i+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","^ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",compile:function(r,o){return angular.isDefined(o.multiple)?r.append("").removeAttr("multiple"):r.append(""),function(r,o,a,u,p){function d(e){if(v.open){var t=!1;if(t=window.jQuery?window.jQuery.contains(o[0],e.target):o[0].contains(e.target),!t&&!v.clickTriggeredSelect){var n=["input","button","textarea"],i=angular.element(e.target).controller("uiSelect"),c=i&&i!==v;c||(c=~n.indexOf(e.target.tagName.toLowerCase())),v.close(c),r.$digest()}v.clickTriggeredSelect=!1}}function f(){var t=c(o);S=angular.element('
    '),S[0].style.width=t.width+"px",S[0].style.height=t.height+"px",o.after(S),b=o[0].style.width,e.find("body").append(o),o[0].style.position="absolute",o[0].style.left=t.left+"px",o[0].style.top=t.top+"px",o[0].style.width=t.width+"px"}function h(){null!==S&&(S.replaceWith(o),S=null,o[0].style.position="",o[0].style.left="",o[0].style.top="",o[0].style.width=b)}var v=u[0],g=u[1];v.generatedId=n.generateId(),v.baseTitle=a.title||"Select box",v.focusserTitle=v.baseTitle+" focus",v.focusserId="focusser-"+v.generatedId,v.closeOnSelect=function(){return angular.isDefined(a.closeOnSelect)?l(a.closeOnSelect)():n.closeOnSelect}(),v.limit=angular.isDefined(a.limit)?parseInt(a.limit,10):void 0,v.ngModel=g,v.choiceGrouped=function(e){return v.isGrouped&&e&&e.name},a.tabindex&&a.$observe("tabindex",function(e){v.focusInput.attr("tabindex",e),o.removeAttr("tabindex")});var m=r.$eval(a.searchEnabled);v.searchEnabled=void 0!==m?m:n.searchEnabled;var E=r.$eval(a.sortable);v.sortable=void 0!==E?E:n.sortable,a.$observe("disabled",function(){v.disabled=void 0!==a.disabled?a.disabled:!1}),angular.isDefined(a.autofocus)&&s(function(){v.setFocus()}),angular.isDefined(a.focusOn)&&r.$on(a.focusOn,function(){s(function(){v.setFocus()})}),e.on("click",d),r.$on("$destroy",function(){e.off("click",d)}),p(r,function(e){var t=angular.element("
    ").append(e),n=t.querySelectorAll(".ui-select-match");if(n.removeAttr("ui-select-match"),n.removeAttr("data-ui-select-match"),1!==n.length)throw i("transcluded","Expected 1 .ui-select-match but got '{0}'.",n.length);o.querySelectorAll(".ui-select-match").replaceWith(n);var c=t.querySelectorAll(".ui-select-choices");if(c.removeAttr("ui-select-choices"),c.removeAttr("data-ui-select-choices"),1!==c.length)throw i("transcluded","Expected 1 .ui-select-choices but got '{0}'.",c.length);o.querySelectorAll(".ui-select-choices").replaceWith(c)});var $=r.$eval(a.appendToBody);(void 0!==$?$:n.appendToBody)&&(r.$watch("$select.open",function(e){e?f():h()}),r.$on("$destroy",function(){h()}));var S=null,b="",w=null,x="direction-up";r.$watch("$select.open",function(n){if(n){if(w=angular.element(o).querySelectorAll(".ui-select-dropdown"),null===w)return;w[0].style.opacity=0,s(function(){var n=c(o),i=c(w);n.top+n.height+i.height>t.pageYOffset+e[0].documentElement.clientHeight&&o.addClass(x),w[0].style.opacity=1})}else{if(null===w)return;o.removeClass(x)}})}}}}]),t.directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var n=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return n+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,n,i,c){function r(e){c.allowClear=angular.isDefined(e)?""===e?!0:"true"===e.toLowerCase():!1}c.lockChoiceExpression=i.uiLockChoice,i.$observe("placeholder",function(t){c.placeholder=void 0!==t?t:e.placeholder}),i.$observe("allowClear",r),r(i.allowClear),c.multiple&&c.sizeSearchInput()}}}]),t.directive("uiSelectMultiple",["uiSelectMinErr","$timeout",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],controller:["$scope","$timeout",function(e,t){var n,i=this,c=e.$select;e.$evalAsync(function(){n=e.ngModel}),i.activeMatchIndex=-1,i.updateModel=function(){n.$setViewValue(Date.now()),i.refreshComponent()},i.refreshComponent=function(){c.refreshItems(),c.sizeSearchInput()},i.removeChoice=function(e){function n(){c.selected.splice(e,1),i.activeMatchIndex=-1,c.sizeSearchInput(),t(function(){c.afterRemove(r)}),i.updateModel()}var r=c.selected[e];if(!r._uiSelectChoiceLocked){var l=c.beforeRemove(r);angular.isFunction(l.then)?l.then(function(e){e===!0&&n()}):l===!0&&n()}},i.getPlaceholder=function(){return c.selected&&c.selected.length?void 0:c.placeholder}}],controllerAs:"$selectMultiple",link:function(n,i,c,r){function l(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function s(e){function t(){switch(e){case o.KEY.LEFT:return~u.activeMatchIndex?p:r;case o.KEY.RIGHT:return~u.activeMatchIndex&&s!==r?a:(o.activate(),!1);case o.KEY.BACKSPACE:return~u.activeMatchIndex?(u.removeChoice(s),p):r;case o.KEY.DELETE:return~u.activeMatchIndex?(u.removeChoice(u.activeMatchIndex),s):!1}}var n=l(o.searchInput[0]),i=o.selected.length,c=0,r=i-1,s=u.activeMatchIndex,a=u.activeMatchIndex+1,p=u.activeMatchIndex-1,d=s;return n>0||o.search.length&&e==o.KEY.RIGHT?!1:(o.close(),d=t(),u.activeMatchIndex=o.selected.length&&d!==!1?Math.min(r,Math.max(c,d)):-1,!0)}var o=r[0],a=n.ngModel=r[1],u=n.$selectMultiple;o.multiple=!0,o.removeSelected=!0,o.focusInput=o.searchInput,a.$parsers.unshift(function(){for(var e,t={},i=[],c=o.selected.length-1;c>=0;c--)t={},t[o.parserResult.itemName]=o.selected[c],e=o.parserResult.modelMapper(n,t),i.unshift(e);return i}),a.$formatters.unshift(function(e){var t,i=o.parserResult.source(n,{$select:{search:""}}),c={};if(!i)return e;var r=[],l=function(e,i){if(e&&e.length){for(var l=e.length-1;l>=0;l--){if(c[o.parserResult.itemName]=e[l],t=o.parserResult.modelMapper(n,c),o.parserResult.trackByExp){var s=/\.(.+)/.exec(o.parserResult.trackByExp);if(s.length>0&&t[s[1]]==i[s[1]])return r.unshift(e[l]),!0}if(angular.equals(t,i))return r.unshift(e[l]),!0}return!1}};if(!e)return r;for(var s=e.length-1;s>=0;s--)l(o.selected,e[s])||l(i,e[s])||r.unshift(e[s]);return r}),n.$watchCollection(function(){return a.$modelValue},function(e,t){t!=e&&(a.$modelValue=null,u.refreshComponent())}),a.$render=function(){if(!angular.isArray(a.$viewValue)){if(!angular.isUndefined(a.$viewValue)&&null!==a.$viewValue)throw e("multiarr","Expected model value to be array but got '{0}'",a.$viewValue);o.selected=[]}o.selected=a.$viewValue,n.$evalAsync()},n.$on("uis:select",function(e,t){o.selected.length>=o.limit||(o.selected.push(t),u.updateModel())}),n.$on("uis:activate",function(){u.activeMatchIndex=-1}),n.$watch("$select.disabled",function(e,t){t&&!e&&o.sizeSearchInput()}),o.searchInput.on("keydown",function(e){var t=e.which;n.$apply(function(){var e=!1;o.KEY.isHorizontalMovement(t)&&(e=s(t)),e&&t!=o.KEY.TAB})}),o.searchInput.on("blur",function(){t(function(){u.activeMatchIndex=-1})})}}}]),t.directive("uiSelectSingle",["$timeout","$compile",function(e,t){return{restrict:"EA",require:["^uiSelect","^ngModel"],link:function(n,i,c,r){var l=r[0],s=r[1];s.$parsers.unshift(function(e){var t,i={};return i[l.parserResult.itemName]=e,t=l.parserResult.modelMapper(n,i)}),s.$formatters.unshift(function(e){var t,i=l.parserResult.source(n,{$select:{search:""}}),c={};if(i){var r=function(i){return c[l.parserResult.itemName]=i,t=l.parserResult.modelMapper(n,c),t==e};if(l.selected&&r(l.selected))return l.selected;for(var s=i.length-1;s>=0;s--)if(r(i[s]))return i[s]}return e}),n.$watch("$select.selected",function(e){s.$viewValue!==e&&s.$setViewValue(e)}),s.$render=function(){l.selected=s.$viewValue},n.$on("uis:select",function(e,t){l.selected=t}),n.$on("uis:close",function(t,n){e(function(){l.focusser.prop("disabled",!1),n||l.focusser[0].focus()},0,!1)}),n.$on("uis:activate",function(){o.prop("disabled",!0)});var o=angular.element("");t(o)(n),l.focusser=o,l.focusInput=o,i.parent().append(o),o.bind("focus",function(){n.$evalAsync(function(){l.focus=!0})}),o.bind("blur",function(){n.$evalAsync(function(){l.focus=!1})}),o.bind("keydown",function(e){return e.which===l.KEY.BACKSPACE?(e.preventDefault(),e.stopPropagation(),l.select(void 0),n.$apply(),void 0):(e.which===l.KEY.TAB||l.KEY.isControl(e)||l.KEY.isFunctionKey(e)||e.which===l.KEY.ESC||((e.which==l.KEY.DOWN||e.which==l.KEY.UP||e.which==l.KEY.ENTER||e.which==l.KEY.SPACE)&&(e.preventDefault(),e.stopPropagation(),l.activate()),n.$digest()),void 0)}),o.bind("keyup input",function(e){e.which===l.KEY.TAB||l.KEY.isControl(e)||l.KEY.isFunctionKey(e)||e.which===l.KEY.ESC||e.which==l.KEY.ENTER||e.which===l.KEY.BACKSPACE||(l.activate(o.val()),o.val(""),n.$digest())})}}}]),t.service("uisRepeatParser",["uiSelectMinErr","$parse",function(e,t){var n=this;n.parse=function(n){var i=n.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!i)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",n);return{itemName:i[2],source:t(i[3]),trackByExp:i[4],modelMapper:t(i[1]||i[2])}},n.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},n.getNgRepeatExpression=function(e,t,n,i){var c=e+" in "+(i?"$group.items":t);return n&&(c+=" track by "+n),c}}])}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("selectize/choices.tpl.html",'
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/dist/select.sort.js b/dist/select.sort.js deleted file mode 100644 index be9742d9c..000000000 --- a/dist/select.sort.js +++ /dev/null @@ -1,234 +0,0 @@ -/*! - * ui-select - * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-11T18:41:59.488Z - * License: MIT - */ - - -(function () { -"use strict"; -// Make multiple matches sortable -angular.module('ui.select.sort', ['ui.select']) - .directive('uiSelectSort', - ['$timeout', 'uiSelectConfig', 'uiSelectMinErr', function ($timeout, uiSelectConfig, uiSelectMinErr) { - return { - require: '^uiSelect', - link: function (scope, element, attrs, $select) { - if (scope[attrs.uiSelectSort] === null) { - throw uiSelectMinErr('sort', "Expected a list to sort"); - } - - var options = angular.extend({ - axis: 'horizontal' - }, - scope.$eval(attrs.uiSelectSortOptions)); - - var axis = options.axis, - draggingClassName = 'dragging', - droppingClassName = 'dropping', - droppingBeforeClassName = 'dropping-before', - droppingAfterClassName = 'dropping-after'; - - scope.$watch(function () { - return $select.sortable; - }, function (n) { - if (n) { - element.attr('draggable', true); - } else { - element.removeAttr('draggable'); - } - }); - - element.on('dragstart', function (e) { - element.addClass(draggingClassName); - - (e.dataTransfer || e.originalEvent.dataTransfer).setData('text/plain', scope.$index); - }); - - element.on('dragend', function () { - element.removeClass(draggingClassName); - }); - - var move = function (from, to) { - /*jshint validthis: true */ - this.splice(to, 0, this.splice(from, 1)[0]); - }; - - var dragOverHandler = function (e) { - e.preventDefault(); - - var offset = axis === 'vertical' ? - e.offsetY || e.layerY || (e.originalEvent ? e.originalEvent.offsetY : 0) : - e.offsetX || e.layerX || (e.originalEvent ? e.originalEvent.offsetX : 0); - - if (offset < (this[axis === 'vertical' ? 'offsetHeight' : 'offsetWidth'] / 2)) { - element.removeClass(droppingAfterClassName); - element.addClass(droppingBeforeClassName); - - } else { - element.removeClass(droppingBeforeClassName); - element.addClass(droppingAfterClassName); - } - }; - - var dropTimeout; - - var dropHandler = function (e) { - e.preventDefault(); - - var droppedItemIndex = parseInt((e.dataTransfer || - e.originalEvent.dataTransfer).getData('text/plain'), 10); - - // prevent event firing multiple times in firefox - $timeout.cancel(dropTimeout); - dropTimeout = $timeout(function () { - _dropHandler(droppedItemIndex); - }, 20); - }; - - var _dropHandler = function (droppedItemIndex) { - var theList = scope.$eval(attrs.uiSelectSort), - itemToMove = theList[droppedItemIndex], - newIndex = null; - - if (element.hasClass(droppingBeforeClassName)) { - if (droppedItemIndex < scope.$index) { - newIndex = scope.$index - 1; - } else { - newIndex = scope.$index; - } - } else { - if (droppedItemIndex < scope.$index) { - newIndex = scope.$index; - } else { - newIndex = scope.$index + 1; - } - } - - move.apply(theList, [droppedItemIndex, newIndex]); - - scope.$apply(function () { - scope.$emit('uiSelectSort:change', { - array: theList, - item: itemToMove, - from: droppedItemIndex, - to: newIndex - }); - }); - - element.removeClass(droppingClassName); - element.removeClass(droppingBeforeClassName); - element.removeClass(droppingAfterClassName); - - element.off('drop', dropHandler); - }; - - element.on('dragenter', function () { - if (element.hasClass(draggingClassName)) { - return; - } - - element.addClass(droppingClassName); - - element.on('dragover', dragOverHandler); - element.on('drop', dropHandler); - }); - - element.on('dragleave', function (e) { - if (e.target != element) { - return; - } - element.removeClass(droppingClassName); - element.removeClass(droppingBeforeClassName); - element.removeClass(droppingAfterClassName); - - element.off('dragover', dragOverHandler); - element.off('drop', dropHandler); - }); - } - }; - }]); - -}());d - if (_findCaseInsensitiveDupe(stashArr.concat($select.selected))) { - // if there is a tag from prev iteration, strip it / queue the change - // and return early - if (hasTag) { - items = stashArr; - scope.$evalAsync(function () { - $select.activeIndex = 0; - $select.items = items; - }); - } - return; - } - if (_findCaseInsensitiveDupe(stashArr)) { - // If there is a tag from prev iteration, strip it - if (hasTag) { - $select.items = stashArr.slice(1, stashArr.length); - } - return; - } - - if (hasTag) { - dupeIndex = _findApproxDupe($select.selected, newItem); - } - // dupe found, shave the first item - if (dupeIndex > -1) { - items = items.slice(dupeIndex + 1, items.length - 1); - } else { - items = []; - items.push(newItem); - items = items.concat(stashArr); - } - scope.$evalAsync(function () { - $select.activeIndex = 0; - $select.items = items; - }); - } - }; - - - function _findCaseInsensitiveDupe(arr) { - if (arr === undefined || $select.search === undefined) { - return false; - } - return arr.filter(function (origItem) { - if ($select.search.toUpperCase() === undefined || origItem === undefined) { - return false; - } - return origItem.toUpperCase() === $select.search.toUpperCase(); - }).length > 0; - } - - function _findApproxDupe(haystack, needle) { - var dupeIndex = -1; - if (angular.isArray(haystack)) { - var tempArr = angular.copy(haystack); - for (var i = 0; i < tempArr.length; i++) { - // handle the simple string version of tagging -// if ($select.tagging.fct === undefined) { - // search the array for the match - if (tempArr[i] + ' ' + $select.taggingLabel === needle) { - dupeIndex = i; - } - // handle the object tagging implementation - /* } else { - var mockObj = tempArr[i]; - mockObj.isTag = true; - if (angular.equals(mockObj, needle)) { - dupeIndex = i; - } - }*/ - } - } - return dupeIndex; - } - - - } - }; - }]); - -}()); \ No newline at end of file diff --git a/dist/select.sort.min.js b/dist/select.sort.min.js deleted file mode 100644 index 61358e531..000000000 --- a/dist/select.sort.min.js +++ /dev/null @@ -1,7 +0,0 @@ -/*! - * ui-select - * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-11T18:41:59.488Z - * License: MIT - */ -!function(){"use strict";angular.module("ui.select.sort",["ui.select"]).directive("uiSelectSort",["$timeout","uiSelectConfig","uiSelectMinErr",function(e,t,a){return{require:"^uiSelect",link:function(t,r,n,i){if(null===t[n.uiSelectSort])throw a("sort","Expected a list to sort");var o=angular.extend({axis:"horizontal"},t.$eval(n.uiSelectSortOptions)),s=o.axis,l="dragging",f="dropping",d="dropping-before",u="dropping-after";t.$watch(function(){return i.sortable},function(e){e?r.attr("draggable",!0):r.removeAttr("draggable")}),r.on("dragstart",function(e){r.addClass(l),(e.dataTransfer||e.originalEvent.dataTransfer).setData("text/plain",t.$index)}),r.on("dragend",function(){r.removeClass(l)});var c,v=function(e,t){this.splice(t,0,this.splice(e,1)[0])},g=function(e){e.preventDefault();var t="vertical"===s?e.offsetY||e.layerY||(e.originalEvent?e.originalEvent.offsetY:0):e.offsetX||e.layerX||(e.originalEvent?e.originalEvent.offsetX:0);t-1)return;if(a(h.concat(i.selected)))return f&&(u=h,e.$evalAsync(function(){i.activeIndex=0,i.items=u})),void 0;if(a(h))return f&&(i.items=h.slice(1,h.length)),void 0;f&&(v=g(i.selected,c)),v>-1?u=u.slice(v+1,u.length-1):(u=[],u.push(c),u=u.concat(h)),e.$evalAsync(function(){i.activeIndex=0,i.items=u})}}}}}])}(); \ No newline at end of file diff --git a/dist/select.tpl.js b/dist/select.tpl.js deleted file mode 100644 index f6ef70af6..000000000 --- a/dist/select.tpl.js +++ /dev/null @@ -1,21 +0,0 @@ -/*! - * ui-select - * http://github.com/angular-ui/ui-select - * Version: 0.12.1 - 2015-08-11T18:41:59.440Z - * License: MIT - */ - - -angular.module("ui.select").run(["$templateCache", function($templateCache) {$templateCache.put("selectize/choices.tpl.html","
    "); -$templateCache.put("selectize/match.tpl.html","
    "); -$templateCache.put("selectize/select.tpl.html","
    ");}]); -angular.module("ui.select").run(["$templateCache", function($templateCache) {$templateCache.put("bootstrap/choices.tpl.html","
      0\">
    • 0\">
    "); -$templateCache.put("bootstrap/match-multiple.tpl.html"," × "); -$templateCache.put("bootstrap/match.tpl.html","
    {{$select.placeholder}}
    "); -$templateCache.put("bootstrap/select-multiple.tpl.html","
    "); -$templateCache.put("bootstrap/select.tpl.html","
    ");}]); -angular.module("ui.select").run(["$templateCache", function($templateCache) {$templateCache.put("select2/choices.tpl.html","
    "); -$templateCache.put("select2/match-multiple.tpl.html","
  • "); -$templateCache.put("select2/match.tpl.html","{{$select.placeholder}} "); -$templateCache.put("select2/select-multiple.tpl.html","
    "); -$templateCache.put("select2/select.tpl.html","
    ");}]); \ No newline at end of file