Пример #1
0
    scroll: function (scrollType, isScrollRight, event, triggerType) {
        if (Arrays.indexOf(scrollType, this._scrollTypes) < 0)
            throw "IllegalArgumentException: scrollType must be one of \"" 
                  + this._scrollTypes.join(", ") + "\".";

        if (typeof isScrollRight !== 'boolean')
            throw "IllegalArgumentException: isScrollRight must be a Boolean.";

        if (typeof event === 'undefined')
            throw "IllegalArgumentException: event must be provided.";

        if (Arrays.indexOf(triggerType, this._triggerTypes) < 0)
            throw "IllegalArgumentException: triggerType must be one of \"" 
                  + this._triggerTypes.join(", ") + "\".";
        
        if (triggerType !== 'mouse') {
            // Mouse is holding by the user, 
            // prevent other events from being triggered.
            if (this._triggerType === 'mouse')
                return;
            else 
                this._triggerType = triggerType;
        }

        var move,
            negSymbol = ( (isScrollRight === true) 
                         ? 1 
                         : -1                   );

        if (scrollType === 'page')
            move = Math.ceil(this._width * 0.8) * negSymbol;
        else if (scrollType === 'arrow')
            move = this._increment * negSymbol;

        // When the user is scrolling by page or arrow,
        // we make a change immediately, 
        // and then wait 750ms to see whether we continue 
        // the scrolling or not.
        this.position(this.position() + move);
        this._change();

        if (   scrollType === 'page'
            || scrollType === 'arrow' ) {
            this._isPaused = false;

            var fn = function () {
                this._isScrolling = true;
                this._scroll(move);
            };
            fn = Fns.inContext(this, fn);
            this._timerChangeBegins = setTimeout(fn, 750);
        }
    },
Пример #2
0
    _scroll: function (move) {
        var freq = 50,
            barPos;
        
        var fn = function () {

            if (this._isPaused === false) {
                if (!this._isScrolling) {
                    clearInterval(this._timerScrolling);
                    return;
                }

                // Clicks on dead-space.
                if (this._isPageRight !== null) {
                    barPos = this._bar.offset();
                    /*
                     * The scrollbar will keep on scrolling only when
                     * the mouse is still at the same side.
                     */
                    if (   (   this._pageXMoveStart < barPos.left 
                            && !this._isPageRight                 )
                        || (   this._pageXMoveStart > barPos.left + this._barLen 
                            && this._isPageRight                  )             ) {
                        this.position(this.position() + move);
                        this._change();
                    }
                }
                else {
                    this.position(this.position() + move);
                    this._change();
                }
            }
        };
        fn = Fns.inContext(this, fn);
        this._timerScrolling = setInterval(fn, freq);
    },