@ -56,7 +56,7 @@
preloadImages : function ( srcArray , onload ) {
preloadImages : function ( srcArray , onload ) {
var count = 0 , images = [ ] ;
var count = 0 , images = [ ] ;
function complete ( ) {
function complete ( ) {
count ++ ;
count ++ ;
if ( count >= srcArray . length ) {
if ( count >= srcArray . length ) {
onload ( ) ;
onload ( ) ;
@ -151,9 +151,15 @@
BI . extend ( BI . DOM , {
BI . extend ( BI . DOM , {
getLeftPosition : function ( combo , popup , extraWidth ) {
getLeftPosition : function ( combo , popup , extraWidth , container ) {
var el = combo . element ;
var popupEl = popup . element ;
var elRect = el [ 0 ] . getBoundingClientRect ( ) ;
var popupElRect = popupEl [ 0 ] . getBoundingClientRect ( ) ;
var containerRect = container ? container . getBoundingClientRect ( ) : { left : 0 } ;
return {
return {
left : combo . element . offset ( ) . left - popup . element . outerWidth ( ) - ( extraWidth || 0 )
left : elRect . left - containerRect . left - popupElRect . width - ( extraWidth || 0 )
} ;
} ;
} ,
} ,
@ -163,10 +169,13 @@
} ;
} ;
} ,
} ,
getRightPosition : function ( combo , popup , extraWidth ) {
getRightPosition : function ( combo , popup , extraWidth , container ) {
var el = combo . element ;
var el = combo . element ;
var elRect = el [ 0 ] . getBoundingClientRect ( ) ;
var containerRect = container ? container . getBoundingClientRect ( ) : { left : 0 } ;
return {
return {
left : el . offset ( ) . left + el . outerWidth ( ) + ( extraWidth || 0 )
left : elRect . left + elRect . width - containerRect . left + ( extraWidth || 0 )
} ;
} ;
} ,
} ,
@ -177,16 +186,25 @@
} ;
} ;
} ,
} ,
getTopPosition : function ( combo , popup , extraHeight ) {
getTopPosition : function ( combo , popup , extraHeight , container ) {
var el = combo . element ;
var popupEl = popup . element ;
var elRect = el [ 0 ] . getBoundingClientRect ( ) ;
var popupElRect = popupEl [ 0 ] . getBoundingClientRect ( ) ;
var containerRect = container ? container . getBoundingClientRect ( ) : { top : 0 } ;
return {
return {
top : combo . element . offset ( ) . top - popup . element . outerHeight ( ) - ( extraHeight || 0 )
top : elRect . top - containerRect . top - popupElRect . height - ( extraHeight || 0 )
} ;
} ;
} ,
} ,
getBottomPosition : function ( combo , popup , extraHeight ) {
getBottomPosition : function ( combo , popup , extraHeight , container ) {
var el = combo . element ;
var el = combo . element ;
var elRect = el [ 0 ] . getBoundingClientRect ( ) ;
var containerRect = container ? container . getBoundingClientRect ( ) : { top : 0 } ;
return {
return {
top : el . offset ( ) . top + el . outerHeight ( ) + ( extraHeight || 0 )
top : elRect . top - containerRect . top + elRect . height + ( extraHeight || 0 )
} ;
} ;
} ,
} ,
@ -201,9 +219,9 @@
} ,
} ,
isRightSpaceEnough : function ( combo , popup , extraWidth ) {
isRightSpaceEnough : function ( combo , popup , extraWidth ) {
var viewBounds = popup . element . bounds ( ) ,
var viewBounds = popup . element [ 0 ] . getBoundingClientRect ( ) ,
windowBounds = BI . Widget . _renderEngine . createElement ( "body" ) . bounds ( ) ;
viewportBounds = document . documentElement . getBoundingClientRect ( ) ;
return BI . DOM . getRightPosition ( combo , popup , extraWidth ) . left + viewBounds . width <= window Bounds. width ;
return BI . DOM . getRightPosition ( combo , popup , extraWidth ) . left + viewBounds . width <= viewport Bounds. width ;
} ,
} ,
isInnerRightSpaceEnough : function ( combo , popup , extraWidth ) {
isInnerRightSpaceEnough : function ( combo , popup , extraWidth ) {
@ -215,41 +233,47 @@
} ,
} ,
isBottomSpaceEnough : function ( combo , popup , extraHeight ) {
isBottomSpaceEnough : function ( combo , popup , extraHeight ) {
var viewBounds = popup . element . bounds ( ) ,
var viewBounds = popup . element [ 0 ] . getBoundingClientRect ( ) ,
windowBounds = BI . Widget . _renderEngine . createElement ( "body" ) . bounds ( ) ;
viewportBounds = document . documentElement . getBoundingClientRect ( ) ;
return BI . DOM . getBottomPosition ( combo , popup , extraHeight ) . top + viewBounds . height <= window Bounds. height ;
return BI . DOM . getBottomPosition ( combo , popup , extraHeight ) . top + viewBounds . height <= viewport Bounds. height ;
} ,
} ,
isRightSpaceLarger : function ( combo ) {
isRightSpaceLarger : function ( combo ) {
var windowBounds = BI . Widget . _renderEngine . createElement ( "body" ) . bounds ( ) ;
var comboBounds = combo . element [ 0 ] . getBoundingClientRect ( ) ,
return windowBounds . width - combo . element . offset ( ) . left - combo . element . bounds ( ) . width >= combo . element . offset ( ) . left ;
viewportBounds = document . documentElement . getBoundingClientRect ( ) ;
return viewportBounds . width - comboBounds . right >= comboBounds . left ;
} ,
} ,
isBottomSpaceLarger : function ( combo ) {
isBottomSpaceLarger : function ( combo ) {
var windowBounds = BI . Widget . _renderEngine . createElement ( "body" ) . bounds ( ) ;
var comboBounds = combo . element [ 0 ] . getBoundingClientRect ( ) ,
return windowBounds . height - combo . element . offset ( ) . top - combo . element . bounds ( ) . height >= combo . element . offset ( ) . top ;
viewportBounds = document . documentElement . getBoundingClientRect ( ) ;
return viewportBounds . height - comboBounds . bottom >= comboBounds . top ;
} ,
} ,
_getLeftAlignPosition : function ( combo , popup , extraWidth ) {
_getLeftAlignPosition : function ( combo , popup , extraWidth , container ) {
var viewBounds = popup . element . bounds ( ) ,
var comboRect = combo . element [ 0 ] . getBoundingClientRect ( ) ,
windowBounds = BI . Widget . _renderEngine . createElement ( "body" ) . bounds ( ) ;
popupRect = popup . element [ 0 ] . getBoundingClientRect ( ) ,
var left = combo . element . offset ( ) . left + extraWidth ;
viewportRect = document . documentElement . getBoundingClientRect ( ) ,
if ( left + viewBounds . width > windowBounds . width ) {
containerRect = container ? container . getBoundingClientRect ( ) : { left : 0 } ;
left = windowBounds . width - viewBounds . width ;
var left = comboRect . left - containerRect . left + extraWidth ;
if ( comboRect . left + popupRect . width > viewportRect . width ) {
left = viewportRect . width - popupRect . width - containerRect . left ;
}
}
return left ;
return left ;
} ,
} ,
getLeftAlignPosition : function ( combo , popup , extraWidth ) {
getLeftAlignPosition : function ( combo , popup , extraWidth , container ) {
var left = this . _getLeftAlignPosition ( combo , popup , extraWidth ) ;
var left = this . _getLeftAlignPosition ( combo , popup , extraWidth , container ) ;
var dir = "" ;
var dir = "" ;
// 如果放不下,优先使用RightAlign, 如果RightAlign也放不下, 再使用left=0
// 如果放不下,优先使用RightAlign, 如果RightAlign也放不下, 再使用left=0
if ( left < 0 ) {
var containerRect = container ? container . getBoundingClientRect ( ) : { left : 0 } ;
if ( left + containerRect . left < 0 ) {
left = this . _getRightAlignPosition ( combo , popup , extraWidth ) ;
left = this . _getRightAlignPosition ( combo , popup , extraWidth ) ;
dir = "left" ;
dir = "left" ;
}
}
if ( left < 0 ) {
if ( left + containerRect . left < 0 ) {
left = 0 ;
left = 0 - containerRect . left ;
}
}
return {
return {
left : left ,
left : left ,
@ -257,26 +281,28 @@
} ;
} ;
} ,
} ,
getLeftAdaptPosition : function ( combo , popup , extraWidth ) {
getLeftAdaptPosition : function ( combo , popup , extraWidth , container ) {
if ( BI . DOM . isLeftSpaceEnough ( combo , popup , extraWidth ) ) {
if ( BI . DOM . isLeftSpaceEnough ( combo , popup , extraWidth , container ) ) {
return BI . DOM . getLeftPosition ( combo , popup , extraWidth ) ;
return BI . DOM . getLeftPosition ( combo , popup , extraWidth , container ) ;
}
}
return {
return {
left : 0
left : 0
} ;
} ;
} ,
} ,
_getRightAlignPosition : function ( combo , popup , extraWidth ) {
_getRightAlignPosition : function ( combo , popup , extraWidth , container ) {
var comboBounds = combo . element . bounds ( ) , viewBounds = popup . element . bounds ( ) ;
var comboBounds = combo . element [ 0 ] . getBoundingClientRect ( ) ,
return combo . element . offset ( ) . left + comboBounds . width - viewBounds . width - extraWidth ;
viewBounds = popup . element [ 0 ] . getBoundingClientRect ( ) ,
containerRect = container ? container . getBoundingClientRect ( ) : { left : 0 } ;
return comboBounds . left + comboBounds . width - viewBounds . width - extraWidth - containerRect . left ;
} ,
} ,
getRightAlignPosition : function ( combo , popup , extraWidth ) {
getRightAlignPosition : function ( combo , popup , extraWidth , container ) {
var left = this . _getRightAlignPosition ( combo , popup , extraWidth ) ;
var left = this . _getRightAlignPosition ( combo , popup , extraWidth , container ) ;
var dir = "" ;
var dir = "" ;
// 如果放不下,优先使用LeftAlign, 如果LeftAlign也放不下, 再使用left=0
// 如果放不下,优先使用LeftAlign, 如果LeftAlign也放不下, 再使用left=0
if ( left < 0 ) {
if ( left < 0 ) {
left = this . _getLeftAlignPosition ( combo , popup , extraWidth ) ;
left = this . _getLeftAlignPosition ( combo , popup , extraWidth , container ) ;
dir = "right" ;
dir = "right" ;
}
}
if ( left < 0 ) {
if ( left < 0 ) {
@ -288,33 +314,34 @@
} ;
} ;
} ,
} ,
getRightAdaptPosition : function ( combo , popup , extraWidth ) {
getRightAdaptPosition : function ( combo , popup , extraWidth , container ) {
if ( BI . DOM . isRightSpaceEnough ( combo , popup , extraWidth ) ) {
if ( BI . DOM . isRightSpaceEnough ( combo , popup , extraWidth , container ) ) {
return BI . DOM . getRightPosition ( combo , popup , extraWidth ) ;
return BI . DOM . getRightPosition ( combo , popup , extraWidth , container ) ;
}
}
return {
return {
left : BI . Widget . _renderEngine . createElement ( "body" ) . bounds ( ) . width - popup . element . bounds ( ) . width
left : document . documentElement . getBoundingClientRect ( ) . width - popup . element [ 0 ] . getBoundingClientRect ( ) . width - container . getBoundingClientRect ( ) . left
} ;
} ;
} ,
} ,
getTopAlignPosition : function ( combo , popup , extraHeight , needAdaptHeight ) {
getTopAlignPosition : function ( combo , popup , extraHeight , needAdaptHeight , container ) {
var comboOffset = combo . element . offset ( ) ;
var comboBounds = combo . element [ 0 ] . getBoundingClientRect ( ) ,
var comboBounds = combo . element . bounds ( ) , popupBounds = popup . element . bounds ( ) ,
popupBounds = popup . element [ 0 ] . getBoundingClientRect ( ) ,
windowBounds = BI . Widget . _renderEngine . createElement ( "body" ) . bounds ( ) ;
viewportBounds = document . documentElement . getBoundingClientRect ( ) ,
containerBounds = container ? container . getBoundingClientRect ( ) : { top : 0 } ;
var top , adaptHeight , dir ;
var top , adaptHeight , dir ;
if ( BI . DOM . isBottomSpaceEnough ( combo , popup , - 1 * comboBounds . height + extraHeight ) ) {
if ( BI . DOM . isBottomSpaceEnough ( combo , popup , - 1 * comboBounds . height + extraHeight ) ) {
top = comboOffset . top + extraHeight ;
top = comboBounds . top - containerBounds . top + extraHeight ;
} else if ( needAdaptHeight ) {
} else if ( needAdaptHeight ) {
top = comboOffset . top + extraHeight ;
top = comboBounds . top - containerBounds . top + extraHeight ;
adaptHeight = window Bounds. height - top ;
adaptHeight = viewport Bounds. height - comboBounds . top ;
} else if ( BI . DOM . isTopSpaceEnough ( combo , popup , - 1 * comboBounds . height + extraHeight ) ) {
} else if ( BI . DOM . isTopSpaceEnough ( combo , popup , - 1 * comboBounds . height + extraHeight ) ) {
// 下方空间不足且不允许调整高度的情况下,优先使用上对齐
// 下方空间不足且不允许调整高度的情况下,优先使用上对齐
top = comboOffset . top + comboBounds . height - popupBounds . height - extraHeight ;
top = comboBounds . top + comboBounds . height - popupBounds . height - containerBounds . top - extraHeight ;
dir = "top" ;
dir = "top" ;
} else {
} else {
top = window Bounds. height - popupBounds . height ;
top = viewport Bounds. height - popupBounds . height ;
if ( top < extraHeight ) {
if ( top < extraHeight ) {
adaptHeight = window Bounds. height - extraHeight ;
adaptHeight = viewport Bounds. height - extraHeight ;
}
}
}
}
if ( top < extraHeight ) {
if ( top < extraHeight ) {
@ -330,42 +357,45 @@
} ;
} ;
} ,
} ,
getTopAdaptPosition : function ( combo , popup , extraHeight , needAdaptHeight ) {
getTopAdaptPosition : function ( combo , popup , extraHeight , needAdaptHeight , positionRelativeElement ) {
var popupBounds = popup . element . bounds ( ) ,
var comboBounds = combo . element [ 0 ] . getBoundingClientRect ( ) ,
windowBounds = BI . Widget . _renderEngine . createElement ( "body" ) . bounds ( ) ;
popupBounds = popup . element [ 0 ] . getBoundingClientRect ( ) ,
positionRelativeElementRect = positionRelativeElement . getBoundingClientRect ( ) ,
viewportBounds = document . documentElement . getBoundingClientRect ( ) ;
if ( BI . DOM . isTopSpaceEnough ( combo , popup , extraHeight ) ) {
if ( BI . DOM . isTopSpaceEnough ( combo , popup , extraHeight ) ) {
return BI . DOM . getTopPosition ( combo , popup , extraHeight ) ;
return BI . DOM . getTopPosition ( combo , popup , extraHeight ) ;
}
}
if ( needAdaptHeight ) {
if ( needAdaptHeight ) {
return {
return {
top : 0 ,
top : 0 - positionRelativeElementRect . top ,
adaptHeight : combo . element . offset ( ) . top - extraHeight
adaptHeight : comboBounds . top - extraHeight
} ;
} ;
}
}
if ( popupBounds . height + extraHeight > window Bounds. height ) {
if ( popupBounds . height + extraHeight > viewport Bounds. height ) {
return {
return {
top : 0 ,
top : 0 - positionRelativeElementRect . top ,
adaptHeight : window Bounds. height - extraHeight
adaptHeight : viewport Bounds. height - extraHeight
} ;
} ;
}
}
return {
return {
top : 0
top : 0 - positionRelativeElementRect . top
} ;
} ;
} ,
} ,
getBottomAlignPosition : function ( combo , popup , extraHeight , needAdaptHeight ) {
getBottomAlignPosition : function ( combo , popup , extraHeight , needAdaptHeight , container ) {
var comboOffset = combo . element . offset ( ) ;
var comboBounds = combo . element [ 0 ] . getBoundingClientRect ( ) ,
var comboBounds = combo . element . bounds ( ) , popupBounds = popup . element . bounds ( ) ,
popupBounds = popup . element [ 0 ] . getBoundingClientRect ( ) ,
windowBounds = BI . Widget . _renderEngine . createElement ( "body" ) . bounds ( ) ;
windowBounds = BI . Widget . _renderEngine . createElement ( "body" ) . bounds ( ) ,
containerBounds = container ? container . getBoundingClientRect ( ) : { top : 0 } ;
var top , adaptHeight , dir ;
var top , adaptHeight , dir ;
if ( BI . DOM . isTopSpaceEnough ( combo , popup , - 1 * comboBounds . height + extraHeight ) ) {
if ( BI . DOM . isTopSpaceEnough ( combo , popup , - 1 * comboBounds . height + extraHeight ) ) {
top = comboOffset . top + comboBounds . height - popup Bounds. heigh t - extraH eight;
top = comboBounds . top + comboBounds . height - container Bounds. top - popupBounds . h eight;
} else if ( needAdaptHeight ) {
} else if ( needAdaptHeight ) {
top = 0 ;
top = 0 - containerBounds . top ;
adaptHeight = comboOffset . top + comboBounds . height - extraHeight ;
adaptHeight = comboBounds . top + comboBounds . height - extraHeight ;
} else if ( BI . DOM . isBottomSpaceEnough ( combo , popup , - 1 * comboBounds . height + extraHeight ) ) {
} else if ( BI . DOM . isBottomSpaceEnough ( combo , popup , - 1 * comboBounds . height + extraHeight ) ) {
// 上方空间不足且不允许调整高度的情况下,优先使用下对齐
// 上方空间不足且不允许调整高度的情况下,优先使用下对齐
top = comboOffset . top + extraHeight ;
top = comboBounds . top - containerBounds . top + extraHeight ;
dir = "bottom" ;
dir = "bottom" ;
} else {
} else {
top = 0 ;
top = 0 ;
@ -373,7 +403,7 @@
adaptHeight = windowBounds . height - extraHeight ;
adaptHeight = windowBounds . height - extraHeight ;
}
}
}
}
if ( top < 0 ) {
if ( top + containerBounds . top < 0 ) {
top = 0 ;
top = 0 ;
}
}
return adaptHeight ? {
return adaptHeight ? {
@ -386,41 +416,43 @@
} ;
} ;
} ,
} ,
getBottomAdaptPosition : function ( combo , popup , extraHeight , needAdaptHeight ) {
getBottomAdaptPosition : function ( combo , popup , extraHeight , needAdaptHeight , positionRelativeElement ) {
var comboOffset = combo . element . offset ( ) ;
var comboBounds = combo . element [ 0 ] . getBoundingClientRect ( ) ,
var comboBounds = combo . element . bounds ( ) , popupBounds = popup . element . bounds ( ) ,
popupBounds = popup . element [ 0 ] . getBoundingClientRect ( ) ,
windowBounds = BI . Widget . _renderEngine . createElement ( "body" ) . bounds ( ) ;
viewportBounds = document . documentElement . getBoundingClientRect ( ) ,
positionRelativeElementRect = positionRelativeElement . getBoundingClientRect ( ) ;
if ( BI . DOM . isBottomSpaceEnough ( combo , popup , extraHeight ) ) {
if ( BI . DOM . isBottomSpaceEnough ( combo , popup , extraHeight ) ) {
return BI . DOM . getBottomPosition ( combo , popup , extraHeight ) ;
return BI . DOM . getBottomPosition ( combo , popup , extraHeight , positionRelativeElement ) ;
}
}
if ( needAdaptHeight ) {
if ( needAdaptHeight ) {
return {
return {
top : comboOffset . top + comboBounds . height + extraHeight ,
top : comboBounds . top + comboBounds . height + extraHeight - positionRelativeElementRect . top ,
adaptHeight : window Bounds. height - comboOffset . top - comboBounds . height - extraHeight
adaptHeight : viewport Bounds. height - comboBounds . top - comboBounds . height - extraHeight
} ;
} ;
}
}
if ( popupBounds . height + extraHeight > window Bounds. height ) {
if ( popupBounds . height + extraHeight > viewport Bounds. height ) {
return {
return {
top : extraHeight ,
top : extraHeight - positionRelativeElementRect . top ,
adaptHeight : window Bounds. height - extraHeight
adaptHeight : viewport Bounds. height - extraHeight
} ;
} ;
}
}
return {
return {
top : window Bounds. height - popupBounds . height - extraHeight
top : viewport Bounds. height - popupBounds . height - extraHeight - positionRelativeElementRect . top
} ;
} ;
} ,
} ,
getCenterAdaptPosition : function ( combo , popup ) {
getCenterAdaptPosition : function ( combo , popup , positionRelativeElement ) {
var comboOffset = combo . element . offset ( ) ;
var comboRect = combo . element [ 0 ] . getBoundingClientRect ( ) ,
var comboBounds = combo . element . bounds ( ) , popupBounds = popup . element . bounds ( ) ,
popupRect = popup . element [ 0 ] . getBoundingClientRect ( ) ,
windowBounds = BI . Widget . _renderEngine . createElement ( "body" ) . bounds ( ) ;
positionRelativeElementRect = positionRelativeElement . getBoundingClientRect ( ) ,
viewportBounds = document . documentElement . getBoundingClientRect ( ) ;
var left ;
var left ;
if ( comboOffse t . left + comboBounds . width / 2 + popupBounds . width / 2 > window Bounds. width ) {
if ( comboRec t . left + comboRect . width / 2 + popupRect . width / 2 > viewport Bounds. width ) {
left = window Bounds. width - popupBounds . width ;
left = viewport Bounds. width - comboRect . width - positionRelativeElementRect . left ;
} else {
} else {
left = comboOffset . left + comboBounds . width / 2 - popupBounds . width / 2 ;
left = comboRect . left + ( comboRect . width - popupRect . width ) / 2 - positionRelativeElementRect . left ;
}
}
if ( left < 0 ) {
if ( left + positionRelativeElementRect . left < 0 ) {
left = 0 ;
left = 0 ;
}
}
return {
return {
@ -428,17 +460,19 @@
} ;
} ;
} ,
} ,
getMiddleAdaptPosition : function ( combo , popup ) {
getMiddleAdaptPosition : function ( combo , popup , positionRelativeElement ) {
var comboOffset = combo . element . offset ( ) ;
var comboRect = combo . element [ 0 ] . getBoundingClientRect ( ) ,
var comboBounds = combo . element . bounds ( ) , popupBounds = popup . element . bounds ( ) ,
popupRect = popup . element [ 0 ] . getBoundingClientRect ( ) ,
windowBounds = BI . Widget . _renderEngine . createElement ( "body" ) . bounds ( ) ;
positionRelativeElementRect = positionRelativeElement . getBoundingClientRect ( ) ,
viewportBounds = document . documentElement . getBoundingClientRect ( ) ;
var top ;
var top ;
if ( comboOffset . top + comboBounds . height / 2 + popupBounds . height / 2 > windowBounds . height ) {
if ( comboRec t . top + comboRect . height / 2 + popupRect . height / 2 > viewport Bounds. height ) {
top = window Bounds. height - popupBounds . height ;
top = viewport Bounds. height - popupRect . height - positionRelativeElementRect . top ;
} else {
} else {
top = comboOffset . top + comboBounds . height / 2 - popupBounds . height / 2 ;
top = comboRect . top + ( comboRect . height - popupRect . height ) / 2 - positionRelativeElementRect . top ;
}
}
if ( top < 0 ) {
if ( top + positionRelativeElementRect . top < 0 ) {
top = 0 ;
top = 0 ;
}
}
return {
return {
@ -446,7 +480,7 @@
} ;
} ;
} ,
} ,
getComboPositionByDirections : function ( combo , popup , extraWidth , extraHeight , needAdaptHeight , directions ) {
getComboPositionByDirections : function ( combo , popup , extraWidth , extraHeight , needAdaptHeight , directions , container ) {
extraWidth || ( extraWidth = 0 ) ;
extraWidth || ( extraWidth = 0 ) ;
extraHeight || ( extraHeight = 0 ) ;
extraHeight || ( extraHeight = 0 ) ;
var i , direct ;
var i , direct ;
@ -483,11 +517,11 @@
if ( ! isNeedAdaptHeight ) {
if ( ! isNeedAdaptHeight ) {
var tW = tbFirst ? extraHeight : extraWidth , tH = tbFirst ? 0 : extraHeight ;
var tW = tbFirst ? extraHeight : extraWidth , tH = tbFirst ? 0 : extraHeight ;
if ( BI . DOM . isLeftSpaceEnough ( combo , popup , tW ) ) {
if ( BI . DOM . isLeftSpaceEnough ( combo , popup , tW ) ) {
left = BI . DOM . getLeftPosition ( combo , popup , tW ) . left ;
left = BI . DOM . getLeftPosition ( combo , popup , tW , container ) . left ;
if ( topBottom [ 0 ] === "bottom" ) {
if ( topBottom [ 0 ] === "bottom" ) {
pos = BI . DOM . getTopAlignPosition ( combo , popup , tH , needAdaptHeight ) ;
pos = BI . DOM . getTopAlignPosition ( combo , popup , tH , needAdaptHeight , container ) ;
} else {
} else {
pos = BI . DOM . getBottomAlignPosition ( combo , popup , tH , needAdaptHeight ) ;
pos = BI . DOM . getBottomAlignPosition ( combo , popup , tH , needAdaptHeight , container ) ;
}
}
pos . dir = "left," + pos . dir ;
pos . dir = "left," + pos . dir ;
if ( tbFirst ) {
if ( tbFirst ) {
@ -503,11 +537,11 @@
if ( ! isNeedAdaptHeight ) {
if ( ! isNeedAdaptHeight ) {
var tW = tbFirst ? extraHeight : extraWidth , tH = tbFirst ? extraWidth : extraHeight ;
var tW = tbFirst ? extraHeight : extraWidth , tH = tbFirst ? extraWidth : extraHeight ;
if ( BI . DOM . isRightSpaceEnough ( combo , popup , tW ) ) {
if ( BI . DOM . isRightSpaceEnough ( combo , popup , tW ) ) {
left = BI . DOM . getRightPosition ( combo , popup , tW ) . left ;
left = BI . DOM . getRightPosition ( combo , popup , tW , container ) . left ;
if ( topBottom [ 0 ] === "bottom" ) {
if ( topBottom [ 0 ] === "bottom" ) {
pos = BI . DOM . getTopAlignPosition ( combo , popup , tH , needAdaptHeight ) ;
pos = BI . DOM . getTopAlignPosition ( combo , popup , tH , needAdaptHeight , container ) ;
} else {
} else {
pos = BI . DOM . getBottomAlignPosition ( combo , popup , tH , needAdaptHeight ) ;
pos = BI . DOM . getBottomAlignPosition ( combo , popup , tH , needAdaptHeight , container ) ;
}
}
pos . dir = "right," + pos . dir ;
pos . dir = "right," + pos . dir ;
if ( tbFirst ) {
if ( tbFirst ) {
@ -522,11 +556,11 @@
case "top" :
case "top" :
var tW = lrFirst ? extraHeight : extraWidth , tH = lrFirst ? extraWidth : extraHeight ;
var tW = lrFirst ? extraHeight : extraWidth , tH = lrFirst ? extraWidth : extraHeight ;
if ( BI . DOM . isTopSpaceEnough ( combo , popup , tH ) ) {
if ( BI . DOM . isTopSpaceEnough ( combo , popup , tH ) ) {
top = BI . DOM . getTopPosition ( combo , popup , tH ) . top ;
top = BI . DOM . getTopPosition ( combo , popup , tH , container ) . top ;
if ( leftRight [ 0 ] === "right" ) {
if ( leftRight [ 0 ] === "right" ) {
pos = BI . DOM . getLeftAlignPosition ( combo , popup , tW , needAdaptHeight ) ;
pos = BI . DOM . getLeftAlignPosition ( combo , popup , tW , container ) ;
} else {
} else {
pos = BI . DOM . getRightAlignPosition ( combo , popup , tW ) ;
pos = BI . DOM . getRightAlignPosition ( combo , popup , tW , container ) ;
}
}
pos . dir = "top," + pos . dir ;
pos . dir = "top," + pos . dir ;
if ( lrFirst ) {
if ( lrFirst ) {
@ -543,11 +577,11 @@
case "bottom" :
case "bottom" :
var tW = lrFirst ? extraHeight : extraWidth , tH = lrFirst ? extraWidth : extraHeight ;
var tW = lrFirst ? extraHeight : extraWidth , tH = lrFirst ? extraWidth : extraHeight ;
if ( BI . DOM . isBottomSpaceEnough ( combo , popup , tH ) ) {
if ( BI . DOM . isBottomSpaceEnough ( combo , popup , tH ) ) {
top = BI . DOM . getBottomPosition ( combo , popup , tH ) . top ;
top = BI . DOM . getBottomPosition ( combo , popup , tH , container ) . top ;
if ( leftRight [ 0 ] === "right" ) {
if ( leftRight [ 0 ] === "right" ) {
pos = BI . DOM . getLeftAlignPosition ( combo , popup , tW , needAdaptHeight ) ;
pos = BI . DOM . getLeftAlignPosition ( combo , popup , tW , container ) ;
} else {
} else {
pos = BI . DOM . getRightAlignPosition ( combo , popup , tW ) ;
pos = BI . DOM . getRightAlignPosition ( combo , popup , tW , container ) ;
}
}
pos . dir = "bottom," + pos . dir ;
pos . dir = "bottom," + pos . dir ;
if ( lrFirst ) {
if ( lrFirst ) {
@ -610,10 +644,10 @@
case "left" :
case "left" :
case "right" :
case "right" :
if ( BI . DOM . isRightSpaceLarger ( combo ) ) {
if ( BI . DOM . isRightSpaceLarger ( combo ) ) {
left = BI . DOM . getRightAdaptPosition ( combo , popup , extraWidth ) . left ;
left = BI . DOM . getRightAdaptPosition ( combo , popup , extraWidth , container ) . left ;
firstDir = "right" ;
firstDir = "right" ;
} else {
} else {
left = BI . DOM . getLeftAdaptPosition ( combo , popup , extraWidth ) . left ;
left = BI . DOM . getLeftAdaptPosition ( combo , popup , extraWidth , container ) . left ;
firstDir = "left" ;
firstDir = "left" ;
}
}
if ( topBottom [ 0 ] === "bottom" ) {
if ( topBottom [ 0 ] === "bottom" ) {
@ -628,19 +662,19 @@
return pos ;
return pos ;
default :
default :
if ( BI . DOM . isBottomSpaceLarger ( combo ) ) {
if ( BI . DOM . isBottomSpaceLarger ( combo ) ) {
top = BI . DOM . getBottomAdaptPosition ( combo , popup , extraHeight , needAdaptHeight ) . top ;
top = BI . DOM . getBottomAdaptPosition ( combo , popup , extraHeight , needAdaptHeight , container ) . top ;
firstDir = "bottom" ;
firstDir = "bottom" ;
} else {
} else {
top = BI . DOM . getTopAdaptPosition ( combo , popup , extraHeight , needAdaptHeight ) . top ;
top = BI . DOM . getTopAdaptPosition ( combo , popup , extraHeight , needAdaptHeight , container ) . top ;
firstDir = "top" ;
firstDir = "top" ;
}
}
if ( leftRight [ 0 ] === "right" ) {
if ( leftRight [ 0 ] === "right" ) {
pos = BI . DOM . getLeftAlignPosition ( combo , popup , extraWidth , needAdaptHeight ) ;
pos = BI . DOM . getLeftAlignPosition ( combo , popup , extraWidth , container ) ;
pos . top = top ;
pos . top = top ;
pos . dir = firstDir + "," + pos . dir ;
pos . dir = firstDir + "," + pos . dir ;
return pos ;
return pos ;
}
}
pos = BI . DOM . getRightAlignPosition ( combo , popup , extraWidth ) ;
pos = BI . DOM . getRightAlignPosition ( combo , popup , extraWidth , container ) ;
pos . top = top ;
pos . top = top ;
pos . dir = firstDir + "," + pos . dir ;
pos . dir = firstDir + "," + pos . dir ;
return pos ;
return pos ;
@ -648,37 +682,77 @@
} ,
} ,
getComboPosition : function ( combo , popup , extraWidth , extraHeight , needAdaptHeight , directions , offsetStyle ) {
getComboPosition : function ( combo , popup , extraWidth , extraHeight , needAdaptHeight , directions , offsetStyle , positionRelativeElement ) {
extraWidth || ( extraWidth = 0 ) ;
extraWidth || ( extraWidth = 0 ) ;
extraHeight || ( extraHeight = 0 ) ;
extraHeight || ( extraHeight = 0 ) ;
var bodyHeight = BI . Widget . _renderEngine . createElement ( "body" ) . bounds ( ) . height - extraHeight ;
var viewportBounds = document . documentElement . getBoundingClientRect ( ) ;
var maxHeight = Math . min ( popup . attr ( "maxHeight" ) || bodyHeight , bodyH eight) ;
var maxHeight = Math . min ( popup . attr ( "maxHeight" ) || viewportBounds . height , viewportBounds . h eight) ;
popup . resetHeight && popup . resetHeight ( maxHeight ) ;
popup . resetHeight && popup . resetHeight ( maxHeight ) ;
var position = BI . DOM . getComboPositionByDirections ( combo , popup , extraWidth , extraHeight , needAdaptHeight , directions || [ "bottom" , "top" , "right" , "left" ] ) ;
var position = BI . DOM . getComboPositionByDirections ( combo , popup , extraWidth , extraHeight , needAdaptHeight , directions || [ "bottom" , "top" , "right" , "left" ] , positionRelativeElement ) ;
switch ( offsetStyle ) {
switch ( offsetStyle ) {
case "center" :
case "center" :
if ( position . change ) {
if ( position . change ) {
var p = BI . DOM . getMiddleAdaptPosition ( combo , popup ) ;
var p = BI . DOM . getMiddleAdaptPosition ( combo , popup , positionRelativeElement ) ;
position . top = p . top ;
position . top = p . top ;
} else {
} else {
var p = BI . DOM . getCenterAdaptPosition ( combo , popup ) ;
var p = BI . DOM . getCenterAdaptPosition ( combo , popup , positionRelativeElement ) ;
position . left = p . left ;
position . left = p . left ;
}
}
break ;
break ;
case "middle" :
case "middle" :
if ( position . change ) {
if ( position . change ) {
var p = BI . DOM . getCenterAdaptPosition ( combo , popup ) ;
var p = BI . DOM . getCenterAdaptPosition ( combo , popup , positionRelativeElement ) ;
position . left = p . left ;
position . left = p . left ;
} else {
} else {
var p = BI . DOM . getMiddleAdaptPosition ( combo , popup ) ;
var p = BI . DOM . getMiddleAdaptPosition ( combo , popup , positionRelativeElement ) ;
position . top = p . top ;
position . top = p . top ;
}
}
break ;
break ;
}
}
if ( needAdaptHeight === true ) {
if ( needAdaptHeight === true ) {
popup . resetHeight && popup . resetHeight ( Math . min ( bodyH eight - position . top , maxHeight ) ) ;
popup . resetHeight && popup . resetHeight ( Math . min ( viewportBounds . h eight - position . top + ( positionRelativeElement ? positionRelativeElement . getBoundingClientRect ( ) . top : 0 ) , maxHeight ) ) ;
}
}
return position ;
return position ;
} ,
/ * *
* 获取position : fixed相对定位的元素
* /
getPositionRelativeContainingBlock : function ( element ) {
if ( [ 'html' , 'body' , '#document' ] . indexOf ( ( element . nodeName || '' ) . toLowerCase ( ) ) >= 0 ) {
// $FlowFixMe[incompatible-return]: assume body is always available
return element . ownerDocument . body ;
}
}
function isExcept ( node ) {
var _computedStyle = getComputedStyle ( node ) ;
var transform = _computedStyle . transform ;
var perspective = _computedStyle . perspective ;
var filter = _computedStyle . filter ;
var willChange = _computedStyle [ "will-change" ] ;
return [ transform , perspective , filter ] . some ( value => value !== 'none' ) || ( willChange === "transform" ) ;
}
if ( isExcept ( element ) ) {
return element ;
}
return BI . DOM . getPositionRelativeContainingBlock ( element . parentNode ) ;
} ,
/ * *
* 获取position : fixed相对定位的元素的clientRect
* /
getPositionRelativeContainingBlockRect : function ( element ) {
var positionRelativeElement = BI . DOM . getPositionRelativeContainingBlock ( element ) ;
var rect = positionRelativeElement . getBoundingClientRect ( ) ;
return {
... rect . toJSON ( ) ,
scaleX : rect . width / positionRelativeElement . offsetWidth ,
scaleY : rect . height / positionRelativeElement . offsetHeight
} ;
} ,
} ) ;
} ) ;
} ) ( ) ;
} ) ( ) ;