scrollview-base-debug.js revision 50fe55a3f078d5dd70124b45a75271e75896be42
f69d245bb21be88752420e834a6b6be37e9b525fTripp * The scrollview-base module provides a basic ScrollView Widget, without scrollbar indicators
f69d245bb21be88752420e834a6b6be37e9b525fTripp * @module scrollview-base
cc21b565833307c2b0b06deb4e3ab22c2a94be3eTripp * ScrollView provides a scrollable widget, supporting flick gestures, across both touch and mouse based devices.
cc21b565833307c2b0b06deb4e3ab22c2a94be3eTripp * @class ScrollView
cc21b565833307c2b0b06deb4e3ab22c2a94be3eTripp * @namespace
cc21b565833307c2b0b06deb4e3ab22c2a94be3eTripp * @param config {Object} Object literal with initial attribute values
cc21b565833307c2b0b06deb4e3ab22c2a94be3eTripp * @extends Widget
cc21b565833307c2b0b06deb4e3ab22c2a94be3eTripp * @constructor
cc21b565833307c2b0b06deb4e3ab22c2a94be3eTripp ScrollView.superclass.constructor.apply(this, arguments);
cc21b565833307c2b0b06deb4e3ab22c2a94be3eTripp // Y.ScrollView prototype
cc21b565833307c2b0b06deb4e3ab22c2a94be3eTripp * Designated initializer
cc21b565833307c2b0b06deb4e3ab22c2a94be3eTripp * @method initializer
cc21b565833307c2b0b06deb4e3ab22c2a94be3eTripp initializer: function() {
422668e1d4513bb870b8b576fd9d828c8872f074Tripp // Cache - they're write once, and not going to change
422668e1d4513bb870b8b576fd9d828c8872f074Tripp * Publishes events which occur during the scroll lifecycle
422668e1d4513bb870b8b576fd9d828c8872f074Tripp * @method _createEvents
422668e1d4513bb870b8b576fd9d828c8872f074Tripp _createEvents: function() {
422668e1d4513bb870b8b576fd9d828c8872f074Tripp * Notification event fired at the end of a scroll transition
422668e1d4513bb870b8b576fd9d828c8872f074Tripp * @event scrollEnd
422668e1d4513bb870b8b576fd9d828c8872f074Tripp * @param e {EventFacade} The default event facade.
422668e1d4513bb870b8b576fd9d828c8872f074Tripp * Notification event fired at the end of a flick gesture (the flick animation may still be in progress)
cc21b565833307c2b0b06deb4e3ab22c2a94be3eTripp * @event flick
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param e {EventFacade} The default event facade.
cc21b565833307c2b0b06deb4e3ab22c2a94be3eTripp * Override the contentBox sizing method, since the contentBox height
cc21b565833307c2b0b06deb4e3ab22c2a94be3eTripp * should not be that of the boundingBox.
422668e1d4513bb870b8b576fd9d828c8872f074Tripp * @method _uiSizeCB
422668e1d4513bb870b8b576fd9d828c8872f074Tripp * @protected
422668e1d4513bb870b8b576fd9d828c8872f074Tripp _uiSizeCB: function() {},
422668e1d4513bb870b8b576fd9d828c8872f074Tripp * TranstionEnd event handler
422668e1d4513bb870b8b576fd9d828c8872f074Tripp * @method _transitionEnded
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * bindUI implementation
422668e1d4513bb870b8b576fd9d828c8872f074Tripp * Hooks up events for the widget
422668e1d4513bb870b8b576fd9d828c8872f074Tripp * @method bindUI
422668e1d4513bb870b8b576fd9d828c8872f074Tripp bindUI: function() {
422668e1d4513bb870b8b576fd9d828c8872f074Tripp this._bb.on('gesturemovestart', Y.bind(this._onGestureMoveStart, this));
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp cb.on('transition:end', Y.bind(this._transitionEnded, this), false);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp // TODO: Fires way to often when using non-native transitions, due to property change
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp cb.on('DOMSubtreeModified', Y.bind(this._uiDimensionsChange, this));
cc21b565833307c2b0b06deb4e3ab22c2a94be3eTripp 'renderedChange': function() { Y.later(0, this, '_uiDimensionsChange'); }
cc21b565833307c2b0b06deb4e3ab22c2a94be3eTripp * syncUI implementation
422668e1d4513bb870b8b576fd9d828c8872f074Tripp * Update the scroll position, based on the current value of scrollY
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method bindUI
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp syncUI: function() {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this.scrollTo(this.get(SCROLL_X), this.get(SCROLL_Y));
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Scroll the element to a given y coordinate
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method scrollTo
cc21b565833307c2b0b06deb4e3ab22c2a94be3eTripp * @param x {Number} The x-position to scroll to
cc21b565833307c2b0b06deb4e3ab22c2a94be3eTripp * @param y {Number} The y-position to scroll to
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param duration {Number} Duration, in ms, of the scroll animation (default is 0)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param easing {String} An easing equation if duration is set
cc21b565833307c2b0b06deb4e3ab22c2a94be3eTripp xSet = (x !== null),
cc21b565833307c2b0b06deb4e3ab22c2a94be3eTripp ySet = (y !== null),
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp Y.log("Transition: duration, easing:" + transition.duration, transition.easing, "scrollview");
422668e1d4513bb870b8b576fd9d828c8872f074Tripp transition.transform = 'translate('+ xMove +'px,'+ yMove +'px)';
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * gesturemovestart event handler
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method _onGestureMoveStart
422668e1d4513bb870b8b576fd9d828c8872f074Tripp * @param e {Event.Facade} The gesturemovestart event facade
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp _onGestureMoveStart: function(e) {
422668e1d4513bb870b8b576fd9d828c8872f074Tripp this._moveEvt = bb.on('gesturemove', Y.bind(this._onGestureMove, this));
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._moveEndEvt = bb.on('gesturemoveend', Y.bind(this._onGestureMoveEnd, this));
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._isDragging = false;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._snapToEdge = false;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * gesturemove event handler
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method _onGestureMove
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param e {Event.Facade} The gesturemove event facade
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp _onGestureMove: function(e) {
cc21b565833307c2b0b06deb4e3ab22c2a94be3eTripp this._isDragging = true;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * gestureend event handler
cc21b565833307c2b0b06deb4e3ab22c2a94be3eTripp * @method _onGestureMoveEnd
cc21b565833307c2b0b06deb4e3ab22c2a94be3eTripp * @param e {Event.Facade} The gesturemoveend event facade
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp _onGestureMoveEnd: function(e) {
422668e1d4513bb870b8b576fd9d828c8872f074Tripp startPoint = this._scrollsVertical ? this._moveStartClientY : this._moveStartClientX,
422668e1d4513bb870b8b576fd9d828c8872f074Tripp endPoint = this._scrollsVertical ? this._moveEndClientY : this._moveEndClientX,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._snapToEdge = false;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._isDragging = false;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if(this._scrollsHorizontal && Math.abs(distance) > (this.get('width')/2)) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if(this._scrollsVertical && Math.abs(distance) > (this.get('height')/2)) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp // Check for minY/maxY
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._snapToEdge = true;
422668e1d4513bb870b8b576fd9d828c8872f074Tripp this._snapToEdge = true;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp // Check for minX/maxX
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._snapToEdge = true;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._snapToEdge = true;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp // Check for staleness
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * after listener for changes to the scrollY attr
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method _afterScrollYChange
f69d245bb21be88752420e834a6b6be37e9b525fTripp * @param e {Event.Facade} The event
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp * @protected
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp _afterScrollYChange : function(e) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Update the UI when the scrollY attr changes
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method _uiScrollY
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param val {Number} The scrollY value
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param duration {Number} The length (in ms) of the scroll animation
_afterScrollXChange : function(e) {
_afterHeightChange: function() {
this._uiDimensionsChange();
_afterWidthChange: function() {
this._uiDimensionsChange();
_uiDimensionsChange: function() {
this._scrollsVertical = true;
this._scrollsHorizontal = true;
_flick: function(e) {
this._flicking = true;
this._flickFrame();
_flickFrame: function() {
var newY,
maxY,
minY,
newX,
maxX,
minX,
if(scrollsVertical) {
if(scrollsHorizontal) {
this._flicking = false;
if(scrollsVertical) {
this._snapToEdge = true;
this._snapToEdge = true;
if(scrollsHorizontal) {
this._snapToEdge = true;
this._snapToEdge = true;
if (scrollsVertical) {
this._exceededYBoundary = true;
if (scrollsHorizontal) {
this._exceededXBoundary = true;
if (!this._flickTimer) {
if(this._flickTimer) {
this._flickTimer = null;
if(fireEvent) {
return val;
ATTRS: {
scrollY: {
scrollX: {
deceleration: {
bounce: {
flick: {
value: {