@@ -30,6 +30,7 @@ var DEFAULT_SETTINGS = {
30
30
searchingText : "Searching..." ,
31
31
deleteText : "×" ,
32
32
animateDropdown : true ,
33
+ placeholder : null ,
33
34
theme : null ,
34
35
zindex : 999 ,
35
36
resultsLimit : null ,
@@ -364,6 +365,10 @@ $.TokenList = function (input, url_or_data, settings) {
364
365
}
365
366
} ) ;
366
367
368
+ // Keep reference for placeholder
369
+ if ( settings . placeholder )
370
+ input_box . attr ( "placeholder" , settings . placeholder )
371
+
367
372
// Keep a reference to the original input box
368
373
var hidden_input = $ ( input )
369
374
. hide ( )
@@ -503,6 +508,9 @@ $.TokenList = function (input, url_or_data, settings) {
503
508
toggleDisabled ( disable ) ;
504
509
} ;
505
510
511
+ // Resize input to maximum width so the placeholder can be seen
512
+ resize_input ( ) ;
513
+
506
514
//
507
515
// Private functions
508
516
//
@@ -539,9 +547,13 @@ $.TokenList = function (input, url_or_data, settings) {
539
547
function resize_input ( ) {
540
548
if ( input_val === ( input_val = input_box . val ( ) ) ) { return ; }
541
549
550
+ // Get width left on the current line
551
+ var width_left = token_list . width ( ) - input_box . offset ( ) . left - token_list . offset ( ) . left ;
542
552
// Enter new content into resizer and resize input accordingly
543
553
input_resizer . html ( _escapeHTML ( input_val ) ) ;
544
- input_box . width ( input_resizer . width ( ) + 30 ) ;
554
+ // Get maximum width, minimum the size of input and maximum the widget's width
555
+ input_box . width ( Math . min ( token_list . width ( ) ,
556
+ Math . max ( width_left , input_resizer . width ( ) + 30 ) ) ) ;
545
557
}
546
558
547
559
function is_printable_character ( keycode ) {
@@ -637,9 +649,14 @@ $.TokenList = function (input, url_or_data, settings) {
637
649
}
638
650
}
639
651
652
+ // Squeeze input_box so we force no unnecessary line break
653
+ input_box . width ( 0 ) ;
654
+
640
655
// Insert the new tokens
641
656
if ( $ ( input ) . data ( "settings" ) . tokenLimit == null || token_count < $ ( input ) . data ( "settings" ) . tokenLimit ) {
642
657
insert_token ( item ) ;
658
+ // Remove the placeholder so it's not seen after you've added a token
659
+ input_box . attr ( "placeholder" , null )
643
660
checkTokenLimit ( ) ;
644
661
}
645
662
@@ -722,6 +739,10 @@ $.TokenList = function (input, url_or_data, settings) {
722
739
723
740
// Remove this token from the saved list
724
741
saved_tokens = saved_tokens . slice ( 0 , index ) . concat ( saved_tokens . slice ( index + 1 ) ) ;
742
+ // If there are no tokens left, restore the placeholder
743
+ if ( saved_tokens . length == 0 ) {
744
+ input_box . attr ( "placeholder" , settings . placeholder )
745
+ }
725
746
if ( index < selected_token_index ) selected_token_index -- ;
726
747
727
748
// Update the hidden input
@@ -1021,3 +1042,4 @@ $.TokenList.Cache = function (options) {
1021
1042
} ;
1022
1043
} ;
1023
1044
} ( jQuery ) ) ;
1045
+
0 commit comments