X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.6.x%2Fjs%2F20_ui%2F16_Repeater.js;h=6deacef79d117dc1e174d33d2cccd9b3366ae323;hb=3d352d8bf476ab57cc333e8d02d0e6ea5efa69b7;hp=e709360de1d8c4d681d1903bdc234fcec463574f;hpb=094b0536bafe5efd70540698cf74ab13ece03ebb;p=pettanr%2FclientJs.git diff --git a/0.6.x/js/20_ui/16_Repeater.js b/0.6.x/js/20_ui/16_Repeater.js index e709360..6deacef 100644 --- a/0.6.x/js/20_ui/16_Repeater.js +++ b/0.6.x/js/20_ui/16_Repeater.js @@ -7,19 +7,14 @@ var XUI_Repeater = XUI_Box.inherits( '_Repeater', X_Class.NONE, { - layout : XUI_Layout_Vertical, + layout : XUI_Layout_Vertical, - dataSource : null, // Array., Array. + dataSource : null, // Array., Array. itemRenderer : null, itemNodes : null, - - startIndex : 0, - startRenderIndex : 0, - numItemsParPage : 0, - numItemsPrev : 0, - numItems : 0, + itemHeightLast : 0, itemHeightLastEM : 0, @@ -33,8 +28,6 @@ var XUI_Repeater = XUI_Box.inherits( initialize : function(){ XUI_AbstractUINode.prototype.initialize.apply( this, arguments ); - - this.parent[ 'listen' ]( XUI_Event.SCROLL_END, this ); }, /* @@ -44,9 +37,6 @@ var XUI_Repeater = XUI_Box.inherits( var dataSource = this[ 'dataSource' ]; if( allowedW + allowedH === XUI_Attr_AUTO ) return false; - - this.scrollPortWidth = allowedW; - this.scrollPortHeight = allowedH; this.preMesure( allowedW, allowedH ); @@ -67,54 +57,8 @@ var XUI_Repeater = XUI_Box.inherits( }, handleEvent : function( e ){ - var scrollBox, scrollY, dataSource, offsetY, startIndex, maxIndex, offset, itemNodes, ary, i, l; - switch( e.type ){ - case XUI_Event.SCROLL_END : - scrollBox = this.parentData; - scrollY = - scrollBox.scrollY; - dataSource = this[ 'dataSource' ]; - itemNodes = this.itemNodes; - itemH = this.itemHeightLast; - - // transition Y を 0 付近に。 - - - // startIndex の計算 - startIndex = scrollY / itemH | 0; - - /*maxIndex = dataSource.length <= this.numItems ? 0 : dataSource.length - this.numItems; - console.log( ' >>> ' + startIndex + ' ' + maxIndex ); - - startIndex = - startIndex < 0 ? 0 : - maxIndex < startIndex ? maxIndex : startIndex; */ - // アイテムの座標の修正とレンジ外のアイテムを配列内で再配置 - offset = startIndex - this.startIndex; // visible な stratIndex renderStartIndex - this.startIndex = startIndex; - - console.log( this.numItemsPrev + ' oo ' + offset ) - - if( 0 < offset ){ - itemNodes.push.apply( itemNodes, itemNodes.splice( 0, offset ) ); - } else - if( offset < - 0 ){ - itemNodes.unshift.apply( itemNodes, itemNodes.splice( itemNodes.length + offset ) ); - }; - - // 再配置されたアイテムにitemData のセット - this.updateItemRenderer( this.contentWidth, this.scrollPortHeight ); - - - - offsetY = scrollY % itemH; - offsetY = offsetY === 0 ? 0 : ( offsetY - itemH ); - offsetY += ( this.startRenderIndex - this.startIndex ) * itemH; - //console.log( ' ====> ' + this.startRenderIndex + ' -> ' + this.startIndex + ' scrollY:' + offsetY ); - //scrollBox.scrollTo( 0, - scrollY, 0, '', 0 ); // anime無し - //console.log( ' <==== ' ); - break; }; }, @@ -123,19 +67,14 @@ var XUI_Repeater = XUI_Box.inherits( attrs = this.attrObject || this.attrClass.prototype, gapY = XUI_AbstractUINode_calcValue( attrs[ this.usableAttrs.gapY.No ], _w ), dataSource = this[ 'dataSource' ], - render = this[ 'itemRenderer' ], + renderer = this[ 'itemRenderer' ], l = dataSource.length, - start = this.startIndex - this.numItemsPrev, itemH = this.itemHeightLastEM, - i, data, node, _y = 0, last, n; - - i = this.startRenderIndex = start = start < 0 ? 0 : start; - - _y = ( itemH + gapY ) * i; + i = 0, data, node, _y = 0, last, n; for( ; i < l; ++i ){ if( !( data = itemNodes[ i ] ) ){ - node = render.clone( true ); + node = renderer.clone( true ); this.addAt( i, [ node ] ); data = itemNodes[ i ] = X_Pair_get( node ); // init -> addToParent -> creationComplete @@ -146,17 +85,10 @@ var XUI_Repeater = XUI_Box.inherits( _y += ( itemH || data.boxHeight ) + gapY; // 一番最初のループ。ここでページあたりのアイテム数を計算 - if( !itemH && i === start ){ + if( !itemH && i === 0 ){ itemH = _y - gapY; this.itemHeightLastEM = itemH; - this.itemHeightLast = itemH * X_ViewPort_baseFontSize, - // scroller の miniHeight は(例えば)親の高さの300% そこにいくつのアイテムを並べることが出来るか?端数切り上げ - this.numItemsParPage = _h / itemH + 0.999 | 0; - n = this.numItems = ( _h * 3 ) / itemH + 0.999 | 0; // TODO boxHeight - this.numItemsPrev = ( this.numItems - this.numItemsParPage ) / 2 | 0; - last = i + n; - // データの最後まで、または、開始位置から 3ページ分を生成する - l = last < l ? last : l; + this.itemHeightLast = itemH * X_ViewPort_baseFontSize; }; }; @@ -165,7 +97,7 @@ var XUI_Repeater = XUI_Box.inherits( }; // TODO contentHeight は attr を無視する -> 未表示領域につくるアイテム数 GPU の有無で変わる - this.contentHeight = dataSource.length * ( itemH + gapY ) - gapY; + this.contentHeight = l * ( itemH + gapY ) - gapY; }, onPropertyChange : function( name, newValue ){