Skip to content

Commit d7a5df2

Browse files
committed
Added test for initial refresh call
1 parent a52f0b2 commit d7a5df2

File tree

7 files changed

+56
-46
lines changed

7 files changed

+56
-46
lines changed

dist/select.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* ui-select
33
* http://github.com/angular-ui/ui-select
4-
* Version: 0.19.5 - 2016-10-24T23:13:59.551Z
4+
* Version: 0.19.6 - 2016-11-08T10:09:40.977Z
55
* License: MIT
66
*/
77

dist/select.js

+41-39
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* ui-select
33
* http://github.com/angular-ui/ui-select
4-
* Version: 0.19.5 - 2016-10-24T23:13:59.434Z
4+
* Version: 0.19.6 - 2016-11-08T10:09:40.868Z
55
* License: MIT
66
*/
77

@@ -118,7 +118,8 @@ var uis = angular.module('ui.select', [])
118118
},
119119
appendToBody: false,
120120
spinnerEnabled: false,
121-
spinnerClass: 'glyphicon-refresh ui-select-spin'
121+
spinnerClass: 'glyphicon-refresh ui-select-spin',
122+
backspaceReset: true
122123
})
123124

124125
// See Rename minErr and make it accessible from outside https://github.com/angular/angular.js/issues/6913
@@ -179,6 +180,31 @@ var uis = angular.module('ui.select', [])
179180
};
180181
}]);
181182

