Skip to content

Commit

Permalink
readme updated; refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
asvd committed Feb 18, 2016
1 parent ca8bc1b commit 6a142a1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
6 changes: 3 additions & 3 deletions dragscroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') ||
Expand Down

0 comments on commit 6a142a1

Please sign in to comment.