/**
* The scrollview-base module provides a basic ScrollView Widget, without scrollbar indicators
*
* @module scrollview-base
*/
SCROLLVIEW = 'scrollview',
CLASS_NAMES = {
},
EV_SCROLL_END = 'scrollEnd',
EV_SCROLL_FLICK = 'flick',
DRAG = "drag",
MOUSEWHEEL_ENABLED = true,
UI = 'ui',
LEFT = "left",
TOP = "top",
PX = "px",
SCROLL_Y = "scrollY",
SCROLL_X = "scrollX",
BOUNCE = "bounce",
DISABLED = "disabled",
DIM_X = "x",
DIM_Y = "y",
BOUNDING_BOX = "boundingBox",
CONTENT_BOX = "contentBox",
EMPTY = "",
ZERO = "0s",
Transition = Y.Transition,
};
/**
* ScrollView provides a scrollable widget, supporting flick gestures, across both touch and mouse based devices.
*
* @class ScrollView
* @param config {Object} Object literal with initial attribute values
* @extends Widget
* @constructor
*/
function ScrollView() {
}
// Y.ScrollView prototype
/**
* Designated initializer
*
* @method initializer
*/
initializer: function() {
/**
* Notification event fired at the end of a scroll transition
*
* @event scrollEnd
* @param e {EventFacade} The default event facade.
*/
/**
* Notification event fired at the end of a flick gesture (the flick animation may still be in progress)
*
* @event flick
* @param e {EventFacade} The default event facade.
*/
var sv = this;
// Cache - they're write once, and not going to change
},
/**
* Override the contentBox sizing method, since the contentBox height
* should not be that of the boundingBox.
*
* @method _uiSizeCB
* @protected
*/
_uiSizeCB: function() {},
/**
* Content box transition callback
*
* @method _onTransEnd
* @param {Event.Facade} e The event facade
* @private
*/
_onTransEnd: function(e) {
this.fire(EV_SCROLL_END);
},
/**
* bindUI implementation
*
* Hooks up events for the widget
* @method bindUI
*/
bindUI: function() {
var sv = this;
// Note: You can find _bindMousewheel() inside syncUI(), becuase it depends on UI details
sv._bindAttrs();
// IE SELECT HACK. See if we can do this non-natively and in the gesture for a future release.
if (IE) {
}
},
/**
* @method _bindAttrs
* @private
*/
_bindAttrs : function() {
var sv = this,
this.after({
'scrollYChange' : scrollChangeHandler,
'scrollXChange' : scrollChangeHandler,
'heightChange' : dimChangeHandler,
'widthChange' : dimChangeHandler
});
// Helps avoid potential CSS race where in the styles from
// scrollview-list-skin.css are applied after syncUI() fires.
// Without a _uiDimensionChange() call, the scrollview only
// scrolls partially due to the fact that styles added in the CSS
// TODO: Remove?
if (!IE) {
this.after('renderedChange', function(e) {
//this._uiDimensionsChange();
});
}
},
/**
* Bind (or unbind) gesture move listeners required for drag support
*
* @method _bindDrag
* @param drag {boolean} If true, the method binds listener to enable drag (gesturemovestart). If false, the method unbinds gesturemove listeners for drag support.
* @private
*/
if (drag) {
} else {
}
},
/**
* Bind (or unbind) flick listeners.
*
* @method _bindFlick
* @param flick {Object|boolean} If truthy, the method binds listeners for flick support. If false, the method unbinds flick listeners.
* @private
*/
_bindFlick : function(flick) {
if (flick) {
} else {
}
},
/**
* Bind (or unbind) mousewheel listeners.
*
* @method _bindMousewheel
* @param mousewheel {Object|boolean} If truthy, the method binds listeners for mousewheel support. If false, the method unbinds mousewheel listeners.
* @private
*/
_bindMousewheel : function(mousewheel) {
// Only enable for vertical scrollviews
if (this._scrollsVertical) {
if (mousewheel) {
} else {
}
}
},
/**
* syncUI implementation.
*
*
* @method syncUI
*/
syncUI: function() {
this._uiDimensionsChange();
},
/**
* Scroll the element to a given xy 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
*/
// TODO: Figure out a better way to detect mousewheel events
if ( y < this._minScrollY) {
y = this._minScrollY;
}
else if ( y > this._maxScrollY) {
y = this._maxScrollY;
}
}
if (!this._cDisabled) {
xSet = (x !== null),
ySet = (y !== null),
callback = this._transEndCB;
if (xSet) {
}
if (ySet) {
}
if (NATIVE_TRANSITIONS) {
// ANDROID WORKAROUND - try and stop existing transition, before kicking off new one.
}
if (duration !== 0) {
transition = {
};
if (NATIVE_TRANSITIONS) {
} else {
}
if (!callback) {
}
} else {
if (NATIVE_TRANSITIONS) {
} else {
}
}
}
},
/**
* Utility method, to create the translate transform string with the
* x, y translation amounts provided.
*
* @method _transform
* @param {Number} x Number of pixels to translate along the x axis
* @param {Number} y Number of pixels to translate along the y axis
* @private
*/
_transform : function(x, y) {
// TODO: Would we be better off using a Matrix for this?
return (this._forceHWTransforms) ? 'translate('+ x +'px,'+ y +'px) translateZ(0px)' : 'translate('+ x +'px,'+ y +'px)';
},
/**
* Utility method, to move the given element to the given xy position
*
* @method _moveTo
* @param node {Node} The node to move
* @param x {Number} The x-position to move to
* @param y {Number} The y-position to move to
* @private
*/
if (NATIVE_TRANSITIONS) {
} else {
}
},
/**
* Flag driving whether or not we should try and force H/W acceleration when transforming. Currently enabled by default for Webkit.
* Used by the _transform method.
*
* @property _forceHWTransforms
* @type boolean
* @protected
*/
/**
* <p>Used to control whether or not ScrollView's internal
* gesturemovestart, gesturemove and gesturemoveend
* event listeners should preventDefault. The value is an
* object, with "start", "move" and "end" properties used to
* specify which events should preventDefault and which shouldn't:</p>
*
* <pre>
* {
* start : false,
* move : true,
* end : false
* }
* </pre>
*
* <p>The default values are set up in order to prevent panning,
* on touch devices, while allowing click listeners on elements inside
* the ScrollView to be notified as expected.</p>
*
* @property _prevent
* @type Object
* @protected
*/
_prevent : {
start : false,
move : true,
end : false
},
/**
* gesturemovestart event handler
*
* @method _onGestureMoveStart
* @param e {Event.Facade} The gesturemovestart event facade
* @private
*/
_onGestureMoveStart: function(e) {
var sv = this,
if (!sv._cDisabled) {
e.preventDefault();
}
sv._killTimer();
/**
* Internal state, defines whether or not the scrollview is currently being dragged
*
* @property _isDragging
* @type boolean
* @protected
*/
sv._isDragging = false;
/**
* Internal state, defines whether or not the scrollview is currently animating a flick
*
* @property _flicking
* @type boolean
* @protected
*/
/**
* Internal state, defines whether or not the scrollview needs to snap to a boundary edge
*
* @property _snapToEdge
* @type boolean
* @protected
*/
sv._snapToEdge = false;
}
},
/**
* gesturemove event handler
*
* @method _onGestureMove
* @param e {Event.Facade} The gesturemove event facade
* @private
*/
_onGestureMove: function(e) {
var sv = this;
e.preventDefault();
}
sv._isDragging = true;
if (sv._scrollsVertical) {
}
if(sv._scrollsHorizontal) {
}
},
/**
* gestureend event handler
*
* @method _onGestureMoveEnd
* @param e {Event.Facade} The gesturemoveend event facade
* @private
*/
_onGestureMoveEnd: function(e) {
e.preventDefault();
}
var sv = this, // kweight
/**
*
* @property _scrolledHalfway
* @type boolean
* @protected
*/
/**
* Contains the distance (postive or negative) in pixels by which the scrollview was last scrolled. This is useful when
* setting up click listeners on the scrollview content, which on mouse based devices are always fired, even after a
*
* <p>Touch based devices don't currently fire a click event, if the finger has been moved (beyond a threshold) so this check isn't required,
* if working in a purely touch based environment</p>
*
* @property lastScrolledAmt
* @type Number
* @public
*/
// Check for halfway
if((horiz && absDistance > bb.get('offsetWidth')/2) || (vert && absDistance > bb.get('offsetHeight')/2)) {
sv._scrolledHalfway = true;
/**
* Internal state, defines whether or not the scrollview has been scrolled in the forward (distance > 0), or backward (distance < 0) direction
*
* @property _scrolledForward
* @type boolean
* @protected
*/
}
if (vert) {
}
if (horiz) {
}
this._snapToEdge = true;
if (vert) {
}
if (horiz) {
}
}
if(sv._snapToEdge) {
return;
}
onGestureMoveEnd: true
});
return;
},
/**
* After listener for changes to the scrollX or scrollY attribute
*
* @method _afterScrollChange
* @param e {Event.Facade} The event facade
* @protected
*/
_afterScrollChange : function(e) {
} else {
}
}
},
/**
* After listener for changes to the flick attribute
*
* @method _afterFlickChange
* @param e {Event.Facade} The event facade
* @protected
*/
_afterFlickChange : function(e) {
this._bindFlick(e.newVal);
},
/**
* After listener for changes to the disabled attribute
*
* @method _afterDisabledChange
* @param e {Event.Facade} The event facade
* @protected
*/
_afterDisabledChange : function(e) {
// Cache for performance - we check during move
this._cDisabled = e.newVal;
},
/**
* After listener for changes to the drag attribute
*
* @method _afterDragChange
* @param e {Event.Facade} The event facade
* @protected
*/
_afterDragChange : function(e) {
},
/**
* Used to move the ScrollView content
*
* @method _uiScrollTo
* @param x {Number}
* @param y {Number}
* @param duration {Number}
* @param easing {String}
* @protected
*
*/
// TODO: This doesn't seem right. This is not UI logic.
},
/**
* After listener for the height or width attribute
*
* @method _afterDimChange
* @param e {Event.Facade} The event facade
* @protected
*/
_afterDimChange: function() {
this._uiDimensionsChange();
},
/**
* Utility method to obtain scrollWidth, scrollHeight,
* accounting for the impact of translate on scrollWidth, scrollHeight
* @method _getScrollDims
* @returns {Array} The offsetWidth, offsetHeight, scrollWidth and scrollHeight as an array: [offsetWidth, offsetHeight, scrollWidth, scrollHeight]
* @private
*/
_getScrollDims: function() {
var dims,
// Ideally using CSSMatrix - don't think we have it normalized yet though.
// origX = (new WebKitCSSMatrix(cb.getComputedStyle("transform"))).e;
// origY = (new WebKitCSSMatrix(cb.getComputedStyle("transform"))).f;
// TODO: Is this OK? Just in case it's called 'during' a transition.
if (NATIVE_TRANSITIONS) {
}
HWTransform = this._forceHWTransforms;
this._forceHWTransforms = false; // the z translation was causing issues with picking up accurate scrollWidths in Chrome/Mac.
dims = [bb.get("offsetWidth"), bb.get("offsetHeight"), bb.get('scrollWidth'), bb.get('scrollHeight')];
this._forceHWTransforms = HWTransform;
return dims;
},
/**
* This method gets invoked whenever the height or width attributes change,
* allowing us to determine which scrolling axes need to be enabled.
*
* @method _uiDimensionsChange
* @protected
*/
_uiDimensionsChange: function() {
var sv = this,
scrollDims = this._getScrollDims(),
sv._scrollsVertical = true;
} else {
sv._scrollsVertical = false;
delete sv._maxScrollY;
delete sv._minScrollY;
delete sv._scrollHeight;
}
sv._scrollsHorizontal = true;
} else {
sv._scrollsHorizontal = false;
delete sv._maxScrollX;
delete sv._minScrollX;
delete sv._scrollWidth;
}
/**
* Internal state, defines whether or not the scrollview can scroll vertically
*
* @property _scrollsVertical
* @type boolean
* @protected
*/
/**
* Internal state, defines the maximum amount that the scrollview can be scrolled along the Y axis
*
* @property _maxScrollY
* @type number
* @protected
*/
/**
* Internal state, defines the minimum amount that the scrollview can be scrolled along the Y axis
*
* @property _minScrollY
* @type number
* @protected
*/
/**
* Internal state, cached scrollHeight, for performance
*
* @property _scrollHeight
* @type number
* @protected
*/
/**
* Internal state, defines whether or not the scrollview can scroll horizontally
*
* @property _scrollsHorizontal
* @type boolean
* @protected
*/
/**
* Internal state, defines the maximum amount that the scrollview can be scrolled along the X axis
*
* @property _maxScrollX
* @type number
* @protected
*/
/**
* Internal state, defines the minimum amount that the scrollview can be scrolled along the X axis
*
* @property _minScrollX
* @type number
* @protected
*/
/**
* Internal state, cached scrollWidth, for performance
*
* @property _scrollWidth
* @type number
* @protected
*/
},
/**
* 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) {
sv = this;
if (!sv._cDisabled) {
/**
* Internal state, currently calculated velocity from the flick
*
* @property _currentVelocity
* @type number
* @protected
*/
sv._pastYEdge = false;
sv._pastXEdge = false;
sv._flickFrame();
}
},
_mousewheel: function(e) {
contentBox = this._cb,
// if we have scrollbars plugin, update & set the flash timer on the scrollbar
if (this.scrollbars) {
// TODO: The scrollbars should handle this themselves
this.scrollbars._update();
this.scrollbars.flash();
// or just this
// this.scrollbars._hostDimensionsChange();
}
// prevent browser default behavior on mouse scroll
e.preventDefault();
},
/**
* Execute a single frame in the flick animation
*
* @method _flickFrame
* @protected
*/
_flickFrame: function() {
var sv = this,
newY,
maxY,
minY,
newX,
maxX,
minX,
if (scrollsVertical) {
}
if (scrollsHorizontal) {
}
if(scrollsVertical) {
sv._snapToEdge = true;
sv._snapToEdge = true;
}
}
if(scrollsHorizontal) {
sv._snapToEdge = true;
sv._snapToEdge = true;
}
}
return;
}
if (scrollsVertical) {
sv._pastYEdge = true;
}
}
if (scrollsHorizontal) {
sv._pastXEdge = true;
}
}
if (!sv._flickTimer) {
}
},
/**
* Stop the animation timer
*
* @method _killTimer
* @param fireEvent {Boolean} If true, fire the scrollEnd event
* @protected
*/
_killTimer: function(fireEvent) {
var sv = this;
if(sv._flickTimer) {
sv._flickTimer = null;
}
if(fireEvent) {
}
},
/**
* The scrollX, scrollY setter implementation
*
* @method _setScroll
* @private
* @param {Number} val
* @param {String} dim
*
*/
if (this._cDisabled) {
} else {
if(!bouncing || !this._isDragging) {
}
}
}
return val;
},
/**
* Setter for the scrollX attribute
*
* @method _setScrollX
* @param val {Number} The new scrollX value
* @return {Number} The normalized value
* @protected
*/
_setScrollX: function(val) {
},
/**
* Setter for the scrollY ATTR
*
* @method _setScrollY
* @param val {Number} The new scrollY value
* @return {Number} The normalized value
* @protected
*/
_setScrollY: function(val) {
}
}, {
// Y.ScrollView static properties
/**
* The identity of the widget.
*
* @property NAME
* @type String
* @default 'scrollview'
* @readOnly
* @protected
* @static
*/
NAME: 'scrollview',
/**
* Static property used to define the default attribute configuration of
* the Widget.
*
* @property 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.93
*/
deceleration: {
value: 0.93
},
/**
* 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.1
*/
bounce: {
value: 0.1
},
/**
*
* @attribute flick
* @type Object
* @default Object with properties minDistance = 10, minVelocity = 0.3.
*/
flick: {
value: {
minDistance: 10,
minVelocity: 0.3
}
},
/**
* Enable/Disable dragging the ScrollView content (note: flick support is enabled/disabled separately)
* @attribute drag
* @type boolean
* @default true
*/
drag: {
value: true
}
},
/**
* 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
* @default "ui"
*/
/**
* The default bounce distance in pixels
*
* @property BOUNCE_RANGE
* @type Number
* @static
* @default 150
*/
BOUNCE_RANGE : 150,
/**
* The interval used when animating the flick
*
* @property FRAME_STEP
* @type Number
* @static
* @default 30
*/
FRAME_STEP : 30,
/**
* The default easing used when animating the flick
*
* @property EASING
* @type String
* @static
* @default 'cubic-bezier(0, 0.1, 0, 1.0)'
*/
EASING : 'cubic-bezier(0, 0.1, 0, 1.0)',
/**
* The default easing to use when animating the bounce snap back.
*
* @property SNAP_EASING
* @type String
* @static
* @default 'ease-out'
*/
SNAP_EASING : 'ease-out',
/**
* Object map of style property names used to set transition properties.
* Defaults to the vendor prefix established by the Transition module.
* The configured property names are `_TRANSITION.DURATION` (e.g. "WebkitTransitionDuration") and
* `_TRANSITION.PROPERTY (e.g. "WebkitTransitionProperty").
*
* @property _TRANSITION
* @private
*/
_TRANSITION : {
}
});
}, '@VERSION@' ,{requires:['widget', 'event-gestures', 'event-mousewheel', 'transition'], skinnable:true});