Перетащите с mootools на мобильный - PullRequest
8 голосов
/ 28 сентября 2011

Есть ли способ заставить работать класс mootools "Drag" на сафари мобиле? Пожалуйста, не связывайте меня с другими фреймворками.

Ответы [ 3 ]

10 голосов
/ 21 октября 2011

Это было моё решение сделать сенсорные события поддержки Mootools Drag. Этот метод не требовал от меня редактирования файла mootools more, так как я использовал Class.refactor (это тестируется только с Mootools v.1.3.1) - он также не нарушает обычные события щелчка

Class.refactor(Drag,
    {
        attach: function(){
            this.handles.addEvent('touchstart', this.bound.start);
            return this.previous.apply(this, arguments);
        },

        detach: function(){
            this.handles.removeEvent('touchstart', this.bound.start);
            return this.previous.apply(this, arguments);
        },

        start: function(event){
            document.body.addEvents({
                touchmove: this.bound.check,
                touchend: this.bound.cancel
            });
            this.previous.apply(this, arguments);
        },

        check: function(event){
            if (this.options.preventDefault) event.preventDefault();
            var distance = Math.round(Math.sqrt(Math.pow(event.page.x - this.mouse.start.x, 2) + Math.pow(event.page.y - this.mouse.start.y, 2)));
            if (distance > this.options.snap){
                this.cancel();
                this.document.addEvents({
                    mousemove: this.bound.drag,
                    mouseup: this.bound.stop
                });
                document.body.addEvents({
                    touchmove: this.bound.drag,
                    touchend: this.bound.stop
                });
                this.fireEvent('start', [this.element, event]).fireEvent('snap', this.element);
            }
        },

        cancel: function(event){
            document.body.removeEvents({
                touchmove: this.bound.check,
                touchend: this.bound.cancel
            });
            return this.previous.apply(this, arguments);
        },

        stop: function(event){
            document.body.removeEvents({
                touchmove: this.bound.drag,
                touchend: this.bound.stop
            });
            return this.previous.apply(this, arguments);
        }
    });
2 голосов
/ 02 октября 2011

Я исправил это сам. Это так же просто, как привязать события мыши к событиям касания.

Таким образом, решение заключается в поиске и замене:

mousedown -> touchstart
mouseup -> touchend
mousemove -> touchmove
0 голосов
/ 29 сентября 2011

Не могли бы вы попробовать https://github.com/kamicane/mootools-touch?

...