@@ -33,7 +33,7 @@ angular.module('duScroll.scrollHelpers', ['duScroll.requestAnimation'])
3333. run ( [ "$window" , "$q" , "cancelAnimation" , "requestAnimation" , "duScrollEasing" , "duScrollDuration" , "duScrollOffset" , function ( $window , $q , cancelAnimation , requestAnimation , duScrollEasing , duScrollDuration , duScrollOffset ) {
3434 'use strict' ;
3535
36- var proto = angular . element . prototype ;
36+ var proto = { } ;
3737
3838 var isDocument = function ( el ) {
3939 return ( typeof HTMLDocument !== 'undefined' && el instanceof HTMLDocument ) || ( el . nodeType && el . nodeType === el . DOCUMENT_NODE ) ;
@@ -47,12 +47,12 @@ angular.module('duScroll.scrollHelpers', ['duScroll.requestAnimation'])
4747 return isElement ( el ) || isDocument ( el ) ? el : el [ 0 ] ;
4848 } ;
4949
50- proto . scrollTo = function ( left , top , duration , easing ) {
50+ proto . duScrollTo = function ( left , top , duration , easing ) {
5151 var aliasFn ;
5252 if ( angular . isElement ( left ) ) {
53- aliasFn = this . scrollToElement ;
53+ aliasFn = this . duScrollToElement ;
5454 } else if ( duration ) {
55- aliasFn = this . scrollToAnimated ;
55+ aliasFn = this . duScrollToAnimated ;
5656 }
5757 if ( aliasFn ) {
5858 return aliasFn . apply ( this , arguments ) ;
@@ -66,12 +66,12 @@ angular.module('duScroll.scrollHelpers', ['duScroll.requestAnimation'])
6666 } ;
6767
6868 var scrollAnimation , deferred ;
69- proto . scrollToAnimated = function ( left , top , duration , easing ) {
69+ proto . duScrollToAnimated = function ( left , top , duration , easing ) {
7070 if ( duration && ! easing ) {
7171 easing = duScrollEasing ;
7272 }
73- var startLeft = this . scrollLeft ( ) ,
74- startTop = this . scrollTop ( ) ,
73+ var startLeft = this . duScrollLeft ( ) ,
74+ startTop = this . duScrollTop ( ) ,
7575 deltaLeft = Math . round ( left - startLeft ) ,
7676 deltaTop = Math . round ( top - startTop ) ;
7777
@@ -120,74 +120,69 @@ angular.module('duScroll.scrollHelpers', ['duScroll.requestAnimation'])
120120 } ;
121121
122122 //Fix random mobile safari bug when scrolling to top by hitting status bar
123- el . scrollTo ( startLeft , startTop ) ;
123+ el . duScrollTo ( startLeft , startTop ) ;
124124
125125 el . bind ( cancelOnEvents , cancelScrollAnimation ) ;
126126
127127 scrollAnimation = requestAnimation ( animationStep ) ;
128128 return deferred . promise ;
129129 } ;
130130
131- proto . scrollToElement = function ( target , offset , duration , easing ) {
131+ proto . duScrollToElement = function ( target , offset , duration , easing ) {
132132 var el = unwrap ( this ) ;
133133 if ( ! angular . isNumber ( offset ) || isNaN ( offset ) ) {
134134 offset = duScrollOffset ;
135135 }
136- var top = this . scrollTop ( ) + unwrap ( target ) . getBoundingClientRect ( ) . top - offset ;
136+ var top = this . duScrollTop ( ) + unwrap ( target ) . getBoundingClientRect ( ) . top - offset ;
137137 if ( isElement ( el ) ) {
138138 top -= el . getBoundingClientRect ( ) . top ;
139139 }
140- return this . scrollTo ( 0 , top , duration , easing ) ;
140+ return this . duScrollTo ( 0 , top , duration , easing ) ;
141141 } ;
142142
143- var overloaders = {
144- scrollLeft : function ( value , duration , easing ) {
145- if ( angular . isNumber ( value ) ) {
146- return this . scrollTo ( value , this . scrollTop ( ) , duration , easing ) ;
147- }
148- var el = unwrap ( this ) ;
149- if ( isDocument ( el ) ) {
150- return $window . scrollX || document . documentElement . scrollLeft || document . body . scrollLeft ;
151- }
152- return el . scrollLeft ;
153- } ,
154- scrollTop : function ( value , duration , easing ) {
155- if ( angular . isNumber ( value ) ) {
156- return this . scrollTo ( this . scrollTop ( ) , value , duration , easing ) ;
157- }
158- var el = unwrap ( this ) ;
159- if ( isDocument ( el ) ) {
160- return $window . scrollY || document . documentElement . scrollTop || document . body . scrollTop ;
161- }
162- return el . scrollTop ;
143+ proto . duScrollLeft = function ( value , duration , easing ) {
144+ if ( angular . isNumber ( value ) ) {
145+ return this . duScrollTo ( value , this . duScrollTop ( ) , duration , easing ) ;
163146 }
147+ var el = unwrap ( this ) ;
148+ if ( isDocument ( el ) ) {
149+ return $window . scrollX || document . documentElement . scrollLeft || document . body . scrollLeft ;
150+ }
151+ return el . scrollLeft ;
164152 } ;
165-
166- proto . scrollToElementAnimated = function ( target , offset , duration , easing ) {
167- return this . scrollToElement ( target , offset , duration || duScrollDuration , easing ) ;
153+ proto . duScrollTop = function ( value , duration , easing ) {
154+ if ( angular . isNumber ( value ) ) {
155+ return this . duScrollTo ( this . duScrollLeft ( ) , value , duration , easing ) ;
156+ }
157+ var el = unwrap ( this ) ;
158+ if ( isDocument ( el ) ) {
159+ return $window . scrollY || document . documentElement . scrollTop || document . body . scrollTop ;
160+ }
161+ return el . scrollTop ;
168162 } ;
169163
170- proto . scrollTopAnimated = function ( top , duration , easing ) {
171- return this . scrollTop ( top , duration || duScrollDuration , easing ) ;
164+ proto . duScrollToElementAnimated = function ( target , offset , duration , easing ) {
165+ return this . duScrollToElement ( target , offset , duration || duScrollDuration , easing ) ;
172166 } ;
173167
174- proto . scrollLeftAnimated = function ( left , duration , easing ) {
175- return this . scrollLeft ( left , duration || duScrollDuration , easing ) ;
168+ proto . duScrollTopAnimated = function ( top , duration , easing ) {
169+ return this . duScrollTop ( top , duration || duScrollDuration , easing ) ;
176170 } ;
177171
178- //Add duration and easing functionality to existing jQuery getter/setters
179- var overloadScrollPos = function ( superFn , overloadFn ) {
180- return function ( value , duration , easing ) {
181- if ( duration ) {
182- return overloadFn . apply ( this , arguments ) ;
183- }
184- return superFn . apply ( this , arguments ) ;
185- } ;
172+ proto . duScrollLeftAnimated = function ( left , duration , easing ) {
173+ return this . duScrollLeft ( left , duration || duScrollDuration , easing ) ;
186174 } ;
187175
188- for ( var methodName in overloaders ) {
189- proto [ methodName ] = ( proto [ methodName ] ? overloadScrollPos ( proto [ methodName ] , overloaders [ methodName ] ) : overloaders [ methodName ] ) ;
190- }
176+ angular . forEach ( proto , function ( fn , key ) {
177+ angular . element . prototype [ key ] = fn ;
178+
179+ //Remove prefix if not already claimed by jQuery / ui.utils
180+ var unprefixed = key . replace ( / ^ d u S c r o l l / , 'scroll' ) ;
181+ if ( angular . isUndefined ( angular . element . prototype [ unprefixed ] ) ) {
182+ angular . element . prototype [ unprefixed ] = fn ;
183+ }
184+ } ) ;
185+
191186} ] ) ;
192187
193188
@@ -395,6 +390,7 @@ angular.module('duScroll.spyAPI', ['duScroll.scrollContainerAPI'])
395390 if ( i !== - 1 ) {
396391 context . spies . splice ( i , 1 ) ;
397392 }
393+ spy . $element = null ;
398394 } ;
399395
400396 return {
@@ -469,7 +465,7 @@ angular.module('duScroll.smoothScroll', ['duScroll.scrollHelpers', 'duScroll.scr
469465 var duration = $attr . duration ? parseInt ( $attr . duration , 10 ) : duScrollDuration ;
470466 var container = scrollContainerAPI . getContainer ( $scope ) ;
471467
472- container . scrollToElement (
468+ container . duScrollToElement (
473469 angular . element ( target ) ,
474470 isNaN ( offset ) ? 0 : offset ,
475471 isNaN ( duration ) ? 0 : duration
0 commit comments