scrollview-base.js revision 31575e6e290a0adabeb28fc630a6d57db415013a
/**
* ScrollView module
*
* @module scrollview
* @submodule scrollview-base
*/
SCROLLVIEW = 'scrollview',
CLASS_NAMES = {
},
EV_SCROLL_START = 'scrollStart',
EV_SCROLL_CHANGE = 'scrollChange',
EV_SCROLL_END = 'scrollEnd',
EV_SCROLL_FLICK = 'flick',
UI = 'ui',
SCROLL_Y = "scrollY",
SCROLL_X = "scrollX",
BOUNCE = "bounce",
BOUNDING_BOX = "boundingBox",
CONTENT_BOX = "contentBox";
/**
* ScrollView provides a scrollable container for devices which do not
* support overflow: hidden
*
* @class ScrollView
* @param config {Object} Object literal specifying scrollview configuration properties.
* @extends Widget
* @constructor
*/
function ScrollView() {
}
// Y.ScrollView prototype
/**
* Designated initializer
*
* @method initializer
*/
initializer: function() {
this._createEvents();
},
/**
* Publish events which occur during the scroll lifecycle
*
* @method _createEvents
* @private
*/
_createEvents: function() {
this.publish(EV_SCROLL_START);
this.publish(EV_SCROLL_CHANGE);
this.publish(EV_SCROLL_END);
this.publish(EV_SCROLL_FLICK);
},
/**
* Override the contentBox sizing method, since the contentBox height
* should not be that of the boundingBox.
*
* @method _uiSizeCB
* @protected
*/
_uiSizeCB: function() {},
/**
* TranstionEnd event handler
*
* @method _transitionEnded
* @private
*/
_transitionEnded: function() {
this.fire(EV_SCROLL_END);
},
/**
* bindUI implementation
*
* Hooks up events for the widget
* @method bindUI
*/
bindUI: function() {
});
this.after({
'scrollYChange' : this._afterScrollYChange,
'scrollXChange' : this._afterScrollXChange,
'heightChange' : this._afterHeightChange,
'widthChange' : this._afterWidthChange,
});
},
/**
* syncUI implementation
*
* Update the scroll position, based on the current value of scrollY
* @method bindUI
*/
syncUI: function() {
},
/**
* Scroll the element to a given y coordinate
*
* @method scrollTo
* @param x {Number} The x-position to scroll to
* @param y {Number} The y-position to scroll to
* @param duration {Number} Duration, in ms, of the scroll animation (default is 0)
* @param easing {String} An easing equation if duration is set
*/
xMove = x * -1,
yMove = y * -1,
}
}
transition = {
};
if (Y.TransitionNative.supported) {
} else {
}
},
/**
* gesturemovestart event handler
*
* @method _onGestureMoveStart
* @param e {Event} The event
* @private
*/
_onGestureMoveStart: function(e) {
this._killTimer();
this._moveStartTime = (new Date()).getTime();
this._moveStartClientY = e.clientY;
this._moveStartClientX = e.clientX;
this._isDragging = false;
this._snapToEdge = false;
},
/**
* gesturemove event handler
*
* @method _onGestureMove
* @param e {Event} The event
* @private
*/
_onGestureMove: function(e) {
this._isDragging = true;
this._moveEndClientY = e.clientY;
this._moveEndClientX = e.clientX;
this._lastMoved = (new Date()).getTime();
if(this._scrollsVertical) {
}
if(this._scrollsHorizontal) {
}
},
/**
* gestureend event handler
*
* @method _onGestureMoveEnd
* @param e {Event} The event
* @private
*/
_onGestureMoveEnd: function(e) {
var minY = this._minScrollY,
maxY = this._maxScrollY,
minX = this._minScrollX,
maxX = this._maxScrollX,
this._moveEndEvt.detach();
this._scrolledHalfway = false;
this._snapToEdge = false;
this._isDragging = false;
this._scrolledHalfway = true;
}
this._scrolledHalfway = true;
}
// Check for minY
this._snapToEdge = true;
}
// Check for minX
this._snapToEdge = true;
}
// Check for maxY
this._snapToEdge = true;
}
// Check for maxX
this._snapToEdge = true;
}
if(this._snapToEdge) {
return;
}
// Check for staleness
if(+(new Date()) - this._moveStartTime > 100) {
this.fire(EV_SCROLL_END, {
staleScroll: true
});
return;
}
},
/**
* after listener for changes to the scrollY attr
*
* @method _afterScrollYChange
* @param e {Event.Facade} The event
* @protected
*/
_afterScrollYChange : function(e) {
}
},
/**
* Update the UI when the scrollY attr changes
*
* @method _uiScrollY
* @param val {Number} The scrollY value
* @param duration {Number} The length (in ms) of the scroll animation
* @param easing {String} An easing equation, if duration is defined
* @protected
*/
},
/**
* after listener for changes to the scrollX attr
*
* @method _afterScrollXChange
* @param e {Event.Facade} The event
* @protected
*/
_afterScrollXChange : function(e) {
}
},
/**
* Update the UI when the scrollX attr changes
*
* @method _uiScrollX
* @param val {Number} The scrollX value
* @param duration {Number} The length (in ms) of the scroll animation
* @param easing {String} An easing equation, if duration is defined
* @protected
*/
},
/**
* after listener for the height attribute
*
* @method _afterHeightChange
* @param e {Event.Facade} The event
* @protected
*/
_afterHeightChange: function() {
this._uiDimensionsChange();
},
/**
* after listener for the width attribute
*
* @method _afterHeightChange
* @param e {Event.Facade} The event
* @protected
*/
_afterWidthChange: function() {
this._uiDimensionsChange();
},
/**
* This method gets invoked whenever the height or width attrs change,
* allowing us to determine which scrolling axes need to be enabled.
*
* @method _uiDimensionsChange
* @protected
*/
_uiDimensionsChange: function() {
this._scrollsVertical = true;
this._minScrollY = 0;
}
this._scrollsHorizontal = true;
this._minScrollX = 0;
}
},
/**
* Execute a flick at the end of a scroll action
*
* @method _flick
* @param distance {Number} The distance (in px) the user scrolled before the flick
* @param time {Number} The number of ms the scroll event lasted before the flick
* @protected
*/
_flick: function(e) {
this._flicking = true;
this._flickFrame();
this.fire(EV_SCROLL_FLICK);
},
/**
* Execute a single frame in the flick animation
*
* @method _flickFrame
* @protected
*/
_flickFrame: function() {
maxY = this._maxScrollY,
minY = this._minScrollY,
maxX = this._maxScrollX,
minX = this._minScrollX,
if(this._scrollsVertical) {
}
if(this._scrollsHorizontal) {
}
this._flicking = false;
if(this._scrollsVertical) {
this._snapToEdge = true;
this._snapToEdge = true;
}
}
if(this._scrollsHorizontal) {
this._snapToEdge = true;
this._snapToEdge = true;
}
}
return;
}
this._exceededYBoundary = true;
}
this._exceededXBoundary = true;
}
if(this._scrollsVertical) {
}
if(this._scrollsHorizontal) {
}
},
/**
* Stop the animation timer
*
* @method _killTimer
* @param fireEvent {Boolean} If true, fire the scrollEnd event
* @private
*/
_killTimer: function(fireEvent) {
if(this._flickTimer) {
this._flickTimer.cancel();
}
if(fireEvent) {
this.fire(EV_SCROLL_END);
}
},
/**
* Setter for the scrollX ATTR
*
* @method _setScrollX
* @param val {Number} The new scrollX value
* @protected
*/
_setScrollX: function(val) {
if(!bouncing || !this._isDragging) {
}
}
return val;
},
/**
* Setter for the scrollY ATTR
*
* @method _setScrollY
* @param val {Number} The new scrollY value
* @protected
*/
_setScrollY: function(val) {
if(!bouncing || !this._isDragging) {
}
}
return val;
}
}, {
// Y.ScrollView static properties
/**
* The identity of the widget.
*
* @property ScrollView.NAME
* @type String
* @default 'scrollview'
* @readOnly
* @protected
* @static
*/
NAME: 'scrollview',
/**
* Static property used to define the default attribute configuration of
* the Widget.
*
* @property ScrollView.ATTRS
* @type {Object}
* @protected
* @static
*/
ATTRS: {
/**
* The scroll position in the y-axis
*
* @attribute scrollY
* @type Number
* @default 0
*/
scrollY: {
value: 0,
setter: '_setScrollY'
},
/**
* The scroll position in the x-axis
*
* @attribute scrollX
* @type Number
* @default 0
*/
scrollX: {
value: 0,
setter: '_setScrollX'
},
/**
* Drag coefficent for inertial scrolling. The closer to 1 this
* value is, the less friction during scrolling.
*
* @attribute deceleration
* @default 0.98
*/
deceleration: {
value: 0.98
},
/**
* Drag coefficient for intertial scrolling at the upper
* and lower boundaries of the scrollview. Set to 0 to
* disable "rubber-banding".
*
* @attribute bounce
* @type Number
* @default 0.7
*/
bounce: {
value: 0.7
}
},
/**
* List of class names used in the scrollview's DOM
*
* @property CLASS_NAMES
* @type Object
* @static
*/
/**
* Flag used to source property changes initiated from the DOM
*
* @property UI_SRC
* @type String
* @static
*/
BOUNCE_RANGE : 150,
FRAME_STEP : 10,
EASING : 'cubic-bezier(0, 0.1, 0, 1.0)',
SNAP_EASING : 'ease-out'
});