@@ -44,30 +44,37 @@ export default function (e, target, node, place, effect, offset) {
4444
4545  // Judge if the tooltip has over the window(screen) 
4646  const  outsideVertical  =  ( )  =>  { 
47-      // Check for horazontal tooltip, if their vertical out of screen 
4847    let  result  =  false 
4948    let  newPlace 
50-     if  ( getTipOffsetTop ( 'left' )  <  0  &&  getTipOffsetBottom ( 'left' )  <=  windowHeight )  { 
49+     if  ( getTipOffsetTop ( 'left' )  <  0  && 
50+       getTipOffsetBottom ( 'left' )  <=  windowHeight  && 
51+       getTipOffsetBottom ( 'bottom' )  <=  windowHeight )  { 
5152      result  =  true 
5253      newPlace  =  'bottom' 
53-     }  else  if  ( getTipOffsetBottom ( 'left' )  >  windowHeight  &&  getTipOffsetTop ( 'left' )  >=  0 )  { 
54+     }  else  if  ( getTipOffsetBottom ( 'left' )  >  windowHeight  && 
55+       getTipOffsetTop ( 'left' )  >=  0  && 
56+       getTipOffsetTop ( 'top' )  >=  0 )  { 
5457      result  =  true 
5558      newPlace  =  'top' 
5659    } 
57-     if  ( result  &&  outsideHorizontal ( ) . result )  result  =  false 
5860    return  { result,  newPlace} 
5961  } 
6062  const  outsideLeft  =  ( )  =>  { 
61-     // For horizontal tooltip, if vertical out of screen, change the vertical place 
62-     let  { result,  newPlace}  =  outsideVertical ( ) 
63+     let  { result,  newPlace}  =  outsideVertical ( )  // Deal with vertical as first priority 
64+     if  ( result  &&  outsideHorizontal ( ) . result )  { 
65+       return  { result : false }  // No need to change, if change to vertical will out of space 
66+     } 
6367    if  ( ! result  &&  getTipOffsetLeft ( 'left' )  <  0  &&  getTipOffsetRight ( 'right' )  <=  windowWidth )  { 
64-       result  =  true 
68+       result  =  true   // If vertical ok, but let out of side and right won't out of side 
6569      newPlace  =  'right' 
6670    } 
6771    return  { result,  newPlace} 
6872  } 
6973  const  outsideRight  =  ( )  =>  { 
7074    let  { result,  newPlace}  =  outsideVertical ( ) 
75+     if  ( result  &&  outsideHorizontal ( ) . result )  { 
76+       return  { result : false }  // No need to change, if change to vertical will out of space 
77+     } 
7178    if  ( ! result  &&  getTipOffsetRight ( 'right' )  >  windowWidth  &&  getTipOffsetLeft ( 'left' )  >=  0 )  { 
7279      result  =  true 
7380      newPlace  =  'left' 
@@ -78,19 +85,24 @@ export default function (e, target, node, place, effect, offset) {
7885  const  outsideHorizontal  =  ( )  =>  { 
7986    let  result  =  false 
8087    let  newPlace 
81-     if  ( getTipOffsetLeft ( 'top' )  <  0  &&  getTipOffsetRight ( 'top' )  <=  windowWidth )  { 
88+     if  ( getTipOffsetLeft ( 'top' )  <  0  && 
89+       getTipOffsetRight ( 'top' )  <=  windowWidth  && 
90+       getTipOffsetRight ( 'right' )  <=  windowWidth )  { 
8291      result  =  true 
8392      newPlace  =  'right' 
84-     }  else  if  ( getTipOffsetRight ( 'top' )  >  windowWidth  &&  getTipOffsetLeft ( 'top' )  >=  0 )  { 
93+     }  else  if  ( getTipOffsetRight ( 'top' )  >  windowWidth  && 
94+       getTipOffsetLeft ( 'top' )  >=  0  && 
95+       getTipOffsetLeft ( 'left' )  >=  0 )  { 
8596      result  =  true 
8697      newPlace  =  'left' 
8798    } 
88- 
89-     if  ( result  &&  outsideVertical ( ) . result )  result  =  false 
9099    return  { result,  newPlace} 
91100  } 
92101  const  outsideTop  =  ( )  =>  { 
93102    let  { result,  newPlace}  =  outsideHorizontal ( ) 
103+     if  ( result  &&  outsideVertical ( ) . result )  { 
104+       return  { result : false } 
105+     } 
94106    if  ( ! result  &&  getTipOffsetTop ( 'top' )  <  0  &&  getTipOffsetBottom ( 'bottom' )  <=  windowHeight )  { 
95107      result  =  true 
96108      newPlace  =  'bottom' 
@@ -99,6 +111,9 @@ export default function (e, target, node, place, effect, offset) {
99111  } 
100112  const  outsideBottom  =  ( )  =>  { 
101113    let  { result,  newPlace}  =  outsideHorizontal ( ) 
114+     if  ( result  &&  outsideVertical ( ) . result )  { 
115+       return  { result : false } 
116+     } 
102117    if  ( ! result  &&  getTipOffsetBottom ( 'bottom' )  >  windowHeight  &&  getTipOffsetTop ( 'top' )  >=  0 )  { 
103118      result  =  true 
104119      newPlace  =  'top' 
0 commit comments