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

Commit d24f9bf

Browse files
author
Brian Feister
committed
Merge branch 'master' of github.com:angular-ui/ui-select
Conflicts: dist/select.css dist/select.css.min.css dist/select.js dist/select.min.js src/select.js
2 parents a692a48 + b044b41 commit d24f9bf

File tree

11 files changed

+290
-127
lines changed

11 files changed

+290
-127
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ AngularJS-native version of [Select2](http://ivaynberg.github.io/select2/) and [
44

55
- [Demo](http://plnkr.co/edit/a3KlK8dKH3wwiiksDSn2?p=preview)
66
- [Demo Multiselect](http://plnkr.co/edit/juqoNOt1z1Gb349XabQ2?p=preview)
7-
- [Bootstrap theme](http://plnkr.co/edit/QCwSM75ilH2Vh6D9aMA4?p=preview)
87

98
Check [examples](https://github.com/angular-ui/ui-select/blob/master/examples).
109

bower.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ui-select",
3-
"version": "0.8.0",
3+
"version": "0.8.3",
44
"homepage": "https://github.com/angular-ui/ui-select",
55
"authors": [
66
"AngularUI"
@@ -19,11 +19,11 @@
1919
"examples"
2020
],
2121
"dependencies": {
22-
"angular": "~1.2"
22+
"angular": ">=1.2.18"
2323
},
2424
"devDependencies": {
2525
"jquery": "~1.11",
26-
"angular-sanitize": "~1.2",
27-
"angular-mocks": "~1.2"
26+
"angular-sanitize": ">=1.2.18",
27+
"angular-mocks": ">=1.2.18"
2828
}
2929
}

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.8.0 - 2014-10-07T13:45:31.567Z
4+
* Version: 0.8.3 - 2014-10-14T18:22:05.435Z
55
* License: MIT
66
*/
77

dist/select.css.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.js

Lines changed: 73 additions & 59 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.8.0 - 2014-10-07T13:45:31.563Z
4+
* Version: 0.8.3 - 2014-10-14T18:22:05.432Z
55
* License: MIT
66
*/
77

@@ -27,9 +27,11 @@
2727
END: 35,
2828
BACKSPACE: 8,
2929
DELETE: 46,
30+
COMMAND: 91,
3031
isControl: function (e) {
3132
var k = e.which;
3233
switch (k) {
34+
case KEY.COMMAND:
3335
case KEY.SHIFT:
3436
case KEY.CTRL:
3537
case KEY.ALT:
@@ -158,7 +160,7 @@
158160
ctrl.selected = undefined;
159161
ctrl.open = false;
160162
ctrl.focus = false;
161-
ctrl.focusser = undefined; //Reference to input element used to handle focus events
163+
ctrl.focusser = undefined; //Reference to input element used to handle focus events
162164
ctrl.disabled = undefined; // Initialized inside uiSelect directive link function
163165
ctrl.searchEnabled = undefined; // Initialized inside uiSelect directive link function
164166
ctrl.resetSearchInput = undefined; // Initialized inside uiSelect directive link function
@@ -190,6 +192,7 @@
190192
ctrl.activate = function(initSearchValue, avoidReset) {
191193
if (!ctrl.disabled && !ctrl.open) {
192194
if(!avoidReset) _resetSearchInput();
195+
ctrl.focusser.prop('disabled', true); //Will reactivate it on .close()
193196
ctrl.open = true;
194197
ctrl.activeMatchIndex = -1;
195198

@@ -257,7 +260,7 @@
257260
var filteredItems = items.filter(function(i) {return ctrl.selected.indexOf(i) < 0;});
258261
setItemsFn(filteredItems);
259262
}else{
260-
setItemsFn(items);
263+
setItemsFn(items);
261264
}
262265
ctrl.ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters
263266

@@ -267,13 +270,15 @@
267270
});
268271

269272
if (ctrl.multiple){
270-
//Remove already selected items
273+
//Remove already selected items
271274
$scope.$watchCollection('$select.selected', function(selectedItems){
272-
if (!selectedItems.length) return;
273275
var data = ctrl.parserResult.source($scope);
274-
if (!data) return;
275-
var filteredItems = data.filter(function(i) {return selectedItems.indexOf(i) < 0;});
276-
setItemsFn(filteredItems);
276+
if (!selectedItems.length) {
277+
setItemsFn(data);
278+
}else{
279+
var filteredItems = data.filter(function(i) {return selectedItems.indexOf(i) < 0;});
280+
setItemsFn(filteredItems);
281+
}
277282
ctrl.sizeSearchInput();
278283
});
279284
}
@@ -307,12 +312,13 @@
307312
};
308313

309314
ctrl.isActive = function(itemScope) {
310-
if ( typeof itemScope[ctrl.itemProperty] === 'undefined') {
311-
return false;
312-
}
315+
return ctrl.open && ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex;
313316
};
314317

315318
ctrl.isDisabled = function(itemScope) {
319+
320+
if (!ctrl.open) return;
321+
316322
var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]);
317323
var isDisabled = false;
318324
var item;
@@ -327,14 +333,9 @@
327333
};
328334

329335
// When the user clicks on an item inside the dropdown
330-
ctrl.select = function(item) {
331-
332-
if (!item || !item._uiSelectChoiceDisabled) {
333-
if(ctrl.tagging.isActivated && !item && ctrl.search.length > 0) {
334-
// create new item on the fly
335-
item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : ctrl.search;
336-
}
336+
ctrl.select = function(item, skipFocusser) {
337337

338+
if (item === undefined || !item._uiSelectChoiceDisabled) {
338339
var locals = {};
339340
locals[ctrl.parserResult.itemName] = item;
340341

@@ -349,17 +350,19 @@
349350
} else {
350351
ctrl.selected = item;
351352
}
352-
ctrl.close();
353+
ctrl.close(skipFocusser);
353354
}
354355
};
355356

356357
// Closes the dropdown
357-
ctrl.close = function() {
358-
if (ctrl.open) {
359-
_resetSearchInput();
360-
ctrl.open = false;
358+
ctrl.close = function(skipFocusser) {
359+
if (!ctrl.open) return;
360+
_resetSearchInput();
361+
ctrl.open = false;
362+
if (!ctrl.multiple){
361363
$timeout(function(){
362-
ctrl.focusser[0].focus();
364+
ctrl.focusser.prop('disabled', false);
365+
if (!skipFocusser) ctrl.focusser[0].focus();
363366
},0,false);
364367
}
365368
};
@@ -373,25 +376,48 @@
373376

374377
// Remove item from multiple select
375378
ctrl.removeChoice = function(index){
379+
var removedChoice = ctrl.selected[index];
380+
var locals = {};
381+
locals[ctrl.parserResult.itemName] = removedChoice;
382+
376383
ctrl.selected.splice(index, 1);
377384
ctrl.activeMatchIndex = -1;
378385
ctrl.sizeSearchInput();
386+
387+
ctrl.onRemoveCallback($scope, {
388+
$item: removedChoice,
389+
$model: ctrl.parserResult.modelMapper($scope, locals)
390+
});
379391
};
380392

381393
ctrl.getPlaceholder = function(){
382394
//Refactor single?
383-
if(ctrl.multiple && (ctrl.selected === undefined || ctrl.selected.length)) return;
395+
if(ctrl.multiple && ctrl.selected.length) return;
384396
return ctrl.placeholder;
385397
};
386398

399+
var containerSizeWatch;
387400
ctrl.sizeSearchInput = function(){
388401
var input = _searchInput[0],
389402
container = _searchInput.parent().parent()[0];
390403
_searchInput.css('width','10px');
391-
$timeout(function(){
404+
var calculate = function(){
392405
var newWidth = container.clientWidth - input.offsetLeft - 10;
393406
if(newWidth < 50) newWidth = container.clientWidth;
394407
_searchInput.css('width',newWidth+'px');
408+
};
409+
$timeout(function(){ //Give tags time to render correctly
410+
if (container.clientWidth === 0 && !containerSizeWatch){
411+
containerSizeWatch = $scope.$watch(function(){ return container.clientWidth;}, function(newValue){
412+
if (newValue !== 0){
413+
calculate();
414+
containerSizeWatch();
415+
containerSizeWatch = null;
416+
}
417+
});
418+
}else if (!containerSizeWatch) {
419+
calculate();
420+
}
395421
}, 0, false);
396422
};
397423

@@ -404,11 +430,10 @@
404430
break;
405431
case KEY.UP:
406432
if (!ctrl.open && ctrl.multiple) ctrl.activate(false, true); //In case its the search input in 'multiple' mode
407-
else if (ctrl.activeIndex > 0 || (ctrl.search.length === 0 && ctrl.tagging.isActivated)) { ctrl.activeIndex--; }
433+
else if (ctrl.activeIndex > 0) { ctrl.activeIndex--; }
408434
break;
409435
case KEY.TAB:
410-
//TODO: Que hacemos en modo multiple?
411-
if (!ctrl.multiple) ctrl.select(ctrl.items[ctrl.activeIndex]);
436+
if (!ctrl.multiple || ctrl.open) ctrl.select(ctrl.items[ctrl.activeIndex], true);
412437
break;
413438
case KEY.ENTER:
414439
if(ctrl.open){
@@ -429,7 +454,7 @@
429454
// Handles selected options in "multiple" mode
430455
function _handleMatchSelection(key){
431456
var caretPosition = _getCaretPosition(_searchInput[0]),
432-
length = ctrl.selected.length,
457+
length = ctrl.selected.length,
433458
// none = -1,
434459
first = 0,
435460
last = length-1,
@@ -452,7 +477,7 @@
452477
break;
453478
case KEY.RIGHT:
454479
// Open drop-down
455-
if(!~ctrl.activeMatchIndex || curr === last){
480+
if(!~ctrl.activeMatchIndex || curr === last){
456481
ctrl.activate();
457482
return false;
458483
}
@@ -475,7 +500,7 @@
475500
return curr;
476501
}
477502
else return false;
478-
}
503+
}
479504
}
480505

481506
newIndex = getNewActiveMatchIndex();
@@ -503,10 +528,10 @@
503528
processed = _handleMatchSelection(key);
504529
}
505530

506-
if (!processed && (ctrl.items.length > 0 || ctrl.tagging.isActivated)) {
531+
if (!processed && ctrl.items.length > 0) {
507532
processed = _handleDropDownSelection(key);
508533
}
509-
534+
510535
if (processed && key != KEY.TAB) {
511536
//TODO Check si el tab selecciona aun correctamente
512537
//Crear test
@@ -524,7 +549,6 @@
524549
_searchInput.on('blur', function() {
525550
$timeout(function() {
526551
ctrl.activeMatchIndex = -1;
527-
ctrl.activeIndex = 0;
528552
});
529553
});
530554

@@ -585,11 +609,10 @@
585609

586610
var searchInput = element.querySelectorAll('input.ui-select-search');
587611

588-
$select.multiple = angular.isDefined(attrs.multiple);
612+
$select.multiple = (angular.isDefined(attrs.multiple)) ? (attrs.multiple === '') ? true : (attrs.multiple.toLowerCase() === 'true') : false;
589613

590614
$select.onSelectCallback = $parse(attrs.onSelect);
591-
592-
$select.tagging = {isActivated: false, fct: undefined};
615+
$select.onRemoveCallback = $parse(attrs.onRemove);
593616

594617
//From view --> model
595618
ngModel.$parsers.unshift(function (inputValue) {
@@ -614,7 +637,7 @@
614637

615638
//From model --> view
616639
ngModel.$formatters.unshift(function (inputValue) {
617-
var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search
640+
var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search
618641
locals = {},
619642
result;
620643
if (data){
@@ -666,7 +689,7 @@
666689
if(attrs.tabindex){
667690
//tabindex might be an expression, wait until it contains the actual value before we set the focusser tabindex
668691
attrs.$observe('tabindex', function(value) {
669-
//If we are using multiple, add tabindex to the search input
692+
//If we are using multiple, add tabindex to the search input
670693
if($select.multiple){
671694
searchInput.attr("tabindex", value);
672695
} else {
@@ -699,7 +722,7 @@
699722
e.preventDefault();
700723
e.stopPropagation();
701724
$select.select(undefined);
702-
scope.$digest();
725+
scope.$apply();
703726
return;
704727
}
705728

@@ -721,7 +744,7 @@
721744
if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) {
722745
return;
723746
}
724-
747+
725748
$select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input
726749
focusser.val('');
727750
scope.$digest();
@@ -747,20 +770,11 @@
747770
$select.resetSearchInput = resetSearchInput !== undefined ? resetSearchInput : true;
748771
});
749772

750-
attrs.$observe('tagging', function() {
751-
if(attrs.tagging !== undefined)
752-
{
753-
// $eval() is needed otherwise we get a string instead of a function or a boolean
754-
var taggingEval = scope.$eval(attrs.tagging);
755-
$select.tagging = {isActivated: true, fct: taggingEval !== true ? taggingEval : undefined};
756-
}
757-
else
758-
{
759-
$select.tagging = {isActivated: false, fct: undefined};
760-
}
761-
});
762-
763773
if ($select.multiple){
774+
scope.$watchCollection(function(){ return ngModel.$modelValue; }, function(newValue, oldValue) {
775+
if (oldValue != newValue)
776+
ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters
777+
});
764778
scope.$watchCollection('$select.selected', function() {
765779
ngModel.$setViewValue(Date.now()); //Set timestamp as a unique string to force changes
766780
});
@@ -859,7 +873,7 @@
859873
if (!tAttrs.repeat) throw uiSelectMinErr('repeat', "Expected 'repeat' expression.");
860874

861875
return function link(scope, element, attrs, $select, transcludeFn) {
862-
876+
863877
// var repeat = RepeatParser.parse(attrs.repeat);
864878
var groupByExp = attrs.groupBy;
865879

@@ -890,7 +904,7 @@
890904

891905
scope.$watch('$select.search', function(newValue) {
892906
if(newValue && !$select.open && $select.multiple) $select.activate(false, true);
893-
$select.activeIndex = $select.tagging.isActivated ? -1 : 0;
907+
$select.activeIndex = 0;
894908
$select.refresh(attrs.refresh);
895909
});
896910

@@ -931,7 +945,7 @@
931945
});
932946

933947
if($select.multiple){
934-
$select.sizeSearchInput();
948+
$select.sizeSearchInput();
935949
}
936950

937951
}
@@ -967,4 +981,4 @@ $templateCache.put("select2/select-multiple.tpl.html","<div class=\"ui-select-mu
967981
$templateCache.put("select2/select.tpl.html","<div class=\"select2 select2-container\" ng-class=\"{\'select2-container-active select2-dropdown-open\': $select.open,\n \'select2-container-disabled\': $select.disabled,\n \'select2-container-active\': $select.focus }\"><div class=\"ui-select-match\"></div><div class=\"select2-drop select2-with-searchbox select2-drop-active\" ng-class=\"{\'select2-display-none\': !$select.open}\"><div class=\"select2-search\" ng-show=\"$select.searchEnabled\"><input type=\"text\" autocomplete=\"off\" autocorrect=\"off\" autocapitalize=\"off\" spellcheck=\"false\" class=\"ui-select-search select2-input\" ng-model=\"$select.search\"></div><div class=\"ui-select-choices\"></div></div></div>");
968982
$templateCache.put("selectize/choices.tpl.html","<div ng-show=\"$select.open\" class=\"ui-select-choices selectize-dropdown single\"><div class=\"ui-select-choices-content selectize-dropdown-content\"><div class=\"ui-select-choices-group optgroup\"><div ng-show=\"$select.isGrouped\" class=\"ui-select-choices-group-label optgroup-header\">{{$group.name}}</div><div class=\"ui-select-choices-row\" ng-class=\"{active: $select.isActive(this), disabled: $select.isDisabled(this)}\"><div class=\"option ui-select-choices-row-inner\" data-selectable=\"\"></div></div></div></div></div>");
969983
$templateCache.put("selectize/match.tpl.html","<div ng-hide=\"$select.searchEnabled && ($select.open || $select.isEmpty())\" class=\"ui-select-match\" ng-transclude=\"\"></div>");
970-
$templateCache.put("selectize/select.tpl.html","<div class=\"selectize-control single\"><div class=\"selectize-input\" ng-class=\"{\'focus\': $select.open, \'disabled\': $select.disabled, \'selectize-focus\' : $select.focus}\" ng-click=\"$select.activate()\"><div class=\"ui-select-match\"></div><input type=\"text\" autocomplete=\"off\" tabindex=\"-1\" class=\"ui-select-search ui-select-toggle\" ng-click=\"$select.toggle($event)\" placeholder=\"{{$select.placeholder}}\" ng-model=\"$select.search\" ng-hide=\"!$select.searchEnabled || ($select.selected && !$select.open)\" ng-disabled=\"$select.disabled\"></div><div class=\"ui-select-choices\"></div></div>");}]);
984+
$templateCache.put("selectize/select.tpl.html","<div class=\"selectize-control single\"><div class=\"selectize-input\" ng-class=\"{\'focus\': $select.open, \'disabled\': $select.disabled, \'selectize-focus\' : $select.focus}\" ng-click=\"$select.activate()\"><div class=\"ui-select-match\"></div><input type=\"text\" autocomplete=\"off\" tabindex=\"-1\" class=\"ui-select-search ui-select-toggle\" ng-click=\"$select.toggle($event)\" placeholder=\"{{$select.placeholder}}\" ng-model=\"$select.search\" ng-hide=\"!$select.searchEnabled || ($select.selected && !$select.open)\" ng-disabled=\"$select.disabled\"></div><div class=\"ui-select-choices\"></div></div>");}]);

0 commit comments

Comments
 (0)