@@ -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 ,
@@ -362,6 +363,10 @@ $.TokenList = function (input, url_or_data, settings) {
362
363
}
363
364
} ) ;
364
365
366
+ // Keep reference for placeholder
367
+ if ( settings . placeholder )
368
+ input_box . attr ( "placeholder" , settings . placeholder )
369
+
365
370
// Keep a reference to the original input box
366
371
var hidden_input = $ ( input )
367
372
. hide ( )
@@ -446,6 +451,7 @@ $.TokenList = function (input, url_or_data, settings) {
446
451
$ . each ( li_data , function ( index , value ) {
447
452
insert_token ( value ) ;
448
453
checkTokenLimit ( ) ;
454
+ input_box . attr ( "placeholder" , null )
449
455
} ) ;
450
456
}
451
457
@@ -501,6 +507,9 @@ $.TokenList = function (input, url_or_data, settings) {
501
507
toggleDisabled ( disable ) ;
502
508
} ;
503
509
510
+ // Resize input to maximum width so the placeholder can be seen
511
+ resize_input ( ) ;
512
+
504
513
//
505
514
// Private functions
506
515
//
@@ -537,9 +546,13 @@ $.TokenList = function (input, url_or_data, settings) {
537
546
function resize_input ( ) {
538
547
if ( input_val === ( input_val = input_box . val ( ) ) ) { return ; }
539
548
549
+ // Get width left on the current line
550
+ var width_left = token_list . width ( ) - input_box . offset ( ) . left - token_list . offset ( ) . left ;
540
551
// Enter new content into resizer and resize input accordingly
541
552
input_resizer . html ( _escapeHTML ( input_val ) ) ;
542
- input_box . width ( input_resizer . width ( ) + 30 ) ;
553
+ // Get maximum width, minimum the size of input and maximum the widget's width
554
+ input_box . width ( Math . min ( token_list . width ( ) ,
555
+ Math . max ( width_left , input_resizer . width ( ) + 30 ) ) ) ;
543
556
}
544
557
545
558
function is_printable_character ( keycode ) {
@@ -635,9 +648,14 @@ $.TokenList = function (input, url_or_data, settings) {
635
648
}
636
649
}
637
650
651
+ // Squeeze input_box so we force no unnecessary line break
652
+ input_box . width ( 0 ) ;
653
+
638
654
// Insert the new tokens
639
655
if ( $ ( input ) . data ( "settings" ) . tokenLimit == null || token_count < $ ( input ) . data ( "settings" ) . tokenLimit ) {
640
656
insert_token ( item ) ;
657
+ // Remove the placeholder so it's not seen after you've added a token
658
+ input_box . attr ( "placeholder" , null )
641
659
checkTokenLimit ( ) ;
642
660
}
643
661
@@ -720,6 +738,9 @@ $.TokenList = function (input, url_or_data, settings) {
720
738
721
739
// Remove this token from the saved list
722
740
saved_tokens = saved_tokens . slice ( 0 , index ) . concat ( saved_tokens . slice ( index + 1 ) ) ;
741
+ if ( saved_tokens . length == 0 ) {
742
+ input_box . attr ( "placeholder" , settings . placeholder )
743
+ }
723
744
if ( index < selected_token_index ) selected_token_index -- ;
724
745
725
746
// Update the hidden input
@@ -1019,3 +1040,4 @@ $.TokenList.Cache = function (options) {
1019
1040
} ;
1020
1041
} ;
1021
1042
} ( jQuery ) ) ;
1043
+
0 commit comments