angular-drag-scroll
Version:
Lightweight drag to scroll directive for AngularJS
1 lines • 1.64 kB
JavaScript
!function(){"use strict";function e(e,t,n){var o={scope:{dragScroll:"="},restrict:"A",link:function(o,l,r,a){function c(){angular.element(t).on("mouseup",s),angular.element(t).on("mousemove",g)}function i(){angular.element(t).off("mouseup",s),angular.element(t).off("mousemove",g)}function u(e){if(o.dragScroll){for(var t=0;t<E.length;t++)if(angular.element(e.target).hasClass(E[t]))return!1;o.$apply(function(){R(o)}),c(),x=!0,v=p=e.clientX,y=S=e.clientY,d(),e.preventDefault(),e.stopPropagation()}}function s(e){if(o.dragScroll){var t="drag-scroll-text"in e.target.attributes,n=e.clientX>=p-$&&e.clientX<=p+$,l=e.clientY>=S-$&&e.clientY<=S+$;x=!1,t&&n&&l&&m(e.target),o.$apply(function(){w(o)}),i()}}function g(e){o.dragScroll&&(x&&(D&&"x"!==D||(l[0].scrollLeft-=-v+(v=e.clientX)),D&&"y"!==D||(l[0].scrollTop-=-y+(y=e.clientY))),e.preventDefault())}function f(){l.off("mousedown",u),angular.element(t).off("mouseup",s),angular.element(t).off("mousemove",g)}function m(e){var n;t.document.selection?(n=t.document.body.createTextRange(),n.moveToElementText(e),n.select()):t.getSelection&&(n=t.document.createRange(),n.selectNode(e),t.getSelection().addRange(n))}function d(){t.getSelection?t.getSelection().empty?t.getSelection().empty():t.getSelection().removeAllRanges&&t.getSelection().removeAllRanges():e.selection&&e.selection.empty()}var p,S,v,y,$=5,x=!1,R=n(r.onDragStart),w=n(r.onDragEnd),D=r.axis||!1,E=r.dragScrollExcludedClasses?r.dragScrollExcludedClasses.split(","):[];l.on("mousedown",u),o.$on("$destroy",f)}};return o}angular.module("ng-drag-scroll",[]).directive("dragScroll",e),e.$inject=["$document","$window","$parse"]}();