File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed
Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change 1212 //Usage:
1313 //<div drag-scroll>Lorem ipsum dolor sit amet</div>
1414 var directive = {
15- scope :{
16- dragScroll :'='
17- } ,
1815 restrict : 'A' ,
1916 link : function ( $scope , $element , $attributes , vm ) {
17+ var enabled = true ;
2018 var allowedClickOffset = 5 ;
2119 var pushed = false ;
2220 var onDragStart = $parse ( $attributes . onDragStart ) ;
2826 var lastClientX ;
2927 var lastClientY ;
3028
29+ $scope . $watch ( $attributes . dragScroll , function ( newValue ) {
30+ enabled = newValue !== undefined ? newValue : true ;
31+ } ) ;
32+
3133 // Set event listeners
3234 $element . on ( 'mousedown' , handleMouseDown ) ;
3335
5557 * @param {object } e MouseDown event
5658 */
5759 function handleMouseDown ( e ) {
58- if ( $scope . dragScroll ) {
60+ if ( enabled ) {
5961 for ( var i = 0 ; i < excludedClasses . length ; i ++ ) {
6062 if ( angular . element ( e . target ) . hasClass ( excludedClasses [ i ] ) ) {
6163 return false ;
8789 * @param {object } e MouseUp event
8890 */
8991 function handleMouseUp ( e ) {
90- if ( $scope . dragScroll ) {
92+ if ( enabled ) {
9193 var selectable = ( 'drag-scroll-text' in e . target . attributes ) ;
9294 var withinXConstraints = ( e . clientX >= ( startClientX - allowedClickOffset ) && e . clientX <= ( startClientX + allowedClickOffset ) ) ;
9395 var withinYConstraints = ( e . clientY >= ( startClientY - allowedClickOffset ) && e . clientY <= ( startClientY + allowedClickOffset ) ) ;
115117 * @param {object } e MouseMove event
116118 */
117119 function handleMouseMove ( e ) {
118- if ( $scope . dragScroll ) {
120+ if ( enabled ) {
119121 if ( pushed ) {
120122 if ( ! axis || axis === 'x' ) {
121123 $element [ 0 ] . scrollLeft -= ( - lastClientX + ( lastClientX = e . clientX ) ) ;
You can’t perform that action at this time.
0 commit comments