| 189 | }, |
| 190 | |
| 191 | scrollToTop = function(t) { |
| 192 | var distance, speed, step, steps, timer, speed_step; |
| 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 | distance = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0; |
| 199 | |
| 200 | if ( distance < 1 ) |
| 201 | return; |
| 202 | |
| 203 | speed_step = distance > 800 ? 130 : 100; |
| 204 | speed = Math.min( 12, Math.round( distance / speed_step ) ); |
| 205 | step = distance > 800 ? Math.round( distance / 30 ) : Math.round( distance / 20 ); |
| 206 | steps = []; |
| 207 | timer = 0; |
| 208 | |
| 209 | // Animate scrolling to the top of the page by generating steps to |
| 210 | // the top of the page and shifting to each step at a set interval. |
| 211 | while ( distance ) { |
| 212 | distance -= step; |
| 213 | if ( distance < 0 ) |
| 214 | distance = 0; |
| 215 | steps.push( distance ); |
| 216 | |
| 217 | setTimeout( function() { |
| 218 | window.scrollTo( 0, steps.shift() ); |
| 219 | }, timer * speed ); |
| 220 | |
| 221 | timer++; |
| 222 | } |