in src/Clients/Web/winjs/js/winjs.js [61248:61350]
_loadItem: function pivot_loadItem(index) {
var goPrevious = this._animateToPrevious;
this._cachedRTL = _Global.getComputedStyle(this._element, null).direction === "rtl";
this._loadId++;
var loadId = this._loadId;
this._hidePivotItemAnimation && this._hidePivotItemAnimation.cancel();
this._showPivotItemAnimation && this._showPivotItemAnimation.cancel();
this._slideHeadersAnimation && this._slideHeadersAnimation.cancel();
if (this._currentItem) {
// Hide existing item
this._hidePivotItem(this._currentItem.element, goPrevious);
}
var oldIndex = this._currentIndexOnScreen;
this._currentIndexOnScreen = index;
this._headersState.handleNavigation(goPrevious, index, oldIndex);
if (index < 0) {
return;
}
// Get next item
var item = this._items.getAt(index);
this._currentItem = item;
if (goPrevious) {
this._offsetFromCenter--;
} else if (index !== oldIndex) {
this._offsetFromCenter++;
}
var zooming = false;
if (supportsSnap && _ElementUtilities._supportsZoomTo && this._currentManipulationState !== MSManipulationEventStates.MS_MANIPULATION_STATE_INERTIA) {
if (this._firstLoad) {
_Log.log && _Log.log('_firstLoad index:' + this.selectedIndex + ' offset: ' + this._offsetFromCenter + ' scrollLeft: ' + this._currentScrollTargetLocation, "winjs pivot", "log");
_ElementUtilities.setScrollPosition(this._viewportElement, { scrollLeft: this._currentScrollTargetLocation });
} else {
_Log.log && _Log.log('zoomTo index:' + this.selectedIndex + ' offset: ' + this._offsetFromCenter + ' scrollLeft: ' + this._currentScrollTargetLocation, "winjs pivot", "log");
this._viewportElement.msZoomTo({ contentX: this._currentScrollTargetLocation, contentY: 0, viewportX: 0, viewportY: 0 });
zooming = this._offsetFromCenter !== 0 && this.items.length > 1;
}
}
var that = this;
var selectionChangedDetail = {
index: index,
direction: goPrevious ? "backwards" : "forward",
item: item
};
this._writeProfilerMark("selectionChanged,info");
this._fireEvent(Pivot._EventName.selectionChanged, true, false, selectionChangedDetail);
// Start it hidden until it is loaded
item._process().then(function () {
if (that._disposed || loadId !== that._loadId) {
return;
}
if (supportsSnap) {
// Position item:
item.element.style[that._getDirectionAccessor()] = that._currentScrollTargetLocation + "px";
that._showPivotItem(item.element, goPrevious);
} else {
// Since we aren't msZoomTo'ing when snap points aren't supported, both the show and hide animations would be
// executing on top of each other which produces undesirable visuals. Here we wait for the hide to finish before showing.
if (that._hidePivotItemAnimation) {
that._showPivotItemAnimation = that._hidePivotItemAnimation.then(function () {
if (that._disposed || loadId !== that._loadId) {
return;
}
return that._showPivotItem(item.element, goPrevious);
});
} else {
// During the very first load or when the hide animation is canceled, we just show the pivot item immediately.
that._showPivotItem(item.element, goPrevious);
}
}
var recenterPromise;
if (zooming) {
if (!that._stoppedAndRecenteredSignal) {
that._stoppedAndRecenteredSignal = new _Signal();
}
recenterPromise = that._stoppedAndRecenteredSignal.promise;
} else {
recenterPromise = Promise.wrap();
}
Promise.join([that._slideHeadersAnimation, that._showPivotItemAnimation, that._hidePivotItemAnimation]).then(function () {
recenterPromise.then(function () {
Promise.timeout(50).then(function () {
if (that._disposed || loadId !== that._loadId) {
return;
}
that._navMode = Pivot._NavigationModes.none;
// Fire event even if animation didn't occur:
that._writeProfilerMark("itemAnimationStop,info");
that._fireEvent(Pivot._EventName.itemAnimationEnd, true);
});
});
});
});
},