1
1
/*!
2
2
* ui-select
3
3
* http://github.com/angular-ui/ui-select
4
- * Version: 0.8.3 - 2014-10-14T18:22:05.432Z
4
+ * Version: 0.8.3 - 2014-10-17T16:24:21.429Z
5
5
* License: MIT
6
6
*/
7
7
59
59
*
60
60
* jqLite find() is limited to lookups by tag name.
61
61
* TODO This will change with future versions of AngularJS, to be removed when this happens
62
- *
62
+ 5 *
63
63
* See jqLite.find - why not use querySelectorAll? https://github.com/angular/angular.js/issues/3586
64
64
* See feat(jqLite): use querySelectorAll instead of getElementsByTagName in jqLite.find https://github.com/angular/angular.js/pull/3598
65
65
*/
160
160
ctrl . selected = undefined ;
161
161
ctrl . open = false ;
162
162
ctrl . focus = false ;
163
- 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
164
164
ctrl . disabled = undefined ; // Initialized inside uiSelect directive link function
165
165
ctrl . searchEnabled = undefined ; // Initialized inside uiSelect directive link function
166
166
ctrl . resetSearchInput = undefined ; // Initialized inside uiSelect directive link function
260
260
var filteredItems = items . filter ( function ( i ) { return ctrl . selected . indexOf ( i ) < 0 ; } ) ;
261
261
setItemsFn ( filteredItems ) ;
262
262
} else {
263
- setItemsFn ( items ) ;
263
+ setItemsFn ( items ) ;
264
264
}
265
265
ctrl . ngModel . $modelValue = null ; //Force scope model value and ngModel value to be out of sync to re-run formatters
266
266
270
270
} ) ;
271
271
272
272
if ( ctrl . multiple ) {
273
- //Remove already selected items
273
+ //Remove already selected items
274
274
$scope . $watchCollection ( '$select.selected' , function ( selectedItems ) {
275
275
var data = ctrl . parserResult . source ( $scope ) ;
276
276
if ( ! selectedItems . length ) {
277
- setItemsFn ( data ) ;
277
+ setItemsFn ( data ) ;
278
278
} else {
279
279
var filteredItems = data . filter ( function ( i ) { return selectedItems . indexOf ( i ) < 0 ; } ) ;
280
- setItemsFn ( filteredItems ) ;
280
+ setItemsFn ( filteredItems ) ;
281
281
}
282
282
ctrl . sizeSearchInput ( ) ;
283
283
} ) ;
312
312
} ;
313
313
314
314
ctrl . isActive = function ( itemScope ) {
315
- < << << << HEAD
316
- if ( typeof itemScope [ ctrl . itemProperty ] === 'undefined' ) {
317
- return false ;
318
- }
319
- = === ===
320
315
return ctrl . open && ctrl . items . indexOf ( itemScope [ ctrl . itemProperty ] ) === ctrl . activeIndex ;
321
- > >>> >>> master
322
316
} ;
323
317
324
318
ctrl . isDisabled = function ( itemScope ) {
325
-
319
+
326
320
if ( ! ctrl . open ) return ;
327
321
328
322
var itemIndex = ctrl . items . indexOf ( itemScope [ ctrl . itemProperty ] ) ;
341
335
// When the user clicks on an item inside the dropdown
342
336
ctrl . select = function ( item , skipFocusser ) {
343
337
344
- if ( item === undefined || ! item . _uiSelectChoiceDisabled ) {
338
+ if ( ! item || ! item . _uiSelectChoiceDisabled ) {
339
+ if ( ctrl . tagging . isActivated && ! item && ctrl . search . length > 0 ) {
340
+ // create new item on the fly
341
+ item = ctrl . tagging . fct !== undefined ? ctrl . tagging . fct ( ctrl . search ) : ctrl . search ;
342
+ }
343
+
345
344
var locals = { } ;
346
345
locals [ ctrl . parserResult . itemName ] = item ;
347
346
362
361
363
362
// Closes the dropdown
364
363
ctrl . close = function ( skipFocusser ) {
365
- if ( ! ctrl . open ) return ;
364
+ if ( ! ctrl . open ) return ;
366
365
_resetSearchInput ( ) ;
367
366
ctrl . open = false ;
368
367
if ( ! ctrl . multiple ) {
402
401
return ctrl . placeholder ;
403
402
} ;
404
403
405
- var containerSizeWatch ;
404
+ var containerSizeWatch ;
406
405
ctrl . sizeSearchInput = function ( ) {
407
406
var input = _searchInput [ 0 ] ,
408
407
container = _searchInput . parent ( ) . parent ( ) [ 0 ] ;
436
435
break ;
437
436
case KEY . UP :
438
437
if ( ! ctrl . open && ctrl . multiple ) ctrl . activate ( false , true ) ; //In case its the search input in 'multiple' mode
439
- else if ( ctrl . activeIndex > 0 ) { ctrl . activeIndex -- ; }
438
+ else if ( ctrl . activeIndex > 0 || ( ctrl . search . length === 0 && ctrl . tagging . isActivated ) ) { ctrl . activeIndex -- ; }
440
439
break ;
441
440
case KEY . TAB :
442
441
if ( ! ctrl . multiple || ctrl . open ) ctrl . select ( ctrl . items [ ctrl . activeIndex ] , true ) ;
460
459
// Handles selected options in "multiple" mode
461
460
function _handleMatchSelection ( key ) {
462
461
var caretPosition = _getCaretPosition ( _searchInput [ 0 ] ) ,
463
- length = ctrl . selected . length ,
462
+ length = ctrl . selected . length ,
464
463
// none = -1,
465
464
first = 0 ,
466
465
last = length - 1 ,
483
482
break ;
484
483
case KEY . RIGHT :
485
484
// Open drop-down
486
- if ( ! ~ ctrl . activeMatchIndex || curr === last ) {
485
+ if ( ! ~ ctrl . activeMatchIndex || curr === last ) {
487
486
ctrl . activate ( ) ;
488
487
return false ;
489
488
}
506
505
return curr ;
507
506
}
508
507
else return false ;
509
- }
508
+ }
510
509
}
511
510
512
511
newIndex = getNewActiveMatchIndex ( ) ;
534
533
processed = _handleMatchSelection ( key ) ;
535
534
}
536
535
537
- if ( ! processed && ctrl . items . length > 0 ) {
536
+ if ( ! processed && ( ctrl . items . length > 0 || ctrl . tagging . isActivated ) ) {
538
537
processed = _handleDropDownSelection ( key ) ;
539
538
}
540
-
539
+
541
540
if ( processed && key != KEY . TAB ) {
542
541
//TODO Check si el tab selecciona aun correctamente
543
542
//Crear test
643
642
644
643
//From model --> view
645
644
ngModel . $formatters . unshift ( function ( inputValue ) {
646
- var data = $select . parserResult . source ( scope , { $select : { search :'' } } ) , //Overwrite $search
645
+ var data = $select . parserResult . source ( scope , { $select : { search :'' } } ) , //Overwrite $search
647
646
locals = { } ,
648
647
result ;
649
648
if ( data ) {
695
694
if ( attrs . tabindex ) {
696
695
//tabindex might be an expression, wait until it contains the actual value before we set the focusser tabindex
697
696
attrs . $observe ( 'tabindex' , function ( value ) {
698
- //If we are using multiple, add tabindex to the search input
697
+ //If we are using multiple, add tabindex to the search input
699
698
if ( $select . multiple ) {
700
699
searchInput . attr ( "tabindex" , value ) ;
701
700
} else {
750
749
if ( e . which === KEY . TAB || KEY . isControl ( e ) || KEY . isFunctionKey ( e ) || e . which === KEY . ESC || e . which == KEY . ENTER || e . which === KEY . BACKSPACE ) {
751
750
return ;
752
751
}
753
-
752
+
754
753
$select . activate ( focusser . val ( ) ) ; //User pressed some regular key, so we pass it to the search input
755
754
focusser . val ( '' ) ;
756
755
scope . $digest ( ) ;
776
775
$select . resetSearchInput = resetSearchInput !== undefined ? resetSearchInput : true ;
777
776
} ) ;
778
777
778
+ attrs . $observe ( 'tagging' , function ( ) {
779
+ if ( attrs . tagging !== undefined )
780
+ {
781
+ // $eval() is needed otherwise we get a string instead of a function or a boolean
782
+ var taggingEval = scope . $eval ( attrs . tagging ) ;
783
+ $select . tagging = { isActivated : true , fct : taggingEval !== true ? taggingEval : undefined } ;
784
+ }
785
+ else
786
+ {
787
+ $select . tagging = { isActivated : false , fct : undefined } ;
788
+ }
789
+ } ) ;
790
+
779
791
if ( $select . multiple ) {
780
792
scope . $watchCollection ( function ( ) { return ngModel . $modelValue ; } , function ( newValue , oldValue ) {
781
793
if ( oldValue != newValue )
879
891
if ( ! tAttrs . repeat ) throw uiSelectMinErr ( 'repeat' , "Expected 'repeat' expression." ) ;
880
892
881
893
return function link ( scope , element , attrs , $select , transcludeFn ) {
882
-
894
+
883
895
// var repeat = RepeatParser.parse(attrs.repeat);
884
896
var groupByExp = attrs . groupBy ;
885
897
910
922
911
923
scope . $watch ( '$select.search' , function ( newValue ) {
912
924
if ( newValue && ! $select . open && $select . multiple ) $select . activate ( false , true ) ;
913
- $select . activeIndex = 0 ;
925
+ $select . activeIndex = $select . tagging . isActivated ? - 1 : 0 ;
914
926
$select . refresh ( attrs . refresh ) ;
915
927
} ) ;
916
928
951
963
} ) ;
952
964
953
965
if ( $select . multiple ) {
954
- $select . sizeSearchInput ( ) ;
966
+ $select . sizeSearchInput ( ) ;
955
967
}
956
968
957
969
}
@@ -987,4 +999,4 @@ $templateCache.put("select2/select-multiple.tpl.html","<div class=\"ui-select-mu
987
999
$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>" ) ;
988
1000
$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>" ) ;
989
1001
$templateCache . put ( "selectize/match.tpl.html" , "<div ng-hide=\"$select.searchEnabled && ($select.open || $select.isEmpty())\" class=\"ui-select-match\" ng-transclude=\"\"></div>" ) ;
990
- $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>" ) ; } ] ) ;
1002
+ $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