};
function getCurrentTime() {
- return ( new Date()).getTime();
+ return Date.now();
}
$.extend( MomentumTracker.prototype, {
},
_create: function () {
- this._$clip = $( this.element).addClass( "ui-scrollview-clip" );
- var $child = this._$clip.children(),
- self;
- //if ( $child.length > 1 ) {
- $child = this._$clip.wrapInner( "<div></div>" ).children();
- //}
- this._$view = $child.addClass( "ui-scrollview-view" );
- this._$list = $child.children();
+ var self = this;
+
+ this._items = $( this.element ).jqmData('list');
+ this._$clip = $( this.element ).addClass( "ui-scrollview-clip" );
+ this._$clip.wrapInner( '<div class="ui-scrollview-view"></div>' );
+ this._$view = $('.ui-scrollview-view', this._$clip );
+ this._$list = $( 'ul', this._$clip );
this._$clip.css( "overflow", "hidden" );
this._makePositioned( this._$clip );
this._timerInterval = 1000 / this.options.fps;
this._timerID = 0;
- self = this;
this._timerCB = function () { self._handleMomentumScroll(); };
this.refresh();
this._addBehaviors();
},
+ reflow: function () {
+ var xy = this.getScrollPosition();
+ this.refresh();
+ this.scrollTo( xy.x, xy.y );
+ },
+
refresh: function () {
var itemsPerView;
- this._viewWidth = this._$view.width();
- this._clipWidth = $( window ).width();
- this._itemWidth = this._$list.children().first().outerWidth();
- this._$items = this._$list.children().detach();
+ this._$clip.width( $(window).width() );
+ this._clipWidth = this._$clip.width();
+ this._$list.empty();
+ this._$list.append(this._items[0]);
+ this._itemWidth = $(this._items[0]).outerWidth();
+ $(this._items[0]).detach();
+
itemsPerView = this._clipWidth / this._itemWidth;
itemsPerView = Math.ceil( itemsPerView * 10 ) / 10;
this._itemsPerView = parseInt( itemsPerView, 10 );
-
+ while ( this._itemsPerView + 1 > this._items.length ) {
+ $.merge( this._items, $(this._items).clone() );
+ }
this._rx = -this._itemWidth;
this._sx = -this._itemWidth;
this._setItems();
$item;
for ( i = -1; i < this._itemsPerView + 1; i++ ) {
- $item = this._$items[ circularNum( i, this._$items.length ) ];
+ $item = this._items[ circularNum( i, this._items.length ) ];
this._$list.append( $item );
}
setElementTransform( this._$view, this._sx + "px", 0 );
for ( i = 0; i < di; i++ ) {
this._$list.children().last().detach();
idx = -parseInt( ( sx / this._itemWidth ) + i + 3, 10 );
- $item = this._$items[ circularNum( idx, this._$items.length ) ];
+ $item = this._items[ circularNum( idx, this._items.length ) ];
this._$list.prepend( $item );
//console.log( "di > 0 : " + idx );
}
for ( i = 0; i > di; i-- ) {
this._$list.children().first().detach();
idx = this._itemsPerView - parseInt( ( sx / this._itemWidth ) + i, 10 );
- $item = this._$items[ circularNum( idx, this._$items.length ) ];
+ $item = this._items[ circularNum( idx, this._items.length ) ];
this._$list.append( $item );
//console.log( "di < 0 : " + idx );
}
return svh;
},
- centerTo: function ( selector ) {
+ centerTo: function ( selector, duration ) {
var i,
newX;
- for ( i = 0; i < this._$items.length; i++ ) {
- if ( $( this._$items[i]).is( selector ) ) {
- newX = -( i * this._itemWidth - this._clipWidth / 2 + this._itemWidth * 2 );
- this.scrollTo( newX, 0 );
- console.log( i + "," + newX );
+ for ( i = 0; i < this._items.length; i++ ) {
+ if ( $( this._items[i]).is( selector ) ) {
+ newX = -( i * this._itemWidth - this._clipWidth / 2 + this._itemWidth * 1.5 );
+ this.scrollTo( newX + this._clipWidth * 2, 0 );
+ this.scrollTo( newX, 0, duration );
return;
}
}
return;
}
- x = -x;
- y = -y;
-
var self = this,
start = getCurrentTime(),
efunc = $.easing.easeOutQuad,
elapsed,
ec;
+ this._rx = x;
+
tfunc = function () {
elapsed = getCurrentTime() - start;
if ( elapsed >= duration ) {