@@ -680,30 +680,54 @@ class Autocomplete {
680
680
681
681
var popup = this . popup ;
682
682
var rect = popup . container . getBoundingClientRect ( ) ;
683
- tooltipNode . style . top = popup . container . style . top ;
684
- tooltipNode . style . bottom = popup . container . style . bottom ;
685
-
686
- tooltipNode . style . display = "block" ;
687
- if ( window . innerWidth - rect . right < 320 ) {
688
- if ( rect . left < 320 ) {
689
- if ( popup . isTopdown ) {
690
- tooltipNode . style . top = rect . bottom + "px" ;
691
- tooltipNode . style . left = rect . left + "px" ;
692
- tooltipNode . style . right = "" ;
693
- tooltipNode . style . bottom = "" ;
694
- } else {
695
- tooltipNode . style . top = popup . container . offsetTop - tooltipNode . offsetHeight + "px" ;
696
- tooltipNode . style . left = rect . left + "px" ;
697
- tooltipNode . style . right = "" ;
698
- tooltipNode . style . bottom = "" ;
699
- }
683
+
684
+ var targetWidth = 400 ;
685
+ var targetHeight = 300 ;
686
+ var scrollBarSize = popup . renderer . scrollBar . width || 10 ;
687
+
688
+ var leftSize = rect . left ;
689
+ var rightSize = window . innerWidth - rect . right - scrollBarSize ;
690
+ var topSize = popup . isTopdown ? rect . top : window . innerHeight - scrollBarSize - rect . bottom ;
691
+ var scores = [
692
+ Math . min ( rightSize / targetWidth , 1 ) ,
693
+ Math . min ( leftSize / targetWidth , 1 ) ,
694
+ Math . min ( topSize / targetHeight * 0.9 ) ,
695
+ ] ;
696
+ var max = Math . max . apply ( Math , scores ) ;
697
+ var tooltipStyle = tooltipNode . style ;
698
+ tooltipStyle . display = "block" ;
699
+
700
+ if ( max == scores [ 0 ] ) {
701
+ tooltipStyle . left = ( rect . right + 1 ) + "px" ;
702
+ tooltipStyle . right = "" ;
703
+ tooltipStyle . maxWidth = targetWidth * max + "px" ;
704
+ tooltipStyle . top = rect . top + "px" ;
705
+ tooltipStyle . bottom = "" ;
706
+ tooltipStyle . maxHeight = Math . min ( window . innerHeight - scrollBarSize - rect . top , targetHeight ) + "px" ;
707
+ } else if ( max == scores [ 1 ] ) {
708
+ tooltipStyle . right = window . innerWidth - rect . left + "px" ;
709
+ tooltipStyle . left = "" ;
710
+ tooltipStyle . maxWidth = targetWidth * max + "px" ;
711
+ tooltipStyle . top = rect . top + "px" ;
712
+ tooltipStyle . bottom = "" ;
713
+ tooltipStyle . maxHeight = Math . min ( window . innerHeight - scrollBarSize - rect . top , targetHeight ) + "px" ;
714
+ } else if ( max == scores [ 2 ] ) {
715
+ tooltipStyle . left = window . innerWidth - rect . left + "px" ;
716
+ tooltipStyle . maxWidth = Math . min ( targetWidth , window . innerWidth ) + "px" ;
717
+
718
+ if ( popup . isTopdown ) {
719
+ tooltipStyle . top = rect . bottom + "px" ;
720
+ tooltipStyle . left = rect . left + "px" ;
721
+ tooltipStyle . right = "" ;
722
+ tooltipStyle . bottom = "" ;
723
+ tooltipStyle . maxHeight = Math . min ( window . innerHeight - scrollBarSize - rect . bottom , targetHeight ) + "px" ;
700
724
} else {
701
- tooltipNode . style . right = window . innerWidth - rect . left + "px" ;
702
- tooltipNode . style . left = "" ;
725
+ tooltipStyle . top = popup . container . offsetTop - tooltipNode . offsetHeight + "px" ;
726
+ tooltipStyle . left = rect . left + "px" ;
727
+ tooltipStyle . right = "" ;
728
+ tooltipStyle . bottom = "" ;
729
+ tooltipStyle . maxHeight = Math . min ( popup . container . offsetTop , targetHeight ) + "px" ;
703
730
}
704
- } else {
705
- tooltipNode . style . left = ( rect . right + 1 ) + "px" ;
706
- tooltipNode . style . right = "" ;
707
731
}
708
732
}
709
733
0 commit comments