From 6a142a1f91da6550e42a02484af308ce0229fc5c Mon Sep 17 00:00:00 2001 From: Dmitry Prokashev Date: Fri, 19 Feb 2016 00:14:23 +0100 Subject: [PATCH] readme updated; refactoring --- README.md | 11 +++++++++-- dragscroll.js | 6 +++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4558a2d..a7d0580 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ dragscroll ========== -Dragscroll is a micro JavaScript library (734 bytes minified) which +Dragscroll is a micro JavaScript library (838 bytes minified) which enables scrolling via holding the mouse button ("drag and drop" or "click and hold" style, [online demo](http://asvd.github.io/dragscroll/)). It has no dependencies and @@ -12,7 +12,7 @@ is written in vanilla JavaScript (which means it works anywhere). Download the and unpack -[distribution](https://github.com/asvd/dragscroll/releases/download/v0.0.5/dragscroll-0.0.5.tar.gz), +[distribution](https://github.com/asvd/dragscroll/releases/download/v0.0.6/dragscroll-0.0.6.tar.gz), or install it using [Bower](http://bower.io/): ```sh @@ -43,6 +43,13 @@ the users (or even `cursor: grab;` in case the content is not a text). If you add or remove the `dragscroll` class dynamically, invoke `dragscroll.reset()` to update the listeners. +You can also add the `nochilddrag` attribute to a scrollable element, +which will only enable drag-scrolling for an element itself, but not +for its subchildren. This can be usefull, if you want to enable the +scrolling the area by dragging its empty space, but keep the +opportunity to select the text (see +[example](http://asvd.github.io/jailed/demos/web/process/)). + - Follow me on twitter: https://twitter.com/asvd0 diff --git a/dragscroll.js b/dragscroll.js index 1144505..b71f732 100644 --- a/dragscroll.js +++ b/dragscroll.js @@ -24,22 +24,22 @@ var EventListener = 'EventListener'; var addEventListener = 'add'+EventListener; var removeEventListener = 'remove'+EventListener; - var container = 'container'; var dragged = []; var reset = function(i, el) { for (i = 0; i < dragged.length;) { el = dragged[i++]; - el = el[container] || el; + el = el.container || el; el[removeEventListener](mousedown, el.md, 0); _window[removeEventListener](mouseup, el.mu, 0); _window[removeEventListener](mousemove, el.mm, 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]( + (cont = el.container || el)[addEventListener]( mousedown, cont.md = function(e) { if (!el.hasAttribute('nochilddrag') ||