@ -23,7 +23,7 @@
} ) ;
} ) ;
var fromChildren = fromElement . children ( ) , toChildren = toElement . children ( ) ;
var fromChildren = fromElement . children ( ) , toChildren = toElement . children ( ) ;
if ( fromChildren . length !== toChildren . length ) {
if ( fromChildren . length !== toChildren . length ) {
throw new Error ( "不匹配 " ) ;
throw new Error ( "don't match " ) ;
}
}
BI . each ( fromChildren , function ( i , child ) {
BI . each ( fromChildren , function ( i , child ) {
BI . DOM . patchProps ( BI . jQuery ( child ) , BI . jQuery ( toChildren [ i ] ) ) ;
BI . DOM . patchProps ( BI . jQuery ( child ) , BI . jQuery ( toChildren [ i ] ) ) ;
@ -108,12 +108,13 @@
} ,
} ,
// 获取滚动条的宽度,页面display: none时候获取到的为0
// 获取滚动条的宽度,页面display: none时候获取到的为0
getScrollWidth : function ( ) {
getScrollWidth : function ( css ) {
if ( BI . isNull ( this . _scrollWidth ) || this . _scrollWidth === 0 ) {
if ( BI . isNull ( this . _scrollWidth ) || this . _scrollWidth === 0 ) {
var ul = BI . Widget . _renderEngine . createElement ( "<div>" ) . width ( 50 ) . height ( 50 ) . css ( {
var ul = BI . Widget . _renderEngine . createElement ( "<div>" ) . width ( 50 ) . height ( 50 ) . css ( {
position : "absolute" ,
position : "absolute" ,
top : "-9999px" ,
top : "-9999px" ,
overflow : "scroll"
overflow : "scroll" ,
... css
} ) . appendTo ( "body" ) ;
} ) . appendTo ( "body" ) ;
this . _scrollWidth = ul [ 0 ] . offsetWidth - ul [ 0 ] . clientWidth ;
this . _scrollWidth = ul [ 0 ] . offsetWidth - ul [ 0 ] . clientWidth ;
ul . destroy ( ) ;
ul . destroy ( ) ;
@ -156,7 +157,7 @@
var popupEl = popup . element ;
var popupEl = popup . element ;
var elRect = el [ 0 ] . getBoundingClientRect ( ) ;
var elRect = el [ 0 ] . getBoundingClientRect ( ) ;
var popupElRect = popupEl [ 0 ] . getBoundingClientRect ( ) ;
var popupElRect = popupEl [ 0 ] . getBoundingClientRect ( ) ;
var containerRect = container ? container . getBoundingClientRect ( ) : { left : 0 } ;
var containerRect = container ? container . getBoundingClientRect ( ) : { left : 0 } ;
return {
return {
left : elRect . left - containerRect . left - popupElRect . width - ( extraWidth || 0 )
left : elRect . left - containerRect . left - popupElRect . width - ( extraWidth || 0 )
@ -172,7 +173,7 @@
getRightPosition : function ( combo , popup , extraWidth , container ) {
getRightPosition : function ( combo , popup , extraWidth , container ) {
var el = combo . element ;
var el = combo . element ;
var elRect = el [ 0 ] . getBoundingClientRect ( ) ;
var elRect = el [ 0 ] . getBoundingClientRect ( ) ;
var containerRect = container ? container . getBoundingClientRect ( ) : { left : 0 } ;
var containerRect = container ? container . getBoundingClientRect ( ) : { left : 0 } ;
return {
return {
left : elRect . left + elRect . width - containerRect . left + ( extraWidth || 0 )
left : elRect . left + elRect . width - containerRect . left + ( extraWidth || 0 )
@ -191,7 +192,7 @@
var popupEl = popup . element ;
var popupEl = popup . element ;
var elRect = el [ 0 ] . getBoundingClientRect ( ) ;
var elRect = el [ 0 ] . getBoundingClientRect ( ) ;
var popupElRect = popupEl [ 0 ] . getBoundingClientRect ( ) ;
var popupElRect = popupEl [ 0 ] . getBoundingClientRect ( ) ;
var containerRect = container ? container . getBoundingClientRect ( ) : { top : 0 } ;
var containerRect = container ? container . getBoundingClientRect ( ) : { top : 0 } ;
return {
return {
top : elRect . top - containerRect . top - popupElRect . height - ( extraHeight || 0 )
top : elRect . top - containerRect . top - popupElRect . height - ( extraHeight || 0 )
@ -201,7 +202,7 @@
getBottomPosition : function ( combo , popup , extraHeight , container ) {
getBottomPosition : function ( combo , popup , extraHeight , container ) {
var el = combo . element ;
var el = combo . element ;
var elRect = el [ 0 ] . getBoundingClientRect ( ) ;
var elRect = el [ 0 ] . getBoundingClientRect ( ) ;
var containerRect = container ? container . getBoundingClientRect ( ) : { top : 0 } ;
var containerRect = container ? container . getBoundingClientRect ( ) : { top : 0 } ;
return {
return {
top : elRect . top - containerRect . top + elRect . height + ( extraHeight || 0 )
top : elRect . top - containerRect . top + elRect . height + ( extraHeight || 0 )
@ -254,7 +255,7 @@
var comboRect = combo . element [ 0 ] . getBoundingClientRect ( ) ,
var comboRect = combo . element [ 0 ] . getBoundingClientRect ( ) ,
popupRect = popup . element [ 0 ] . getBoundingClientRect ( ) ,
popupRect = popup . element [ 0 ] . getBoundingClientRect ( ) ,
viewportRect = document . documentElement . getBoundingClientRect ( ) ,
viewportRect = document . documentElement . getBoundingClientRect ( ) ,
containerRect = container ? container . getBoundingClientRect ( ) : { left : 0 } ;
containerRect = container ? container . getBoundingClientRect ( ) : { left : 0 } ;
var left = comboRect . left - containerRect . left + extraWidth ;
var left = comboRect . left - containerRect . left + extraWidth ;
if ( comboRect . left + popupRect . width > viewportRect . width ) {
if ( comboRect . left + popupRect . width > viewportRect . width ) {
@ -267,7 +268,7 @@
var left = this . _getLeftAlignPosition ( combo , popup , extraWidth , container ) ;
var left = this . _getLeftAlignPosition ( combo , popup , extraWidth , container ) ;
var dir = "" ;
var dir = "" ;
// 如果放不下,优先使用RightAlign, 如果RightAlign也放不下, 再使用left=0
// 如果放不下,优先使用RightAlign, 如果RightAlign也放不下, 再使用left=0
var containerRect = container ? container . getBoundingClientRect ( ) : { left : 0 } ;
var containerRect = container ? container . getBoundingClientRect ( ) : { left : 0 } ;
if ( left + containerRect . left < 0 ) {
if ( left + containerRect . left < 0 ) {
left = this . _getRightAlignPosition ( combo , popup , extraWidth ) ;
left = this . _getRightAlignPosition ( combo , popup , extraWidth ) ;
dir = "left" ;
dir = "left" ;
@ -293,7 +294,7 @@
_getRightAlignPosition : function ( combo , popup , extraWidth , container ) {
_getRightAlignPosition : function ( combo , popup , extraWidth , container ) {
var comboBounds = combo . element [ 0 ] . getBoundingClientRect ( ) ,
var comboBounds = combo . element [ 0 ] . getBoundingClientRect ( ) ,
viewBounds = popup . element [ 0 ] . getBoundingClientRect ( ) ,
viewBounds = popup . element [ 0 ] . getBoundingClientRect ( ) ,
containerRect = container ? container . getBoundingClientRect ( ) : { left : 0 } ;
containerRect = container ? container . getBoundingClientRect ( ) : { left : 0 } ;
return comboBounds . left + comboBounds . width - viewBounds . width - extraWidth - containerRect . left ;
return comboBounds . left + comboBounds . width - viewBounds . width - extraWidth - containerRect . left ;
} ,
} ,
@ -327,7 +328,7 @@
var comboBounds = combo . element [ 0 ] . getBoundingClientRect ( ) ,
var comboBounds = combo . element [ 0 ] . getBoundingClientRect ( ) ,
popupBounds = popup . element [ 0 ] . getBoundingClientRect ( ) ,
popupBounds = popup . element [ 0 ] . getBoundingClientRect ( ) ,
viewportBounds = document . documentElement . getBoundingClientRect ( ) ,
viewportBounds = document . documentElement . getBoundingClientRect ( ) ,
containerBounds = container ? container . getBoundingClientRect ( ) : { top : 0 } ;
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 = comboBounds . top - containerBounds . top + extraHeight ;
top = comboBounds . top - containerBounds . top + extraHeight ;
@ -386,7 +387,7 @@
var comboBounds = combo . element [ 0 ] . getBoundingClientRect ( ) ,
var comboBounds = combo . element [ 0 ] . getBoundingClientRect ( ) ,
popupBounds = popup . element [ 0 ] . getBoundingClientRect ( ) ,
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 } ;
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 = comboBounds . top + comboBounds . height - containerBounds . top - popupBounds . height ;
top = comboBounds . top + comboBounds . height - containerBounds . top - popupBounds . height ;
@ -746,7 +747,7 @@
* /
* /
getPositionRelativeContainingBlockRect : function ( element ) {
getPositionRelativeContainingBlockRect : function ( element ) {
const positionRelativeElement = BI . DOM . getPositionRelativeContainingBlock ( element ) ;
const positionRelativeElement = BI . DOM . getPositionRelativeContainingBlock ( element ) ;
const { top , right , bottom , left , width , height , x , y } = positionRelativeElement . getBoundingClientRect ( ) ;
const { top , right , bottom , left , width , height , x , y } = positionRelativeElement . getBoundingClientRect ( ) ;
return {
return {