183+
/**
184+
* Debounces functions
185+
*
186+
* Taken from UI Bootstrap $$debounce source code
187+
* See https://github.com/angular-ui/bootstrap/blob/master/src/debounce/debounce.js
188+
*
189+
*/
190+
uis.factory('$$uisDebounce', ['$timeout', function($timeout) {
191+
return function(callback, debounceTime) {
192+
var timeoutPromise;
193+
194+
return function() {
195+
var self = this;
196+
var args = Array.prototype.slice.call(arguments);
197+
if (timeoutPromise) {
198+
$timeout.cancel(timeoutPromise);
199+
}
200+
201+
timeoutPromise = $timeout(function() {
202+
callback.apply(self, args);
203+
}, debounceTime);
204+
};
205+
};
206+
}]);
207+
182208
uis.directive('uiSelectChoices',
183209
['uiSelectConfig', 'uisRepeatParser', 'uiSelectMinErr', '$compile', '$window',
184210
function(uiSelectConfig, RepeatParser, uiSelectMinErr, $compile, $window) {
@@ -236,10 +262,8 @@ uis.directive('uiSelectChoices',
236262

237263

238264
$select.parseRepeatAttr(attrs.repeat, groupByExp, groupFilterExp); //Result ready at $select.parserResult
239-
240265
$select.disableChoiceExpression = attrs.uiDisableChoice;
241266
$select.onHighlightCallback = attrs.onHighlight;
242-
243267
$select.dropdownPosition = attrs.position ? attrs.position.toLowerCase() : uiSelectConfig.dropdownPosition;
244268

245269
scope.$on('$destroy', function() {
@@ -249,7 +273,7 @@ uis.directive('uiSelectChoices',
249273
scope.$watch('$select.search', function(newValue) {
250274
if(newValue && !$select.open && $select.multiple) $select.activate(false, true);
251275
$select.activeIndex = $select.tagging.isActivated ? -1 : 0;
252-
if (!attrs.minimumInputLength || $select.search.length >= attrs.minimumInputLength) {
276+
if ((!attrs.minimumInputLength || $select.search.length >= attrs.minimumInputLength)) {
253277
$select.refresh(attrs.refresh);
254278
} else {
255279
$select.items = [];
@@ -261,10 +285,11 @@ uis.directive('uiSelectChoices',
261285
var refreshDelay = scope.$eval(attrs.refreshDelay);
262286
$select.refreshDelay = refreshDelay !== undefined ? refreshDelay : uiSelectConfig.refreshDelay;
263287
});
264-
288+
265289
scope.$watch('$select.open', function(open) {
266290
if (open) {
267291
tElement.attr('role', 'listbox');
292+
$select.refresh(attrs.refresh);
268293
} else {
269294
tElement.removeAttr('role');
270295
}
@@ -391,11 +416,8 @@ uis.controller('uiSelectCtrl',
391416
if(!avoidReset) _resetSearchInput();
392417

393418
$scope.$broadcast('uis:activate');
394-
395419
ctrl.open = true;
396-
397420
ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex;
398-
399421
// ensure that the index is set to zero for tagging variants
400422
// that where first option is auto-selected
401423
if ( ctrl.activeIndex === -1 && ctrl.taggingLabel !== false ) {
@@ -533,7 +555,6 @@ uis.controller('uiSelectCtrl',
533555
if (ctrl.dropdownPosition === 'auto' || ctrl.dropdownPosition === 'up'){
534556
$scope.calculateDropdownPos();
535557
}
536-
537558
$scope.$broadcast('uis:refresh');
538559
};
539560

@@ -581,7 +602,7 @@ uis.controller('uiSelectCtrl',
581602
var refreshPromise = $scope.$eval(refreshAttr);
582603
if (refreshPromise && angular.isFunction(refreshPromise.then) && !ctrl.refreshing) {
583604
ctrl.refreshing = true;
584-
refreshPromise.then(function() {
605+
refreshPromise.finally(function() {
585606
ctrl.refreshing = false;
586607
});
587608
}}, ctrl.refreshDelay);
@@ -706,7 +727,7 @@ uis.controller('uiSelectCtrl',
706727
ctrl.close(skipFocusser);
707728
return;
708729
}
709-
}
730+
}
710731
_resetSearchInput();
711732
$scope.$broadcast('uis:select', item);
712733

@@ -782,7 +803,7 @@ uis.controller('uiSelectCtrl',
782803
}
783804

784805
if (!isLocked && lockedItemIndex > -1) {
785-
lockedItems.splice(lockedItemIndex, 0);
806+
lockedItems.splice(lockedItemIndex, 1);
786807
}
787808
}
788809

@@ -1117,6 +1138,12 @@ uis.directive('uiSelect',
11171138
$select.sortable = sortable !== undefined ? sortable : uiSelectConfig.sortable;
11181139
});
11191140

1141+
attrs.$observe('backspaceReset', function() {
1142+
// $eval() is needed otherwise we get a string instead of a boolean
1143+
var backspaceReset = scope.$eval(attrs.backspaceReset);
1144+
$select.backspaceReset = backspaceReset !== undefined ? backspaceReset : true;
1145+
});
1146+
11201147
attrs.$observe('limit', function() {
11211148
//Limit the number of selections allowed
11221149
$select.limit = (angular.isDefined(attrs.limit)) ? parseInt(attrs.limit, 10) : undefined;
@@ -2056,7 +2083,7 @@ uis.directive('uiSelectSingle', ['$timeout','$compile', function($timeout, $comp
20562083
});
20572084
focusser.bind("keydown", function(e){
20582085

2059-
if (e.which === KEY.BACKSPACE) {
2086+
if (e.which === KEY.BACKSPACE && $select.backspaceReset !== false) {
20602087
e.preventDefault();
20612088
e.stopPropagation();
20622089
$select.select(undefined);
@@ -2243,31 +2270,6 @@ uis.directive('uiSelectSort', ['$timeout', 'uiSelectConfig', 'uiSelectMinErr', f
22432270
};
22442271
}]);
22452272

2246-
/**
2247-
* Debounces functions
2248-
*
2249-
* Taken from UI Bootstrap $$debounce source code
2250-
* See https://github.com/angular-ui/bootstrap/blob/master/src/debounce/debounce.js
2251-
*
2252-
*/
2253-
uis.factory('$$uisDebounce', ['$timeout', function($timeout) {
2254-
return function(callback, debounceTime) {
2255-
var timeoutPromise;
2256-
2257-
return function() {
2258-
var self = this;
2259-
var args = Array.prototype.slice.call(arguments);
2260-
if (timeoutPromise) {
2261-
$timeout.cancel(timeoutPromise);
2262-
}
2263-
2264-
timeoutPromise = $timeout(function() {
2265-
callback.apply(self, args);
2266-
}, debounceTime);
2267-
};
2268-
};
2269-
}]);
2270-
22712273
uis.directive('uisOpenClose', ['$parse', '$timeout', function ($parse, $timeout) {
22722274
return {
22732275
restrict: 'A',

dist/select.min.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)