Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Fixed determination of dropdown direction #1188

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions dist/select.js
Original file line number Diff line number Diff line change
@@ -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-09-10T21:05:24.707Z
* License: MIT
*/

Expand Down Expand Up @@ -382,11 +382,11 @@ 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 ) {
var filteredItems = data.filter(function(i) {return selectedItems.indexOf(i) < 0;});
var filteredItems = data.filter(function(i) {return selectedItems && selectedItems.indexOf(i) < 0;});
ctrl.setItemsFn(filteredItems);
}
}
Expand Down Expand Up @@ -803,6 +803,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;

Expand Down Expand Up @@ -905,8 +908,8 @@ uis.directive('uiSelect',
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
var targetController = angular.element(e.target).controller('uiSelect'); //To check if target is other ui-select
var skipFocusser = targetController && targetController !== $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();
Expand Down Expand Up @@ -1025,11 +1028,10 @@ uis.directive('uiSelect',

// 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) {
if (offsetDropdown.top + offsetDropdown.height > window.innerHeight + window.pageYOffset) {
dropdown[0].style.position = 'absolute';
dropdown[0].style.top = (offsetDropdown.height * -1) + 'px';
element.addClass(directionUpClassName);
Expand Down Expand Up @@ -1145,7 +1147,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;
};

Expand Down Expand Up @@ -1244,6 +1246,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();
});
Expand Down Expand Up @@ -1488,6 +1493,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
}
};
}]);

uis.directive('uiSelectSingle', ['$timeout','$compile', function($timeout, $compile) {
return {
restrict: 'EA',
Expand Down
Loading