| | 189 | }, |
| | 190 | |
| | 191 | scrollToTop = function(t) { |
| | 192 | var startY, distance, direction, speed, step, steps, timer; |
| | 193 | |
| | 194 | // Ensure that the #wpadminbar was the target of the click. |
| | 195 | if ( t.id != 'wpadminbar' && t.id != 'wp-admin-bar-top-secondary' ) |
| | 196 | return; |
| | 197 | |
| | 198 | startY = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0; |
| | 199 | direction = ( startY > 0 ) ? 1 : -1; |
| | 200 | distance = Math.abs( startY ); |
| | 201 | speed = Math.min( 20, Math.round( distance / 100 ) ); |
| | 202 | step = Math.round( distance / 25 ); |
| | 203 | steps = []; |
| | 204 | timer = 0; |
| | 205 | |
| | 206 | // Animate scrolling to the top of the page by generating steps to |
| | 207 | // the top of the page and shifting to each step at a set interval. |
| | 208 | while ( distance ) { |
| | 209 | distance -= step; |
| | 210 | if ( distance < 0 ) |
| | 211 | distance = 0; |
| | 212 | steps.push( distance * direction ); |
| | 213 | |
| | 214 | setTimeout( function() { |
| | 215 | window.scrollTo( 0, steps.shift() ); |
| | 216 | }, timer * speed ); |
| | 217 | |
| | 218 | timer++; |
| | 219 | } |