From 87fe947473659ee2c110512ed177b76b0559c140 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Wed, 13 May 2015 14:44:25 -0500
Subject: [PATCH] Scroll to most-recent thread entry

---
 scp/js/scp.js    | 4 ++--
 scp/js/ticket.js | 8 ++++++++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/scp/js/scp.js b/scp/js/scp.js
index 496b724c6..d1c73fc8b 100644
--- a/scp/js/scp.js
+++ b/scp/js/scp.js
@@ -450,13 +450,13 @@ var scp_prep = function() {
          stop = $('div.sticky.bar.stop'),
          stopAt,
          visible = false;
-     if (stop.length)
-       stopAt = stop.offset().top - $that.height();
 
      $that.find('.content').width($that.width());
      $(window).scroll(function (event) {
        // what the y position of the scroll is
        var y = $(this).scrollTop();
+       if (stop.length)
+         stopAt = stop.offset().top - $that.height();
 
        // whether that's below the form
        if (y >= top && (!stopAt || stopAt > y)) {
diff --git a/scp/js/ticket.js b/scp/js/ticket.js
index c5c8df202..9e731a756 100644
--- a/scp/js/ticket.js
+++ b/scp/js/ticket.js
@@ -343,6 +343,9 @@ $.refreshTicketView = function() {
 }
 
 var ticket_onload = function($) {
+    if (0 === $('#ticket_thread').length)
+        return;
+
     //Start watching the form for activity.
     autoLock.Init();
 
@@ -422,6 +425,11 @@ var ticket_onload = function($) {
     });
 
     $.showImagesInline($('#ticket_thread').data('imageUrls'));
+
+    var last_entry = $('#ticket_thread .thread-entry').last().offset().top - 50;
+    $('html, body').animate({
+        scrollTop: last_entry
+    }, 1000);
 };
 $(ticket_onload);
 $(document).on('pjax:success', function() { ticket_onload(jQuery); });
-- 
GitLab