nl_tokens: @ngdoc function @name ng . $anchorScroll @requires $window @requires $location @requires $rootScope
pl_tokens: function $AnchorScrollProvider ( ) { var autoScrollingEnabled = true ; this . disableAutoScrolling = function ( ) { autoScrollingEnabled = false ; } ; this . $get = [ '$window' , '$location' , '$rootScope' , function ( $window , $location , $rootScope ) { var document = $window . document ; // helper function to get first anchor from a NodeList // can't use filter.filter, as it accepts only instances of Array // and IE can't convert NodeList to an array using [].slice // TODO(vojta): use filter if we change it to accept lists as well function getFirstAnchor ( list ) { var result = null ; forEach ( list , function ( element ) { if ( ! result && lowercase ( element . nodeName ) === 'a' ) result = element ; } ) ; return result ; } function scroll ( ) { var hash = $location . hash ( ) , elm ; // empty hash, scroll to the top of the page if ( ! hash ) $window . scrollTo ( 0 , 0 ) ; // element with given id else if ( ( elm = document . getElementById ( hash ) ) ) elm . scrollIntoView ( ) ; // first anchor with given name :-D else if ( ( elm = getFirstAnchor ( <mask> . getElementsByName ( hash ) ) ) ) elm . scrollIntoView ( ) ; // no element and hash == 'top', scroll to the top of the page else if ( hash === 'top' ) $window . scrollTo ( 0 , 0 ) ; } // does not scroll when user clicks on anchor link that is currently on // (no url change, no $location.hash() change), browser native does scroll if ( autoScrollingEnabled ) { $rootScope . $watch ( function autoScrollWatch ( ) { return $location . hash ( ) ; } , function autoScrollWatchAction ( ) { $rootScope . $evalAsync ( scroll ) ; } ) ; } return scroll ; } ] ; }