dragscroll icon indicating copy to clipboard operation
dragscroll copied to clipboard

Input element not working

Open claudchan opened this issue 9 years ago • 10 comments
trafficstars

Hi, Any way can exclude action elements such as input fields, buttons, etc...? Will be great if implement options or api to use.

claudchan avatar Apr 14 '16 06:04 claudchan

Hi,

I have made a little update to prevent click when user has drag content from a link, I think it could work with buttons too. I didn't have permissions to make a PR. Here is the new code. Feel free to update the lib if you think it's useful.

(function (root, factory) { if (typeof define === 'function' && define.amd) { define(['exports'], factory); } else if (typeof exports !== 'undefined') { factory(exports); } else { factory((root.dragscroll = {})); } }(this, function (exports) { var _window = window; var _document = document; var mousemove = 'mousemove'; var mouseup = 'mouseup'; var mousedown = 'mousedown'; var click = 'click'; var EventListener = 'EventListener'; var addEventListener = 'add'+EventListener; var removeEventListener = 'remove'+EventListener;

var dragged = [];
var reset = function(i, el) {
    for (i = 0; i < dragged.length;) {
        el = dragged[i++];
        el = el.container || el;
        el[removeEventListener](mousedown, el.md, 0);
        _window[removeEventListener](mouseup, el.mu, 0);
        _window[removeEventListener](mousemove, el.mm, 0);
        _window[removeEventListener](click, el.cl, 0);
    }

    // cloning into array since HTMLCollection is updated dynamically
    dragged = [].slice.call(_document.getElementsByClassName('dragscroll'));
    for (i = 0; i < dragged.length;) {
        (function(el, lastClientX, lastClientY, pushed, scroller, cont){
            (cont = el.container || el)[addEventListener](
                mousedown,
                cont.md = function(e) {
                    if (!el.hasAttribute('nochilddrag') ||
                        _document.elementFromPoint(
                            e.pageX, e.pageY
                        ) == cont
                    ) {
                        pushed = 1;
                        hasMove = false;
                        lastClientX = e.clientX;
                        lastClientY = e.clientY;

                        e.preventDefault();
                    }
                }, 0
            );

            _window[addEventListener](
                mouseup, cont.mu = function() {pushed = 0;}, 0
            );

            _window[addEventListener](
                mousemove,
                cont.mm = function(e) {
                    if (pushed) {
                        hasMove = true;
                         (scroller = el.scroller||el).scrollLeft -=
                             (- lastClientX + (lastClientX=e.clientX));
                         scroller.scrollTop -=
                             (- lastClientY + (lastClientY=e.clientY));
                    }
                }, 0
            );

            _window[addEventListener](
                click,
                cont.cl = function(e) {
                    if(hasMove) {
                        e.preventDefault();
                    }
                }, 0
            );
         })(dragged[i++]);
    }
}


if (_document.readyState == 'complete') {
    reset();
} else {
    _window[addEventListener]('load', reset, 0);
}

exports.reset = reset;

}));

jonathan-vallet avatar May 03 '16 12:05 jonathan-vallet

Doesn't work.

claudchan avatar May 09 '16 09:05 claudchan

I've got the same problem

graphiclaboratory avatar May 27 '16 09:05 graphiclaboratory

would it solve the problem, if you use the nochilddrag attribute? (see readme of dragscroll)

asvd avatar Jun 22 '16 15:06 asvd

nochilddrag it stop entire element. Not fit into my current problems. By default, the plugin should ignore those inputs, button, links, etc...

claudchan avatar Jun 26 '16 03:06 claudchan

Jquery DragOn did a very good job. But I tested there have mobile issues.

claudchan avatar Jun 26 '16 03:06 claudchan

Can anyone tell me how to fix input boxes?

Necko1996 avatar Dec 06 '16 17:12 Necko1996

Are we just going to remove 'e.preventDefault();' ?

eysmnje avatar Sep 11 '18 09:09 eysmnje

mousedown --> remove 'e.preventDefault()' mousemove --> add 'e.preventDefault()'

eysmnje avatar Sep 11 '18 10:09 eysmnje

You can find answer for this question here:

https://github.com/asvd/dragscroll/pull/34

evgeniy-vashchuk avatar Dec 21 '18 20:12 evgeniy-vashchuk