scrollview-base-debug.js revision 81779a842aaa6d4807c29c98ccbcb6d5e5116683
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * The scrollview-base module provides a basic ScrollView Widget, without scrollbar indicators
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @module scrollview-base
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNicovar getClassName = Y.ClassNameManager.getClassName,
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * ScrollView provides a srollable widget, supporting flick gestures, across both touch and mouse based devices.
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * @class ScrollView
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * @namespace
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * @param config {Object} Object literal with initial attribute values
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @extends Widget
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * @constructor
c544ac2705cf516901c8455356d56b52c8615525mfloryan ScrollView.superclass.constructor.apply(this, arguments);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico // Y.ScrollView prototype
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * Designated initializer
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @method initializer
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico initializer: function() {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * Publishes events which occur during the scroll lifecycle
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * @method _createEvents
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * Notification event fired at the end of a scroll transition
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * @event scrollEnd
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @param e {EventFacade} The default event facade.
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * Notification event fired at the end of a flick gesture (the flick animation may still be in progress)
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @event flick
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @param e {EventFacade} The default event facade.
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * Override the contentBox sizing method, since the contentBox height
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * should not be that of the boundingBox.
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico * @method _uiSizeCB
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @protected
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico _uiSizeCB: function() {},
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * TranstionEnd event handler
7b1aa68aa70f0fd01248fda5441d4e1a5a103786JazzyNico * @method _transitionEnded
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * bindUI implementation
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * Hooks up events for the widget
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @method bindUI
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico bindUI: function() {
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico this.get(BOUNDING_BOX).on('gesturemovestart', Y.bind(this._onGestureMoveStart, this));
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico cb.on('transition:end', Y.bind(this._transitionEnded, this), false);
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico // TODO: Fires way to often when using non-native transitions, due to property change
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico cb.on('DOMSubtreeModified', Y.bind(this._uiDimensionsChange, this));
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico 'renderedChange': function() { Y.later(0, this, '_uiDimensionsChange'); }
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * syncUI implementation
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * Update the scroll position, based on the current value of scrollY
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @method bindUI
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico syncUI: function() {
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this.scrollTo(this.get(SCROLL_X), this.get(SCROLL_Y));
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * Scroll the element to a given y coordinate
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @method scrollTo
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @param x {Number} The x-position to scroll to
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * @param y {Number} The y-position to scroll to
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @param duration {Number} Duration, in ms, of the scroll animation (default is 0)
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @param easing {String} An easing equation if duration is set
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico xSet = (x !== null),
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico ySet = (y !== null),
c544ac2705cf516901c8455356d56b52c8615525mfloryan Y.log("Transition: duration, easing:" + transition.duration, transition.easing, "scrollview");
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico transition.transform = 'translate('+ xMove +'px,'+ yMove +'px)';
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * gesturemovestart event handler
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @method _onGestureMoveStart
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @param e {Event.Facade} The gesturemovestart event facade
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._moveEvt = bb.on('gesturemove', Y.bind(this._onGestureMove, this));
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._moveEndEvt = bb.on('gesturemoveend', Y.bind(this._onGestureMoveEnd, this));
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._moveStartY = e.clientY + this.get(SCROLL_Y);
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico this._moveStartX = e.clientX + this.get(SCROLL_X);
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._isDragging = false;
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._snapToEdge = false;
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * gesturemove event handler
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @method _onGestureMove
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @param e {Event.Facade} The gesturemove event facade
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico _onGestureMove: function(e) {
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico this.set(SCROLL_Y, -(e.clientY - this._moveStartY));
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this.set(SCROLL_X, -(e.clientX - this._moveStartX));
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * gestureend event handler
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * @method _onGestureMoveEnd
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @param e {Event.Facade} The gesturemoveend event facade
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico startPoint = this._scrollsVertical ? this._moveStartClientY : this._moveStartClientX,
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico endPoint = this._scrollsVertical ? this._moveEndClientY : this._moveEndClientX,
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._snapToEdge = false;
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._isDragging = false;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if(this._scrollsHorizontal && Math.abs(distance) > (this.get('width')/2)) {
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico if(this._scrollsVertical && Math.abs(distance) > (this.get('height')/2)) {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico // Check for minY
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico if(this._scrollsVertical && this.get(SCROLL_Y) < minY) {
c544ac2705cf516901c8455356d56b52c8615525mfloryan // Check for minX
c544ac2705cf516901c8455356d56b52c8615525mfloryan if(this._scrollsHorizontal && this.get(SCROLL_X) < minX) {
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico // Check for maxY
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico // Check for maxX
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico // Check for staleness
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * after listener for changes to the scrollY attr
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @method _afterScrollYChange
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @param e {Event.Facade} The event
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @protected
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico _afterScrollYChange : function(e) {
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * Update the UI when the scrollY attr changes
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @method _uiScrollY
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @param val {Number} The scrollY value
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico * @param duration {Number} The length (in ms) of the scroll animation
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @param easing {String} An easing equation, if duration is defined
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @protected
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico duration = duration || this._snapToEdge ? 400 : 0;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico easing = easing || this._snapToEdge ? ScrollView.SNAP_EASING : null;
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * after listener for changes to the scrollX attr
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @method _afterScrollXChange
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @param e {Event.Facade} The event
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @protected
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico _afterScrollXChange : function(e) {
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * Update the UI when the scrollX attr changes
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * @method _uiScrollX
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @param val {Number} The scrollX value
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @param duration {Number} The length (in ms) of the scroll animation
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @param easing {String} An easing equation, if duration is defined
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico * @protected
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico duration = duration || this._snapToEdge ? 400 : 0;
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico easing = easing || this._snapToEdge ? ScrollView.SNAP_EASING : null;
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * after listener for the height attribute
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @method _afterHeightChange
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @param e {Event.Facade} The event
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @protected
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * after listener for the width attribute
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @method _afterHeightChange
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @param e {Event.Facade} The event
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * @protected
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * This method gets invoked whenever the height or width attrs change,
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * allowing us to determine which scrolling axes need to be enabled.
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @method _uiDimensionsChange
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @protected
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico // Use bb instead of cb. cb doesn't gives us the right results
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico // in FF (due to overflow:hidden)
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * Execute a flick at the end of a scroll action
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @method _flick
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @param distance {Number} The distance (in px) the user scrolled before the flick
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * @param time {Number} The number of ms the scroll event lasted before the flick
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @protected
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico _flick: function(e) {
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * Execute a single frame in the flick animation
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @method _flickFrame
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @protected
c544ac2705cf516901c8455356d56b52c8615525mfloryan _flickFrame: function() {
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico newY = this.get(SCROLL_Y) - (this._currentVelocity * step);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico newX = this.get(SCROLL_X) - (this._currentVelocity * step);
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._currentVelocity = (this._currentVelocity*this.get('deceleration'));
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if(Math.abs(this._currentVelocity).toFixed(4) <= 0.015) {
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._flicking = false;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this._killTimer(!(this._exceededYBoundary || this._exceededXBoundary));
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._flickTimer = Y.later(step, this, '_flickFrame');
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * Stop the animation timer
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @method _killTimer
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @param fireEvent {Boolean} If true, fire the scrollEnd event
d048f1c15089c16b8ca1b264513a2f92ff86e703JazzyNico * @method _setScroll
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @param {Number} val
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @param {String} dim
d048f1c15089c16b8ca1b264513a2f92ff86e703JazzyNico maxScroll = (dim == DIM_X) ? this._maxScrollX : this._maxScrollY,
ATTRS: {
scrollY: {
scrollX: {
deceleration: {
bounce: {
flick: {
value: {