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

Commit 0e4552d

Browse files
graingertaaronroberson
authored andcommitted
chore(uiSelectController): use _findIndex instead of polyfill
1 parent 5f2d229 commit 0e4552d

File tree

5 files changed

+43
-55
lines changed

5 files changed

+43
-55
lines changed

dist/select.css

Lines changed: 1 addition & 1 deletion
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.14.3 - 2016-02-18T15:32:28.784Z
4+
* Version: 0.14.3 - 2016-02-18T19:58:15.973Z
55
* License: MIT
66
*/
77

dist/select.js

Lines changed: 20 additions & 26 deletions
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.14.3 - 2016-02-18T15:32:28.698Z
4+
* Version: 0.14.3 - 2016-02-18T19:58:15.912Z
55
* License: MIT
66
*/
77

@@ -312,13 +312,31 @@ uis.controller('uiSelectCtrl',
312312
return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === '' || (ctrl.multiple && ctrl.selected.length === 0);
313313
};
314314

315+
function _findIndex(collection, predicate, thisArg){
316+
if (collection.findIndex){
317+
return collection.findIndex(predicate, thisArg);
318+
} else {
319+
var list = Object(collection);
320+
var length = list.length >>> 0;
321+
var value;
322+
323+
for (var i = 0; i < length; i++) {
324+
value = list[i];
325+
if (predicate.call(thisArg, value, i, list)) {
326+
return i;
327+
}
328+
}
329+
return -1;
330+
}
331+
}
332+
315333
// Most of the time the user does not want to empty the search input when in typeahead mode
316334
function _resetSearchInput() {
317335
if (ctrl.resetSearchInput || (ctrl.resetSearchInput === undefined && uiSelectConfig.resetSearchInput)) {
318336
ctrl.search = EMPTY_SEARCH;
319337
//reset activeIndex
320338
if (ctrl.selected && ctrl.items.length && !ctrl.multiple) {
321-
ctrl.activeIndex = ctrl.items.findIndex(function(item){
339+
ctrl.activeIndex = _findIndex(ctrl.items, function(item){
322340
return angular.equals(this, item);
323341
}, ctrl.selected);
324342
}
@@ -828,30 +846,6 @@ uis.controller('uiSelectCtrl',
828846

829847
}]);
830848

831-
// Array findIndex polyfill (source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex#Polyfill)
832-
if (!Array.prototype.findIndex) {
833-
Array.prototype.findIndex = function(predicate) {
834-
if (this === null) {
835-
throw new TypeError('Array.prototype.findIndex called on null or undefined');
836-
}
837-
if (typeof predicate !== 'function') {
838-
throw new TypeError('predicate must be a function');
839-
}
840-
var list = Object(this);
841-
var length = list.length >>> 0;
842-
var thisArg = arguments[1];
843-
var value;
844-
845-
for (var i = 0; i < length; i++) {
846-
value = list[i];
847-
if (predicate.call(thisArg, value, i, list)) {
848-
return i;
849-
}
850-
}
851-
return -1;
852-
};
853-
}
854-
855849
uis.directive('uiSelect',
856850
['$document', 'uiSelectConfig', 'uiSelectMinErr', 'uisOffset', '$compile', '$parse', '$timeout',
857851
function($document, uiSelectConfig, uiSelectMinErr, uisOffset, $compile, $parse, $timeout) {

dist/select.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/select.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/uiSelectController.js

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,31 @@ uis.controller('uiSelectCtrl',
6060
return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === '' || (ctrl.multiple && ctrl.selected.length === 0);
6161
};
6262

63+
function _findIndex(collection, predicate, thisArg){
64+
if (collection.findIndex){
65+
return collection.findIndex(predicate, thisArg);
66+
} else {
67+
var list = Object(collection);
68+
var length = list.length >>> 0;
69+
var value;
70+
71+
for (var i = 0; i < length; i++) {
72+
value = list[i];
73+
if (predicate.call(thisArg, value, i, list)) {
74+
return i;
75+
}
76+
}
77+
return -1;
78+
}
79+
}
80+
6381
// Most of the time the user does not want to empty the search input when in typeahead mode
6482
function _resetSearchInput() {
6583
if (ctrl.resetSearchInput || (ctrl.resetSearchInput === undefined && uiSelectConfig.resetSearchInput)) {
6684
ctrl.search = EMPTY_SEARCH;
6785
//reset activeIndex
6886
if (ctrl.selected && ctrl.items.length && !ctrl.multiple) {
69-
ctrl.activeIndex = ctrl.items.findIndex(function(item){
87+
ctrl.activeIndex = _findIndex(ctrl.items, function(item){
7088
return angular.equals(this, item);
7189
}, ctrl.selected);
7290
}
@@ -575,27 +593,3 @@ uis.controller('uiSelectCtrl',
575593
});
576594

577595
}]);
578-
579-
// Array findIndex polyfill (source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex#Polyfill)
580-
if (!Array.prototype.findIndex) {
581-
Array.prototype.findIndex = function(predicate) {
582-
if (this === null) {
583-
throw new TypeError('Array.prototype.findIndex called on null or undefined');
584-
}
585-
if (typeof predicate !== 'function') {
586-
throw new TypeError('predicate must be a function');
587-
}
588-
var list = Object(this);
589-
var length = list.length >>> 0;
590-
var thisArg = arguments[1];
591-
var value;
592-
593-
for (var i = 0; i < length; i++) {
594-
value = list[i];
595-
if (predicate.call(thisArg, value, i, list)) {
596-
return i;
597-
}
598-
}
599-
return -1;
600-
};
601-
}

0 commit comments

Comments
 (0)