| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- AUI.add('aui-scroller', function(A) {
- var L = A.Lang,
- isNumber = L.isNumber,
- isString = L.isString,
-
- BOUNDING_BOX = 'boundingBox',
- CLIENT_WIDTH = 'clientWidth',
- CONTENT_BOX = 'contentBox',
- DURATION = 'duration',
- EDGE_PROXIMITY = 'edgeProximity',
-
- HEIGHT = 'Height',
- LEFT = 'Left',
- OFFSET = 'offset',
- SCROLL = 'scroll',
- TOP = 'Top',
- WIDTH = 'Width',
-
- HORIZONTAL = 'horizontal',
- OFFSET_HEIGHT = OFFSET + HEIGHT,
- OFFSET_LEFT = OFFSET + LEFT,
- OFFSET_TOP = OFFSET + TOP,
- OFFSET_WIDTH = OFFSET + WIDTH,
- ORIENTATION = 'orientation',
- PX = 'px',
- SCROLL_HEIGHT = SCROLL + HEIGHT,
- SCROLLER = 'scroller',
- SCROLLCONTENT = 'scrollcontent',
- UNDERLINE = '_',
- VERTICAL = 'vertical',
-
- getCN = A.getClassName,
-
- CSS_HORIZONTAL = getCN(SCROLLER, HORIZONTAL),
- CSS_ITEM = getCN(SCROLLER, 'item'),
- CSS_VERTICAL = getCN(SCROLLER, VERTICAL);
-
- var Scroller = A.Component.create (
- {
- NAME: SCROLLER,
-
- ATTRS: {
- duration: {
- setter: function(value) {
- return value * 1000;
- },
- validator: isNumber,
- value: 0.1
- },
-
- edgeProximity: {
- value: 0.1
- },
-
- itemSelector: {
- value: '>*'
- },
-
- orientation: {
- validator: function(val) {
- return isString(val) && (val === HORIZONTAL || val === VERTICAL);
- },
- value: HORIZONTAL
- }
- },
-
- UI_ATTRS: [ORIENTATION],
-
- prototype: {
- nodeSelection: null,
-
- initializer: function() {
- var instance = this;
-
- var boundingBox = instance.get(BOUNDING_BOX);
- var contentBox = instance.get(CONTENT_BOX);
-
- instance._boundingBox = boundingBox;
- instance._contentBox = contentBox;
-
- instance._duration = instance.get(DURATION);
- instance._edgeProximity = instance.get(EDGE_PROXIMITY);
- instance._orientation = instance.get(ORIENTATION);
-
- instance.boundingBoxXY = instance._boundingBox.getXY();
-
- instance._boundingBoxEl = boundingBox.getDOM();
- instance._contentBoxEl = contentBox.getDOM();
-
- instance._setCoords(instance._orientation == HORIZONTAL);
-
- instance._updateNodeSelection();
- },
-
- bindUI: function() {
- var instance = this;
-
- instance.publish(
- SCROLLCONTENT,
- {
- defaultFn: instance._defaultScrollFn
- }
- );
-
- var contentBox = instance._contentBox;
-
- instance.after(['durationChange', 'edgeProximityChange'], instance._setPrivateAttr);
-
- contentBox.on('mouseenter', A.rbind(instance._updateDimensions, instance));
-
- contentBox.on('mousemove', A.rbind(instance._onMouseMove, instance, instance._boundingBox, instance._contentBox, instance._orientation));
-
- instance._boundingBox.on('focus', instance._onItemFocus, instance);
-
- instance._createAnimation();
- },
-
- _adjustToEdge: function(value) {
- var instance = this;
-
- var edgeProximity = instance._edgeProximity;
-
- var adjusted = value;
-
- if (edgeProximity) {
- value = Math.max(value, edgeProximity);
- value = Math.min(value, 1 - edgeProximity);
-
- value = value - edgeProximity;
-
- adjusted = value / (1 - (edgeProximity * 2));
- }
-
- return adjusted;
- },
-
- _animate: function(event) {
- var instance = this;
-
- var fx = instance._fx;
-
- var boundingBoxEl = instance._boundingBoxEl;
- var orientation = instance._orientation;
-
- var scroll = SCROLL + instance._coordTL;
- var coordXY = instance._coordXY.toLowerCase();
-
- var from = boundingBoxEl[scroll] || 0;
- var to = event[coordXY];
-
- fx.from = from;
- fx.to = to;
-
- fx.start();
- },
-
- _constrain: function(value, min, max) {
- var instance = this;
-
- return Math.max(Math.min(value, max), min);
- },
-
- _createAnimation: function() {
- var instance = this;
-
- var boundingBoxEl = instance._boundingBoxEl;
-
- var from = boundingBoxEl[SCROLL + instance._coordTL] || 0;
- var to = from;
-
- instance._fx = new A.SimpleAnim(
- {
- duration: instance._duration,
- from: from,
- intervalRate: 1,
- to: to,
- onTween: function(value) {
- boundingBoxEl[SCROLL + instance._coordTL] = value;
- }
- }
- );
-
- instance._throttleAnimate = instance._animate;
- },
-
- _defaultScrollFn: function(event) {
- var instance = this;
-
- instance._throttleAnimate(event);
- },
-
- _getPositionData: function(absoluteX, absoluteY) {
- var instance = this;
-
- var boundingBoxXY = instance.boundingBoxXY;
-
- var relativeMouseX = absoluteX - boundingBoxXY[0];
- var relativeMouseY = absoluteY - boundingBoxXY[1];
-
- var scaledX = relativeMouseX * instance.ratioX;
- var scaledY = relativeMouseY * instance.ratioY;
-
- var relativeX = instance._constrain(relativeMouseX / instance.boundingBoxWidth, 0, 1);
- var relativeY = instance._constrain(relativeMouseY / instance.boundingBoxHeight, 0, 1);
-
- relativeX = instance._adjustToEdge(relativeX);
- relativeY = instance._adjustToEdge(relativeY);
-
- var adjustedX = (instance.deltaX * relativeX);
- var adjustedY = (instance.deltaY * relativeY);
-
- return {
- x: adjustedX,
- y: adjustedY,
- scaledX: scaledX,
- scaledY: scaledY,
- relativeX: relativeMouseX,
- relativeY: relativeMouseY
- };
- },
-
- _onItemFocus: function(event) {
- var instance = this;
-
- instance._updateDimensions();
-
- var xy = event.target.getXY();
-
- var data = instance._getPositionData.apply(instance, xy);
-
- instance.fire(SCROLLCONTENT, data);
-
- instance._updatePrevXY(data.relativeX, data.relativeY);
- },
-
- _onMouseMove: function(event, boundingBox, contentBox, orientation) {
- var instance = this;
-
- var data = instance._getPositionData(event.pageX, event.pageY);
-
- instance.fire(SCROLLCONTENT, data);
-
- instance._updatePrevXY(data.relativeX, data.relativeY);
- },
-
- _setCoords: function(horizontal) {
- var instance = this;
-
- var coordTL = TOP;
- var coordXY = 'Y';
-
- if (horizontal) {
- coordTL = LEFT;
- coordXY = 'X';
- }
-
- instance._coordTL = coordTL;
- instance._coordXY = coordXY;
- },
-
- _setPrivateAttr: function(event) {
- var instance = this;
-
- instance[UNDERLINE + event.attrName] = event.newVal;
- },
-
- _updateDimensions: function(event) {
- var instance = this;
-
- var boundingBox = instance._boundingBox;
- var contentBox = instance._contentBox;
-
- var boundingBoxOffsetHeight = boundingBox.get(OFFSET_HEIGHT);
- var boundingBoxOffsetWidth = boundingBox.get(OFFSET_WIDTH);
-
- var contentBoxClientWidth = contentBox.get(CLIENT_WIDTH);
- var contentBoxScrollHeight = contentBox.get(SCROLL_HEIGHT);
-
- var deltaX = contentBoxClientWidth - boundingBoxOffsetWidth;
- var deltaY = contentBoxScrollHeight - boundingBoxOffsetHeight;
-
- instance.boundingBoxXY = boundingBox.getXY();
-
- instance.ratioX = deltaX / boundingBoxOffsetWidth;
- instance.ratioY = deltaY / boundingBoxOffsetHeight;
-
- instance.deltaX = deltaX;
- instance.deltaY = deltaY;
-
- instance.boundingBoxHeight = boundingBoxOffsetHeight;
- instance.boundingBoxWidth = boundingBoxOffsetWidth;
-
- instance.contentBoxHeight = contentBoxScrollHeight;
- instance.contentBoxWidth = contentBoxClientWidth;
- },
-
- _updatePrevXY: function(x, y) {
- var instance = this;
-
- instance._prevX = x;
- instance._prevY = y;
- },
-
- _uiSetOrientation: function(val) {
- var instance = this;
-
- var boundingBox = instance._boundingBox;
-
- var horizontal = (val === HORIZONTAL);
-
- boundingBox.toggleClass(CSS_HORIZONTAL, horizontal);
- boundingBox.toggleClass(CSS_VERTICAL, !horizontal);
-
- instance._setCoords(horizontal);
-
- instance._orientation = val;
- },
-
- _updateNodeSelection: function() {
- var instance = this;
-
- var itemSelector = instance.get('itemSelector');
-
- instance.nodeSelection = instance._contentBox.all(itemSelector).addClass(CSS_ITEM);
- },
-
- _prevX: 0,
- _prevY: 0
- }
- }
- );
-
- A.Scroller = Scroller;
-
- }, '@VERSION@' ,{requires:['aui-base','aui-simple-anim'], skinnable:true});
|