%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/shaban/laviva/wp-content/themes/levelup/assets/js/app/tools/
Upload File :
Create Path :
Current File : /var/www/html/shaban/laviva/wp-content/themes/levelup/assets/js/app/tools/mouse.class.js

(function() {
    "use strict";

    APP.TOOLS.Mouse = APP.CORE.Event_Emitter.extend({
        staticInstantiate: function () {
            if (APP.TOOLS.Mouse.prototype.instance === null)
                return null;
            else
                return APP.TOOLS.Mouse.prototype.instance;
        },

        init: function (options) {
            this._super(options);

            this.ticker = new APP.TOOLS.Ticker();
            this.browser = new APP.TOOLS.Browser();
            this.shall_trigger = {};
            this.down = false;
            this.x = 0;
            this.y = 0;
            this.ratio = {};
            this.ratio.x = 0;
            this.ratio.y = 0;
            this.wheel = {};
            this.wheel.delta = 0;

            this.init_events();

            this.enable = true;

            APP.TOOLS.Mouse.prototype.instance = this;
        },

        init_events: function () {
            var that = this;

            this.ticker.on('tick', function () {
                that.frame();
            });

            window.onmousedown = function (e) {
                // e.preventDefault();
                that.down = true;

                that.trigger('down', [e.target]);
            };

            window.onmouseup = function (e) {
                // e.preventDefault();
                that.down = false;

                that.trigger('up', [e.target]);
            };

            window.onmousemove = function (e) {
                // e.preventDefault();
                that.x = e.clientX;
                that.y = e.clientY;

                that.ratio.x = that.x / that.browser.width;
                that.ratio.y = that.y / that.browser.height;

                that.trigger('move', [e.target]);
            };

            var mouse_wheel_handler = function (e) {

                that.wheel.delta = e.wheelDeltaY || e.wheelDelta || -e.detail;

                if (that.trigger('wheel', [that.wheel.delta]) === false) {
                    e.preventDefault();
                    return false;
                }
            };


            that.newActionTime = Date.now();
            that.lastDeltaY = 0;
            that.lastDeltasY = [];
            that.lastDirection = 0;

            that.mouseWheelSpeed = 20;
            that.invertWheelDirection = -1;
            that.currentPage = {};
            that.enabled = true;

            var mouse_wheel_handler_new = function (e) {
                if (!that.enabled) {
                    that.lastDirection = e.deltaY < 0 ? -1 : 1;
                    that.lastDeltaY = e.deltaY;
                    that.lastDeltasY.push(e.deltaY);
                    if (that.lastDeltasY.length>4) that.lastDeltasY.shift();
                }

                e.preventDefault();

                var wheelDeltaX, wheelDeltaY,
                    newX, newY,
                    that1 = this;

                if (typeof that.isStepScrolling == 'undefined') that.isStepScrolling = (e.deltaFactor && e.deltaFactor > that.mouseWheelSpeed);

                if ( 'deltaX' in e ) {
                    if (that.isStepScrolling) {
                        wheelDeltaX = -e.deltaX * e.deltaFactor;
                        wheelDeltaY = -e.deltaY * e.deltaFactor;
                    } else if (e.deltaMode === 1) {
                        wheelDeltaX = -e.deltaX * that.mouseWheelSpeed;
                        wheelDeltaY = -e.deltaY * that.mouseWheelSpeed;
                    } else {
                        wheelDeltaX = -e.deltaX;
                        wheelDeltaY = -e.deltaY;
                    }
                } else if ( 'wheelDeltaX' in e ) {
                    wheelDeltaX = e.wheelDeltaX / 120 * that.mouseWheelSpeed;
                    wheelDeltaY = e.wheelDeltaY / 120 * that.mouseWheelSpeed;
                } else if ( 'wheelDelta' in e ) {
                    wheelDeltaX = wheelDeltaY = e.wheelDelta / 120 * that.mouseWheelSpeed;
                } else if ( 'detail' in e ) {
                    wheelDeltaX = wheelDeltaY = -e.detail / 3 * that.mouseWheelSpeed;
                } else {
                    return;
                }

                that.directionY = (-wheelDeltaY)>0 ? 1 : -1;
                wheelDeltaY *= that.invertWheelDirection;
                wheelDeltaX = 0;

                newX = that.x + wheelDeltaX;
                newY = that.y + wheelDeltaY;

                that.lastDeltasY.push(wheelDeltaY);
                if (that.lastDeltasY.length>4) that.lastDeltasY.shift();

                var isLarger = true;
                for (var i=1; i<that.lastDeltasY.length; i++) {
                    if (Math.abs(that.lastDeltasY[i-1]) >= Math.abs(that.lastDeltasY[i])) {
                        isLarger = false;
                        break;
                    }
                }

                var now = Date.now(),
                    isNewAction = ((Math.abs(wheelDeltaY)>=5) && (isLarger || that.isStepScrolling) && (now - that.newActionTime > (that.isStepScrolling ? 350 : 400) )),
                    isNewDirection = (e.deltaY < 0 ? -1 : 1) != that.lastDirection;

                if (isNewAction && that.isSnapped) that.isSnapped = false;
                if (isNewAction) { // || isNewDirection
                    that.newActionTime = now;
                    if ( wheelDeltaY > 0 ) {
                        newY = Math.max(newY-1, 0);
                        that.isSnapped = true;
                    } else if ( wheelDeltaY < 0 ) {
                        newY++;
                        that.isSnapped = true;
                    }

                    if (that.trigger('wheel', [wheelDeltaY]) === false) {
                        e.preventDefault();
                        return false;
                    }
                }

                that.lastDirection = wheelDeltaY < 0 ? -1 : 1;
                that.lastDeltaY = wheelDeltaY;

                return;

            };

            $(document).on('mousewheel', function(e){
                mouse_wheel_handler_new(e);
            });

        },

        frame: function () {
            var keys = Object.keys(this.shall_trigger);
            for (var i = 0; i < keys.length; i++)
                this.trigger(keys[i], [this.shall_trigger[keys[i]]]);

            if (keys.length)
                this.shall_trigger = {};
        }
    });
})();

Zerion Mini Shell 1.0