|
381 | 381 | </div> |
382 | 382 |
|
383 | 383 | <script type="text/javascript" charset="utf-8"> |
| 384 | + // Which element is on top. |
| 385 | + var topElement = null |
| 386 | + // Scroll to the unread marker, or bottom if not found. |
| 387 | + function scrollToUnreadMarker() { |
| 388 | + var marker = document.getElementById('unread-marker') |
| 389 | + if (marker) { |
| 390 | + var rect = marker.getBoundingClientRect() |
| 391 | + window.scrollTo(0, rect.top + window.pageYOffset - (window.innerHeight / 2)) |
| 392 | + } else { |
| 393 | + window.scrollTo(0, document.body.scrollHeight) |
| 394 | + } |
| 395 | + } |
| 396 | + // For IE we need to scroll after ready, as the window body's size may be |
| 397 | + // incorrect before showing the browser. |
| 398 | + // For morden browsers scrolling before showing has the best visual effect. |
| 399 | + var isIE = /Trident|MSIE/.test(navigator.userAgent) |
| 400 | + if (!isIE) |
| 401 | + scrollToUnreadMarker() |
384 | 402 | // Helper to pass callbacks to UI. |
385 | 403 | var callbacks = {} |
386 | 404 | var nextCallbackId = 0 |
|
414 | 432 | wrapper.innerHTML = html |
415 | 433 | return wrapper.childNodes |
416 | 434 | } |
417 | | - // Which element is on top. |
418 | | - var topElement = null |
419 | 435 | // External API to add a new message. |
420 | 436 | var messages = document.getElementById('messages') |
421 | 437 | window.addMessage = function(html, firstUnread, fromCurrentUser) { |
|
526 | 542 | window.onresize = scrollToPreivousTopElement |
527 | 543 | // We are ready. |
528 | 544 | wey.ready() |
529 | | - // Scroll to the unread marker, or bottom if not found. |
530 | | - // Note: this must be done after ready, as the window body's size may be |
531 | | - // incorrect before showing the browser. |
532 | | - var marker = document.getElementById('unread-marker') |
533 | | - if (marker) { |
534 | | - var rect = marker.getBoundingClientRect() |
535 | | - window.scrollTo(0, rect.top + window.pageYOffset - (window.innerHeight / 2)) |
536 | | - } else { |
537 | | - window.scrollTo(0, document.body.scrollHeight) |
538 | | - } |
| 545 | + // See comment above on IE. |
| 546 | + if (isIE) |
| 547 | + scrollToUnreadMarker() |
539 | 548 | </script> |
540 | 549 | </body> |
541 | 550 | </html> |
0 commit comments