scrollview-base-debug.js revision 81779a842aaa6d4807c29c98ccbcb6d5e5116683
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNicoYUI.add('scrollview-base', function(Y) {
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico/**
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * The scrollview-base module provides a basic ScrollView Widget, without scrollbar indicators
d048f1c15089c16b8ca1b264513a2f92ff86e703JazzyNico *
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @module scrollview-base
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico */
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNicovar getClassName = Y.ClassNameManager.getClassName,
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico SCROLLVIEW = 'scrollview',
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico CLASS_NAMES = {
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico vertical: getClassName(SCROLLVIEW, 'vert'),
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico horizontal: getClassName(SCROLLVIEW, 'horiz')
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico },
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico EV_SCROLL_END = 'scrollEnd',
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico EV_SCROLL_FLICK = 'flick',
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico FLICK = EV_SCROLL_FLICK,
d048f1c15089c16b8ca1b264513a2f92ff86e703JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico UI = 'ui',
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico SCROLL_Y = "scrollY",
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico SCROLL_X = "scrollX",
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico BOUNCE = "bounce",
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico DIM_X = "x",
d048f1c15089c16b8ca1b264513a2f92ff86e703JazzyNico DIM_Y = "y",
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico BOUNDING_BOX = "boundingBox",
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico CONTENT_BOX = "contentBox",
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico NATIVE_TRANSITIONS = Y.Transition.useNative;
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico
037bf91e68f10e796fecad5054b332b003c3a562JazzyNicoY.Node.DOM_EVENTS.DOMSubtreeModified = true;
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico/**
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * ScrollView provides a srollable widget, supporting flick gestures, across both touch and mouse based devices.
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico *
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * @class ScrollView
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * @namespace
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * @param config {Object} Object literal with initial attribute values
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @extends Widget
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * @constructor
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico */
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNicofunction ScrollView() {
c544ac2705cf516901c8455356d56b52c8615525mfloryan ScrollView.superclass.constructor.apply(this, arguments);
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico}
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNicoY.ScrollView = Y.extend(ScrollView, Y.Widget, {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico // Y.ScrollView prototype
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico /**
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * Designated initializer
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico *
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @method initializer
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico */
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico initializer: function() {
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico this._createEvents();
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico },
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico /**
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * Publishes events which occur during the scroll lifecycle
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico *
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * @method _createEvents
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @private
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico */
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico _createEvents: function() {
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico /**
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * Notification event fired at the end of a scroll transition
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico *
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * @event scrollEnd
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @param e {EventFacade} The default event facade.
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico */
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this.publish(EV_SCROLL_END);
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico /**
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * Notification event fired at the end of a flick gesture (the flick animation may still be in progress)
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico *
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @event flick
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @param e {EventFacade} The default event facade.
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico */
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico this.publish(EV_SCROLL_FLICK);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico },
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico /**
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * Override the contentBox sizing method, since the contentBox height
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * should not be that of the boundingBox.
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico *
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico * @method _uiSizeCB
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @protected
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico */
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico _uiSizeCB: function() {},
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico /**
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * TranstionEnd event handler
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico *
7b1aa68aa70f0fd01248fda5441d4e1a5a103786JazzyNico * @method _transitionEnded
7b1aa68aa70f0fd01248fda5441d4e1a5a103786JazzyNico * @private
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico */
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico _transitionEnded: function() {
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico this.fire(EV_SCROLL_END);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico },
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico /**
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * bindUI implementation
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico *
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * Hooks up events for the widget
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @method bindUI
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico */
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico bindUI: function() {
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico var cb = this.get(CONTENT_BOX),
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico flick = this.get(FLICK);
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico this.get(BOUNDING_BOX).on('gesturemovestart', Y.bind(this._onGestureMoveStart, this));
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico cb.on('transition:end', Y.bind(this._transitionEnded, this), false);
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico // TODO: Fires way to often when using non-native transitions, due to property change
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico if (NATIVE_TRANSITIONS) {
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico cb.on('DOMSubtreeModified', Y.bind(this._uiDimensionsChange, this));
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if (flick) {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico cb.on("flick", Y.bind(this._flick, this), flick);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this.after({
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico 'scrollYChange' : this._afterScrollYChange,
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico 'scrollXChange' : this._afterScrollXChange,
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico 'heightChange' : this._afterHeightChange,
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico 'widthChange' : this._afterWidthChange,
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico 'renderedChange': function() { Y.later(0, this, '_uiDimensionsChange'); }
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico });
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico },
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico /**
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * syncUI implementation
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico *
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * Update the scroll position, based on the current value of scrollY
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @method bindUI
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico */
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico syncUI: function() {
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this.scrollTo(this.get(SCROLL_X), this.get(SCROLL_Y));
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico },
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico /**
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * Scroll the element to a given y coordinate
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico *
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
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico */
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico scrollTo: function(x, y, duration, easing) {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico var cb = this.get(CONTENT_BOX),
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico xSet = (x !== null),
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico ySet = (y !== null),
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico xMove = (xSet) ? x * -1 : 0,
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico yMove = (ySet) ? y * -1 : 0,
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico transition;
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico duration = duration || 0;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico easing = easing || ScrollView.EASING;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico if (xSet) {
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this.set(SCROLL_X, x, { src: UI });
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico }
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico if (ySet) {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this.set(SCROLL_Y, y, { src: UI });
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico transition = {
c544ac2705cf516901c8455356d56b52c8615525mfloryan easing : easing,
c544ac2705cf516901c8455356d56b52c8615525mfloryan duration : duration/1000
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico };
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
c544ac2705cf516901c8455356d56b52c8615525mfloryan Y.log("Transition: duration, easing:" + transition.duration, transition.easing, "scrollview");
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if (NATIVE_TRANSITIONS) {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico transition.transform = 'translate('+ xMove +'px,'+ yMove +'px)';
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico } else {
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico transition.left = xMove + "px";
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico transition.top = yMove + "px";
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico }
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico cb.transition(transition);
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico },
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico /**
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * gesturemovestart event handler
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico *
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @method _onGestureMoveStart
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @param e {Event.Facade} The gesturemovestart event facade
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @private
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico */
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico _onGestureMoveStart: function(e) {
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico e.preventDefault();
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._killTimer();
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico var bb = this.get(BOUNDING_BOX);
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._moveEvt = bb.on('gesturemove', Y.bind(this._onGestureMove, this));
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._moveEndEvt = bb.on('gesturemoveend', Y.bind(this._onGestureMoveEnd, this));
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._moveStartY = e.clientY + this.get(SCROLL_Y);
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico this._moveStartX = e.clientX + this.get(SCROLL_X);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._moveStartTime = (new Date()).getTime();
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this._moveStartClientY = e.clientY;
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._moveStartClientX = e.clientX;
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._isDragging = false;
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._snapToEdge = false;
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico },
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico /**
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * gesturemove event handler
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico *
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @method _onGestureMove
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @param e {Event.Facade} The gesturemove event facade
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @private
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico */
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico _onGestureMove: function(e) {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico e.preventDefault();
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this._isDragging = true;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this._moveEndClientY = e.clientY;
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._moveEndClientX = e.clientX;
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._lastMoved = (new Date()).getTime();
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico if(this._scrollsVertical) {
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico this.set(SCROLL_Y, -(e.clientY - this._moveStartY));
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if(this._scrollsHorizontal) {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this.set(SCROLL_X, -(e.clientX - this._moveStartX));
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico },
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico /**
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * gestureend event handler
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico *
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * @method _onGestureMoveEnd
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @param e {Event.Facade} The gesturemoveend event facade
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @private
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico */
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico _onGestureMoveEnd: function(e) {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico e.preventDefault();
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico var minY = this._minScrollY,
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico maxY = this._maxScrollY,
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico minX = this._minScrollX,
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico maxX = this._maxScrollX,
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico startPoint = this._scrollsVertical ? this._moveStartClientY : this._moveStartClientX,
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico endPoint = this._scrollsVertical ? this._moveEndClientY : this._moveEndClientX,
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico distance = startPoint - endPoint;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._moveEvt.detach();
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this._moveEndEvt.detach();
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this._scrolledHalfway = false;
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._snapToEdge = false;
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._isDragging = false;
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if(this._scrollsHorizontal && Math.abs(distance) > (this.get('width')/2)) {
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._scrolledHalfway = true;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this._scrolledForward = distance > 0;
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico }
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico if(this._scrollsVertical && Math.abs(distance) > (this.get('height')/2)) {
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._scrolledHalfway = true;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this._scrolledForward = distance > 0;
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico }
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico // Check for minY
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico if(this._scrollsVertical && this.get(SCROLL_Y) < minY) {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this._snapToEdge = true;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this.set(SCROLL_Y, minY);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico
c544ac2705cf516901c8455356d56b52c8615525mfloryan // Check for minX
c544ac2705cf516901c8455356d56b52c8615525mfloryan if(this._scrollsHorizontal && this.get(SCROLL_X) < minX) {
c544ac2705cf516901c8455356d56b52c8615525mfloryan this._snapToEdge = true;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this.set(SCROLL_X, minX);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico // Check for maxY
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico if(this.get(SCROLL_Y) > maxY) {
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico this._snapToEdge = true;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this.set(SCROLL_Y, maxY);
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico }
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico // Check for maxX
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if(this.get(SCROLL_X) > maxX) {
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._snapToEdge = true;
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this.set(SCROLL_X, maxX);
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico }
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if(this._snapToEdge) {
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico return;
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico }
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico // Check for staleness
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if(+(new Date()) - this._moveStartTime > 100) {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this.fire(EV_SCROLL_END, {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico staleScroll: true
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico });
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico return;
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico }
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico },
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico /**
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * after listener for changes to the scrollY attr
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico *
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @method _afterScrollYChange
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @param e {Event.Facade} The event
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @protected
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico */
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico _afterScrollYChange : function(e) {
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico if(e.src !== UI) {
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._uiScrollY(e.newVal, e.duration, e.easing);
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico }
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico },
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico /**
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * Update the UI when the scrollY attr changes
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico *
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
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico */
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico _uiScrollY : function(val, duration, easing) {
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico duration = duration || this._snapToEdge ? 400 : 0;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico easing = easing || this._snapToEdge ? ScrollView.SNAP_EASING : null;
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this.scrollTo(null, val, duration, easing);
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico },
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico /**
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * after listener for changes to the scrollX attr
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico *
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @method _afterScrollXChange
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @param e {Event.Facade} The event
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @protected
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico */
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico _afterScrollXChange : function(e) {
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico if(e.src !== UI) {
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._uiScrollX(e.newVal, e.duration, e.easing);
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico }
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico },
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico /**
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * Update the UI when the scrollX attr changes
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico *
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
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico */
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico _uiScrollX : function(val, duration, easing) {
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico duration = duration || this._snapToEdge ? 400 : 0;
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico easing = easing || this._snapToEdge ? ScrollView.SNAP_EASING : null;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this.scrollTo(val, null, duration, easing);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico },
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico /**
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * after listener for the height attribute
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico *
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @method _afterHeightChange
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @param e {Event.Facade} The event
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @protected
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico */
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico _afterHeightChange: function() {
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._uiDimensionsChange();
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico },
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico /**
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * after listener for the width attribute
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico *
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @method _afterHeightChange
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @param e {Event.Facade} The event
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * @protected
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico */
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico _afterWidthChange: function() {
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico this._uiDimensionsChange();
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico },
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico /**
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * This method gets invoked whenever the height or width attrs change,
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * allowing us to determine which scrolling axes need to be enabled.
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico *
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @method _uiDimensionsChange
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @protected
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico */
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico _uiDimensionsChange: function() {
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico var bb = this.get(BOUNDING_BOX),
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico height = this.get('height'),
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico width = this.get('width'),
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico // Use bb instead of cb. cb doesn't gives us the right results
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico // in FF (due to overflow:hidden)
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico scrollHeight = bb.get('scrollHeight'),
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico scrollWidth = bb.get('scrollWidth');
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico if(height && scrollHeight > height) {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this._scrollsVertical = true;
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._maxScrollY = scrollHeight - height;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this._minScrollY = 0;
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico this._scrollHeight = scrollHeight;
c544ac2705cf516901c8455356d56b52c8615525mfloryan bb.addClass(ScrollView.CLASS_NAMES.vertical);
c544ac2705cf516901c8455356d56b52c8615525mfloryan }
c544ac2705cf516901c8455356d56b52c8615525mfloryan
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico if(width && scrollWidth > width) {
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico this._scrollsHorizontal = true;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this._maxScrollX = scrollWidth - width;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this._minScrollX = 0;
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._scrollWidth = scrollWidth;
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico bb.addClass(ScrollView.CLASS_NAMES.horizontal);
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico }
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico },
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico /**
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * Execute a flick at the end of a scroll action
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico *
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
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico */
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico _flick: function(e) {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico var flick = e.flick;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._currentVelocity = flick.velocity;
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico this._flicking = true;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this._flickFrame();
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this.fire(EV_SCROLL_FLICK);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico },
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico /**
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * Execute a single frame in the flick animation
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico *
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @method _flickFrame
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @protected
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico */
c544ac2705cf516901c8455356d56b52c8615525mfloryan _flickFrame: function() {
c544ac2705cf516901c8455356d56b52c8615525mfloryan var newY,
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico maxY,
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico minY,
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico newX,
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico maxX,
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico minX,
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico scrollsVertical = this._scrollsVertical,
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico scrollsHorizontal = this._scrollsHorizontal,
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico step = ScrollView.FRAME_STEP;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico if(scrollsVertical) {
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico maxY = this._maxScrollY;
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico minY = this._minScrollY;
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico newY = this.get(SCROLL_Y) - (this._currentVelocity * step);
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico }
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico if(scrollsHorizontal) {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico maxX = this._maxScrollX;
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico minX = this._minScrollX;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico newX = this.get(SCROLL_X) - (this._currentVelocity * step);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._currentVelocity = (this._currentVelocity*this.get('deceleration'));
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if(Math.abs(this._currentVelocity).toFixed(4) <= 0.015) {
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._flicking = false;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this._killTimer(!(this._exceededYBoundary || this._exceededXBoundary));
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if(scrollsVertical) {
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico if(newY < minY) {
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._snapToEdge = true;
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this.set(SCROLL_Y, minY);
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico } else if(newY > maxY) {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this._snapToEdge = true;
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this.set(SCROLL_Y, maxY);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico if(scrollsHorizontal) {
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico if(newX < minX) {
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico this._snapToEdge = true;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this.set(SCROLL_X, minX);
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico } else if(newX > maxX) {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this._snapToEdge = true;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this.set(SCROLL_X, maxX);
c544ac2705cf516901c8455356d56b52c8615525mfloryan }
c544ac2705cf516901c8455356d56b52c8615525mfloryan }
c544ac2705cf516901c8455356d56b52c8615525mfloryan
c544ac2705cf516901c8455356d56b52c8615525mfloryan return;
c544ac2705cf516901c8455356d56b52c8615525mfloryan }
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if(scrollsVertical) {
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico if (newY < minY || newY > maxY) {
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico this._exceededYBoundary = true;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this._currentVelocity *= this.get(BOUNCE);
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico }
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this.set(SCROLL_Y, newY);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico if(scrollsHorizontal) {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if (newX < minX || newX > maxX) {
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._exceededXBoundary = true;
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico this._currentVelocity *= this.get(BOUNCE);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this.set(SCROLL_X, newX);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico this._flickTimer = Y.later(step, this, '_flickFrame');
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico },
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico /**
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico * Stop the animation timer
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico *
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico * @method _killTimer
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @param fireEvent {Boolean} If true, fire the scrollEnd event
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico * @private
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico */
03a66cd4de660bda047af143016e23dbcbbc9b1aJazzyNico _killTimer: function(fireEvent) {
d048f1c15089c16b8ca1b264513a2f92ff86e703JazzyNico if(this._flickTimer) {
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico this._flickTimer.cancel();
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico }
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico if(fireEvent) {
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico this.fire(EV_SCROLL_END);
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico }
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico },
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico /**
d048f1c15089c16b8ca1b264513a2f92ff86e703JazzyNico * @method _setScroll
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @private
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @param {Number} val
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @param {String} dim
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico */
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico _setScroll : function(val, dim) {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico var bouncing = this.get(BOUNCE),
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico range = ScrollView.BOUNCE_RANGE,
d048f1c15089c16b8ca1b264513a2f92ff86e703JazzyNico maxScroll = (dim == DIM_X) ? this._maxScrollX : this._maxScrollY,
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico min = bouncing ? -range : 0,
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico max = bouncing ? maxScroll + range : maxScroll;
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico if(!bouncing || !this._isDragging) {
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico if(val < min) {
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico val = min;
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico } else if(val > max) {
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico val = max;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico }
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico return val;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico },
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico /**
* Setter for the scrollX ATTR
*
* @method _setScrollX
* @param val {Number} The new scrollX value
* @protected
*/
_setScrollX: function(val) {
return this._setScroll(val, DIM_X);
},
/**
* Setter for the scrollY ATTR
*
* @method _setScrollY
* @param val {Number} The new scrollY value
* @protected
*/
_setScrollY: function(val) {
return this._setScroll(val, DIM_Y);
}
}, {
// 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.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
},
/**
* The minimum distance and/or velocity which define a flick
*
* @attribute flick
* @type Object
* @default Object with properties minDistance = 10, minVelocity = 0.3.
*/
flick: {
value: {
minDistance: 10,
minVelocity: 0.3
}
}
},
/**
* List of class names used in the scrollview's DOM
*
* @property ScrollView.CLASS_NAMES
* @type Object
* @static
*/
CLASS_NAMES: CLASS_NAMES,
/**
* Flag used to source property changes initiated from the DOM
*
* @property ScrollView.UI_SRC
* @type String
* @static
* @default "ui"
*/
UI_SRC: UI,
/**
* The default bounce distance in pixels
*
* @property ScrollView.BOUNCE_RANGE
* @type Number
* @static
* @default 150
*/
BOUNCE_RANGE : 150,
/**
* The step amount used when animating the flick
*
* @property ScrollView.FRAME_STEP
* @type Number
* @static
* @default 30
*/
FRAME_STEP : 30,
/**
* The default easing used when animating the flick
*
* @property ScrollView.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 animatiing the bounce snap back.
*
* @property ScrollView.SNAP_EASING
* @type String
* @static
* @default 'ease-out'
*/
SNAP_EASING : 'ease-out'
});
}, '@VERSION@' ,{skinnable:true, requires:['widget', 'event-gestures', 'transition']});